blob: b69f6b4631155d9a3b4cbd15fa4b0551daf5e777 [file] [log] [blame]
zeertzjqe9a27ef2025-04-18 10:45:45 +02001*builtin.txt* For Vim version 9.1. Last change: 2025 Apr 18
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002
3
4 VIM REFERENCE MANUAL by Bram Moolenaar
5
6
7Builtin functions *builtin-functions*
8
Bram Moolenaarf269eab2022-10-03 18:04:35 +01009Note: Expression evaluation can be disabled at compile time, the builtin
10functions are not available then. See |+eval| and |no-eval-feature|.
11
12For functions grouped by what they are used for see |function-list|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000013
141. Overview |builtin-function-list|
152. Details |builtin-function-details|
163. Feature list |feature-list|
174. Matching a pattern in a String |string-match|
18
19==============================================================================
201. Overview *builtin-function-list*
21
22Use CTRL-] on the function name to jump to the full explanation.
23
24USAGE RESULT DESCRIPTION ~
25
26abs({expr}) Float or Number absolute value of {expr}
27acos({expr}) Float arc cosine of {expr}
28add({object}, {item}) List/Blob append {item} to {object}
29and({expr}, {expr}) Number bitwise AND
30append({lnum}, {text}) Number append {text} below line {lnum}
erraelf0837ba2024-06-24 12:27:01 -070031appendbufline({buf}, {lnum}, {text})
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000032 Number append {text} below line {lnum}
erraelf0837ba2024-06-24 12:27:01 -070033 in buffer {buf}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000034argc([{winid}]) Number number of files in the argument list
35argidx() Number current index in the argument list
36arglistid([{winnr} [, {tabnr}]]) Number argument list id
37argv({nr} [, {winid}]) String {nr} entry of the argument list
38argv([-1, {winid}]) List the argument list
39asin({expr}) Float arc sine of {expr}
40assert_beeps({cmd}) Number assert {cmd} causes a beep
41assert_equal({exp}, {act} [, {msg}])
42 Number assert {exp} is equal to {act}
43assert_equalfile({fname-one}, {fname-two} [, {msg}])
44 Number assert file contents are equal
45assert_exception({error} [, {msg}])
46 Number assert {error} is in v:exception
47assert_fails({cmd} [, {error} [, {msg} [, {lnum} [, {context}]]]])
48 Number assert {cmd} fails
49assert_false({actual} [, {msg}])
50 Number assert {actual} is false
51assert_inrange({lower}, {upper}, {actual} [, {msg}])
52 Number assert {actual} is inside the range
53assert_match({pat}, {text} [, {msg}])
54 Number assert {pat} matches {text}
55assert_nobeep({cmd}) Number assert {cmd} does not cause a beep
56assert_notequal({exp}, {act} [, {msg}])
57 Number assert {exp} is not equal {act}
58assert_notmatch({pat}, {text} [, {msg}])
59 Number assert {pat} not matches {text}
60assert_report({msg}) Number report a test failure
61assert_true({actual} [, {msg}]) Number assert {actual} is true
62atan({expr}) Float arc tangent of {expr}
63atan2({expr1}, {expr2}) Float arc tangent of {expr1} / {expr2}
Yegappan Lakshmanan1755a912022-05-19 10:31:47 +010064autocmd_add({acmds}) Bool add a list of autocmds and groups
65autocmd_delete({acmds}) Bool delete a list of autocmds and groups
66autocmd_get([{opts}]) List return a list of autocmds
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000067balloon_gettext() String current text in the balloon
68balloon_show({expr}) none show {expr} inside the balloon
69balloon_split({msg}) List split {msg} as used for a balloon
h-easte80f3452025-01-02 10:40:29 +010070base64_decode({string}) Blob base64 decode {string} characters
71base64_encode({blob}) String base64 encode the bytes in {blob}
Christ van Willegence0ef912024-06-20 23:41:59 +020072bindtextdomain({package}, {path})
Christ van Willegen8252ef12024-07-11 21:36:21 +020073 Bool bind text domain to specified path
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000074blob2list({blob}) List convert {blob} into a list of numbers
Yegappan Lakshmanan166b1752025-01-17 11:48:12 +010075blob2str({blob} [, {options}]) List convert {blob} into a list of strings
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000076browse({save}, {title}, {initdir}, {default})
77 String put up a file requester
78browsedir({title}, {initdir}) String put up a directory requester
79bufadd({name}) Number add a buffer to the buffer list
80bufexists({buf}) Number |TRUE| if buffer {buf} exists
81buflisted({buf}) Number |TRUE| if buffer {buf} is listed
82bufload({buf}) Number load buffer {buf} if not loaded yet
83bufloaded({buf}) Number |TRUE| if buffer {buf} is loaded
84bufname([{buf}]) String Name of the buffer {buf}
85bufnr([{buf} [, {create}]]) Number Number of the buffer {buf}
86bufwinid({buf}) Number window ID of buffer {buf}
87bufwinnr({buf}) Number window number of buffer {buf}
88byte2line({byte}) Number line number at byte count {byte}
Christian Brabandt67672ef2023-04-24 21:09:54 +010089byteidx({expr}, {nr} [, {utf16}])
90 Number byte index of {nr}'th char in {expr}
91byteidxcomp({expr}, {nr} [, {utf16}])
92 Number byte index of {nr}'th char in {expr}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000093call({func}, {arglist} [, {dict}])
94 any call {func} with arguments {arglist}
95ceil({expr}) Float round {expr} up
96ch_canread({handle}) Number check if there is something to read
97ch_close({handle}) none close {handle}
98ch_close_in({handle}) none close in part of {handle}
99ch_evalexpr({handle}, {expr} [, {options}])
100 any evaluate {expr} on JSON {handle}
101ch_evalraw({handle}, {string} [, {options}])
102 any evaluate {string} on raw {handle}
103ch_getbufnr({handle}, {what}) Number get buffer number for {handle}/{what}
104ch_getjob({channel}) Job get the Job of {channel}
105ch_info({handle}) String info about channel {handle}
106ch_log({msg} [, {handle}]) none write {msg} in the channel log file
107ch_logfile({fname} [, {mode}]) none start logging channel activity
108ch_open({address} [, {options}])
109 Channel open a channel to {address}
110ch_read({handle} [, {options}]) String read from {handle}
111ch_readblob({handle} [, {options}])
112 Blob read Blob from {handle}
113ch_readraw({handle} [, {options}])
114 String read raw from {handle}
115ch_sendexpr({handle}, {expr} [, {options}])
116 any send {expr} over JSON {handle}
117ch_sendraw({handle}, {expr} [, {options}])
118 any send {expr} over raw {handle}
119ch_setoptions({handle}, {options})
120 none set options for {handle}
121ch_status({handle} [, {options}])
122 String status of channel {handle}
123changenr() Number current change number
124char2nr({expr} [, {utf8}]) Number ASCII/UTF-8 value of first char in {expr}
125charclass({string}) Number character class of {string}
Yegappan Lakshmanan4c8d2f02022-11-12 16:07:47 +0000126charcol({expr} [, {winid}]) Number column number of cursor or mark
Christian Brabandt67672ef2023-04-24 21:09:54 +0100127charidx({string}, {idx} [, {countcc} [, {utf16}]])
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000128 Number char index of byte {idx} in {string}
129chdir({dir}) String change current working directory
130cindent({lnum}) Number C indent for line {lnum}
131clearmatches([{win}]) none clear all matches
Yegappan Lakshmanan4c8d2f02022-11-12 16:07:47 +0000132col({expr} [, {winid}]) Number column byte index of cursor or mark
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000133complete({startcol}, {matches}) none set Insert mode completion
134complete_add({expr}) Number add completion match
135complete_check() Number check for key typed during completion
136complete_info([{what}]) Dict get current completion information
137confirm({msg} [, {choices} [, {default} [, {type}]]])
138 Number number of choice picked by user
139copy({expr}) any make a shallow copy of {expr}
140cos({expr}) Float cosine of {expr}
141cosh({expr}) Float hyperbolic cosine of {expr}
142count({comp}, {expr} [, {ic} [, {start}]])
143 Number count how many {expr} are in {comp}
144cscope_connection([{num}, {dbpath} [, {prepend}]])
145 Number checks existence of cscope connection
146cursor({lnum}, {col} [, {off}])
147 Number move cursor to {lnum}, {col}, {off}
148cursor({list}) Number move cursor to position in {list}
149debugbreak({pid}) Number interrupt process being debugged
150deepcopy({expr} [, {noref}]) any make a full copy of {expr}
151delete({fname} [, {flags}]) Number delete the file or directory {fname}
152deletebufline({buf}, {first} [, {last}])
153 Number delete lines from buffer {buf}
154did_filetype() Number |TRUE| if FileType autocmd event used
Yegappan Lakshmananfa378352024-02-01 22:05:27 +0100155diff({fromlist}, {tolist} [, {options}])
156 List diff two Lists of strings
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000157diff_filler({lnum}) Number diff filler lines about {lnum}
158diff_hlID({lnum}, {col}) Number diff highlighting at {lnum}/{col}
159digraph_get({chars}) String get the |digraph| of {chars}
160digraph_getlist([{listall}]) List get all |digraph|s
Christian Brabandtfbc37f12024-06-18 20:50:58 +0200161digraph_set({chars}, {digraph}) Bool register |digraph|
162digraph_setlist({digraphlist}) Bool register multiple |digraph|s
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000163echoraw({expr}) none output {expr} as-is
164empty({expr}) Number |TRUE| if {expr} is empty
165environ() Dict return environment variables
Sean Dewarb0efa492023-07-08 10:35:19 +0100166err_teapot([{expr}]) none give E418, or E503 if {expr} is |TRUE|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000167escape({string}, {chars}) String escape {chars} in {string} with '\'
168eval({string}) any evaluate {string} into its value
169eventhandler() Number |TRUE| if inside an event handler
170executable({expr}) Number 1 if executable {expr} exists
171execute({command}) String execute {command} and get the output
172exepath({expr}) String full path of the command {expr}
173exists({expr}) Number |TRUE| if {expr} exists
174exists_compiled({expr}) Number |TRUE| if {expr} exists at compile time
175exp({expr}) Float exponential of {expr}
176expand({expr} [, {nosuf} [, {list}]])
177 any expand special keywords in {expr}
Yegappan Lakshmanan2b74b682022-04-03 21:30:32 +0100178expandcmd({string} [, {options}])
179 String expand {string} like with `:edit`
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000180extend({expr1}, {expr2} [, {expr3}])
181 List/Dict insert items of {expr2} into {expr1}
182extendnew({expr1}, {expr2} [, {expr3}])
183 List/Dict like |extend()| but creates a new
184 List or Dictionary
185feedkeys({string} [, {mode}]) Number add key sequence to typeahead buffer
Shougo Matsushita60c87432024-06-03 22:59:27 +0200186filecopy({from}, {to}) Number |TRUE| if copying file {from} to {to}
187 worked
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000188filereadable({file}) Number |TRUE| if {file} is a readable file
189filewritable({file}) Number |TRUE| if {file} is a writable file
190filter({expr1}, {expr2}) List/Dict/Blob/String
191 remove items from {expr1} where
192 {expr2} is 0
193finddir({name} [, {path} [, {count}]])
194 String find directory {name} in {path}
195findfile({name} [, {path} [, {count}]])
196 String find file {name} in {path}
197flatten({list} [, {maxdepth}]) List flatten {list} up to {maxdepth} levels
198flattennew({list} [, {maxdepth}])
199 List flatten a copy of {list}
200float2nr({expr}) Number convert Float {expr} to a Number
201floor({expr}) Float round {expr} down
202fmod({expr1}, {expr2}) Float remainder of {expr1} / {expr2}
203fnameescape({fname}) String escape special characters in {fname}
204fnamemodify({fname}, {mods}) String modify file name
205foldclosed({lnum}) Number first line of fold at {lnum} if closed
206foldclosedend({lnum}) Number last line of fold at {lnum} if closed
207foldlevel({lnum}) Number fold level at {lnum}
208foldtext() String line displayed for closed fold
209foldtextresult({lnum}) String text for closed fold at {lnum}
Yegappan Lakshmanan9cb865e2025-03-23 16:42:16 +0100210foreach({expr1}, {expr2}) List/Tuple/Dict/Blob/String
Ernie Raele79e2072024-01-13 11:47:33 +0100211 for each item in {expr1} call {expr2}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000212foreground() Number bring the Vim window to the foreground
Bram Moolenaaraa534142022-09-15 21:46:02 +0100213fullcommand({name} [, {vim9}]) String get full command from {name}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000214funcref({name} [, {arglist}] [, {dict}])
215 Funcref reference to function {name}
216function({name} [, {arglist}] [, {dict}])
217 Funcref named reference to function {name}
218garbagecollect([{atexit}]) none free memory, breaking cyclic references
219get({list}, {idx} [, {def}]) any get item {idx} from {list} or {def}
220get({dict}, {key} [, {def}]) any get item {key} from {dict} or {def}
221get({func}, {what}) any get property of funcref/partial {func}
222getbufinfo([{buf}]) List information about buffers
223getbufline({buf}, {lnum} [, {end}])
224 List lines {lnum} to {end} of buffer {buf}
Bram Moolenaarce30ccc2022-11-21 19:57:04 +0000225getbufoneline({buf}, {lnum}) String line {lnum} of buffer {buf}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000226getbufvar({buf}, {varname} [, {def}])
227 any variable {varname} in buffer {buf}
mikoto20001083cae2024-11-11 21:24:14 +0100228getcellpixels() List get character cell pixel size
Kota Kato66bb9ae2023-01-17 18:31:56 +0000229getcellwidths() List get character cell width overrides
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000230getchangelist([{buf}]) List list of change list items
zeertzjqe0a2ab32025-02-02 09:14:35 +0100231getchar([{expr} [, {opts}]]) Number or String
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000232 get one character from the user
233getcharmod() Number modifiers for the last typed character
234getcharpos({expr}) List position of cursor, mark, etc.
235getcharsearch() Dict last character search
zeertzjqe0a2ab32025-02-02 09:14:35 +0100236getcharstr([{expr} [, {opts}]]) String get one character from the user
Ruslan Russkikh0407d622024-10-08 22:21:05 +0200237getcmdcomplpat() String return the completion pattern of the
238 current command-line completion
Shougo Matsushita79d599b2022-05-07 12:48:29 +0100239getcmdcompltype() String return the type of the current
240 command-line completion
Shougo Matsushita69084282024-09-23 20:34:47 +0200241getcmdline() String return the current command-line input
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000242getcmdpos() Number return cursor position in command-line
Shougo Matsushita69084282024-09-23 20:34:47 +0200243getcmdprompt() String return the current command-line prompt
Shougo Matsushita79d599b2022-05-07 12:48:29 +0100244getcmdscreenpos() Number return cursor screen position in
245 command-line
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000246getcmdtype() String return current command-line type
247getcmdwintype() String return current command-line window type
248getcompletion({pat}, {type} [, {filtered}])
249 List list of cmdline completion matches
250getcurpos([{winnr}]) List position of the cursor
251getcursorcharpos([{winnr}]) List character position of the cursor
252getcwd([{winnr} [, {tabnr}]]) String get the current working directory
253getenv({name}) String return environment variable
254getfontname([{name}]) String name of font being used
255getfperm({fname}) String file permissions of file {fname}
256getfsize({fname}) Number size in bytes of file {fname}
257getftime({fname}) Number last modification time of file
258getftype({fname}) String description of type of file {fname}
259getimstatus() Number |TRUE| if the IME status is active
260getjumplist([{winnr} [, {tabnr}]])
261 List list of jump list items
262getline({lnum}) String line {lnum} of current buffer
263getline({lnum}, {end}) List lines {lnum} to {end} of current buffer
264getloclist({nr}) List list of location list items
265getloclist({nr}, {what}) Dict get specific location list properties
266getmarklist([{buf}]) List list of global/local marks
267getmatches([{win}]) List list of current matches
268getmousepos() Dict last known mouse position
Bram Moolenaar24dc19c2022-11-14 19:49:15 +0000269getmouseshape() String current mouse shape name
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000270getpid() Number process ID of Vim
271getpos({expr}) List position of cursor, mark, etc.
272getqflist() List list of quickfix items
273getqflist({what}) Dict get specific quickfix list properties
274getreg([{regname} [, 1 [, {list}]]])
275 String or List contents of a register
276getreginfo([{regname}]) Dict information about a register
Shougo Matsushita19b71882024-02-28 22:48:12 +0100277getregion({pos1}, {pos2} [, {opts}])
Shougo Matsushita3f905ab2024-02-21 00:02:45 +0100278 List get the text from {pos1} to {pos2}
Shougo Matsushitab4757e62024-05-07 20:49:24 +0200279getregionpos({pos1}, {pos2} [, {opts}])
280 List get a list of positions for a region
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000281getregtype([{regname}]) String type of a register
Yegappan Lakshmanan520f6ef2022-08-25 17:40:40 +0100282getscriptinfo([{opts}]) List list of sourced scripts
ichizok663d18d2025-01-02 18:06:00 +0100283getstacktrace() List get current stack trace of Vim scripts
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000284gettabinfo([{expr}]) List list of tab pages
285gettabvar({nr}, {varname} [, {def}])
286 any variable {varname} in tab {nr} or {def}
287gettabwinvar({tabnr}, {winnr}, {name} [, {def}])
288 any {name} in {winnr} in tab page {tabnr}
289gettagstack([{nr}]) Dict get the tag stack of window {nr}
h-east52e7cc22024-07-28 17:03:29 +0200290gettext({text} [, {package}]) String lookup translation of {text}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000291getwininfo([{winid}]) List list of info about each window
Bram Moolenaar938ae282023-02-20 20:44:55 +0000292getwinpos([{timeout}]) List X and Y coord in pixels of Vim window
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000293getwinposx() Number X coord in pixels of the Vim window
294getwinposy() Number Y coord in pixels of the Vim window
295getwinvar({nr}, {varname} [, {def}])
296 any variable {varname} in window {nr}
297glob({expr} [, {nosuf} [, {list} [, {alllinks}]]])
298 any expand file wildcards in {expr}
299glob2regpat({expr}) String convert a glob pat into a search pat
300globpath({path}, {expr} [, {nosuf} [, {list} [, {alllinks}]]])
301 String do glob({expr}) for all dirs in {path}
302has({feature} [, {check}]) Number |TRUE| if feature {feature} supported
303has_key({dict}, {key}) Number |TRUE| if {dict} has entry {key}
304haslocaldir([{winnr} [, {tabnr}]])
305 Number |TRUE| if the window executed |:lcd|
306 or |:tcd|
307hasmapto({what} [, {mode} [, {abbr}]])
308 Number |TRUE| if mapping to {what} exists
309histadd({history}, {item}) Number add an item to a history
310histdel({history} [, {item}]) Number remove an item from a history
311histget({history} [, {index}]) String get the item {index} from a history
312histnr({history}) Number highest index of a history
313hlID({name}) Number syntax ID of highlight group {name}
314hlexists({name}) Number |TRUE| if highlight group {name} exists
315hlget([{name} [, {resolve}]]) List get highlight group attributes
316hlset({list}) Number set highlight group attributes
317hostname() String name of the machine Vim is running on
318iconv({expr}, {from}, {to}) String convert encoding of {expr}
Ernie Rael05124252024-07-11 22:10:45 +0200319id({item}) String get unique identity string of item
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000320indent({lnum}) Number indent of line {lnum}
321index({object}, {expr} [, {start} [, {ic}]])
322 Number index in {object} where {expr} appears
Yegappan Lakshmananb2186552022-08-13 13:09:20 +0100323indexof({object}, {expr} [, {opts}]])
324 Number index in {object} where {expr} is true
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000325input({prompt} [, {text} [, {completion}]])
326 String get input from the user
Bram Moolenaarb529cfb2022-07-25 15:42:07 +0100327inputdialog({prompt} [, {text} [, {cancelreturn}]])
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000328 String like input() but in a GUI dialog
329inputlist({textlist}) Number let the user pick from a choice list
330inputrestore() Number restore typeahead
331inputsave() Number save and clear typeahead
332inputsecret({prompt} [, {text}]) String like input() but hiding the text
333insert({object}, {item} [, {idx}]) List insert {item} in {object} [before {idx}]
LemonBoyafe04662023-08-23 21:08:11 +0200334instanceof({object}, {class}) Number |TRUE| if {object} is an instance of {class}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000335interrupt() none interrupt script execution
336invert({expr}) Number bitwise invert
LemonBoydca1d402022-04-28 15:26:33 +0100337isabsolutepath({path}) Number |TRUE| if {path} is an absolute path
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000338isdirectory({directory}) Number |TRUE| if {directory} is a directory
339isinf({expr}) Number determine if {expr} is infinity value
340 (positive or negative)
341islocked({expr}) Number |TRUE| if {expr} is locked
342isnan({expr}) Number |TRUE| if {expr} is NaN
343items({dict}) List key-value pairs in {dict}
344job_getchannel({job}) Channel get the channel handle for {job}
345job_info([{job}]) Dict get information about {job}
346job_setoptions({job}, {options}) none set options for {job}
347job_start({command} [, {options}])
348 Job start a job
349job_status({job}) String get the status of {job}
350job_stop({job} [, {how}]) Number stop {job}
Yegappan Lakshmanan9cb865e2025-03-23 16:42:16 +0100351join({expr} [, {sep}]) String join items in {expr} into one String
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000352js_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
Yegappan Lakshmanan9cb865e2025-03-23 16:42:16 +0100367list2tuple({list}) Tuple turn {list} of items into a tuple
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000368listener_add({callback} [, {buf}])
369 Number add a callback to listen to changes
370listener_flush([{buf}]) none invoke listener callbacks
371listener_remove({id}) none remove a listener callback
372localtime() Number current time
373log({expr}) Float natural logarithm (base e) of {expr}
374log10({expr}) Float logarithm of Float {expr} to base 10
375luaeval({expr} [, {expr}]) any evaluate |Lua| expression
376map({expr1}, {expr2}) List/Dict/Blob/String
377 change each item in {expr1} to {expr2}
378maparg({name} [, {mode} [, {abbr} [, {dict}]]])
379 String or Dict
380 rhs of mapping {name} in mode {mode}
381mapcheck({name} [, {mode} [, {abbr}]])
382 String check for mappings matching {name}
Ernie Rael09661202022-04-25 14:40:44 +0100383maplist([{abbr}]) List list of all mappings, a dict for each
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000384mapnew({expr1}, {expr2}) List/Dict/Blob/String
385 like |map()| but creates a new List or
386 Dictionary
387mapset({mode}, {abbr}, {dict}) none restore mapping from |maparg()| result
388match({expr}, {pat} [, {start} [, {count}]])
389 Number position where {pat} matches in {expr}
390matchadd({group}, {pattern} [, {priority} [, {id} [, {dict}]]])
391 Number highlight {pattern} with {group}
392matchaddpos({group}, {pos} [, {priority} [, {id} [, {dict}]]])
393 Number highlight positions with {group}
394matcharg({nr}) List arguments of |:match|
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +0100395matchbufline({buf}, {pat}, {lnum}, {end}, [, {dict})
396 List all the {pat} matches in buffer {buf}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000397matchdelete({id} [, {win}]) Number delete match identified by {id}
398matchend({expr}, {pat} [, {start} [, {count}]])
399 Number position where {pat} ends in {expr}
400matchfuzzy({list}, {str} [, {dict}])
401 List fuzzy match {str} in {list}
402matchfuzzypos({list}, {str} [, {dict}])
403 List fuzzy match {str} in {list}
404matchlist({expr}, {pat} [, {start} [, {count}]])
405 List match and submatches of {pat} in {expr}
406matchstr({expr}, {pat} [, {start} [, {count}]])
407 String {count}'th match of {pat} in {expr}
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +0100408matchstrlist({list}, {pat} [, {dict})
409 List all the {pat} matches in {list}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000410matchstrpos({expr}, {pat} [, {start} [, {count}]])
411 List {count}'th match of {pat} in {expr}
412max({expr}) Number maximum value of items in {expr}
413menu_info({name} [, {mode}]) Dict get menu item information
414min({expr}) Number minimum value of items in {expr}
Bram Moolenaar938ae282023-02-20 20:44:55 +0000415mkdir({name} [, {flags} [, {prot}]])
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000416 Number create directory {name}
Doug Kearns9cd9e752024-04-07 17:42:17 +0200417mode([{expr}]) String current editing mode
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000418mzeval({expr}) any evaluate |MzScheme| expression
419nextnonblank({lnum}) Number line nr of non-blank line >= {lnum}
Christ van Willegenc0786752025-02-01 15:42:16 +0100420ngettext({single}, {plural}, {number}[, {domain}])
421 String translate text based on {number}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000422nr2char({expr} [, {utf8}]) String single char with ASCII/UTF-8 value {expr}
423or({expr}, {expr}) Number bitwise OR
424pathshorten({expr} [, {len}]) String shorten directory names in a path
425perleval({expr}) any evaluate |Perl| expression
426popup_atcursor({what}, {options}) Number create popup window near the cursor
427popup_beval({what}, {options}) Number create popup window for 'ballooneval'
428popup_clear() none close all popup windows
429popup_close({id} [, {result}]) none close popup window {id}
430popup_create({what}, {options}) Number create a popup window
431popup_dialog({what}, {options}) Number create a popup window used as a dialog
432popup_filter_menu({id}, {key}) Number filter for a menu popup window
433popup_filter_yesno({id}, {key}) Number filter for a dialog popup window
Bram Moolenaarbdc09a12022-10-07 14:31:45 +0100434popup_findecho() Number get window ID of popup for `:echowin`
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000435popup_findinfo() Number get window ID of info popup window
436popup_findpreview() Number get window ID of preview popup window
437popup_getoptions({id}) Dict get options of popup window {id}
438popup_getpos({id}) Dict get position of popup window {id}
439popup_hide({id}) none hide popup menu {id}
440popup_list() List get a list of window IDs of all popups
441popup_locate({row}, {col}) Number get window ID of popup at position
442popup_menu({what}, {options}) Number create a popup window used as a menu
443popup_move({id}, {options}) none set position of popup window {id}
444popup_notification({what}, {options})
445 Number create a notification popup window
Christian Brabandtfbc37f12024-06-18 20:50:58 +0200446popup_setbuf({id}, {buf}) Bool set the buffer for the popup window {id}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000447popup_setoptions({id}, {options})
448 none set options for popup window {id}
449popup_settext({id}, {text}) none set the text of popup window {id}
450popup_show({id}) none unhide popup window {id}
451pow({x}, {y}) Float {x} to the power of {y}
452prevnonblank({lnum}) Number line nr of non-blank line <= {lnum}
453printf({fmt}, {expr1}...) String format text
454prompt_getprompt({buf}) String get prompt text
455prompt_setcallback({buf}, {expr}) none set prompt callback function
456prompt_setinterrupt({buf}, {text}) none set prompt interrupt function
457prompt_setprompt({buf}, {text}) none set prompt text
458prop_add({lnum}, {col}, {props}) none add one text property
459prop_add_list({props}, [[{lnum}, {col}, {end-lnum}, {end-col}], ...])
460 none add multiple text properties
461prop_clear({lnum} [, {lnum-end} [, {props}]])
462 none remove all text properties
463prop_find({props} [, {direction}])
464 Dict search for a text property
465prop_list({lnum} [, {props}]) List text properties in {lnum}
466prop_remove({props} [, {lnum} [, {lnum-end}]])
467 Number remove a text property
468prop_type_add({name}, {props}) none define a new property type
469prop_type_change({name}, {props})
470 none change an existing property type
471prop_type_delete({name} [, {props}])
472 none delete a property type
473prop_type_get({name} [, {props}])
474 Dict get property type values
475prop_type_list([{props}]) List get list of property types
476pum_getpos() Dict position and size of pum if visible
477pumvisible() Number whether popup menu is visible
zeertzjq7c515282024-11-10 20:26:12 +0100478py3eval({expr} [, {locals}]) any evaluate |python3| expression
479pyeval({expr} [, {locals}]) any evaluate |Python| expression
480pyxeval({expr} [, {locals}]) any evaluate |python_x| expression
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000481rand([{expr}]) Number get pseudo-random number
482range({expr} [, {max} [, {stride}]])
483 List items from {expr} to {max}
K.Takata11df3ae2022-10-19 14:02:40 +0100484readblob({fname} [, {offset} [, {size}]])
485 Blob read a |Blob| from {fname}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000486readdir({dir} [, {expr} [, {dict}]])
487 List file names in {dir} selected by {expr}
488readdirex({dir} [, {expr} [, {dict}]])
489 List file info in {dir} selected by {expr}
490readfile({fname} [, {type} [, {max}]])
491 List get list of lines from file {fname}
492reduce({object}, {func} [, {initial}])
493 any reduce {object} using {func}
494reg_executing() String get the executing register name
495reg_recording() String get the recording register name
496reltime([{start} [, {end}]]) List get time value
497reltimefloat({time}) Float turn the time value into a Float
498reltimestr({time}) String turn time value into a String
499remote_expr({server}, {string} [, {idvar} [, {timeout}]])
500 String send expression
501remote_foreground({server}) Number bring Vim server to the foreground
502remote_peek({serverid} [, {retvar}])
503 Number check for reply string
504remote_read({serverid} [, {timeout}])
505 String read reply string
506remote_send({server}, {string} [, {idvar}])
507 String send key sequence
508remote_startserver({name}) none become server {name}
509remove({list}, {idx} [, {end}]) any/List
510 remove items {idx}-{end} from {list}
511remove({blob}, {idx} [, {end}]) Number/Blob
512 remove bytes {idx}-{end} from {blob}
513remove({dict}, {key}) any remove entry {key} from {dict}
514rename({from}, {to}) Number rename (move) file from {from} to {to}
Yegappan Lakshmanan9cb865e2025-03-23 16:42:16 +0100515repeat({expr}, {count}) List/Tuple/Blob/String
Bakudankun375141e2022-09-09 18:46:47 +0100516 repeat {expr} {count} times
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000517resolve({filename}) String get filename a shortcut points to
Yegappan Lakshmanan9cb865e2025-03-23 16:42:16 +0100518reverse({obj}) List/Tuple/Blob/String
Yegappan Lakshmanan03ff1c22023-05-06 14:08:21 +0100519 reverse {obj}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000520round({expr}) Float round off {expr}
521rubyeval({expr}) any evaluate |Ruby| expression
522screenattr({row}, {col}) Number attribute at screen position
523screenchar({row}, {col}) Number character at screen position
524screenchars({row}, {col}) List List of characters at screen position
525screencol() Number current cursor column
526screenpos({winid}, {lnum}, {col}) Dict screen row and col of a text character
527screenrow() Number current cursor row
528screenstring({row}, {col}) String characters at screen position
529search({pattern} [, {flags} [, {stopline} [, {timeout} [, {skip}]]]])
530 Number search for {pattern}
531searchcount([{options}]) Dict get or update search stats
532searchdecl({name} [, {global} [, {thisblock}]])
533 Number search for variable declaration
534searchpair({start}, {middle}, {end} [, {flags} [, {skip} [...]]])
535 Number search for other end of start/end pair
536searchpairpos({start}, {middle}, {end} [, {flags} [, {skip} [...]]])
537 List search for other end of start/end pair
538searchpos({pattern} [, {flags} [, {stopline} [, {timeout} [, {skip}]]]])
539 List search for {pattern}
540server2client({clientid}, {string})
541 Number send reply string
542serverlist() String get a list of available servers
erraelf0837ba2024-06-24 12:27:01 -0700543setbufline({buf}, {lnum}, {text})
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000544 Number set line {lnum} to {text} in buffer
erraelf0837ba2024-06-24 12:27:01 -0700545 {buf}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000546setbufvar({buf}, {varname}, {val})
547 none set {varname} in buffer {buf} to {val}
548setcellwidths({list}) none set character cell width overrides
549setcharpos({expr}, {list}) Number set the {expr} position to {list}
550setcharsearch({dict}) Dict set character search from {dict}
Shougo Matsushita07ea5f12022-08-27 12:22:25 +0100551setcmdline({str} [, {pos}]) Number set command-line
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000552setcmdpos({pos}) Number set cursor position in command-line
553setcursorcharpos({list}) Number move cursor to position in {list}
554setenv({name}, {val}) none set environment variable
555setfperm({fname}, {mode}) Number set {fname} file permissions to {mode}
556setline({lnum}, {line}) Number set line {lnum} to {line}
557setloclist({nr}, {list} [, {action}])
558 Number modify location list using {list}
559setloclist({nr}, {list}, {action}, {what})
560 Number modify specific location list props
561setmatches({list} [, {win}]) Number restore a list of matches
562setpos({expr}, {list}) Number set the {expr} position to {list}
563setqflist({list} [, {action}]) Number modify quickfix list using {list}
564setqflist({list}, {action}, {what})
565 Number modify specific quickfix list props
566setreg({n}, {v} [, {opt}]) Number set register to value and type
567settabvar({nr}, {varname}, {val}) none set {varname} in tab page {nr} to {val}
568settabwinvar({tabnr}, {winnr}, {varname}, {val})
569 none set {varname} in window {winnr} in tab
570 page {tabnr} to {val}
571settagstack({nr}, {dict} [, {action}])
572 Number modify tag stack using {dict}
573setwinvar({nr}, {varname}, {val}) none set {varname} in window {nr} to {val}
574sha256({string}) String SHA256 checksum of {string}
575shellescape({string} [, {special}])
576 String escape {string} for use as shell
577 command argument
578shiftwidth([{col}]) Number effective value of 'shiftwidth'
579sign_define({name} [, {dict}]) Number define or update a sign
580sign_define({list}) List define or update a list of signs
581sign_getdefined([{name}]) List get a list of defined signs
582sign_getplaced([{buf} [, {dict}]])
583 List get a list of placed signs
584sign_jump({id}, {group}, {buf})
585 Number jump to a sign
586sign_place({id}, {group}, {name}, {buf} [, {dict}])
587 Number place a sign
588sign_placelist({list}) List place a list of signs
589sign_undefine([{name}]) Number undefine a sign
590sign_undefine({list}) List undefine a list of signs
591sign_unplace({group} [, {dict}])
592 Number unplace a sign
593sign_unplacelist({list}) List unplace a list of signs
594simplify({filename}) String simplify filename as much as possible
595sin({expr}) Float sine of {expr}
596sinh({expr}) Float hyperbolic sine of {expr}
597slice({expr}, {start} [, {end}]) String, List or Blob
598 slice of a String, List or Blob
Bram Moolenaar2007dd42022-02-23 13:17:47 +0000599sort({list} [, {how} [, {dict}]])
600 List sort {list}, compare with {how}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000601sound_clear() none stop playing all sounds
602sound_playevent({name} [, {callback}])
603 Number play an event sound
604sound_playfile({path} [, {callback}])
605 Number play sound file {path}
606sound_stop({id}) none stop playing sound {id}
607soundfold({word}) String sound-fold {word}
608spellbadword() String badly spelled word at cursor
609spellsuggest({word} [, {max} [, {capital}]])
610 List spelling suggestions
611split({expr} [, {pat} [, {keepempty}]])
612 List make |List| from {pat} separated {expr}
613sqrt({expr}) Float square root of {expr}
614srand([{expr}]) List get seed for |rand()|
615state([{what}]) String current state of Vim
Hirohito Higashi195fcc92025-02-01 10:26:58 +0100616str2blob({list} [, {options}]) Blob convert list of strings into a Blob
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000617str2float({expr} [, {quoted}]) Float convert String to Float
618str2list({expr} [, {utf8}]) List convert each character of {expr} to
619 ASCII/UTF-8 value
620str2nr({expr} [, {base} [, {quoted}]])
621 Number convert String to Number
622strcharlen({expr}) Number character length of the String {expr}
623strcharpart({str}, {start} [, {len} [, {skipcc}]])
624 String {len} characters of {str} at
625 character {start}
626strchars({expr} [, {skipcc}]) Number character count of the String {expr}
627strdisplaywidth({expr} [, {col}]) Number display length of the String {expr}
628strftime({format} [, {time}]) String format time with a specified format
629strgetchar({str}, {index}) Number get char {index} from {str}
630stridx({haystack}, {needle} [, {start}])
631 Number index of {needle} in {haystack}
632string({expr}) String String representation of {expr} value
633strlen({expr}) Number length of the String {expr}
634strpart({str}, {start} [, {len} [, {chars}]])
635 String {len} bytes/chars of {str} at
636 byte {start}
637strptime({format}, {timestring})
638 Number Convert {timestring} to unix timestamp
639strridx({haystack}, {needle} [, {start}])
640 Number last index of {needle} in {haystack}
641strtrans({expr}) String translate string to make it printable
Christian Brabandt67672ef2023-04-24 21:09:54 +0100642strutf16len({string} [, {countcc}])
643 Number number of UTF-16 code units in {string}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000644strwidth({expr}) Number display cell length of the String {expr}
645submatch({nr} [, {list}]) String or List
646 specific match in ":s" or substitute()
647substitute({expr}, {pat}, {sub}, {flags})
648 String all {pat} in {expr} replaced with {sub}
Bram Moolenaarc216a7a2022-12-05 13:50:55 +0000649swapfilelist() List swap files found in 'directory'
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000650swapinfo({fname}) Dict information about swap file {fname}
651swapname({buf}) String swap file of buffer {buf}
652synID({lnum}, {col}, {trans}) Number syntax ID at {lnum} and {col}
653synIDattr({synID}, {what} [, {mode}])
654 String attribute {what} of syntax ID {synID}
655synIDtrans({synID}) Number translated syntax ID of {synID}
656synconcealed({lnum}, {col}) List info about concealing
657synstack({lnum}, {col}) List stack of syntax IDs at {lnum} and {col}
658system({expr} [, {input}]) String output of shell command/filter {expr}
659systemlist({expr} [, {input}]) List output of shell command/filter {expr}
660tabpagebuflist([{arg}]) List list of buffer numbers in tab page
661tabpagenr([{arg}]) Number number of current or last tab page
662tabpagewinnr({tabarg} [, {arg}]) Number number of current window in tab page
663tagfiles() List tags files used
664taglist({expr} [, {filename}]) List list of tags matching {expr}
665tan({expr}) Float tangent of {expr}
666tanh({expr}) Float hyperbolic tangent of {expr}
667tempname() String name for a temporary file
668term_dumpdiff({filename}, {filename} [, {options}])
669 Number display difference between two dumps
670term_dumpload({filename} [, {options}])
671 Number displaying a screen dump
672term_dumpwrite({buf}, {filename} [, {options}])
673 none dump terminal window contents
674term_getaltscreen({buf}) Number get the alternate screen flag
675term_getansicolors({buf}) List get ANSI palette in GUI color mode
676term_getattr({attr}, {what}) Number get the value of attribute {what}
677term_getcursor({buf}) List get the cursor position of a terminal
678term_getjob({buf}) Job get the job associated with a terminal
679term_getline({buf}, {row}) String get a line of text from a terminal
680term_getscrolled({buf}) Number get the scroll count of a terminal
681term_getsize({buf}) List get the size of a terminal
682term_getstatus({buf}) String get the status of a terminal
683term_gettitle({buf}) String get the title of a terminal
684term_gettty({buf}, [{input}]) String get the tty name of a terminal
685term_list() List get the list of terminal buffers
686term_scrape({buf}, {row}) List get row of a terminal screen
687term_sendkeys({buf}, {keys}) none send keystrokes to a terminal
688term_setansicolors({buf}, {colors})
689 none set ANSI palette in GUI color mode
690term_setapi({buf}, {expr}) none set |terminal-api| function name prefix
691term_setkill({buf}, {how}) none set signal to stop job in terminal
692term_setrestore({buf}, {command}) none set command to restore terminal
693term_setsize({buf}, {rows}, {cols})
694 none set the size of a terminal
695term_start({cmd} [, {options}]) Number open a terminal window and run a job
696term_wait({buf} [, {time}]) Number wait for screen to be updated
697terminalprops() Dict properties of the terminal
698test_alloc_fail({id}, {countdown}, {repeat})
699 none make memory allocation fail
700test_autochdir() none enable 'autochdir' during startup
701test_feedinput({string}) none add key sequence to input buffer
702test_garbagecollect_now() none free memory right now for testing
703test_garbagecollect_soon() none free memory soon for testing
704test_getvalue({string}) any get value of an internal variable
Yegappan Lakshmanan06011e12022-01-30 12:37:29 +0000705test_gui_event({event}, {args}) bool generate a GUI event for testing
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000706test_ignore_error({expr}) none ignore a specific error
Christopher Plewright20b795e2022-12-20 20:01:58 +0000707test_mswin_event({event}, {args})
708 bool generate MS-Windows event for testing
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000709test_null_blob() Blob null value for testing
710test_null_channel() Channel null value for testing
711test_null_dict() Dict null value for testing
712test_null_function() Funcref null value for testing
713test_null_job() Job null value for testing
714test_null_list() List null value for testing
715test_null_partial() Funcref null value for testing
716test_null_string() String null value for testing
Yegappan Lakshmanan9cb865e2025-03-23 16:42:16 +0100717test_null_tuple() Tuple null value for testing
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000718test_option_not_set({name}) none reset flag indicating option was set
719test_override({expr}, {val}) none test with Vim internal overrides
720test_refcount({expr}) Number get the reference count of {expr}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000721test_setmouse({row}, {col}) none set the mouse position for testing
722test_settime({expr}) none set current time for testing
Doug Kearns9cd9e752024-04-07 17:42:17 +0200723test_srand_seed([{seed}]) none set seed for testing srand()
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000724test_unknown() any unknown value for testing
725test_void() any void value for testing
726timer_info([{id}]) List information about timers
727timer_pause({id}, {pause}) none pause or unpause a timer
728timer_start({time}, {callback} [, {options}])
729 Number create a timer
730timer_stop({timer}) none stop a timer
731timer_stopall() none stop all timers
732tolower({expr}) String the String {expr} switched to lowercase
733toupper({expr}) String the String {expr} switched to uppercase
734tr({src}, {fromstr}, {tostr}) String translate chars of {src} in {fromstr}
735 to chars in {tostr}
736trim({text} [, {mask} [, {dir}]])
737 String trim characters in {mask} from {text}
738trunc({expr}) Float truncate Float {expr}
Yegappan Lakshmanan9cb865e2025-03-23 16:42:16 +0100739tuple2list({tuple}) List turn {tuple} of items into a list
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000740type({expr}) Number type of value {expr}
741typename({expr}) String representation of the type of {expr}
742undofile({name}) String undo file name for {name}
Devin J. Pohly5fee1112023-04-23 20:26:59 -0500743undotree([{buf}]) List undo file tree for buffer {buf}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000744uniq({list} [, {func} [, {dict}]])
745 List remove adjacent duplicates from a list
Christian Brabandt67672ef2023-04-24 21:09:54 +0100746utf16idx({string}, {idx} [, {countcc} [, {charidx}]])
747 Number UTF-16 index of byte {idx} in {string}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000748values({dict}) List values in {dict}
zeertzjq825cf812023-08-17 22:55:25 +0200749virtcol({expr} [, {list} [, {winid}])
750 Number or List
LemonBoy0f7a3e12022-05-26 12:10:37 +0100751 screen column of cursor or mark
Bram Moolenaar5a6ec102022-05-27 21:58:00 +0100752virtcol2col({winid}, {lnum}, {col})
753 Number byte index of a character on screen
Doug Kearns9cd9e752024-04-07 17:42:17 +0200754visualmode([{expr}]) String last visual mode used
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000755wildmenumode() Number whether 'wildmenu' mode is active
756win_execute({id}, {command} [, {silent}])
757 String execute {command} in window {id}
758win_findbuf({bufnr}) List find windows containing {bufnr}
759win_getid([{win} [, {tab}]]) Number get window ID for {win} in {tab}
760win_gettype([{nr}]) String type of window {nr}
761win_gotoid({expr}) Number go to window with ID {expr}
762win_id2tabwin({expr}) List get tab and window nr from window ID
763win_id2win({expr}) Number get window nr from window ID
Daniel Steinbergee630312022-01-10 13:36:34 +0000764win_move_separator({nr}) Number move window vertical separator
765win_move_statusline({nr}) Number move window status line
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000766win_screenpos({nr}) List get screen position of window {nr}
767win_splitmove({nr}, {target} [, {options}])
768 Number move window {nr} to split of {target}
769winbufnr({nr}) Number buffer number of window {nr}
770wincol() Number window column of the cursor
771windowsversion() String MS-Windows OS version
772winheight({nr}) Number height of window {nr}
773winlayout([{tabnr}]) List layout of windows in tab {tabnr}
774winline() Number window line of the cursor
775winnr([{expr}]) Number number of current window
776winrestcmd() String returns command to restore window sizes
777winrestview({dict}) none restore view of current window
778winsaveview() Dict save view of current window
779winwidth({nr}) Number width of window {nr}
780wordcount() Dict get byte/char/word statistics
781writefile({object}, {fname} [, {flags}])
782 Number write |Blob| or |List| of lines to file
783xor({expr}, {expr}) Number bitwise XOR
784
785==============================================================================
7862. Details *builtin-function-details*
787
788Not all functions are here, some have been moved to a help file covering the
789specific functionality.
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200790Return type specifies the type for |Vim9-script|, see |vim9-types|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000791
792abs({expr}) *abs()*
793 Return the absolute value of {expr}. When {expr} evaluates to
794 a |Float| abs() returns a |Float|. When {expr} can be
795 converted to a |Number| abs() returns a |Number|. Otherwise
796 abs() gives an error message and returns -1.
797 Examples: >
798 echo abs(1.456)
799< 1.456 >
800 echo abs(-5.456)
801< 5.456 >
802 echo abs(-4)
803< 4
804
805 Can also be used as a |method|: >
806 Compute()->abs()
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200807<
808 Return type: |Number| or |Float| depending on {expr}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000809
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000810
811acos({expr}) *acos()*
812 Return the arc cosine of {expr} measured in radians, as a
813 |Float| in the range of [0, pi].
814 {expr} must evaluate to a |Float| or a |Number| in the range
Bram Moolenaar016188f2022-06-06 20:52:59 +0100815 [-1, 1]. Otherwise acos() returns "nan".
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000816 Examples: >
817 :echo acos(0)
818< 1.570796 >
819 :echo acos(-0.5)
820< 2.094395
821
822 Can also be used as a |method|: >
823 Compute()->acos()
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200824<
825 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000826
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000827
828add({object}, {expr}) *add()*
829 Append the item {expr} to |List| or |Blob| {object}. Returns
830 the resulting |List| or |Blob|. Examples: >
831 :let alist = add([1, 2, 3], item)
832 :call add(mylist, "woodstock")
833< Note that when {expr} is a |List| it is appended as a single
834 item. Use |extend()| to concatenate |Lists|.
835 When {object} is a |Blob| then {expr} must be a number.
836 Use |insert()| to add an item at another position.
Bram Moolenaar016188f2022-06-06 20:52:59 +0100837 Returns 1 if {object} is not a |List| or a |Blob|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000838
839 Can also be used as a |method|: >
840 mylist->add(val1)->add(val2)
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200841<
842 Return type: list<{type}> (depending on the given |List|) or
843 |Blob|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000844
845
846and({expr}, {expr}) *and()*
847 Bitwise AND on the two arguments. The arguments are converted
848 to a number. A List, Dict or Float argument causes an error.
LemonBoy0f7a3e12022-05-26 12:10:37 +0100849 Also see `or()` and `xor()`.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000850 Example: >
851 :let flag = and(bits, 0x80)
852< Can also be used as a |method|: >
853 :let flag = bits->and(0x80)
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200854<
855 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000856
857
858append({lnum}, {text}) *append()*
859 When {text} is a |List|: Append each item of the |List| as a
860 text line below line {lnum} in the current buffer.
861 Otherwise append {text} as one text line below line {lnum} in
862 the current buffer.
863 Any type of item is accepted and converted to a String.
864 {lnum} can be zero to insert a line before the first one.
865 {lnum} is used like with |getline()|.
866 Returns 1 for failure ({lnum} out of range or out of memory),
Bram Moolenaarcd9c8d42022-11-05 23:46:43 +0000867 0 for success. When {text} is an empty list zero is returned,
868 no matter the value of {lnum}.
869 In |Vim9| script an invalid argument or negative number
870 results in an error. Example: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000871 :let failed = append(line('$'), "# THE END")
872 :let failed = append(0, ["Chapter 1", "the beginning"])
873
874< Can also be used as a |method| after a List, the base is
875 passed as the second argument: >
876 mylist->append(lnum)
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200877<
878 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000879
880
881appendbufline({buf}, {lnum}, {text}) *appendbufline()*
882 Like |append()| but append the text in buffer {buf}.
883
884 This function works only for loaded buffers. First call
885 |bufload()| if needed.
886
887 For the use of {buf}, see |bufname()|.
888
Bram Moolenaar8b6256f2021-12-28 11:24:49 +0000889 {lnum} is the line number to append below. Note that using
890 |line()| would use the current buffer, not the one appending
891 to. Use "$" to append at the end of the buffer. Other string
892 values are not supported.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000893
894 On success 0 is returned, on failure 1 is returned.
895 In |Vim9| script an error is given for an invalid {lnum}.
896
897 If {buf} is not a valid buffer or {lnum} is not valid, an
898 error message is given. Example: >
899 :let failed = appendbufline(13, 0, "# THE START")
Bram Moolenaarcd9c8d42022-11-05 23:46:43 +0000900< However, when {text} is an empty list then no error is given
901 for an invalid {lnum}, since {lnum} isn't actually used.
902
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000903 Can also be used as a |method| after a List, the base is
904 passed as the second argument: >
905 mylist->appendbufline(buf, lnum)
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200906<
907 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000908
909
910argc([{winid}]) *argc()*
911 The result is the number of files in the argument list. See
912 |arglist|.
913 If {winid} is not supplied, the argument list of the current
914 window is used.
915 If {winid} is -1, the global argument list is used.
916 Otherwise {winid} specifies the window of which the argument
917 list is used: either the window number or the window ID.
918 Returns -1 if the {winid} argument is invalid.
919
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200920 Return type: |Number|
921
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000922 *argidx()*
923argidx() The result is the current index in the argument list. 0 is
924 the first file. argc() - 1 is the last one. See |arglist|.
925
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200926 Return type: |Number|
927
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000928 *arglistid()*
929arglistid([{winnr} [, {tabnr}]])
930 Return the argument list ID. This is a number which
931 identifies the argument list being used. Zero is used for the
932 global argument list. See |arglist|.
933 Returns -1 if the arguments are invalid.
934
935 Without arguments use the current window.
936 With {winnr} only use this window in the current tab page.
937 With {winnr} and {tabnr} use the window in the specified tab
938 page.
939 {winnr} can be the window number or the |window-ID|.
940
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200941 Return type: |Number|
942
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000943 *argv()*
944argv([{nr} [, {winid}]])
945 The result is the {nr}th file in the argument list. See
946 |arglist|. "argv(0)" is the first one. Example: >
947 :let i = 0
948 :while i < argc()
949 : let f = escape(fnameescape(argv(i)), '.')
Bram Moolenaarc51cf032022-02-26 12:25:45 +0000950 : exe 'amenu Arg.' .. f .. ' :e ' .. f .. '<CR>'
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000951 : let i = i + 1
952 :endwhile
953< Without the {nr} argument, or when {nr} is -1, a |List| with
954 the whole |arglist| is returned.
955
956 The {winid} argument specifies the window ID, see |argc()|.
957 For the Vim command line arguments see |v:argv|.
958
Bram Moolenaar016188f2022-06-06 20:52:59 +0100959 Returns an empty string if {nr}th argument is not present in
960 the argument list. Returns an empty List if the {winid}
961 argument is invalid.
962
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200963 Return type: |String|
964
965
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000966asin({expr}) *asin()*
967 Return the arc sine of {expr} measured in radians, as a |Float|
968 in the range of [-pi/2, pi/2].
969 {expr} must evaluate to a |Float| or a |Number| in the range
970 [-1, 1].
Bram Moolenaar016188f2022-06-06 20:52:59 +0100971 Returns "nan" if {expr} is outside the range [-1, 1]. Returns
972 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000973 Examples: >
974 :echo asin(0.8)
975< 0.927295 >
976 :echo asin(-0.5)
977< -0.523599
978
979 Can also be used as a |method|: >
980 Compute()->asin()
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200981<
982 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000983
984assert_ functions are documented here: |assert-functions-details|
985
986
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000987atan({expr}) *atan()*
988 Return the principal value of the arc tangent of {expr}, in
989 the range [-pi/2, +pi/2] radians, as a |Float|.
990 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar016188f2022-06-06 20:52:59 +0100991 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000992 Examples: >
993 :echo atan(100)
994< 1.560797 >
995 :echo atan(-4.01)
996< -1.326405
997
998 Can also be used as a |method|: >
999 Compute()->atan()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001000<
1001 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001002
1003
1004atan2({expr1}, {expr2}) *atan2()*
1005 Return the arc tangent of {expr1} / {expr2}, measured in
1006 radians, as a |Float| in the range [-pi, pi].
1007 {expr1} and {expr2} must evaluate to a |Float| or a |Number|.
Bram Moolenaar016188f2022-06-06 20:52:59 +01001008 Returns 0.0 if {expr1} or {expr2} is not a |Float| or a
1009 |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001010 Examples: >
1011 :echo atan2(-1, 1)
1012< -0.785398 >
1013 :echo atan2(1, -1)
1014< 2.356194
1015
1016 Can also be used as a |method|: >
1017 Compute()->atan2(1)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001018<
1019 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001020
Yegappan Lakshmanan1755a912022-05-19 10:31:47 +01001021
1022autocmd_add({acmds}) *autocmd_add()*
1023 Adds a List of autocmds and autocmd groups.
1024
1025 The {acmds} argument is a List where each item is a Dict with
1026 the following optional items:
1027 bufnr buffer number to add a buffer-local autocmd.
1028 If this item is specified, then the "pattern"
1029 item is ignored.
1030 cmd Ex command to execute for this autocmd event
1031 event autocmd event name. Refer to |autocmd-events|.
Yegappan Lakshmanane0ff3a72022-05-27 18:05:33 +01001032 This can be either a String with a single
1033 event name or a List of event names.
Yegappan Lakshmanan1755a912022-05-19 10:31:47 +01001034 group autocmd group name. Refer to |autocmd-groups|.
1035 If this group doesn't exist then it is
1036 created. If not specified or empty, then the
1037 default group is used.
Yegappan Lakshmanan971f6822022-05-24 11:40:11 +01001038 nested boolean flag, set to v:true to add a nested
1039 autocmd. Refer to |autocmd-nested|.
LemonBoy0f7a3e12022-05-26 12:10:37 +01001040 once boolean flag, set to v:true to add an autocmd
Yegappan Lakshmanan971f6822022-05-24 11:40:11 +01001041 which executes only once. Refer to
1042 |autocmd-once|.
Yegappan Lakshmanan1755a912022-05-19 10:31:47 +01001043 pattern autocmd pattern string. Refer to
1044 |autocmd-patterns|. If "bufnr" item is
Yegappan Lakshmanane0ff3a72022-05-27 18:05:33 +01001045 present, then this item is ignored. This can
1046 be a String with a single pattern or a List of
1047 patterns.
Yegappan Lakshmanan971f6822022-05-24 11:40:11 +01001048 replace boolean flag, set to v:true to remove all the
1049 commands associated with the specified autocmd
1050 event and group and add the {cmd}. This is
1051 useful to avoid adding the same command
LemonBoy0f7a3e12022-05-26 12:10:37 +01001052 multiple times for an autocmd event in a group.
Yegappan Lakshmanan1755a912022-05-19 10:31:47 +01001053
1054 Returns v:true on success and v:false on failure.
1055 Examples: >
1056 " Create a buffer-local autocmd for buffer 5
1057 let acmd = {}
1058 let acmd.group = 'MyGroup'
1059 let acmd.event = 'BufEnter'
1060 let acmd.bufnr = 5
1061 let acmd.cmd = 'call BufEnterFunc()'
1062 call autocmd_add([acmd])
Bram Moolenaarcd9c8d42022-11-05 23:46:43 +00001063<
Yegappan Lakshmanan1755a912022-05-19 10:31:47 +01001064 Can also be used as a |method|: >
1065 GetAutocmdList()->autocmd_add()
1066<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001067 Return type: |vim9-boolean|
1068
1069
Yegappan Lakshmanan1755a912022-05-19 10:31:47 +01001070autocmd_delete({acmds}) *autocmd_delete()*
1071 Deletes a List of autocmds and autocmd groups.
1072
1073 The {acmds} argument is a List where each item is a Dict with
1074 the following optional items:
1075 bufnr buffer number to delete a buffer-local autocmd.
1076 If this item is specified, then the "pattern"
1077 item is ignored.
1078 cmd Ex command for this autocmd event
1079 event autocmd event name. Refer to |autocmd-events|.
1080 If '*' then all the autocmd events in this
1081 group are deleted.
1082 group autocmd group name. Refer to |autocmd-groups|.
1083 If not specified or empty, then the default
1084 group is used.
1085 nested set to v:true for a nested autocmd.
1086 Refer to |autocmd-nested|.
1087 once set to v:true for an autocmd which executes
1088 only once. Refer to |autocmd-once|.
1089 pattern autocmd pattern string. Refer to
1090 |autocmd-patterns|. If "bufnr" item is
1091 present, then this item is ignored.
1092
1093 If only {group} is specified in a {acmds} entry and {event},
1094 {pattern} and {cmd} are not specified, then that autocmd group
1095 is deleted.
1096
Bram Moolenaar016188f2022-06-06 20:52:59 +01001097 Returns |v:true| on success and |v:false| on failure.
Yegappan Lakshmanan1755a912022-05-19 10:31:47 +01001098 Examples: >
1099 " :autocmd! BufLeave *.vim
1100 let acmd = #{event: 'BufLeave', pattern: '*.vim'}
1101 call autocmd_delete([acmd]})
1102 " :autocmd! MyGroup1 BufLeave
1103 let acmd = #{group: 'MyGroup1', event: 'BufLeave'}
1104 call autocmd_delete([acmd])
1105 " :autocmd! MyGroup2 BufEnter *.c
1106 let acmd = #{group: 'MyGroup2', event: 'BufEnter',
1107 \ pattern: '*.c'}
1108 " :autocmd! MyGroup2 * *.c
1109 let acmd = #{group: 'MyGroup2', event: '*',
1110 \ pattern: '*.c'}
1111 call autocmd_delete([acmd])
1112 " :autocmd! MyGroup3
1113 let acmd = #{group: 'MyGroup3'}
1114 call autocmd_delete([acmd])
1115<
1116 Can also be used as a |method|: >
1117 GetAutocmdList()->autocmd_delete()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001118<
1119 Return type: |vim9-boolean|
1120
Yegappan Lakshmanan1755a912022-05-19 10:31:47 +01001121
1122autocmd_get([{opts}]) *autocmd_get()*
1123 Returns a |List| of autocmds. If {opts} is not supplied, then
1124 returns the autocmds for all the events in all the groups.
1125
1126 The optional {opts} Dict argument supports the following
1127 items:
1128 group Autocmd group name. If specified, returns only
1129 the autocmds defined in this group. If the
1130 specified group doesn't exist, results in an
1131 error message. If set to an empty string,
1132 then the default autocmd group is used.
1133 event Autocmd event name. If specified, returns only
1134 the autocmds defined for this event. If set
1135 to "*", then returns autocmds for all the
1136 events. If the specified event doesn't exist,
1137 results in an error message.
1138 pattern Autocmd pattern. If specified, returns only
1139 the autocmds defined for this pattern.
1140 A combination of the above three times can be supplied in
1141 {opts}.
1142
1143 Each Dict in the returned List contains the following items:
1144 bufnr For buffer-local autocmds, buffer number where
1145 the autocmd is defined.
1146 cmd Command executed for this autocmd.
1147 event Autocmd event name.
1148 group Autocmd group name.
Yegappan Lakshmanan971f6822022-05-24 11:40:11 +01001149 nested Boolean flag, set to v:true for a nested
1150 autocmd. See |autocmd-nested|.
1151 once Boolean flag, set to v:true, if the autocmd
1152 will be executed only once. See |autocmd-once|.
Yegappan Lakshmanan1755a912022-05-19 10:31:47 +01001153 pattern Autocmd pattern. For a buffer-local
1154 autocmd, this will be of the form "<buffer=n>".
1155 If there are multiple commands for an autocmd event in a
1156 group, then separate items are returned for each command.
1157
Bram Moolenaar016188f2022-06-06 20:52:59 +01001158 Returns an empty List if an autocmd with the specified group
1159 or event or pattern is not found.
1160
Yegappan Lakshmanan1755a912022-05-19 10:31:47 +01001161 Examples: >
1162 " :autocmd MyGroup
1163 echo autocmd_get(#{group: 'Mygroup'})
1164 " :autocmd G BufUnload
1165 echo autocmd_get(#{group: 'G', event: 'BufUnload'})
1166 " :autocmd G * *.ts
1167 let acmd = #{group: 'G', event: '*', pattern: '*.ts'}
1168 echo autocmd_get(acmd)
1169 " :autocmd Syntax
1170 echo autocmd_get(#{event: 'Syntax'})
1171 " :autocmd G BufEnter *.ts
1172 let acmd = #{group: 'G', event: 'BufEnter',
1173 \ pattern: '*.ts'}
1174 echo autocmd_get(acmd)
1175<
1176 Can also be used as a |method|: >
1177 Getopts()->autocmd_get()
1178<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001179 Return type: list<dict<any>>
1180
1181
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001182balloon_gettext() *balloon_gettext()*
1183 Return the current text in the balloon. Only for the string,
Bram Moolenaar016188f2022-06-06 20:52:59 +01001184 not used for the List. Returns an empty string if balloon
1185 is not present.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001186
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001187 Return type: |String|
1188
1189
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001190balloon_show({expr}) *balloon_show()*
1191 Show {expr} inside the balloon. For the GUI {expr} is used as
1192 a string. For a terminal {expr} can be a list, which contains
1193 the lines of the balloon. If {expr} is not a list it will be
1194 split with |balloon_split()|.
1195 If {expr} is an empty string any existing balloon is removed.
1196
1197 Example: >
1198 func GetBalloonContent()
1199 " ... initiate getting the content
1200 return ''
1201 endfunc
1202 set balloonexpr=GetBalloonContent()
1203
1204 func BalloonCallback(result)
1205 call balloon_show(a:result)
1206 endfunc
1207< Can also be used as a |method|: >
1208 GetText()->balloon_show()
1209<
1210 The intended use is that fetching the content of the balloon
1211 is initiated from 'balloonexpr'. It will invoke an
1212 asynchronous method, in which a callback invokes
1213 balloon_show(). The 'balloonexpr' itself can return an
Bram Moolenaar069a7d52022-06-27 22:16:08 +01001214 empty string or a placeholder, e.g. "loading...".
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001215
Bram Moolenaar069a7d52022-06-27 22:16:08 +01001216 When showing a balloon is not possible then nothing happens,
1217 no error message is given.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001218 {only available when compiled with the |+balloon_eval| or
1219 |+balloon_eval_term| feature}
1220
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001221 Return type: |Number|
1222
1223
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001224balloon_split({msg}) *balloon_split()*
1225 Split String {msg} into lines to be displayed in a balloon.
1226 The splits are made for the current window size and optimize
1227 to show debugger output.
Bram Moolenaar016188f2022-06-06 20:52:59 +01001228 Returns a |List| with the split lines. Returns an empty List
1229 on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001230 Can also be used as a |method|: >
1231 GetText()->balloon_split()->balloon_show()
1232
1233< {only available when compiled with the |+balloon_eval_term|
1234 feature}
1235
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001236 Return type: list<any> or list<string>
1237
h-easte80f3452025-01-02 10:40:29 +01001238base64_decode({string}) *base64_decode()*
1239 Return a Blob containing the bytes decoded from the base64
1240 encoded characters in {string}.
1241
1242 The {string} argument should contain only base64-encoded
1243 characters and should have a length that is a multiple of 4.
1244
1245 Returns an empty blob on error.
1246
1247 Examples: >
1248 " Write the decoded contents to a binary file
1249 call writefile(base64_decode(s), 'tools.bmp')
1250 " Decode a base64-encoded string
Maxim Kim6472e582025-01-15 18:31:05 +01001251 echo blob2str(base64_decode(encodedstr))
h-easte80f3452025-01-02 10:40:29 +01001252<
1253 Can also be used as a |method|: >
1254 GetEncodedString()->base64_decode()
1255<
1256 Return type: |Blob|
1257
1258
1259base64_encode({blob}) *base64_encode()*
1260 Return a base64-encoded String representing the bytes in
1261 {blob}. The base64 alphabet defined in RFC 4648 is used.
1262
1263 Examples: >
1264 " Encode the contents of a binary file
1265 echo base64_encode(readblob('somefile.bin'))
1266 " Encode a string
Yegappan Lakshmanana11b23c2025-01-16 19:16:42 +01001267 echo base64_encode(str2blob([somestr]))
h-easte80f3452025-01-02 10:40:29 +01001268<
1269 Can also be used as a |method|: >
1270 GetBinaryData()->base64_encode()
1271<
1272 Return type: |String|
1273
1274
Christ van Willegence0ef912024-06-20 23:41:59 +02001275bindtextdomain({package}, {path}) *bindtextdomain()*
1276 Bind a specific {package} to a {path} so that the
1277 |gettext()| function can be used to get language-specific
1278 translations for a package. {path} is the directory name
h-east52e7cc22024-07-28 17:03:29 +02001279 for the translations. See |package-translation|.
Christ van Willegence0ef912024-06-20 23:41:59 +02001280
Christ van Willegen8252ef12024-07-11 21:36:21 +02001281 Returns v:true on success and v:false on failure (out of
1282 memory).
1283
1284 Return type: |vim9-boolean|
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001285
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001286blob2list({blob}) *blob2list()*
1287 Return a List containing the number value of each byte in Blob
1288 {blob}. Examples: >
1289 blob2list(0z0102.0304) returns [1, 2, 3, 4]
1290 blob2list(0z) returns []
1291< Returns an empty List on error. |list2blob()| does the
1292 opposite.
1293
1294 Can also be used as a |method|: >
1295 GetBlob()->blob2list()
Bram Moolenaarb529cfb2022-07-25 15:42:07 +01001296<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001297 Return type: list<any> or list<number>
1298
Yegappan Lakshmanan1aefe1d2025-01-14 17:29:42 +01001299
1300blob2str({blob} [, {options}]) *blob2str()*
Yegappan Lakshmanana11b23c2025-01-16 19:16:42 +01001301 Return a List of Strings in the current 'encoding' by
1302 converting the bytes in {blob} into characters.
1303
1304 Each <NL> byte in the blob is interpreted as the end of a
1305 string and a new list item is added. Each <NUL> byte in the
1306 blob is converted into a <NL> character.
Yegappan Lakshmanan1aefe1d2025-01-14 17:29:42 +01001307
1308 If {options} is not supplied, the current 'encoding' value is
1309 used to decode the bytes in {blob}.
1310
1311 The argument {options} is a |Dict| and supports the following
1312 items:
1313 encoding Decode the bytes in {blob} using this
1314 encoding. The value is a |String|. See
Bakudankunb3854bf2025-02-23 20:29:21 +01001315 |encoding-names| for the supported values
1316 (plus the special value "none").
Christian Brabandtd5afc742025-03-18 20:55:42 +01001317 *E1515* *E1516*
Bakudankunb3854bf2025-02-23 20:29:21 +01001318 When current 'encoding' is "utf-8", an error is given and an
1319 empty List is returned if an invalid byte sequence is
1320 encountered in {blob}. To suppress this validation and get
1321 potentially invalid string, set "encoding" in {options} to
1322 "none".
Yegappan Lakshmanan1aefe1d2025-01-14 17:29:42 +01001323
Yegappan Lakshmanana11b23c2025-01-16 19:16:42 +01001324 Returns an empty List if blob is empty.
Yegappan Lakshmanan1aefe1d2025-01-14 17:29:42 +01001325
1326 See also |str2blob()|
1327
1328 Examples: >
Hirohito Higashi932a5352025-03-23 10:20:20 +01001329 blob2str(0z6162) returns ['ab']
1330 blob2str(0zC2ABC2BB) returns ['«»']
1331 blob2str(0z610A62) returns ['a', 'b']
1332 blob2str(0z610062) returns ['a\nb']
1333 blob2str(0zABBB, {'encoding': 'latin1'}) returns ['«»']
Yegappan Lakshmanan1aefe1d2025-01-14 17:29:42 +01001334<
1335 Can also be used as a |method|: >
1336 GetBlob()->blob2str()
1337<
Yegappan Lakshmanana11b23c2025-01-16 19:16:42 +01001338 Return type: list<string>
Yegappan Lakshmanan1aefe1d2025-01-14 17:29:42 +01001339
1340
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001341 *browse()*
1342browse({save}, {title}, {initdir}, {default})
1343 Put up a file requester. This only works when "has("browse")"
1344 returns |TRUE| (only in some GUI versions).
1345 The input fields are:
1346 {save} when |TRUE|, select file to write
1347 {title} title for the requester
1348 {initdir} directory to start browsing in
1349 {default} default file name
1350 An empty string is returned when the "Cancel" button is hit,
1351 something went wrong, or browsing is not possible.
1352
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001353 Return type: |String|
1354
1355
1356browsedir({title}, {initdir}) *browsedir()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001357 Put up a directory requester. This only works when
1358 "has("browse")" returns |TRUE| (only in some GUI versions).
1359 On systems where a directory browser is not supported a file
1360 browser is used. In that case: select a file in the directory
1361 to be used.
1362 The input fields are:
1363 {title} title for the requester
1364 {initdir} directory to start browsing in
1365 When the "Cancel" button is hit, something went wrong, or
1366 browsing is not possible, an empty string is returned.
1367
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001368 Return type: |String|
1369
1370
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001371bufadd({name}) *bufadd()*
Bram Moolenaar2eddbac2022-08-25 12:45:21 +01001372 Add a buffer to the buffer list with name {name} (must be a
1373 String).
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001374 If a buffer for file {name} already exists, return that buffer
1375 number. Otherwise return the buffer number of the newly
1376 created buffer. When {name} is an empty string then a new
1377 buffer is always created.
1378 The buffer will not have 'buflisted' set and not be loaded
1379 yet. To add some text to the buffer use this: >
1380 let bufnr = bufadd('someName')
1381 call bufload(bufnr)
1382 call setbufline(bufnr, 1, ['some', 'text'])
Bram Moolenaar016188f2022-06-06 20:52:59 +01001383< Returns 0 on error.
1384 Can also be used as a |method|: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001385 let bufnr = 'somename'->bufadd()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001386<
1387 Return type: |Number|
1388
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001389
1390bufexists({buf}) *bufexists()*
1391 The result is a Number, which is |TRUE| if a buffer called
1392 {buf} exists.
1393 If the {buf} argument is a number, buffer numbers are used.
1394 Number zero is the alternate buffer for the current window.
1395
1396 If the {buf} argument is a string it must match a buffer name
1397 exactly. The name can be:
1398 - Relative to the current directory.
1399 - A full path.
1400 - The name of a buffer with 'buftype' set to "nofile".
1401 - A URL name.
1402 Unlisted buffers will be found.
1403 Note that help files are listed by their short name in the
1404 output of |:buffers|, but bufexists() requires using their
1405 long name to be able to find them.
1406 bufexists() may report a buffer exists, but to use the name
1407 with a |:buffer| command you may need to use |expand()|. Esp
1408 for MS-Windows 8.3 names in the form "c:\DOCUME~1"
1409 Use "bufexists(0)" to test for the existence of an alternate
1410 file name.
1411
1412 Can also be used as a |method|: >
1413 let exists = 'somename'->bufexists()
1414<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001415 Return type: |Number|
1416
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001417 Obsolete name: buffer_exists(). *buffer_exists()*
1418
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001419
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001420buflisted({buf}) *buflisted()*
1421 The result is a Number, which is |TRUE| if a buffer called
1422 {buf} exists and is listed (has the 'buflisted' option set).
1423 The {buf} argument is used like with |bufexists()|.
1424
1425 Can also be used as a |method|: >
1426 let listed = 'somename'->buflisted()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001427<
1428 Return type: |Number|
1429
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001430
1431bufload({buf}) *bufload()*
1432 Ensure the buffer {buf} is loaded. When the buffer name
1433 refers to an existing file then the file is read. Otherwise
1434 the buffer will be empty. If the buffer was already loaded
Bram Moolenaar2eddbac2022-08-25 12:45:21 +01001435 then there is no change. If the buffer is not related to a
Daniel Steinbergc2bd2052023-08-09 12:10:59 -04001436 file then no file is read (e.g., when 'buftype' is "nofile").
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001437 If there is an existing swap file for the file of the buffer,
1438 there will be no dialog, the buffer will be loaded anyway.
1439 The {buf} argument is used like with |bufexists()|.
1440
1441 Can also be used as a |method|: >
1442 eval 'somename'->bufload()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001443<
1444 Return type: |Number|
1445
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001446
1447bufloaded({buf}) *bufloaded()*
1448 The result is a Number, which is |TRUE| if a buffer called
1449 {buf} exists and is loaded (shown in a window or hidden).
1450 The {buf} argument is used like with |bufexists()|.
1451
1452 Can also be used as a |method|: >
1453 let loaded = 'somename'->bufloaded()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001454<
1455 Return type: |Number|
1456
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001457
1458bufname([{buf}]) *bufname()*
1459 The result is the name of a buffer. Mostly as it is displayed
1460 by the `:ls` command, but not using special names such as
1461 "[No Name]".
1462 If {buf} is omitted the current buffer is used.
1463 If {buf} is a Number, that buffer number's name is given.
1464 Number zero is the alternate buffer for the current window.
1465 If {buf} is a String, it is used as a |file-pattern| to match
1466 with the buffer names. This is always done like 'magic' is
1467 set and 'cpoptions' is empty. When there is more than one
1468 match an empty string is returned.
1469 "" or "%" can be used for the current buffer, "#" for the
1470 alternate buffer.
1471 A full match is preferred, otherwise a match at the start, end
1472 or middle of the buffer name is accepted. If you only want a
1473 full match then put "^" at the start and "$" at the end of the
1474 pattern.
1475 Listed buffers are found first. If there is a single match
1476 with a listed buffer, that one is returned. Next unlisted
1477 buffers are searched for.
1478 If the {buf} is a String, but you want to use it as a buffer
1479 number, force it to be a Number by adding zero to it: >
1480 :echo bufname("3" + 0)
1481< Can also be used as a |method|: >
1482 echo bufnr->bufname()
1483
1484< If the buffer doesn't exist, or doesn't have a name, an empty
1485 string is returned. >
1486 bufname("#") alternate buffer name
1487 bufname(3) name of buffer 3
1488 bufname("%") name of current buffer
1489 bufname("file2") name of buffer where "file2" matches.
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001490<
1491 Return type: |String|
1492 *buffer_name()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001493 Obsolete name: buffer_name().
1494
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001495
1496bufnr([{buf} [, {create}]]) *bufnr()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001497 The result is the number of a buffer, as it is displayed by
1498 the `:ls` command. For the use of {buf}, see |bufname()|
1499 above.
1500
1501 If the buffer doesn't exist, -1 is returned. Or, if the
1502 {create} argument is present and TRUE, a new, unlisted,
1503 buffer is created and its number is returned. Example: >
1504 let newbuf = bufnr('Scratch001', 1)
1505< Using an empty name uses the current buffer. To create a new
1506 buffer with an empty name use |bufadd()|.
1507
1508 bufnr("$") is the last buffer: >
1509 :let last_buffer = bufnr("$")
1510< The result is a Number, which is the highest buffer number
1511 of existing buffers. Note that not all buffers with a smaller
1512 number necessarily exist, because ":bwipeout" may have removed
1513 them. Use bufexists() to test for the existence of a buffer.
1514
1515 Can also be used as a |method|: >
1516 echo bufref->bufnr()
1517<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001518 Return type: |Number|
1519
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001520 Obsolete name: buffer_number(). *buffer_number()*
1521 *last_buffer_nr()*
1522 Obsolete name for bufnr("$"): last_buffer_nr().
1523
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001524
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001525bufwinid({buf}) *bufwinid()*
1526 The result is a Number, which is the |window-ID| of the first
1527 window associated with buffer {buf}. For the use of {buf},
1528 see |bufname()| above. If buffer {buf} doesn't exist or
1529 there is no such window, -1 is returned. Example: >
1530
Bram Moolenaarc51cf032022-02-26 12:25:45 +00001531 echo "A window containing buffer 1 is " .. (bufwinid(1))
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001532<
Bram Moolenaar76db9e02022-11-09 21:21:04 +00001533 Only deals with the current tab page. See |win_findbuf()| for
1534 finding more.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001535
1536 Can also be used as a |method|: >
1537 FindBuffer()->bufwinid()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001538<
1539 Return type: |Number|
1540
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001541
1542bufwinnr({buf}) *bufwinnr()*
1543 Like |bufwinid()| but return the window number instead of the
1544 |window-ID|.
1545 If buffer {buf} doesn't exist or there is no such window, -1
1546 is returned. Example: >
1547
Bram Moolenaarc51cf032022-02-26 12:25:45 +00001548 echo "A window containing buffer 1 is " .. (bufwinnr(1))
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001549
1550< The number can be used with |CTRL-W_w| and ":wincmd w"
1551 |:wincmd|.
1552
1553 Can also be used as a |method|: >
1554 FindBuffer()->bufwinnr()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001555<
1556 Return type: |Number|
1557
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001558
1559byte2line({byte}) *byte2line()*
1560 Return the line number that contains the character at byte
1561 count {byte} in the current buffer. This includes the
1562 end-of-line character, depending on the 'fileformat' option
1563 for the current buffer. The first character has byte count
1564 one.
1565 Also see |line2byte()|, |go| and |:goto|.
1566
Bram Moolenaar016188f2022-06-06 20:52:59 +01001567 Returns -1 if the {byte} value is invalid.
1568
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001569 Can also be used as a |method|: >
1570 GetOffset()->byte2line()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001571<
1572 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001573
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001574 {not available when compiled without the |+byte_offset|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001575 feature}
1576
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001577
Christian Brabandt67672ef2023-04-24 21:09:54 +01001578byteidx({expr}, {nr} [, {utf16}]) *byteidx()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001579 Return byte index of the {nr}'th character in the String
1580 {expr}. Use zero for the first character, it then returns
1581 zero.
1582 If there are no multibyte characters the returned value is
1583 equal to {nr}.
1584 Composing characters are not counted separately, their byte
1585 length is added to the preceding base character. See
1586 |byteidxcomp()| below for counting composing characters
1587 separately.
Christian Brabandt67672ef2023-04-24 21:09:54 +01001588 When {utf16} is present and TRUE, {nr} is used as the UTF-16
1589 index in the String {expr} instead of as the character index.
1590 The UTF-16 index is the index in the string when it is encoded
1591 with 16-bit words. If the specified UTF-16 index is in the
1592 middle of a character (e.g. in a 4-byte character), then the
1593 byte index of the first byte in the character is returned.
1594 Refer to |string-offset-encoding| for more information.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001595 Example : >
1596 echo matchstr(str, ".", byteidx(str, 3))
1597< will display the fourth character. Another way to do the
1598 same: >
1599 let s = strpart(str, byteidx(str, 3))
1600 echo strpart(s, 0, byteidx(s, 1))
1601< Also see |strgetchar()| and |strcharpart()|.
1602
1603 If there are less than {nr} characters -1 is returned.
1604 If there are exactly {nr} characters the length of the string
1605 in bytes is returned.
Christian Brabandt67672ef2023-04-24 21:09:54 +01001606 See |charidx()| and |utf16idx()| for getting the character and
1607 UTF-16 index respectively from the byte index.
1608 Examples: >
1609 echo byteidx('a😊😊', 2) returns 5
1610 echo byteidx('a😊😊', 2, 1) returns 1
1611 echo byteidx('a😊😊', 3, 1) returns 5
1612<
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001613 Can also be used as a |method|: >
1614 GetName()->byteidx(idx)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001615<
1616 Return type: |Number|
1617
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001618
Christian Brabandt67672ef2023-04-24 21:09:54 +01001619byteidxcomp({expr}, {nr} [, {utf16}]) *byteidxcomp()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001620 Like byteidx(), except that a composing character is counted
1621 as a separate character. Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00001622 let s = 'e' .. nr2char(0x301)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001623 echo byteidx(s, 1)
1624 echo byteidxcomp(s, 1)
1625 echo byteidxcomp(s, 2)
1626< The first and third echo result in 3 ('e' plus composing
1627 character is 3 bytes), the second echo results in 1 ('e' is
1628 one byte).
1629 Only works differently from byteidx() when 'encoding' is set
1630 to a Unicode encoding.
1631
1632 Can also be used as a |method|: >
1633 GetName()->byteidxcomp(idx)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001634<
1635 Return type: |Number|
1636
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001637
1638call({func}, {arglist} [, {dict}]) *call()* *E699*
1639 Call function {func} with the items in |List| {arglist} as
1640 arguments.
1641 {func} can either be a |Funcref| or the name of a function.
1642 a:firstline and a:lastline are set to the cursor line.
1643 Returns the return value of the called function.
1644 {dict} is for functions with the "dict" attribute. It will be
1645 used to set the local variable "self". |Dictionary-function|
1646
1647 Can also be used as a |method|: >
1648 GetFunc()->call([arg, arg], dict)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001649<
1650 Return type: any, depending on {func}
1651
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001652
1653ceil({expr}) *ceil()*
1654 Return the smallest integral value greater than or equal to
1655 {expr} as a |Float| (round up).
1656 {expr} must evaluate to a |Float| or a |Number|.
1657 Examples: >
1658 echo ceil(1.456)
1659< 2.0 >
1660 echo ceil(-5.456)
1661< -5.0 >
1662 echo ceil(4.0)
1663< 4.0
1664
Bram Moolenaar016188f2022-06-06 20:52:59 +01001665 Returns 0.0 if {expr} is not a |Float| or a |Number|.
1666
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001667 Can also be used as a |method|: >
1668 Compute()->ceil()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001669<
1670 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001671
1672
1673ch_ functions are documented here: |channel-functions-details|
1674
1675
1676changenr() *changenr()*
1677 Return the number of the most recent change. This is the same
1678 number as what is displayed with |:undolist| and can be used
1679 with the |:undo| command.
1680 When a change was made it is the number of that change. After
1681 redo it is the number of the redone change. After undo it is
1682 one less than the number of the undone change.
Bram Moolenaar016188f2022-06-06 20:52:59 +01001683 Returns 0 if the undo list is empty.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001684
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001685 Return type: |Number|
1686
1687
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001688char2nr({string} [, {utf8}]) *char2nr()*
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01001689 Return Number value of the first char in {string}.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001690 Examples: >
1691 char2nr(" ") returns 32
1692 char2nr("ABC") returns 65
1693< When {utf8} is omitted or zero, the current 'encoding' is used.
1694 Example for "utf-8": >
1695 char2nr("á") returns 225
1696 char2nr("á"[0]) returns 195
1697< When {utf8} is TRUE, always treat as UTF-8 characters.
1698 A combining character is a separate character.
1699 |nr2char()| does the opposite.
1700 To turn a string into a list of character numbers: >
1701 let str = "ABC"
1702 let list = map(split(str, '\zs'), {_, val -> char2nr(val)})
1703< Result: [65, 66, 67]
1704
Bram Moolenaar016188f2022-06-06 20:52:59 +01001705 Returns 0 if {string} is not a |String|.
1706
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001707 Can also be used as a |method|: >
1708 GetChar()->char2nr()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001709<
1710 Return type: |Number|
1711
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001712
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001713charclass({string}) *charclass()*
1714 Return the character class of the first character in {string}.
1715 The character class is one of:
1716 0 blank
1717 1 punctuation
Christian Brabandtb5e7da12024-11-01 09:33:00 +01001718 2 word character (depends on 'iskeyword')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001719 3 emoji
1720 other specific Unicode class
1721 The class is used in patterns and word motions.
Bram Moolenaar016188f2022-06-06 20:52:59 +01001722 Returns 0 if {string} is not a |String|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001723
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001724 Return type: |Number|
1725
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001726
Yegappan Lakshmanan4c8d2f02022-11-12 16:07:47 +00001727charcol({expr} [, {winid}]) *charcol()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001728 Same as |col()| but returns the character index of the column
1729 position given with {expr} instead of the byte position.
1730
1731 Example:
1732 With the cursor on '세' in line 5 with text "여보세요": >
1733 charcol('.') returns 3
1734 col('.') returns 7
1735
1736< Can also be used as a |method|: >
1737 GetPos()->col()
1738<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001739 Return type: |Number|
1740
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001741 *charidx()*
Christian Brabandt67672ef2023-04-24 21:09:54 +01001742charidx({string}, {idx} [, {countcc} [, {utf16}]])
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001743 Return the character index of the byte at {idx} in {string}.
1744 The index of the first character is zero.
1745 If there are no multibyte characters the returned value is
1746 equal to {idx}.
Christian Brabandt67672ef2023-04-24 21:09:54 +01001747
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001748 When {countcc} is omitted or |FALSE|, then composing characters
Christian Brabandt67672ef2023-04-24 21:09:54 +01001749 are not counted separately, their byte length is added to the
1750 preceding base character.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001751 When {countcc} is |TRUE|, then composing characters are
1752 counted as separate characters.
Christian Brabandt67672ef2023-04-24 21:09:54 +01001753
1754 When {utf16} is present and TRUE, {idx} is used as the UTF-16
1755 index in the String {expr} instead of as the byte index.
1756
Yegappan Lakshmanan577922b2023-06-08 17:09:45 +01001757 Returns -1 if the arguments are invalid or if there are less
1758 than {idx} bytes. If there are exactly {idx} bytes the length
1759 of the string in characters is returned.
1760
1761 An error is given and -1 is returned if the first argument is
1762 not a string, the second argument is not a number or when the
1763 third argument is present and is not zero or one.
Christian Brabandt67672ef2023-04-24 21:09:54 +01001764
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001765 See |byteidx()| and |byteidxcomp()| for getting the byte index
Christian Brabandt67672ef2023-04-24 21:09:54 +01001766 from the character index and |utf16idx()| for getting the
1767 UTF-16 index from the character index.
1768 Refer to |string-offset-encoding| for more information.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001769 Examples: >
1770 echo charidx('áb́ć', 3) returns 1
1771 echo charidx('áb́ć', 6, 1) returns 4
1772 echo charidx('áb́ć', 16) returns -1
Christian Brabandt67672ef2023-04-24 21:09:54 +01001773 echo charidx('a😊😊', 4, 0, 1) returns 2
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001774<
1775 Can also be used as a |method|: >
1776 GetName()->charidx(idx)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001777<
1778 Return type: |Number|
1779
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001780
1781chdir({dir}) *chdir()*
1782 Change the current working directory to {dir}. The scope of
1783 the directory change depends on the directory of the current
1784 window:
1785 - If the current window has a window-local directory
1786 (|:lcd|), then changes the window local directory.
1787 - Otherwise, if the current tabpage has a local
1788 directory (|:tcd|) then changes the tabpage local
1789 directory.
1790 - Otherwise, changes the global directory.
1791 {dir} must be a String.
1792 If successful, returns the previous working directory. Pass
1793 this to another chdir() to restore the directory.
1794 On failure, returns an empty string.
1795
1796 Example: >
1797 let save_dir = chdir(newdir)
1798 if save_dir != ""
1799 " ... do some work
1800 call chdir(save_dir)
1801 endif
1802
1803< Can also be used as a |method|: >
1804 GetDir()->chdir()
1805<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001806 Return type: |String|
1807
1808
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001809cindent({lnum}) *cindent()*
1810 Get the amount of indent for line {lnum} according the C
1811 indenting rules, as with 'cindent'.
1812 The indent is counted in spaces, the value of 'tabstop' is
1813 relevant. {lnum} is used just like in |getline()|.
Bram Moolenaar8e145b82022-05-21 20:17:31 +01001814 When {lnum} is invalid -1 is returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001815 See |C-indenting|.
1816
1817 Can also be used as a |method|: >
1818 GetLnum()->cindent()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001819<
1820 Return type: |Number|
1821
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001822
1823clearmatches([{win}]) *clearmatches()*
1824 Clears all matches previously defined for the current window
1825 by |matchadd()| and the |:match| commands.
1826 If {win} is specified, use the window with this number or
1827 window ID instead of the current window.
1828
1829 Can also be used as a |method|: >
1830 GetWin()->clearmatches()
1831<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001832 Return type: |Number|
1833
1834
Bram Moolenaar10e8ff92023-06-10 21:40:39 +01001835col({expr} [, {winid}]) *col()*
Yegappan Lakshmanan4c8d2f02022-11-12 16:07:47 +00001836 The result is a Number, which is the byte index of the column
zeertzjq02f3eba2024-06-12 20:45:24 +02001837 position given with {expr}.
1838 For accepted positions see |getpos()|.
zeertzjqd353d272024-06-13 23:00:25 +08001839 When {expr} is "$", it means the end of the cursor line, so
1840 the result is the number of bytes in the cursor line plus one.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001841 Additionally {expr} can be [lnum, col]: a |List| with the line
1842 and column number. Most useful when the column is "$", to get
1843 the last column of a specific line. When "lnum" or "col" is
1844 out of range then col() returns zero.
zeertzjq02f3eba2024-06-12 20:45:24 +02001845
Yegappan Lakshmanan4c8d2f02022-11-12 16:07:47 +00001846 With the optional {winid} argument the values are obtained for
1847 that window instead of the current window.
zeertzjq02f3eba2024-06-12 20:45:24 +02001848
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001849 To get the line number use |line()|. To get both use
1850 |getpos()|.
1851 For the screen column position use |virtcol()|. For the
1852 character position use |charcol()|.
zeertzjq02f3eba2024-06-12 20:45:24 +02001853
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001854 Note that only marks in the current file can be used.
zeertzjq02f3eba2024-06-12 20:45:24 +02001855
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001856 Examples: >
1857 col(".") column of cursor
1858 col("$") length of cursor line plus one
1859 col("'t") column of mark t
Bram Moolenaarc51cf032022-02-26 12:25:45 +00001860 col("'" .. markname) column of mark markname
zeertzjq02f3eba2024-06-12 20:45:24 +02001861<
1862 The first column is 1. Returns 0 if {expr} is invalid or when
Yegappan Lakshmanan4c8d2f02022-11-12 16:07:47 +00001863 the window with ID {winid} is not found.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001864 For an uppercase mark the column may actually be in another
1865 buffer.
1866 For the cursor position, when 'virtualedit' is active, the
1867 column is one higher if the cursor is after the end of the
Bram Moolenaar6ebe4f92022-10-28 20:47:54 +01001868 line. Also, when using a <Cmd> mapping the cursor isn't
1869 moved, this can be used to obtain the column in Insert mode: >
Bram Moolenaar76db9e02022-11-09 21:21:04 +00001870 :imap <F2> <Cmd>echowin col(".")<CR>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001871
1872< Can also be used as a |method|: >
1873 GetPos()->col()
1874<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001875 Return type: |Number|
1876
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001877
1878complete({startcol}, {matches}) *complete()* *E785*
1879 Set the matches for Insert mode completion.
1880 Can only be used in Insert mode. You need to use a mapping
1881 with CTRL-R = (see |i_CTRL-R|). It does not work after CTRL-O
1882 or with an expression mapping.
1883 {startcol} is the byte offset in the line where the completed
1884 text start. The text up to the cursor is the original text
1885 that will be replaced by the matches. Use col('.') for an
1886 empty string. "col('.') - 1" will replace one character by a
1887 match.
1888 {matches} must be a |List|. Each |List| item is one match.
1889 See |complete-items| for the kind of items that are possible.
1890 "longest" in 'completeopt' is ignored.
1891 Note that the after calling this function you need to avoid
1892 inserting anything that would cause completion to stop.
1893 The match can be selected with CTRL-N and CTRL-P as usual with
1894 Insert mode completion. The popup menu will appear if
1895 specified, see |ins-completion-menu|.
1896 Example: >
1897 inoremap <F5> <C-R>=ListMonths()<CR>
1898
Bram Moolenaar10e8ff92023-06-10 21:40:39 +01001899 func ListMonths()
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001900 call complete(col('.'), ['January', 'February', 'March',
1901 \ 'April', 'May', 'June', 'July', 'August', 'September',
1902 \ 'October', 'November', 'December'])
1903 return ''
1904 endfunc
1905< This isn't very useful, but it shows how it works. Note that
1906 an empty string is returned to avoid a zero being inserted.
1907
1908 Can also be used as a |method|, the base is passed as the
1909 second argument: >
1910 GetMatches()->complete(col('.'))
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001911<
1912 Return type: |Number|
1913
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001914
1915complete_add({expr}) *complete_add()*
1916 Add {expr} to the list of matches. Only to be used by the
1917 function specified with the 'completefunc' option.
1918 Returns 0 for failure (empty string or out of memory),
1919 1 when the match was added, 2 when the match was already in
1920 the list.
1921 See |complete-functions| for an explanation of {expr}. It is
1922 the same as one item in the list that 'omnifunc' would return.
1923
1924 Can also be used as a |method|: >
1925 GetMoreMatches()->complete_add()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001926<
1927 Return type: |Number|
1928
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001929
1930complete_check() *complete_check()*
1931 Check for a key typed while looking for completion matches.
1932 This is to be used when looking for matches takes some time.
1933 Returns |TRUE| when searching for matches is to be aborted,
1934 zero otherwise.
1935 Only to be used by the function specified with the
1936 'completefunc' option.
1937
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001938 Return type: |Number|
1939
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001940
1941complete_info([{what}]) *complete_info()*
1942 Returns a |Dictionary| with information about Insert mode
1943 completion. See |ins-completion|.
1944 The items are:
1945 mode Current completion mode name string.
1946 See |complete_info_mode| for the values.
1947 pum_visible |TRUE| if popup menu is visible.
1948 See |pumvisible()|.
glepnird4088ed2024-12-31 10:55:22 +01001949 items List of all completion candidates. Each item
1950 is a dictionary containing the entries "word",
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001951 "abbr", "menu", "kind", "info" and "user_data".
1952 See |complete-items|.
glepnird4088ed2024-12-31 10:55:22 +01001953 matches Same as "items", but only returns items that
1954 are matching current query. If both "matches"
1955 and "items" are in "what", the returned list
1956 will still be named "items", but each item
1957 will have an additional "match" field.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001958 selected Selected item index. First index is zero.
1959 Index is -1 if no item is selected (showing
1960 typed text only, or the last completion after
1961 no item is selected when using the <Up> or
1962 <Down> keys)
glepnir037b0282025-01-16 14:37:44 +01001963 completed Return a dictionary containing the entries of
1964 the currently selected index item.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001965
1966 *complete_info_mode*
1967 mode values are:
1968 "" Not in completion mode
1969 "keyword" Keyword completion |i_CTRL-X_CTRL-N|
1970 "ctrl_x" Just pressed CTRL-X |i_CTRL-X|
1971 "scroll" Scrolling with |i_CTRL-X_CTRL-E| or
1972 |i_CTRL-X_CTRL-Y|
1973 "whole_line" Whole lines |i_CTRL-X_CTRL-L|
1974 "files" File names |i_CTRL-X_CTRL-F|
1975 "tags" Tags |i_CTRL-X_CTRL-]|
1976 "path_defines" Definition completion |i_CTRL-X_CTRL-D|
1977 "path_patterns" Include completion |i_CTRL-X_CTRL-I|
1978 "dictionary" Dictionary |i_CTRL-X_CTRL-K|
1979 "thesaurus" Thesaurus |i_CTRL-X_CTRL-T|
1980 "cmdline" Vim Command line |i_CTRL-X_CTRL-V|
1981 "function" User defined completion |i_CTRL-X_CTRL-U|
1982 "omni" Omni completion |i_CTRL-X_CTRL-O|
1983 "spell" Spelling suggestions |i_CTRL-X_s|
1984 "eval" |complete()| completion
1985 "unknown" Other internal modes
1986
1987 If the optional {what} list argument is supplied, then only
1988 the items listed in {what} are returned. Unsupported items in
1989 {what} are silently ignored.
1990
1991 To get the position and size of the popup menu, see
1992 |pum_getpos()|. It's also available in |v:event| during the
1993 |CompleteChanged| event.
1994
Bram Moolenaar016188f2022-06-06 20:52:59 +01001995 Returns an empty |Dictionary| on error.
1996
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001997 Examples: >
1998 " Get all items
1999 call complete_info()
2000 " Get only 'mode'
2001 call complete_info(['mode'])
2002 " Get only 'mode' and 'pum_visible'
2003 call complete_info(['mode', 'pum_visible'])
2004
2005< Can also be used as a |method|: >
2006 GetItems()->complete_info()
2007<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002008 Return type: dict<any>
2009
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002010 *confirm()*
2011confirm({msg} [, {choices} [, {default} [, {type}]]])
2012 confirm() offers the user a dialog, from which a choice can be
2013 made. It returns the number of the choice. For the first
2014 choice this is 1.
2015 Note: confirm() is only supported when compiled with dialog
glepnirdf461152024-04-04 22:23:29 +02002016 support, see |+dialog_con| |+dialog_con_gui| and |+dialog_gui|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002017
2018 {msg} is displayed in a |dialog| with {choices} as the
2019 alternatives. When {choices} is missing or empty, "&OK" is
2020 used (and translated).
2021 {msg} is a String, use '\n' to include a newline. Only on
2022 some systems the string is wrapped when it doesn't fit.
2023
2024 {choices} is a String, with the individual choices separated
2025 by '\n', e.g. >
2026 confirm("Save changes?", "&Yes\n&No\n&Cancel")
2027< The letter after the '&' is the shortcut key for that choice.
2028 Thus you can type 'c' to select "Cancel". The shortcut does
2029 not need to be the first letter: >
2030 confirm("file has been modified", "&Save\nSave &All")
2031< For the console, the first letter of each choice is used as
2032 the default shortcut key. Case is ignored.
2033
2034 The optional {default} argument is the number of the choice
2035 that is made if the user hits <CR>. Use 1 to make the first
2036 choice the default one. Use 0 to not set a default. If
2037 {default} is omitted, 1 is used.
2038
2039 The optional {type} String argument gives the type of dialog.
2040 This is only used for the icon of the GTK, Mac, Motif and
2041 Win32 GUI. It can be one of these values: "Error",
2042 "Question", "Info", "Warning" or "Generic". Only the first
2043 character is relevant. When {type} is omitted, "Generic" is
2044 used.
2045
2046 If the user aborts the dialog by pressing <Esc>, CTRL-C,
2047 or another valid interrupt key, confirm() returns 0.
2048
2049 An example: >
Bram Moolenaar46eea442022-03-30 10:51:39 +01002050 let choice = confirm("What do you want?",
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01002051 \ "&Apples\n&Oranges\n&Bananas", 2)
Bram Moolenaar46eea442022-03-30 10:51:39 +01002052 if choice == 0
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01002053 echo "make up your mind!"
Bram Moolenaar46eea442022-03-30 10:51:39 +01002054 elseif choice == 3
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01002055 echo "tasteful"
Bram Moolenaar46eea442022-03-30 10:51:39 +01002056 else
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01002057 echo "I prefer bananas myself."
Bram Moolenaar46eea442022-03-30 10:51:39 +01002058 endif
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002059< In a GUI dialog, buttons are used. The layout of the buttons
2060 depends on the 'v' flag in 'guioptions'. If it is included,
2061 the buttons are always put vertically. Otherwise, confirm()
2062 tries to put the buttons in one horizontal line. If they
2063 don't fit, a vertical layout is used anyway. For some systems
2064 the horizontal layout is always used.
2065
2066 Can also be used as a |method|in: >
2067 BuildMessage()->confirm("&Yes\n&No")
2068<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002069 Return type: |Number|
2070
2071
2072copy({expr}) *copy()*
2073 Make a copy of {expr}. For Numbers and Strings this isn't
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002074 different from using {expr} directly.
2075 When {expr} is a |List| a shallow copy is created. This means
2076 that the original |List| can be changed without changing the
2077 copy, and vice versa. But the items are identical, thus
2078 changing an item changes the contents of both |Lists|.
Yegappan Lakshmanan9cb865e2025-03-23 16:42:16 +01002079 A |Tuple| or |Dictionary| is copied in a similar way as a
2080 |List|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002081 Also see |deepcopy()|.
2082 Can also be used as a |method|: >
2083 mylist->copy()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002084<
2085 Return type: any, depending on {expr}
2086
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002087
2088cos({expr}) *cos()*
2089 Return the cosine of {expr}, measured in radians, as a |Float|.
2090 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar016188f2022-06-06 20:52:59 +01002091 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002092 Examples: >
2093 :echo cos(100)
2094< 0.862319 >
2095 :echo cos(-4.01)
2096< -0.646043
2097
2098 Can also be used as a |method|: >
2099 Compute()->cos()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002100<
2101 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002102
2103
2104cosh({expr}) *cosh()*
2105 Return the hyperbolic cosine of {expr} as a |Float| in the range
2106 [1, inf].
2107 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar016188f2022-06-06 20:52:59 +01002108 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002109 Examples: >
2110 :echo cosh(0.5)
2111< 1.127626 >
2112 :echo cosh(-0.5)
2113< -1.127626
2114
2115 Can also be used as a |method|: >
2116 Compute()->cosh()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002117<
2118 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002119
2120
Yegappan Lakshmanancd39b692023-10-02 12:50:45 -07002121count({comp}, {expr} [, {ic} [, {start}]]) *count()* *E706*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002122 Return the number of times an item with value {expr} appears
Yegappan Lakshmanan9cb865e2025-03-23 16:42:16 +01002123 in |String|, |List|, |Tuple| or |Dictionary| {comp}.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002124
2125 If {start} is given then start with the item with this index.
Yegappan Lakshmanan9cb865e2025-03-23 16:42:16 +01002126 {start} can only be used with a |List| or a |Tuple|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002127
2128 When {ic} is given and it's |TRUE| then case is ignored.
2129
2130 When {comp} is a string then the number of not overlapping
2131 occurrences of {expr} is returned. Zero is returned when
2132 {expr} is an empty string.
2133
2134 Can also be used as a |method|: >
2135 mylist->count(val)
2136<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002137 Return type: |Number|
2138
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002139 *cscope_connection()*
2140cscope_connection([{num} , {dbpath} [, {prepend}]])
2141 Checks for the existence of a |cscope| connection. If no
2142 parameters are specified, then the function returns:
2143 0, if cscope was not available (not compiled in), or
2144 if there are no cscope connections;
2145 1, if there is at least one cscope connection.
2146
2147 If parameters are specified, then the value of {num}
2148 determines how existence of a cscope connection is checked:
2149
2150 {num} Description of existence check
2151 ----- ------------------------------
2152 0 Same as no parameters (e.g., "cscope_connection()").
2153 1 Ignore {prepend}, and use partial string matches for
2154 {dbpath}.
2155 2 Ignore {prepend}, and use exact string matches for
2156 {dbpath}.
2157 3 Use {prepend}, use partial string matches for both
2158 {dbpath} and {prepend}.
2159 4 Use {prepend}, use exact string matches for both
2160 {dbpath} and {prepend}.
2161
2162 Note: All string comparisons are case sensitive!
2163
2164 Examples. Suppose we had the following (from ":cs show"): >
2165
2166 # pid database name prepend path
2167 0 27664 cscope.out /usr/local
2168<
2169 Invocation Return Val ~
2170 ---------- ---------- >
2171 cscope_connection() 1
2172 cscope_connection(1, "out") 1
2173 cscope_connection(2, "out") 0
2174 cscope_connection(3, "out") 0
2175 cscope_connection(3, "out", "local") 1
2176 cscope_connection(4, "out") 0
2177 cscope_connection(4, "out", "local") 0
2178 cscope_connection(4, "cscope.out", "/usr/local") 1
2179<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002180 Return type: |Number|
2181
2182
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002183cursor({lnum}, {col} [, {off}]) *cursor()*
2184cursor({list})
2185 Positions the cursor at the column (byte count) {col} in the
2186 line {lnum}. The first column is one.
2187
2188 When there is one argument {list} this is used as a |List|
2189 with two, three or four item:
2190 [{lnum}, {col}]
2191 [{lnum}, {col}, {off}]
2192 [{lnum}, {col}, {off}, {curswant}]
2193 This is like the return value of |getpos()| or |getcurpos()|,
2194 but without the first item.
2195
Bram Moolenaar10e8ff92023-06-10 21:40:39 +01002196 To position the cursor using {col} as the character count, use
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002197 |setcursorcharpos()|.
2198
2199 Does not change the jumplist.
Bram Moolenaar7c6cd442022-10-11 21:54:04 +01002200 {lnum} is used like with |getline()|, except that if {lnum} is
2201 zero, the cursor will stay in the current line.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002202 If {lnum} is greater than the number of lines in the buffer,
2203 the cursor will be positioned at the last line in the buffer.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002204 If {col} is greater than the number of bytes in the line,
2205 the cursor will be positioned at the last character in the
2206 line.
2207 If {col} is zero, the cursor will stay in the current column.
2208 If {curswant} is given it is used to set the preferred column
2209 for vertical movement. Otherwise {col} is used.
2210
2211 When 'virtualedit' is used {off} specifies the offset in
2212 screen columns from the start of the character. E.g., a
2213 position within a <Tab> or after the last character.
2214 Returns 0 when the position could be set, -1 otherwise.
2215
2216 Can also be used as a |method|: >
2217 GetCursorPos()->cursor()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002218<
2219 Return type: |Number|
2220
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002221
2222debugbreak({pid}) *debugbreak()*
2223 Specifically used to interrupt a program being debugged. It
2224 will cause process {pid} to get a SIGTRAP. Behavior for other
2225 processes is undefined. See |terminal-debugger|.
2226 {only available on MS-Windows}
2227
Bram Moolenaar016188f2022-06-06 20:52:59 +01002228 Returns |TRUE| if successfully interrupted the program.
2229 Otherwise returns |FALSE|.
2230
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002231 Can also be used as a |method|: >
2232 GetPid()->debugbreak()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002233<
2234 Return type: |Number|
2235
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002236
2237deepcopy({expr} [, {noref}]) *deepcopy()* *E698*
2238 Make a copy of {expr}. For Numbers and Strings this isn't
2239 different from using {expr} directly.
2240 When {expr} is a |List| a full copy is created. This means
2241 that the original |List| can be changed without changing the
2242 copy, and vice versa. When an item is a |List| or
2243 |Dictionary|, a copy for it is made, recursively. Thus
2244 changing an item in the copy does not change the contents of
2245 the original |List|.
Yegappan Lakshmanan9cb865e2025-03-23 16:42:16 +01002246 A |Tuple| or |Dictionary| is copied in a similar way as a
2247 |List|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002248
2249 When {noref} is omitted or zero a contained |List| or
2250 |Dictionary| is only copied once. All references point to
2251 this single copy. With {noref} set to 1 every occurrence of a
2252 |List| or |Dictionary| results in a new copy. This also means
2253 that a cyclic reference causes deepcopy() to fail.
2254 *E724*
2255 Nesting is possible up to 100 levels. When there is an item
2256 that refers back to a higher level making a deep copy with
2257 {noref} set to 1 will fail.
2258 Also see |copy()|.
2259
2260 Can also be used as a |method|: >
2261 GetObject()->deepcopy()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002262<
2263 Return type: any, depending on {expr}
2264
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002265
2266delete({fname} [, {flags}]) *delete()*
2267 Without {flags} or with {flags} empty: Deletes the file by the
Bram Moolenaarcbaff5e2022-04-08 17:45:08 +01002268 name {fname}.
2269
2270 This also works when {fname} is a symbolic link. The symbolic
2271 link itself is deleted, not what it points to.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002272
2273 When {flags} is "d": Deletes the directory by the name
2274 {fname}. This fails when directory {fname} is not empty.
2275
2276 When {flags} is "rf": Deletes the directory by the name
2277 {fname} and everything in it, recursively. BE CAREFUL!
2278 Note: on MS-Windows it is not possible to delete a directory
2279 that is being used.
2280
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002281 The result is a Number, which is 0/false if the delete
2282 operation was successful and -1/true when the deletion failed
2283 or partly failed.
2284
2285 Use |remove()| to delete an item from a |List|.
2286 To delete a line from the buffer use |:delete| or
2287 |deletebufline()|.
2288
2289 Can also be used as a |method|: >
2290 GetName()->delete()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002291<
2292 Return type: |Number|
2293
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002294
2295deletebufline({buf}, {first} [, {last}]) *deletebufline()*
2296 Delete lines {first} to {last} (inclusive) from buffer {buf}.
2297 If {last} is omitted then delete line {first} only.
2298 On success 0 is returned, on failure 1 is returned.
2299
2300 This function works only for loaded buffers. First call
2301 |bufload()| if needed.
2302
2303 For the use of {buf}, see |bufname()| above.
2304
2305 {first} and {last} are used like with |getline()|. Note that
2306 when using |line()| this refers to the current buffer. Use "$"
2307 to refer to the last line in buffer {buf}.
2308
2309 Can also be used as a |method|: >
2310 GetBuffer()->deletebufline(1)
2311<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002312 Return type: |Number|
2313
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002314 *did_filetype()*
2315did_filetype() Returns |TRUE| when autocommands are being executed and the
2316 FileType event has been triggered at least once. Can be used
2317 to avoid triggering the FileType event again in the scripts
2318 that detect the file type. |FileType|
2319 Returns |FALSE| when `:setf FALLBACK` was used.
2320 When editing another file, the counter is reset, thus this
2321 really checks if the FileType event has been triggered for the
2322 current buffer. This allows an autocommand that starts
2323 editing another buffer to set 'filetype' and load a syntax
2324 file.
2325
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002326 Return type: |Number|
2327
2328
Yegappan Lakshmananfa378352024-02-01 22:05:27 +01002329diff({fromlist}, {tolist} [, {options}]) *diff()*
2330 Returns a String or a List containing the diff between the
2331 strings in {fromlist} and {tolist}. Uses the Vim internal
2332 diff library to compute the diff.
2333
2334 *E106*
2335 The optional "output" item in {options} specifies the returned
2336 diff format. The following values are supported:
2337 indices Return a List of the starting and ending
2338 indices and a count of the strings in each
2339 diff hunk.
2340 unified Return the unified diff output as a String.
2341 This is the default.
2342
2343 If the "output" item in {options} is "indices", then a List is
2344 returned. Each List item contains a Dict with the following
2345 items for each diff hunk:
2346 from_idx start index in {fromlist} for this diff hunk.
2347 from_count number of strings in {fromlist} that are
2348 added/removed/modified in this diff hunk.
2349 to_idx start index in {tolist} for this diff hunk.
2350 to_count number of strings in {tolist} that are
2351 added/removed/modified in this diff hunk.
2352
2353 The {options} Dict argument also specifies diff options
2354 (similar to 'diffopt') and supports the following items:
Yegappan Lakshmananbe156a32024-02-11 17:08:29 +01002355 algorithm Dict specifying the diff algorithm to
2356 use. Supported boolean items are
2357 "myers", "minimal", "patience" and
2358 "histogram".
Yegappan Lakshmanana0010a12024-02-12 20:21:26 +01002359 context diff context length. Default is 0.
Yegappan Lakshmananfa378352024-02-01 22:05:27 +01002360 iblank ignore changes where lines are all
2361 blank.
2362 icase ignore changes in case of text.
Yegappan Lakshmananbe156a32024-02-11 17:08:29 +01002363 indent-heuristic use the indent heuristic for the
2364 internal diff library.
Yegappan Lakshmananfa378352024-02-01 22:05:27 +01002365 iwhite ignore changes in amount of white
2366 space.
2367 iwhiteall ignore all white space changes.
2368 iwhiteeol ignore white space changes at end of
2369 line.
Yegappan Lakshmananfa378352024-02-01 22:05:27 +01002370 For more information about these options, refer to 'diffopt'.
2371
Yegappan Lakshmanana0010a12024-02-12 20:21:26 +01002372 To compute the unified diff, all the items in {fromlist} are
2373 concatenated into a string using a newline separator and the
2374 same for {tolist}. The unified diff output uses line numbers.
2375
Yegappan Lakshmananfa378352024-02-01 22:05:27 +01002376 Returns an empty List or String if {fromlist} and {tolist} are
2377 identical.
2378
Yegappan Lakshmanan1af35632024-02-06 11:03:36 +01002379 Examples: >
Yegappan Lakshmananfa378352024-02-01 22:05:27 +01002380 :echo diff(['abc'], ['xxx'])
2381 @@ -1 +1 @@
2382 -abc
2383 +xxx
2384
2385 :echo diff(['abc'], ['xxx'], {'output': 'indices'})
2386 [{'from_idx': 0, 'from_count': 1, 'to_idx': 0, 'to_count': 1}]
2387 :echo diff(readfile('oldfile'), readfile('newfile'))
2388 :echo diff(getbufline(5, 1, '$'), getbufline(6, 1, '$'))
Yegappan Lakshmanan1af35632024-02-06 11:03:36 +01002389<
Yegappan Lakshmananfa378352024-02-01 22:05:27 +01002390 For more examples, refer to |diff-func-examples|
2391
2392 Can also be used as a |method|: >
2393 GetFromList->diff(to_list)
2394<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002395 Return type: |String| or list<dict<number>> or list<any>
2396 depending on {options}
2397
2398
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002399diff_filler({lnum}) *diff_filler()*
2400 Returns the number of filler lines above line {lnum}.
2401 These are the lines that were inserted at this point in
2402 another diff'ed window. These filler lines are shown in the
2403 display but don't exist in the buffer.
2404 {lnum} is used like with |getline()|. Thus "." is the current
2405 line, "'m" mark m, etc.
2406 Returns 0 if the current window is not in diff mode.
2407
2408 Can also be used as a |method|: >
2409 GetLnum()->diff_filler()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002410<
2411 Return type: |Number|
2412
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002413
2414diff_hlID({lnum}, {col}) *diff_hlID()*
2415 Returns the highlight ID for diff mode at line {lnum} column
2416 {col} (byte index). When the current line does not have a
2417 diff change zero is returned.
2418 {lnum} is used like with |getline()|. Thus "." is the current
2419 line, "'m" mark m, etc.
2420 {col} is 1 for the leftmost column, {lnum} is 1 for the first
2421 line.
2422 The highlight ID can be used with |synIDattr()| to obtain
2423 syntax information about the highlighting.
2424
2425 Can also be used as a |method|: >
2426 GetLnum()->diff_hlID(col)
2427<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002428 Return type: |Number|
2429
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002430
2431digraph_get({chars}) *digraph_get()* *E1214*
2432 Return the digraph of {chars}. This should be a string with
2433 exactly two characters. If {chars} are not just two
2434 characters, or the digraph of {chars} does not exist, an error
2435 is given and an empty string is returned.
2436
2437 The character will be converted from Unicode to 'encoding'
2438 when needed. This does require the conversion to be
2439 available, it might fail.
2440
2441 Also see |digraph_getlist()|.
2442
2443 Examples: >
2444 " Get a built-in digraph
2445 :echo digraph_get('00') " Returns '∞'
2446
2447 " Get a user-defined digraph
2448 :call digraph_set('aa', 'あ')
2449 :echo digraph_get('aa') " Returns 'あ'
2450<
2451 Can also be used as a |method|: >
2452 GetChars()->digraph_get()
2453<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002454 Return type: |String|
2455
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002456 This function works only when compiled with the |+digraphs|
2457 feature. If this feature is disabled, this function will
2458 display an error message.
2459
2460
2461digraph_getlist([{listall}]) *digraph_getlist()*
2462 Return a list of digraphs. If the {listall} argument is given
2463 and it is TRUE, return all digraphs, including the default
2464 digraphs. Otherwise, return only user-defined digraphs.
2465
2466 The characters will be converted from Unicode to 'encoding'
2467 when needed. This does require the conservation to be
2468 available, it might fail.
2469
2470 Also see |digraph_get()|.
2471
2472 Examples: >
2473 " Get user-defined digraphs
2474 :echo digraph_getlist()
2475
2476 " Get all the digraphs, including default digraphs
2477 :echo digraph_getlist(1)
2478<
2479 Can also be used as a |method|: >
2480 GetNumber()->digraph_getlist()
2481<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002482 Return type: list<list<string>>
2483
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002484 This function works only when compiled with the |+digraphs|
2485 feature. If this feature is disabled, this function will
2486 display an error message.
2487
2488
Bram Moolenaara2baa732022-02-04 16:09:54 +00002489digraph_set({chars}, {digraph}) *digraph_set()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002490 Add digraph {chars} to the list. {chars} must be a string
2491 with two characters. {digraph} is a string with one UTF-8
Bram Moolenaara2baa732022-02-04 16:09:54 +00002492 encoded character. *E1215*
2493 Be careful, composing characters are NOT ignored. This
2494 function is similar to |:digraphs| command, but useful to add
2495 digraphs start with a white space.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002496
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002497 The function returns v:true if |digraph| is registered. If
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002498 this fails an error message is given and v:false is returned.
2499
2500 If you want to define multiple digraphs at once, you can use
2501 |digraph_setlist()|.
2502
2503 Example: >
2504 call digraph_set(' ', 'あ')
2505<
2506 Can be used as a |method|: >
2507 GetString()->digraph_set('あ')
2508<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002509 Return type: |vim9-boolean|
2510
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002511 This function works only when compiled with the |+digraphs|
2512 feature. If this feature is disabled, this function will
2513 display an error message.
2514
2515
2516digraph_setlist({digraphlist}) *digraph_setlist()*
2517 Similar to |digraph_set()| but this function can add multiple
2518 digraphs at once. {digraphlist} is a list composed of lists,
2519 where each list contains two strings with {chars} and
Bram Moolenaara2baa732022-02-04 16:09:54 +00002520 {digraph} as in |digraph_set()|. *E1216*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002521 Example: >
2522 call digraph_setlist([['aa', 'あ'], ['ii', 'い']])
2523<
2524 It is similar to the following: >
2525 for [chars, digraph] in [['aa', 'あ'], ['ii', 'い']]
2526 call digraph_set(chars, digraph)
2527 endfor
2528< Except that the function returns after the first error,
2529 following digraphs will not be added.
2530
2531 Can be used as a |method|: >
2532 GetList()->digraph_setlist()
2533<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002534 Return type: |vim9-boolean|
2535
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002536 This function works only when compiled with the |+digraphs|
2537 feature. If this feature is disabled, this function will
2538 display an error message.
2539
2540
2541echoraw({string}) *echoraw()*
2542 Output {string} as-is, including unprintable characters.
2543 This can be used to output a terminal code. For example, to
2544 disable modifyOtherKeys: >
2545 call echoraw(&t_TE)
2546< and to enable it again: >
2547 call echoraw(&t_TI)
2548< Use with care, you can mess up the terminal this way.
2549
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002550 Return type: |Number|
2551
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002552
2553empty({expr}) *empty()*
2554 Return the Number 1 if {expr} is empty, zero otherwise.
Yegappan Lakshmanan9cb865e2025-03-23 16:42:16 +01002555 - A |List|, |Tuple| or |Dictionary| is empty when it does
2556 not have any items.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002557 - A |String| is empty when its length is zero.
2558 - A |Number| and |Float| are empty when their value is zero.
2559 - |v:false|, |v:none| and |v:null| are empty, |v:true| is not.
2560 - A |Job| is empty when it failed to start.
2561 - A |Channel| is empty when it is closed.
2562 - A |Blob| is empty when its length is zero.
mityu7f0bba22024-03-29 10:14:41 +01002563 - An |Object| is empty, when the empty() method in the object
2564 (if present) returns true. |object-empty()|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002565
2566 For a long |List| this is much faster than comparing the
2567 length with zero.
2568
2569 Can also be used as a |method|: >
2570 mylist->empty()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002571<
2572 Return type: |Number|
2573
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002574
2575environ() *environ()*
2576 Return all of environment variables as dictionary. You can
2577 check if an environment variable exists like this: >
2578 :echo has_key(environ(), 'HOME')
2579< Note that the variable name may be CamelCase; to ignore case
2580 use this: >
2581 :echo index(keys(environ()), 'HOME', 0, 1) != -1
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002582<
2583 Return type: dict<string>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002584
Bram Moolenaar416bd912023-07-07 23:19:18 +01002585
2586err_teapot([{expr}]) *err_teapot()*
2587 Produce an error with number 418, needed for implementation of
Christian Brabandtee17b6f2023-09-09 11:23:50 +02002588 RFC 2324.
Bram Moolenaar416bd912023-07-07 23:19:18 +01002589 If {expr} is present and it is TRUE error 503 is given,
2590 indicating that coffee is temporarily not available.
2591 If {expr} is present it must be a String.
2592
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002593 Return type: |Number|
2594
Bram Moolenaar416bd912023-07-07 23:19:18 +01002595
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002596escape({string}, {chars}) *escape()*
2597 Escape the characters in {chars} that occur in {string} with a
2598 backslash. Example: >
2599 :echo escape('c:\program files\vim', ' \')
2600< results in: >
2601 c:\\program\ files\\vim
2602< Also see |shellescape()| and |fnameescape()|.
2603
2604 Can also be used as a |method|: >
2605 GetText()->escape(' \')
2606<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002607 Return type: |String|
2608
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002609 *eval()*
2610eval({string}) Evaluate {string} and return the result. Especially useful to
2611 turn the result of |string()| back into the original value.
2612 This works for Numbers, Floats, Strings, Blobs and composites
2613 of them. Also works for |Funcref|s that refer to existing
Aliaksei Budavei95740222024-04-04 23:05:33 +03002614 functions. In |Vim9| script, it can be used to obtain |enum|
2615 values from their fully qualified names.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002616
2617 Can also be used as a |method|: >
2618 argv->join()->eval()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002619<
2620 Return type: any, depending on {string}
2621
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002622
2623eventhandler() *eventhandler()*
2624 Returns 1 when inside an event handler. That is that Vim got
2625 interrupted while waiting for the user to type a character,
2626 e.g., when dropping a file on Vim. This means interactive
2627 commands cannot be used. Otherwise zero is returned.
2628
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002629 Return type: |Number|
2630
2631
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002632executable({expr}) *executable()*
2633 This function checks if an executable with the name {expr}
2634 exists. {expr} must be the name of the program without any
2635 arguments.
zeertzjq0cc5dce2024-08-08 21:12:15 +02002636
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002637 executable() uses the value of $PATH and/or the normal
zeertzjq0cc5dce2024-08-08 21:12:15 +02002638 searchpath for programs.
2639 *PATHEXT*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002640 On MS-Windows the ".exe", ".bat", etc. can optionally be
2641 included. Then the extensions in $PATHEXT are tried. Thus if
2642 "foo.exe" does not exist, "foo.exe.bat" can be found. If
2643 $PATHEXT is not set then ".com;.exe;.bat;.cmd" is used. A dot
2644 by itself can be used in $PATHEXT to try using the name
2645 without an extension. When 'shell' looks like a Unix shell,
2646 then the name is also tried without adding an extension.
2647 On MS-Windows it only checks if the file exists and is not a
2648 directory, not if it's really executable.
zeertzjq0cc5dce2024-08-08 21:12:15 +02002649 On MS-Windows an executable in the same directory as the Vim
2650 executable is always found. Since this directory is added to
2651 $PATH it should also work to execute it |win32-PATH|.
2652 *NoDefaultCurrentDirectoryInExePath*
2653 On MS-Windows an executable in Vim's current working directory
2654 is also normally found, but this can be disabled by setting
2655 the $NoDefaultCurrentDirectoryInExePath environment variable.
2656
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002657 The result is a Number:
2658 1 exists
2659 0 does not exist
2660 -1 not implemented on this system
2661 |exepath()| can be used to get the full path of an executable.
2662
2663 Can also be used as a |method|: >
2664 GetCommand()->executable()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002665<
2666 Return type: |Number|
2667
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002668
2669execute({command} [, {silent}]) *execute()*
2670 Execute an Ex command or commands and return the output as a
2671 string.
2672 {command} can be a string or a List. In case of a List the
2673 lines are executed one by one.
Bram Moolenaarb7398fe2023-05-14 18:50:25 +01002674 This is more or less equivalent to: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002675 redir => var
2676 {command}
2677 redir END
Bram Moolenaar71badf92023-04-22 22:40:14 +01002678< Except that line continuation in {command} is not recognized.
2679
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002680 The optional {silent} argument can have these values:
2681 "" no `:silent` used
2682 "silent" `:silent` used
2683 "silent!" `:silent!` used
2684 The default is "silent". Note that with "silent!", unlike
2685 `:redir`, error messages are dropped. When using an external
2686 command the screen may be messed up, use `system()` instead.
2687 *E930*
2688 It is not possible to use `:redir` anywhere in {command}.
2689
Bram Moolenaarb7398fe2023-05-14 18:50:25 +01002690 To get a list of lines use `split()` on the result: >
Bram Moolenaar75ab5902022-04-18 15:36:40 +01002691 execute('args')->split("\n")
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002692
2693< To execute a command in another window than the current one
2694 use `win_execute()`.
2695
2696 When used recursively the output of the recursive call is not
2697 included in the output of the higher level call.
2698
2699 Can also be used as a |method|: >
2700 GetCommand()->execute()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002701<
Marius Gedminasc98bfb92024-06-19 19:59:23 +02002702 Return type: |String|
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002703
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002704
2705exepath({expr}) *exepath()*
2706 If {expr} is an executable and is either an absolute path, a
2707 relative path or found in $PATH, return the full path.
2708 Note that the current directory is used when {expr} starts
2709 with "./", which may be a problem for Vim: >
2710 echo exepath(v:progpath)
2711< If {expr} cannot be found in $PATH or is not executable then
2712 an empty string is returned.
2713
2714 Can also be used as a |method|: >
2715 GetCommand()->exepath()
2716<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002717 Return type: |String|
2718
2719
2720exists({expr}) *exists()*
2721 The result is a Number, which is |TRUE| if {expr} is defined,
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002722 zero otherwise.
2723
2724 Note: In a compiled |:def| function the evaluation is done at
2725 runtime. Use `exists_compiled()` to evaluate the expression
2726 at compile time.
2727
2728 For checking for a supported feature use |has()|.
2729 For checking if a file exists use |filereadable()|.
2730
2731 The {expr} argument is a string, which contains one of these:
Bram Moolenaarf10911e2022-01-29 22:20:48 +00002732 varname internal variable (see
2733 dict.key |internal-variables|). Also works
2734 list[i] for |curly-braces-names|, |Dictionary|
Yegappan Lakshmanana2ebb6e2024-02-25 08:40:10 +01002735 import.Func entries, |List| items, class and
2736 class.Func object methods, imported items, etc.
2737 object.Func Does not work for local variables in a
2738 class.varname compiled `:def` function.
2739 object.varname Also works for a function in |Vim9|
Bram Moolenaar944697a2022-02-20 19:48:20 +00002740 script, since it can be used as a
2741 function reference.
Bram Moolenaarf10911e2022-01-29 22:20:48 +00002742 Beware that evaluating an index may
2743 cause an error message for an invalid
2744 expression. E.g.: >
2745 :let l = [1, 2, 3]
2746 :echo exists("l[5]")
2747< 0 >
2748 :echo exists("l[xx]")
2749< E121: Undefined variable: xx
2750 0
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002751 &option-name Vim option (only checks if it exists,
2752 not if it really works)
2753 +option-name Vim option that works.
2754 $ENVNAME environment variable (could also be
2755 done by comparing with an empty
2756 string)
2757 *funcname built-in function (see |functions|)
2758 or user defined function (see
2759 |user-functions|) that is implemented.
2760 Also works for a variable that is a
2761 Funcref.
2762 ?funcname built-in function that could be
2763 implemented; to be used to check if
2764 "funcname" is valid
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002765 :cmdname Ex command: built-in command, user
2766 command or command modifier |:command|.
2767 Returns:
2768 1 for match with start of a command
2769 2 full match with a command
2770 3 matches several user commands
2771 To check for a supported command
2772 always check the return value to be 2.
2773 :2match The |:2match| command.
Bram Moolenaarb529cfb2022-07-25 15:42:07 +01002774 :3match The |:3match| command (but you
2775 probably should not use it, it is
2776 reserved for internal usage)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002777 #event autocommand defined for this event
2778 #event#pattern autocommand defined for this event and
2779 pattern (the pattern is taken
2780 literally and compared to the
2781 autocommand patterns character by
2782 character)
2783 #group autocommand group exists
2784 #group#event autocommand defined for this group and
2785 event.
2786 #group#event#pattern
2787 autocommand defined for this group,
2788 event and pattern.
2789 ##event autocommand for this event is
2790 supported.
2791
2792 Examples: >
2793 exists("&shortname")
2794 exists("$HOSTNAME")
2795 exists("*strftime")
Bram Moolenaar944697a2022-02-20 19:48:20 +00002796 exists("*s:MyFunc") " only for legacy script
2797 exists("*MyFunc")
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002798 exists("bufcount")
2799 exists(":Make")
2800 exists("#CursorHold")
2801 exists("#BufReadPre#*.gz")
2802 exists("#filetypeindent")
2803 exists("#filetypeindent#FileType")
2804 exists("#filetypeindent#FileType#*")
2805 exists("##ColorScheme")
2806< There must be no space between the symbol (&/$/*/#) and the
2807 name.
2808 There must be no extra characters after the name, although in
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01002809 a few cases this is ignored. That may become stricter in the
2810 future, thus don't count on it!
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002811 Working example: >
2812 exists(":make")
2813< NOT working example: >
2814 exists(":make install")
2815
2816< Note that the argument must be a string, not the name of the
2817 variable itself. For example: >
2818 exists(bufcount)
2819< This doesn't check for existence of the "bufcount" variable,
2820 but gets the value of "bufcount", and checks if that exists.
2821
2822 Can also be used as a |method|: >
2823 Varname()->exists()
2824<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002825 Return type: |String|
2826
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002827
2828exists_compiled({expr}) *exists_compiled()*
2829 Like `exists()` but evaluated at compile time. This is useful
2830 to skip a block where a function is used that would otherwise
2831 give an error: >
2832 if exists_compiled('*ThatFunction')
2833 ThatFunction('works')
2834 endif
2835< If `exists()` were used then a compilation error would be
2836 given if ThatFunction() is not defined.
2837
2838 {expr} must be a literal string. *E1232*
2839 Can only be used in a |:def| function. *E1233*
2840 This does not work to check for arguments or local variables.
2841
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002842 Return type: |String|
2843
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002844
2845exp({expr}) *exp()*
2846 Return the exponential of {expr} as a |Float| in the range
2847 [0, inf].
2848 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar016188f2022-06-06 20:52:59 +01002849 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002850 Examples: >
2851 :echo exp(2)
2852< 7.389056 >
2853 :echo exp(-1)
2854< 0.367879
2855
2856 Can also be used as a |method|: >
2857 Compute()->exp()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002858<
2859 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002860
2861
2862expand({string} [, {nosuf} [, {list}]]) *expand()*
2863 Expand wildcards and the following special keywords in
2864 {string}. 'wildignorecase' applies.
2865
2866 If {list} is given and it is |TRUE|, a List will be returned.
2867 Otherwise the result is a String and when there are several
2868 matches, they are separated by <NL> characters. [Note: in
2869 version 5.0 a space was used, which caused problems when a
2870 file name contains a space]
2871
2872 If the expansion fails, the result is an empty string. A name
2873 for a non-existing file is not included, unless {string} does
2874 not start with '%', '#' or '<', see below.
2875
Christian Brabandtec9c3262024-02-21 20:40:05 +01002876 For a |:terminal| window '%' expands to a '!' followed by
h-east53753f62024-05-05 18:42:31 +02002877 the command or shell that is run. |terminal-bufname|
Christian Brabandtec9c3262024-02-21 20:40:05 +01002878
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002879 When {string} starts with '%', '#' or '<', the expansion is
2880 done like for the |cmdline-special| variables with their
2881 associated modifiers. Here is a short overview:
2882
2883 % current file name
2884 # alternate file name
2885 #n alternate file name n
2886 <cfile> file name under the cursor
2887 <afile> autocmd file name
2888 <abuf> autocmd buffer number (as a String!)
2889 <amatch> autocmd matched name
2890 <cexpr> C expression under the cursor
2891 <sfile> sourced script file or function name
2892 <slnum> sourced script line number or function
2893 line number
2894 <sflnum> script file line number, also when in
2895 a function
2896 <SID> "<SNR>123_" where "123" is the
2897 current script ID |<SID>|
Bram Moolenaar75ab5902022-04-18 15:36:40 +01002898 <script> sourced script file, or script file
2899 where the current function was defined
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002900 <stack> call stack
2901 <cword> word under the cursor
2902 <cWORD> WORD under the cursor
2903 <client> the {clientid} of the last received
2904 message |server2client()|
2905 Modifiers:
2906 :p expand to full path
2907 :h head (last path component removed)
2908 :t tail (last path component only)
2909 :r root (one extension removed)
2910 :e extension only
2911
2912 Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00002913 :let &tags = expand("%:p:h") .. "/tags"
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002914< Note that when expanding a string that starts with '%', '#' or
2915 '<', any following text is ignored. This does NOT work: >
2916 :let doesntwork = expand("%:h.bak")
2917< Use this: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00002918 :let doeswork = expand("%:h") .. ".bak"
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002919< Also note that expanding "<cfile>" and others only returns the
2920 referenced file name without further expansion. If "<cfile>"
2921 is "~/.cshrc", you need to do another expand() to have the
2922 "~/" expanded into the path of the home directory: >
2923 :echo expand(expand("<cfile>"))
2924<
2925 There cannot be white space between the variables and the
2926 following modifier. The |fnamemodify()| function can be used
2927 to modify normal file names.
2928
2929 When using '%' or '#', and the current or alternate file name
2930 is not defined, an empty string is used. Using "%:p" in a
2931 buffer with no name, results in the current directory, with a
2932 '/' added.
Bram Moolenaar57544522022-04-12 12:54:11 +01002933 When 'verbose' is set then expanding '%', '#' and <> items
2934 will result in an error message if the argument cannot be
2935 expanded.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002936
2937 When {string} does not start with '%', '#' or '<', it is
2938 expanded like a file name is expanded on the command line.
2939 'suffixes' and 'wildignore' are used, unless the optional
2940 {nosuf} argument is given and it is |TRUE|.
2941 Names for non-existing files are included. The "**" item can
2942 be used to search in a directory tree. For example, to find
2943 all "README" files in the current directory and below: >
2944 :echo expand("**/README")
2945<
2946 expand() can also be used to expand variables and environment
2947 variables that are only known in a shell. But this can be
2948 slow, because a shell may be used to do the expansion. See
2949 |expr-env-expand|.
2950 The expanded variable is still handled like a list of file
2951 names. When an environment variable cannot be expanded, it is
2952 left unchanged. Thus ":echo expand('$FOOBAR')" results in
2953 "$FOOBAR".
2954
2955 See |glob()| for finding existing files. See |system()| for
2956 getting the raw output of an external command.
2957
2958 Can also be used as a |method|: >
2959 Getpattern()->expand()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002960<
2961 Return type: |String| or list<string> depending on {list}
2962
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002963
Yegappan Lakshmanan2b74b682022-04-03 21:30:32 +01002964expandcmd({string} [, {options}]) *expandcmd()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002965 Expand special items in String {string} like what is done for
2966 an Ex command such as `:edit`. This expands special keywords,
2967 like with |expand()|, and environment variables, anywhere in
2968 {string}. "~user" and "~/path" are only expanded at the
2969 start.
Yegappan Lakshmanan2b74b682022-04-03 21:30:32 +01002970
2971 The following items are supported in the {options} Dict
2972 argument:
2973 errmsg If set to TRUE, error messages are displayed
2974 if an error is encountered during expansion.
2975 By default, error messages are not displayed.
2976
Yegappan Lakshmanan5018a832022-04-02 21:12:21 +01002977 Returns the expanded string. If an error is encountered
2978 during expansion, the unmodified {string} is returned.
Yegappan Lakshmanan2b74b682022-04-03 21:30:32 +01002979
Yegappan Lakshmanan5018a832022-04-02 21:12:21 +01002980 Example: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002981 :echo expandcmd('make %<.o')
Yegappan Lakshmanan2b74b682022-04-03 21:30:32 +01002982 make /path/runtime/doc/builtin.o
2983 :echo expandcmd('make %<.o', {'errmsg': v:true})
2984<
Yegappan Lakshmanan5018a832022-04-02 21:12:21 +01002985 Can also be used as a |method|: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002986 GetCommand()->expandcmd()
2987<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002988 Return type: |String| or list<string> depending on {list}
2989
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002990extend({expr1}, {expr2} [, {expr3}]) *extend()*
2991 {expr1} and {expr2} must be both |Lists| or both
2992 |Dictionaries|.
2993
2994 If they are |Lists|: Append {expr2} to {expr1}.
2995 If {expr3} is given insert the items of {expr2} before the
2996 item with index {expr3} in {expr1}. When {expr3} is zero
2997 insert before the first item. When {expr3} is equal to
2998 len({expr1}) then {expr2} is appended.
2999 Examples: >
3000 :echo sort(extend(mylist, [7, 5]))
3001 :call extend(mylist, [2, 3], 1)
3002< When {expr1} is the same List as {expr2} then the number of
3003 items copied is equal to the original length of the List.
3004 E.g., when {expr3} is 1 you get N new copies of the first item
3005 (where N is the original length of the List).
3006 Use |add()| to concatenate one item to a list. To concatenate
3007 two lists into a new list use the + operator: >
3008 :let newlist = [1, 2, 3] + [4, 5]
3009<
3010 If they are |Dictionaries|:
3011 Add all entries from {expr2} to {expr1}.
3012 If a key exists in both {expr1} and {expr2} then {expr3} is
3013 used to decide what to do:
3014 {expr3} = "keep": keep the value of {expr1}
3015 {expr3} = "force": use the value of {expr2}
3016 {expr3} = "error": give an error message *E737*
3017 When {expr3} is omitted then "force" is assumed.
3018
3019 {expr1} is changed when {expr2} is not empty. If necessary
Christian Brabandt5647c912025-02-17 21:33:30 +01003020 make a copy of {expr1} first or use |extendnew()| to return a
3021 new List/Dictionary.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003022 {expr2} remains unchanged.
3023 When {expr1} is locked and {expr2} is not empty the operation
3024 fails.
Bram Moolenaar016188f2022-06-06 20:52:59 +01003025 Returns {expr1}. Returns 0 on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003026
3027 Can also be used as a |method|: >
3028 mylist->extend(otherlist)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003029<
3030 Return type: list<{type}> or dict<{type}> depending on {expr1}
3031 and {expr2}, in case of error: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003032
3033
3034extendnew({expr1}, {expr2} [, {expr3}]) *extendnew()*
3035 Like |extend()| but instead of adding items to {expr1} a new
3036 List or Dictionary is created and returned. {expr1} remains
Bram Moolenaardd60c362023-02-27 15:49:53 +00003037 unchanged.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003038
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003039 Return type: list<{type}> or dict<{type}> depending on {expr1}
3040 and {expr2}, in case of error: |Number|
3041
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003042
3043feedkeys({string} [, {mode}]) *feedkeys()*
3044 Characters in {string} are queued for processing as if they
3045 come from a mapping or were typed by the user.
3046
3047 By default the string is added to the end of the typeahead
3048 buffer, thus if a mapping is still being executed the
3049 characters come after them. Use the 'i' flag to insert before
3050 other characters, they will be executed next, before any
3051 characters from a mapping.
3052
3053 The function does not wait for processing of keys contained in
3054 {string}.
3055
3056 To include special keys into {string}, use double-quotes
3057 and "\..." notation |expr-quote|. For example,
3058 feedkeys("\<CR>") simulates pressing of the <Enter> key. But
3059 feedkeys('\<CR>') pushes 5 characters.
3060 A special code that might be useful is <Ignore>, it exits the
3061 wait for a character without doing anything. *<Ignore>*
3062
3063 {mode} is a String, which can contain these character flags:
3064 'm' Remap keys. This is default. If {mode} is absent,
3065 keys are remapped.
3066 'n' Do not remap keys.
3067 't' Handle keys as if typed; otherwise they are handled as
3068 if coming from a mapping. This matters for undo,
3069 opening folds, etc.
3070 'L' Lowlevel input. Only works for Unix or when using the
3071 GUI. Keys are used as if they were coming from the
3072 terminal. Other flags are not used. *E980*
3073 When a CTRL-C interrupts and 't' is included it sets
3074 the internal "got_int" flag.
3075 'i' Insert the string instead of appending (see above).
3076 'x' Execute commands until typeahead is empty. This is
3077 similar to using ":normal!". You can call feedkeys()
3078 several times without 'x' and then one time with 'x'
3079 (possibly with an empty {string}) to execute all the
3080 typeahead. Note that when Vim ends in Insert mode it
3081 will behave as if <Esc> is typed, to avoid getting
3082 stuck, waiting for a character to be typed before the
3083 script continues.
3084 Note that if you manage to call feedkeys() while
3085 executing commands, thus calling it recursively, then
3086 all typeahead will be consumed by the last call.
Bram Moolenaara9725222022-01-16 13:30:33 +00003087 'c' Remove any script context when executing, so that
3088 legacy script syntax applies, "s:var" does not work,
Bram Moolenaard899e512022-05-07 21:54:03 +01003089 etc. Note that if the string being fed sets a script
Bram Moolenaarce001a32022-04-27 15:25:03 +01003090 context this still applies.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003091 '!' When used with 'x' will not end Insert mode. Can be
3092 used in a test when a timer is set to exit Insert mode
3093 a little later. Useful for testing CursorHoldI.
3094
3095 Return value is always 0.
3096
3097 Can also be used as a |method|: >
3098 GetInput()->feedkeys()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003099<
3100 Return type: |String| or list<string> depending on {list}
3101
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003102
Shougo Matsushita60c87432024-06-03 22:59:27 +02003103filecopy({from}, {to}) *filecopy()*
3104 Copy the file pointed to by the name {from} to {to}. The
3105 result is a Number, which is |TRUE| if the file was copied
3106 successfully, and |FALSE| when it failed.
3107 If a file with name {to} already exists, it will fail.
3108 Note that it does not handle directories (yet).
3109
3110 This function is not available in the |sandbox|.
3111
3112 Can also be used as a |method|: >
3113 GetOldName()->filecopy(newname)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003114<
3115 Return type: |Number|
3116
Shougo Matsushita60c87432024-06-03 22:59:27 +02003117
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003118filereadable({file}) *filereadable()*
3119 The result is a Number, which is |TRUE| when a file with the
3120 name {file} exists, and can be read. If {file} doesn't exist,
3121 or is a directory, the result is |FALSE|. {file} is any
3122 expression, which is used as a String.
3123 If you don't care about the file being readable you can use
3124 |glob()|.
3125 {file} is used as-is, you may want to expand wildcards first: >
3126 echo filereadable('~/.vimrc')
3127 0
3128 echo filereadable(expand('~/.vimrc'))
3129 1
3130
3131< Can also be used as a |method|: >
3132 GetName()->filereadable()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003133<
3134 Return type: |Number|
3135
3136 *file_readable()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003137 Obsolete name: file_readable().
3138
3139
3140filewritable({file}) *filewritable()*
3141 The result is a Number, which is 1 when a file with the
3142 name {file} exists, and can be written. If {file} doesn't
3143 exist, or is not writable, the result is 0. If {file} is a
3144 directory, and we can write to it, the result is 2.
3145
3146 Can also be used as a |method|: >
3147 GetName()->filewritable()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003148<
3149 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003150
3151
3152filter({expr1}, {expr2}) *filter()*
3153 {expr1} must be a |List|, |String|, |Blob| or |Dictionary|.
3154 For each item in {expr1} evaluate {expr2} and when the result
3155 is zero or false remove the item from the |List| or
3156 |Dictionary|. Similarly for each byte in a |Blob| and each
Bram Moolenaar2f0936c2022-01-08 21:51:59 +00003157 character in a |String|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003158
3159 {expr2} must be a |string| or |Funcref|.
3160
3161 If {expr2} is a |string|, inside {expr2} |v:val| has the value
3162 of the current item. For a |Dictionary| |v:key| has the key
3163 of the current item and for a |List| |v:key| has the index of
3164 the current item. For a |Blob| |v:key| has the index of the
3165 current byte. For a |String| |v:key| has the index of the
3166 current character.
3167 Examples: >
3168 call filter(mylist, 'v:val !~ "OLD"')
3169< Removes the items where "OLD" appears. >
3170 call filter(mydict, 'v:key >= 8')
3171< Removes the items with a key below 8. >
3172 call filter(var, 0)
3173< Removes all the items, thus clears the |List| or |Dictionary|.
3174
3175 Note that {expr2} is the result of expression and is then
3176 used as an expression again. Often it is good to use a
3177 |literal-string| to avoid having to double backslashes.
3178
3179 If {expr2} is a |Funcref| it must take two arguments:
3180 1. the key or the index of the current item.
3181 2. the value of the current item.
3182 The function must return |TRUE| if the item should be kept.
3183 Example that keeps the odd items of a list: >
3184 func Odd(idx, val)
3185 return a:idx % 2 == 1
3186 endfunc
3187 call filter(mylist, function('Odd'))
Bram Moolenaar2f0936c2022-01-08 21:51:59 +00003188< It is shorter when using a |lambda|. In |Vim9| syntax: >
3189 call filter(myList, (idx, val) => idx * val <= 42)
3190< In legacy script syntax: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003191 call filter(myList, {idx, val -> idx * val <= 42})
3192< If you do not use "val" you can leave it out: >
3193 call filter(myList, {idx -> idx % 2 == 1})
3194<
3195 In |Vim9| script the result must be true, false, zero or one.
3196 Other values will result in a type error.
3197
3198 For a |List| and a |Dictionary| the operation is done
3199 in-place. If you want it to remain unmodified make a copy
3200 first: >
3201 :let l = filter(copy(mylist), 'v:val =~ "KEEP"')
3202
3203< Returns {expr1}, the |List| or |Dictionary| that was filtered,
naohiro ono56200ee2022-01-01 14:59:44 +00003204 or a new |Blob| or |String|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003205 When an error is encountered while evaluating {expr2} no
3206 further items in {expr1} are processed.
3207 When {expr2} is a Funcref errors inside a function are ignored,
3208 unless it was defined with the "abort" flag.
3209
3210 Can also be used as a |method|: >
3211 mylist->filter(expr2)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003212<
3213 Return type: |String|, |Blob|, list<{type}> or dict<{type}>
3214 depending on {expr1}
3215
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003216
3217finddir({name} [, {path} [, {count}]]) *finddir()*
3218 Find directory {name} in {path}. Supports both downwards and
3219 upwards recursive directory searches. See |file-searching|
3220 for the syntax of {path}.
3221
3222 Returns the path of the first found match. When the found
3223 directory is below the current directory a relative path is
3224 returned. Otherwise a full path is returned.
3225 If {path} is omitted or empty then 'path' is used.
3226
3227 If the optional {count} is given, find {count}'s occurrence of
3228 {name} in {path} instead of the first one.
3229 When {count} is negative return all the matches in a |List|.
3230
Bram Moolenaar016188f2022-06-06 20:52:59 +01003231 Returns an empty string if the directory is not found.
3232
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003233 This is quite similar to the ex-command `:find`.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003234
3235 Can also be used as a |method|: >
3236 GetName()->finddir()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003237<
3238 Return type: |String|
3239
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003240
3241findfile({name} [, {path} [, {count}]]) *findfile()*
3242 Just like |finddir()|, but find a file instead of a directory.
3243 Uses 'suffixesadd'.
3244 Example: >
3245 :echo findfile("tags.vim", ".;")
3246< Searches from the directory of the current file upwards until
3247 it finds the file "tags.vim".
3248
3249 Can also be used as a |method|: >
3250 GetName()->findfile()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003251<
3252 Return type: |String|
3253
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003254
3255flatten({list} [, {maxdepth}]) *flatten()*
3256 Flatten {list} up to {maxdepth} levels. Without {maxdepth}
3257 the result is a |List| without nesting, as if {maxdepth} is
3258 a very large number.
3259 The {list} is changed in place, use |flattennew()| if you do
3260 not want that.
3261 In Vim9 script flatten() cannot be used, you must always use
Bram Moolenaara2baa732022-02-04 16:09:54 +00003262 |flattennew()|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003263 *E900*
3264 {maxdepth} means how deep in nested lists changes are made.
3265 {list} is not modified when {maxdepth} is 0.
3266 {maxdepth} must be positive number.
3267
3268 If there is an error the number zero is returned.
3269
3270 Example: >
3271 :echo flatten([1, [2, [3, 4]], 5])
3272< [1, 2, 3, 4, 5] >
3273 :echo flatten([1, [2, [3, 4]], 5], 1)
3274< [1, 2, [3, 4], 5]
3275
3276 Can also be used as a |method|: >
3277 mylist->flatten()
3278<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003279 Return type: list<{type}>
3280
3281
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003282flattennew({list} [, {maxdepth}]) *flattennew()*
3283 Like |flatten()| but first make a copy of {list}.
3284
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003285 Return type: list<{type}>
3286
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003287
3288float2nr({expr}) *float2nr()*
3289 Convert {expr} to a Number by omitting the part after the
3290 decimal point.
Bram Moolenaar76db9e02022-11-09 21:21:04 +00003291 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar016188f2022-06-06 20:52:59 +01003292 Returns 0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003293 When the value of {expr} is out of range for a |Number| the
3294 result is truncated to 0x7fffffff or -0x7fffffff (or when
3295 64-bit Number support is enabled, 0x7fffffffffffffff or
3296 -0x7fffffffffffffff). NaN results in -0x80000000 (or when
3297 64-bit Number support is enabled, -0x8000000000000000).
3298 Examples: >
3299 echo float2nr(3.95)
3300< 3 >
3301 echo float2nr(-23.45)
3302< -23 >
3303 echo float2nr(1.0e100)
3304< 2147483647 (or 9223372036854775807) >
3305 echo float2nr(-1.0e150)
3306< -2147483647 (or -9223372036854775807) >
3307 echo float2nr(1.0e-100)
3308< 0
3309
3310 Can also be used as a |method|: >
3311 Compute()->float2nr()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003312<
3313 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003314
3315
3316floor({expr}) *floor()*
3317 Return the largest integral value less than or equal to
3318 {expr} as a |Float| (round down).
3319 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar016188f2022-06-06 20:52:59 +01003320 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003321 Examples: >
3322 echo floor(1.856)
3323< 1.0 >
3324 echo floor(-5.456)
3325< -6.0 >
3326 echo floor(4.0)
3327< 4.0
3328
3329 Can also be used as a |method|: >
3330 Compute()->floor()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003331<
3332 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003333
3334
3335fmod({expr1}, {expr2}) *fmod()*
3336 Return the remainder of {expr1} / {expr2}, even if the
3337 division is not representable. Returns {expr1} - i * {expr2}
3338 for some integer i such that if {expr2} is non-zero, the
3339 result has the same sign as {expr1} and magnitude less than
3340 the magnitude of {expr2}. If {expr2} is zero, the value
3341 returned is zero. The value returned is a |Float|.
3342 {expr1} and {expr2} must evaluate to a |Float| or a |Number|.
Bram Moolenaar016188f2022-06-06 20:52:59 +01003343 Returns 0.0 if {expr1} or {expr2} is not a |Float| or a
3344 |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003345 Examples: >
3346 :echo fmod(12.33, 1.22)
3347< 0.13 >
3348 :echo fmod(-12.33, 1.22)
3349< -0.13
3350
3351 Can also be used as a |method|: >
3352 Compute()->fmod(1.22)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003353<
3354 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003355
3356
3357fnameescape({string}) *fnameescape()*
3358 Escape {string} for use as file name command argument. All
3359 characters that have a special meaning, such as '%' and '|'
3360 are escaped with a backslash.
3361 For most systems the characters escaped are
3362 " \t\n*?[{`$\\%#'\"|!<". For systems where a backslash
3363 appears in a filename, it depends on the value of 'isfname'.
3364 A leading '+' and '>' is also escaped (special after |:edit|
3365 and |:write|). And a "-" by itself (special after |:cd|).
Bram Moolenaar016188f2022-06-06 20:52:59 +01003366 Returns an empty string on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003367 Example: >
3368 :let fname = '+some str%nge|name'
Bram Moolenaarc51cf032022-02-26 12:25:45 +00003369 :exe "edit " .. fnameescape(fname)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003370< results in executing: >
3371 edit \+some\ str\%nge\|name
3372<
3373 Can also be used as a |method|: >
3374 GetName()->fnameescape()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003375<
3376 Return type: |String|
3377
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003378
3379fnamemodify({fname}, {mods}) *fnamemodify()*
3380 Modify file name {fname} according to {mods}. {mods} is a
3381 string of characters like it is used for file names on the
3382 command line. See |filename-modifiers|.
3383 Example: >
3384 :echo fnamemodify("main.c", ":p:h")
3385< results in: >
Bram Moolenaard799daa2022-06-20 11:17:32 +01003386 /home/user/vim/vim/src
Bram Moolenaar016188f2022-06-06 20:52:59 +01003387< If {mods} is empty or an unsupported modifier is used then
3388 {fname} is returned.
Bram Moolenaar5ed11532022-07-06 13:18:11 +01003389 When {fname} is empty then with {mods} ":h" returns ".", so
3390 that `:cd` can be used with it. This is different from
3391 expand('%:h') without a buffer name, which returns an empty
3392 string.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003393 Note: Environment variables don't work in {fname}, use
3394 |expand()| first then.
3395
3396 Can also be used as a |method|: >
3397 GetName()->fnamemodify(':p:h')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003398<
3399 Return type: |String|
3400
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003401
3402foldclosed({lnum}) *foldclosed()*
3403 The result is a Number. If the line {lnum} is in a closed
3404 fold, the result is the number of the first line in that fold.
3405 If the line {lnum} is not in a closed fold, -1 is returned.
3406 {lnum} is used like with |getline()|. Thus "." is the current
3407 line, "'m" mark m, etc.
3408
3409 Can also be used as a |method|: >
3410 GetLnum()->foldclosed()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003411<
3412 Return type: |Number|
3413
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003414
3415foldclosedend({lnum}) *foldclosedend()*
3416 The result is a Number. If the line {lnum} is in a closed
3417 fold, the result is the number of the last line in that fold.
3418 If the line {lnum} is not in a closed fold, -1 is returned.
3419 {lnum} is used like with |getline()|. Thus "." is the current
3420 line, "'m" mark m, etc.
3421
3422 Can also be used as a |method|: >
3423 GetLnum()->foldclosedend()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003424<
3425 Return type: |Number|
3426
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003427
3428foldlevel({lnum}) *foldlevel()*
3429 The result is a Number, which is the foldlevel of line {lnum}
3430 in the current buffer. For nested folds the deepest level is
3431 returned. If there is no fold at line {lnum}, zero is
3432 returned. It doesn't matter if the folds are open or closed.
3433 When used while updating folds (from 'foldexpr') -1 is
3434 returned for lines where folds are still to be updated and the
3435 foldlevel is unknown. As a special case the level of the
3436 previous line is usually available.
3437 {lnum} is used like with |getline()|. Thus "." is the current
3438 line, "'m" mark m, etc.
3439
3440 Can also be used as a |method|: >
3441 GetLnum()->foldlevel()
3442<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003443 Return type: |Number|
3444
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003445 *foldtext()*
3446foldtext() Returns a String, to be displayed for a closed fold. This is
3447 the default function used for the 'foldtext' option and should
3448 only be called from evaluating 'foldtext'. It uses the
3449 |v:foldstart|, |v:foldend| and |v:folddashes| variables.
3450 The returned string looks like this: >
3451 +-- 45 lines: abcdef
3452< The number of leading dashes depends on the foldlevel. The
3453 "45" is the number of lines in the fold. "abcdef" is the text
3454 in the first non-blank line of the fold. Leading white space,
3455 "//" or "/*" and the text from the 'foldmarker' and
3456 'commentstring' options is removed.
3457 When used to draw the actual foldtext, the rest of the line
3458 will be filled with the fold char from the 'fillchars'
3459 setting.
Bram Moolenaar016188f2022-06-06 20:52:59 +01003460 Returns an empty string when there is no fold.
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003461
3462 Return type: |String|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003463 {not available when compiled without the |+folding| feature}
3464
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003465
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003466foldtextresult({lnum}) *foldtextresult()*
3467 Returns the text that is displayed for the closed fold at line
3468 {lnum}. Evaluates 'foldtext' in the appropriate context.
3469 When there is no closed fold at {lnum} an empty string is
3470 returned.
3471 {lnum} is used like with |getline()|. Thus "." is the current
3472 line, "'m" mark m, etc.
3473 Useful when exporting folded text, e.g., to HTML.
3474 {not available when compiled without the |+folding| feature}
3475
3476
3477 Can also be used as a |method|: >
3478 GetLnum()->foldtextresult()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003479<
3480 Return type: |String|
3481
Ernie Raele79e2072024-01-13 11:47:33 +01003482
Yegappan Lakshmanan9cb865e2025-03-23 16:42:16 +01003483foreach({expr1}, {expr2}) *foreach()* *E1525*
3484 {expr1} must be a |List|, |Tuple|, |String|, |Blob| or
3485 |Dictionary|.
Ernie Raele79e2072024-01-13 11:47:33 +01003486 For each item in {expr1} execute {expr2}. {expr1} is not
erraelc92b8be2024-01-14 10:11:07 -08003487 modified; its values may be, as with |:lockvar| 1. |E741|
Ernie Raele79e2072024-01-13 11:47:33 +01003488 See |map()| and |filter()| to modify {expr1}.
3489
3490 {expr2} must be a |string| or |Funcref|.
3491
3492 If {expr2} is a |string|, inside {expr2} |v:val| has the value
3493 of the current item. For a |Dictionary| |v:key| has the key
Yegappan Lakshmanan9cb865e2025-03-23 16:42:16 +01003494 of the current item and for a |List| or a |Tuple| |v:key| has
3495 the index of the current item. For a |Blob| |v:key| has the
3496 index of the current byte. For a |String| |v:key| has the
3497 index of the current character.
Ernie Raele79e2072024-01-13 11:47:33 +01003498 Examples: >
3499 call foreach(mylist, 'used[v:val] = true')
3500< This records the items that are in the {expr1} list.
3501
3502 Note that {expr2} is the result of expression and is then used
3503 as a command. Often it is good to use a |literal-string| to
3504 avoid having to double backslashes.
3505
3506 If {expr2} is a |Funcref| it must take two arguments:
3507 1. the key or the index of the current item.
3508 2. the value of the current item.
3509 With a legacy script lambda you don't get an error if it only
3510 accepts one argument, but with a Vim9 lambda you get "E1106:
3511 One argument too many", the number of arguments must match.
3512 If the function returns a value, it is ignored.
3513
3514 Returns {expr1} in all cases.
3515 When an error is encountered while executing {expr2} no
3516 further items in {expr1} are processed.
3517 When {expr2} is a Funcref errors inside a function are ignored,
3518 unless it was defined with the "abort" flag.
3519
3520 Can also be used as a |method|: >
3521 mylist->foreach(expr2)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003522<
Yegappan Lakshmanan9cb865e2025-03-23 16:42:16 +01003523 Return type: |String|, |Blob|, list<{type}>, tuple<{type}> or
3524 dict<{type}> depending on {expr1}
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003525
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003526 *foreground()*
3527foreground() Move the Vim window to the foreground. Useful when sent from
3528 a client to a Vim server. |remote_send()|
3529 On Win32 systems this might not work, the OS does not always
3530 allow a window to bring itself to the foreground. Use
3531 |remote_foreground()| instead.
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003532
3533 Return type: |Number|
Bram Moolenaarcbaff5e2022-04-08 17:45:08 +01003534 {only in the Win32, Motif and GTK GUI versions and the
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003535 Win32 console version}
3536
Bram Moolenaaraa534142022-09-15 21:46:02 +01003537fullcommand({name} [, {vim9}]) *fullcommand()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003538 Get the full command name from a short abbreviated command
3539 name; see |20.2| for details on command abbreviations.
3540
3541 The string argument {name} may start with a `:` and can
3542 include a [range], these are skipped and not returned.
Bram Moolenaaraa534142022-09-15 21:46:02 +01003543 Returns an empty string if a command doesn't exist, if it's
3544 ambiguous (for user-defined commands) or cannot be shortened
3545 this way. |vim9-no-shorten|
3546
3547 Without the {vim9} argument uses the current script version.
3548 If {vim9} is present and FALSE then legacy script rules are
3549 used. When {vim9} is present and TRUE then Vim9 rules are
3550 used, e.g. "en" is not a short form of "endif".
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003551
3552 For example `fullcommand('s')`, `fullcommand('sub')`,
3553 `fullcommand(':%substitute')` all return "substitute".
3554
3555 Can also be used as a |method|: >
3556 GetName()->fullcommand()
3557<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003558 Return type: |String|
3559
3560
3561funcref({name} [, {arglist}] [, {dict}]) *funcref()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003562 Just like |function()|, but the returned Funcref will lookup
3563 the function by reference, not by name. This matters when the
3564 function {name} is redefined later.
3565
3566 Unlike |function()|, {name} must be an existing user function.
Bram Moolenaar2f0936c2022-01-08 21:51:59 +00003567 It only works for an autoloaded function if it has already
3568 been loaded (to avoid mistakenly loading the autoload script
3569 when only intending to use the function name, use |function()|
3570 instead). {name} cannot be a builtin function.
Bram Moolenaar016188f2022-06-06 20:52:59 +01003571 Returns 0 on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003572
3573 Can also be used as a |method|: >
3574 GetFuncname()->funcref([arg])
3575<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003576 Return type: func(...): any or |Number| on error
3577
Dominique Pellee764d1b2023-03-12 21:20:59 +00003578 *function()* *partial* *E700* *E923*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003579function({name} [, {arglist}] [, {dict}])
3580 Return a |Funcref| variable that refers to function {name}.
3581 {name} can be the name of a user defined function or an
3582 internal function.
3583
3584 {name} can also be a Funcref or a partial. When it is a
3585 partial the dict stored in it will be used and the {dict}
3586 argument is not allowed. E.g.: >
3587 let FuncWithArg = function(dict.Func, [arg])
3588 let Broken = function(dict.Func, [arg], dict)
3589<
3590 When using the Funcref the function will be found by {name},
3591 also when it was redefined later. Use |funcref()| to keep the
3592 same function.
3593
3594 When {arglist} or {dict} is present this creates a partial.
3595 That means the argument list and/or the dictionary is stored in
3596 the Funcref and will be used when the Funcref is called.
3597
3598 The arguments are passed to the function in front of other
3599 arguments, but after any argument from |method|. Example: >
3600 func Callback(arg1, arg2, name)
3601 ...
3602 let Partial = function('Callback', ['one', 'two'])
3603 ...
3604 call Partial('name')
3605< Invokes the function as with: >
3606 call Callback('one', 'two', 'name')
3607
3608< With a |method|: >
3609 func Callback(one, two, three)
3610 ...
3611 let Partial = function('Callback', ['two'])
3612 ...
3613 eval 'one'->Partial('three')
3614< Invokes the function as with: >
3615 call Callback('one', 'two', 'three')
3616
3617< The function() call can be nested to add more arguments to the
3618 Funcref. The extra arguments are appended to the list of
3619 arguments. Example: >
3620 func Callback(arg1, arg2, name)
Bram Moolenaar0daafaa2022-09-04 17:45:43 +01003621 "...
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003622 let Func = function('Callback', ['one'])
3623 let Func2 = function(Func, ['two'])
Bram Moolenaar0daafaa2022-09-04 17:45:43 +01003624 "...
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003625 call Func2('name')
3626< Invokes the function as with: >
3627 call Callback('one', 'two', 'name')
3628
3629< The Dictionary is only useful when calling a "dict" function.
3630 In that case the {dict} is passed in as "self". Example: >
3631 function Callback() dict
Bram Moolenaarc51cf032022-02-26 12:25:45 +00003632 echo "called for " .. self.name
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003633 endfunction
Bram Moolenaar0daafaa2022-09-04 17:45:43 +01003634 "...
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003635 let context = {"name": "example"}
3636 let Func = function('Callback', context)
Bram Moolenaar0daafaa2022-09-04 17:45:43 +01003637 "...
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003638 call Func() " will echo: called for example
3639< The use of function() is not needed when there are no extra
Bram Moolenaar0daafaa2022-09-04 17:45:43 +01003640 arguments, these two are equivalent, if Callback() is defined
3641 as context.Callback(): >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003642 let Func = function('Callback', context)
3643 let Func = context.Callback
3644
3645< The argument list and the Dictionary can be combined: >
3646 function Callback(arg1, count) dict
Bram Moolenaar0daafaa2022-09-04 17:45:43 +01003647 "...
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003648 let context = {"name": "example"}
3649 let Func = function('Callback', ['one'], context)
Bram Moolenaar0daafaa2022-09-04 17:45:43 +01003650 "...
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003651 call Func(500)
3652< Invokes the function as with: >
3653 call context.Callback('one', 500)
3654<
Bram Moolenaar016188f2022-06-06 20:52:59 +01003655 Returns 0 on error.
3656
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003657 Can also be used as a |method|: >
3658 GetFuncname()->function([arg])
3659
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003660<
3661 Return type: func(...): any or |Number| on error
3662
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003663
3664garbagecollect([{atexit}]) *garbagecollect()*
3665 Cleanup unused |Lists|, |Dictionaries|, |Channels| and |Jobs|
3666 that have circular references.
3667
3668 There is hardly ever a need to invoke this function, as it is
3669 automatically done when Vim runs out of memory or is waiting
3670 for the user to press a key after 'updatetime'. Items without
3671 circular references are always freed when they become unused.
3672 This is useful if you have deleted a very big |List| and/or
3673 |Dictionary| with circular references in a script that runs
3674 for a long time.
3675
3676 When the optional {atexit} argument is one, garbage
3677 collection will also be done when exiting Vim, if it wasn't
3678 done before. This is useful when checking for memory leaks.
3679
3680 The garbage collection is not done immediately but only when
3681 it's safe to perform. This is when waiting for the user to
3682 type a character. To force garbage collection immediately use
3683 |test_garbagecollect_now()|.
3684
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003685 Return type: |String|
3686
3687
LemonBoy48b7d052024-07-09 18:24:59 +02003688get({list}, {idx} [, {default}]) *get()* *get()-list*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003689 Get item {idx} from |List| {list}. When this item is not
3690 available return {default}. Return zero when {default} is
3691 omitted.
3692 Preferably used as a |method|: >
3693 mylist->get(idx)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003694<
3695 Return type: any, depending on {list}
3696
Yegappan Lakshmanan9cb865e2025-03-23 16:42:16 +01003697get({tuple}, {idx} [, {default}]) *get()-tuple*
3698 Get item {idx} from |Tuple| {tuple}. When this item is not
3699 available return {default}. Return zero when {default} is
3700 omitted.
3701 Preferably used as a |method|: >
3702 mytuple->get(idx)
3703<
3704 Return type: any, depending on {tuple}
3705
LemonBoy48b7d052024-07-09 18:24:59 +02003706get({blob}, {idx} [, {default}]) *get()-blob*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003707 Get byte {idx} from |Blob| {blob}. When this byte is not
3708 available return {default}. Return -1 when {default} is
3709 omitted.
3710 Preferably used as a |method|: >
3711 myblob->get(idx)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003712<
3713 Return type: |Number|
3714
LemonBoy48b7d052024-07-09 18:24:59 +02003715get({dict}, {key} [, {default}]) *get()-dict*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003716 Get item with key {key} from |Dictionary| {dict}. When this
3717 item is not available return {default}. Return zero when
3718 {default} is omitted. Useful example: >
3719 let val = get(g:, 'var_name', 'default')
3720< This gets the value of g:var_name if it exists, and uses
3721 'default' when it does not exist.
3722 Preferably used as a |method|: >
3723 mydict->get(key)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003724<
h-east84ac2122024-06-17 18:12:30 +02003725 Return type: any, depending on {dict}
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003726
LemonBoy48b7d052024-07-09 18:24:59 +02003727get({func}, {what}) *get()-func*
3728 Get item {what} from |Funcref| {func}. Possible values for
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003729 {what} are:
LemonBoy48b7d052024-07-09 18:24:59 +02003730 "name" The function name
3731 "func" The function
3732 "dict" The dictionary
3733 "args" The list with arguments
3734 "arity" A dictionary with information about the number of
3735 arguments accepted by the function (minus the
3736 {arglist}) with the following fields:
3737 required the number of positional arguments
3738 optional the number of optional arguments,
3739 in addition to the required ones
3740 varargs |TRUE| if the function accepts a
3741 variable number of arguments |...|
3742
3743 Note: There is no error, if the {arglist} of
3744 the Funcref contains more arguments than the
3745 Funcref expects, it's not validated.
3746
Bram Moolenaar016188f2022-06-06 20:52:59 +01003747 Returns zero on error.
LemonBoy48b7d052024-07-09 18:24:59 +02003748
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003749 Preferably used as a |method|: >
3750 myfunc->get(what)
3751<
LemonBoy48b7d052024-07-09 18:24:59 +02003752 Return type: any, depending on {func} and {what}
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003753
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003754 *getbufinfo()*
3755getbufinfo([{buf}])
3756getbufinfo([{dict}])
3757 Get information about buffers as a List of Dictionaries.
3758
3759 Without an argument information about all the buffers is
3760 returned.
3761
3762 When the argument is a |Dictionary| only the buffers matching
3763 the specified criteria are returned. The following keys can
3764 be specified in {dict}:
3765 buflisted include only listed buffers.
3766 bufloaded include only loaded buffers.
3767 bufmodified include only modified buffers.
3768
3769 Otherwise, {buf} specifies a particular buffer to return
3770 information for. For the use of {buf}, see |bufname()|
3771 above. If the buffer is found the returned List has one item.
3772 Otherwise the result is an empty list.
3773
3774 Each returned List item is a dictionary with the following
3775 entries:
3776 bufnr Buffer number.
3777 changed TRUE if the buffer is modified.
3778 changedtick Number of changes made to the buffer.
Sean Dewar1fb41032023-08-16 17:15:05 +01003779 command TRUE if the buffer belongs to the
3780 command-line window |cmdwin|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003781 hidden TRUE if the buffer is hidden.
3782 lastused Timestamp in seconds, like
3783 |localtime()|, when the buffer was
3784 last used.
3785 {only with the |+viminfo| feature}
3786 listed TRUE if the buffer is listed.
3787 lnum Line number used for the buffer when
3788 opened in the current window.
3789 Only valid if the buffer has been
3790 displayed in the window in the past.
3791 If you want the line number of the
3792 last known cursor position in a given
3793 window, use |line()|: >
3794 :echo line('.', {winid})
3795<
3796 linecount Number of lines in the buffer (only
3797 valid when loaded)
3798 loaded TRUE if the buffer is loaded.
3799 name Full path to the file in the buffer.
3800 signs List of signs placed in the buffer.
3801 Each list item is a dictionary with
3802 the following fields:
3803 id sign identifier
3804 lnum line number
3805 name sign name
3806 variables A reference to the dictionary with
3807 buffer-local variables.
3808 windows List of |window-ID|s that display this
3809 buffer
3810 popups List of popup |window-ID|s that
3811 display this buffer
3812
3813 Examples: >
3814 for buf in getbufinfo()
3815 echo buf.name
3816 endfor
3817 for buf in getbufinfo({'buflisted':1})
3818 if buf.changed
3819 ....
3820 endif
3821 endfor
3822<
3823 To get buffer-local options use: >
3824 getbufvar({bufnr}, '&option_name')
3825<
3826 Can also be used as a |method|: >
3827 GetBufnr()->getbufinfo()
3828<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003829 Return type: list<dict<any>>
3830
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003831
3832 *getbufline()*
3833getbufline({buf}, {lnum} [, {end}])
3834 Return a |List| with the lines starting from {lnum} to {end}
3835 (inclusive) in the buffer {buf}. If {end} is omitted, a
Bram Moolenaarce30ccc2022-11-21 19:57:04 +00003836 |List| with only the line {lnum} is returned. See
3837 `getbufoneline()` for only getting the line.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003838
3839 For the use of {buf}, see |bufname()| above.
3840
3841 For {lnum} and {end} "$" can be used for the last line of the
3842 buffer. Otherwise a number must be used.
3843
3844 When {lnum} is smaller than 1 or bigger than the number of
3845 lines in the buffer, an empty |List| is returned.
3846
3847 When {end} is greater than the number of lines in the buffer,
3848 it is treated as {end} is set to the number of lines in the
3849 buffer. When {end} is before {lnum} an empty |List| is
3850 returned.
3851
3852 This function works only for loaded buffers. For unloaded and
3853 non-existing buffers, an empty |List| is returned.
3854
3855 Example: >
3856 :let lines = getbufline(bufnr("myfile"), 1, "$")
3857
3858< Can also be used as a |method|: >
3859 GetBufnr()->getbufline(lnum)
Bram Moolenaarce30ccc2022-11-21 19:57:04 +00003860<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003861 Return type: list<string>
3862
Bram Moolenaarce30ccc2022-11-21 19:57:04 +00003863 *getbufoneline()*
3864getbufoneline({buf}, {lnum})
3865 Just like `getbufline()` but only get one line and return it
3866 as a string.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003867
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003868 Return type: |String|
3869
3870
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003871getbufvar({buf}, {varname} [, {def}]) *getbufvar()*
3872 The result is the value of option or local buffer variable
3873 {varname} in buffer {buf}. Note that the name without "b:"
3874 must be used.
3875 The {varname} argument is a string.
3876 When {varname} is empty returns a |Dictionary| with all the
3877 buffer-local variables.
3878 When {varname} is equal to "&" returns a |Dictionary| with all
3879 the buffer-local options.
3880 Otherwise, when {varname} starts with "&" returns the value of
3881 a buffer-local option.
3882 This also works for a global or buffer-local option, but it
3883 doesn't work for a global variable, window-local variable or
3884 window-local option.
3885 For the use of {buf}, see |bufname()| above.
3886 When the buffer or variable doesn't exist {def} or an empty
3887 string is returned, there is no error message.
3888 Examples: >
3889 :let bufmodified = getbufvar(1, "&mod")
Bram Moolenaarc51cf032022-02-26 12:25:45 +00003890 :echo "todo myvar = " .. getbufvar("todo", "myvar")
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003891
3892< Can also be used as a |method|: >
3893 GetBufnr()->getbufvar(varname)
3894<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003895 Return type: any, depending on {varname}
3896
3897
mikoto20001083cae2024-11-11 21:24:14 +01003898getcellpixels() *getcellpixels()*
3899 Returns a |List| of terminal cell pixel size.
h-eastb534e802024-12-03 20:37:52 +01003900 List format is [xpixel, ypixel].
mikoto2000a73dfc22024-11-18 21:12:21 +01003901
3902 Only works on Unix (terminal and gVim) and Windows (gVim only).
3903 Returns [] on other systems or on failure.
3904 Note that there could be variations across different terminals.
3905 On macOS, system Terminal.app returns sizes in points (before
3906 Retina scaling), whereas third-party terminals return raw pixel
3907 sizes (post Retina scaling).
mikoto20001083cae2024-11-11 21:24:14 +01003908
mikoto2000de094dc2024-11-14 22:13:48 +01003909 Return type: list<any>
mikoto20001083cae2024-11-11 21:24:14 +01003910
3911
Kota Kato66bb9ae2023-01-17 18:31:56 +00003912getcellwidths() *getcellwidths()*
3913 Returns a |List| of cell widths of character ranges overridden
3914 by |setcellwidths()|. The format is equal to the argument of
3915 |setcellwidths()|. If no character ranges have their cell
3916 widths overridden, an empty List is returned.
h-east84ac2122024-06-17 18:12:30 +02003917
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003918 Return type: list<any>
Kota Kato66bb9ae2023-01-17 18:31:56 +00003919
3920
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003921getchangelist([{buf}]) *getchangelist()*
3922 Returns the |changelist| for the buffer {buf}. For the use
3923 of {buf}, see |bufname()| above. If buffer {buf} doesn't
3924 exist, an empty list is returned.
3925
3926 The returned list contains two entries: a list with the change
3927 locations and the current position in the list. Each
3928 entry in the change list is a dictionary with the following
3929 entries:
3930 col column number
3931 coladd column offset for 'virtualedit'
3932 lnum line number
3933 If buffer {buf} is the current buffer, then the current
3934 position refers to the position in the list. For other
3935 buffers, it is set to the length of the list.
3936
3937 Can also be used as a |method|: >
3938 GetBufnr()->getchangelist()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003939<
3940 Return type: list<any>
3941
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003942
zeertzjqe0a2ab32025-02-02 09:14:35 +01003943getchar([{expr} [, {opts}]]) *getchar()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003944 Get a single character from the user or input stream.
zeertzjqe0a2ab32025-02-02 09:14:35 +01003945 If {expr} is omitted or is -1, wait until a character is
3946 available.
Doug Kearns9cd9e752024-04-07 17:42:17 +02003947 If {expr} is 0, only get a character when one is available.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003948 Return zero otherwise.
Doug Kearns9cd9e752024-04-07 17:42:17 +02003949 If {expr} is 1, only check if a character is available, it is
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003950 not consumed. Return zero if no character available.
zeertzjqe0a2ab32025-02-02 09:14:35 +01003951 If you prefer always getting a string use |getcharstr()|, or
3952 specify |FALSE| as "number" in {opts}.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003953
Doug Kearns9cd9e752024-04-07 17:42:17 +02003954 Without {expr} and when {expr} is 0 a whole character or
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003955 special key is returned. If it is a single character, the
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01003956 result is a Number. Use |nr2char()| to convert it to a String.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003957 Otherwise a String is returned with the encoded character.
3958 For a special key it's a String with a sequence of bytes
3959 starting with 0x80 (decimal: 128). This is the same value as
3960 the String "\<Key>", e.g., "\<Left>". The returned value is
3961 also a String when a modifier (shift, control, alt) was used
zeertzjqe0a2ab32025-02-02 09:14:35 +01003962 that is not included in the character. |keytrans()| can also
3963 be used to convert a returned String into a readable form.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003964
Doug Kearns9cd9e752024-04-07 17:42:17 +02003965 When {expr} is 0 and Esc is typed, there will be a short delay
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003966 while Vim waits to see if this is the start of an escape
3967 sequence.
3968
Doug Kearns9cd9e752024-04-07 17:42:17 +02003969 When {expr} is 1 only the first byte is returned. For a
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003970 one-byte character it is the character itself as a number.
3971 Use nr2char() to convert it to a String.
3972
3973 Use getcharmod() to obtain any additional modifiers.
3974
zeertzjqe0a2ab32025-02-02 09:14:35 +01003975 The optional argument {opts} is a Dict and supports the
3976 following items:
3977
zeertzjqedf0f7d2025-02-02 19:01:01 +01003978 cursor A String specifying cursor behavior
3979 when waiting for a character.
3980 "hide": hide the cursor.
3981 "keep": keep current cursor unchanged.
3982 "msg": move cursor to message area.
3983 (default: "msg")
3984
zeertzjqe0a2ab32025-02-02 09:14:35 +01003985 number If |TRUE|, return a Number when getting
3986 a single character.
3987 If |FALSE|, the return value is always
3988 converted to a String, and an empty
3989 String (instead of 0) is returned when
3990 no character is available.
3991 (default: |TRUE|)
3992
3993 simplify If |TRUE|, include modifiers in the
3994 character if possible. E.g., return
3995 the same value for CTRL-I and <Tab>.
3996 If |FALSE|, don't include modifiers in
3997 the character.
3998 (default: |TRUE|)
3999
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004000 When the user clicks a mouse button, the mouse event will be
4001 returned. The position can then be found in |v:mouse_col|,
4002 |v:mouse_lnum|, |v:mouse_winid| and |v:mouse_win|.
4003 |getmousepos()| can also be used. Mouse move events will be
4004 ignored.
4005 This example positions the mouse as it would normally happen: >
4006 let c = getchar()
4007 if c == "\<LeftMouse>" && v:mouse_win > 0
Bram Moolenaarc51cf032022-02-26 12:25:45 +00004008 exe v:mouse_win .. "wincmd w"
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004009 exe v:mouse_lnum
Bram Moolenaarc51cf032022-02-26 12:25:45 +00004010 exe "normal " .. v:mouse_col .. "|"
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004011 endif
4012<
4013 When using bracketed paste only the first character is
4014 returned, the rest of the pasted text is dropped.
4015 |xterm-bracketed-paste|.
4016
4017 There is no prompt, you will somehow have to make clear to the
4018 user that a character has to be typed. The screen is not
4019 redrawn, e.g. when resizing the window. When using a popup
4020 window it should work better with a |popup-filter|.
4021
4022 There is no mapping for the character.
4023 Key codes are replaced, thus when the user presses the <Del>
4024 key you get the code for the <Del> key, not the raw character
4025 sequence. Examples: >
4026 getchar() == "\<Del>"
4027 getchar() == "\<S-Left>"
4028< This example redefines "f" to ignore case: >
4029 :nmap f :call FindChar()<CR>
4030 :function FindChar()
4031 : let c = nr2char(getchar())
4032 : while col('.') < col('$') - 1
4033 : normal l
4034 : if getline('.')[col('.') - 1] ==? c
4035 : break
4036 : endif
4037 : endwhile
4038 :endfunction
4039<
4040 You may also receive synthetic characters, such as
4041 |<CursorHold>|. Often you will want to ignore this and get
4042 another character: >
4043 :function GetKey()
4044 : let c = getchar()
4045 : while c == "\<CursorHold>"
4046 : let c = getchar()
4047 : endwhile
4048 : return c
4049 :endfunction
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004050<
4051 Return type: |Number| or |String|
4052
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004053
4054getcharmod() *getcharmod()*
4055 The result is a Number which is the state of the modifiers for
4056 the last obtained character with getchar() or in another way.
4057 These values are added together:
4058 2 shift
4059 4 control
4060 8 alt (meta)
4061 16 meta (when it's different from ALT)
4062 32 mouse double click
4063 64 mouse triple click
4064 96 mouse quadruple click (== 32 + 64)
Casey Tucker92e90a12024-01-25 22:44:00 +01004065 128 command (Mac) or super (GTK)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004066 Only the modifiers that have not been included in the
4067 character itself are obtained. Thus Shift-a results in "A"
Bram Moolenaar016188f2022-06-06 20:52:59 +01004068 without a modifier. Returns 0 if no modifiers are used.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004069
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004070 Return type: |Number|
4071
4072
4073getcharpos({expr}) *getcharpos()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004074 Get the position for String {expr}. Same as |getpos()| but the
4075 column number in the returned List is a character index
4076 instead of a byte index.
naohiro ono56200ee2022-01-01 14:59:44 +00004077 If |getpos()| returns a very large column number, equal to
4078 |v:maxcol|, then getcharpos() will return the character index
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004079 of the last character.
4080
4081 Example:
4082 With the cursor on '세' in line 5 with text "여보세요": >
4083 getcharpos('.') returns [0, 5, 3, 0]
4084 getpos('.') returns [0, 5, 7, 0]
4085<
4086 Can also be used as a |method|: >
4087 GetMark()->getcharpos()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004088<
4089 Return type: list<number>
4090
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004091
4092getcharsearch() *getcharsearch()*
4093 Return the current character search information as a {dict}
4094 with the following entries:
4095
4096 char character previously used for a character
4097 search (|t|, |f|, |T|, or |F|); empty string
4098 if no character search has been performed
4099 forward direction of character search; 1 for forward,
4100 0 for backward
4101 until type of character search; 1 for a |t| or |T|
4102 character search, 0 for an |f| or |F|
4103 character search
4104
4105 This can be useful to always have |;| and |,| search
4106 forward/backward regardless of the direction of the previous
4107 character search: >
4108 :nnoremap <expr> ; getcharsearch().forward ? ';' : ','
4109 :nnoremap <expr> , getcharsearch().forward ? ',' : ';'
4110< Also see |setcharsearch()|.
4111
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004112 Return type: dict<any>
4113
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004114
zeertzjqe0a2ab32025-02-02 09:14:35 +01004115getcharstr([{expr} [, {opts}]]) *getcharstr()*
4116 The same as |getchar()|, except that this always returns a
4117 String, and "number" isn't allowed in {opts}.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004118
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004119 Return type: |String|
4120
Ruslan Russkikh0407d622024-10-08 22:21:05 +02004121getcmdcomplpat() *getcmdcomplpat()*
4122 Return completion pattern of the current command-line.
4123 Only works when the command line is being edited, thus
4124 requires use of |c_CTRL-\_e| or |c_CTRL-R_=|.
4125 Also see |getcmdtype()|, |setcmdpos()|, |getcmdline()|,
4126 |getcmdprompt()|, |getcmdcompltype()| and |setcmdline()|.
4127 Returns an empty string when completion is not defined.
4128
4129 Return type: |String|
4130
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004131
Shougo Matsushita79d599b2022-05-07 12:48:29 +01004132getcmdcompltype() *getcmdcompltype()*
4133 Return the type of the current command-line completion.
4134 Only works when the command line is being edited, thus
4135 requires use of |c_CTRL-\_e| or |c_CTRL-R_=|.
Bram Moolenaar921bde82022-05-09 19:50:35 +01004136 See |:command-completion| for the return string.
Shougo Matsushita69084282024-09-23 20:34:47 +02004137 Also see |getcmdtype()|, |setcmdpos()|, |getcmdline()|,
Ruslan Russkikh0407d622024-10-08 22:21:05 +02004138 |getcmdprompt()|, |getcmdcomplpat()| and |setcmdline()|.
Shougo Matsushita79d599b2022-05-07 12:48:29 +01004139 Returns an empty string when completion is not defined.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004140
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004141 Return type: |String|
4142
4143
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004144getcmdline() *getcmdline()*
Shougo Matsushita69084282024-09-23 20:34:47 +02004145 Return the current command-line input. Only works when the
4146 command line is being edited, thus requires use of
4147 |c_CTRL-\_e| or |c_CTRL-R_=|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004148 Example: >
4149 :cmap <F7> <C-\>eescape(getcmdline(), ' \')<CR>
Shougo Matsushita69084282024-09-23 20:34:47 +02004150< Also see |getcmdtype()|, |getcmdpos()|, |setcmdpos()|,
4151 |getcmdprompt()| and |setcmdline()|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004152 Returns an empty string when entering a password or using
4153 |inputsecret()|.
4154
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004155 Return type: |String|
4156
4157
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004158getcmdpos() *getcmdpos()*
4159 Return the position of the cursor in the command line as a
4160 byte count. The first column is 1.
4161 Only works when editing the command line, thus requires use of
4162 |c_CTRL-\_e| or |c_CTRL-R_=| or an expression mapping.
4163 Returns 0 otherwise.
Shougo Matsushita69084282024-09-23 20:34:47 +02004164 Also see |getcmdtype()|, |setcmdpos()|, |getcmdline()|,
4165 |getcmdprompt()| and |setcmdline()|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004166
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004167 Return type: |Number|
4168
4169
Shougo Matsushita69084282024-09-23 20:34:47 +02004170getcmdprompt() *getcmdprompt()*
4171 Return the current command-line prompt when using functions
4172 like |input()| or |confirm()|.
4173 Only works when the command line is being edited, thus
4174 requires use of |c_CTRL-\_e| or |c_CTRL-R_=|.
4175 Also see |getcmdtype()|, |getcmdline()|, |getcmdpos()|,
4176 |setcmdpos()| and |setcmdline()|.
4177
4178 Return type: |String|
4179
4180
Shougo Matsushita79d599b2022-05-07 12:48:29 +01004181getcmdscreenpos() *getcmdscreenpos()*
4182 Return the screen position of the cursor in the command line
4183 as a byte count. The first column is 1.
4184 Instead of |getcmdpos()|, it adds the prompt position.
4185 Only works when editing the command line, thus requires use of
4186 |c_CTRL-\_e| or |c_CTRL-R_=| or an expression mapping.
4187 Returns 0 otherwise.
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01004188 Also see |getcmdpos()|, |setcmdpos()|, |getcmdline()| and
4189 |setcmdline()|.
Shougo Matsushita79d599b2022-05-07 12:48:29 +01004190
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004191 Return type: |Number|
4192
4193
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004194getcmdtype() *getcmdtype()*
4195 Return the current command-line type. Possible return values
4196 are:
4197 : normal Ex command
4198 > debug mode command |debug-mode|
4199 / forward search command
4200 ? backward search command
4201 @ |input()| command
4202 - |:insert| or |:append| command
4203 = |i_CTRL-R_=|
4204 Only works when editing the command line, thus requires use of
4205 |c_CTRL-\_e| or |c_CTRL-R_=| or an expression mapping.
4206 Returns an empty string otherwise.
4207 Also see |getcmdpos()|, |setcmdpos()| and |getcmdline()|.
4208
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004209 Return type: |String|
4210
4211
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004212getcmdwintype() *getcmdwintype()*
4213 Return the current |command-line-window| type. Possible return
4214 values are the same as |getcmdtype()|. Returns an empty string
4215 when not in the command-line window.
4216
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004217 Return type: |String|
4218
4219
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004220getcompletion({pat}, {type} [, {filtered}]) *getcompletion()*
4221 Return a list of command-line completion matches. The String
4222 {type} argument specifies what for. The following completion
4223 types are supported:
4224
4225 arglist file names in argument list
4226 augroup autocmd groups
4227 buffer buffer names
Bram Moolenaar6e2e2cc2022-03-14 19:24:46 +00004228 behave |:behave| suboptions
4229 breakpoint |:breakadd| and |:breakdel| suboptions
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004230 color color schemes
4231 command Ex command
4232 cmdline |cmdline-completion| result
4233 compiler compilers
4234 cscope |:cscope| suboptions
Shougo Matsushita92997dd2023-08-20 20:55:55 +02004235 custom,{func} custom completion, defined via {func}
4236 customlist,{func} custom completion, defined via {func}
zeertzjq85f36d62024-10-10 19:14:13 +02004237 diff_buffer |:diffget| and |:diffput| completion
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004238 dir directory names
LemonBoya20bf692024-07-11 22:35:53 +02004239 dir_in_path directory names in |'cdpath'|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004240 environment environment variable names
4241 event autocommand events
4242 expression Vim expression
4243 file file and directory names
4244 file_in_path file and directory names in |'path'|
4245 filetype filetype names |'filetype'|
4246 function function name
4247 help help subjects
4248 highlight highlight groups
Bram Moolenaar6e2e2cc2022-03-14 19:24:46 +00004249 history |:history| suboptions
Doug Kearns81642d92024-01-04 22:37:44 +01004250 keymap keyboard mappings
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004251 locale locale names (as output of locale -a)
4252 mapclear buffer argument
4253 mapping mapping name
4254 menu menus
4255 messages |:messages| suboptions
4256 option options
4257 packadd optional package |pack-add| names
zeertzjq5c8771b2023-01-24 12:34:03 +00004258 runtime |:runtime| completion
Yegappan Lakshmanan454ce672022-03-24 11:22:13 +00004259 scriptnames sourced script names |:scriptnames|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004260 shellcmd Shell command
zeertzjq85f36d62024-10-10 19:14:13 +02004261 shellcmdline Shell command line with filename arguments
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004262 sign |:sign| suboptions
4263 syntax syntax file names |'syntax'|
4264 syntime |:syntime| suboptions
4265 tag tags
4266 tag_listfiles tags, file names
4267 user user names
4268 var user variables
4269
4270 If {pat} is an empty string, then all the matches are
4271 returned. Otherwise only items matching {pat} are returned.
4272 See |wildcards| for the use of special characters in {pat}.
4273
4274 If the optional {filtered} flag is set to 1, then 'wildignore'
4275 is applied to filter the results. Otherwise all the matches
4276 are returned. The 'wildignorecase' option always applies.
4277
Yegappan Lakshmanane7dd0fa2022-03-22 16:06:31 +00004278 If the 'wildoptions' option contains 'fuzzy', then fuzzy
4279 matching is used to get the completion matches. Otherwise
Yegappan Lakshmanan454ce672022-03-24 11:22:13 +00004280 regular expression matching is used. Thus this function
4281 follows the user preference, what happens on the command line.
4282 If you do not want this you can make 'wildoptions' empty
4283 before calling getcompletion() and restore it afterwards.
Yegappan Lakshmanane7dd0fa2022-03-22 16:06:31 +00004284
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004285 If {type} is "cmdline", then the |cmdline-completion| result is
4286 returned. For example, to complete the possible values after
4287 a ":call" command: >
4288 echo getcompletion('call ', 'cmdline')
4289<
4290 If there are no matches, an empty list is returned. An
4291 invalid value for {type} produces an error.
4292
4293 Can also be used as a |method|: >
4294 GetPattern()->getcompletion('color')
4295<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004296 Return type: list<string>
4297
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004298 *getcurpos()*
4299getcurpos([{winid}])
4300 Get the position of the cursor. This is like getpos('.'), but
4301 includes an extra "curswant" item in the list:
4302 [0, lnum, col, off, curswant] ~
4303 The "curswant" number is the preferred column when moving the
naohiro ono56200ee2022-01-01 14:59:44 +00004304 cursor vertically. After |$| command it will be a very large
4305 number equal to |v:maxcol|. Also see |getcursorcharpos()| and
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004306 |getpos()|.
4307 The first "bufnum" item is always zero. The byte position of
4308 the cursor is returned in 'col'. To get the character
4309 position, use |getcursorcharpos()|.
4310
4311 The optional {winid} argument can specify the window. It can
4312 be the window number or the |window-ID|. The last known
4313 cursor position is returned, this may be invalid for the
4314 current value of the buffer if it is not the current window.
4315 If {winid} is invalid a list with zeroes is returned.
4316
4317 This can be used to save and restore the cursor position: >
4318 let save_cursor = getcurpos()
4319 MoveTheCursorAround
4320 call setpos('.', save_cursor)
4321< Note that this only works within the window. See
4322 |winrestview()| for restoring more state.
4323
4324 Can also be used as a |method|: >
4325 GetWinid()->getcurpos()
4326<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004327 Return type: list<number>
4328
4329
4330getcursorcharpos([{winid}]) *getcursorcharpos()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004331 Same as |getcurpos()| but the column number in the returned
4332 List is a character index instead of a byte index.
4333
4334 Example:
4335 With the cursor on '보' in line 3 with text "여보세요": >
4336 getcursorcharpos() returns [0, 3, 2, 0, 3]
4337 getcurpos() returns [0, 3, 4, 0, 3]
4338<
4339 Can also be used as a |method|: >
4340 GetWinid()->getcursorcharpos()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004341<
4342 Return type: list<number>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004343
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004344
4345getcwd([{winnr} [, {tabnr}]]) *getcwd()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004346 The result is a String, which is the name of the current
4347 working directory. 'autochdir' is ignored.
4348
4349 With {winnr} return the local current directory of this window
4350 in the current tab page. {winnr} can be the window number or
4351 the |window-ID|.
4352 If {winnr} is -1 return the name of the global working
4353 directory. See also |haslocaldir()|.
4354
4355 With {winnr} and {tabnr} return the local current directory of
4356 the window in the specified tab page. If {winnr} is -1 return
4357 the working directory of the tabpage.
4358 If {winnr} is zero use the current window, if {tabnr} is zero
4359 use the current tabpage.
4360 Without any arguments, return the actual working directory of
4361 the current window.
4362 Return an empty string if the arguments are invalid.
4363
4364 Examples: >
4365 " Get the working directory of the current window
4366 :echo getcwd()
4367 :echo getcwd(0)
4368 :echo getcwd(0, 0)
4369 " Get the working directory of window 3 in tabpage 2
4370 :echo getcwd(3, 2)
4371 " Get the global working directory
4372 :echo getcwd(-1)
4373 " Get the working directory of tabpage 3
4374 :echo getcwd(-1, 3)
4375 " Get the working directory of current tabpage
4376 :echo getcwd(-1, 0)
4377
4378< Can also be used as a |method|: >
4379 GetWinnr()->getcwd()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004380<
4381 Return type: |String|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004382
4383getenv({name}) *getenv()*
4384 Return the value of environment variable {name}. The {name}
4385 argument is a string, without a leading '$'. Example: >
4386 myHome = getenv('HOME')
4387
4388< When the variable does not exist |v:null| is returned. That
4389 is different from a variable set to an empty string, although
4390 some systems interpret the empty value as the variable being
4391 deleted. See also |expr-env|.
4392
4393 Can also be used as a |method|: >
4394 GetVarname()->getenv()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004395<
4396 Return type: |String| or |Number|
4397
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004398
4399getfontname([{name}]) *getfontname()*
4400 Without an argument returns the name of the normal font being
4401 used. Like what is used for the Normal highlight group
4402 |hl-Normal|.
4403 With an argument a check is done whether String {name} is a
4404 valid font name. If not then an empty string is returned.
4405 Otherwise the actual font name is returned, or {name} if the
4406 GUI does not support obtaining the real name.
4407 Only works when the GUI is running, thus not in your vimrc or
4408 gvimrc file. Use the |GUIEnter| autocommand to use this
4409 function just after the GUI has started.
4410 Note that the GTK GUI accepts any font name, thus checking for
4411 a valid name does not work.
4412
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004413 Return type: |String|
4414
4415
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004416getfperm({fname}) *getfperm()*
4417 The result is a String, which is the read, write, and execute
4418 permissions of the given file {fname}.
4419 If {fname} does not exist or its directory cannot be read, an
4420 empty string is returned.
4421 The result is of the form "rwxrwxrwx", where each group of
4422 "rwx" flags represent, in turn, the permissions of the owner
4423 of the file, the group the file belongs to, and other users.
4424 If a user does not have a given permission the flag for this
4425 is replaced with the string "-". Examples: >
4426 :echo getfperm("/etc/passwd")
4427 :echo getfperm(expand("~/.vimrc"))
4428< This will hopefully (from a security point of view) display
4429 the string "rw-r--r--" or even "rw-------".
4430
4431 Can also be used as a |method|: >
4432 GetFilename()->getfperm()
4433<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004434 Return type: |String|
4435
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004436 For setting permissions use |setfperm()|.
4437
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004438
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004439getfsize({fname}) *getfsize()*
4440 The result is a Number, which is the size in bytes of the
4441 given file {fname}.
4442 If {fname} is a directory, 0 is returned.
4443 If the file {fname} can't be found, -1 is returned.
4444 If the size of {fname} is too big to fit in a Number then -2
4445 is returned.
4446
4447 Can also be used as a |method|: >
4448 GetFilename()->getfsize()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004449<
4450 Return type: |Number|
4451
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004452
4453getftime({fname}) *getftime()*
4454 The result is a Number, which is the last modification time of
4455 the given file {fname}. The value is measured as seconds
4456 since 1st Jan 1970, and may be passed to strftime(). See also
4457 |localtime()| and |strftime()|.
4458 If the file {fname} can't be found -1 is returned.
4459
4460 Can also be used as a |method|: >
4461 GetFilename()->getftime()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004462<
4463 Return type: |Number|
4464
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004465
4466getftype({fname}) *getftype()*
4467 The result is a String, which is a description of the kind of
4468 file of the given file {fname}.
4469 If {fname} does not exist an empty string is returned.
4470 Here is a table over different kinds of files and their
4471 results:
4472 Normal file "file"
4473 Directory "dir"
4474 Symbolic link "link"
4475 Block device "bdev"
4476 Character device "cdev"
4477 Socket "socket"
4478 FIFO "fifo"
4479 All other "other"
4480 Example: >
4481 getftype("/home")
4482< Note that a type such as "link" will only be returned on
4483 systems that support it. On some systems only "dir" and
4484 "file" are returned. On MS-Windows a symbolic link to a
4485 directory returns "dir" instead of "link".
4486
4487 Can also be used as a |method|: >
4488 GetFilename()->getftype()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004489<
4490 Return type: |String|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004491
4492getimstatus() *getimstatus()*
4493 The result is a Number, which is |TRUE| when the IME status is
Bram Moolenaar016188f2022-06-06 20:52:59 +01004494 active and |FALSE| otherwise.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004495 See 'imstatusfunc'.
4496
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004497 Return type: |Number|
4498
4499
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004500getjumplist([{winnr} [, {tabnr}]]) *getjumplist()*
4501 Returns the |jumplist| for the specified window.
4502
4503 Without arguments use the current window.
4504 With {winnr} only use this window in the current tab page.
4505 {winnr} can also be a |window-ID|.
4506 With {winnr} and {tabnr} use the window in the specified tab
Bram Moolenaar016188f2022-06-06 20:52:59 +01004507 page. If {winnr} or {tabnr} is invalid, an empty list is
4508 returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004509
4510 The returned list contains two entries: a list with the jump
4511 locations and the last used jump position number in the list.
4512 Each entry in the jump location list is a dictionary with
4513 the following entries:
4514 bufnr buffer number
4515 col column number
4516 coladd column offset for 'virtualedit'
4517 filename filename if available
4518 lnum line number
4519
4520 Can also be used as a |method|: >
4521 GetWinnr()->getjumplist()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004522<
4523 Return type: list<any>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004524
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004525 *getline()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004526getline({lnum} [, {end}])
4527 Without {end} the result is a String, which is line {lnum}
4528 from the current buffer. Example: >
4529 getline(1)
4530< When {lnum} is a String that doesn't start with a
4531 digit, |line()| is called to translate the String into a Number.
4532 To get the line under the cursor: >
4533 getline(".")
4534< When {lnum} is a number smaller than 1 or bigger than the
4535 number of lines in the buffer, an empty string is returned.
4536
4537 When {end} is given the result is a |List| where each item is
4538 a line from the current buffer in the range {lnum} to {end},
4539 including line {end}.
4540 {end} is used in the same way as {lnum}.
4541 Non-existing lines are silently omitted.
4542 When {end} is before {lnum} an empty |List| is returned.
4543 Example: >
4544 :let start = line('.')
4545 :let end = search("^$") - 1
4546 :let lines = getline(start, end)
4547
4548< Can also be used as a |method|: >
4549 ComputeLnum()->getline()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004550<
4551 Return type: list<string> or |String| depending on {end}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004552
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004553 To get lines from another buffer see |getbufline()| and
Bram Moolenaarce30ccc2022-11-21 19:57:04 +00004554 |getbufoneline()|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004555
4556getloclist({nr} [, {what}]) *getloclist()*
4557 Returns a |List| with all the entries in the location list for
4558 window {nr}. {nr} can be the window number or the |window-ID|.
4559 When {nr} is zero the current window is used.
4560
4561 For a location list window, the displayed location list is
4562 returned. For an invalid window number {nr}, an empty list is
4563 returned. Otherwise, same as |getqflist()|.
4564
4565 If the optional {what} dictionary argument is supplied, then
4566 returns the items listed in {what} as a dictionary. Refer to
4567 |getqflist()| for the supported items in {what}.
4568
4569 In addition to the items supported by |getqflist()| in {what},
4570 the following item is supported by |getloclist()|:
4571
4572 filewinid id of the window used to display files
4573 from the location list. This field is
4574 applicable only when called from a
4575 location list window. See
4576 |location-list-file-window| for more
4577 details.
4578
4579 Returns a |Dictionary| with default values if there is no
4580 location list for the window {nr}.
4581 Returns an empty Dictionary if window {nr} does not exist.
4582
4583 Examples (See also |getqflist-examples|): >
4584 :echo getloclist(3, {'all': 0})
4585 :echo getloclist(5, {'filewinid': 0})
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004586<
4587 Return type: list<dict<any>> or list<any>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004588
4589
4590getmarklist([{buf}]) *getmarklist()*
4591 Without the {buf} argument returns a |List| with information
4592 about all the global marks. |mark|
4593
4594 If the optional {buf} argument is specified, returns the
4595 local marks defined in buffer {buf}. For the use of {buf},
Bram Moolenaar016188f2022-06-06 20:52:59 +01004596 see |bufname()|. If {buf} is invalid, an empty list is
4597 returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004598
4599 Each item in the returned List is a |Dict| with the following:
4600 mark name of the mark prefixed by "'"
4601 pos a |List| with the position of the mark:
4602 [bufnum, lnum, col, off]
4603 Refer to |getpos()| for more information.
4604 file file name
4605
4606 Refer to |getpos()| for getting information about a specific
4607 mark.
4608
4609 Can also be used as a |method|: >
4610 GetBufnr()->getmarklist()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004611<
4612 Return type: list<dict<any>> or list<any>
4613
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004614
4615getmatches([{win}]) *getmatches()*
4616 Returns a |List| with all matches previously defined for the
4617 current window by |matchadd()| and the |:match| commands.
4618 |getmatches()| is useful in combination with |setmatches()|,
4619 as |setmatches()| can restore a list of matches saved by
4620 |getmatches()|.
4621 If {win} is specified, use the window with this number or
Bram Moolenaar016188f2022-06-06 20:52:59 +01004622 window ID instead of the current window. If {win} is invalid,
4623 an empty list is returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004624 Example: >
4625 :echo getmatches()
4626< [{'group': 'MyGroup1', 'pattern': 'TODO',
4627 'priority': 10, 'id': 1}, {'group': 'MyGroup2',
4628 'pattern': 'FIXME', 'priority': 10, 'id': 2}] >
4629 :let m = getmatches()
4630 :call clearmatches()
4631 :echo getmatches()
4632< [] >
4633 :call setmatches(m)
4634 :echo getmatches()
4635< [{'group': 'MyGroup1', 'pattern': 'TODO',
4636 'priority': 10, 'id': 1}, {'group': 'MyGroup2',
4637 'pattern': 'FIXME', 'priority': 10, 'id': 2}] >
4638 :unlet m
4639<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004640 Return type: list<dict<any>> or list<any>
4641
4642
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004643getmousepos() *getmousepos()*
4644 Returns a |Dictionary| with the last known position of the
4645 mouse. This can be used in a mapping for a mouse click or in
4646 a filter of a popup window. The items are:
4647 screenrow screen row
4648 screencol screen column
4649 winid Window ID of the click
4650 winrow row inside "winid"
4651 wincol column inside "winid"
4652 line text line inside "winid"
4653 column text column inside "winid"
zeertzjqf5a94d52023-10-15 10:03:30 +02004654 coladd offset (in screen columns) from the
4655 start of the clicked char
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004656 All numbers are 1-based.
4657
4658 If not over a window, e.g. when in the command line, then only
4659 "screenrow" and "screencol" are valid, the others are zero.
4660
4661 When on the status line below a window or the vertical
4662 separator right of a window, the "line" and "column" values
4663 are zero.
4664
4665 When the position is after the text then "column" is the
4666 length of the text in bytes plus one.
4667
4668 If the mouse is over a popup window then that window is used.
4669
4670 When using |getchar()| the Vim variables |v:mouse_lnum|,
4671 |v:mouse_col| and |v:mouse_winid| also provide these values.
4672
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004673 Return type: dict<number>
4674
4675
Bram Moolenaar24dc19c2022-11-14 19:49:15 +00004676getmouseshape() *getmouseshape()*
4677 Returns the name of the currently showing mouse pointer.
4678 When the |+mouseshape| feature is not supported or the shape
4679 is unknown an empty string is returned.
4680 This function is mainly intended for testing.
4681
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004682 Return type: |String|
4683
4684
4685getpid() *getpid()*
4686 Return a Number which is the process ID of the Vim process.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004687 On Unix and MS-Windows this is a unique number, until Vim
4688 exits.
4689
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004690 Return type: |Number|
4691
4692
4693getpos({expr}) *getpos()*
zeertzjq02f3eba2024-06-12 20:45:24 +02004694 Get the position for String {expr}.
4695 The accepted values for {expr} are: *E1209*
4696 . The cursor position.
4697 $ The last line in the current buffer.
4698 'x Position of mark x (if the mark is not set, 0 is
zeertzjqd353d272024-06-13 23:00:25 +08004699 returned for all values).
zeertzjq02f3eba2024-06-12 20:45:24 +02004700 w0 First line visible in current window (one if the
4701 display isn't updated, e.g. in silent Ex mode).
4702 w$ Last line visible in current window (this is one
4703 less than "w0" if no lines are visible).
4704 v When not in Visual mode, returns the cursor
4705 position. In Visual mode, returns the other end
4706 of the Visual area. A good way to think about
4707 this is that in Visual mode "v" and "." complement
4708 each other. While "." refers to the cursor
4709 position, "v" refers to where |v_o| would move the
4710 cursor. As a result, you can use "v" and "."
4711 together to work on all of a selection in
4712 characterwise Visual mode. If the cursor is at
4713 the end of a characterwise Visual area, "v" refers
4714 to the start of the same Visual area. And if the
4715 cursor is at the start of a characterwise Visual
4716 area, "v" refers to the end of the same Visual
4717 area. "v" differs from |'<| and |'>| in that it's
4718 updated right away.
4719 Note that a mark in another file can be used. The line number
4720 then applies to another buffer.
4721
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004722 The result is a |List| with four numbers:
4723 [bufnum, lnum, col, off]
4724 "bufnum" is zero, unless a mark like '0 or 'A is used, then it
4725 is the buffer number of the mark.
4726 "lnum" and "col" are the position in the buffer. The first
4727 column is 1.
4728 The "off" number is zero, unless 'virtualedit' is used. Then
4729 it is the offset in screen columns from the start of the
4730 character. E.g., a position within a <Tab> or after the last
4731 character.
zeertzjq02f3eba2024-06-12 20:45:24 +02004732
4733 For getting the cursor position see |getcurpos()|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004734 The column number in the returned List is the byte position
4735 within the line. To get the character position in the line,
4736 use |getcharpos()|.
zeertzjq02f3eba2024-06-12 20:45:24 +02004737
4738 Note that for '< and '> Visual mode matters: when it is "V"
4739 (visual line mode) the column of '< is zero and the column of
4740 '> is a large number equal to |v:maxcol|.
naohiro ono56200ee2022-01-01 14:59:44 +00004741 A very large column number equal to |v:maxcol| can be returned,
4742 in which case it means "after the end of the line".
Bram Moolenaar016188f2022-06-06 20:52:59 +01004743 If {expr} is invalid, returns a list with all zeros.
zeertzjq02f3eba2024-06-12 20:45:24 +02004744
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004745 This can be used to save and restore the position of a mark: >
4746 let save_a_mark = getpos("'a")
4747 ...
4748 call setpos("'a", save_a_mark)
zeertzjqd353d272024-06-13 23:00:25 +08004749<
4750 Also see |getcharpos()|, |getcurpos()| and |setpos()|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004751
4752 Can also be used as a |method|: >
4753 GetMark()->getpos()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004754<
4755 Return type: list<number>
4756
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004757
4758getqflist([{what}]) *getqflist()*
4759 Returns a |List| with all the current quickfix errors. Each
4760 list item is a dictionary with these entries:
4761 bufnr number of buffer that has the file name, use
4762 bufname() to get the name
4763 module module name
4764 lnum line number in the buffer (first line is 1)
4765 end_lnum
4766 end of line number if the item is multiline
4767 col column number (first column is 1)
4768 end_col end of column number if the item has range
4769 vcol |TRUE|: "col" is visual column
4770 |FALSE|: "col" is byte index
4771 nr error number
h-east84ac2122024-06-17 18:12:30 +02004772 pattern search pattern used to locate the error
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004773 text description of the error
4774 type type of the error, 'E', '1', etc.
4775 valid |TRUE|: recognized error message
h_east596a9f22023-11-21 21:24:23 +09004776 user_data
4777 custom data associated with the item, can be
Tom Praschanca6ac992023-08-11 23:26:12 +02004778 any type.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004779
4780 When there is no error list or it's empty, an empty list is
4781 returned. Quickfix list entries with a non-existing buffer
4782 number are returned with "bufnr" set to zero (Note: some
4783 functions accept buffer number zero for the alternate buffer,
4784 you may need to explicitly check for zero).
4785
4786 Useful application: Find pattern matches in multiple files and
4787 do something with them: >
4788 :vimgrep /theword/jg *.c
4789 :for d in getqflist()
4790 : echo bufname(d.bufnr) ':' d.lnum '=' d.text
4791 :endfor
4792<
4793 If the optional {what} dictionary argument is supplied, then
4794 returns only the items listed in {what} as a dictionary. The
4795 following string items are supported in {what}:
4796 changedtick get the total number of changes made
4797 to the list |quickfix-changedtick|
4798 context get the |quickfix-context|
4799 efm errorformat to use when parsing "lines". If
4800 not present, then the 'errorformat' option
4801 value is used.
4802 id get information for the quickfix list with
4803 |quickfix-ID|; zero means the id for the
4804 current list or the list specified by "nr"
4805 idx get information for the quickfix entry at this
4806 index in the list specified by 'id' or 'nr'.
4807 If set to zero, then uses the current entry.
4808 See |quickfix-index|
4809 items quickfix list entries
4810 lines parse a list of lines using 'efm' and return
4811 the resulting entries. Only a |List| type is
4812 accepted. The current quickfix list is not
4813 modified. See |quickfix-parse|.
4814 nr get information for this quickfix list; zero
4815 means the current quickfix list and "$" means
4816 the last quickfix list
4817 qfbufnr number of the buffer displayed in the quickfix
4818 window. Returns 0 if the quickfix buffer is
4819 not present. See |quickfix-buffer|.
4820 size number of entries in the quickfix list
4821 title get the list title |quickfix-title|
4822 winid get the quickfix |window-ID|
4823 all all of the above quickfix properties
4824 Non-string items in {what} are ignored. To get the value of a
4825 particular item, set it to zero.
4826 If "nr" is not present then the current quickfix list is used.
4827 If both "nr" and a non-zero "id" are specified, then the list
4828 specified by "id" is used.
4829 To get the number of lists in the quickfix stack, set "nr" to
4830 "$" in {what}. The "nr" value in the returned dictionary
4831 contains the quickfix stack size.
4832 When "lines" is specified, all the other items except "efm"
4833 are ignored. The returned dictionary contains the entry
4834 "items" with the list of entries.
4835
4836 The returned dictionary contains the following entries:
4837 changedtick total number of changes made to the
4838 list |quickfix-changedtick|
4839 context quickfix list context. See |quickfix-context|
4840 If not present, set to "".
4841 id quickfix list ID |quickfix-ID|. If not
4842 present, set to 0.
4843 idx index of the quickfix entry in the list. If not
4844 present, set to 0.
4845 items quickfix list entries. If not present, set to
4846 an empty list.
4847 nr quickfix list number. If not present, set to 0
4848 qfbufnr number of the buffer displayed in the quickfix
4849 window. If not present, set to 0.
4850 size number of entries in the quickfix list. If not
4851 present, set to 0.
4852 title quickfix list title text. If not present, set
4853 to "".
4854 winid quickfix |window-ID|. If not present, set to 0
4855
4856 Examples (See also |getqflist-examples|): >
4857 :echo getqflist({'all': 1})
4858 :echo getqflist({'nr': 2, 'title': 1})
4859 :echo getqflist({'lines' : ["F1:10:L10"]})
4860<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004861 Return type: list<dict<any>> or list<any>
4862
4863
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004864getreg([{regname} [, 1 [, {list}]]]) *getreg()*
4865 The result is a String, which is the contents of register
4866 {regname}. Example: >
4867 :let cliptext = getreg('*')
4868< When register {regname} was not set the result is an empty
4869 string.
Bram Moolenaara2baa732022-02-04 16:09:54 +00004870 The {regname} argument must be a string. *E1162*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004871
4872 getreg('=') returns the last evaluated value of the expression
4873 register. (For use in maps.)
4874 getreg('=', 1) returns the expression itself, so that it can
4875 be restored with |setreg()|. For other registers the extra
4876 argument is ignored, thus you can always give it.
4877
4878 If {list} is present and |TRUE|, the result type is changed
4879 to |List|. Each list item is one text line. Use it if you care
4880 about zero bytes possibly present inside register: without
4881 third argument both NLs and zero bytes are represented as NLs
4882 (see |NL-used-for-Nul|).
4883 When the register was not set an empty list is returned.
4884
4885 If {regname} is "", the unnamed register '"' is used.
4886 If {regname} is not specified, |v:register| is used.
4887 In |Vim9-script| {regname} must be one character.
4888
4889 Can also be used as a |method|: >
4890 GetRegname()->getreg()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004891<
4892 Return type: |String|
4893
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004894
4895getreginfo([{regname}]) *getreginfo()*
4896 Returns detailed information about register {regname} as a
4897 Dictionary with the following entries:
4898 regcontents List of lines contained in register
4899 {regname}, like
4900 |getreg|({regname}, 1, 1).
4901 regtype the type of register {regname}, as in
4902 |getregtype()|.
4903 isunnamed Boolean flag, v:true if this register
4904 is currently pointed to by the unnamed
4905 register.
4906 points_to for the unnamed register, gives the
4907 single letter name of the register
4908 currently pointed to (see |quotequote|).
4909 For example, after deleting a line
4910 with `dd`, this field will be "1",
4911 which is the register that got the
4912 deleted text.
4913
4914 The {regname} argument is a string. If {regname} is invalid
4915 or not set, an empty Dictionary will be returned.
4916 If {regname} is "" or "@", the unnamed register '"' is used.
4917 If {regname} is not specified, |v:register| is used.
4918 The returned Dictionary can be passed to |setreg()|.
4919 In |Vim9-script| {regname} must be one character.
4920
4921 Can also be used as a |method|: >
4922 GetRegname()->getreginfo()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004923<
4924 Return type: dict<any>
4925
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004926
Shougo Matsushita19b71882024-02-28 22:48:12 +01004927getregion({pos1}, {pos2} [, {opts}]) *getregion()*
Shougo Matsushita84bf6e62024-03-06 21:10:18 +01004928 Returns the list of strings from {pos1} to {pos2} from a
Shougo Matsushita19b71882024-02-28 22:48:12 +01004929 buffer.
4930
4931 {pos1} and {pos2} must both be |List|s with four numbers.
Shougo Matsushita84bf6e62024-03-06 21:10:18 +01004932 See |getpos()| for the format of the list. It's possible
4933 to specify positions from a different buffer, but please
zeertzjq0df8f932024-03-07 21:40:53 +01004934 note the limitations at |getregion-notes|.
Shougo Matsushita19b71882024-02-28 22:48:12 +01004935
4936 The optional argument {opts} is a Dict and supports the
4937 following items:
4938
zeertzjqafc22952024-05-24 19:07:12 +02004939 type Specify the region's selection type.
4940 See |getregtype()| for possible values,
zeertzjqdff55a32024-05-25 10:25:36 +02004941 except that the width can be omitted
4942 and an empty string cannot be used.
zeertzjqafc22952024-05-24 19:07:12 +02004943 (default: "v")
Shougo Matsushita19b71882024-02-28 22:48:12 +01004944
zeertzjq87410ab2024-03-02 06:00:23 +08004945 exclusive If |TRUE|, use exclusive selection
zeertzjqafc22952024-05-24 19:07:12 +02004946 for the end position.
zeertzjq87410ab2024-03-02 06:00:23 +08004947 (default: follow 'selection')
Shougo Matsushita19b71882024-02-28 22:48:12 +01004948
Shougo Matsushita3f905ab2024-02-21 00:02:45 +01004949 You can get the last selection type by |visualmode()|.
4950 If Visual mode is active, use |mode()| to get the Visual mode
4951 (e.g., in a |:vmap|).
zeertzjq87410ab2024-03-02 06:00:23 +08004952 This function is useful to get text starting and ending in
4953 different columns, such as a |characterwise-visual| selection.
Shougo Matsushita3f905ab2024-02-21 00:02:45 +01004954
Shougo Matsushita84bf6e62024-03-06 21:10:18 +01004955 *getregion-notes*
Shougo Matsushita3f905ab2024-02-21 00:02:45 +01004956 Note that:
4957 - Order of {pos1} and {pos2} doesn't matter, it will always
4958 return content from the upper left position to the lower
4959 right position.
zeertzjq87410ab2024-03-02 06:00:23 +08004960 - If 'virtualedit' is enabled and the region is past the end
4961 of the lines, resulting lines are padded with spaces.
4962 - If the region is blockwise and it starts or ends in the
4963 middle of a multi-cell character, it is not included but
4964 its selected part is substituted with spaces.
Shougo Matsushita84bf6e62024-03-06 21:10:18 +01004965 - If {pos1} and {pos2} are not in the same buffer, an empty
zeertzjq421b5972024-02-22 19:48:06 +01004966 list is returned.
Shougo Matsushita84bf6e62024-03-06 21:10:18 +01004967 - {pos1} and {pos2} must belong to a |bufloaded()| buffer.
zeertzjq0df8f932024-03-07 21:40:53 +01004968 - It is evaluated in current window context, which makes a
4969 difference if the buffer is displayed in a window with
4970 different 'virtualedit' or 'list' values.
Shougo Matsushita3f905ab2024-02-21 00:02:45 +01004971
4972 Examples: >
4973 :xnoremap <CR>
Shougo Matsushita19b71882024-02-28 22:48:12 +01004974 \ <Cmd>echow getregion(
4975 \ getpos('v'), getpos('.'), #{ type: mode() })<CR>
Shougo Matsushita3f905ab2024-02-21 00:02:45 +01004976<
4977 Can also be used as a |method|: >
Shougo Matsushita19b71882024-02-28 22:48:12 +01004978 getpos('.')->getregion(getpos("'a"))
zeertzjqd4d12072024-07-16 20:34:16 +02004979<
4980 Return type: list<string>
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004981
Yee Cheng Chind52fb2f2024-10-31 09:25:09 +01004982
Shougo Matsushitab4757e62024-05-07 20:49:24 +02004983getregionpos({pos1}, {pos2} [, {opts}]) *getregionpos()*
4984 Same as |getregion()|, but returns a list of positions
4985 describing the buffer text segments bound by {pos1} and
4986 {pos2}.
4987 The segments are a pair of positions for every line: >
4988 [[{start_pos}, {end_pos}], ...]
4989<
4990 The position is a |List| with four numbers:
4991 [bufnum, lnum, col, off]
4992 "bufnum" is the buffer number.
4993 "lnum" and "col" are the position in the buffer. The first
4994 column is 1.
zeertzjqc95e64f2024-05-20 14:00:31 +02004995 If the "off" number of a starting position is non-zero, it is
4996 the offset in screen columns from the start of the character.
4997 E.g., a position within a <Tab> or after the last character.
4998 If the "off" number of an ending position is non-zero, it is
zeertzjq52a6f342024-05-22 16:42:44 +02004999 the offset of the character's first cell not included in the
5000 selection, otherwise all its cells are included.
Shougo Matsushitab4757e62024-05-07 20:49:24 +02005001
zeertzjq2b09de92024-05-24 07:48:51 +02005002 Apart from the options supported by |getregion()|, {opts} also
5003 supports the following:
5004
5005 eol If |TRUE|, indicate positions beyond
5006 the end of a line with "col" values
5007 one more than the length of the line.
5008 If |FALSE|, positions are limited
5009 within their lines, and if a line is
5010 empty or the selection is entirely
5011 beyond the end of a line, a "col"
5012 value of 0 is used for both positions.
5013 (default: |FALSE|)
5014
Shougo Matsushitab4757e62024-05-07 20:49:24 +02005015 Can also be used as a |method|: >
5016 getpos('.')->getregionpos(getpos("'a"))
5017<
Christian Brabandt83d74402025-03-19 21:55:59 +01005018 For an example, see the highlight-yank plugin |52.6|
5019
zeertzjqd4d12072024-07-16 20:34:16 +02005020 Return type: list<list<list<number>>>
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005021
5022
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005023getregtype([{regname}]) *getregtype()*
5024 The result is a String, which is type of register {regname}.
5025 The value will be one of:
5026 "v" for |characterwise| text
5027 "V" for |linewise| text
5028 "<CTRL-V>{width}" for |blockwise-visual| text
5029 "" for an empty or unknown register
5030 <CTRL-V> is one character with value 0x16.
5031 The {regname} argument is a string. If {regname} is "", the
5032 unnamed register '"' is used. If {regname} is not specified,
5033 |v:register| is used.
5034 In |Vim9-script| {regname} must be one character.
5035
5036 Can also be used as a |method|: >
5037 GetRegname()->getregtype()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005038<
5039 Return type: |String|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005040
Yee Cheng Chind52fb2f2024-10-31 09:25:09 +01005041
Bram Moolenaar71badf92023-04-22 22:40:14 +01005042getscriptinfo([{opts}]) *getscriptinfo()*
Yegappan Lakshmananf768c3d2022-08-22 13:15:13 +01005043 Returns a |List| with information about all the sourced Vim
Bram Moolenaar753885b2022-08-24 16:30:36 +01005044 scripts in the order they were sourced, like what
5045 `:scriptnames` shows.
Yegappan Lakshmananf768c3d2022-08-22 13:15:13 +01005046
Yegappan Lakshmanan2f892d82022-08-28 18:52:10 +01005047 The optional Dict argument {opts} supports the following
5048 optional items:
5049 name Script name match pattern. If specified,
5050 and "sid" is not specified, information about
Bram Moolenaar71badf92023-04-22 22:40:14 +01005051 scripts with a name that match the pattern
Yegappan Lakshmanan2f892d82022-08-28 18:52:10 +01005052 "name" are returned.
5053 sid Script ID |<SID>|. If specified, only
5054 information about the script with ID "sid" is
5055 returned and "name" is ignored.
5056
Yegappan Lakshmananf768c3d2022-08-22 13:15:13 +01005057 Each item in the returned List is a |Dict| with the following
5058 items:
Yegappan Lakshmanan2f892d82022-08-28 18:52:10 +01005059 autoload Set to TRUE for a script that was used with
Bram Moolenaar753885b2022-08-24 16:30:36 +01005060 `import autoload` but was not actually sourced
5061 yet (see |import-autoload|).
Yegappan Lakshmanan2f892d82022-08-28 18:52:10 +01005062 functions List of script-local function names defined in
5063 the script. Present only when a particular
5064 script is specified using the "sid" item in
5065 {opts}.
5066 name Vim script file name.
5067 sid Script ID |<SID>|.
5068 sourced Script ID of the actually sourced script that
Bram Moolenaarfd999452022-08-24 18:30:14 +01005069 this script name links to, if any, otherwise
5070 zero
Yegappan Lakshmanan2f892d82022-08-28 18:52:10 +01005071 variables A dictionary with the script-local variables.
Bram Moolenaarf1dcd142022-12-31 15:30:45 +00005072 Present only when a particular script is
Yegappan Lakshmanan2f892d82022-08-28 18:52:10 +01005073 specified using the "sid" item in {opts}.
5074 Note that this is a copy, the value of
5075 script-local variables cannot be changed using
5076 this dictionary.
h_east59858792023-10-25 22:47:05 +09005077 version Vim script version (|scriptversion|)
Yegappan Lakshmanan520f6ef2022-08-25 17:40:40 +01005078
Yegappan Lakshmanan2f892d82022-08-28 18:52:10 +01005079 Examples: >
5080 :echo getscriptinfo({'name': 'myscript'})
zeertzjqad4881c2024-05-04 15:35:30 +08005081 :echo getscriptinfo({'sid': 15})[0].variables
Yegappan Lakshmanan2f892d82022-08-28 18:52:10 +01005082<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005083 Return type: list<dict<any>>
5084
5085
ichizok663d18d2025-01-02 18:06:00 +01005086getstacktrace() *getstacktrace()*
5087 Returns the current stack trace of Vim scripts.
5088 Stack trace is a |List|, of which each item is a |Dictionary|
5089 with the following items:
zeertzjq6655bef2025-01-06 18:32:13 +01005090 funcref The funcref if the stack is at a function,
5091 otherwise this item is omitted.
ichizok663d18d2025-01-02 18:06:00 +01005092 event The string of the event description if the
zeertzjq6655bef2025-01-06 18:32:13 +01005093 stack is at an autocmd event, otherwise this
5094 item is omitted.
5095 lnum The line number in the script on the stack.
ichizok663d18d2025-01-02 18:06:00 +01005096 filepath The file path of the script on the stack.
5097
5098 Return type: list<dict<any>>
5099
5100
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005101gettabinfo([{tabnr}]) *gettabinfo()*
5102 If {tabnr} is not specified, then information about all the
5103 tab pages is returned as a |List|. Each List item is a
5104 |Dictionary|. Otherwise, {tabnr} specifies the tab page
5105 number and information about that one is returned. If the tab
5106 page does not exist an empty List is returned.
5107
5108 Each List item is a |Dictionary| with the following entries:
5109 tabnr tab page number.
5110 variables a reference to the dictionary with
5111 tabpage-local variables
5112 windows List of |window-ID|s in the tab page.
5113
5114 Can also be used as a |method|: >
5115 GetTabnr()->gettabinfo()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005116<
5117 Return type: list<dict<any>>
5118
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005119
5120gettabvar({tabnr}, {varname} [, {def}]) *gettabvar()*
5121 Get the value of a tab-local variable {varname} in tab page
5122 {tabnr}. |t:var|
5123 Tabs are numbered starting with one.
5124 The {varname} argument is a string. When {varname} is empty a
5125 dictionary with all tab-local variables is returned.
5126 Note that the name without "t:" must be used.
5127 When the tab or variable doesn't exist {def} or an empty
5128 string is returned, there is no error message.
5129
5130 Can also be used as a |method|: >
5131 GetTabnr()->gettabvar(varname)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005132<
5133 Return type: any, depending on {varname}
5134
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005135
5136gettabwinvar({tabnr}, {winnr}, {varname} [, {def}]) *gettabwinvar()*
5137 Get the value of window-local variable {varname} in window
5138 {winnr} in tab page {tabnr}.
5139 The {varname} argument is a string. When {varname} is empty a
5140 dictionary with all window-local variables is returned.
5141 When {varname} is equal to "&" get the values of all
5142 window-local options in a |Dictionary|.
5143 Otherwise, when {varname} starts with "&" get the value of a
5144 window-local option.
5145 Note that {varname} must be the name without "w:".
5146 Tabs are numbered starting with one. For the current tabpage
5147 use |getwinvar()|.
5148 {winnr} can be the window number or the |window-ID|.
5149 When {winnr} is zero the current window is used.
5150 This also works for a global option, buffer-local option and
5151 window-local option, but it doesn't work for a global variable
5152 or buffer-local variable.
5153 When the tab, window or variable doesn't exist {def} or an
5154 empty string is returned, there is no error message.
5155 Examples: >
5156 :let list_is_on = gettabwinvar(1, 2, '&list')
Bram Moolenaarc51cf032022-02-26 12:25:45 +00005157 :echo "myvar = " .. gettabwinvar(3, 1, 'myvar')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005158<
5159 To obtain all window-local variables use: >
5160 gettabwinvar({tabnr}, {winnr}, '&')
5161
5162< Can also be used as a |method|: >
5163 GetTabnr()->gettabwinvar(winnr, varname)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005164<
5165 Return type: any, depending on {varname}
5166
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005167
5168gettagstack([{winnr}]) *gettagstack()*
5169 The result is a Dict, which is the tag stack of window {winnr}.
5170 {winnr} can be the window number or the |window-ID|.
5171 When {winnr} is not specified, the current window is used.
5172 When window {winnr} doesn't exist, an empty Dict is returned.
5173
5174 The returned dictionary contains the following entries:
5175 curidx Current index in the stack. When at
5176 top of the stack, set to (length + 1).
5177 Index of bottom of the stack is 1.
5178 items List of items in the stack. Each item
5179 is a dictionary containing the
5180 entries described below.
5181 length Number of entries in the stack.
5182
5183 Each item in the stack is a dictionary with the following
5184 entries:
5185 bufnr buffer number of the current jump
5186 from cursor position before the tag jump.
5187 See |getpos()| for the format of the
5188 returned list.
5189 matchnr current matching tag number. Used when
5190 multiple matching tags are found for a
5191 name.
5192 tagname name of the tag
5193
5194 See |tagstack| for more information about the tag stack.
5195
5196 Can also be used as a |method|: >
5197 GetWinnr()->gettagstack()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005198<
5199 Return type: dict<any>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005200
5201
Christ van Willegence0ef912024-06-20 23:41:59 +02005202gettext({text} [, {package}]) *gettext()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005203 Translate String {text} if possible.
RestorerZ96509102024-07-11 21:14:15 +02005204 This is intended for use in Vim scripts. When generating
5205 message translations the {text} is extracted by `xgettext`,
5206 the translator can add translated messages into the .po file
5207 and Vim will lookup the translation when gettext() is called.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005208 For {text} double quoted strings are preferred, because
RestorerZ96509102024-07-11 21:14:15 +02005209 `xgettext` does not support single quoted escaped text.
5210
Christ van Willegence0ef912024-06-20 23:41:59 +02005211 When the {package} is specified, the translation is looked up
RestorerZ96509102024-07-11 21:14:15 +02005212 for that specific package. This is mainly required for
5213 third-party Vim scripts. You need to specify a path to the
5214 translations with the |bindtextdomain()| function before
5215 using the gettext() function.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005216
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005217 Return type: |String|
5218
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005219
5220getwininfo([{winid}]) *getwininfo()*
5221 Returns information about windows as a |List| with Dictionaries.
5222
5223 If {winid} is given Information about the window with that ID
5224 is returned, as a |List| with one item. If the window does not
5225 exist the result is an empty list.
5226
5227 Without {winid} information about all the windows in all the
5228 tab pages is returned.
5229
5230 Each List item is a |Dictionary| with the following entries:
5231 botline last complete displayed buffer line
5232 bufnr number of buffer in the window
5233 height window height (excluding winbar)
glepnir0a850672024-11-25 19:39:04 +01005234 leftcol first column displayed; only used when
5235 'wrap' is off
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005236 loclist 1 if showing a location list
5237 {only with the +quickfix feature}
5238 quickfix 1 if quickfix or location list window
5239 {only with the +quickfix feature}
5240 terminal 1 if a terminal window
5241 {only with the +terminal feature}
5242 tabnr tab page number
5243 topline first displayed buffer line
5244 variables a reference to the dictionary with
5245 window-local variables
5246 width window width
5247 winbar 1 if the window has a toolbar, 0
5248 otherwise
5249 wincol leftmost screen column of the window;
5250 "col" from |win_screenpos()|
5251 textoff number of columns occupied by any
5252 'foldcolumn', 'signcolumn' and line
5253 number in front of the text
5254 winid |window-ID|
5255 winnr window number
5256 winrow topmost screen line of the window;
5257 "row" from |win_screenpos()|
5258
5259 Can also be used as a |method|: >
5260 GetWinnr()->getwininfo()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005261<
5262 Return type: list<dict<any>>
5263
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005264
5265getwinpos([{timeout}]) *getwinpos()*
5266 The result is a |List| with two numbers, the result of
5267 |getwinposx()| and |getwinposy()| combined:
5268 [x-pos, y-pos]
5269 {timeout} can be used to specify how long to wait in msec for
5270 a response from the terminal. When omitted 100 msec is used.
5271 Use a longer time for a remote terminal.
5272 When using a value less than 10 and no response is received
5273 within that time, a previously reported position is returned,
5274 if available. This can be used to poll for the position and
5275 do some work in the meantime: >
5276 while 1
5277 let res = getwinpos(1)
5278 if res[0] >= 0
5279 break
5280 endif
5281 " Do some work here
5282 endwhile
5283<
5284
5285 Can also be used as a |method|: >
5286 GetTimeout()->getwinpos()
5287<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005288 Return type: list<number>
5289
5290
5291getwinposx() *getwinposx()*
5292 The result is a Number, which is the X coordinate in pixels of
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005293 the left hand side of the GUI Vim window. Also works for an
5294 xterm (uses a timeout of 100 msec).
lilydjwg6e0a18f2024-01-29 20:54:28 +01005295 The result will be -1 if the information is not available
5296 (e.g. on the Wayland backend).
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005297 The value can be used with `:winpos`.
5298
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005299 Return type: |Number|
5300
5301
5302getwinposy() *getwinposy()*
5303 The result is a Number, which is the Y coordinate in pixels of
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005304 the top of the GUI Vim window. Also works for an xterm (uses
5305 a timeout of 100 msec).
lilydjwg6e0a18f2024-01-29 20:54:28 +01005306 The result will be -1 if the information is not available
5307 (e.g. on the Wayland backend).
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005308 The value can be used with `:winpos`.
5309
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005310 Return type: |Number|
5311
5312
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005313getwinvar({winnr}, {varname} [, {def}]) *getwinvar()*
5314 Like |gettabwinvar()| for the current tabpage.
5315 Examples: >
5316 :let list_is_on = getwinvar(2, '&list')
Bram Moolenaarc51cf032022-02-26 12:25:45 +00005317 :echo "myvar = " .. getwinvar(1, 'myvar')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005318
5319< Can also be used as a |method|: >
5320 GetWinnr()->getwinvar(varname)
5321<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005322 Return type: any, depending on {varname}
5323
5324
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005325glob({expr} [, {nosuf} [, {list} [, {alllinks}]]]) *glob()*
5326 Expand the file wildcards in {expr}. See |wildcards| for the
5327 use of special characters.
5328
5329 Unless the optional {nosuf} argument is given and is |TRUE|,
5330 the 'suffixes' and 'wildignore' options apply: Names matching
5331 one of the patterns in 'wildignore' will be skipped and
5332 'suffixes' affect the ordering of matches.
5333 'wildignorecase' always applies.
5334
5335 When {list} is present and it is |TRUE| the result is a |List|
5336 with all matching files. The advantage of using a List is,
5337 you also get filenames containing newlines correctly.
5338 Otherwise the result is a String and when there are several
5339 matches, they are separated by <NL> characters.
5340
5341 If the expansion fails, the result is an empty String or List.
5342
5343 You can also use |readdir()| if you need to do complicated
5344 things, such as limiting the number of matches.
5345
5346 A name for a non-existing file is not included. A symbolic
5347 link is only included if it points to an existing file.
5348 However, when the {alllinks} argument is present and it is
5349 |TRUE| then all symbolic links are included.
5350
5351 For most systems backticks can be used to get files names from
5352 any external command. Example: >
5353 :let tagfiles = glob("`find . -name tags -print`")
5354 :let &tags = substitute(tagfiles, "\n", ",", "g")
5355< The result of the program inside the backticks should be one
5356 item per line. Spaces inside an item are allowed.
5357
5358 See |expand()| for expanding special Vim variables. See
5359 |system()| for getting the raw output of an external command.
5360
5361 Can also be used as a |method|: >
5362 GetExpr()->glob()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005363<
5364 Return type: |String| or list<string> or list<any> depending
5365 on {list}
5366
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005367
h-east624bb832024-11-09 18:37:32 +01005368glob2regpat({string}) *glob2regpat()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005369 Convert a file pattern, as used by glob(), into a search
5370 pattern. The result can be used to match with a string that
5371 is a file name. E.g. >
5372 if filename =~ glob2regpat('Make*.mak')
5373< This is equivalent to: >
5374 if filename =~ '^Make.*\.mak$'
5375< When {string} is an empty string the result is "^$", match an
5376 empty string.
5377 Note that the result depends on the system. On MS-Windows
5378 a backslash usually means a path separator.
5379
5380 Can also be used as a |method|: >
5381 GetExpr()->glob2regpat()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005382<
5383 Return type: |String|
5384
5385 *globpath()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005386globpath({path}, {expr} [, {nosuf} [, {list} [, {alllinks}]]])
5387 Perform glob() for String {expr} on all directories in {path}
5388 and concatenate the results. Example: >
5389 :echo globpath(&rtp, "syntax/c.vim")
5390<
5391 {path} is a comma-separated list of directory names. Each
5392 directory name is prepended to {expr} and expanded like with
5393 |glob()|. A path separator is inserted when needed.
5394 To add a comma inside a directory name escape it with a
5395 backslash. Note that on MS-Windows a directory may have a
5396 trailing backslash, remove it if you put a comma after it.
5397 If the expansion fails for one of the directories, there is no
5398 error message.
5399
5400 Unless the optional {nosuf} argument is given and is |TRUE|,
5401 the 'suffixes' and 'wildignore' options apply: Names matching
5402 one of the patterns in 'wildignore' will be skipped and
5403 'suffixes' affect the ordering of matches.
5404
5405 When {list} is present and it is |TRUE| the result is a |List|
5406 with all matching files. The advantage of using a List is, you
5407 also get filenames containing newlines correctly. Otherwise
5408 the result is a String and when there are several matches,
5409 they are separated by <NL> characters. Example: >
5410 :echo globpath(&rtp, "syntax/c.vim", 0, 1)
5411<
5412 {alllinks} is used as with |glob()|.
5413
5414 The "**" item can be used to search in a directory tree.
5415 For example, to find all "README.txt" files in the directories
5416 in 'runtimepath' and below: >
5417 :echo globpath(&rtp, "**/README.txt")
5418< Upwards search and limiting the depth of "**" is not
5419 supported, thus using 'path' will not always work properly.
5420
5421 Can also be used as a |method|, the base is passed as the
5422 second argument: >
5423 GetExpr()->globpath(&rtp)
5424<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005425 Return type: |String| or list<string> or list<any> depending
5426 on {list}
5427
5428
5429has({feature} [, {check}]) *has()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005430 When {check} is omitted or is zero: The result is a Number,
5431 which is 1 if the feature {feature} is supported, zero
5432 otherwise. The {feature} argument is a string, case is
5433 ignored. See |feature-list| below.
5434
5435 When {check} is present and not zero: The result is a Number,
5436 which is 1 if the feature {feature} could ever be supported,
5437 zero otherwise. This is useful to check for a typo in
5438 {feature} and to detect dead code. Keep in mind that an older
5439 Vim version will not know about a feature added later and
5440 features that have been abandoned will not be known by the
5441 current Vim version.
5442
5443 Also see |exists()| and |exists_compiled()|.
5444
5445 Note that to skip code that has a syntax error when the
5446 feature is not available, Vim may skip the rest of the line
5447 and miss a following `endif`. Therefore put the `endif` on a
5448 separate line: >
5449 if has('feature')
5450 let x = this->breaks->without->the->feature
5451 endif
5452< If the `endif` would be moved to the second line as "| endif" it
5453 would not be found.
5454
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005455 Return type: |Number|
5456
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005457
5458has_key({dict}, {key}) *has_key()*
5459 The result is a Number, which is TRUE if |Dictionary| {dict}
Bram Moolenaare8008642022-08-19 17:15:35 +01005460 has an entry with key {key}. FALSE otherwise.
5461 The {key} argument is a string. In |Vim9| script a number is
5462 also accepted (and converted to a string) but no other types.
5463 In legacy script the usual automatic conversion to string is
5464 done.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005465
5466 Can also be used as a |method|: >
5467 mydict->has_key(key)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005468<
5469 Return type: |Number|
5470
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005471
5472haslocaldir([{winnr} [, {tabnr}]]) *haslocaldir()*
5473 The result is a Number:
5474 1 when the window has set a local directory via |:lcd|
5475 2 when the tab-page has set a local directory via |:tcd|
5476 0 otherwise.
5477
5478 Without arguments use the current window.
5479 With {winnr} use this window in the current tab page.
5480 With {winnr} and {tabnr} use the window in the specified tab
5481 page.
5482 {winnr} can be the window number or the |window-ID|.
5483 If {winnr} is -1 it is ignored and only the tabpage is used.
5484 Return 0 if the arguments are invalid.
5485 Examples: >
5486 if haslocaldir() == 1
5487 " window local directory case
5488 elseif haslocaldir() == 2
5489 " tab-local directory case
5490 else
5491 " global directory case
5492 endif
5493
5494 " current window
5495 :echo haslocaldir()
5496 :echo haslocaldir(0)
5497 :echo haslocaldir(0, 0)
5498 " window n in current tab page
5499 :echo haslocaldir(n)
5500 :echo haslocaldir(n, 0)
5501 " window n in tab page m
5502 :echo haslocaldir(n, m)
5503 " tab page m
5504 :echo haslocaldir(-1, m)
5505<
5506 Can also be used as a |method|: >
5507 GetWinnr()->haslocaldir()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005508<
5509 Return type: |Number|
5510
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005511
5512hasmapto({what} [, {mode} [, {abbr}]]) *hasmapto()*
5513 The result is a Number, which is TRUE if there is a mapping
5514 that contains {what} in somewhere in the rhs (what it is
5515 mapped to) and this mapping exists in one of the modes
5516 indicated by {mode}.
5517 The arguments {what} and {mode} are strings.
5518 When {abbr} is there and it is |TRUE| use abbreviations
5519 instead of mappings. Don't forget to specify Insert and/or
5520 Command-line mode.
5521 Both the global mappings and the mappings local to the current
5522 buffer are checked for a match.
5523 If no matching mapping is found FALSE is returned.
5524 The following characters are recognized in {mode}:
5525 n Normal mode
5526 v Visual and Select mode
5527 x Visual mode
5528 s Select mode
5529 o Operator-pending mode
5530 i Insert mode
5531 l Language-Argument ("r", "f", "t", etc.)
5532 c Command-line mode
5533 When {mode} is omitted, "nvo" is used.
5534
5535 This function is useful to check if a mapping already exists
5536 to a function in a Vim script. Example: >
5537 :if !hasmapto('\ABCdoit')
5538 : map <Leader>d \ABCdoit
5539 :endif
5540< This installs the mapping to "\ABCdoit" only if there isn't
5541 already a mapping to "\ABCdoit".
5542
5543 Can also be used as a |method|: >
5544 GetRHS()->hasmapto()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005545<
5546 Return type: |Number|
5547
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005548
5549histadd({history}, {item}) *histadd()*
5550 Add the String {item} to the history {history} which can be
5551 one of: *hist-names*
5552 "cmd" or ":" command line history
5553 "search" or "/" search pattern history
5554 "expr" or "=" typed expression history
5555 "input" or "@" input line history
5556 "debug" or ">" debug command history
5557 empty the current or last used history
5558 The {history} string does not need to be the whole name, one
5559 character is sufficient.
5560 If {item} does already exist in the history, it will be
5561 shifted to become the newest entry.
5562 The result is a Number: TRUE if the operation was successful,
5563 otherwise FALSE is returned.
5564
5565 Example: >
5566 :call histadd("input", strftime("%Y %b %d"))
5567 :let date=input("Enter date: ")
5568< This function is not available in the |sandbox|.
5569
5570 Can also be used as a |method|, the base is passed as the
5571 second argument: >
5572 GetHistory()->histadd('search')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005573<
5574 Return type: |Number|
5575
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005576
5577histdel({history} [, {item}]) *histdel()*
5578 Clear {history}, i.e. delete all its entries. See |hist-names|
5579 for the possible values of {history}.
5580
5581 If the parameter {item} evaluates to a String, it is used as a
5582 regular expression. All entries matching that expression will
5583 be removed from the history (if there are any).
5584 Upper/lowercase must match, unless "\c" is used |/\c|.
5585 If {item} evaluates to a Number, it will be interpreted as
5586 an index, see |:history-indexing|. The respective entry will
5587 be removed if it exists.
5588
5589 The result is TRUE for a successful operation, otherwise FALSE
5590 is returned.
5591
5592 Examples:
5593 Clear expression register history: >
5594 :call histdel("expr")
5595<
5596 Remove all entries starting with "*" from the search history: >
5597 :call histdel("/", '^\*')
5598<
5599 The following three are equivalent: >
5600 :call histdel("search", histnr("search"))
5601 :call histdel("search", -1)
Bram Moolenaarc51cf032022-02-26 12:25:45 +00005602 :call histdel("search", '^' .. histget("search", -1) .. '$')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005603<
5604 To delete the last search pattern and use the last-but-one for
5605 the "n" command and 'hlsearch': >
5606 :call histdel("search", -1)
5607 :let @/ = histget("search", -1)
5608<
5609 Can also be used as a |method|: >
5610 GetHistory()->histdel()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005611<
5612 Return type: |Number|
5613
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005614
5615histget({history} [, {index}]) *histget()*
5616 The result is a String, the entry with Number {index} from
5617 {history}. See |hist-names| for the possible values of
5618 {history}, and |:history-indexing| for {index}. If there is
5619 no such entry, an empty String is returned. When {index} is
5620 omitted, the most recent item from the history is used.
5621
5622 Examples:
5623 Redo the second last search from history. >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00005624 :execute '/' .. histget("search", -2)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005625
5626< Define an Ex command ":H {num}" that supports re-execution of
5627 the {num}th entry from the output of |:history|. >
5628 :command -nargs=1 H execute histget("cmd", 0+<args>)
5629<
5630 Can also be used as a |method|: >
5631 GetHistory()->histget()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005632<
5633 Return type: |String|
5634
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005635
5636histnr({history}) *histnr()*
5637 The result is the Number of the current entry in {history}.
5638 See |hist-names| for the possible values of {history}.
5639 If an error occurred, -1 is returned.
5640
5641 Example: >
5642 :let inp_index = histnr("expr")
5643
5644< Can also be used as a |method|: >
5645 GetHistory()->histnr()
5646<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005647 Return type: |Number|
5648
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005649hlexists({name}) *hlexists()*
5650 The result is a Number, which is TRUE if a highlight group
5651 called {name} exists. This is when the group has been
5652 defined in some way. Not necessarily when highlighting has
5653 been defined for it, it may also have been used for a syntax
5654 item.
5655 *highlight_exists()*
5656 Obsolete name: highlight_exists().
5657
5658 Can also be used as a |method|: >
5659 GetName()->hlexists()
5660<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005661 Return type: |Number|
5662
5663
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005664hlget([{name} [, {resolve}]]) *hlget()*
5665 Returns a List of all the highlight group attributes. If the
5666 optional {name} is specified, then returns a List with only
5667 the attributes of the specified highlight group. Returns an
5668 empty List if the highlight group {name} is not present.
5669
5670 If the optional {resolve} argument is set to v:true and the
5671 highlight group {name} is linked to another group, then the
5672 link is resolved recursively and the attributes of the
5673 resolved highlight group are returned.
5674
5675 Each entry in the returned List is a Dictionary with the
5676 following items:
5677 cleared boolean flag, set to v:true if the highlight
5678 group attributes are cleared or not yet
5679 specified. See |highlight-clear|.
5680 cterm cterm attributes. See |highlight-cterm|.
5681 ctermbg cterm background color.
5682 See |highlight-ctermbg|.
5683 ctermfg cterm foreground color.
5684 See |highlight-ctermfg|.
5685 ctermul cterm underline color. See |highlight-ctermul|.
5686 default boolean flag, set to v:true if the highlight
5687 group link is a default link. See
5688 |highlight-default|.
5689 font highlight group font. See |highlight-font|.
5690 gui gui attributes. See |highlight-gui|.
5691 guibg gui background color. See |highlight-guibg|.
5692 guifg gui foreground color. See |highlight-guifg|.
5693 guisp gui special color. See |highlight-guisp|.
5694 id highlight group ID.
5695 linksto linked highlight group name.
5696 See |:highlight-link|.
5697 name highlight group name. See |group-name|.
5698 start start terminal keycode. See |highlight-start|.
5699 stop stop terminal keycode. See |highlight-stop|.
5700 term term attributes. See |highlight-term|.
5701
5702 The 'term', 'cterm' and 'gui' items in the above Dictionary
5703 have a dictionary value with the following optional boolean
5704 items: 'bold', 'standout', 'underline', 'undercurl', 'italic',
5705 'reverse', 'inverse' and 'strikethrough'.
5706
5707 Example(s): >
5708 :echo hlget()
5709 :echo hlget('ModeMsg')
5710 :echo hlget('Number', v:true)
5711<
5712 Can also be used as a |method|: >
5713 GetName()->hlget()
5714<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005715 Return type: list<dict<any>>
5716
5717
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005718hlset({list}) *hlset()*
5719 Creates or modifies the attributes of a List of highlight
5720 groups. Each item in {list} is a dictionary containing the
5721 attributes of a highlight group. See |hlget()| for the list of
5722 supported items in this dictionary.
5723
5724 In addition to the items described in |hlget()|, the following
5725 additional items are supported in the dictionary:
5726
5727 force boolean flag to force the creation of
5728 a link for an existing highlight group
5729 with attributes.
5730
5731 The highlight group is identified using the 'name' item and
5732 the 'id' item (if supplied) is ignored. If a highlight group
5733 with a specified name doesn't exist, then it is created.
5734 Otherwise the attributes of an existing highlight group are
5735 modified.
5736
5737 If an empty dictionary value is used for the 'term' or 'cterm'
5738 or 'gui' entries, then the corresponding attributes are
5739 cleared. If the 'cleared' item is set to v:true, then all the
5740 attributes of the highlight group are cleared.
5741
5742 The 'linksto' item can be used to link a highlight group to
5743 another highlight group. See |:highlight-link|.
5744
5745 Returns zero for success, -1 for failure.
5746
5747 Example(s): >
5748 " add bold attribute to the Visual highlight group
5749 :call hlset([#{name: 'Visual',
5750 \ term: #{reverse: 1 , bold: 1}}])
5751 :call hlset([#{name: 'Type', guifg: 'DarkGreen'}])
5752 :let l = hlget()
5753 :call hlset(l)
5754 " clear the Search highlight group
5755 :call hlset([#{name: 'Search', cleared: v:true}])
5756 " clear the 'term' attributes for a highlight group
5757 :call hlset([#{name: 'Title', term: {}}])
5758 " create the MyHlg group linking it to DiffAdd
5759 :call hlset([#{name: 'MyHlg', linksto: 'DiffAdd'}])
5760 " remove the MyHlg group link
5761 :call hlset([#{name: 'MyHlg', linksto: 'NONE'}])
5762 " clear the attributes and a link
5763 :call hlset([#{name: 'MyHlg', cleared: v:true,
5764 \ linksto: 'NONE'}])
5765<
5766 Can also be used as a |method|: >
5767 GetAttrList()->hlset()
5768<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005769 Return type: |Number|
5770
5771hlID({name}) *hlID()*
5772 The result is a Number, which is the ID of the highlight group
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005773 with name {name}. When the highlight group doesn't exist,
5774 zero is returned.
5775 This can be used to retrieve information about the highlight
5776 group. For example, to get the background color of the
5777 "Comment" group: >
5778 :echo synIDattr(synIDtrans(hlID("Comment")), "bg")
5779< *highlightID()*
5780 Obsolete name: highlightID().
5781
5782 Can also be used as a |method|: >
5783 GetName()->hlID()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005784<
5785 Return type: |Number|
5786
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005787
5788hostname() *hostname()*
5789 The result is a String, which is the name of the machine on
5790 which Vim is currently running. Machine names greater than
5791 256 characters long are truncated.
5792
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005793 Return type: |String|
5794
5795
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005796iconv({string}, {from}, {to}) *iconv()*
5797 The result is a String, which is the text {string} converted
5798 from encoding {from} to encoding {to}.
5799 When the conversion completely fails an empty string is
5800 returned. When some characters could not be converted they
5801 are replaced with "?".
5802 The encoding names are whatever the iconv() library function
5803 can accept, see ":!man 3 iconv".
5804 Most conversions require Vim to be compiled with the |+iconv|
5805 feature. Otherwise only UTF-8 to latin1 conversion and back
5806 can be done.
5807 This can be used to display messages with special characters,
5808 no matter what 'encoding' is set to. Write the message in
5809 UTF-8 and use: >
5810 echo iconv(utf8_str, "utf-8", &enc)
5811< Note that Vim uses UTF-8 for all Unicode encodings, conversion
5812 from/to UCS-2 is automatically changed to use UTF-8. You
5813 cannot use UCS-2 in a string anyway, because of the NUL bytes.
5814
5815 Can also be used as a |method|: >
5816 GetText()->iconv('latin1', 'utf-8')
5817<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005818 Return type: |String|
5819
5820
h-east624bb832024-11-09 18:37:32 +01005821id({item}) *id()*
Ernie Raelc8e158b2024-07-09 18:39:52 +02005822 The result is a unique String associated with the {item} and
5823 not with the {item}'s contents. It is only valid while the
5824 {item} exists and is referenced. It is valid only in the
5825 instance of vim that produces the result. The whole idea is
5826 that `id({item})` does not change if the contents of {item}
5827 changes. This is useful as a `key` for creating an identity
5828 dictionary, rather than one based on equals.
5829
5830 This operation does not reference {item} and there is no
5831 function to convert the `id` to the {item}. It may be useful to
5832 have a map of `id` to {item}. The following >
5833 var referenceMap: dict<any>
5834 var id = item->id()
5835 referenceMap[id] = item
5836< prevents {item} from being garbage collected and provides a
5837 way to get the {item} from the `id`.
5838
Yegappan Lakshmanan9cb865e2025-03-23 16:42:16 +01005839 {item} may be a List, Tuple, Dictionary, Object, Job, Channel
5840 or Blob. If the item is not a permitted type, or it is a null
Ernie Raelc8e158b2024-07-09 18:39:52 +02005841 value, then an empty String is returned.
5842
5843 Can also be used as a |method|: >
5844 GetItem()->id()
5845<
5846 Return type: |String|
5847
5848
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005849indent({lnum}) *indent()*
5850 The result is a Number, which is indent of line {lnum} in the
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005851 current buffer. The indent is counted in spaces, the value
5852 of 'tabstop' is relevant. {lnum} is used just like in
5853 |getline()|.
5854 When {lnum} is invalid -1 is returned. In |Vim9| script an
5855 error is given.
5856
5857 Can also be used as a |method|: >
5858 GetLnum()->indent()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005859<
5860 Return type: |Number|
5861
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005862
5863index({object}, {expr} [, {start} [, {ic}]]) *index()*
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005864 Find {expr} in {object} and return its index. See
Yegappan Lakshmanan3fbf6cd2022-08-13 21:35:13 +01005865 |indexof()| for using a lambda to select the item.
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005866
Yegappan Lakshmanan9cb865e2025-03-23 16:42:16 +01005867 If {object} is a |List| or a |Tuple| return the lowest index
5868 where the item has a value equal to {expr}. There is no
5869 automatic conversion, so the String "4" is different from the
5870 Number 4. And the number 4 is different from the Float 4.0.
5871 The value of 'ignorecase' is not used here, case matters as
5872 indicated by the {ic} argument.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005873
5874 If {object} is |Blob| return the lowest index where the byte
5875 value is equal to {expr}.
5876
5877 If {start} is given then start looking at the item with index
5878 {start} (may be negative for an item relative to the end).
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005879
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005880 When {ic} is given and it is |TRUE|, ignore case. Otherwise
5881 case must match.
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005882
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005883 -1 is returned when {expr} is not found in {object}.
5884 Example: >
5885 :let idx = index(words, "the")
5886 :if index(numbers, 123) >= 0
5887
5888< Can also be used as a |method|: >
5889 GetObject()->index(what)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005890<
5891 Return type: |Number|
5892
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005893
Yegappan Lakshmanan3fbf6cd2022-08-13 21:35:13 +01005894indexof({object}, {expr} [, {opts}]) *indexof()*
5895 Returns the index of an item in {object} where {expr} is
Yegappan Lakshmanan9cb865e2025-03-23 16:42:16 +01005896 v:true. {object} must be a |List|, a |Tuple| or a |Blob|.
Yegappan Lakshmanan3fbf6cd2022-08-13 21:35:13 +01005897
Yegappan Lakshmanan9cb865e2025-03-23 16:42:16 +01005898 If {object} is a |List| or a |Tuple|, evaluate {expr} for each
Christ van Willegen92e109f2025-03-24 20:12:37 +01005899 item in the List or Tuple until the expression is v:true
5900 and return the index of this item.
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005901
5902 If {object} is a |Blob| evaluate {expr} for each byte in the
Yegappan Lakshmanan3fbf6cd2022-08-13 21:35:13 +01005903 Blob until the expression is v:true and return the index of
5904 this byte.
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005905
5906 {expr} must be a |string| or |Funcref|.
5907
Yegappan Lakshmanan9cb865e2025-03-23 16:42:16 +01005908 If {expr} is a |string|: If {object} is a |List| or a |Tuple|,
5909 inside {expr} |v:key| has the index of the current List or
5910 Tuple item and |v:val| has the value of the item. If {object}
5911 is a |Blob|, inside {expr} |v:key| has the index of the
5912 current byte and |v:val| has the byte value.
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005913
5914 If {expr} is a |Funcref| it must take two arguments:
5915 1. the key or the index of the current item.
5916 2. the value of the current item.
5917 The function must return |TRUE| if the item is found and the
5918 search should stop.
5919
Yegappan Lakshmanan3fbf6cd2022-08-13 21:35:13 +01005920 The optional argument {opts} is a Dict and supports the
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005921 following items:
Yegappan Lakshmanan3fbf6cd2022-08-13 21:35:13 +01005922 startidx start evaluating {expr} at the item with this
5923 index; may be negative for an item relative to
5924 the end
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005925 Returns -1 when {expr} evaluates to v:false for all the items.
5926 Example: >
Yegappan Lakshmanan3fbf6cd2022-08-13 21:35:13 +01005927 :let l = [#{n: 10}, #{n: 20}, #{n: 30}]
5928 :echo indexof(l, "v:val.n == 20")
5929 :echo indexof(l, {i, v -> v.n == 30})
5930 :echo indexof(l, "v:val.n == 20", #{startidx: 1})
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005931
5932< Can also be used as a |method|: >
5933 mylist->indexof(expr)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005934<
5935 Return type: |Number|
5936
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005937
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005938input({prompt} [, {text} [, {completion}]]) *input()*
5939 The result is a String, which is whatever the user typed on
5940 the command-line. The {prompt} argument is either a prompt
5941 string, or a blank string (for no prompt). A '\n' can be used
5942 in the prompt to start a new line.
5943 The highlighting set with |:echohl| is used for the prompt.
5944 The input is entered just like a command-line, with the same
5945 editing commands and mappings. There is a separate history
5946 for lines typed for input().
5947 Example: >
5948 :if input("Coffee or beer? ") == "beer"
5949 : echo "Cheers!"
5950 :endif
5951<
5952 If the optional {text} argument is present and not empty, this
5953 is used for the default reply, as if the user typed this.
5954 Example: >
5955 :let color = input("Color? ", "white")
5956
5957< The optional {completion} argument specifies the type of
5958 completion supported for the input. Without it completion is
5959 not performed. The supported completion types are the same as
5960 that can be supplied to a user-defined command using the
5961 "-complete=" argument. Refer to |:command-completion| for
5962 more information. Example: >
5963 let fname = input("File: ", "", "file")
5964<
5965 NOTE: This function must not be used in a startup file, for
5966 the versions that only run in GUI mode (e.g., the Win32 GUI).
5967 Note: When input() is called from within a mapping it will
5968 consume remaining characters from that mapping, because a
5969 mapping is handled like the characters were typed.
5970 Use |inputsave()| before input() and |inputrestore()|
5971 after input() to avoid that. Another solution is to avoid
5972 that further characters follow in the mapping, e.g., by using
5973 |:execute| or |:normal|.
5974
5975 Example with a mapping: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00005976 :nmap \x :call GetFoo()<CR>:exe "/" .. Foo<CR>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005977 :function GetFoo()
5978 : call inputsave()
5979 : let g:Foo = input("enter search pattern: ")
5980 : call inputrestore()
5981 :endfunction
5982
5983< Can also be used as a |method|: >
5984 GetPrompt()->input()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005985<
5986 Return type: |String|
5987
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005988
5989inputdialog({prompt} [, {text} [, {cancelreturn}]]) *inputdialog()*
5990 Like |input()|, but when the GUI is running and text dialogs
5991 are supported, a dialog window pops up to input the text.
5992 Example: >
5993 :let n = inputdialog("value for shiftwidth", shiftwidth())
5994 :if n != ""
5995 : let &sw = n
5996 :endif
5997< When the dialog is cancelled {cancelreturn} is returned. When
5998 omitted an empty string is returned.
5999 Hitting <Enter> works like pressing the OK button. Hitting
6000 <Esc> works like pressing the Cancel button.
6001 NOTE: Command-line completion is not supported.
6002
6003 Can also be used as a |method|: >
6004 GetPrompt()->inputdialog()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006005<
6006 Return type: |String|
6007
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006008
6009inputlist({textlist}) *inputlist()*
6010 {textlist} must be a |List| of strings. This |List| is
6011 displayed, one string per line. The user will be prompted to
6012 enter a number, which is returned.
6013 The user can also select an item by clicking on it with the
6014 mouse, if the mouse is enabled in the command line ('mouse' is
6015 "a" or includes "c"). For the first string 0 is returned.
6016 When clicking above the first item a negative number is
6017 returned. When clicking on the prompt one more than the
6018 length of {textlist} is returned.
6019 Make sure {textlist} has less than 'lines' entries, otherwise
6020 it won't work. It's a good idea to put the entry number at
6021 the start of the string. And put a prompt in the first item.
6022 Example: >
6023 let color = inputlist(['Select color:', '1. red',
6024 \ '2. green', '3. blue'])
6025
6026< Can also be used as a |method|: >
6027 GetChoices()->inputlist()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006028<
6029 Return type: |Number|
6030
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006031
6032inputrestore() *inputrestore()*
6033 Restore typeahead that was saved with a previous |inputsave()|.
6034 Should be called the same number of times inputsave() is
6035 called. Calling it more often is harmless though.
6036 Returns TRUE when there is nothing to restore, FALSE otherwise.
6037
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006038 Return type: |Number|
6039
6040
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006041inputsave() *inputsave()*
6042 Preserve typeahead (also from mappings) and clear it, so that
6043 a following prompt gets input from the user. Should be
6044 followed by a matching inputrestore() after the prompt. Can
6045 be used several times, in which case there must be just as
6046 many inputrestore() calls.
6047 Returns TRUE when out of memory, FALSE otherwise.
6048
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006049 Return type: |Number|
6050
6051
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006052inputsecret({prompt} [, {text}]) *inputsecret()*
6053 This function acts much like the |input()| function with but
6054 two exceptions:
6055 a) the user's response will be displayed as a sequence of
6056 asterisks ("*") thereby keeping the entry secret, and
6057 b) the user's response will not be recorded on the input
6058 |history| stack.
6059 The result is a String, which is whatever the user actually
6060 typed on the command-line in response to the issued prompt.
6061 NOTE: Command-line completion is not supported.
6062
6063 Can also be used as a |method|: >
6064 GetPrompt()->inputsecret()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006065<
6066 Return type: |String|
6067
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006068
6069insert({object}, {item} [, {idx}]) *insert()*
6070 When {object} is a |List| or a |Blob| insert {item} at the start
6071 of it.
6072
6073 If {idx} is specified insert {item} before the item with index
6074 {idx}. If {idx} is zero it goes before the first item, just
6075 like omitting {idx}. A negative {idx} is also possible, see
6076 |list-index|. -1 inserts just before the last item.
6077
6078 Returns the resulting |List| or |Blob|. Examples: >
6079 :let mylist = insert([2, 3, 5], 1)
6080 :call insert(mylist, 4, -1)
6081 :call insert(mylist, 6, len(mylist))
6082< The last example can be done simpler with |add()|.
6083 Note that when {item} is a |List| it is inserted as a single
6084 item. Use |extend()| to concatenate |Lists|.
6085
6086 Can also be used as a |method|: >
6087 mylist->insert(item)
Yegappan Lakshmanancd39b692023-10-02 12:50:45 -07006088<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006089 Return type: |Number|
6090
6091
Yegappan Lakshmanancd39b692023-10-02 12:50:45 -07006092 *instanceof()* *E614* *E616* *E693*
6093instanceof({object}, {class})
6094 The result is a Number, which is |TRUE| when the {object}
Ernie Rael2025af12023-12-12 16:58:00 +01006095 argument is a direct or indirect instance of a |Class|,
6096 |Interface|, or class |:type| alias specified by {class}.
6097 If {class} is varargs, the function returns |TRUE| when
Yegappan Lakshmanancd39b692023-10-02 12:50:45 -07006098 {object} is an instance of any of the specified classes.
LemonBoyafe04662023-08-23 21:08:11 +02006099 Example: >
Ernie Rael2025af12023-12-12 16:58:00 +01006100 instanceof(animal, Dog, Cat)
LemonBoyafe04662023-08-23 21:08:11 +02006101
6102< Can also be used as a |method|: >
6103 myobj->instanceof(mytype)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006104<
6105 Return type: |Number|
LemonBoyafe04662023-08-23 21:08:11 +02006106
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006107interrupt() *interrupt()*
6108 Interrupt script execution. It works more or less like the
6109 user typing CTRL-C, most commands won't execute and control
6110 returns to the user. This is useful to abort execution
6111 from lower down, e.g. in an autocommand. Example: >
6112 :function s:check_typoname(file)
6113 : if fnamemodify(a:file, ':t') == '['
6114 : echomsg 'Maybe typo'
6115 : call interrupt()
6116 : endif
6117 :endfunction
6118 :au BufWritePre * call s:check_typoname(expand('<amatch>'))
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006119<
6120 Return type: void
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006121
6122invert({expr}) *invert()*
6123 Bitwise invert. The argument is converted to a number. A
6124 List, Dict or Float argument causes an error. Example: >
6125 :let bits = invert(bits)
6126< Can also be used as a |method|: >
6127 :let bits = bits->invert()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006128<
6129 Return type: |Number|
6130
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006131
Bram Moolenaar8a3b8052022-06-26 12:21:15 +01006132isabsolutepath({path}) *isabsolutepath()*
LemonBoydca1d402022-04-28 15:26:33 +01006133 The result is a Number, which is |TRUE| when {path} is an
6134 absolute path.
Bram Moolenaar8a3b8052022-06-26 12:21:15 +01006135 On Unix, a path is considered absolute when it starts with '/'.
LemonBoydca1d402022-04-28 15:26:33 +01006136 On MS-Windows, it is considered absolute when it starts with an
6137 optional drive prefix and is followed by a '\' or '/'. UNC paths
6138 are always absolute.
6139 Example: >
6140 echo isabsolutepath('/usr/share/') " 1
6141 echo isabsolutepath('./foobar') " 0
6142 echo isabsolutepath('C:\Windows') " 1
6143 echo isabsolutepath('foobar') " 0
6144 echo isabsolutepath('\\remote\file') " 1
Bram Moolenaar8a3b8052022-06-26 12:21:15 +01006145<
LemonBoydca1d402022-04-28 15:26:33 +01006146 Can also be used as a |method|: >
6147 GetName()->isabsolutepath()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006148<
6149 Return type: |Number|
LemonBoydca1d402022-04-28 15:26:33 +01006150
6151
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006152isdirectory({directory}) *isdirectory()*
6153 The result is a Number, which is |TRUE| when a directory
6154 with the name {directory} exists. If {directory} doesn't
6155 exist, or isn't a directory, the result is |FALSE|. {directory}
6156 is any expression, which is used as a String.
6157
6158 Can also be used as a |method|: >
6159 GetName()->isdirectory()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006160<
6161 Return type: |Number|
6162
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006163
6164isinf({expr}) *isinf()*
6165 Return 1 if {expr} is a positive infinity, or -1 a negative
6166 infinity, otherwise 0. >
6167 :echo isinf(1.0 / 0.0)
6168< 1 >
6169 :echo isinf(-1.0 / 0.0)
6170< -1
6171
6172 Can also be used as a |method|: >
6173 Compute()->isinf()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006174<
6175 Return type: |Number|
6176
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006177
6178islocked({expr}) *islocked()* *E786*
6179 The result is a Number, which is |TRUE| when {expr} is the
6180 name of a locked variable.
6181 The string argument {expr} must be the name of a variable,
6182 |List| item or |Dictionary| entry, not the variable itself!
6183 Example: >
6184 :let alist = [0, ['a', 'b'], 2, 3]
6185 :lockvar 1 alist
6186 :echo islocked('alist') " 1
6187 :echo islocked('alist[1]') " 0
6188
Bram Moolenaar9da17d72022-02-09 21:50:44 +00006189< When {expr} is a variable that does not exist -1 is returned.
6190 If {expr} uses a range, list or dict index that is out of
6191 range or does not exist you get an error message. Use
6192 |exists()| to check for existence.
6193 In Vim9 script it does not work for local function variables.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006194
6195 Can also be used as a |method|: >
6196 GetName()->islocked()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006197<
6198 Return type: |Number|
6199
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006200
6201isnan({expr}) *isnan()*
6202 Return |TRUE| if {expr} is a float with value NaN. >
6203 echo isnan(0.0 / 0.0)
6204< 1
6205
6206 Can also be used as a |method|: >
6207 Compute()->isnan()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006208<
6209 Return type: |Number|
6210
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006211
6212items({dict}) *items()*
6213 Return a |List| with all the key-value pairs of {dict}. Each
6214 |List| item is a list with two items: the key of a {dict}
6215 entry and the value of this entry. The |List| is in arbitrary
6216 order. Also see |keys()| and |values()|.
6217 Example: >
6218 for [key, value] in items(mydict)
Bram Moolenaarc51cf032022-02-26 12:25:45 +00006219 echo key .. ': ' .. value
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006220 endfor
Yegappan Lakshmanan49cdd622023-12-24 11:01:23 +01006221<
Yegappan Lakshmanan9cb865e2025-03-23 16:42:16 +01006222 A |List|, a |Tuple| or a |String| argument is also supported.
6223 In these cases, items() returns a List with the index and the
6224 value at the index.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006225
Yegappan Lakshmanan49cdd622023-12-24 11:01:23 +01006226 Can also be used as a |method|: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006227 mydict->items()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006228<
6229 Return type: list<list<any>> or list<any>
6230
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006231
6232job_ functions are documented here: |job-functions-details|
6233
6234
Yegappan Lakshmanan9cb865e2025-03-23 16:42:16 +01006235join({expr} [, {sep}]) *join()*
6236 Join the items in {expr} together into one String. {expr} can
6237 be a |List| or a |Tuple|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006238 When {sep} is specified it is put in between the items. If
6239 {sep} is omitted a single space is used.
6240 Note that {sep} is not added at the end. You might want to
6241 add it there too: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00006242 let lines = join(mylist, "\n") .. "\n"
Yegappan Lakshmanan9cb865e2025-03-23 16:42:16 +01006243< String items are used as-is. |Lists|, |Tuples| and
6244 |Dictionaries| are converted into a string like with
6245 |string()|. The opposite function is |split()|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006246
6247 Can also be used as a |method|: >
6248 mylist->join()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006249<
6250 Return type: |String|
6251
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006252
6253js_decode({string}) *js_decode()*
6254 This is similar to |json_decode()| with these differences:
6255 - Object key names do not have to be in quotes.
6256 - Strings can be in single quotes.
6257 - Empty items in an array (between two commas) are allowed and
6258 result in v:none items.
6259
6260 Can also be used as a |method|: >
6261 ReadObject()->js_decode()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006262<
6263 Return type: any, depending on {varname}
6264
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006265
6266js_encode({expr}) *js_encode()*
6267 This is similar to |json_encode()| with these differences:
6268 - Object key names are not in quotes.
6269 - v:none items in an array result in an empty item between
6270 commas.
6271 For example, the Vim object:
6272 [1,v:none,{"one":1},v:none] ~
6273 Will be encoded as:
6274 [1,,{one:1},,] ~
6275 While json_encode() would produce:
6276 [1,null,{"one":1},null] ~
6277 This encoding is valid for JavaScript. It is more efficient
6278 than JSON, especially when using an array with optional items.
6279
6280 Can also be used as a |method|: >
6281 GetObject()->js_encode()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006282<
6283 Return type: |String|
6284
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006285
Bram Moolenaar2f0936c2022-01-08 21:51:59 +00006286json_decode({string}) *json_decode()* *E491*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006287 This parses a JSON formatted string and returns the equivalent
6288 in Vim values. See |json_encode()| for the relation between
6289 JSON and Vim values.
6290 The decoding is permissive:
6291 - A trailing comma in an array and object is ignored, e.g.
6292 "[1, 2, ]" is the same as "[1, 2]".
6293 - Integer keys are accepted in objects, e.g. {1:2} is the
6294 same as {"1":2}.
6295 - More floating point numbers are recognized, e.g. "1." for
6296 "1.0", or "001.2" for "1.2". Special floating point values
6297 "Infinity", "-Infinity" and "NaN" (capitalization ignored)
6298 are accepted.
6299 - Leading zeroes in integer numbers are ignored, e.g. "012"
6300 for "12" or "-012" for "-12".
6301 - Capitalization is ignored in literal names null, true or
6302 false, e.g. "NULL" for "null", "True" for "true".
6303 - Control characters U+0000 through U+001F which are not
6304 escaped in strings are accepted, e.g. " " (tab
6305 character in string) for "\t".
6306 - An empty JSON expression or made of only spaces is accepted
6307 and results in v:none.
6308 - Backslash in an invalid 2-character sequence escape is
6309 ignored, e.g. "\a" is decoded as "a".
6310 - A correct surrogate pair in JSON strings should normally be
6311 a 12 character sequence such as "\uD834\uDD1E", but
6312 json_decode() silently accepts truncated surrogate pairs
6313 such as "\uD834" or "\uD834\u"
6314 *E938*
6315 A duplicate key in an object, valid in rfc7159, is not
6316 accepted by json_decode() as the result must be a valid Vim
6317 type, e.g. this fails: {"a":"b", "a":"c"}
6318
6319 Can also be used as a |method|: >
6320 ReadObject()->json_decode()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006321<
6322 Return type: any, depending on {varname}
6323
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006324
6325json_encode({expr}) *json_encode()*
6326 Encode {expr} as JSON and return this as a string.
6327 The encoding is specified in:
6328 https://tools.ietf.org/html/rfc7159.html
Bram Moolenaara2baa732022-02-04 16:09:54 +00006329 Vim values are converted as follows: *E1161*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006330 |Number| decimal number
6331 |Float| floating point number
6332 Float nan "NaN"
6333 Float inf "Infinity"
6334 Float -inf "-Infinity"
6335 |String| in double quotes (possibly null)
6336 |Funcref| not possible, error
6337 |List| as an array (possibly null); when
6338 used recursively: []
Yegappan Lakshmanan9cb865e2025-03-23 16:42:16 +01006339 |Tuple| as an array (possibly null); when
6340 used recursively: []
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006341 |Dict| as an object (possibly null); when
6342 used recursively: {}
6343 |Blob| as an array of the individual bytes
6344 v:false "false"
6345 v:true "true"
6346 v:none "null"
6347 v:null "null"
6348 Note that NaN and Infinity are passed on as values. This is
6349 missing in the JSON standard, but several implementations do
6350 allow it. If not then you will get an error.
Bram Moolenaarcbaff5e2022-04-08 17:45:08 +01006351 If a string contains an illegal character then the replacement
6352 character 0xfffd is used.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006353
6354 Can also be used as a |method|: >
6355 GetObject()->json_encode()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006356<
6357 Return type: |String|
6358
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006359
6360keys({dict}) *keys()*
6361 Return a |List| with all the keys of {dict}. The |List| is in
6362 arbitrary order. Also see |items()| and |values()|.
6363
6364 Can also be used as a |method|: >
6365 mydict->keys()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006366<
6367 Return type: list<string>
6368
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006369
zeertzjqcdc83932022-09-12 13:38:41 +01006370keytrans({string}) *keytrans()*
6371 Turn the internal byte representation of keys into a form that
6372 can be used for |:map|. E.g. >
6373 :let xx = "\<C-Home>"
6374 :echo keytrans(xx)
6375< <C-Home>
6376
6377 Can also be used as a |method|: >
6378 "\<C-Home>"->keytrans()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006379<
6380 Return type: |String|
zeertzjqcdc83932022-09-12 13:38:41 +01006381
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006382
6383len({expr}) *len()* *E701*
6384 The result is a Number, which is the length of the argument.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006385 When {expr} is a String or a Number the length in bytes is
6386 used, as with |strlen()|.
6387 When {expr} is a |List| the number of items in the |List| is
6388 returned.
Yegappan Lakshmanan9cb865e2025-03-23 16:42:16 +01006389 When {expr} is a |Tuple| the number of items in the |Tuple| is
6390 returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006391 When {expr} is a |Blob| the number of bytes is returned.
6392 When {expr} is a |Dictionary| the number of entries in the
6393 |Dictionary| is returned.
mityu7f0bba22024-03-29 10:14:41 +01006394 When {expr} is an |Object|, invokes the len() method in the
6395 object (if present) to get the length (|object-len()|).
6396 Otherwise returns zero.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006397
6398 Can also be used as a |method|: >
6399 mylist->len()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006400<
6401 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006402
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006403
6404 *libcall()* *E364* *E368*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006405libcall({libname}, {funcname}, {argument})
6406 Call function {funcname} in the run-time library {libname}
6407 with single argument {argument}.
6408 This is useful to call functions in a library that you
6409 especially made to be used with Vim. Since only one argument
6410 is possible, calling standard library functions is rather
6411 limited.
6412 The result is the String returned by the function. If the
6413 function returns NULL, this will appear as an empty string ""
6414 to Vim.
6415 If the function returns a number, use libcallnr()!
6416 If {argument} is a number, it is passed to the function as an
6417 int; if {argument} is a string, it is passed as a
6418 null-terminated string.
6419 This function will fail in |restricted-mode|.
6420
6421 libcall() allows you to write your own 'plug-in' extensions to
6422 Vim without having to recompile the program. It is NOT a
6423 means to call system functions! If you try to do so Vim will
6424 very probably crash.
6425
6426 For Win32, the functions you write must be placed in a DLL
6427 and use the normal C calling convention (NOT Pascal which is
6428 used in Windows System DLLs). The function must take exactly
6429 one parameter, either a character pointer or a long integer,
6430 and must return a character pointer or NULL. The character
6431 pointer returned must point to memory that will remain valid
6432 after the function has returned (e.g. in static data in the
6433 DLL). If it points to allocated memory, that memory will
6434 leak away. Using a static buffer in the function should work,
6435 it's then freed when the DLL is unloaded.
6436
6437 WARNING: If the function returns a non-valid pointer, Vim may
6438 crash! This also happens if the function returns a number,
6439 because Vim thinks it's a pointer.
6440 For Win32 systems, {libname} should be the filename of the DLL
6441 without the ".DLL" suffix. A full path is only required if
6442 the DLL is not in the usual places.
6443 For Unix: When compiling your own plugins, remember that the
6444 object code must be compiled as position-independent ('PIC').
6445 {only in Win32 and some Unix versions, when the |+libcall|
6446 feature is present}
6447 Examples: >
6448 :echo libcall("libc.so", "getenv", "HOME")
6449
6450< Can also be used as a |method|, the base is passed as the
6451 third argument: >
6452 GetValue()->libcall("libc.so", "getenv")
6453<
6454 *libcallnr()*
6455libcallnr({libname}, {funcname}, {argument})
6456 Just like |libcall()|, but used for a function that returns an
6457 int instead of a string.
6458 {only in Win32 on some Unix versions, when the |+libcall|
6459 feature is present}
6460 Examples: >
6461 :echo libcallnr("/usr/lib/libc.so", "getpid", "")
6462 :call libcallnr("libc.so", "printf", "Hello World!\n")
6463 :call libcallnr("libc.so", "sleep", 10)
6464<
6465 Can also be used as a |method|, the base is passed as the
6466 third argument: >
6467 GetValue()->libcallnr("libc.so", "printf")
6468<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006469 Return type: |String|
6470
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006471
6472line({expr} [, {winid}]) *line()*
6473 The result is a Number, which is the line number of the file
6474 position given with {expr}. The {expr} argument is a string.
zeertzjq02f3eba2024-06-12 20:45:24 +02006475 See |getpos()| for accepted positions.
6476
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006477 To get the column number use |col()|. To get both use
6478 |getpos()|.
zeertzjq02f3eba2024-06-12 20:45:24 +02006479
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006480 With the optional {winid} argument the values are obtained for
6481 that window instead of the current window.
zeertzjq02f3eba2024-06-12 20:45:24 +02006482
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01006483 Returns 0 for invalid values of {expr} and {winid}.
zeertzjq02f3eba2024-06-12 20:45:24 +02006484
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006485 Examples: >
6486 line(".") line number of the cursor
6487 line(".", winid) idem, in window "winid"
6488 line("'t") line number of mark t
Bram Moolenaarc51cf032022-02-26 12:25:45 +00006489 line("'" .. marker) line number of mark marker
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006490<
6491 To jump to the last known position when opening a file see
6492 |last-position-jump|.
6493
6494 Can also be used as a |method|: >
6495 GetValue()->line()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006496<
6497 Return type: |Number|
6498
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006499
6500line2byte({lnum}) *line2byte()*
6501 Return the byte count from the start of the buffer for line
6502 {lnum}. This includes the end-of-line character, depending on
6503 the 'fileformat' option for the current buffer. The first
6504 line returns 1. 'encoding' matters, 'fileencoding' is ignored.
6505 This can also be used to get the byte count for the line just
6506 below the last line: >
6507 line2byte(line("$") + 1)
6508< This is the buffer size plus one. If 'fileencoding' is empty
6509 it is the file size plus one. {lnum} is used like with
6510 |getline()|. When {lnum} is invalid, or the |+byte_offset|
6511 feature has been disabled at compile time, -1 is returned.
6512 Also see |byte2line()|, |go| and |:goto|.
6513
6514 Can also be used as a |method|: >
6515 GetLnum()->line2byte()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006516<
6517 Return type: |Number|
6518
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006519
6520lispindent({lnum}) *lispindent()*
6521 Get the amount of indent for line {lnum} according the lisp
6522 indenting rules, as with 'lisp'.
6523 The indent is counted in spaces, the value of 'tabstop' is
6524 relevant. {lnum} is used just like in |getline()|.
Bram Moolenaar8e145b82022-05-21 20:17:31 +01006525 When {lnum} is invalid -1 is returned. In |Vim9| script an
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006526 error is given.
6527
6528 Can also be used as a |method|: >
6529 GetLnum()->lispindent()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006530<
6531 Return type: |Number|
6532
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006533
6534list2blob({list}) *list2blob()*
6535 Return a Blob concatenating all the number values in {list}.
6536 Examples: >
6537 list2blob([1, 2, 3, 4]) returns 0z01020304
6538 list2blob([]) returns 0z
6539< Returns an empty Blob on error. If one of the numbers is
6540 negative or more than 255 error *E1239* is given.
6541
6542 |blob2list()| does the opposite.
6543
6544 Can also be used as a |method|: >
6545 GetList()->list2blob()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006546<
6547 Return type: |Blob|
6548
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006549
6550list2str({list} [, {utf8}]) *list2str()*
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006551 Convert each number in {list} to a character string and
6552 concatenates them all. Examples: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006553 list2str([32]) returns " "
6554 list2str([65, 66, 67]) returns "ABC"
6555< The same can be done (slowly) with: >
6556 join(map(list, {nr, val -> nr2char(val)}), '')
6557< |str2list()| does the opposite.
6558
6559 When {utf8} is omitted or zero, the current 'encoding' is used.
6560 When {utf8} is TRUE, always return UTF-8 characters.
6561 With UTF-8 composing characters work as expected: >
6562 list2str([97, 769]) returns "á"
6563<
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01006564 Returns an empty string on error.
6565
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006566 Can also be used as a |method|: >
6567 GetList()->list2str()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006568<
6569 Return type: |String|
6570
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006571
Yegappan Lakshmanan9cb865e2025-03-23 16:42:16 +01006572list2tuple({list}) *list2tuple()*
6573 Create a Tuple from a shallow copy of the list items.
6574 Examples: >
6575 list2tuple([1, 2, 3]) returns (1, 2, 3)
6576< |tuple2list()| does the opposite.
6577
6578 This function doesn't recursively convert all the List items
6579 in {list} to a Tuple. Note that the items are identical
6580 between the list and the tuple, changing an item changes the
6581 contents of both the tuple and the list.
6582
6583 Returns an empty tuple on error.
6584
6585 Can also be used as a |method|: >
6586 GetList()->list2tuple()
6587<
6588 Return type: tuple<{type}> (depending on the given |List|)
6589
6590
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006591listener_add({callback} [, {buf}]) *listener_add()*
6592 Add a callback function that will be invoked when changes have
6593 been made to buffer {buf}.
6594 {buf} refers to a buffer name or number. For the accepted
6595 values, see |bufname()|. When {buf} is omitted the current
6596 buffer is used.
6597 Returns a unique ID that can be passed to |listener_remove()|.
6598
6599 The {callback} is invoked with five arguments:
Bram Moolenaar944697a2022-02-20 19:48:20 +00006600 bufnr the buffer that was changed
6601 start first changed line number
6602 end first line number below the change
6603 added number of lines added, negative if lines were
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006604 deleted
Bram Moolenaar944697a2022-02-20 19:48:20 +00006605 changes a List of items with details about the changes
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006606
6607 Example: >
6608 func Listener(bufnr, start, end, added, changes)
6609 echo 'lines ' .. a:start .. ' until ' .. a:end .. ' changed'
6610 endfunc
6611 call listener_add('Listener', bufnr)
6612
Bram Moolenaar944697a2022-02-20 19:48:20 +00006613< The List cannot be changed. Each item in "changes" is a
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006614 dictionary with these entries:
6615 lnum the first line number of the change
6616 end the first line below the change
6617 added number of lines added; negative if lines were
6618 deleted
6619 col first column in "lnum" that was affected by
6620 the change; one if unknown or the whole line
6621 was affected; this is a byte index, first
6622 character has a value of one.
Bram Moolenaar3c053a12022-10-16 13:11:12 +01006623 When lines are inserted (not when a line is split, e.g. by
6624 typing CR in Insert mode) the values are:
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006625 lnum line above which the new line is added
6626 end equal to "lnum"
6627 added number of lines inserted
6628 col 1
6629 When lines are deleted the values are:
6630 lnum the first deleted line
6631 end the line below the first deleted line, before
6632 the deletion was done
6633 added negative, number of lines deleted
6634 col 1
6635 When lines are changed:
6636 lnum the first changed line
6637 end the line below the last changed line
6638 added 0
6639 col first column with a change or 1
6640
6641 The entries are in the order the changes were made, thus the
6642 most recent change is at the end. The line numbers are valid
6643 when the callback is invoked, but later changes may make them
6644 invalid, thus keeping a copy for later might not work.
6645
6646 The {callback} is invoked just before the screen is updated,
6647 when |listener_flush()| is called or when a change is being
6648 made that changes the line count in a way it causes a line
6649 number in the list of changes to become invalid.
6650
6651 The {callback} is invoked with the text locked, see
6652 |textlock|. If you do need to make changes to the buffer, use
6653 a timer to do this later |timer_start()|.
6654
6655 The {callback} is not invoked when the buffer is first loaded.
6656 Use the |BufReadPost| autocmd event to handle the initial text
6657 of a buffer.
6658 The {callback} is also not invoked when the buffer is
6659 unloaded, use the |BufUnload| autocmd event for that.
6660
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01006661 Returns zero if {callback} or {buf} is invalid.
6662
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006663 Can also be used as a |method|, the base is passed as the
6664 second argument: >
6665 GetBuffer()->listener_add(callback)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006666<
6667 Return type: |Number|
6668
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006669
6670listener_flush([{buf}]) *listener_flush()*
6671 Invoke listener callbacks for buffer {buf}. If there are no
6672 pending changes then no callbacks are invoked.
6673
6674 {buf} refers to a buffer name or number. For the accepted
6675 values, see |bufname()|. When {buf} is omitted the current
6676 buffer is used.
6677
6678 Can also be used as a |method|: >
6679 GetBuffer()->listener_flush()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006680<
6681 Return type: |Number|
6682
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006683
6684listener_remove({id}) *listener_remove()*
6685 Remove a listener previously added with listener_add().
6686 Returns FALSE when {id} could not be found, TRUE when {id} was
6687 removed.
6688
6689 Can also be used as a |method|: >
6690 GetListenerId()->listener_remove()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006691<
6692 Return type: |Number|
6693
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006694
6695localtime() *localtime()*
6696 Return the current time, measured as seconds since 1st Jan
6697 1970. See also |strftime()|, |strptime()| and |getftime()|.
6698
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006699 Return type: |Number|
6700
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006701
6702log({expr}) *log()*
6703 Return the natural logarithm (base e) of {expr} as a |Float|.
6704 {expr} must evaluate to a |Float| or a |Number| in the range
6705 (0, inf].
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01006706 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006707 Examples: >
6708 :echo log(10)
6709< 2.302585 >
6710 :echo log(exp(5))
6711< 5.0
6712
6713 Can also be used as a |method|: >
6714 Compute()->log()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006715<
6716 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006717
6718
6719log10({expr}) *log10()*
6720 Return the logarithm of Float {expr} to base 10 as a |Float|.
6721 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01006722 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006723 Examples: >
6724 :echo log10(1000)
6725< 3.0 >
6726 :echo log10(0.01)
6727< -2.0
6728
6729 Can also be used as a |method|: >
6730 Compute()->log10()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006731<
6732 Return type: |Float|
6733
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006734
6735luaeval({expr} [, {expr}]) *luaeval()*
6736 Evaluate Lua expression {expr} and return its result converted
6737 to Vim data structures. Second {expr} may hold additional
6738 argument accessible as _A inside first {expr}.
6739 Strings are returned as they are.
6740 Boolean objects are converted to numbers.
Bram Moolenaar73e28dc2022-09-17 21:08:33 +01006741 Numbers are converted to |Float| values.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006742 Dictionaries and lists obtained by vim.eval() are returned
6743 as-is.
6744 Other objects are returned as zero without any errors.
6745 See |lua-luaeval| for more details.
6746 Note that in a `:def` function local variables are not visible
6747 to {expr}.
6748
6749 Can also be used as a |method|: >
6750 GetExpr()->luaeval()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006751<
6752 Return type: any, depending on {expr}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006753
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006754 {only available when compiled with the |+lua| feature}
6755
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006756
6757map({expr1}, {expr2}) *map()*
6758 {expr1} must be a |List|, |String|, |Blob| or |Dictionary|.
Bram Moolenaar944697a2022-02-20 19:48:20 +00006759 When {expr1} is a |List| or |Dictionary|, replace each
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006760 item in {expr1} with the result of evaluating {expr2}.
6761 For a |Blob| each byte is replaced.
6762 For a |String|, each character, including composing
6763 characters, is replaced.
6764 If the item type changes you may want to use |mapnew()| to
6765 create a new List or Dictionary. This is required when using
6766 Vim9 script.
6767
6768 {expr2} must be a |String| or |Funcref|.
6769
6770 If {expr2} is a |String|, inside {expr2} |v:val| has the value
6771 of the current item. For a |Dictionary| |v:key| has the key
6772 of the current item and for a |List| |v:key| has the index of
6773 the current item. For a |Blob| |v:key| has the index of the
6774 current byte. For a |String| |v:key| has the index of the
6775 current character.
6776 Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00006777 :call map(mylist, '"> " .. v:val .. " <"')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006778< This puts "> " before and " <" after each item in "mylist".
6779
6780 Note that {expr2} is the result of an expression and is then
6781 used as an expression again. Often it is good to use a
6782 |literal-string| to avoid having to double backslashes. You
6783 still have to double ' quotes
6784
6785 If {expr2} is a |Funcref| it is called with two arguments:
6786 1. The key or the index of the current item.
6787 2. the value of the current item.
Bram Moolenaarb59ae592022-11-23 23:46:31 +00006788 With a legacy script lambda you don't get an error if it only
6789 accepts one argument, but with a Vim9 lambda you get "E1106:
6790 One argument too many", the number of arguments must match.
6791
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006792 The function must return the new value of the item. Example
6793 that changes each value by "key-value": >
6794 func KeyValue(key, val)
Bram Moolenaarc51cf032022-02-26 12:25:45 +00006795 return a:key .. '-' .. a:val
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006796 endfunc
6797 call map(myDict, function('KeyValue'))
6798< It is shorter when using a |lambda|: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00006799 call map(myDict, {key, val -> key .. '-' .. val})
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006800< If you do not use "val" you can leave it out: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00006801 call map(myDict, {key -> 'item: ' .. key})
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006802< If you do not use "key" you can use a short name: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00006803 call map(myDict, {_, val -> 'item: ' .. val})
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006804<
6805 The operation is done in-place for a |List| and |Dictionary|.
6806 If you want it to remain unmodified make a copy first: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00006807 :let tlist = map(copy(mylist), ' v:val .. "\t"')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006808
6809< Returns {expr1}, the |List| or |Dictionary| that was filtered,
6810 or a new |Blob| or |String|.
6811 When an error is encountered while evaluating {expr2} no
6812 further items in {expr1} are processed.
6813 When {expr2} is a Funcref errors inside a function are ignored,
6814 unless it was defined with the "abort" flag.
6815
6816 Can also be used as a |method|: >
6817 mylist->map(expr2)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006818<
6819 Return type: |String|, |Blob|, list<{type}> or dict<{type}>
6820 depending on {expr1}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006821
6822
6823maparg({name} [, {mode} [, {abbr} [, {dict}]]]) *maparg()*
6824 When {dict} is omitted or zero: Return the rhs of mapping
6825 {name} in mode {mode}. The returned String has special
6826 characters translated like in the output of the ":map" command
Ernie Rael09661202022-04-25 14:40:44 +01006827 listing. When {dict} is TRUE a dictionary is returned, see
6828 below. To get a list of all mappings see |maplist()|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006829
6830 When there is no mapping for {name}, an empty String is
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01006831 returned if {dict} is FALSE, otherwise returns an empty Dict.
6832 When the mapping for {name} is empty, then "<Nop>" is
6833 returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006834
6835 The {name} can have special key names, like in the ":map"
6836 command.
6837
6838 {mode} can be one of these strings:
6839 "n" Normal
6840 "v" Visual (including Select)
6841 "o" Operator-pending
6842 "i" Insert
6843 "c" Cmd-line
6844 "s" Select
6845 "x" Visual
6846 "l" langmap |language-mapping|
6847 "t" Terminal-Job
6848 "" Normal, Visual and Operator-pending
6849 When {mode} is omitted, the modes for "" are used.
6850
6851 When {abbr} is there and it is |TRUE| use abbreviations
6852 instead of mappings.
6853
6854 When {dict} is there and it is |TRUE| return a dictionary
6855 containing all the information of the mapping with the
Ernie Rael659c2402022-04-24 18:40:28 +01006856 following items: *mapping-dict*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006857 "lhs" The {lhs} of the mapping as it would be typed
6858 "lhsraw" The {lhs} of the mapping as raw bytes
6859 "lhsrawalt" The {lhs} of the mapping as raw bytes, alternate
6860 form, only present when it differs from "lhsraw"
6861 "rhs" The {rhs} of the mapping as typed.
6862 "silent" 1 for a |:map-silent| mapping, else 0.
6863 "noremap" 1 if the {rhs} of the mapping is not remappable.
6864 "script" 1 if mapping was defined with <script>.
6865 "expr" 1 for an expression mapping (|:map-<expr>|).
6866 "buffer" 1 for a buffer local mapping (|:map-local|).
6867 "mode" Modes for which the mapping is defined. In
6868 addition to the modes mentioned above, these
6869 characters will be used:
6870 " " Normal, Visual and Operator-pending
6871 "!" Insert and Commandline mode
6872 (|mapmode-ic|)
6873 "sid" The script local ID, used for <sid> mappings
Bram Moolenaar71badf92023-04-22 22:40:14 +01006874 (|<SID>|). Negative for special contexts.
Bram Moolenaara9528b32022-01-18 20:51:35 +00006875 "scriptversion" The version of the script. 999999 for
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01006876 |Vim9| script.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006877 "lnum" The line number in "sid", zero if unknown.
6878 "nowait" Do not wait for other, longer mappings.
6879 (|:map-<nowait>|).
Bram Moolenaar921bde82022-05-09 19:50:35 +01006880 "abbr" True if this is an abbreviation |abbreviations|.
Ernie Raeld8f5f762022-05-10 17:50:39 +01006881 "mode_bits" Vim's internal binary representation of "mode".
6882 |mapset()| ignores this; only "mode" is used.
6883 See |maplist()| for usage examples. The values
6884 are from src/vim.h and may change in the future.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006885
6886 The dictionary can be used to restore a mapping with
6887 |mapset()|.
6888
6889 The mappings local to the current buffer are checked first,
6890 then the global mappings.
6891 This function can be used to map a key even when it's already
6892 mapped, and have it do the original mapping too. Sketch: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00006893 exe 'nnoremap <Tab> ==' .. maparg('<Tab>', 'n')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006894
6895< Can also be used as a |method|: >
6896 GetKey()->maparg('n')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006897<
6898 Return type: |String| or dict<any> depending on {dict}
6899
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006900
6901mapcheck({name} [, {mode} [, {abbr}]]) *mapcheck()*
6902 Check if there is a mapping that matches with {name} in mode
6903 {mode}. See |maparg()| for {mode} and special names in
6904 {name}.
6905 When {abbr} is there and it is |TRUE| use abbreviations
6906 instead of mappings.
6907 A match happens with a mapping that starts with {name} and
6908 with a mapping which is equal to the start of {name}.
6909
6910 matches mapping "a" "ab" "abc" ~
6911 mapcheck("a") yes yes yes
6912 mapcheck("abc") yes yes yes
6913 mapcheck("ax") yes no no
6914 mapcheck("b") no no no
6915
6916 The difference with maparg() is that mapcheck() finds a
6917 mapping that matches with {name}, while maparg() only finds a
6918 mapping for {name} exactly.
6919 When there is no mapping that starts with {name}, an empty
6920 String is returned. If there is one, the RHS of that mapping
6921 is returned. If there are several mappings that start with
6922 {name}, the RHS of one of them is returned. This will be
6923 "<Nop>" if the RHS is empty.
6924 The mappings local to the current buffer are checked first,
6925 then the global mappings.
6926 This function can be used to check if a mapping can be added
6927 without being ambiguous. Example: >
6928 :if mapcheck("_vv") == ""
6929 : map _vv :set guifont=7x13<CR>
6930 :endif
6931< This avoids adding the "_vv" mapping when there already is a
6932 mapping for "_v" or for "_vvv".
6933
6934 Can also be used as a |method|: >
6935 GetKey()->mapcheck('n')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006936<
6937 Return type: |String|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006938
6939
Ernie Rael09661202022-04-25 14:40:44 +01006940maplist([{abbr}]) *maplist()*
6941 Returns a |List| of all mappings. Each List item is a |Dict|,
6942 the same as what is returned by |maparg()|, see
6943 |mapping-dict|. When {abbr} is there and it is |TRUE| use
6944 abbreviations instead of mappings.
6945
6946 Example to show all mappings with 'MultiMatch' in rhs: >
6947 vim9script
6948 echo maplist()->filter(
6949 (_, m) => match(m.rhs, 'MultiMatch') >= 0)
Ernie Raeld8f5f762022-05-10 17:50:39 +01006950< It can be tricky to find mappings for particular |:map-modes|.
6951 |mapping-dict|'s "mode_bits" can simplify this. For example,
6952 the mode_bits for Normal, Insert or Command-line modes are
6953 0x19. To find all the mappings available in those modes you
6954 can do: >
6955 vim9script
6956 var saved_maps = []
6957 for m in maplist()
6958 if and(m.mode_bits, 0x19) != 0
6959 saved_maps->add(m)
6960 endif
6961 endfor
6962 echo saved_maps->mapnew((_, m) => m.lhs)
6963< The values of the mode_bits are defined in Vim's src/vim.h
6964 file and they can be discovered at runtime using
6965 |:map-commands| and "maplist()". Example: >
6966 vim9script
6967 omap xyzzy <Nop>
6968 var op_bit = maplist()->filter(
6969 (_, m) => m.lhs == 'xyzzy')[0].mode_bits
6970 ounmap xyzzy
6971 echo printf("Operator-pending mode bit: 0x%x", op_bit)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006972<
6973 Return type: list<dict<any>>
Ernie Rael09661202022-04-25 14:40:44 +01006974
6975
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006976mapnew({expr1}, {expr2}) *mapnew()*
6977 Like |map()| but instead of replacing items in {expr1} a new
6978 List or Dictionary is created and returned. {expr1} remains
6979 unchanged. Items can still be changed by {expr2}, if you
6980 don't want that use |deepcopy()| first.
6981
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006982 Return type: |String|, |Blob|, list<{type}> or dict<{type}>
6983 depending on {expr1}
6984
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006985
6986mapset({mode}, {abbr}, {dict}) *mapset()*
Ernie Rael51d04d12022-05-04 15:40:22 +01006987mapset({dict})
6988 Restore a mapping from a dictionary, possibly returned by
6989 |maparg()| or |maplist()|. A buffer mapping, when dict.buffer
6990 is true, is set on the current buffer; it is up to the caller
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01006991 to ensure that the intended buffer is the current buffer. This
Ernie Rael51d04d12022-05-04 15:40:22 +01006992 feature allows copying mappings from one buffer to another.
6993 The dict.mode value may restore a single mapping that covers
6994 more than one mode, like with mode values of '!', ' ', 'nox',
6995 or 'v'. *E1276*
6996
6997 In the first form, {mode} and {abbr} should be the same as
6998 for the call to |maparg()|. *E460*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006999 {mode} is used to define the mode in which the mapping is set,
7000 not the "mode" entry in {dict}.
7001 Example for saving and restoring a mapping: >
7002 let save_map = maparg('K', 'n', 0, 1)
7003 nnoremap K somethingelse
7004 ...
7005 call mapset('n', 0, save_map)
7006< Note that if you are going to replace a map in several modes,
Ernie Rael51d04d12022-05-04 15:40:22 +01007007 e.g. with `:map!`, you need to save/restore the mapping for
7008 all of them, when they might differ.
7009
7010 In the second form, with {dict} as the only argument, mode
7011 and abbr are taken from the dict.
7012 Example: >
7013 vim9script
7014 var save_maps = maplist()->filter(
7015 (_, m) => m.lhs == 'K')
7016 nnoremap K somethingelse
7017 cnoremap K somethingelse2
7018 # ...
7019 unmap K
7020 for d in save_maps
7021 mapset(d)
7022 endfor
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007023<
7024 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007025
7026
7027match({expr}, {pat} [, {start} [, {count}]]) *match()*
7028 When {expr} is a |List| then this returns the index of the
7029 first item where {pat} matches. Each item is used as a
7030 String, |Lists| and |Dictionaries| are used as echoed.
7031
7032 Otherwise, {expr} is used as a String. The result is a
7033 Number, which gives the index (byte offset) in {expr} where
7034 {pat} matches.
7035
7036 A match at the first character or |List| item returns zero.
7037 If there is no match -1 is returned.
7038
7039 For getting submatches see |matchlist()|.
7040 Example: >
7041 :echo match("testing", "ing") " results in 4
7042 :echo match([1, 'x'], '\a') " results in 1
7043< See |string-match| for how {pat} is used.
7044 *strpbrk()*
7045 Vim doesn't have a strpbrk() function. But you can do: >
7046 :let sepidx = match(line, '[.,;: \t]')
7047< *strcasestr()*
7048 Vim doesn't have a strcasestr() function. But you can add
7049 "\c" to the pattern to ignore case: >
7050 :let idx = match(haystack, '\cneedle')
7051<
7052 If {start} is given, the search starts from byte index
7053 {start} in a String or item {start} in a |List|.
7054 The result, however, is still the index counted from the
7055 first character/item. Example: >
7056 :echo match("testing", "ing", 2)
7057< result is again "4". >
7058 :echo match("testing", "ing", 4)
7059< result is again "4". >
7060 :echo match("testing", "t", 2)
7061< result is "3".
7062 For a String, if {start} > 0 then it is like the string starts
7063 {start} bytes later, thus "^" will match at {start}. Except
7064 when {count} is given, then it's like matches before the
7065 {start} byte are ignored (this is a bit complicated to keep it
7066 backwards compatible).
7067 For a String, if {start} < 0, it will be set to 0. For a list
7068 the index is counted from the end.
7069 If {start} is out of range ({start} > strlen({expr}) for a
7070 String or {start} > len({expr}) for a |List|) -1 is returned.
7071
7072 When {count} is given use the {count}'th match. When a match
7073 is found in a String the search for the next one starts one
7074 character further. Thus this example results in 1: >
7075 echo match("testing", "..", 0, 2)
7076< In a |List| the search continues in the next item.
7077 Note that when {count} is added the way {start} works changes,
7078 see above.
7079
Yegappan Lakshmanana35235e2024-02-24 10:09:43 +01007080 *match-pattern*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007081 See |pattern| for the patterns that are accepted.
7082 The 'ignorecase' option is used to set the ignore-caseness of
7083 the pattern. 'smartcase' is NOT used. The matching is always
7084 done like 'magic' is set and 'cpoptions' is empty.
7085 Note that a match at the start is preferred, thus when the
7086 pattern is using "*" (any number of matches) it tends to find
7087 zero matches at the start instead of a number of matches
7088 further down in the text.
7089
7090 Can also be used as a |method|: >
7091 GetText()->match('word')
7092 GetList()->match('word')
7093<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007094 Return type: |Number|
7095
7096
Bram Moolenaar2f0936c2022-01-08 21:51:59 +00007097 *matchadd()* *E290* *E798* *E799* *E801* *E957*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007098matchadd({group}, {pattern} [, {priority} [, {id} [, {dict}]]])
7099 Defines a pattern to be highlighted in the current window (a
7100 "match"). It will be highlighted with {group}. Returns an
7101 identification number (ID), which can be used to delete the
7102 match using |matchdelete()|. The ID is bound to the window.
7103 Matching is case sensitive and magic, unless case sensitivity
7104 or magicness are explicitly overridden in {pattern}. The
7105 'magic', 'smartcase' and 'ignorecase' options are not used.
7106 The "Conceal" value is special, it causes the match to be
7107 concealed.
7108
7109 The optional {priority} argument assigns a priority to the
7110 match. A match with a high priority will have its
7111 highlighting overrule that of a match with a lower priority.
7112 A priority is specified as an integer (negative numbers are no
7113 exception). If the {priority} argument is not specified, the
7114 default priority is 10. The priority of 'hlsearch' is zero,
7115 hence all matches with a priority greater than zero will
7116 overrule it. Syntax highlighting (see 'syntax') is a separate
7117 mechanism, and regardless of the chosen priority a match will
7118 always overrule syntax highlighting.
7119
7120 The optional {id} argument allows the request for a specific
7121 match ID. If a specified ID is already taken, an error
7122 message will appear and the match will not be added. An ID
7123 is specified as a positive integer (zero excluded). IDs 1, 2
7124 and 3 are reserved for |:match|, |:2match| and |:3match|,
Bram Moolenaar2ecbe532022-07-29 21:36:21 +01007125 respectively. 3 is reserved for use by the |matchparen|
7126 plugin.
Bram Moolenaarb529cfb2022-07-25 15:42:07 +01007127 If the {id} argument is not specified or -1, |matchadd()|
Bram Moolenaar9f573a82022-09-29 13:50:08 +01007128 automatically chooses a free ID, which is at least 1000.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007129
7130 The optional {dict} argument allows for further custom
7131 values. Currently this is used to specify a match specific
7132 conceal character that will be shown for |hl-Conceal|
7133 highlighted matches. The dict can have the following members:
7134
7135 conceal Special character to show instead of the
7136 match (only for |hl-Conceal| highlighted
7137 matches, see |:syn-cchar|)
7138 window Instead of the current window use the
7139 window with this number or window ID.
7140
7141 The number of matches is not limited, as it is the case with
7142 the |:match| commands.
7143
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01007144 Returns -1 on error.
7145
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007146 Example: >
7147 :highlight MyGroup ctermbg=green guibg=green
7148 :let m = matchadd("MyGroup", "TODO")
7149< Deletion of the pattern: >
7150 :call matchdelete(m)
7151
7152< A list of matches defined by |matchadd()| and |:match| are
7153 available from |getmatches()|. All matches can be deleted in
7154 one operation by |clearmatches()|.
7155
7156 Can also be used as a |method|: >
7157 GetGroup()->matchadd('TODO')
7158<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007159 Return type: |Number|
7160
7161
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007162 *matchaddpos()*
7163matchaddpos({group}, {pos} [, {priority} [, {id} [, {dict}]]])
7164 Same as |matchadd()|, but requires a list of positions {pos}
7165 instead of a pattern. This command is faster than |matchadd()|
Shane Harperc1b39842024-07-17 19:40:40 +02007166 because it does not handle regular expressions and it sets
7167 buffer line boundaries to redraw screen. It is supposed to be
7168 used when fast match additions and deletions are required, for
7169 example to highlight matching parentheses.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007170
7171 {pos} is a list of positions. Each position can be one of
7172 these:
7173 - A number. This whole line will be highlighted. The first
7174 line has number 1.
7175 - A list with one number, e.g., [23]. The whole line with this
7176 number will be highlighted.
7177 - A list with two numbers, e.g., [23, 11]. The first number is
7178 the line number, the second one is the column number (first
7179 column is 1, the value must correspond to the byte index as
7180 |col()| would return). The character at this position will
7181 be highlighted.
7182 - A list with three numbers, e.g., [23, 11, 3]. As above, but
7183 the third number gives the length of the highlight in bytes.
7184
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01007185 Returns -1 on error.
7186
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007187 Example: >
7188 :highlight MyGroup ctermbg=green guibg=green
7189 :let m = matchaddpos("MyGroup", [[23, 24], 34])
7190< Deletion of the pattern: >
7191 :call matchdelete(m)
7192
7193< Matches added by |matchaddpos()| are returned by
7194 |getmatches()|.
7195
7196 Can also be used as a |method|: >
7197 GetGroup()->matchaddpos([23, 11])
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007198<
7199 Return type: |Number|
7200
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007201
7202matcharg({nr}) *matcharg()*
7203 Selects the {nr} match item, as set with a |:match|,
7204 |:2match| or |:3match| command.
7205 Return a |List| with two elements:
7206 The name of the highlight group used
7207 The pattern used.
7208 When {nr} is not 1, 2 or 3 returns an empty |List|.
7209 When there is no match item set returns ['', ''].
7210 This is useful to save and restore a |:match|.
7211 Highlighting matches using the |:match| commands are limited
7212 to three matches. |matchadd()| does not have this limitation.
7213
7214 Can also be used as a |method|: >
7215 GetMatch()->matcharg()
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +01007216<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007217 Return type: list<string>
7218
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +01007219 *matchbufline()*
7220matchbufline({buf}, {pat}, {lnum}, {end}, [, {dict}])
7221 Returns the |List| of matches in lines from {lnum} to {end} in
7222 buffer {buf} where {pat} matches.
7223
7224 {lnum} and {end} can either be a line number or the string "$"
7225 to refer to the last line in {buf}.
7226
7227 The {dict} argument supports following items:
7228 submatches include submatch information (|/\(|)
7229
7230 For each match, a |Dict| with the following items is returned:
7231 byteidx starting byte index of the match
Yegappan Lakshmananeb3475d2024-01-15 11:08:25 -08007232 lnum line number where there is a match
7233 text matched string
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +01007234 Note that there can be multiple matches in a single line.
7235
7236 This function works only for loaded buffers. First call
7237 |bufload()| if needed.
7238
Yegappan Lakshmanana35235e2024-02-24 10:09:43 +01007239 See |match-pattern| for information about the effect of some
7240 option settings on the pattern.
7241
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +01007242 When {buf} is not a valid buffer, the buffer is not loaded or
7243 {lnum} or {end} is not valid then an error is given and an
7244 empty |List| is returned.
7245
7246 Examples: >
Yegappan Lakshmananeb3475d2024-01-15 11:08:25 -08007247 " Assuming line 3 in buffer 5 contains "a"
7248 :echo matchbufline(5, '\<\k\+\>', 3, 3)
7249 [{'lnum': 3, 'byteidx': 0, 'text': 'a'}]
7250 " Assuming line 4 in buffer 10 contains "tik tok"
7251 :echo matchbufline(10, '\<\k\+\>', 1, 4)
7252 [{'lnum': 4, 'byteidx': 0, 'text': 'tik'}, {'lnum': 4, 'byteidx': 4, 'text': 'tok'}]
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +01007253<
7254 If {submatch} is present and is v:true, then submatches like
Yegappan Lakshmananeb3475d2024-01-15 11:08:25 -08007255 "\1", "\2", etc. are also returned. Example: >
7256 " Assuming line 2 in buffer 2 contains "acd"
7257 :echo matchbufline(2, '\(a\)\?\(b\)\?\(c\)\?\(.*\)', 2, 2
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +01007258 \ {'submatches': v:true})
Yegappan Lakshmananeb3475d2024-01-15 11:08:25 -08007259 [{'lnum': 2, 'byteidx': 0, 'text': 'acd', 'submatches': ['a', '', 'c', 'd', '', '', '', '', '']}]
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +01007260< The "submatches" List always contains 9 items. If a submatch
7261 is not found, then an empty string is returned for that
7262 submatch.
7263
7264 Can also be used as a |method|: >
7265 GetBuffer()->matchbufline('mypat', 1, '$')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007266<
7267 Return type: list<dict<any>> or list<any>
7268
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007269
h-east624bb832024-11-09 18:37:32 +01007270matchdelete({id} [, {win}) *matchdelete()* *E802* *E803*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007271 Deletes a match with ID {id} previously defined by |matchadd()|
7272 or one of the |:match| commands. Returns 0 if successful,
7273 otherwise -1. See example for |matchadd()|. All matches can
7274 be deleted in one operation by |clearmatches()|.
7275 If {win} is specified, use the window with this number or
7276 window ID instead of the current window.
7277
7278 Can also be used as a |method|: >
7279 GetMatch()->matchdelete()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007280<
7281 Return type: |Number|
7282
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007283
7284matchend({expr}, {pat} [, {start} [, {count}]]) *matchend()*
7285 Same as |match()|, but return the index of first character
7286 after the match. Example: >
7287 :echo matchend("testing", "ing")
7288< results in "7".
7289 *strspn()* *strcspn()*
7290 Vim doesn't have a strspn() or strcspn() function, but you can
7291 do it with matchend(): >
7292 :let span = matchend(line, '[a-zA-Z]')
7293 :let span = matchend(line, '[^a-zA-Z]')
7294< Except that -1 is returned when there are no matches.
7295
7296 The {start}, if given, has the same meaning as for |match()|. >
7297 :echo matchend("testing", "ing", 2)
7298< results in "7". >
7299 :echo matchend("testing", "ing", 5)
7300< result is "-1".
7301 When {expr} is a |List| the result is equal to |match()|.
7302
7303 Can also be used as a |method|: >
7304 GetText()->matchend('word')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007305<
7306 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007307
7308
7309matchfuzzy({list}, {str} [, {dict}]) *matchfuzzy()*
7310 If {list} is a list of strings, then returns a |List| with all
7311 the strings in {list} that fuzzy match {str}. The strings in
7312 the returned list are sorted based on the matching score.
7313
7314 The optional {dict} argument always supports the following
7315 items:
zeertzjq9af2bc02022-05-11 14:15:37 +01007316 matchseq When this item is present return only matches
7317 that contain the characters in {str} in the
7318 given sequence.
Kazuyuki Miyagi47f1a552022-06-17 18:30:03 +01007319 limit Maximum number of matches in {list} to be
7320 returned. Zero means no limit.
glepnir28e40a72025-03-16 21:24:22 +01007321 camelcase Use enhanced camel case scoring making results
7322 better suited for completion related to
zeertzjqc4815c12025-03-18 20:28:00 +01007323 programming languages. Defaults to v:true.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007324
7325 If {list} is a list of dictionaries, then the optional {dict}
7326 argument supports the following additional items:
Yasuhiro Matsumoto9029a6e2022-04-16 12:35:35 +01007327 key Key of the item which is fuzzy matched against
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007328 {str}. The value of this item should be a
7329 string.
7330 text_cb |Funcref| that will be called for every item
7331 in {list} to get the text for fuzzy matching.
7332 This should accept a dictionary item as the
7333 argument and return the text for that item to
7334 use for fuzzy matching.
7335
7336 {str} is treated as a literal string and regular expression
7337 matching is NOT supported. The maximum supported {str} length
7338 is 256.
7339
7340 When {str} has multiple words each separated by white space,
7341 then the list of strings that have all the words is returned.
7342
7343 If there are no matching strings or there is an error, then an
7344 empty list is returned. If length of {str} is greater than
7345 256, then returns an empty list.
7346
Yasuhiro Matsumoto9029a6e2022-04-16 12:35:35 +01007347 When {limit} is given, matchfuzzy() will find up to this
7348 number of matches in {list} and return them in sorted order.
7349
Bram Moolenaar1588bc82022-03-08 21:35:07 +00007350 Refer to |fuzzy-matching| for more information about fuzzy
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007351 matching strings.
7352
7353 Example: >
7354 :echo matchfuzzy(["clay", "crow"], "cay")
7355< results in ["clay"]. >
7356 :echo getbufinfo()->map({_, v -> v.name})->matchfuzzy("ndl")
7357< results in a list of buffer names fuzzy matching "ndl". >
7358 :echo getbufinfo()->matchfuzzy("ndl", {'key' : 'name'})
7359< results in a list of buffer information dicts with buffer
7360 names fuzzy matching "ndl". >
7361 :echo getbufinfo()->matchfuzzy("spl",
7362 \ {'text_cb' : {v -> v.name}})
7363< results in a list of buffer information dicts with buffer
7364 names fuzzy matching "spl". >
7365 :echo v:oldfiles->matchfuzzy("test")
7366< results in a list of file names fuzzy matching "test". >
7367 :let l = readfile("buffer.c")->matchfuzzy("str")
7368< results in a list of lines in "buffer.c" fuzzy matching "str". >
7369 :echo ['one two', 'two one']->matchfuzzy('two one')
7370< results in ['two one', 'one two']. >
7371 :echo ['one two', 'two one']->matchfuzzy('two one',
7372 \ {'matchseq': 1})
7373< results in ['two one'].
7374
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007375 Return type: list<string> or list<any>
7376
7377
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007378matchfuzzypos({list}, {str} [, {dict}]) *matchfuzzypos()*
7379 Same as |matchfuzzy()|, but returns the list of matched
7380 strings, the list of character positions where characters
7381 in {str} matches and a list of matching scores. You can
7382 use |byteidx()| to convert a character position to a byte
7383 position.
7384
7385 If {str} matches multiple times in a string, then only the
7386 positions for the best match is returned.
7387
7388 If there are no matching strings or there is an error, then a
7389 list with three empty list items is returned.
7390
7391 Example: >
7392 :echo matchfuzzypos(['testing'], 'tsg')
7393< results in [['testing'], [[0, 2, 6]], [99]] >
7394 :echo matchfuzzypos(['clay', 'lacy'], 'la')
7395< results in [['lacy', 'clay'], [[0, 1], [1, 2]], [153, 133]] >
7396 :echo [{'text': 'hello', 'id' : 10}]->matchfuzzypos('ll', {'key' : 'text'})
7397< results in [[{'id': 10, 'text': 'hello'}], [[2, 3]], [127]]
7398
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007399 Return type: list<list<any>>
7400
7401
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007402matchlist({expr}, {pat} [, {start} [, {count}]]) *matchlist()*
7403 Same as |match()|, but return a |List|. The first item in the
7404 list is the matched string, same as what matchstr() would
7405 return. Following items are submatches, like "\1", "\2", etc.
7406 in |:substitute|. When an optional submatch didn't match an
7407 empty string is used. Example: >
7408 echo matchlist('acd', '\(a\)\?\(b\)\?\(c\)\?\(.*\)')
7409< Results in: ['acd', 'a', '', 'c', 'd', '', '', '', '', '']
7410 When there is no match an empty list is returned.
7411
7412 You can pass in a List, but that is not very useful.
7413
7414 Can also be used as a |method|: >
7415 GetText()->matchlist('word')
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +01007416<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007417 Return type: list<string> or list<any>
7418
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +01007419 *matchstrlist()*
7420matchstrlist({list}, {pat} [, {dict}])
7421 Returns the |List| of matches in {list} where {pat} matches.
7422 {list} is a |List| of strings. {pat} is matched against each
7423 string in {list}.
7424
7425 The {dict} argument supports following items:
7426 submatches include submatch information (|/\(|)
7427
7428 For each match, a |Dict| with the following items is returned:
7429 byteidx starting byte index of the match.
7430 idx index in {list} of the match.
7431 text matched string
7432 submatches a List of submatches. Present only if
7433 "submatches" is set to v:true in {dict}.
7434
Yegappan Lakshmanana35235e2024-02-24 10:09:43 +01007435 See |match-pattern| for information about the effect of some
7436 option settings on the pattern.
7437
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +01007438 Example: >
Yegappan Lakshmananeb3475d2024-01-15 11:08:25 -08007439 :echo matchstrlist(['tik tok'], '\<\k\+\>')
7440 [{'idx': 0, 'byteidx': 0, 'text': 'tik'}, {'idx': 0, 'byteidx': 4, 'text': 'tok'}]
7441 :echo matchstrlist(['a', 'b'], '\<\k\+\>')
7442 [{'idx': 0, 'byteidx': 0, 'text': 'a'}, {'idx': 1, 'byteidx': 0, 'text': 'b'}]
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +01007443<
7444 If "submatches" is present and is v:true, then submatches like
7445 "\1", "\2", etc. are also returned. Example: >
7446 :echo matchstrlist(['acd'], '\(a\)\?\(b\)\?\(c\)\?\(.*\)',
7447 \ #{submatches: v:true})
7448 [{'idx': 0, 'byteidx': 0, 'text': 'acd', 'submatches': ['a', '', 'c', 'd', '', '', '', '', '']}]
7449< The "submatches" List always contains 9 items. If a submatch
7450 is not found, then an empty string is returned for that
7451 submatch.
7452
7453 Can also be used as a |method|: >
7454 GetListOfStrings()->matchstrlist('mypat')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007455<
7456 Return type: list<dict<any>> or list<any>
7457
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007458
7459matchstr({expr}, {pat} [, {start} [, {count}]]) *matchstr()*
7460 Same as |match()|, but return the matched string. Example: >
7461 :echo matchstr("testing", "ing")
7462< results in "ing".
7463 When there is no match "" is returned.
7464 The {start}, if given, has the same meaning as for |match()|. >
7465 :echo matchstr("testing", "ing", 2)
7466< results in "ing". >
7467 :echo matchstr("testing", "ing", 5)
7468< result is "".
7469 When {expr} is a |List| then the matching item is returned.
7470 The type isn't changed, it's not necessarily a String.
7471
7472 Can also be used as a |method|: >
7473 GetText()->matchstr('word')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007474<
7475 Return type: |String|
7476
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007477
7478matchstrpos({expr}, {pat} [, {start} [, {count}]]) *matchstrpos()*
7479 Same as |matchstr()|, but return the matched string, the start
7480 position and the end position of the match. Example: >
7481 :echo matchstrpos("testing", "ing")
7482< results in ["ing", 4, 7].
7483 When there is no match ["", -1, -1] is returned.
7484 The {start}, if given, has the same meaning as for |match()|. >
7485 :echo matchstrpos("testing", "ing", 2)
7486< results in ["ing", 4, 7]. >
7487 :echo matchstrpos("testing", "ing", 5)
7488< result is ["", -1, -1].
7489 When {expr} is a |List| then the matching item, the index
7490 of first item where {pat} matches, the start position and the
7491 end position of the match are returned. >
7492 :echo matchstrpos([1, '__x'], '\a')
7493< result is ["x", 1, 2, 3].
7494 The type isn't changed, it's not necessarily a String.
7495
7496 Can also be used as a |method|: >
7497 GetText()->matchstrpos('word')
7498<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007499 Return type: list<any>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007500
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007501
7502max({expr}) *max()*
7503 Return the maximum value of all items in {expr}. Example: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007504 echo max([apples, pears, oranges])
7505
Yegappan Lakshmanan9cb865e2025-03-23 16:42:16 +01007506< {expr} can be a |List|, a |Tuple| or a |Dictionary|. For a
7507 Dictionary, it returns the maximum of all values in the
7508 Dictionary. If {expr} is neither a List nor a Tuple nor a
7509 Dictionary, or one of the items in {expr} cannot be used as a
7510 Number this results in an error. An empty |List|, |Tuple|
7511 or |Dictionary| results in zero.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007512
7513 Can also be used as a |method|: >
7514 mylist->max()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007515<
7516 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007517
7518
7519menu_info({name} [, {mode}]) *menu_info()*
7520 Return information about the specified menu {name} in
7521 mode {mode}. The menu name should be specified without the
7522 shortcut character ('&'). If {name} is "", then the top-level
7523 menu names are returned.
7524
7525 {mode} can be one of these strings:
7526 "n" Normal
7527 "v" Visual (including Select)
7528 "o" Operator-pending
7529 "i" Insert
7530 "c" Cmd-line
7531 "s" Select
7532 "x" Visual
7533 "t" Terminal-Job
7534 "" Normal, Visual and Operator-pending
7535 "!" Insert and Cmd-line
7536 When {mode} is omitted, the modes for "" are used.
7537
7538 Returns a |Dictionary| containing the following items:
7539 accel menu item accelerator text |menu-text|
7540 display display name (name without '&')
7541 enabled v:true if this menu item is enabled
7542 Refer to |:menu-enable|
7543 icon name of the icon file (for toolbar)
7544 |toolbar-icon|
7545 iconidx index of a built-in icon
7546 modes modes for which the menu is defined. In
7547 addition to the modes mentioned above, these
7548 characters will be used:
7549 " " Normal, Visual and Operator-pending
7550 name menu item name.
7551 noremenu v:true if the {rhs} of the menu item is not
7552 remappable else v:false.
7553 priority menu order priority |menu-priority|
7554 rhs right-hand-side of the menu item. The returned
7555 string has special characters translated like
7556 in the output of the ":menu" command listing.
7557 When the {rhs} of a menu item is empty, then
7558 "<Nop>" is returned.
7559 script v:true if script-local remapping of {rhs} is
7560 allowed else v:false. See |:menu-script|.
7561 shortcut shortcut key (character after '&' in
7562 the menu name) |menu-shortcut|
7563 silent v:true if the menu item is created
7564 with <silent> argument |:menu-silent|
7565 submenus |List| containing the names of
7566 all the submenus. Present only if the menu
7567 item has submenus.
7568
7569 Returns an empty dictionary if the menu item is not found.
7570
7571 Examples: >
7572 :echo menu_info('Edit.Cut')
7573 :echo menu_info('File.Save', 'n')
7574
7575 " Display the entire menu hierarchy in a buffer
7576 func ShowMenu(name, pfx)
7577 let m = menu_info(a:name)
7578 call append(line('$'), a:pfx .. m.display)
7579 for child in m->get('submenus', [])
7580 call ShowMenu(a:name .. '.' .. escape(child, '.'),
7581 \ a:pfx .. ' ')
7582 endfor
7583 endfunc
7584 new
7585 for topmenu in menu_info('').submenus
7586 call ShowMenu(topmenu, '')
7587 endfor
7588<
7589 Can also be used as a |method|: >
7590 GetMenuName()->menu_info('v')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007591<
7592 Return type: dict<any>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007593
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007594min({expr}) *min()*
7595 Return the minimum value of all items in {expr}. Example: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007596 echo min([apples, pears, oranges])
7597
Yegappan Lakshmanan9cb865e2025-03-23 16:42:16 +01007598< {expr} can be a |List|, a |Tuple| or a |Dictionary|. For a
7599 Dictionary, it returns the minimum of all values in the
7600 Dictionary. If {expr} is neither a List nor a Tuple nor a
7601 Dictionary, or one of the items in {expr} cannot be used as a
7602 Number this results in an error. An empty |List|, |Tuple| or
7603 |Dictionary| results in zero.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007604
7605 Can also be used as a |method|: >
7606 mylist->min()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007607<
7608 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007609
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007610
7611mkdir({name} [, {flags} [, {prot}]]) *mkdir()* *E739*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007612 Create directory {name}.
7613
Bram Moolenaar938ae282023-02-20 20:44:55 +00007614 When {flags} is present it must be a string. An empty string
7615 has no effect.
Bram Moolenaar6f14da12022-09-07 21:30:44 +01007616
Christian Brabandtd6d4e132024-06-13 21:21:41 +02007617 {flags} can contain these character flags:
7618 "p" intermediate directories will be created as necessary
7619 "D" {name} will be deleted at the end of the current
Christian Brabandtc509c002024-06-14 20:22:05 +02007620 function, but not recursively |:defer|
Christian Brabandtd6d4e132024-06-13 21:21:41 +02007621 "R" {name} will be deleted recursively at the end of the
Christian Brabandtc509c002024-06-14 20:22:05 +02007622 current function |:defer|
Bram Moolenaar938ae282023-02-20 20:44:55 +00007623
Christian Brabandtd6d4e132024-06-13 21:21:41 +02007624 Note that when {name} has more than one part and "p" is used
Bram Moolenaar6f14da12022-09-07 21:30:44 +01007625 some directories may already exist. Only the first one that
7626 is created and what it contains is scheduled to be deleted.
7627 E.g. when using: >
7628 call mkdir('subdir/tmp/autoload', 'pR')
7629< and "subdir" already exists then "subdir/tmp" will be
7630 scheduled for deletion, like with: >
7631 defer delete('subdir/tmp', 'rf')
7632< Note that if scheduling the defer fails the directory is not
7633 deleted. This should only happen when out of memory.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007634
7635 If {prot} is given it is used to set the protection bits of
7636 the new directory. The default is 0o755 (rwxr-xr-x: r/w for
7637 the user, readable for others). Use 0o700 to make it
Christian Brabandt0a336cc2025-03-11 21:14:31 +01007638 unreadable for others. This is used for the newly created
zeertzjqc1c3b5d2025-03-12 21:16:13 +01007639 directories. Note: umask is applied to {prot} (on Unix).
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007640 Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00007641 :call mkdir($HOME .. "/tmp/foo/bar", "p", 0o700)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007642
7643< This function is not available in the |sandbox|.
7644
7645 There is no error if the directory already exists and the "p"
7646 flag is passed (since patch 8.0.1708). However, without the
7647 "p" option the call will fail.
7648
7649 The function result is a Number, which is TRUE if the call was
7650 successful or FALSE if the directory creation failed or partly
7651 failed.
7652
7653 Not available on all systems. To check use: >
7654 :if exists("*mkdir")
7655
7656< Can also be used as a |method|: >
7657 GetName()->mkdir()
7658<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007659 Return type: |Number|
7660
7661
7662mode([{expr}]) *mode()*
7663 Return a string that indicates the current mode.
Doug Kearns9cd9e752024-04-07 17:42:17 +02007664 If {expr} is supplied and it evaluates to a non-zero Number or
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007665 a non-empty String (|non-zero-arg|), then the full mode is
7666 returned, otherwise only the first letter is returned.
7667 Also see |state()|.
7668
7669 n Normal
7670 no Operator-pending
7671 nov Operator-pending (forced characterwise |o_v|)
7672 noV Operator-pending (forced linewise |o_V|)
7673 noCTRL-V Operator-pending (forced blockwise |o_CTRL-V|);
7674 CTRL-V is one character
7675 niI Normal using |i_CTRL-O| in |Insert-mode|
7676 niR Normal using |i_CTRL-O| in |Replace-mode|
7677 niV Normal using |i_CTRL-O| in |Virtual-Replace-mode|
7678 nt Terminal-Normal (insert goes to Terminal-Job mode)
7679 v Visual by character
7680 vs Visual by character using |v_CTRL-O| in Select mode
7681 V Visual by line
7682 Vs Visual by line using |v_CTRL-O| in Select mode
7683 CTRL-V Visual blockwise
7684 CTRL-Vs Visual blockwise using |v_CTRL-O| in Select mode
7685 s Select by character
7686 S Select by line
7687 CTRL-S Select blockwise
7688 i Insert
7689 ic Insert mode completion |compl-generic|
7690 ix Insert mode |i_CTRL-X| completion
7691 R Replace |R|
7692 Rc Replace mode completion |compl-generic|
7693 Rx Replace mode |i_CTRL-X| completion
7694 Rv Virtual Replace |gR|
7695 Rvc Virtual Replace mode completion |compl-generic|
7696 Rvx Virtual Replace mode |i_CTRL-X| completion
7697 c Command-line editing
h-east71ebf3b2023-09-03 17:12:55 +02007698 ct Command-line editing via Terminal-Job mode
zeertzjqfcaeb3d2023-11-28 20:46:29 +01007699 cr Command-line editing overstrike mode |c_<Insert>|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007700 cv Vim Ex mode |gQ|
zeertzjqfcaeb3d2023-11-28 20:46:29 +01007701 cvr Vim Ex mode while in overstrike mode |c_<Insert>|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007702 ce Normal Ex mode |Q|
7703 r Hit-enter prompt
7704 rm The -- more -- prompt
7705 r? A |:confirm| query of some sort
7706 ! Shell or external command is executing
7707 t Terminal-Job mode: keys go to the job
7708
7709 This is useful in the 'statusline' option or when used
7710 with |remote_expr()| In most other places it always returns
7711 "c" or "n".
7712 Note that in the future more modes and more specific modes may
7713 be added. It's better not to compare the whole string but only
7714 the leading character(s).
7715 Also see |visualmode()|.
7716
7717 Can also be used as a |method|: >
7718 DoFull()->mode()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007719<
7720 Return type: |String|
7721
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007722
7723mzeval({expr}) *mzeval()*
7724 Evaluate MzScheme expression {expr} and return its result
7725 converted to Vim data structures.
7726 Numbers and strings are returned as they are.
7727 Pairs (including lists and improper lists) and vectors are
7728 returned as Vim |Lists|.
7729 Hash tables are represented as Vim |Dictionary| type with keys
7730 converted to strings.
7731 All other types are converted to string with display function.
7732 Examples: >
7733 :mz (define l (list 1 2 3))
7734 :mz (define h (make-hash)) (hash-set! h "list" l)
7735 :echo mzeval("l")
7736 :echo mzeval("h")
7737<
7738 Note that in a `:def` function local variables are not visible
7739 to {expr}.
7740
7741 Can also be used as a |method|: >
7742 GetExpr()->mzeval()
7743<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007744 Return type: any, depending on {expr}
7745
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007746 {only available when compiled with the |+mzscheme| feature}
7747
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007748
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007749nextnonblank({lnum}) *nextnonblank()*
7750 Return the line number of the first line at or below {lnum}
7751 that is not blank. Example: >
7752 if getline(nextnonblank(1)) =~ "Java"
7753< When {lnum} is invalid or there is no non-blank line at or
7754 below it, zero is returned.
7755 {lnum} is used like with |getline()|.
7756 See also |prevnonblank()|.
7757
7758 Can also be used as a |method|: >
7759 GetLnum()->nextnonblank()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007760<
7761 Return type: |Number|
7762
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007763
Christ van Willegenc0786752025-02-01 15:42:16 +01007764ngettext({single}, {plural}, {number}[, {domain}) *ngettext()*
7765 Return a string that contains the correct value for a
7766 message based on the rules for plural form(s) in
7767 a language. Examples: >
7768 ngettext("File", "Files", 2) # returns "Files"
7769<
7770 Can be used as a |method|: >
7771 1->ngettext("File", "Files") # returns "File"
7772<
7773 See |gettext()| for information on the domain parameter.
7774
7775 Return type: |String|
7776
7777
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007778nr2char({expr} [, {utf8}]) *nr2char()*
7779 Return a string with a single character, which has the number
7780 value {expr}. Examples: >
7781 nr2char(64) returns "@"
7782 nr2char(32) returns " "
7783< When {utf8} is omitted or zero, the current 'encoding' is used.
7784 Example for "utf-8": >
7785 nr2char(300) returns I with bow character
7786< When {utf8} is TRUE, always return UTF-8 characters.
7787 Note that a NUL character in the file is specified with
7788 nr2char(10), because NULs are represented with newline
7789 characters. nr2char(0) is a real NUL and terminates the
7790 string, thus results in an empty string.
7791 To turn a list of character numbers into a string: >
7792 let list = [65, 66, 67]
7793 let str = join(map(list, {_, val -> nr2char(val)}), '')
7794< Result: "ABC"
7795
7796 Can also be used as a |method|: >
7797 GetNumber()->nr2char()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007798<
7799 Return type: |String|
7800
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007801
7802or({expr}, {expr}) *or()*
7803 Bitwise OR on the two arguments. The arguments are converted
7804 to a number. A List, Dict or Float argument causes an error.
Bram Moolenaar5a6ec102022-05-27 21:58:00 +01007805 Also see `and()` and `xor()`.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007806 Example: >
7807 :let bits = or(bits, 0x80)
7808< Can also be used as a |method|: >
7809 :let bits = bits->or(0x80)
7810
Bram Moolenaar5a6ec102022-05-27 21:58:00 +01007811< Rationale: The reason this is a function and not using the "|"
7812 character like many languages, is that Vi has always used "|"
7813 to separate commands. In many places it would not be clear if
7814 "|" is an operator or a command separator.
7815
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007816 Return type: |Number|
7817
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007818
7819pathshorten({path} [, {len}]) *pathshorten()*
7820 Shorten directory names in the path {path} and return the
7821 result. The tail, the file name, is kept as-is. The other
7822 components in the path are reduced to {len} letters in length.
7823 If {len} is omitted or smaller than 1 then 1 is used (single
7824 letters). Leading '~' and '.' characters are kept. Examples: >
7825 :echo pathshorten('~/.vim/autoload/myfile.vim')
7826< ~/.v/a/myfile.vim ~
7827>
7828 :echo pathshorten('~/.vim/autoload/myfile.vim', 2)
7829< ~/.vi/au/myfile.vim ~
7830 It doesn't matter if the path exists or not.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01007831 Returns an empty string on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007832
7833 Can also be used as a |method|: >
7834 GetDirectories()->pathshorten()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007835<
7836 Return type: |String|
7837
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007838
7839perleval({expr}) *perleval()*
7840 Evaluate Perl expression {expr} in scalar context and return
7841 its result converted to Vim data structures. If value can't be
7842 converted, it is returned as a string Perl representation.
7843 Note: If you want an array or hash, {expr} must return a
7844 reference to it.
7845 Example: >
7846 :echo perleval('[1 .. 4]')
7847< [1, 2, 3, 4]
7848
7849 Note that in a `:def` function local variables are not visible
7850 to {expr}.
7851
7852 Can also be used as a |method|: >
7853 GetExpr()->perleval()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007854<
7855 Return type: any, depending on {expr}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007856
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007857 {only available when compiled with the |+perl| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007858
7859
7860popup_ functions are documented here: |popup-functions|
7861
7862
7863pow({x}, {y}) *pow()*
7864 Return the power of {x} to the exponent {y} as a |Float|.
7865 {x} and {y} must evaluate to a |Float| or a |Number|.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01007866 Returns 0.0 if {x} or {y} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007867 Examples: >
7868 :echo pow(3, 3)
7869< 27.0 >
7870 :echo pow(2, 16)
7871< 65536.0 >
7872 :echo pow(32, 0.20)
7873< 2.0
7874
7875 Can also be used as a |method|: >
7876 Compute()->pow(3)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007877<
7878 Return type: |Number|
7879
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007880
7881prevnonblank({lnum}) *prevnonblank()*
7882 Return the line number of the first line at or above {lnum}
7883 that is not blank. Example: >
7884 let ind = indent(prevnonblank(v:lnum - 1))
7885< When {lnum} is invalid or there is no non-blank line at or
7886 above it, zero is returned.
7887 {lnum} is used like with |getline()|.
7888 Also see |nextnonblank()|.
7889
7890 Can also be used as a |method|: >
7891 GetLnum()->prevnonblank()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007892<
7893 Return type: |Number|
7894
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007895
7896printf({fmt}, {expr1} ...) *printf()*
7897 Return a String with {fmt}, where "%" items are replaced by
7898 the formatted form of their respective arguments. Example: >
7899 printf("%4d: E%d %.30s", lnum, errno, msg)
7900< May result in:
7901 " 99: E42 asdfasdfasdfasdfasdfasdfasdfas" ~
7902
7903 When used as a |method| the base is passed as the second
7904 argument: >
7905 Compute()->printf("result: %d")
Bram Moolenaarcbaff5e2022-04-08 17:45:08 +01007906<
7907 You can use `call()` to pass the items as a list.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007908
Bram Moolenaarcbaff5e2022-04-08 17:45:08 +01007909 Often used items are:
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007910 %s string
7911 %6S string right-aligned in 6 display cells
7912 %6s string right-aligned in 6 bytes
7913 %.9s string truncated to 9 bytes
7914 %c single byte
7915 %d decimal number
7916 %5d decimal number padded with spaces to 5 characters
7917 %x hex number
7918 %04x hex number padded with zeros to at least 4 characters
7919 %X hex number using upper case letters
7920 %o octal number
7921 %08b binary number padded with zeros to at least 8 chars
7922 %f floating point number as 12.23, inf, -inf or nan
7923 %F floating point number as 12.23, INF, -INF or NAN
7924 %e floating point number as 1.23e3, inf, -inf or nan
7925 %E floating point number as 1.23E3, INF, -INF or NAN
7926 %g floating point number, as %f or %e depending on value
7927 %G floating point number, as %F or %E depending on value
7928 %% the % character itself
7929
7930 Conversion specifications start with '%' and end with the
7931 conversion type. All other characters are copied unchanged to
7932 the result.
7933
7934 The "%" starts a conversion specification. The following
7935 arguments appear in sequence:
7936
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007937 % [pos-argument] [flags] [field-width] [.precision] type
7938
7939 pos-argument
7940 At most one positional argument specifier. These
7941 take the form {n$}, where n is >= 1.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007942
7943 flags
7944 Zero or more of the following flags:
7945
7946 # The value should be converted to an "alternate
7947 form". For c, d, and s conversions, this option
7948 has no effect. For o conversions, the precision
7949 of the number is increased to force the first
7950 character of the output string to a zero (except
7951 if a zero value is printed with an explicit
7952 precision of zero).
7953 For b and B conversions, a non-zero result has
7954 the string "0b" (or "0B" for B conversions)
7955 prepended to it.
7956 For x and X conversions, a non-zero result has
7957 the string "0x" (or "0X" for X conversions)
7958 prepended to it.
7959
7960 0 (zero) Zero padding. For all conversions the converted
7961 value is padded on the left with zeros rather
7962 than blanks. If a precision is given with a
7963 numeric conversion (d, b, B, o, x, and X), the 0
7964 flag is ignored.
7965
7966 - A negative field width flag; the converted value
7967 is to be left adjusted on the field boundary.
7968 The converted value is padded on the right with
7969 blanks, rather than on the left with blanks or
7970 zeros. A - overrides a 0 if both are given.
7971
7972 ' ' (space) A blank should be left before a positive
7973 number produced by a signed conversion (d).
7974
7975 + A sign must always be placed before a number
7976 produced by a signed conversion. A + overrides
7977 a space if both are used.
7978
7979 field-width
7980 An optional decimal digit string specifying a minimum
7981 field width. If the converted value has fewer bytes
7982 than the field width, it will be padded with spaces on
7983 the left (or right, if the left-adjustment flag has
7984 been given) to fill out the field width. For the S
7985 conversion the count is in cells.
7986
7987 .precision
7988 An optional precision, in the form of a period '.'
7989 followed by an optional digit string. If the digit
7990 string is omitted, the precision is taken as zero.
7991 This gives the minimum number of digits to appear for
7992 d, o, x, and X conversions, the maximum number of
7993 bytes to be printed from a string for s conversions,
7994 or the maximum number of cells to be printed from a
7995 string for S conversions.
7996 For floating point it is the number of digits after
7997 the decimal point.
7998
7999 type
8000 A character that specifies the type of conversion to
8001 be applied, see below.
8002
8003 A field width or precision, or both, may be indicated by an
8004 asterisk '*' instead of a digit string. In this case, a
8005 Number argument supplies the field width or precision. A
8006 negative field width is treated as a left adjustment flag
8007 followed by a positive field width; a negative precision is
8008 treated as though it were missing. Example: >
8009 :echo printf("%d: %.*s", nr, width, line)
8010< This limits the length of the text used from "line" to
8011 "width" bytes.
8012
Dominique Pellé17dca3c2023-12-14 20:36:32 +01008013 If the argument to be formatted is specified using a
8014 positional argument specifier, and a '*' is used to indicate
8015 that a number argument is to be used to specify the width or
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008016 precision, the argument(s) to be used must also be specified
8017 using a {n$} positional argument specifier. See |printf-$|.
8018
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008019 The conversion specifiers and their meanings are:
8020
8021 *printf-d* *printf-b* *printf-B* *printf-o*
8022 *printf-x* *printf-X*
8023 dbBoxX The Number argument is converted to signed decimal
8024 (d), unsigned binary (b and B), unsigned octal (o), or
8025 unsigned hexadecimal (x and X) notation. The letters
8026 "abcdef" are used for x conversions; the letters
8027 "ABCDEF" are used for X conversions.
8028 The precision, if any, gives the minimum number of
8029 digits that must appear; if the converted value
8030 requires fewer digits, it is padded on the left with
8031 zeros.
8032 In no case does a non-existent or small field width
8033 cause truncation of a numeric field; if the result of
8034 a conversion is wider than the field width, the field
8035 is expanded to contain the conversion result.
8036 The 'h' modifier indicates the argument is 16 bits.
Christ van Willegenaa90d4f2023-09-03 17:22:37 +02008037 The 'l' modifier indicates the argument is a long
8038 integer. The size will be 32 bits or 64 bits
8039 depending on your platform.
8040 The "ll" modifier indicates the argument is 64 bits.
8041 The b and B conversion specifiers never take a width
8042 modifier and always assume their argument is a 64 bit
8043 integer.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008044 Generally, these modifiers are not useful. They are
8045 ignored when type is known from the argument.
8046
8047 i alias for d
8048 D alias for ld
8049 U alias for lu
8050 O alias for lo
8051
8052 *printf-c*
8053 c The Number argument is converted to a byte, and the
8054 resulting character is written.
8055
8056 *printf-s*
8057 s The text of the String argument is used. If a
8058 precision is specified, no more bytes than the number
8059 specified are used.
8060 If the argument is not a String type, it is
8061 automatically converted to text with the same format
8062 as ":echo".
8063 *printf-S*
8064 S The text of the String argument is used. If a
8065 precision is specified, no more display cells than the
8066 number specified are used.
8067
8068 *printf-f* *E807*
8069 f F The Float argument is converted into a string of the
8070 form 123.456. The precision specifies the number of
8071 digits after the decimal point. When the precision is
8072 zero the decimal point is omitted. When the precision
8073 is not specified 6 is used. A really big number
8074 (out of range or dividing by zero) results in "inf"
8075 or "-inf" with %f (INF or -INF with %F).
8076 "0.0 / 0.0" results in "nan" with %f (NAN with %F).
8077 Example: >
8078 echo printf("%.2f", 12.115)
8079< 12.12
8080 Note that roundoff depends on the system libraries.
8081 Use |round()| when in doubt.
8082
8083 *printf-e* *printf-E*
8084 e E The Float argument is converted into a string of the
8085 form 1.234e+03 or 1.234E+03 when using 'E'. The
8086 precision specifies the number of digits after the
8087 decimal point, like with 'f'.
8088
8089 *printf-g* *printf-G*
8090 g G The Float argument is converted like with 'f' if the
8091 value is between 0.001 (inclusive) and 10000000.0
8092 (exclusive). Otherwise 'e' is used for 'g' and 'E'
8093 for 'G'. When no precision is specified superfluous
8094 zeroes and '+' signs are removed, except for the zero
8095 immediately after the decimal point. Thus 10000000.0
8096 results in 1.0e7.
8097
8098 *printf-%*
8099 % A '%' is written. No argument is converted. The
8100 complete conversion specification is "%%".
8101
8102 When a Number argument is expected a String argument is also
8103 accepted and automatically converted.
8104 When a Float or String argument is expected a Number argument
8105 is also accepted and automatically converted.
8106 Any other argument type results in an error message.
8107
8108 *E766* *E767*
8109 The number of {exprN} arguments must exactly match the number
8110 of "%" items. If there are not sufficient or too many
8111 arguments an error is given. Up to 18 arguments can be used.
8112
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008113 *printf-$*
8114 In certain languages, error and informative messages are
8115 more readable when the order of words is different from the
Christian Brabandtee17b6f2023-09-09 11:23:50 +02008116 corresponding message in English. To accommodate translations
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008117 having a different word order, positional arguments may be
8118 used to indicate this. For instance: >
8119
h_east596a9f22023-11-21 21:24:23 +09008120 #, c-format
8121 msgid "%s returning %s"
8122 msgstr "waarde %2$s komt terug van %1$s"
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008123<
h_east596a9f22023-11-21 21:24:23 +09008124 In this example, the sentence has its 2 string arguments
8125 reversed in the output. >
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008126
h_east596a9f22023-11-21 21:24:23 +09008127 echo printf(
8128 "In The Netherlands, vim's creator's name is: %1$s %2$s",
8129 "Bram", "Moolenaar")
8130< In The Netherlands, vim's creator's name is: Bram Moolenaar >
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008131
h_east596a9f22023-11-21 21:24:23 +09008132 echo printf(
8133 "In Belgium, vim's creator's name is: %2$s %1$s",
8134 "Bram", "Moolenaar")
8135< In Belgium, vim's creator's name is: Moolenaar Bram
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008136
8137 Width (and precision) can be specified using the '*' specifier.
8138 In this case, you must specify the field width position in the
8139 argument list. >
8140
h_east596a9f22023-11-21 21:24:23 +09008141 echo printf("%1$*2$.*3$d", 1, 2, 3)
8142< 001 >
8143 echo printf("%2$*3$.*1$d", 1, 2, 3)
8144< 2 >
8145 echo printf("%3$*1$.*2$d", 1, 2, 3)
8146< 03 >
8147 echo printf("%1$*2$.*3$g", 1.4142, 2, 3)
8148< 1.414
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008149
8150 You can mix specifying the width and/or precision directly
8151 and via positional arguments: >
8152
h_east596a9f22023-11-21 21:24:23 +09008153 echo printf("%1$4.*2$f", 1.4142135, 6)
8154< 1.414214 >
8155 echo printf("%1$*2$.4f", 1.4142135, 6)
8156< 1.4142 >
8157 echo printf("%1$*2$.*3$f", 1.4142135, 6, 2)
8158< 1.41
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008159
Christ van Willegenc35fc032024-03-14 18:30:41 +01008160 You will get an overflow error |E1510|, when the field-width
Hirohito Higashi0ed11ba2025-04-18 18:45:31 +02008161 or precision will result in a string longer than 1 MiB
zeertzjqe9a27ef2025-04-18 10:45:45 +02008162 (1024*1024 = 1048576) chars.
Christ van Willegenc35fc032024-03-14 18:30:41 +01008163
Yegappan Lakshmanan413f8392023-09-28 22:46:37 +02008164 *E1500*
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008165 You cannot mix positional and non-positional arguments: >
h_east596a9f22023-11-21 21:24:23 +09008166 echo printf("%s%1$s", "One", "Two")
8167< E1500: Cannot mix positional and non-positional arguments:
8168 %s%1$s
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008169
Yegappan Lakshmanan413f8392023-09-28 22:46:37 +02008170 *E1501*
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008171 You cannot skip a positional argument in a format string: >
h_east596a9f22023-11-21 21:24:23 +09008172 echo printf("%3$s%1$s", "One", "Two", "Three")
8173< E1501: format argument 2 unused in $-style format:
8174 %3$s%1$s
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008175
Yegappan Lakshmanan413f8392023-09-28 22:46:37 +02008176 *E1502*
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008177 You can re-use a [field-width] (or [precision]) argument: >
h_east596a9f22023-11-21 21:24:23 +09008178 echo printf("%1$d at width %2$d is: %01$*2$d", 1, 2)
8179< 1 at width 2 is: 01
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008180
8181 However, you can't use it as a different type: >
h_east596a9f22023-11-21 21:24:23 +09008182 echo printf("%1$d at width %2$ld is: %01$*2$d", 1, 2)
8183< E1502: Positional argument 2 used as field width reused as
8184 different type: long int/int
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008185
Yegappan Lakshmanan413f8392023-09-28 22:46:37 +02008186 *E1503*
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008187 When a positional argument is used, but not the correct number
8188 or arguments is given, an error is raised: >
h_east596a9f22023-11-21 21:24:23 +09008189 echo printf("%1$d at width %2$d is: %01$*2$.*3$d", 1, 2)
8190< E1503: Positional argument 3 out of bounds: %1$d at width
8191 %2$d is: %01$*2$.*3$d
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008192
8193 Only the first error is reported: >
h_east596a9f22023-11-21 21:24:23 +09008194 echo printf("%01$*2$.*3$d %4$d", 1, 2)
8195< E1503: Positional argument 3 out of bounds: %01$*2$.*3$d
8196 %4$d
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008197
Yegappan Lakshmanan413f8392023-09-28 22:46:37 +02008198 *E1504*
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008199 A positional argument can be used more than once: >
h_east596a9f22023-11-21 21:24:23 +09008200 echo printf("%1$s %2$s %1$s", "One", "Two")
8201< One Two One
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008202
8203 However, you can't use a different type the second time: >
h_east596a9f22023-11-21 21:24:23 +09008204 echo printf("%1$s %2$s %1$d", "One", "Two")
8205< E1504: Positional argument 1 type used inconsistently:
8206 int/string
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008207
Yegappan Lakshmanan413f8392023-09-28 22:46:37 +02008208 *E1505*
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008209 Various other errors that lead to a format string being
8210 wrongly formatted lead to: >
h_east596a9f22023-11-21 21:24:23 +09008211 echo printf("%1$d at width %2$d is: %01$*2$.3$d", 1, 2)
8212< E1505: Invalid format specifier: %1$d at width %2$d is:
8213 %01$*2$.3$d
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008214
Christ van Willegenea746f92023-10-05 20:48:36 +02008215 *E1507*
zeertzjq27e12c72023-10-07 01:34:04 +08008216 This internal error indicates that the logic to parse a
8217 positional format argument ran into a problem that couldn't be
8218 otherwise reported. Please file a bug against Vim if you run
8219 into this, copying the exact format string and parameters that
8220 were used.
Christ van Willegenea746f92023-10-05 20:48:36 +02008221
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008222 Return type: |String|
8223
Christ van Willegenea746f92023-10-05 20:48:36 +02008224
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008225prompt_getprompt({buf}) *prompt_getprompt()*
8226 Returns the effective prompt text for buffer {buf}. {buf} can
8227 be a buffer name or number. See |prompt-buffer|.
8228
8229 If the buffer doesn't exist or isn't a prompt buffer, an empty
8230 string is returned.
8231
8232 Can also be used as a |method|: >
8233 GetBuffer()->prompt_getprompt()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008234<
8235 Return type: |String|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008236
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008237 {only available when compiled with the |+channel| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008238
8239
8240prompt_setcallback({buf}, {expr}) *prompt_setcallback()*
8241 Set prompt callback for buffer {buf} to {expr}. When {expr}
8242 is an empty string the callback is removed. This has only
8243 effect if {buf} has 'buftype' set to "prompt".
8244
8245 The callback is invoked when pressing Enter. The current
8246 buffer will always be the prompt buffer. A new line for a
8247 prompt is added before invoking the callback, thus the prompt
8248 for which the callback was invoked will be in the last but one
8249 line.
8250 If the callback wants to add text to the buffer, it must
8251 insert it above the last line, since that is where the current
8252 prompt is. This can also be done asynchronously.
8253 The callback is invoked with one argument, which is the text
8254 that was entered at the prompt. This can be an empty string
8255 if the user only typed Enter.
8256 Example: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008257 func s:TextEntered(text)
8258 if a:text == 'exit' || a:text == 'quit'
8259 stopinsert
Bram Moolenaarb7398fe2023-05-14 18:50:25 +01008260 " Reset 'modified' to allow the buffer to be closed.
8261 " We assume there is nothing useful to be saved.
8262 set nomodified
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008263 close
8264 else
Bram Moolenaarb7398fe2023-05-14 18:50:25 +01008265 " Do something useful with "a:text". In this example
8266 " we just repeat it.
Bram Moolenaarc51cf032022-02-26 12:25:45 +00008267 call append(line('$') - 1, 'Entered: "' .. a:text .. '"')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008268 endif
8269 endfunc
Bram Moolenaarb7398fe2023-05-14 18:50:25 +01008270 call prompt_setcallback(bufnr(), function('s:TextEntered'))
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008271
8272< Can also be used as a |method|: >
8273 GetBuffer()->prompt_setcallback(callback)
8274
8275< {only available when compiled with the |+channel| feature}
8276
8277prompt_setinterrupt({buf}, {expr}) *prompt_setinterrupt()*
8278 Set a callback for buffer {buf} to {expr}. When {expr} is an
8279 empty string the callback is removed. This has only effect if
8280 {buf} has 'buftype' set to "prompt".
8281
8282 This callback will be invoked when pressing CTRL-C in Insert
8283 mode. Without setting a callback Vim will exit Insert mode,
8284 as in any buffer.
8285
8286 Can also be used as a |method|: >
8287 GetBuffer()->prompt_setinterrupt(callback)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008288<
8289 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008290
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008291 {only available when compiled with the |+channel| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008292
8293prompt_setprompt({buf}, {text}) *prompt_setprompt()*
8294 Set prompt for buffer {buf} to {text}. You most likely want
8295 {text} to end in a space.
8296 The result is only visible if {buf} has 'buftype' set to
8297 "prompt". Example: >
8298 call prompt_setprompt(bufnr(), 'command: ')
8299<
8300 Can also be used as a |method|: >
8301 GetBuffer()->prompt_setprompt('command: ')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008302<
8303 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008304
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008305 {only available when compiled with the |+channel| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008306
8307prop_ functions are documented here: |text-prop-functions|
8308
8309pum_getpos() *pum_getpos()*
8310 If the popup menu (see |ins-completion-menu|) is not visible,
8311 returns an empty |Dictionary|, otherwise, returns a
8312 |Dictionary| with the following keys:
8313 height nr of items visible
8314 width screen cells
8315 row top screen row (0 first row)
8316 col leftmost screen column (0 first col)
8317 size total nr of items
8318 scrollbar |TRUE| if scrollbar is visible
8319
8320 The values are the same as in |v:event| during
8321 |CompleteChanged|.
8322
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008323 Return type: dict<any>
8324
8325
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008326pumvisible() *pumvisible()*
8327 Returns non-zero when the popup menu is visible, zero
8328 otherwise. See |ins-completion-menu|.
8329 This can be used to avoid some things that would remove the
8330 popup menu.
8331
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008332 Return type: |Number|
8333
8334
zeertzjq7c515282024-11-10 20:26:12 +01008335py3eval({expr} [, {locals}]) *py3eval()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008336 Evaluate Python expression {expr} and return its result
8337 converted to Vim data structures.
Ben Jacksonea19e782024-11-06 21:50:05 +01008338 If a {locals} |Dictionary| is given, it defines set of local
8339 variables available in the expression. The keys are variable
Yegappan Lakshmanan038be272025-03-26 18:46:21 +01008340 names and the values are the variable values. |Dictionary|,
8341 |List| and |Tuple| values are referenced, and may be updated
8342 by the expression (as if |python-bindeval| was used).
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008343 Numbers and strings are returned as they are (strings are
8344 copied though, Unicode strings are additionally converted to
8345 'encoding').
8346 Lists are represented as Vim |List| type.
Yegappan Lakshmanan038be272025-03-26 18:46:21 +01008347 Tuples are represented as Vim |Tuple| type.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008348 Dictionaries are represented as Vim |Dictionary| type with
8349 keys converted to strings.
8350 Note that in a `:def` function local variables are not visible
8351 to {expr}.
8352
8353 Can also be used as a |method|: >
8354 GetExpr()->py3eval()
Ben Jacksonea19e782024-11-06 21:50:05 +01008355 'b",".join(l)'->py3eval({'l': ['a', 'b', 'c']})
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008356<
8357 Return type: any, depending on {expr}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008358
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008359 {only available when compiled with the |+python3| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008360
8361 *E858* *E859*
zeertzjq7c515282024-11-10 20:26:12 +01008362pyeval({expr} [, {locals}]) *pyeval()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008363 Evaluate Python expression {expr} and return its result
8364 converted to Vim data structures.
Ben Jacksonea19e782024-11-06 21:50:05 +01008365 For {locals} see |py3eval()|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008366 Numbers and strings are returned as they are (strings are
8367 copied though).
8368 Lists are represented as Vim |List| type.
Yegappan Lakshmanan038be272025-03-26 18:46:21 +01008369 Tuples are represented as Vim |Tuple| type.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008370 Dictionaries are represented as Vim |Dictionary| type,
8371 non-string keys result in error.
8372 Note that in a `:def` function local variables are not visible
8373 to {expr}.
8374
8375 Can also be used as a |method|: >
8376 GetExpr()->pyeval()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008377<
8378 Return type: any, depending on {expr}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008379
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008380 {only available when compiled with the |+python| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008381
zeertzjq7c515282024-11-10 20:26:12 +01008382pyxeval({expr} [, {locals}]) *pyxeval()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008383 Evaluate Python expression {expr} and return its result
8384 converted to Vim data structures.
Ben Jacksonea19e782024-11-06 21:50:05 +01008385 For {locals} see |py3eval()|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008386 Uses Python 2 or 3, see |python_x| and 'pyxversion'.
8387 See also: |pyeval()|, |py3eval()|
8388
8389 Can also be used as a |method|: >
h-east52e7cc22024-07-28 17:03:29 +02008390 GetExpr()->pyxeval()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008391<
8392 Return type: any, depending on {expr}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008393
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008394 {only available when compiled with the |+python| or the
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008395 |+python3| feature}
8396
8397rand([{expr}]) *rand()* *random*
8398 Return a pseudo-random Number generated with an xoshiro128**
8399 algorithm using seed {expr}. The returned number is 32 bits,
8400 also on 64 bits systems, for consistency.
8401 {expr} can be initialized by |srand()| and will be updated by
8402 rand(). If {expr} is omitted, an internal seed value is used
8403 and updated.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01008404 Returns -1 if {expr} is invalid.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008405
8406 Examples: >
8407 :echo rand()
8408 :let seed = srand()
8409 :echo rand(seed)
8410 :echo rand(seed) % 16 " random number 0 - 15
8411<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008412 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008413
8414 *E726* *E727*
8415range({expr} [, {max} [, {stride}]]) *range()*
8416 Returns a |List| with Numbers:
8417 - If only {expr} is specified: [0, 1, ..., {expr} - 1]
8418 - If {max} is specified: [{expr}, {expr} + 1, ..., {max}]
8419 - If {stride} is specified: [{expr}, {expr} + {stride}, ...,
8420 {max}] (increasing {expr} with {stride} each time, not
8421 producing a value past {max}).
8422 When the maximum is one before the start the result is an
8423 empty list. When the maximum is more than one before the
8424 start this is an error.
8425 Examples: >
8426 range(4) " [0, 1, 2, 3]
8427 range(2, 4) " [2, 3, 4]
8428 range(2, 9, 3) " [2, 5, 8]
8429 range(2, -2, -1) " [2, 1, 0, -1, -2]
8430 range(0) " []
8431 range(2, 0) " error!
8432<
8433 Can also be used as a |method|: >
8434 GetExpr()->range()
8435<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008436 Return type: list<number>
8437
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008438
K.Takata11df3ae2022-10-19 14:02:40 +01008439readblob({fname} [, {offset} [, {size}]]) *readblob()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008440 Read file {fname} in binary mode and return a |Blob|.
K.Takata11df3ae2022-10-19 14:02:40 +01008441 If {offset} is specified, read the file from the specified
8442 offset. If it is a negative value, it is used as an offset
8443 from the end of the file. E.g., to read the last 12 bytes: >
8444 readblob('file.bin', -12)
8445< If {size} is specified, only the specified size will be read.
8446 E.g. to read the first 100 bytes of a file: >
8447 readblob('file.bin', 0, 100)
8448< If {size} is -1 or omitted, the whole data starting from
8449 {offset} will be read.
K.Takata43625762022-10-20 13:28:51 +01008450 This can be also used to read the data from a character device
8451 on Unix when {size} is explicitly set. Only if the device
8452 supports seeking {offset} can be used. Otherwise it should be
8453 zero. E.g. to read 10 bytes from a serial console: >
8454 readblob('/dev/ttyS0', 0, 10)
8455< When the file can't be opened an error message is given and
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008456 the result is an empty |Blob|.
Bram Moolenaar5b2a3d72022-10-21 11:25:30 +01008457 When the offset is beyond the end of the file the result is an
8458 empty blob.
8459 When trying to read more bytes than are available the result
8460 is truncated.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008461 Also see |readfile()| and |writefile()|.
8462
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008463 Return type: |Blob|
8464
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008465
8466readdir({directory} [, {expr} [, {dict}]]) *readdir()*
8467 Return a list with file and directory names in {directory}.
8468 You can also use |glob()| if you don't need to do complicated
8469 things, such as limiting the number of matches.
8470 The list will be sorted (case sensitive), see the {dict}
8471 argument below for changing the sort order.
8472
8473 When {expr} is omitted all entries are included.
8474 When {expr} is given, it is evaluated to check what to do:
8475 If {expr} results in -1 then no further entries will
8476 be handled.
8477 If {expr} results in 0 then this entry will not be
8478 added to the list.
8479 If {expr} results in 1 then this entry will be added
8480 to the list.
8481 The entries "." and ".." are always excluded.
8482 Each time {expr} is evaluated |v:val| is set to the entry name.
8483 When {expr} is a function the name is passed as the argument.
8484 For example, to get a list of files ending in ".txt": >
8485 readdir(dirname, {n -> n =~ '.txt$'})
8486< To skip hidden and backup files: >
8487 readdir(dirname, {n -> n !~ '^\.\|\~$'})
Bram Moolenaar6f4754b2022-01-23 12:07:04 +00008488< *E857*
8489 The optional {dict} argument allows for further custom
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008490 values. Currently this is used to specify if and how sorting
8491 should be performed. The dict can have the following members:
8492
8493 sort How to sort the result returned from the system.
8494 Valid values are:
8495 "none" do not sort (fastest method)
8496 "case" sort case sensitive (byte value of
8497 each character, technically, using
8498 strcmp()) (default)
8499 "icase" sort case insensitive (technically
8500 using strcasecmp())
8501 "collate" sort using the collation order
8502 of the "POSIX" or "C" |locale|
8503 (technically using strcoll())
8504 Other values are silently ignored.
8505
8506 For example, to get a list of all files in the current
8507 directory without sorting the individual entries: >
8508 readdir('.', '1', #{sort: 'none'})
8509< If you want to get a directory tree: >
8510 function! s:tree(dir)
8511 return {a:dir : map(readdir(a:dir),
8512 \ {_, x -> isdirectory(x) ?
Bram Moolenaarc51cf032022-02-26 12:25:45 +00008513 \ {x : s:tree(a:dir .. '/' .. x)} : x})}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008514 endfunction
8515 echo s:tree(".")
8516<
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01008517 Returns an empty List on error.
8518
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008519 Can also be used as a |method|: >
8520 GetDirName()->readdir()
8521<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008522 Return type: list<string> or list<any>
8523
8524
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008525readdirex({directory} [, {expr} [, {dict}]]) *readdirex()*
8526 Extended version of |readdir()|.
8527 Return a list of Dictionaries with file and directory
8528 information in {directory}.
8529 This is useful if you want to get the attributes of file and
8530 directory at the same time as getting a list of a directory.
8531 This is much faster than calling |readdir()| then calling
8532 |getfperm()|, |getfsize()|, |getftime()| and |getftype()| for
8533 each file and directory especially on MS-Windows.
8534 The list will by default be sorted by name (case sensitive),
8535 the sorting can be changed by using the optional {dict}
8536 argument, see |readdir()|.
8537
8538 The Dictionary for file and directory information has the
8539 following items:
8540 group Group name of the entry. (Only on Unix)
8541 name Name of the entry.
8542 perm Permissions of the entry. See |getfperm()|.
8543 size Size of the entry. See |getfsize()|.
8544 time Timestamp of the entry. See |getftime()|.
8545 type Type of the entry.
8546 On Unix, almost same as |getftype()| except:
8547 Symlink to a dir "linkd"
8548 Other symlink "link"
8549 On MS-Windows:
8550 Normal file "file"
8551 Directory "dir"
8552 Junction "junction"
8553 Symlink to a dir "linkd"
8554 Other symlink "link"
8555 Other reparse point "reparse"
8556 user User name of the entry's owner. (Only on Unix)
8557 On Unix, if the entry is a symlink, the Dictionary includes
8558 the information of the target (except the "type" item).
8559 On MS-Windows, it includes the information of the symlink
8560 itself because of performance reasons.
8561
8562 When {expr} is omitted all entries are included.
8563 When {expr} is given, it is evaluated to check what to do:
8564 If {expr} results in -1 then no further entries will
8565 be handled.
8566 If {expr} results in 0 then this entry will not be
8567 added to the list.
8568 If {expr} results in 1 then this entry will be added
8569 to the list.
8570 The entries "." and ".." are always excluded.
8571 Each time {expr} is evaluated |v:val| is set to a |Dictionary|
8572 of the entry.
8573 When {expr} is a function the entry is passed as the argument.
8574 For example, to get a list of files ending in ".txt": >
8575 readdirex(dirname, {e -> e.name =~ '.txt$'})
8576<
8577 For example, to get a list of all files in the current
8578 directory without sorting the individual entries: >
8579 readdirex(dirname, '1', #{sort: 'none'})
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008580<
8581 Can also be used as a |method|: >
8582 GetDirName()->readdirex()
8583<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008584 Return type: list<dict<any>> or list<any>
8585
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008586
8587 *readfile()*
8588readfile({fname} [, {type} [, {max}]])
8589 Read file {fname} and return a |List|, each line of the file
8590 as an item. Lines are broken at NL characters. Macintosh
8591 files separated with CR will result in a single long line
8592 (unless a NL appears somewhere).
8593 All NUL characters are replaced with a NL character.
8594 When {type} contains "b" binary mode is used:
8595 - When the last line ends in a NL an extra empty list item is
8596 added.
8597 - No CR characters are removed.
8598 Otherwise:
8599 - CR characters that appear before a NL are removed.
8600 - Whether the last line ends in a NL or not does not matter.
8601 - When 'encoding' is Unicode any UTF-8 byte order mark is
8602 removed from the text.
8603 When {max} is given this specifies the maximum number of lines
8604 to be read. Useful if you only want to check the first ten
8605 lines of a file: >
8606 :for line in readfile(fname, '', 10)
8607 : if line =~ 'Date' | echo line | endif
8608 :endfor
8609< When {max} is negative -{max} lines from the end of the file
8610 are returned, or as many as there are.
8611 When {max} is zero the result is an empty list.
8612 Note that without {max} the whole file is read into memory.
8613 Also note that there is no recognition of encoding. Read a
8614 file into a buffer if you need to.
8615 Deprecated (use |readblob()| instead): When {type} contains
8616 "B" a |Blob| is returned with the binary data of the file
8617 unmodified.
8618 When the file can't be opened an error message is given and
8619 the result is an empty list.
8620 Also see |writefile()|.
8621
8622 Can also be used as a |method|: >
8623 GetFileName()->readfile()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008624<
8625 Return type: list<string> or list<any>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008626
8627reduce({object}, {func} [, {initial}]) *reduce()* *E998*
8628 {func} is called for every item in {object}, which can be a
Yegappan Lakshmanan9cb865e2025-03-23 16:42:16 +01008629 |String|, |List|, |Tuple| or a |Blob|. {func} is called with
8630 two arguments: the result so far and current item. After
Bram Moolenaarf10911e2022-01-29 22:20:48 +00008631 processing all items the result is returned. *E1132*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008632
8633 {initial} is the initial result. When omitted, the first item
8634 in {object} is used and {func} is first called for the second
8635 item. If {initial} is not given and {object} is empty no
8636 result can be computed, an E998 error is given.
8637
8638 Examples: >
8639 echo reduce([1, 3, 5], { acc, val -> acc + val })
8640 echo reduce(['x', 'y'], { acc, val -> acc .. val }, 'a')
8641 echo reduce(0z1122, { acc, val -> 2 * acc + val })
8642 echo reduce('xyz', { acc, val -> acc .. ',' .. val })
8643<
8644 Can also be used as a |method|: >
8645 echo mylist->reduce({ acc, val -> acc + val }, 0)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008646<
8647 Return type: |String|, |Blob|, list<{type}> or dict<{type}>
8648 depending on {object} and {func}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008649
8650
8651reg_executing() *reg_executing()*
8652 Returns the single letter name of the register being executed.
8653 Returns an empty string when no register is being executed.
8654 See |@|.
8655
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008656 Return type: |String|
8657
8658
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008659reg_recording() *reg_recording()*
8660 Returns the single letter name of the register being recorded.
8661 Returns an empty string when not recording. See |q|.
8662
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008663 Return type: |String|
8664
8665
8666reltime() *reltime()*
Bram Moolenaarf269eab2022-10-03 18:04:35 +01008667reltime({start})
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008668reltime({start}, {end})
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008669 Return an item that represents a time value. The item is a
8670 list with items that depend on the system. In Vim 9 script
Bram Moolenaar71badf92023-04-22 22:40:14 +01008671 the type list<any> can be used.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008672 The item can be passed to |reltimestr()| to convert it to a
Bram Moolenaarf269eab2022-10-03 18:04:35 +01008673 string or |reltimefloat()| to convert to a Float. For
8674 example, to see the time spent in function Work(): >
8675 var startTime = reltime()
8676 Work()
8677 echo startTime->reltime()->reltimestr()
8678<
Bram Moolenaar016188f2022-06-06 20:52:59 +01008679 Without an argument reltime() returns the current time (the
Lifepillar963fd7d2024-01-05 17:44:57 +01008680 representation is system-dependent, it cannot be used as the
Bram Moolenaar016188f2022-06-06 20:52:59 +01008681 wall-clock time, see |localtime()| for that).
Lifepillar963fd7d2024-01-05 17:44:57 +01008682 With one argument it returns the time passed since the time
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008683 specified in the argument.
8684 With two arguments it returns the time passed between {start}
8685 and {end}.
8686
8687 The {start} and {end} arguments must be values returned by
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01008688 reltime(). If there is an error an empty List is returned in
8689 legacy script, in Vim9 script an error is given.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008690
8691 Can also be used as a |method|: >
8692 GetStart()->reltime()
8693<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008694 Return type: list<number>
8695
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008696 {only available when compiled with the |+reltime| feature}
8697
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008698
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008699reltimefloat({time}) *reltimefloat()*
8700 Return a Float that represents the time value of {time}.
8701 Example: >
8702 let start = reltime()
8703 call MyFunction()
8704 let seconds = reltimefloat(reltime(start))
8705< See the note of reltimestr() about overhead.
8706 Also see |profiling|.
8707 If there is an error 0.0 is returned in legacy script, in Vim9
8708 script an error is given.
8709
8710 Can also be used as a |method|: >
8711 reltime(start)->reltimefloat()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008712<
8713 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008714
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008715 {only available when compiled with the |+reltime| feature}
8716
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008717
8718reltimestr({time}) *reltimestr()*
8719 Return a String that represents the time value of {time}.
8720 This is the number of seconds, a dot and the number of
8721 microseconds. Example: >
8722 let start = reltime()
8723 call MyFunction()
8724 echo reltimestr(reltime(start))
8725< Note that overhead for the commands will be added to the time.
Ernie Rael076de792023-03-16 21:43:15 +00008726 The accuracy depends on the system. Use reltimefloat() for the
8727 greatest accuracy which is nanoseconds on some systems.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008728 Leading spaces are used to make the string align nicely. You
8729 can use split() to remove it. >
8730 echo split(reltimestr(reltime(start)))[0]
8731< Also see |profiling|.
8732 If there is an error an empty string is returned in legacy
8733 script, in Vim9 script an error is given.
8734
8735 Can also be used as a |method|: >
8736 reltime(start)->reltimestr()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008737<
8738 Return type: |String|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008739
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008740 {only available when compiled with the |+reltime| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008741
8742 *remote_expr()* *E449*
8743remote_expr({server}, {string} [, {idvar} [, {timeout}]])
Bram Moolenaar944697a2022-02-20 19:48:20 +00008744 Send the {string} to {server}. The {server} argument is a
8745 string, also see |{server}|.
8746
8747 The string is sent as an expression and the result is returned
Christian Brabandt1961caf2024-10-12 11:57:12 +02008748 after evaluation. The result must be a String or a |List|
8749 other types will be converted to String. A |List| is turned
8750 into a String by joining the items with a line break in
8751 between (not at the end), like with join(expr, "\n").
Bram Moolenaar944697a2022-02-20 19:48:20 +00008752
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008753 If {idvar} is present and not empty, it is taken as the name
8754 of a variable and a {serverid} for later use with
8755 |remote_read()| is stored there.
Bram Moolenaar944697a2022-02-20 19:48:20 +00008756
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008757 If {timeout} is given the read times out after this many
8758 seconds. Otherwise a timeout of 600 seconds is used.
Bram Moolenaar944697a2022-02-20 19:48:20 +00008759
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008760 See also |clientserver| |RemoteReply|.
8761 This function is not available in the |sandbox|.
8762 {only available when compiled with the |+clientserver| feature}
8763 Note: Any errors will cause a local error message to be issued
8764 and the result will be the empty string.
8765
8766 Variables will be evaluated in the global namespace,
8767 independent of a function currently being active. Except
8768 when in debug mode, then local function variables and
8769 arguments can be evaluated.
8770
8771 Examples: >
8772 :echo remote_expr("gvim", "2+2")
8773 :echo remote_expr("gvim1", "b:current_syntax")
8774<
8775 Can also be used as a |method|: >
8776 ServerName()->remote_expr(expr)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008777<
8778 Return type: |String| or list<{type}>
8779
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008780
8781remote_foreground({server}) *remote_foreground()*
8782 Move the Vim server with the name {server} to the foreground.
Bram Moolenaar944697a2022-02-20 19:48:20 +00008783 The {server} argument is a string, also see |{server}|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008784 This works like: >
8785 remote_expr({server}, "foreground()")
8786< Except that on Win32 systems the client does the work, to work
8787 around the problem that the OS doesn't always allow the server
8788 to bring itself to the foreground.
8789 Note: This does not restore the window if it was minimized,
8790 like foreground() does.
8791 This function is not available in the |sandbox|.
8792
8793 Can also be used as a |method|: >
8794 ServerName()->remote_foreground()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008795<
8796 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008797
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008798 {only in the Win32, Motif and GTK GUI versions and the
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008799 Win32 console version}
8800
8801
8802remote_peek({serverid} [, {retvar}]) *remote_peek()*
8803 Returns a positive number if there are available strings
8804 from {serverid}. Copies any reply string into the variable
8805 {retvar} if specified. {retvar} must be a string with the
8806 name of a variable.
8807 Returns zero if none are available.
8808 Returns -1 if something is wrong.
8809 See also |clientserver|.
8810 This function is not available in the |sandbox|.
8811 {only available when compiled with the |+clientserver| feature}
8812 Examples: >
Bram Moolenaarf269eab2022-10-03 18:04:35 +01008813 :let repl = ""
8814 :echo "PEEK: " .. remote_peek(id, "repl") .. ": " .. repl
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008815
8816< Can also be used as a |method|: >
8817 ServerId()->remote_peek()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008818<
8819 Return type: |Number|
8820
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008821
8822remote_read({serverid}, [{timeout}]) *remote_read()*
8823 Return the oldest available reply from {serverid} and consume
8824 it. Unless a {timeout} in seconds is given, it blocks until a
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01008825 reply is available. Returns an empty string, if a reply is
8826 not available or on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008827 See also |clientserver|.
8828 This function is not available in the |sandbox|.
8829 {only available when compiled with the |+clientserver| feature}
8830 Example: >
8831 :echo remote_read(id)
8832
8833< Can also be used as a |method|: >
8834 ServerId()->remote_read()
8835<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008836 Return type: |String|
8837
8838
8839remote_send({server}, {string} [, {idvar}]) *remote_send()* *E241*
Bram Moolenaar944697a2022-02-20 19:48:20 +00008840 Send the {string} to {server}. The {server} argument is a
8841 string, also see |{server}|.
8842
8843 The string is sent as input keys and the function returns
8844 immediately. At the Vim server the keys are not mapped
8845 |:map|.
8846
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008847 If {idvar} is present, it is taken as the name of a variable
8848 and a {serverid} for later use with remote_read() is stored
8849 there.
Bram Moolenaar944697a2022-02-20 19:48:20 +00008850
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008851 See also |clientserver| |RemoteReply|.
8852 This function is not available in the |sandbox|.
8853 {only available when compiled with the |+clientserver| feature}
8854
8855 Note: Any errors will be reported in the server and may mess
8856 up the display.
8857 Examples: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00008858 :echo remote_send("gvim", ":DropAndReply " .. file, "serverid") ..
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008859 \ remote_read(serverid)
8860
8861 :autocmd NONE RemoteReply *
8862 \ echo remote_read(expand("<amatch>"))
Bram Moolenaarc51cf032022-02-26 12:25:45 +00008863 :echo remote_send("gvim", ":sleep 10 | echo " ..
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008864 \ 'server2client(expand("<client>"), "HELLO")<CR>')
8865<
8866 Can also be used as a |method|: >
8867 ServerName()->remote_send(keys)
8868<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008869 Return type: |String|
8870
8871
8872remote_startserver({name}) *remote_startserver()* *E941* *E942*
h-east17b69512023-05-01 22:36:56 +01008873 Become the server {name}. {name} must be a non-empty string.
8874 This fails if already running as a server, when |v:servername|
8875 is not empty.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008876
8877 Can also be used as a |method|: >
8878 ServerName()->remote_startserver()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008879<
8880 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008881
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008882 {only available when compiled with the |+clientserver| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008883
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008884
8885remove({list}, {idx}) *remove()*
8886remove({list}, {idx}, {end})
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008887 Without {end}: Remove the item at {idx} from |List| {list} and
8888 return the item.
8889 With {end}: Remove items from {idx} to {end} (inclusive) and
8890 return a |List| with these items. When {idx} points to the same
8891 item as {end} a list with one item is returned. When {end}
8892 points to an item before {idx} this is an error.
8893 See |list-index| for possible values of {idx} and {end}.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01008894 Returns zero on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008895 Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00008896 :echo "last item: " .. remove(mylist, -1)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008897 :call remove(mylist, 0, 9)
8898<
8899 Use |delete()| to remove a file.
8900
8901 Can also be used as a |method|: >
8902 mylist->remove(idx)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008903<
8904 Return type: any, depending on {list}
8905
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008906
Bram Moolenaarf269eab2022-10-03 18:04:35 +01008907remove({blob}, {idx})
8908remove({blob}, {idx}, {end})
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008909 Without {end}: Remove the byte at {idx} from |Blob| {blob} and
8910 return the byte.
8911 With {end}: Remove bytes from {idx} to {end} (inclusive) and
8912 return a |Blob| with these bytes. When {idx} points to the same
8913 byte as {end} a |Blob| with one byte is returned. When {end}
8914 points to a byte before {idx} this is an error.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01008915 Returns zero on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008916 Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00008917 :echo "last byte: " .. remove(myblob, -1)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008918 :call remove(mylist, 0, 9)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008919<
8920 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008921
8922remove({dict}, {key})
8923 Remove the entry from {dict} with key {key} and return it.
8924 Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00008925 :echo "removed " .. remove(dict, "one")
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008926< If there is no {key} in {dict} this is an error.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01008927 Returns zero on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008928
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008929 Return type: any, depending on {dict}
8930
8931
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008932rename({from}, {to}) *rename()*
8933 Rename the file by the name {from} to the name {to}. This
8934 should also work to move files across file systems. The
8935 result is a Number, which is 0 if the file was renamed
8936 successfully, and non-zero when the renaming failed.
8937 NOTE: If {to} exists it is overwritten without warning.
8938 This function is not available in the |sandbox|.
8939
8940 Can also be used as a |method|: >
8941 GetOldName()->rename(newname)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008942<
8943 Return type: |Number|
8944
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008945
8946repeat({expr}, {count}) *repeat()*
8947 Repeat {expr} {count} times and return the concatenated
8948 result. Example: >
8949 :let separator = repeat('-', 80)
8950< When {count} is zero or negative the result is empty.
Yegappan Lakshmanan9cb865e2025-03-23 16:42:16 +01008951 When {expr} is a |List|, a |Tuple| or a |Blob| the result is
8952 {expr} concatenated {count} times. Example: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008953 :let longlist = repeat(['a', 'b'], 3)
8954< Results in ['a', 'b', 'a', 'b', 'a', 'b'].
8955
8956 Can also be used as a |method|: >
8957 mylist->repeat(count)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008958<
Yegappan Lakshmanan9cb865e2025-03-23 16:42:16 +01008959 Return type: |String|, |Blob|, list<{type}> or tuple<{type}>
8960 depending on {expr}
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008961
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008962
8963resolve({filename}) *resolve()* *E655*
8964 On MS-Windows, when {filename} is a shortcut (a .lnk file),
8965 returns the path the shortcut points to in a simplified form.
8966 When {filename} is a symbolic link or junction point, return
8967 the full path to the target. If the target of junction is
8968 removed, return {filename}.
8969 On Unix, repeat resolving symbolic links in all path
8970 components of {filename} and return the simplified result.
8971 To cope with link cycles, resolving of symbolic links is
8972 stopped after 100 iterations.
8973 On other systems, return the simplified {filename}.
8974 The simplification step is done as by |simplify()|.
8975 resolve() keeps a leading path component specifying the
8976 current directory (provided the result is still a relative
8977 path name) and also keeps a trailing path separator.
8978
8979 Can also be used as a |method|: >
8980 GetName()->resolve()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008981<
8982 Return type: |String|
8983
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008984
8985reverse({object}) *reverse()*
Yegappan Lakshmanan03ff1c22023-05-06 14:08:21 +01008986 Reverse the order of items in {object}. {object} can be a
Yegappan Lakshmanan9cb865e2025-03-23 16:42:16 +01008987 |List|, a |Tuple|, a |Blob| or a |String|. For a List and a
8988 Blob the items are reversed in-place and {object} is returned.
8989 For a Tuple, a new Tuple is returned.
Yegappan Lakshmanan03ff1c22023-05-06 14:08:21 +01008990 For a String a new String is returned.
Yegappan Lakshmanan9cb865e2025-03-23 16:42:16 +01008991 Returns zero if {object} is not a List, Tuple, Blob or a
8992 String. If you want a List or Blob to remain unmodified make
8993 a copy first: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008994 :let revlist = reverse(copy(mylist))
8995< Can also be used as a |method|: >
8996 mylist->reverse()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008997<
Yegappan Lakshmanan9cb865e2025-03-23 16:42:16 +01008998 Return type: |String|, |Blob|, list<{type}> or tuple<{type}>
8999 depending on {object}
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009000
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009001
9002round({expr}) *round()*
9003 Round off {expr} to the nearest integral value and return it
9004 as a |Float|. If {expr} lies halfway between two integral
9005 values, then use the larger one (away from zero).
9006 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01009007 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009008 Examples: >
9009 echo round(0.456)
9010< 0.0 >
9011 echo round(4.5)
9012< 5.0 >
9013 echo round(-4.5)
9014< -5.0
9015
9016 Can also be used as a |method|: >
9017 Compute()->round()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009018<
9019 Return type: |Float|
9020
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009021
9022rubyeval({expr}) *rubyeval()*
9023 Evaluate Ruby expression {expr} and return its result
9024 converted to Vim data structures.
9025 Numbers, floats and strings are returned as they are (strings
9026 are copied though).
9027 Arrays are represented as Vim |List| type.
9028 Hashes are represented as Vim |Dictionary| type.
9029 Other objects are represented as strings resulted from their
9030 "Object#to_s" method.
9031 Note that in a `:def` function local variables are not visible
9032 to {expr}.
9033
9034 Can also be used as a |method|: >
9035 GetRubyExpr()->rubyeval()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009036<
9037 Return type: any, depending on {expr}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009038
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009039 {only available when compiled with the |+ruby| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009040
9041screenattr({row}, {col}) *screenattr()*
9042 Like |screenchar()|, but return the attribute. This is a rather
9043 arbitrary number that can only be used to compare to the
9044 attribute at other positions.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01009045 Returns -1 when row or col is out of range.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009046
9047 Can also be used as a |method|: >
9048 GetRow()->screenattr(col)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009049<
9050 Return type: |Number|
9051
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009052
9053screenchar({row}, {col}) *screenchar()*
9054 The result is a Number, which is the character at position
9055 [row, col] on the screen. This works for every possible
9056 screen position, also status lines, window separators and the
9057 command line. The top left position is row one, column one
9058 The character excludes composing characters. For double-byte
9059 encodings it may only be the first byte.
9060 This is mainly to be used for testing.
9061 Returns -1 when row or col is out of range.
9062
9063 Can also be used as a |method|: >
9064 GetRow()->screenchar(col)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009065<
9066 Return type: |Number|
9067
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009068
9069screenchars({row}, {col}) *screenchars()*
9070 The result is a |List| of Numbers. The first number is the same
9071 as what |screenchar()| returns. Further numbers are
9072 composing characters on top of the base character.
9073 This is mainly to be used for testing.
9074 Returns an empty List when row or col is out of range.
9075
9076 Can also be used as a |method|: >
9077 GetRow()->screenchars(col)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009078<
9079 Return type: list<number> or list<any>
9080
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009081
9082screencol() *screencol()*
9083 The result is a Number, which is the current screen column of
9084 the cursor. The leftmost column has number 1.
9085 This function is mainly used for testing.
9086
9087 Note: Always returns the current screen column, thus if used
9088 in a command (e.g. ":echo screencol()") it will return the
9089 column inside the command line, which is 1 when the command is
9090 executed. To get the cursor position in the file use one of
9091 the following mappings: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00009092 nnoremap <expr> GG ":echom " .. screencol() .. "\n"
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009093 nnoremap <silent> GG :echom screencol()<CR>
9094 nnoremap GG <Cmd>echom screencol()<CR>
9095<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009096 Return type: |Number|
9097
9098
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009099screenpos({winid}, {lnum}, {col}) *screenpos()*
9100 The result is a Dict with the screen position of the text
9101 character in window {winid} at buffer line {lnum} and column
9102 {col}. {col} is a one-based byte index.
9103 The Dict has these members:
9104 row screen row
9105 col first screen column
9106 endcol last screen column
9107 curscol cursor screen column
9108 If the specified position is not visible, all values are zero.
9109 The "endcol" value differs from "col" when the character
9110 occupies more than one screen cell. E.g. for a Tab "col" can
9111 be 1 and "endcol" can be 8.
9112 The "curscol" value is where the cursor would be placed. For
9113 a Tab it would be the same as "endcol", while for a double
9114 width character it would be the same as "col".
9115 The |conceal| feature is ignored here, the column numbers are
9116 as if 'conceallevel' is zero. You can set the cursor to the
9117 right position and use |screencol()| to get the value with
9118 |conceal| taken into account.
Bram Moolenaar944697a2022-02-20 19:48:20 +00009119 If the position is in a closed fold the screen position of the
9120 first character is returned, {col} is not used.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01009121 Returns an empty Dict if {winid} is invalid.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009122
9123 Can also be used as a |method|: >
9124 GetWinid()->screenpos(lnum, col)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009125<
9126 Return type: dict<number> or dict<any>
9127
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009128
9129screenrow() *screenrow()*
9130 The result is a Number, which is the current screen row of the
9131 cursor. The top line has number one.
9132 This function is mainly used for testing.
9133 Alternatively you can use |winline()|.
9134
9135 Note: Same restrictions as with |screencol()|.
9136
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009137 Return type: |Number|
9138
9139
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009140screenstring({row}, {col}) *screenstring()*
9141 The result is a String that contains the base character and
9142 any composing characters at position [row, col] on the screen.
9143 This is like |screenchars()| but returning a String with the
9144 characters.
9145 This is mainly to be used for testing.
9146 Returns an empty String when row or col is out of range.
9147
9148 Can also be used as a |method|: >
9149 GetRow()->screenstring(col)
9150<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009151 Return type: |String|
9152
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009153 *search()*
9154search({pattern} [, {flags} [, {stopline} [, {timeout} [, {skip}]]]])
9155 Search for regexp pattern {pattern}. The search starts at the
9156 cursor position (you can use |cursor()| to set it).
9157
9158 When a match has been found its line number is returned.
9159 If there is no match a 0 is returned and the cursor doesn't
9160 move. No error message is given.
Christian Brabandt9a660d22024-03-12 22:03:09 +01009161 To get the matched string, use |matchbufline()|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009162
9163 {flags} is a String, which can contain these character flags:
9164 'b' search Backward instead of forward
9165 'c' accept a match at the Cursor position
9166 'e' move to the End of the match
9167 'n' do Not move the cursor
9168 'p' return number of matching sub-Pattern (see below)
9169 's' Set the ' mark at the previous location of the cursor
9170 'w' Wrap around the end of the file
9171 'W' don't Wrap around the end of the file
Doug Kearns8a27d972025-01-05 15:56:57 +01009172 'z' start searching at the cursor column instead of Zero
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009173 If neither 'w' or 'W' is given, the 'wrapscan' option applies.
9174
9175 If the 's' flag is supplied, the ' mark is set, only if the
9176 cursor is moved. The 's' flag cannot be combined with the 'n'
9177 flag.
9178
9179 'ignorecase', 'smartcase' and 'magic' are used.
9180
9181 When the 'z' flag is not given, forward searching always
9182 starts in column zero and then matches before the cursor are
9183 skipped. When the 'c' flag is present in 'cpo' the next
9184 search starts after the match. Without the 'c' flag the next
Bram Moolenaarfd999452022-08-24 18:30:14 +01009185 search starts one column after the start of the match. This
9186 matters for overlapping matches. See |cpo-c|. You can also
9187 insert "\ze" to change where the match ends, see |/\ze|.
9188
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009189 When searching backwards and the 'z' flag is given then the
9190 search starts in column zero, thus no match in the current
9191 line will be found (unless wrapping around the end of the
9192 file).
9193
9194 When the {stopline} argument is given then the search stops
9195 after searching this line. This is useful to restrict the
9196 search to a range of lines. Examples: >
9197 let match = search('(', 'b', line("w0"))
9198 let end = search('END', '', line("w$"))
9199< When {stopline} is used and it is not zero this also implies
9200 that the search does not wrap around the end of the file.
9201 A zero value is equal to not giving the argument.
Bram Moolenaar2ecbe532022-07-29 21:36:21 +01009202 *E1285* *E1286* *E1287* *E1288* *E1289*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009203 When the {timeout} argument is given the search stops when
9204 more than this many milliseconds have passed. Thus when
9205 {timeout} is 500 the search stops after half a second.
9206 The value must not be negative. A zero value is like not
9207 giving the argument.
Christian Brabandtd657d3d2024-09-10 21:55:49 +02009208
9209 Note: the timeout is only considered when searching, not
9210 while evaluating the {skip} expression.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009211 {only available when compiled with the |+reltime| feature}
9212
9213 If the {skip} expression is given it is evaluated with the
9214 cursor positioned on the start of a match. If it evaluates to
9215 non-zero this match is skipped. This can be used, for
9216 example, to skip a match in a comment or a string.
9217 {skip} can be a string, which is evaluated as an expression, a
9218 function reference or a lambda.
9219 When {skip} is omitted or empty, every match is accepted.
9220 When evaluating {skip} causes an error the search is aborted
9221 and -1 returned.
9222 *search()-sub-match*
9223 With the 'p' flag the returned value is one more than the
9224 first sub-match in \(\). One if none of them matched but the
9225 whole pattern did match.
9226 To get the column number too use |searchpos()|.
9227
9228 The cursor will be positioned at the match, unless the 'n'
9229 flag is used.
9230
9231 Example (goes over all files in the argument list): >
9232 :let n = 1
9233 :while n <= argc() " loop over all files in arglist
Bram Moolenaarc51cf032022-02-26 12:25:45 +00009234 : exe "argument " .. n
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009235 : " start at the last char in the file and wrap for the
9236 : " first search to find match at start of file
9237 : normal G$
9238 : let flags = "w"
9239 : while search("foo", flags) > 0
9240 : s/foo/bar/g
9241 : let flags = "W"
9242 : endwhile
9243 : update " write the file if modified
9244 : let n = n + 1
9245 :endwhile
9246<
9247 Example for using some flags: >
9248 :echo search('\<if\|\(else\)\|\(endif\)', 'ncpe')
9249< This will search for the keywords "if", "else", and "endif"
9250 under or after the cursor. Because of the 'p' flag, it
9251 returns 1, 2, or 3 depending on which keyword is found, or 0
9252 if the search fails. With the cursor on the first word of the
9253 line:
9254 if (foo == 0) | let foo = foo + 1 | endif ~
9255 the function returns 1. Without the 'c' flag, the function
9256 finds the "endif" and returns 3. The same thing happens
9257 without the 'e' flag if the cursor is on the "f" of "if".
9258 The 'n' flag tells the function not to move the cursor.
9259
9260 Can also be used as a |method|: >
9261 GetPattern()->search()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009262<
9263 Return type: |Number|
9264
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009265
9266searchcount([{options}]) *searchcount()*
9267 Get or update the last search count, like what is displayed
9268 without the "S" flag in 'shortmess'. This works even if
9269 'shortmess' does contain the "S" flag.
9270
9271 This returns a |Dictionary|. The dictionary is empty if the
9272 previous pattern was not set and "pattern" was not specified.
9273
9274 key type meaning ~
9275 current |Number| current position of match;
9276 0 if the cursor position is
9277 before the first match
9278 exact_match |Boolean| 1 if "current" is matched on
9279 "pos", otherwise 0
9280 total |Number| total count of matches found
9281 incomplete |Number| 0: search was fully completed
9282 1: recomputing was timed out
9283 2: max count exceeded
9284
9285 For {options} see further down.
9286
9287 To get the last search count when |n| or |N| was pressed, call
9288 this function with `recompute: 0` . This sometimes returns
9289 wrong information because |n| and |N|'s maximum count is 99.
9290 If it exceeded 99 the result must be max count + 1 (100). If
9291 you want to get correct information, specify `recompute: 1`: >
9292
9293 " result == maxcount + 1 (100) when many matches
9294 let result = searchcount(#{recompute: 0})
9295
9296 " Below returns correct result (recompute defaults
9297 " to 1)
9298 let result = searchcount()
9299<
Bram Moolenaarb529cfb2022-07-25 15:42:07 +01009300 The function is useful to add the count to 'statusline': >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009301 function! LastSearchCount() abort
9302 let result = searchcount(#{recompute: 0})
9303 if empty(result)
9304 return ''
9305 endif
9306 if result.incomplete ==# 1 " timed out
9307 return printf(' /%s [?/??]', @/)
9308 elseif result.incomplete ==# 2 " max count exceeded
9309 if result.total > result.maxcount &&
9310 \ result.current > result.maxcount
9311 return printf(' /%s [>%d/>%d]', @/,
9312 \ result.current, result.total)
9313 elseif result.total > result.maxcount
9314 return printf(' /%s [%d/>%d]', @/,
9315 \ result.current, result.total)
9316 endif
9317 endif
9318 return printf(' /%s [%d/%d]', @/,
9319 \ result.current, result.total)
9320 endfunction
Bram Moolenaarc51cf032022-02-26 12:25:45 +00009321 let &statusline ..= '%{LastSearchCount()}'
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009322
9323 " Or if you want to show the count only when
9324 " 'hlsearch' was on
Bram Moolenaarc51cf032022-02-26 12:25:45 +00009325 " let &statusline ..=
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009326 " \ '%{v:hlsearch ? LastSearchCount() : ""}'
9327<
9328 You can also update the search count, which can be useful in a
9329 |CursorMoved| or |CursorMovedI| autocommand: >
9330
9331 autocmd CursorMoved,CursorMovedI *
9332 \ let s:searchcount_timer = timer_start(
9333 \ 200, function('s:update_searchcount'))
9334 function! s:update_searchcount(timer) abort
9335 if a:timer ==# s:searchcount_timer
9336 call searchcount(#{
9337 \ recompute: 1, maxcount: 0, timeout: 100})
9338 redrawstatus
9339 endif
9340 endfunction
9341<
9342 This can also be used to count matched texts with specified
9343 pattern in the current buffer using "pattern": >
9344
9345 " Count '\<foo\>' in this buffer
9346 " (Note that it also updates search count)
9347 let result = searchcount(#{pattern: '\<foo\>'})
9348
9349 " To restore old search count by old pattern,
9350 " search again
9351 call searchcount()
9352<
9353 {options} must be a |Dictionary|. It can contain:
9354 key type meaning ~
9355 recompute |Boolean| if |TRUE|, recompute the count
9356 like |n| or |N| was executed.
9357 otherwise returns the last
9358 computed result (when |n| or
9359 |N| was used when "S" is not
9360 in 'shortmess', or this
9361 function was called).
9362 (default: |TRUE|)
9363 pattern |String| recompute if this was given
9364 and different with |@/|.
9365 this works as same as the
9366 below command is executed
9367 before calling this function >
9368 let @/ = pattern
9369< (default: |@/|)
9370 timeout |Number| 0 or negative number is no
9371 timeout. timeout milliseconds
9372 for recomputing the result
9373 (default: 0)
9374 maxcount |Number| 0 or negative number is no
9375 limit. max count of matched
9376 text while recomputing the
9377 result. if search exceeded
9378 total count, "total" value
9379 becomes `maxcount + 1`
9380 (default: 99)
9381 pos |List| `[lnum, col, off]` value
9382 when recomputing the result.
9383 this changes "current" result
9384 value. see |cursor()|,
9385 |getpos()|
9386 (default: cursor's position)
9387
9388 Can also be used as a |method|: >
9389 GetSearchOpts()->searchcount()
9390<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009391 Return type: dict<number>
9392
9393
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009394searchdecl({name} [, {global} [, {thisblock}]]) *searchdecl()*
9395 Search for the declaration of {name}.
9396
9397 With a non-zero {global} argument it works like |gD|, find
9398 first match in the file. Otherwise it works like |gd|, find
9399 first match in the function.
9400
9401 With a non-zero {thisblock} argument matches in a {} block
9402 that ends before the cursor position are ignored. Avoids
9403 finding variable declarations only valid in another scope.
9404
9405 Moves the cursor to the found match.
9406 Returns zero for success, non-zero for failure.
9407 Example: >
9408 if searchdecl('myvar') == 0
9409 echo getline('.')
9410 endif
9411<
9412 Can also be used as a |method|: >
9413 GetName()->searchdecl()
9414<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009415 Return type: |Number|
9416
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009417 *searchpair()*
9418searchpair({start}, {middle}, {end} [, {flags} [, {skip}
9419 [, {stopline} [, {timeout}]]]])
9420 Search for the match of a nested start-end pair. This can be
9421 used to find the "endif" that matches an "if", while other
9422 if/endif pairs in between are ignored.
9423 The search starts at the cursor. The default is to search
9424 forward, include 'b' in {flags} to search backward.
9425 If a match is found, the cursor is positioned at it and the
9426 line number is returned. If no match is found 0 or -1 is
9427 returned and the cursor doesn't move. No error message is
9428 given.
9429
9430 {start}, {middle} and {end} are patterns, see |pattern|. They
9431 must not contain \( \) pairs. Use of \%( \) is allowed. When
9432 {middle} is not empty, it is found when searching from either
9433 direction, but only when not in a nested start-end pair. A
9434 typical use is: >
9435 searchpair('\<if\>', '\<else\>', '\<endif\>')
9436< By leaving {middle} empty the "else" is skipped.
9437
9438 {flags} 'b', 'c', 'n', 's', 'w' and 'W' are used like with
9439 |search()|. Additionally:
9440 'r' Repeat until no more matches found; will find the
9441 outer pair. Implies the 'W' flag.
9442 'm' Return number of matches instead of line number with
9443 the match; will be > 1 when 'r' is used.
9444 Note: it's nearly always a good idea to use the 'W' flag, to
9445 avoid wrapping around the end of the file.
9446
9447 When a match for {start}, {middle} or {end} is found, the
9448 {skip} expression is evaluated with the cursor positioned on
9449 the start of the match. It should return non-zero if this
9450 match is to be skipped. E.g., because it is inside a comment
9451 or a string.
9452 When {skip} is omitted or empty, every match is accepted.
9453 When evaluating {skip} causes an error the search is aborted
9454 and -1 returned.
9455 {skip} can be a string, a lambda, a funcref or a partial.
9456 Anything else makes the function fail.
9457 In a `:def` function when the {skip} argument is a string
9458 constant it is compiled into instructions.
9459
9460 For {stopline} and {timeout} see |search()|.
9461
9462 The value of 'ignorecase' is used. 'magic' is ignored, the
9463 patterns are used like it's on.
9464
9465 The search starts exactly at the cursor. A match with
9466 {start}, {middle} or {end} at the next character, in the
9467 direction of searching, is the first one found. Example: >
9468 if 1
9469 if 2
9470 endif 2
9471 endif 1
9472< When starting at the "if 2", with the cursor on the "i", and
9473 searching forwards, the "endif 2" is found. When starting on
9474 the character just before the "if 2", the "endif 1" will be
9475 found. That's because the "if 2" will be found first, and
9476 then this is considered to be a nested if/endif from "if 2" to
9477 "endif 2".
9478 When searching backwards and {end} is more than one character,
9479 it may be useful to put "\zs" at the end of the pattern, so
9480 that when the cursor is inside a match with the end it finds
9481 the matching start.
9482
9483 Example, to find the "endif" command in a Vim script: >
9484
9485 :echo searchpair('\<if\>', '\<el\%[seif]\>', '\<en\%[dif]\>', 'W',
9486 \ 'getline(".") =~ "^\\s*\""')
9487
9488< The cursor must be at or after the "if" for which a match is
9489 to be found. Note that single-quote strings are used to avoid
9490 having to double the backslashes. The skip expression only
9491 catches comments at the start of a line, not after a command.
9492 Also, a word "en" or "if" halfway a line is considered a
9493 match.
9494 Another example, to search for the matching "{" of a "}": >
9495
9496 :echo searchpair('{', '', '}', 'bW')
9497
9498< This works when the cursor is at or before the "}" for which a
9499 match is to be found. To reject matches that syntax
9500 highlighting recognized as strings: >
9501
9502 :echo searchpair('{', '', '}', 'bW',
9503 \ 'synIDattr(synID(line("."), col("."), 0), "name") =~? "string"')
9504<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009505 Return type: |Number|
9506
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009507 *searchpairpos()*
9508searchpairpos({start}, {middle}, {end} [, {flags} [, {skip}
9509 [, {stopline} [, {timeout}]]]])
9510 Same as |searchpair()|, but returns a |List| with the line and
9511 column position of the match. The first element of the |List|
9512 is the line number and the second element is the byte index of
9513 the column position of the match. If no match is found,
9514 returns [0, 0]. >
9515
9516 :let [lnum,col] = searchpairpos('{', '', '}', 'n')
9517<
9518 See |match-parens| for a bigger and more useful example.
9519
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009520 Return type: list<number>
9521
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009522 *searchpos()*
9523searchpos({pattern} [, {flags} [, {stopline} [, {timeout} [, {skip}]]]])
9524 Same as |search()|, but returns a |List| with the line and
9525 column position of the match. The first element of the |List|
9526 is the line number and the second element is the byte index of
9527 the column position of the match. If no match is found,
9528 returns [0, 0].
9529 Example: >
9530 :let [lnum, col] = searchpos('mypattern', 'n')
9531
9532< When the 'p' flag is given then there is an extra item with
9533 the sub-pattern match number |search()-sub-match|. Example: >
9534 :let [lnum, col, submatch] = searchpos('\(\l\)\|\(\u\)', 'np')
9535< In this example "submatch" is 2 when a lowercase letter is
9536 found |/\l|, 3 when an uppercase letter is found |/\u|.
9537
9538 Can also be used as a |method|: >
9539 GetPattern()->searchpos()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009540<
9541 Return type: list<number>
9542
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009543
9544server2client({clientid}, {string}) *server2client()*
9545 Send a reply string to {clientid}. The most recent {clientid}
9546 that sent a string can be retrieved with expand("<client>").
9547 {only available when compiled with the |+clientserver| feature}
9548 Returns zero for success, -1 for failure.
9549 Note:
9550 This id has to be stored before the next command can be
9551 received. I.e. before returning from the received command and
9552 before calling any commands that waits for input.
9553 See also |clientserver|.
9554 Example: >
9555 :echo server2client(expand("<client>"), "HELLO")
9556
9557< Can also be used as a |method|: >
9558 GetClientId()->server2client(string)
9559<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009560 Return type: |Number|
9561
9562
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009563serverlist() *serverlist()*
9564 Return a list of available server names, one per line.
9565 When there are no servers or the information is not available
9566 an empty string is returned. See also |clientserver|.
9567 {only available when compiled with the |+clientserver| feature}
9568 Example: >
9569 :echo serverlist()
9570<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009571 Return type: |String|
9572
9573
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009574setbufline({buf}, {lnum}, {text}) *setbufline()*
9575 Set line {lnum} to {text} in buffer {buf}. This works like
9576 |setline()| for the specified buffer.
9577
9578 This function works only for loaded buffers. First call
9579 |bufload()| if needed.
9580
9581 To insert lines use |appendbufline()|.
9582 Any text properties in {lnum} are cleared.
9583
Bram Moolenaarcd9c8d42022-11-05 23:46:43 +00009584 {text} can be a string to set one line, or a List of strings
9585 to set multiple lines. If the List extends below the last
9586 line then those lines are added. If the List is empty then
9587 nothing is changed and zero is returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009588
9589 For the use of {buf}, see |bufname()| above.
9590
9591 {lnum} is used like with |setline()|.
9592 Use "$" to refer to the last line in buffer {buf}.
9593 When {lnum} is just below the last line the {text} will be
9594 added below the last line.
9595
9596 When {buf} is not a valid buffer, the buffer is not loaded or
9597 {lnum} is not valid then 1 is returned. In |Vim9| script an
9598 error is given.
9599 On success 0 is returned.
9600
9601 Can also be used as a |method|, the base is passed as the
9602 third argument: >
9603 GetText()->setbufline(buf, lnum)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009604<
9605 Return type: |Number|
9606
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009607
9608setbufvar({buf}, {varname}, {val}) *setbufvar()*
9609 Set option or local variable {varname} in buffer {buf} to
9610 {val}.
9611 This also works for a global or local window option, but it
9612 doesn't work for a global or local window variable.
9613 For a local window option the global value is unchanged.
9614 For the use of {buf}, see |bufname()| above.
9615 The {varname} argument is a string.
9616 Note that the variable name without "b:" must be used.
9617 Examples: >
9618 :call setbufvar(1, "&mod", 1)
9619 :call setbufvar("todo", "myvar", "foobar")
9620< This function is not available in the |sandbox|.
9621
9622 Can also be used as a |method|, the base is passed as the
9623 third argument: >
9624 GetValue()->setbufvar(buf, varname)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009625<
9626 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009627
9628
9629setcellwidths({list}) *setcellwidths()*
9630 Specify overrides for cell widths of character ranges. This
Bram Moolenaarb59ae592022-11-23 23:46:31 +00009631 tells Vim how wide characters are when displayed in the
9632 terminal, counted in screen cells. The values override
9633 'ambiwidth'. Example: >
9634 call setcellwidths([
Bram Moolenaar938ae282023-02-20 20:44:55 +00009635 \ [0x111, 0x111, 1],
Bram Moolenaarb59ae592022-11-23 23:46:31 +00009636 \ [0x2194, 0x2199, 2],
9637 \ ])
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009638
Bram Moolenaarb59ae592022-11-23 23:46:31 +00009639< The {list} argument is a List of Lists with each three
9640 numbers: [{low}, {high}, {width}]. *E1109* *E1110*
9641 {low} and {high} can be the same, in which case this refers to
9642 one character. Otherwise it is the range of characters from
9643 {low} to {high} (inclusive). *E1111* *E1114*
K.Takata71933232023-01-20 16:00:55 +00009644 Only characters with value 0x80 and higher can be used.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009645
Bram Moolenaarb59ae592022-11-23 23:46:31 +00009646 {width} must be either 1 or 2, indicating the character width
9647 in screen cells. *E1112*
9648 An error is given if the argument is invalid, also when a
Bram Moolenaar938ae282023-02-20 20:44:55 +00009649 range overlaps with another. *E1113*
Bram Moolenaarb59ae592022-11-23 23:46:31 +00009650
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009651 If the new value causes 'fillchars' or 'listchars' to become
9652 invalid it is rejected and an error is given.
9653
Bram Moolenaarb59ae592022-11-23 23:46:31 +00009654 To clear the overrides pass an empty {list}: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009655 setcellwidths([]);
Bram Moolenaarb59ae592022-11-23 23:46:31 +00009656
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009657< You can use the script $VIMRUNTIME/tools/emoji_list.vim to see
Bram Moolenaarb59ae592022-11-23 23:46:31 +00009658 the effect for known emoji characters. Move the cursor
9659 through the text to check if the cell widths of your terminal
9660 match with what Vim knows about each emoji. If it doesn't
9661 look right you need to adjust the {list} argument.
9662
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009663 Return type: |Number|
9664
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009665
9666setcharpos({expr}, {list}) *setcharpos()*
9667 Same as |setpos()| but uses the specified column number as the
9668 character index instead of the byte index in the line.
9669
9670 Example:
9671 With the text "여보세요" in line 8: >
9672 call setcharpos('.', [0, 8, 4, 0])
9673< positions the cursor on the fourth character '요'. >
9674 call setpos('.', [0, 8, 4, 0])
9675< positions the cursor on the second character '보'.
9676
9677 Can also be used as a |method|: >
9678 GetPosition()->setcharpos('.')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009679<
9680 Return type: |Number|
9681
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009682
9683setcharsearch({dict}) *setcharsearch()*
9684 Set the current character search information to {dict},
9685 which contains one or more of the following entries:
9686
9687 char character which will be used for a subsequent
9688 |,| or |;| command; an empty string clears the
9689 character search
9690 forward direction of character search; 1 for forward,
9691 0 for backward
9692 until type of character search; 1 for a |t| or |T|
9693 character search, 0 for an |f| or |F|
9694 character search
9695
9696 This can be useful to save/restore a user's character search
9697 from a script: >
9698 :let prevsearch = getcharsearch()
9699 :" Perform a command which clobbers user's search
9700 :call setcharsearch(prevsearch)
9701< Also see |getcharsearch()|.
9702
9703 Can also be used as a |method|: >
9704 SavedSearch()->setcharsearch()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009705<
9706 Return type: dict<any>
9707
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009708
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01009709setcmdline({str} [, {pos}]) *setcmdline()*
9710 Set the command line to {str} and set the cursor position to
9711 {pos}.
9712 If {pos} is omitted, the cursor is positioned after the text.
9713 Returns 0 when successful, 1 when not editing the command
9714 line.
9715
9716 Can also be used as a |method|: >
9717 GetText()->setcmdline()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009718<
9719 Return type: |Number|
9720
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01009721
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009722setcmdpos({pos}) *setcmdpos()*
9723 Set the cursor position in the command line to byte position
9724 {pos}. The first position is 1.
9725 Use |getcmdpos()| to obtain the current position.
9726 Only works while editing the command line, thus you must use
9727 |c_CTRL-\_e|, |c_CTRL-R_=| or |c_CTRL-R_CTRL-R| with '='. For
9728 |c_CTRL-\_e| and |c_CTRL-R_CTRL-R| with '=' the position is
9729 set after the command line is set to the expression. For
9730 |c_CTRL-R_=| it is set after evaluating the expression but
9731 before inserting the resulting text.
9732 When the number is too big the cursor is put at the end of the
9733 line. A number smaller than one has undefined results.
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01009734 Returns 0 when successful, 1 when not editing the command
9735 line.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009736
9737 Can also be used as a |method|: >
9738 GetPos()->setcmdpos()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009739<
9740 Return type: |Number|
9741
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009742
9743setcursorcharpos({lnum}, {col} [, {off}]) *setcursorcharpos()*
9744setcursorcharpos({list})
9745 Same as |cursor()| but uses the specified column number as the
9746 character index instead of the byte index in the line.
9747
9748 Example:
9749 With the text "여보세요" in line 4: >
9750 call setcursorcharpos(4, 3)
9751< positions the cursor on the third character '세'. >
9752 call cursor(4, 3)
9753< positions the cursor on the first character '여'.
9754
9755 Can also be used as a |method|: >
9756 GetCursorPos()->setcursorcharpos()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009757<
9758 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009759
9760
9761setenv({name}, {val}) *setenv()*
9762 Set environment variable {name} to {val}. Example: >
9763 call setenv('HOME', '/home/myhome')
9764
9765< When {val} is |v:null| the environment variable is deleted.
9766 See also |expr-env|.
9767
9768 Can also be used as a |method|, the base is passed as the
9769 second argument: >
9770 GetPath()->setenv('PATH')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009771<
9772 Return type: |Number|
9773
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009774
9775setfperm({fname}, {mode}) *setfperm()* *chmod*
9776 Set the file permissions for {fname} to {mode}.
9777 {mode} must be a string with 9 characters. It is of the form
9778 "rwxrwxrwx", where each group of "rwx" flags represent, in
9779 turn, the permissions of the owner of the file, the group the
9780 file belongs to, and other users. A '-' character means the
9781 permission is off, any other character means on. Multi-byte
9782 characters are not supported.
9783
9784 For example "rw-r-----" means read-write for the user,
9785 readable by the group, not accessible by others. "xx-x-----"
9786 would do the same thing.
9787
9788 Returns non-zero for success, zero for failure.
9789
9790 Can also be used as a |method|: >
9791 GetFilename()->setfperm(mode)
9792<
9793 To read permissions see |getfperm()|.
9794
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009795 Return type: |Number|
9796
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009797
9798setline({lnum}, {text}) *setline()*
9799 Set line {lnum} of the current buffer to {text}. To insert
9800 lines use |append()|. To set lines in another buffer use
Christian Brabandt946f61c2024-06-17 13:17:58 +02009801 |setbufline()|.
h-east52e7cc22024-07-28 17:03:29 +02009802 Any text properties in {lnum} are cleared. See
9803 |text-prop-cleared|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009804
9805 {lnum} is used like with |getline()|.
9806 When {lnum} is just below the last line the {text} will be
9807 added below the last line.
9808 {text} can be any type or a List of any type, each item is
Bram Moolenaarcd9c8d42022-11-05 23:46:43 +00009809 converted to a String. When {text} is an empty List then
9810 nothing is changed and FALSE is returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009811
9812 If this succeeds, FALSE is returned. If this fails (most likely
9813 because {lnum} is invalid) TRUE is returned.
9814 In |Vim9| script an error is given if {lnum} is invalid.
9815
9816 Example: >
9817 :call setline(5, strftime("%c"))
9818
9819< When {text} is a |List| then line {lnum} and following lines
9820 will be set to the items in the list. Example: >
9821 :call setline(5, ['aaa', 'bbb', 'ccc'])
9822< This is equivalent to: >
9823 :for [n, l] in [[5, 'aaa'], [6, 'bbb'], [7, 'ccc']]
9824 : call setline(n, l)
9825 :endfor
9826
9827< Note: The '[ and '] marks are not set.
9828
9829 Can also be used as a |method|, the base is passed as the
9830 second argument: >
9831 GetText()->setline(lnum)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009832<
9833 Return type: |Number|
9834
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009835
9836setloclist({nr}, {list} [, {action} [, {what}]]) *setloclist()*
9837 Create or replace or add to the location list for window {nr}.
9838 {nr} can be the window number or the |window-ID|.
9839 When {nr} is zero the current window is used.
9840
9841 For a location list window, the displayed location list is
9842 modified. For an invalid window number {nr}, -1 is returned.
9843 Otherwise, same as |setqflist()|.
9844 Also see |location-list|.
9845
9846 For {action} see |setqflist-action|.
9847
9848 If the optional {what} dictionary argument is supplied, then
9849 only the items listed in {what} are set. Refer to |setqflist()|
9850 for the list of supported keys in {what}.
9851
9852 Can also be used as a |method|, the base is passed as the
9853 second argument: >
9854 GetLoclist()->setloclist(winnr)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009855<
9856 Return type: |Number|
9857
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009858
9859setmatches({list} [, {win}]) *setmatches()*
9860 Restores a list of matches saved by |getmatches()| for the
9861 current window. Returns 0 if successful, otherwise -1. All
9862 current matches are cleared before the list is restored. See
9863 example for |getmatches()|.
9864 If {win} is specified, use the window with this number or
9865 window ID instead of the current window.
9866
9867 Can also be used as a |method|: >
9868 GetMatches()->setmatches()
9869<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009870 Return type: |Number|
9871
9872
9873setpos({expr}, {list}) *setpos()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009874 Set the position for String {expr}. Possible values:
9875 . the cursor
9876 'x mark x
9877
9878 {list} must be a |List| with four or five numbers:
9879 [bufnum, lnum, col, off]
9880 [bufnum, lnum, col, off, curswant]
9881
9882 "bufnum" is the buffer number. Zero can be used for the
9883 current buffer. When setting an uppercase mark "bufnum" is
9884 used for the mark position. For other marks it specifies the
9885 buffer to set the mark in. You can use the |bufnr()| function
9886 to turn a file name into a buffer number.
9887 For setting the cursor and the ' mark "bufnum" is ignored,
9888 since these are associated with a window, not a buffer.
9889 Does not change the jumplist.
9890
9891 "lnum" and "col" are the position in the buffer. The first
9892 column is 1. Use a zero "lnum" to delete a mark. If "col" is
9893 smaller than 1 then 1 is used. To use the character count
9894 instead of the byte count, use |setcharpos()|.
9895
9896 The "off" number is only used when 'virtualedit' is set. Then
9897 it is the offset in screen columns from the start of the
9898 character. E.g., a position within a <Tab> or after the last
9899 character.
9900
9901 The "curswant" number is only used when setting the cursor
9902 position. It sets the preferred column for when moving the
9903 cursor vertically. When the "curswant" number is missing the
9904 preferred column is not set. When it is present and setting a
9905 mark position it is not used.
9906
9907 Note that for '< and '> changing the line number may result in
9908 the marks to be effectively be swapped, so that '< is always
9909 before '>.
9910
9911 Returns 0 when the position could be set, -1 otherwise.
9912 An error message is given if {expr} is invalid.
9913
9914 Also see |setcharpos()|, |getpos()| and |getcurpos()|.
9915
9916 This does not restore the preferred column for moving
9917 vertically; if you set the cursor position with this, |j| and
9918 |k| motions will jump to previous columns! Use |cursor()| to
9919 also set the preferred column. Also see the "curswant" key in
9920 |winrestview()|.
9921
9922 Can also be used as a |method|: >
9923 GetPosition()->setpos('.')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009924<
9925 Return type: |Number|
9926
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009927
9928setqflist({list} [, {action} [, {what}]]) *setqflist()*
9929 Create or replace or add to the quickfix list.
9930
9931 If the optional {what} dictionary argument is supplied, then
9932 only the items listed in {what} are set. The first {list}
9933 argument is ignored. See below for the supported items in
9934 {what}.
9935 *setqflist-what*
9936 When {what} is not present, the items in {list} are used. Each
9937 item must be a dictionary. Non-dictionary items in {list} are
9938 ignored. Each dictionary item can contain the following
9939 entries:
9940
9941 bufnr buffer number; must be the number of a valid
9942 buffer
9943 filename name of a file; only used when "bufnr" is not
9944 present or it is invalid.
9945 module name of a module; if given it will be used in
9946 quickfix error window instead of the filename.
9947 lnum line number in the file
Bram Moolenaara2baa732022-02-04 16:09:54 +00009948 end_lnum end of lines, if the item spans multiple lines
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009949 pattern search pattern used to locate the error
9950 col column number
9951 vcol when non-zero: "col" is visual column
9952 when zero: "col" is byte index
Bram Moolenaara2baa732022-02-04 16:09:54 +00009953 end_col end column, if the item spans multiple columns
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009954 nr error number
9955 text description of the error
9956 type single-character error type, 'E', 'W', etc.
9957 valid recognized error message
Tom Praschanca6ac992023-08-11 23:26:12 +02009958 user_data custom data associated with the item, can be
9959 any type.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009960
9961 The "col", "vcol", "nr", "type" and "text" entries are
9962 optional. Either "lnum" or "pattern" entry can be used to
9963 locate a matching error line.
9964 If the "filename" and "bufnr" entries are not present or
9965 neither the "lnum" or "pattern" entries are present, then the
9966 item will not be handled as an error line.
9967 If both "pattern" and "lnum" are present then "pattern" will
9968 be used.
9969 If the "valid" entry is not supplied, then the valid flag is
9970 set when "bufnr" is a valid buffer or "filename" exists.
9971 If you supply an empty {list}, the quickfix list will be
9972 cleared.
9973 Note that the list is not exactly the same as what
9974 |getqflist()| returns.
9975
9976 {action} values: *setqflist-action* *E927*
9977 'a' The items from {list} are added to the existing
9978 quickfix list. If there is no existing list, then a
9979 new list is created.
9980
9981 'r' The items from the current quickfix list are replaced
9982 with the items from {list}. This can also be used to
9983 clear the list: >
9984 :call setqflist([], 'r')
9985<
Jeremy Fleischman27fbf6e2024-10-14 20:46:27 +02009986 'u' Like 'r', but tries to preserve the current selection
9987 in the quickfix list.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009988 'f' All the quickfix lists in the quickfix stack are
9989 freed.
9990
9991 If {action} is not present or is set to ' ', then a new list
9992 is created. The new quickfix list is added after the current
9993 quickfix list in the stack and all the following lists are
9994 freed. To add a new quickfix list at the end of the stack,
9995 set "nr" in {what} to "$".
9996
9997 The following items can be specified in dictionary {what}:
9998 context quickfix list context. See |quickfix-context|
9999 efm errorformat to use when parsing text from
10000 "lines". If this is not present, then the
10001 'errorformat' option value is used.
10002 See |quickfix-parse|
10003 id quickfix list identifier |quickfix-ID|
10004 idx index of the current entry in the quickfix
10005 list specified by 'id' or 'nr'. If set to '$',
10006 then the last entry in the list is set as the
10007 current entry. See |quickfix-index|
10008 items list of quickfix entries. Same as the {list}
10009 argument.
10010 lines use 'errorformat' to parse a list of lines and
10011 add the resulting entries to the quickfix list
10012 {nr} or {id}. Only a |List| value is supported.
10013 See |quickfix-parse|
10014 nr list number in the quickfix stack; zero
10015 means the current quickfix list and "$" means
10016 the last quickfix list.
10017 quickfixtextfunc
10018 function to get the text to display in the
10019 quickfix window. The value can be the name of
10020 a function or a funcref or a lambda. Refer to
10021 |quickfix-window-function| for an explanation
10022 of how to write the function and an example.
10023 title quickfix list title text. See |quickfix-title|
10024 Unsupported keys in {what} are ignored.
10025 If the "nr" item is not present, then the current quickfix list
10026 is modified. When creating a new quickfix list, "nr" can be
10027 set to a value one greater than the quickfix stack size.
10028 When modifying a quickfix list, to guarantee that the correct
10029 list is modified, "id" should be used instead of "nr" to
10030 specify the list.
10031
10032 Examples (See also |setqflist-examples|): >
10033 :call setqflist([], 'r', {'title': 'My search'})
10034 :call setqflist([], 'r', {'nr': 2, 'title': 'Errors'})
10035 :call setqflist([], 'a', {'id':qfid, 'lines':["F1:10:L10"]})
10036<
10037 Returns zero for success, -1 for failure.
10038
10039 This function can be used to create a quickfix list
10040 independent of the 'errorformat' setting. Use a command like
10041 `:cc 1` to jump to the first position.
10042
10043 Can also be used as a |method|, the base is passed as the
10044 second argument: >
10045 GetErrorlist()->setqflist()
10046<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010047 Return type: |Number|
10048
10049
10050setreg({regname}, {value} [, {options}]) *setreg()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010051 Set the register {regname} to {value}.
10052 If {regname} is "" or "@", the unnamed register '"' is used.
10053 The {regname} argument is a string. In |Vim9-script|
10054 {regname} must be one character.
10055
10056 {value} may be any value returned by |getreg()| or
10057 |getreginfo()|, including a |List| or |Dict|.
10058 If {options} contains "a" or {regname} is upper case,
10059 then the value is appended.
10060
10061 {options} can also contain a register type specification:
10062 "c" or "v" |characterwise| mode
10063 "l" or "V" |linewise| mode
10064 "b" or "<CTRL-V>" |blockwise-visual| mode
10065 If a number immediately follows "b" or "<CTRL-V>" then this is
10066 used as the width of the selection - if it is not specified
10067 then the width of the block is set to the number of characters
10068 in the longest line (counting a <Tab> as 1 character).
10069
10070 If {options} contains no register settings, then the default
10071 is to use character mode unless {value} ends in a <NL> for
10072 string {value} and linewise mode for list {value}. Blockwise
10073 mode is never selected automatically.
10074 Returns zero for success, non-zero for failure.
10075
10076 *E883*
10077 Note: you may not use |List| containing more than one item to
10078 set search and expression registers. Lists containing no
10079 items act like empty strings.
10080
10081 Examples: >
10082 :call setreg(v:register, @*)
10083 :call setreg('*', @%, 'ac')
10084 :call setreg('a', "1\n2\n3", 'b5')
10085 :call setreg('"', { 'points_to': 'a'})
10086
10087< This example shows using the functions to save and restore a
10088 register: >
10089 :let var_a = getreginfo()
10090 :call setreg('a', var_a)
10091< or: >
10092 :let var_a = getreg('a', 1, 1)
10093 :let var_amode = getregtype('a')
10094 ....
10095 :call setreg('a', var_a, var_amode)
10096< Note: you may not reliably restore register value
10097 without using the third argument to |getreg()| as without it
10098 newlines are represented as newlines AND Nul bytes are
10099 represented as newlines as well, see |NL-used-for-Nul|.
10100
10101 You can also change the type of a register by appending
10102 nothing: >
10103 :call setreg('a', '', 'al')
10104
10105< Can also be used as a |method|, the base is passed as the
10106 second argument: >
10107 GetText()->setreg('a')
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010108<
10109 Return type: |Number|
10110
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010111
10112settabvar({tabnr}, {varname}, {val}) *settabvar()*
10113 Set tab-local variable {varname} to {val} in tab page {tabnr}.
10114 |t:var|
10115 The {varname} argument is a string.
10116 Note that autocommands are blocked, side effects may not be
10117 triggered, e.g. when setting 'filetype'.
10118 Note that the variable name without "t:" must be used.
10119 Tabs are numbered starting with one.
10120 This function is not available in the |sandbox|.
10121
10122 Can also be used as a |method|, the base is passed as the
10123 third argument: >
10124 GetValue()->settabvar(tab, name)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010125<
10126 Return type: |Number|
10127
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010128
10129settabwinvar({tabnr}, {winnr}, {varname}, {val}) *settabwinvar()*
10130 Set option or local variable {varname} in window {winnr} to
10131 {val}.
10132 Tabs are numbered starting with one. For the current tabpage
10133 use |setwinvar()|.
10134 {winnr} can be the window number or the |window-ID|.
10135 When {winnr} is zero the current window is used.
10136 Note that autocommands are blocked, side effects may not be
10137 triggered, e.g. when setting 'filetype' or 'syntax'.
10138 This also works for a global or local buffer option, but it
10139 doesn't work for a global or local buffer variable.
10140 For a local buffer option the global value is unchanged.
10141 Note that the variable name without "w:" must be used.
10142 Examples: >
10143 :call settabwinvar(1, 1, "&list", 0)
10144 :call settabwinvar(3, 2, "myvar", "foobar")
10145< This function is not available in the |sandbox|.
10146
10147 Can also be used as a |method|, the base is passed as the
10148 fourth argument: >
10149 GetValue()->settabwinvar(tab, winnr, name)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010150<
10151 Return type: |Number|
10152
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010153
10154settagstack({nr}, {dict} [, {action}]) *settagstack()*
10155 Modify the tag stack of the window {nr} using {dict}.
10156 {nr} can be the window number or the |window-ID|.
10157
10158 For a list of supported items in {dict}, refer to
10159 |gettagstack()|. "curidx" takes effect before changing the tag
10160 stack.
10161 *E962*
10162 How the tag stack is modified depends on the {action}
10163 argument:
10164 - If {action} is not present or is set to 'r', then the tag
10165 stack is replaced.
10166 - If {action} is set to 'a', then new entries from {dict} are
10167 pushed (added) onto the tag stack.
10168 - If {action} is set to 't', then all the entries from the
10169 current entry in the tag stack or "curidx" in {dict} are
10170 removed and then new entries are pushed to the stack.
10171
10172 The current index is set to one after the length of the tag
10173 stack after the modification.
10174
10175 Returns zero for success, -1 for failure.
10176
10177 Examples (for more examples see |tagstack-examples|):
10178 Empty the tag stack of window 3: >
10179 call settagstack(3, {'items' : []})
10180
10181< Save and restore the tag stack: >
10182 let stack = gettagstack(1003)
10183 " do something else
10184 call settagstack(1003, stack)
10185 unlet stack
10186<
10187 Can also be used as a |method|, the base is passed as the
10188 second argument: >
10189 GetStack()->settagstack(winnr)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010190<
10191 Return type: |Number|
10192
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010193
10194setwinvar({winnr}, {varname}, {val}) *setwinvar()*
10195 Like |settabwinvar()| for the current tab page.
10196 Examples: >
10197 :call setwinvar(1, "&list", 0)
10198 :call setwinvar(2, "myvar", "foobar")
10199
10200< Can also be used as a |method|, the base is passed as the
10201 third argument: >
10202 GetValue()->setwinvar(winnr, name)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010203<
10204 Return type: |Number|
10205
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010206
10207sha256({string}) *sha256()*
10208 Returns a String with 64 hex characters, which is the SHA256
10209 checksum of {string}.
10210
10211 Can also be used as a |method|: >
10212 GetText()->sha256()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010213<
10214 Return type: |String|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010215
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010216 {only available when compiled with the |+cryptv| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010217
10218shellescape({string} [, {special}]) *shellescape()*
10219 Escape {string} for use as a shell command argument.
10220 When the 'shell' contains powershell (MS-Windows) or pwsh
Bram Moolenaar944697a2022-02-20 19:48:20 +000010221 (MS-Windows, Linux, and macOS) then it will enclose {string}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010222 in single quotes and will double up all internal single
10223 quotes.
10224 On MS-Windows, when 'shellslash' is not set, it will enclose
10225 {string} in double quotes and double all double quotes within
10226 {string}.
10227 Otherwise it will enclose {string} in single quotes and
10228 replace all "'" with "'\''".
10229
Enno5faeb602024-05-15 21:54:19 +020010230 The {special} argument adds additional escaping of keywords
10231 used in Vim commands. When it is not omitted and a non-zero
K.Takatac0e038b2024-05-16 12:39:01 +090010232 number or a non-empty String (|non-zero-arg|), then special
10233 items such as "!", "%", "#" and "<cword>" (as listed in
10234 |expand()|) will be preceded by a backslash.
Enno5faeb602024-05-15 21:54:19 +020010235 This backslash will be removed again by the |:!| command.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010236
10237 The "!" character will be escaped (again with a |non-zero-arg|
10238 {special}) when 'shell' contains "csh" in the tail. That is
10239 because for csh and tcsh "!" is used for history replacement
10240 even when inside single quotes.
10241
10242 With a |non-zero-arg| {special} the <NL> character is also
10243 escaped. When 'shell' containing "csh" in the tail it's
10244 escaped a second time.
10245
10246 The "\" character will be escaped when 'shell' contains "fish"
10247 in the tail. That is because for fish "\" is used as an escape
10248 character inside single quotes.
10249
10250 Example of use with a |:!| command: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +000010251 :exe '!dir ' .. shellescape(expand('<cfile>'), 1)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010252< This results in a directory listing for the file under the
10253 cursor. Example of use with |system()|: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +000010254 :call system("chmod +w -- " .. shellescape(expand("%")))
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010255< See also |::S|.
10256
10257 Can also be used as a |method|: >
10258 GetCommand()->shellescape()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010259<
10260 Return type: |String|
10261
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010262
10263shiftwidth([{col}]) *shiftwidth()*
10264 Returns the effective value of 'shiftwidth'. This is the
10265 'shiftwidth' value unless it is zero, in which case it is the
10266 'tabstop' value. This function was introduced with patch
10267 7.3.694 in 2012, everybody should have it by now (however it
10268 did not allow for the optional {col} argument until 8.1.542).
10269
10270 When there is one argument {col} this is used as column number
10271 for which to return the 'shiftwidth' value. This matters for the
10272 'vartabstop' feature. If the 'vartabstop' setting is enabled and
10273 no {col} argument is given, column 1 will be assumed.
10274
10275 Can also be used as a |method|: >
10276 GetColumn()->shiftwidth()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010277<
10278 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010279
10280sign_ functions are documented here: |sign-functions-details|
10281
10282
10283simplify({filename}) *simplify()*
10284 Simplify the file name as much as possible without changing
10285 the meaning. Shortcuts (on MS-Windows) or symbolic links (on
10286 Unix) are not resolved. If the first path component in
10287 {filename} designates the current directory, this will be
10288 valid for the result as well. A trailing path separator is
10289 not removed either. On Unix "//path" is unchanged, but
10290 "///path" is simplified to "/path" (this follows the Posix
10291 standard).
10292 Example: >
10293 simplify("./dir/.././/file/") == "./file/"
10294< Note: The combination "dir/.." is only removed if "dir" is
10295 a searchable directory or does not exist. On Unix, it is also
10296 removed when "dir" is a symbolic link within the same
10297 directory. In order to resolve all the involved symbolic
10298 links before simplifying the path name, use |resolve()|.
10299
10300 Can also be used as a |method|: >
10301 GetName()->simplify()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010302<
10303 Return type: |String|
10304
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010305
10306sin({expr}) *sin()*
10307 Return the sine of {expr}, measured in radians, as a |Float|.
10308 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +010010309 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010310 Examples: >
10311 :echo sin(100)
10312< -0.506366 >
10313 :echo sin(-4.01)
10314< 0.763301
10315
10316 Can also be used as a |method|: >
10317 Compute()->sin()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010318<
10319 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010320
10321
10322sinh({expr}) *sinh()*
10323 Return the hyperbolic sine of {expr} as a |Float| in the range
10324 [-inf, inf].
10325 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +010010326 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010327 Examples: >
10328 :echo sinh(0.5)
10329< 0.521095 >
10330 :echo sinh(-0.9)
10331< -1.026517
10332
10333 Can also be used as a |method|: >
10334 Compute()->sinh()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010335<
10336 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010337
10338
10339slice({expr}, {start} [, {end}]) *slice()*
10340 Similar to using a |slice| "expr[start : end]", but "end" is
10341 used exclusive. And for a string the indexes are used as
10342 character indexes instead of byte indexes, like in
zeertzjqad387692024-03-23 08:23:48 +010010343 |vim9script|. Also, composing characters are treated as a
10344 part of the preceding base character.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010345 When {end} is omitted the slice continues to the last item.
10346 When {end} is -1 the last item is omitted.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +010010347 Returns an empty value if {start} or {end} are invalid.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010348
10349 Can also be used as a |method|: >
10350 GetList()->slice(offset)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010351<
Yegappan Lakshmanan9cb865e2025-03-23 16:42:16 +010010352 Return type: list<{type}> or tuple<{type}>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010353
10354
Bram Moolenaar2007dd42022-02-23 13:17:47 +000010355sort({list} [, {how} [, {dict}]]) *sort()* *E702*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010356 Sort the items in {list} in-place. Returns {list}.
10357
10358 If you want a list to remain unmodified make a copy first: >
10359 :let sortedlist = sort(copy(mylist))
10360
Bram Moolenaar2d8ed022022-05-21 13:08:16 +010010361< When {how} is omitted or is a string, then sort() uses the
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010362 string representation of each item to sort on. Numbers sort
10363 after Strings, |Lists| after Numbers. For sorting text in the
10364 current buffer use |:sort|.
10365
Bram Moolenaar2007dd42022-02-23 13:17:47 +000010366 When {how} is given and it is 'i' then case is ignored.
10367 In legacy script, for backwards compatibility, the value one
10368 can be used to ignore case. Zero means to not ignore case.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010369
Bram Moolenaar2007dd42022-02-23 13:17:47 +000010370 When {how} is given and it is 'l' then the current collation
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010371 locale is used for ordering. Implementation details: strcoll()
10372 is used to compare strings. See |:language| check or set the
10373 collation locale. |v:collate| can also be used to check the
10374 current locale. Sorting using the locale typically ignores
10375 case. Example: >
10376 " ö is sorted similarly to o with English locale.
10377 :language collate en_US.UTF8
10378 :echo sort(['n', 'o', 'O', 'ö', 'p', 'z'], 'l')
10379< ['n', 'o', 'O', 'ö', 'p', 'z'] ~
10380>
10381 " ö is sorted after z with Swedish locale.
10382 :language collate sv_SE.UTF8
10383 :echo sort(['n', 'o', 'O', 'ö', 'p', 'z'], 'l')
10384< ['n', 'o', 'O', 'p', 'z', 'ö'] ~
10385 This does not work properly on Mac.
10386
Bram Moolenaar2007dd42022-02-23 13:17:47 +000010387 When {how} is given and it is 'n' then all items will be
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010388 sorted numerical (Implementation detail: this uses the
Bram Moolenaarbe19d782023-03-09 22:06:49 +000010389 strtod() function to parse numbers. Strings, Lists, Dicts and
10390 Funcrefs will be considered as being 0). Note that this won't
10391 sort a list of strings with numbers!
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010392
Bram Moolenaar2007dd42022-02-23 13:17:47 +000010393 When {how} is given and it is 'N' then all items will be
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010394 sorted numerical. This is like 'n' but a string containing
10395 digits will be used as the number they represent.
10396
Bram Moolenaar2007dd42022-02-23 13:17:47 +000010397 When {how} is given and it is 'f' then all items will be
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010398 sorted numerical. All values must be a Number or a Float.
10399
Bram Moolenaar2007dd42022-02-23 13:17:47 +000010400 When {how} is a |Funcref| or a function name, this function
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010401 is called to compare items. The function is invoked with two
10402 items as argument and must return zero if they are equal, 1 or
10403 bigger if the first one sorts after the second one, -1 or
10404 smaller if the first one sorts before the second one.
10405
10406 {dict} is for functions with the "dict" attribute. It will be
10407 used to set the local variable "self". |Dictionary-function|
10408
10409 The sort is stable, items which compare equal (as number or as
10410 string) will keep their relative position. E.g., when sorting
10411 on numbers, text strings will sort next to each other, in the
10412 same order as they were originally.
10413
10414 Can also be used as a |method|: >
10415 mylist->sort()
10416
10417< Also see |uniq()|.
10418
10419 Example: >
10420 func MyCompare(i1, i2)
10421 return a:i1 == a:i2 ? 0 : a:i1 > a:i2 ? 1 : -1
10422 endfunc
10423 eval mylist->sort("MyCompare")
10424< A shorter compare version for this specific simple case, which
10425 ignores overflow: >
10426 func MyCompare(i1, i2)
10427 return a:i1 - a:i2
10428 endfunc
10429< For a simple expression you can use a lambda: >
10430 eval mylist->sort({i1, i2 -> i1 - i2})
10431<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010432 Return type: list<{type}>
10433
10434
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010435sound_clear() *sound_clear()*
10436 Stop playing all sounds.
10437
10438 On some Linux systems you may need the libcanberra-pulse
10439 package, otherwise sound may not stop.
10440
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010441 Return type: |Number|
10442
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010443 {only available when compiled with the |+sound| feature}
10444
10445 *sound_playevent()*
10446sound_playevent({name} [, {callback}])
10447 Play a sound identified by {name}. Which event names are
10448 supported depends on the system. Often the XDG sound names
10449 are used. On Ubuntu they may be found in
10450 /usr/share/sounds/freedesktop/stereo. Example: >
10451 call sound_playevent('bell')
10452< On MS-Windows, {name} can be SystemAsterisk, SystemDefault,
10453 SystemExclamation, SystemExit, SystemHand, SystemQuestion,
10454 SystemStart, SystemWelcome, etc.
Yee Cheng Chin4314e4f2022-10-08 13:50:05 +010010455 On macOS, {name} refers to files located in
10456 /System/Library/Sounds (e.g. "Tink"). It will also work for
10457 custom installed sounds in folders like ~/Library/Sounds.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010458
10459 When {callback} is specified it is invoked when the sound is
10460 finished. The first argument is the sound ID, the second
10461 argument is the status:
10462 0 sound was played to the end
10463 1 sound was interrupted
10464 2 error occurred after sound started
10465 Example: >
10466 func Callback(id, status)
10467 echomsg "sound " .. a:id .. " finished with " .. a:status
10468 endfunc
10469 call sound_playevent('bell', 'Callback')
10470
10471< MS-Windows: {callback} doesn't work for this function.
10472
10473 Returns the sound ID, which can be passed to `sound_stop()`.
10474 Returns zero if the sound could not be played.
10475
10476 Can also be used as a |method|: >
10477 GetSoundName()->sound_playevent()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010478<
10479 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010480
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010481 {only available when compiled with the |+sound| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010482
10483 *sound_playfile()*
10484sound_playfile({path} [, {callback}])
10485 Like `sound_playevent()` but play sound file {path}. {path}
10486 must be a full path. On Ubuntu you may find files to play
10487 with this command: >
10488 :!find /usr/share/sounds -type f | grep -v index.theme
10489
10490< Can also be used as a |method|: >
10491 GetSoundPath()->sound_playfile()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010492<
10493 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010494
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010495 {only available when compiled with the |+sound| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010496
10497
10498sound_stop({id}) *sound_stop()*
10499 Stop playing sound {id}. {id} must be previously returned by
10500 `sound_playevent()` or `sound_playfile()`.
10501
10502 On some Linux systems you may need the libcanberra-pulse
10503 package, otherwise sound may not stop.
10504
10505 On MS-Windows, this does not work for event sound started by
10506 `sound_playevent()`. To stop event sounds, use `sound_clear()`.
10507
10508 Can also be used as a |method|: >
10509 soundid->sound_stop()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010510<
10511 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010512
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010513 {only available when compiled with the |+sound| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010514
10515 *soundfold()*
10516soundfold({word})
10517 Return the sound-folded equivalent of {word}. Uses the first
10518 language in 'spelllang' for the current window that supports
10519 soundfolding. 'spell' must be set. When no sound folding is
10520 possible the {word} is returned unmodified.
10521 This can be used for making spelling suggestions. Note that
10522 the method can be quite slow.
10523
10524 Can also be used as a |method|: >
10525 GetWord()->soundfold()
10526<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010527 Return type: |String|
10528
10529
10530spellbadword([{sentence}]) *spellbadword()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010531 Without argument: The result is the badly spelled word under
10532 or after the cursor. The cursor is moved to the start of the
10533 bad word. When no bad word is found in the cursor line the
10534 result is an empty string and the cursor doesn't move.
10535
10536 With argument: The result is the first word in {sentence} that
10537 is badly spelled. If there are no spelling mistakes the
10538 result is an empty string.
10539
10540 The return value is a list with two items:
10541 - The badly spelled word or an empty string.
10542 - The type of the spelling error:
10543 "bad" spelling mistake
10544 "rare" rare word
10545 "local" word only valid in another region
10546 "caps" word should start with Capital
10547 Example: >
10548 echo spellbadword("the quik brown fox")
10549< ['quik', 'bad'] ~
10550
10551 The spelling information for the current window and the value
10552 of 'spelllang' are used.
10553
10554 Can also be used as a |method|: >
10555 GetText()->spellbadword()
10556<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010557 Return type: list<string>
10558
10559
10560spellsuggest({word} [, {max} [, {capital}]]) *spellsuggest()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010561 Return a |List| with spelling suggestions to replace {word}.
10562 When {max} is given up to this number of suggestions are
10563 returned. Otherwise up to 25 suggestions are returned.
10564
10565 When the {capital} argument is given and it's non-zero only
10566 suggestions with a leading capital will be given. Use this
10567 after a match with 'spellcapcheck'.
10568
10569 {word} can be a badly spelled word followed by other text.
10570 This allows for joining two words that were split. The
10571 suggestions also include the following text, thus you can
10572 replace a line.
10573
10574 {word} may also be a good word. Similar words will then be
10575 returned. {word} itself is not included in the suggestions,
10576 although it may appear capitalized.
10577
10578 The spelling information for the current window is used. The
10579 values of 'spelllang' and 'spellsuggest' are used.
10580
10581 Can also be used as a |method|: >
10582 GetWord()->spellsuggest()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010583<
10584 Return type: list<string> or list<any>
10585
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010586
10587split({string} [, {pattern} [, {keepempty}]]) *split()*
10588 Make a |List| out of {string}. When {pattern} is omitted or
Shane Harperc1b39842024-07-17 19:40:40 +020010589 empty each white space separated sequence of characters
10590 becomes an item.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010591 Otherwise the string is split where {pattern} matches,
10592 removing the matched characters. 'ignorecase' is not used
10593 here, add \c to ignore case. |/\c|
10594 When the first or last item is empty it is omitted, unless the
10595 {keepempty} argument is given and it's non-zero.
10596 Other empty items are kept when {pattern} matches at least one
10597 character or when {keepempty} is non-zero.
10598 Example: >
10599 :let words = split(getline('.'), '\W\+')
10600< To split a string in individual characters: >
10601 :for c in split(mystring, '\zs')
10602< If you want to keep the separator you can also use '\zs' at
10603 the end of the pattern: >
10604 :echo split('abc:def:ghi', ':\zs')
10605< ['abc:', 'def:', 'ghi'] ~
10606 Splitting a table where the first element can be empty: >
10607 :let items = split(line, ':', 1)
10608< The opposite function is |join()|.
10609
10610 Can also be used as a |method|: >
10611 GetString()->split()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010612<
10613 Return type: list<string>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010614
10615sqrt({expr}) *sqrt()*
10616 Return the non-negative square root of Float {expr} as a
10617 |Float|.
10618 {expr} must evaluate to a |Float| or a |Number|. When {expr}
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +010010619 is negative the result is NaN (Not a Number). Returns 0.0 if
10620 {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010621 Examples: >
10622 :echo sqrt(100)
10623< 10.0 >
10624 :echo sqrt(-4.01)
10625< nan
10626 "nan" may be different, it depends on system libraries.
10627
10628 Can also be used as a |method|: >
10629 Compute()->sqrt()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010630<
10631 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010632
10633
10634srand([{expr}]) *srand()*
10635 Initialize seed used by |rand()|:
10636 - If {expr} is not given, seed values are initialized by
10637 reading from /dev/urandom, if possible, or using time(NULL)
10638 a.k.a. epoch time otherwise; this only has second accuracy.
10639 - If {expr} is given it must be a Number. It is used to
10640 initialize the seed values. This is useful for testing or
10641 when a predictable sequence is intended.
10642
10643 Examples: >
10644 :let seed = srand()
10645 :let seed = srand(userinput)
10646 :echo rand(seed)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010647<
10648 Return type: list<number>
10649
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010650
10651state([{what}]) *state()*
10652 Return a string which contains characters indicating the
10653 current state. Mostly useful in callbacks that want to do
10654 work that may not always be safe. Roughly this works like:
10655 - callback uses state() to check if work is safe to do.
10656 Yes: then do it right away.
10657 No: add to work queue and add a |SafeState| and/or
10658 |SafeStateAgain| autocommand (|SafeState| triggers at
10659 toplevel, |SafeStateAgain| triggers after handling
10660 messages and callbacks).
10661 - When SafeState or SafeStateAgain is triggered and executes
10662 your autocommand, check with `state()` if the work can be
10663 done now, and if yes remove it from the queue and execute.
10664 Remove the autocommand if the queue is now empty.
10665 Also see |mode()|.
10666
10667 When {what} is given only characters in this string will be
10668 added. E.g, this checks if the screen has scrolled: >
10669 if state('s') == ''
10670 " screen has not scrolled
10671<
10672 These characters indicate the state, generally indicating that
10673 something is busy:
10674 m halfway a mapping, :normal command, feedkeys() or
10675 stuffed command
10676 o operator pending, e.g. after |d|
10677 a Insert mode autocomplete active
10678 x executing an autocommand
10679 w blocked on waiting, e.g. ch_evalexpr(), ch_read() and
10680 ch_readraw() when reading json
10681 S not triggering SafeState or SafeStateAgain, e.g. after
10682 |f| or a count
10683 c callback invoked, including timer (repeats for
10684 recursiveness up to "ccc")
10685 s screen has scrolled for messages
10686
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010687 Return type: |String|
10688
10689
Yegappan Lakshmanana11b23c2025-01-16 19:16:42 +010010690str2blob({list} [, {options}]) *str2blob()*
10691 Return a Blob by converting the characters in the List of
10692 strings in {list} into bytes.
10693
10694 A <NL> byte is added to the blob after each list item. A
10695 newline character in the string is translated into a <NUL>
10696 byte in the blob.
Yegappan Lakshmanan1aefe1d2025-01-14 17:29:42 +010010697
10698 If {options} is not supplied, the current 'encoding' value is
Yegappan Lakshmanana11b23c2025-01-16 19:16:42 +010010699 used to convert the characters into bytes.
Yegappan Lakshmanan1aefe1d2025-01-14 17:29:42 +010010700
10701 The argument {options} is a |Dict| and supports the following
10702 items:
Bakudankunb3854bf2025-02-23 20:29:21 +010010703 encoding Convert the characters using this encoding
10704 before making the Blob.
Yegappan Lakshmanana11b23c2025-01-16 19:16:42 +010010705 The value is a |String|. See |encoding-names|
10706 for the supported values.
Yegappan Lakshmanan1aefe1d2025-01-14 17:29:42 +010010707
10708 An error is given and an empty blob is returned if the
10709 character encoding fails.
10710
Yegappan Lakshmanana11b23c2025-01-16 19:16:42 +010010711 Returns an empty Blob if {list} is empty.
Yegappan Lakshmanan1aefe1d2025-01-14 17:29:42 +010010712
10713 See also |blob2str()|
10714
10715 Examples: >
Hirohito Higashi932a5352025-03-23 10:20:20 +010010716 str2blob(["ab"]) returns 0z6162
10717 str2blob(["«»"]) returns 0zC2ABC2BB
10718 str2blob(["a\nb"]) returns 0z610062
10719 str2blob(["a","b"]) returns 0z610A62
Yegappan Lakshmanana11b23c2025-01-16 19:16:42 +010010720 str2blob(["«»"], {'encoding': 'latin1'}) returns 0zABBB
Hirohito Higashi932a5352025-03-23 10:20:20 +010010721 str2blob(readfile('myfile.txt'))
Yegappan Lakshmanan1aefe1d2025-01-14 17:29:42 +010010722<
10723 Can also be used as a |method|: >
Yegappan Lakshmanana11b23c2025-01-16 19:16:42 +010010724 GetListOfStrings()->str2blob()
Yegappan Lakshmanan1aefe1d2025-01-14 17:29:42 +010010725<
10726 Return type: |Blob|
10727
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010728str2float({string} [, {quoted}]) *str2float()*
10729 Convert String {string} to a Float. This mostly works the
10730 same as when using a floating point number in an expression,
10731 see |floating-point-format|. But it's a bit more permissive.
10732 E.g., "1e40" is accepted, while in an expression you need to
10733 write "1.0e40". The hexadecimal form "0x123" is also
10734 accepted, but not others, like binary or octal.
10735 When {quoted} is present and non-zero then embedded single
10736 quotes before the dot are ignored, thus "1'000.0" is a
10737 thousand.
10738 Text after the number is silently ignored.
10739 The decimal point is always '.', no matter what the locale is
10740 set to. A comma ends the number: "12,345.67" is converted to
10741 12.0. You can strip out thousands separators with
10742 |substitute()|: >
10743 let f = str2float(substitute(text, ',', '', 'g'))
10744<
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +010010745 Returns 0.0 if the conversion fails.
10746
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010747 Can also be used as a |method|: >
10748 let f = text->substitute(',', '', 'g')->str2float()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010749<
10750 Return type: |Float|
10751
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010752
10753str2list({string} [, {utf8}]) *str2list()*
10754 Return a list containing the number values which represent
10755 each character in String {string}. Examples: >
10756 str2list(" ") returns [32]
10757 str2list("ABC") returns [65, 66, 67]
10758< |list2str()| does the opposite.
10759
10760 When {utf8} is omitted or zero, the current 'encoding' is used.
10761 When {utf8} is TRUE, always treat the String as UTF-8
10762 characters. With UTF-8 composing characters are handled
10763 properly: >
10764 str2list("á") returns [97, 769]
10765
10766< Can also be used as a |method|: >
10767 GetString()->str2list()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010768<
10769 Return type: list<number>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010770
10771
10772str2nr({string} [, {base} [, {quoted}]]) *str2nr()*
10773 Convert string {string} to a number.
10774 {base} is the conversion base, it can be 2, 8, 10 or 16.
10775 When {quoted} is present and non-zero then embedded single
10776 quotes are ignored, thus "1'000'000" is a million.
10777
10778 When {base} is omitted base 10 is used. This also means that
10779 a leading zero doesn't cause octal conversion to be used, as
10780 with the default String to Number conversion. Example: >
10781 let nr = str2nr('0123')
10782<
10783 When {base} is 16 a leading "0x" or "0X" is ignored. With a
10784 different base the result will be zero. Similarly, when
10785 {base} is 8 a leading "0", "0o" or "0O" is ignored, and when
10786 {base} is 2 a leading "0b" or "0B" is ignored.
10787 Text after the number is silently ignored.
10788
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +010010789 Returns 0 if {string} is empty or on error.
10790
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010791 Can also be used as a |method|: >
10792 GetText()->str2nr()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010793<
10794 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010795
10796
10797strcharlen({string}) *strcharlen()*
10798 The result is a Number, which is the number of characters
10799 in String {string}. Composing characters are ignored.
10800 |strchars()| can count the number of characters, counting
10801 composing characters separately.
10802
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +010010803 Returns 0 if {string} is empty or on error.
10804
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010805 Also see |strlen()|, |strdisplaywidth()| and |strwidth()|.
10806
10807 Can also be used as a |method|: >
10808 GetText()->strcharlen()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010809<
10810 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010811
10812
10813strcharpart({src}, {start} [, {len} [, {skipcc}]]) *strcharpart()*
10814 Like |strpart()| but using character index and length instead
10815 of byte index and length.
10816 When {skipcc} is omitted or zero, composing characters are
10817 counted separately.
zeertzjqad387692024-03-23 08:23:48 +010010818 When {skipcc} set to 1, composing characters are treated as a
10819 part of the preceding base character, similar to |slice()|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010820 When a character index is used where a character does not
10821 exist it is omitted and counted as one character. For
10822 example: >
10823 strcharpart('abc', -1, 2)
10824< results in 'a'.
10825
Bram Moolenaard592deb2022-06-17 15:42:40 +010010826 Returns an empty string on error.
10827
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010828 Can also be used as a |method|: >
10829 GetText()->strcharpart(5)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010830<
10831 Return type: |String|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010832
10833
10834strchars({string} [, {skipcc}]) *strchars()*
10835 The result is a Number, which is the number of characters
10836 in String {string}.
10837 When {skipcc} is omitted or zero, composing characters are
10838 counted separately.
zeertzjqad387692024-03-23 08:23:48 +010010839 When {skipcc} set to 1, composing characters are ignored.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010840 |strcharlen()| always does this.
10841
Bram Moolenaard592deb2022-06-17 15:42:40 +010010842 Returns zero on error.
10843
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010844 Also see |strlen()|, |strdisplaywidth()| and |strwidth()|.
10845
10846 {skipcc} is only available after 7.4.755. For backward
10847 compatibility, you can define a wrapper function: >
10848 if has("patch-7.4.755")
10849 function s:strchars(str, skipcc)
10850 return strchars(a:str, a:skipcc)
10851 endfunction
10852 else
10853 function s:strchars(str, skipcc)
10854 if a:skipcc
10855 return strlen(substitute(a:str, ".", "x", "g"))
10856 else
10857 return strchars(a:str)
10858 endif
10859 endfunction
10860 endif
10861<
10862 Can also be used as a |method|: >
10863 GetText()->strchars()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010864<
10865 Return type: |Number|
10866
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010867
10868strdisplaywidth({string} [, {col}]) *strdisplaywidth()*
10869 The result is a Number, which is the number of display cells
10870 String {string} occupies on the screen when it starts at {col}
10871 (first column is zero). When {col} is omitted zero is used.
10872 Otherwise it is the screen column where to start. This
10873 matters for Tab characters.
10874 The option settings of the current window are used. This
10875 matters for anything that's displayed differently, such as
10876 'tabstop' and 'display'.
10877 When {string} contains characters with East Asian Width Class
10878 Ambiguous, this function's return value depends on 'ambiwidth'.
Bram Moolenaard592deb2022-06-17 15:42:40 +010010879 Returns zero on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010880 Also see |strlen()|, |strwidth()| and |strchars()|.
10881
10882 Can also be used as a |method|: >
10883 GetText()->strdisplaywidth()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010884<
10885 Return type: |Number|
10886
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010887
10888strftime({format} [, {time}]) *strftime()*
10889 The result is a String, which is a formatted date and time, as
10890 specified by the {format} string. The given {time} is used,
10891 or the current time if no time is given. The accepted
10892 {format} depends on your system, thus this is not portable!
10893 See the manual page of the C function strftime() for the
10894 format. The maximum length of the result is 80 characters.
10895 See also |localtime()|, |getftime()| and |strptime()|.
10896 The language can be changed with the |:language| command.
10897 Examples: >
10898 :echo strftime("%c") Sun Apr 27 11:49:23 1997
10899 :echo strftime("%Y %b %d %X") 1997 Apr 27 11:53:25
10900 :echo strftime("%y%m%d %T") 970427 11:53:55
10901 :echo strftime("%H:%M") 11:55
10902 :echo strftime("%c", getftime("file.c"))
10903 Show mod time of file.c.
10904< Not available on all systems. To check use: >
10905 :if exists("*strftime")
10906
10907< Can also be used as a |method|: >
10908 GetFormat()->strftime()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010909<
10910 Return type: |String|
10911
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010912
10913strgetchar({str}, {index}) *strgetchar()*
Bram Moolenaar2d8ed022022-05-21 13:08:16 +010010914 Get a Number corresponding to the character at {index} in
10915 {str}. This uses a zero-based character index, not a byte
10916 index. Composing characters are considered separate
10917 characters here. Use |nr2char()| to convert the Number to a
10918 String.
Bram Moolenaard592deb2022-06-17 15:42:40 +010010919 Returns -1 if {index} is invalid.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010920 Also see |strcharpart()| and |strchars()|.
10921
10922 Can also be used as a |method|: >
10923 GetText()->strgetchar(5)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010924<
10925 Return type: |Number|
10926
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010927
10928stridx({haystack}, {needle} [, {start}]) *stridx()*
10929 The result is a Number, which gives the byte index in
10930 {haystack} of the first occurrence of the String {needle}.
10931 If {start} is specified, the search starts at index {start}.
10932 This can be used to find a second match: >
10933 :let colon1 = stridx(line, ":")
10934 :let colon2 = stridx(line, ":", colon1 + 1)
10935< The search is done case-sensitive.
10936 For pattern searches use |match()|.
10937 -1 is returned if the {needle} does not occur in {haystack}.
10938 See also |strridx()|.
10939 Examples: >
10940 :echo stridx("An Example", "Example") 3
10941 :echo stridx("Starting point", "Start") 0
10942 :echo stridx("Starting point", "start") -1
10943< *strstr()* *strchr()*
10944 stridx() works similar to the C function strstr(). When used
10945 with a single character it works similar to strchr().
10946
10947 Can also be used as a |method|: >
10948 GetHaystack()->stridx(needle)
10949<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010950 Return type: |Number|
10951
10952
10953string({expr}) *string()*
10954 Return {expr} converted to a String. If {expr} is a Number,
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010955 Float, String, Blob or a composition of them, then the result
10956 can be parsed back with |eval()|.
10957 {expr} type result ~
10958 String 'string' (single quotes are doubled)
10959 Number 123
10960 Float 123.123456 or 1.123456e8
10961 Funcref function('name')
10962 Blob 0z00112233.44556677.8899
10963 List [item, item]
Yegappan Lakshmanan9cb865e2025-03-23 16:42:16 +010010964 Tuple (item, item)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010965 Dictionary {key: value, key: value}
Bram Moolenaarf1dcd142022-12-31 15:30:45 +000010966 Class class SomeName
10967 Object object of SomeName {lnum: 1, col: 3}
Yegappan Lakshmanan3164cf82024-03-28 10:36:42 +010010968 Enum enum EnumName
Yegappan Lakshmanan3cf121e2024-03-31 18:45:35 +020010969 EnumValue enum name.value {name: str, ordinal: nr}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010970
Yegappan Lakshmanan9cb865e2025-03-23 16:42:16 +010010971 When a |List|, |Tuple| or |Dictionary| has a recursive
10972 reference it is replaced by "[...]" or "(...)" or "{...}".
10973 Using eval() on the result will then fail.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010974
mityu7f0bba22024-03-29 10:14:41 +010010975 For an object, invokes the string() method to get a textual
Yegappan Lakshmanand3eae7b2024-03-03 16:26:58 +010010976 representation of the object. If the method is not present,
mityu7f0bba22024-03-29 10:14:41 +010010977 then the default representation is used. |object-string()|
Yegappan Lakshmanand3eae7b2024-03-03 16:26:58 +010010978
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010979 Can also be used as a |method|: >
10980 mylist->string()
10981
10982< Also see |strtrans()|.
10983
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010984 Return type: |String|
10985
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010986
10987strlen({string}) *strlen()*
10988 The result is a Number, which is the length of the String
10989 {string} in bytes.
10990 If the argument is a Number it is first converted to a String.
Bram Moolenaard592deb2022-06-17 15:42:40 +010010991 For other types an error is given and zero is returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010992 If you want to count the number of multibyte characters use
10993 |strchars()|.
10994 Also see |len()|, |strdisplaywidth()| and |strwidth()|.
10995
10996 Can also be used as a |method|: >
10997 GetString()->strlen()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010998<
10999 Return type: |Number|
11000
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011001
11002strpart({src}, {start} [, {len} [, {chars}]]) *strpart()*
11003 The result is a String, which is part of {src}, starting from
11004 byte {start}, with the byte length {len}.
11005 When {chars} is present and TRUE then {len} is the number of
11006 characters positions (composing characters are not counted
11007 separately, thus "1" means one base character and any
11008 following composing characters).
11009 To count {start} as characters instead of bytes use
11010 |strcharpart()|.
11011
11012 When bytes are selected which do not exist, this doesn't
11013 result in an error, the bytes are simply omitted.
11014 If {len} is missing, the copy continues from {start} till the
11015 end of the {src}. >
11016 strpart("abcdefg", 3, 2) == "de"
11017 strpart("abcdefg", -2, 4) == "ab"
11018 strpart("abcdefg", 5, 4) == "fg"
11019 strpart("abcdefg", 3) == "defg"
11020
11021< Note: To get the first character, {start} must be 0. For
11022 example, to get the character under the cursor: >
11023 strpart(getline("."), col(".") - 1, 1, v:true)
11024<
Bram Moolenaard592deb2022-06-17 15:42:40 +010011025 Returns an empty string on error.
11026
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011027 Can also be used as a |method|: >
11028 GetText()->strpart(5)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011029<
11030 Return type: |String|
11031
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011032
11033strptime({format}, {timestring}) *strptime()*
11034 The result is a Number, which is a unix timestamp representing
11035 the date and time in {timestring}, which is expected to match
11036 the format specified in {format}.
11037
11038 The accepted {format} depends on your system, thus this is not
11039 portable! See the manual page of the C function strptime()
11040 for the format. Especially avoid "%c". The value of $TZ also
11041 matters.
11042
11043 If the {timestring} cannot be parsed with {format} zero is
11044 returned. If you do not know the format of {timestring} you
11045 can try different {format} values until you get a non-zero
11046 result.
11047
11048 See also |strftime()|.
11049 Examples: >
11050 :echo strptime("%Y %b %d %X", "1997 Apr 27 11:49:23")
11051< 862156163 >
11052 :echo strftime("%c", strptime("%y%m%d %T", "970427 11:53:55"))
11053< Sun Apr 27 11:53:55 1997 >
11054 :echo strftime("%c", strptime("%Y%m%d%H%M%S", "19970427115355") + 3600)
11055< Sun Apr 27 12:53:55 1997
11056
11057 Can also be used as a |method|: >
11058 GetFormat()->strptime(timestring)
11059<
11060 Not available on all systems. To check use: >
11061 :if exists("*strptime")
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011062<
11063 Return type: |Number|
11064
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011065
11066strridx({haystack}, {needle} [, {start}]) *strridx()*
11067 The result is a Number, which gives the byte index in
11068 {haystack} of the last occurrence of the String {needle}.
11069 When {start} is specified, matches beyond this index are
11070 ignored. This can be used to find a match before a previous
11071 match: >
11072 :let lastcomma = strridx(line, ",")
11073 :let comma2 = strridx(line, ",", lastcomma - 1)
11074< The search is done case-sensitive.
11075 For pattern searches use |match()|.
11076 -1 is returned if the {needle} does not occur in {haystack}.
11077 If the {needle} is empty the length of {haystack} is returned.
11078 See also |stridx()|. Examples: >
11079 :echo strridx("an angry armadillo", "an") 3
11080< *strrchr()*
11081 When used with a single character it works similar to the C
11082 function strrchr().
11083
11084 Can also be used as a |method|: >
11085 GetHaystack()->strridx(needle)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011086<
11087 Return type: |Number|
11088
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011089
11090strtrans({string}) *strtrans()*
11091 The result is a String, which is {string} with all unprintable
11092 characters translated into printable characters |'isprint'|.
11093 Like they are shown in a window. Example: >
11094 echo strtrans(@a)
11095< This displays a newline in register a as "^@" instead of
11096 starting a new line.
11097
Bram Moolenaard592deb2022-06-17 15:42:40 +010011098 Returns an empty string on error.
11099
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011100 Can also be used as a |method|: >
11101 GetString()->strtrans()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011102<
11103 Return type: |String|
11104
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011105
Christian Brabandt67672ef2023-04-24 21:09:54 +010011106strutf16len({string} [, {countcc}]) *strutf16len()*
11107 The result is a Number, which is the number of UTF-16 code
11108 units in String {string} (after converting it to UTF-16).
11109
11110 When {countcc} is TRUE, composing characters are counted
11111 separately.
11112 When {countcc} is omitted or FALSE, composing characters are
11113 ignored.
11114
11115 Returns zero on error.
11116
11117 Also see |strlen()| and |strcharlen()|.
11118 Examples: >
11119 echo strutf16len('a') returns 1
11120 echo strutf16len('©') returns 1
11121 echo strutf16len('😊') returns 2
11122 echo strutf16len('ą́') returns 1
11123 echo strutf16len('ą́', v:true) returns 3
a5ob7r790f9a82023-09-25 06:05:47 +090011124<
Christian Brabandt67672ef2023-04-24 21:09:54 +010011125 Can also be used as a |method|: >
11126 GetText()->strutf16len()
11127<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011128 Return type: |Number|
11129
11130
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011131strwidth({string}) *strwidth()*
11132 The result is a Number, which is the number of display cells
11133 String {string} occupies. A Tab character is counted as one
11134 cell, alternatively use |strdisplaywidth()|.
11135 When {string} contains characters with East Asian Width Class
11136 Ambiguous, this function's return value depends on 'ambiwidth'.
Bram Moolenaard592deb2022-06-17 15:42:40 +010011137 Returns zero on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011138 Also see |strlen()|, |strdisplaywidth()| and |strchars()|.
11139
11140 Can also be used as a |method|: >
11141 GetString()->strwidth()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011142<
11143 Return type: |Number|
11144
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011145
11146submatch({nr} [, {list}]) *submatch()* *E935*
11147 Only for an expression in a |:substitute| command or
11148 substitute() function.
11149 Returns the {nr}'th submatch of the matched text. When {nr}
11150 is 0 the whole matched text is returned.
11151 Note that a NL in the string can stand for a line break of a
11152 multi-line match or a NUL character in the text.
11153 Also see |sub-replace-expression|.
11154
11155 If {list} is present and non-zero then submatch() returns
11156 a list of strings, similar to |getline()| with two arguments.
11157 NL characters in the text represent NUL characters in the
11158 text.
11159 Only returns more than one item for |:substitute|, inside
11160 |substitute()| this list will always contain one or zero
11161 items, since there are no real line breaks.
11162
11163 When substitute() is used recursively only the submatches in
11164 the current (deepest) call can be obtained.
11165
Bram Moolenaard592deb2022-06-17 15:42:40 +010011166 Returns an empty string or list on error.
11167
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011168 Examples: >
11169 :s/\d\+/\=submatch(0) + 1/
11170 :echo substitute(text, '\d\+', '\=submatch(0) + 1', '')
11171< This finds the first number in the line and adds one to it.
11172 A line break is included as a newline character.
11173
11174 Can also be used as a |method|: >
11175 GetNr()->submatch()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011176<
11177 Return type: |String| or list<string> depending on {list}
11178
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011179
11180substitute({string}, {pat}, {sub}, {flags}) *substitute()*
11181 The result is a String, which is a copy of {string}, in which
11182 the first match of {pat} is replaced with {sub}.
11183 When {flags} is "g", all matches of {pat} in {string} are
11184 replaced. Otherwise {flags} should be "".
11185
11186 This works like the ":substitute" command (without any flags).
11187 But the matching with {pat} is always done like the 'magic'
11188 option is set and 'cpoptions' is empty (to make scripts
11189 portable). 'ignorecase' is still relevant, use |/\c| or |/\C|
11190 if you want to ignore or match case and ignore 'ignorecase'.
11191 'smartcase' is not used. See |string-match| for how {pat} is
11192 used.
11193
11194 A "~" in {sub} is not replaced with the previous {sub}.
11195 Note that some codes in {sub} have a special meaning
11196 |sub-replace-special|. For example, to replace something with
11197 "\n" (two characters), use "\\\\n" or '\\n'.
11198
11199 When {pat} does not match in {string}, {string} is returned
11200 unmodified.
11201
11202 Example: >
11203 :let &path = substitute(&path, ",\\=[^,]*$", "", "")
11204< This removes the last component of the 'path' option. >
11205 :echo substitute("testing", ".*", "\\U\\0", "")
11206< results in "TESTING".
11207
11208 When {sub} starts with "\=", the remainder is interpreted as
11209 an expression. See |sub-replace-expression|. Example: >
11210 :echo substitute(s, '%\(\x\x\)',
Bram Moolenaarc51cf032022-02-26 12:25:45 +000011211 \ '\=nr2char("0x" .. submatch(1))', 'g')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011212
11213< When {sub} is a Funcref that function is called, with one
11214 optional argument. Example: >
11215 :echo substitute(s, '%\(\x\x\)', SubNr, 'g')
11216< The optional argument is a list which contains the whole
11217 matched string and up to nine submatches, like what
11218 |submatch()| returns. Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +000011219 :echo substitute(s, '%\(\x\x\)', {m -> '0x' .. m[1]}, 'g')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011220
Bram Moolenaard592deb2022-06-17 15:42:40 +010011221< Returns an empty string on error.
11222
11223 Can also be used as a |method|: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011224 GetString()->substitute(pat, sub, flags)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011225<
11226 Return type: |String|
11227
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011228
Bram Moolenaarc216a7a2022-12-05 13:50:55 +000011229swapfilelist() *swapfilelist()*
11230 Returns a list of swap file names, like what "vim -r" shows.
11231 See the |-r| command argument. The 'directory' option is used
11232 for the directories to inspect. If you only want to get a
11233 list of swap files in the current directory then temporarily
11234 set 'directory' to a dot: >
11235 let save_dir = &directory
11236 let &directory = '.'
11237 let swapfiles = swapfilelist()
11238 let &directory = save_dir
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011239<
11240 Return type: list<string>
11241
Bram Moolenaarc216a7a2022-12-05 13:50:55 +000011242
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011243swapinfo({fname}) *swapinfo()*
11244 The result is a dictionary, which holds information about the
11245 swapfile {fname}. The available fields are:
11246 version Vim version
11247 user user name
11248 host host name
11249 fname original file name
11250 pid PID of the Vim process that created the swap
11251 file
11252 mtime last modification time in seconds
11253 inode Optional: INODE number of the file
11254 dirty 1 if file was modified, 0 if not
11255 Note that "user" and "host" are truncated to at most 39 bytes.
11256 In case of failure an "error" item is added with the reason:
11257 Cannot open file: file not found or in accessible
11258 Cannot read file: cannot read first block
11259 Not a swap file: does not contain correct block ID
11260 Magic number mismatch: Info in first block is invalid
11261
11262 Can also be used as a |method|: >
11263 GetFilename()->swapinfo()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011264<
11265 Return type: dict<any> or dict<string>
11266
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011267
11268swapname({buf}) *swapname()*
11269 The result is the swap file path of the buffer {expr}.
11270 For the use of {buf}, see |bufname()| above.
11271 If buffer {buf} is the current buffer, the result is equal to
11272 |:swapname| (unless there is no swap file).
11273 If buffer {buf} has no swap file, returns an empty string.
11274
11275 Can also be used as a |method|: >
11276 GetBufname()->swapname()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011277<
11278 Return type: |String|
11279
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011280
11281synID({lnum}, {col}, {trans}) *synID()*
11282 The result is a Number, which is the syntax ID at the position
11283 {lnum} and {col} in the current window.
11284 The syntax ID can be used with |synIDattr()| and
11285 |synIDtrans()| to obtain syntax information about text.
11286
11287 {col} is 1 for the leftmost column, {lnum} is 1 for the first
11288 line. 'synmaxcol' applies, in a longer line zero is returned.
11289 Note that when the position is after the last character,
11290 that's where the cursor can be in Insert mode, synID() returns
11291 zero. {lnum} is used like with |getline()|.
11292
11293 When {trans} is |TRUE|, transparent items are reduced to the
11294 item that they reveal. This is useful when wanting to know
11295 the effective color. When {trans} is |FALSE|, the transparent
11296 item is returned. This is useful when wanting to know which
11297 syntax item is effective (e.g. inside parens).
11298 Warning: This function can be very slow. Best speed is
11299 obtained by going through the file in forward direction.
11300
Bram Moolenaard592deb2022-06-17 15:42:40 +010011301 Returns zero on error.
11302
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011303 Example (echoes the name of the syntax item under the cursor): >
11304 :echo synIDattr(synID(line("."), col("."), 1), "name")
11305<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011306 Return type: |Number|
11307
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011308
11309synIDattr({synID}, {what} [, {mode}]) *synIDattr()*
11310 The result is a String, which is the {what} attribute of
11311 syntax ID {synID}. This can be used to obtain information
11312 about a syntax item.
11313 {mode} can be "gui", "cterm" or "term", to get the attributes
11314 for that mode. When {mode} is omitted, or an invalid value is
11315 used, the attributes for the currently active highlighting are
11316 used (GUI, cterm or term).
11317 Use synIDtrans() to follow linked highlight groups.
11318 {what} result
11319 "name" the name of the syntax item
11320 "fg" foreground color (GUI: color name used to set
11321 the color, cterm: color number as a string,
11322 term: empty string)
11323 "bg" background color (as with "fg")
11324 "font" font name (only available in the GUI)
11325 |highlight-font|
11326 "sp" special color for the GUI (as with "fg")
11327 |highlight-guisp|
11328 "ul" underline color for cterm: number as a string
11329 "fg#" like "fg", but for the GUI and the GUI is
11330 running the name in "#RRGGBB" form
11331 "bg#" like "fg#" for "bg"
11332 "sp#" like "fg#" for "sp"
11333 "bold" "1" if bold
11334 "italic" "1" if italic
11335 "reverse" "1" if reverse
11336 "inverse" "1" if inverse (= reverse)
11337 "standout" "1" if standout
11338 "underline" "1" if underlined
11339 "undercurl" "1" if undercurled
11340 "strike" "1" if strikethrough
Bram Moolenaarde786322022-07-30 14:56:17 +010011341 "nocombine" "1" if nocombine
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011342
Bram Moolenaard592deb2022-06-17 15:42:40 +010011343 Returns an empty string on error.
11344
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011345 Example (echoes the color of the syntax item under the
11346 cursor): >
11347 :echo synIDattr(synIDtrans(synID(line("."), col("."), 1)), "fg")
11348<
11349 Can also be used as a |method|: >
11350 :echo synID(line("."), col("."), 1)->synIDtrans()->synIDattr("fg")
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011351<
11352 Return type: |String|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011353
11354
11355synIDtrans({synID}) *synIDtrans()*
11356 The result is a Number, which is the translated syntax ID of
11357 {synID}. This is the syntax group ID of what is being used to
11358 highlight the character. Highlight links given with
11359 ":highlight link" are followed.
11360
Bram Moolenaard592deb2022-06-17 15:42:40 +010011361 Returns zero on error.
11362
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011363 Can also be used as a |method|: >
11364 :echo synID(line("."), col("."), 1)->synIDtrans()->synIDattr("fg")
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011365<
11366 Return type: |Number|
11367
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011368
11369synconcealed({lnum}, {col}) *synconcealed()*
11370 The result is a |List| with currently three items:
11371 1. The first item in the list is 0 if the character at the
11372 position {lnum} and {col} is not part of a concealable
11373 region, 1 if it is. {lnum} is used like with |getline()|.
11374 2. The second item in the list is a string. If the first item
11375 is 1, the second item contains the text which will be
11376 displayed in place of the concealed text, depending on the
11377 current setting of 'conceallevel' and 'listchars'.
11378 3. The third and final item in the list is a number
11379 representing the specific syntax region matched in the
11380 line. When the character is not concealed the value is
11381 zero. This allows detection of the beginning of a new
11382 concealable region if there are two consecutive regions
11383 with the same replacement character. For an example, if
11384 the text is "123456" and both "23" and "45" are concealed
11385 and replaced by the character "X", then:
11386 call returns ~
11387 synconcealed(lnum, 1) [0, '', 0]
11388 synconcealed(lnum, 2) [1, 'X', 1]
11389 synconcealed(lnum, 3) [1, 'X', 1]
11390 synconcealed(lnum, 4) [1, 'X', 2]
11391 synconcealed(lnum, 5) [1, 'X', 2]
11392 synconcealed(lnum, 6) [0, '', 0]
11393
Christian Brabandtfe1e2b52024-04-26 18:42:59 +020011394 Note: Doesn't consider |matchadd()| highlighting items,
11395 since syntax and matching highlighting are two different
11396 mechanisms |syntax-vs-match|.
h-east52e7cc22024-07-28 17:03:29 +020011397
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011398 Return type: list<any>
Christian Brabandtfe1e2b52024-04-26 18:42:59 +020011399
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011400
11401synstack({lnum}, {col}) *synstack()*
11402 Return a |List|, which is the stack of syntax items at the
11403 position {lnum} and {col} in the current window. {lnum} is
11404 used like with |getline()|. Each item in the List is an ID
11405 like what |synID()| returns.
11406 The first item in the List is the outer region, following are
11407 items contained in that one. The last one is what |synID()|
11408 returns, unless not the whole item is highlighted or it is a
11409 transparent item.
11410 This function is useful for debugging a syntax file.
11411 Example that shows the syntax stack under the cursor: >
11412 for id in synstack(line("."), col("."))
11413 echo synIDattr(id, "name")
11414 endfor
11415< When the position specified with {lnum} and {col} is invalid
Bram Moolenaard592deb2022-06-17 15:42:40 +010011416 an empty List is returned. The position just after the last
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011417 character in a line and the first column in an empty line are
11418 valid positions.
11419
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011420 Return type: list<number> or list<any>
11421
11422
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011423system({expr} [, {input}]) *system()* *E677*
11424 Get the output of the shell command {expr} as a |String|. See
11425 |systemlist()| to get the output as a |List|.
11426
11427 When {input} is given and is a |String| this string is written
11428 to a file and passed as stdin to the command. The string is
11429 written as-is, you need to take care of using the correct line
11430 separators yourself.
11431 If {input} is given and is a |List| it is written to the file
11432 in a way |writefile()| does with {binary} set to "b" (i.e.
11433 with a newline between each list item with newlines inside
11434 list items converted to NULs).
11435 When {input} is given and is a number that is a valid id for
11436 an existing buffer then the content of the buffer is written
11437 to the file line by line, each line terminated by a NL and
11438 NULs characters where the text has a NL.
11439
11440 Pipes are not used, the 'shelltemp' option is not used.
11441
11442 When prepended by |:silent| the terminal will not be set to
11443 cooked mode. This is meant to be used for commands that do
11444 not need the user to type. It avoids stray characters showing
11445 up on the screen which require |CTRL-L| to remove. >
11446 :silent let f = system('ls *.vim')
11447<
11448 Note: Use |shellescape()| or |::S| with |expand()| or
11449 |fnamemodify()| to escape special characters in a command
11450 argument. Newlines in {expr} may cause the command to fail.
11451 The characters in 'shellquote' and 'shellxquote' may also
11452 cause trouble.
11453 This is not to be used for interactive commands.
11454
11455 The result is a String. Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +000011456 :let files = system('ls ' .. shellescape(expand('%:h')))
11457 :let files = system('ls ' .. expand('%:h:S'))
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011458
11459< To make the result more system-independent, the shell output
11460 is filtered to replace <CR> with <NL> for Macintosh, and
11461 <CR><NL> with <NL> for DOS-like systems.
11462 To avoid the string being truncated at a NUL, all NUL
11463 characters are replaced with SOH (0x01).
11464
11465 The command executed is constructed using several options:
11466 'shell' 'shellcmdflag' 'shellxquote' {expr} 'shellredir' {tmp} 'shellxquote'
11467 ({tmp} is an automatically generated file name).
11468 For Unix, braces are put around {expr} to allow for
11469 concatenated commands.
11470
11471 The command will be executed in "cooked" mode, so that a
11472 CTRL-C will interrupt the command (on Unix at least).
11473
11474 The resulting error code can be found in |v:shell_error|.
11475 This function will fail in |restricted-mode|.
11476
11477 Note that any wrong value in the options mentioned above may
11478 make the function fail. It has also been reported to fail
11479 when using a security agent application.
11480 Unlike ":!cmd" there is no automatic check for changed files.
11481 Use |:checktime| to force a check.
11482
11483 Can also be used as a |method|: >
11484 :echo GetCmd()->system()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011485<
11486 Return type: |String|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011487
11488
11489systemlist({expr} [, {input}]) *systemlist()*
11490 Same as |system()|, but returns a |List| with lines (parts of
11491 output separated by NL) with NULs transformed into NLs. Output
11492 is the same as |readfile()| will output with {binary} argument
11493 set to "b", except that there is no extra empty item when the
11494 result ends in a NL.
11495 Note that on MS-Windows you may get trailing CR characters.
11496
11497 To see the difference between "echo hello" and "echo -n hello"
11498 use |system()| and |split()|: >
11499 echo system('echo hello')->split('\n', 1)
11500<
11501 Returns an empty string on error.
11502
11503 Can also be used as a |method|: >
11504 :echo GetCmd()->systemlist()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011505<
11506 Return type: list<string>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011507
11508
11509tabpagebuflist([{arg}]) *tabpagebuflist()*
11510 The result is a |List|, where each item is the number of the
11511 buffer associated with each window in the current tab page.
11512 {arg} specifies the number of the tab page to be used. When
11513 omitted the current tab page is used.
11514 When {arg} is invalid the number zero is returned.
11515 To get a list of all buffers in all tabs use this: >
11516 let buflist = []
11517 for i in range(tabpagenr('$'))
11518 call extend(buflist, tabpagebuflist(i + 1))
11519 endfor
11520< Note that a buffer may appear in more than one window.
11521
11522 Can also be used as a |method|: >
11523 GetTabpage()->tabpagebuflist()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011524<
11525 Return type: list<number>
11526
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011527
11528tabpagenr([{arg}]) *tabpagenr()*
11529 The result is a Number, which is the number of the current
11530 tab page. The first tab page has number 1.
11531
11532 The optional argument {arg} supports the following values:
11533 $ the number of the last tab page (the tab page
11534 count).
11535 # the number of the last accessed tab page
11536 (where |g<Tab>| goes to). if there is no
11537 previous tab page 0 is returned.
11538 The number can be used with the |:tab| command.
11539
Bram Moolenaard592deb2022-06-17 15:42:40 +010011540 Returns zero on error.
11541
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011542 Return type: |Number|
11543
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011544
11545tabpagewinnr({tabarg} [, {arg}]) *tabpagewinnr()*
11546 Like |winnr()| but for tab page {tabarg}.
11547 {tabarg} specifies the number of tab page to be used.
11548 {arg} is used like with |winnr()|:
11549 - When omitted the current window number is returned. This is
11550 the window which will be used when going to this tab page.
11551 - When "$" the number of windows is returned.
11552 - When "#" the previous window nr is returned.
11553 Useful examples: >
11554 tabpagewinnr(1) " current window of tab page 1
11555 tabpagewinnr(4, '$') " number of windows in tab page 4
11556< When {tabarg} is invalid zero is returned.
11557
11558 Can also be used as a |method|: >
11559 GetTabpage()->tabpagewinnr()
11560<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011561 Return type: |Number|
11562
11563
11564tagfiles() *tagfiles()*
11565 Returns a |List| with the file names used to search for tags
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011566 for the current buffer. This is the 'tags' option expanded.
11567
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011568 Return type: list<string> or list<any>
11569
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011570
11571taglist({expr} [, {filename}]) *taglist()*
11572 Returns a |List| of tags matching the regular expression {expr}.
11573
11574 If {filename} is passed it is used to prioritize the results
11575 in the same way that |:tselect| does. See |tag-priority|.
11576 {filename} should be the full path of the file.
11577
11578 Each list item is a dictionary with at least the following
11579 entries:
11580 name Name of the tag.
11581 filename Name of the file where the tag is
11582 defined. It is either relative to the
11583 current directory or a full path.
11584 cmd Ex command used to locate the tag in
11585 the file.
11586 kind Type of the tag. The value for this
11587 entry depends on the language specific
11588 kind values. Only available when
11589 using a tags file generated by
Bram Moolenaar47c532e2022-03-19 15:18:53 +000011590 Universal/Exuberant ctags or hdrtag.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011591 static A file specific tag. Refer to
11592 |static-tag| for more information.
11593 More entries may be present, depending on the content of the
11594 tags file: access, implementation, inherits and signature.
11595 Refer to the ctags documentation for information about these
11596 fields. For C code the fields "struct", "class" and "enum"
11597 may appear, they give the name of the entity the tag is
11598 contained in.
11599
11600 The ex-command "cmd" can be either an ex search pattern, a
11601 line number or a line number followed by a byte number.
11602
11603 If there are no matching tags, then an empty list is returned.
11604
11605 To get an exact tag match, the anchors '^' and '$' should be
11606 used in {expr}. This also make the function work faster.
11607 Refer to |tag-regexp| for more information about the tag
11608 search regular expression pattern.
11609
11610 Refer to |'tags'| for information about how the tags file is
11611 located by Vim. Refer to |tags-file-format| for the format of
11612 the tags file generated by the different ctags tools.
11613
11614 Can also be used as a |method|: >
11615 GetTagpattern()->taglist()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011616<
11617 Return type: list<dict<any>> or list<any>
11618
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011619
11620tan({expr}) *tan()*
11621 Return the tangent of {expr}, measured in radians, as a |Float|
11622 in the range [-inf, inf].
11623 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaard592deb2022-06-17 15:42:40 +010011624 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011625 Examples: >
11626 :echo tan(10)
11627< 0.648361 >
11628 :echo tan(-4.01)
11629< -1.181502
11630
11631 Can also be used as a |method|: >
11632 Compute()->tan()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011633<
11634 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011635
11636
11637tanh({expr}) *tanh()*
11638 Return the hyperbolic tangent of {expr} as a |Float| in the
11639 range [-1, 1].
11640 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaard592deb2022-06-17 15:42:40 +010011641 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011642 Examples: >
11643 :echo tanh(0.5)
11644< 0.462117 >
11645 :echo tanh(-1)
11646< -0.761594
11647
11648 Can also be used as a |method|: >
11649 Compute()->tanh()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011650<
11651 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011652
11653
11654tempname() *tempname()* *temp-file-name*
11655 The result is a String, which is the name of a file that
11656 doesn't exist. It can be used for a temporary file. The name
11657 is different for at least 26 consecutive calls. Example: >
11658 :let tmpfile = tempname()
Bram Moolenaarc51cf032022-02-26 12:25:45 +000011659 :exe "redir > " .. tmpfile
Christian Brabandt5cf53012024-05-18 10:13:11 +020011660< For Unix, the file will be in a private directory |tempfile|
11661 that is recursively deleted when Vim exits, on other systems
11662 temporary files are not cleaned up automatically on exit.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011663 For MS-Windows forward slashes are used when the 'shellslash'
11664 option is set, or when 'shellcmdflag' starts with '-' and
11665 'shell' does not contain powershell or pwsh.
11666
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011667 Return type: |String|
11668
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011669
11670term_ functions are documented here: |terminal-function-details|
11671
11672
11673terminalprops() *terminalprops()*
11674 Returns a |Dictionary| with properties of the terminal that Vim
11675 detected from the response to |t_RV| request. See
11676 |v:termresponse| for the response itself. If |v:termresponse|
11677 is empty most values here will be 'u' for unknown.
11678 cursor_style whether sending |t_RS| works **
11679 cursor_blink_mode whether sending |t_RC| works **
11680 underline_rgb whether |t_8u| works **
11681 mouse mouse type supported
Bram Moolenaar4bc85f22022-10-21 14:17:24 +010011682 kitty whether Kitty terminal was detected
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011683
11684 ** value 'u' for unknown, 'y' for yes, 'n' for no
11685
11686 If the |+termresponse| feature is missing then the result is
11687 an empty dictionary.
11688
11689 If "cursor_style" is 'y' then |t_RS| will be sent to request the
11690 current cursor style.
11691 If "cursor_blink_mode" is 'y' then |t_RC| will be sent to
11692 request the cursor blink status.
11693 "cursor_style" and "cursor_blink_mode" are also set if |t_u7|
11694 is not empty, Vim will detect the working of sending |t_RS|
11695 and |t_RC| on startup.
11696
11697 When "underline_rgb" is not 'y', then |t_8u| will be made empty.
11698 This avoids sending it to xterm, which would clear the colors.
11699
11700 For "mouse" the value 'u' is unknown
11701
11702 Also see:
11703 - 'ambiwidth' - detected by using |t_u7|.
11704 - |v:termstyleresp| and |v:termblinkresp| for the response to
11705 |t_RS| and |t_RC|.
11706
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011707 Return type: dict<string>
11708
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011709
11710test_ functions are documented here: |test-functions-details|
11711
11712
11713 *timer_info()*
11714timer_info([{id}])
11715 Return a list with information about timers.
11716 When {id} is given only information about this timer is
11717 returned. When timer {id} does not exist an empty list is
11718 returned.
11719 When {id} is omitted information about all timers is returned.
11720
11721 For each timer the information is stored in a |Dictionary| with
11722 these items:
11723 "id" the timer ID
11724 "time" time the timer was started with
11725 "remaining" time until the timer fires
11726 "repeat" number of times the timer will still fire;
11727 -1 means forever
11728 "callback" the callback
11729 "paused" 1 if the timer is paused, 0 otherwise
11730
11731 Can also be used as a |method|: >
11732 GetTimer()->timer_info()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011733<
11734 Return type: list<dict<any>> or list<any>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011735
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011736 {only available when compiled with the |+timers| feature}
11737
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011738
11739timer_pause({timer}, {paused}) *timer_pause()*
11740 Pause or unpause a timer. A paused timer does not invoke its
11741 callback when its time expires. Unpausing a timer may cause
11742 the callback to be invoked almost immediately if enough time
11743 has passed.
11744
11745 Pausing a timer is useful to avoid the callback to be called
11746 for a short time.
11747
11748 If {paused} evaluates to a non-zero Number or a non-empty
11749 String, then the timer is paused, otherwise it is unpaused.
11750 See |non-zero-arg|.
11751
11752 Can also be used as a |method|: >
11753 GetTimer()->timer_pause(1)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011754<
11755 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011756
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011757 {only available when compiled with the |+timers| feature}
11758
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011759
11760 *timer_start()* *timer* *timers*
11761timer_start({time}, {callback} [, {options}])
11762 Create a timer and return the timer ID.
11763
11764 {time} is the waiting time in milliseconds. This is the
11765 minimum time before invoking the callback. When the system is
11766 busy or Vim is not waiting for input the time will be longer.
Bram Moolenaardd60c362023-02-27 15:49:53 +000011767 Zero can be used to execute the callback when Vim is back in
11768 the main loop.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011769
11770 {callback} is the function to call. It can be the name of a
11771 function or a |Funcref|. It is called with one argument, which
11772 is the timer ID. The callback is only invoked when Vim is
11773 waiting for input.
11774 If you want to show a message look at |popup_notification()|
11775 to avoid interfering with what the user is doing.
11776
11777 {options} is a dictionary. Supported entries:
11778 "repeat" Number of times to repeat calling the
11779 callback. -1 means forever. When not present
11780 the callback will be called once.
11781 If the timer causes an error three times in a
11782 row the repeat is cancelled. This avoids that
11783 Vim becomes unusable because of all the error
11784 messages.
11785
Bram Moolenaard592deb2022-06-17 15:42:40 +010011786 Returns -1 on error.
11787
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011788 Example: >
11789 func MyHandler(timer)
11790 echo 'Handler called'
11791 endfunc
11792 let timer = timer_start(500, 'MyHandler',
11793 \ {'repeat': 3})
11794< This will invoke MyHandler() three times at 500 msec
11795 intervals.
11796
11797 Can also be used as a |method|: >
11798 GetMsec()->timer_start(callback)
11799
11800< Not available in the |sandbox|.
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011801
11802 Return type: |Number|
11803
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011804 {only available when compiled with the |+timers| feature}
11805
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011806
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011807timer_stop({timer}) *timer_stop()*
11808 Stop a timer. The timer callback will no longer be invoked.
11809 {timer} is an ID returned by timer_start(), thus it must be a
11810 Number. If {timer} does not exist there is no error.
11811
11812 Can also be used as a |method|: >
11813 GetTimer()->timer_stop()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011814<
11815 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011816
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011817 {only available when compiled with the |+timers| feature}
11818
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011819
11820timer_stopall() *timer_stopall()*
11821 Stop all timers. The timer callbacks will no longer be
11822 invoked. Useful if a timer is misbehaving. If there are no
11823 timers there is no error.
11824
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011825 Return type: |Number|
11826
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011827 {only available when compiled with the |+timers| feature}
11828
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011829
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011830tolower({expr}) *tolower()*
11831 The result is a copy of the String given, with all uppercase
11832 characters turned into lowercase (just like applying |gu| to
Bram Moolenaard592deb2022-06-17 15:42:40 +010011833 the string). Returns an empty string on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011834
11835 Can also be used as a |method|: >
11836 GetText()->tolower()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011837<
11838 Return type: |String|
11839
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011840
11841toupper({expr}) *toupper()*
11842 The result is a copy of the String given, with all lowercase
11843 characters turned into uppercase (just like applying |gU| to
Bram Moolenaard592deb2022-06-17 15:42:40 +010011844 the string). Returns an empty string on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011845
11846 Can also be used as a |method|: >
11847 GetText()->toupper()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011848<
11849 Return type: |String|
11850
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011851
11852tr({src}, {fromstr}, {tostr}) *tr()*
11853 The result is a copy of the {src} string with all characters
11854 which appear in {fromstr} replaced by the character in that
11855 position in the {tostr} string. Thus the first character in
11856 {fromstr} is translated into the first character in {tostr}
11857 and so on. Exactly like the unix "tr" command.
11858 This code also deals with multibyte characters properly.
11859
Bram Moolenaard592deb2022-06-17 15:42:40 +010011860 Returns an empty string on error.
11861
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011862 Examples: >
11863 echo tr("hello there", "ht", "HT")
11864< returns "Hello THere" >
11865 echo tr("<blob>", "<>", "{}")
11866< returns "{blob}"
11867
11868 Can also be used as a |method|: >
11869 GetText()->tr(from, to)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011870<
11871 Return type: |String|
11872
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011873
11874trim({text} [, {mask} [, {dir}]]) *trim()*
11875 Return {text} as a String where any character in {mask} is
11876 removed from the beginning and/or end of {text}.
11877
Illia Bobyr80799172023-10-17 18:00:50 +020011878 If {mask} is not given, or is an empty string, {mask} is all
11879 characters up to 0x20, which includes Tab, space, NL and CR,
11880 plus the non-breaking space character 0xa0.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011881
11882 The optional {dir} argument specifies where to remove the
11883 characters:
11884 0 remove from the beginning and end of {text}
11885 1 remove only at the beginning of {text}
11886 2 remove only at the end of {text}
11887 When omitted both ends are trimmed.
11888
11889 This function deals with multibyte characters properly.
Bram Moolenaard592deb2022-06-17 15:42:40 +010011890 Returns an empty string on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011891
11892 Examples: >
11893 echo trim(" some text ")
11894< returns "some text" >
Bram Moolenaarc51cf032022-02-26 12:25:45 +000011895 echo trim(" \r\t\t\r RESERVE \t\n\x0B\xA0") .. "_TAIL"
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011896< returns "RESERVE_TAIL" >
11897 echo trim("rm<Xrm<>X>rrm", "rm<>")
11898< returns "Xrm<>X" (characters in the middle are not removed) >
11899 echo trim(" vim ", " ", 2)
11900< returns " vim"
11901
11902 Can also be used as a |method|: >
11903 GetText()->trim()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011904<
11905 Return type: |String|
11906
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011907
11908trunc({expr}) *trunc()*
11909 Return the largest integral value with magnitude less than or
11910 equal to {expr} as a |Float| (truncate towards zero).
11911 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaard592deb2022-06-17 15:42:40 +010011912 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011913 Examples: >
11914 echo trunc(1.456)
11915< 1.0 >
11916 echo trunc(-5.456)
11917< -5.0 >
11918 echo trunc(4.0)
11919< 4.0
11920
11921 Can also be used as a |method|: >
11922 Compute()->trunc()
11923<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011924 Return type: |Float|
11925
11926
Yegappan Lakshmanan1c2f4752025-03-30 15:37:24 +020011927tuple2list({tuple}) *tuple2list()*
Yegappan Lakshmanan9cb865e2025-03-23 16:42:16 +010011928 Create a List from a shallow copy of the tuple items.
11929 Examples: >
11930 tuple2list((1, 2, 3)) returns [1, 2, 3]
11931< |list2tuple()| does the opposite.
11932
11933 This function doesn't recursively convert all the Tuple items
11934 in {tuple} to a List. Note that the items are identical
11935 between the list and the tuple, changing an item changes the
11936 contents of both the tuple and the list.
11937
11938 Returns an empty list on error.
11939
11940 Can also be used as a |method|: >
11941 GetTuple()->tuple2list()
11942<
11943 Return type: list<{type}> (depending on the given |Tuple|)
11944
11945
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011946 *type()*
11947type({expr}) The result is a Number representing the type of {expr}.
11948 Instead of using the number directly, it is better to use the
11949 v:t_ variable that has the value:
11950 Number: 0 |v:t_number|
11951 String: 1 |v:t_string|
11952 Funcref: 2 |v:t_func|
11953 List: 3 |v:t_list|
11954 Dictionary: 4 |v:t_dict|
11955 Float: 5 |v:t_float|
11956 Boolean: 6 |v:t_bool| (v:false and v:true)
11957 None: 7 |v:t_none| (v:null and v:none)
11958 Job: 8 |v:t_job|
11959 Channel: 9 |v:t_channel|
11960 Blob: 10 |v:t_blob|
h_east596a9f22023-11-21 21:24:23 +090011961 Class: 12 |v:t_class|
11962 Object: 13 |v:t_object|
Yegappan Lakshmanan2a71b542023-12-14 20:03:03 +010011963 Typealias: 14 |v:t_typealias|
Yegappan Lakshmanan3164cf82024-03-28 10:36:42 +010011964 Enum: 15 |v:t_enum|
11965 EnumValue: 16 |v:t_enumvalue|
Yegappan Lakshmanan9cb865e2025-03-23 16:42:16 +010011966 Tuple: 17 |v:t_tuple|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011967 For backward compatibility, this method can be used: >
11968 :if type(myvar) == type(0)
11969 :if type(myvar) == type("")
11970 :if type(myvar) == type(function("tr"))
11971 :if type(myvar) == type([])
11972 :if type(myvar) == type({})
11973 :if type(myvar) == type(0.0)
11974 :if type(myvar) == type(v:false)
11975 :if type(myvar) == type(v:none)
11976< To check if the v:t_ variables exist use this: >
11977 :if exists('v:t_number')
11978
11979< Can also be used as a |method|: >
11980 mylist->type()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011981<
11982 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011983
11984
11985typename({expr}) *typename()*
11986 Return a string representation of the type of {expr}.
11987 Example: >
11988 echo typename([1, 2, 3])
Kota Kato66bb9ae2023-01-17 18:31:56 +000011989< list<number> ~
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011990
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011991 Return type: |String|
11992
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011993
11994undofile({name}) *undofile()*
11995 Return the name of the undo file that would be used for a file
11996 with name {name} when writing. This uses the 'undodir'
11997 option, finding directories that exist. It does not check if
11998 the undo file exists.
11999 {name} is always expanded to the full path, since that is what
12000 is used internally.
12001 If {name} is empty undofile() returns an empty string, since a
12002 buffer without a file name will not write an undo file.
12003 Useful in combination with |:wundo| and |:rundo|.
12004 When compiled without the |+persistent_undo| option this always
12005 returns an empty string.
12006
12007 Can also be used as a |method|: >
12008 GetFilename()->undofile()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012009<
12010 Return type: |String|
12011
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012012
Devin J. Pohly5fee1112023-04-23 20:26:59 -050012013undotree([{buf}]) *undotree()*
12014 Return the current state of the undo tree for the current
12015 buffer, or for a specific buffer if {buf} is given. The
12016 result is a dictionary with the following items:
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012017 "seq_last" The highest undo sequence number used.
12018 "seq_cur" The sequence number of the current position in
12019 the undo tree. This differs from "seq_last"
12020 when some changes were undone.
12021 "time_cur" Time last used for |:earlier| and related
12022 commands. Use |strftime()| to convert to
12023 something readable.
12024 "save_last" Number of the last file write. Zero when no
12025 write yet.
12026 "save_cur" Number of the current position in the undo
12027 tree.
12028 "synced" Non-zero when the last undo block was synced.
12029 This happens when waiting from input from the
12030 user. See |undo-blocks|.
12031 "entries" A list of dictionaries with information about
12032 undo blocks.
12033
12034 The first item in the "entries" list is the oldest undo item.
12035 Each List item is a |Dictionary| with these items:
12036 "seq" Undo sequence number. Same as what appears in
12037 |:undolist|.
12038 "time" Timestamp when the change happened. Use
12039 |strftime()| to convert to something readable.
12040 "newhead" Only appears in the item that is the last one
12041 that was added. This marks the last change
12042 and where further changes will be added.
12043 "curhead" Only appears in the item that is the last one
12044 that was undone. This marks the current
12045 position in the undo tree, the block that will
12046 be used by a redo command. When nothing was
12047 undone after the last change this item will
12048 not appear anywhere.
12049 "save" Only appears on the last block before a file
12050 write. The number is the write count. The
12051 first write has number 1, the last one the
12052 "save_last" mentioned above.
12053 "alt" Alternate entry. This is again a List of undo
12054 blocks. Each item may again have an "alt"
12055 item.
12056
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012057 Return type: dict<any>
12058
12059
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012060uniq({list} [, {func} [, {dict}]]) *uniq()* *E882*
12061 Remove second and succeeding copies of repeated adjacent
12062 {list} items in-place. Returns {list}. If you want a list
12063 to remain unmodified make a copy first: >
12064 :let newlist = uniq(copy(mylist))
12065< The default compare function uses the string representation of
12066 each item. For the use of {func} and {dict} see |sort()|.
12067
Bram Moolenaard592deb2022-06-17 15:42:40 +010012068 Returns zero if {list} is not a |List|.
12069
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012070 Can also be used as a |method|: >
12071 mylist->uniq()
Christian Brabandt67672ef2023-04-24 21:09:54 +010012072<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012073 Return type: list<{type}>
12074
12075
Christian Brabandt67672ef2023-04-24 21:09:54 +010012076 *utf16idx()*
12077utf16idx({string}, {idx} [, {countcc} [, {charidx}]])
Yegappan Lakshmanan577922b2023-06-08 17:09:45 +010012078 Same as |charidx()| but returns the UTF-16 code unit index of
12079 the byte at {idx} in {string} (after converting it to UTF-16).
Christian Brabandt67672ef2023-04-24 21:09:54 +010012080
12081 When {charidx} is present and TRUE, {idx} is used as the
12082 character index in the String {string} instead of as the byte
12083 index.
Yegappan Lakshmanan95707032023-06-14 13:10:15 +010012084 An {idx} in the middle of a UTF-8 sequence is rounded
12085 downwards to the beginning of that sequence.
Christian Brabandt67672ef2023-04-24 21:09:54 +010012086
Yegappan Lakshmanan577922b2023-06-08 17:09:45 +010012087 Returns -1 if the arguments are invalid or if there are less
12088 than {idx} bytes in {string}. If there are exactly {idx} bytes
12089 the length of the string in UTF-16 code units is returned.
12090
Christian Brabandt67672ef2023-04-24 21:09:54 +010012091 See |byteidx()| and |byteidxcomp()| for getting the byte index
12092 from the UTF-16 index and |charidx()| for getting the
12093 character index from the UTF-16 index.
12094 Refer to |string-offset-encoding| for more information.
12095 Examples: >
12096 echo utf16idx('a😊😊', 3) returns 2
12097 echo utf16idx('a😊😊', 7) returns 4
12098 echo utf16idx('a😊😊', 1, 0, 1) returns 2
12099 echo utf16idx('a😊😊', 2, 0, 1) returns 4
12100 echo utf16idx('aą́c', 6) returns 2
12101 echo utf16idx('aą́c', 6, 1) returns 4
12102 echo utf16idx('a😊😊', 9) returns -1
12103<
12104 Can also be used as a |method|: >
12105 GetName()->utf16idx(idx)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012106<
12107 Return type: |Number|
Christian Brabandt67672ef2023-04-24 21:09:54 +010012108
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012109
12110values({dict}) *values()*
12111 Return a |List| with all the values of {dict}. The |List| is
12112 in arbitrary order. Also see |items()| and |keys()|.
Bram Moolenaard592deb2022-06-17 15:42:40 +010012113 Returns zero if {dict} is not a |Dict|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012114
12115 Can also be used as a |method|: >
12116 mydict->values()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012117<
12118 Return type: list<any>
12119
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012120
zeertzjq825cf812023-08-17 22:55:25 +020012121virtcol({expr} [, {list} [, {winid}]]) *virtcol()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012122 The result is a Number, which is the screen column of the file
12123 position given with {expr}. That is, the last screen position
12124 occupied by the character at that position, when the screen
12125 would be of unlimited width. When there is a <Tab> at the
12126 position, the returned Number will be the column at the end of
12127 the <Tab>. For example, for a <Tab> in column 1, with 'ts'
12128 set to 8, it returns 8. |conceal| is ignored.
12129 For the byte position use |col()|.
LemonBoy0f7a3e12022-05-26 12:10:37 +010012130
zeertzjq02f3eba2024-06-12 20:45:24 +020012131 For the use of {expr} see |getpos()| and |col()|.
zeertzjqd353d272024-06-13 23:00:25 +080012132 When {expr} is "$", it means the end of the cursor line, so
12133 the result is the number of cells in the cursor line plus one.
LemonBoy0f7a3e12022-05-26 12:10:37 +010012134
12135 When 'virtualedit' is used {expr} can be [lnum, col, off],
12136 where "off" is the offset in screen columns from the start of
12137 the character. E.g., a position within a <Tab> or after the
12138 last character. When "off" is omitted zero is used. When
12139 Virtual editing is active in the current mode, a position
12140 beyond the end of the line can be returned. Also see
12141 |'virtualedit'|
12142
zeertzjq825cf812023-08-17 22:55:25 +020012143 If {list} is present and non-zero then virtcol() returns a
12144 List with the first and last screen position occupied by the
LemonBoy0f7a3e12022-05-26 12:10:37 +010012145 character.
12146
zeertzjq825cf812023-08-17 22:55:25 +020012147 With the optional {winid} argument the values are obtained for
12148 that window instead of the current window.
12149
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012150 Note that only marks in the current file can be used.
zeertzjq02f3eba2024-06-12 20:45:24 +020012151
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012152 Examples: >
LemonBoy0f7a3e12022-05-26 12:10:37 +010012153 " With text "foo^Lbar" and cursor on the "^L":
12154
12155 virtcol(".") " returns 5
12156 virtcol(".", 1) " returns [4, 5]
12157 virtcol("$") " returns 9
12158
12159 " With text " there", with 't at 'h':
12160
12161 virtcol("'t") " returns 6
zeertzjq02f3eba2024-06-12 20:45:24 +020012162<
12163 The first column is 1. 0 or [0, 0] is returned for an error.
12164
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012165 A more advanced example that echoes the maximum length of
12166 all lines: >
12167 echo max(map(range(1, line('$')), "virtcol([v:val, '$'])"))
12168
12169< Can also be used as a |method|: >
12170 GetPos()->virtcol()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012171<
12172 Return type: |Number|
12173
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012174
Bram Moolenaar5a6ec102022-05-27 21:58:00 +010012175virtcol2col({winid}, {lnum}, {col}) *virtcol2col()*
12176 The result is a Number, which is the byte index of the
12177 character in window {winid} at buffer line {lnum} and virtual
12178 column {col}.
12179
zeertzjqb583eda2023-10-14 11:32:28 +020012180 If buffer line {lnum} is an empty line, 0 is returned.
12181
Bram Moolenaar5a6ec102022-05-27 21:58:00 +010012182 If {col} is greater than the last virtual column in line
12183 {lnum}, then the byte index of the character at the last
12184 virtual column is returned.
12185
Yegappan Lakshmananb209b862023-08-15 23:01:44 +020012186 For a multi-byte character, the column number of the first
12187 byte in the character is returned.
12188
Bram Moolenaar5a6ec102022-05-27 21:58:00 +010012189 The {winid} argument can be the window number or the
12190 |window-ID|. If this is zero, then the current window is used.
12191
12192 Returns -1 if the window {winid} doesn't exist or the buffer
12193 line {lnum} or virtual column {col} is invalid.
12194
12195 See also |screenpos()|, |virtcol()| and |col()|.
12196
12197 Can also be used as a |method|: >
12198 GetWinid()->virtcol2col(lnum, col)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012199<
12200 Return type: |Number|
12201
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012202
12203visualmode([{expr}]) *visualmode()*
12204 The result is a String, which describes the last Visual mode
12205 used in the current buffer. Initially it returns an empty
12206 string, but once Visual mode has been used, it returns "v",
12207 "V", or "<CTRL-V>" (a single CTRL-V character) for
12208 character-wise, line-wise, or block-wise Visual mode
12209 respectively.
12210 Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +000012211 :exe "normal " .. visualmode()
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012212< This enters the same Visual mode as before. It is also useful
12213 in scripts if you wish to act differently depending on the
12214 Visual mode that was used.
12215 If Visual mode is active, use |mode()| to get the Visual mode
12216 (e.g., in a |:vmap|).
12217 If {expr} is supplied and it evaluates to a non-zero Number or
12218 a non-empty String, then the Visual mode will be cleared and
12219 the old value is returned. See |non-zero-arg|.
12220
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012221 Return type: |String|
12222
12223
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012224wildmenumode() *wildmenumode()*
12225 Returns |TRUE| when the wildmenu is active and |FALSE|
12226 otherwise. See 'wildmenu' and 'wildmode'.
12227 This can be used in mappings to handle the 'wildcharm' option
12228 gracefully. (Makes only sense with |mapmode-c| mappings).
12229
12230 For example to make <c-j> work like <down> in wildmode, use: >
12231 :cnoremap <expr> <C-j> wildmenumode() ? "\<Down>\<Tab>" : "\<c-j>"
12232<
Milly6c2fc372024-10-16 22:11:17 +020012233 (Note: this needs the 'wildcharm' option set appropriately).
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012234
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012235 Return type: |Number|
12236
12237
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012238win_execute({id}, {command} [, {silent}]) *win_execute()*
12239 Like `execute()` but in the context of window {id}.
12240 The window will temporarily be made the current window,
12241 without triggering autocommands or changing directory. When
12242 executing {command} autocommands will be triggered, this may
Bram Moolenaarb7398fe2023-05-14 18:50:25 +010012243 have unexpected side effects. Use `:noautocmd` if needed.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012244 Example: >
12245 call win_execute(winid, 'set syntax=python')
12246< Doing the same with `setwinvar()` would not trigger
12247 autocommands and not actually show syntax highlighting.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012248 *E994*
12249 Not all commands are allowed in popup windows.
12250 When window {id} does not exist then no error is given and
12251 an empty string is returned.
12252
12253 Can also be used as a |method|, the base is passed as the
12254 second argument: >
12255 GetCommand()->win_execute(winid)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012256<
12257 Return type: |String|
12258
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012259
12260win_findbuf({bufnr}) *win_findbuf()*
12261 Returns a |List| with |window-ID|s for windows that contain
12262 buffer {bufnr}. When there is none the list is empty.
12263
12264 Can also be used as a |method|: >
12265 GetBufnr()->win_findbuf()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012266<
12267 Return type: list<number> or list<any>
12268
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012269
12270win_getid([{win} [, {tab}]]) *win_getid()*
12271 Get the |window-ID| for the specified window.
12272 When {win} is missing use the current window.
12273 With {win} this is the window number. The top window has
12274 number 1.
12275 Without {tab} use the current tab, otherwise the tab with
12276 number {tab}. The first tab has number one.
12277 Return zero if the window cannot be found.
12278
12279 Can also be used as a |method|: >
12280 GetWinnr()->win_getid()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012281<
12282 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012283
12284
12285win_gettype([{nr}]) *win_gettype()*
12286 Return the type of the window:
12287 "autocmd" autocommand window. Temporary window
12288 used to execute autocommands.
12289 "command" command-line window |cmdwin|
12290 (empty) normal window
12291 "loclist" |location-list-window|
12292 "popup" popup window |popup|
12293 "preview" preview window |preview-window|
12294 "quickfix" |quickfix-window|
12295 "unknown" window {nr} not found
12296
12297 When {nr} is omitted return the type of the current window.
12298 When {nr} is given return the type of this window by number or
12299 |window-ID|.
12300
12301 Also see the 'buftype' option. When running a terminal in a
12302 popup window then 'buftype' is "terminal" and win_gettype()
12303 returns "popup".
12304
12305 Can also be used as a |method|: >
12306 GetWinid()->win_gettype()
12307<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012308 Return type: |String|
12309
12310
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012311win_gotoid({expr}) *win_gotoid()*
12312 Go to window with ID {expr}. This may also change the current
12313 tabpage.
12314 Return TRUE if successful, FALSE if the window cannot be found.
12315
12316 Can also be used as a |method|: >
12317 GetWinid()->win_gotoid()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012318<
12319 Return type: |Number|
12320
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012321
12322win_id2tabwin({expr}) *win_id2tabwin()*
12323 Return a list with the tab number and window number of window
12324 with ID {expr}: [tabnr, winnr].
12325 Return [0, 0] if the window cannot be found.
12326
12327 Can also be used as a |method|: >
12328 GetWinid()->win_id2tabwin()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012329<
12330 Return type: list<number>
12331
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012332
12333win_id2win({expr}) *win_id2win()*
12334 Return the window number of window with ID {expr}.
12335 Return 0 if the window cannot be found in the current tabpage.
12336
12337 Can also be used as a |method|: >
12338 GetWinid()->win_id2win()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012339<
12340 Return type: |Number|
12341
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012342
Daniel Steinbergee630312022-01-10 13:36:34 +000012343win_move_separator({nr}, {offset}) *win_move_separator()*
12344 Move window {nr}'s vertical separator (i.e., the right border)
12345 by {offset} columns, as if being dragged by the mouse. {nr}
12346 can be a window number or |window-ID|. A positive {offset}
12347 moves right and a negative {offset} moves left. Moving a
12348 window's vertical separator will change the width of the
12349 window and the width of other windows adjacent to the vertical
12350 separator. The magnitude of movement may be smaller than
12351 specified (e.g., as a consequence of maintaining
12352 'winminwidth'). Returns TRUE if the window can be found and
12353 FALSE otherwise.
Bram Moolenaard592deb2022-06-17 15:42:40 +010012354 This will fail for the rightmost window and a full-width
12355 window, since it has no separator on the right.
Bram Moolenaar76db9e02022-11-09 21:21:04 +000012356 Only works for the current tab page. *E1308*
Daniel Steinbergee630312022-01-10 13:36:34 +000012357
12358 Can also be used as a |method|: >
12359 GetWinnr()->win_move_separator(offset)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012360<
12361 Return type: |Number|
12362
Daniel Steinbergee630312022-01-10 13:36:34 +000012363
12364win_move_statusline({nr}, {offset}) *win_move_statusline()*
12365 Move window {nr}'s status line (i.e., the bottom border) by
12366 {offset} rows, as if being dragged by the mouse. {nr} can be a
12367 window number or |window-ID|. A positive {offset} moves down
12368 and a negative {offset} moves up. Moving a window's status
12369 line will change the height of the window and the height of
12370 other windows adjacent to the status line. The magnitude of
12371 movement may be smaller than specified (e.g., as a consequence
12372 of maintaining 'winminheight'). Returns TRUE if the window can
12373 be found and FALSE otherwise.
Bram Moolenaar76db9e02022-11-09 21:21:04 +000012374 Only works for the current tab page.
Daniel Steinbergee630312022-01-10 13:36:34 +000012375
12376 Can also be used as a |method|: >
12377 GetWinnr()->win_move_statusline(offset)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012378<
12379 Return type: |Number|
12380
Daniel Steinbergee630312022-01-10 13:36:34 +000012381
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012382win_screenpos({nr}) *win_screenpos()*
12383 Return the screen position of window {nr} as a list with two
12384 numbers: [row, col]. The first window always has position
12385 [1, 1], unless there is a tabline, then it is [2, 1].
12386 {nr} can be the window number or the |window-ID|. Use zero
12387 for the current window.
Sean Dewar5866bc32024-03-13 20:17:24 +010012388 Returns [0, 0] if the window cannot be found.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012389
12390 Can also be used as a |method|: >
12391 GetWinid()->win_screenpos()
12392<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012393 Return type: list<number>
12394
12395
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012396win_splitmove({nr}, {target} [, {options}]) *win_splitmove()*
Sean Dewar96cc4ae2024-02-20 21:52:31 +010012397 Temporarily switch to window {target}, then move window {nr}
12398 to a new split adjacent to {target}.
12399 Unlike commands such as |:split|, no new windows are created
12400 (the |window-ID| of window {nr} is unchanged after the move).
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012401
12402 Both {nr} and {target} can be window numbers or |window-ID|s.
12403 Both must be in the current tab page.
12404
12405 Returns zero for success, non-zero for failure.
12406
12407 {options} is a |Dictionary| with the following optional entries:
12408 "vertical" When TRUE, the split is created vertically,
12409 like with |:vsplit|.
12410 "rightbelow" When TRUE, the split is made below or to the
12411 right (if vertical). When FALSE, it is done
12412 above or to the left (if vertical). When not
12413 present, the values of 'splitbelow' and
12414 'splitright' are used.
12415
12416 Can also be used as a |method|: >
12417 GetWinid()->win_splitmove(target)
12418<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012419 Return type: |Number|
12420
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012421
12422 *winbufnr()*
12423winbufnr({nr}) The result is a Number, which is the number of the buffer
12424 associated with window {nr}. {nr} can be the window number or
12425 the |window-ID|.
12426 When {nr} is zero, the number of the buffer in the current
12427 window is returned.
12428 When window {nr} doesn't exist, -1 is returned.
12429 Example: >
12430 :echo "The file in the current window is " . bufname(winbufnr(0))
12431<
12432 Can also be used as a |method|: >
12433 FindWindow()->winbufnr()->bufname()
12434<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012435 Return type: |Number|
12436
12437
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012438 *wincol()*
12439wincol() The result is a Number, which is the virtual column of the
12440 cursor in the window. This is counting screen cells from the
12441 left side of the window. The leftmost column is one.
12442
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012443 Return type: |Number|
12444
12445
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012446 *windowsversion()*
12447windowsversion()
12448 The result is a String. For MS-Windows it indicates the OS
12449 version. E.g, Windows 10 is "10.0", Windows 8 is "6.2",
12450 Windows XP is "5.1". For non-MS-Windows systems the result is
12451 an empty string.
12452
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012453 Return type: |String|
12454
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012455winheight({nr}) *winheight()*
12456 The result is a Number, which is the height of window {nr}.
12457 {nr} can be the window number or the |window-ID|.
12458 When {nr} is zero, the height of the current window is
12459 returned. When window {nr} doesn't exist, -1 is returned.
12460 An existing window always has a height of zero or more.
12461 This excludes any window toolbar line.
12462 Examples: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +000012463 :echo "The current window has " .. winheight(0) .. " lines."
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012464
12465< Can also be used as a |method|: >
12466 GetWinid()->winheight()
12467<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012468 Return type: |Number|
12469
12470
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012471winlayout([{tabnr}]) *winlayout()*
12472 The result is a nested List containing the layout of windows
12473 in a tabpage.
12474
12475 Without {tabnr} use the current tabpage, otherwise the tabpage
12476 with number {tabnr}. If the tabpage {tabnr} is not found,
12477 returns an empty list.
12478
12479 For a leaf window, it returns:
12480 ['leaf', {winid}]
12481 For horizontally split windows, which form a column, it
12482 returns:
12483 ['col', [{nested list of windows}]]
12484 For vertically split windows, which form a row, it returns:
12485 ['row', [{nested list of windows}]]
12486
12487 Example: >
12488 " Only one window in the tab page
12489 :echo winlayout()
12490 ['leaf', 1000]
12491 " Two horizontally split windows
12492 :echo winlayout()
12493 ['col', [['leaf', 1000], ['leaf', 1001]]]
12494 " The second tab page, with three horizontally split
12495 " windows, with two vertically split windows in the
12496 " middle window
12497 :echo winlayout(2)
12498 ['col', [['leaf', 1002], ['row', [['leaf', 1003],
12499 ['leaf', 1001]]], ['leaf', 1000]]]
12500<
12501 Can also be used as a |method|: >
12502 GetTabnr()->winlayout()
12503<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012504 Return type: list<any>
12505
12506
12507winline() *winline()*
12508 The result is a Number, which is the screen line of the cursor
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012509 in the window. This is counting screen lines from the top of
12510 the window. The first line is one.
12511 If the cursor was moved the view on the file will be updated
12512 first, this may cause a scroll.
12513
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012514 Return type: |Number|
12515
12516
12517winnr([{arg}]) *winnr()*
12518 The result is a Number, which is the number of the current
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012519 window. The top window has number 1.
12520 Returns zero for a popup window.
12521
12522 The optional argument {arg} supports the following values:
12523 $ the number of the last window (the window
12524 count).
12525 # the number of the last accessed window (where
12526 |CTRL-W_p| goes to). If there is no previous
12527 window or it is in another tab page 0 is
Sean Deward64801e2024-03-12 20:46:12 +010012528 returned. May refer to the current window in
12529 some cases (e.g. when evaluating 'statusline'
12530 expressions).
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012531 {N}j the number of the Nth window below the
12532 current window (where |CTRL-W_j| goes to).
12533 {N}k the number of the Nth window above the current
12534 window (where |CTRL-W_k| goes to).
12535 {N}h the number of the Nth window left of the
12536 current window (where |CTRL-W_h| goes to).
12537 {N}l the number of the Nth window right of the
12538 current window (where |CTRL-W_l| goes to).
12539 The number can be used with |CTRL-W_w| and ":wincmd w"
12540 |:wincmd|.
Bram Moolenaar016188f2022-06-06 20:52:59 +010012541 When {arg} is invalid an error is given and zero is returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012542 Also see |tabpagewinnr()| and |win_getid()|.
12543 Examples: >
12544 let window_count = winnr('$')
12545 let prev_window = winnr('#')
12546 let wnum = winnr('3k')
12547
12548< Can also be used as a |method|: >
12549 GetWinval()->winnr()
12550<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012551 Return type: |Number|
12552
12553
12554winrestcmd() *winrestcmd()*
12555 Returns a sequence of |:resize| commands that should restore
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012556 the current window sizes. Only works properly when no windows
12557 are opened or closed and the current window and tab page is
12558 unchanged.
12559 Example: >
12560 :let cmd = winrestcmd()
12561 :call MessWithWindowSizes()
12562 :exe cmd
12563<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012564 Return type: |String|
12565
12566
12567winrestview({dict}) *winrestview()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012568 Uses the |Dictionary| returned by |winsaveview()| to restore
12569 the view of the current window.
12570 Note: The {dict} does not have to contain all values, that are
12571 returned by |winsaveview()|. If values are missing, those
12572 settings won't be restored. So you can use: >
12573 :call winrestview({'curswant': 4})
12574<
12575 This will only set the curswant value (the column the cursor
12576 wants to move on vertical movements) of the cursor to column 5
12577 (yes, that is 5), while all other settings will remain the
12578 same. This is useful, if you set the cursor position manually.
12579
12580 If you have changed the values the result is unpredictable.
12581 If the window size changed the result won't be the same.
12582
12583 Can also be used as a |method|: >
12584 GetView()->winrestview()
12585<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012586 Return type: |Number|
12587
12588
12589winsaveview() *winsaveview()*
12590 Returns a |Dictionary| that contains information to restore
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012591 the view of the current window. Use |winrestview()| to
12592 restore the view.
12593 This is useful if you have a mapping that jumps around in the
12594 buffer and you want to go back to the original view.
12595 This does not save fold information. Use the 'foldenable'
12596 option to temporarily switch off folding, so that folds are
12597 not opened when moving around. This may have side effects.
12598 The return value includes:
12599 lnum cursor line number
12600 col cursor column (Note: the first column
naohiro ono56200ee2022-01-01 14:59:44 +000012601 zero, as opposed to what |getcurpos()|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012602 returns)
12603 coladd cursor column offset for 'virtualedit'
naohiro ono56200ee2022-01-01 14:59:44 +000012604 curswant column for vertical movement (Note:
12605 the first column is zero, as opposed
12606 to what |getcurpos()| returns). After
12607 |$| command it will be a very large
12608 number equal to |v:maxcol|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012609 topline first line in the window
12610 topfill filler lines, only in diff mode
12611 leftcol first column displayed; only used when
12612 'wrap' is off
12613 skipcol columns skipped
12614 Note that no option values are saved.
12615
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012616 Return type: dict<number>
12617
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012618
12619winwidth({nr}) *winwidth()*
12620 The result is a Number, which is the width of window {nr}.
12621 {nr} can be the window number or the |window-ID|.
12622 When {nr} is zero, the width of the current window is
12623 returned. When window {nr} doesn't exist, -1 is returned.
12624 An existing window always has a width of zero or more.
12625 Examples: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +000012626 :echo "The current window has " .. winwidth(0) .. " columns."
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012627 :if winwidth(0) <= 50
12628 : 50 wincmd |
12629 :endif
12630< For getting the terminal or screen size, see the 'columns'
12631 option.
12632
12633 Can also be used as a |method|: >
12634 GetWinid()->winwidth()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012635<
12636 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012637
12638
12639wordcount() *wordcount()*
12640 The result is a dictionary of byte/chars/word statistics for
12641 the current buffer. This is the same info as provided by
12642 |g_CTRL-G|
12643 The return value includes:
12644 bytes Number of bytes in the buffer
12645 chars Number of chars in the buffer
12646 words Number of words in the buffer
12647 cursor_bytes Number of bytes before cursor position
12648 (not in Visual mode)
12649 cursor_chars Number of chars before cursor position
12650 (not in Visual mode)
12651 cursor_words Number of words before cursor position
12652 (not in Visual mode)
12653 visual_bytes Number of bytes visually selected
12654 (only in Visual mode)
12655 visual_chars Number of chars visually selected
12656 (only in Visual mode)
12657 visual_words Number of words visually selected
12658 (only in Visual mode)
12659
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012660 Return type: dict<number>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012661
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012662
12663writefile({object}, {fname} [, {flags}]) *writefile()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012664 When {object} is a |List| write it to file {fname}. Each list
12665 item is separated with a NL. Each list item must be a String
12666 or Number.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012667 All NL characters are replaced with a NUL character.
12668 Inserting CR characters needs to be done before passing {list}
12669 to writefile().
Bram Moolenaar806a2732022-09-04 15:40:36 +010012670
12671 When {object} is a |Blob| write the bytes to file {fname}
12672 unmodified, also when binary mode is not specified.
12673
12674 {flags} must be a String. These characters are recognized:
12675
12676 'b' Binary mode is used: There will not be a NL after the
12677 last list item. An empty item at the end does cause the
12678 last line in the file to end in a NL.
12679
12680 'a' Append mode is used, lines are appended to the file: >
12681 :call writefile(["foo"], "event.log", "a")
12682 :call writefile(["bar"], "event.log", "a")
12683<
12684 'D' Delete the file when the current function ends. This
12685 works like: >
Bram Moolenaar938ae282023-02-20 20:44:55 +000012686 :defer delete({fname})
Bram Moolenaar806a2732022-09-04 15:40:36 +010012687< Fails when not in a function. Also see |:defer|.
12688
12689 's' fsync() is called after writing the file. This flushes
12690 the file to disk, if possible. This takes more time but
12691 avoids losing the file if the system crashes.
12692
12693 'S' fsync() is not called, even when 'fsync' is set.
12694
12695 When {flags} does not contain "S" or "s" then fsync() is
12696 called if the 'fsync' option is set.
12697
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012698 An existing file is overwritten, if possible.
Bram Moolenaar806a2732022-09-04 15:40:36 +010012699
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012700 When the write fails -1 is returned, otherwise 0. There is an
12701 error message if the file can't be created or when writing
12702 fails.
Bram Moolenaar806a2732022-09-04 15:40:36 +010012703
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012704 Also see |readfile()|.
12705 To copy a file byte for byte: >
12706 :let fl = readfile("foo", "b")
12707 :call writefile(fl, "foocopy", "b")
12708
12709< Can also be used as a |method|: >
12710 GetText()->writefile("thefile")
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012711<
12712 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012713
12714
12715xor({expr}, {expr}) *xor()*
12716 Bitwise XOR on the two arguments. The arguments are converted
12717 to a number. A List, Dict or Float argument causes an error.
Bram Moolenaar5a6ec102022-05-27 21:58:00 +010012718 Also see `and()` and `or()`.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012719 Example: >
12720 :let bits = xor(bits, 0x80)
12721<
12722 Can also be used as a |method|: >
12723 :let bits = bits->xor(0x80)
12724<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012725 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012726
12727==============================================================================
127283. Feature list *feature-list*
12729
12730There are three types of features:
127311. Features that are only supported when they have been enabled when Vim
12732 was compiled |+feature-list|. Example: >
12733 :if has("cindent")
12734< *gui_running*
127352. Features that are only supported when certain conditions have been met.
12736 Example: >
12737 :if has("gui_running")
12738< *has-patch*
127393. Beyond a certain version or at a certain version and including a specific
12740 patch. The "patch-7.4.248" feature means that the Vim version is 7.5 or
12741 later, or it is version 7.4 and patch 248 was included. Example: >
12742 :if has("patch-7.4.248")
12743< Note that it's possible for patch 248 to be omitted even though 249 is
12744 included. Only happens when cherry-picking patches.
12745 Note that this form only works for patch 7.4.237 and later, before that
12746 you need to check for the patch and the v:version. Example (checking
12747 version 6.2.148 or later): >
12748 :if v:version > 602 || (v:version == 602 && has("patch148"))
12749
12750Hint: To find out if Vim supports backslashes in a file name (MS-Windows),
12751use: `if exists('+shellslash')`
12752
12753
12754acl Compiled with |ACL| support.
Bram Moolenaar2ee347f2022-08-26 17:53:44 +010012755all_builtin_terms Compiled with all builtin terminals enabled. (always
12756 true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012757amiga Amiga version of Vim.
12758arabic Compiled with Arabic support |Arabic|.
12759arp Compiled with ARP support (Amiga).
12760autocmd Compiled with autocommand support. (always true)
12761autochdir Compiled with support for 'autochdir'
12762autoservername Automatically enable |clientserver|
12763balloon_eval Compiled with |balloon-eval| support.
12764balloon_multiline GUI supports multiline balloons.
12765beos BeOS version of Vim.
12766browse Compiled with |:browse| support, and browse() will
12767 work.
12768browsefilter Compiled with support for |browsefilter|.
12769bsd Compiled on an OS in the BSD family (excluding macOS).
Bram Moolenaar2ee347f2022-08-26 17:53:44 +010012770builtin_terms Compiled with some builtin terminals. (always true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012771byte_offset Compiled with support for 'o' in 'statusline'
12772channel Compiled with support for |channel| and |job|
Bram Moolenaare1dc76f2022-06-25 18:01:32 +010012773cindent Compiled with 'cindent' support. (always true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012774clientserver Compiled with remote invocation support |clientserver|.
12775clipboard Compiled with 'clipboard' support.
12776clipboard_working Compiled with 'clipboard' support and it can be used.
12777cmdline_compl Compiled with |cmdline-completion| support.
12778cmdline_hist Compiled with |cmdline-history| support.
12779cmdline_info Compiled with 'showcmd' and 'ruler' support.
12780comments Compiled with |'comments'| support.
12781compatible Compiled to be very Vi compatible.
12782conpty Platform where |ConPTY| can be used.
12783cryptv Compiled with encryption support |encryption|.
12784cscope Compiled with |cscope| support.
12785cursorbind Compiled with |'cursorbind'| (always true)
12786debug Compiled with "DEBUG" defined.
12787dialog_con Compiled with console dialog support.
glepnirdf461152024-04-04 22:23:29 +020012788dialog_con_gui Compiled with console and GUI dialog support.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012789dialog_gui Compiled with GUI dialog support.
12790diff Compiled with |vimdiff| and 'diff' support.
12791digraphs Compiled with support for digraphs.
12792directx Compiled with support for DirectX and 'renderoptions'.
12793dnd Compiled with support for the "~ register |quote_~|.
12794drop_file Compiled with |drop_file| support.
12795ebcdic Compiled on a machine with ebcdic character set.
12796emacs_tags Compiled with support for Emacs tags.
12797eval Compiled with expression evaluation support. Always
12798 true, of course!
12799ex_extra |+ex_extra| (always true)
12800extra_search Compiled with support for |'incsearch'| and
12801 |'hlsearch'|
12802farsi Support for Farsi was removed |farsi|.
Bram Moolenaarf80f40a2022-08-25 16:02:23 +010012803file_in_path Compiled with support for |gf| and |<cfile>| (always
12804 true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012805filterpipe When 'shelltemp' is off pipes are used for shell
12806 read/write/filter commands
12807find_in_path Compiled with support for include file searches
12808 |+find_in_path|.
12809float Compiled with support for |Float|.
12810fname_case Case in file names matters (for Amiga and MS-Windows
12811 this is not present).
12812folding Compiled with |folding| support.
12813footer Compiled with GUI footer support. |gui-footer|
12814fork Compiled to use fork()/exec() instead of system().
12815gettext Compiled with message translation |multi-lang|
12816gui Compiled with GUI enabled.
Bram Moolenaarcbaff5e2022-04-08 17:45:08 +010012817gui_athena Compiled with Athena GUI (always false).
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012818gui_gnome Compiled with Gnome support (gui_gtk is also defined).
12819gui_gtk Compiled with GTK+ GUI (any version).
12820gui_gtk2 Compiled with GTK+ 2 GUI (gui_gtk is also defined).
12821gui_gtk3 Compiled with GTK+ 3 GUI (gui_gtk is also defined).
12822gui_haiku Compiled with Haiku GUI.
12823gui_mac Compiled with Macintosh GUI.
12824gui_motif Compiled with Motif GUI.
12825gui_photon Compiled with Photon GUI.
12826gui_running Vim is running in the GUI, or it will start soon.
12827gui_win32 Compiled with MS-Windows Win32 GUI.
12828gui_win32s idem, and Win32s system being used (Windows 3.1)
12829haiku Haiku version of Vim.
12830hangul_input Compiled with Hangul input support. |hangul|
12831hpux HP-UX version of Vim.
Zhaoming Luoa41dfcd2025-02-06 21:39:35 +010012832hurd GNU/Hurd version of Vim
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012833iconv Can use iconv() for conversion.
12834insert_expand Compiled with support for CTRL-X expansion commands in
12835 Insert mode. (always true)
12836job Compiled with support for |channel| and |job|
12837ipv6 Compiled with support for IPv6 networking in |channel|.
Bram Moolenaare1dc76f2022-06-25 18:01:32 +010012838jumplist Compiled with |jumplist| support. (always true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012839keymap Compiled with 'keymap' support.
12840lambda Compiled with |lambda| support.
12841langmap Compiled with 'langmap' support.
12842libcall Compiled with |libcall()| support.
12843linebreak Compiled with 'linebreak', 'breakat', 'showbreak' and
12844 'breakindent' support.
12845linux Linux version of Vim.
12846lispindent Compiled with support for lisp indenting.
Bram Moolenaare1dc76f2022-06-25 18:01:32 +010012847 (always true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012848listcmds Compiled with commands for the buffer list |:files|
12849 and the argument list |arglist|.
12850localmap Compiled with local mappings and abbr. |:map-local|
12851lua Compiled with Lua interface |Lua|.
12852mac Any Macintosh version of Vim cf. osx
12853macunix Synonym for osxdarwin
12854menu Compiled with support for |:menu|.
12855mksession Compiled with support for |:mksession|.
12856modify_fname Compiled with file name modifiers. |filename-modifiers|
12857 (always true)
12858mouse Compiled with support for mouse.
12859mouse_dec Compiled with support for Dec terminal mouse.
12860mouse_gpm Compiled with support for gpm (Linux console mouse)
12861mouse_gpm_enabled GPM mouse is working
12862mouse_netterm Compiled with support for netterm mouse.
12863mouse_pterm Compiled with support for qnx pterm mouse.
12864mouse_sysmouse Compiled with support for sysmouse (*BSD console mouse)
12865mouse_sgr Compiled with support for sgr mouse.
12866mouse_urxvt Compiled with support for urxvt mouse.
12867mouse_xterm Compiled with support for xterm mouse.
12868mouseshape Compiled with support for 'mouseshape'.
12869multi_byte Compiled with support for 'encoding' (always true)
12870multi_byte_encoding 'encoding' is set to a multibyte encoding.
12871multi_byte_ime Compiled with support for IME input method.
12872multi_lang Compiled with support for multiple languages.
12873mzscheme Compiled with MzScheme interface |mzscheme|.
12874nanotime Compiled with sub-second time stamp checks.
12875netbeans_enabled Compiled with support for |netbeans| and connected.
12876netbeans_intg Compiled with support for |netbeans|.
Bram Moolenaare1dc76f2022-06-25 18:01:32 +010012877num64 Compiled with 64-bit |Number| support. (always true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012878ole Compiled with OLE automation support for Win32.
12879osx Compiled for macOS cf. mac
12880osxdarwin Compiled for macOS, with |mac-darwin-feature|
12881packages Compiled with |packages| support.
12882path_extra Compiled with up/downwards search in 'path' and 'tags'
12883perl Compiled with Perl interface.
12884persistent_undo Compiled with support for persistent undo history.
12885postscript Compiled with PostScript file printing.
12886printer Compiled with |:hardcopy| support.
12887profile Compiled with |:profile| support.
Bram Moolenaar71badf92023-04-22 22:40:14 +010012888prof_nsec Profile results are in nanoseconds.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012889python Python 2.x interface available. |has-python|
12890python_compiled Compiled with Python 2.x interface. |has-python|
12891python_dynamic Python 2.x interface is dynamically loaded. |has-python|
12892python3 Python 3.x interface available. |has-python|
12893python3_compiled Compiled with Python 3.x interface. |has-python|
12894python3_dynamic Python 3.x interface is dynamically loaded. |has-python|
Yee Cheng Chinc13b3d12023-08-20 21:18:38 +020012895python3_stable Python 3.x interface is using Python Stable ABI. |has-python|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012896pythonx Python 2.x and/or 3.x interface available. |python_x|
12897qnx QNX version of Vim.
12898quickfix Compiled with |quickfix| support.
12899reltime Compiled with |reltime()| support.
12900rightleft Compiled with 'rightleft' support.
12901ruby Compiled with Ruby interface |ruby|.
12902scrollbind Compiled with 'scrollbind' support. (always true)
12903showcmd Compiled with 'showcmd' support.
12904signs Compiled with |:sign| support.
Bram Moolenaare1dc76f2022-06-25 18:01:32 +010012905smartindent Compiled with 'smartindent' support. (always true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012906sodium Compiled with libsodium for better crypt support
12907sound Compiled with sound support, e.g. `sound_playevent()`
12908spell Compiled with spell checking support |spell|.
12909startuptime Compiled with |--startuptime| support.
12910statusline Compiled with support for 'statusline', 'rulerformat'
12911 and special formats of 'titlestring' and 'iconstring'.
12912sun SunOS version of Vim.
12913sun_workshop Support for Sun |workshop| has been removed.
12914syntax Compiled with syntax highlighting support |syntax|.
12915syntax_items There are active syntax highlighting items for the
12916 current buffer.
12917system Compiled to use system() instead of fork()/exec().
12918tag_binary Compiled with binary searching in tags files
Bram Moolenaare1dc76f2022-06-25 18:01:32 +010012919 |tag-binary-search|. (always true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012920tag_old_static Support for old static tags was removed, see
12921 |tag-old-static|.
12922tcl Compiled with Tcl interface.
12923termguicolors Compiled with true color in terminal support.
12924terminal Compiled with |terminal| support.
12925terminfo Compiled with terminfo instead of termcap.
12926termresponse Compiled with support for |t_RV| and |v:termresponse|.
12927textobjects Compiled with support for |text-objects|.
12928textprop Compiled with support for |text-properties|.
12929tgetent Compiled with tgetent support, able to use a termcap
12930 or terminfo file.
12931timers Compiled with |timer_start()| support.
12932title Compiled with window title support |'title'|.
Bram Moolenaare1dc76f2022-06-25 18:01:32 +010012933 (always true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012934toolbar Compiled with support for |gui-toolbar|.
12935ttyin input is a terminal (tty)
12936ttyout output is a terminal (tty)
12937unix Unix version of Vim. *+unix*
12938unnamedplus Compiled with support for "unnamedplus" in 'clipboard'
12939user_commands User-defined commands. (always true)
12940vartabs Compiled with variable tabstop support |'vartabstop'|.
12941vcon Win32: Virtual console support is working, can use
12942 'termguicolors'. Also see |+vtp|.
12943vertsplit Compiled with vertically split windows |:vsplit|.
12944 (always true)
12945vim_starting True while initial source'ing takes place. |startup|
12946 *vim_starting*
Bram Moolenaara6feb162022-01-02 12:06:33 +000012947vim9script Compiled with |Vim9| script support
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012948viminfo Compiled with viminfo support.
12949vimscript-1 Compiled Vim script version 1 support
12950vimscript-2 Compiled Vim script version 2 support
12951vimscript-3 Compiled Vim script version 3 support
Bram Moolenaar8a3b8052022-06-26 12:21:15 +010012952vimscript-4 Compiled Vim script version 4 support
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012953virtualedit Compiled with 'virtualedit' option. (always true)
12954visual Compiled with Visual mode. (always true)
12955visualextra Compiled with extra Visual mode commands. (always
12956 true) |blockwise-operators|.
12957vms VMS version of Vim.
12958vreplace Compiled with |gR| and |gr| commands. (always true)
12959vtp Compiled for vcon support |+vtp| (check vcon to find
12960 out if it works in the current console).
12961wildignore Compiled with 'wildignore' option.
12962wildmenu Compiled with 'wildmenu' option.
12963win16 old version for MS-Windows 3.1 (always false)
12964win32 Win32 version of Vim (MS-Windows 95 and later, 32 or
12965 64 bits)
12966win32unix Win32 version of Vim, using Unix files (Cygwin)
12967win64 Win64 version of Vim (MS-Windows 64 bit).
12968win95 Win32 version for MS-Windows 95/98/ME (always false)
12969winaltkeys Compiled with 'winaltkeys' option.
12970windows Compiled with support for more than one window.
12971 (always true)
12972writebackup Compiled with 'writebackup' default on.
Christian Brabandte085dfd2023-09-30 12:49:18 +020012973xattr Compiled with extended attributes support |xattr|
12974 (currently only supported on Linux).
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012975xfontset Compiled with X fontset support |xfontset|.
12976xim Compiled with X input method support |xim|.
12977xpm Compiled with pixmap support.
12978xpm_w32 Compiled with pixmap support for Win32. (Only for
12979 backward compatibility. Use "xpm" instead.)
12980xsmp Compiled with X session management support.
12981xsmp_interact Compiled with interactive X session management support.
12982xterm_clipboard Compiled with support for xterm clipboard.
12983xterm_save Compiled with support for saving and restoring the
12984 xterm screen.
12985x11 Compiled with X11 support.
12986
12987
12988==============================================================================
129894. Matching a pattern in a String *string-match*
12990
12991This is common between several functions. A regexp pattern as explained at
12992|pattern| is normally used to find a match in the buffer lines. When a
12993pattern is used to find a match in a String, almost everything works in the
12994same way. The difference is that a String is handled like it is one line.
12995When it contains a "\n" character, this is not seen as a line break for the
12996pattern. It can be matched with a "\n" in the pattern, or with ".". Example:
12997>
12998 :let a = "aaaa\nxxxx"
12999 :echo matchstr(a, "..\n..")
13000 aa
13001 xx
13002 :echo matchstr(a, "a.x")
13003 a
13004 x
13005
13006Don't forget that "^" will only match at the first character of the String and
13007"$" at the last character of the string. They don't match after or before a
13008"\n".
13009
13010 vim:tw=78:ts=8:noet:ft=help:norl: