blob: a34c63aebc4634d1b2ad27cf20ba9148ba7f949f [file] [log] [blame]
zeertzjq6655bef2025-01-06 18:32:13 +01001*builtin.txt* For Vim version 9.1. Last change: 2025 Jan 06
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
75browse({save}, {title}, {initdir}, {default})
76 String put up a file requester
77browsedir({title}, {initdir}) String put up a directory requester
78bufadd({name}) Number add a buffer to the buffer list
79bufexists({buf}) Number |TRUE| if buffer {buf} exists
80buflisted({buf}) Number |TRUE| if buffer {buf} is listed
81bufload({buf}) Number load buffer {buf} if not loaded yet
82bufloaded({buf}) Number |TRUE| if buffer {buf} is loaded
83bufname([{buf}]) String Name of the buffer {buf}
84bufnr([{buf} [, {create}]]) Number Number of the buffer {buf}
85bufwinid({buf}) Number window ID of buffer {buf}
86bufwinnr({buf}) Number window number of buffer {buf}
87byte2line({byte}) Number line number at byte count {byte}
Christian Brabandt67672ef2023-04-24 21:09:54 +010088byteidx({expr}, {nr} [, {utf16}])
89 Number byte index of {nr}'th char in {expr}
90byteidxcomp({expr}, {nr} [, {utf16}])
91 Number byte index of {nr}'th char in {expr}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000092call({func}, {arglist} [, {dict}])
93 any call {func} with arguments {arglist}
94ceil({expr}) Float round {expr} up
95ch_canread({handle}) Number check if there is something to read
96ch_close({handle}) none close {handle}
97ch_close_in({handle}) none close in part of {handle}
98ch_evalexpr({handle}, {expr} [, {options}])
99 any evaluate {expr} on JSON {handle}
100ch_evalraw({handle}, {string} [, {options}])
101 any evaluate {string} on raw {handle}
102ch_getbufnr({handle}, {what}) Number get buffer number for {handle}/{what}
103ch_getjob({channel}) Job get the Job of {channel}
104ch_info({handle}) String info about channel {handle}
105ch_log({msg} [, {handle}]) none write {msg} in the channel log file
106ch_logfile({fname} [, {mode}]) none start logging channel activity
107ch_open({address} [, {options}])
108 Channel open a channel to {address}
109ch_read({handle} [, {options}]) String read from {handle}
110ch_readblob({handle} [, {options}])
111 Blob read Blob from {handle}
112ch_readraw({handle} [, {options}])
113 String read raw from {handle}
114ch_sendexpr({handle}, {expr} [, {options}])
115 any send {expr} over JSON {handle}
116ch_sendraw({handle}, {expr} [, {options}])
117 any send {expr} over raw {handle}
118ch_setoptions({handle}, {options})
119 none set options for {handle}
120ch_status({handle} [, {options}])
121 String status of channel {handle}
122changenr() Number current change number
123char2nr({expr} [, {utf8}]) Number ASCII/UTF-8 value of first char in {expr}
124charclass({string}) Number character class of {string}
Yegappan Lakshmanan4c8d2f02022-11-12 16:07:47 +0000125charcol({expr} [, {winid}]) Number column number of cursor or mark
Christian Brabandt67672ef2023-04-24 21:09:54 +0100126charidx({string}, {idx} [, {countcc} [, {utf16}]])
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000127 Number char index of byte {idx} in {string}
128chdir({dir}) String change current working directory
129cindent({lnum}) Number C indent for line {lnum}
130clearmatches([{win}]) none clear all matches
Yegappan Lakshmanan4c8d2f02022-11-12 16:07:47 +0000131col({expr} [, {winid}]) Number column byte index of cursor or mark
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000132complete({startcol}, {matches}) none set Insert mode completion
133complete_add({expr}) Number add completion match
134complete_check() Number check for key typed during completion
135complete_info([{what}]) Dict get current completion information
136confirm({msg} [, {choices} [, {default} [, {type}]]])
137 Number number of choice picked by user
138copy({expr}) any make a shallow copy of {expr}
139cos({expr}) Float cosine of {expr}
140cosh({expr}) Float hyperbolic cosine of {expr}
141count({comp}, {expr} [, {ic} [, {start}]])
142 Number count how many {expr} are in {comp}
143cscope_connection([{num}, {dbpath} [, {prepend}]])
144 Number checks existence of cscope connection
145cursor({lnum}, {col} [, {off}])
146 Number move cursor to {lnum}, {col}, {off}
147cursor({list}) Number move cursor to position in {list}
148debugbreak({pid}) Number interrupt process being debugged
149deepcopy({expr} [, {noref}]) any make a full copy of {expr}
150delete({fname} [, {flags}]) Number delete the file or directory {fname}
151deletebufline({buf}, {first} [, {last}])
152 Number delete lines from buffer {buf}
153did_filetype() Number |TRUE| if FileType autocmd event used
Yegappan Lakshmananfa378352024-02-01 22:05:27 +0100154diff({fromlist}, {tolist} [, {options}])
155 List diff two Lists of strings
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000156diff_filler({lnum}) Number diff filler lines about {lnum}
157diff_hlID({lnum}, {col}) Number diff highlighting at {lnum}/{col}
158digraph_get({chars}) String get the |digraph| of {chars}
159digraph_getlist([{listall}]) List get all |digraph|s
Christian Brabandtfbc37f12024-06-18 20:50:58 +0200160digraph_set({chars}, {digraph}) Bool register |digraph|
161digraph_setlist({digraphlist}) Bool register multiple |digraph|s
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000162echoraw({expr}) none output {expr} as-is
163empty({expr}) Number |TRUE| if {expr} is empty
164environ() Dict return environment variables
Sean Dewarb0efa492023-07-08 10:35:19 +0100165err_teapot([{expr}]) none give E418, or E503 if {expr} is |TRUE|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000166escape({string}, {chars}) String escape {chars} in {string} with '\'
167eval({string}) any evaluate {string} into its value
168eventhandler() Number |TRUE| if inside an event handler
169executable({expr}) Number 1 if executable {expr} exists
170execute({command}) String execute {command} and get the output
171exepath({expr}) String full path of the command {expr}
172exists({expr}) Number |TRUE| if {expr} exists
173exists_compiled({expr}) Number |TRUE| if {expr} exists at compile time
174exp({expr}) Float exponential of {expr}
175expand({expr} [, {nosuf} [, {list}]])
176 any expand special keywords in {expr}
Yegappan Lakshmanan2b74b682022-04-03 21:30:32 +0100177expandcmd({string} [, {options}])
178 String expand {string} like with `:edit`
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000179extend({expr1}, {expr2} [, {expr3}])
180 List/Dict insert items of {expr2} into {expr1}
181extendnew({expr1}, {expr2} [, {expr3}])
182 List/Dict like |extend()| but creates a new
183 List or Dictionary
184feedkeys({string} [, {mode}]) Number add key sequence to typeahead buffer
Shougo Matsushita60c87432024-06-03 22:59:27 +0200185filecopy({from}, {to}) Number |TRUE| if copying file {from} to {to}
186 worked
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000187filereadable({file}) Number |TRUE| if {file} is a readable file
188filewritable({file}) Number |TRUE| if {file} is a writable file
189filter({expr1}, {expr2}) List/Dict/Blob/String
190 remove items from {expr1} where
191 {expr2} is 0
192finddir({name} [, {path} [, {count}]])
193 String find directory {name} in {path}
194findfile({name} [, {path} [, {count}]])
195 String find file {name} in {path}
196flatten({list} [, {maxdepth}]) List flatten {list} up to {maxdepth} levels
197flattennew({list} [, {maxdepth}])
198 List flatten a copy of {list}
199float2nr({expr}) Number convert Float {expr} to a Number
200floor({expr}) Float round {expr} down
201fmod({expr1}, {expr2}) Float remainder of {expr1} / {expr2}
202fnameescape({fname}) String escape special characters in {fname}
203fnamemodify({fname}, {mods}) String modify file name
204foldclosed({lnum}) Number first line of fold at {lnum} if closed
205foldclosedend({lnum}) Number last line of fold at {lnum} if closed
206foldlevel({lnum}) Number fold level at {lnum}
207foldtext() String line displayed for closed fold
208foldtextresult({lnum}) String text for closed fold at {lnum}
Ernie Raele79e2072024-01-13 11:47:33 +0100209foreach({expr1}, {expr2}) List/Dict/Blob/String
210 for each item in {expr1} call {expr2}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000211foreground() Number bring the Vim window to the foreground
Bram Moolenaaraa534142022-09-15 21:46:02 +0100212fullcommand({name} [, {vim9}]) String get full command from {name}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000213funcref({name} [, {arglist}] [, {dict}])
214 Funcref reference to function {name}
215function({name} [, {arglist}] [, {dict}])
216 Funcref named reference to function {name}
217garbagecollect([{atexit}]) none free memory, breaking cyclic references
218get({list}, {idx} [, {def}]) any get item {idx} from {list} or {def}
219get({dict}, {key} [, {def}]) any get item {key} from {dict} or {def}
220get({func}, {what}) any get property of funcref/partial {func}
221getbufinfo([{buf}]) List information about buffers
222getbufline({buf}, {lnum} [, {end}])
223 List lines {lnum} to {end} of buffer {buf}
Bram Moolenaarce30ccc2022-11-21 19:57:04 +0000224getbufoneline({buf}, {lnum}) String line {lnum} of buffer {buf}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000225getbufvar({buf}, {varname} [, {def}])
226 any variable {varname} in buffer {buf}
mikoto20001083cae2024-11-11 21:24:14 +0100227getcellpixels() List get character cell pixel size
Kota Kato66bb9ae2023-01-17 18:31:56 +0000228getcellwidths() List get character cell width overrides
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000229getchangelist([{buf}]) List list of change list items
Doug Kearns9cd9e752024-04-07 17:42:17 +0200230getchar([{expr}]) Number or String
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000231 get one character from the user
232getcharmod() Number modifiers for the last typed character
233getcharpos({expr}) List position of cursor, mark, etc.
234getcharsearch() Dict last character search
Doug Kearns9cd9e752024-04-07 17:42:17 +0200235getcharstr([{expr}]) String get one character from the user
Ruslan Russkikh0407d622024-10-08 22:21:05 +0200236getcmdcomplpat() String return the completion pattern of the
237 current command-line completion
Shougo Matsushita79d599b2022-05-07 12:48:29 +0100238getcmdcompltype() String return the type of the current
239 command-line completion
Shougo Matsushita69084282024-09-23 20:34:47 +0200240getcmdline() String return the current command-line input
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000241getcmdpos() Number return cursor position in command-line
Shougo Matsushita69084282024-09-23 20:34:47 +0200242getcmdprompt() String return the current command-line prompt
Shougo Matsushita79d599b2022-05-07 12:48:29 +0100243getcmdscreenpos() Number return cursor screen position in
244 command-line
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000245getcmdtype() String return current command-line type
246getcmdwintype() String return current command-line window type
247getcompletion({pat}, {type} [, {filtered}])
248 List list of cmdline completion matches
249getcurpos([{winnr}]) List position of the cursor
250getcursorcharpos([{winnr}]) List character position of the cursor
251getcwd([{winnr} [, {tabnr}]]) String get the current working directory
252getenv({name}) String return environment variable
253getfontname([{name}]) String name of font being used
254getfperm({fname}) String file permissions of file {fname}
255getfsize({fname}) Number size in bytes of file {fname}
256getftime({fname}) Number last modification time of file
257getftype({fname}) String description of type of file {fname}
258getimstatus() Number |TRUE| if the IME status is active
259getjumplist([{winnr} [, {tabnr}]])
260 List list of jump list items
261getline({lnum}) String line {lnum} of current buffer
262getline({lnum}, {end}) List lines {lnum} to {end} of current buffer
263getloclist({nr}) List list of location list items
264getloclist({nr}, {what}) Dict get specific location list properties
265getmarklist([{buf}]) List list of global/local marks
266getmatches([{win}]) List list of current matches
267getmousepos() Dict last known mouse position
Bram Moolenaar24dc19c2022-11-14 19:49:15 +0000268getmouseshape() String current mouse shape name
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000269getpid() Number process ID of Vim
270getpos({expr}) List position of cursor, mark, etc.
271getqflist() List list of quickfix items
272getqflist({what}) Dict get specific quickfix list properties
273getreg([{regname} [, 1 [, {list}]]])
274 String or List contents of a register
275getreginfo([{regname}]) Dict information about a register
Shougo Matsushita19b71882024-02-28 22:48:12 +0100276getregion({pos1}, {pos2} [, {opts}])
Shougo Matsushita3f905ab2024-02-21 00:02:45 +0100277 List get the text from {pos1} to {pos2}
Shougo Matsushitab4757e62024-05-07 20:49:24 +0200278getregionpos({pos1}, {pos2} [, {opts}])
279 List get a list of positions for a region
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000280getregtype([{regname}]) String type of a register
Yegappan Lakshmanan520f6ef2022-08-25 17:40:40 +0100281getscriptinfo([{opts}]) List list of sourced scripts
ichizok663d18d2025-01-02 18:06:00 +0100282getstacktrace() List get current stack trace of Vim scripts
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000283gettabinfo([{expr}]) List list of tab pages
284gettabvar({nr}, {varname} [, {def}])
285 any variable {varname} in tab {nr} or {def}
286gettabwinvar({tabnr}, {winnr}, {name} [, {def}])
287 any {name} in {winnr} in tab page {tabnr}
288gettagstack([{nr}]) Dict get the tag stack of window {nr}
h-east52e7cc22024-07-28 17:03:29 +0200289gettext({text} [, {package}]) String lookup translation of {text}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000290getwininfo([{winid}]) List list of info about each window
Bram Moolenaar938ae282023-02-20 20:44:55 +0000291getwinpos([{timeout}]) List X and Y coord in pixels of Vim window
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000292getwinposx() Number X coord in pixels of the Vim window
293getwinposy() Number Y coord in pixels of the Vim window
294getwinvar({nr}, {varname} [, {def}])
295 any variable {varname} in window {nr}
296glob({expr} [, {nosuf} [, {list} [, {alllinks}]]])
297 any expand file wildcards in {expr}
298glob2regpat({expr}) String convert a glob pat into a search pat
299globpath({path}, {expr} [, {nosuf} [, {list} [, {alllinks}]]])
300 String do glob({expr}) for all dirs in {path}
301has({feature} [, {check}]) Number |TRUE| if feature {feature} supported
302has_key({dict}, {key}) Number |TRUE| if {dict} has entry {key}
303haslocaldir([{winnr} [, {tabnr}]])
304 Number |TRUE| if the window executed |:lcd|
305 or |:tcd|
306hasmapto({what} [, {mode} [, {abbr}]])
307 Number |TRUE| if mapping to {what} exists
308histadd({history}, {item}) Number add an item to a history
309histdel({history} [, {item}]) Number remove an item from a history
310histget({history} [, {index}]) String get the item {index} from a history
311histnr({history}) Number highest index of a history
312hlID({name}) Number syntax ID of highlight group {name}
313hlexists({name}) Number |TRUE| if highlight group {name} exists
314hlget([{name} [, {resolve}]]) List get highlight group attributes
315hlset({list}) Number set highlight group attributes
316hostname() String name of the machine Vim is running on
317iconv({expr}, {from}, {to}) String convert encoding of {expr}
Ernie Rael05124252024-07-11 22:10:45 +0200318id({item}) String get unique identity string of item
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000319indent({lnum}) Number indent of line {lnum}
320index({object}, {expr} [, {start} [, {ic}]])
321 Number index in {object} where {expr} appears
Yegappan Lakshmananb2186552022-08-13 13:09:20 +0100322indexof({object}, {expr} [, {opts}]])
323 Number index in {object} where {expr} is true
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000324input({prompt} [, {text} [, {completion}]])
325 String get input from the user
Bram Moolenaarb529cfb2022-07-25 15:42:07 +0100326inputdialog({prompt} [, {text} [, {cancelreturn}]])
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000327 String like input() but in a GUI dialog
328inputlist({textlist}) Number let the user pick from a choice list
329inputrestore() Number restore typeahead
330inputsave() Number save and clear typeahead
331inputsecret({prompt} [, {text}]) String like input() but hiding the text
332insert({object}, {item} [, {idx}]) List insert {item} in {object} [before {idx}]
LemonBoyafe04662023-08-23 21:08:11 +0200333instanceof({object}, {class}) Number |TRUE| if {object} is an instance of {class}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000334interrupt() none interrupt script execution
335invert({expr}) Number bitwise invert
LemonBoydca1d402022-04-28 15:26:33 +0100336isabsolutepath({path}) Number |TRUE| if {path} is an absolute path
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000337isdirectory({directory}) Number |TRUE| if {directory} is a directory
338isinf({expr}) Number determine if {expr} is infinity value
339 (positive or negative)
340islocked({expr}) Number |TRUE| if {expr} is locked
341isnan({expr}) Number |TRUE| if {expr} is NaN
342items({dict}) List key-value pairs in {dict}
343job_getchannel({job}) Channel get the channel handle for {job}
344job_info([{job}]) Dict get information about {job}
345job_setoptions({job}, {options}) none set options for {job}
346job_start({command} [, {options}])
347 Job start a job
348job_status({job}) String get the status of {job}
349job_stop({job} [, {how}]) Number stop {job}
350join({list} [, {sep}]) String join {list} items into one String
351js_decode({string}) any decode JS style JSON
352js_encode({expr}) String encode JS style JSON
353json_decode({string}) any decode JSON
354json_encode({expr}) String encode JSON
355keys({dict}) List keys in {dict}
zeertzjqcdc83932022-09-12 13:38:41 +0100356keytrans({string}) String translate internal keycodes to a form
357 that can be used by |:map|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000358len({expr}) Number the length of {expr}
359libcall({lib}, {func}, {arg}) String call {func} in library {lib} with {arg}
360libcallnr({lib}, {func}, {arg}) Number idem, but return a Number
361line({expr} [, {winid}]) Number line nr of cursor, last line or mark
362line2byte({lnum}) Number byte count of line {lnum}
363lispindent({lnum}) Number Lisp indent for line {lnum}
364list2blob({list}) Blob turn {list} of numbers into a Blob
365list2str({list} [, {utf8}]) String turn {list} of numbers into a String
366listener_add({callback} [, {buf}])
367 Number add a callback to listen to changes
368listener_flush([{buf}]) none invoke listener callbacks
369listener_remove({id}) none remove a listener callback
370localtime() Number current time
371log({expr}) Float natural logarithm (base e) of {expr}
372log10({expr}) Float logarithm of Float {expr} to base 10
373luaeval({expr} [, {expr}]) any evaluate |Lua| expression
374map({expr1}, {expr2}) List/Dict/Blob/String
375 change each item in {expr1} to {expr2}
376maparg({name} [, {mode} [, {abbr} [, {dict}]]])
377 String or Dict
378 rhs of mapping {name} in mode {mode}
379mapcheck({name} [, {mode} [, {abbr}]])
380 String check for mappings matching {name}
Ernie Rael09661202022-04-25 14:40:44 +0100381maplist([{abbr}]) List list of all mappings, a dict for each
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000382mapnew({expr1}, {expr2}) List/Dict/Blob/String
383 like |map()| but creates a new List or
384 Dictionary
385mapset({mode}, {abbr}, {dict}) none restore mapping from |maparg()| result
386match({expr}, {pat} [, {start} [, {count}]])
387 Number position where {pat} matches in {expr}
388matchadd({group}, {pattern} [, {priority} [, {id} [, {dict}]]])
389 Number highlight {pattern} with {group}
390matchaddpos({group}, {pos} [, {priority} [, {id} [, {dict}]]])
391 Number highlight positions with {group}
392matcharg({nr}) List arguments of |:match|
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +0100393matchbufline({buf}, {pat}, {lnum}, {end}, [, {dict})
394 List all the {pat} matches in buffer {buf}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000395matchdelete({id} [, {win}]) Number delete match identified by {id}
396matchend({expr}, {pat} [, {start} [, {count}]])
397 Number position where {pat} ends in {expr}
398matchfuzzy({list}, {str} [, {dict}])
399 List fuzzy match {str} in {list}
400matchfuzzypos({list}, {str} [, {dict}])
401 List fuzzy match {str} in {list}
402matchlist({expr}, {pat} [, {start} [, {count}]])
403 List match and submatches of {pat} in {expr}
404matchstr({expr}, {pat} [, {start} [, {count}]])
405 String {count}'th match of {pat} in {expr}
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +0100406matchstrlist({list}, {pat} [, {dict})
407 List all the {pat} matches in {list}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000408matchstrpos({expr}, {pat} [, {start} [, {count}]])
409 List {count}'th match of {pat} in {expr}
410max({expr}) Number maximum value of items in {expr}
411menu_info({name} [, {mode}]) Dict get menu item information
412min({expr}) Number minimum value of items in {expr}
Bram Moolenaar938ae282023-02-20 20:44:55 +0000413mkdir({name} [, {flags} [, {prot}]])
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000414 Number create directory {name}
Doug Kearns9cd9e752024-04-07 17:42:17 +0200415mode([{expr}]) String current editing mode
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000416mzeval({expr}) any evaluate |MzScheme| expression
417nextnonblank({lnum}) Number line nr of non-blank line >= {lnum}
418nr2char({expr} [, {utf8}]) String single char with ASCII/UTF-8 value {expr}
419or({expr}, {expr}) Number bitwise OR
420pathshorten({expr} [, {len}]) String shorten directory names in a path
421perleval({expr}) any evaluate |Perl| expression
422popup_atcursor({what}, {options}) Number create popup window near the cursor
423popup_beval({what}, {options}) Number create popup window for 'ballooneval'
424popup_clear() none close all popup windows
425popup_close({id} [, {result}]) none close popup window {id}
426popup_create({what}, {options}) Number create a popup window
427popup_dialog({what}, {options}) Number create a popup window used as a dialog
428popup_filter_menu({id}, {key}) Number filter for a menu popup window
429popup_filter_yesno({id}, {key}) Number filter for a dialog popup window
Bram Moolenaarbdc09a12022-10-07 14:31:45 +0100430popup_findecho() Number get window ID of popup for `:echowin`
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000431popup_findinfo() Number get window ID of info popup window
432popup_findpreview() Number get window ID of preview popup window
433popup_getoptions({id}) Dict get options of popup window {id}
434popup_getpos({id}) Dict get position of popup window {id}
435popup_hide({id}) none hide popup menu {id}
436popup_list() List get a list of window IDs of all popups
437popup_locate({row}, {col}) Number get window ID of popup at position
438popup_menu({what}, {options}) Number create a popup window used as a menu
439popup_move({id}, {options}) none set position of popup window {id}
440popup_notification({what}, {options})
441 Number create a notification popup window
Christian Brabandtfbc37f12024-06-18 20:50:58 +0200442popup_setbuf({id}, {buf}) Bool set the buffer for the popup window {id}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000443popup_setoptions({id}, {options})
444 none set options for popup window {id}
445popup_settext({id}, {text}) none set the text of popup window {id}
446popup_show({id}) none unhide popup window {id}
447pow({x}, {y}) Float {x} to the power of {y}
448prevnonblank({lnum}) Number line nr of non-blank line <= {lnum}
449printf({fmt}, {expr1}...) String format text
450prompt_getprompt({buf}) String get prompt text
451prompt_setcallback({buf}, {expr}) none set prompt callback function
452prompt_setinterrupt({buf}, {text}) none set prompt interrupt function
453prompt_setprompt({buf}, {text}) none set prompt text
454prop_add({lnum}, {col}, {props}) none add one text property
455prop_add_list({props}, [[{lnum}, {col}, {end-lnum}, {end-col}], ...])
456 none add multiple text properties
457prop_clear({lnum} [, {lnum-end} [, {props}]])
458 none remove all text properties
459prop_find({props} [, {direction}])
460 Dict search for a text property
461prop_list({lnum} [, {props}]) List text properties in {lnum}
462prop_remove({props} [, {lnum} [, {lnum-end}]])
463 Number remove a text property
464prop_type_add({name}, {props}) none define a new property type
465prop_type_change({name}, {props})
466 none change an existing property type
467prop_type_delete({name} [, {props}])
468 none delete a property type
469prop_type_get({name} [, {props}])
470 Dict get property type values
471prop_type_list([{props}]) List get list of property types
472pum_getpos() Dict position and size of pum if visible
473pumvisible() Number whether popup menu is visible
zeertzjq7c515282024-11-10 20:26:12 +0100474py3eval({expr} [, {locals}]) any evaluate |python3| expression
475pyeval({expr} [, {locals}]) any evaluate |Python| expression
476pyxeval({expr} [, {locals}]) any evaluate |python_x| expression
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000477rand([{expr}]) Number get pseudo-random number
478range({expr} [, {max} [, {stride}]])
479 List items from {expr} to {max}
K.Takata11df3ae2022-10-19 14:02:40 +0100480readblob({fname} [, {offset} [, {size}]])
481 Blob read a |Blob| from {fname}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000482readdir({dir} [, {expr} [, {dict}]])
483 List file names in {dir} selected by {expr}
484readdirex({dir} [, {expr} [, {dict}]])
485 List file info in {dir} selected by {expr}
486readfile({fname} [, {type} [, {max}]])
487 List get list of lines from file {fname}
488reduce({object}, {func} [, {initial}])
489 any reduce {object} using {func}
490reg_executing() String get the executing register name
491reg_recording() String get the recording register name
492reltime([{start} [, {end}]]) List get time value
493reltimefloat({time}) Float turn the time value into a Float
494reltimestr({time}) String turn time value into a String
495remote_expr({server}, {string} [, {idvar} [, {timeout}]])
496 String send expression
497remote_foreground({server}) Number bring Vim server to the foreground
498remote_peek({serverid} [, {retvar}])
499 Number check for reply string
500remote_read({serverid} [, {timeout}])
501 String read reply string
502remote_send({server}, {string} [, {idvar}])
503 String send key sequence
504remote_startserver({name}) none become server {name}
505remove({list}, {idx} [, {end}]) any/List
506 remove items {idx}-{end} from {list}
507remove({blob}, {idx} [, {end}]) Number/Blob
508 remove bytes {idx}-{end} from {blob}
509remove({dict}, {key}) any remove entry {key} from {dict}
510rename({from}, {to}) Number rename (move) file from {from} to {to}
Bakudankun375141e2022-09-09 18:46:47 +0100511repeat({expr}, {count}) List/Blob/String
512 repeat {expr} {count} times
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000513resolve({filename}) String get filename a shortcut points to
Yegappan Lakshmanan03ff1c22023-05-06 14:08:21 +0100514reverse({obj}) List/Blob/String
515 reverse {obj}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000516round({expr}) Float round off {expr}
517rubyeval({expr}) any evaluate |Ruby| expression
518screenattr({row}, {col}) Number attribute at screen position
519screenchar({row}, {col}) Number character at screen position
520screenchars({row}, {col}) List List of characters at screen position
521screencol() Number current cursor column
522screenpos({winid}, {lnum}, {col}) Dict screen row and col of a text character
523screenrow() Number current cursor row
524screenstring({row}, {col}) String characters at screen position
525search({pattern} [, {flags} [, {stopline} [, {timeout} [, {skip}]]]])
526 Number search for {pattern}
527searchcount([{options}]) Dict get or update search stats
528searchdecl({name} [, {global} [, {thisblock}]])
529 Number search for variable declaration
530searchpair({start}, {middle}, {end} [, {flags} [, {skip} [...]]])
531 Number search for other end of start/end pair
532searchpairpos({start}, {middle}, {end} [, {flags} [, {skip} [...]]])
533 List search for other end of start/end pair
534searchpos({pattern} [, {flags} [, {stopline} [, {timeout} [, {skip}]]]])
535 List search for {pattern}
536server2client({clientid}, {string})
537 Number send reply string
538serverlist() String get a list of available servers
erraelf0837ba2024-06-24 12:27:01 -0700539setbufline({buf}, {lnum}, {text})
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000540 Number set line {lnum} to {text} in buffer
erraelf0837ba2024-06-24 12:27:01 -0700541 {buf}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000542setbufvar({buf}, {varname}, {val})
543 none set {varname} in buffer {buf} to {val}
544setcellwidths({list}) none set character cell width overrides
545setcharpos({expr}, {list}) Number set the {expr} position to {list}
546setcharsearch({dict}) Dict set character search from {dict}
Shougo Matsushita07ea5f12022-08-27 12:22:25 +0100547setcmdline({str} [, {pos}]) Number set command-line
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000548setcmdpos({pos}) Number set cursor position in command-line
549setcursorcharpos({list}) Number move cursor to position in {list}
550setenv({name}, {val}) none set environment variable
551setfperm({fname}, {mode}) Number set {fname} file permissions to {mode}
552setline({lnum}, {line}) Number set line {lnum} to {line}
553setloclist({nr}, {list} [, {action}])
554 Number modify location list using {list}
555setloclist({nr}, {list}, {action}, {what})
556 Number modify specific location list props
557setmatches({list} [, {win}]) Number restore a list of matches
558setpos({expr}, {list}) Number set the {expr} position to {list}
559setqflist({list} [, {action}]) Number modify quickfix list using {list}
560setqflist({list}, {action}, {what})
561 Number modify specific quickfix list props
562setreg({n}, {v} [, {opt}]) Number set register to value and type
563settabvar({nr}, {varname}, {val}) none set {varname} in tab page {nr} to {val}
564settabwinvar({tabnr}, {winnr}, {varname}, {val})
565 none set {varname} in window {winnr} in tab
566 page {tabnr} to {val}
567settagstack({nr}, {dict} [, {action}])
568 Number modify tag stack using {dict}
569setwinvar({nr}, {varname}, {val}) none set {varname} in window {nr} to {val}
570sha256({string}) String SHA256 checksum of {string}
571shellescape({string} [, {special}])
572 String escape {string} for use as shell
573 command argument
574shiftwidth([{col}]) Number effective value of 'shiftwidth'
575sign_define({name} [, {dict}]) Number define or update a sign
576sign_define({list}) List define or update a list of signs
577sign_getdefined([{name}]) List get a list of defined signs
578sign_getplaced([{buf} [, {dict}]])
579 List get a list of placed signs
580sign_jump({id}, {group}, {buf})
581 Number jump to a sign
582sign_place({id}, {group}, {name}, {buf} [, {dict}])
583 Number place a sign
584sign_placelist({list}) List place a list of signs
585sign_undefine([{name}]) Number undefine a sign
586sign_undefine({list}) List undefine a list of signs
587sign_unplace({group} [, {dict}])
588 Number unplace a sign
589sign_unplacelist({list}) List unplace a list of signs
590simplify({filename}) String simplify filename as much as possible
591sin({expr}) Float sine of {expr}
592sinh({expr}) Float hyperbolic sine of {expr}
593slice({expr}, {start} [, {end}]) String, List or Blob
594 slice of a String, List or Blob
Bram Moolenaar2007dd42022-02-23 13:17:47 +0000595sort({list} [, {how} [, {dict}]])
596 List sort {list}, compare with {how}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000597sound_clear() none stop playing all sounds
598sound_playevent({name} [, {callback}])
599 Number play an event sound
600sound_playfile({path} [, {callback}])
601 Number play sound file {path}
602sound_stop({id}) none stop playing sound {id}
603soundfold({word}) String sound-fold {word}
604spellbadword() String badly spelled word at cursor
605spellsuggest({word} [, {max} [, {capital}]])
606 List spelling suggestions
607split({expr} [, {pat} [, {keepempty}]])
608 List make |List| from {pat} separated {expr}
609sqrt({expr}) Float square root of {expr}
610srand([{expr}]) List get seed for |rand()|
611state([{what}]) String current state of Vim
612str2float({expr} [, {quoted}]) Float convert String to Float
613str2list({expr} [, {utf8}]) List convert each character of {expr} to
614 ASCII/UTF-8 value
615str2nr({expr} [, {base} [, {quoted}]])
616 Number convert String to Number
617strcharlen({expr}) Number character length of the String {expr}
618strcharpart({str}, {start} [, {len} [, {skipcc}]])
619 String {len} characters of {str} at
620 character {start}
621strchars({expr} [, {skipcc}]) Number character count of the String {expr}
622strdisplaywidth({expr} [, {col}]) Number display length of the String {expr}
623strftime({format} [, {time}]) String format time with a specified format
624strgetchar({str}, {index}) Number get char {index} from {str}
625stridx({haystack}, {needle} [, {start}])
626 Number index of {needle} in {haystack}
627string({expr}) String String representation of {expr} value
628strlen({expr}) Number length of the String {expr}
629strpart({str}, {start} [, {len} [, {chars}]])
630 String {len} bytes/chars of {str} at
631 byte {start}
632strptime({format}, {timestring})
633 Number Convert {timestring} to unix timestamp
634strridx({haystack}, {needle} [, {start}])
635 Number last index of {needle} in {haystack}
636strtrans({expr}) String translate string to make it printable
Christian Brabandt67672ef2023-04-24 21:09:54 +0100637strutf16len({string} [, {countcc}])
638 Number number of UTF-16 code units in {string}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000639strwidth({expr}) Number display cell length of the String {expr}
640submatch({nr} [, {list}]) String or List
641 specific match in ":s" or substitute()
642substitute({expr}, {pat}, {sub}, {flags})
643 String all {pat} in {expr} replaced with {sub}
Bram Moolenaarc216a7a2022-12-05 13:50:55 +0000644swapfilelist() List swap files found in 'directory'
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000645swapinfo({fname}) Dict information about swap file {fname}
646swapname({buf}) String swap file of buffer {buf}
647synID({lnum}, {col}, {trans}) Number syntax ID at {lnum} and {col}
648synIDattr({synID}, {what} [, {mode}])
649 String attribute {what} of syntax ID {synID}
650synIDtrans({synID}) Number translated syntax ID of {synID}
651synconcealed({lnum}, {col}) List info about concealing
652synstack({lnum}, {col}) List stack of syntax IDs at {lnum} and {col}
653system({expr} [, {input}]) String output of shell command/filter {expr}
654systemlist({expr} [, {input}]) List output of shell command/filter {expr}
655tabpagebuflist([{arg}]) List list of buffer numbers in tab page
656tabpagenr([{arg}]) Number number of current or last tab page
657tabpagewinnr({tabarg} [, {arg}]) Number number of current window in tab page
658tagfiles() List tags files used
659taglist({expr} [, {filename}]) List list of tags matching {expr}
660tan({expr}) Float tangent of {expr}
661tanh({expr}) Float hyperbolic tangent of {expr}
662tempname() String name for a temporary file
663term_dumpdiff({filename}, {filename} [, {options}])
664 Number display difference between two dumps
665term_dumpload({filename} [, {options}])
666 Number displaying a screen dump
667term_dumpwrite({buf}, {filename} [, {options}])
668 none dump terminal window contents
669term_getaltscreen({buf}) Number get the alternate screen flag
670term_getansicolors({buf}) List get ANSI palette in GUI color mode
671term_getattr({attr}, {what}) Number get the value of attribute {what}
672term_getcursor({buf}) List get the cursor position of a terminal
673term_getjob({buf}) Job get the job associated with a terminal
674term_getline({buf}, {row}) String get a line of text from a terminal
675term_getscrolled({buf}) Number get the scroll count of a terminal
676term_getsize({buf}) List get the size of a terminal
677term_getstatus({buf}) String get the status of a terminal
678term_gettitle({buf}) String get the title of a terminal
679term_gettty({buf}, [{input}]) String get the tty name of a terminal
680term_list() List get the list of terminal buffers
681term_scrape({buf}, {row}) List get row of a terminal screen
682term_sendkeys({buf}, {keys}) none send keystrokes to a terminal
683term_setansicolors({buf}, {colors})
684 none set ANSI palette in GUI color mode
685term_setapi({buf}, {expr}) none set |terminal-api| function name prefix
686term_setkill({buf}, {how}) none set signal to stop job in terminal
687term_setrestore({buf}, {command}) none set command to restore terminal
688term_setsize({buf}, {rows}, {cols})
689 none set the size of a terminal
690term_start({cmd} [, {options}]) Number open a terminal window and run a job
691term_wait({buf} [, {time}]) Number wait for screen to be updated
692terminalprops() Dict properties of the terminal
693test_alloc_fail({id}, {countdown}, {repeat})
694 none make memory allocation fail
695test_autochdir() none enable 'autochdir' during startup
696test_feedinput({string}) none add key sequence to input buffer
697test_garbagecollect_now() none free memory right now for testing
698test_garbagecollect_soon() none free memory soon for testing
699test_getvalue({string}) any get value of an internal variable
Yegappan Lakshmanan06011e12022-01-30 12:37:29 +0000700test_gui_event({event}, {args}) bool generate a GUI event for testing
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000701test_ignore_error({expr}) none ignore a specific error
Christopher Plewright20b795e2022-12-20 20:01:58 +0000702test_mswin_event({event}, {args})
703 bool generate MS-Windows event for testing
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000704test_null_blob() Blob null value for testing
705test_null_channel() Channel null value for testing
706test_null_dict() Dict null value for testing
707test_null_function() Funcref null value for testing
708test_null_job() Job null value for testing
709test_null_list() List null value for testing
710test_null_partial() Funcref null value for testing
711test_null_string() String null value for testing
712test_option_not_set({name}) none reset flag indicating option was set
713test_override({expr}, {val}) none test with Vim internal overrides
714test_refcount({expr}) Number get the reference count of {expr}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000715test_setmouse({row}, {col}) none set the mouse position for testing
716test_settime({expr}) none set current time for testing
Doug Kearns9cd9e752024-04-07 17:42:17 +0200717test_srand_seed([{seed}]) none set seed for testing srand()
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000718test_unknown() any unknown value for testing
719test_void() any void value for testing
720timer_info([{id}]) List information about timers
721timer_pause({id}, {pause}) none pause or unpause a timer
722timer_start({time}, {callback} [, {options}])
723 Number create a timer
724timer_stop({timer}) none stop a timer
725timer_stopall() none stop all timers
726tolower({expr}) String the String {expr} switched to lowercase
727toupper({expr}) String the String {expr} switched to uppercase
728tr({src}, {fromstr}, {tostr}) String translate chars of {src} in {fromstr}
729 to chars in {tostr}
730trim({text} [, {mask} [, {dir}]])
731 String trim characters in {mask} from {text}
732trunc({expr}) Float truncate Float {expr}
733type({expr}) Number type of value {expr}
734typename({expr}) String representation of the type of {expr}
735undofile({name}) String undo file name for {name}
Devin J. Pohly5fee1112023-04-23 20:26:59 -0500736undotree([{buf}]) List undo file tree for buffer {buf}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000737uniq({list} [, {func} [, {dict}]])
738 List remove adjacent duplicates from a list
Christian Brabandt67672ef2023-04-24 21:09:54 +0100739utf16idx({string}, {idx} [, {countcc} [, {charidx}]])
740 Number UTF-16 index of byte {idx} in {string}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000741values({dict}) List values in {dict}
zeertzjq825cf812023-08-17 22:55:25 +0200742virtcol({expr} [, {list} [, {winid}])
743 Number or List
LemonBoy0f7a3e12022-05-26 12:10:37 +0100744 screen column of cursor or mark
Bram Moolenaar5a6ec102022-05-27 21:58:00 +0100745virtcol2col({winid}, {lnum}, {col})
746 Number byte index of a character on screen
Doug Kearns9cd9e752024-04-07 17:42:17 +0200747visualmode([{expr}]) String last visual mode used
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000748wildmenumode() Number whether 'wildmenu' mode is active
749win_execute({id}, {command} [, {silent}])
750 String execute {command} in window {id}
751win_findbuf({bufnr}) List find windows containing {bufnr}
752win_getid([{win} [, {tab}]]) Number get window ID for {win} in {tab}
753win_gettype([{nr}]) String type of window {nr}
754win_gotoid({expr}) Number go to window with ID {expr}
755win_id2tabwin({expr}) List get tab and window nr from window ID
756win_id2win({expr}) Number get window nr from window ID
Daniel Steinbergee630312022-01-10 13:36:34 +0000757win_move_separator({nr}) Number move window vertical separator
758win_move_statusline({nr}) Number move window status line
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000759win_screenpos({nr}) List get screen position of window {nr}
760win_splitmove({nr}, {target} [, {options}])
761 Number move window {nr} to split of {target}
762winbufnr({nr}) Number buffer number of window {nr}
763wincol() Number window column of the cursor
764windowsversion() String MS-Windows OS version
765winheight({nr}) Number height of window {nr}
766winlayout([{tabnr}]) List layout of windows in tab {tabnr}
767winline() Number window line of the cursor
768winnr([{expr}]) Number number of current window
769winrestcmd() String returns command to restore window sizes
770winrestview({dict}) none restore view of current window
771winsaveview() Dict save view of current window
772winwidth({nr}) Number width of window {nr}
773wordcount() Dict get byte/char/word statistics
774writefile({object}, {fname} [, {flags}])
775 Number write |Blob| or |List| of lines to file
776xor({expr}, {expr}) Number bitwise XOR
777
778==============================================================================
7792. Details *builtin-function-details*
780
781Not all functions are here, some have been moved to a help file covering the
782specific functionality.
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200783Return type specifies the type for |Vim9-script|, see |vim9-types|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000784
785abs({expr}) *abs()*
786 Return the absolute value of {expr}. When {expr} evaluates to
787 a |Float| abs() returns a |Float|. When {expr} can be
788 converted to a |Number| abs() returns a |Number|. Otherwise
789 abs() gives an error message and returns -1.
790 Examples: >
791 echo abs(1.456)
792< 1.456 >
793 echo abs(-5.456)
794< 5.456 >
795 echo abs(-4)
796< 4
797
798 Can also be used as a |method|: >
799 Compute()->abs()
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200800<
801 Return type: |Number| or |Float| depending on {expr}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000802
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000803
804acos({expr}) *acos()*
805 Return the arc cosine of {expr} measured in radians, as a
806 |Float| in the range of [0, pi].
807 {expr} must evaluate to a |Float| or a |Number| in the range
Bram Moolenaar016188f2022-06-06 20:52:59 +0100808 [-1, 1]. Otherwise acos() returns "nan".
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000809 Examples: >
810 :echo acos(0)
811< 1.570796 >
812 :echo acos(-0.5)
813< 2.094395
814
815 Can also be used as a |method|: >
816 Compute()->acos()
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200817<
818 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000819
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000820
821add({object}, {expr}) *add()*
822 Append the item {expr} to |List| or |Blob| {object}. Returns
823 the resulting |List| or |Blob|. Examples: >
824 :let alist = add([1, 2, 3], item)
825 :call add(mylist, "woodstock")
826< Note that when {expr} is a |List| it is appended as a single
827 item. Use |extend()| to concatenate |Lists|.
828 When {object} is a |Blob| then {expr} must be a number.
829 Use |insert()| to add an item at another position.
Bram Moolenaar016188f2022-06-06 20:52:59 +0100830 Returns 1 if {object} is not a |List| or a |Blob|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000831
832 Can also be used as a |method|: >
833 mylist->add(val1)->add(val2)
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200834<
835 Return type: list<{type}> (depending on the given |List|) or
836 |Blob|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000837
838
839and({expr}, {expr}) *and()*
840 Bitwise AND on the two arguments. The arguments are converted
841 to a number. A List, Dict or Float argument causes an error.
LemonBoy0f7a3e12022-05-26 12:10:37 +0100842 Also see `or()` and `xor()`.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000843 Example: >
844 :let flag = and(bits, 0x80)
845< Can also be used as a |method|: >
846 :let flag = bits->and(0x80)
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200847<
848 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000849
850
851append({lnum}, {text}) *append()*
852 When {text} is a |List|: Append each item of the |List| as a
853 text line below line {lnum} in the current buffer.
854 Otherwise append {text} as one text line below line {lnum} in
855 the current buffer.
856 Any type of item is accepted and converted to a String.
857 {lnum} can be zero to insert a line before the first one.
858 {lnum} is used like with |getline()|.
859 Returns 1 for failure ({lnum} out of range or out of memory),
Bram Moolenaarcd9c8d42022-11-05 23:46:43 +0000860 0 for success. When {text} is an empty list zero is returned,
861 no matter the value of {lnum}.
862 In |Vim9| script an invalid argument or negative number
863 results in an error. Example: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000864 :let failed = append(line('$'), "# THE END")
865 :let failed = append(0, ["Chapter 1", "the beginning"])
866
867< Can also be used as a |method| after a List, the base is
868 passed as the second argument: >
869 mylist->append(lnum)
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200870<
871 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000872
873
874appendbufline({buf}, {lnum}, {text}) *appendbufline()*
875 Like |append()| but append the text in buffer {buf}.
876
877 This function works only for loaded buffers. First call
878 |bufload()| if needed.
879
880 For the use of {buf}, see |bufname()|.
881
Bram Moolenaar8b6256f2021-12-28 11:24:49 +0000882 {lnum} is the line number to append below. Note that using
883 |line()| would use the current buffer, not the one appending
884 to. Use "$" to append at the end of the buffer. Other string
885 values are not supported.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000886
887 On success 0 is returned, on failure 1 is returned.
888 In |Vim9| script an error is given for an invalid {lnum}.
889
890 If {buf} is not a valid buffer or {lnum} is not valid, an
891 error message is given. Example: >
892 :let failed = appendbufline(13, 0, "# THE START")
Bram Moolenaarcd9c8d42022-11-05 23:46:43 +0000893< However, when {text} is an empty list then no error is given
894 for an invalid {lnum}, since {lnum} isn't actually used.
895
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000896 Can also be used as a |method| after a List, the base is
897 passed as the second argument: >
898 mylist->appendbufline(buf, lnum)
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200899<
900 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000901
902
903argc([{winid}]) *argc()*
904 The result is the number of files in the argument list. See
905 |arglist|.
906 If {winid} is not supplied, the argument list of the current
907 window is used.
908 If {winid} is -1, the global argument list is used.
909 Otherwise {winid} specifies the window of which the argument
910 list is used: either the window number or the window ID.
911 Returns -1 if the {winid} argument is invalid.
912
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200913 Return type: |Number|
914
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000915 *argidx()*
916argidx() The result is the current index in the argument list. 0 is
917 the first file. argc() - 1 is the last one. See |arglist|.
918
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200919 Return type: |Number|
920
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000921 *arglistid()*
922arglistid([{winnr} [, {tabnr}]])
923 Return the argument list ID. This is a number which
924 identifies the argument list being used. Zero is used for the
925 global argument list. See |arglist|.
926 Returns -1 if the arguments are invalid.
927
928 Without arguments use the current window.
929 With {winnr} only use this window in the current tab page.
930 With {winnr} and {tabnr} use the window in the specified tab
931 page.
932 {winnr} can be the window number or the |window-ID|.
933
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200934 Return type: |Number|
935
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000936 *argv()*
937argv([{nr} [, {winid}]])
938 The result is the {nr}th file in the argument list. See
939 |arglist|. "argv(0)" is the first one. Example: >
940 :let i = 0
941 :while i < argc()
942 : let f = escape(fnameescape(argv(i)), '.')
Bram Moolenaarc51cf032022-02-26 12:25:45 +0000943 : exe 'amenu Arg.' .. f .. ' :e ' .. f .. '<CR>'
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000944 : let i = i + 1
945 :endwhile
946< Without the {nr} argument, or when {nr} is -1, a |List| with
947 the whole |arglist| is returned.
948
949 The {winid} argument specifies the window ID, see |argc()|.
950 For the Vim command line arguments see |v:argv|.
951
Bram Moolenaar016188f2022-06-06 20:52:59 +0100952 Returns an empty string if {nr}th argument is not present in
953 the argument list. Returns an empty List if the {winid}
954 argument is invalid.
955
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200956 Return type: |String|
957
958
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000959asin({expr}) *asin()*
960 Return the arc sine of {expr} measured in radians, as a |Float|
961 in the range of [-pi/2, pi/2].
962 {expr} must evaluate to a |Float| or a |Number| in the range
963 [-1, 1].
Bram Moolenaar016188f2022-06-06 20:52:59 +0100964 Returns "nan" if {expr} is outside the range [-1, 1]. Returns
965 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000966 Examples: >
967 :echo asin(0.8)
968< 0.927295 >
969 :echo asin(-0.5)
970< -0.523599
971
972 Can also be used as a |method|: >
973 Compute()->asin()
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200974<
975 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000976
977assert_ functions are documented here: |assert-functions-details|
978
979
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000980atan({expr}) *atan()*
981 Return the principal value of the arc tangent of {expr}, in
982 the range [-pi/2, +pi/2] radians, as a |Float|.
983 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar016188f2022-06-06 20:52:59 +0100984 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000985 Examples: >
986 :echo atan(100)
987< 1.560797 >
988 :echo atan(-4.01)
989< -1.326405
990
991 Can also be used as a |method|: >
992 Compute()->atan()
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200993<
994 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000995
996
997atan2({expr1}, {expr2}) *atan2()*
998 Return the arc tangent of {expr1} / {expr2}, measured in
999 radians, as a |Float| in the range [-pi, pi].
1000 {expr1} and {expr2} must evaluate to a |Float| or a |Number|.
Bram Moolenaar016188f2022-06-06 20:52:59 +01001001 Returns 0.0 if {expr1} or {expr2} is not a |Float| or a
1002 |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001003 Examples: >
1004 :echo atan2(-1, 1)
1005< -0.785398 >
1006 :echo atan2(1, -1)
1007< 2.356194
1008
1009 Can also be used as a |method|: >
1010 Compute()->atan2(1)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001011<
1012 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001013
Yegappan Lakshmanan1755a912022-05-19 10:31:47 +01001014
1015autocmd_add({acmds}) *autocmd_add()*
1016 Adds a List of autocmds and autocmd groups.
1017
1018 The {acmds} argument is a List where each item is a Dict with
1019 the following optional items:
1020 bufnr buffer number to add a buffer-local autocmd.
1021 If this item is specified, then the "pattern"
1022 item is ignored.
1023 cmd Ex command to execute for this autocmd event
1024 event autocmd event name. Refer to |autocmd-events|.
Yegappan Lakshmanane0ff3a72022-05-27 18:05:33 +01001025 This can be either a String with a single
1026 event name or a List of event names.
Yegappan Lakshmanan1755a912022-05-19 10:31:47 +01001027 group autocmd group name. Refer to |autocmd-groups|.
1028 If this group doesn't exist then it is
1029 created. If not specified or empty, then the
1030 default group is used.
Yegappan Lakshmanan971f6822022-05-24 11:40:11 +01001031 nested boolean flag, set to v:true to add a nested
1032 autocmd. Refer to |autocmd-nested|.
LemonBoy0f7a3e12022-05-26 12:10:37 +01001033 once boolean flag, set to v:true to add an autocmd
Yegappan Lakshmanan971f6822022-05-24 11:40:11 +01001034 which executes only once. Refer to
1035 |autocmd-once|.
Yegappan Lakshmanan1755a912022-05-19 10:31:47 +01001036 pattern autocmd pattern string. Refer to
1037 |autocmd-patterns|. If "bufnr" item is
Yegappan Lakshmanane0ff3a72022-05-27 18:05:33 +01001038 present, then this item is ignored. This can
1039 be a String with a single pattern or a List of
1040 patterns.
Yegappan Lakshmanan971f6822022-05-24 11:40:11 +01001041 replace boolean flag, set to v:true to remove all the
1042 commands associated with the specified autocmd
1043 event and group and add the {cmd}. This is
1044 useful to avoid adding the same command
LemonBoy0f7a3e12022-05-26 12:10:37 +01001045 multiple times for an autocmd event in a group.
Yegappan Lakshmanan1755a912022-05-19 10:31:47 +01001046
1047 Returns v:true on success and v:false on failure.
1048 Examples: >
1049 " Create a buffer-local autocmd for buffer 5
1050 let acmd = {}
1051 let acmd.group = 'MyGroup'
1052 let acmd.event = 'BufEnter'
1053 let acmd.bufnr = 5
1054 let acmd.cmd = 'call BufEnterFunc()'
1055 call autocmd_add([acmd])
Bram Moolenaarcd9c8d42022-11-05 23:46:43 +00001056<
Yegappan Lakshmanan1755a912022-05-19 10:31:47 +01001057 Can also be used as a |method|: >
1058 GetAutocmdList()->autocmd_add()
1059<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001060 Return type: |vim9-boolean|
1061
1062
Yegappan Lakshmanan1755a912022-05-19 10:31:47 +01001063autocmd_delete({acmds}) *autocmd_delete()*
1064 Deletes a List of autocmds and autocmd groups.
1065
1066 The {acmds} argument is a List where each item is a Dict with
1067 the following optional items:
1068 bufnr buffer number to delete a buffer-local autocmd.
1069 If this item is specified, then the "pattern"
1070 item is ignored.
1071 cmd Ex command for this autocmd event
1072 event autocmd event name. Refer to |autocmd-events|.
1073 If '*' then all the autocmd events in this
1074 group are deleted.
1075 group autocmd group name. Refer to |autocmd-groups|.
1076 If not specified or empty, then the default
1077 group is used.
1078 nested set to v:true for a nested autocmd.
1079 Refer to |autocmd-nested|.
1080 once set to v:true for an autocmd which executes
1081 only once. Refer to |autocmd-once|.
1082 pattern autocmd pattern string. Refer to
1083 |autocmd-patterns|. If "bufnr" item is
1084 present, then this item is ignored.
1085
1086 If only {group} is specified in a {acmds} entry and {event},
1087 {pattern} and {cmd} are not specified, then that autocmd group
1088 is deleted.
1089
Bram Moolenaar016188f2022-06-06 20:52:59 +01001090 Returns |v:true| on success and |v:false| on failure.
Yegappan Lakshmanan1755a912022-05-19 10:31:47 +01001091 Examples: >
1092 " :autocmd! BufLeave *.vim
1093 let acmd = #{event: 'BufLeave', pattern: '*.vim'}
1094 call autocmd_delete([acmd]})
1095 " :autocmd! MyGroup1 BufLeave
1096 let acmd = #{group: 'MyGroup1', event: 'BufLeave'}
1097 call autocmd_delete([acmd])
1098 " :autocmd! MyGroup2 BufEnter *.c
1099 let acmd = #{group: 'MyGroup2', event: 'BufEnter',
1100 \ pattern: '*.c'}
1101 " :autocmd! MyGroup2 * *.c
1102 let acmd = #{group: 'MyGroup2', event: '*',
1103 \ pattern: '*.c'}
1104 call autocmd_delete([acmd])
1105 " :autocmd! MyGroup3
1106 let acmd = #{group: 'MyGroup3'}
1107 call autocmd_delete([acmd])
1108<
1109 Can also be used as a |method|: >
1110 GetAutocmdList()->autocmd_delete()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001111<
1112 Return type: |vim9-boolean|
1113
Yegappan Lakshmanan1755a912022-05-19 10:31:47 +01001114
1115autocmd_get([{opts}]) *autocmd_get()*
1116 Returns a |List| of autocmds. If {opts} is not supplied, then
1117 returns the autocmds for all the events in all the groups.
1118
1119 The optional {opts} Dict argument supports the following
1120 items:
1121 group Autocmd group name. If specified, returns only
1122 the autocmds defined in this group. If the
1123 specified group doesn't exist, results in an
1124 error message. If set to an empty string,
1125 then the default autocmd group is used.
1126 event Autocmd event name. If specified, returns only
1127 the autocmds defined for this event. If set
1128 to "*", then returns autocmds for all the
1129 events. If the specified event doesn't exist,
1130 results in an error message.
1131 pattern Autocmd pattern. If specified, returns only
1132 the autocmds defined for this pattern.
1133 A combination of the above three times can be supplied in
1134 {opts}.
1135
1136 Each Dict in the returned List contains the following items:
1137 bufnr For buffer-local autocmds, buffer number where
1138 the autocmd is defined.
1139 cmd Command executed for this autocmd.
1140 event Autocmd event name.
1141 group Autocmd group name.
Yegappan Lakshmanan971f6822022-05-24 11:40:11 +01001142 nested Boolean flag, set to v:true for a nested
1143 autocmd. See |autocmd-nested|.
1144 once Boolean flag, set to v:true, if the autocmd
1145 will be executed only once. See |autocmd-once|.
Yegappan Lakshmanan1755a912022-05-19 10:31:47 +01001146 pattern Autocmd pattern. For a buffer-local
1147 autocmd, this will be of the form "<buffer=n>".
1148 If there are multiple commands for an autocmd event in a
1149 group, then separate items are returned for each command.
1150
Bram Moolenaar016188f2022-06-06 20:52:59 +01001151 Returns an empty List if an autocmd with the specified group
1152 or event or pattern is not found.
1153
Yegappan Lakshmanan1755a912022-05-19 10:31:47 +01001154 Examples: >
1155 " :autocmd MyGroup
1156 echo autocmd_get(#{group: 'Mygroup'})
1157 " :autocmd G BufUnload
1158 echo autocmd_get(#{group: 'G', event: 'BufUnload'})
1159 " :autocmd G * *.ts
1160 let acmd = #{group: 'G', event: '*', pattern: '*.ts'}
1161 echo autocmd_get(acmd)
1162 " :autocmd Syntax
1163 echo autocmd_get(#{event: 'Syntax'})
1164 " :autocmd G BufEnter *.ts
1165 let acmd = #{group: 'G', event: 'BufEnter',
1166 \ pattern: '*.ts'}
1167 echo autocmd_get(acmd)
1168<
1169 Can also be used as a |method|: >
1170 Getopts()->autocmd_get()
1171<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001172 Return type: list<dict<any>>
1173
1174
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001175balloon_gettext() *balloon_gettext()*
1176 Return the current text in the balloon. Only for the string,
Bram Moolenaar016188f2022-06-06 20:52:59 +01001177 not used for the List. Returns an empty string if balloon
1178 is not present.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001179
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001180 Return type: |String|
1181
1182
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001183balloon_show({expr}) *balloon_show()*
1184 Show {expr} inside the balloon. For the GUI {expr} is used as
1185 a string. For a terminal {expr} can be a list, which contains
1186 the lines of the balloon. If {expr} is not a list it will be
1187 split with |balloon_split()|.
1188 If {expr} is an empty string any existing balloon is removed.
1189
1190 Example: >
1191 func GetBalloonContent()
1192 " ... initiate getting the content
1193 return ''
1194 endfunc
1195 set balloonexpr=GetBalloonContent()
1196
1197 func BalloonCallback(result)
1198 call balloon_show(a:result)
1199 endfunc
1200< Can also be used as a |method|: >
1201 GetText()->balloon_show()
1202<
1203 The intended use is that fetching the content of the balloon
1204 is initiated from 'balloonexpr'. It will invoke an
1205 asynchronous method, in which a callback invokes
1206 balloon_show(). The 'balloonexpr' itself can return an
Bram Moolenaar069a7d52022-06-27 22:16:08 +01001207 empty string or a placeholder, e.g. "loading...".
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001208
Bram Moolenaar069a7d52022-06-27 22:16:08 +01001209 When showing a balloon is not possible then nothing happens,
1210 no error message is given.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001211 {only available when compiled with the |+balloon_eval| or
1212 |+balloon_eval_term| feature}
1213
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001214 Return type: |Number|
1215
1216
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001217balloon_split({msg}) *balloon_split()*
1218 Split String {msg} into lines to be displayed in a balloon.
1219 The splits are made for the current window size and optimize
1220 to show debugger output.
Bram Moolenaar016188f2022-06-06 20:52:59 +01001221 Returns a |List| with the split lines. Returns an empty List
1222 on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001223 Can also be used as a |method|: >
1224 GetText()->balloon_split()->balloon_show()
1225
1226< {only available when compiled with the |+balloon_eval_term|
1227 feature}
1228
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001229 Return type: list<any> or list<string>
1230
h-easte80f3452025-01-02 10:40:29 +01001231base64_decode({string}) *base64_decode()*
1232 Return a Blob containing the bytes decoded from the base64
1233 encoded characters in {string}.
1234
1235 The {string} argument should contain only base64-encoded
1236 characters and should have a length that is a multiple of 4.
1237
1238 Returns an empty blob on error.
1239
1240 Examples: >
1241 " Write the decoded contents to a binary file
1242 call writefile(base64_decode(s), 'tools.bmp')
1243 " Decode a base64-encoded string
1244 echo list2str(blob2list(base64_decode(encodedstr)))
1245<
1246 Can also be used as a |method|: >
1247 GetEncodedString()->base64_decode()
1248<
1249 Return type: |Blob|
1250
1251
1252base64_encode({blob}) *base64_encode()*
1253 Return a base64-encoded String representing the bytes in
1254 {blob}. The base64 alphabet defined in RFC 4648 is used.
1255
1256 Examples: >
1257 " Encode the contents of a binary file
1258 echo base64_encode(readblob('somefile.bin'))
1259 " Encode a string
1260 echo base64_encode(list2blob(str2list(somestr)))
1261<
1262 Can also be used as a |method|: >
1263 GetBinaryData()->base64_encode()
1264<
1265 Return type: |String|
1266
1267
Christ van Willegence0ef912024-06-20 23:41:59 +02001268bindtextdomain({package}, {path}) *bindtextdomain()*
1269 Bind a specific {package} to a {path} so that the
1270 |gettext()| function can be used to get language-specific
1271 translations for a package. {path} is the directory name
h-east52e7cc22024-07-28 17:03:29 +02001272 for the translations. See |package-translation|.
Christ van Willegence0ef912024-06-20 23:41:59 +02001273
Christ van Willegen8252ef12024-07-11 21:36:21 +02001274 Returns v:true on success and v:false on failure (out of
1275 memory).
1276
1277 Return type: |vim9-boolean|
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001278
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001279blob2list({blob}) *blob2list()*
1280 Return a List containing the number value of each byte in Blob
1281 {blob}. Examples: >
1282 blob2list(0z0102.0304) returns [1, 2, 3, 4]
1283 blob2list(0z) returns []
1284< Returns an empty List on error. |list2blob()| does the
1285 opposite.
1286
1287 Can also be used as a |method|: >
1288 GetBlob()->blob2list()
Bram Moolenaarb529cfb2022-07-25 15:42:07 +01001289<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001290 Return type: list<any> or list<number>
1291
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001292 *browse()*
1293browse({save}, {title}, {initdir}, {default})
1294 Put up a file requester. This only works when "has("browse")"
1295 returns |TRUE| (only in some GUI versions).
1296 The input fields are:
1297 {save} when |TRUE|, select file to write
1298 {title} title for the requester
1299 {initdir} directory to start browsing in
1300 {default} default file name
1301 An empty string is returned when the "Cancel" button is hit,
1302 something went wrong, or browsing is not possible.
1303
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001304 Return type: |String|
1305
1306
1307browsedir({title}, {initdir}) *browsedir()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001308 Put up a directory requester. This only works when
1309 "has("browse")" returns |TRUE| (only in some GUI versions).
1310 On systems where a directory browser is not supported a file
1311 browser is used. In that case: select a file in the directory
1312 to be used.
1313 The input fields are:
1314 {title} title for the requester
1315 {initdir} directory to start browsing in
1316 When the "Cancel" button is hit, something went wrong, or
1317 browsing is not possible, an empty string is returned.
1318
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001319 Return type: |String|
1320
1321
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001322bufadd({name}) *bufadd()*
Bram Moolenaar2eddbac2022-08-25 12:45:21 +01001323 Add a buffer to the buffer list with name {name} (must be a
1324 String).
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001325 If a buffer for file {name} already exists, return that buffer
1326 number. Otherwise return the buffer number of the newly
1327 created buffer. When {name} is an empty string then a new
1328 buffer is always created.
1329 The buffer will not have 'buflisted' set and not be loaded
1330 yet. To add some text to the buffer use this: >
1331 let bufnr = bufadd('someName')
1332 call bufload(bufnr)
1333 call setbufline(bufnr, 1, ['some', 'text'])
Bram Moolenaar016188f2022-06-06 20:52:59 +01001334< Returns 0 on error.
1335 Can also be used as a |method|: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001336 let bufnr = 'somename'->bufadd()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001337<
1338 Return type: |Number|
1339
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001340
1341bufexists({buf}) *bufexists()*
1342 The result is a Number, which is |TRUE| if a buffer called
1343 {buf} exists.
1344 If the {buf} argument is a number, buffer numbers are used.
1345 Number zero is the alternate buffer for the current window.
1346
1347 If the {buf} argument is a string it must match a buffer name
1348 exactly. The name can be:
1349 - Relative to the current directory.
1350 - A full path.
1351 - The name of a buffer with 'buftype' set to "nofile".
1352 - A URL name.
1353 Unlisted buffers will be found.
1354 Note that help files are listed by their short name in the
1355 output of |:buffers|, but bufexists() requires using their
1356 long name to be able to find them.
1357 bufexists() may report a buffer exists, but to use the name
1358 with a |:buffer| command you may need to use |expand()|. Esp
1359 for MS-Windows 8.3 names in the form "c:\DOCUME~1"
1360 Use "bufexists(0)" to test for the existence of an alternate
1361 file name.
1362
1363 Can also be used as a |method|: >
1364 let exists = 'somename'->bufexists()
1365<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001366 Return type: |Number|
1367
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001368 Obsolete name: buffer_exists(). *buffer_exists()*
1369
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001370
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001371buflisted({buf}) *buflisted()*
1372 The result is a Number, which is |TRUE| if a buffer called
1373 {buf} exists and is listed (has the 'buflisted' option set).
1374 The {buf} argument is used like with |bufexists()|.
1375
1376 Can also be used as a |method|: >
1377 let listed = 'somename'->buflisted()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001378<
1379 Return type: |Number|
1380
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001381
1382bufload({buf}) *bufload()*
1383 Ensure the buffer {buf} is loaded. When the buffer name
1384 refers to an existing file then the file is read. Otherwise
1385 the buffer will be empty. If the buffer was already loaded
Bram Moolenaar2eddbac2022-08-25 12:45:21 +01001386 then there is no change. If the buffer is not related to a
Daniel Steinbergc2bd2052023-08-09 12:10:59 -04001387 file then no file is read (e.g., when 'buftype' is "nofile").
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001388 If there is an existing swap file for the file of the buffer,
1389 there will be no dialog, the buffer will be loaded anyway.
1390 The {buf} argument is used like with |bufexists()|.
1391
1392 Can also be used as a |method|: >
1393 eval 'somename'->bufload()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001394<
1395 Return type: |Number|
1396
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001397
1398bufloaded({buf}) *bufloaded()*
1399 The result is a Number, which is |TRUE| if a buffer called
1400 {buf} exists and is loaded (shown in a window or hidden).
1401 The {buf} argument is used like with |bufexists()|.
1402
1403 Can also be used as a |method|: >
1404 let loaded = 'somename'->bufloaded()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001405<
1406 Return type: |Number|
1407
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001408
1409bufname([{buf}]) *bufname()*
1410 The result is the name of a buffer. Mostly as it is displayed
1411 by the `:ls` command, but not using special names such as
1412 "[No Name]".
1413 If {buf} is omitted the current buffer is used.
1414 If {buf} is a Number, that buffer number's name is given.
1415 Number zero is the alternate buffer for the current window.
1416 If {buf} is a String, it is used as a |file-pattern| to match
1417 with the buffer names. This is always done like 'magic' is
1418 set and 'cpoptions' is empty. When there is more than one
1419 match an empty string is returned.
1420 "" or "%" can be used for the current buffer, "#" for the
1421 alternate buffer.
1422 A full match is preferred, otherwise a match at the start, end
1423 or middle of the buffer name is accepted. If you only want a
1424 full match then put "^" at the start and "$" at the end of the
1425 pattern.
1426 Listed buffers are found first. If there is a single match
1427 with a listed buffer, that one is returned. Next unlisted
1428 buffers are searched for.
1429 If the {buf} is a String, but you want to use it as a buffer
1430 number, force it to be a Number by adding zero to it: >
1431 :echo bufname("3" + 0)
1432< Can also be used as a |method|: >
1433 echo bufnr->bufname()
1434
1435< If the buffer doesn't exist, or doesn't have a name, an empty
1436 string is returned. >
1437 bufname("#") alternate buffer name
1438 bufname(3) name of buffer 3
1439 bufname("%") name of current buffer
1440 bufname("file2") name of buffer where "file2" matches.
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001441<
1442 Return type: |String|
1443 *buffer_name()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001444 Obsolete name: buffer_name().
1445
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001446
1447bufnr([{buf} [, {create}]]) *bufnr()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001448 The result is the number of a buffer, as it is displayed by
1449 the `:ls` command. For the use of {buf}, see |bufname()|
1450 above.
1451
1452 If the buffer doesn't exist, -1 is returned. Or, if the
1453 {create} argument is present and TRUE, a new, unlisted,
1454 buffer is created and its number is returned. Example: >
1455 let newbuf = bufnr('Scratch001', 1)
1456< Using an empty name uses the current buffer. To create a new
1457 buffer with an empty name use |bufadd()|.
1458
1459 bufnr("$") is the last buffer: >
1460 :let last_buffer = bufnr("$")
1461< The result is a Number, which is the highest buffer number
1462 of existing buffers. Note that not all buffers with a smaller
1463 number necessarily exist, because ":bwipeout" may have removed
1464 them. Use bufexists() to test for the existence of a buffer.
1465
1466 Can also be used as a |method|: >
1467 echo bufref->bufnr()
1468<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001469 Return type: |Number|
1470
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001471 Obsolete name: buffer_number(). *buffer_number()*
1472 *last_buffer_nr()*
1473 Obsolete name for bufnr("$"): last_buffer_nr().
1474
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001475
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001476bufwinid({buf}) *bufwinid()*
1477 The result is a Number, which is the |window-ID| of the first
1478 window associated with buffer {buf}. For the use of {buf},
1479 see |bufname()| above. If buffer {buf} doesn't exist or
1480 there is no such window, -1 is returned. Example: >
1481
Bram Moolenaarc51cf032022-02-26 12:25:45 +00001482 echo "A window containing buffer 1 is " .. (bufwinid(1))
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001483<
Bram Moolenaar76db9e02022-11-09 21:21:04 +00001484 Only deals with the current tab page. See |win_findbuf()| for
1485 finding more.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001486
1487 Can also be used as a |method|: >
1488 FindBuffer()->bufwinid()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001489<
1490 Return type: |Number|
1491
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001492
1493bufwinnr({buf}) *bufwinnr()*
1494 Like |bufwinid()| but return the window number instead of the
1495 |window-ID|.
1496 If buffer {buf} doesn't exist or there is no such window, -1
1497 is returned. Example: >
1498
Bram Moolenaarc51cf032022-02-26 12:25:45 +00001499 echo "A window containing buffer 1 is " .. (bufwinnr(1))
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001500
1501< The number can be used with |CTRL-W_w| and ":wincmd w"
1502 |:wincmd|.
1503
1504 Can also be used as a |method|: >
1505 FindBuffer()->bufwinnr()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001506<
1507 Return type: |Number|
1508
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001509
1510byte2line({byte}) *byte2line()*
1511 Return the line number that contains the character at byte
1512 count {byte} in the current buffer. This includes the
1513 end-of-line character, depending on the 'fileformat' option
1514 for the current buffer. The first character has byte count
1515 one.
1516 Also see |line2byte()|, |go| and |:goto|.
1517
Bram Moolenaar016188f2022-06-06 20:52:59 +01001518 Returns -1 if the {byte} value is invalid.
1519
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001520 Can also be used as a |method|: >
1521 GetOffset()->byte2line()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001522<
1523 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001524
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001525 {not available when compiled without the |+byte_offset|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001526 feature}
1527
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001528
Christian Brabandt67672ef2023-04-24 21:09:54 +01001529byteidx({expr}, {nr} [, {utf16}]) *byteidx()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001530 Return byte index of the {nr}'th character in the String
1531 {expr}. Use zero for the first character, it then returns
1532 zero.
1533 If there are no multibyte characters the returned value is
1534 equal to {nr}.
1535 Composing characters are not counted separately, their byte
1536 length is added to the preceding base character. See
1537 |byteidxcomp()| below for counting composing characters
1538 separately.
Christian Brabandt67672ef2023-04-24 21:09:54 +01001539 When {utf16} is present and TRUE, {nr} is used as the UTF-16
1540 index in the String {expr} instead of as the character index.
1541 The UTF-16 index is the index in the string when it is encoded
1542 with 16-bit words. If the specified UTF-16 index is in the
1543 middle of a character (e.g. in a 4-byte character), then the
1544 byte index of the first byte in the character is returned.
1545 Refer to |string-offset-encoding| for more information.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001546 Example : >
1547 echo matchstr(str, ".", byteidx(str, 3))
1548< will display the fourth character. Another way to do the
1549 same: >
1550 let s = strpart(str, byteidx(str, 3))
1551 echo strpart(s, 0, byteidx(s, 1))
1552< Also see |strgetchar()| and |strcharpart()|.
1553
1554 If there are less than {nr} characters -1 is returned.
1555 If there are exactly {nr} characters the length of the string
1556 in bytes is returned.
Christian Brabandt67672ef2023-04-24 21:09:54 +01001557 See |charidx()| and |utf16idx()| for getting the character and
1558 UTF-16 index respectively from the byte index.
1559 Examples: >
1560 echo byteidx('a😊😊', 2) returns 5
1561 echo byteidx('a😊😊', 2, 1) returns 1
1562 echo byteidx('a😊😊', 3, 1) returns 5
1563<
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001564 Can also be used as a |method|: >
1565 GetName()->byteidx(idx)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001566<
1567 Return type: |Number|
1568
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001569
Christian Brabandt67672ef2023-04-24 21:09:54 +01001570byteidxcomp({expr}, {nr} [, {utf16}]) *byteidxcomp()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001571 Like byteidx(), except that a composing character is counted
1572 as a separate character. Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00001573 let s = 'e' .. nr2char(0x301)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001574 echo byteidx(s, 1)
1575 echo byteidxcomp(s, 1)
1576 echo byteidxcomp(s, 2)
1577< The first and third echo result in 3 ('e' plus composing
1578 character is 3 bytes), the second echo results in 1 ('e' is
1579 one byte).
1580 Only works differently from byteidx() when 'encoding' is set
1581 to a Unicode encoding.
1582
1583 Can also be used as a |method|: >
1584 GetName()->byteidxcomp(idx)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001585<
1586 Return type: |Number|
1587
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001588
1589call({func}, {arglist} [, {dict}]) *call()* *E699*
1590 Call function {func} with the items in |List| {arglist} as
1591 arguments.
1592 {func} can either be a |Funcref| or the name of a function.
1593 a:firstline and a:lastline are set to the cursor line.
1594 Returns the return value of the called function.
1595 {dict} is for functions with the "dict" attribute. It will be
1596 used to set the local variable "self". |Dictionary-function|
1597
1598 Can also be used as a |method|: >
1599 GetFunc()->call([arg, arg], dict)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001600<
1601 Return type: any, depending on {func}
1602
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001603
1604ceil({expr}) *ceil()*
1605 Return the smallest integral value greater than or equal to
1606 {expr} as a |Float| (round up).
1607 {expr} must evaluate to a |Float| or a |Number|.
1608 Examples: >
1609 echo ceil(1.456)
1610< 2.0 >
1611 echo ceil(-5.456)
1612< -5.0 >
1613 echo ceil(4.0)
1614< 4.0
1615
Bram Moolenaar016188f2022-06-06 20:52:59 +01001616 Returns 0.0 if {expr} is not a |Float| or a |Number|.
1617
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001618 Can also be used as a |method|: >
1619 Compute()->ceil()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001620<
1621 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001622
1623
1624ch_ functions are documented here: |channel-functions-details|
1625
1626
1627changenr() *changenr()*
1628 Return the number of the most recent change. This is the same
1629 number as what is displayed with |:undolist| and can be used
1630 with the |:undo| command.
1631 When a change was made it is the number of that change. After
1632 redo it is the number of the redone change. After undo it is
1633 one less than the number of the undone change.
Bram Moolenaar016188f2022-06-06 20:52:59 +01001634 Returns 0 if the undo list is empty.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001635
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001636 Return type: |Number|
1637
1638
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001639char2nr({string} [, {utf8}]) *char2nr()*
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01001640 Return Number value of the first char in {string}.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001641 Examples: >
1642 char2nr(" ") returns 32
1643 char2nr("ABC") returns 65
1644< When {utf8} is omitted or zero, the current 'encoding' is used.
1645 Example for "utf-8": >
1646 char2nr("á") returns 225
1647 char2nr("á"[0]) returns 195
1648< When {utf8} is TRUE, always treat as UTF-8 characters.
1649 A combining character is a separate character.
1650 |nr2char()| does the opposite.
1651 To turn a string into a list of character numbers: >
1652 let str = "ABC"
1653 let list = map(split(str, '\zs'), {_, val -> char2nr(val)})
1654< Result: [65, 66, 67]
1655
Bram Moolenaar016188f2022-06-06 20:52:59 +01001656 Returns 0 if {string} is not a |String|.
1657
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001658 Can also be used as a |method|: >
1659 GetChar()->char2nr()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001660<
1661 Return type: |Number|
1662
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001663
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001664charclass({string}) *charclass()*
1665 Return the character class of the first character in {string}.
1666 The character class is one of:
1667 0 blank
1668 1 punctuation
Christian Brabandtb5e7da12024-11-01 09:33:00 +01001669 2 word character (depends on 'iskeyword')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001670 3 emoji
1671 other specific Unicode class
1672 The class is used in patterns and word motions.
Bram Moolenaar016188f2022-06-06 20:52:59 +01001673 Returns 0 if {string} is not a |String|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001674
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001675 Return type: |Number|
1676
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001677
Yegappan Lakshmanan4c8d2f02022-11-12 16:07:47 +00001678charcol({expr} [, {winid}]) *charcol()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001679 Same as |col()| but returns the character index of the column
1680 position given with {expr} instead of the byte position.
1681
1682 Example:
1683 With the cursor on '세' in line 5 with text "여보세요": >
1684 charcol('.') returns 3
1685 col('.') returns 7
1686
1687< Can also be used as a |method|: >
1688 GetPos()->col()
1689<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001690 Return type: |Number|
1691
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001692 *charidx()*
Christian Brabandt67672ef2023-04-24 21:09:54 +01001693charidx({string}, {idx} [, {countcc} [, {utf16}]])
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001694 Return the character index of the byte at {idx} in {string}.
1695 The index of the first character is zero.
1696 If there are no multibyte characters the returned value is
1697 equal to {idx}.
Christian Brabandt67672ef2023-04-24 21:09:54 +01001698
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001699 When {countcc} is omitted or |FALSE|, then composing characters
Christian Brabandt67672ef2023-04-24 21:09:54 +01001700 are not counted separately, their byte length is added to the
1701 preceding base character.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001702 When {countcc} is |TRUE|, then composing characters are
1703 counted as separate characters.
Christian Brabandt67672ef2023-04-24 21:09:54 +01001704
1705 When {utf16} is present and TRUE, {idx} is used as the UTF-16
1706 index in the String {expr} instead of as the byte index.
1707
Yegappan Lakshmanan577922b2023-06-08 17:09:45 +01001708 Returns -1 if the arguments are invalid or if there are less
1709 than {idx} bytes. If there are exactly {idx} bytes the length
1710 of the string in characters is returned.
1711
1712 An error is given and -1 is returned if the first argument is
1713 not a string, the second argument is not a number or when the
1714 third argument is present and is not zero or one.
Christian Brabandt67672ef2023-04-24 21:09:54 +01001715
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001716 See |byteidx()| and |byteidxcomp()| for getting the byte index
Christian Brabandt67672ef2023-04-24 21:09:54 +01001717 from the character index and |utf16idx()| for getting the
1718 UTF-16 index from the character index.
1719 Refer to |string-offset-encoding| for more information.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001720 Examples: >
1721 echo charidx('áb́ć', 3) returns 1
1722 echo charidx('áb́ć', 6, 1) returns 4
1723 echo charidx('áb́ć', 16) returns -1
Christian Brabandt67672ef2023-04-24 21:09:54 +01001724 echo charidx('a😊😊', 4, 0, 1) returns 2
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001725<
1726 Can also be used as a |method|: >
1727 GetName()->charidx(idx)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001728<
1729 Return type: |Number|
1730
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001731
1732chdir({dir}) *chdir()*
1733 Change the current working directory to {dir}. The scope of
1734 the directory change depends on the directory of the current
1735 window:
1736 - If the current window has a window-local directory
1737 (|:lcd|), then changes the window local directory.
1738 - Otherwise, if the current tabpage has a local
1739 directory (|:tcd|) then changes the tabpage local
1740 directory.
1741 - Otherwise, changes the global directory.
1742 {dir} must be a String.
1743 If successful, returns the previous working directory. Pass
1744 this to another chdir() to restore the directory.
1745 On failure, returns an empty string.
1746
1747 Example: >
1748 let save_dir = chdir(newdir)
1749 if save_dir != ""
1750 " ... do some work
1751 call chdir(save_dir)
1752 endif
1753
1754< Can also be used as a |method|: >
1755 GetDir()->chdir()
1756<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001757 Return type: |String|
1758
1759
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001760cindent({lnum}) *cindent()*
1761 Get the amount of indent for line {lnum} according the C
1762 indenting rules, as with 'cindent'.
1763 The indent is counted in spaces, the value of 'tabstop' is
1764 relevant. {lnum} is used just like in |getline()|.
Bram Moolenaar8e145b82022-05-21 20:17:31 +01001765 When {lnum} is invalid -1 is returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001766 See |C-indenting|.
1767
1768 Can also be used as a |method|: >
1769 GetLnum()->cindent()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001770<
1771 Return type: |Number|
1772
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001773
1774clearmatches([{win}]) *clearmatches()*
1775 Clears all matches previously defined for the current window
1776 by |matchadd()| and the |:match| commands.
1777 If {win} is specified, use the window with this number or
1778 window ID instead of the current window.
1779
1780 Can also be used as a |method|: >
1781 GetWin()->clearmatches()
1782<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001783 Return type: |Number|
1784
1785
Bram Moolenaar10e8ff92023-06-10 21:40:39 +01001786col({expr} [, {winid}]) *col()*
Yegappan Lakshmanan4c8d2f02022-11-12 16:07:47 +00001787 The result is a Number, which is the byte index of the column
zeertzjq02f3eba2024-06-12 20:45:24 +02001788 position given with {expr}.
1789 For accepted positions see |getpos()|.
zeertzjqd353d272024-06-13 23:00:25 +08001790 When {expr} is "$", it means the end of the cursor line, so
1791 the result is the number of bytes in the cursor line plus one.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001792 Additionally {expr} can be [lnum, col]: a |List| with the line
1793 and column number. Most useful when the column is "$", to get
1794 the last column of a specific line. When "lnum" or "col" is
1795 out of range then col() returns zero.
zeertzjq02f3eba2024-06-12 20:45:24 +02001796
Yegappan Lakshmanan4c8d2f02022-11-12 16:07:47 +00001797 With the optional {winid} argument the values are obtained for
1798 that window instead of the current window.
zeertzjq02f3eba2024-06-12 20:45:24 +02001799
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001800 To get the line number use |line()|. To get both use
1801 |getpos()|.
1802 For the screen column position use |virtcol()|. For the
1803 character position use |charcol()|.
zeertzjq02f3eba2024-06-12 20:45:24 +02001804
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001805 Note that only marks in the current file can be used.
zeertzjq02f3eba2024-06-12 20:45:24 +02001806
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001807 Examples: >
1808 col(".") column of cursor
1809 col("$") length of cursor line plus one
1810 col("'t") column of mark t
Bram Moolenaarc51cf032022-02-26 12:25:45 +00001811 col("'" .. markname) column of mark markname
zeertzjq02f3eba2024-06-12 20:45:24 +02001812<
1813 The first column is 1. Returns 0 if {expr} is invalid or when
Yegappan Lakshmanan4c8d2f02022-11-12 16:07:47 +00001814 the window with ID {winid} is not found.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001815 For an uppercase mark the column may actually be in another
1816 buffer.
1817 For the cursor position, when 'virtualedit' is active, the
1818 column is one higher if the cursor is after the end of the
Bram Moolenaar6ebe4f92022-10-28 20:47:54 +01001819 line. Also, when using a <Cmd> mapping the cursor isn't
1820 moved, this can be used to obtain the column in Insert mode: >
Bram Moolenaar76db9e02022-11-09 21:21:04 +00001821 :imap <F2> <Cmd>echowin col(".")<CR>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001822
1823< Can also be used as a |method|: >
1824 GetPos()->col()
1825<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001826 Return type: |Number|
1827
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001828
1829complete({startcol}, {matches}) *complete()* *E785*
1830 Set the matches for Insert mode completion.
1831 Can only be used in Insert mode. You need to use a mapping
1832 with CTRL-R = (see |i_CTRL-R|). It does not work after CTRL-O
1833 or with an expression mapping.
1834 {startcol} is the byte offset in the line where the completed
1835 text start. The text up to the cursor is the original text
1836 that will be replaced by the matches. Use col('.') for an
1837 empty string. "col('.') - 1" will replace one character by a
1838 match.
1839 {matches} must be a |List|. Each |List| item is one match.
1840 See |complete-items| for the kind of items that are possible.
1841 "longest" in 'completeopt' is ignored.
1842 Note that the after calling this function you need to avoid
1843 inserting anything that would cause completion to stop.
1844 The match can be selected with CTRL-N and CTRL-P as usual with
1845 Insert mode completion. The popup menu will appear if
1846 specified, see |ins-completion-menu|.
1847 Example: >
1848 inoremap <F5> <C-R>=ListMonths()<CR>
1849
Bram Moolenaar10e8ff92023-06-10 21:40:39 +01001850 func ListMonths()
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001851 call complete(col('.'), ['January', 'February', 'March',
1852 \ 'April', 'May', 'June', 'July', 'August', 'September',
1853 \ 'October', 'November', 'December'])
1854 return ''
1855 endfunc
1856< This isn't very useful, but it shows how it works. Note that
1857 an empty string is returned to avoid a zero being inserted.
1858
1859 Can also be used as a |method|, the base is passed as the
1860 second argument: >
1861 GetMatches()->complete(col('.'))
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001862<
1863 Return type: |Number|
1864
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001865
1866complete_add({expr}) *complete_add()*
1867 Add {expr} to the list of matches. Only to be used by the
1868 function specified with the 'completefunc' option.
1869 Returns 0 for failure (empty string or out of memory),
1870 1 when the match was added, 2 when the match was already in
1871 the list.
1872 See |complete-functions| for an explanation of {expr}. It is
1873 the same as one item in the list that 'omnifunc' would return.
1874
1875 Can also be used as a |method|: >
1876 GetMoreMatches()->complete_add()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001877<
1878 Return type: |Number|
1879
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001880
1881complete_check() *complete_check()*
1882 Check for a key typed while looking for completion matches.
1883 This is to be used when looking for matches takes some time.
1884 Returns |TRUE| when searching for matches is to be aborted,
1885 zero otherwise.
1886 Only to be used by the function specified with the
1887 'completefunc' option.
1888
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001889 Return type: |Number|
1890
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001891
1892complete_info([{what}]) *complete_info()*
1893 Returns a |Dictionary| with information about Insert mode
1894 completion. See |ins-completion|.
1895 The items are:
1896 mode Current completion mode name string.
1897 See |complete_info_mode| for the values.
1898 pum_visible |TRUE| if popup menu is visible.
1899 See |pumvisible()|.
glepnird4088ed2024-12-31 10:55:22 +01001900 items List of all completion candidates. Each item
1901 is a dictionary containing the entries "word",
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001902 "abbr", "menu", "kind", "info" and "user_data".
1903 See |complete-items|.
glepnird4088ed2024-12-31 10:55:22 +01001904 matches Same as "items", but only returns items that
1905 are matching current query. If both "matches"
1906 and "items" are in "what", the returned list
1907 will still be named "items", but each item
1908 will have an additional "match" field.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001909 selected Selected item index. First index is zero.
1910 Index is -1 if no item is selected (showing
1911 typed text only, or the last completion after
1912 no item is selected when using the <Up> or
1913 <Down> keys)
Bram Moolenaar0daafaa2022-09-04 17:45:43 +01001914 inserted Inserted string. [NOT IMPLEMENTED YET]
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001915
1916 *complete_info_mode*
1917 mode values are:
1918 "" Not in completion mode
1919 "keyword" Keyword completion |i_CTRL-X_CTRL-N|
1920 "ctrl_x" Just pressed CTRL-X |i_CTRL-X|
1921 "scroll" Scrolling with |i_CTRL-X_CTRL-E| or
1922 |i_CTRL-X_CTRL-Y|
1923 "whole_line" Whole lines |i_CTRL-X_CTRL-L|
1924 "files" File names |i_CTRL-X_CTRL-F|
1925 "tags" Tags |i_CTRL-X_CTRL-]|
1926 "path_defines" Definition completion |i_CTRL-X_CTRL-D|
1927 "path_patterns" Include completion |i_CTRL-X_CTRL-I|
1928 "dictionary" Dictionary |i_CTRL-X_CTRL-K|
1929 "thesaurus" Thesaurus |i_CTRL-X_CTRL-T|
1930 "cmdline" Vim Command line |i_CTRL-X_CTRL-V|
1931 "function" User defined completion |i_CTRL-X_CTRL-U|
1932 "omni" Omni completion |i_CTRL-X_CTRL-O|
1933 "spell" Spelling suggestions |i_CTRL-X_s|
1934 "eval" |complete()| completion
1935 "unknown" Other internal modes
1936
1937 If the optional {what} list argument is supplied, then only
1938 the items listed in {what} are returned. Unsupported items in
1939 {what} are silently ignored.
1940
1941 To get the position and size of the popup menu, see
1942 |pum_getpos()|. It's also available in |v:event| during the
1943 |CompleteChanged| event.
1944
Bram Moolenaar016188f2022-06-06 20:52:59 +01001945 Returns an empty |Dictionary| on error.
1946
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001947 Examples: >
1948 " Get all items
1949 call complete_info()
1950 " Get only 'mode'
1951 call complete_info(['mode'])
1952 " Get only 'mode' and 'pum_visible'
1953 call complete_info(['mode', 'pum_visible'])
1954
1955< Can also be used as a |method|: >
1956 GetItems()->complete_info()
1957<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001958 Return type: dict<any>
1959
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001960 *confirm()*
1961confirm({msg} [, {choices} [, {default} [, {type}]]])
1962 confirm() offers the user a dialog, from which a choice can be
1963 made. It returns the number of the choice. For the first
1964 choice this is 1.
1965 Note: confirm() is only supported when compiled with dialog
glepnirdf461152024-04-04 22:23:29 +02001966 support, see |+dialog_con| |+dialog_con_gui| and |+dialog_gui|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001967
1968 {msg} is displayed in a |dialog| with {choices} as the
1969 alternatives. When {choices} is missing or empty, "&OK" is
1970 used (and translated).
1971 {msg} is a String, use '\n' to include a newline. Only on
1972 some systems the string is wrapped when it doesn't fit.
1973
1974 {choices} is a String, with the individual choices separated
1975 by '\n', e.g. >
1976 confirm("Save changes?", "&Yes\n&No\n&Cancel")
1977< The letter after the '&' is the shortcut key for that choice.
1978 Thus you can type 'c' to select "Cancel". The shortcut does
1979 not need to be the first letter: >
1980 confirm("file has been modified", "&Save\nSave &All")
1981< For the console, the first letter of each choice is used as
1982 the default shortcut key. Case is ignored.
1983
1984 The optional {default} argument is the number of the choice
1985 that is made if the user hits <CR>. Use 1 to make the first
1986 choice the default one. Use 0 to not set a default. If
1987 {default} is omitted, 1 is used.
1988
1989 The optional {type} String argument gives the type of dialog.
1990 This is only used for the icon of the GTK, Mac, Motif and
1991 Win32 GUI. It can be one of these values: "Error",
1992 "Question", "Info", "Warning" or "Generic". Only the first
1993 character is relevant. When {type} is omitted, "Generic" is
1994 used.
1995
1996 If the user aborts the dialog by pressing <Esc>, CTRL-C,
1997 or another valid interrupt key, confirm() returns 0.
1998
1999 An example: >
Bram Moolenaar46eea442022-03-30 10:51:39 +01002000 let choice = confirm("What do you want?",
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01002001 \ "&Apples\n&Oranges\n&Bananas", 2)
Bram Moolenaar46eea442022-03-30 10:51:39 +01002002 if choice == 0
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01002003 echo "make up your mind!"
Bram Moolenaar46eea442022-03-30 10:51:39 +01002004 elseif choice == 3
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01002005 echo "tasteful"
Bram Moolenaar46eea442022-03-30 10:51:39 +01002006 else
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01002007 echo "I prefer bananas myself."
Bram Moolenaar46eea442022-03-30 10:51:39 +01002008 endif
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002009< In a GUI dialog, buttons are used. The layout of the buttons
2010 depends on the 'v' flag in 'guioptions'. If it is included,
2011 the buttons are always put vertically. Otherwise, confirm()
2012 tries to put the buttons in one horizontal line. If they
2013 don't fit, a vertical layout is used anyway. For some systems
2014 the horizontal layout is always used.
2015
2016 Can also be used as a |method|in: >
2017 BuildMessage()->confirm("&Yes\n&No")
2018<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002019 Return type: |Number|
2020
2021
2022copy({expr}) *copy()*
2023 Make a copy of {expr}. For Numbers and Strings this isn't
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002024 different from using {expr} directly.
2025 When {expr} is a |List| a shallow copy is created. This means
2026 that the original |List| can be changed without changing the
2027 copy, and vice versa. But the items are identical, thus
2028 changing an item changes the contents of both |Lists|.
2029 A |Dictionary| is copied in a similar way as a |List|.
2030 Also see |deepcopy()|.
2031 Can also be used as a |method|: >
2032 mylist->copy()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002033<
2034 Return type: any, depending on {expr}
2035
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002036
2037cos({expr}) *cos()*
2038 Return the cosine of {expr}, measured in radians, as a |Float|.
2039 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar016188f2022-06-06 20:52:59 +01002040 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002041 Examples: >
2042 :echo cos(100)
2043< 0.862319 >
2044 :echo cos(-4.01)
2045< -0.646043
2046
2047 Can also be used as a |method|: >
2048 Compute()->cos()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002049<
2050 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002051
2052
2053cosh({expr}) *cosh()*
2054 Return the hyperbolic cosine of {expr} as a |Float| in the range
2055 [1, inf].
2056 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar016188f2022-06-06 20:52:59 +01002057 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002058 Examples: >
2059 :echo cosh(0.5)
2060< 1.127626 >
2061 :echo cosh(-0.5)
2062< -1.127626
2063
2064 Can also be used as a |method|: >
2065 Compute()->cosh()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002066<
2067 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002068
2069
Yegappan Lakshmanancd39b692023-10-02 12:50:45 -07002070count({comp}, {expr} [, {ic} [, {start}]]) *count()* *E706*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002071 Return the number of times an item with value {expr} appears
2072 in |String|, |List| or |Dictionary| {comp}.
2073
2074 If {start} is given then start with the item with this index.
2075 {start} can only be used with a |List|.
2076
2077 When {ic} is given and it's |TRUE| then case is ignored.
2078
2079 When {comp} is a string then the number of not overlapping
2080 occurrences of {expr} is returned. Zero is returned when
2081 {expr} is an empty string.
2082
2083 Can also be used as a |method|: >
2084 mylist->count(val)
2085<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002086 Return type: |Number|
2087
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002088 *cscope_connection()*
2089cscope_connection([{num} , {dbpath} [, {prepend}]])
2090 Checks for the existence of a |cscope| connection. If no
2091 parameters are specified, then the function returns:
2092 0, if cscope was not available (not compiled in), or
2093 if there are no cscope connections;
2094 1, if there is at least one cscope connection.
2095
2096 If parameters are specified, then the value of {num}
2097 determines how existence of a cscope connection is checked:
2098
2099 {num} Description of existence check
2100 ----- ------------------------------
2101 0 Same as no parameters (e.g., "cscope_connection()").
2102 1 Ignore {prepend}, and use partial string matches for
2103 {dbpath}.
2104 2 Ignore {prepend}, and use exact string matches for
2105 {dbpath}.
2106 3 Use {prepend}, use partial string matches for both
2107 {dbpath} and {prepend}.
2108 4 Use {prepend}, use exact string matches for both
2109 {dbpath} and {prepend}.
2110
2111 Note: All string comparisons are case sensitive!
2112
2113 Examples. Suppose we had the following (from ":cs show"): >
2114
2115 # pid database name prepend path
2116 0 27664 cscope.out /usr/local
2117<
2118 Invocation Return Val ~
2119 ---------- ---------- >
2120 cscope_connection() 1
2121 cscope_connection(1, "out") 1
2122 cscope_connection(2, "out") 0
2123 cscope_connection(3, "out") 0
2124 cscope_connection(3, "out", "local") 1
2125 cscope_connection(4, "out") 0
2126 cscope_connection(4, "out", "local") 0
2127 cscope_connection(4, "cscope.out", "/usr/local") 1
2128<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002129 Return type: |Number|
2130
2131
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002132cursor({lnum}, {col} [, {off}]) *cursor()*
2133cursor({list})
2134 Positions the cursor at the column (byte count) {col} in the
2135 line {lnum}. The first column is one.
2136
2137 When there is one argument {list} this is used as a |List|
2138 with two, three or four item:
2139 [{lnum}, {col}]
2140 [{lnum}, {col}, {off}]
2141 [{lnum}, {col}, {off}, {curswant}]
2142 This is like the return value of |getpos()| or |getcurpos()|,
2143 but without the first item.
2144
Bram Moolenaar10e8ff92023-06-10 21:40:39 +01002145 To position the cursor using {col} as the character count, use
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002146 |setcursorcharpos()|.
2147
2148 Does not change the jumplist.
Bram Moolenaar7c6cd442022-10-11 21:54:04 +01002149 {lnum} is used like with |getline()|, except that if {lnum} is
2150 zero, the cursor will stay in the current line.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002151 If {lnum} is greater than the number of lines in the buffer,
2152 the cursor will be positioned at the last line in the buffer.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002153 If {col} is greater than the number of bytes in the line,
2154 the cursor will be positioned at the last character in the
2155 line.
2156 If {col} is zero, the cursor will stay in the current column.
2157 If {curswant} is given it is used to set the preferred column
2158 for vertical movement. Otherwise {col} is used.
2159
2160 When 'virtualedit' is used {off} specifies the offset in
2161 screen columns from the start of the character. E.g., a
2162 position within a <Tab> or after the last character.
2163 Returns 0 when the position could be set, -1 otherwise.
2164
2165 Can also be used as a |method|: >
2166 GetCursorPos()->cursor()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002167<
2168 Return type: |Number|
2169
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002170
2171debugbreak({pid}) *debugbreak()*
2172 Specifically used to interrupt a program being debugged. It
2173 will cause process {pid} to get a SIGTRAP. Behavior for other
2174 processes is undefined. See |terminal-debugger|.
2175 {only available on MS-Windows}
2176
Bram Moolenaar016188f2022-06-06 20:52:59 +01002177 Returns |TRUE| if successfully interrupted the program.
2178 Otherwise returns |FALSE|.
2179
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002180 Can also be used as a |method|: >
2181 GetPid()->debugbreak()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002182<
2183 Return type: |Number|
2184
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002185
2186deepcopy({expr} [, {noref}]) *deepcopy()* *E698*
2187 Make a copy of {expr}. For Numbers and Strings this isn't
2188 different from using {expr} directly.
2189 When {expr} is a |List| a full copy is created. This means
2190 that the original |List| can be changed without changing the
2191 copy, and vice versa. When an item is a |List| or
2192 |Dictionary|, a copy for it is made, recursively. Thus
2193 changing an item in the copy does not change the contents of
2194 the original |List|.
2195 A |Dictionary| is copied in a similar way as a |List|.
2196
2197 When {noref} is omitted or zero a contained |List| or
2198 |Dictionary| is only copied once. All references point to
2199 this single copy. With {noref} set to 1 every occurrence of a
2200 |List| or |Dictionary| results in a new copy. This also means
2201 that a cyclic reference causes deepcopy() to fail.
2202 *E724*
2203 Nesting is possible up to 100 levels. When there is an item
2204 that refers back to a higher level making a deep copy with
2205 {noref} set to 1 will fail.
2206 Also see |copy()|.
2207
2208 Can also be used as a |method|: >
2209 GetObject()->deepcopy()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002210<
2211 Return type: any, depending on {expr}
2212
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002213
2214delete({fname} [, {flags}]) *delete()*
2215 Without {flags} or with {flags} empty: Deletes the file by the
Bram Moolenaarcbaff5e2022-04-08 17:45:08 +01002216 name {fname}.
2217
2218 This also works when {fname} is a symbolic link. The symbolic
2219 link itself is deleted, not what it points to.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002220
2221 When {flags} is "d": Deletes the directory by the name
2222 {fname}. This fails when directory {fname} is not empty.
2223
2224 When {flags} is "rf": Deletes the directory by the name
2225 {fname} and everything in it, recursively. BE CAREFUL!
2226 Note: on MS-Windows it is not possible to delete a directory
2227 that is being used.
2228
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002229 The result is a Number, which is 0/false if the delete
2230 operation was successful and -1/true when the deletion failed
2231 or partly failed.
2232
2233 Use |remove()| to delete an item from a |List|.
2234 To delete a line from the buffer use |:delete| or
2235 |deletebufline()|.
2236
2237 Can also be used as a |method|: >
2238 GetName()->delete()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002239<
2240 Return type: |Number|
2241
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002242
2243deletebufline({buf}, {first} [, {last}]) *deletebufline()*
2244 Delete lines {first} to {last} (inclusive) from buffer {buf}.
2245 If {last} is omitted then delete line {first} only.
2246 On success 0 is returned, on failure 1 is returned.
2247
2248 This function works only for loaded buffers. First call
2249 |bufload()| if needed.
2250
2251 For the use of {buf}, see |bufname()| above.
2252
2253 {first} and {last} are used like with |getline()|. Note that
2254 when using |line()| this refers to the current buffer. Use "$"
2255 to refer to the last line in buffer {buf}.
2256
2257 Can also be used as a |method|: >
2258 GetBuffer()->deletebufline(1)
2259<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002260 Return type: |Number|
2261
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002262 *did_filetype()*
2263did_filetype() Returns |TRUE| when autocommands are being executed and the
2264 FileType event has been triggered at least once. Can be used
2265 to avoid triggering the FileType event again in the scripts
2266 that detect the file type. |FileType|
2267 Returns |FALSE| when `:setf FALLBACK` was used.
2268 When editing another file, the counter is reset, thus this
2269 really checks if the FileType event has been triggered for the
2270 current buffer. This allows an autocommand that starts
2271 editing another buffer to set 'filetype' and load a syntax
2272 file.
2273
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002274 Return type: |Number|
2275
2276
Yegappan Lakshmananfa378352024-02-01 22:05:27 +01002277diff({fromlist}, {tolist} [, {options}]) *diff()*
2278 Returns a String or a List containing the diff between the
2279 strings in {fromlist} and {tolist}. Uses the Vim internal
2280 diff library to compute the diff.
2281
2282 *E106*
2283 The optional "output" item in {options} specifies the returned
2284 diff format. The following values are supported:
2285 indices Return a List of the starting and ending
2286 indices and a count of the strings in each
2287 diff hunk.
2288 unified Return the unified diff output as a String.
2289 This is the default.
2290
2291 If the "output" item in {options} is "indices", then a List is
2292 returned. Each List item contains a Dict with the following
2293 items for each diff hunk:
2294 from_idx start index in {fromlist} for this diff hunk.
2295 from_count number of strings in {fromlist} that are
2296 added/removed/modified in this diff hunk.
2297 to_idx start index in {tolist} for this diff hunk.
2298 to_count number of strings in {tolist} that are
2299 added/removed/modified in this diff hunk.
2300
2301 The {options} Dict argument also specifies diff options
2302 (similar to 'diffopt') and supports the following items:
Yegappan Lakshmananbe156a32024-02-11 17:08:29 +01002303 algorithm Dict specifying the diff algorithm to
2304 use. Supported boolean items are
2305 "myers", "minimal", "patience" and
2306 "histogram".
Yegappan Lakshmanana0010a12024-02-12 20:21:26 +01002307 context diff context length. Default is 0.
Yegappan Lakshmananfa378352024-02-01 22:05:27 +01002308 iblank ignore changes where lines are all
2309 blank.
2310 icase ignore changes in case of text.
Yegappan Lakshmananbe156a32024-02-11 17:08:29 +01002311 indent-heuristic use the indent heuristic for the
2312 internal diff library.
Yegappan Lakshmananfa378352024-02-01 22:05:27 +01002313 iwhite ignore changes in amount of white
2314 space.
2315 iwhiteall ignore all white space changes.
2316 iwhiteeol ignore white space changes at end of
2317 line.
Yegappan Lakshmananfa378352024-02-01 22:05:27 +01002318 For more information about these options, refer to 'diffopt'.
2319
Yegappan Lakshmanana0010a12024-02-12 20:21:26 +01002320 To compute the unified diff, all the items in {fromlist} are
2321 concatenated into a string using a newline separator and the
2322 same for {tolist}. The unified diff output uses line numbers.
2323
Yegappan Lakshmananfa378352024-02-01 22:05:27 +01002324 Returns an empty List or String if {fromlist} and {tolist} are
2325 identical.
2326
Yegappan Lakshmanan1af35632024-02-06 11:03:36 +01002327 Examples: >
Yegappan Lakshmananfa378352024-02-01 22:05:27 +01002328 :echo diff(['abc'], ['xxx'])
2329 @@ -1 +1 @@
2330 -abc
2331 +xxx
2332
2333 :echo diff(['abc'], ['xxx'], {'output': 'indices'})
2334 [{'from_idx': 0, 'from_count': 1, 'to_idx': 0, 'to_count': 1}]
2335 :echo diff(readfile('oldfile'), readfile('newfile'))
2336 :echo diff(getbufline(5, 1, '$'), getbufline(6, 1, '$'))
Yegappan Lakshmanan1af35632024-02-06 11:03:36 +01002337<
Yegappan Lakshmananfa378352024-02-01 22:05:27 +01002338 For more examples, refer to |diff-func-examples|
2339
2340 Can also be used as a |method|: >
2341 GetFromList->diff(to_list)
2342<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002343 Return type: |String| or list<dict<number>> or list<any>
2344 depending on {options}
2345
2346
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002347diff_filler({lnum}) *diff_filler()*
2348 Returns the number of filler lines above line {lnum}.
2349 These are the lines that were inserted at this point in
2350 another diff'ed window. These filler lines are shown in the
2351 display but don't exist in the buffer.
2352 {lnum} is used like with |getline()|. Thus "." is the current
2353 line, "'m" mark m, etc.
2354 Returns 0 if the current window is not in diff mode.
2355
2356 Can also be used as a |method|: >
2357 GetLnum()->diff_filler()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002358<
2359 Return type: |Number|
2360
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002361
2362diff_hlID({lnum}, {col}) *diff_hlID()*
2363 Returns the highlight ID for diff mode at line {lnum} column
2364 {col} (byte index). When the current line does not have a
2365 diff change zero is returned.
2366 {lnum} is used like with |getline()|. Thus "." is the current
2367 line, "'m" mark m, etc.
2368 {col} is 1 for the leftmost column, {lnum} is 1 for the first
2369 line.
2370 The highlight ID can be used with |synIDattr()| to obtain
2371 syntax information about the highlighting.
2372
2373 Can also be used as a |method|: >
2374 GetLnum()->diff_hlID(col)
2375<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002376 Return type: |Number|
2377
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002378
2379digraph_get({chars}) *digraph_get()* *E1214*
2380 Return the digraph of {chars}. This should be a string with
2381 exactly two characters. If {chars} are not just two
2382 characters, or the digraph of {chars} does not exist, an error
2383 is given and an empty string is returned.
2384
2385 The character will be converted from Unicode to 'encoding'
2386 when needed. This does require the conversion to be
2387 available, it might fail.
2388
2389 Also see |digraph_getlist()|.
2390
2391 Examples: >
2392 " Get a built-in digraph
2393 :echo digraph_get('00') " Returns '∞'
2394
2395 " Get a user-defined digraph
2396 :call digraph_set('aa', 'あ')
2397 :echo digraph_get('aa') " Returns 'あ'
2398<
2399 Can also be used as a |method|: >
2400 GetChars()->digraph_get()
2401<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002402 Return type: |String|
2403
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002404 This function works only when compiled with the |+digraphs|
2405 feature. If this feature is disabled, this function will
2406 display an error message.
2407
2408
2409digraph_getlist([{listall}]) *digraph_getlist()*
2410 Return a list of digraphs. If the {listall} argument is given
2411 and it is TRUE, return all digraphs, including the default
2412 digraphs. Otherwise, return only user-defined digraphs.
2413
2414 The characters will be converted from Unicode to 'encoding'
2415 when needed. This does require the conservation to be
2416 available, it might fail.
2417
2418 Also see |digraph_get()|.
2419
2420 Examples: >
2421 " Get user-defined digraphs
2422 :echo digraph_getlist()
2423
2424 " Get all the digraphs, including default digraphs
2425 :echo digraph_getlist(1)
2426<
2427 Can also be used as a |method|: >
2428 GetNumber()->digraph_getlist()
2429<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002430 Return type: list<list<string>>
2431
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002432 This function works only when compiled with the |+digraphs|
2433 feature. If this feature is disabled, this function will
2434 display an error message.
2435
2436
Bram Moolenaara2baa732022-02-04 16:09:54 +00002437digraph_set({chars}, {digraph}) *digraph_set()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002438 Add digraph {chars} to the list. {chars} must be a string
2439 with two characters. {digraph} is a string with one UTF-8
Bram Moolenaara2baa732022-02-04 16:09:54 +00002440 encoded character. *E1215*
2441 Be careful, composing characters are NOT ignored. This
2442 function is similar to |:digraphs| command, but useful to add
2443 digraphs start with a white space.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002444
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002445 The function returns v:true if |digraph| is registered. If
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002446 this fails an error message is given and v:false is returned.
2447
2448 If you want to define multiple digraphs at once, you can use
2449 |digraph_setlist()|.
2450
2451 Example: >
2452 call digraph_set(' ', 'あ')
2453<
2454 Can be used as a |method|: >
2455 GetString()->digraph_set('あ')
2456<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002457 Return type: |vim9-boolean|
2458
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002459 This function works only when compiled with the |+digraphs|
2460 feature. If this feature is disabled, this function will
2461 display an error message.
2462
2463
2464digraph_setlist({digraphlist}) *digraph_setlist()*
2465 Similar to |digraph_set()| but this function can add multiple
2466 digraphs at once. {digraphlist} is a list composed of lists,
2467 where each list contains two strings with {chars} and
Bram Moolenaara2baa732022-02-04 16:09:54 +00002468 {digraph} as in |digraph_set()|. *E1216*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002469 Example: >
2470 call digraph_setlist([['aa', 'あ'], ['ii', 'い']])
2471<
2472 It is similar to the following: >
2473 for [chars, digraph] in [['aa', 'あ'], ['ii', 'い']]
2474 call digraph_set(chars, digraph)
2475 endfor
2476< Except that the function returns after the first error,
2477 following digraphs will not be added.
2478
2479 Can be used as a |method|: >
2480 GetList()->digraph_setlist()
2481<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002482 Return type: |vim9-boolean|
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
2489echoraw({string}) *echoraw()*
2490 Output {string} as-is, including unprintable characters.
2491 This can be used to output a terminal code. For example, to
2492 disable modifyOtherKeys: >
2493 call echoraw(&t_TE)
2494< and to enable it again: >
2495 call echoraw(&t_TI)
2496< Use with care, you can mess up the terminal this way.
2497
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002498 Return type: |Number|
2499
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002500
2501empty({expr}) *empty()*
2502 Return the Number 1 if {expr} is empty, zero otherwise.
2503 - A |List| or |Dictionary| is empty when it does not have any
2504 items.
2505 - A |String| is empty when its length is zero.
2506 - A |Number| and |Float| are empty when their value is zero.
2507 - |v:false|, |v:none| and |v:null| are empty, |v:true| is not.
2508 - A |Job| is empty when it failed to start.
2509 - A |Channel| is empty when it is closed.
2510 - A |Blob| is empty when its length is zero.
mityu7f0bba22024-03-29 10:14:41 +01002511 - An |Object| is empty, when the empty() method in the object
2512 (if present) returns true. |object-empty()|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002513
2514 For a long |List| this is much faster than comparing the
2515 length with zero.
2516
2517 Can also be used as a |method|: >
2518 mylist->empty()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002519<
2520 Return type: |Number|
2521
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002522
2523environ() *environ()*
2524 Return all of environment variables as dictionary. You can
2525 check if an environment variable exists like this: >
2526 :echo has_key(environ(), 'HOME')
2527< Note that the variable name may be CamelCase; to ignore case
2528 use this: >
2529 :echo index(keys(environ()), 'HOME', 0, 1) != -1
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002530<
2531 Return type: dict<string>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002532
Bram Moolenaar416bd912023-07-07 23:19:18 +01002533
2534err_teapot([{expr}]) *err_teapot()*
2535 Produce an error with number 418, needed for implementation of
Christian Brabandtee17b6f2023-09-09 11:23:50 +02002536 RFC 2324.
Bram Moolenaar416bd912023-07-07 23:19:18 +01002537 If {expr} is present and it is TRUE error 503 is given,
2538 indicating that coffee is temporarily not available.
2539 If {expr} is present it must be a String.
2540
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002541 Return type: |Number|
2542
Bram Moolenaar416bd912023-07-07 23:19:18 +01002543
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002544escape({string}, {chars}) *escape()*
2545 Escape the characters in {chars} that occur in {string} with a
2546 backslash. Example: >
2547 :echo escape('c:\program files\vim', ' \')
2548< results in: >
2549 c:\\program\ files\\vim
2550< Also see |shellescape()| and |fnameescape()|.
2551
2552 Can also be used as a |method|: >
2553 GetText()->escape(' \')
2554<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002555 Return type: |String|
2556
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002557 *eval()*
2558eval({string}) Evaluate {string} and return the result. Especially useful to
2559 turn the result of |string()| back into the original value.
2560 This works for Numbers, Floats, Strings, Blobs and composites
2561 of them. Also works for |Funcref|s that refer to existing
Aliaksei Budavei95740222024-04-04 23:05:33 +03002562 functions. In |Vim9| script, it can be used to obtain |enum|
2563 values from their fully qualified names.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002564
2565 Can also be used as a |method|: >
2566 argv->join()->eval()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002567<
2568 Return type: any, depending on {string}
2569
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002570
2571eventhandler() *eventhandler()*
2572 Returns 1 when inside an event handler. That is that Vim got
2573 interrupted while waiting for the user to type a character,
2574 e.g., when dropping a file on Vim. This means interactive
2575 commands cannot be used. Otherwise zero is returned.
2576
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002577 Return type: |Number|
2578
2579
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002580executable({expr}) *executable()*
2581 This function checks if an executable with the name {expr}
2582 exists. {expr} must be the name of the program without any
2583 arguments.
zeertzjq0cc5dce2024-08-08 21:12:15 +02002584
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002585 executable() uses the value of $PATH and/or the normal
zeertzjq0cc5dce2024-08-08 21:12:15 +02002586 searchpath for programs.
2587 *PATHEXT*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002588 On MS-Windows the ".exe", ".bat", etc. can optionally be
2589 included. Then the extensions in $PATHEXT are tried. Thus if
2590 "foo.exe" does not exist, "foo.exe.bat" can be found. If
2591 $PATHEXT is not set then ".com;.exe;.bat;.cmd" is used. A dot
2592 by itself can be used in $PATHEXT to try using the name
2593 without an extension. When 'shell' looks like a Unix shell,
2594 then the name is also tried without adding an extension.
2595 On MS-Windows it only checks if the file exists and is not a
2596 directory, not if it's really executable.
zeertzjq0cc5dce2024-08-08 21:12:15 +02002597 On MS-Windows an executable in the same directory as the Vim
2598 executable is always found. Since this directory is added to
2599 $PATH it should also work to execute it |win32-PATH|.
2600 *NoDefaultCurrentDirectoryInExePath*
2601 On MS-Windows an executable in Vim's current working directory
2602 is also normally found, but this can be disabled by setting
2603 the $NoDefaultCurrentDirectoryInExePath environment variable.
2604
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002605 The result is a Number:
2606 1 exists
2607 0 does not exist
2608 -1 not implemented on this system
2609 |exepath()| can be used to get the full path of an executable.
2610
2611 Can also be used as a |method|: >
2612 GetCommand()->executable()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002613<
2614 Return type: |Number|
2615
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002616
2617execute({command} [, {silent}]) *execute()*
2618 Execute an Ex command or commands and return the output as a
2619 string.
2620 {command} can be a string or a List. In case of a List the
2621 lines are executed one by one.
Bram Moolenaarb7398fe2023-05-14 18:50:25 +01002622 This is more or less equivalent to: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002623 redir => var
2624 {command}
2625 redir END
Bram Moolenaar71badf92023-04-22 22:40:14 +01002626< Except that line continuation in {command} is not recognized.
2627
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002628 The optional {silent} argument can have these values:
2629 "" no `:silent` used
2630 "silent" `:silent` used
2631 "silent!" `:silent!` used
2632 The default is "silent". Note that with "silent!", unlike
2633 `:redir`, error messages are dropped. When using an external
2634 command the screen may be messed up, use `system()` instead.
2635 *E930*
2636 It is not possible to use `:redir` anywhere in {command}.
2637
Bram Moolenaarb7398fe2023-05-14 18:50:25 +01002638 To get a list of lines use `split()` on the result: >
Bram Moolenaar75ab5902022-04-18 15:36:40 +01002639 execute('args')->split("\n")
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002640
2641< To execute a command in another window than the current one
2642 use `win_execute()`.
2643
2644 When used recursively the output of the recursive call is not
2645 included in the output of the higher level call.
2646
2647 Can also be used as a |method|: >
2648 GetCommand()->execute()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002649<
Marius Gedminasc98bfb92024-06-19 19:59:23 +02002650 Return type: |String|
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002651
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002652
2653exepath({expr}) *exepath()*
2654 If {expr} is an executable and is either an absolute path, a
2655 relative path or found in $PATH, return the full path.
2656 Note that the current directory is used when {expr} starts
2657 with "./", which may be a problem for Vim: >
2658 echo exepath(v:progpath)
2659< If {expr} cannot be found in $PATH or is not executable then
2660 an empty string is returned.
2661
2662 Can also be used as a |method|: >
2663 GetCommand()->exepath()
2664<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002665 Return type: |String|
2666
2667
2668exists({expr}) *exists()*
2669 The result is a Number, which is |TRUE| if {expr} is defined,
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002670 zero otherwise.
2671
2672 Note: In a compiled |:def| function the evaluation is done at
2673 runtime. Use `exists_compiled()` to evaluate the expression
2674 at compile time.
2675
2676 For checking for a supported feature use |has()|.
2677 For checking if a file exists use |filereadable()|.
2678
2679 The {expr} argument is a string, which contains one of these:
Bram Moolenaarf10911e2022-01-29 22:20:48 +00002680 varname internal variable (see
2681 dict.key |internal-variables|). Also works
2682 list[i] for |curly-braces-names|, |Dictionary|
Yegappan Lakshmanana2ebb6e2024-02-25 08:40:10 +01002683 import.Func entries, |List| items, class and
2684 class.Func object methods, imported items, etc.
2685 object.Func Does not work for local variables in a
2686 class.varname compiled `:def` function.
2687 object.varname Also works for a function in |Vim9|
Bram Moolenaar944697a2022-02-20 19:48:20 +00002688 script, since it can be used as a
2689 function reference.
Bram Moolenaarf10911e2022-01-29 22:20:48 +00002690 Beware that evaluating an index may
2691 cause an error message for an invalid
2692 expression. E.g.: >
2693 :let l = [1, 2, 3]
2694 :echo exists("l[5]")
2695< 0 >
2696 :echo exists("l[xx]")
2697< E121: Undefined variable: xx
2698 0
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002699 &option-name Vim option (only checks if it exists,
2700 not if it really works)
2701 +option-name Vim option that works.
2702 $ENVNAME environment variable (could also be
2703 done by comparing with an empty
2704 string)
2705 *funcname built-in function (see |functions|)
2706 or user defined function (see
2707 |user-functions|) that is implemented.
2708 Also works for a variable that is a
2709 Funcref.
2710 ?funcname built-in function that could be
2711 implemented; to be used to check if
2712 "funcname" is valid
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002713 :cmdname Ex command: built-in command, user
2714 command or command modifier |:command|.
2715 Returns:
2716 1 for match with start of a command
2717 2 full match with a command
2718 3 matches several user commands
2719 To check for a supported command
2720 always check the return value to be 2.
2721 :2match The |:2match| command.
Bram Moolenaarb529cfb2022-07-25 15:42:07 +01002722 :3match The |:3match| command (but you
2723 probably should not use it, it is
2724 reserved for internal usage)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002725 #event autocommand defined for this event
2726 #event#pattern autocommand defined for this event and
2727 pattern (the pattern is taken
2728 literally and compared to the
2729 autocommand patterns character by
2730 character)
2731 #group autocommand group exists
2732 #group#event autocommand defined for this group and
2733 event.
2734 #group#event#pattern
2735 autocommand defined for this group,
2736 event and pattern.
2737 ##event autocommand for this event is
2738 supported.
2739
2740 Examples: >
2741 exists("&shortname")
2742 exists("$HOSTNAME")
2743 exists("*strftime")
Bram Moolenaar944697a2022-02-20 19:48:20 +00002744 exists("*s:MyFunc") " only for legacy script
2745 exists("*MyFunc")
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002746 exists("bufcount")
2747 exists(":Make")
2748 exists("#CursorHold")
2749 exists("#BufReadPre#*.gz")
2750 exists("#filetypeindent")
2751 exists("#filetypeindent#FileType")
2752 exists("#filetypeindent#FileType#*")
2753 exists("##ColorScheme")
2754< There must be no space between the symbol (&/$/*/#) and the
2755 name.
2756 There must be no extra characters after the name, although in
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01002757 a few cases this is ignored. That may become stricter in the
2758 future, thus don't count on it!
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002759 Working example: >
2760 exists(":make")
2761< NOT working example: >
2762 exists(":make install")
2763
2764< Note that the argument must be a string, not the name of the
2765 variable itself. For example: >
2766 exists(bufcount)
2767< This doesn't check for existence of the "bufcount" variable,
2768 but gets the value of "bufcount", and checks if that exists.
2769
2770 Can also be used as a |method|: >
2771 Varname()->exists()
2772<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002773 Return type: |String|
2774
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002775
2776exists_compiled({expr}) *exists_compiled()*
2777 Like `exists()` but evaluated at compile time. This is useful
2778 to skip a block where a function is used that would otherwise
2779 give an error: >
2780 if exists_compiled('*ThatFunction')
2781 ThatFunction('works')
2782 endif
2783< If `exists()` were used then a compilation error would be
2784 given if ThatFunction() is not defined.
2785
2786 {expr} must be a literal string. *E1232*
2787 Can only be used in a |:def| function. *E1233*
2788 This does not work to check for arguments or local variables.
2789
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002790 Return type: |String|
2791
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002792
2793exp({expr}) *exp()*
2794 Return the exponential of {expr} as a |Float| in the range
2795 [0, inf].
2796 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar016188f2022-06-06 20:52:59 +01002797 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002798 Examples: >
2799 :echo exp(2)
2800< 7.389056 >
2801 :echo exp(-1)
2802< 0.367879
2803
2804 Can also be used as a |method|: >
2805 Compute()->exp()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002806<
2807 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002808
2809
2810expand({string} [, {nosuf} [, {list}]]) *expand()*
2811 Expand wildcards and the following special keywords in
2812 {string}. 'wildignorecase' applies.
2813
2814 If {list} is given and it is |TRUE|, a List will be returned.
2815 Otherwise the result is a String and when there are several
2816 matches, they are separated by <NL> characters. [Note: in
2817 version 5.0 a space was used, which caused problems when a
2818 file name contains a space]
2819
2820 If the expansion fails, the result is an empty string. A name
2821 for a non-existing file is not included, unless {string} does
2822 not start with '%', '#' or '<', see below.
2823
Christian Brabandtec9c3262024-02-21 20:40:05 +01002824 For a |:terminal| window '%' expands to a '!' followed by
h-east53753f62024-05-05 18:42:31 +02002825 the command or shell that is run. |terminal-bufname|
Christian Brabandtec9c3262024-02-21 20:40:05 +01002826
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002827 When {string} starts with '%', '#' or '<', the expansion is
2828 done like for the |cmdline-special| variables with their
2829 associated modifiers. Here is a short overview:
2830
2831 % current file name
2832 # alternate file name
2833 #n alternate file name n
2834 <cfile> file name under the cursor
2835 <afile> autocmd file name
2836 <abuf> autocmd buffer number (as a String!)
2837 <amatch> autocmd matched name
2838 <cexpr> C expression under the cursor
2839 <sfile> sourced script file or function name
2840 <slnum> sourced script line number or function
2841 line number
2842 <sflnum> script file line number, also when in
2843 a function
2844 <SID> "<SNR>123_" where "123" is the
2845 current script ID |<SID>|
Bram Moolenaar75ab5902022-04-18 15:36:40 +01002846 <script> sourced script file, or script file
2847 where the current function was defined
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002848 <stack> call stack
2849 <cword> word under the cursor
2850 <cWORD> WORD under the cursor
2851 <client> the {clientid} of the last received
2852 message |server2client()|
2853 Modifiers:
2854 :p expand to full path
2855 :h head (last path component removed)
2856 :t tail (last path component only)
2857 :r root (one extension removed)
2858 :e extension only
2859
2860 Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00002861 :let &tags = expand("%:p:h") .. "/tags"
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002862< Note that when expanding a string that starts with '%', '#' or
2863 '<', any following text is ignored. This does NOT work: >
2864 :let doesntwork = expand("%:h.bak")
2865< Use this: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00002866 :let doeswork = expand("%:h") .. ".bak"
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002867< Also note that expanding "<cfile>" and others only returns the
2868 referenced file name without further expansion. If "<cfile>"
2869 is "~/.cshrc", you need to do another expand() to have the
2870 "~/" expanded into the path of the home directory: >
2871 :echo expand(expand("<cfile>"))
2872<
2873 There cannot be white space between the variables and the
2874 following modifier. The |fnamemodify()| function can be used
2875 to modify normal file names.
2876
2877 When using '%' or '#', and the current or alternate file name
2878 is not defined, an empty string is used. Using "%:p" in a
2879 buffer with no name, results in the current directory, with a
2880 '/' added.
Bram Moolenaar57544522022-04-12 12:54:11 +01002881 When 'verbose' is set then expanding '%', '#' and <> items
2882 will result in an error message if the argument cannot be
2883 expanded.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002884
2885 When {string} does not start with '%', '#' or '<', it is
2886 expanded like a file name is expanded on the command line.
2887 'suffixes' and 'wildignore' are used, unless the optional
2888 {nosuf} argument is given and it is |TRUE|.
2889 Names for non-existing files are included. The "**" item can
2890 be used to search in a directory tree. For example, to find
2891 all "README" files in the current directory and below: >
2892 :echo expand("**/README")
2893<
2894 expand() can also be used to expand variables and environment
2895 variables that are only known in a shell. But this can be
2896 slow, because a shell may be used to do the expansion. See
2897 |expr-env-expand|.
2898 The expanded variable is still handled like a list of file
2899 names. When an environment variable cannot be expanded, it is
2900 left unchanged. Thus ":echo expand('$FOOBAR')" results in
2901 "$FOOBAR".
2902
2903 See |glob()| for finding existing files. See |system()| for
2904 getting the raw output of an external command.
2905
2906 Can also be used as a |method|: >
2907 Getpattern()->expand()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002908<
2909 Return type: |String| or list<string> depending on {list}
2910
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002911
Yegappan Lakshmanan2b74b682022-04-03 21:30:32 +01002912expandcmd({string} [, {options}]) *expandcmd()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002913 Expand special items in String {string} like what is done for
2914 an Ex command such as `:edit`. This expands special keywords,
2915 like with |expand()|, and environment variables, anywhere in
2916 {string}. "~user" and "~/path" are only expanded at the
2917 start.
Yegappan Lakshmanan2b74b682022-04-03 21:30:32 +01002918
2919 The following items are supported in the {options} Dict
2920 argument:
2921 errmsg If set to TRUE, error messages are displayed
2922 if an error is encountered during expansion.
2923 By default, error messages are not displayed.
2924
Yegappan Lakshmanan5018a832022-04-02 21:12:21 +01002925 Returns the expanded string. If an error is encountered
2926 during expansion, the unmodified {string} is returned.
Yegappan Lakshmanan2b74b682022-04-03 21:30:32 +01002927
Yegappan Lakshmanan5018a832022-04-02 21:12:21 +01002928 Example: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002929 :echo expandcmd('make %<.o')
Yegappan Lakshmanan2b74b682022-04-03 21:30:32 +01002930 make /path/runtime/doc/builtin.o
2931 :echo expandcmd('make %<.o', {'errmsg': v:true})
2932<
Yegappan Lakshmanan5018a832022-04-02 21:12:21 +01002933 Can also be used as a |method|: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002934 GetCommand()->expandcmd()
2935<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002936 Return type: |String| or list<string> depending on {list}
2937
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002938extend({expr1}, {expr2} [, {expr3}]) *extend()*
2939 {expr1} and {expr2} must be both |Lists| or both
2940 |Dictionaries|.
2941
2942 If they are |Lists|: Append {expr2} to {expr1}.
2943 If {expr3} is given insert the items of {expr2} before the
2944 item with index {expr3} in {expr1}. When {expr3} is zero
2945 insert before the first item. When {expr3} is equal to
2946 len({expr1}) then {expr2} is appended.
2947 Examples: >
2948 :echo sort(extend(mylist, [7, 5]))
2949 :call extend(mylist, [2, 3], 1)
2950< When {expr1} is the same List as {expr2} then the number of
2951 items copied is equal to the original length of the List.
2952 E.g., when {expr3} is 1 you get N new copies of the first item
2953 (where N is the original length of the List).
2954 Use |add()| to concatenate one item to a list. To concatenate
2955 two lists into a new list use the + operator: >
2956 :let newlist = [1, 2, 3] + [4, 5]
2957<
2958 If they are |Dictionaries|:
2959 Add all entries from {expr2} to {expr1}.
2960 If a key exists in both {expr1} and {expr2} then {expr3} is
2961 used to decide what to do:
2962 {expr3} = "keep": keep the value of {expr1}
2963 {expr3} = "force": use the value of {expr2}
2964 {expr3} = "error": give an error message *E737*
2965 When {expr3} is omitted then "force" is assumed.
2966
2967 {expr1} is changed when {expr2} is not empty. If necessary
2968 make a copy of {expr1} first.
2969 {expr2} remains unchanged.
2970 When {expr1} is locked and {expr2} is not empty the operation
2971 fails.
Bram Moolenaar016188f2022-06-06 20:52:59 +01002972 Returns {expr1}. Returns 0 on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002973
2974 Can also be used as a |method|: >
2975 mylist->extend(otherlist)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002976<
2977 Return type: list<{type}> or dict<{type}> depending on {expr1}
2978 and {expr2}, in case of error: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002979
2980
2981extendnew({expr1}, {expr2} [, {expr3}]) *extendnew()*
2982 Like |extend()| but instead of adding items to {expr1} a new
2983 List or Dictionary is created and returned. {expr1} remains
Bram Moolenaardd60c362023-02-27 15:49:53 +00002984 unchanged.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002985
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002986 Return type: list<{type}> or dict<{type}> depending on {expr1}
2987 and {expr2}, in case of error: |Number|
2988
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002989
2990feedkeys({string} [, {mode}]) *feedkeys()*
2991 Characters in {string} are queued for processing as if they
2992 come from a mapping or were typed by the user.
2993
2994 By default the string is added to the end of the typeahead
2995 buffer, thus if a mapping is still being executed the
2996 characters come after them. Use the 'i' flag to insert before
2997 other characters, they will be executed next, before any
2998 characters from a mapping.
2999
3000 The function does not wait for processing of keys contained in
3001 {string}.
3002
3003 To include special keys into {string}, use double-quotes
3004 and "\..." notation |expr-quote|. For example,
3005 feedkeys("\<CR>") simulates pressing of the <Enter> key. But
3006 feedkeys('\<CR>') pushes 5 characters.
3007 A special code that might be useful is <Ignore>, it exits the
3008 wait for a character without doing anything. *<Ignore>*
3009
3010 {mode} is a String, which can contain these character flags:
3011 'm' Remap keys. This is default. If {mode} is absent,
3012 keys are remapped.
3013 'n' Do not remap keys.
3014 't' Handle keys as if typed; otherwise they are handled as
3015 if coming from a mapping. This matters for undo,
3016 opening folds, etc.
3017 'L' Lowlevel input. Only works for Unix or when using the
3018 GUI. Keys are used as if they were coming from the
3019 terminal. Other flags are not used. *E980*
3020 When a CTRL-C interrupts and 't' is included it sets
3021 the internal "got_int" flag.
3022 'i' Insert the string instead of appending (see above).
3023 'x' Execute commands until typeahead is empty. This is
3024 similar to using ":normal!". You can call feedkeys()
3025 several times without 'x' and then one time with 'x'
3026 (possibly with an empty {string}) to execute all the
3027 typeahead. Note that when Vim ends in Insert mode it
3028 will behave as if <Esc> is typed, to avoid getting
3029 stuck, waiting for a character to be typed before the
3030 script continues.
3031 Note that if you manage to call feedkeys() while
3032 executing commands, thus calling it recursively, then
3033 all typeahead will be consumed by the last call.
Bram Moolenaara9725222022-01-16 13:30:33 +00003034 'c' Remove any script context when executing, so that
3035 legacy script syntax applies, "s:var" does not work,
Bram Moolenaard899e512022-05-07 21:54:03 +01003036 etc. Note that if the string being fed sets a script
Bram Moolenaarce001a32022-04-27 15:25:03 +01003037 context this still applies.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003038 '!' When used with 'x' will not end Insert mode. Can be
3039 used in a test when a timer is set to exit Insert mode
3040 a little later. Useful for testing CursorHoldI.
3041
3042 Return value is always 0.
3043
3044 Can also be used as a |method|: >
3045 GetInput()->feedkeys()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003046<
3047 Return type: |String| or list<string> depending on {list}
3048
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003049
Shougo Matsushita60c87432024-06-03 22:59:27 +02003050filecopy({from}, {to}) *filecopy()*
3051 Copy the file pointed to by the name {from} to {to}. The
3052 result is a Number, which is |TRUE| if the file was copied
3053 successfully, and |FALSE| when it failed.
3054 If a file with name {to} already exists, it will fail.
3055 Note that it does not handle directories (yet).
3056
3057 This function is not available in the |sandbox|.
3058
3059 Can also be used as a |method|: >
3060 GetOldName()->filecopy(newname)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003061<
3062 Return type: |Number|
3063
Shougo Matsushita60c87432024-06-03 22:59:27 +02003064
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003065filereadable({file}) *filereadable()*
3066 The result is a Number, which is |TRUE| when a file with the
3067 name {file} exists, and can be read. If {file} doesn't exist,
3068 or is a directory, the result is |FALSE|. {file} is any
3069 expression, which is used as a String.
3070 If you don't care about the file being readable you can use
3071 |glob()|.
3072 {file} is used as-is, you may want to expand wildcards first: >
3073 echo filereadable('~/.vimrc')
3074 0
3075 echo filereadable(expand('~/.vimrc'))
3076 1
3077
3078< Can also be used as a |method|: >
3079 GetName()->filereadable()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003080<
3081 Return type: |Number|
3082
3083 *file_readable()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003084 Obsolete name: file_readable().
3085
3086
3087filewritable({file}) *filewritable()*
3088 The result is a Number, which is 1 when a file with the
3089 name {file} exists, and can be written. If {file} doesn't
3090 exist, or is not writable, the result is 0. If {file} is a
3091 directory, and we can write to it, the result is 2.
3092
3093 Can also be used as a |method|: >
3094 GetName()->filewritable()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003095<
3096 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003097
3098
3099filter({expr1}, {expr2}) *filter()*
3100 {expr1} must be a |List|, |String|, |Blob| or |Dictionary|.
3101 For each item in {expr1} evaluate {expr2} and when the result
3102 is zero or false remove the item from the |List| or
3103 |Dictionary|. Similarly for each byte in a |Blob| and each
Bram Moolenaar2f0936c2022-01-08 21:51:59 +00003104 character in a |String|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003105
3106 {expr2} must be a |string| or |Funcref|.
3107
3108 If {expr2} is a |string|, inside {expr2} |v:val| has the value
3109 of the current item. For a |Dictionary| |v:key| has the key
3110 of the current item and for a |List| |v:key| has the index of
3111 the current item. For a |Blob| |v:key| has the index of the
3112 current byte. For a |String| |v:key| has the index of the
3113 current character.
3114 Examples: >
3115 call filter(mylist, 'v:val !~ "OLD"')
3116< Removes the items where "OLD" appears. >
3117 call filter(mydict, 'v:key >= 8')
3118< Removes the items with a key below 8. >
3119 call filter(var, 0)
3120< Removes all the items, thus clears the |List| or |Dictionary|.
3121
3122 Note that {expr2} is the result of expression and is then
3123 used as an expression again. Often it is good to use a
3124 |literal-string| to avoid having to double backslashes.
3125
3126 If {expr2} is a |Funcref| it must take two arguments:
3127 1. the key or the index of the current item.
3128 2. the value of the current item.
3129 The function must return |TRUE| if the item should be kept.
3130 Example that keeps the odd items of a list: >
3131 func Odd(idx, val)
3132 return a:idx % 2 == 1
3133 endfunc
3134 call filter(mylist, function('Odd'))
Bram Moolenaar2f0936c2022-01-08 21:51:59 +00003135< It is shorter when using a |lambda|. In |Vim9| syntax: >
3136 call filter(myList, (idx, val) => idx * val <= 42)
3137< In legacy script syntax: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003138 call filter(myList, {idx, val -> idx * val <= 42})
3139< If you do not use "val" you can leave it out: >
3140 call filter(myList, {idx -> idx % 2 == 1})
3141<
3142 In |Vim9| script the result must be true, false, zero or one.
3143 Other values will result in a type error.
3144
3145 For a |List| and a |Dictionary| the operation is done
3146 in-place. If you want it to remain unmodified make a copy
3147 first: >
3148 :let l = filter(copy(mylist), 'v:val =~ "KEEP"')
3149
3150< Returns {expr1}, the |List| or |Dictionary| that was filtered,
naohiro ono56200ee2022-01-01 14:59:44 +00003151 or a new |Blob| or |String|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003152 When an error is encountered while evaluating {expr2} no
3153 further items in {expr1} are processed.
3154 When {expr2} is a Funcref errors inside a function are ignored,
3155 unless it was defined with the "abort" flag.
3156
3157 Can also be used as a |method|: >
3158 mylist->filter(expr2)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003159<
3160 Return type: |String|, |Blob|, list<{type}> or dict<{type}>
3161 depending on {expr1}
3162
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003163
3164finddir({name} [, {path} [, {count}]]) *finddir()*
3165 Find directory {name} in {path}. Supports both downwards and
3166 upwards recursive directory searches. See |file-searching|
3167 for the syntax of {path}.
3168
3169 Returns the path of the first found match. When the found
3170 directory is below the current directory a relative path is
3171 returned. Otherwise a full path is returned.
3172 If {path} is omitted or empty then 'path' is used.
3173
3174 If the optional {count} is given, find {count}'s occurrence of
3175 {name} in {path} instead of the first one.
3176 When {count} is negative return all the matches in a |List|.
3177
Bram Moolenaar016188f2022-06-06 20:52:59 +01003178 Returns an empty string if the directory is not found.
3179
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003180 This is quite similar to the ex-command `:find`.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003181
3182 Can also be used as a |method|: >
3183 GetName()->finddir()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003184<
3185 Return type: |String|
3186
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003187
3188findfile({name} [, {path} [, {count}]]) *findfile()*
3189 Just like |finddir()|, but find a file instead of a directory.
3190 Uses 'suffixesadd'.
3191 Example: >
3192 :echo findfile("tags.vim", ".;")
3193< Searches from the directory of the current file upwards until
3194 it finds the file "tags.vim".
3195
3196 Can also be used as a |method|: >
3197 GetName()->findfile()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003198<
3199 Return type: |String|
3200
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003201
3202flatten({list} [, {maxdepth}]) *flatten()*
3203 Flatten {list} up to {maxdepth} levels. Without {maxdepth}
3204 the result is a |List| without nesting, as if {maxdepth} is
3205 a very large number.
3206 The {list} is changed in place, use |flattennew()| if you do
3207 not want that.
3208 In Vim9 script flatten() cannot be used, you must always use
Bram Moolenaara2baa732022-02-04 16:09:54 +00003209 |flattennew()|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003210 *E900*
3211 {maxdepth} means how deep in nested lists changes are made.
3212 {list} is not modified when {maxdepth} is 0.
3213 {maxdepth} must be positive number.
3214
3215 If there is an error the number zero is returned.
3216
3217 Example: >
3218 :echo flatten([1, [2, [3, 4]], 5])
3219< [1, 2, 3, 4, 5] >
3220 :echo flatten([1, [2, [3, 4]], 5], 1)
3221< [1, 2, [3, 4], 5]
3222
3223 Can also be used as a |method|: >
3224 mylist->flatten()
3225<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003226 Return type: list<{type}>
3227
3228
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003229flattennew({list} [, {maxdepth}]) *flattennew()*
3230 Like |flatten()| but first make a copy of {list}.
3231
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003232 Return type: list<{type}>
3233
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003234
3235float2nr({expr}) *float2nr()*
3236 Convert {expr} to a Number by omitting the part after the
3237 decimal point.
Bram Moolenaar76db9e02022-11-09 21:21:04 +00003238 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar016188f2022-06-06 20:52:59 +01003239 Returns 0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003240 When the value of {expr} is out of range for a |Number| the
3241 result is truncated to 0x7fffffff or -0x7fffffff (or when
3242 64-bit Number support is enabled, 0x7fffffffffffffff or
3243 -0x7fffffffffffffff). NaN results in -0x80000000 (or when
3244 64-bit Number support is enabled, -0x8000000000000000).
3245 Examples: >
3246 echo float2nr(3.95)
3247< 3 >
3248 echo float2nr(-23.45)
3249< -23 >
3250 echo float2nr(1.0e100)
3251< 2147483647 (or 9223372036854775807) >
3252 echo float2nr(-1.0e150)
3253< -2147483647 (or -9223372036854775807) >
3254 echo float2nr(1.0e-100)
3255< 0
3256
3257 Can also be used as a |method|: >
3258 Compute()->float2nr()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003259<
3260 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003261
3262
3263floor({expr}) *floor()*
3264 Return the largest integral value less than or equal to
3265 {expr} as a |Float| (round down).
3266 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar016188f2022-06-06 20:52:59 +01003267 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003268 Examples: >
3269 echo floor(1.856)
3270< 1.0 >
3271 echo floor(-5.456)
3272< -6.0 >
3273 echo floor(4.0)
3274< 4.0
3275
3276 Can also be used as a |method|: >
3277 Compute()->floor()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003278<
3279 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003280
3281
3282fmod({expr1}, {expr2}) *fmod()*
3283 Return the remainder of {expr1} / {expr2}, even if the
3284 division is not representable. Returns {expr1} - i * {expr2}
3285 for some integer i such that if {expr2} is non-zero, the
3286 result has the same sign as {expr1} and magnitude less than
3287 the magnitude of {expr2}. If {expr2} is zero, the value
3288 returned is zero. The value returned is a |Float|.
3289 {expr1} and {expr2} must evaluate to a |Float| or a |Number|.
Bram Moolenaar016188f2022-06-06 20:52:59 +01003290 Returns 0.0 if {expr1} or {expr2} is not a |Float| or a
3291 |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003292 Examples: >
3293 :echo fmod(12.33, 1.22)
3294< 0.13 >
3295 :echo fmod(-12.33, 1.22)
3296< -0.13
3297
3298 Can also be used as a |method|: >
3299 Compute()->fmod(1.22)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003300<
3301 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003302
3303
3304fnameescape({string}) *fnameescape()*
3305 Escape {string} for use as file name command argument. All
3306 characters that have a special meaning, such as '%' and '|'
3307 are escaped with a backslash.
3308 For most systems the characters escaped are
3309 " \t\n*?[{`$\\%#'\"|!<". For systems where a backslash
3310 appears in a filename, it depends on the value of 'isfname'.
3311 A leading '+' and '>' is also escaped (special after |:edit|
3312 and |:write|). And a "-" by itself (special after |:cd|).
Bram Moolenaar016188f2022-06-06 20:52:59 +01003313 Returns an empty string on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003314 Example: >
3315 :let fname = '+some str%nge|name'
Bram Moolenaarc51cf032022-02-26 12:25:45 +00003316 :exe "edit " .. fnameescape(fname)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003317< results in executing: >
3318 edit \+some\ str\%nge\|name
3319<
3320 Can also be used as a |method|: >
3321 GetName()->fnameescape()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003322<
3323 Return type: |String|
3324
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003325
3326fnamemodify({fname}, {mods}) *fnamemodify()*
3327 Modify file name {fname} according to {mods}. {mods} is a
3328 string of characters like it is used for file names on the
3329 command line. See |filename-modifiers|.
3330 Example: >
3331 :echo fnamemodify("main.c", ":p:h")
3332< results in: >
Bram Moolenaard799daa2022-06-20 11:17:32 +01003333 /home/user/vim/vim/src
Bram Moolenaar016188f2022-06-06 20:52:59 +01003334< If {mods} is empty or an unsupported modifier is used then
3335 {fname} is returned.
Bram Moolenaar5ed11532022-07-06 13:18:11 +01003336 When {fname} is empty then with {mods} ":h" returns ".", so
3337 that `:cd` can be used with it. This is different from
3338 expand('%:h') without a buffer name, which returns an empty
3339 string.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003340 Note: Environment variables don't work in {fname}, use
3341 |expand()| first then.
3342
3343 Can also be used as a |method|: >
3344 GetName()->fnamemodify(':p:h')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003345<
3346 Return type: |String|
3347
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003348
3349foldclosed({lnum}) *foldclosed()*
3350 The result is a Number. If the line {lnum} is in a closed
3351 fold, the result is the number of the first line in that fold.
3352 If the line {lnum} is not in a closed fold, -1 is returned.
3353 {lnum} is used like with |getline()|. Thus "." is the current
3354 line, "'m" mark m, etc.
3355
3356 Can also be used as a |method|: >
3357 GetLnum()->foldclosed()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003358<
3359 Return type: |Number|
3360
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003361
3362foldclosedend({lnum}) *foldclosedend()*
3363 The result is a Number. If the line {lnum} is in a closed
3364 fold, the result is the number of the last line in that fold.
3365 If the line {lnum} is not in a closed fold, -1 is returned.
3366 {lnum} is used like with |getline()|. Thus "." is the current
3367 line, "'m" mark m, etc.
3368
3369 Can also be used as a |method|: >
3370 GetLnum()->foldclosedend()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003371<
3372 Return type: |Number|
3373
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003374
3375foldlevel({lnum}) *foldlevel()*
3376 The result is a Number, which is the foldlevel of line {lnum}
3377 in the current buffer. For nested folds the deepest level is
3378 returned. If there is no fold at line {lnum}, zero is
3379 returned. It doesn't matter if the folds are open or closed.
3380 When used while updating folds (from 'foldexpr') -1 is
3381 returned for lines where folds are still to be updated and the
3382 foldlevel is unknown. As a special case the level of the
3383 previous line is usually available.
3384 {lnum} is used like with |getline()|. Thus "." is the current
3385 line, "'m" mark m, etc.
3386
3387 Can also be used as a |method|: >
3388 GetLnum()->foldlevel()
3389<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003390 Return type: |Number|
3391
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003392 *foldtext()*
3393foldtext() Returns a String, to be displayed for a closed fold. This is
3394 the default function used for the 'foldtext' option and should
3395 only be called from evaluating 'foldtext'. It uses the
3396 |v:foldstart|, |v:foldend| and |v:folddashes| variables.
3397 The returned string looks like this: >
3398 +-- 45 lines: abcdef
3399< The number of leading dashes depends on the foldlevel. The
3400 "45" is the number of lines in the fold. "abcdef" is the text
3401 in the first non-blank line of the fold. Leading white space,
3402 "//" or "/*" and the text from the 'foldmarker' and
3403 'commentstring' options is removed.
3404 When used to draw the actual foldtext, the rest of the line
3405 will be filled with the fold char from the 'fillchars'
3406 setting.
Bram Moolenaar016188f2022-06-06 20:52:59 +01003407 Returns an empty string when there is no fold.
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003408
3409 Return type: |String|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003410 {not available when compiled without the |+folding| feature}
3411
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003412
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003413foldtextresult({lnum}) *foldtextresult()*
3414 Returns the text that is displayed for the closed fold at line
3415 {lnum}. Evaluates 'foldtext' in the appropriate context.
3416 When there is no closed fold at {lnum} an empty string is
3417 returned.
3418 {lnum} is used like with |getline()|. Thus "." is the current
3419 line, "'m" mark m, etc.
3420 Useful when exporting folded text, e.g., to HTML.
3421 {not available when compiled without the |+folding| feature}
3422
3423
3424 Can also be used as a |method|: >
3425 GetLnum()->foldtextresult()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003426<
3427 Return type: |String|
3428
Ernie Raele79e2072024-01-13 11:47:33 +01003429
3430foreach({expr1}, {expr2}) *foreach()*
3431 {expr1} must be a |List|, |String|, |Blob| or |Dictionary|.
3432 For each item in {expr1} execute {expr2}. {expr1} is not
erraelc92b8be2024-01-14 10:11:07 -08003433 modified; its values may be, as with |:lockvar| 1. |E741|
Ernie Raele79e2072024-01-13 11:47:33 +01003434 See |map()| and |filter()| to modify {expr1}.
3435
3436 {expr2} must be a |string| or |Funcref|.
3437
3438 If {expr2} is a |string|, inside {expr2} |v:val| has the value
3439 of the current item. For a |Dictionary| |v:key| has the key
3440 of the current item and for a |List| |v:key| has the index of
3441 the current item. For a |Blob| |v:key| has the index of the
3442 current byte. For a |String| |v:key| has the index of the
3443 current character.
3444 Examples: >
3445 call foreach(mylist, 'used[v:val] = true')
3446< This records the items that are in the {expr1} list.
3447
3448 Note that {expr2} is the result of expression and is then used
3449 as a command. Often it is good to use a |literal-string| to
3450 avoid having to double backslashes.
3451
3452 If {expr2} is a |Funcref| it must take two arguments:
3453 1. the key or the index of the current item.
3454 2. the value of the current item.
3455 With a legacy script lambda you don't get an error if it only
3456 accepts one argument, but with a Vim9 lambda you get "E1106:
3457 One argument too many", the number of arguments must match.
3458 If the function returns a value, it is ignored.
3459
3460 Returns {expr1} in all cases.
3461 When an error is encountered while executing {expr2} no
3462 further items in {expr1} are processed.
3463 When {expr2} is a Funcref errors inside a function are ignored,
3464 unless it was defined with the "abort" flag.
3465
3466 Can also be used as a |method|: >
3467 mylist->foreach(expr2)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003468<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003469 Return type: |String|, |Blob| list<{type}> or dict<{type}>
3470 depending on {expr1}
3471
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003472 *foreground()*
3473foreground() Move the Vim window to the foreground. Useful when sent from
3474 a client to a Vim server. |remote_send()|
3475 On Win32 systems this might not work, the OS does not always
3476 allow a window to bring itself to the foreground. Use
3477 |remote_foreground()| instead.
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003478
3479 Return type: |Number|
Bram Moolenaarcbaff5e2022-04-08 17:45:08 +01003480 {only in the Win32, Motif and GTK GUI versions and the
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003481 Win32 console version}
3482
Bram Moolenaaraa534142022-09-15 21:46:02 +01003483fullcommand({name} [, {vim9}]) *fullcommand()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003484 Get the full command name from a short abbreviated command
3485 name; see |20.2| for details on command abbreviations.
3486
3487 The string argument {name} may start with a `:` and can
3488 include a [range], these are skipped and not returned.
Bram Moolenaaraa534142022-09-15 21:46:02 +01003489 Returns an empty string if a command doesn't exist, if it's
3490 ambiguous (for user-defined commands) or cannot be shortened
3491 this way. |vim9-no-shorten|
3492
3493 Without the {vim9} argument uses the current script version.
3494 If {vim9} is present and FALSE then legacy script rules are
3495 used. When {vim9} is present and TRUE then Vim9 rules are
3496 used, e.g. "en" is not a short form of "endif".
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003497
3498 For example `fullcommand('s')`, `fullcommand('sub')`,
3499 `fullcommand(':%substitute')` all return "substitute".
3500
3501 Can also be used as a |method|: >
3502 GetName()->fullcommand()
3503<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003504 Return type: |String|
3505
3506
3507funcref({name} [, {arglist}] [, {dict}]) *funcref()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003508 Just like |function()|, but the returned Funcref will lookup
3509 the function by reference, not by name. This matters when the
3510 function {name} is redefined later.
3511
3512 Unlike |function()|, {name} must be an existing user function.
Bram Moolenaar2f0936c2022-01-08 21:51:59 +00003513 It only works for an autoloaded function if it has already
3514 been loaded (to avoid mistakenly loading the autoload script
3515 when only intending to use the function name, use |function()|
3516 instead). {name} cannot be a builtin function.
Bram Moolenaar016188f2022-06-06 20:52:59 +01003517 Returns 0 on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003518
3519 Can also be used as a |method|: >
3520 GetFuncname()->funcref([arg])
3521<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003522 Return type: func(...): any or |Number| on error
3523
Dominique Pellee764d1b2023-03-12 21:20:59 +00003524 *function()* *partial* *E700* *E923*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003525function({name} [, {arglist}] [, {dict}])
3526 Return a |Funcref| variable that refers to function {name}.
3527 {name} can be the name of a user defined function or an
3528 internal function.
3529
3530 {name} can also be a Funcref or a partial. When it is a
3531 partial the dict stored in it will be used and the {dict}
3532 argument is not allowed. E.g.: >
3533 let FuncWithArg = function(dict.Func, [arg])
3534 let Broken = function(dict.Func, [arg], dict)
3535<
3536 When using the Funcref the function will be found by {name},
3537 also when it was redefined later. Use |funcref()| to keep the
3538 same function.
3539
3540 When {arglist} or {dict} is present this creates a partial.
3541 That means the argument list and/or the dictionary is stored in
3542 the Funcref and will be used when the Funcref is called.
3543
3544 The arguments are passed to the function in front of other
3545 arguments, but after any argument from |method|. Example: >
3546 func Callback(arg1, arg2, name)
3547 ...
3548 let Partial = function('Callback', ['one', 'two'])
3549 ...
3550 call Partial('name')
3551< Invokes the function as with: >
3552 call Callback('one', 'two', 'name')
3553
3554< With a |method|: >
3555 func Callback(one, two, three)
3556 ...
3557 let Partial = function('Callback', ['two'])
3558 ...
3559 eval 'one'->Partial('three')
3560< Invokes the function as with: >
3561 call Callback('one', 'two', 'three')
3562
3563< The function() call can be nested to add more arguments to the
3564 Funcref. The extra arguments are appended to the list of
3565 arguments. Example: >
3566 func Callback(arg1, arg2, name)
Bram Moolenaar0daafaa2022-09-04 17:45:43 +01003567 "...
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003568 let Func = function('Callback', ['one'])
3569 let Func2 = function(Func, ['two'])
Bram Moolenaar0daafaa2022-09-04 17:45:43 +01003570 "...
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003571 call Func2('name')
3572< Invokes the function as with: >
3573 call Callback('one', 'two', 'name')
3574
3575< The Dictionary is only useful when calling a "dict" function.
3576 In that case the {dict} is passed in as "self". Example: >
3577 function Callback() dict
Bram Moolenaarc51cf032022-02-26 12:25:45 +00003578 echo "called for " .. self.name
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003579 endfunction
Bram Moolenaar0daafaa2022-09-04 17:45:43 +01003580 "...
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003581 let context = {"name": "example"}
3582 let Func = function('Callback', context)
Bram Moolenaar0daafaa2022-09-04 17:45:43 +01003583 "...
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003584 call Func() " will echo: called for example
3585< The use of function() is not needed when there are no extra
Bram Moolenaar0daafaa2022-09-04 17:45:43 +01003586 arguments, these two are equivalent, if Callback() is defined
3587 as context.Callback(): >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003588 let Func = function('Callback', context)
3589 let Func = context.Callback
3590
3591< The argument list and the Dictionary can be combined: >
3592 function Callback(arg1, count) dict
Bram Moolenaar0daafaa2022-09-04 17:45:43 +01003593 "...
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003594 let context = {"name": "example"}
3595 let Func = function('Callback', ['one'], context)
Bram Moolenaar0daafaa2022-09-04 17:45:43 +01003596 "...
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003597 call Func(500)
3598< Invokes the function as with: >
3599 call context.Callback('one', 500)
3600<
Bram Moolenaar016188f2022-06-06 20:52:59 +01003601 Returns 0 on error.
3602
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003603 Can also be used as a |method|: >
3604 GetFuncname()->function([arg])
3605
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003606<
3607 Return type: func(...): any or |Number| on error
3608
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003609
3610garbagecollect([{atexit}]) *garbagecollect()*
3611 Cleanup unused |Lists|, |Dictionaries|, |Channels| and |Jobs|
3612 that have circular references.
3613
3614 There is hardly ever a need to invoke this function, as it is
3615 automatically done when Vim runs out of memory or is waiting
3616 for the user to press a key after 'updatetime'. Items without
3617 circular references are always freed when they become unused.
3618 This is useful if you have deleted a very big |List| and/or
3619 |Dictionary| with circular references in a script that runs
3620 for a long time.
3621
3622 When the optional {atexit} argument is one, garbage
3623 collection will also be done when exiting Vim, if it wasn't
3624 done before. This is useful when checking for memory leaks.
3625
3626 The garbage collection is not done immediately but only when
3627 it's safe to perform. This is when waiting for the user to
3628 type a character. To force garbage collection immediately use
3629 |test_garbagecollect_now()|.
3630
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003631 Return type: |String|
3632
3633
LemonBoy48b7d052024-07-09 18:24:59 +02003634get({list}, {idx} [, {default}]) *get()* *get()-list*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003635 Get item {idx} from |List| {list}. When this item is not
3636 available return {default}. Return zero when {default} is
3637 omitted.
3638 Preferably used as a |method|: >
3639 mylist->get(idx)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003640<
3641 Return type: any, depending on {list}
3642
LemonBoy48b7d052024-07-09 18:24:59 +02003643get({blob}, {idx} [, {default}]) *get()-blob*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003644 Get byte {idx} from |Blob| {blob}. When this byte is not
3645 available return {default}. Return -1 when {default} is
3646 omitted.
3647 Preferably used as a |method|: >
3648 myblob->get(idx)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003649<
3650 Return type: |Number|
3651
LemonBoy48b7d052024-07-09 18:24:59 +02003652get({dict}, {key} [, {default}]) *get()-dict*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003653 Get item with key {key} from |Dictionary| {dict}. When this
3654 item is not available return {default}. Return zero when
3655 {default} is omitted. Useful example: >
3656 let val = get(g:, 'var_name', 'default')
3657< This gets the value of g:var_name if it exists, and uses
3658 'default' when it does not exist.
3659 Preferably used as a |method|: >
3660 mydict->get(key)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003661<
h-east84ac2122024-06-17 18:12:30 +02003662 Return type: any, depending on {dict}
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003663
LemonBoy48b7d052024-07-09 18:24:59 +02003664get({func}, {what}) *get()-func*
3665 Get item {what} from |Funcref| {func}. Possible values for
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003666 {what} are:
LemonBoy48b7d052024-07-09 18:24:59 +02003667 "name" The function name
3668 "func" The function
3669 "dict" The dictionary
3670 "args" The list with arguments
3671 "arity" A dictionary with information about the number of
3672 arguments accepted by the function (minus the
3673 {arglist}) with the following fields:
3674 required the number of positional arguments
3675 optional the number of optional arguments,
3676 in addition to the required ones
3677 varargs |TRUE| if the function accepts a
3678 variable number of arguments |...|
3679
3680 Note: There is no error, if the {arglist} of
3681 the Funcref contains more arguments than the
3682 Funcref expects, it's not validated.
3683
Bram Moolenaar016188f2022-06-06 20:52:59 +01003684 Returns zero on error.
LemonBoy48b7d052024-07-09 18:24:59 +02003685
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003686 Preferably used as a |method|: >
3687 myfunc->get(what)
3688<
LemonBoy48b7d052024-07-09 18:24:59 +02003689 Return type: any, depending on {func} and {what}
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003690
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003691 *getbufinfo()*
3692getbufinfo([{buf}])
3693getbufinfo([{dict}])
3694 Get information about buffers as a List of Dictionaries.
3695
3696 Without an argument information about all the buffers is
3697 returned.
3698
3699 When the argument is a |Dictionary| only the buffers matching
3700 the specified criteria are returned. The following keys can
3701 be specified in {dict}:
3702 buflisted include only listed buffers.
3703 bufloaded include only loaded buffers.
3704 bufmodified include only modified buffers.
3705
3706 Otherwise, {buf} specifies a particular buffer to return
3707 information for. For the use of {buf}, see |bufname()|
3708 above. If the buffer is found the returned List has one item.
3709 Otherwise the result is an empty list.
3710
3711 Each returned List item is a dictionary with the following
3712 entries:
3713 bufnr Buffer number.
3714 changed TRUE if the buffer is modified.
3715 changedtick Number of changes made to the buffer.
Sean Dewar1fb41032023-08-16 17:15:05 +01003716 command TRUE if the buffer belongs to the
3717 command-line window |cmdwin|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003718 hidden TRUE if the buffer is hidden.
3719 lastused Timestamp in seconds, like
3720 |localtime()|, when the buffer was
3721 last used.
3722 {only with the |+viminfo| feature}
3723 listed TRUE if the buffer is listed.
3724 lnum Line number used for the buffer when
3725 opened in the current window.
3726 Only valid if the buffer has been
3727 displayed in the window in the past.
3728 If you want the line number of the
3729 last known cursor position in a given
3730 window, use |line()|: >
3731 :echo line('.', {winid})
3732<
3733 linecount Number of lines in the buffer (only
3734 valid when loaded)
3735 loaded TRUE if the buffer is loaded.
3736 name Full path to the file in the buffer.
3737 signs List of signs placed in the buffer.
3738 Each list item is a dictionary with
3739 the following fields:
3740 id sign identifier
3741 lnum line number
3742 name sign name
3743 variables A reference to the dictionary with
3744 buffer-local variables.
3745 windows List of |window-ID|s that display this
3746 buffer
3747 popups List of popup |window-ID|s that
3748 display this buffer
3749
3750 Examples: >
3751 for buf in getbufinfo()
3752 echo buf.name
3753 endfor
3754 for buf in getbufinfo({'buflisted':1})
3755 if buf.changed
3756 ....
3757 endif
3758 endfor
3759<
3760 To get buffer-local options use: >
3761 getbufvar({bufnr}, '&option_name')
3762<
3763 Can also be used as a |method|: >
3764 GetBufnr()->getbufinfo()
3765<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003766 Return type: list<dict<any>>
3767
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003768
3769 *getbufline()*
3770getbufline({buf}, {lnum} [, {end}])
3771 Return a |List| with the lines starting from {lnum} to {end}
3772 (inclusive) in the buffer {buf}. If {end} is omitted, a
Bram Moolenaarce30ccc2022-11-21 19:57:04 +00003773 |List| with only the line {lnum} is returned. See
3774 `getbufoneline()` for only getting the line.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003775
3776 For the use of {buf}, see |bufname()| above.
3777
3778 For {lnum} and {end} "$" can be used for the last line of the
3779 buffer. Otherwise a number must be used.
3780
3781 When {lnum} is smaller than 1 or bigger than the number of
3782 lines in the buffer, an empty |List| is returned.
3783
3784 When {end} is greater than the number of lines in the buffer,
3785 it is treated as {end} is set to the number of lines in the
3786 buffer. When {end} is before {lnum} an empty |List| is
3787 returned.
3788
3789 This function works only for loaded buffers. For unloaded and
3790 non-existing buffers, an empty |List| is returned.
3791
3792 Example: >
3793 :let lines = getbufline(bufnr("myfile"), 1, "$")
3794
3795< Can also be used as a |method|: >
3796 GetBufnr()->getbufline(lnum)
Bram Moolenaarce30ccc2022-11-21 19:57:04 +00003797<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003798 Return type: list<string>
3799
Bram Moolenaarce30ccc2022-11-21 19:57:04 +00003800 *getbufoneline()*
3801getbufoneline({buf}, {lnum})
3802 Just like `getbufline()` but only get one line and return it
3803 as a string.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003804
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003805 Return type: |String|
3806
3807
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003808getbufvar({buf}, {varname} [, {def}]) *getbufvar()*
3809 The result is the value of option or local buffer variable
3810 {varname} in buffer {buf}. Note that the name without "b:"
3811 must be used.
3812 The {varname} argument is a string.
3813 When {varname} is empty returns a |Dictionary| with all the
3814 buffer-local variables.
3815 When {varname} is equal to "&" returns a |Dictionary| with all
3816 the buffer-local options.
3817 Otherwise, when {varname} starts with "&" returns the value of
3818 a buffer-local option.
3819 This also works for a global or buffer-local option, but it
3820 doesn't work for a global variable, window-local variable or
3821 window-local option.
3822 For the use of {buf}, see |bufname()| above.
3823 When the buffer or variable doesn't exist {def} or an empty
3824 string is returned, there is no error message.
3825 Examples: >
3826 :let bufmodified = getbufvar(1, "&mod")
Bram Moolenaarc51cf032022-02-26 12:25:45 +00003827 :echo "todo myvar = " .. getbufvar("todo", "myvar")
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003828
3829< Can also be used as a |method|: >
3830 GetBufnr()->getbufvar(varname)
3831<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003832 Return type: any, depending on {varname}
3833
3834
mikoto20001083cae2024-11-11 21:24:14 +01003835getcellpixels() *getcellpixels()*
3836 Returns a |List| of terminal cell pixel size.
h-eastb534e802024-12-03 20:37:52 +01003837 List format is [xpixel, ypixel].
mikoto2000a73dfc22024-11-18 21:12:21 +01003838
3839 Only works on Unix (terminal and gVim) and Windows (gVim only).
3840 Returns [] on other systems or on failure.
3841 Note that there could be variations across different terminals.
3842 On macOS, system Terminal.app returns sizes in points (before
3843 Retina scaling), whereas third-party terminals return raw pixel
3844 sizes (post Retina scaling).
mikoto20001083cae2024-11-11 21:24:14 +01003845
mikoto2000de094dc2024-11-14 22:13:48 +01003846 Return type: list<any>
mikoto20001083cae2024-11-11 21:24:14 +01003847
3848
Kota Kato66bb9ae2023-01-17 18:31:56 +00003849getcellwidths() *getcellwidths()*
3850 Returns a |List| of cell widths of character ranges overridden
3851 by |setcellwidths()|. The format is equal to the argument of
3852 |setcellwidths()|. If no character ranges have their cell
3853 widths overridden, an empty List is returned.
h-east84ac2122024-06-17 18:12:30 +02003854
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003855 Return type: list<any>
Kota Kato66bb9ae2023-01-17 18:31:56 +00003856
3857
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003858getchangelist([{buf}]) *getchangelist()*
3859 Returns the |changelist| for the buffer {buf}. For the use
3860 of {buf}, see |bufname()| above. If buffer {buf} doesn't
3861 exist, an empty list is returned.
3862
3863 The returned list contains two entries: a list with the change
3864 locations and the current position in the list. Each
3865 entry in the change list is a dictionary with the following
3866 entries:
3867 col column number
3868 coladd column offset for 'virtualedit'
3869 lnum line number
3870 If buffer {buf} is the current buffer, then the current
3871 position refers to the position in the list. For other
3872 buffers, it is set to the length of the list.
3873
3874 Can also be used as a |method|: >
3875 GetBufnr()->getchangelist()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003876<
3877 Return type: list<any>
3878
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003879
Doug Kearns9cd9e752024-04-07 17:42:17 +02003880getchar([{expr}]) *getchar()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003881 Get a single character from the user or input stream.
Doug Kearns9cd9e752024-04-07 17:42:17 +02003882 If {expr} is omitted, wait until a character is available.
3883 If {expr} is 0, only get a character when one is available.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003884 Return zero otherwise.
Doug Kearns9cd9e752024-04-07 17:42:17 +02003885 If {expr} is 1, only check if a character is available, it is
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003886 not consumed. Return zero if no character available.
3887 If you prefer always getting a string use |getcharstr()|.
3888
Doug Kearns9cd9e752024-04-07 17:42:17 +02003889 Without {expr} and when {expr} is 0 a whole character or
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003890 special key is returned. If it is a single character, the
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01003891 result is a Number. Use |nr2char()| to convert it to a String.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003892 Otherwise a String is returned with the encoded character.
3893 For a special key it's a String with a sequence of bytes
3894 starting with 0x80 (decimal: 128). This is the same value as
3895 the String "\<Key>", e.g., "\<Left>". The returned value is
3896 also a String when a modifier (shift, control, alt) was used
3897 that is not included in the character.
3898
Doug Kearns9cd9e752024-04-07 17:42:17 +02003899 When {expr} is 0 and Esc is typed, there will be a short delay
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003900 while Vim waits to see if this is the start of an escape
3901 sequence.
3902
Doug Kearns9cd9e752024-04-07 17:42:17 +02003903 When {expr} is 1 only the first byte is returned. For a
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003904 one-byte character it is the character itself as a number.
3905 Use nr2char() to convert it to a String.
3906
3907 Use getcharmod() to obtain any additional modifiers.
3908
3909 When the user clicks a mouse button, the mouse event will be
3910 returned. The position can then be found in |v:mouse_col|,
3911 |v:mouse_lnum|, |v:mouse_winid| and |v:mouse_win|.
3912 |getmousepos()| can also be used. Mouse move events will be
3913 ignored.
3914 This example positions the mouse as it would normally happen: >
3915 let c = getchar()
3916 if c == "\<LeftMouse>" && v:mouse_win > 0
Bram Moolenaarc51cf032022-02-26 12:25:45 +00003917 exe v:mouse_win .. "wincmd w"
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003918 exe v:mouse_lnum
Bram Moolenaarc51cf032022-02-26 12:25:45 +00003919 exe "normal " .. v:mouse_col .. "|"
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003920 endif
3921<
3922 When using bracketed paste only the first character is
3923 returned, the rest of the pasted text is dropped.
3924 |xterm-bracketed-paste|.
3925
3926 There is no prompt, you will somehow have to make clear to the
3927 user that a character has to be typed. The screen is not
3928 redrawn, e.g. when resizing the window. When using a popup
3929 window it should work better with a |popup-filter|.
3930
3931 There is no mapping for the character.
3932 Key codes are replaced, thus when the user presses the <Del>
3933 key you get the code for the <Del> key, not the raw character
3934 sequence. Examples: >
3935 getchar() == "\<Del>"
3936 getchar() == "\<S-Left>"
3937< This example redefines "f" to ignore case: >
3938 :nmap f :call FindChar()<CR>
3939 :function FindChar()
3940 : let c = nr2char(getchar())
3941 : while col('.') < col('$') - 1
3942 : normal l
3943 : if getline('.')[col('.') - 1] ==? c
3944 : break
3945 : endif
3946 : endwhile
3947 :endfunction
3948<
3949 You may also receive synthetic characters, such as
3950 |<CursorHold>|. Often you will want to ignore this and get
3951 another character: >
3952 :function GetKey()
3953 : let c = getchar()
3954 : while c == "\<CursorHold>"
3955 : let c = getchar()
3956 : endwhile
3957 : return c
3958 :endfunction
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003959<
3960 Return type: |Number| or |String|
3961
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003962
3963getcharmod() *getcharmod()*
3964 The result is a Number which is the state of the modifiers for
3965 the last obtained character with getchar() or in another way.
3966 These values are added together:
3967 2 shift
3968 4 control
3969 8 alt (meta)
3970 16 meta (when it's different from ALT)
3971 32 mouse double click
3972 64 mouse triple click
3973 96 mouse quadruple click (== 32 + 64)
Casey Tucker92e90a12024-01-25 22:44:00 +01003974 128 command (Mac) or super (GTK)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003975 Only the modifiers that have not been included in the
3976 character itself are obtained. Thus Shift-a results in "A"
Bram Moolenaar016188f2022-06-06 20:52:59 +01003977 without a modifier. Returns 0 if no modifiers are used.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003978
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003979 Return type: |Number|
3980
3981
3982getcharpos({expr}) *getcharpos()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003983 Get the position for String {expr}. Same as |getpos()| but the
3984 column number in the returned List is a character index
3985 instead of a byte index.
naohiro ono56200ee2022-01-01 14:59:44 +00003986 If |getpos()| returns a very large column number, equal to
3987 |v:maxcol|, then getcharpos() will return the character index
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003988 of the last character.
3989
3990 Example:
3991 With the cursor on '세' in line 5 with text "여보세요": >
3992 getcharpos('.') returns [0, 5, 3, 0]
3993 getpos('.') returns [0, 5, 7, 0]
3994<
3995 Can also be used as a |method|: >
3996 GetMark()->getcharpos()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003997<
3998 Return type: list<number>
3999
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004000
4001getcharsearch() *getcharsearch()*
4002 Return the current character search information as a {dict}
4003 with the following entries:
4004
4005 char character previously used for a character
4006 search (|t|, |f|, |T|, or |F|); empty string
4007 if no character search has been performed
4008 forward direction of character search; 1 for forward,
4009 0 for backward
4010 until type of character search; 1 for a |t| or |T|
4011 character search, 0 for an |f| or |F|
4012 character search
4013
4014 This can be useful to always have |;| and |,| search
4015 forward/backward regardless of the direction of the previous
4016 character search: >
4017 :nnoremap <expr> ; getcharsearch().forward ? ';' : ','
4018 :nnoremap <expr> , getcharsearch().forward ? ',' : ';'
4019< Also see |setcharsearch()|.
4020
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004021 Return type: dict<any>
4022
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004023
Doug Kearns9cd9e752024-04-07 17:42:17 +02004024getcharstr([{expr}]) *getcharstr()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004025 Get a single character from the user or input stream as a
4026 string.
Doug Kearns9cd9e752024-04-07 17:42:17 +02004027 If {expr} is omitted, wait until a character is available.
4028 If {expr} is 0 or false, only get a character when one is
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004029 available. Return an empty string otherwise.
Doug Kearns9cd9e752024-04-07 17:42:17 +02004030 If {expr} is 1 or true, only check if a character is
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004031 available, it is not consumed. Return an empty string
4032 if no character is available.
4033 Otherwise this works like |getchar()|, except that a number
4034 result is converted to a string.
4035
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004036 Return type: |String|
4037
Ruslan Russkikh0407d622024-10-08 22:21:05 +02004038getcmdcomplpat() *getcmdcomplpat()*
4039 Return completion pattern of the current command-line.
4040 Only works when the command line is being edited, thus
4041 requires use of |c_CTRL-\_e| or |c_CTRL-R_=|.
4042 Also see |getcmdtype()|, |setcmdpos()|, |getcmdline()|,
4043 |getcmdprompt()|, |getcmdcompltype()| and |setcmdline()|.
4044 Returns an empty string when completion is not defined.
4045
4046 Return type: |String|
4047
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004048
Shougo Matsushita79d599b2022-05-07 12:48:29 +01004049getcmdcompltype() *getcmdcompltype()*
4050 Return the type of the current command-line completion.
4051 Only works when the command line is being edited, thus
4052 requires use of |c_CTRL-\_e| or |c_CTRL-R_=|.
Bram Moolenaar921bde82022-05-09 19:50:35 +01004053 See |:command-completion| for the return string.
Shougo Matsushita69084282024-09-23 20:34:47 +02004054 Also see |getcmdtype()|, |setcmdpos()|, |getcmdline()|,
Ruslan Russkikh0407d622024-10-08 22:21:05 +02004055 |getcmdprompt()|, |getcmdcomplpat()| and |setcmdline()|.
Shougo Matsushita79d599b2022-05-07 12:48:29 +01004056 Returns an empty string when completion is not defined.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004057
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004058 Return type: |String|
4059
4060
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004061getcmdline() *getcmdline()*
Shougo Matsushita69084282024-09-23 20:34:47 +02004062 Return the current command-line input. Only works when the
4063 command line is being edited, thus requires use of
4064 |c_CTRL-\_e| or |c_CTRL-R_=|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004065 Example: >
4066 :cmap <F7> <C-\>eescape(getcmdline(), ' \')<CR>
Shougo Matsushita69084282024-09-23 20:34:47 +02004067< Also see |getcmdtype()|, |getcmdpos()|, |setcmdpos()|,
4068 |getcmdprompt()| and |setcmdline()|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004069 Returns an empty string when entering a password or using
4070 |inputsecret()|.
4071
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004072 Return type: |String|
4073
4074
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004075getcmdpos() *getcmdpos()*
4076 Return the position of the cursor in the command line as a
4077 byte count. The first column is 1.
4078 Only works when editing the command line, thus requires use of
4079 |c_CTRL-\_e| or |c_CTRL-R_=| or an expression mapping.
4080 Returns 0 otherwise.
Shougo Matsushita69084282024-09-23 20:34:47 +02004081 Also see |getcmdtype()|, |setcmdpos()|, |getcmdline()|,
4082 |getcmdprompt()| and |setcmdline()|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004083
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004084 Return type: |Number|
4085
4086
Shougo Matsushita69084282024-09-23 20:34:47 +02004087getcmdprompt() *getcmdprompt()*
4088 Return the current command-line prompt when using functions
4089 like |input()| or |confirm()|.
4090 Only works when the command line is being edited, thus
4091 requires use of |c_CTRL-\_e| or |c_CTRL-R_=|.
4092 Also see |getcmdtype()|, |getcmdline()|, |getcmdpos()|,
4093 |setcmdpos()| and |setcmdline()|.
4094
4095 Return type: |String|
4096
4097
Shougo Matsushita79d599b2022-05-07 12:48:29 +01004098getcmdscreenpos() *getcmdscreenpos()*
4099 Return the screen position of the cursor in the command line
4100 as a byte count. The first column is 1.
4101 Instead of |getcmdpos()|, it adds the prompt position.
4102 Only works when editing the command line, thus requires use of
4103 |c_CTRL-\_e| or |c_CTRL-R_=| or an expression mapping.
4104 Returns 0 otherwise.
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01004105 Also see |getcmdpos()|, |setcmdpos()|, |getcmdline()| and
4106 |setcmdline()|.
Shougo Matsushita79d599b2022-05-07 12:48:29 +01004107
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004108 Return type: |Number|
4109
4110
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004111getcmdtype() *getcmdtype()*
4112 Return the current command-line type. Possible return values
4113 are:
4114 : normal Ex command
4115 > debug mode command |debug-mode|
4116 / forward search command
4117 ? backward search command
4118 @ |input()| command
4119 - |:insert| or |:append| command
4120 = |i_CTRL-R_=|
4121 Only works when editing the command line, thus requires use of
4122 |c_CTRL-\_e| or |c_CTRL-R_=| or an expression mapping.
4123 Returns an empty string otherwise.
4124 Also see |getcmdpos()|, |setcmdpos()| and |getcmdline()|.
4125
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004126 Return type: |String|
4127
4128
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004129getcmdwintype() *getcmdwintype()*
4130 Return the current |command-line-window| type. Possible return
4131 values are the same as |getcmdtype()|. Returns an empty string
4132 when not in the command-line window.
4133
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004134 Return type: |String|
4135
4136
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004137getcompletion({pat}, {type} [, {filtered}]) *getcompletion()*
4138 Return a list of command-line completion matches. The String
4139 {type} argument specifies what for. The following completion
4140 types are supported:
4141
4142 arglist file names in argument list
4143 augroup autocmd groups
4144 buffer buffer names
Bram Moolenaar6e2e2cc2022-03-14 19:24:46 +00004145 behave |:behave| suboptions
4146 breakpoint |:breakadd| and |:breakdel| suboptions
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004147 color color schemes
4148 command Ex command
4149 cmdline |cmdline-completion| result
4150 compiler compilers
4151 cscope |:cscope| suboptions
Shougo Matsushita92997dd2023-08-20 20:55:55 +02004152 custom,{func} custom completion, defined via {func}
4153 customlist,{func} custom completion, defined via {func}
zeertzjq85f36d62024-10-10 19:14:13 +02004154 diff_buffer |:diffget| and |:diffput| completion
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004155 dir directory names
LemonBoya20bf692024-07-11 22:35:53 +02004156 dir_in_path directory names in |'cdpath'|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004157 environment environment variable names
4158 event autocommand events
4159 expression Vim expression
4160 file file and directory names
4161 file_in_path file and directory names in |'path'|
4162 filetype filetype names |'filetype'|
4163 function function name
4164 help help subjects
4165 highlight highlight groups
Bram Moolenaar6e2e2cc2022-03-14 19:24:46 +00004166 history |:history| suboptions
Doug Kearns81642d92024-01-04 22:37:44 +01004167 keymap keyboard mappings
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004168 locale locale names (as output of locale -a)
4169 mapclear buffer argument
4170 mapping mapping name
4171 menu menus
4172 messages |:messages| suboptions
4173 option options
4174 packadd optional package |pack-add| names
zeertzjq5c8771b2023-01-24 12:34:03 +00004175 runtime |:runtime| completion
Yegappan Lakshmanan454ce672022-03-24 11:22:13 +00004176 scriptnames sourced script names |:scriptnames|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004177 shellcmd Shell command
zeertzjq85f36d62024-10-10 19:14:13 +02004178 shellcmdline Shell command line with filename arguments
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004179 sign |:sign| suboptions
4180 syntax syntax file names |'syntax'|
4181 syntime |:syntime| suboptions
4182 tag tags
4183 tag_listfiles tags, file names
4184 user user names
4185 var user variables
4186
4187 If {pat} is an empty string, then all the matches are
4188 returned. Otherwise only items matching {pat} are returned.
4189 See |wildcards| for the use of special characters in {pat}.
4190
4191 If the optional {filtered} flag is set to 1, then 'wildignore'
4192 is applied to filter the results. Otherwise all the matches
4193 are returned. The 'wildignorecase' option always applies.
4194
Yegappan Lakshmanane7dd0fa2022-03-22 16:06:31 +00004195 If the 'wildoptions' option contains 'fuzzy', then fuzzy
4196 matching is used to get the completion matches. Otherwise
Yegappan Lakshmanan454ce672022-03-24 11:22:13 +00004197 regular expression matching is used. Thus this function
4198 follows the user preference, what happens on the command line.
4199 If you do not want this you can make 'wildoptions' empty
4200 before calling getcompletion() and restore it afterwards.
Yegappan Lakshmanane7dd0fa2022-03-22 16:06:31 +00004201
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004202 If {type} is "cmdline", then the |cmdline-completion| result is
4203 returned. For example, to complete the possible values after
4204 a ":call" command: >
4205 echo getcompletion('call ', 'cmdline')
4206<
4207 If there are no matches, an empty list is returned. An
4208 invalid value for {type} produces an error.
4209
4210 Can also be used as a |method|: >
4211 GetPattern()->getcompletion('color')
4212<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004213 Return type: list<string>
4214
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004215 *getcurpos()*
4216getcurpos([{winid}])
4217 Get the position of the cursor. This is like getpos('.'), but
4218 includes an extra "curswant" item in the list:
4219 [0, lnum, col, off, curswant] ~
4220 The "curswant" number is the preferred column when moving the
naohiro ono56200ee2022-01-01 14:59:44 +00004221 cursor vertically. After |$| command it will be a very large
4222 number equal to |v:maxcol|. Also see |getcursorcharpos()| and
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004223 |getpos()|.
4224 The first "bufnum" item is always zero. The byte position of
4225 the cursor is returned in 'col'. To get the character
4226 position, use |getcursorcharpos()|.
4227
4228 The optional {winid} argument can specify the window. It can
4229 be the window number or the |window-ID|. The last known
4230 cursor position is returned, this may be invalid for the
4231 current value of the buffer if it is not the current window.
4232 If {winid} is invalid a list with zeroes is returned.
4233
4234 This can be used to save and restore the cursor position: >
4235 let save_cursor = getcurpos()
4236 MoveTheCursorAround
4237 call setpos('.', save_cursor)
4238< Note that this only works within the window. See
4239 |winrestview()| for restoring more state.
4240
4241 Can also be used as a |method|: >
4242 GetWinid()->getcurpos()
4243<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004244 Return type: list<number>
4245
4246
4247getcursorcharpos([{winid}]) *getcursorcharpos()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004248 Same as |getcurpos()| but the column number in the returned
4249 List is a character index instead of a byte index.
4250
4251 Example:
4252 With the cursor on '보' in line 3 with text "여보세요": >
4253 getcursorcharpos() returns [0, 3, 2, 0, 3]
4254 getcurpos() returns [0, 3, 4, 0, 3]
4255<
4256 Can also be used as a |method|: >
4257 GetWinid()->getcursorcharpos()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004258<
4259 Return type: list<number>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004260
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004261
4262getcwd([{winnr} [, {tabnr}]]) *getcwd()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004263 The result is a String, which is the name of the current
4264 working directory. 'autochdir' is ignored.
4265
4266 With {winnr} return the local current directory of this window
4267 in the current tab page. {winnr} can be the window number or
4268 the |window-ID|.
4269 If {winnr} is -1 return the name of the global working
4270 directory. See also |haslocaldir()|.
4271
4272 With {winnr} and {tabnr} return the local current directory of
4273 the window in the specified tab page. If {winnr} is -1 return
4274 the working directory of the tabpage.
4275 If {winnr} is zero use the current window, if {tabnr} is zero
4276 use the current tabpage.
4277 Without any arguments, return the actual working directory of
4278 the current window.
4279 Return an empty string if the arguments are invalid.
4280
4281 Examples: >
4282 " Get the working directory of the current window
4283 :echo getcwd()
4284 :echo getcwd(0)
4285 :echo getcwd(0, 0)
4286 " Get the working directory of window 3 in tabpage 2
4287 :echo getcwd(3, 2)
4288 " Get the global working directory
4289 :echo getcwd(-1)
4290 " Get the working directory of tabpage 3
4291 :echo getcwd(-1, 3)
4292 " Get the working directory of current tabpage
4293 :echo getcwd(-1, 0)
4294
4295< Can also be used as a |method|: >
4296 GetWinnr()->getcwd()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004297<
4298 Return type: |String|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004299
4300getenv({name}) *getenv()*
4301 Return the value of environment variable {name}. The {name}
4302 argument is a string, without a leading '$'. Example: >
4303 myHome = getenv('HOME')
4304
4305< When the variable does not exist |v:null| is returned. That
4306 is different from a variable set to an empty string, although
4307 some systems interpret the empty value as the variable being
4308 deleted. See also |expr-env|.
4309
4310 Can also be used as a |method|: >
4311 GetVarname()->getenv()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004312<
4313 Return type: |String| or |Number|
4314
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004315
4316getfontname([{name}]) *getfontname()*
4317 Without an argument returns the name of the normal font being
4318 used. Like what is used for the Normal highlight group
4319 |hl-Normal|.
4320 With an argument a check is done whether String {name} is a
4321 valid font name. If not then an empty string is returned.
4322 Otherwise the actual font name is returned, or {name} if the
4323 GUI does not support obtaining the real name.
4324 Only works when the GUI is running, thus not in your vimrc or
4325 gvimrc file. Use the |GUIEnter| autocommand to use this
4326 function just after the GUI has started.
4327 Note that the GTK GUI accepts any font name, thus checking for
4328 a valid name does not work.
4329
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004330 Return type: |String|
4331
4332
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004333getfperm({fname}) *getfperm()*
4334 The result is a String, which is the read, write, and execute
4335 permissions of the given file {fname}.
4336 If {fname} does not exist or its directory cannot be read, an
4337 empty string is returned.
4338 The result is of the form "rwxrwxrwx", where each group of
4339 "rwx" flags represent, in turn, the permissions of the owner
4340 of the file, the group the file belongs to, and other users.
4341 If a user does not have a given permission the flag for this
4342 is replaced with the string "-". Examples: >
4343 :echo getfperm("/etc/passwd")
4344 :echo getfperm(expand("~/.vimrc"))
4345< This will hopefully (from a security point of view) display
4346 the string "rw-r--r--" or even "rw-------".
4347
4348 Can also be used as a |method|: >
4349 GetFilename()->getfperm()
4350<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004351 Return type: |String|
4352
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004353 For setting permissions use |setfperm()|.
4354
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004355
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004356getfsize({fname}) *getfsize()*
4357 The result is a Number, which is the size in bytes of the
4358 given file {fname}.
4359 If {fname} is a directory, 0 is returned.
4360 If the file {fname} can't be found, -1 is returned.
4361 If the size of {fname} is too big to fit in a Number then -2
4362 is returned.
4363
4364 Can also be used as a |method|: >
4365 GetFilename()->getfsize()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004366<
4367 Return type: |Number|
4368
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004369
4370getftime({fname}) *getftime()*
4371 The result is a Number, which is the last modification time of
4372 the given file {fname}. The value is measured as seconds
4373 since 1st Jan 1970, and may be passed to strftime(). See also
4374 |localtime()| and |strftime()|.
4375 If the file {fname} can't be found -1 is returned.
4376
4377 Can also be used as a |method|: >
4378 GetFilename()->getftime()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004379<
4380 Return type: |Number|
4381
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004382
4383getftype({fname}) *getftype()*
4384 The result is a String, which is a description of the kind of
4385 file of the given file {fname}.
4386 If {fname} does not exist an empty string is returned.
4387 Here is a table over different kinds of files and their
4388 results:
4389 Normal file "file"
4390 Directory "dir"
4391 Symbolic link "link"
4392 Block device "bdev"
4393 Character device "cdev"
4394 Socket "socket"
4395 FIFO "fifo"
4396 All other "other"
4397 Example: >
4398 getftype("/home")
4399< Note that a type such as "link" will only be returned on
4400 systems that support it. On some systems only "dir" and
4401 "file" are returned. On MS-Windows a symbolic link to a
4402 directory returns "dir" instead of "link".
4403
4404 Can also be used as a |method|: >
4405 GetFilename()->getftype()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004406<
4407 Return type: |String|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004408
4409getimstatus() *getimstatus()*
4410 The result is a Number, which is |TRUE| when the IME status is
Bram Moolenaar016188f2022-06-06 20:52:59 +01004411 active and |FALSE| otherwise.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004412 See 'imstatusfunc'.
4413
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004414 Return type: |Number|
4415
4416
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004417getjumplist([{winnr} [, {tabnr}]]) *getjumplist()*
4418 Returns the |jumplist| for the specified window.
4419
4420 Without arguments use the current window.
4421 With {winnr} only use this window in the current tab page.
4422 {winnr} can also be a |window-ID|.
4423 With {winnr} and {tabnr} use the window in the specified tab
Bram Moolenaar016188f2022-06-06 20:52:59 +01004424 page. If {winnr} or {tabnr} is invalid, an empty list is
4425 returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004426
4427 The returned list contains two entries: a list with the jump
4428 locations and the last used jump position number in the list.
4429 Each entry in the jump location list is a dictionary with
4430 the following entries:
4431 bufnr buffer number
4432 col column number
4433 coladd column offset for 'virtualedit'
4434 filename filename if available
4435 lnum line number
4436
4437 Can also be used as a |method|: >
4438 GetWinnr()->getjumplist()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004439<
4440 Return type: list<any>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004441
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004442 *getline()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004443getline({lnum} [, {end}])
4444 Without {end} the result is a String, which is line {lnum}
4445 from the current buffer. Example: >
4446 getline(1)
4447< When {lnum} is a String that doesn't start with a
4448 digit, |line()| is called to translate the String into a Number.
4449 To get the line under the cursor: >
4450 getline(".")
4451< When {lnum} is a number smaller than 1 or bigger than the
4452 number of lines in the buffer, an empty string is returned.
4453
4454 When {end} is given the result is a |List| where each item is
4455 a line from the current buffer in the range {lnum} to {end},
4456 including line {end}.
4457 {end} is used in the same way as {lnum}.
4458 Non-existing lines are silently omitted.
4459 When {end} is before {lnum} an empty |List| is returned.
4460 Example: >
4461 :let start = line('.')
4462 :let end = search("^$") - 1
4463 :let lines = getline(start, end)
4464
4465< Can also be used as a |method|: >
4466 ComputeLnum()->getline()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004467<
4468 Return type: list<string> or |String| depending on {end}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004469
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004470 To get lines from another buffer see |getbufline()| and
Bram Moolenaarce30ccc2022-11-21 19:57:04 +00004471 |getbufoneline()|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004472
4473getloclist({nr} [, {what}]) *getloclist()*
4474 Returns a |List| with all the entries in the location list for
4475 window {nr}. {nr} can be the window number or the |window-ID|.
4476 When {nr} is zero the current window is used.
4477
4478 For a location list window, the displayed location list is
4479 returned. For an invalid window number {nr}, an empty list is
4480 returned. Otherwise, same as |getqflist()|.
4481
4482 If the optional {what} dictionary argument is supplied, then
4483 returns the items listed in {what} as a dictionary. Refer to
4484 |getqflist()| for the supported items in {what}.
4485
4486 In addition to the items supported by |getqflist()| in {what},
4487 the following item is supported by |getloclist()|:
4488
4489 filewinid id of the window used to display files
4490 from the location list. This field is
4491 applicable only when called from a
4492 location list window. See
4493 |location-list-file-window| for more
4494 details.
4495
4496 Returns a |Dictionary| with default values if there is no
4497 location list for the window {nr}.
4498 Returns an empty Dictionary if window {nr} does not exist.
4499
4500 Examples (See also |getqflist-examples|): >
4501 :echo getloclist(3, {'all': 0})
4502 :echo getloclist(5, {'filewinid': 0})
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004503<
4504 Return type: list<dict<any>> or list<any>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004505
4506
4507getmarklist([{buf}]) *getmarklist()*
4508 Without the {buf} argument returns a |List| with information
4509 about all the global marks. |mark|
4510
4511 If the optional {buf} argument is specified, returns the
4512 local marks defined in buffer {buf}. For the use of {buf},
Bram Moolenaar016188f2022-06-06 20:52:59 +01004513 see |bufname()|. If {buf} is invalid, an empty list is
4514 returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004515
4516 Each item in the returned List is a |Dict| with the following:
4517 mark name of the mark prefixed by "'"
4518 pos a |List| with the position of the mark:
4519 [bufnum, lnum, col, off]
4520 Refer to |getpos()| for more information.
4521 file file name
4522
4523 Refer to |getpos()| for getting information about a specific
4524 mark.
4525
4526 Can also be used as a |method|: >
4527 GetBufnr()->getmarklist()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004528<
4529 Return type: list<dict<any>> or list<any>
4530
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004531
4532getmatches([{win}]) *getmatches()*
4533 Returns a |List| with all matches previously defined for the
4534 current window by |matchadd()| and the |:match| commands.
4535 |getmatches()| is useful in combination with |setmatches()|,
4536 as |setmatches()| can restore a list of matches saved by
4537 |getmatches()|.
4538 If {win} is specified, use the window with this number or
Bram Moolenaar016188f2022-06-06 20:52:59 +01004539 window ID instead of the current window. If {win} is invalid,
4540 an empty list is returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004541 Example: >
4542 :echo getmatches()
4543< [{'group': 'MyGroup1', 'pattern': 'TODO',
4544 'priority': 10, 'id': 1}, {'group': 'MyGroup2',
4545 'pattern': 'FIXME', 'priority': 10, 'id': 2}] >
4546 :let m = getmatches()
4547 :call clearmatches()
4548 :echo getmatches()
4549< [] >
4550 :call setmatches(m)
4551 :echo getmatches()
4552< [{'group': 'MyGroup1', 'pattern': 'TODO',
4553 'priority': 10, 'id': 1}, {'group': 'MyGroup2',
4554 'pattern': 'FIXME', 'priority': 10, 'id': 2}] >
4555 :unlet m
4556<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004557 Return type: list<dict<any>> or list<any>
4558
4559
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004560getmousepos() *getmousepos()*
4561 Returns a |Dictionary| with the last known position of the
4562 mouse. This can be used in a mapping for a mouse click or in
4563 a filter of a popup window. The items are:
4564 screenrow screen row
4565 screencol screen column
4566 winid Window ID of the click
4567 winrow row inside "winid"
4568 wincol column inside "winid"
4569 line text line inside "winid"
4570 column text column inside "winid"
zeertzjqf5a94d52023-10-15 10:03:30 +02004571 coladd offset (in screen columns) from the
4572 start of the clicked char
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004573 All numbers are 1-based.
4574
4575 If not over a window, e.g. when in the command line, then only
4576 "screenrow" and "screencol" are valid, the others are zero.
4577
4578 When on the status line below a window or the vertical
4579 separator right of a window, the "line" and "column" values
4580 are zero.
4581
4582 When the position is after the text then "column" is the
4583 length of the text in bytes plus one.
4584
4585 If the mouse is over a popup window then that window is used.
4586
4587 When using |getchar()| the Vim variables |v:mouse_lnum|,
4588 |v:mouse_col| and |v:mouse_winid| also provide these values.
4589
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004590 Return type: dict<number>
4591
4592
Bram Moolenaar24dc19c2022-11-14 19:49:15 +00004593getmouseshape() *getmouseshape()*
4594 Returns the name of the currently showing mouse pointer.
4595 When the |+mouseshape| feature is not supported or the shape
4596 is unknown an empty string is returned.
4597 This function is mainly intended for testing.
4598
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004599 Return type: |String|
4600
4601
4602getpid() *getpid()*
4603 Return a Number which is the process ID of the Vim process.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004604 On Unix and MS-Windows this is a unique number, until Vim
4605 exits.
4606
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004607 Return type: |Number|
4608
4609
4610getpos({expr}) *getpos()*
zeertzjq02f3eba2024-06-12 20:45:24 +02004611 Get the position for String {expr}.
4612 The accepted values for {expr} are: *E1209*
4613 . The cursor position.
4614 $ The last line in the current buffer.
4615 'x Position of mark x (if the mark is not set, 0 is
zeertzjqd353d272024-06-13 23:00:25 +08004616 returned for all values).
zeertzjq02f3eba2024-06-12 20:45:24 +02004617 w0 First line visible in current window (one if the
4618 display isn't updated, e.g. in silent Ex mode).
4619 w$ Last line visible in current window (this is one
4620 less than "w0" if no lines are visible).
4621 v When not in Visual mode, returns the cursor
4622 position. In Visual mode, returns the other end
4623 of the Visual area. A good way to think about
4624 this is that in Visual mode "v" and "." complement
4625 each other. While "." refers to the cursor
4626 position, "v" refers to where |v_o| would move the
4627 cursor. As a result, you can use "v" and "."
4628 together to work on all of a selection in
4629 characterwise Visual mode. If the cursor is at
4630 the end of a characterwise Visual area, "v" refers
4631 to the start of the same Visual area. And if the
4632 cursor is at the start of a characterwise Visual
4633 area, "v" refers to the end of the same Visual
4634 area. "v" differs from |'<| and |'>| in that it's
4635 updated right away.
4636 Note that a mark in another file can be used. The line number
4637 then applies to another buffer.
4638
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004639 The result is a |List| with four numbers:
4640 [bufnum, lnum, col, off]
4641 "bufnum" is zero, unless a mark like '0 or 'A is used, then it
4642 is the buffer number of the mark.
4643 "lnum" and "col" are the position in the buffer. The first
4644 column is 1.
4645 The "off" number is zero, unless 'virtualedit' is used. Then
4646 it is the offset in screen columns from the start of the
4647 character. E.g., a position within a <Tab> or after the last
4648 character.
zeertzjq02f3eba2024-06-12 20:45:24 +02004649
4650 For getting the cursor position see |getcurpos()|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004651 The column number in the returned List is the byte position
4652 within the line. To get the character position in the line,
4653 use |getcharpos()|.
zeertzjq02f3eba2024-06-12 20:45:24 +02004654
4655 Note that for '< and '> Visual mode matters: when it is "V"
4656 (visual line mode) the column of '< is zero and the column of
4657 '> is a large number equal to |v:maxcol|.
naohiro ono56200ee2022-01-01 14:59:44 +00004658 A very large column number equal to |v:maxcol| can be returned,
4659 in which case it means "after the end of the line".
Bram Moolenaar016188f2022-06-06 20:52:59 +01004660 If {expr} is invalid, returns a list with all zeros.
zeertzjq02f3eba2024-06-12 20:45:24 +02004661
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004662 This can be used to save and restore the position of a mark: >
4663 let save_a_mark = getpos("'a")
4664 ...
4665 call setpos("'a", save_a_mark)
zeertzjqd353d272024-06-13 23:00:25 +08004666<
4667 Also see |getcharpos()|, |getcurpos()| and |setpos()|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004668
4669 Can also be used as a |method|: >
4670 GetMark()->getpos()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004671<
4672 Return type: list<number>
4673
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004674
4675getqflist([{what}]) *getqflist()*
4676 Returns a |List| with all the current quickfix errors. Each
4677 list item is a dictionary with these entries:
4678 bufnr number of buffer that has the file name, use
4679 bufname() to get the name
4680 module module name
4681 lnum line number in the buffer (first line is 1)
4682 end_lnum
4683 end of line number if the item is multiline
4684 col column number (first column is 1)
4685 end_col end of column number if the item has range
4686 vcol |TRUE|: "col" is visual column
4687 |FALSE|: "col" is byte index
4688 nr error number
h-east84ac2122024-06-17 18:12:30 +02004689 pattern search pattern used to locate the error
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004690 text description of the error
4691 type type of the error, 'E', '1', etc.
4692 valid |TRUE|: recognized error message
h_east596a9f22023-11-21 21:24:23 +09004693 user_data
4694 custom data associated with the item, can be
Tom Praschanca6ac992023-08-11 23:26:12 +02004695 any type.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004696
4697 When there is no error list or it's empty, an empty list is
4698 returned. Quickfix list entries with a non-existing buffer
4699 number are returned with "bufnr" set to zero (Note: some
4700 functions accept buffer number zero for the alternate buffer,
4701 you may need to explicitly check for zero).
4702
4703 Useful application: Find pattern matches in multiple files and
4704 do something with them: >
4705 :vimgrep /theword/jg *.c
4706 :for d in getqflist()
4707 : echo bufname(d.bufnr) ':' d.lnum '=' d.text
4708 :endfor
4709<
4710 If the optional {what} dictionary argument is supplied, then
4711 returns only the items listed in {what} as a dictionary. The
4712 following string items are supported in {what}:
4713 changedtick get the total number of changes made
4714 to the list |quickfix-changedtick|
4715 context get the |quickfix-context|
4716 efm errorformat to use when parsing "lines". If
4717 not present, then the 'errorformat' option
4718 value is used.
4719 id get information for the quickfix list with
4720 |quickfix-ID|; zero means the id for the
4721 current list or the list specified by "nr"
4722 idx get information for the quickfix entry at this
4723 index in the list specified by 'id' or 'nr'.
4724 If set to zero, then uses the current entry.
4725 See |quickfix-index|
4726 items quickfix list entries
4727 lines parse a list of lines using 'efm' and return
4728 the resulting entries. Only a |List| type is
4729 accepted. The current quickfix list is not
4730 modified. See |quickfix-parse|.
4731 nr get information for this quickfix list; zero
4732 means the current quickfix list and "$" means
4733 the last quickfix list
4734 qfbufnr number of the buffer displayed in the quickfix
4735 window. Returns 0 if the quickfix buffer is
4736 not present. See |quickfix-buffer|.
4737 size number of entries in the quickfix list
4738 title get the list title |quickfix-title|
4739 winid get the quickfix |window-ID|
4740 all all of the above quickfix properties
4741 Non-string items in {what} are ignored. To get the value of a
4742 particular item, set it to zero.
4743 If "nr" is not present then the current quickfix list is used.
4744 If both "nr" and a non-zero "id" are specified, then the list
4745 specified by "id" is used.
4746 To get the number of lists in the quickfix stack, set "nr" to
4747 "$" in {what}. The "nr" value in the returned dictionary
4748 contains the quickfix stack size.
4749 When "lines" is specified, all the other items except "efm"
4750 are ignored. The returned dictionary contains the entry
4751 "items" with the list of entries.
4752
4753 The returned dictionary contains the following entries:
4754 changedtick total number of changes made to the
4755 list |quickfix-changedtick|
4756 context quickfix list context. See |quickfix-context|
4757 If not present, set to "".
4758 id quickfix list ID |quickfix-ID|. If not
4759 present, set to 0.
4760 idx index of the quickfix entry in the list. If not
4761 present, set to 0.
4762 items quickfix list entries. If not present, set to
4763 an empty list.
4764 nr quickfix list number. If not present, set to 0
4765 qfbufnr number of the buffer displayed in the quickfix
4766 window. If not present, set to 0.
4767 size number of entries in the quickfix list. If not
4768 present, set to 0.
4769 title quickfix list title text. If not present, set
4770 to "".
4771 winid quickfix |window-ID|. If not present, set to 0
4772
4773 Examples (See also |getqflist-examples|): >
4774 :echo getqflist({'all': 1})
4775 :echo getqflist({'nr': 2, 'title': 1})
4776 :echo getqflist({'lines' : ["F1:10:L10"]})
4777<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004778 Return type: list<dict<any>> or list<any>
4779
4780
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004781getreg([{regname} [, 1 [, {list}]]]) *getreg()*
4782 The result is a String, which is the contents of register
4783 {regname}. Example: >
4784 :let cliptext = getreg('*')
4785< When register {regname} was not set the result is an empty
4786 string.
Bram Moolenaara2baa732022-02-04 16:09:54 +00004787 The {regname} argument must be a string. *E1162*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004788
4789 getreg('=') returns the last evaluated value of the expression
4790 register. (For use in maps.)
4791 getreg('=', 1) returns the expression itself, so that it can
4792 be restored with |setreg()|. For other registers the extra
4793 argument is ignored, thus you can always give it.
4794
4795 If {list} is present and |TRUE|, the result type is changed
4796 to |List|. Each list item is one text line. Use it if you care
4797 about zero bytes possibly present inside register: without
4798 third argument both NLs and zero bytes are represented as NLs
4799 (see |NL-used-for-Nul|).
4800 When the register was not set an empty list is returned.
4801
4802 If {regname} is "", the unnamed register '"' is used.
4803 If {regname} is not specified, |v:register| is used.
4804 In |Vim9-script| {regname} must be one character.
4805
4806 Can also be used as a |method|: >
4807 GetRegname()->getreg()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004808<
4809 Return type: |String|
4810
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004811
4812getreginfo([{regname}]) *getreginfo()*
4813 Returns detailed information about register {regname} as a
4814 Dictionary with the following entries:
4815 regcontents List of lines contained in register
4816 {regname}, like
4817 |getreg|({regname}, 1, 1).
4818 regtype the type of register {regname}, as in
4819 |getregtype()|.
4820 isunnamed Boolean flag, v:true if this register
4821 is currently pointed to by the unnamed
4822 register.
4823 points_to for the unnamed register, gives the
4824 single letter name of the register
4825 currently pointed to (see |quotequote|).
4826 For example, after deleting a line
4827 with `dd`, this field will be "1",
4828 which is the register that got the
4829 deleted text.
4830
4831 The {regname} argument is a string. If {regname} is invalid
4832 or not set, an empty Dictionary will be returned.
4833 If {regname} is "" or "@", the unnamed register '"' is used.
4834 If {regname} is not specified, |v:register| is used.
4835 The returned Dictionary can be passed to |setreg()|.
4836 In |Vim9-script| {regname} must be one character.
4837
4838 Can also be used as a |method|: >
4839 GetRegname()->getreginfo()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004840<
4841 Return type: dict<any>
4842
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004843
Shougo Matsushita19b71882024-02-28 22:48:12 +01004844getregion({pos1}, {pos2} [, {opts}]) *getregion()*
Shougo Matsushita84bf6e62024-03-06 21:10:18 +01004845 Returns the list of strings from {pos1} to {pos2} from a
Shougo Matsushita19b71882024-02-28 22:48:12 +01004846 buffer.
4847
4848 {pos1} and {pos2} must both be |List|s with four numbers.
Shougo Matsushita84bf6e62024-03-06 21:10:18 +01004849 See |getpos()| for the format of the list. It's possible
4850 to specify positions from a different buffer, but please
zeertzjq0df8f932024-03-07 21:40:53 +01004851 note the limitations at |getregion-notes|.
Shougo Matsushita19b71882024-02-28 22:48:12 +01004852
4853 The optional argument {opts} is a Dict and supports the
4854 following items:
4855
zeertzjqafc22952024-05-24 19:07:12 +02004856 type Specify the region's selection type.
4857 See |getregtype()| for possible values,
zeertzjqdff55a32024-05-25 10:25:36 +02004858 except that the width can be omitted
4859 and an empty string cannot be used.
zeertzjqafc22952024-05-24 19:07:12 +02004860 (default: "v")
Shougo Matsushita19b71882024-02-28 22:48:12 +01004861
zeertzjq87410ab2024-03-02 06:00:23 +08004862 exclusive If |TRUE|, use exclusive selection
zeertzjqafc22952024-05-24 19:07:12 +02004863 for the end position.
zeertzjq87410ab2024-03-02 06:00:23 +08004864 (default: follow 'selection')
Shougo Matsushita19b71882024-02-28 22:48:12 +01004865
Shougo Matsushita3f905ab2024-02-21 00:02:45 +01004866 You can get the last selection type by |visualmode()|.
4867 If Visual mode is active, use |mode()| to get the Visual mode
4868 (e.g., in a |:vmap|).
zeertzjq87410ab2024-03-02 06:00:23 +08004869 This function is useful to get text starting and ending in
4870 different columns, such as a |characterwise-visual| selection.
Shougo Matsushita3f905ab2024-02-21 00:02:45 +01004871
Shougo Matsushita84bf6e62024-03-06 21:10:18 +01004872 *getregion-notes*
Shougo Matsushita3f905ab2024-02-21 00:02:45 +01004873 Note that:
4874 - Order of {pos1} and {pos2} doesn't matter, it will always
4875 return content from the upper left position to the lower
4876 right position.
zeertzjq87410ab2024-03-02 06:00:23 +08004877 - If 'virtualedit' is enabled and the region is past the end
4878 of the lines, resulting lines are padded with spaces.
4879 - If the region is blockwise and it starts or ends in the
4880 middle of a multi-cell character, it is not included but
4881 its selected part is substituted with spaces.
Shougo Matsushita84bf6e62024-03-06 21:10:18 +01004882 - If {pos1} and {pos2} are not in the same buffer, an empty
zeertzjq421b5972024-02-22 19:48:06 +01004883 list is returned.
Shougo Matsushita84bf6e62024-03-06 21:10:18 +01004884 - {pos1} and {pos2} must belong to a |bufloaded()| buffer.
zeertzjq0df8f932024-03-07 21:40:53 +01004885 - It is evaluated in current window context, which makes a
4886 difference if the buffer is displayed in a window with
4887 different 'virtualedit' or 'list' values.
Shougo Matsushita3f905ab2024-02-21 00:02:45 +01004888
4889 Examples: >
4890 :xnoremap <CR>
Shougo Matsushita19b71882024-02-28 22:48:12 +01004891 \ <Cmd>echow getregion(
4892 \ getpos('v'), getpos('.'), #{ type: mode() })<CR>
Shougo Matsushita3f905ab2024-02-21 00:02:45 +01004893<
4894 Can also be used as a |method|: >
Shougo Matsushita19b71882024-02-28 22:48:12 +01004895 getpos('.')->getregion(getpos("'a"))
zeertzjqd4d12072024-07-16 20:34:16 +02004896<
4897 Return type: list<string>
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004898
Yee Cheng Chind52fb2f2024-10-31 09:25:09 +01004899
Shougo Matsushitab4757e62024-05-07 20:49:24 +02004900getregionpos({pos1}, {pos2} [, {opts}]) *getregionpos()*
4901 Same as |getregion()|, but returns a list of positions
4902 describing the buffer text segments bound by {pos1} and
4903 {pos2}.
4904 The segments are a pair of positions for every line: >
4905 [[{start_pos}, {end_pos}], ...]
4906<
4907 The position is a |List| with four numbers:
4908 [bufnum, lnum, col, off]
4909 "bufnum" is the buffer number.
4910 "lnum" and "col" are the position in the buffer. The first
4911 column is 1.
zeertzjqc95e64f2024-05-20 14:00:31 +02004912 If the "off" number of a starting position is non-zero, it is
4913 the offset in screen columns from the start of the character.
4914 E.g., a position within a <Tab> or after the last character.
4915 If the "off" number of an ending position is non-zero, it is
zeertzjq52a6f342024-05-22 16:42:44 +02004916 the offset of the character's first cell not included in the
4917 selection, otherwise all its cells are included.
Shougo Matsushitab4757e62024-05-07 20:49:24 +02004918
zeertzjq2b09de92024-05-24 07:48:51 +02004919 Apart from the options supported by |getregion()|, {opts} also
4920 supports the following:
4921
4922 eol If |TRUE|, indicate positions beyond
4923 the end of a line with "col" values
4924 one more than the length of the line.
4925 If |FALSE|, positions are limited
4926 within their lines, and if a line is
4927 empty or the selection is entirely
4928 beyond the end of a line, a "col"
4929 value of 0 is used for both positions.
4930 (default: |FALSE|)
4931
Shougo Matsushitab4757e62024-05-07 20:49:24 +02004932 Can also be used as a |method|: >
4933 getpos('.')->getregionpos(getpos("'a"))
4934<
zeertzjqd4d12072024-07-16 20:34:16 +02004935 Return type: list<list<list<number>>>
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004936
4937
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004938getregtype([{regname}]) *getregtype()*
4939 The result is a String, which is type of register {regname}.
4940 The value will be one of:
4941 "v" for |characterwise| text
4942 "V" for |linewise| text
4943 "<CTRL-V>{width}" for |blockwise-visual| text
4944 "" for an empty or unknown register
4945 <CTRL-V> is one character with value 0x16.
4946 The {regname} argument is a string. If {regname} is "", the
4947 unnamed register '"' is used. If {regname} is not specified,
4948 |v:register| is used.
4949 In |Vim9-script| {regname} must be one character.
4950
4951 Can also be used as a |method|: >
4952 GetRegname()->getregtype()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004953<
4954 Return type: |String|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004955
Yee Cheng Chind52fb2f2024-10-31 09:25:09 +01004956
Bram Moolenaar71badf92023-04-22 22:40:14 +01004957getscriptinfo([{opts}]) *getscriptinfo()*
Yegappan Lakshmananf768c3d2022-08-22 13:15:13 +01004958 Returns a |List| with information about all the sourced Vim
Bram Moolenaar753885b2022-08-24 16:30:36 +01004959 scripts in the order they were sourced, like what
4960 `:scriptnames` shows.
Yegappan Lakshmananf768c3d2022-08-22 13:15:13 +01004961
Yegappan Lakshmanan2f892d82022-08-28 18:52:10 +01004962 The optional Dict argument {opts} supports the following
4963 optional items:
4964 name Script name match pattern. If specified,
4965 and "sid" is not specified, information about
Bram Moolenaar71badf92023-04-22 22:40:14 +01004966 scripts with a name that match the pattern
Yegappan Lakshmanan2f892d82022-08-28 18:52:10 +01004967 "name" are returned.
4968 sid Script ID |<SID>|. If specified, only
4969 information about the script with ID "sid" is
4970 returned and "name" is ignored.
4971
Yegappan Lakshmananf768c3d2022-08-22 13:15:13 +01004972 Each item in the returned List is a |Dict| with the following
4973 items:
Yegappan Lakshmanan2f892d82022-08-28 18:52:10 +01004974 autoload Set to TRUE for a script that was used with
Bram Moolenaar753885b2022-08-24 16:30:36 +01004975 `import autoload` but was not actually sourced
4976 yet (see |import-autoload|).
Yegappan Lakshmanan2f892d82022-08-28 18:52:10 +01004977 functions List of script-local function names defined in
4978 the script. Present only when a particular
4979 script is specified using the "sid" item in
4980 {opts}.
4981 name Vim script file name.
4982 sid Script ID |<SID>|.
4983 sourced Script ID of the actually sourced script that
Bram Moolenaarfd999452022-08-24 18:30:14 +01004984 this script name links to, if any, otherwise
4985 zero
Yegappan Lakshmanan2f892d82022-08-28 18:52:10 +01004986 variables A dictionary with the script-local variables.
Bram Moolenaarf1dcd142022-12-31 15:30:45 +00004987 Present only when a particular script is
Yegappan Lakshmanan2f892d82022-08-28 18:52:10 +01004988 specified using the "sid" item in {opts}.
4989 Note that this is a copy, the value of
4990 script-local variables cannot be changed using
4991 this dictionary.
h_east59858792023-10-25 22:47:05 +09004992 version Vim script version (|scriptversion|)
Yegappan Lakshmanan520f6ef2022-08-25 17:40:40 +01004993
Yegappan Lakshmanan2f892d82022-08-28 18:52:10 +01004994 Examples: >
4995 :echo getscriptinfo({'name': 'myscript'})
zeertzjqad4881c2024-05-04 15:35:30 +08004996 :echo getscriptinfo({'sid': 15})[0].variables
Yegappan Lakshmanan2f892d82022-08-28 18:52:10 +01004997<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004998 Return type: list<dict<any>>
4999
5000
ichizok663d18d2025-01-02 18:06:00 +01005001getstacktrace() *getstacktrace()*
5002 Returns the current stack trace of Vim scripts.
5003 Stack trace is a |List|, of which each item is a |Dictionary|
5004 with the following items:
zeertzjq6655bef2025-01-06 18:32:13 +01005005 funcref The funcref if the stack is at a function,
5006 otherwise this item is omitted.
ichizok663d18d2025-01-02 18:06:00 +01005007 event The string of the event description if the
zeertzjq6655bef2025-01-06 18:32:13 +01005008 stack is at an autocmd event, otherwise this
5009 item is omitted.
5010 lnum The line number in the script on the stack.
ichizok663d18d2025-01-02 18:06:00 +01005011 filepath The file path of the script on the stack.
5012
5013 Return type: list<dict<any>>
5014
5015
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005016gettabinfo([{tabnr}]) *gettabinfo()*
5017 If {tabnr} is not specified, then information about all the
5018 tab pages is returned as a |List|. Each List item is a
5019 |Dictionary|. Otherwise, {tabnr} specifies the tab page
5020 number and information about that one is returned. If the tab
5021 page does not exist an empty List is returned.
5022
5023 Each List item is a |Dictionary| with the following entries:
5024 tabnr tab page number.
5025 variables a reference to the dictionary with
5026 tabpage-local variables
5027 windows List of |window-ID|s in the tab page.
5028
5029 Can also be used as a |method|: >
5030 GetTabnr()->gettabinfo()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005031<
5032 Return type: list<dict<any>>
5033
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005034
5035gettabvar({tabnr}, {varname} [, {def}]) *gettabvar()*
5036 Get the value of a tab-local variable {varname} in tab page
5037 {tabnr}. |t:var|
5038 Tabs are numbered starting with one.
5039 The {varname} argument is a string. When {varname} is empty a
5040 dictionary with all tab-local variables is returned.
5041 Note that the name without "t:" must be used.
5042 When the tab or variable doesn't exist {def} or an empty
5043 string is returned, there is no error message.
5044
5045 Can also be used as a |method|: >
5046 GetTabnr()->gettabvar(varname)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005047<
5048 Return type: any, depending on {varname}
5049
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005050
5051gettabwinvar({tabnr}, {winnr}, {varname} [, {def}]) *gettabwinvar()*
5052 Get the value of window-local variable {varname} in window
5053 {winnr} in tab page {tabnr}.
5054 The {varname} argument is a string. When {varname} is empty a
5055 dictionary with all window-local variables is returned.
5056 When {varname} is equal to "&" get the values of all
5057 window-local options in a |Dictionary|.
5058 Otherwise, when {varname} starts with "&" get the value of a
5059 window-local option.
5060 Note that {varname} must be the name without "w:".
5061 Tabs are numbered starting with one. For the current tabpage
5062 use |getwinvar()|.
5063 {winnr} can be the window number or the |window-ID|.
5064 When {winnr} is zero the current window is used.
5065 This also works for a global option, buffer-local option and
5066 window-local option, but it doesn't work for a global variable
5067 or buffer-local variable.
5068 When the tab, window or variable doesn't exist {def} or an
5069 empty string is returned, there is no error message.
5070 Examples: >
5071 :let list_is_on = gettabwinvar(1, 2, '&list')
Bram Moolenaarc51cf032022-02-26 12:25:45 +00005072 :echo "myvar = " .. gettabwinvar(3, 1, 'myvar')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005073<
5074 To obtain all window-local variables use: >
5075 gettabwinvar({tabnr}, {winnr}, '&')
5076
5077< Can also be used as a |method|: >
5078 GetTabnr()->gettabwinvar(winnr, varname)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005079<
5080 Return type: any, depending on {varname}
5081
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005082
5083gettagstack([{winnr}]) *gettagstack()*
5084 The result is a Dict, which is the tag stack of window {winnr}.
5085 {winnr} can be the window number or the |window-ID|.
5086 When {winnr} is not specified, the current window is used.
5087 When window {winnr} doesn't exist, an empty Dict is returned.
5088
5089 The returned dictionary contains the following entries:
5090 curidx Current index in the stack. When at
5091 top of the stack, set to (length + 1).
5092 Index of bottom of the stack is 1.
5093 items List of items in the stack. Each item
5094 is a dictionary containing the
5095 entries described below.
5096 length Number of entries in the stack.
5097
5098 Each item in the stack is a dictionary with the following
5099 entries:
5100 bufnr buffer number of the current jump
5101 from cursor position before the tag jump.
5102 See |getpos()| for the format of the
5103 returned list.
5104 matchnr current matching tag number. Used when
5105 multiple matching tags are found for a
5106 name.
5107 tagname name of the tag
5108
5109 See |tagstack| for more information about the tag stack.
5110
5111 Can also be used as a |method|: >
5112 GetWinnr()->gettagstack()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005113<
5114 Return type: dict<any>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005115
5116
Christ van Willegence0ef912024-06-20 23:41:59 +02005117gettext({text} [, {package}]) *gettext()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005118 Translate String {text} if possible.
RestorerZ96509102024-07-11 21:14:15 +02005119 This is intended for use in Vim scripts. When generating
5120 message translations the {text} is extracted by `xgettext`,
5121 the translator can add translated messages into the .po file
5122 and Vim will lookup the translation when gettext() is called.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005123 For {text} double quoted strings are preferred, because
RestorerZ96509102024-07-11 21:14:15 +02005124 `xgettext` does not support single quoted escaped text.
5125
Christ van Willegence0ef912024-06-20 23:41:59 +02005126 When the {package} is specified, the translation is looked up
RestorerZ96509102024-07-11 21:14:15 +02005127 for that specific package. This is mainly required for
5128 third-party Vim scripts. You need to specify a path to the
5129 translations with the |bindtextdomain()| function before
5130 using the gettext() function.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005131
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005132 Return type: |String|
5133
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005134
5135getwininfo([{winid}]) *getwininfo()*
5136 Returns information about windows as a |List| with Dictionaries.
5137
5138 If {winid} is given Information about the window with that ID
5139 is returned, as a |List| with one item. If the window does not
5140 exist the result is an empty list.
5141
5142 Without {winid} information about all the windows in all the
5143 tab pages is returned.
5144
5145 Each List item is a |Dictionary| with the following entries:
5146 botline last complete displayed buffer line
5147 bufnr number of buffer in the window
5148 height window height (excluding winbar)
glepnir0a850672024-11-25 19:39:04 +01005149 leftcol first column displayed; only used when
5150 'wrap' is off
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005151 loclist 1 if showing a location list
5152 {only with the +quickfix feature}
5153 quickfix 1 if quickfix or location list window
5154 {only with the +quickfix feature}
5155 terminal 1 if a terminal window
5156 {only with the +terminal feature}
5157 tabnr tab page number
5158 topline first displayed buffer line
5159 variables a reference to the dictionary with
5160 window-local variables
5161 width window width
5162 winbar 1 if the window has a toolbar, 0
5163 otherwise
5164 wincol leftmost screen column of the window;
5165 "col" from |win_screenpos()|
5166 textoff number of columns occupied by any
5167 'foldcolumn', 'signcolumn' and line
5168 number in front of the text
5169 winid |window-ID|
5170 winnr window number
5171 winrow topmost screen line of the window;
5172 "row" from |win_screenpos()|
5173
5174 Can also be used as a |method|: >
5175 GetWinnr()->getwininfo()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005176<
5177 Return type: list<dict<any>>
5178
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005179
5180getwinpos([{timeout}]) *getwinpos()*
5181 The result is a |List| with two numbers, the result of
5182 |getwinposx()| and |getwinposy()| combined:
5183 [x-pos, y-pos]
5184 {timeout} can be used to specify how long to wait in msec for
5185 a response from the terminal. When omitted 100 msec is used.
5186 Use a longer time for a remote terminal.
5187 When using a value less than 10 and no response is received
5188 within that time, a previously reported position is returned,
5189 if available. This can be used to poll for the position and
5190 do some work in the meantime: >
5191 while 1
5192 let res = getwinpos(1)
5193 if res[0] >= 0
5194 break
5195 endif
5196 " Do some work here
5197 endwhile
5198<
5199
5200 Can also be used as a |method|: >
5201 GetTimeout()->getwinpos()
5202<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005203 Return type: list<number>
5204
5205
5206getwinposx() *getwinposx()*
5207 The result is a Number, which is the X coordinate in pixels of
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005208 the left hand side of the GUI Vim window. Also works for an
5209 xterm (uses a timeout of 100 msec).
lilydjwg6e0a18f2024-01-29 20:54:28 +01005210 The result will be -1 if the information is not available
5211 (e.g. on the Wayland backend).
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005212 The value can be used with `:winpos`.
5213
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005214 Return type: |Number|
5215
5216
5217getwinposy() *getwinposy()*
5218 The result is a Number, which is the Y coordinate in pixels of
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005219 the top of the GUI Vim window. Also works for an xterm (uses
5220 a timeout of 100 msec).
lilydjwg6e0a18f2024-01-29 20:54:28 +01005221 The result will be -1 if the information is not available
5222 (e.g. on the Wayland backend).
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005223 The value can be used with `:winpos`.
5224
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005225 Return type: |Number|
5226
5227
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005228getwinvar({winnr}, {varname} [, {def}]) *getwinvar()*
5229 Like |gettabwinvar()| for the current tabpage.
5230 Examples: >
5231 :let list_is_on = getwinvar(2, '&list')
Bram Moolenaarc51cf032022-02-26 12:25:45 +00005232 :echo "myvar = " .. getwinvar(1, 'myvar')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005233
5234< Can also be used as a |method|: >
5235 GetWinnr()->getwinvar(varname)
5236<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005237 Return type: any, depending on {varname}
5238
5239
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005240glob({expr} [, {nosuf} [, {list} [, {alllinks}]]]) *glob()*
5241 Expand the file wildcards in {expr}. See |wildcards| for the
5242 use of special characters.
5243
5244 Unless the optional {nosuf} argument is given and is |TRUE|,
5245 the 'suffixes' and 'wildignore' options apply: Names matching
5246 one of the patterns in 'wildignore' will be skipped and
5247 'suffixes' affect the ordering of matches.
5248 'wildignorecase' always applies.
5249
5250 When {list} is present and it is |TRUE| the result is a |List|
5251 with all matching files. The advantage of using a List is,
5252 you also get filenames containing newlines correctly.
5253 Otherwise the result is a String and when there are several
5254 matches, they are separated by <NL> characters.
5255
5256 If the expansion fails, the result is an empty String or List.
5257
5258 You can also use |readdir()| if you need to do complicated
5259 things, such as limiting the number of matches.
5260
5261 A name for a non-existing file is not included. A symbolic
5262 link is only included if it points to an existing file.
5263 However, when the {alllinks} argument is present and it is
5264 |TRUE| then all symbolic links are included.
5265
5266 For most systems backticks can be used to get files names from
5267 any external command. Example: >
5268 :let tagfiles = glob("`find . -name tags -print`")
5269 :let &tags = substitute(tagfiles, "\n", ",", "g")
5270< The result of the program inside the backticks should be one
5271 item per line. Spaces inside an item are allowed.
5272
5273 See |expand()| for expanding special Vim variables. See
5274 |system()| for getting the raw output of an external command.
5275
5276 Can also be used as a |method|: >
5277 GetExpr()->glob()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005278<
5279 Return type: |String| or list<string> or list<any> depending
5280 on {list}
5281
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005282
h-east624bb832024-11-09 18:37:32 +01005283glob2regpat({string}) *glob2regpat()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005284 Convert a file pattern, as used by glob(), into a search
5285 pattern. The result can be used to match with a string that
5286 is a file name. E.g. >
5287 if filename =~ glob2regpat('Make*.mak')
5288< This is equivalent to: >
5289 if filename =~ '^Make.*\.mak$'
5290< When {string} is an empty string the result is "^$", match an
5291 empty string.
5292 Note that the result depends on the system. On MS-Windows
5293 a backslash usually means a path separator.
5294
5295 Can also be used as a |method|: >
5296 GetExpr()->glob2regpat()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005297<
5298 Return type: |String|
5299
5300 *globpath()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005301globpath({path}, {expr} [, {nosuf} [, {list} [, {alllinks}]]])
5302 Perform glob() for String {expr} on all directories in {path}
5303 and concatenate the results. Example: >
5304 :echo globpath(&rtp, "syntax/c.vim")
5305<
5306 {path} is a comma-separated list of directory names. Each
5307 directory name is prepended to {expr} and expanded like with
5308 |glob()|. A path separator is inserted when needed.
5309 To add a comma inside a directory name escape it with a
5310 backslash. Note that on MS-Windows a directory may have a
5311 trailing backslash, remove it if you put a comma after it.
5312 If the expansion fails for one of the directories, there is no
5313 error message.
5314
5315 Unless the optional {nosuf} argument is given and is |TRUE|,
5316 the 'suffixes' and 'wildignore' options apply: Names matching
5317 one of the patterns in 'wildignore' will be skipped and
5318 'suffixes' affect the ordering of matches.
5319
5320 When {list} is present and it is |TRUE| the result is a |List|
5321 with all matching files. The advantage of using a List is, you
5322 also get filenames containing newlines correctly. Otherwise
5323 the result is a String and when there are several matches,
5324 they are separated by <NL> characters. Example: >
5325 :echo globpath(&rtp, "syntax/c.vim", 0, 1)
5326<
5327 {alllinks} is used as with |glob()|.
5328
5329 The "**" item can be used to search in a directory tree.
5330 For example, to find all "README.txt" files in the directories
5331 in 'runtimepath' and below: >
5332 :echo globpath(&rtp, "**/README.txt")
5333< Upwards search and limiting the depth of "**" is not
5334 supported, thus using 'path' will not always work properly.
5335
5336 Can also be used as a |method|, the base is passed as the
5337 second argument: >
5338 GetExpr()->globpath(&rtp)
5339<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005340 Return type: |String| or list<string> or list<any> depending
5341 on {list}
5342
5343
5344has({feature} [, {check}]) *has()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005345 When {check} is omitted or is zero: The result is a Number,
5346 which is 1 if the feature {feature} is supported, zero
5347 otherwise. The {feature} argument is a string, case is
5348 ignored. See |feature-list| below.
5349
5350 When {check} is present and not zero: The result is a Number,
5351 which is 1 if the feature {feature} could ever be supported,
5352 zero otherwise. This is useful to check for a typo in
5353 {feature} and to detect dead code. Keep in mind that an older
5354 Vim version will not know about a feature added later and
5355 features that have been abandoned will not be known by the
5356 current Vim version.
5357
5358 Also see |exists()| and |exists_compiled()|.
5359
5360 Note that to skip code that has a syntax error when the
5361 feature is not available, Vim may skip the rest of the line
5362 and miss a following `endif`. Therefore put the `endif` on a
5363 separate line: >
5364 if has('feature')
5365 let x = this->breaks->without->the->feature
5366 endif
5367< If the `endif` would be moved to the second line as "| endif" it
5368 would not be found.
5369
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005370 Return type: |Number|
5371
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005372
5373has_key({dict}, {key}) *has_key()*
5374 The result is a Number, which is TRUE if |Dictionary| {dict}
Bram Moolenaare8008642022-08-19 17:15:35 +01005375 has an entry with key {key}. FALSE otherwise.
5376 The {key} argument is a string. In |Vim9| script a number is
5377 also accepted (and converted to a string) but no other types.
5378 In legacy script the usual automatic conversion to string is
5379 done.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005380
5381 Can also be used as a |method|: >
5382 mydict->has_key(key)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005383<
5384 Return type: |Number|
5385
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005386
5387haslocaldir([{winnr} [, {tabnr}]]) *haslocaldir()*
5388 The result is a Number:
5389 1 when the window has set a local directory via |:lcd|
5390 2 when the tab-page has set a local directory via |:tcd|
5391 0 otherwise.
5392
5393 Without arguments use the current window.
5394 With {winnr} use this window in the current tab page.
5395 With {winnr} and {tabnr} use the window in the specified tab
5396 page.
5397 {winnr} can be the window number or the |window-ID|.
5398 If {winnr} is -1 it is ignored and only the tabpage is used.
5399 Return 0 if the arguments are invalid.
5400 Examples: >
5401 if haslocaldir() == 1
5402 " window local directory case
5403 elseif haslocaldir() == 2
5404 " tab-local directory case
5405 else
5406 " global directory case
5407 endif
5408
5409 " current window
5410 :echo haslocaldir()
5411 :echo haslocaldir(0)
5412 :echo haslocaldir(0, 0)
5413 " window n in current tab page
5414 :echo haslocaldir(n)
5415 :echo haslocaldir(n, 0)
5416 " window n in tab page m
5417 :echo haslocaldir(n, m)
5418 " tab page m
5419 :echo haslocaldir(-1, m)
5420<
5421 Can also be used as a |method|: >
5422 GetWinnr()->haslocaldir()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005423<
5424 Return type: |Number|
5425
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005426
5427hasmapto({what} [, {mode} [, {abbr}]]) *hasmapto()*
5428 The result is a Number, which is TRUE if there is a mapping
5429 that contains {what} in somewhere in the rhs (what it is
5430 mapped to) and this mapping exists in one of the modes
5431 indicated by {mode}.
5432 The arguments {what} and {mode} are strings.
5433 When {abbr} is there and it is |TRUE| use abbreviations
5434 instead of mappings. Don't forget to specify Insert and/or
5435 Command-line mode.
5436 Both the global mappings and the mappings local to the current
5437 buffer are checked for a match.
5438 If no matching mapping is found FALSE is returned.
5439 The following characters are recognized in {mode}:
5440 n Normal mode
5441 v Visual and Select mode
5442 x Visual mode
5443 s Select mode
5444 o Operator-pending mode
5445 i Insert mode
5446 l Language-Argument ("r", "f", "t", etc.)
5447 c Command-line mode
5448 When {mode} is omitted, "nvo" is used.
5449
5450 This function is useful to check if a mapping already exists
5451 to a function in a Vim script. Example: >
5452 :if !hasmapto('\ABCdoit')
5453 : map <Leader>d \ABCdoit
5454 :endif
5455< This installs the mapping to "\ABCdoit" only if there isn't
5456 already a mapping to "\ABCdoit".
5457
5458 Can also be used as a |method|: >
5459 GetRHS()->hasmapto()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005460<
5461 Return type: |Number|
5462
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005463
5464histadd({history}, {item}) *histadd()*
5465 Add the String {item} to the history {history} which can be
5466 one of: *hist-names*
5467 "cmd" or ":" command line history
5468 "search" or "/" search pattern history
5469 "expr" or "=" typed expression history
5470 "input" or "@" input line history
5471 "debug" or ">" debug command history
5472 empty the current or last used history
5473 The {history} string does not need to be the whole name, one
5474 character is sufficient.
5475 If {item} does already exist in the history, it will be
5476 shifted to become the newest entry.
5477 The result is a Number: TRUE if the operation was successful,
5478 otherwise FALSE is returned.
5479
5480 Example: >
5481 :call histadd("input", strftime("%Y %b %d"))
5482 :let date=input("Enter date: ")
5483< This function is not available in the |sandbox|.
5484
5485 Can also be used as a |method|, the base is passed as the
5486 second argument: >
5487 GetHistory()->histadd('search')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005488<
5489 Return type: |Number|
5490
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005491
5492histdel({history} [, {item}]) *histdel()*
5493 Clear {history}, i.e. delete all its entries. See |hist-names|
5494 for the possible values of {history}.
5495
5496 If the parameter {item} evaluates to a String, it is used as a
5497 regular expression. All entries matching that expression will
5498 be removed from the history (if there are any).
5499 Upper/lowercase must match, unless "\c" is used |/\c|.
5500 If {item} evaluates to a Number, it will be interpreted as
5501 an index, see |:history-indexing|. The respective entry will
5502 be removed if it exists.
5503
5504 The result is TRUE for a successful operation, otherwise FALSE
5505 is returned.
5506
5507 Examples:
5508 Clear expression register history: >
5509 :call histdel("expr")
5510<
5511 Remove all entries starting with "*" from the search history: >
5512 :call histdel("/", '^\*')
5513<
5514 The following three are equivalent: >
5515 :call histdel("search", histnr("search"))
5516 :call histdel("search", -1)
Bram Moolenaarc51cf032022-02-26 12:25:45 +00005517 :call histdel("search", '^' .. histget("search", -1) .. '$')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005518<
5519 To delete the last search pattern and use the last-but-one for
5520 the "n" command and 'hlsearch': >
5521 :call histdel("search", -1)
5522 :let @/ = histget("search", -1)
5523<
5524 Can also be used as a |method|: >
5525 GetHistory()->histdel()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005526<
5527 Return type: |Number|
5528
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005529
5530histget({history} [, {index}]) *histget()*
5531 The result is a String, the entry with Number {index} from
5532 {history}. See |hist-names| for the possible values of
5533 {history}, and |:history-indexing| for {index}. If there is
5534 no such entry, an empty String is returned. When {index} is
5535 omitted, the most recent item from the history is used.
5536
5537 Examples:
5538 Redo the second last search from history. >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00005539 :execute '/' .. histget("search", -2)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005540
5541< Define an Ex command ":H {num}" that supports re-execution of
5542 the {num}th entry from the output of |:history|. >
5543 :command -nargs=1 H execute histget("cmd", 0+<args>)
5544<
5545 Can also be used as a |method|: >
5546 GetHistory()->histget()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005547<
5548 Return type: |String|
5549
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005550
5551histnr({history}) *histnr()*
5552 The result is the Number of the current entry in {history}.
5553 See |hist-names| for the possible values of {history}.
5554 If an error occurred, -1 is returned.
5555
5556 Example: >
5557 :let inp_index = histnr("expr")
5558
5559< Can also be used as a |method|: >
5560 GetHistory()->histnr()
5561<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005562 Return type: |Number|
5563
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005564hlexists({name}) *hlexists()*
5565 The result is a Number, which is TRUE if a highlight group
5566 called {name} exists. This is when the group has been
5567 defined in some way. Not necessarily when highlighting has
5568 been defined for it, it may also have been used for a syntax
5569 item.
5570 *highlight_exists()*
5571 Obsolete name: highlight_exists().
5572
5573 Can also be used as a |method|: >
5574 GetName()->hlexists()
5575<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005576 Return type: |Number|
5577
5578
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005579hlget([{name} [, {resolve}]]) *hlget()*
5580 Returns a List of all the highlight group attributes. If the
5581 optional {name} is specified, then returns a List with only
5582 the attributes of the specified highlight group. Returns an
5583 empty List if the highlight group {name} is not present.
5584
5585 If the optional {resolve} argument is set to v:true and the
5586 highlight group {name} is linked to another group, then the
5587 link is resolved recursively and the attributes of the
5588 resolved highlight group are returned.
5589
5590 Each entry in the returned List is a Dictionary with the
5591 following items:
5592 cleared boolean flag, set to v:true if the highlight
5593 group attributes are cleared or not yet
5594 specified. See |highlight-clear|.
5595 cterm cterm attributes. See |highlight-cterm|.
5596 ctermbg cterm background color.
5597 See |highlight-ctermbg|.
5598 ctermfg cterm foreground color.
5599 See |highlight-ctermfg|.
5600 ctermul cterm underline color. See |highlight-ctermul|.
5601 default boolean flag, set to v:true if the highlight
5602 group link is a default link. See
5603 |highlight-default|.
5604 font highlight group font. See |highlight-font|.
5605 gui gui attributes. See |highlight-gui|.
5606 guibg gui background color. See |highlight-guibg|.
5607 guifg gui foreground color. See |highlight-guifg|.
5608 guisp gui special color. See |highlight-guisp|.
5609 id highlight group ID.
5610 linksto linked highlight group name.
5611 See |:highlight-link|.
5612 name highlight group name. See |group-name|.
5613 start start terminal keycode. See |highlight-start|.
5614 stop stop terminal keycode. See |highlight-stop|.
5615 term term attributes. See |highlight-term|.
5616
5617 The 'term', 'cterm' and 'gui' items in the above Dictionary
5618 have a dictionary value with the following optional boolean
5619 items: 'bold', 'standout', 'underline', 'undercurl', 'italic',
5620 'reverse', 'inverse' and 'strikethrough'.
5621
5622 Example(s): >
5623 :echo hlget()
5624 :echo hlget('ModeMsg')
5625 :echo hlget('Number', v:true)
5626<
5627 Can also be used as a |method|: >
5628 GetName()->hlget()
5629<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005630 Return type: list<dict<any>>
5631
5632
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005633hlset({list}) *hlset()*
5634 Creates or modifies the attributes of a List of highlight
5635 groups. Each item in {list} is a dictionary containing the
5636 attributes of a highlight group. See |hlget()| for the list of
5637 supported items in this dictionary.
5638
5639 In addition to the items described in |hlget()|, the following
5640 additional items are supported in the dictionary:
5641
5642 force boolean flag to force the creation of
5643 a link for an existing highlight group
5644 with attributes.
5645
5646 The highlight group is identified using the 'name' item and
5647 the 'id' item (if supplied) is ignored. If a highlight group
5648 with a specified name doesn't exist, then it is created.
5649 Otherwise the attributes of an existing highlight group are
5650 modified.
5651
5652 If an empty dictionary value is used for the 'term' or 'cterm'
5653 or 'gui' entries, then the corresponding attributes are
5654 cleared. If the 'cleared' item is set to v:true, then all the
5655 attributes of the highlight group are cleared.
5656
5657 The 'linksto' item can be used to link a highlight group to
5658 another highlight group. See |:highlight-link|.
5659
5660 Returns zero for success, -1 for failure.
5661
5662 Example(s): >
5663 " add bold attribute to the Visual highlight group
5664 :call hlset([#{name: 'Visual',
5665 \ term: #{reverse: 1 , bold: 1}}])
5666 :call hlset([#{name: 'Type', guifg: 'DarkGreen'}])
5667 :let l = hlget()
5668 :call hlset(l)
5669 " clear the Search highlight group
5670 :call hlset([#{name: 'Search', cleared: v:true}])
5671 " clear the 'term' attributes for a highlight group
5672 :call hlset([#{name: 'Title', term: {}}])
5673 " create the MyHlg group linking it to DiffAdd
5674 :call hlset([#{name: 'MyHlg', linksto: 'DiffAdd'}])
5675 " remove the MyHlg group link
5676 :call hlset([#{name: 'MyHlg', linksto: 'NONE'}])
5677 " clear the attributes and a link
5678 :call hlset([#{name: 'MyHlg', cleared: v:true,
5679 \ linksto: 'NONE'}])
5680<
5681 Can also be used as a |method|: >
5682 GetAttrList()->hlset()
5683<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005684 Return type: |Number|
5685
5686hlID({name}) *hlID()*
5687 The result is a Number, which is the ID of the highlight group
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005688 with name {name}. When the highlight group doesn't exist,
5689 zero is returned.
5690 This can be used to retrieve information about the highlight
5691 group. For example, to get the background color of the
5692 "Comment" group: >
5693 :echo synIDattr(synIDtrans(hlID("Comment")), "bg")
5694< *highlightID()*
5695 Obsolete name: highlightID().
5696
5697 Can also be used as a |method|: >
5698 GetName()->hlID()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005699<
5700 Return type: |Number|
5701
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005702
5703hostname() *hostname()*
5704 The result is a String, which is the name of the machine on
5705 which Vim is currently running. Machine names greater than
5706 256 characters long are truncated.
5707
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005708 Return type: |String|
5709
5710
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005711iconv({string}, {from}, {to}) *iconv()*
5712 The result is a String, which is the text {string} converted
5713 from encoding {from} to encoding {to}.
5714 When the conversion completely fails an empty string is
5715 returned. When some characters could not be converted they
5716 are replaced with "?".
5717 The encoding names are whatever the iconv() library function
5718 can accept, see ":!man 3 iconv".
5719 Most conversions require Vim to be compiled with the |+iconv|
5720 feature. Otherwise only UTF-8 to latin1 conversion and back
5721 can be done.
5722 This can be used to display messages with special characters,
5723 no matter what 'encoding' is set to. Write the message in
5724 UTF-8 and use: >
5725 echo iconv(utf8_str, "utf-8", &enc)
5726< Note that Vim uses UTF-8 for all Unicode encodings, conversion
5727 from/to UCS-2 is automatically changed to use UTF-8. You
5728 cannot use UCS-2 in a string anyway, because of the NUL bytes.
5729
5730 Can also be used as a |method|: >
5731 GetText()->iconv('latin1', 'utf-8')
5732<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005733 Return type: |String|
5734
5735
h-east624bb832024-11-09 18:37:32 +01005736id({item}) *id()*
Ernie Raelc8e158b2024-07-09 18:39:52 +02005737 The result is a unique String associated with the {item} and
5738 not with the {item}'s contents. It is only valid while the
5739 {item} exists and is referenced. It is valid only in the
5740 instance of vim that produces the result. The whole idea is
5741 that `id({item})` does not change if the contents of {item}
5742 changes. This is useful as a `key` for creating an identity
5743 dictionary, rather than one based on equals.
5744
5745 This operation does not reference {item} and there is no
5746 function to convert the `id` to the {item}. It may be useful to
5747 have a map of `id` to {item}. The following >
5748 var referenceMap: dict<any>
5749 var id = item->id()
5750 referenceMap[id] = item
5751< prevents {item} from being garbage collected and provides a
5752 way to get the {item} from the `id`.
5753
5754 {item} may be a List, Dictionary, Object, Job, Channel or
5755 Blob. If the item is not a permitted type, or it is a null
5756 value, then an empty String is returned.
5757
5758 Can also be used as a |method|: >
5759 GetItem()->id()
5760<
5761 Return type: |String|
5762
5763
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005764indent({lnum}) *indent()*
5765 The result is a Number, which is indent of line {lnum} in the
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005766 current buffer. The indent is counted in spaces, the value
5767 of 'tabstop' is relevant. {lnum} is used just like in
5768 |getline()|.
5769 When {lnum} is invalid -1 is returned. In |Vim9| script an
5770 error is given.
5771
5772 Can also be used as a |method|: >
5773 GetLnum()->indent()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005774<
5775 Return type: |Number|
5776
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005777
5778index({object}, {expr} [, {start} [, {ic}]]) *index()*
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005779 Find {expr} in {object} and return its index. See
Yegappan Lakshmanan3fbf6cd2022-08-13 21:35:13 +01005780 |indexof()| for using a lambda to select the item.
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005781
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005782 If {object} is a |List| return the lowest index where the item
5783 has a value equal to {expr}. There is no automatic
5784 conversion, so the String "4" is different from the Number 4.
5785 And the number 4 is different from the Float 4.0. The value
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005786 of 'ignorecase' is not used here, case matters as indicated by
5787 the {ic} argument.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005788
5789 If {object} is |Blob| return the lowest index where the byte
5790 value is equal to {expr}.
5791
5792 If {start} is given then start looking at the item with index
5793 {start} (may be negative for an item relative to the end).
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005794
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005795 When {ic} is given and it is |TRUE|, ignore case. Otherwise
5796 case must match.
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005797
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005798 -1 is returned when {expr} is not found in {object}.
5799 Example: >
5800 :let idx = index(words, "the")
5801 :if index(numbers, 123) >= 0
5802
5803< Can also be used as a |method|: >
5804 GetObject()->index(what)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005805<
5806 Return type: |Number|
5807
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005808
Yegappan Lakshmanan3fbf6cd2022-08-13 21:35:13 +01005809indexof({object}, {expr} [, {opts}]) *indexof()*
5810 Returns the index of an item in {object} where {expr} is
5811 v:true. {object} must be a |List| or a |Blob|.
5812
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005813 If {object} is a |List|, evaluate {expr} for each item in the
Yegappan Lakshmanan3fbf6cd2022-08-13 21:35:13 +01005814 List until the expression is v:true and return the index of
5815 this item.
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005816
5817 If {object} is a |Blob| evaluate {expr} for each byte in the
Yegappan Lakshmanan3fbf6cd2022-08-13 21:35:13 +01005818 Blob until the expression is v:true and return the index of
5819 this byte.
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005820
5821 {expr} must be a |string| or |Funcref|.
5822
5823 If {expr} is a |string|: If {object} is a |List|, inside
5824 {expr} |v:key| has the index of the current List item and
5825 |v:val| has the value of the item. If {object} is a |Blob|,
5826 inside {expr} |v:key| has the index of the current byte and
5827 |v:val| has the byte value.
5828
5829 If {expr} is a |Funcref| it must take two arguments:
5830 1. the key or the index of the current item.
5831 2. the value of the current item.
5832 The function must return |TRUE| if the item is found and the
5833 search should stop.
5834
Yegappan Lakshmanan3fbf6cd2022-08-13 21:35:13 +01005835 The optional argument {opts} is a Dict and supports the
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005836 following items:
Yegappan Lakshmanan3fbf6cd2022-08-13 21:35:13 +01005837 startidx start evaluating {expr} at the item with this
5838 index; may be negative for an item relative to
5839 the end
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005840 Returns -1 when {expr} evaluates to v:false for all the items.
5841 Example: >
Yegappan Lakshmanan3fbf6cd2022-08-13 21:35:13 +01005842 :let l = [#{n: 10}, #{n: 20}, #{n: 30}]
5843 :echo indexof(l, "v:val.n == 20")
5844 :echo indexof(l, {i, v -> v.n == 30})
5845 :echo indexof(l, "v:val.n == 20", #{startidx: 1})
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005846
5847< Can also be used as a |method|: >
5848 mylist->indexof(expr)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005849<
5850 Return type: |Number|
5851
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005852
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005853input({prompt} [, {text} [, {completion}]]) *input()*
5854 The result is a String, which is whatever the user typed on
5855 the command-line. The {prompt} argument is either a prompt
5856 string, or a blank string (for no prompt). A '\n' can be used
5857 in the prompt to start a new line.
5858 The highlighting set with |:echohl| is used for the prompt.
5859 The input is entered just like a command-line, with the same
5860 editing commands and mappings. There is a separate history
5861 for lines typed for input().
5862 Example: >
5863 :if input("Coffee or beer? ") == "beer"
5864 : echo "Cheers!"
5865 :endif
5866<
5867 If the optional {text} argument is present and not empty, this
5868 is used for the default reply, as if the user typed this.
5869 Example: >
5870 :let color = input("Color? ", "white")
5871
5872< The optional {completion} argument specifies the type of
5873 completion supported for the input. Without it completion is
5874 not performed. The supported completion types are the same as
5875 that can be supplied to a user-defined command using the
5876 "-complete=" argument. Refer to |:command-completion| for
5877 more information. Example: >
5878 let fname = input("File: ", "", "file")
5879<
5880 NOTE: This function must not be used in a startup file, for
5881 the versions that only run in GUI mode (e.g., the Win32 GUI).
5882 Note: When input() is called from within a mapping it will
5883 consume remaining characters from that mapping, because a
5884 mapping is handled like the characters were typed.
5885 Use |inputsave()| before input() and |inputrestore()|
5886 after input() to avoid that. Another solution is to avoid
5887 that further characters follow in the mapping, e.g., by using
5888 |:execute| or |:normal|.
5889
5890 Example with a mapping: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00005891 :nmap \x :call GetFoo()<CR>:exe "/" .. Foo<CR>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005892 :function GetFoo()
5893 : call inputsave()
5894 : let g:Foo = input("enter search pattern: ")
5895 : call inputrestore()
5896 :endfunction
5897
5898< Can also be used as a |method|: >
5899 GetPrompt()->input()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005900<
5901 Return type: |String|
5902
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005903
5904inputdialog({prompt} [, {text} [, {cancelreturn}]]) *inputdialog()*
5905 Like |input()|, but when the GUI is running and text dialogs
5906 are supported, a dialog window pops up to input the text.
5907 Example: >
5908 :let n = inputdialog("value for shiftwidth", shiftwidth())
5909 :if n != ""
5910 : let &sw = n
5911 :endif
5912< When the dialog is cancelled {cancelreturn} is returned. When
5913 omitted an empty string is returned.
5914 Hitting <Enter> works like pressing the OK button. Hitting
5915 <Esc> works like pressing the Cancel button.
5916 NOTE: Command-line completion is not supported.
5917
5918 Can also be used as a |method|: >
5919 GetPrompt()->inputdialog()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005920<
5921 Return type: |String|
5922
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005923
5924inputlist({textlist}) *inputlist()*
5925 {textlist} must be a |List| of strings. This |List| is
5926 displayed, one string per line. The user will be prompted to
5927 enter a number, which is returned.
5928 The user can also select an item by clicking on it with the
5929 mouse, if the mouse is enabled in the command line ('mouse' is
5930 "a" or includes "c"). For the first string 0 is returned.
5931 When clicking above the first item a negative number is
5932 returned. When clicking on the prompt one more than the
5933 length of {textlist} is returned.
5934 Make sure {textlist} has less than 'lines' entries, otherwise
5935 it won't work. It's a good idea to put the entry number at
5936 the start of the string. And put a prompt in the first item.
5937 Example: >
5938 let color = inputlist(['Select color:', '1. red',
5939 \ '2. green', '3. blue'])
5940
5941< Can also be used as a |method|: >
5942 GetChoices()->inputlist()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005943<
5944 Return type: |Number|
5945
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005946
5947inputrestore() *inputrestore()*
5948 Restore typeahead that was saved with a previous |inputsave()|.
5949 Should be called the same number of times inputsave() is
5950 called. Calling it more often is harmless though.
5951 Returns TRUE when there is nothing to restore, FALSE otherwise.
5952
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005953 Return type: |Number|
5954
5955
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005956inputsave() *inputsave()*
5957 Preserve typeahead (also from mappings) and clear it, so that
5958 a following prompt gets input from the user. Should be
5959 followed by a matching inputrestore() after the prompt. Can
5960 be used several times, in which case there must be just as
5961 many inputrestore() calls.
5962 Returns TRUE when out of memory, FALSE otherwise.
5963
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005964 Return type: |Number|
5965
5966
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005967inputsecret({prompt} [, {text}]) *inputsecret()*
5968 This function acts much like the |input()| function with but
5969 two exceptions:
5970 a) the user's response will be displayed as a sequence of
5971 asterisks ("*") thereby keeping the entry secret, and
5972 b) the user's response will not be recorded on the input
5973 |history| stack.
5974 The result is a String, which is whatever the user actually
5975 typed on the command-line in response to the issued prompt.
5976 NOTE: Command-line completion is not supported.
5977
5978 Can also be used as a |method|: >
5979 GetPrompt()->inputsecret()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005980<
5981 Return type: |String|
5982
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005983
5984insert({object}, {item} [, {idx}]) *insert()*
5985 When {object} is a |List| or a |Blob| insert {item} at the start
5986 of it.
5987
5988 If {idx} is specified insert {item} before the item with index
5989 {idx}. If {idx} is zero it goes before the first item, just
5990 like omitting {idx}. A negative {idx} is also possible, see
5991 |list-index|. -1 inserts just before the last item.
5992
5993 Returns the resulting |List| or |Blob|. Examples: >
5994 :let mylist = insert([2, 3, 5], 1)
5995 :call insert(mylist, 4, -1)
5996 :call insert(mylist, 6, len(mylist))
5997< The last example can be done simpler with |add()|.
5998 Note that when {item} is a |List| it is inserted as a single
5999 item. Use |extend()| to concatenate |Lists|.
6000
6001 Can also be used as a |method|: >
6002 mylist->insert(item)
Yegappan Lakshmanancd39b692023-10-02 12:50:45 -07006003<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006004 Return type: |Number|
6005
6006
Yegappan Lakshmanancd39b692023-10-02 12:50:45 -07006007 *instanceof()* *E614* *E616* *E693*
6008instanceof({object}, {class})
6009 The result is a Number, which is |TRUE| when the {object}
Ernie Rael2025af12023-12-12 16:58:00 +01006010 argument is a direct or indirect instance of a |Class|,
6011 |Interface|, or class |:type| alias specified by {class}.
6012 If {class} is varargs, the function returns |TRUE| when
Yegappan Lakshmanancd39b692023-10-02 12:50:45 -07006013 {object} is an instance of any of the specified classes.
LemonBoyafe04662023-08-23 21:08:11 +02006014 Example: >
Ernie Rael2025af12023-12-12 16:58:00 +01006015 instanceof(animal, Dog, Cat)
LemonBoyafe04662023-08-23 21:08:11 +02006016
6017< Can also be used as a |method|: >
6018 myobj->instanceof(mytype)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006019<
6020 Return type: |Number|
LemonBoyafe04662023-08-23 21:08:11 +02006021
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006022interrupt() *interrupt()*
6023 Interrupt script execution. It works more or less like the
6024 user typing CTRL-C, most commands won't execute and control
6025 returns to the user. This is useful to abort execution
6026 from lower down, e.g. in an autocommand. Example: >
6027 :function s:check_typoname(file)
6028 : if fnamemodify(a:file, ':t') == '['
6029 : echomsg 'Maybe typo'
6030 : call interrupt()
6031 : endif
6032 :endfunction
6033 :au BufWritePre * call s:check_typoname(expand('<amatch>'))
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006034<
6035 Return type: void
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006036
6037invert({expr}) *invert()*
6038 Bitwise invert. The argument is converted to a number. A
6039 List, Dict or Float argument causes an error. Example: >
6040 :let bits = invert(bits)
6041< Can also be used as a |method|: >
6042 :let bits = bits->invert()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006043<
6044 Return type: |Number|
6045
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006046
Bram Moolenaar8a3b8052022-06-26 12:21:15 +01006047isabsolutepath({path}) *isabsolutepath()*
LemonBoydca1d402022-04-28 15:26:33 +01006048 The result is a Number, which is |TRUE| when {path} is an
6049 absolute path.
Bram Moolenaar8a3b8052022-06-26 12:21:15 +01006050 On Unix, a path is considered absolute when it starts with '/'.
LemonBoydca1d402022-04-28 15:26:33 +01006051 On MS-Windows, it is considered absolute when it starts with an
6052 optional drive prefix and is followed by a '\' or '/'. UNC paths
6053 are always absolute.
6054 Example: >
6055 echo isabsolutepath('/usr/share/') " 1
6056 echo isabsolutepath('./foobar') " 0
6057 echo isabsolutepath('C:\Windows') " 1
6058 echo isabsolutepath('foobar') " 0
6059 echo isabsolutepath('\\remote\file') " 1
Bram Moolenaar8a3b8052022-06-26 12:21:15 +01006060<
LemonBoydca1d402022-04-28 15:26:33 +01006061 Can also be used as a |method|: >
6062 GetName()->isabsolutepath()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006063<
6064 Return type: |Number|
LemonBoydca1d402022-04-28 15:26:33 +01006065
6066
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006067isdirectory({directory}) *isdirectory()*
6068 The result is a Number, which is |TRUE| when a directory
6069 with the name {directory} exists. If {directory} doesn't
6070 exist, or isn't a directory, the result is |FALSE|. {directory}
6071 is any expression, which is used as a String.
6072
6073 Can also be used as a |method|: >
6074 GetName()->isdirectory()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006075<
6076 Return type: |Number|
6077
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006078
6079isinf({expr}) *isinf()*
6080 Return 1 if {expr} is a positive infinity, or -1 a negative
6081 infinity, otherwise 0. >
6082 :echo isinf(1.0 / 0.0)
6083< 1 >
6084 :echo isinf(-1.0 / 0.0)
6085< -1
6086
6087 Can also be used as a |method|: >
6088 Compute()->isinf()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006089<
6090 Return type: |Number|
6091
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006092
6093islocked({expr}) *islocked()* *E786*
6094 The result is a Number, which is |TRUE| when {expr} is the
6095 name of a locked variable.
6096 The string argument {expr} must be the name of a variable,
6097 |List| item or |Dictionary| entry, not the variable itself!
6098 Example: >
6099 :let alist = [0, ['a', 'b'], 2, 3]
6100 :lockvar 1 alist
6101 :echo islocked('alist') " 1
6102 :echo islocked('alist[1]') " 0
6103
Bram Moolenaar9da17d72022-02-09 21:50:44 +00006104< When {expr} is a variable that does not exist -1 is returned.
6105 If {expr} uses a range, list or dict index that is out of
6106 range or does not exist you get an error message. Use
6107 |exists()| to check for existence.
6108 In Vim9 script it does not work for local function variables.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006109
6110 Can also be used as a |method|: >
6111 GetName()->islocked()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006112<
6113 Return type: |Number|
6114
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006115
6116isnan({expr}) *isnan()*
6117 Return |TRUE| if {expr} is a float with value NaN. >
6118 echo isnan(0.0 / 0.0)
6119< 1
6120
6121 Can also be used as a |method|: >
6122 Compute()->isnan()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006123<
6124 Return type: |Number|
6125
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006126
6127items({dict}) *items()*
6128 Return a |List| with all the key-value pairs of {dict}. Each
6129 |List| item is a list with two items: the key of a {dict}
6130 entry and the value of this entry. The |List| is in arbitrary
6131 order. Also see |keys()| and |values()|.
6132 Example: >
6133 for [key, value] in items(mydict)
Bram Moolenaarc51cf032022-02-26 12:25:45 +00006134 echo key .. ': ' .. value
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006135 endfor
Yegappan Lakshmanan49cdd622023-12-24 11:01:23 +01006136<
6137 A List or a String argument is also supported. In these
6138 cases, items() returns a List with the index and the value at
6139 the index.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006140
Yegappan Lakshmanan49cdd622023-12-24 11:01:23 +01006141 Can also be used as a |method|: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006142 mydict->items()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006143<
6144 Return type: list<list<any>> or list<any>
6145
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006146
6147job_ functions are documented here: |job-functions-details|
6148
6149
6150join({list} [, {sep}]) *join()*
6151 Join the items in {list} together into one String.
6152 When {sep} is specified it is put in between the items. If
6153 {sep} is omitted a single space is used.
6154 Note that {sep} is not added at the end. You might want to
6155 add it there too: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00006156 let lines = join(mylist, "\n") .. "\n"
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006157< String items are used as-is. |Lists| and |Dictionaries| are
6158 converted into a string like with |string()|.
6159 The opposite function is |split()|.
6160
6161 Can also be used as a |method|: >
6162 mylist->join()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006163<
6164 Return type: |String|
6165
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006166
6167js_decode({string}) *js_decode()*
6168 This is similar to |json_decode()| with these differences:
6169 - Object key names do not have to be in quotes.
6170 - Strings can be in single quotes.
6171 - Empty items in an array (between two commas) are allowed and
6172 result in v:none items.
6173
6174 Can also be used as a |method|: >
6175 ReadObject()->js_decode()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006176<
6177 Return type: any, depending on {varname}
6178
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006179
6180js_encode({expr}) *js_encode()*
6181 This is similar to |json_encode()| with these differences:
6182 - Object key names are not in quotes.
6183 - v:none items in an array result in an empty item between
6184 commas.
6185 For example, the Vim object:
6186 [1,v:none,{"one":1},v:none] ~
6187 Will be encoded as:
6188 [1,,{one:1},,] ~
6189 While json_encode() would produce:
6190 [1,null,{"one":1},null] ~
6191 This encoding is valid for JavaScript. It is more efficient
6192 than JSON, especially when using an array with optional items.
6193
6194 Can also be used as a |method|: >
6195 GetObject()->js_encode()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006196<
6197 Return type: |String|
6198
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006199
Bram Moolenaar2f0936c2022-01-08 21:51:59 +00006200json_decode({string}) *json_decode()* *E491*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006201 This parses a JSON formatted string and returns the equivalent
6202 in Vim values. See |json_encode()| for the relation between
6203 JSON and Vim values.
6204 The decoding is permissive:
6205 - A trailing comma in an array and object is ignored, e.g.
6206 "[1, 2, ]" is the same as "[1, 2]".
6207 - Integer keys are accepted in objects, e.g. {1:2} is the
6208 same as {"1":2}.
6209 - More floating point numbers are recognized, e.g. "1." for
6210 "1.0", or "001.2" for "1.2". Special floating point values
6211 "Infinity", "-Infinity" and "NaN" (capitalization ignored)
6212 are accepted.
6213 - Leading zeroes in integer numbers are ignored, e.g. "012"
6214 for "12" or "-012" for "-12".
6215 - Capitalization is ignored in literal names null, true or
6216 false, e.g. "NULL" for "null", "True" for "true".
6217 - Control characters U+0000 through U+001F which are not
6218 escaped in strings are accepted, e.g. " " (tab
6219 character in string) for "\t".
6220 - An empty JSON expression or made of only spaces is accepted
6221 and results in v:none.
6222 - Backslash in an invalid 2-character sequence escape is
6223 ignored, e.g. "\a" is decoded as "a".
6224 - A correct surrogate pair in JSON strings should normally be
6225 a 12 character sequence such as "\uD834\uDD1E", but
6226 json_decode() silently accepts truncated surrogate pairs
6227 such as "\uD834" or "\uD834\u"
6228 *E938*
6229 A duplicate key in an object, valid in rfc7159, is not
6230 accepted by json_decode() as the result must be a valid Vim
6231 type, e.g. this fails: {"a":"b", "a":"c"}
6232
6233 Can also be used as a |method|: >
6234 ReadObject()->json_decode()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006235<
6236 Return type: any, depending on {varname}
6237
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006238
6239json_encode({expr}) *json_encode()*
6240 Encode {expr} as JSON and return this as a string.
6241 The encoding is specified in:
6242 https://tools.ietf.org/html/rfc7159.html
Bram Moolenaara2baa732022-02-04 16:09:54 +00006243 Vim values are converted as follows: *E1161*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006244 |Number| decimal number
6245 |Float| floating point number
6246 Float nan "NaN"
6247 Float inf "Infinity"
6248 Float -inf "-Infinity"
6249 |String| in double quotes (possibly null)
6250 |Funcref| not possible, error
6251 |List| as an array (possibly null); when
6252 used recursively: []
6253 |Dict| as an object (possibly null); when
6254 used recursively: {}
6255 |Blob| as an array of the individual bytes
6256 v:false "false"
6257 v:true "true"
6258 v:none "null"
6259 v:null "null"
6260 Note that NaN and Infinity are passed on as values. This is
6261 missing in the JSON standard, but several implementations do
6262 allow it. If not then you will get an error.
Bram Moolenaarcbaff5e2022-04-08 17:45:08 +01006263 If a string contains an illegal character then the replacement
6264 character 0xfffd is used.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006265
6266 Can also be used as a |method|: >
6267 GetObject()->json_encode()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006268<
6269 Return type: |String|
6270
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006271
6272keys({dict}) *keys()*
6273 Return a |List| with all the keys of {dict}. The |List| is in
6274 arbitrary order. Also see |items()| and |values()|.
6275
6276 Can also be used as a |method|: >
6277 mydict->keys()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006278<
6279 Return type: list<string>
6280
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006281
zeertzjqcdc83932022-09-12 13:38:41 +01006282keytrans({string}) *keytrans()*
6283 Turn the internal byte representation of keys into a form that
6284 can be used for |:map|. E.g. >
6285 :let xx = "\<C-Home>"
6286 :echo keytrans(xx)
6287< <C-Home>
6288
6289 Can also be used as a |method|: >
6290 "\<C-Home>"->keytrans()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006291<
6292 Return type: |String|
zeertzjqcdc83932022-09-12 13:38:41 +01006293
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006294
6295len({expr}) *len()* *E701*
6296 The result is a Number, which is the length of the argument.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006297 When {expr} is a String or a Number the length in bytes is
6298 used, as with |strlen()|.
6299 When {expr} is a |List| the number of items in the |List| is
6300 returned.
6301 When {expr} is a |Blob| the number of bytes is returned.
6302 When {expr} is a |Dictionary| the number of entries in the
6303 |Dictionary| is returned.
mityu7f0bba22024-03-29 10:14:41 +01006304 When {expr} is an |Object|, invokes the len() method in the
6305 object (if present) to get the length (|object-len()|).
6306 Otherwise returns zero.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006307
6308 Can also be used as a |method|: >
6309 mylist->len()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006310<
6311 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006312
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006313
6314 *libcall()* *E364* *E368*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006315libcall({libname}, {funcname}, {argument})
6316 Call function {funcname} in the run-time library {libname}
6317 with single argument {argument}.
6318 This is useful to call functions in a library that you
6319 especially made to be used with Vim. Since only one argument
6320 is possible, calling standard library functions is rather
6321 limited.
6322 The result is the String returned by the function. If the
6323 function returns NULL, this will appear as an empty string ""
6324 to Vim.
6325 If the function returns a number, use libcallnr()!
6326 If {argument} is a number, it is passed to the function as an
6327 int; if {argument} is a string, it is passed as a
6328 null-terminated string.
6329 This function will fail in |restricted-mode|.
6330
6331 libcall() allows you to write your own 'plug-in' extensions to
6332 Vim without having to recompile the program. It is NOT a
6333 means to call system functions! If you try to do so Vim will
6334 very probably crash.
6335
6336 For Win32, the functions you write must be placed in a DLL
6337 and use the normal C calling convention (NOT Pascal which is
6338 used in Windows System DLLs). The function must take exactly
6339 one parameter, either a character pointer or a long integer,
6340 and must return a character pointer or NULL. The character
6341 pointer returned must point to memory that will remain valid
6342 after the function has returned (e.g. in static data in the
6343 DLL). If it points to allocated memory, that memory will
6344 leak away. Using a static buffer in the function should work,
6345 it's then freed when the DLL is unloaded.
6346
6347 WARNING: If the function returns a non-valid pointer, Vim may
6348 crash! This also happens if the function returns a number,
6349 because Vim thinks it's a pointer.
6350 For Win32 systems, {libname} should be the filename of the DLL
6351 without the ".DLL" suffix. A full path is only required if
6352 the DLL is not in the usual places.
6353 For Unix: When compiling your own plugins, remember that the
6354 object code must be compiled as position-independent ('PIC').
6355 {only in Win32 and some Unix versions, when the |+libcall|
6356 feature is present}
6357 Examples: >
6358 :echo libcall("libc.so", "getenv", "HOME")
6359
6360< Can also be used as a |method|, the base is passed as the
6361 third argument: >
6362 GetValue()->libcall("libc.so", "getenv")
6363<
6364 *libcallnr()*
6365libcallnr({libname}, {funcname}, {argument})
6366 Just like |libcall()|, but used for a function that returns an
6367 int instead of a string.
6368 {only in Win32 on some Unix versions, when the |+libcall|
6369 feature is present}
6370 Examples: >
6371 :echo libcallnr("/usr/lib/libc.so", "getpid", "")
6372 :call libcallnr("libc.so", "printf", "Hello World!\n")
6373 :call libcallnr("libc.so", "sleep", 10)
6374<
6375 Can also be used as a |method|, the base is passed as the
6376 third argument: >
6377 GetValue()->libcallnr("libc.so", "printf")
6378<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006379 Return type: |String|
6380
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006381
6382line({expr} [, {winid}]) *line()*
6383 The result is a Number, which is the line number of the file
6384 position given with {expr}. The {expr} argument is a string.
zeertzjq02f3eba2024-06-12 20:45:24 +02006385 See |getpos()| for accepted positions.
6386
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006387 To get the column number use |col()|. To get both use
6388 |getpos()|.
zeertzjq02f3eba2024-06-12 20:45:24 +02006389
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006390 With the optional {winid} argument the values are obtained for
6391 that window instead of the current window.
zeertzjq02f3eba2024-06-12 20:45:24 +02006392
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01006393 Returns 0 for invalid values of {expr} and {winid}.
zeertzjq02f3eba2024-06-12 20:45:24 +02006394
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006395 Examples: >
6396 line(".") line number of the cursor
6397 line(".", winid) idem, in window "winid"
6398 line("'t") line number of mark t
Bram Moolenaarc51cf032022-02-26 12:25:45 +00006399 line("'" .. marker) line number of mark marker
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006400<
6401 To jump to the last known position when opening a file see
6402 |last-position-jump|.
6403
6404 Can also be used as a |method|: >
6405 GetValue()->line()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006406<
6407 Return type: |Number|
6408
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006409
6410line2byte({lnum}) *line2byte()*
6411 Return the byte count from the start of the buffer for line
6412 {lnum}. This includes the end-of-line character, depending on
6413 the 'fileformat' option for the current buffer. The first
6414 line returns 1. 'encoding' matters, 'fileencoding' is ignored.
6415 This can also be used to get the byte count for the line just
6416 below the last line: >
6417 line2byte(line("$") + 1)
6418< This is the buffer size plus one. If 'fileencoding' is empty
6419 it is the file size plus one. {lnum} is used like with
6420 |getline()|. When {lnum} is invalid, or the |+byte_offset|
6421 feature has been disabled at compile time, -1 is returned.
6422 Also see |byte2line()|, |go| and |:goto|.
6423
6424 Can also be used as a |method|: >
6425 GetLnum()->line2byte()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006426<
6427 Return type: |Number|
6428
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006429
6430lispindent({lnum}) *lispindent()*
6431 Get the amount of indent for line {lnum} according the lisp
6432 indenting rules, as with 'lisp'.
6433 The indent is counted in spaces, the value of 'tabstop' is
6434 relevant. {lnum} is used just like in |getline()|.
Bram Moolenaar8e145b82022-05-21 20:17:31 +01006435 When {lnum} is invalid -1 is returned. In |Vim9| script an
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006436 error is given.
6437
6438 Can also be used as a |method|: >
6439 GetLnum()->lispindent()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006440<
6441 Return type: |Number|
6442
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006443
6444list2blob({list}) *list2blob()*
6445 Return a Blob concatenating all the number values in {list}.
6446 Examples: >
6447 list2blob([1, 2, 3, 4]) returns 0z01020304
6448 list2blob([]) returns 0z
6449< Returns an empty Blob on error. If one of the numbers is
6450 negative or more than 255 error *E1239* is given.
6451
6452 |blob2list()| does the opposite.
6453
6454 Can also be used as a |method|: >
6455 GetList()->list2blob()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006456<
6457 Return type: |Blob|
6458
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006459
6460list2str({list} [, {utf8}]) *list2str()*
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006461 Convert each number in {list} to a character string and
6462 concatenates them all. Examples: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006463 list2str([32]) returns " "
6464 list2str([65, 66, 67]) returns "ABC"
6465< The same can be done (slowly) with: >
6466 join(map(list, {nr, val -> nr2char(val)}), '')
6467< |str2list()| does the opposite.
6468
6469 When {utf8} is omitted or zero, the current 'encoding' is used.
6470 When {utf8} is TRUE, always return UTF-8 characters.
6471 With UTF-8 composing characters work as expected: >
6472 list2str([97, 769]) returns "á"
6473<
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01006474 Returns an empty string on error.
6475
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006476 Can also be used as a |method|: >
6477 GetList()->list2str()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006478<
6479 Return type: |String|
6480
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006481
6482listener_add({callback} [, {buf}]) *listener_add()*
6483 Add a callback function that will be invoked when changes have
6484 been made to buffer {buf}.
6485 {buf} refers to a buffer name or number. For the accepted
6486 values, see |bufname()|. When {buf} is omitted the current
6487 buffer is used.
6488 Returns a unique ID that can be passed to |listener_remove()|.
6489
6490 The {callback} is invoked with five arguments:
Bram Moolenaar944697a2022-02-20 19:48:20 +00006491 bufnr the buffer that was changed
6492 start first changed line number
6493 end first line number below the change
6494 added number of lines added, negative if lines were
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006495 deleted
Bram Moolenaar944697a2022-02-20 19:48:20 +00006496 changes a List of items with details about the changes
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006497
6498 Example: >
6499 func Listener(bufnr, start, end, added, changes)
6500 echo 'lines ' .. a:start .. ' until ' .. a:end .. ' changed'
6501 endfunc
6502 call listener_add('Listener', bufnr)
6503
Bram Moolenaar944697a2022-02-20 19:48:20 +00006504< The List cannot be changed. Each item in "changes" is a
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006505 dictionary with these entries:
6506 lnum the first line number of the change
6507 end the first line below the change
6508 added number of lines added; negative if lines were
6509 deleted
6510 col first column in "lnum" that was affected by
6511 the change; one if unknown or the whole line
6512 was affected; this is a byte index, first
6513 character has a value of one.
Bram Moolenaar3c053a12022-10-16 13:11:12 +01006514 When lines are inserted (not when a line is split, e.g. by
6515 typing CR in Insert mode) the values are:
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006516 lnum line above which the new line is added
6517 end equal to "lnum"
6518 added number of lines inserted
6519 col 1
6520 When lines are deleted the values are:
6521 lnum the first deleted line
6522 end the line below the first deleted line, before
6523 the deletion was done
6524 added negative, number of lines deleted
6525 col 1
6526 When lines are changed:
6527 lnum the first changed line
6528 end the line below the last changed line
6529 added 0
6530 col first column with a change or 1
6531
6532 The entries are in the order the changes were made, thus the
6533 most recent change is at the end. The line numbers are valid
6534 when the callback is invoked, but later changes may make them
6535 invalid, thus keeping a copy for later might not work.
6536
6537 The {callback} is invoked just before the screen is updated,
6538 when |listener_flush()| is called or when a change is being
6539 made that changes the line count in a way it causes a line
6540 number in the list of changes to become invalid.
6541
6542 The {callback} is invoked with the text locked, see
6543 |textlock|. If you do need to make changes to the buffer, use
6544 a timer to do this later |timer_start()|.
6545
6546 The {callback} is not invoked when the buffer is first loaded.
6547 Use the |BufReadPost| autocmd event to handle the initial text
6548 of a buffer.
6549 The {callback} is also not invoked when the buffer is
6550 unloaded, use the |BufUnload| autocmd event for that.
6551
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01006552 Returns zero if {callback} or {buf} is invalid.
6553
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006554 Can also be used as a |method|, the base is passed as the
6555 second argument: >
6556 GetBuffer()->listener_add(callback)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006557<
6558 Return type: |Number|
6559
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006560
6561listener_flush([{buf}]) *listener_flush()*
6562 Invoke listener callbacks for buffer {buf}. If there are no
6563 pending changes then no callbacks are invoked.
6564
6565 {buf} refers to a buffer name or number. For the accepted
6566 values, see |bufname()|. When {buf} is omitted the current
6567 buffer is used.
6568
6569 Can also be used as a |method|: >
6570 GetBuffer()->listener_flush()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006571<
6572 Return type: |Number|
6573
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006574
6575listener_remove({id}) *listener_remove()*
6576 Remove a listener previously added with listener_add().
6577 Returns FALSE when {id} could not be found, TRUE when {id} was
6578 removed.
6579
6580 Can also be used as a |method|: >
6581 GetListenerId()->listener_remove()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006582<
6583 Return type: |Number|
6584
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006585
6586localtime() *localtime()*
6587 Return the current time, measured as seconds since 1st Jan
6588 1970. See also |strftime()|, |strptime()| and |getftime()|.
6589
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006590 Return type: |Number|
6591
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006592
6593log({expr}) *log()*
6594 Return the natural logarithm (base e) of {expr} as a |Float|.
6595 {expr} must evaluate to a |Float| or a |Number| in the range
6596 (0, inf].
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01006597 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006598 Examples: >
6599 :echo log(10)
6600< 2.302585 >
6601 :echo log(exp(5))
6602< 5.0
6603
6604 Can also be used as a |method|: >
6605 Compute()->log()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006606<
6607 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006608
6609
6610log10({expr}) *log10()*
6611 Return the logarithm of Float {expr} to base 10 as a |Float|.
6612 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01006613 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006614 Examples: >
6615 :echo log10(1000)
6616< 3.0 >
6617 :echo log10(0.01)
6618< -2.0
6619
6620 Can also be used as a |method|: >
6621 Compute()->log10()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006622<
6623 Return type: |Float|
6624
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006625
6626luaeval({expr} [, {expr}]) *luaeval()*
6627 Evaluate Lua expression {expr} and return its result converted
6628 to Vim data structures. Second {expr} may hold additional
6629 argument accessible as _A inside first {expr}.
6630 Strings are returned as they are.
6631 Boolean objects are converted to numbers.
Bram Moolenaar73e28dc2022-09-17 21:08:33 +01006632 Numbers are converted to |Float| values.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006633 Dictionaries and lists obtained by vim.eval() are returned
6634 as-is.
6635 Other objects are returned as zero without any errors.
6636 See |lua-luaeval| for more details.
6637 Note that in a `:def` function local variables are not visible
6638 to {expr}.
6639
6640 Can also be used as a |method|: >
6641 GetExpr()->luaeval()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006642<
6643 Return type: any, depending on {expr}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006644
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006645 {only available when compiled with the |+lua| feature}
6646
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006647
6648map({expr1}, {expr2}) *map()*
6649 {expr1} must be a |List|, |String|, |Blob| or |Dictionary|.
Bram Moolenaar944697a2022-02-20 19:48:20 +00006650 When {expr1} is a |List| or |Dictionary|, replace each
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006651 item in {expr1} with the result of evaluating {expr2}.
6652 For a |Blob| each byte is replaced.
6653 For a |String|, each character, including composing
6654 characters, is replaced.
6655 If the item type changes you may want to use |mapnew()| to
6656 create a new List or Dictionary. This is required when using
6657 Vim9 script.
6658
6659 {expr2} must be a |String| or |Funcref|.
6660
6661 If {expr2} is a |String|, inside {expr2} |v:val| has the value
6662 of the current item. For a |Dictionary| |v:key| has the key
6663 of the current item and for a |List| |v:key| has the index of
6664 the current item. For a |Blob| |v:key| has the index of the
6665 current byte. For a |String| |v:key| has the index of the
6666 current character.
6667 Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00006668 :call map(mylist, '"> " .. v:val .. " <"')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006669< This puts "> " before and " <" after each item in "mylist".
6670
6671 Note that {expr2} is the result of an expression and is then
6672 used as an expression again. Often it is good to use a
6673 |literal-string| to avoid having to double backslashes. You
6674 still have to double ' quotes
6675
6676 If {expr2} is a |Funcref| it is called with two arguments:
6677 1. The key or the index of the current item.
6678 2. the value of the current item.
Bram Moolenaarb59ae592022-11-23 23:46:31 +00006679 With a legacy script lambda you don't get an error if it only
6680 accepts one argument, but with a Vim9 lambda you get "E1106:
6681 One argument too many", the number of arguments must match.
6682
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006683 The function must return the new value of the item. Example
6684 that changes each value by "key-value": >
6685 func KeyValue(key, val)
Bram Moolenaarc51cf032022-02-26 12:25:45 +00006686 return a:key .. '-' .. a:val
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006687 endfunc
6688 call map(myDict, function('KeyValue'))
6689< It is shorter when using a |lambda|: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00006690 call map(myDict, {key, val -> key .. '-' .. val})
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006691< If you do not use "val" you can leave it out: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00006692 call map(myDict, {key -> 'item: ' .. key})
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006693< If you do not use "key" you can use a short name: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00006694 call map(myDict, {_, val -> 'item: ' .. val})
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006695<
6696 The operation is done in-place for a |List| and |Dictionary|.
6697 If you want it to remain unmodified make a copy first: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00006698 :let tlist = map(copy(mylist), ' v:val .. "\t"')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006699
6700< Returns {expr1}, the |List| or |Dictionary| that was filtered,
6701 or a new |Blob| or |String|.
6702 When an error is encountered while evaluating {expr2} no
6703 further items in {expr1} are processed.
6704 When {expr2} is a Funcref errors inside a function are ignored,
6705 unless it was defined with the "abort" flag.
6706
6707 Can also be used as a |method|: >
6708 mylist->map(expr2)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006709<
6710 Return type: |String|, |Blob|, list<{type}> or dict<{type}>
6711 depending on {expr1}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006712
6713
6714maparg({name} [, {mode} [, {abbr} [, {dict}]]]) *maparg()*
6715 When {dict} is omitted or zero: Return the rhs of mapping
6716 {name} in mode {mode}. The returned String has special
6717 characters translated like in the output of the ":map" command
Ernie Rael09661202022-04-25 14:40:44 +01006718 listing. When {dict} is TRUE a dictionary is returned, see
6719 below. To get a list of all mappings see |maplist()|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006720
6721 When there is no mapping for {name}, an empty String is
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01006722 returned if {dict} is FALSE, otherwise returns an empty Dict.
6723 When the mapping for {name} is empty, then "<Nop>" is
6724 returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006725
6726 The {name} can have special key names, like in the ":map"
6727 command.
6728
6729 {mode} can be one of these strings:
6730 "n" Normal
6731 "v" Visual (including Select)
6732 "o" Operator-pending
6733 "i" Insert
6734 "c" Cmd-line
6735 "s" Select
6736 "x" Visual
6737 "l" langmap |language-mapping|
6738 "t" Terminal-Job
6739 "" Normal, Visual and Operator-pending
6740 When {mode} is omitted, the modes for "" are used.
6741
6742 When {abbr} is there and it is |TRUE| use abbreviations
6743 instead of mappings.
6744
6745 When {dict} is there and it is |TRUE| return a dictionary
6746 containing all the information of the mapping with the
Ernie Rael659c2402022-04-24 18:40:28 +01006747 following items: *mapping-dict*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006748 "lhs" The {lhs} of the mapping as it would be typed
6749 "lhsraw" The {lhs} of the mapping as raw bytes
6750 "lhsrawalt" The {lhs} of the mapping as raw bytes, alternate
6751 form, only present when it differs from "lhsraw"
6752 "rhs" The {rhs} of the mapping as typed.
6753 "silent" 1 for a |:map-silent| mapping, else 0.
6754 "noremap" 1 if the {rhs} of the mapping is not remappable.
6755 "script" 1 if mapping was defined with <script>.
6756 "expr" 1 for an expression mapping (|:map-<expr>|).
6757 "buffer" 1 for a buffer local mapping (|:map-local|).
6758 "mode" Modes for which the mapping is defined. In
6759 addition to the modes mentioned above, these
6760 characters will be used:
6761 " " Normal, Visual and Operator-pending
6762 "!" Insert and Commandline mode
6763 (|mapmode-ic|)
6764 "sid" The script local ID, used for <sid> mappings
Bram Moolenaar71badf92023-04-22 22:40:14 +01006765 (|<SID>|). Negative for special contexts.
Bram Moolenaara9528b32022-01-18 20:51:35 +00006766 "scriptversion" The version of the script. 999999 for
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01006767 |Vim9| script.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006768 "lnum" The line number in "sid", zero if unknown.
6769 "nowait" Do not wait for other, longer mappings.
6770 (|:map-<nowait>|).
Bram Moolenaar921bde82022-05-09 19:50:35 +01006771 "abbr" True if this is an abbreviation |abbreviations|.
Ernie Raeld8f5f762022-05-10 17:50:39 +01006772 "mode_bits" Vim's internal binary representation of "mode".
6773 |mapset()| ignores this; only "mode" is used.
6774 See |maplist()| for usage examples. The values
6775 are from src/vim.h and may change in the future.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006776
6777 The dictionary can be used to restore a mapping with
6778 |mapset()|.
6779
6780 The mappings local to the current buffer are checked first,
6781 then the global mappings.
6782 This function can be used to map a key even when it's already
6783 mapped, and have it do the original mapping too. Sketch: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00006784 exe 'nnoremap <Tab> ==' .. maparg('<Tab>', 'n')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006785
6786< Can also be used as a |method|: >
6787 GetKey()->maparg('n')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006788<
6789 Return type: |String| or dict<any> depending on {dict}
6790
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006791
6792mapcheck({name} [, {mode} [, {abbr}]]) *mapcheck()*
6793 Check if there is a mapping that matches with {name} in mode
6794 {mode}. See |maparg()| for {mode} and special names in
6795 {name}.
6796 When {abbr} is there and it is |TRUE| use abbreviations
6797 instead of mappings.
6798 A match happens with a mapping that starts with {name} and
6799 with a mapping which is equal to the start of {name}.
6800
6801 matches mapping "a" "ab" "abc" ~
6802 mapcheck("a") yes yes yes
6803 mapcheck("abc") yes yes yes
6804 mapcheck("ax") yes no no
6805 mapcheck("b") no no no
6806
6807 The difference with maparg() is that mapcheck() finds a
6808 mapping that matches with {name}, while maparg() only finds a
6809 mapping for {name} exactly.
6810 When there is no mapping that starts with {name}, an empty
6811 String is returned. If there is one, the RHS of that mapping
6812 is returned. If there are several mappings that start with
6813 {name}, the RHS of one of them is returned. This will be
6814 "<Nop>" if the RHS is empty.
6815 The mappings local to the current buffer are checked first,
6816 then the global mappings.
6817 This function can be used to check if a mapping can be added
6818 without being ambiguous. Example: >
6819 :if mapcheck("_vv") == ""
6820 : map _vv :set guifont=7x13<CR>
6821 :endif
6822< This avoids adding the "_vv" mapping when there already is a
6823 mapping for "_v" or for "_vvv".
6824
6825 Can also be used as a |method|: >
6826 GetKey()->mapcheck('n')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006827<
6828 Return type: |String|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006829
6830
Ernie Rael09661202022-04-25 14:40:44 +01006831maplist([{abbr}]) *maplist()*
6832 Returns a |List| of all mappings. Each List item is a |Dict|,
6833 the same as what is returned by |maparg()|, see
6834 |mapping-dict|. When {abbr} is there and it is |TRUE| use
6835 abbreviations instead of mappings.
6836
6837 Example to show all mappings with 'MultiMatch' in rhs: >
6838 vim9script
6839 echo maplist()->filter(
6840 (_, m) => match(m.rhs, 'MultiMatch') >= 0)
Ernie Raeld8f5f762022-05-10 17:50:39 +01006841< It can be tricky to find mappings for particular |:map-modes|.
6842 |mapping-dict|'s "mode_bits" can simplify this. For example,
6843 the mode_bits for Normal, Insert or Command-line modes are
6844 0x19. To find all the mappings available in those modes you
6845 can do: >
6846 vim9script
6847 var saved_maps = []
6848 for m in maplist()
6849 if and(m.mode_bits, 0x19) != 0
6850 saved_maps->add(m)
6851 endif
6852 endfor
6853 echo saved_maps->mapnew((_, m) => m.lhs)
6854< The values of the mode_bits are defined in Vim's src/vim.h
6855 file and they can be discovered at runtime using
6856 |:map-commands| and "maplist()". Example: >
6857 vim9script
6858 omap xyzzy <Nop>
6859 var op_bit = maplist()->filter(
6860 (_, m) => m.lhs == 'xyzzy')[0].mode_bits
6861 ounmap xyzzy
6862 echo printf("Operator-pending mode bit: 0x%x", op_bit)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006863<
6864 Return type: list<dict<any>>
Ernie Rael09661202022-04-25 14:40:44 +01006865
6866
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006867mapnew({expr1}, {expr2}) *mapnew()*
6868 Like |map()| but instead of replacing items in {expr1} a new
6869 List or Dictionary is created and returned. {expr1} remains
6870 unchanged. Items can still be changed by {expr2}, if you
6871 don't want that use |deepcopy()| first.
6872
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006873 Return type: |String|, |Blob|, list<{type}> or dict<{type}>
6874 depending on {expr1}
6875
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006876
6877mapset({mode}, {abbr}, {dict}) *mapset()*
Ernie Rael51d04d12022-05-04 15:40:22 +01006878mapset({dict})
6879 Restore a mapping from a dictionary, possibly returned by
6880 |maparg()| or |maplist()|. A buffer mapping, when dict.buffer
6881 is true, is set on the current buffer; it is up to the caller
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01006882 to ensure that the intended buffer is the current buffer. This
Ernie Rael51d04d12022-05-04 15:40:22 +01006883 feature allows copying mappings from one buffer to another.
6884 The dict.mode value may restore a single mapping that covers
6885 more than one mode, like with mode values of '!', ' ', 'nox',
6886 or 'v'. *E1276*
6887
6888 In the first form, {mode} and {abbr} should be the same as
6889 for the call to |maparg()|. *E460*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006890 {mode} is used to define the mode in which the mapping is set,
6891 not the "mode" entry in {dict}.
6892 Example for saving and restoring a mapping: >
6893 let save_map = maparg('K', 'n', 0, 1)
6894 nnoremap K somethingelse
6895 ...
6896 call mapset('n', 0, save_map)
6897< Note that if you are going to replace a map in several modes,
Ernie Rael51d04d12022-05-04 15:40:22 +01006898 e.g. with `:map!`, you need to save/restore the mapping for
6899 all of them, when they might differ.
6900
6901 In the second form, with {dict} as the only argument, mode
6902 and abbr are taken from the dict.
6903 Example: >
6904 vim9script
6905 var save_maps = maplist()->filter(
6906 (_, m) => m.lhs == 'K')
6907 nnoremap K somethingelse
6908 cnoremap K somethingelse2
6909 # ...
6910 unmap K
6911 for d in save_maps
6912 mapset(d)
6913 endfor
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006914<
6915 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006916
6917
6918match({expr}, {pat} [, {start} [, {count}]]) *match()*
6919 When {expr} is a |List| then this returns the index of the
6920 first item where {pat} matches. Each item is used as a
6921 String, |Lists| and |Dictionaries| are used as echoed.
6922
6923 Otherwise, {expr} is used as a String. The result is a
6924 Number, which gives the index (byte offset) in {expr} where
6925 {pat} matches.
6926
6927 A match at the first character or |List| item returns zero.
6928 If there is no match -1 is returned.
6929
6930 For getting submatches see |matchlist()|.
6931 Example: >
6932 :echo match("testing", "ing") " results in 4
6933 :echo match([1, 'x'], '\a') " results in 1
6934< See |string-match| for how {pat} is used.
6935 *strpbrk()*
6936 Vim doesn't have a strpbrk() function. But you can do: >
6937 :let sepidx = match(line, '[.,;: \t]')
6938< *strcasestr()*
6939 Vim doesn't have a strcasestr() function. But you can add
6940 "\c" to the pattern to ignore case: >
6941 :let idx = match(haystack, '\cneedle')
6942<
6943 If {start} is given, the search starts from byte index
6944 {start} in a String or item {start} in a |List|.
6945 The result, however, is still the index counted from the
6946 first character/item. Example: >
6947 :echo match("testing", "ing", 2)
6948< result is again "4". >
6949 :echo match("testing", "ing", 4)
6950< result is again "4". >
6951 :echo match("testing", "t", 2)
6952< result is "3".
6953 For a String, if {start} > 0 then it is like the string starts
6954 {start} bytes later, thus "^" will match at {start}. Except
6955 when {count} is given, then it's like matches before the
6956 {start} byte are ignored (this is a bit complicated to keep it
6957 backwards compatible).
6958 For a String, if {start} < 0, it will be set to 0. For a list
6959 the index is counted from the end.
6960 If {start} is out of range ({start} > strlen({expr}) for a
6961 String or {start} > len({expr}) for a |List|) -1 is returned.
6962
6963 When {count} is given use the {count}'th match. When a match
6964 is found in a String the search for the next one starts one
6965 character further. Thus this example results in 1: >
6966 echo match("testing", "..", 0, 2)
6967< In a |List| the search continues in the next item.
6968 Note that when {count} is added the way {start} works changes,
6969 see above.
6970
Yegappan Lakshmanana35235e2024-02-24 10:09:43 +01006971 *match-pattern*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006972 See |pattern| for the patterns that are accepted.
6973 The 'ignorecase' option is used to set the ignore-caseness of
6974 the pattern. 'smartcase' is NOT used. The matching is always
6975 done like 'magic' is set and 'cpoptions' is empty.
6976 Note that a match at the start is preferred, thus when the
6977 pattern is using "*" (any number of matches) it tends to find
6978 zero matches at the start instead of a number of matches
6979 further down in the text.
6980
6981 Can also be used as a |method|: >
6982 GetText()->match('word')
6983 GetList()->match('word')
6984<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006985 Return type: |Number|
6986
6987
Bram Moolenaar2f0936c2022-01-08 21:51:59 +00006988 *matchadd()* *E290* *E798* *E799* *E801* *E957*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006989matchadd({group}, {pattern} [, {priority} [, {id} [, {dict}]]])
6990 Defines a pattern to be highlighted in the current window (a
6991 "match"). It will be highlighted with {group}. Returns an
6992 identification number (ID), which can be used to delete the
6993 match using |matchdelete()|. The ID is bound to the window.
6994 Matching is case sensitive and magic, unless case sensitivity
6995 or magicness are explicitly overridden in {pattern}. The
6996 'magic', 'smartcase' and 'ignorecase' options are not used.
6997 The "Conceal" value is special, it causes the match to be
6998 concealed.
6999
7000 The optional {priority} argument assigns a priority to the
7001 match. A match with a high priority will have its
7002 highlighting overrule that of a match with a lower priority.
7003 A priority is specified as an integer (negative numbers are no
7004 exception). If the {priority} argument is not specified, the
7005 default priority is 10. The priority of 'hlsearch' is zero,
7006 hence all matches with a priority greater than zero will
7007 overrule it. Syntax highlighting (see 'syntax') is a separate
7008 mechanism, and regardless of the chosen priority a match will
7009 always overrule syntax highlighting.
7010
7011 The optional {id} argument allows the request for a specific
7012 match ID. If a specified ID is already taken, an error
7013 message will appear and the match will not be added. An ID
7014 is specified as a positive integer (zero excluded). IDs 1, 2
7015 and 3 are reserved for |:match|, |:2match| and |:3match|,
Bram Moolenaar2ecbe532022-07-29 21:36:21 +01007016 respectively. 3 is reserved for use by the |matchparen|
7017 plugin.
Bram Moolenaarb529cfb2022-07-25 15:42:07 +01007018 If the {id} argument is not specified or -1, |matchadd()|
Bram Moolenaar9f573a82022-09-29 13:50:08 +01007019 automatically chooses a free ID, which is at least 1000.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007020
7021 The optional {dict} argument allows for further custom
7022 values. Currently this is used to specify a match specific
7023 conceal character that will be shown for |hl-Conceal|
7024 highlighted matches. The dict can have the following members:
7025
7026 conceal Special character to show instead of the
7027 match (only for |hl-Conceal| highlighted
7028 matches, see |:syn-cchar|)
7029 window Instead of the current window use the
7030 window with this number or window ID.
7031
7032 The number of matches is not limited, as it is the case with
7033 the |:match| commands.
7034
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01007035 Returns -1 on error.
7036
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007037 Example: >
7038 :highlight MyGroup ctermbg=green guibg=green
7039 :let m = matchadd("MyGroup", "TODO")
7040< Deletion of the pattern: >
7041 :call matchdelete(m)
7042
7043< A list of matches defined by |matchadd()| and |:match| are
7044 available from |getmatches()|. All matches can be deleted in
7045 one operation by |clearmatches()|.
7046
7047 Can also be used as a |method|: >
7048 GetGroup()->matchadd('TODO')
7049<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007050 Return type: |Number|
7051
7052
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007053 *matchaddpos()*
7054matchaddpos({group}, {pos} [, {priority} [, {id} [, {dict}]]])
7055 Same as |matchadd()|, but requires a list of positions {pos}
7056 instead of a pattern. This command is faster than |matchadd()|
Shane Harperc1b39842024-07-17 19:40:40 +02007057 because it does not handle regular expressions and it sets
7058 buffer line boundaries to redraw screen. It is supposed to be
7059 used when fast match additions and deletions are required, for
7060 example to highlight matching parentheses.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007061
7062 {pos} is a list of positions. Each position can be one of
7063 these:
7064 - A number. This whole line will be highlighted. The first
7065 line has number 1.
7066 - A list with one number, e.g., [23]. The whole line with this
7067 number will be highlighted.
7068 - A list with two numbers, e.g., [23, 11]. The first number is
7069 the line number, the second one is the column number (first
7070 column is 1, the value must correspond to the byte index as
7071 |col()| would return). The character at this position will
7072 be highlighted.
7073 - A list with three numbers, e.g., [23, 11, 3]. As above, but
7074 the third number gives the length of the highlight in bytes.
7075
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01007076 Returns -1 on error.
7077
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007078 Example: >
7079 :highlight MyGroup ctermbg=green guibg=green
7080 :let m = matchaddpos("MyGroup", [[23, 24], 34])
7081< Deletion of the pattern: >
7082 :call matchdelete(m)
7083
7084< Matches added by |matchaddpos()| are returned by
7085 |getmatches()|.
7086
7087 Can also be used as a |method|: >
7088 GetGroup()->matchaddpos([23, 11])
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007089<
7090 Return type: |Number|
7091
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007092
7093matcharg({nr}) *matcharg()*
7094 Selects the {nr} match item, as set with a |:match|,
7095 |:2match| or |:3match| command.
7096 Return a |List| with two elements:
7097 The name of the highlight group used
7098 The pattern used.
7099 When {nr} is not 1, 2 or 3 returns an empty |List|.
7100 When there is no match item set returns ['', ''].
7101 This is useful to save and restore a |:match|.
7102 Highlighting matches using the |:match| commands are limited
7103 to three matches. |matchadd()| does not have this limitation.
7104
7105 Can also be used as a |method|: >
7106 GetMatch()->matcharg()
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +01007107<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007108 Return type: list<string>
7109
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +01007110 *matchbufline()*
7111matchbufline({buf}, {pat}, {lnum}, {end}, [, {dict}])
7112 Returns the |List| of matches in lines from {lnum} to {end} in
7113 buffer {buf} where {pat} matches.
7114
7115 {lnum} and {end} can either be a line number or the string "$"
7116 to refer to the last line in {buf}.
7117
7118 The {dict} argument supports following items:
7119 submatches include submatch information (|/\(|)
7120
7121 For each match, a |Dict| with the following items is returned:
7122 byteidx starting byte index of the match
Yegappan Lakshmananeb3475d2024-01-15 11:08:25 -08007123 lnum line number where there is a match
7124 text matched string
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +01007125 Note that there can be multiple matches in a single line.
7126
7127 This function works only for loaded buffers. First call
7128 |bufload()| if needed.
7129
Yegappan Lakshmanana35235e2024-02-24 10:09:43 +01007130 See |match-pattern| for information about the effect of some
7131 option settings on the pattern.
7132
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +01007133 When {buf} is not a valid buffer, the buffer is not loaded or
7134 {lnum} or {end} is not valid then an error is given and an
7135 empty |List| is returned.
7136
7137 Examples: >
Yegappan Lakshmananeb3475d2024-01-15 11:08:25 -08007138 " Assuming line 3 in buffer 5 contains "a"
7139 :echo matchbufline(5, '\<\k\+\>', 3, 3)
7140 [{'lnum': 3, 'byteidx': 0, 'text': 'a'}]
7141 " Assuming line 4 in buffer 10 contains "tik tok"
7142 :echo matchbufline(10, '\<\k\+\>', 1, 4)
7143 [{'lnum': 4, 'byteidx': 0, 'text': 'tik'}, {'lnum': 4, 'byteidx': 4, 'text': 'tok'}]
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +01007144<
7145 If {submatch} is present and is v:true, then submatches like
Yegappan Lakshmananeb3475d2024-01-15 11:08:25 -08007146 "\1", "\2", etc. are also returned. Example: >
7147 " Assuming line 2 in buffer 2 contains "acd"
7148 :echo matchbufline(2, '\(a\)\?\(b\)\?\(c\)\?\(.*\)', 2, 2
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +01007149 \ {'submatches': v:true})
Yegappan Lakshmananeb3475d2024-01-15 11:08:25 -08007150 [{'lnum': 2, 'byteidx': 0, 'text': 'acd', 'submatches': ['a', '', 'c', 'd', '', '', '', '', '']}]
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +01007151< The "submatches" List always contains 9 items. If a submatch
7152 is not found, then an empty string is returned for that
7153 submatch.
7154
7155 Can also be used as a |method|: >
7156 GetBuffer()->matchbufline('mypat', 1, '$')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007157<
7158 Return type: list<dict<any>> or list<any>
7159
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007160
h-east624bb832024-11-09 18:37:32 +01007161matchdelete({id} [, {win}) *matchdelete()* *E802* *E803*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007162 Deletes a match with ID {id} previously defined by |matchadd()|
7163 or one of the |:match| commands. Returns 0 if successful,
7164 otherwise -1. See example for |matchadd()|. All matches can
7165 be deleted in one operation by |clearmatches()|.
7166 If {win} is specified, use the window with this number or
7167 window ID instead of the current window.
7168
7169 Can also be used as a |method|: >
7170 GetMatch()->matchdelete()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007171<
7172 Return type: |Number|
7173
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007174
7175matchend({expr}, {pat} [, {start} [, {count}]]) *matchend()*
7176 Same as |match()|, but return the index of first character
7177 after the match. Example: >
7178 :echo matchend("testing", "ing")
7179< results in "7".
7180 *strspn()* *strcspn()*
7181 Vim doesn't have a strspn() or strcspn() function, but you can
7182 do it with matchend(): >
7183 :let span = matchend(line, '[a-zA-Z]')
7184 :let span = matchend(line, '[^a-zA-Z]')
7185< Except that -1 is returned when there are no matches.
7186
7187 The {start}, if given, has the same meaning as for |match()|. >
7188 :echo matchend("testing", "ing", 2)
7189< results in "7". >
7190 :echo matchend("testing", "ing", 5)
7191< result is "-1".
7192 When {expr} is a |List| the result is equal to |match()|.
7193
7194 Can also be used as a |method|: >
7195 GetText()->matchend('word')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007196<
7197 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007198
7199
7200matchfuzzy({list}, {str} [, {dict}]) *matchfuzzy()*
7201 If {list} is a list of strings, then returns a |List| with all
7202 the strings in {list} that fuzzy match {str}. The strings in
7203 the returned list are sorted based on the matching score.
7204
7205 The optional {dict} argument always supports the following
7206 items:
zeertzjq9af2bc02022-05-11 14:15:37 +01007207 matchseq When this item is present return only matches
7208 that contain the characters in {str} in the
7209 given sequence.
Kazuyuki Miyagi47f1a552022-06-17 18:30:03 +01007210 limit Maximum number of matches in {list} to be
7211 returned. Zero means no limit.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007212
7213 If {list} is a list of dictionaries, then the optional {dict}
7214 argument supports the following additional items:
Yasuhiro Matsumoto9029a6e2022-04-16 12:35:35 +01007215 key Key of the item which is fuzzy matched against
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007216 {str}. The value of this item should be a
7217 string.
7218 text_cb |Funcref| that will be called for every item
7219 in {list} to get the text for fuzzy matching.
7220 This should accept a dictionary item as the
7221 argument and return the text for that item to
7222 use for fuzzy matching.
7223
7224 {str} is treated as a literal string and regular expression
7225 matching is NOT supported. The maximum supported {str} length
7226 is 256.
7227
7228 When {str} has multiple words each separated by white space,
7229 then the list of strings that have all the words is returned.
7230
7231 If there are no matching strings or there is an error, then an
7232 empty list is returned. If length of {str} is greater than
7233 256, then returns an empty list.
7234
Yasuhiro Matsumoto9029a6e2022-04-16 12:35:35 +01007235 When {limit} is given, matchfuzzy() will find up to this
7236 number of matches in {list} and return them in sorted order.
7237
Bram Moolenaar1588bc82022-03-08 21:35:07 +00007238 Refer to |fuzzy-matching| for more information about fuzzy
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007239 matching strings.
7240
7241 Example: >
7242 :echo matchfuzzy(["clay", "crow"], "cay")
7243< results in ["clay"]. >
7244 :echo getbufinfo()->map({_, v -> v.name})->matchfuzzy("ndl")
7245< results in a list of buffer names fuzzy matching "ndl". >
7246 :echo getbufinfo()->matchfuzzy("ndl", {'key' : 'name'})
7247< results in a list of buffer information dicts with buffer
7248 names fuzzy matching "ndl". >
7249 :echo getbufinfo()->matchfuzzy("spl",
7250 \ {'text_cb' : {v -> v.name}})
7251< results in a list of buffer information dicts with buffer
7252 names fuzzy matching "spl". >
7253 :echo v:oldfiles->matchfuzzy("test")
7254< results in a list of file names fuzzy matching "test". >
7255 :let l = readfile("buffer.c")->matchfuzzy("str")
7256< results in a list of lines in "buffer.c" fuzzy matching "str". >
7257 :echo ['one two', 'two one']->matchfuzzy('two one')
7258< results in ['two one', 'one two']. >
7259 :echo ['one two', 'two one']->matchfuzzy('two one',
7260 \ {'matchseq': 1})
7261< results in ['two one'].
7262
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007263 Return type: list<string> or list<any>
7264
7265
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007266matchfuzzypos({list}, {str} [, {dict}]) *matchfuzzypos()*
7267 Same as |matchfuzzy()|, but returns the list of matched
7268 strings, the list of character positions where characters
7269 in {str} matches and a list of matching scores. You can
7270 use |byteidx()| to convert a character position to a byte
7271 position.
7272
7273 If {str} matches multiple times in a string, then only the
7274 positions for the best match is returned.
7275
7276 If there are no matching strings or there is an error, then a
7277 list with three empty list items is returned.
7278
7279 Example: >
7280 :echo matchfuzzypos(['testing'], 'tsg')
7281< results in [['testing'], [[0, 2, 6]], [99]] >
7282 :echo matchfuzzypos(['clay', 'lacy'], 'la')
7283< results in [['lacy', 'clay'], [[0, 1], [1, 2]], [153, 133]] >
7284 :echo [{'text': 'hello', 'id' : 10}]->matchfuzzypos('ll', {'key' : 'text'})
7285< results in [[{'id': 10, 'text': 'hello'}], [[2, 3]], [127]]
7286
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007287 Return type: list<list<any>>
7288
7289
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007290matchlist({expr}, {pat} [, {start} [, {count}]]) *matchlist()*
7291 Same as |match()|, but return a |List|. The first item in the
7292 list is the matched string, same as what matchstr() would
7293 return. Following items are submatches, like "\1", "\2", etc.
7294 in |:substitute|. When an optional submatch didn't match an
7295 empty string is used. Example: >
7296 echo matchlist('acd', '\(a\)\?\(b\)\?\(c\)\?\(.*\)')
7297< Results in: ['acd', 'a', '', 'c', 'd', '', '', '', '', '']
7298 When there is no match an empty list is returned.
7299
7300 You can pass in a List, but that is not very useful.
7301
7302 Can also be used as a |method|: >
7303 GetText()->matchlist('word')
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +01007304<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007305 Return type: list<string> or list<any>
7306
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +01007307 *matchstrlist()*
7308matchstrlist({list}, {pat} [, {dict}])
7309 Returns the |List| of matches in {list} where {pat} matches.
7310 {list} is a |List| of strings. {pat} is matched against each
7311 string in {list}.
7312
7313 The {dict} argument supports following items:
7314 submatches include submatch information (|/\(|)
7315
7316 For each match, a |Dict| with the following items is returned:
7317 byteidx starting byte index of the match.
7318 idx index in {list} of the match.
7319 text matched string
7320 submatches a List of submatches. Present only if
7321 "submatches" is set to v:true in {dict}.
7322
Yegappan Lakshmanana35235e2024-02-24 10:09:43 +01007323 See |match-pattern| for information about the effect of some
7324 option settings on the pattern.
7325
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +01007326 Example: >
Yegappan Lakshmananeb3475d2024-01-15 11:08:25 -08007327 :echo matchstrlist(['tik tok'], '\<\k\+\>')
7328 [{'idx': 0, 'byteidx': 0, 'text': 'tik'}, {'idx': 0, 'byteidx': 4, 'text': 'tok'}]
7329 :echo matchstrlist(['a', 'b'], '\<\k\+\>')
7330 [{'idx': 0, 'byteidx': 0, 'text': 'a'}, {'idx': 1, 'byteidx': 0, 'text': 'b'}]
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +01007331<
7332 If "submatches" is present and is v:true, then submatches like
7333 "\1", "\2", etc. are also returned. Example: >
7334 :echo matchstrlist(['acd'], '\(a\)\?\(b\)\?\(c\)\?\(.*\)',
7335 \ #{submatches: v:true})
7336 [{'idx': 0, 'byteidx': 0, 'text': 'acd', 'submatches': ['a', '', 'c', 'd', '', '', '', '', '']}]
7337< The "submatches" List always contains 9 items. If a submatch
7338 is not found, then an empty string is returned for that
7339 submatch.
7340
7341 Can also be used as a |method|: >
7342 GetListOfStrings()->matchstrlist('mypat')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007343<
7344 Return type: list<dict<any>> or list<any>
7345
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007346
7347matchstr({expr}, {pat} [, {start} [, {count}]]) *matchstr()*
7348 Same as |match()|, but return the matched string. Example: >
7349 :echo matchstr("testing", "ing")
7350< results in "ing".
7351 When there is no match "" is returned.
7352 The {start}, if given, has the same meaning as for |match()|. >
7353 :echo matchstr("testing", "ing", 2)
7354< results in "ing". >
7355 :echo matchstr("testing", "ing", 5)
7356< result is "".
7357 When {expr} is a |List| then the matching item is returned.
7358 The type isn't changed, it's not necessarily a String.
7359
7360 Can also be used as a |method|: >
7361 GetText()->matchstr('word')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007362<
7363 Return type: |String|
7364
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007365
7366matchstrpos({expr}, {pat} [, {start} [, {count}]]) *matchstrpos()*
7367 Same as |matchstr()|, but return the matched string, the start
7368 position and the end position of the match. Example: >
7369 :echo matchstrpos("testing", "ing")
7370< results in ["ing", 4, 7].
7371 When there is no match ["", -1, -1] is returned.
7372 The {start}, if given, has the same meaning as for |match()|. >
7373 :echo matchstrpos("testing", "ing", 2)
7374< results in ["ing", 4, 7]. >
7375 :echo matchstrpos("testing", "ing", 5)
7376< result is ["", -1, -1].
7377 When {expr} is a |List| then the matching item, the index
7378 of first item where {pat} matches, the start position and the
7379 end position of the match are returned. >
7380 :echo matchstrpos([1, '__x'], '\a')
7381< result is ["x", 1, 2, 3].
7382 The type isn't changed, it's not necessarily a String.
7383
7384 Can also be used as a |method|: >
7385 GetText()->matchstrpos('word')
7386<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007387 Return type: list<any>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007388
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007389
7390max({expr}) *max()*
7391 Return the maximum value of all items in {expr}. Example: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007392 echo max([apples, pears, oranges])
7393
7394< {expr} can be a |List| or a |Dictionary|. For a Dictionary,
7395 it returns the maximum of all values in the Dictionary.
7396 If {expr} is neither a List nor a Dictionary, or one of the
7397 items in {expr} cannot be used as a Number this results in
7398 an error. An empty |List| or |Dictionary| results in zero.
7399
7400 Can also be used as a |method|: >
7401 mylist->max()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007402<
7403 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007404
7405
7406menu_info({name} [, {mode}]) *menu_info()*
7407 Return information about the specified menu {name} in
7408 mode {mode}. The menu name should be specified without the
7409 shortcut character ('&'). If {name} is "", then the top-level
7410 menu names are returned.
7411
7412 {mode} can be one of these strings:
7413 "n" Normal
7414 "v" Visual (including Select)
7415 "o" Operator-pending
7416 "i" Insert
7417 "c" Cmd-line
7418 "s" Select
7419 "x" Visual
7420 "t" Terminal-Job
7421 "" Normal, Visual and Operator-pending
7422 "!" Insert and Cmd-line
7423 When {mode} is omitted, the modes for "" are used.
7424
7425 Returns a |Dictionary| containing the following items:
7426 accel menu item accelerator text |menu-text|
7427 display display name (name without '&')
7428 enabled v:true if this menu item is enabled
7429 Refer to |:menu-enable|
7430 icon name of the icon file (for toolbar)
7431 |toolbar-icon|
7432 iconidx index of a built-in icon
7433 modes modes for which the menu is defined. In
7434 addition to the modes mentioned above, these
7435 characters will be used:
7436 " " Normal, Visual and Operator-pending
7437 name menu item name.
7438 noremenu v:true if the {rhs} of the menu item is not
7439 remappable else v:false.
7440 priority menu order priority |menu-priority|
7441 rhs right-hand-side of the menu item. The returned
7442 string has special characters translated like
7443 in the output of the ":menu" command listing.
7444 When the {rhs} of a menu item is empty, then
7445 "<Nop>" is returned.
7446 script v:true if script-local remapping of {rhs} is
7447 allowed else v:false. See |:menu-script|.
7448 shortcut shortcut key (character after '&' in
7449 the menu name) |menu-shortcut|
7450 silent v:true if the menu item is created
7451 with <silent> argument |:menu-silent|
7452 submenus |List| containing the names of
7453 all the submenus. Present only if the menu
7454 item has submenus.
7455
7456 Returns an empty dictionary if the menu item is not found.
7457
7458 Examples: >
7459 :echo menu_info('Edit.Cut')
7460 :echo menu_info('File.Save', 'n')
7461
7462 " Display the entire menu hierarchy in a buffer
7463 func ShowMenu(name, pfx)
7464 let m = menu_info(a:name)
7465 call append(line('$'), a:pfx .. m.display)
7466 for child in m->get('submenus', [])
7467 call ShowMenu(a:name .. '.' .. escape(child, '.'),
7468 \ a:pfx .. ' ')
7469 endfor
7470 endfunc
7471 new
7472 for topmenu in menu_info('').submenus
7473 call ShowMenu(topmenu, '')
7474 endfor
7475<
7476 Can also be used as a |method|: >
7477 GetMenuName()->menu_info('v')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007478<
7479 Return type: dict<any>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007480
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007481min({expr}) *min()*
7482 Return the minimum value of all items in {expr}. Example: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007483 echo min([apples, pears, oranges])
7484
7485< {expr} can be a |List| or a |Dictionary|. For a Dictionary,
7486 it returns the minimum of all values in the Dictionary.
7487 If {expr} is neither a List nor a Dictionary, or one of the
7488 items in {expr} cannot be used as a Number this results in
7489 an error. An empty |List| or |Dictionary| results in zero.
7490
7491 Can also be used as a |method|: >
7492 mylist->min()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007493<
7494 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007495
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007496
7497mkdir({name} [, {flags} [, {prot}]]) *mkdir()* *E739*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007498 Create directory {name}.
7499
Bram Moolenaar938ae282023-02-20 20:44:55 +00007500 When {flags} is present it must be a string. An empty string
7501 has no effect.
Bram Moolenaar6f14da12022-09-07 21:30:44 +01007502
Christian Brabandtd6d4e132024-06-13 21:21:41 +02007503 {flags} can contain these character flags:
7504 "p" intermediate directories will be created as necessary
7505 "D" {name} will be deleted at the end of the current
Christian Brabandtc509c002024-06-14 20:22:05 +02007506 function, but not recursively |:defer|
Christian Brabandtd6d4e132024-06-13 21:21:41 +02007507 "R" {name} will be deleted recursively at the end of the
Christian Brabandtc509c002024-06-14 20:22:05 +02007508 current function |:defer|
Bram Moolenaar938ae282023-02-20 20:44:55 +00007509
Christian Brabandtd6d4e132024-06-13 21:21:41 +02007510 Note that when {name} has more than one part and "p" is used
Bram Moolenaar6f14da12022-09-07 21:30:44 +01007511 some directories may already exist. Only the first one that
7512 is created and what it contains is scheduled to be deleted.
7513 E.g. when using: >
7514 call mkdir('subdir/tmp/autoload', 'pR')
7515< and "subdir" already exists then "subdir/tmp" will be
7516 scheduled for deletion, like with: >
7517 defer delete('subdir/tmp', 'rf')
7518< Note that if scheduling the defer fails the directory is not
7519 deleted. This should only happen when out of memory.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007520
7521 If {prot} is given it is used to set the protection bits of
7522 the new directory. The default is 0o755 (rwxr-xr-x: r/w for
7523 the user, readable for others). Use 0o700 to make it
7524 unreadable for others. This is only used for the last part of
7525 {name}. Thus if you create /tmp/foo/bar then /tmp/foo will be
7526 created with 0o755.
7527 Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00007528 :call mkdir($HOME .. "/tmp/foo/bar", "p", 0o700)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007529
7530< This function is not available in the |sandbox|.
7531
7532 There is no error if the directory already exists and the "p"
7533 flag is passed (since patch 8.0.1708). However, without the
7534 "p" option the call will fail.
7535
7536 The function result is a Number, which is TRUE if the call was
7537 successful or FALSE if the directory creation failed or partly
7538 failed.
7539
7540 Not available on all systems. To check use: >
7541 :if exists("*mkdir")
7542
7543< Can also be used as a |method|: >
7544 GetName()->mkdir()
7545<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007546 Return type: |Number|
7547
7548
7549mode([{expr}]) *mode()*
7550 Return a string that indicates the current mode.
Doug Kearns9cd9e752024-04-07 17:42:17 +02007551 If {expr} is supplied and it evaluates to a non-zero Number or
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007552 a non-empty String (|non-zero-arg|), then the full mode is
7553 returned, otherwise only the first letter is returned.
7554 Also see |state()|.
7555
7556 n Normal
7557 no Operator-pending
7558 nov Operator-pending (forced characterwise |o_v|)
7559 noV Operator-pending (forced linewise |o_V|)
7560 noCTRL-V Operator-pending (forced blockwise |o_CTRL-V|);
7561 CTRL-V is one character
7562 niI Normal using |i_CTRL-O| in |Insert-mode|
7563 niR Normal using |i_CTRL-O| in |Replace-mode|
7564 niV Normal using |i_CTRL-O| in |Virtual-Replace-mode|
7565 nt Terminal-Normal (insert goes to Terminal-Job mode)
7566 v Visual by character
7567 vs Visual by character using |v_CTRL-O| in Select mode
7568 V Visual by line
7569 Vs Visual by line using |v_CTRL-O| in Select mode
7570 CTRL-V Visual blockwise
7571 CTRL-Vs Visual blockwise using |v_CTRL-O| in Select mode
7572 s Select by character
7573 S Select by line
7574 CTRL-S Select blockwise
7575 i Insert
7576 ic Insert mode completion |compl-generic|
7577 ix Insert mode |i_CTRL-X| completion
7578 R Replace |R|
7579 Rc Replace mode completion |compl-generic|
7580 Rx Replace mode |i_CTRL-X| completion
7581 Rv Virtual Replace |gR|
7582 Rvc Virtual Replace mode completion |compl-generic|
7583 Rvx Virtual Replace mode |i_CTRL-X| completion
7584 c Command-line editing
h-east71ebf3b2023-09-03 17:12:55 +02007585 ct Command-line editing via Terminal-Job mode
zeertzjqfcaeb3d2023-11-28 20:46:29 +01007586 cr Command-line editing overstrike mode |c_<Insert>|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007587 cv Vim Ex mode |gQ|
zeertzjqfcaeb3d2023-11-28 20:46:29 +01007588 cvr Vim Ex mode while in overstrike mode |c_<Insert>|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007589 ce Normal Ex mode |Q|
7590 r Hit-enter prompt
7591 rm The -- more -- prompt
7592 r? A |:confirm| query of some sort
7593 ! Shell or external command is executing
7594 t Terminal-Job mode: keys go to the job
7595
7596 This is useful in the 'statusline' option or when used
7597 with |remote_expr()| In most other places it always returns
7598 "c" or "n".
7599 Note that in the future more modes and more specific modes may
7600 be added. It's better not to compare the whole string but only
7601 the leading character(s).
7602 Also see |visualmode()|.
7603
7604 Can also be used as a |method|: >
7605 DoFull()->mode()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007606<
7607 Return type: |String|
7608
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007609
7610mzeval({expr}) *mzeval()*
7611 Evaluate MzScheme expression {expr} and return its result
7612 converted to Vim data structures.
7613 Numbers and strings are returned as they are.
7614 Pairs (including lists and improper lists) and vectors are
7615 returned as Vim |Lists|.
7616 Hash tables are represented as Vim |Dictionary| type with keys
7617 converted to strings.
7618 All other types are converted to string with display function.
7619 Examples: >
7620 :mz (define l (list 1 2 3))
7621 :mz (define h (make-hash)) (hash-set! h "list" l)
7622 :echo mzeval("l")
7623 :echo mzeval("h")
7624<
7625 Note that in a `:def` function local variables are not visible
7626 to {expr}.
7627
7628 Can also be used as a |method|: >
7629 GetExpr()->mzeval()
7630<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007631 Return type: any, depending on {expr}
7632
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007633 {only available when compiled with the |+mzscheme| feature}
7634
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007635
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007636nextnonblank({lnum}) *nextnonblank()*
7637 Return the line number of the first line at or below {lnum}
7638 that is not blank. Example: >
7639 if getline(nextnonblank(1)) =~ "Java"
7640< When {lnum} is invalid or there is no non-blank line at or
7641 below it, zero is returned.
7642 {lnum} is used like with |getline()|.
7643 See also |prevnonblank()|.
7644
7645 Can also be used as a |method|: >
7646 GetLnum()->nextnonblank()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007647<
7648 Return type: |Number|
7649
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007650
7651nr2char({expr} [, {utf8}]) *nr2char()*
7652 Return a string with a single character, which has the number
7653 value {expr}. Examples: >
7654 nr2char(64) returns "@"
7655 nr2char(32) returns " "
7656< When {utf8} is omitted or zero, the current 'encoding' is used.
7657 Example for "utf-8": >
7658 nr2char(300) returns I with bow character
7659< When {utf8} is TRUE, always return UTF-8 characters.
7660 Note that a NUL character in the file is specified with
7661 nr2char(10), because NULs are represented with newline
7662 characters. nr2char(0) is a real NUL and terminates the
7663 string, thus results in an empty string.
7664 To turn a list of character numbers into a string: >
7665 let list = [65, 66, 67]
7666 let str = join(map(list, {_, val -> nr2char(val)}), '')
7667< Result: "ABC"
7668
7669 Can also be used as a |method|: >
7670 GetNumber()->nr2char()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007671<
7672 Return type: |String|
7673
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007674
7675or({expr}, {expr}) *or()*
7676 Bitwise OR on the two arguments. The arguments are converted
7677 to a number. A List, Dict or Float argument causes an error.
Bram Moolenaar5a6ec102022-05-27 21:58:00 +01007678 Also see `and()` and `xor()`.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007679 Example: >
7680 :let bits = or(bits, 0x80)
7681< Can also be used as a |method|: >
7682 :let bits = bits->or(0x80)
7683
Bram Moolenaar5a6ec102022-05-27 21:58:00 +01007684< Rationale: The reason this is a function and not using the "|"
7685 character like many languages, is that Vi has always used "|"
7686 to separate commands. In many places it would not be clear if
7687 "|" is an operator or a command separator.
7688
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007689 Return type: |Number|
7690
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007691
7692pathshorten({path} [, {len}]) *pathshorten()*
7693 Shorten directory names in the path {path} and return the
7694 result. The tail, the file name, is kept as-is. The other
7695 components in the path are reduced to {len} letters in length.
7696 If {len} is omitted or smaller than 1 then 1 is used (single
7697 letters). Leading '~' and '.' characters are kept. Examples: >
7698 :echo pathshorten('~/.vim/autoload/myfile.vim')
7699< ~/.v/a/myfile.vim ~
7700>
7701 :echo pathshorten('~/.vim/autoload/myfile.vim', 2)
7702< ~/.vi/au/myfile.vim ~
7703 It doesn't matter if the path exists or not.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01007704 Returns an empty string on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007705
7706 Can also be used as a |method|: >
7707 GetDirectories()->pathshorten()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007708<
7709 Return type: |String|
7710
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007711
7712perleval({expr}) *perleval()*
7713 Evaluate Perl expression {expr} in scalar context and return
7714 its result converted to Vim data structures. If value can't be
7715 converted, it is returned as a string Perl representation.
7716 Note: If you want an array or hash, {expr} must return a
7717 reference to it.
7718 Example: >
7719 :echo perleval('[1 .. 4]')
7720< [1, 2, 3, 4]
7721
7722 Note that in a `:def` function local variables are not visible
7723 to {expr}.
7724
7725 Can also be used as a |method|: >
7726 GetExpr()->perleval()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007727<
7728 Return type: any, depending on {expr}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007729
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007730 {only available when compiled with the |+perl| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007731
7732
7733popup_ functions are documented here: |popup-functions|
7734
7735
7736pow({x}, {y}) *pow()*
7737 Return the power of {x} to the exponent {y} as a |Float|.
7738 {x} and {y} must evaluate to a |Float| or a |Number|.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01007739 Returns 0.0 if {x} or {y} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007740 Examples: >
7741 :echo pow(3, 3)
7742< 27.0 >
7743 :echo pow(2, 16)
7744< 65536.0 >
7745 :echo pow(32, 0.20)
7746< 2.0
7747
7748 Can also be used as a |method|: >
7749 Compute()->pow(3)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007750<
7751 Return type: |Number|
7752
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007753
7754prevnonblank({lnum}) *prevnonblank()*
7755 Return the line number of the first line at or above {lnum}
7756 that is not blank. Example: >
7757 let ind = indent(prevnonblank(v:lnum - 1))
7758< When {lnum} is invalid or there is no non-blank line at or
7759 above it, zero is returned.
7760 {lnum} is used like with |getline()|.
7761 Also see |nextnonblank()|.
7762
7763 Can also be used as a |method|: >
7764 GetLnum()->prevnonblank()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007765<
7766 Return type: |Number|
7767
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007768
7769printf({fmt}, {expr1} ...) *printf()*
7770 Return a String with {fmt}, where "%" items are replaced by
7771 the formatted form of their respective arguments. Example: >
7772 printf("%4d: E%d %.30s", lnum, errno, msg)
7773< May result in:
7774 " 99: E42 asdfasdfasdfasdfasdfasdfasdfas" ~
7775
7776 When used as a |method| the base is passed as the second
7777 argument: >
7778 Compute()->printf("result: %d")
Bram Moolenaarcbaff5e2022-04-08 17:45:08 +01007779<
7780 You can use `call()` to pass the items as a list.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007781
Bram Moolenaarcbaff5e2022-04-08 17:45:08 +01007782 Often used items are:
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007783 %s string
7784 %6S string right-aligned in 6 display cells
7785 %6s string right-aligned in 6 bytes
7786 %.9s string truncated to 9 bytes
7787 %c single byte
7788 %d decimal number
7789 %5d decimal number padded with spaces to 5 characters
7790 %x hex number
7791 %04x hex number padded with zeros to at least 4 characters
7792 %X hex number using upper case letters
7793 %o octal number
7794 %08b binary number padded with zeros to at least 8 chars
7795 %f floating point number as 12.23, inf, -inf or nan
7796 %F floating point number as 12.23, INF, -INF or NAN
7797 %e floating point number as 1.23e3, inf, -inf or nan
7798 %E floating point number as 1.23E3, INF, -INF or NAN
7799 %g floating point number, as %f or %e depending on value
7800 %G floating point number, as %F or %E depending on value
7801 %% the % character itself
7802
7803 Conversion specifications start with '%' and end with the
7804 conversion type. All other characters are copied unchanged to
7805 the result.
7806
7807 The "%" starts a conversion specification. The following
7808 arguments appear in sequence:
7809
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007810 % [pos-argument] [flags] [field-width] [.precision] type
7811
7812 pos-argument
7813 At most one positional argument specifier. These
7814 take the form {n$}, where n is >= 1.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007815
7816 flags
7817 Zero or more of the following flags:
7818
7819 # The value should be converted to an "alternate
7820 form". For c, d, and s conversions, this option
7821 has no effect. For o conversions, the precision
7822 of the number is increased to force the first
7823 character of the output string to a zero (except
7824 if a zero value is printed with an explicit
7825 precision of zero).
7826 For b and B conversions, a non-zero result has
7827 the string "0b" (or "0B" for B conversions)
7828 prepended to it.
7829 For x and X conversions, a non-zero result has
7830 the string "0x" (or "0X" for X conversions)
7831 prepended to it.
7832
7833 0 (zero) Zero padding. For all conversions the converted
7834 value is padded on the left with zeros rather
7835 than blanks. If a precision is given with a
7836 numeric conversion (d, b, B, o, x, and X), the 0
7837 flag is ignored.
7838
7839 - A negative field width flag; the converted value
7840 is to be left adjusted on the field boundary.
7841 The converted value is padded on the right with
7842 blanks, rather than on the left with blanks or
7843 zeros. A - overrides a 0 if both are given.
7844
7845 ' ' (space) A blank should be left before a positive
7846 number produced by a signed conversion (d).
7847
7848 + A sign must always be placed before a number
7849 produced by a signed conversion. A + overrides
7850 a space if both are used.
7851
7852 field-width
7853 An optional decimal digit string specifying a minimum
7854 field width. If the converted value has fewer bytes
7855 than the field width, it will be padded with spaces on
7856 the left (or right, if the left-adjustment flag has
7857 been given) to fill out the field width. For the S
7858 conversion the count is in cells.
7859
7860 .precision
7861 An optional precision, in the form of a period '.'
7862 followed by an optional digit string. If the digit
7863 string is omitted, the precision is taken as zero.
7864 This gives the minimum number of digits to appear for
7865 d, o, x, and X conversions, the maximum number of
7866 bytes to be printed from a string for s conversions,
7867 or the maximum number of cells to be printed from a
7868 string for S conversions.
7869 For floating point it is the number of digits after
7870 the decimal point.
7871
7872 type
7873 A character that specifies the type of conversion to
7874 be applied, see below.
7875
7876 A field width or precision, or both, may be indicated by an
7877 asterisk '*' instead of a digit string. In this case, a
7878 Number argument supplies the field width or precision. A
7879 negative field width is treated as a left adjustment flag
7880 followed by a positive field width; a negative precision is
7881 treated as though it were missing. Example: >
7882 :echo printf("%d: %.*s", nr, width, line)
7883< This limits the length of the text used from "line" to
7884 "width" bytes.
7885
Dominique Pellé17dca3c2023-12-14 20:36:32 +01007886 If the argument to be formatted is specified using a
7887 positional argument specifier, and a '*' is used to indicate
7888 that a number argument is to be used to specify the width or
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007889 precision, the argument(s) to be used must also be specified
7890 using a {n$} positional argument specifier. See |printf-$|.
7891
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007892 The conversion specifiers and their meanings are:
7893
7894 *printf-d* *printf-b* *printf-B* *printf-o*
7895 *printf-x* *printf-X*
7896 dbBoxX The Number argument is converted to signed decimal
7897 (d), unsigned binary (b and B), unsigned octal (o), or
7898 unsigned hexadecimal (x and X) notation. The letters
7899 "abcdef" are used for x conversions; the letters
7900 "ABCDEF" are used for X conversions.
7901 The precision, if any, gives the minimum number of
7902 digits that must appear; if the converted value
7903 requires fewer digits, it is padded on the left with
7904 zeros.
7905 In no case does a non-existent or small field width
7906 cause truncation of a numeric field; if the result of
7907 a conversion is wider than the field width, the field
7908 is expanded to contain the conversion result.
7909 The 'h' modifier indicates the argument is 16 bits.
Christ van Willegenaa90d4f2023-09-03 17:22:37 +02007910 The 'l' modifier indicates the argument is a long
7911 integer. The size will be 32 bits or 64 bits
7912 depending on your platform.
7913 The "ll" modifier indicates the argument is 64 bits.
7914 The b and B conversion specifiers never take a width
7915 modifier and always assume their argument is a 64 bit
7916 integer.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007917 Generally, these modifiers are not useful. They are
7918 ignored when type is known from the argument.
7919
7920 i alias for d
7921 D alias for ld
7922 U alias for lu
7923 O alias for lo
7924
7925 *printf-c*
7926 c The Number argument is converted to a byte, and the
7927 resulting character is written.
7928
7929 *printf-s*
7930 s The text of the String argument is used. If a
7931 precision is specified, no more bytes than the number
7932 specified are used.
7933 If the argument is not a String type, it is
7934 automatically converted to text with the same format
7935 as ":echo".
7936 *printf-S*
7937 S The text of the String argument is used. If a
7938 precision is specified, no more display cells than the
7939 number specified are used.
7940
7941 *printf-f* *E807*
7942 f F The Float argument is converted into a string of the
7943 form 123.456. The precision specifies the number of
7944 digits after the decimal point. When the precision is
7945 zero the decimal point is omitted. When the precision
7946 is not specified 6 is used. A really big number
7947 (out of range or dividing by zero) results in "inf"
7948 or "-inf" with %f (INF or -INF with %F).
7949 "0.0 / 0.0" results in "nan" with %f (NAN with %F).
7950 Example: >
7951 echo printf("%.2f", 12.115)
7952< 12.12
7953 Note that roundoff depends on the system libraries.
7954 Use |round()| when in doubt.
7955
7956 *printf-e* *printf-E*
7957 e E The Float argument is converted into a string of the
7958 form 1.234e+03 or 1.234E+03 when using 'E'. The
7959 precision specifies the number of digits after the
7960 decimal point, like with 'f'.
7961
7962 *printf-g* *printf-G*
7963 g G The Float argument is converted like with 'f' if the
7964 value is between 0.001 (inclusive) and 10000000.0
7965 (exclusive). Otherwise 'e' is used for 'g' and 'E'
7966 for 'G'. When no precision is specified superfluous
7967 zeroes and '+' signs are removed, except for the zero
7968 immediately after the decimal point. Thus 10000000.0
7969 results in 1.0e7.
7970
7971 *printf-%*
7972 % A '%' is written. No argument is converted. The
7973 complete conversion specification is "%%".
7974
7975 When a Number argument is expected a String argument is also
7976 accepted and automatically converted.
7977 When a Float or String argument is expected a Number argument
7978 is also accepted and automatically converted.
7979 Any other argument type results in an error message.
7980
7981 *E766* *E767*
7982 The number of {exprN} arguments must exactly match the number
7983 of "%" items. If there are not sufficient or too many
7984 arguments an error is given. Up to 18 arguments can be used.
7985
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007986 *printf-$*
7987 In certain languages, error and informative messages are
7988 more readable when the order of words is different from the
Christian Brabandtee17b6f2023-09-09 11:23:50 +02007989 corresponding message in English. To accommodate translations
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007990 having a different word order, positional arguments may be
7991 used to indicate this. For instance: >
7992
h_east596a9f22023-11-21 21:24:23 +09007993 #, c-format
7994 msgid "%s returning %s"
7995 msgstr "waarde %2$s komt terug van %1$s"
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007996<
h_east596a9f22023-11-21 21:24:23 +09007997 In this example, the sentence has its 2 string arguments
7998 reversed in the output. >
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007999
h_east596a9f22023-11-21 21:24:23 +09008000 echo printf(
8001 "In The Netherlands, vim's creator's name is: %1$s %2$s",
8002 "Bram", "Moolenaar")
8003< In The Netherlands, vim's creator's name is: Bram Moolenaar >
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008004
h_east596a9f22023-11-21 21:24:23 +09008005 echo printf(
8006 "In Belgium, vim's creator's name is: %2$s %1$s",
8007 "Bram", "Moolenaar")
8008< In Belgium, vim's creator's name is: Moolenaar Bram
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008009
8010 Width (and precision) can be specified using the '*' specifier.
8011 In this case, you must specify the field width position in the
8012 argument list. >
8013
h_east596a9f22023-11-21 21:24:23 +09008014 echo printf("%1$*2$.*3$d", 1, 2, 3)
8015< 001 >
8016 echo printf("%2$*3$.*1$d", 1, 2, 3)
8017< 2 >
8018 echo printf("%3$*1$.*2$d", 1, 2, 3)
8019< 03 >
8020 echo printf("%1$*2$.*3$g", 1.4142, 2, 3)
8021< 1.414
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008022
8023 You can mix specifying the width and/or precision directly
8024 and via positional arguments: >
8025
h_east596a9f22023-11-21 21:24:23 +09008026 echo printf("%1$4.*2$f", 1.4142135, 6)
8027< 1.414214 >
8028 echo printf("%1$*2$.4f", 1.4142135, 6)
8029< 1.4142 >
8030 echo printf("%1$*2$.*3$f", 1.4142135, 6, 2)
8031< 1.41
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008032
Christ van Willegenc35fc032024-03-14 18:30:41 +01008033 You will get an overflow error |E1510|, when the field-width
8034 or precision will result in a string longer than 6400 chars.
8035
Yegappan Lakshmanan413f8392023-09-28 22:46:37 +02008036 *E1500*
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008037 You cannot mix positional and non-positional arguments: >
h_east596a9f22023-11-21 21:24:23 +09008038 echo printf("%s%1$s", "One", "Two")
8039< E1500: Cannot mix positional and non-positional arguments:
8040 %s%1$s
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008041
Yegappan Lakshmanan413f8392023-09-28 22:46:37 +02008042 *E1501*
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008043 You cannot skip a positional argument in a format string: >
h_east596a9f22023-11-21 21:24:23 +09008044 echo printf("%3$s%1$s", "One", "Two", "Three")
8045< E1501: format argument 2 unused in $-style format:
8046 %3$s%1$s
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008047
Yegappan Lakshmanan413f8392023-09-28 22:46:37 +02008048 *E1502*
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008049 You can re-use a [field-width] (or [precision]) argument: >
h_east596a9f22023-11-21 21:24:23 +09008050 echo printf("%1$d at width %2$d is: %01$*2$d", 1, 2)
8051< 1 at width 2 is: 01
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008052
8053 However, you can't use it as a different type: >
h_east596a9f22023-11-21 21:24:23 +09008054 echo printf("%1$d at width %2$ld is: %01$*2$d", 1, 2)
8055< E1502: Positional argument 2 used as field width reused as
8056 different type: long int/int
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008057
Yegappan Lakshmanan413f8392023-09-28 22:46:37 +02008058 *E1503*
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008059 When a positional argument is used, but not the correct number
8060 or arguments is given, an error is raised: >
h_east596a9f22023-11-21 21:24:23 +09008061 echo printf("%1$d at width %2$d is: %01$*2$.*3$d", 1, 2)
8062< E1503: Positional argument 3 out of bounds: %1$d at width
8063 %2$d is: %01$*2$.*3$d
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008064
8065 Only the first error is reported: >
h_east596a9f22023-11-21 21:24:23 +09008066 echo printf("%01$*2$.*3$d %4$d", 1, 2)
8067< E1503: Positional argument 3 out of bounds: %01$*2$.*3$d
8068 %4$d
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008069
Yegappan Lakshmanan413f8392023-09-28 22:46:37 +02008070 *E1504*
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008071 A positional argument can be used more than once: >
h_east596a9f22023-11-21 21:24:23 +09008072 echo printf("%1$s %2$s %1$s", "One", "Two")
8073< One Two One
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008074
8075 However, you can't use a different type the second time: >
h_east596a9f22023-11-21 21:24:23 +09008076 echo printf("%1$s %2$s %1$d", "One", "Two")
8077< E1504: Positional argument 1 type used inconsistently:
8078 int/string
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008079
Yegappan Lakshmanan413f8392023-09-28 22:46:37 +02008080 *E1505*
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008081 Various other errors that lead to a format string being
8082 wrongly formatted lead to: >
h_east596a9f22023-11-21 21:24:23 +09008083 echo printf("%1$d at width %2$d is: %01$*2$.3$d", 1, 2)
8084< E1505: Invalid format specifier: %1$d at width %2$d is:
8085 %01$*2$.3$d
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008086
Christ van Willegenea746f92023-10-05 20:48:36 +02008087 *E1507*
zeertzjq27e12c72023-10-07 01:34:04 +08008088 This internal error indicates that the logic to parse a
8089 positional format argument ran into a problem that couldn't be
8090 otherwise reported. Please file a bug against Vim if you run
8091 into this, copying the exact format string and parameters that
8092 were used.
Christ van Willegenea746f92023-10-05 20:48:36 +02008093
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008094 Return type: |String|
8095
Christ van Willegenea746f92023-10-05 20:48:36 +02008096
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008097prompt_getprompt({buf}) *prompt_getprompt()*
8098 Returns the effective prompt text for buffer {buf}. {buf} can
8099 be a buffer name or number. See |prompt-buffer|.
8100
8101 If the buffer doesn't exist or isn't a prompt buffer, an empty
8102 string is returned.
8103
8104 Can also be used as a |method|: >
8105 GetBuffer()->prompt_getprompt()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008106<
8107 Return type: |String|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008108
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008109 {only available when compiled with the |+channel| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008110
8111
8112prompt_setcallback({buf}, {expr}) *prompt_setcallback()*
8113 Set prompt callback for buffer {buf} to {expr}. When {expr}
8114 is an empty string the callback is removed. This has only
8115 effect if {buf} has 'buftype' set to "prompt".
8116
8117 The callback is invoked when pressing Enter. The current
8118 buffer will always be the prompt buffer. A new line for a
8119 prompt is added before invoking the callback, thus the prompt
8120 for which the callback was invoked will be in the last but one
8121 line.
8122 If the callback wants to add text to the buffer, it must
8123 insert it above the last line, since that is where the current
8124 prompt is. This can also be done asynchronously.
8125 The callback is invoked with one argument, which is the text
8126 that was entered at the prompt. This can be an empty string
8127 if the user only typed Enter.
8128 Example: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008129 func s:TextEntered(text)
8130 if a:text == 'exit' || a:text == 'quit'
8131 stopinsert
Bram Moolenaarb7398fe2023-05-14 18:50:25 +01008132 " Reset 'modified' to allow the buffer to be closed.
8133 " We assume there is nothing useful to be saved.
8134 set nomodified
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008135 close
8136 else
Bram Moolenaarb7398fe2023-05-14 18:50:25 +01008137 " Do something useful with "a:text". In this example
8138 " we just repeat it.
Bram Moolenaarc51cf032022-02-26 12:25:45 +00008139 call append(line('$') - 1, 'Entered: "' .. a:text .. '"')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008140 endif
8141 endfunc
Bram Moolenaarb7398fe2023-05-14 18:50:25 +01008142 call prompt_setcallback(bufnr(), function('s:TextEntered'))
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008143
8144< Can also be used as a |method|: >
8145 GetBuffer()->prompt_setcallback(callback)
8146
8147< {only available when compiled with the |+channel| feature}
8148
8149prompt_setinterrupt({buf}, {expr}) *prompt_setinterrupt()*
8150 Set a callback for buffer {buf} to {expr}. When {expr} is an
8151 empty string the callback is removed. This has only effect if
8152 {buf} has 'buftype' set to "prompt".
8153
8154 This callback will be invoked when pressing CTRL-C in Insert
8155 mode. Without setting a callback Vim will exit Insert mode,
8156 as in any buffer.
8157
8158 Can also be used as a |method|: >
8159 GetBuffer()->prompt_setinterrupt(callback)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008160<
8161 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008162
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008163 {only available when compiled with the |+channel| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008164
8165prompt_setprompt({buf}, {text}) *prompt_setprompt()*
8166 Set prompt for buffer {buf} to {text}. You most likely want
8167 {text} to end in a space.
8168 The result is only visible if {buf} has 'buftype' set to
8169 "prompt". Example: >
8170 call prompt_setprompt(bufnr(), 'command: ')
8171<
8172 Can also be used as a |method|: >
8173 GetBuffer()->prompt_setprompt('command: ')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008174<
8175 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008176
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008177 {only available when compiled with the |+channel| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008178
8179prop_ functions are documented here: |text-prop-functions|
8180
8181pum_getpos() *pum_getpos()*
8182 If the popup menu (see |ins-completion-menu|) is not visible,
8183 returns an empty |Dictionary|, otherwise, returns a
8184 |Dictionary| with the following keys:
8185 height nr of items visible
8186 width screen cells
8187 row top screen row (0 first row)
8188 col leftmost screen column (0 first col)
8189 size total nr of items
8190 scrollbar |TRUE| if scrollbar is visible
8191
8192 The values are the same as in |v:event| during
8193 |CompleteChanged|.
8194
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008195 Return type: dict<any>
8196
8197
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008198pumvisible() *pumvisible()*
8199 Returns non-zero when the popup menu is visible, zero
8200 otherwise. See |ins-completion-menu|.
8201 This can be used to avoid some things that would remove the
8202 popup menu.
8203
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008204 Return type: |Number|
8205
8206
zeertzjq7c515282024-11-10 20:26:12 +01008207py3eval({expr} [, {locals}]) *py3eval()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008208 Evaluate Python expression {expr} and return its result
8209 converted to Vim data structures.
Ben Jacksonea19e782024-11-06 21:50:05 +01008210 If a {locals} |Dictionary| is given, it defines set of local
8211 variables available in the expression. The keys are variable
8212 names and the values are the variable values. |Dictionary| and
8213 |List| values are referenced, and may be updated by the
8214 expression (as if |python-bindeval| was used).
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008215 Numbers and strings are returned as they are (strings are
8216 copied though, Unicode strings are additionally converted to
8217 'encoding').
8218 Lists are represented as Vim |List| type.
8219 Dictionaries are represented as Vim |Dictionary| type with
8220 keys converted to strings.
8221 Note that in a `:def` function local variables are not visible
8222 to {expr}.
8223
8224 Can also be used as a |method|: >
8225 GetExpr()->py3eval()
Ben Jacksonea19e782024-11-06 21:50:05 +01008226 'b",".join(l)'->py3eval({'l': ['a', 'b', 'c']})
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008227<
8228 Return type: any, depending on {expr}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008229
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008230 {only available when compiled with the |+python3| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008231
8232 *E858* *E859*
zeertzjq7c515282024-11-10 20:26:12 +01008233pyeval({expr} [, {locals}]) *pyeval()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008234 Evaluate Python expression {expr} and return its result
8235 converted to Vim data structures.
Ben Jacksonea19e782024-11-06 21:50:05 +01008236 For {locals} see |py3eval()|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008237 Numbers and strings are returned as they are (strings are
8238 copied though).
8239 Lists are represented as Vim |List| type.
8240 Dictionaries are represented as Vim |Dictionary| type,
8241 non-string keys result in error.
8242 Note that in a `:def` function local variables are not visible
8243 to {expr}.
8244
8245 Can also be used as a |method|: >
8246 GetExpr()->pyeval()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008247<
8248 Return type: any, depending on {expr}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008249
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008250 {only available when compiled with the |+python| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008251
zeertzjq7c515282024-11-10 20:26:12 +01008252pyxeval({expr} [, {locals}]) *pyxeval()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008253 Evaluate Python expression {expr} and return its result
8254 converted to Vim data structures.
Ben Jacksonea19e782024-11-06 21:50:05 +01008255 For {locals} see |py3eval()|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008256 Uses Python 2 or 3, see |python_x| and 'pyxversion'.
8257 See also: |pyeval()|, |py3eval()|
8258
8259 Can also be used as a |method|: >
h-east52e7cc22024-07-28 17:03:29 +02008260 GetExpr()->pyxeval()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008261<
8262 Return type: any, depending on {expr}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008263
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008264 {only available when compiled with the |+python| or the
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008265 |+python3| feature}
8266
8267rand([{expr}]) *rand()* *random*
8268 Return a pseudo-random Number generated with an xoshiro128**
8269 algorithm using seed {expr}. The returned number is 32 bits,
8270 also on 64 bits systems, for consistency.
8271 {expr} can be initialized by |srand()| and will be updated by
8272 rand(). If {expr} is omitted, an internal seed value is used
8273 and updated.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01008274 Returns -1 if {expr} is invalid.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008275
8276 Examples: >
8277 :echo rand()
8278 :let seed = srand()
8279 :echo rand(seed)
8280 :echo rand(seed) % 16 " random number 0 - 15
8281<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008282 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008283
8284 *E726* *E727*
8285range({expr} [, {max} [, {stride}]]) *range()*
8286 Returns a |List| with Numbers:
8287 - If only {expr} is specified: [0, 1, ..., {expr} - 1]
8288 - If {max} is specified: [{expr}, {expr} + 1, ..., {max}]
8289 - If {stride} is specified: [{expr}, {expr} + {stride}, ...,
8290 {max}] (increasing {expr} with {stride} each time, not
8291 producing a value past {max}).
8292 When the maximum is one before the start the result is an
8293 empty list. When the maximum is more than one before the
8294 start this is an error.
8295 Examples: >
8296 range(4) " [0, 1, 2, 3]
8297 range(2, 4) " [2, 3, 4]
8298 range(2, 9, 3) " [2, 5, 8]
8299 range(2, -2, -1) " [2, 1, 0, -1, -2]
8300 range(0) " []
8301 range(2, 0) " error!
8302<
8303 Can also be used as a |method|: >
8304 GetExpr()->range()
8305<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008306 Return type: list<number>
8307
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008308
K.Takata11df3ae2022-10-19 14:02:40 +01008309readblob({fname} [, {offset} [, {size}]]) *readblob()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008310 Read file {fname} in binary mode and return a |Blob|.
K.Takata11df3ae2022-10-19 14:02:40 +01008311 If {offset} is specified, read the file from the specified
8312 offset. If it is a negative value, it is used as an offset
8313 from the end of the file. E.g., to read the last 12 bytes: >
8314 readblob('file.bin', -12)
8315< If {size} is specified, only the specified size will be read.
8316 E.g. to read the first 100 bytes of a file: >
8317 readblob('file.bin', 0, 100)
8318< If {size} is -1 or omitted, the whole data starting from
8319 {offset} will be read.
K.Takata43625762022-10-20 13:28:51 +01008320 This can be also used to read the data from a character device
8321 on Unix when {size} is explicitly set. Only if the device
8322 supports seeking {offset} can be used. Otherwise it should be
8323 zero. E.g. to read 10 bytes from a serial console: >
8324 readblob('/dev/ttyS0', 0, 10)
8325< When the file can't be opened an error message is given and
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008326 the result is an empty |Blob|.
Bram Moolenaar5b2a3d72022-10-21 11:25:30 +01008327 When the offset is beyond the end of the file the result is an
8328 empty blob.
8329 When trying to read more bytes than are available the result
8330 is truncated.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008331 Also see |readfile()| and |writefile()|.
8332
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008333 Return type: |Blob|
8334
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008335
8336readdir({directory} [, {expr} [, {dict}]]) *readdir()*
8337 Return a list with file and directory names in {directory}.
8338 You can also use |glob()| if you don't need to do complicated
8339 things, such as limiting the number of matches.
8340 The list will be sorted (case sensitive), see the {dict}
8341 argument below for changing the sort order.
8342
8343 When {expr} is omitted all entries are included.
8344 When {expr} is given, it is evaluated to check what to do:
8345 If {expr} results in -1 then no further entries will
8346 be handled.
8347 If {expr} results in 0 then this entry will not be
8348 added to the list.
8349 If {expr} results in 1 then this entry will be added
8350 to the list.
8351 The entries "." and ".." are always excluded.
8352 Each time {expr} is evaluated |v:val| is set to the entry name.
8353 When {expr} is a function the name is passed as the argument.
8354 For example, to get a list of files ending in ".txt": >
8355 readdir(dirname, {n -> n =~ '.txt$'})
8356< To skip hidden and backup files: >
8357 readdir(dirname, {n -> n !~ '^\.\|\~$'})
Bram Moolenaar6f4754b2022-01-23 12:07:04 +00008358< *E857*
8359 The optional {dict} argument allows for further custom
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008360 values. Currently this is used to specify if and how sorting
8361 should be performed. The dict can have the following members:
8362
8363 sort How to sort the result returned from the system.
8364 Valid values are:
8365 "none" do not sort (fastest method)
8366 "case" sort case sensitive (byte value of
8367 each character, technically, using
8368 strcmp()) (default)
8369 "icase" sort case insensitive (technically
8370 using strcasecmp())
8371 "collate" sort using the collation order
8372 of the "POSIX" or "C" |locale|
8373 (technically using strcoll())
8374 Other values are silently ignored.
8375
8376 For example, to get a list of all files in the current
8377 directory without sorting the individual entries: >
8378 readdir('.', '1', #{sort: 'none'})
8379< If you want to get a directory tree: >
8380 function! s:tree(dir)
8381 return {a:dir : map(readdir(a:dir),
8382 \ {_, x -> isdirectory(x) ?
Bram Moolenaarc51cf032022-02-26 12:25:45 +00008383 \ {x : s:tree(a:dir .. '/' .. x)} : x})}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008384 endfunction
8385 echo s:tree(".")
8386<
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01008387 Returns an empty List on error.
8388
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008389 Can also be used as a |method|: >
8390 GetDirName()->readdir()
8391<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008392 Return type: list<string> or list<any>
8393
8394
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008395readdirex({directory} [, {expr} [, {dict}]]) *readdirex()*
8396 Extended version of |readdir()|.
8397 Return a list of Dictionaries with file and directory
8398 information in {directory}.
8399 This is useful if you want to get the attributes of file and
8400 directory at the same time as getting a list of a directory.
8401 This is much faster than calling |readdir()| then calling
8402 |getfperm()|, |getfsize()|, |getftime()| and |getftype()| for
8403 each file and directory especially on MS-Windows.
8404 The list will by default be sorted by name (case sensitive),
8405 the sorting can be changed by using the optional {dict}
8406 argument, see |readdir()|.
8407
8408 The Dictionary for file and directory information has the
8409 following items:
8410 group Group name of the entry. (Only on Unix)
8411 name Name of the entry.
8412 perm Permissions of the entry. See |getfperm()|.
8413 size Size of the entry. See |getfsize()|.
8414 time Timestamp of the entry. See |getftime()|.
8415 type Type of the entry.
8416 On Unix, almost same as |getftype()| except:
8417 Symlink to a dir "linkd"
8418 Other symlink "link"
8419 On MS-Windows:
8420 Normal file "file"
8421 Directory "dir"
8422 Junction "junction"
8423 Symlink to a dir "linkd"
8424 Other symlink "link"
8425 Other reparse point "reparse"
8426 user User name of the entry's owner. (Only on Unix)
8427 On Unix, if the entry is a symlink, the Dictionary includes
8428 the information of the target (except the "type" item).
8429 On MS-Windows, it includes the information of the symlink
8430 itself because of performance reasons.
8431
8432 When {expr} is omitted all entries are included.
8433 When {expr} is given, it is evaluated to check what to do:
8434 If {expr} results in -1 then no further entries will
8435 be handled.
8436 If {expr} results in 0 then this entry will not be
8437 added to the list.
8438 If {expr} results in 1 then this entry will be added
8439 to the list.
8440 The entries "." and ".." are always excluded.
8441 Each time {expr} is evaluated |v:val| is set to a |Dictionary|
8442 of the entry.
8443 When {expr} is a function the entry is passed as the argument.
8444 For example, to get a list of files ending in ".txt": >
8445 readdirex(dirname, {e -> e.name =~ '.txt$'})
8446<
8447 For example, to get a list of all files in the current
8448 directory without sorting the individual entries: >
8449 readdirex(dirname, '1', #{sort: 'none'})
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008450<
8451 Can also be used as a |method|: >
8452 GetDirName()->readdirex()
8453<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008454 Return type: list<dict<any>> or list<any>
8455
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008456
8457 *readfile()*
8458readfile({fname} [, {type} [, {max}]])
8459 Read file {fname} and return a |List|, each line of the file
8460 as an item. Lines are broken at NL characters. Macintosh
8461 files separated with CR will result in a single long line
8462 (unless a NL appears somewhere).
8463 All NUL characters are replaced with a NL character.
8464 When {type} contains "b" binary mode is used:
8465 - When the last line ends in a NL an extra empty list item is
8466 added.
8467 - No CR characters are removed.
8468 Otherwise:
8469 - CR characters that appear before a NL are removed.
8470 - Whether the last line ends in a NL or not does not matter.
8471 - When 'encoding' is Unicode any UTF-8 byte order mark is
8472 removed from the text.
8473 When {max} is given this specifies the maximum number of lines
8474 to be read. Useful if you only want to check the first ten
8475 lines of a file: >
8476 :for line in readfile(fname, '', 10)
8477 : if line =~ 'Date' | echo line | endif
8478 :endfor
8479< When {max} is negative -{max} lines from the end of the file
8480 are returned, or as many as there are.
8481 When {max} is zero the result is an empty list.
8482 Note that without {max} the whole file is read into memory.
8483 Also note that there is no recognition of encoding. Read a
8484 file into a buffer if you need to.
8485 Deprecated (use |readblob()| instead): When {type} contains
8486 "B" a |Blob| is returned with the binary data of the file
8487 unmodified.
8488 When the file can't be opened an error message is given and
8489 the result is an empty list.
8490 Also see |writefile()|.
8491
8492 Can also be used as a |method|: >
8493 GetFileName()->readfile()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008494<
8495 Return type: list<string> or list<any>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008496
8497reduce({object}, {func} [, {initial}]) *reduce()* *E998*
8498 {func} is called for every item in {object}, which can be a
8499 |String|, |List| or a |Blob|. {func} is called with two
8500 arguments: the result so far and current item. After
Bram Moolenaarf10911e2022-01-29 22:20:48 +00008501 processing all items the result is returned. *E1132*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008502
8503 {initial} is the initial result. When omitted, the first item
8504 in {object} is used and {func} is first called for the second
8505 item. If {initial} is not given and {object} is empty no
8506 result can be computed, an E998 error is given.
8507
8508 Examples: >
8509 echo reduce([1, 3, 5], { acc, val -> acc + val })
8510 echo reduce(['x', 'y'], { acc, val -> acc .. val }, 'a')
8511 echo reduce(0z1122, { acc, val -> 2 * acc + val })
8512 echo reduce('xyz', { acc, val -> acc .. ',' .. val })
8513<
8514 Can also be used as a |method|: >
8515 echo mylist->reduce({ acc, val -> acc + val }, 0)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008516<
8517 Return type: |String|, |Blob|, list<{type}> or dict<{type}>
8518 depending on {object} and {func}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008519
8520
8521reg_executing() *reg_executing()*
8522 Returns the single letter name of the register being executed.
8523 Returns an empty string when no register is being executed.
8524 See |@|.
8525
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008526 Return type: |String|
8527
8528
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008529reg_recording() *reg_recording()*
8530 Returns the single letter name of the register being recorded.
8531 Returns an empty string when not recording. See |q|.
8532
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008533 Return type: |String|
8534
8535
8536reltime() *reltime()*
Bram Moolenaarf269eab2022-10-03 18:04:35 +01008537reltime({start})
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008538reltime({start}, {end})
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008539 Return an item that represents a time value. The item is a
8540 list with items that depend on the system. In Vim 9 script
Bram Moolenaar71badf92023-04-22 22:40:14 +01008541 the type list<any> can be used.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008542 The item can be passed to |reltimestr()| to convert it to a
Bram Moolenaarf269eab2022-10-03 18:04:35 +01008543 string or |reltimefloat()| to convert to a Float. For
8544 example, to see the time spent in function Work(): >
8545 var startTime = reltime()
8546 Work()
8547 echo startTime->reltime()->reltimestr()
8548<
Bram Moolenaar016188f2022-06-06 20:52:59 +01008549 Without an argument reltime() returns the current time (the
Lifepillar963fd7d2024-01-05 17:44:57 +01008550 representation is system-dependent, it cannot be used as the
Bram Moolenaar016188f2022-06-06 20:52:59 +01008551 wall-clock time, see |localtime()| for that).
Lifepillar963fd7d2024-01-05 17:44:57 +01008552 With one argument it returns the time passed since the time
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008553 specified in the argument.
8554 With two arguments it returns the time passed between {start}
8555 and {end}.
8556
8557 The {start} and {end} arguments must be values returned by
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01008558 reltime(). If there is an error an empty List is returned in
8559 legacy script, in Vim9 script an error is given.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008560
8561 Can also be used as a |method|: >
8562 GetStart()->reltime()
8563<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008564 Return type: list<number>
8565
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008566 {only available when compiled with the |+reltime| feature}
8567
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008568
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008569reltimefloat({time}) *reltimefloat()*
8570 Return a Float that represents the time value of {time}.
8571 Example: >
8572 let start = reltime()
8573 call MyFunction()
8574 let seconds = reltimefloat(reltime(start))
8575< See the note of reltimestr() about overhead.
8576 Also see |profiling|.
8577 If there is an error 0.0 is returned in legacy script, in Vim9
8578 script an error is given.
8579
8580 Can also be used as a |method|: >
8581 reltime(start)->reltimefloat()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008582<
8583 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008584
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008585 {only available when compiled with the |+reltime| feature}
8586
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008587
8588reltimestr({time}) *reltimestr()*
8589 Return a String that represents the time value of {time}.
8590 This is the number of seconds, a dot and the number of
8591 microseconds. Example: >
8592 let start = reltime()
8593 call MyFunction()
8594 echo reltimestr(reltime(start))
8595< Note that overhead for the commands will be added to the time.
Ernie Rael076de792023-03-16 21:43:15 +00008596 The accuracy depends on the system. Use reltimefloat() for the
8597 greatest accuracy which is nanoseconds on some systems.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008598 Leading spaces are used to make the string align nicely. You
8599 can use split() to remove it. >
8600 echo split(reltimestr(reltime(start)))[0]
8601< Also see |profiling|.
8602 If there is an error an empty string is returned in legacy
8603 script, in Vim9 script an error is given.
8604
8605 Can also be used as a |method|: >
8606 reltime(start)->reltimestr()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008607<
8608 Return type: |String|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008609
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008610 {only available when compiled with the |+reltime| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008611
8612 *remote_expr()* *E449*
8613remote_expr({server}, {string} [, {idvar} [, {timeout}]])
Bram Moolenaar944697a2022-02-20 19:48:20 +00008614 Send the {string} to {server}. The {server} argument is a
8615 string, also see |{server}|.
8616
8617 The string is sent as an expression and the result is returned
Christian Brabandt1961caf2024-10-12 11:57:12 +02008618 after evaluation. The result must be a String or a |List|
8619 other types will be converted to String. A |List| is turned
8620 into a String by joining the items with a line break in
8621 between (not at the end), like with join(expr, "\n").
Bram Moolenaar944697a2022-02-20 19:48:20 +00008622
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008623 If {idvar} is present and not empty, it is taken as the name
8624 of a variable and a {serverid} for later use with
8625 |remote_read()| is stored there.
Bram Moolenaar944697a2022-02-20 19:48:20 +00008626
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008627 If {timeout} is given the read times out after this many
8628 seconds. Otherwise a timeout of 600 seconds is used.
Bram Moolenaar944697a2022-02-20 19:48:20 +00008629
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008630 See also |clientserver| |RemoteReply|.
8631 This function is not available in the |sandbox|.
8632 {only available when compiled with the |+clientserver| feature}
8633 Note: Any errors will cause a local error message to be issued
8634 and the result will be the empty string.
8635
8636 Variables will be evaluated in the global namespace,
8637 independent of a function currently being active. Except
8638 when in debug mode, then local function variables and
8639 arguments can be evaluated.
8640
8641 Examples: >
8642 :echo remote_expr("gvim", "2+2")
8643 :echo remote_expr("gvim1", "b:current_syntax")
8644<
8645 Can also be used as a |method|: >
8646 ServerName()->remote_expr(expr)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008647<
8648 Return type: |String| or list<{type}>
8649
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008650
8651remote_foreground({server}) *remote_foreground()*
8652 Move the Vim server with the name {server} to the foreground.
Bram Moolenaar944697a2022-02-20 19:48:20 +00008653 The {server} argument is a string, also see |{server}|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008654 This works like: >
8655 remote_expr({server}, "foreground()")
8656< Except that on Win32 systems the client does the work, to work
8657 around the problem that the OS doesn't always allow the server
8658 to bring itself to the foreground.
8659 Note: This does not restore the window if it was minimized,
8660 like foreground() does.
8661 This function is not available in the |sandbox|.
8662
8663 Can also be used as a |method|: >
8664 ServerName()->remote_foreground()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008665<
8666 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008667
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008668 {only in the Win32, Motif and GTK GUI versions and the
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008669 Win32 console version}
8670
8671
8672remote_peek({serverid} [, {retvar}]) *remote_peek()*
8673 Returns a positive number if there are available strings
8674 from {serverid}. Copies any reply string into the variable
8675 {retvar} if specified. {retvar} must be a string with the
8676 name of a variable.
8677 Returns zero if none are available.
8678 Returns -1 if something is wrong.
8679 See also |clientserver|.
8680 This function is not available in the |sandbox|.
8681 {only available when compiled with the |+clientserver| feature}
8682 Examples: >
Bram Moolenaarf269eab2022-10-03 18:04:35 +01008683 :let repl = ""
8684 :echo "PEEK: " .. remote_peek(id, "repl") .. ": " .. repl
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008685
8686< Can also be used as a |method|: >
8687 ServerId()->remote_peek()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008688<
8689 Return type: |Number|
8690
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008691
8692remote_read({serverid}, [{timeout}]) *remote_read()*
8693 Return the oldest available reply from {serverid} and consume
8694 it. Unless a {timeout} in seconds is given, it blocks until a
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01008695 reply is available. Returns an empty string, if a reply is
8696 not available or on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008697 See also |clientserver|.
8698 This function is not available in the |sandbox|.
8699 {only available when compiled with the |+clientserver| feature}
8700 Example: >
8701 :echo remote_read(id)
8702
8703< Can also be used as a |method|: >
8704 ServerId()->remote_read()
8705<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008706 Return type: |String|
8707
8708
8709remote_send({server}, {string} [, {idvar}]) *remote_send()* *E241*
Bram Moolenaar944697a2022-02-20 19:48:20 +00008710 Send the {string} to {server}. The {server} argument is a
8711 string, also see |{server}|.
8712
8713 The string is sent as input keys and the function returns
8714 immediately. At the Vim server the keys are not mapped
8715 |:map|.
8716
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008717 If {idvar} is present, it is taken as the name of a variable
8718 and a {serverid} for later use with remote_read() is stored
8719 there.
Bram Moolenaar944697a2022-02-20 19:48:20 +00008720
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008721 See also |clientserver| |RemoteReply|.
8722 This function is not available in the |sandbox|.
8723 {only available when compiled with the |+clientserver| feature}
8724
8725 Note: Any errors will be reported in the server and may mess
8726 up the display.
8727 Examples: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00008728 :echo remote_send("gvim", ":DropAndReply " .. file, "serverid") ..
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008729 \ remote_read(serverid)
8730
8731 :autocmd NONE RemoteReply *
8732 \ echo remote_read(expand("<amatch>"))
Bram Moolenaarc51cf032022-02-26 12:25:45 +00008733 :echo remote_send("gvim", ":sleep 10 | echo " ..
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008734 \ 'server2client(expand("<client>"), "HELLO")<CR>')
8735<
8736 Can also be used as a |method|: >
8737 ServerName()->remote_send(keys)
8738<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008739 Return type: |String|
8740
8741
8742remote_startserver({name}) *remote_startserver()* *E941* *E942*
h-east17b69512023-05-01 22:36:56 +01008743 Become the server {name}. {name} must be a non-empty string.
8744 This fails if already running as a server, when |v:servername|
8745 is not empty.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008746
8747 Can also be used as a |method|: >
8748 ServerName()->remote_startserver()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008749<
8750 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008751
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008752 {only available when compiled with the |+clientserver| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008753
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008754
8755remove({list}, {idx}) *remove()*
8756remove({list}, {idx}, {end})
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008757 Without {end}: Remove the item at {idx} from |List| {list} and
8758 return the item.
8759 With {end}: Remove items from {idx} to {end} (inclusive) and
8760 return a |List| with these items. When {idx} points to the same
8761 item as {end} a list with one item is returned. When {end}
8762 points to an item before {idx} this is an error.
8763 See |list-index| for possible values of {idx} and {end}.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01008764 Returns zero on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008765 Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00008766 :echo "last item: " .. remove(mylist, -1)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008767 :call remove(mylist, 0, 9)
8768<
8769 Use |delete()| to remove a file.
8770
8771 Can also be used as a |method|: >
8772 mylist->remove(idx)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008773<
8774 Return type: any, depending on {list}
8775
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008776
Bram Moolenaarf269eab2022-10-03 18:04:35 +01008777remove({blob}, {idx})
8778remove({blob}, {idx}, {end})
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008779 Without {end}: Remove the byte at {idx} from |Blob| {blob} and
8780 return the byte.
8781 With {end}: Remove bytes from {idx} to {end} (inclusive) and
8782 return a |Blob| with these bytes. When {idx} points to the same
8783 byte as {end} a |Blob| with one byte is returned. When {end}
8784 points to a byte before {idx} this is an error.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01008785 Returns zero on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008786 Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00008787 :echo "last byte: " .. remove(myblob, -1)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008788 :call remove(mylist, 0, 9)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008789<
8790 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008791
8792remove({dict}, {key})
8793 Remove the entry from {dict} with key {key} and return it.
8794 Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00008795 :echo "removed " .. remove(dict, "one")
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008796< If there is no {key} in {dict} this is an error.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01008797 Returns zero on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008798
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008799 Return type: any, depending on {dict}
8800
8801
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008802rename({from}, {to}) *rename()*
8803 Rename the file by the name {from} to the name {to}. This
8804 should also work to move files across file systems. The
8805 result is a Number, which is 0 if the file was renamed
8806 successfully, and non-zero when the renaming failed.
8807 NOTE: If {to} exists it is overwritten without warning.
8808 This function is not available in the |sandbox|.
8809
8810 Can also be used as a |method|: >
8811 GetOldName()->rename(newname)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008812<
8813 Return type: |Number|
8814
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008815
8816repeat({expr}, {count}) *repeat()*
8817 Repeat {expr} {count} times and return the concatenated
8818 result. Example: >
8819 :let separator = repeat('-', 80)
8820< When {count} is zero or negative the result is empty.
Bakudankun375141e2022-09-09 18:46:47 +01008821 When {expr} is a |List| or a |Blob| the result is {expr}
8822 concatenated {count} times. Example: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008823 :let longlist = repeat(['a', 'b'], 3)
8824< Results in ['a', 'b', 'a', 'b', 'a', 'b'].
8825
8826 Can also be used as a |method|: >
8827 mylist->repeat(count)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008828<
8829 Return type: |String|, |Blob| or list<{type}> depending on
8830 {expr}
8831
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008832
8833resolve({filename}) *resolve()* *E655*
8834 On MS-Windows, when {filename} is a shortcut (a .lnk file),
8835 returns the path the shortcut points to in a simplified form.
8836 When {filename} is a symbolic link or junction point, return
8837 the full path to the target. If the target of junction is
8838 removed, return {filename}.
8839 On Unix, repeat resolving symbolic links in all path
8840 components of {filename} and return the simplified result.
8841 To cope with link cycles, resolving of symbolic links is
8842 stopped after 100 iterations.
8843 On other systems, return the simplified {filename}.
8844 The simplification step is done as by |simplify()|.
8845 resolve() keeps a leading path component specifying the
8846 current directory (provided the result is still a relative
8847 path name) and also keeps a trailing path separator.
8848
8849 Can also be used as a |method|: >
8850 GetName()->resolve()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008851<
8852 Return type: |String|
8853
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008854
8855reverse({object}) *reverse()*
Yegappan Lakshmanan03ff1c22023-05-06 14:08:21 +01008856 Reverse the order of items in {object}. {object} can be a
8857 |List|, a |Blob| or a |String|. For a List and a Blob the
8858 items are reversed in-place and {object} is returned.
8859 For a String a new String is returned.
8860 Returns zero if {object} is not a List, Blob or a String.
8861 If you want a List or Blob to remain unmodified make a copy
8862 first: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008863 :let revlist = reverse(copy(mylist))
8864< Can also be used as a |method|: >
8865 mylist->reverse()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008866<
8867 Return type: |String|, |Blob| or list<{type}> depending on
8868 {object}
8869
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008870
8871round({expr}) *round()*
8872 Round off {expr} to the nearest integral value and return it
8873 as a |Float|. If {expr} lies halfway between two integral
8874 values, then use the larger one (away from zero).
8875 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01008876 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008877 Examples: >
8878 echo round(0.456)
8879< 0.0 >
8880 echo round(4.5)
8881< 5.0 >
8882 echo round(-4.5)
8883< -5.0
8884
8885 Can also be used as a |method|: >
8886 Compute()->round()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008887<
8888 Return type: |Float|
8889
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008890
8891rubyeval({expr}) *rubyeval()*
8892 Evaluate Ruby expression {expr} and return its result
8893 converted to Vim data structures.
8894 Numbers, floats and strings are returned as they are (strings
8895 are copied though).
8896 Arrays are represented as Vim |List| type.
8897 Hashes are represented as Vim |Dictionary| type.
8898 Other objects are represented as strings resulted from their
8899 "Object#to_s" method.
8900 Note that in a `:def` function local variables are not visible
8901 to {expr}.
8902
8903 Can also be used as a |method|: >
8904 GetRubyExpr()->rubyeval()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008905<
8906 Return type: any, depending on {expr}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008907
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008908 {only available when compiled with the |+ruby| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008909
8910screenattr({row}, {col}) *screenattr()*
8911 Like |screenchar()|, but return the attribute. This is a rather
8912 arbitrary number that can only be used to compare to the
8913 attribute at other positions.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01008914 Returns -1 when row or col is out of range.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008915
8916 Can also be used as a |method|: >
8917 GetRow()->screenattr(col)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008918<
8919 Return type: |Number|
8920
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008921
8922screenchar({row}, {col}) *screenchar()*
8923 The result is a Number, which is the character at position
8924 [row, col] on the screen. This works for every possible
8925 screen position, also status lines, window separators and the
8926 command line. The top left position is row one, column one
8927 The character excludes composing characters. For double-byte
8928 encodings it may only be the first byte.
8929 This is mainly to be used for testing.
8930 Returns -1 when row or col is out of range.
8931
8932 Can also be used as a |method|: >
8933 GetRow()->screenchar(col)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008934<
8935 Return type: |Number|
8936
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008937
8938screenchars({row}, {col}) *screenchars()*
8939 The result is a |List| of Numbers. The first number is the same
8940 as what |screenchar()| returns. Further numbers are
8941 composing characters on top of the base character.
8942 This is mainly to be used for testing.
8943 Returns an empty List when row or col is out of range.
8944
8945 Can also be used as a |method|: >
8946 GetRow()->screenchars(col)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008947<
8948 Return type: list<number> or list<any>
8949
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008950
8951screencol() *screencol()*
8952 The result is a Number, which is the current screen column of
8953 the cursor. The leftmost column has number 1.
8954 This function is mainly used for testing.
8955
8956 Note: Always returns the current screen column, thus if used
8957 in a command (e.g. ":echo screencol()") it will return the
8958 column inside the command line, which is 1 when the command is
8959 executed. To get the cursor position in the file use one of
8960 the following mappings: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00008961 nnoremap <expr> GG ":echom " .. screencol() .. "\n"
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008962 nnoremap <silent> GG :echom screencol()<CR>
8963 nnoremap GG <Cmd>echom screencol()<CR>
8964<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008965 Return type: |Number|
8966
8967
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008968screenpos({winid}, {lnum}, {col}) *screenpos()*
8969 The result is a Dict with the screen position of the text
8970 character in window {winid} at buffer line {lnum} and column
8971 {col}. {col} is a one-based byte index.
8972 The Dict has these members:
8973 row screen row
8974 col first screen column
8975 endcol last screen column
8976 curscol cursor screen column
8977 If the specified position is not visible, all values are zero.
8978 The "endcol" value differs from "col" when the character
8979 occupies more than one screen cell. E.g. for a Tab "col" can
8980 be 1 and "endcol" can be 8.
8981 The "curscol" value is where the cursor would be placed. For
8982 a Tab it would be the same as "endcol", while for a double
8983 width character it would be the same as "col".
8984 The |conceal| feature is ignored here, the column numbers are
8985 as if 'conceallevel' is zero. You can set the cursor to the
8986 right position and use |screencol()| to get the value with
8987 |conceal| taken into account.
Bram Moolenaar944697a2022-02-20 19:48:20 +00008988 If the position is in a closed fold the screen position of the
8989 first character is returned, {col} is not used.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01008990 Returns an empty Dict if {winid} is invalid.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008991
8992 Can also be used as a |method|: >
8993 GetWinid()->screenpos(lnum, col)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008994<
8995 Return type: dict<number> or dict<any>
8996
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008997
8998screenrow() *screenrow()*
8999 The result is a Number, which is the current screen row of the
9000 cursor. The top line has number one.
9001 This function is mainly used for testing.
9002 Alternatively you can use |winline()|.
9003
9004 Note: Same restrictions as with |screencol()|.
9005
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009006 Return type: |Number|
9007
9008
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009009screenstring({row}, {col}) *screenstring()*
9010 The result is a String that contains the base character and
9011 any composing characters at position [row, col] on the screen.
9012 This is like |screenchars()| but returning a String with the
9013 characters.
9014 This is mainly to be used for testing.
9015 Returns an empty String when row or col is out of range.
9016
9017 Can also be used as a |method|: >
9018 GetRow()->screenstring(col)
9019<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009020 Return type: |String|
9021
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009022 *search()*
9023search({pattern} [, {flags} [, {stopline} [, {timeout} [, {skip}]]]])
9024 Search for regexp pattern {pattern}. The search starts at the
9025 cursor position (you can use |cursor()| to set it).
9026
9027 When a match has been found its line number is returned.
9028 If there is no match a 0 is returned and the cursor doesn't
9029 move. No error message is given.
Christian Brabandt9a660d22024-03-12 22:03:09 +01009030 To get the matched string, use |matchbufline()|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009031
9032 {flags} is a String, which can contain these character flags:
9033 'b' search Backward instead of forward
9034 'c' accept a match at the Cursor position
9035 'e' move to the End of the match
9036 'n' do Not move the cursor
9037 'p' return number of matching sub-Pattern (see below)
9038 's' Set the ' mark at the previous location of the cursor
9039 'w' Wrap around the end of the file
9040 'W' don't Wrap around the end of the file
Doug Kearns8a27d972025-01-05 15:56:57 +01009041 'z' start searching at the cursor column instead of Zero
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009042 If neither 'w' or 'W' is given, the 'wrapscan' option applies.
9043
9044 If the 's' flag is supplied, the ' mark is set, only if the
9045 cursor is moved. The 's' flag cannot be combined with the 'n'
9046 flag.
9047
9048 'ignorecase', 'smartcase' and 'magic' are used.
9049
9050 When the 'z' flag is not given, forward searching always
9051 starts in column zero and then matches before the cursor are
9052 skipped. When the 'c' flag is present in 'cpo' the next
9053 search starts after the match. Without the 'c' flag the next
Bram Moolenaarfd999452022-08-24 18:30:14 +01009054 search starts one column after the start of the match. This
9055 matters for overlapping matches. See |cpo-c|. You can also
9056 insert "\ze" to change where the match ends, see |/\ze|.
9057
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009058 When searching backwards and the 'z' flag is given then the
9059 search starts in column zero, thus no match in the current
9060 line will be found (unless wrapping around the end of the
9061 file).
9062
9063 When the {stopline} argument is given then the search stops
9064 after searching this line. This is useful to restrict the
9065 search to a range of lines. Examples: >
9066 let match = search('(', 'b', line("w0"))
9067 let end = search('END', '', line("w$"))
9068< When {stopline} is used and it is not zero this also implies
9069 that the search does not wrap around the end of the file.
9070 A zero value is equal to not giving the argument.
Bram Moolenaar2ecbe532022-07-29 21:36:21 +01009071 *E1285* *E1286* *E1287* *E1288* *E1289*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009072 When the {timeout} argument is given the search stops when
9073 more than this many milliseconds have passed. Thus when
9074 {timeout} is 500 the search stops after half a second.
9075 The value must not be negative. A zero value is like not
9076 giving the argument.
Christian Brabandtd657d3d2024-09-10 21:55:49 +02009077
9078 Note: the timeout is only considered when searching, not
9079 while evaluating the {skip} expression.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009080 {only available when compiled with the |+reltime| feature}
9081
9082 If the {skip} expression is given it is evaluated with the
9083 cursor positioned on the start of a match. If it evaluates to
9084 non-zero this match is skipped. This can be used, for
9085 example, to skip a match in a comment or a string.
9086 {skip} can be a string, which is evaluated as an expression, a
9087 function reference or a lambda.
9088 When {skip} is omitted or empty, every match is accepted.
9089 When evaluating {skip} causes an error the search is aborted
9090 and -1 returned.
9091 *search()-sub-match*
9092 With the 'p' flag the returned value is one more than the
9093 first sub-match in \(\). One if none of them matched but the
9094 whole pattern did match.
9095 To get the column number too use |searchpos()|.
9096
9097 The cursor will be positioned at the match, unless the 'n'
9098 flag is used.
9099
9100 Example (goes over all files in the argument list): >
9101 :let n = 1
9102 :while n <= argc() " loop over all files in arglist
Bram Moolenaarc51cf032022-02-26 12:25:45 +00009103 : exe "argument " .. n
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009104 : " start at the last char in the file and wrap for the
9105 : " first search to find match at start of file
9106 : normal G$
9107 : let flags = "w"
9108 : while search("foo", flags) > 0
9109 : s/foo/bar/g
9110 : let flags = "W"
9111 : endwhile
9112 : update " write the file if modified
9113 : let n = n + 1
9114 :endwhile
9115<
9116 Example for using some flags: >
9117 :echo search('\<if\|\(else\)\|\(endif\)', 'ncpe')
9118< This will search for the keywords "if", "else", and "endif"
9119 under or after the cursor. Because of the 'p' flag, it
9120 returns 1, 2, or 3 depending on which keyword is found, or 0
9121 if the search fails. With the cursor on the first word of the
9122 line:
9123 if (foo == 0) | let foo = foo + 1 | endif ~
9124 the function returns 1. Without the 'c' flag, the function
9125 finds the "endif" and returns 3. The same thing happens
9126 without the 'e' flag if the cursor is on the "f" of "if".
9127 The 'n' flag tells the function not to move the cursor.
9128
9129 Can also be used as a |method|: >
9130 GetPattern()->search()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009131<
9132 Return type: |Number|
9133
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009134
9135searchcount([{options}]) *searchcount()*
9136 Get or update the last search count, like what is displayed
9137 without the "S" flag in 'shortmess'. This works even if
9138 'shortmess' does contain the "S" flag.
9139
9140 This returns a |Dictionary|. The dictionary is empty if the
9141 previous pattern was not set and "pattern" was not specified.
9142
9143 key type meaning ~
9144 current |Number| current position of match;
9145 0 if the cursor position is
9146 before the first match
9147 exact_match |Boolean| 1 if "current" is matched on
9148 "pos", otherwise 0
9149 total |Number| total count of matches found
9150 incomplete |Number| 0: search was fully completed
9151 1: recomputing was timed out
9152 2: max count exceeded
9153
9154 For {options} see further down.
9155
9156 To get the last search count when |n| or |N| was pressed, call
9157 this function with `recompute: 0` . This sometimes returns
9158 wrong information because |n| and |N|'s maximum count is 99.
9159 If it exceeded 99 the result must be max count + 1 (100). If
9160 you want to get correct information, specify `recompute: 1`: >
9161
9162 " result == maxcount + 1 (100) when many matches
9163 let result = searchcount(#{recompute: 0})
9164
9165 " Below returns correct result (recompute defaults
9166 " to 1)
9167 let result = searchcount()
9168<
Bram Moolenaarb529cfb2022-07-25 15:42:07 +01009169 The function is useful to add the count to 'statusline': >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009170 function! LastSearchCount() abort
9171 let result = searchcount(#{recompute: 0})
9172 if empty(result)
9173 return ''
9174 endif
9175 if result.incomplete ==# 1 " timed out
9176 return printf(' /%s [?/??]', @/)
9177 elseif result.incomplete ==# 2 " max count exceeded
9178 if result.total > result.maxcount &&
9179 \ result.current > result.maxcount
9180 return printf(' /%s [>%d/>%d]', @/,
9181 \ result.current, result.total)
9182 elseif result.total > result.maxcount
9183 return printf(' /%s [%d/>%d]', @/,
9184 \ result.current, result.total)
9185 endif
9186 endif
9187 return printf(' /%s [%d/%d]', @/,
9188 \ result.current, result.total)
9189 endfunction
Bram Moolenaarc51cf032022-02-26 12:25:45 +00009190 let &statusline ..= '%{LastSearchCount()}'
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009191
9192 " Or if you want to show the count only when
9193 " 'hlsearch' was on
Bram Moolenaarc51cf032022-02-26 12:25:45 +00009194 " let &statusline ..=
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009195 " \ '%{v:hlsearch ? LastSearchCount() : ""}'
9196<
9197 You can also update the search count, which can be useful in a
9198 |CursorMoved| or |CursorMovedI| autocommand: >
9199
9200 autocmd CursorMoved,CursorMovedI *
9201 \ let s:searchcount_timer = timer_start(
9202 \ 200, function('s:update_searchcount'))
9203 function! s:update_searchcount(timer) abort
9204 if a:timer ==# s:searchcount_timer
9205 call searchcount(#{
9206 \ recompute: 1, maxcount: 0, timeout: 100})
9207 redrawstatus
9208 endif
9209 endfunction
9210<
9211 This can also be used to count matched texts with specified
9212 pattern in the current buffer using "pattern": >
9213
9214 " Count '\<foo\>' in this buffer
9215 " (Note that it also updates search count)
9216 let result = searchcount(#{pattern: '\<foo\>'})
9217
9218 " To restore old search count by old pattern,
9219 " search again
9220 call searchcount()
9221<
9222 {options} must be a |Dictionary|. It can contain:
9223 key type meaning ~
9224 recompute |Boolean| if |TRUE|, recompute the count
9225 like |n| or |N| was executed.
9226 otherwise returns the last
9227 computed result (when |n| or
9228 |N| was used when "S" is not
9229 in 'shortmess', or this
9230 function was called).
9231 (default: |TRUE|)
9232 pattern |String| recompute if this was given
9233 and different with |@/|.
9234 this works as same as the
9235 below command is executed
9236 before calling this function >
9237 let @/ = pattern
9238< (default: |@/|)
9239 timeout |Number| 0 or negative number is no
9240 timeout. timeout milliseconds
9241 for recomputing the result
9242 (default: 0)
9243 maxcount |Number| 0 or negative number is no
9244 limit. max count of matched
9245 text while recomputing the
9246 result. if search exceeded
9247 total count, "total" value
9248 becomes `maxcount + 1`
9249 (default: 99)
9250 pos |List| `[lnum, col, off]` value
9251 when recomputing the result.
9252 this changes "current" result
9253 value. see |cursor()|,
9254 |getpos()|
9255 (default: cursor's position)
9256
9257 Can also be used as a |method|: >
9258 GetSearchOpts()->searchcount()
9259<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009260 Return type: dict<number>
9261
9262
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009263searchdecl({name} [, {global} [, {thisblock}]]) *searchdecl()*
9264 Search for the declaration of {name}.
9265
9266 With a non-zero {global} argument it works like |gD|, find
9267 first match in the file. Otherwise it works like |gd|, find
9268 first match in the function.
9269
9270 With a non-zero {thisblock} argument matches in a {} block
9271 that ends before the cursor position are ignored. Avoids
9272 finding variable declarations only valid in another scope.
9273
9274 Moves the cursor to the found match.
9275 Returns zero for success, non-zero for failure.
9276 Example: >
9277 if searchdecl('myvar') == 0
9278 echo getline('.')
9279 endif
9280<
9281 Can also be used as a |method|: >
9282 GetName()->searchdecl()
9283<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009284 Return type: |Number|
9285
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009286 *searchpair()*
9287searchpair({start}, {middle}, {end} [, {flags} [, {skip}
9288 [, {stopline} [, {timeout}]]]])
9289 Search for the match of a nested start-end pair. This can be
9290 used to find the "endif" that matches an "if", while other
9291 if/endif pairs in between are ignored.
9292 The search starts at the cursor. The default is to search
9293 forward, include 'b' in {flags} to search backward.
9294 If a match is found, the cursor is positioned at it and the
9295 line number is returned. If no match is found 0 or -1 is
9296 returned and the cursor doesn't move. No error message is
9297 given.
9298
9299 {start}, {middle} and {end} are patterns, see |pattern|. They
9300 must not contain \( \) pairs. Use of \%( \) is allowed. When
9301 {middle} is not empty, it is found when searching from either
9302 direction, but only when not in a nested start-end pair. A
9303 typical use is: >
9304 searchpair('\<if\>', '\<else\>', '\<endif\>')
9305< By leaving {middle} empty the "else" is skipped.
9306
9307 {flags} 'b', 'c', 'n', 's', 'w' and 'W' are used like with
9308 |search()|. Additionally:
9309 'r' Repeat until no more matches found; will find the
9310 outer pair. Implies the 'W' flag.
9311 'm' Return number of matches instead of line number with
9312 the match; will be > 1 when 'r' is used.
9313 Note: it's nearly always a good idea to use the 'W' flag, to
9314 avoid wrapping around the end of the file.
9315
9316 When a match for {start}, {middle} or {end} is found, the
9317 {skip} expression is evaluated with the cursor positioned on
9318 the start of the match. It should return non-zero if this
9319 match is to be skipped. E.g., because it is inside a comment
9320 or a string.
9321 When {skip} is omitted or empty, every match is accepted.
9322 When evaluating {skip} causes an error the search is aborted
9323 and -1 returned.
9324 {skip} can be a string, a lambda, a funcref or a partial.
9325 Anything else makes the function fail.
9326 In a `:def` function when the {skip} argument is a string
9327 constant it is compiled into instructions.
9328
9329 For {stopline} and {timeout} see |search()|.
9330
9331 The value of 'ignorecase' is used. 'magic' is ignored, the
9332 patterns are used like it's on.
9333
9334 The search starts exactly at the cursor. A match with
9335 {start}, {middle} or {end} at the next character, in the
9336 direction of searching, is the first one found. Example: >
9337 if 1
9338 if 2
9339 endif 2
9340 endif 1
9341< When starting at the "if 2", with the cursor on the "i", and
9342 searching forwards, the "endif 2" is found. When starting on
9343 the character just before the "if 2", the "endif 1" will be
9344 found. That's because the "if 2" will be found first, and
9345 then this is considered to be a nested if/endif from "if 2" to
9346 "endif 2".
9347 When searching backwards and {end} is more than one character,
9348 it may be useful to put "\zs" at the end of the pattern, so
9349 that when the cursor is inside a match with the end it finds
9350 the matching start.
9351
9352 Example, to find the "endif" command in a Vim script: >
9353
9354 :echo searchpair('\<if\>', '\<el\%[seif]\>', '\<en\%[dif]\>', 'W',
9355 \ 'getline(".") =~ "^\\s*\""')
9356
9357< The cursor must be at or after the "if" for which a match is
9358 to be found. Note that single-quote strings are used to avoid
9359 having to double the backslashes. The skip expression only
9360 catches comments at the start of a line, not after a command.
9361 Also, a word "en" or "if" halfway a line is considered a
9362 match.
9363 Another example, to search for the matching "{" of a "}": >
9364
9365 :echo searchpair('{', '', '}', 'bW')
9366
9367< This works when the cursor is at or before the "}" for which a
9368 match is to be found. To reject matches that syntax
9369 highlighting recognized as strings: >
9370
9371 :echo searchpair('{', '', '}', 'bW',
9372 \ 'synIDattr(synID(line("."), col("."), 0), "name") =~? "string"')
9373<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009374 Return type: |Number|
9375
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009376 *searchpairpos()*
9377searchpairpos({start}, {middle}, {end} [, {flags} [, {skip}
9378 [, {stopline} [, {timeout}]]]])
9379 Same as |searchpair()|, but returns a |List| with the line and
9380 column position of the match. The first element of the |List|
9381 is the line number and the second element is the byte index of
9382 the column position of the match. If no match is found,
9383 returns [0, 0]. >
9384
9385 :let [lnum,col] = searchpairpos('{', '', '}', 'n')
9386<
9387 See |match-parens| for a bigger and more useful example.
9388
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009389 Return type: list<number>
9390
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009391 *searchpos()*
9392searchpos({pattern} [, {flags} [, {stopline} [, {timeout} [, {skip}]]]])
9393 Same as |search()|, but returns a |List| with the line and
9394 column position of the match. The first element of the |List|
9395 is the line number and the second element is the byte index of
9396 the column position of the match. If no match is found,
9397 returns [0, 0].
9398 Example: >
9399 :let [lnum, col] = searchpos('mypattern', 'n')
9400
9401< When the 'p' flag is given then there is an extra item with
9402 the sub-pattern match number |search()-sub-match|. Example: >
9403 :let [lnum, col, submatch] = searchpos('\(\l\)\|\(\u\)', 'np')
9404< In this example "submatch" is 2 when a lowercase letter is
9405 found |/\l|, 3 when an uppercase letter is found |/\u|.
9406
9407 Can also be used as a |method|: >
9408 GetPattern()->searchpos()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009409<
9410 Return type: list<number>
9411
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009412
9413server2client({clientid}, {string}) *server2client()*
9414 Send a reply string to {clientid}. The most recent {clientid}
9415 that sent a string can be retrieved with expand("<client>").
9416 {only available when compiled with the |+clientserver| feature}
9417 Returns zero for success, -1 for failure.
9418 Note:
9419 This id has to be stored before the next command can be
9420 received. I.e. before returning from the received command and
9421 before calling any commands that waits for input.
9422 See also |clientserver|.
9423 Example: >
9424 :echo server2client(expand("<client>"), "HELLO")
9425
9426< Can also be used as a |method|: >
9427 GetClientId()->server2client(string)
9428<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009429 Return type: |Number|
9430
9431
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009432serverlist() *serverlist()*
9433 Return a list of available server names, one per line.
9434 When there are no servers or the information is not available
9435 an empty string is returned. See also |clientserver|.
9436 {only available when compiled with the |+clientserver| feature}
9437 Example: >
9438 :echo serverlist()
9439<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009440 Return type: |String|
9441
9442
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009443setbufline({buf}, {lnum}, {text}) *setbufline()*
9444 Set line {lnum} to {text} in buffer {buf}. This works like
9445 |setline()| for the specified buffer.
9446
9447 This function works only for loaded buffers. First call
9448 |bufload()| if needed.
9449
9450 To insert lines use |appendbufline()|.
9451 Any text properties in {lnum} are cleared.
9452
Bram Moolenaarcd9c8d42022-11-05 23:46:43 +00009453 {text} can be a string to set one line, or a List of strings
9454 to set multiple lines. If the List extends below the last
9455 line then those lines are added. If the List is empty then
9456 nothing is changed and zero is returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009457
9458 For the use of {buf}, see |bufname()| above.
9459
9460 {lnum} is used like with |setline()|.
9461 Use "$" to refer to the last line in buffer {buf}.
9462 When {lnum} is just below the last line the {text} will be
9463 added below the last line.
9464
9465 When {buf} is not a valid buffer, the buffer is not loaded or
9466 {lnum} is not valid then 1 is returned. In |Vim9| script an
9467 error is given.
9468 On success 0 is returned.
9469
9470 Can also be used as a |method|, the base is passed as the
9471 third argument: >
9472 GetText()->setbufline(buf, lnum)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009473<
9474 Return type: |Number|
9475
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009476
9477setbufvar({buf}, {varname}, {val}) *setbufvar()*
9478 Set option or local variable {varname} in buffer {buf} to
9479 {val}.
9480 This also works for a global or local window option, but it
9481 doesn't work for a global or local window variable.
9482 For a local window option the global value is unchanged.
9483 For the use of {buf}, see |bufname()| above.
9484 The {varname} argument is a string.
9485 Note that the variable name without "b:" must be used.
9486 Examples: >
9487 :call setbufvar(1, "&mod", 1)
9488 :call setbufvar("todo", "myvar", "foobar")
9489< This function is not available in the |sandbox|.
9490
9491 Can also be used as a |method|, the base is passed as the
9492 third argument: >
9493 GetValue()->setbufvar(buf, varname)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009494<
9495 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009496
9497
9498setcellwidths({list}) *setcellwidths()*
9499 Specify overrides for cell widths of character ranges. This
Bram Moolenaarb59ae592022-11-23 23:46:31 +00009500 tells Vim how wide characters are when displayed in the
9501 terminal, counted in screen cells. The values override
9502 'ambiwidth'. Example: >
9503 call setcellwidths([
Bram Moolenaar938ae282023-02-20 20:44:55 +00009504 \ [0x111, 0x111, 1],
Bram Moolenaarb59ae592022-11-23 23:46:31 +00009505 \ [0x2194, 0x2199, 2],
9506 \ ])
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009507
Bram Moolenaarb59ae592022-11-23 23:46:31 +00009508< The {list} argument is a List of Lists with each three
9509 numbers: [{low}, {high}, {width}]. *E1109* *E1110*
9510 {low} and {high} can be the same, in which case this refers to
9511 one character. Otherwise it is the range of characters from
9512 {low} to {high} (inclusive). *E1111* *E1114*
K.Takata71933232023-01-20 16:00:55 +00009513 Only characters with value 0x80 and higher can be used.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009514
Bram Moolenaarb59ae592022-11-23 23:46:31 +00009515 {width} must be either 1 or 2, indicating the character width
9516 in screen cells. *E1112*
9517 An error is given if the argument is invalid, also when a
Bram Moolenaar938ae282023-02-20 20:44:55 +00009518 range overlaps with another. *E1113*
Bram Moolenaarb59ae592022-11-23 23:46:31 +00009519
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009520 If the new value causes 'fillchars' or 'listchars' to become
9521 invalid it is rejected and an error is given.
9522
Bram Moolenaarb59ae592022-11-23 23:46:31 +00009523 To clear the overrides pass an empty {list}: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009524 setcellwidths([]);
Bram Moolenaarb59ae592022-11-23 23:46:31 +00009525
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009526< You can use the script $VIMRUNTIME/tools/emoji_list.vim to see
Bram Moolenaarb59ae592022-11-23 23:46:31 +00009527 the effect for known emoji characters. Move the cursor
9528 through the text to check if the cell widths of your terminal
9529 match with what Vim knows about each emoji. If it doesn't
9530 look right you need to adjust the {list} argument.
9531
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009532 Return type: |Number|
9533
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009534
9535setcharpos({expr}, {list}) *setcharpos()*
9536 Same as |setpos()| but uses the specified column number as the
9537 character index instead of the byte index in the line.
9538
9539 Example:
9540 With the text "여보세요" in line 8: >
9541 call setcharpos('.', [0, 8, 4, 0])
9542< positions the cursor on the fourth character '요'. >
9543 call setpos('.', [0, 8, 4, 0])
9544< positions the cursor on the second character '보'.
9545
9546 Can also be used as a |method|: >
9547 GetPosition()->setcharpos('.')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009548<
9549 Return type: |Number|
9550
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009551
9552setcharsearch({dict}) *setcharsearch()*
9553 Set the current character search information to {dict},
9554 which contains one or more of the following entries:
9555
9556 char character which will be used for a subsequent
9557 |,| or |;| command; an empty string clears the
9558 character search
9559 forward direction of character search; 1 for forward,
9560 0 for backward
9561 until type of character search; 1 for a |t| or |T|
9562 character search, 0 for an |f| or |F|
9563 character search
9564
9565 This can be useful to save/restore a user's character search
9566 from a script: >
9567 :let prevsearch = getcharsearch()
9568 :" Perform a command which clobbers user's search
9569 :call setcharsearch(prevsearch)
9570< Also see |getcharsearch()|.
9571
9572 Can also be used as a |method|: >
9573 SavedSearch()->setcharsearch()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009574<
9575 Return type: dict<any>
9576
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009577
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01009578setcmdline({str} [, {pos}]) *setcmdline()*
9579 Set the command line to {str} and set the cursor position to
9580 {pos}.
9581 If {pos} is omitted, the cursor is positioned after the text.
9582 Returns 0 when successful, 1 when not editing the command
9583 line.
9584
9585 Can also be used as a |method|: >
9586 GetText()->setcmdline()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009587<
9588 Return type: |Number|
9589
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01009590
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009591setcmdpos({pos}) *setcmdpos()*
9592 Set the cursor position in the command line to byte position
9593 {pos}. The first position is 1.
9594 Use |getcmdpos()| to obtain the current position.
9595 Only works while editing the command line, thus you must use
9596 |c_CTRL-\_e|, |c_CTRL-R_=| or |c_CTRL-R_CTRL-R| with '='. For
9597 |c_CTRL-\_e| and |c_CTRL-R_CTRL-R| with '=' the position is
9598 set after the command line is set to the expression. For
9599 |c_CTRL-R_=| it is set after evaluating the expression but
9600 before inserting the resulting text.
9601 When the number is too big the cursor is put at the end of the
9602 line. A number smaller than one has undefined results.
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01009603 Returns 0 when successful, 1 when not editing the command
9604 line.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009605
9606 Can also be used as a |method|: >
9607 GetPos()->setcmdpos()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009608<
9609 Return type: |Number|
9610
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009611
9612setcursorcharpos({lnum}, {col} [, {off}]) *setcursorcharpos()*
9613setcursorcharpos({list})
9614 Same as |cursor()| but uses the specified column number as the
9615 character index instead of the byte index in the line.
9616
9617 Example:
9618 With the text "여보세요" in line 4: >
9619 call setcursorcharpos(4, 3)
9620< positions the cursor on the third character '세'. >
9621 call cursor(4, 3)
9622< positions the cursor on the first character '여'.
9623
9624 Can also be used as a |method|: >
9625 GetCursorPos()->setcursorcharpos()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009626<
9627 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009628
9629
9630setenv({name}, {val}) *setenv()*
9631 Set environment variable {name} to {val}. Example: >
9632 call setenv('HOME', '/home/myhome')
9633
9634< When {val} is |v:null| the environment variable is deleted.
9635 See also |expr-env|.
9636
9637 Can also be used as a |method|, the base is passed as the
9638 second argument: >
9639 GetPath()->setenv('PATH')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009640<
9641 Return type: |Number|
9642
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009643
9644setfperm({fname}, {mode}) *setfperm()* *chmod*
9645 Set the file permissions for {fname} to {mode}.
9646 {mode} must be a string with 9 characters. It is of the form
9647 "rwxrwxrwx", where each group of "rwx" flags represent, in
9648 turn, the permissions of the owner of the file, the group the
9649 file belongs to, and other users. A '-' character means the
9650 permission is off, any other character means on. Multi-byte
9651 characters are not supported.
9652
9653 For example "rw-r-----" means read-write for the user,
9654 readable by the group, not accessible by others. "xx-x-----"
9655 would do the same thing.
9656
9657 Returns non-zero for success, zero for failure.
9658
9659 Can also be used as a |method|: >
9660 GetFilename()->setfperm(mode)
9661<
9662 To read permissions see |getfperm()|.
9663
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009664 Return type: |Number|
9665
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009666
9667setline({lnum}, {text}) *setline()*
9668 Set line {lnum} of the current buffer to {text}. To insert
9669 lines use |append()|. To set lines in another buffer use
Christian Brabandt946f61c2024-06-17 13:17:58 +02009670 |setbufline()|.
h-east52e7cc22024-07-28 17:03:29 +02009671 Any text properties in {lnum} are cleared. See
9672 |text-prop-cleared|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009673
9674 {lnum} is used like with |getline()|.
9675 When {lnum} is just below the last line the {text} will be
9676 added below the last line.
9677 {text} can be any type or a List of any type, each item is
Bram Moolenaarcd9c8d42022-11-05 23:46:43 +00009678 converted to a String. When {text} is an empty List then
9679 nothing is changed and FALSE is returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009680
9681 If this succeeds, FALSE is returned. If this fails (most likely
9682 because {lnum} is invalid) TRUE is returned.
9683 In |Vim9| script an error is given if {lnum} is invalid.
9684
9685 Example: >
9686 :call setline(5, strftime("%c"))
9687
9688< When {text} is a |List| then line {lnum} and following lines
9689 will be set to the items in the list. Example: >
9690 :call setline(5, ['aaa', 'bbb', 'ccc'])
9691< This is equivalent to: >
9692 :for [n, l] in [[5, 'aaa'], [6, 'bbb'], [7, 'ccc']]
9693 : call setline(n, l)
9694 :endfor
9695
9696< Note: The '[ and '] marks are not set.
9697
9698 Can also be used as a |method|, the base is passed as the
9699 second argument: >
9700 GetText()->setline(lnum)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009701<
9702 Return type: |Number|
9703
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009704
9705setloclist({nr}, {list} [, {action} [, {what}]]) *setloclist()*
9706 Create or replace or add to the location list for window {nr}.
9707 {nr} can be the window number or the |window-ID|.
9708 When {nr} is zero the current window is used.
9709
9710 For a location list window, the displayed location list is
9711 modified. For an invalid window number {nr}, -1 is returned.
9712 Otherwise, same as |setqflist()|.
9713 Also see |location-list|.
9714
9715 For {action} see |setqflist-action|.
9716
9717 If the optional {what} dictionary argument is supplied, then
9718 only the items listed in {what} are set. Refer to |setqflist()|
9719 for the list of supported keys in {what}.
9720
9721 Can also be used as a |method|, the base is passed as the
9722 second argument: >
9723 GetLoclist()->setloclist(winnr)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009724<
9725 Return type: |Number|
9726
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009727
9728setmatches({list} [, {win}]) *setmatches()*
9729 Restores a list of matches saved by |getmatches()| for the
9730 current window. Returns 0 if successful, otherwise -1. All
9731 current matches are cleared before the list is restored. See
9732 example for |getmatches()|.
9733 If {win} is specified, use the window with this number or
9734 window ID instead of the current window.
9735
9736 Can also be used as a |method|: >
9737 GetMatches()->setmatches()
9738<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009739 Return type: |Number|
9740
9741
9742setpos({expr}, {list}) *setpos()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009743 Set the position for String {expr}. Possible values:
9744 . the cursor
9745 'x mark x
9746
9747 {list} must be a |List| with four or five numbers:
9748 [bufnum, lnum, col, off]
9749 [bufnum, lnum, col, off, curswant]
9750
9751 "bufnum" is the buffer number. Zero can be used for the
9752 current buffer. When setting an uppercase mark "bufnum" is
9753 used for the mark position. For other marks it specifies the
9754 buffer to set the mark in. You can use the |bufnr()| function
9755 to turn a file name into a buffer number.
9756 For setting the cursor and the ' mark "bufnum" is ignored,
9757 since these are associated with a window, not a buffer.
9758 Does not change the jumplist.
9759
9760 "lnum" and "col" are the position in the buffer. The first
9761 column is 1. Use a zero "lnum" to delete a mark. If "col" is
9762 smaller than 1 then 1 is used. To use the character count
9763 instead of the byte count, use |setcharpos()|.
9764
9765 The "off" number is only used when 'virtualedit' is set. Then
9766 it is the offset in screen columns from the start of the
9767 character. E.g., a position within a <Tab> or after the last
9768 character.
9769
9770 The "curswant" number is only used when setting the cursor
9771 position. It sets the preferred column for when moving the
9772 cursor vertically. When the "curswant" number is missing the
9773 preferred column is not set. When it is present and setting a
9774 mark position it is not used.
9775
9776 Note that for '< and '> changing the line number may result in
9777 the marks to be effectively be swapped, so that '< is always
9778 before '>.
9779
9780 Returns 0 when the position could be set, -1 otherwise.
9781 An error message is given if {expr} is invalid.
9782
9783 Also see |setcharpos()|, |getpos()| and |getcurpos()|.
9784
9785 This does not restore the preferred column for moving
9786 vertically; if you set the cursor position with this, |j| and
9787 |k| motions will jump to previous columns! Use |cursor()| to
9788 also set the preferred column. Also see the "curswant" key in
9789 |winrestview()|.
9790
9791 Can also be used as a |method|: >
9792 GetPosition()->setpos('.')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009793<
9794 Return type: |Number|
9795
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009796
9797setqflist({list} [, {action} [, {what}]]) *setqflist()*
9798 Create or replace or add to the quickfix list.
9799
9800 If the optional {what} dictionary argument is supplied, then
9801 only the items listed in {what} are set. The first {list}
9802 argument is ignored. See below for the supported items in
9803 {what}.
9804 *setqflist-what*
9805 When {what} is not present, the items in {list} are used. Each
9806 item must be a dictionary. Non-dictionary items in {list} are
9807 ignored. Each dictionary item can contain the following
9808 entries:
9809
9810 bufnr buffer number; must be the number of a valid
9811 buffer
9812 filename name of a file; only used when "bufnr" is not
9813 present or it is invalid.
9814 module name of a module; if given it will be used in
9815 quickfix error window instead of the filename.
9816 lnum line number in the file
Bram Moolenaara2baa732022-02-04 16:09:54 +00009817 end_lnum end of lines, if the item spans multiple lines
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009818 pattern search pattern used to locate the error
9819 col column number
9820 vcol when non-zero: "col" is visual column
9821 when zero: "col" is byte index
Bram Moolenaara2baa732022-02-04 16:09:54 +00009822 end_col end column, if the item spans multiple columns
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009823 nr error number
9824 text description of the error
9825 type single-character error type, 'E', 'W', etc.
9826 valid recognized error message
Tom Praschanca6ac992023-08-11 23:26:12 +02009827 user_data custom data associated with the item, can be
9828 any type.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009829
9830 The "col", "vcol", "nr", "type" and "text" entries are
9831 optional. Either "lnum" or "pattern" entry can be used to
9832 locate a matching error line.
9833 If the "filename" and "bufnr" entries are not present or
9834 neither the "lnum" or "pattern" entries are present, then the
9835 item will not be handled as an error line.
9836 If both "pattern" and "lnum" are present then "pattern" will
9837 be used.
9838 If the "valid" entry is not supplied, then the valid flag is
9839 set when "bufnr" is a valid buffer or "filename" exists.
9840 If you supply an empty {list}, the quickfix list will be
9841 cleared.
9842 Note that the list is not exactly the same as what
9843 |getqflist()| returns.
9844
9845 {action} values: *setqflist-action* *E927*
9846 'a' The items from {list} are added to the existing
9847 quickfix list. If there is no existing list, then a
9848 new list is created.
9849
9850 'r' The items from the current quickfix list are replaced
9851 with the items from {list}. This can also be used to
9852 clear the list: >
9853 :call setqflist([], 'r')
9854<
Jeremy Fleischman27fbf6e2024-10-14 20:46:27 +02009855 'u' Like 'r', but tries to preserve the current selection
9856 in the quickfix list.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009857 'f' All the quickfix lists in the quickfix stack are
9858 freed.
9859
9860 If {action} is not present or is set to ' ', then a new list
9861 is created. The new quickfix list is added after the current
9862 quickfix list in the stack and all the following lists are
9863 freed. To add a new quickfix list at the end of the stack,
9864 set "nr" in {what} to "$".
9865
9866 The following items can be specified in dictionary {what}:
9867 context quickfix list context. See |quickfix-context|
9868 efm errorformat to use when parsing text from
9869 "lines". If this is not present, then the
9870 'errorformat' option value is used.
9871 See |quickfix-parse|
9872 id quickfix list identifier |quickfix-ID|
9873 idx index of the current entry in the quickfix
9874 list specified by 'id' or 'nr'. If set to '$',
9875 then the last entry in the list is set as the
9876 current entry. See |quickfix-index|
9877 items list of quickfix entries. Same as the {list}
9878 argument.
9879 lines use 'errorformat' to parse a list of lines and
9880 add the resulting entries to the quickfix list
9881 {nr} or {id}. Only a |List| value is supported.
9882 See |quickfix-parse|
9883 nr list number in the quickfix stack; zero
9884 means the current quickfix list and "$" means
9885 the last quickfix list.
9886 quickfixtextfunc
9887 function to get the text to display in the
9888 quickfix window. The value can be the name of
9889 a function or a funcref or a lambda. Refer to
9890 |quickfix-window-function| for an explanation
9891 of how to write the function and an example.
9892 title quickfix list title text. See |quickfix-title|
9893 Unsupported keys in {what} are ignored.
9894 If the "nr" item is not present, then the current quickfix list
9895 is modified. When creating a new quickfix list, "nr" can be
9896 set to a value one greater than the quickfix stack size.
9897 When modifying a quickfix list, to guarantee that the correct
9898 list is modified, "id" should be used instead of "nr" to
9899 specify the list.
9900
9901 Examples (See also |setqflist-examples|): >
9902 :call setqflist([], 'r', {'title': 'My search'})
9903 :call setqflist([], 'r', {'nr': 2, 'title': 'Errors'})
9904 :call setqflist([], 'a', {'id':qfid, 'lines':["F1:10:L10"]})
9905<
9906 Returns zero for success, -1 for failure.
9907
9908 This function can be used to create a quickfix list
9909 independent of the 'errorformat' setting. Use a command like
9910 `:cc 1` to jump to the first position.
9911
9912 Can also be used as a |method|, the base is passed as the
9913 second argument: >
9914 GetErrorlist()->setqflist()
9915<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009916 Return type: |Number|
9917
9918
9919setreg({regname}, {value} [, {options}]) *setreg()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009920 Set the register {regname} to {value}.
9921 If {regname} is "" or "@", the unnamed register '"' is used.
9922 The {regname} argument is a string. In |Vim9-script|
9923 {regname} must be one character.
9924
9925 {value} may be any value returned by |getreg()| or
9926 |getreginfo()|, including a |List| or |Dict|.
9927 If {options} contains "a" or {regname} is upper case,
9928 then the value is appended.
9929
9930 {options} can also contain a register type specification:
9931 "c" or "v" |characterwise| mode
9932 "l" or "V" |linewise| mode
9933 "b" or "<CTRL-V>" |blockwise-visual| mode
9934 If a number immediately follows "b" or "<CTRL-V>" then this is
9935 used as the width of the selection - if it is not specified
9936 then the width of the block is set to the number of characters
9937 in the longest line (counting a <Tab> as 1 character).
9938
9939 If {options} contains no register settings, then the default
9940 is to use character mode unless {value} ends in a <NL> for
9941 string {value} and linewise mode for list {value}. Blockwise
9942 mode is never selected automatically.
9943 Returns zero for success, non-zero for failure.
9944
9945 *E883*
9946 Note: you may not use |List| containing more than one item to
9947 set search and expression registers. Lists containing no
9948 items act like empty strings.
9949
9950 Examples: >
9951 :call setreg(v:register, @*)
9952 :call setreg('*', @%, 'ac')
9953 :call setreg('a', "1\n2\n3", 'b5')
9954 :call setreg('"', { 'points_to': 'a'})
9955
9956< This example shows using the functions to save and restore a
9957 register: >
9958 :let var_a = getreginfo()
9959 :call setreg('a', var_a)
9960< or: >
9961 :let var_a = getreg('a', 1, 1)
9962 :let var_amode = getregtype('a')
9963 ....
9964 :call setreg('a', var_a, var_amode)
9965< Note: you may not reliably restore register value
9966 without using the third argument to |getreg()| as without it
9967 newlines are represented as newlines AND Nul bytes are
9968 represented as newlines as well, see |NL-used-for-Nul|.
9969
9970 You can also change the type of a register by appending
9971 nothing: >
9972 :call setreg('a', '', 'al')
9973
9974< Can also be used as a |method|, the base is passed as the
9975 second argument: >
9976 GetText()->setreg('a')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009977<
9978 Return type: |Number|
9979
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009980
9981settabvar({tabnr}, {varname}, {val}) *settabvar()*
9982 Set tab-local variable {varname} to {val} in tab page {tabnr}.
9983 |t:var|
9984 The {varname} argument is a string.
9985 Note that autocommands are blocked, side effects may not be
9986 triggered, e.g. when setting 'filetype'.
9987 Note that the variable name without "t:" must be used.
9988 Tabs are numbered starting with one.
9989 This function is not available in the |sandbox|.
9990
9991 Can also be used as a |method|, the base is passed as the
9992 third argument: >
9993 GetValue()->settabvar(tab, name)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009994<
9995 Return type: |Number|
9996
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009997
9998settabwinvar({tabnr}, {winnr}, {varname}, {val}) *settabwinvar()*
9999 Set option or local variable {varname} in window {winnr} to
10000 {val}.
10001 Tabs are numbered starting with one. For the current tabpage
10002 use |setwinvar()|.
10003 {winnr} can be the window number or the |window-ID|.
10004 When {winnr} is zero the current window is used.
10005 Note that autocommands are blocked, side effects may not be
10006 triggered, e.g. when setting 'filetype' or 'syntax'.
10007 This also works for a global or local buffer option, but it
10008 doesn't work for a global or local buffer variable.
10009 For a local buffer option the global value is unchanged.
10010 Note that the variable name without "w:" must be used.
10011 Examples: >
10012 :call settabwinvar(1, 1, "&list", 0)
10013 :call settabwinvar(3, 2, "myvar", "foobar")
10014< This function is not available in the |sandbox|.
10015
10016 Can also be used as a |method|, the base is passed as the
10017 fourth argument: >
10018 GetValue()->settabwinvar(tab, winnr, name)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010019<
10020 Return type: |Number|
10021
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010022
10023settagstack({nr}, {dict} [, {action}]) *settagstack()*
10024 Modify the tag stack of the window {nr} using {dict}.
10025 {nr} can be the window number or the |window-ID|.
10026
10027 For a list of supported items in {dict}, refer to
10028 |gettagstack()|. "curidx" takes effect before changing the tag
10029 stack.
10030 *E962*
10031 How the tag stack is modified depends on the {action}
10032 argument:
10033 - If {action} is not present or is set to 'r', then the tag
10034 stack is replaced.
10035 - If {action} is set to 'a', then new entries from {dict} are
10036 pushed (added) onto the tag stack.
10037 - If {action} is set to 't', then all the entries from the
10038 current entry in the tag stack or "curidx" in {dict} are
10039 removed and then new entries are pushed to the stack.
10040
10041 The current index is set to one after the length of the tag
10042 stack after the modification.
10043
10044 Returns zero for success, -1 for failure.
10045
10046 Examples (for more examples see |tagstack-examples|):
10047 Empty the tag stack of window 3: >
10048 call settagstack(3, {'items' : []})
10049
10050< Save and restore the tag stack: >
10051 let stack = gettagstack(1003)
10052 " do something else
10053 call settagstack(1003, stack)
10054 unlet stack
10055<
10056 Can also be used as a |method|, the base is passed as the
10057 second argument: >
10058 GetStack()->settagstack(winnr)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010059<
10060 Return type: |Number|
10061
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010062
10063setwinvar({winnr}, {varname}, {val}) *setwinvar()*
10064 Like |settabwinvar()| for the current tab page.
10065 Examples: >
10066 :call setwinvar(1, "&list", 0)
10067 :call setwinvar(2, "myvar", "foobar")
10068
10069< Can also be used as a |method|, the base is passed as the
10070 third argument: >
10071 GetValue()->setwinvar(winnr, name)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010072<
10073 Return type: |Number|
10074
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010075
10076sha256({string}) *sha256()*
10077 Returns a String with 64 hex characters, which is the SHA256
10078 checksum of {string}.
10079
10080 Can also be used as a |method|: >
10081 GetText()->sha256()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010082<
10083 Return type: |String|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010084
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010085 {only available when compiled with the |+cryptv| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010086
10087shellescape({string} [, {special}]) *shellescape()*
10088 Escape {string} for use as a shell command argument.
10089 When the 'shell' contains powershell (MS-Windows) or pwsh
Bram Moolenaar944697a2022-02-20 19:48:20 +000010090 (MS-Windows, Linux, and macOS) then it will enclose {string}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010091 in single quotes and will double up all internal single
10092 quotes.
10093 On MS-Windows, when 'shellslash' is not set, it will enclose
10094 {string} in double quotes and double all double quotes within
10095 {string}.
10096 Otherwise it will enclose {string} in single quotes and
10097 replace all "'" with "'\''".
10098
Enno5faeb602024-05-15 21:54:19 +020010099 The {special} argument adds additional escaping of keywords
10100 used in Vim commands. When it is not omitted and a non-zero
K.Takatac0e038b2024-05-16 12:39:01 +090010101 number or a non-empty String (|non-zero-arg|), then special
10102 items such as "!", "%", "#" and "<cword>" (as listed in
10103 |expand()|) will be preceded by a backslash.
Enno5faeb602024-05-15 21:54:19 +020010104 This backslash will be removed again by the |:!| command.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010105
10106 The "!" character will be escaped (again with a |non-zero-arg|
10107 {special}) when 'shell' contains "csh" in the tail. That is
10108 because for csh and tcsh "!" is used for history replacement
10109 even when inside single quotes.
10110
10111 With a |non-zero-arg| {special} the <NL> character is also
10112 escaped. When 'shell' containing "csh" in the tail it's
10113 escaped a second time.
10114
10115 The "\" character will be escaped when 'shell' contains "fish"
10116 in the tail. That is because for fish "\" is used as an escape
10117 character inside single quotes.
10118
10119 Example of use with a |:!| command: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +000010120 :exe '!dir ' .. shellescape(expand('<cfile>'), 1)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010121< This results in a directory listing for the file under the
10122 cursor. Example of use with |system()|: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +000010123 :call system("chmod +w -- " .. shellescape(expand("%")))
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010124< See also |::S|.
10125
10126 Can also be used as a |method|: >
10127 GetCommand()->shellescape()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010128<
10129 Return type: |String|
10130
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010131
10132shiftwidth([{col}]) *shiftwidth()*
10133 Returns the effective value of 'shiftwidth'. This is the
10134 'shiftwidth' value unless it is zero, in which case it is the
10135 'tabstop' value. This function was introduced with patch
10136 7.3.694 in 2012, everybody should have it by now (however it
10137 did not allow for the optional {col} argument until 8.1.542).
10138
10139 When there is one argument {col} this is used as column number
10140 for which to return the 'shiftwidth' value. This matters for the
10141 'vartabstop' feature. If the 'vartabstop' setting is enabled and
10142 no {col} argument is given, column 1 will be assumed.
10143
10144 Can also be used as a |method|: >
10145 GetColumn()->shiftwidth()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010146<
10147 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010148
10149sign_ functions are documented here: |sign-functions-details|
10150
10151
10152simplify({filename}) *simplify()*
10153 Simplify the file name as much as possible without changing
10154 the meaning. Shortcuts (on MS-Windows) or symbolic links (on
10155 Unix) are not resolved. If the first path component in
10156 {filename} designates the current directory, this will be
10157 valid for the result as well. A trailing path separator is
10158 not removed either. On Unix "//path" is unchanged, but
10159 "///path" is simplified to "/path" (this follows the Posix
10160 standard).
10161 Example: >
10162 simplify("./dir/.././/file/") == "./file/"
10163< Note: The combination "dir/.." is only removed if "dir" is
10164 a searchable directory or does not exist. On Unix, it is also
10165 removed when "dir" is a symbolic link within the same
10166 directory. In order to resolve all the involved symbolic
10167 links before simplifying the path name, use |resolve()|.
10168
10169 Can also be used as a |method|: >
10170 GetName()->simplify()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010171<
10172 Return type: |String|
10173
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010174
10175sin({expr}) *sin()*
10176 Return the sine of {expr}, measured in radians, as a |Float|.
10177 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +010010178 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010179 Examples: >
10180 :echo sin(100)
10181< -0.506366 >
10182 :echo sin(-4.01)
10183< 0.763301
10184
10185 Can also be used as a |method|: >
10186 Compute()->sin()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010187<
10188 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010189
10190
10191sinh({expr}) *sinh()*
10192 Return the hyperbolic sine of {expr} as a |Float| in the range
10193 [-inf, inf].
10194 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +010010195 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010196 Examples: >
10197 :echo sinh(0.5)
10198< 0.521095 >
10199 :echo sinh(-0.9)
10200< -1.026517
10201
10202 Can also be used as a |method|: >
10203 Compute()->sinh()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010204<
10205 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010206
10207
10208slice({expr}, {start} [, {end}]) *slice()*
10209 Similar to using a |slice| "expr[start : end]", but "end" is
10210 used exclusive. And for a string the indexes are used as
10211 character indexes instead of byte indexes, like in
zeertzjqad387692024-03-23 08:23:48 +010010212 |vim9script|. Also, composing characters are treated as a
10213 part of the preceding base character.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010214 When {end} is omitted the slice continues to the last item.
10215 When {end} is -1 the last item is omitted.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +010010216 Returns an empty value if {start} or {end} are invalid.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010217
10218 Can also be used as a |method|: >
10219 GetList()->slice(offset)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010220<
10221 Return type: list<{type}>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010222
10223
Bram Moolenaar2007dd42022-02-23 13:17:47 +000010224sort({list} [, {how} [, {dict}]]) *sort()* *E702*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010225 Sort the items in {list} in-place. Returns {list}.
10226
10227 If you want a list to remain unmodified make a copy first: >
10228 :let sortedlist = sort(copy(mylist))
10229
Bram Moolenaar2d8ed022022-05-21 13:08:16 +010010230< When {how} is omitted or is a string, then sort() uses the
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010231 string representation of each item to sort on. Numbers sort
10232 after Strings, |Lists| after Numbers. For sorting text in the
10233 current buffer use |:sort|.
10234
Bram Moolenaar2007dd42022-02-23 13:17:47 +000010235 When {how} is given and it is 'i' then case is ignored.
10236 In legacy script, for backwards compatibility, the value one
10237 can be used to ignore case. Zero means to not ignore case.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010238
Bram Moolenaar2007dd42022-02-23 13:17:47 +000010239 When {how} is given and it is 'l' then the current collation
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010240 locale is used for ordering. Implementation details: strcoll()
10241 is used to compare strings. See |:language| check or set the
10242 collation locale. |v:collate| can also be used to check the
10243 current locale. Sorting using the locale typically ignores
10244 case. Example: >
10245 " ö is sorted similarly to o with English locale.
10246 :language collate en_US.UTF8
10247 :echo sort(['n', 'o', 'O', 'ö', 'p', 'z'], 'l')
10248< ['n', 'o', 'O', 'ö', 'p', 'z'] ~
10249>
10250 " ö is sorted after z with Swedish locale.
10251 :language collate sv_SE.UTF8
10252 :echo sort(['n', 'o', 'O', 'ö', 'p', 'z'], 'l')
10253< ['n', 'o', 'O', 'p', 'z', 'ö'] ~
10254 This does not work properly on Mac.
10255
Bram Moolenaar2007dd42022-02-23 13:17:47 +000010256 When {how} is given and it is 'n' then all items will be
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010257 sorted numerical (Implementation detail: this uses the
Bram Moolenaarbe19d782023-03-09 22:06:49 +000010258 strtod() function to parse numbers. Strings, Lists, Dicts and
10259 Funcrefs will be considered as being 0). Note that this won't
10260 sort a list of strings with numbers!
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010261
Bram Moolenaar2007dd42022-02-23 13:17:47 +000010262 When {how} is given and it is 'N' then all items will be
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010263 sorted numerical. This is like 'n' but a string containing
10264 digits will be used as the number they represent.
10265
Bram Moolenaar2007dd42022-02-23 13:17:47 +000010266 When {how} is given and it is 'f' then all items will be
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010267 sorted numerical. All values must be a Number or a Float.
10268
Bram Moolenaar2007dd42022-02-23 13:17:47 +000010269 When {how} is a |Funcref| or a function name, this function
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010270 is called to compare items. The function is invoked with two
10271 items as argument and must return zero if they are equal, 1 or
10272 bigger if the first one sorts after the second one, -1 or
10273 smaller if the first one sorts before the second one.
10274
10275 {dict} is for functions with the "dict" attribute. It will be
10276 used to set the local variable "self". |Dictionary-function|
10277
10278 The sort is stable, items which compare equal (as number or as
10279 string) will keep their relative position. E.g., when sorting
10280 on numbers, text strings will sort next to each other, in the
10281 same order as they were originally.
10282
10283 Can also be used as a |method|: >
10284 mylist->sort()
10285
10286< Also see |uniq()|.
10287
10288 Example: >
10289 func MyCompare(i1, i2)
10290 return a:i1 == a:i2 ? 0 : a:i1 > a:i2 ? 1 : -1
10291 endfunc
10292 eval mylist->sort("MyCompare")
10293< A shorter compare version for this specific simple case, which
10294 ignores overflow: >
10295 func MyCompare(i1, i2)
10296 return a:i1 - a:i2
10297 endfunc
10298< For a simple expression you can use a lambda: >
10299 eval mylist->sort({i1, i2 -> i1 - i2})
10300<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010301 Return type: list<{type}>
10302
10303
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010304sound_clear() *sound_clear()*
10305 Stop playing all sounds.
10306
10307 On some Linux systems you may need the libcanberra-pulse
10308 package, otherwise sound may not stop.
10309
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010310 Return type: |Number|
10311
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010312 {only available when compiled with the |+sound| feature}
10313
10314 *sound_playevent()*
10315sound_playevent({name} [, {callback}])
10316 Play a sound identified by {name}. Which event names are
10317 supported depends on the system. Often the XDG sound names
10318 are used. On Ubuntu they may be found in
10319 /usr/share/sounds/freedesktop/stereo. Example: >
10320 call sound_playevent('bell')
10321< On MS-Windows, {name} can be SystemAsterisk, SystemDefault,
10322 SystemExclamation, SystemExit, SystemHand, SystemQuestion,
10323 SystemStart, SystemWelcome, etc.
Yee Cheng Chin4314e4f2022-10-08 13:50:05 +010010324 On macOS, {name} refers to files located in
10325 /System/Library/Sounds (e.g. "Tink"). It will also work for
10326 custom installed sounds in folders like ~/Library/Sounds.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010327
10328 When {callback} is specified it is invoked when the sound is
10329 finished. The first argument is the sound ID, the second
10330 argument is the status:
10331 0 sound was played to the end
10332 1 sound was interrupted
10333 2 error occurred after sound started
10334 Example: >
10335 func Callback(id, status)
10336 echomsg "sound " .. a:id .. " finished with " .. a:status
10337 endfunc
10338 call sound_playevent('bell', 'Callback')
10339
10340< MS-Windows: {callback} doesn't work for this function.
10341
10342 Returns the sound ID, which can be passed to `sound_stop()`.
10343 Returns zero if the sound could not be played.
10344
10345 Can also be used as a |method|: >
10346 GetSoundName()->sound_playevent()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010347<
10348 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010349
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010350 {only available when compiled with the |+sound| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010351
10352 *sound_playfile()*
10353sound_playfile({path} [, {callback}])
10354 Like `sound_playevent()` but play sound file {path}. {path}
10355 must be a full path. On Ubuntu you may find files to play
10356 with this command: >
10357 :!find /usr/share/sounds -type f | grep -v index.theme
10358
10359< Can also be used as a |method|: >
10360 GetSoundPath()->sound_playfile()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010361<
10362 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010363
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010364 {only available when compiled with the |+sound| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010365
10366
10367sound_stop({id}) *sound_stop()*
10368 Stop playing sound {id}. {id} must be previously returned by
10369 `sound_playevent()` or `sound_playfile()`.
10370
10371 On some Linux systems you may need the libcanberra-pulse
10372 package, otherwise sound may not stop.
10373
10374 On MS-Windows, this does not work for event sound started by
10375 `sound_playevent()`. To stop event sounds, use `sound_clear()`.
10376
10377 Can also be used as a |method|: >
10378 soundid->sound_stop()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010379<
10380 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010381
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010382 {only available when compiled with the |+sound| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010383
10384 *soundfold()*
10385soundfold({word})
10386 Return the sound-folded equivalent of {word}. Uses the first
10387 language in 'spelllang' for the current window that supports
10388 soundfolding. 'spell' must be set. When no sound folding is
10389 possible the {word} is returned unmodified.
10390 This can be used for making spelling suggestions. Note that
10391 the method can be quite slow.
10392
10393 Can also be used as a |method|: >
10394 GetWord()->soundfold()
10395<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010396 Return type: |String|
10397
10398
10399spellbadword([{sentence}]) *spellbadword()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010400 Without argument: The result is the badly spelled word under
10401 or after the cursor. The cursor is moved to the start of the
10402 bad word. When no bad word is found in the cursor line the
10403 result is an empty string and the cursor doesn't move.
10404
10405 With argument: The result is the first word in {sentence} that
10406 is badly spelled. If there are no spelling mistakes the
10407 result is an empty string.
10408
10409 The return value is a list with two items:
10410 - The badly spelled word or an empty string.
10411 - The type of the spelling error:
10412 "bad" spelling mistake
10413 "rare" rare word
10414 "local" word only valid in another region
10415 "caps" word should start with Capital
10416 Example: >
10417 echo spellbadword("the quik brown fox")
10418< ['quik', 'bad'] ~
10419
10420 The spelling information for the current window and the value
10421 of 'spelllang' are used.
10422
10423 Can also be used as a |method|: >
10424 GetText()->spellbadword()
10425<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010426 Return type: list<string>
10427
10428
10429spellsuggest({word} [, {max} [, {capital}]]) *spellsuggest()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010430 Return a |List| with spelling suggestions to replace {word}.
10431 When {max} is given up to this number of suggestions are
10432 returned. Otherwise up to 25 suggestions are returned.
10433
10434 When the {capital} argument is given and it's non-zero only
10435 suggestions with a leading capital will be given. Use this
10436 after a match with 'spellcapcheck'.
10437
10438 {word} can be a badly spelled word followed by other text.
10439 This allows for joining two words that were split. The
10440 suggestions also include the following text, thus you can
10441 replace a line.
10442
10443 {word} may also be a good word. Similar words will then be
10444 returned. {word} itself is not included in the suggestions,
10445 although it may appear capitalized.
10446
10447 The spelling information for the current window is used. The
10448 values of 'spelllang' and 'spellsuggest' are used.
10449
10450 Can also be used as a |method|: >
10451 GetWord()->spellsuggest()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010452<
10453 Return type: list<string> or list<any>
10454
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010455
10456split({string} [, {pattern} [, {keepempty}]]) *split()*
10457 Make a |List| out of {string}. When {pattern} is omitted or
Shane Harperc1b39842024-07-17 19:40:40 +020010458 empty each white space separated sequence of characters
10459 becomes an item.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010460 Otherwise the string is split where {pattern} matches,
10461 removing the matched characters. 'ignorecase' is not used
10462 here, add \c to ignore case. |/\c|
10463 When the first or last item is empty it is omitted, unless the
10464 {keepempty} argument is given and it's non-zero.
10465 Other empty items are kept when {pattern} matches at least one
10466 character or when {keepempty} is non-zero.
10467 Example: >
10468 :let words = split(getline('.'), '\W\+')
10469< To split a string in individual characters: >
10470 :for c in split(mystring, '\zs')
10471< If you want to keep the separator you can also use '\zs' at
10472 the end of the pattern: >
10473 :echo split('abc:def:ghi', ':\zs')
10474< ['abc:', 'def:', 'ghi'] ~
10475 Splitting a table where the first element can be empty: >
10476 :let items = split(line, ':', 1)
10477< The opposite function is |join()|.
10478
10479 Can also be used as a |method|: >
10480 GetString()->split()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010481<
10482 Return type: list<string>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010483
10484sqrt({expr}) *sqrt()*
10485 Return the non-negative square root of Float {expr} as a
10486 |Float|.
10487 {expr} must evaluate to a |Float| or a |Number|. When {expr}
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +010010488 is negative the result is NaN (Not a Number). Returns 0.0 if
10489 {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010490 Examples: >
10491 :echo sqrt(100)
10492< 10.0 >
10493 :echo sqrt(-4.01)
10494< nan
10495 "nan" may be different, it depends on system libraries.
10496
10497 Can also be used as a |method|: >
10498 Compute()->sqrt()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010499<
10500 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010501
10502
10503srand([{expr}]) *srand()*
10504 Initialize seed used by |rand()|:
10505 - If {expr} is not given, seed values are initialized by
10506 reading from /dev/urandom, if possible, or using time(NULL)
10507 a.k.a. epoch time otherwise; this only has second accuracy.
10508 - If {expr} is given it must be a Number. It is used to
10509 initialize the seed values. This is useful for testing or
10510 when a predictable sequence is intended.
10511
10512 Examples: >
10513 :let seed = srand()
10514 :let seed = srand(userinput)
10515 :echo rand(seed)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010516<
10517 Return type: list<number>
10518
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010519
10520state([{what}]) *state()*
10521 Return a string which contains characters indicating the
10522 current state. Mostly useful in callbacks that want to do
10523 work that may not always be safe. Roughly this works like:
10524 - callback uses state() to check if work is safe to do.
10525 Yes: then do it right away.
10526 No: add to work queue and add a |SafeState| and/or
10527 |SafeStateAgain| autocommand (|SafeState| triggers at
10528 toplevel, |SafeStateAgain| triggers after handling
10529 messages and callbacks).
10530 - When SafeState or SafeStateAgain is triggered and executes
10531 your autocommand, check with `state()` if the work can be
10532 done now, and if yes remove it from the queue and execute.
10533 Remove the autocommand if the queue is now empty.
10534 Also see |mode()|.
10535
10536 When {what} is given only characters in this string will be
10537 added. E.g, this checks if the screen has scrolled: >
10538 if state('s') == ''
10539 " screen has not scrolled
10540<
10541 These characters indicate the state, generally indicating that
10542 something is busy:
10543 m halfway a mapping, :normal command, feedkeys() or
10544 stuffed command
10545 o operator pending, e.g. after |d|
10546 a Insert mode autocomplete active
10547 x executing an autocommand
10548 w blocked on waiting, e.g. ch_evalexpr(), ch_read() and
10549 ch_readraw() when reading json
10550 S not triggering SafeState or SafeStateAgain, e.g. after
10551 |f| or a count
10552 c callback invoked, including timer (repeats for
10553 recursiveness up to "ccc")
10554 s screen has scrolled for messages
10555
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010556 Return type: |String|
10557
10558
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010559str2float({string} [, {quoted}]) *str2float()*
10560 Convert String {string} to a Float. This mostly works the
10561 same as when using a floating point number in an expression,
10562 see |floating-point-format|. But it's a bit more permissive.
10563 E.g., "1e40" is accepted, while in an expression you need to
10564 write "1.0e40". The hexadecimal form "0x123" is also
10565 accepted, but not others, like binary or octal.
10566 When {quoted} is present and non-zero then embedded single
10567 quotes before the dot are ignored, thus "1'000.0" is a
10568 thousand.
10569 Text after the number is silently ignored.
10570 The decimal point is always '.', no matter what the locale is
10571 set to. A comma ends the number: "12,345.67" is converted to
10572 12.0. You can strip out thousands separators with
10573 |substitute()|: >
10574 let f = str2float(substitute(text, ',', '', 'g'))
10575<
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +010010576 Returns 0.0 if the conversion fails.
10577
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010578 Can also be used as a |method|: >
10579 let f = text->substitute(',', '', 'g')->str2float()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010580<
10581 Return type: |Float|
10582
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010583
10584str2list({string} [, {utf8}]) *str2list()*
10585 Return a list containing the number values which represent
10586 each character in String {string}. Examples: >
10587 str2list(" ") returns [32]
10588 str2list("ABC") returns [65, 66, 67]
10589< |list2str()| does the opposite.
10590
10591 When {utf8} is omitted or zero, the current 'encoding' is used.
10592 When {utf8} is TRUE, always treat the String as UTF-8
10593 characters. With UTF-8 composing characters are handled
10594 properly: >
10595 str2list("á") returns [97, 769]
10596
10597< Can also be used as a |method|: >
10598 GetString()->str2list()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010599<
10600 Return type: list<number>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010601
10602
10603str2nr({string} [, {base} [, {quoted}]]) *str2nr()*
10604 Convert string {string} to a number.
10605 {base} is the conversion base, it can be 2, 8, 10 or 16.
10606 When {quoted} is present and non-zero then embedded single
10607 quotes are ignored, thus "1'000'000" is a million.
10608
10609 When {base} is omitted base 10 is used. This also means that
10610 a leading zero doesn't cause octal conversion to be used, as
10611 with the default String to Number conversion. Example: >
10612 let nr = str2nr('0123')
10613<
10614 When {base} is 16 a leading "0x" or "0X" is ignored. With a
10615 different base the result will be zero. Similarly, when
10616 {base} is 8 a leading "0", "0o" or "0O" is ignored, and when
10617 {base} is 2 a leading "0b" or "0B" is ignored.
10618 Text after the number is silently ignored.
10619
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +010010620 Returns 0 if {string} is empty or on error.
10621
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010622 Can also be used as a |method|: >
10623 GetText()->str2nr()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010624<
10625 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010626
10627
10628strcharlen({string}) *strcharlen()*
10629 The result is a Number, which is the number of characters
10630 in String {string}. Composing characters are ignored.
10631 |strchars()| can count the number of characters, counting
10632 composing characters separately.
10633
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +010010634 Returns 0 if {string} is empty or on error.
10635
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010636 Also see |strlen()|, |strdisplaywidth()| and |strwidth()|.
10637
10638 Can also be used as a |method|: >
10639 GetText()->strcharlen()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010640<
10641 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010642
10643
10644strcharpart({src}, {start} [, {len} [, {skipcc}]]) *strcharpart()*
10645 Like |strpart()| but using character index and length instead
10646 of byte index and length.
10647 When {skipcc} is omitted or zero, composing characters are
10648 counted separately.
zeertzjqad387692024-03-23 08:23:48 +010010649 When {skipcc} set to 1, composing characters are treated as a
10650 part of the preceding base character, similar to |slice()|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010651 When a character index is used where a character does not
10652 exist it is omitted and counted as one character. For
10653 example: >
10654 strcharpart('abc', -1, 2)
10655< results in 'a'.
10656
Bram Moolenaard592deb2022-06-17 15:42:40 +010010657 Returns an empty string on error.
10658
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010659 Can also be used as a |method|: >
10660 GetText()->strcharpart(5)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010661<
10662 Return type: |String|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010663
10664
10665strchars({string} [, {skipcc}]) *strchars()*
10666 The result is a Number, which is the number of characters
10667 in String {string}.
10668 When {skipcc} is omitted or zero, composing characters are
10669 counted separately.
zeertzjqad387692024-03-23 08:23:48 +010010670 When {skipcc} set to 1, composing characters are ignored.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010671 |strcharlen()| always does this.
10672
Bram Moolenaard592deb2022-06-17 15:42:40 +010010673 Returns zero on error.
10674
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010675 Also see |strlen()|, |strdisplaywidth()| and |strwidth()|.
10676
10677 {skipcc} is only available after 7.4.755. For backward
10678 compatibility, you can define a wrapper function: >
10679 if has("patch-7.4.755")
10680 function s:strchars(str, skipcc)
10681 return strchars(a:str, a:skipcc)
10682 endfunction
10683 else
10684 function s:strchars(str, skipcc)
10685 if a:skipcc
10686 return strlen(substitute(a:str, ".", "x", "g"))
10687 else
10688 return strchars(a:str)
10689 endif
10690 endfunction
10691 endif
10692<
10693 Can also be used as a |method|: >
10694 GetText()->strchars()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010695<
10696 Return type: |Number|
10697
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010698
10699strdisplaywidth({string} [, {col}]) *strdisplaywidth()*
10700 The result is a Number, which is the number of display cells
10701 String {string} occupies on the screen when it starts at {col}
10702 (first column is zero). When {col} is omitted zero is used.
10703 Otherwise it is the screen column where to start. This
10704 matters for Tab characters.
10705 The option settings of the current window are used. This
10706 matters for anything that's displayed differently, such as
10707 'tabstop' and 'display'.
10708 When {string} contains characters with East Asian Width Class
10709 Ambiguous, this function's return value depends on 'ambiwidth'.
Bram Moolenaard592deb2022-06-17 15:42:40 +010010710 Returns zero on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010711 Also see |strlen()|, |strwidth()| and |strchars()|.
10712
10713 Can also be used as a |method|: >
10714 GetText()->strdisplaywidth()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010715<
10716 Return type: |Number|
10717
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010718
10719strftime({format} [, {time}]) *strftime()*
10720 The result is a String, which is a formatted date and time, as
10721 specified by the {format} string. The given {time} is used,
10722 or the current time if no time is given. The accepted
10723 {format} depends on your system, thus this is not portable!
10724 See the manual page of the C function strftime() for the
10725 format. The maximum length of the result is 80 characters.
10726 See also |localtime()|, |getftime()| and |strptime()|.
10727 The language can be changed with the |:language| command.
10728 Examples: >
10729 :echo strftime("%c") Sun Apr 27 11:49:23 1997
10730 :echo strftime("%Y %b %d %X") 1997 Apr 27 11:53:25
10731 :echo strftime("%y%m%d %T") 970427 11:53:55
10732 :echo strftime("%H:%M") 11:55
10733 :echo strftime("%c", getftime("file.c"))
10734 Show mod time of file.c.
10735< Not available on all systems. To check use: >
10736 :if exists("*strftime")
10737
10738< Can also be used as a |method|: >
10739 GetFormat()->strftime()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010740<
10741 Return type: |String|
10742
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010743
10744strgetchar({str}, {index}) *strgetchar()*
Bram Moolenaar2d8ed022022-05-21 13:08:16 +010010745 Get a Number corresponding to the character at {index} in
10746 {str}. This uses a zero-based character index, not a byte
10747 index. Composing characters are considered separate
10748 characters here. Use |nr2char()| to convert the Number to a
10749 String.
Bram Moolenaard592deb2022-06-17 15:42:40 +010010750 Returns -1 if {index} is invalid.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010751 Also see |strcharpart()| and |strchars()|.
10752
10753 Can also be used as a |method|: >
10754 GetText()->strgetchar(5)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010755<
10756 Return type: |Number|
10757
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010758
10759stridx({haystack}, {needle} [, {start}]) *stridx()*
10760 The result is a Number, which gives the byte index in
10761 {haystack} of the first occurrence of the String {needle}.
10762 If {start} is specified, the search starts at index {start}.
10763 This can be used to find a second match: >
10764 :let colon1 = stridx(line, ":")
10765 :let colon2 = stridx(line, ":", colon1 + 1)
10766< The search is done case-sensitive.
10767 For pattern searches use |match()|.
10768 -1 is returned if the {needle} does not occur in {haystack}.
10769 See also |strridx()|.
10770 Examples: >
10771 :echo stridx("An Example", "Example") 3
10772 :echo stridx("Starting point", "Start") 0
10773 :echo stridx("Starting point", "start") -1
10774< *strstr()* *strchr()*
10775 stridx() works similar to the C function strstr(). When used
10776 with a single character it works similar to strchr().
10777
10778 Can also be used as a |method|: >
10779 GetHaystack()->stridx(needle)
10780<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010781 Return type: |Number|
10782
10783
10784string({expr}) *string()*
10785 Return {expr} converted to a String. If {expr} is a Number,
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010786 Float, String, Blob or a composition of them, then the result
10787 can be parsed back with |eval()|.
10788 {expr} type result ~
10789 String 'string' (single quotes are doubled)
10790 Number 123
10791 Float 123.123456 or 1.123456e8
10792 Funcref function('name')
10793 Blob 0z00112233.44556677.8899
10794 List [item, item]
10795 Dictionary {key: value, key: value}
Bram Moolenaarf1dcd142022-12-31 15:30:45 +000010796 Class class SomeName
10797 Object object of SomeName {lnum: 1, col: 3}
Yegappan Lakshmanan3164cf82024-03-28 10:36:42 +010010798 Enum enum EnumName
Yegappan Lakshmanan3cf121e2024-03-31 18:45:35 +020010799 EnumValue enum name.value {name: str, ordinal: nr}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010800
10801 When a |List| or |Dictionary| has a recursive reference it is
10802 replaced by "[...]" or "{...}". Using eval() on the result
10803 will then fail.
10804
mityu7f0bba22024-03-29 10:14:41 +010010805 For an object, invokes the string() method to get a textual
Yegappan Lakshmanand3eae7b2024-03-03 16:26:58 +010010806 representation of the object. If the method is not present,
mityu7f0bba22024-03-29 10:14:41 +010010807 then the default representation is used. |object-string()|
Yegappan Lakshmanand3eae7b2024-03-03 16:26:58 +010010808
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010809 Can also be used as a |method|: >
10810 mylist->string()
10811
10812< Also see |strtrans()|.
10813
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010814 Return type: |String|
10815
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010816
10817strlen({string}) *strlen()*
10818 The result is a Number, which is the length of the String
10819 {string} in bytes.
10820 If the argument is a Number it is first converted to a String.
Bram Moolenaard592deb2022-06-17 15:42:40 +010010821 For other types an error is given and zero is returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010822 If you want to count the number of multibyte characters use
10823 |strchars()|.
10824 Also see |len()|, |strdisplaywidth()| and |strwidth()|.
10825
10826 Can also be used as a |method|: >
10827 GetString()->strlen()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010828<
10829 Return type: |Number|
10830
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010831
10832strpart({src}, {start} [, {len} [, {chars}]]) *strpart()*
10833 The result is a String, which is part of {src}, starting from
10834 byte {start}, with the byte length {len}.
10835 When {chars} is present and TRUE then {len} is the number of
10836 characters positions (composing characters are not counted
10837 separately, thus "1" means one base character and any
10838 following composing characters).
10839 To count {start} as characters instead of bytes use
10840 |strcharpart()|.
10841
10842 When bytes are selected which do not exist, this doesn't
10843 result in an error, the bytes are simply omitted.
10844 If {len} is missing, the copy continues from {start} till the
10845 end of the {src}. >
10846 strpart("abcdefg", 3, 2) == "de"
10847 strpart("abcdefg", -2, 4) == "ab"
10848 strpart("abcdefg", 5, 4) == "fg"
10849 strpart("abcdefg", 3) == "defg"
10850
10851< Note: To get the first character, {start} must be 0. For
10852 example, to get the character under the cursor: >
10853 strpart(getline("."), col(".") - 1, 1, v:true)
10854<
Bram Moolenaard592deb2022-06-17 15:42:40 +010010855 Returns an empty string on error.
10856
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010857 Can also be used as a |method|: >
10858 GetText()->strpart(5)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010859<
10860 Return type: |String|
10861
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010862
10863strptime({format}, {timestring}) *strptime()*
10864 The result is a Number, which is a unix timestamp representing
10865 the date and time in {timestring}, which is expected to match
10866 the format specified in {format}.
10867
10868 The accepted {format} depends on your system, thus this is not
10869 portable! See the manual page of the C function strptime()
10870 for the format. Especially avoid "%c". The value of $TZ also
10871 matters.
10872
10873 If the {timestring} cannot be parsed with {format} zero is
10874 returned. If you do not know the format of {timestring} you
10875 can try different {format} values until you get a non-zero
10876 result.
10877
10878 See also |strftime()|.
10879 Examples: >
10880 :echo strptime("%Y %b %d %X", "1997 Apr 27 11:49:23")
10881< 862156163 >
10882 :echo strftime("%c", strptime("%y%m%d %T", "970427 11:53:55"))
10883< Sun Apr 27 11:53:55 1997 >
10884 :echo strftime("%c", strptime("%Y%m%d%H%M%S", "19970427115355") + 3600)
10885< Sun Apr 27 12:53:55 1997
10886
10887 Can also be used as a |method|: >
10888 GetFormat()->strptime(timestring)
10889<
10890 Not available on all systems. To check use: >
10891 :if exists("*strptime")
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010892<
10893 Return type: |Number|
10894
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010895
10896strridx({haystack}, {needle} [, {start}]) *strridx()*
10897 The result is a Number, which gives the byte index in
10898 {haystack} of the last occurrence of the String {needle}.
10899 When {start} is specified, matches beyond this index are
10900 ignored. This can be used to find a match before a previous
10901 match: >
10902 :let lastcomma = strridx(line, ",")
10903 :let comma2 = strridx(line, ",", lastcomma - 1)
10904< The search is done case-sensitive.
10905 For pattern searches use |match()|.
10906 -1 is returned if the {needle} does not occur in {haystack}.
10907 If the {needle} is empty the length of {haystack} is returned.
10908 See also |stridx()|. Examples: >
10909 :echo strridx("an angry armadillo", "an") 3
10910< *strrchr()*
10911 When used with a single character it works similar to the C
10912 function strrchr().
10913
10914 Can also be used as a |method|: >
10915 GetHaystack()->strridx(needle)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010916<
10917 Return type: |Number|
10918
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010919
10920strtrans({string}) *strtrans()*
10921 The result is a String, which is {string} with all unprintable
10922 characters translated into printable characters |'isprint'|.
10923 Like they are shown in a window. Example: >
10924 echo strtrans(@a)
10925< This displays a newline in register a as "^@" instead of
10926 starting a new line.
10927
Bram Moolenaard592deb2022-06-17 15:42:40 +010010928 Returns an empty string on error.
10929
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010930 Can also be used as a |method|: >
10931 GetString()->strtrans()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010932<
10933 Return type: |String|
10934
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010935
Christian Brabandt67672ef2023-04-24 21:09:54 +010010936strutf16len({string} [, {countcc}]) *strutf16len()*
10937 The result is a Number, which is the number of UTF-16 code
10938 units in String {string} (after converting it to UTF-16).
10939
10940 When {countcc} is TRUE, composing characters are counted
10941 separately.
10942 When {countcc} is omitted or FALSE, composing characters are
10943 ignored.
10944
10945 Returns zero on error.
10946
10947 Also see |strlen()| and |strcharlen()|.
10948 Examples: >
10949 echo strutf16len('a') returns 1
10950 echo strutf16len('©') returns 1
10951 echo strutf16len('😊') returns 2
10952 echo strutf16len('ą́') returns 1
10953 echo strutf16len('ą́', v:true) returns 3
a5ob7r790f9a82023-09-25 06:05:47 +090010954<
Christian Brabandt67672ef2023-04-24 21:09:54 +010010955 Can also be used as a |method|: >
10956 GetText()->strutf16len()
10957<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010958 Return type: |Number|
10959
10960
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010961strwidth({string}) *strwidth()*
10962 The result is a Number, which is the number of display cells
10963 String {string} occupies. A Tab character is counted as one
10964 cell, alternatively use |strdisplaywidth()|.
10965 When {string} contains characters with East Asian Width Class
10966 Ambiguous, this function's return value depends on 'ambiwidth'.
Bram Moolenaard592deb2022-06-17 15:42:40 +010010967 Returns zero on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010968 Also see |strlen()|, |strdisplaywidth()| and |strchars()|.
10969
10970 Can also be used as a |method|: >
10971 GetString()->strwidth()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010972<
10973 Return type: |Number|
10974
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010975
10976submatch({nr} [, {list}]) *submatch()* *E935*
10977 Only for an expression in a |:substitute| command or
10978 substitute() function.
10979 Returns the {nr}'th submatch of the matched text. When {nr}
10980 is 0 the whole matched text is returned.
10981 Note that a NL in the string can stand for a line break of a
10982 multi-line match or a NUL character in the text.
10983 Also see |sub-replace-expression|.
10984
10985 If {list} is present and non-zero then submatch() returns
10986 a list of strings, similar to |getline()| with two arguments.
10987 NL characters in the text represent NUL characters in the
10988 text.
10989 Only returns more than one item for |:substitute|, inside
10990 |substitute()| this list will always contain one or zero
10991 items, since there are no real line breaks.
10992
10993 When substitute() is used recursively only the submatches in
10994 the current (deepest) call can be obtained.
10995
Bram Moolenaard592deb2022-06-17 15:42:40 +010010996 Returns an empty string or list on error.
10997
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010998 Examples: >
10999 :s/\d\+/\=submatch(0) + 1/
11000 :echo substitute(text, '\d\+', '\=submatch(0) + 1', '')
11001< This finds the first number in the line and adds one to it.
11002 A line break is included as a newline character.
11003
11004 Can also be used as a |method|: >
11005 GetNr()->submatch()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011006<
11007 Return type: |String| or list<string> depending on {list}
11008
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011009
11010substitute({string}, {pat}, {sub}, {flags}) *substitute()*
11011 The result is a String, which is a copy of {string}, in which
11012 the first match of {pat} is replaced with {sub}.
11013 When {flags} is "g", all matches of {pat} in {string} are
11014 replaced. Otherwise {flags} should be "".
11015
11016 This works like the ":substitute" command (without any flags).
11017 But the matching with {pat} is always done like the 'magic'
11018 option is set and 'cpoptions' is empty (to make scripts
11019 portable). 'ignorecase' is still relevant, use |/\c| or |/\C|
11020 if you want to ignore or match case and ignore 'ignorecase'.
11021 'smartcase' is not used. See |string-match| for how {pat} is
11022 used.
11023
11024 A "~" in {sub} is not replaced with the previous {sub}.
11025 Note that some codes in {sub} have a special meaning
11026 |sub-replace-special|. For example, to replace something with
11027 "\n" (two characters), use "\\\\n" or '\\n'.
11028
11029 When {pat} does not match in {string}, {string} is returned
11030 unmodified.
11031
11032 Example: >
11033 :let &path = substitute(&path, ",\\=[^,]*$", "", "")
11034< This removes the last component of the 'path' option. >
11035 :echo substitute("testing", ".*", "\\U\\0", "")
11036< results in "TESTING".
11037
11038 When {sub} starts with "\=", the remainder is interpreted as
11039 an expression. See |sub-replace-expression|. Example: >
11040 :echo substitute(s, '%\(\x\x\)',
Bram Moolenaarc51cf032022-02-26 12:25:45 +000011041 \ '\=nr2char("0x" .. submatch(1))', 'g')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011042
11043< When {sub} is a Funcref that function is called, with one
11044 optional argument. Example: >
11045 :echo substitute(s, '%\(\x\x\)', SubNr, 'g')
11046< The optional argument is a list which contains the whole
11047 matched string and up to nine submatches, like what
11048 |submatch()| returns. Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +000011049 :echo substitute(s, '%\(\x\x\)', {m -> '0x' .. m[1]}, 'g')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011050
Bram Moolenaard592deb2022-06-17 15:42:40 +010011051< Returns an empty string on error.
11052
11053 Can also be used as a |method|: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011054 GetString()->substitute(pat, sub, flags)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011055<
11056 Return type: |String|
11057
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011058
Bram Moolenaarc216a7a2022-12-05 13:50:55 +000011059swapfilelist() *swapfilelist()*
11060 Returns a list of swap file names, like what "vim -r" shows.
11061 See the |-r| command argument. The 'directory' option is used
11062 for the directories to inspect. If you only want to get a
11063 list of swap files in the current directory then temporarily
11064 set 'directory' to a dot: >
11065 let save_dir = &directory
11066 let &directory = '.'
11067 let swapfiles = swapfilelist()
11068 let &directory = save_dir
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011069<
11070 Return type: list<string>
11071
Bram Moolenaarc216a7a2022-12-05 13:50:55 +000011072
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011073swapinfo({fname}) *swapinfo()*
11074 The result is a dictionary, which holds information about the
11075 swapfile {fname}. The available fields are:
11076 version Vim version
11077 user user name
11078 host host name
11079 fname original file name
11080 pid PID of the Vim process that created the swap
11081 file
11082 mtime last modification time in seconds
11083 inode Optional: INODE number of the file
11084 dirty 1 if file was modified, 0 if not
11085 Note that "user" and "host" are truncated to at most 39 bytes.
11086 In case of failure an "error" item is added with the reason:
11087 Cannot open file: file not found or in accessible
11088 Cannot read file: cannot read first block
11089 Not a swap file: does not contain correct block ID
11090 Magic number mismatch: Info in first block is invalid
11091
11092 Can also be used as a |method|: >
11093 GetFilename()->swapinfo()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011094<
11095 Return type: dict<any> or dict<string>
11096
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011097
11098swapname({buf}) *swapname()*
11099 The result is the swap file path of the buffer {expr}.
11100 For the use of {buf}, see |bufname()| above.
11101 If buffer {buf} is the current buffer, the result is equal to
11102 |:swapname| (unless there is no swap file).
11103 If buffer {buf} has no swap file, returns an empty string.
11104
11105 Can also be used as a |method|: >
11106 GetBufname()->swapname()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011107<
11108 Return type: |String|
11109
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011110
11111synID({lnum}, {col}, {trans}) *synID()*
11112 The result is a Number, which is the syntax ID at the position
11113 {lnum} and {col} in the current window.
11114 The syntax ID can be used with |synIDattr()| and
11115 |synIDtrans()| to obtain syntax information about text.
11116
11117 {col} is 1 for the leftmost column, {lnum} is 1 for the first
11118 line. 'synmaxcol' applies, in a longer line zero is returned.
11119 Note that when the position is after the last character,
11120 that's where the cursor can be in Insert mode, synID() returns
11121 zero. {lnum} is used like with |getline()|.
11122
11123 When {trans} is |TRUE|, transparent items are reduced to the
11124 item that they reveal. This is useful when wanting to know
11125 the effective color. When {trans} is |FALSE|, the transparent
11126 item is returned. This is useful when wanting to know which
11127 syntax item is effective (e.g. inside parens).
11128 Warning: This function can be very slow. Best speed is
11129 obtained by going through the file in forward direction.
11130
Bram Moolenaard592deb2022-06-17 15:42:40 +010011131 Returns zero on error.
11132
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011133 Example (echoes the name of the syntax item under the cursor): >
11134 :echo synIDattr(synID(line("."), col("."), 1), "name")
11135<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011136 Return type: |Number|
11137
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011138
11139synIDattr({synID}, {what} [, {mode}]) *synIDattr()*
11140 The result is a String, which is the {what} attribute of
11141 syntax ID {synID}. This can be used to obtain information
11142 about a syntax item.
11143 {mode} can be "gui", "cterm" or "term", to get the attributes
11144 for that mode. When {mode} is omitted, or an invalid value is
11145 used, the attributes for the currently active highlighting are
11146 used (GUI, cterm or term).
11147 Use synIDtrans() to follow linked highlight groups.
11148 {what} result
11149 "name" the name of the syntax item
11150 "fg" foreground color (GUI: color name used to set
11151 the color, cterm: color number as a string,
11152 term: empty string)
11153 "bg" background color (as with "fg")
11154 "font" font name (only available in the GUI)
11155 |highlight-font|
11156 "sp" special color for the GUI (as with "fg")
11157 |highlight-guisp|
11158 "ul" underline color for cterm: number as a string
11159 "fg#" like "fg", but for the GUI and the GUI is
11160 running the name in "#RRGGBB" form
11161 "bg#" like "fg#" for "bg"
11162 "sp#" like "fg#" for "sp"
11163 "bold" "1" if bold
11164 "italic" "1" if italic
11165 "reverse" "1" if reverse
11166 "inverse" "1" if inverse (= reverse)
11167 "standout" "1" if standout
11168 "underline" "1" if underlined
11169 "undercurl" "1" if undercurled
11170 "strike" "1" if strikethrough
Bram Moolenaarde786322022-07-30 14:56:17 +010011171 "nocombine" "1" if nocombine
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011172
Bram Moolenaard592deb2022-06-17 15:42:40 +010011173 Returns an empty string on error.
11174
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011175 Example (echoes the color of the syntax item under the
11176 cursor): >
11177 :echo synIDattr(synIDtrans(synID(line("."), col("."), 1)), "fg")
11178<
11179 Can also be used as a |method|: >
11180 :echo synID(line("."), col("."), 1)->synIDtrans()->synIDattr("fg")
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011181<
11182 Return type: |String|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011183
11184
11185synIDtrans({synID}) *synIDtrans()*
11186 The result is a Number, which is the translated syntax ID of
11187 {synID}. This is the syntax group ID of what is being used to
11188 highlight the character. Highlight links given with
11189 ":highlight link" are followed.
11190
Bram Moolenaard592deb2022-06-17 15:42:40 +010011191 Returns zero on error.
11192
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011193 Can also be used as a |method|: >
11194 :echo synID(line("."), col("."), 1)->synIDtrans()->synIDattr("fg")
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011195<
11196 Return type: |Number|
11197
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011198
11199synconcealed({lnum}, {col}) *synconcealed()*
11200 The result is a |List| with currently three items:
11201 1. The first item in the list is 0 if the character at the
11202 position {lnum} and {col} is not part of a concealable
11203 region, 1 if it is. {lnum} is used like with |getline()|.
11204 2. The second item in the list is a string. If the first item
11205 is 1, the second item contains the text which will be
11206 displayed in place of the concealed text, depending on the
11207 current setting of 'conceallevel' and 'listchars'.
11208 3. The third and final item in the list is a number
11209 representing the specific syntax region matched in the
11210 line. When the character is not concealed the value is
11211 zero. This allows detection of the beginning of a new
11212 concealable region if there are two consecutive regions
11213 with the same replacement character. For an example, if
11214 the text is "123456" and both "23" and "45" are concealed
11215 and replaced by the character "X", then:
11216 call returns ~
11217 synconcealed(lnum, 1) [0, '', 0]
11218 synconcealed(lnum, 2) [1, 'X', 1]
11219 synconcealed(lnum, 3) [1, 'X', 1]
11220 synconcealed(lnum, 4) [1, 'X', 2]
11221 synconcealed(lnum, 5) [1, 'X', 2]
11222 synconcealed(lnum, 6) [0, '', 0]
11223
Christian Brabandtfe1e2b52024-04-26 18:42:59 +020011224 Note: Doesn't consider |matchadd()| highlighting items,
11225 since syntax and matching highlighting are two different
11226 mechanisms |syntax-vs-match|.
h-east52e7cc22024-07-28 17:03:29 +020011227
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011228 Return type: list<any>
Christian Brabandtfe1e2b52024-04-26 18:42:59 +020011229
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011230
11231synstack({lnum}, {col}) *synstack()*
11232 Return a |List|, which is the stack of syntax items at the
11233 position {lnum} and {col} in the current window. {lnum} is
11234 used like with |getline()|. Each item in the List is an ID
11235 like what |synID()| returns.
11236 The first item in the List is the outer region, following are
11237 items contained in that one. The last one is what |synID()|
11238 returns, unless not the whole item is highlighted or it is a
11239 transparent item.
11240 This function is useful for debugging a syntax file.
11241 Example that shows the syntax stack under the cursor: >
11242 for id in synstack(line("."), col("."))
11243 echo synIDattr(id, "name")
11244 endfor
11245< When the position specified with {lnum} and {col} is invalid
Bram Moolenaard592deb2022-06-17 15:42:40 +010011246 an empty List is returned. The position just after the last
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011247 character in a line and the first column in an empty line are
11248 valid positions.
11249
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011250 Return type: list<number> or list<any>
11251
11252
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011253system({expr} [, {input}]) *system()* *E677*
11254 Get the output of the shell command {expr} as a |String|. See
11255 |systemlist()| to get the output as a |List|.
11256
11257 When {input} is given and is a |String| this string is written
11258 to a file and passed as stdin to the command. The string is
11259 written as-is, you need to take care of using the correct line
11260 separators yourself.
11261 If {input} is given and is a |List| it is written to the file
11262 in a way |writefile()| does with {binary} set to "b" (i.e.
11263 with a newline between each list item with newlines inside
11264 list items converted to NULs).
11265 When {input} is given and is a number that is a valid id for
11266 an existing buffer then the content of the buffer is written
11267 to the file line by line, each line terminated by a NL and
11268 NULs characters where the text has a NL.
11269
11270 Pipes are not used, the 'shelltemp' option is not used.
11271
11272 When prepended by |:silent| the terminal will not be set to
11273 cooked mode. This is meant to be used for commands that do
11274 not need the user to type. It avoids stray characters showing
11275 up on the screen which require |CTRL-L| to remove. >
11276 :silent let f = system('ls *.vim')
11277<
11278 Note: Use |shellescape()| or |::S| with |expand()| or
11279 |fnamemodify()| to escape special characters in a command
11280 argument. Newlines in {expr} may cause the command to fail.
11281 The characters in 'shellquote' and 'shellxquote' may also
11282 cause trouble.
11283 This is not to be used for interactive commands.
11284
11285 The result is a String. Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +000011286 :let files = system('ls ' .. shellescape(expand('%:h')))
11287 :let files = system('ls ' .. expand('%:h:S'))
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011288
11289< To make the result more system-independent, the shell output
11290 is filtered to replace <CR> with <NL> for Macintosh, and
11291 <CR><NL> with <NL> for DOS-like systems.
11292 To avoid the string being truncated at a NUL, all NUL
11293 characters are replaced with SOH (0x01).
11294
11295 The command executed is constructed using several options:
11296 'shell' 'shellcmdflag' 'shellxquote' {expr} 'shellredir' {tmp} 'shellxquote'
11297 ({tmp} is an automatically generated file name).
11298 For Unix, braces are put around {expr} to allow for
11299 concatenated commands.
11300
11301 The command will be executed in "cooked" mode, so that a
11302 CTRL-C will interrupt the command (on Unix at least).
11303
11304 The resulting error code can be found in |v:shell_error|.
11305 This function will fail in |restricted-mode|.
11306
11307 Note that any wrong value in the options mentioned above may
11308 make the function fail. It has also been reported to fail
11309 when using a security agent application.
11310 Unlike ":!cmd" there is no automatic check for changed files.
11311 Use |:checktime| to force a check.
11312
11313 Can also be used as a |method|: >
11314 :echo GetCmd()->system()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011315<
11316 Return type: |String|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011317
11318
11319systemlist({expr} [, {input}]) *systemlist()*
11320 Same as |system()|, but returns a |List| with lines (parts of
11321 output separated by NL) with NULs transformed into NLs. Output
11322 is the same as |readfile()| will output with {binary} argument
11323 set to "b", except that there is no extra empty item when the
11324 result ends in a NL.
11325 Note that on MS-Windows you may get trailing CR characters.
11326
11327 To see the difference between "echo hello" and "echo -n hello"
11328 use |system()| and |split()|: >
11329 echo system('echo hello')->split('\n', 1)
11330<
11331 Returns an empty string on error.
11332
11333 Can also be used as a |method|: >
11334 :echo GetCmd()->systemlist()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011335<
11336 Return type: list<string>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011337
11338
11339tabpagebuflist([{arg}]) *tabpagebuflist()*
11340 The result is a |List|, where each item is the number of the
11341 buffer associated with each window in the current tab page.
11342 {arg} specifies the number of the tab page to be used. When
11343 omitted the current tab page is used.
11344 When {arg} is invalid the number zero is returned.
11345 To get a list of all buffers in all tabs use this: >
11346 let buflist = []
11347 for i in range(tabpagenr('$'))
11348 call extend(buflist, tabpagebuflist(i + 1))
11349 endfor
11350< Note that a buffer may appear in more than one window.
11351
11352 Can also be used as a |method|: >
11353 GetTabpage()->tabpagebuflist()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011354<
11355 Return type: list<number>
11356
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011357
11358tabpagenr([{arg}]) *tabpagenr()*
11359 The result is a Number, which is the number of the current
11360 tab page. The first tab page has number 1.
11361
11362 The optional argument {arg} supports the following values:
11363 $ the number of the last tab page (the tab page
11364 count).
11365 # the number of the last accessed tab page
11366 (where |g<Tab>| goes to). if there is no
11367 previous tab page 0 is returned.
11368 The number can be used with the |:tab| command.
11369
Bram Moolenaard592deb2022-06-17 15:42:40 +010011370 Returns zero on error.
11371
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011372 Return type: |Number|
11373
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011374
11375tabpagewinnr({tabarg} [, {arg}]) *tabpagewinnr()*
11376 Like |winnr()| but for tab page {tabarg}.
11377 {tabarg} specifies the number of tab page to be used.
11378 {arg} is used like with |winnr()|:
11379 - When omitted the current window number is returned. This is
11380 the window which will be used when going to this tab page.
11381 - When "$" the number of windows is returned.
11382 - When "#" the previous window nr is returned.
11383 Useful examples: >
11384 tabpagewinnr(1) " current window of tab page 1
11385 tabpagewinnr(4, '$') " number of windows in tab page 4
11386< When {tabarg} is invalid zero is returned.
11387
11388 Can also be used as a |method|: >
11389 GetTabpage()->tabpagewinnr()
11390<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011391 Return type: |Number|
11392
11393
11394tagfiles() *tagfiles()*
11395 Returns a |List| with the file names used to search for tags
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011396 for the current buffer. This is the 'tags' option expanded.
11397
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011398 Return type: list<string> or list<any>
11399
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011400
11401taglist({expr} [, {filename}]) *taglist()*
11402 Returns a |List| of tags matching the regular expression {expr}.
11403
11404 If {filename} is passed it is used to prioritize the results
11405 in the same way that |:tselect| does. See |tag-priority|.
11406 {filename} should be the full path of the file.
11407
11408 Each list item is a dictionary with at least the following
11409 entries:
11410 name Name of the tag.
11411 filename Name of the file where the tag is
11412 defined. It is either relative to the
11413 current directory or a full path.
11414 cmd Ex command used to locate the tag in
11415 the file.
11416 kind Type of the tag. The value for this
11417 entry depends on the language specific
11418 kind values. Only available when
11419 using a tags file generated by
Bram Moolenaar47c532e2022-03-19 15:18:53 +000011420 Universal/Exuberant ctags or hdrtag.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011421 static A file specific tag. Refer to
11422 |static-tag| for more information.
11423 More entries may be present, depending on the content of the
11424 tags file: access, implementation, inherits and signature.
11425 Refer to the ctags documentation for information about these
11426 fields. For C code the fields "struct", "class" and "enum"
11427 may appear, they give the name of the entity the tag is
11428 contained in.
11429
11430 The ex-command "cmd" can be either an ex search pattern, a
11431 line number or a line number followed by a byte number.
11432
11433 If there are no matching tags, then an empty list is returned.
11434
11435 To get an exact tag match, the anchors '^' and '$' should be
11436 used in {expr}. This also make the function work faster.
11437 Refer to |tag-regexp| for more information about the tag
11438 search regular expression pattern.
11439
11440 Refer to |'tags'| for information about how the tags file is
11441 located by Vim. Refer to |tags-file-format| for the format of
11442 the tags file generated by the different ctags tools.
11443
11444 Can also be used as a |method|: >
11445 GetTagpattern()->taglist()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011446<
11447 Return type: list<dict<any>> or list<any>
11448
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011449
11450tan({expr}) *tan()*
11451 Return the tangent of {expr}, measured in radians, as a |Float|
11452 in the range [-inf, inf].
11453 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaard592deb2022-06-17 15:42:40 +010011454 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011455 Examples: >
11456 :echo tan(10)
11457< 0.648361 >
11458 :echo tan(-4.01)
11459< -1.181502
11460
11461 Can also be used as a |method|: >
11462 Compute()->tan()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011463<
11464 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011465
11466
11467tanh({expr}) *tanh()*
11468 Return the hyperbolic tangent of {expr} as a |Float| in the
11469 range [-1, 1].
11470 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaard592deb2022-06-17 15:42:40 +010011471 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011472 Examples: >
11473 :echo tanh(0.5)
11474< 0.462117 >
11475 :echo tanh(-1)
11476< -0.761594
11477
11478 Can also be used as a |method|: >
11479 Compute()->tanh()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011480<
11481 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011482
11483
11484tempname() *tempname()* *temp-file-name*
11485 The result is a String, which is the name of a file that
11486 doesn't exist. It can be used for a temporary file. The name
11487 is different for at least 26 consecutive calls. Example: >
11488 :let tmpfile = tempname()
Bram Moolenaarc51cf032022-02-26 12:25:45 +000011489 :exe "redir > " .. tmpfile
Christian Brabandt5cf53012024-05-18 10:13:11 +020011490< For Unix, the file will be in a private directory |tempfile|
11491 that is recursively deleted when Vim exits, on other systems
11492 temporary files are not cleaned up automatically on exit.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011493 For MS-Windows forward slashes are used when the 'shellslash'
11494 option is set, or when 'shellcmdflag' starts with '-' and
11495 'shell' does not contain powershell or pwsh.
11496
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011497 Return type: |String|
11498
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011499
11500term_ functions are documented here: |terminal-function-details|
11501
11502
11503terminalprops() *terminalprops()*
11504 Returns a |Dictionary| with properties of the terminal that Vim
11505 detected from the response to |t_RV| request. See
11506 |v:termresponse| for the response itself. If |v:termresponse|
11507 is empty most values here will be 'u' for unknown.
11508 cursor_style whether sending |t_RS| works **
11509 cursor_blink_mode whether sending |t_RC| works **
11510 underline_rgb whether |t_8u| works **
11511 mouse mouse type supported
Bram Moolenaar4bc85f22022-10-21 14:17:24 +010011512 kitty whether Kitty terminal was detected
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011513
11514 ** value 'u' for unknown, 'y' for yes, 'n' for no
11515
11516 If the |+termresponse| feature is missing then the result is
11517 an empty dictionary.
11518
11519 If "cursor_style" is 'y' then |t_RS| will be sent to request the
11520 current cursor style.
11521 If "cursor_blink_mode" is 'y' then |t_RC| will be sent to
11522 request the cursor blink status.
11523 "cursor_style" and "cursor_blink_mode" are also set if |t_u7|
11524 is not empty, Vim will detect the working of sending |t_RS|
11525 and |t_RC| on startup.
11526
11527 When "underline_rgb" is not 'y', then |t_8u| will be made empty.
11528 This avoids sending it to xterm, which would clear the colors.
11529
11530 For "mouse" the value 'u' is unknown
11531
11532 Also see:
11533 - 'ambiwidth' - detected by using |t_u7|.
11534 - |v:termstyleresp| and |v:termblinkresp| for the response to
11535 |t_RS| and |t_RC|.
11536
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011537 Return type: dict<string>
11538
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011539
11540test_ functions are documented here: |test-functions-details|
11541
11542
11543 *timer_info()*
11544timer_info([{id}])
11545 Return a list with information about timers.
11546 When {id} is given only information about this timer is
11547 returned. When timer {id} does not exist an empty list is
11548 returned.
11549 When {id} is omitted information about all timers is returned.
11550
11551 For each timer the information is stored in a |Dictionary| with
11552 these items:
11553 "id" the timer ID
11554 "time" time the timer was started with
11555 "remaining" time until the timer fires
11556 "repeat" number of times the timer will still fire;
11557 -1 means forever
11558 "callback" the callback
11559 "paused" 1 if the timer is paused, 0 otherwise
11560
11561 Can also be used as a |method|: >
11562 GetTimer()->timer_info()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011563<
11564 Return type: list<dict<any>> or list<any>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011565
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011566 {only available when compiled with the |+timers| feature}
11567
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011568
11569timer_pause({timer}, {paused}) *timer_pause()*
11570 Pause or unpause a timer. A paused timer does not invoke its
11571 callback when its time expires. Unpausing a timer may cause
11572 the callback to be invoked almost immediately if enough time
11573 has passed.
11574
11575 Pausing a timer is useful to avoid the callback to be called
11576 for a short time.
11577
11578 If {paused} evaluates to a non-zero Number or a non-empty
11579 String, then the timer is paused, otherwise it is unpaused.
11580 See |non-zero-arg|.
11581
11582 Can also be used as a |method|: >
11583 GetTimer()->timer_pause(1)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011584<
11585 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011586
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011587 {only available when compiled with the |+timers| feature}
11588
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011589
11590 *timer_start()* *timer* *timers*
11591timer_start({time}, {callback} [, {options}])
11592 Create a timer and return the timer ID.
11593
11594 {time} is the waiting time in milliseconds. This is the
11595 minimum time before invoking the callback. When the system is
11596 busy or Vim is not waiting for input the time will be longer.
Bram Moolenaardd60c362023-02-27 15:49:53 +000011597 Zero can be used to execute the callback when Vim is back in
11598 the main loop.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011599
11600 {callback} is the function to call. It can be the name of a
11601 function or a |Funcref|. It is called with one argument, which
11602 is the timer ID. The callback is only invoked when Vim is
11603 waiting for input.
11604 If you want to show a message look at |popup_notification()|
11605 to avoid interfering with what the user is doing.
11606
11607 {options} is a dictionary. Supported entries:
11608 "repeat" Number of times to repeat calling the
11609 callback. -1 means forever. When not present
11610 the callback will be called once.
11611 If the timer causes an error three times in a
11612 row the repeat is cancelled. This avoids that
11613 Vim becomes unusable because of all the error
11614 messages.
11615
Bram Moolenaard592deb2022-06-17 15:42:40 +010011616 Returns -1 on error.
11617
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011618 Example: >
11619 func MyHandler(timer)
11620 echo 'Handler called'
11621 endfunc
11622 let timer = timer_start(500, 'MyHandler',
11623 \ {'repeat': 3})
11624< This will invoke MyHandler() three times at 500 msec
11625 intervals.
11626
11627 Can also be used as a |method|: >
11628 GetMsec()->timer_start(callback)
11629
11630< Not available in the |sandbox|.
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011631
11632 Return type: |Number|
11633
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011634 {only available when compiled with the |+timers| feature}
11635
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011636
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011637timer_stop({timer}) *timer_stop()*
11638 Stop a timer. The timer callback will no longer be invoked.
11639 {timer} is an ID returned by timer_start(), thus it must be a
11640 Number. If {timer} does not exist there is no error.
11641
11642 Can also be used as a |method|: >
11643 GetTimer()->timer_stop()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011644<
11645 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011646
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011647 {only available when compiled with the |+timers| feature}
11648
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011649
11650timer_stopall() *timer_stopall()*
11651 Stop all timers. The timer callbacks will no longer be
11652 invoked. Useful if a timer is misbehaving. If there are no
11653 timers there is no error.
11654
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011655 Return type: |Number|
11656
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011657 {only available when compiled with the |+timers| feature}
11658
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011659
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011660tolower({expr}) *tolower()*
11661 The result is a copy of the String given, with all uppercase
11662 characters turned into lowercase (just like applying |gu| to
Bram Moolenaard592deb2022-06-17 15:42:40 +010011663 the string). Returns an empty string on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011664
11665 Can also be used as a |method|: >
11666 GetText()->tolower()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011667<
11668 Return type: |String|
11669
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011670
11671toupper({expr}) *toupper()*
11672 The result is a copy of the String given, with all lowercase
11673 characters turned into uppercase (just like applying |gU| to
Bram Moolenaard592deb2022-06-17 15:42:40 +010011674 the string). Returns an empty string on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011675
11676 Can also be used as a |method|: >
11677 GetText()->toupper()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011678<
11679 Return type: |String|
11680
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011681
11682tr({src}, {fromstr}, {tostr}) *tr()*
11683 The result is a copy of the {src} string with all characters
11684 which appear in {fromstr} replaced by the character in that
11685 position in the {tostr} string. Thus the first character in
11686 {fromstr} is translated into the first character in {tostr}
11687 and so on. Exactly like the unix "tr" command.
11688 This code also deals with multibyte characters properly.
11689
Bram Moolenaard592deb2022-06-17 15:42:40 +010011690 Returns an empty string on error.
11691
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011692 Examples: >
11693 echo tr("hello there", "ht", "HT")
11694< returns "Hello THere" >
11695 echo tr("<blob>", "<>", "{}")
11696< returns "{blob}"
11697
11698 Can also be used as a |method|: >
11699 GetText()->tr(from, to)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011700<
11701 Return type: |String|
11702
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011703
11704trim({text} [, {mask} [, {dir}]]) *trim()*
11705 Return {text} as a String where any character in {mask} is
11706 removed from the beginning and/or end of {text}.
11707
Illia Bobyr80799172023-10-17 18:00:50 +020011708 If {mask} is not given, or is an empty string, {mask} is all
11709 characters up to 0x20, which includes Tab, space, NL and CR,
11710 plus the non-breaking space character 0xa0.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011711
11712 The optional {dir} argument specifies where to remove the
11713 characters:
11714 0 remove from the beginning and end of {text}
11715 1 remove only at the beginning of {text}
11716 2 remove only at the end of {text}
11717 When omitted both ends are trimmed.
11718
11719 This function deals with multibyte characters properly.
Bram Moolenaard592deb2022-06-17 15:42:40 +010011720 Returns an empty string on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011721
11722 Examples: >
11723 echo trim(" some text ")
11724< returns "some text" >
Bram Moolenaarc51cf032022-02-26 12:25:45 +000011725 echo trim(" \r\t\t\r RESERVE \t\n\x0B\xA0") .. "_TAIL"
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011726< returns "RESERVE_TAIL" >
11727 echo trim("rm<Xrm<>X>rrm", "rm<>")
11728< returns "Xrm<>X" (characters in the middle are not removed) >
11729 echo trim(" vim ", " ", 2)
11730< returns " vim"
11731
11732 Can also be used as a |method|: >
11733 GetText()->trim()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011734<
11735 Return type: |String|
11736
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011737
11738trunc({expr}) *trunc()*
11739 Return the largest integral value with magnitude less than or
11740 equal to {expr} as a |Float| (truncate towards zero).
11741 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaard592deb2022-06-17 15:42:40 +010011742 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011743 Examples: >
11744 echo trunc(1.456)
11745< 1.0 >
11746 echo trunc(-5.456)
11747< -5.0 >
11748 echo trunc(4.0)
11749< 4.0
11750
11751 Can also be used as a |method|: >
11752 Compute()->trunc()
11753<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011754 Return type: |Float|
11755
11756
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011757 *type()*
11758type({expr}) The result is a Number representing the type of {expr}.
11759 Instead of using the number directly, it is better to use the
11760 v:t_ variable that has the value:
11761 Number: 0 |v:t_number|
11762 String: 1 |v:t_string|
11763 Funcref: 2 |v:t_func|
11764 List: 3 |v:t_list|
11765 Dictionary: 4 |v:t_dict|
11766 Float: 5 |v:t_float|
11767 Boolean: 6 |v:t_bool| (v:false and v:true)
11768 None: 7 |v:t_none| (v:null and v:none)
11769 Job: 8 |v:t_job|
11770 Channel: 9 |v:t_channel|
11771 Blob: 10 |v:t_blob|
h_east596a9f22023-11-21 21:24:23 +090011772 Class: 12 |v:t_class|
11773 Object: 13 |v:t_object|
Yegappan Lakshmanan2a71b542023-12-14 20:03:03 +010011774 Typealias: 14 |v:t_typealias|
Yegappan Lakshmanan3164cf82024-03-28 10:36:42 +010011775 Enum: 15 |v:t_enum|
11776 EnumValue: 16 |v:t_enumvalue|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011777 For backward compatibility, this method can be used: >
11778 :if type(myvar) == type(0)
11779 :if type(myvar) == type("")
11780 :if type(myvar) == type(function("tr"))
11781 :if type(myvar) == type([])
11782 :if type(myvar) == type({})
11783 :if type(myvar) == type(0.0)
11784 :if type(myvar) == type(v:false)
11785 :if type(myvar) == type(v:none)
11786< To check if the v:t_ variables exist use this: >
11787 :if exists('v:t_number')
11788
11789< Can also be used as a |method|: >
11790 mylist->type()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011791<
11792 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011793
11794
11795typename({expr}) *typename()*
11796 Return a string representation of the type of {expr}.
11797 Example: >
11798 echo typename([1, 2, 3])
Kota Kato66bb9ae2023-01-17 18:31:56 +000011799< list<number> ~
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011800
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011801 Return type: |String|
11802
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011803
11804undofile({name}) *undofile()*
11805 Return the name of the undo file that would be used for a file
11806 with name {name} when writing. This uses the 'undodir'
11807 option, finding directories that exist. It does not check if
11808 the undo file exists.
11809 {name} is always expanded to the full path, since that is what
11810 is used internally.
11811 If {name} is empty undofile() returns an empty string, since a
11812 buffer without a file name will not write an undo file.
11813 Useful in combination with |:wundo| and |:rundo|.
11814 When compiled without the |+persistent_undo| option this always
11815 returns an empty string.
11816
11817 Can also be used as a |method|: >
11818 GetFilename()->undofile()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011819<
11820 Return type: |String|
11821
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011822
Devin J. Pohly5fee1112023-04-23 20:26:59 -050011823undotree([{buf}]) *undotree()*
11824 Return the current state of the undo tree for the current
11825 buffer, or for a specific buffer if {buf} is given. The
11826 result is a dictionary with the following items:
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011827 "seq_last" The highest undo sequence number used.
11828 "seq_cur" The sequence number of the current position in
11829 the undo tree. This differs from "seq_last"
11830 when some changes were undone.
11831 "time_cur" Time last used for |:earlier| and related
11832 commands. Use |strftime()| to convert to
11833 something readable.
11834 "save_last" Number of the last file write. Zero when no
11835 write yet.
11836 "save_cur" Number of the current position in the undo
11837 tree.
11838 "synced" Non-zero when the last undo block was synced.
11839 This happens when waiting from input from the
11840 user. See |undo-blocks|.
11841 "entries" A list of dictionaries with information about
11842 undo blocks.
11843
11844 The first item in the "entries" list is the oldest undo item.
11845 Each List item is a |Dictionary| with these items:
11846 "seq" Undo sequence number. Same as what appears in
11847 |:undolist|.
11848 "time" Timestamp when the change happened. Use
11849 |strftime()| to convert to something readable.
11850 "newhead" Only appears in the item that is the last one
11851 that was added. This marks the last change
11852 and where further changes will be added.
11853 "curhead" Only appears in the item that is the last one
11854 that was undone. This marks the current
11855 position in the undo tree, the block that will
11856 be used by a redo command. When nothing was
11857 undone after the last change this item will
11858 not appear anywhere.
11859 "save" Only appears on the last block before a file
11860 write. The number is the write count. The
11861 first write has number 1, the last one the
11862 "save_last" mentioned above.
11863 "alt" Alternate entry. This is again a List of undo
11864 blocks. Each item may again have an "alt"
11865 item.
11866
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011867 Return type: dict<any>
11868
11869
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011870uniq({list} [, {func} [, {dict}]]) *uniq()* *E882*
11871 Remove second and succeeding copies of repeated adjacent
11872 {list} items in-place. Returns {list}. If you want a list
11873 to remain unmodified make a copy first: >
11874 :let newlist = uniq(copy(mylist))
11875< The default compare function uses the string representation of
11876 each item. For the use of {func} and {dict} see |sort()|.
11877
Bram Moolenaard592deb2022-06-17 15:42:40 +010011878 Returns zero if {list} is not a |List|.
11879
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011880 Can also be used as a |method|: >
11881 mylist->uniq()
Christian Brabandt67672ef2023-04-24 21:09:54 +010011882<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011883 Return type: list<{type}>
11884
11885
Christian Brabandt67672ef2023-04-24 21:09:54 +010011886 *utf16idx()*
11887utf16idx({string}, {idx} [, {countcc} [, {charidx}]])
Yegappan Lakshmanan577922b2023-06-08 17:09:45 +010011888 Same as |charidx()| but returns the UTF-16 code unit index of
11889 the byte at {idx} in {string} (after converting it to UTF-16).
Christian Brabandt67672ef2023-04-24 21:09:54 +010011890
11891 When {charidx} is present and TRUE, {idx} is used as the
11892 character index in the String {string} instead of as the byte
11893 index.
Yegappan Lakshmanan95707032023-06-14 13:10:15 +010011894 An {idx} in the middle of a UTF-8 sequence is rounded
11895 downwards to the beginning of that sequence.
Christian Brabandt67672ef2023-04-24 21:09:54 +010011896
Yegappan Lakshmanan577922b2023-06-08 17:09:45 +010011897 Returns -1 if the arguments are invalid or if there are less
11898 than {idx} bytes in {string}. If there are exactly {idx} bytes
11899 the length of the string in UTF-16 code units is returned.
11900
Christian Brabandt67672ef2023-04-24 21:09:54 +010011901 See |byteidx()| and |byteidxcomp()| for getting the byte index
11902 from the UTF-16 index and |charidx()| for getting the
11903 character index from the UTF-16 index.
11904 Refer to |string-offset-encoding| for more information.
11905 Examples: >
11906 echo utf16idx('a😊😊', 3) returns 2
11907 echo utf16idx('a😊😊', 7) returns 4
11908 echo utf16idx('a😊😊', 1, 0, 1) returns 2
11909 echo utf16idx('a😊😊', 2, 0, 1) returns 4
11910 echo utf16idx('aą́c', 6) returns 2
11911 echo utf16idx('aą́c', 6, 1) returns 4
11912 echo utf16idx('a😊😊', 9) returns -1
11913<
11914 Can also be used as a |method|: >
11915 GetName()->utf16idx(idx)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011916<
11917 Return type: |Number|
Christian Brabandt67672ef2023-04-24 21:09:54 +010011918
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011919
11920values({dict}) *values()*
11921 Return a |List| with all the values of {dict}. The |List| is
11922 in arbitrary order. Also see |items()| and |keys()|.
Bram Moolenaard592deb2022-06-17 15:42:40 +010011923 Returns zero if {dict} is not a |Dict|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011924
11925 Can also be used as a |method|: >
11926 mydict->values()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011927<
11928 Return type: list<any>
11929
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011930
zeertzjq825cf812023-08-17 22:55:25 +020011931virtcol({expr} [, {list} [, {winid}]]) *virtcol()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011932 The result is a Number, which is the screen column of the file
11933 position given with {expr}. That is, the last screen position
11934 occupied by the character at that position, when the screen
11935 would be of unlimited width. When there is a <Tab> at the
11936 position, the returned Number will be the column at the end of
11937 the <Tab>. For example, for a <Tab> in column 1, with 'ts'
11938 set to 8, it returns 8. |conceal| is ignored.
11939 For the byte position use |col()|.
LemonBoy0f7a3e12022-05-26 12:10:37 +010011940
zeertzjq02f3eba2024-06-12 20:45:24 +020011941 For the use of {expr} see |getpos()| and |col()|.
zeertzjqd353d272024-06-13 23:00:25 +080011942 When {expr} is "$", it means the end of the cursor line, so
11943 the result is the number of cells in the cursor line plus one.
LemonBoy0f7a3e12022-05-26 12:10:37 +010011944
11945 When 'virtualedit' is used {expr} can be [lnum, col, off],
11946 where "off" is the offset in screen columns from the start of
11947 the character. E.g., a position within a <Tab> or after the
11948 last character. When "off" is omitted zero is used. When
11949 Virtual editing is active in the current mode, a position
11950 beyond the end of the line can be returned. Also see
11951 |'virtualedit'|
11952
zeertzjq825cf812023-08-17 22:55:25 +020011953 If {list} is present and non-zero then virtcol() returns a
11954 List with the first and last screen position occupied by the
LemonBoy0f7a3e12022-05-26 12:10:37 +010011955 character.
11956
zeertzjq825cf812023-08-17 22:55:25 +020011957 With the optional {winid} argument the values are obtained for
11958 that window instead of the current window.
11959
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011960 Note that only marks in the current file can be used.
zeertzjq02f3eba2024-06-12 20:45:24 +020011961
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011962 Examples: >
LemonBoy0f7a3e12022-05-26 12:10:37 +010011963 " With text "foo^Lbar" and cursor on the "^L":
11964
11965 virtcol(".") " returns 5
11966 virtcol(".", 1) " returns [4, 5]
11967 virtcol("$") " returns 9
11968
11969 " With text " there", with 't at 'h':
11970
11971 virtcol("'t") " returns 6
zeertzjq02f3eba2024-06-12 20:45:24 +020011972<
11973 The first column is 1. 0 or [0, 0] is returned for an error.
11974
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011975 A more advanced example that echoes the maximum length of
11976 all lines: >
11977 echo max(map(range(1, line('$')), "virtcol([v:val, '$'])"))
11978
11979< Can also be used as a |method|: >
11980 GetPos()->virtcol()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011981<
11982 Return type: |Number|
11983
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011984
Bram Moolenaar5a6ec102022-05-27 21:58:00 +010011985virtcol2col({winid}, {lnum}, {col}) *virtcol2col()*
11986 The result is a Number, which is the byte index of the
11987 character in window {winid} at buffer line {lnum} and virtual
11988 column {col}.
11989
zeertzjqb583eda2023-10-14 11:32:28 +020011990 If buffer line {lnum} is an empty line, 0 is returned.
11991
Bram Moolenaar5a6ec102022-05-27 21:58:00 +010011992 If {col} is greater than the last virtual column in line
11993 {lnum}, then the byte index of the character at the last
11994 virtual column is returned.
11995
Yegappan Lakshmananb209b862023-08-15 23:01:44 +020011996 For a multi-byte character, the column number of the first
11997 byte in the character is returned.
11998
Bram Moolenaar5a6ec102022-05-27 21:58:00 +010011999 The {winid} argument can be the window number or the
12000 |window-ID|. If this is zero, then the current window is used.
12001
12002 Returns -1 if the window {winid} doesn't exist or the buffer
12003 line {lnum} or virtual column {col} is invalid.
12004
12005 See also |screenpos()|, |virtcol()| and |col()|.
12006
12007 Can also be used as a |method|: >
12008 GetWinid()->virtcol2col(lnum, col)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012009<
12010 Return type: |Number|
12011
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012012
12013visualmode([{expr}]) *visualmode()*
12014 The result is a String, which describes the last Visual mode
12015 used in the current buffer. Initially it returns an empty
12016 string, but once Visual mode has been used, it returns "v",
12017 "V", or "<CTRL-V>" (a single CTRL-V character) for
12018 character-wise, line-wise, or block-wise Visual mode
12019 respectively.
12020 Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +000012021 :exe "normal " .. visualmode()
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012022< This enters the same Visual mode as before. It is also useful
12023 in scripts if you wish to act differently depending on the
12024 Visual mode that was used.
12025 If Visual mode is active, use |mode()| to get the Visual mode
12026 (e.g., in a |:vmap|).
12027 If {expr} is supplied and it evaluates to a non-zero Number or
12028 a non-empty String, then the Visual mode will be cleared and
12029 the old value is returned. See |non-zero-arg|.
12030
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012031 Return type: |String|
12032
12033
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012034wildmenumode() *wildmenumode()*
12035 Returns |TRUE| when the wildmenu is active and |FALSE|
12036 otherwise. See 'wildmenu' and 'wildmode'.
12037 This can be used in mappings to handle the 'wildcharm' option
12038 gracefully. (Makes only sense with |mapmode-c| mappings).
12039
12040 For example to make <c-j> work like <down> in wildmode, use: >
12041 :cnoremap <expr> <C-j> wildmenumode() ? "\<Down>\<Tab>" : "\<c-j>"
12042<
Milly6c2fc372024-10-16 22:11:17 +020012043 (Note: this needs the 'wildcharm' option set appropriately).
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012044
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012045 Return type: |Number|
12046
12047
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012048win_execute({id}, {command} [, {silent}]) *win_execute()*
12049 Like `execute()` but in the context of window {id}.
12050 The window will temporarily be made the current window,
12051 without triggering autocommands or changing directory. When
12052 executing {command} autocommands will be triggered, this may
Bram Moolenaarb7398fe2023-05-14 18:50:25 +010012053 have unexpected side effects. Use `:noautocmd` if needed.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012054 Example: >
12055 call win_execute(winid, 'set syntax=python')
12056< Doing the same with `setwinvar()` would not trigger
12057 autocommands and not actually show syntax highlighting.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012058 *E994*
12059 Not all commands are allowed in popup windows.
12060 When window {id} does not exist then no error is given and
12061 an empty string is returned.
12062
12063 Can also be used as a |method|, the base is passed as the
12064 second argument: >
12065 GetCommand()->win_execute(winid)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012066<
12067 Return type: |String|
12068
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012069
12070win_findbuf({bufnr}) *win_findbuf()*
12071 Returns a |List| with |window-ID|s for windows that contain
12072 buffer {bufnr}. When there is none the list is empty.
12073
12074 Can also be used as a |method|: >
12075 GetBufnr()->win_findbuf()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012076<
12077 Return type: list<number> or list<any>
12078
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012079
12080win_getid([{win} [, {tab}]]) *win_getid()*
12081 Get the |window-ID| for the specified window.
12082 When {win} is missing use the current window.
12083 With {win} this is the window number. The top window has
12084 number 1.
12085 Without {tab} use the current tab, otherwise the tab with
12086 number {tab}. The first tab has number one.
12087 Return zero if the window cannot be found.
12088
12089 Can also be used as a |method|: >
12090 GetWinnr()->win_getid()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012091<
12092 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012093
12094
12095win_gettype([{nr}]) *win_gettype()*
12096 Return the type of the window:
12097 "autocmd" autocommand window. Temporary window
12098 used to execute autocommands.
12099 "command" command-line window |cmdwin|
12100 (empty) normal window
12101 "loclist" |location-list-window|
12102 "popup" popup window |popup|
12103 "preview" preview window |preview-window|
12104 "quickfix" |quickfix-window|
12105 "unknown" window {nr} not found
12106
12107 When {nr} is omitted return the type of the current window.
12108 When {nr} is given return the type of this window by number or
12109 |window-ID|.
12110
12111 Also see the 'buftype' option. When running a terminal in a
12112 popup window then 'buftype' is "terminal" and win_gettype()
12113 returns "popup".
12114
12115 Can also be used as a |method|: >
12116 GetWinid()->win_gettype()
12117<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012118 Return type: |String|
12119
12120
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012121win_gotoid({expr}) *win_gotoid()*
12122 Go to window with ID {expr}. This may also change the current
12123 tabpage.
12124 Return TRUE if successful, FALSE if the window cannot be found.
12125
12126 Can also be used as a |method|: >
12127 GetWinid()->win_gotoid()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012128<
12129 Return type: |Number|
12130
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012131
12132win_id2tabwin({expr}) *win_id2tabwin()*
12133 Return a list with the tab number and window number of window
12134 with ID {expr}: [tabnr, winnr].
12135 Return [0, 0] if the window cannot be found.
12136
12137 Can also be used as a |method|: >
12138 GetWinid()->win_id2tabwin()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012139<
12140 Return type: list<number>
12141
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012142
12143win_id2win({expr}) *win_id2win()*
12144 Return the window number of window with ID {expr}.
12145 Return 0 if the window cannot be found in the current tabpage.
12146
12147 Can also be used as a |method|: >
12148 GetWinid()->win_id2win()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012149<
12150 Return type: |Number|
12151
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012152
Daniel Steinbergee630312022-01-10 13:36:34 +000012153win_move_separator({nr}, {offset}) *win_move_separator()*
12154 Move window {nr}'s vertical separator (i.e., the right border)
12155 by {offset} columns, as if being dragged by the mouse. {nr}
12156 can be a window number or |window-ID|. A positive {offset}
12157 moves right and a negative {offset} moves left. Moving a
12158 window's vertical separator will change the width of the
12159 window and the width of other windows adjacent to the vertical
12160 separator. The magnitude of movement may be smaller than
12161 specified (e.g., as a consequence of maintaining
12162 'winminwidth'). Returns TRUE if the window can be found and
12163 FALSE otherwise.
Bram Moolenaard592deb2022-06-17 15:42:40 +010012164 This will fail for the rightmost window and a full-width
12165 window, since it has no separator on the right.
Bram Moolenaar76db9e02022-11-09 21:21:04 +000012166 Only works for the current tab page. *E1308*
Daniel Steinbergee630312022-01-10 13:36:34 +000012167
12168 Can also be used as a |method|: >
12169 GetWinnr()->win_move_separator(offset)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012170<
12171 Return type: |Number|
12172
Daniel Steinbergee630312022-01-10 13:36:34 +000012173
12174win_move_statusline({nr}, {offset}) *win_move_statusline()*
12175 Move window {nr}'s status line (i.e., the bottom border) by
12176 {offset} rows, as if being dragged by the mouse. {nr} can be a
12177 window number or |window-ID|. A positive {offset} moves down
12178 and a negative {offset} moves up. Moving a window's status
12179 line will change the height of the window and the height of
12180 other windows adjacent to the status line. The magnitude of
12181 movement may be smaller than specified (e.g., as a consequence
12182 of maintaining 'winminheight'). Returns TRUE if the window can
12183 be found and FALSE otherwise.
Bram Moolenaar76db9e02022-11-09 21:21:04 +000012184 Only works for the current tab page.
Daniel Steinbergee630312022-01-10 13:36:34 +000012185
12186 Can also be used as a |method|: >
12187 GetWinnr()->win_move_statusline(offset)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012188<
12189 Return type: |Number|
12190
Daniel Steinbergee630312022-01-10 13:36:34 +000012191
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012192win_screenpos({nr}) *win_screenpos()*
12193 Return the screen position of window {nr} as a list with two
12194 numbers: [row, col]. The first window always has position
12195 [1, 1], unless there is a tabline, then it is [2, 1].
12196 {nr} can be the window number or the |window-ID|. Use zero
12197 for the current window.
Sean Dewar5866bc32024-03-13 20:17:24 +010012198 Returns [0, 0] if the window cannot be found.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012199
12200 Can also be used as a |method|: >
12201 GetWinid()->win_screenpos()
12202<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012203 Return type: list<number>
12204
12205
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012206win_splitmove({nr}, {target} [, {options}]) *win_splitmove()*
Sean Dewar96cc4ae2024-02-20 21:52:31 +010012207 Temporarily switch to window {target}, then move window {nr}
12208 to a new split adjacent to {target}.
12209 Unlike commands such as |:split|, no new windows are created
12210 (the |window-ID| of window {nr} is unchanged after the move).
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012211
12212 Both {nr} and {target} can be window numbers or |window-ID|s.
12213 Both must be in the current tab page.
12214
12215 Returns zero for success, non-zero for failure.
12216
12217 {options} is a |Dictionary| with the following optional entries:
12218 "vertical" When TRUE, the split is created vertically,
12219 like with |:vsplit|.
12220 "rightbelow" When TRUE, the split is made below or to the
12221 right (if vertical). When FALSE, it is done
12222 above or to the left (if vertical). When not
12223 present, the values of 'splitbelow' and
12224 'splitright' are used.
12225
12226 Can also be used as a |method|: >
12227 GetWinid()->win_splitmove(target)
12228<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012229 Return type: |Number|
12230
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012231
12232 *winbufnr()*
12233winbufnr({nr}) The result is a Number, which is the number of the buffer
12234 associated with window {nr}. {nr} can be the window number or
12235 the |window-ID|.
12236 When {nr} is zero, the number of the buffer in the current
12237 window is returned.
12238 When window {nr} doesn't exist, -1 is returned.
12239 Example: >
12240 :echo "The file in the current window is " . bufname(winbufnr(0))
12241<
12242 Can also be used as a |method|: >
12243 FindWindow()->winbufnr()->bufname()
12244<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012245 Return type: |Number|
12246
12247
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012248 *wincol()*
12249wincol() The result is a Number, which is the virtual column of the
12250 cursor in the window. This is counting screen cells from the
12251 left side of the window. The leftmost column is one.
12252
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012253 Return type: |Number|
12254
12255
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012256 *windowsversion()*
12257windowsversion()
12258 The result is a String. For MS-Windows it indicates the OS
12259 version. E.g, Windows 10 is "10.0", Windows 8 is "6.2",
12260 Windows XP is "5.1". For non-MS-Windows systems the result is
12261 an empty string.
12262
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012263 Return type: |String|
12264
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012265winheight({nr}) *winheight()*
12266 The result is a Number, which is the height of window {nr}.
12267 {nr} can be the window number or the |window-ID|.
12268 When {nr} is zero, the height of the current window is
12269 returned. When window {nr} doesn't exist, -1 is returned.
12270 An existing window always has a height of zero or more.
12271 This excludes any window toolbar line.
12272 Examples: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +000012273 :echo "The current window has " .. winheight(0) .. " lines."
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012274
12275< Can also be used as a |method|: >
12276 GetWinid()->winheight()
12277<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012278 Return type: |Number|
12279
12280
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012281winlayout([{tabnr}]) *winlayout()*
12282 The result is a nested List containing the layout of windows
12283 in a tabpage.
12284
12285 Without {tabnr} use the current tabpage, otherwise the tabpage
12286 with number {tabnr}. If the tabpage {tabnr} is not found,
12287 returns an empty list.
12288
12289 For a leaf window, it returns:
12290 ['leaf', {winid}]
12291 For horizontally split windows, which form a column, it
12292 returns:
12293 ['col', [{nested list of windows}]]
12294 For vertically split windows, which form a row, it returns:
12295 ['row', [{nested list of windows}]]
12296
12297 Example: >
12298 " Only one window in the tab page
12299 :echo winlayout()
12300 ['leaf', 1000]
12301 " Two horizontally split windows
12302 :echo winlayout()
12303 ['col', [['leaf', 1000], ['leaf', 1001]]]
12304 " The second tab page, with three horizontally split
12305 " windows, with two vertically split windows in the
12306 " middle window
12307 :echo winlayout(2)
12308 ['col', [['leaf', 1002], ['row', [['leaf', 1003],
12309 ['leaf', 1001]]], ['leaf', 1000]]]
12310<
12311 Can also be used as a |method|: >
12312 GetTabnr()->winlayout()
12313<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012314 Return type: list<any>
12315
12316
12317winline() *winline()*
12318 The result is a Number, which is the screen line of the cursor
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012319 in the window. This is counting screen lines from the top of
12320 the window. The first line is one.
12321 If the cursor was moved the view on the file will be updated
12322 first, this may cause a scroll.
12323
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012324 Return type: |Number|
12325
12326
12327winnr([{arg}]) *winnr()*
12328 The result is a Number, which is the number of the current
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012329 window. The top window has number 1.
12330 Returns zero for a popup window.
12331
12332 The optional argument {arg} supports the following values:
12333 $ the number of the last window (the window
12334 count).
12335 # the number of the last accessed window (where
12336 |CTRL-W_p| goes to). If there is no previous
12337 window or it is in another tab page 0 is
Sean Deward64801e2024-03-12 20:46:12 +010012338 returned. May refer to the current window in
12339 some cases (e.g. when evaluating 'statusline'
12340 expressions).
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012341 {N}j the number of the Nth window below the
12342 current window (where |CTRL-W_j| goes to).
12343 {N}k the number of the Nth window above the current
12344 window (where |CTRL-W_k| goes to).
12345 {N}h the number of the Nth window left of the
12346 current window (where |CTRL-W_h| goes to).
12347 {N}l the number of the Nth window right of the
12348 current window (where |CTRL-W_l| goes to).
12349 The number can be used with |CTRL-W_w| and ":wincmd w"
12350 |:wincmd|.
Bram Moolenaar016188f2022-06-06 20:52:59 +010012351 When {arg} is invalid an error is given and zero is returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012352 Also see |tabpagewinnr()| and |win_getid()|.
12353 Examples: >
12354 let window_count = winnr('$')
12355 let prev_window = winnr('#')
12356 let wnum = winnr('3k')
12357
12358< Can also be used as a |method|: >
12359 GetWinval()->winnr()
12360<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012361 Return type: |Number|
12362
12363
12364winrestcmd() *winrestcmd()*
12365 Returns a sequence of |:resize| commands that should restore
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012366 the current window sizes. Only works properly when no windows
12367 are opened or closed and the current window and tab page is
12368 unchanged.
12369 Example: >
12370 :let cmd = winrestcmd()
12371 :call MessWithWindowSizes()
12372 :exe cmd
12373<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012374 Return type: |String|
12375
12376
12377winrestview({dict}) *winrestview()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012378 Uses the |Dictionary| returned by |winsaveview()| to restore
12379 the view of the current window.
12380 Note: The {dict} does not have to contain all values, that are
12381 returned by |winsaveview()|. If values are missing, those
12382 settings won't be restored. So you can use: >
12383 :call winrestview({'curswant': 4})
12384<
12385 This will only set the curswant value (the column the cursor
12386 wants to move on vertical movements) of the cursor to column 5
12387 (yes, that is 5), while all other settings will remain the
12388 same. This is useful, if you set the cursor position manually.
12389
12390 If you have changed the values the result is unpredictable.
12391 If the window size changed the result won't be the same.
12392
12393 Can also be used as a |method|: >
12394 GetView()->winrestview()
12395<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012396 Return type: |Number|
12397
12398
12399winsaveview() *winsaveview()*
12400 Returns a |Dictionary| that contains information to restore
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012401 the view of the current window. Use |winrestview()| to
12402 restore the view.
12403 This is useful if you have a mapping that jumps around in the
12404 buffer and you want to go back to the original view.
12405 This does not save fold information. Use the 'foldenable'
12406 option to temporarily switch off folding, so that folds are
12407 not opened when moving around. This may have side effects.
12408 The return value includes:
12409 lnum cursor line number
12410 col cursor column (Note: the first column
naohiro ono56200ee2022-01-01 14:59:44 +000012411 zero, as opposed to what |getcurpos()|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012412 returns)
12413 coladd cursor column offset for 'virtualedit'
naohiro ono56200ee2022-01-01 14:59:44 +000012414 curswant column for vertical movement (Note:
12415 the first column is zero, as opposed
12416 to what |getcurpos()| returns). After
12417 |$| command it will be a very large
12418 number equal to |v:maxcol|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012419 topline first line in the window
12420 topfill filler lines, only in diff mode
12421 leftcol first column displayed; only used when
12422 'wrap' is off
12423 skipcol columns skipped
12424 Note that no option values are saved.
12425
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012426 Return type: dict<number>
12427
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012428
12429winwidth({nr}) *winwidth()*
12430 The result is a Number, which is the width of window {nr}.
12431 {nr} can be the window number or the |window-ID|.
12432 When {nr} is zero, the width of the current window is
12433 returned. When window {nr} doesn't exist, -1 is returned.
12434 An existing window always has a width of zero or more.
12435 Examples: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +000012436 :echo "The current window has " .. winwidth(0) .. " columns."
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012437 :if winwidth(0) <= 50
12438 : 50 wincmd |
12439 :endif
12440< For getting the terminal or screen size, see the 'columns'
12441 option.
12442
12443 Can also be used as a |method|: >
12444 GetWinid()->winwidth()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012445<
12446 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012447
12448
12449wordcount() *wordcount()*
12450 The result is a dictionary of byte/chars/word statistics for
12451 the current buffer. This is the same info as provided by
12452 |g_CTRL-G|
12453 The return value includes:
12454 bytes Number of bytes in the buffer
12455 chars Number of chars in the buffer
12456 words Number of words in the buffer
12457 cursor_bytes Number of bytes before cursor position
12458 (not in Visual mode)
12459 cursor_chars Number of chars before cursor position
12460 (not in Visual mode)
12461 cursor_words Number of words before cursor position
12462 (not in Visual mode)
12463 visual_bytes Number of bytes visually selected
12464 (only in Visual mode)
12465 visual_chars Number of chars visually selected
12466 (only in Visual mode)
12467 visual_words Number of words visually selected
12468 (only in Visual mode)
12469
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012470 Return type: dict<number>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012471
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012472
12473writefile({object}, {fname} [, {flags}]) *writefile()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012474 When {object} is a |List| write it to file {fname}. Each list
12475 item is separated with a NL. Each list item must be a String
12476 or Number.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012477 All NL characters are replaced with a NUL character.
12478 Inserting CR characters needs to be done before passing {list}
12479 to writefile().
Bram Moolenaar806a2732022-09-04 15:40:36 +010012480
12481 When {object} is a |Blob| write the bytes to file {fname}
12482 unmodified, also when binary mode is not specified.
12483
12484 {flags} must be a String. These characters are recognized:
12485
12486 'b' Binary mode is used: There will not be a NL after the
12487 last list item. An empty item at the end does cause the
12488 last line in the file to end in a NL.
12489
12490 'a' Append mode is used, lines are appended to the file: >
12491 :call writefile(["foo"], "event.log", "a")
12492 :call writefile(["bar"], "event.log", "a")
12493<
12494 'D' Delete the file when the current function ends. This
12495 works like: >
Bram Moolenaar938ae282023-02-20 20:44:55 +000012496 :defer delete({fname})
Bram Moolenaar806a2732022-09-04 15:40:36 +010012497< Fails when not in a function. Also see |:defer|.
12498
12499 's' fsync() is called after writing the file. This flushes
12500 the file to disk, if possible. This takes more time but
12501 avoids losing the file if the system crashes.
12502
12503 'S' fsync() is not called, even when 'fsync' is set.
12504
12505 When {flags} does not contain "S" or "s" then fsync() is
12506 called if the 'fsync' option is set.
12507
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012508 An existing file is overwritten, if possible.
Bram Moolenaar806a2732022-09-04 15:40:36 +010012509
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012510 When the write fails -1 is returned, otherwise 0. There is an
12511 error message if the file can't be created or when writing
12512 fails.
Bram Moolenaar806a2732022-09-04 15:40:36 +010012513
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012514 Also see |readfile()|.
12515 To copy a file byte for byte: >
12516 :let fl = readfile("foo", "b")
12517 :call writefile(fl, "foocopy", "b")
12518
12519< Can also be used as a |method|: >
12520 GetText()->writefile("thefile")
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012521<
12522 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012523
12524
12525xor({expr}, {expr}) *xor()*
12526 Bitwise XOR on the two arguments. The arguments are converted
12527 to a number. A List, Dict or Float argument causes an error.
Bram Moolenaar5a6ec102022-05-27 21:58:00 +010012528 Also see `and()` and `or()`.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012529 Example: >
12530 :let bits = xor(bits, 0x80)
12531<
12532 Can also be used as a |method|: >
12533 :let bits = bits->xor(0x80)
12534<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012535 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012536
12537==============================================================================
125383. Feature list *feature-list*
12539
12540There are three types of features:
125411. Features that are only supported when they have been enabled when Vim
12542 was compiled |+feature-list|. Example: >
12543 :if has("cindent")
12544< *gui_running*
125452. Features that are only supported when certain conditions have been met.
12546 Example: >
12547 :if has("gui_running")
12548< *has-patch*
125493. Beyond a certain version or at a certain version and including a specific
12550 patch. The "patch-7.4.248" feature means that the Vim version is 7.5 or
12551 later, or it is version 7.4 and patch 248 was included. Example: >
12552 :if has("patch-7.4.248")
12553< Note that it's possible for patch 248 to be omitted even though 249 is
12554 included. Only happens when cherry-picking patches.
12555 Note that this form only works for patch 7.4.237 and later, before that
12556 you need to check for the patch and the v:version. Example (checking
12557 version 6.2.148 or later): >
12558 :if v:version > 602 || (v:version == 602 && has("patch148"))
12559
12560Hint: To find out if Vim supports backslashes in a file name (MS-Windows),
12561use: `if exists('+shellslash')`
12562
12563
12564acl Compiled with |ACL| support.
Bram Moolenaar2ee347f2022-08-26 17:53:44 +010012565all_builtin_terms Compiled with all builtin terminals enabled. (always
12566 true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012567amiga Amiga version of Vim.
12568arabic Compiled with Arabic support |Arabic|.
12569arp Compiled with ARP support (Amiga).
12570autocmd Compiled with autocommand support. (always true)
12571autochdir Compiled with support for 'autochdir'
12572autoservername Automatically enable |clientserver|
12573balloon_eval Compiled with |balloon-eval| support.
12574balloon_multiline GUI supports multiline balloons.
12575beos BeOS version of Vim.
12576browse Compiled with |:browse| support, and browse() will
12577 work.
12578browsefilter Compiled with support for |browsefilter|.
12579bsd Compiled on an OS in the BSD family (excluding macOS).
Bram Moolenaar2ee347f2022-08-26 17:53:44 +010012580builtin_terms Compiled with some builtin terminals. (always true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012581byte_offset Compiled with support for 'o' in 'statusline'
12582channel Compiled with support for |channel| and |job|
Bram Moolenaare1dc76f2022-06-25 18:01:32 +010012583cindent Compiled with 'cindent' support. (always true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012584clientserver Compiled with remote invocation support |clientserver|.
12585clipboard Compiled with 'clipboard' support.
12586clipboard_working Compiled with 'clipboard' support and it can be used.
12587cmdline_compl Compiled with |cmdline-completion| support.
12588cmdline_hist Compiled with |cmdline-history| support.
12589cmdline_info Compiled with 'showcmd' and 'ruler' support.
12590comments Compiled with |'comments'| support.
12591compatible Compiled to be very Vi compatible.
12592conpty Platform where |ConPTY| can be used.
12593cryptv Compiled with encryption support |encryption|.
12594cscope Compiled with |cscope| support.
12595cursorbind Compiled with |'cursorbind'| (always true)
12596debug Compiled with "DEBUG" defined.
12597dialog_con Compiled with console dialog support.
glepnirdf461152024-04-04 22:23:29 +020012598dialog_con_gui Compiled with console and GUI dialog support.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012599dialog_gui Compiled with GUI dialog support.
12600diff Compiled with |vimdiff| and 'diff' support.
12601digraphs Compiled with support for digraphs.
12602directx Compiled with support for DirectX and 'renderoptions'.
12603dnd Compiled with support for the "~ register |quote_~|.
12604drop_file Compiled with |drop_file| support.
12605ebcdic Compiled on a machine with ebcdic character set.
12606emacs_tags Compiled with support for Emacs tags.
12607eval Compiled with expression evaluation support. Always
12608 true, of course!
12609ex_extra |+ex_extra| (always true)
12610extra_search Compiled with support for |'incsearch'| and
12611 |'hlsearch'|
12612farsi Support for Farsi was removed |farsi|.
Bram Moolenaarf80f40a2022-08-25 16:02:23 +010012613file_in_path Compiled with support for |gf| and |<cfile>| (always
12614 true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012615filterpipe When 'shelltemp' is off pipes are used for shell
12616 read/write/filter commands
12617find_in_path Compiled with support for include file searches
12618 |+find_in_path|.
12619float Compiled with support for |Float|.
12620fname_case Case in file names matters (for Amiga and MS-Windows
12621 this is not present).
12622folding Compiled with |folding| support.
12623footer Compiled with GUI footer support. |gui-footer|
12624fork Compiled to use fork()/exec() instead of system().
12625gettext Compiled with message translation |multi-lang|
12626gui Compiled with GUI enabled.
Bram Moolenaarcbaff5e2022-04-08 17:45:08 +010012627gui_athena Compiled with Athena GUI (always false).
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012628gui_gnome Compiled with Gnome support (gui_gtk is also defined).
12629gui_gtk Compiled with GTK+ GUI (any version).
12630gui_gtk2 Compiled with GTK+ 2 GUI (gui_gtk is also defined).
12631gui_gtk3 Compiled with GTK+ 3 GUI (gui_gtk is also defined).
12632gui_haiku Compiled with Haiku GUI.
12633gui_mac Compiled with Macintosh GUI.
12634gui_motif Compiled with Motif GUI.
12635gui_photon Compiled with Photon GUI.
12636gui_running Vim is running in the GUI, or it will start soon.
12637gui_win32 Compiled with MS-Windows Win32 GUI.
12638gui_win32s idem, and Win32s system being used (Windows 3.1)
12639haiku Haiku version of Vim.
12640hangul_input Compiled with Hangul input support. |hangul|
12641hpux HP-UX version of Vim.
12642iconv Can use iconv() for conversion.
12643insert_expand Compiled with support for CTRL-X expansion commands in
12644 Insert mode. (always true)
12645job Compiled with support for |channel| and |job|
12646ipv6 Compiled with support for IPv6 networking in |channel|.
Bram Moolenaare1dc76f2022-06-25 18:01:32 +010012647jumplist Compiled with |jumplist| support. (always true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012648keymap Compiled with 'keymap' support.
12649lambda Compiled with |lambda| support.
12650langmap Compiled with 'langmap' support.
12651libcall Compiled with |libcall()| support.
12652linebreak Compiled with 'linebreak', 'breakat', 'showbreak' and
12653 'breakindent' support.
12654linux Linux version of Vim.
12655lispindent Compiled with support for lisp indenting.
Bram Moolenaare1dc76f2022-06-25 18:01:32 +010012656 (always true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012657listcmds Compiled with commands for the buffer list |:files|
12658 and the argument list |arglist|.
12659localmap Compiled with local mappings and abbr. |:map-local|
12660lua Compiled with Lua interface |Lua|.
12661mac Any Macintosh version of Vim cf. osx
12662macunix Synonym for osxdarwin
12663menu Compiled with support for |:menu|.
12664mksession Compiled with support for |:mksession|.
12665modify_fname Compiled with file name modifiers. |filename-modifiers|
12666 (always true)
12667mouse Compiled with support for mouse.
12668mouse_dec Compiled with support for Dec terminal mouse.
12669mouse_gpm Compiled with support for gpm (Linux console mouse)
12670mouse_gpm_enabled GPM mouse is working
12671mouse_netterm Compiled with support for netterm mouse.
12672mouse_pterm Compiled with support for qnx pterm mouse.
12673mouse_sysmouse Compiled with support for sysmouse (*BSD console mouse)
12674mouse_sgr Compiled with support for sgr mouse.
12675mouse_urxvt Compiled with support for urxvt mouse.
12676mouse_xterm Compiled with support for xterm mouse.
12677mouseshape Compiled with support for 'mouseshape'.
12678multi_byte Compiled with support for 'encoding' (always true)
12679multi_byte_encoding 'encoding' is set to a multibyte encoding.
12680multi_byte_ime Compiled with support for IME input method.
12681multi_lang Compiled with support for multiple languages.
12682mzscheme Compiled with MzScheme interface |mzscheme|.
12683nanotime Compiled with sub-second time stamp checks.
12684netbeans_enabled Compiled with support for |netbeans| and connected.
12685netbeans_intg Compiled with support for |netbeans|.
Bram Moolenaare1dc76f2022-06-25 18:01:32 +010012686num64 Compiled with 64-bit |Number| support. (always true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012687ole Compiled with OLE automation support for Win32.
12688osx Compiled for macOS cf. mac
12689osxdarwin Compiled for macOS, with |mac-darwin-feature|
12690packages Compiled with |packages| support.
12691path_extra Compiled with up/downwards search in 'path' and 'tags'
12692perl Compiled with Perl interface.
12693persistent_undo Compiled with support for persistent undo history.
12694postscript Compiled with PostScript file printing.
12695printer Compiled with |:hardcopy| support.
12696profile Compiled with |:profile| support.
Bram Moolenaar71badf92023-04-22 22:40:14 +010012697prof_nsec Profile results are in nanoseconds.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012698python Python 2.x interface available. |has-python|
12699python_compiled Compiled with Python 2.x interface. |has-python|
12700python_dynamic Python 2.x interface is dynamically loaded. |has-python|
12701python3 Python 3.x interface available. |has-python|
12702python3_compiled Compiled with Python 3.x interface. |has-python|
12703python3_dynamic Python 3.x interface is dynamically loaded. |has-python|
Yee Cheng Chinc13b3d12023-08-20 21:18:38 +020012704python3_stable Python 3.x interface is using Python Stable ABI. |has-python|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012705pythonx Python 2.x and/or 3.x interface available. |python_x|
12706qnx QNX version of Vim.
12707quickfix Compiled with |quickfix| support.
12708reltime Compiled with |reltime()| support.
12709rightleft Compiled with 'rightleft' support.
12710ruby Compiled with Ruby interface |ruby|.
12711scrollbind Compiled with 'scrollbind' support. (always true)
12712showcmd Compiled with 'showcmd' support.
12713signs Compiled with |:sign| support.
Bram Moolenaare1dc76f2022-06-25 18:01:32 +010012714smartindent Compiled with 'smartindent' support. (always true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012715sodium Compiled with libsodium for better crypt support
12716sound Compiled with sound support, e.g. `sound_playevent()`
12717spell Compiled with spell checking support |spell|.
12718startuptime Compiled with |--startuptime| support.
12719statusline Compiled with support for 'statusline', 'rulerformat'
12720 and special formats of 'titlestring' and 'iconstring'.
12721sun SunOS version of Vim.
12722sun_workshop Support for Sun |workshop| has been removed.
12723syntax Compiled with syntax highlighting support |syntax|.
12724syntax_items There are active syntax highlighting items for the
12725 current buffer.
12726system Compiled to use system() instead of fork()/exec().
12727tag_binary Compiled with binary searching in tags files
Bram Moolenaare1dc76f2022-06-25 18:01:32 +010012728 |tag-binary-search|. (always true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012729tag_old_static Support for old static tags was removed, see
12730 |tag-old-static|.
12731tcl Compiled with Tcl interface.
12732termguicolors Compiled with true color in terminal support.
12733terminal Compiled with |terminal| support.
12734terminfo Compiled with terminfo instead of termcap.
12735termresponse Compiled with support for |t_RV| and |v:termresponse|.
12736textobjects Compiled with support for |text-objects|.
12737textprop Compiled with support for |text-properties|.
12738tgetent Compiled with tgetent support, able to use a termcap
12739 or terminfo file.
12740timers Compiled with |timer_start()| support.
12741title Compiled with window title support |'title'|.
Bram Moolenaare1dc76f2022-06-25 18:01:32 +010012742 (always true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012743toolbar Compiled with support for |gui-toolbar|.
12744ttyin input is a terminal (tty)
12745ttyout output is a terminal (tty)
12746unix Unix version of Vim. *+unix*
12747unnamedplus Compiled with support for "unnamedplus" in 'clipboard'
12748user_commands User-defined commands. (always true)
12749vartabs Compiled with variable tabstop support |'vartabstop'|.
12750vcon Win32: Virtual console support is working, can use
12751 'termguicolors'. Also see |+vtp|.
12752vertsplit Compiled with vertically split windows |:vsplit|.
12753 (always true)
12754vim_starting True while initial source'ing takes place. |startup|
12755 *vim_starting*
Bram Moolenaara6feb162022-01-02 12:06:33 +000012756vim9script Compiled with |Vim9| script support
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012757viminfo Compiled with viminfo support.
12758vimscript-1 Compiled Vim script version 1 support
12759vimscript-2 Compiled Vim script version 2 support
12760vimscript-3 Compiled Vim script version 3 support
Bram Moolenaar8a3b8052022-06-26 12:21:15 +010012761vimscript-4 Compiled Vim script version 4 support
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012762virtualedit Compiled with 'virtualedit' option. (always true)
12763visual Compiled with Visual mode. (always true)
12764visualextra Compiled with extra Visual mode commands. (always
12765 true) |blockwise-operators|.
12766vms VMS version of Vim.
12767vreplace Compiled with |gR| and |gr| commands. (always true)
12768vtp Compiled for vcon support |+vtp| (check vcon to find
12769 out if it works in the current console).
12770wildignore Compiled with 'wildignore' option.
12771wildmenu Compiled with 'wildmenu' option.
12772win16 old version for MS-Windows 3.1 (always false)
12773win32 Win32 version of Vim (MS-Windows 95 and later, 32 or
12774 64 bits)
12775win32unix Win32 version of Vim, using Unix files (Cygwin)
12776win64 Win64 version of Vim (MS-Windows 64 bit).
12777win95 Win32 version for MS-Windows 95/98/ME (always false)
12778winaltkeys Compiled with 'winaltkeys' option.
12779windows Compiled with support for more than one window.
12780 (always true)
12781writebackup Compiled with 'writebackup' default on.
Christian Brabandte085dfd2023-09-30 12:49:18 +020012782xattr Compiled with extended attributes support |xattr|
12783 (currently only supported on Linux).
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012784xfontset Compiled with X fontset support |xfontset|.
12785xim Compiled with X input method support |xim|.
12786xpm Compiled with pixmap support.
12787xpm_w32 Compiled with pixmap support for Win32. (Only for
12788 backward compatibility. Use "xpm" instead.)
12789xsmp Compiled with X session management support.
12790xsmp_interact Compiled with interactive X session management support.
12791xterm_clipboard Compiled with support for xterm clipboard.
12792xterm_save Compiled with support for saving and restoring the
12793 xterm screen.
12794x11 Compiled with X11 support.
12795
12796
12797==============================================================================
127984. Matching a pattern in a String *string-match*
12799
12800This is common between several functions. A regexp pattern as explained at
12801|pattern| is normally used to find a match in the buffer lines. When a
12802pattern is used to find a match in a String, almost everything works in the
12803same way. The difference is that a String is handled like it is one line.
12804When it contains a "\n" character, this is not seen as a line break for the
12805pattern. It can be matched with a "\n" in the pattern, or with ".". Example:
12806>
12807 :let a = "aaaa\nxxxx"
12808 :echo matchstr(a, "..\n..")
12809 aa
12810 xx
12811 :echo matchstr(a, "a.x")
12812 a
12813 x
12814
12815Don't forget that "^" will only match at the first character of the String and
12816"$" at the last character of the string. They don't match after or before a
12817"\n".
12818
12819 vim:tw=78:ts=8:noet:ft=help:norl: