blob: 94fcdf70c60e683870ec3998d72d20769dd8b453 [file] [log] [blame]
Doug Kearns81642d92024-01-04 22:37:44 +01001*builtin.txt* For Vim version 9.1. Last change: 2024 Jan 04
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}
31appendbufline({expr}, {lnum}, {text})
32 Number append {text} below line {lnum}
33 in buffer {expr}
34argc([{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
70blob2list({blob}) List convert {blob} into a list of numbers
71browse({save}, {title}, {initdir}, {default})
72 String put up a file requester
73browsedir({title}, {initdir}) String put up a directory requester
74bufadd({name}) Number add a buffer to the buffer list
75bufexists({buf}) Number |TRUE| if buffer {buf} exists
76buflisted({buf}) Number |TRUE| if buffer {buf} is listed
77bufload({buf}) Number load buffer {buf} if not loaded yet
78bufloaded({buf}) Number |TRUE| if buffer {buf} is loaded
79bufname([{buf}]) String Name of the buffer {buf}
80bufnr([{buf} [, {create}]]) Number Number of the buffer {buf}
81bufwinid({buf}) Number window ID of buffer {buf}
82bufwinnr({buf}) Number window number of buffer {buf}
83byte2line({byte}) Number line number at byte count {byte}
Christian Brabandt67672ef2023-04-24 21:09:54 +010084byteidx({expr}, {nr} [, {utf16}])
85 Number byte index of {nr}'th char in {expr}
86byteidxcomp({expr}, {nr} [, {utf16}])
87 Number byte index of {nr}'th char in {expr}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000088call({func}, {arglist} [, {dict}])
89 any call {func} with arguments {arglist}
90ceil({expr}) Float round {expr} up
91ch_canread({handle}) Number check if there is something to read
92ch_close({handle}) none close {handle}
93ch_close_in({handle}) none close in part of {handle}
94ch_evalexpr({handle}, {expr} [, {options}])
95 any evaluate {expr} on JSON {handle}
96ch_evalraw({handle}, {string} [, {options}])
97 any evaluate {string} on raw {handle}
98ch_getbufnr({handle}, {what}) Number get buffer number for {handle}/{what}
99ch_getjob({channel}) Job get the Job of {channel}
100ch_info({handle}) String info about channel {handle}
101ch_log({msg} [, {handle}]) none write {msg} in the channel log file
102ch_logfile({fname} [, {mode}]) none start logging channel activity
103ch_open({address} [, {options}])
104 Channel open a channel to {address}
105ch_read({handle} [, {options}]) String read from {handle}
106ch_readblob({handle} [, {options}])
107 Blob read Blob from {handle}
108ch_readraw({handle} [, {options}])
109 String read raw from {handle}
110ch_sendexpr({handle}, {expr} [, {options}])
111 any send {expr} over JSON {handle}
112ch_sendraw({handle}, {expr} [, {options}])
113 any send {expr} over raw {handle}
114ch_setoptions({handle}, {options})
115 none set options for {handle}
116ch_status({handle} [, {options}])
117 String status of channel {handle}
118changenr() Number current change number
119char2nr({expr} [, {utf8}]) Number ASCII/UTF-8 value of first char in {expr}
120charclass({string}) Number character class of {string}
Yegappan Lakshmanan4c8d2f02022-11-12 16:07:47 +0000121charcol({expr} [, {winid}]) Number column number of cursor or mark
Christian Brabandt67672ef2023-04-24 21:09:54 +0100122charidx({string}, {idx} [, {countcc} [, {utf16}]])
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000123 Number char index of byte {idx} in {string}
124chdir({dir}) String change current working directory
125cindent({lnum}) Number C indent for line {lnum}
126clearmatches([{win}]) none clear all matches
Yegappan Lakshmanan4c8d2f02022-11-12 16:07:47 +0000127col({expr} [, {winid}]) Number column byte index of cursor or mark
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000128complete({startcol}, {matches}) none set Insert mode completion
129complete_add({expr}) Number add completion match
130complete_check() Number check for key typed during completion
131complete_info([{what}]) Dict get current completion information
132confirm({msg} [, {choices} [, {default} [, {type}]]])
133 Number number of choice picked by user
134copy({expr}) any make a shallow copy of {expr}
135cos({expr}) Float cosine of {expr}
136cosh({expr}) Float hyperbolic cosine of {expr}
137count({comp}, {expr} [, {ic} [, {start}]])
138 Number count how many {expr} are in {comp}
139cscope_connection([{num}, {dbpath} [, {prepend}]])
140 Number checks existence of cscope connection
141cursor({lnum}, {col} [, {off}])
142 Number move cursor to {lnum}, {col}, {off}
143cursor({list}) Number move cursor to position in {list}
144debugbreak({pid}) Number interrupt process being debugged
145deepcopy({expr} [, {noref}]) any make a full copy of {expr}
146delete({fname} [, {flags}]) Number delete the file or directory {fname}
147deletebufline({buf}, {first} [, {last}])
148 Number delete lines from buffer {buf}
149did_filetype() Number |TRUE| if FileType autocmd event used
150diff_filler({lnum}) Number diff filler lines about {lnum}
151diff_hlID({lnum}, {col}) Number diff highlighting at {lnum}/{col}
152digraph_get({chars}) String get the |digraph| of {chars}
153digraph_getlist([{listall}]) List get all |digraph|s
154digraph_set({chars}, {digraph}) Boolean register |digraph|
155digraph_setlist({digraphlist}) Boolean register multiple |digraph|s
156echoraw({expr}) none output {expr} as-is
157empty({expr}) Number |TRUE| if {expr} is empty
158environ() Dict return environment variables
Sean Dewarb0efa492023-07-08 10:35:19 +0100159err_teapot([{expr}]) none give E418, or E503 if {expr} is |TRUE|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000160escape({string}, {chars}) String escape {chars} in {string} with '\'
161eval({string}) any evaluate {string} into its value
162eventhandler() Number |TRUE| if inside an event handler
163executable({expr}) Number 1 if executable {expr} exists
164execute({command}) String execute {command} and get the output
165exepath({expr}) String full path of the command {expr}
166exists({expr}) Number |TRUE| if {expr} exists
167exists_compiled({expr}) Number |TRUE| if {expr} exists at compile time
168exp({expr}) Float exponential of {expr}
169expand({expr} [, {nosuf} [, {list}]])
170 any expand special keywords in {expr}
Yegappan Lakshmanan2b74b682022-04-03 21:30:32 +0100171expandcmd({string} [, {options}])
172 String expand {string} like with `:edit`
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000173extend({expr1}, {expr2} [, {expr3}])
174 List/Dict insert items of {expr2} into {expr1}
175extendnew({expr1}, {expr2} [, {expr3}])
176 List/Dict like |extend()| but creates a new
177 List or Dictionary
178feedkeys({string} [, {mode}]) Number add key sequence to typeahead buffer
179filereadable({file}) Number |TRUE| if {file} is a readable file
180filewritable({file}) Number |TRUE| if {file} is a writable file
181filter({expr1}, {expr2}) List/Dict/Blob/String
182 remove items from {expr1} where
183 {expr2} is 0
184finddir({name} [, {path} [, {count}]])
185 String find directory {name} in {path}
186findfile({name} [, {path} [, {count}]])
187 String find file {name} in {path}
188flatten({list} [, {maxdepth}]) List flatten {list} up to {maxdepth} levels
189flattennew({list} [, {maxdepth}])
190 List flatten a copy of {list}
191float2nr({expr}) Number convert Float {expr} to a Number
192floor({expr}) Float round {expr} down
193fmod({expr1}, {expr2}) Float remainder of {expr1} / {expr2}
194fnameescape({fname}) String escape special characters in {fname}
195fnamemodify({fname}, {mods}) String modify file name
196foldclosed({lnum}) Number first line of fold at {lnum} if closed
197foldclosedend({lnum}) Number last line of fold at {lnum} if closed
198foldlevel({lnum}) Number fold level at {lnum}
199foldtext() String line displayed for closed fold
200foldtextresult({lnum}) String text for closed fold at {lnum}
201foreground() Number bring the Vim window to the foreground
Bram Moolenaaraa534142022-09-15 21:46:02 +0100202fullcommand({name} [, {vim9}]) String get full command from {name}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000203funcref({name} [, {arglist}] [, {dict}])
204 Funcref reference to function {name}
205function({name} [, {arglist}] [, {dict}])
206 Funcref named reference to function {name}
207garbagecollect([{atexit}]) none free memory, breaking cyclic references
208get({list}, {idx} [, {def}]) any get item {idx} from {list} or {def}
209get({dict}, {key} [, {def}]) any get item {key} from {dict} or {def}
210get({func}, {what}) any get property of funcref/partial {func}
211getbufinfo([{buf}]) List information about buffers
212getbufline({buf}, {lnum} [, {end}])
213 List lines {lnum} to {end} of buffer {buf}
Bram Moolenaarce30ccc2022-11-21 19:57:04 +0000214getbufoneline({buf}, {lnum}) String line {lnum} of buffer {buf}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000215getbufvar({buf}, {varname} [, {def}])
216 any variable {varname} in buffer {buf}
Kota Kato66bb9ae2023-01-17 18:31:56 +0000217getcellwidths() List get character cell width overrides
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000218getchangelist([{buf}]) List list of change list items
219getchar([expr]) Number or String
220 get one character from the user
221getcharmod() Number modifiers for the last typed character
222getcharpos({expr}) List position of cursor, mark, etc.
223getcharsearch() Dict last character search
224getcharstr([expr]) String get one character from the user
Shougo Matsushita79d599b2022-05-07 12:48:29 +0100225getcmdcompltype() String return the type of the current
226 command-line completion
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000227getcmdline() String return the current command-line
228getcmdpos() Number return cursor position in command-line
Shougo Matsushita79d599b2022-05-07 12:48:29 +0100229getcmdscreenpos() Number return cursor screen position in
230 command-line
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000231getcmdtype() String return current command-line type
232getcmdwintype() String return current command-line window type
233getcompletion({pat}, {type} [, {filtered}])
234 List list of cmdline completion matches
235getcurpos([{winnr}]) List position of the cursor
236getcursorcharpos([{winnr}]) List character position of the cursor
237getcwd([{winnr} [, {tabnr}]]) String get the current working directory
238getenv({name}) String return environment variable
239getfontname([{name}]) String name of font being used
240getfperm({fname}) String file permissions of file {fname}
241getfsize({fname}) Number size in bytes of file {fname}
242getftime({fname}) Number last modification time of file
243getftype({fname}) String description of type of file {fname}
244getimstatus() Number |TRUE| if the IME status is active
245getjumplist([{winnr} [, {tabnr}]])
246 List list of jump list items
247getline({lnum}) String line {lnum} of current buffer
248getline({lnum}, {end}) List lines {lnum} to {end} of current buffer
249getloclist({nr}) List list of location list items
250getloclist({nr}, {what}) Dict get specific location list properties
251getmarklist([{buf}]) List list of global/local marks
252getmatches([{win}]) List list of current matches
253getmousepos() Dict last known mouse position
Bram Moolenaar24dc19c2022-11-14 19:49:15 +0000254getmouseshape() String current mouse shape name
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000255getpid() Number process ID of Vim
256getpos({expr}) List position of cursor, mark, etc.
257getqflist() List list of quickfix items
258getqflist({what}) Dict get specific quickfix list properties
259getreg([{regname} [, 1 [, {list}]]])
260 String or List contents of a register
261getreginfo([{regname}]) Dict information about a register
262getregtype([{regname}]) String type of a register
Yegappan Lakshmanan520f6ef2022-08-25 17:40:40 +0100263getscriptinfo([{opts}]) List list of sourced scripts
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000264gettabinfo([{expr}]) List list of tab pages
265gettabvar({nr}, {varname} [, {def}])
266 any variable {varname} in tab {nr} or {def}
267gettabwinvar({tabnr}, {winnr}, {name} [, {def}])
268 any {name} in {winnr} in tab page {tabnr}
269gettagstack([{nr}]) Dict get the tag stack of window {nr}
270gettext({text}) String lookup translation of {text}
271getwininfo([{winid}]) List list of info about each window
Bram Moolenaar938ae282023-02-20 20:44:55 +0000272getwinpos([{timeout}]) List X and Y coord in pixels of Vim window
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000273getwinposx() Number X coord in pixels of the Vim window
274getwinposy() Number Y coord in pixels of the Vim window
275getwinvar({nr}, {varname} [, {def}])
276 any variable {varname} in window {nr}
277glob({expr} [, {nosuf} [, {list} [, {alllinks}]]])
278 any expand file wildcards in {expr}
279glob2regpat({expr}) String convert a glob pat into a search pat
280globpath({path}, {expr} [, {nosuf} [, {list} [, {alllinks}]]])
281 String do glob({expr}) for all dirs in {path}
282has({feature} [, {check}]) Number |TRUE| if feature {feature} supported
283has_key({dict}, {key}) Number |TRUE| if {dict} has entry {key}
284haslocaldir([{winnr} [, {tabnr}]])
285 Number |TRUE| if the window executed |:lcd|
286 or |:tcd|
287hasmapto({what} [, {mode} [, {abbr}]])
288 Number |TRUE| if mapping to {what} exists
289histadd({history}, {item}) Number add an item to a history
290histdel({history} [, {item}]) Number remove an item from a history
291histget({history} [, {index}]) String get the item {index} from a history
292histnr({history}) Number highest index of a history
293hlID({name}) Number syntax ID of highlight group {name}
294hlexists({name}) Number |TRUE| if highlight group {name} exists
295hlget([{name} [, {resolve}]]) List get highlight group attributes
296hlset({list}) Number set highlight group attributes
297hostname() String name of the machine Vim is running on
298iconv({expr}, {from}, {to}) String convert encoding of {expr}
299indent({lnum}) Number indent of line {lnum}
300index({object}, {expr} [, {start} [, {ic}]])
301 Number index in {object} where {expr} appears
Yegappan Lakshmananb2186552022-08-13 13:09:20 +0100302indexof({object}, {expr} [, {opts}]])
303 Number index in {object} where {expr} is true
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000304input({prompt} [, {text} [, {completion}]])
305 String get input from the user
Bram Moolenaarb529cfb2022-07-25 15:42:07 +0100306inputdialog({prompt} [, {text} [, {cancelreturn}]])
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000307 String like input() but in a GUI dialog
308inputlist({textlist}) Number let the user pick from a choice list
309inputrestore() Number restore typeahead
310inputsave() Number save and clear typeahead
311inputsecret({prompt} [, {text}]) String like input() but hiding the text
312insert({object}, {item} [, {idx}]) List insert {item} in {object} [before {idx}]
LemonBoyafe04662023-08-23 21:08:11 +0200313instanceof({object}, {class}) Number |TRUE| if {object} is an instance of {class}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000314interrupt() none interrupt script execution
315invert({expr}) Number bitwise invert
LemonBoydca1d402022-04-28 15:26:33 +0100316isabsolutepath({path}) Number |TRUE| if {path} is an absolute path
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000317isdirectory({directory}) Number |TRUE| if {directory} is a directory
318isinf({expr}) Number determine if {expr} is infinity value
319 (positive or negative)
320islocked({expr}) Number |TRUE| if {expr} is locked
321isnan({expr}) Number |TRUE| if {expr} is NaN
322items({dict}) List key-value pairs in {dict}
323job_getchannel({job}) Channel get the channel handle for {job}
324job_info([{job}]) Dict get information about {job}
325job_setoptions({job}, {options}) none set options for {job}
326job_start({command} [, {options}])
327 Job start a job
328job_status({job}) String get the status of {job}
329job_stop({job} [, {how}]) Number stop {job}
330join({list} [, {sep}]) String join {list} items into one String
331js_decode({string}) any decode JS style JSON
332js_encode({expr}) String encode JS style JSON
333json_decode({string}) any decode JSON
334json_encode({expr}) String encode JSON
335keys({dict}) List keys in {dict}
zeertzjqcdc83932022-09-12 13:38:41 +0100336keytrans({string}) String translate internal keycodes to a form
337 that can be used by |:map|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000338len({expr}) Number the length of {expr}
339libcall({lib}, {func}, {arg}) String call {func} in library {lib} with {arg}
340libcallnr({lib}, {func}, {arg}) Number idem, but return a Number
341line({expr} [, {winid}]) Number line nr of cursor, last line or mark
342line2byte({lnum}) Number byte count of line {lnum}
343lispindent({lnum}) Number Lisp indent for line {lnum}
344list2blob({list}) Blob turn {list} of numbers into a Blob
345list2str({list} [, {utf8}]) String turn {list} of numbers into a String
346listener_add({callback} [, {buf}])
347 Number add a callback to listen to changes
348listener_flush([{buf}]) none invoke listener callbacks
349listener_remove({id}) none remove a listener callback
350localtime() Number current time
351log({expr}) Float natural logarithm (base e) of {expr}
352log10({expr}) Float logarithm of Float {expr} to base 10
353luaeval({expr} [, {expr}]) any evaluate |Lua| expression
354map({expr1}, {expr2}) List/Dict/Blob/String
355 change each item in {expr1} to {expr2}
356maparg({name} [, {mode} [, {abbr} [, {dict}]]])
357 String or Dict
358 rhs of mapping {name} in mode {mode}
359mapcheck({name} [, {mode} [, {abbr}]])
360 String check for mappings matching {name}
Ernie Rael09661202022-04-25 14:40:44 +0100361maplist([{abbr}]) List list of all mappings, a dict for each
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000362mapnew({expr1}, {expr2}) List/Dict/Blob/String
363 like |map()| but creates a new List or
364 Dictionary
365mapset({mode}, {abbr}, {dict}) none restore mapping from |maparg()| result
366match({expr}, {pat} [, {start} [, {count}]])
367 Number position where {pat} matches in {expr}
368matchadd({group}, {pattern} [, {priority} [, {id} [, {dict}]]])
369 Number highlight {pattern} with {group}
370matchaddpos({group}, {pos} [, {priority} [, {id} [, {dict}]]])
371 Number highlight positions with {group}
372matcharg({nr}) List arguments of |:match|
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +0100373matchbufline({buf}, {pat}, {lnum}, {end}, [, {dict})
374 List all the {pat} matches in buffer {buf}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000375matchdelete({id} [, {win}]) Number delete match identified by {id}
376matchend({expr}, {pat} [, {start} [, {count}]])
377 Number position where {pat} ends in {expr}
378matchfuzzy({list}, {str} [, {dict}])
379 List fuzzy match {str} in {list}
380matchfuzzypos({list}, {str} [, {dict}])
381 List fuzzy match {str} in {list}
382matchlist({expr}, {pat} [, {start} [, {count}]])
383 List match and submatches of {pat} in {expr}
384matchstr({expr}, {pat} [, {start} [, {count}]])
385 String {count}'th match of {pat} in {expr}
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +0100386matchstrlist({list}, {pat} [, {dict})
387 List all the {pat} matches in {list}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000388matchstrpos({expr}, {pat} [, {start} [, {count}]])
389 List {count}'th match of {pat} in {expr}
390max({expr}) Number maximum value of items in {expr}
391menu_info({name} [, {mode}]) Dict get menu item information
392min({expr}) Number minimum value of items in {expr}
Bram Moolenaar938ae282023-02-20 20:44:55 +0000393mkdir({name} [, {flags} [, {prot}]])
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000394 Number create directory {name}
395mode([expr]) String current editing mode
396mzeval({expr}) any evaluate |MzScheme| expression
397nextnonblank({lnum}) Number line nr of non-blank line >= {lnum}
398nr2char({expr} [, {utf8}]) String single char with ASCII/UTF-8 value {expr}
399or({expr}, {expr}) Number bitwise OR
400pathshorten({expr} [, {len}]) String shorten directory names in a path
401perleval({expr}) any evaluate |Perl| expression
402popup_atcursor({what}, {options}) Number create popup window near the cursor
403popup_beval({what}, {options}) Number create popup window for 'ballooneval'
404popup_clear() none close all popup windows
405popup_close({id} [, {result}]) none close popup window {id}
406popup_create({what}, {options}) Number create a popup window
407popup_dialog({what}, {options}) Number create a popup window used as a dialog
408popup_filter_menu({id}, {key}) Number filter for a menu popup window
409popup_filter_yesno({id}, {key}) Number filter for a dialog popup window
Bram Moolenaarbdc09a12022-10-07 14:31:45 +0100410popup_findecho() Number get window ID of popup for `:echowin`
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000411popup_findinfo() Number get window ID of info popup window
412popup_findpreview() Number get window ID of preview popup window
413popup_getoptions({id}) Dict get options of popup window {id}
414popup_getpos({id}) Dict get position of popup window {id}
415popup_hide({id}) none hide popup menu {id}
416popup_list() List get a list of window IDs of all popups
417popup_locate({row}, {col}) Number get window ID of popup at position
418popup_menu({what}, {options}) Number create a popup window used as a menu
419popup_move({id}, {options}) none set position of popup window {id}
420popup_notification({what}, {options})
421 Number create a notification popup window
422popup_setoptions({id}, {options})
423 none set options for popup window {id}
424popup_settext({id}, {text}) none set the text of popup window {id}
425popup_show({id}) none unhide popup window {id}
426pow({x}, {y}) Float {x} to the power of {y}
427prevnonblank({lnum}) Number line nr of non-blank line <= {lnum}
428printf({fmt}, {expr1}...) String format text
429prompt_getprompt({buf}) String get prompt text
430prompt_setcallback({buf}, {expr}) none set prompt callback function
431prompt_setinterrupt({buf}, {text}) none set prompt interrupt function
432prompt_setprompt({buf}, {text}) none set prompt text
433prop_add({lnum}, {col}, {props}) none add one text property
434prop_add_list({props}, [[{lnum}, {col}, {end-lnum}, {end-col}], ...])
435 none add multiple text properties
436prop_clear({lnum} [, {lnum-end} [, {props}]])
437 none remove all text properties
438prop_find({props} [, {direction}])
439 Dict search for a text property
440prop_list({lnum} [, {props}]) List text properties in {lnum}
441prop_remove({props} [, {lnum} [, {lnum-end}]])
442 Number remove a text property
443prop_type_add({name}, {props}) none define a new property type
444prop_type_change({name}, {props})
445 none change an existing property type
446prop_type_delete({name} [, {props}])
447 none delete a property type
448prop_type_get({name} [, {props}])
449 Dict get property type values
450prop_type_list([{props}]) List get list of property types
451pum_getpos() Dict position and size of pum if visible
452pumvisible() Number whether popup menu is visible
453py3eval({expr}) any evaluate |python3| expression
454pyeval({expr}) any evaluate |Python| expression
455pyxeval({expr}) any evaluate |python_x| expression
456rand([{expr}]) Number get pseudo-random number
457range({expr} [, {max} [, {stride}]])
458 List items from {expr} to {max}
K.Takata11df3ae2022-10-19 14:02:40 +0100459readblob({fname} [, {offset} [, {size}]])
460 Blob read a |Blob| from {fname}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000461readdir({dir} [, {expr} [, {dict}]])
462 List file names in {dir} selected by {expr}
463readdirex({dir} [, {expr} [, {dict}]])
464 List file info in {dir} selected by {expr}
465readfile({fname} [, {type} [, {max}]])
466 List get list of lines from file {fname}
467reduce({object}, {func} [, {initial}])
468 any reduce {object} using {func}
469reg_executing() String get the executing register name
470reg_recording() String get the recording register name
471reltime([{start} [, {end}]]) List get time value
472reltimefloat({time}) Float turn the time value into a Float
473reltimestr({time}) String turn time value into a String
474remote_expr({server}, {string} [, {idvar} [, {timeout}]])
475 String send expression
476remote_foreground({server}) Number bring Vim server to the foreground
477remote_peek({serverid} [, {retvar}])
478 Number check for reply string
479remote_read({serverid} [, {timeout}])
480 String read reply string
481remote_send({server}, {string} [, {idvar}])
482 String send key sequence
483remote_startserver({name}) none become server {name}
484remove({list}, {idx} [, {end}]) any/List
485 remove items {idx}-{end} from {list}
486remove({blob}, {idx} [, {end}]) Number/Blob
487 remove bytes {idx}-{end} from {blob}
488remove({dict}, {key}) any remove entry {key} from {dict}
489rename({from}, {to}) Number rename (move) file from {from} to {to}
Bakudankun375141e2022-09-09 18:46:47 +0100490repeat({expr}, {count}) List/Blob/String
491 repeat {expr} {count} times
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000492resolve({filename}) String get filename a shortcut points to
Yegappan Lakshmanan03ff1c22023-05-06 14:08:21 +0100493reverse({obj}) List/Blob/String
494 reverse {obj}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000495round({expr}) Float round off {expr}
496rubyeval({expr}) any evaluate |Ruby| expression
497screenattr({row}, {col}) Number attribute at screen position
498screenchar({row}, {col}) Number character at screen position
499screenchars({row}, {col}) List List of characters at screen position
500screencol() Number current cursor column
501screenpos({winid}, {lnum}, {col}) Dict screen row and col of a text character
502screenrow() Number current cursor row
503screenstring({row}, {col}) String characters at screen position
504search({pattern} [, {flags} [, {stopline} [, {timeout} [, {skip}]]]])
505 Number search for {pattern}
506searchcount([{options}]) Dict get or update search stats
507searchdecl({name} [, {global} [, {thisblock}]])
508 Number search for variable declaration
509searchpair({start}, {middle}, {end} [, {flags} [, {skip} [...]]])
510 Number search for other end of start/end pair
511searchpairpos({start}, {middle}, {end} [, {flags} [, {skip} [...]]])
512 List search for other end of start/end pair
513searchpos({pattern} [, {flags} [, {stopline} [, {timeout} [, {skip}]]]])
514 List search for {pattern}
515server2client({clientid}, {string})
516 Number send reply string
517serverlist() String get a list of available servers
518setbufline({expr}, {lnum}, {text})
519 Number set line {lnum} to {text} in buffer
520 {expr}
521setbufvar({buf}, {varname}, {val})
522 none set {varname} in buffer {buf} to {val}
523setcellwidths({list}) none set character cell width overrides
524setcharpos({expr}, {list}) Number set the {expr} position to {list}
525setcharsearch({dict}) Dict set character search from {dict}
Shougo Matsushita07ea5f12022-08-27 12:22:25 +0100526setcmdline({str} [, {pos}]) Number set command-line
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000527setcmdpos({pos}) Number set cursor position in command-line
528setcursorcharpos({list}) Number move cursor to position in {list}
529setenv({name}, {val}) none set environment variable
530setfperm({fname}, {mode}) Number set {fname} file permissions to {mode}
531setline({lnum}, {line}) Number set line {lnum} to {line}
532setloclist({nr}, {list} [, {action}])
533 Number modify location list using {list}
534setloclist({nr}, {list}, {action}, {what})
535 Number modify specific location list props
536setmatches({list} [, {win}]) Number restore a list of matches
537setpos({expr}, {list}) Number set the {expr} position to {list}
538setqflist({list} [, {action}]) Number modify quickfix list using {list}
539setqflist({list}, {action}, {what})
540 Number modify specific quickfix list props
541setreg({n}, {v} [, {opt}]) Number set register to value and type
542settabvar({nr}, {varname}, {val}) none set {varname} in tab page {nr} to {val}
543settabwinvar({tabnr}, {winnr}, {varname}, {val})
544 none set {varname} in window {winnr} in tab
545 page {tabnr} to {val}
546settagstack({nr}, {dict} [, {action}])
547 Number modify tag stack using {dict}
548setwinvar({nr}, {varname}, {val}) none set {varname} in window {nr} to {val}
549sha256({string}) String SHA256 checksum of {string}
550shellescape({string} [, {special}])
551 String escape {string} for use as shell
552 command argument
553shiftwidth([{col}]) Number effective value of 'shiftwidth'
554sign_define({name} [, {dict}]) Number define or update a sign
555sign_define({list}) List define or update a list of signs
556sign_getdefined([{name}]) List get a list of defined signs
557sign_getplaced([{buf} [, {dict}]])
558 List get a list of placed signs
559sign_jump({id}, {group}, {buf})
560 Number jump to a sign
561sign_place({id}, {group}, {name}, {buf} [, {dict}])
562 Number place a sign
563sign_placelist({list}) List place a list of signs
564sign_undefine([{name}]) Number undefine a sign
565sign_undefine({list}) List undefine a list of signs
566sign_unplace({group} [, {dict}])
567 Number unplace a sign
568sign_unplacelist({list}) List unplace a list of signs
569simplify({filename}) String simplify filename as much as possible
570sin({expr}) Float sine of {expr}
571sinh({expr}) Float hyperbolic sine of {expr}
572slice({expr}, {start} [, {end}]) String, List or Blob
573 slice of a String, List or Blob
Bram Moolenaar2007dd42022-02-23 13:17:47 +0000574sort({list} [, {how} [, {dict}]])
575 List sort {list}, compare with {how}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000576sound_clear() none stop playing all sounds
577sound_playevent({name} [, {callback}])
578 Number play an event sound
579sound_playfile({path} [, {callback}])
580 Number play sound file {path}
581sound_stop({id}) none stop playing sound {id}
582soundfold({word}) String sound-fold {word}
583spellbadword() String badly spelled word at cursor
584spellsuggest({word} [, {max} [, {capital}]])
585 List spelling suggestions
586split({expr} [, {pat} [, {keepempty}]])
587 List make |List| from {pat} separated {expr}
588sqrt({expr}) Float square root of {expr}
589srand([{expr}]) List get seed for |rand()|
590state([{what}]) String current state of Vim
591str2float({expr} [, {quoted}]) Float convert String to Float
592str2list({expr} [, {utf8}]) List convert each character of {expr} to
593 ASCII/UTF-8 value
594str2nr({expr} [, {base} [, {quoted}]])
595 Number convert String to Number
596strcharlen({expr}) Number character length of the String {expr}
597strcharpart({str}, {start} [, {len} [, {skipcc}]])
598 String {len} characters of {str} at
599 character {start}
600strchars({expr} [, {skipcc}]) Number character count of the String {expr}
601strdisplaywidth({expr} [, {col}]) Number display length of the String {expr}
602strftime({format} [, {time}]) String format time with a specified format
603strgetchar({str}, {index}) Number get char {index} from {str}
604stridx({haystack}, {needle} [, {start}])
605 Number index of {needle} in {haystack}
606string({expr}) String String representation of {expr} value
607strlen({expr}) Number length of the String {expr}
608strpart({str}, {start} [, {len} [, {chars}]])
609 String {len} bytes/chars of {str} at
610 byte {start}
611strptime({format}, {timestring})
612 Number Convert {timestring} to unix timestamp
613strridx({haystack}, {needle} [, {start}])
614 Number last index of {needle} in {haystack}
615strtrans({expr}) String translate string to make it printable
Christian Brabandt67672ef2023-04-24 21:09:54 +0100616strutf16len({string} [, {countcc}])
617 Number number of UTF-16 code units in {string}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000618strwidth({expr}) Number display cell length of the String {expr}
619submatch({nr} [, {list}]) String or List
620 specific match in ":s" or substitute()
621substitute({expr}, {pat}, {sub}, {flags})
622 String all {pat} in {expr} replaced with {sub}
Bram Moolenaarc216a7a2022-12-05 13:50:55 +0000623swapfilelist() List swap files found in 'directory'
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000624swapinfo({fname}) Dict information about swap file {fname}
625swapname({buf}) String swap file of buffer {buf}
626synID({lnum}, {col}, {trans}) Number syntax ID at {lnum} and {col}
627synIDattr({synID}, {what} [, {mode}])
628 String attribute {what} of syntax ID {synID}
629synIDtrans({synID}) Number translated syntax ID of {synID}
630synconcealed({lnum}, {col}) List info about concealing
631synstack({lnum}, {col}) List stack of syntax IDs at {lnum} and {col}
632system({expr} [, {input}]) String output of shell command/filter {expr}
633systemlist({expr} [, {input}]) List output of shell command/filter {expr}
634tabpagebuflist([{arg}]) List list of buffer numbers in tab page
635tabpagenr([{arg}]) Number number of current or last tab page
636tabpagewinnr({tabarg} [, {arg}]) Number number of current window in tab page
637tagfiles() List tags files used
638taglist({expr} [, {filename}]) List list of tags matching {expr}
639tan({expr}) Float tangent of {expr}
640tanh({expr}) Float hyperbolic tangent of {expr}
641tempname() String name for a temporary file
642term_dumpdiff({filename}, {filename} [, {options}])
643 Number display difference between two dumps
644term_dumpload({filename} [, {options}])
645 Number displaying a screen dump
646term_dumpwrite({buf}, {filename} [, {options}])
647 none dump terminal window contents
648term_getaltscreen({buf}) Number get the alternate screen flag
649term_getansicolors({buf}) List get ANSI palette in GUI color mode
650term_getattr({attr}, {what}) Number get the value of attribute {what}
651term_getcursor({buf}) List get the cursor position of a terminal
652term_getjob({buf}) Job get the job associated with a terminal
653term_getline({buf}, {row}) String get a line of text from a terminal
654term_getscrolled({buf}) Number get the scroll count of a terminal
655term_getsize({buf}) List get the size of a terminal
656term_getstatus({buf}) String get the status of a terminal
657term_gettitle({buf}) String get the title of a terminal
658term_gettty({buf}, [{input}]) String get the tty name of a terminal
659term_list() List get the list of terminal buffers
660term_scrape({buf}, {row}) List get row of a terminal screen
661term_sendkeys({buf}, {keys}) none send keystrokes to a terminal
662term_setansicolors({buf}, {colors})
663 none set ANSI palette in GUI color mode
664term_setapi({buf}, {expr}) none set |terminal-api| function name prefix
665term_setkill({buf}, {how}) none set signal to stop job in terminal
666term_setrestore({buf}, {command}) none set command to restore terminal
667term_setsize({buf}, {rows}, {cols})
668 none set the size of a terminal
669term_start({cmd} [, {options}]) Number open a terminal window and run a job
670term_wait({buf} [, {time}]) Number wait for screen to be updated
671terminalprops() Dict properties of the terminal
672test_alloc_fail({id}, {countdown}, {repeat})
673 none make memory allocation fail
674test_autochdir() none enable 'autochdir' during startup
675test_feedinput({string}) none add key sequence to input buffer
676test_garbagecollect_now() none free memory right now for testing
677test_garbagecollect_soon() none free memory soon for testing
678test_getvalue({string}) any get value of an internal variable
Yegappan Lakshmanan06011e12022-01-30 12:37:29 +0000679test_gui_event({event}, {args}) bool generate a GUI event for testing
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000680test_ignore_error({expr}) none ignore a specific error
Christopher Plewright20b795e2022-12-20 20:01:58 +0000681test_mswin_event({event}, {args})
682 bool generate MS-Windows event for testing
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000683test_null_blob() Blob null value for testing
684test_null_channel() Channel null value for testing
685test_null_dict() Dict null value for testing
686test_null_function() Funcref null value for testing
687test_null_job() Job null value for testing
688test_null_list() List null value for testing
689test_null_partial() Funcref null value for testing
690test_null_string() String null value for testing
691test_option_not_set({name}) none reset flag indicating option was set
692test_override({expr}, {val}) none test with Vim internal overrides
693test_refcount({expr}) Number get the reference count of {expr}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000694test_setmouse({row}, {col}) none set the mouse position for testing
695test_settime({expr}) none set current time for testing
696test_srand_seed([seed]) none set seed for testing srand()
697test_unknown() any unknown value for testing
698test_void() any void value for testing
699timer_info([{id}]) List information about timers
700timer_pause({id}, {pause}) none pause or unpause a timer
701timer_start({time}, {callback} [, {options}])
702 Number create a timer
703timer_stop({timer}) none stop a timer
704timer_stopall() none stop all timers
705tolower({expr}) String the String {expr} switched to lowercase
706toupper({expr}) String the String {expr} switched to uppercase
707tr({src}, {fromstr}, {tostr}) String translate chars of {src} in {fromstr}
708 to chars in {tostr}
709trim({text} [, {mask} [, {dir}]])
710 String trim characters in {mask} from {text}
711trunc({expr}) Float truncate Float {expr}
712type({expr}) Number type of value {expr}
713typename({expr}) String representation of the type of {expr}
714undofile({name}) String undo file name for {name}
Devin J. Pohly5fee1112023-04-23 20:26:59 -0500715undotree([{buf}]) List undo file tree for buffer {buf}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000716uniq({list} [, {func} [, {dict}]])
717 List remove adjacent duplicates from a list
Christian Brabandt67672ef2023-04-24 21:09:54 +0100718utf16idx({string}, {idx} [, {countcc} [, {charidx}]])
719 Number UTF-16 index of byte {idx} in {string}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000720values({dict}) List values in {dict}
zeertzjq825cf812023-08-17 22:55:25 +0200721virtcol({expr} [, {list} [, {winid}])
722 Number or List
LemonBoy0f7a3e12022-05-26 12:10:37 +0100723 screen column of cursor or mark
Bram Moolenaar5a6ec102022-05-27 21:58:00 +0100724virtcol2col({winid}, {lnum}, {col})
725 Number byte index of a character on screen
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000726visualmode([expr]) String last visual mode used
727wildmenumode() Number whether 'wildmenu' mode is active
728win_execute({id}, {command} [, {silent}])
729 String execute {command} in window {id}
730win_findbuf({bufnr}) List find windows containing {bufnr}
731win_getid([{win} [, {tab}]]) Number get window ID for {win} in {tab}
732win_gettype([{nr}]) String type of window {nr}
733win_gotoid({expr}) Number go to window with ID {expr}
734win_id2tabwin({expr}) List get tab and window nr from window ID
735win_id2win({expr}) Number get window nr from window ID
Daniel Steinbergee630312022-01-10 13:36:34 +0000736win_move_separator({nr}) Number move window vertical separator
737win_move_statusline({nr}) Number move window status line
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000738win_screenpos({nr}) List get screen position of window {nr}
739win_splitmove({nr}, {target} [, {options}])
740 Number move window {nr} to split of {target}
741winbufnr({nr}) Number buffer number of window {nr}
742wincol() Number window column of the cursor
743windowsversion() String MS-Windows OS version
744winheight({nr}) Number height of window {nr}
745winlayout([{tabnr}]) List layout of windows in tab {tabnr}
746winline() Number window line of the cursor
747winnr([{expr}]) Number number of current window
748winrestcmd() String returns command to restore window sizes
749winrestview({dict}) none restore view of current window
750winsaveview() Dict save view of current window
751winwidth({nr}) Number width of window {nr}
752wordcount() Dict get byte/char/word statistics
753writefile({object}, {fname} [, {flags}])
754 Number write |Blob| or |List| of lines to file
755xor({expr}, {expr}) Number bitwise XOR
756
757==============================================================================
7582. Details *builtin-function-details*
759
760Not all functions are here, some have been moved to a help file covering the
761specific functionality.
762
763abs({expr}) *abs()*
764 Return the absolute value of {expr}. When {expr} evaluates to
765 a |Float| abs() returns a |Float|. When {expr} can be
766 converted to a |Number| abs() returns a |Number|. Otherwise
767 abs() gives an error message and returns -1.
768 Examples: >
769 echo abs(1.456)
770< 1.456 >
771 echo abs(-5.456)
772< 5.456 >
773 echo abs(-4)
774< 4
775
776 Can also be used as a |method|: >
777 Compute()->abs()
778
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000779
780acos({expr}) *acos()*
781 Return the arc cosine of {expr} measured in radians, as a
782 |Float| in the range of [0, pi].
783 {expr} must evaluate to a |Float| or a |Number| in the range
Bram Moolenaar016188f2022-06-06 20:52:59 +0100784 [-1, 1]. Otherwise acos() returns "nan".
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000785 Examples: >
786 :echo acos(0)
787< 1.570796 >
788 :echo acos(-0.5)
789< 2.094395
790
791 Can also be used as a |method|: >
792 Compute()->acos()
793
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000794
795add({object}, {expr}) *add()*
796 Append the item {expr} to |List| or |Blob| {object}. Returns
797 the resulting |List| or |Blob|. Examples: >
798 :let alist = add([1, 2, 3], item)
799 :call add(mylist, "woodstock")
800< Note that when {expr} is a |List| it is appended as a single
801 item. Use |extend()| to concatenate |Lists|.
802 When {object} is a |Blob| then {expr} must be a number.
803 Use |insert()| to add an item at another position.
Bram Moolenaar016188f2022-06-06 20:52:59 +0100804 Returns 1 if {object} is not a |List| or a |Blob|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000805
806 Can also be used as a |method|: >
807 mylist->add(val1)->add(val2)
808
809
810and({expr}, {expr}) *and()*
811 Bitwise AND on the two arguments. The arguments are converted
812 to a number. A List, Dict or Float argument causes an error.
LemonBoy0f7a3e12022-05-26 12:10:37 +0100813 Also see `or()` and `xor()`.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000814 Example: >
815 :let flag = and(bits, 0x80)
816< Can also be used as a |method|: >
817 :let flag = bits->and(0x80)
818
819
820append({lnum}, {text}) *append()*
821 When {text} is a |List|: Append each item of the |List| as a
822 text line below line {lnum} in the current buffer.
823 Otherwise append {text} as one text line below line {lnum} in
824 the current buffer.
825 Any type of item is accepted and converted to a String.
826 {lnum} can be zero to insert a line before the first one.
827 {lnum} is used like with |getline()|.
828 Returns 1 for failure ({lnum} out of range or out of memory),
Bram Moolenaarcd9c8d42022-11-05 23:46:43 +0000829 0 for success. When {text} is an empty list zero is returned,
830 no matter the value of {lnum}.
831 In |Vim9| script an invalid argument or negative number
832 results in an error. Example: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000833 :let failed = append(line('$'), "# THE END")
834 :let failed = append(0, ["Chapter 1", "the beginning"])
835
836< Can also be used as a |method| after a List, the base is
837 passed as the second argument: >
838 mylist->append(lnum)
839
840
841appendbufline({buf}, {lnum}, {text}) *appendbufline()*
842 Like |append()| but append the text in buffer {buf}.
843
844 This function works only for loaded buffers. First call
845 |bufload()| if needed.
846
847 For the use of {buf}, see |bufname()|.
848
Bram Moolenaar8b6256f2021-12-28 11:24:49 +0000849 {lnum} is the line number to append below. Note that using
850 |line()| would use the current buffer, not the one appending
851 to. Use "$" to append at the end of the buffer. Other string
852 values are not supported.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000853
854 On success 0 is returned, on failure 1 is returned.
855 In |Vim9| script an error is given for an invalid {lnum}.
856
857 If {buf} is not a valid buffer or {lnum} is not valid, an
858 error message is given. Example: >
859 :let failed = appendbufline(13, 0, "# THE START")
Bram Moolenaarcd9c8d42022-11-05 23:46:43 +0000860< However, when {text} is an empty list then no error is given
861 for an invalid {lnum}, since {lnum} isn't actually used.
862
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000863 Can also be used as a |method| after a List, the base is
864 passed as the second argument: >
865 mylist->appendbufline(buf, lnum)
866
867
868argc([{winid}]) *argc()*
869 The result is the number of files in the argument list. See
870 |arglist|.
871 If {winid} is not supplied, the argument list of the current
872 window is used.
873 If {winid} is -1, the global argument list is used.
874 Otherwise {winid} specifies the window of which the argument
875 list is used: either the window number or the window ID.
876 Returns -1 if the {winid} argument is invalid.
877
878 *argidx()*
879argidx() The result is the current index in the argument list. 0 is
880 the first file. argc() - 1 is the last one. See |arglist|.
881
882 *arglistid()*
883arglistid([{winnr} [, {tabnr}]])
884 Return the argument list ID. This is a number which
885 identifies the argument list being used. Zero is used for the
886 global argument list. See |arglist|.
887 Returns -1 if the arguments are invalid.
888
889 Without arguments use the current window.
890 With {winnr} only use this window in the current tab page.
891 With {winnr} and {tabnr} use the window in the specified tab
892 page.
893 {winnr} can be the window number or the |window-ID|.
894
895 *argv()*
896argv([{nr} [, {winid}]])
897 The result is the {nr}th file in the argument list. See
898 |arglist|. "argv(0)" is the first one. Example: >
899 :let i = 0
900 :while i < argc()
901 : let f = escape(fnameescape(argv(i)), '.')
Bram Moolenaarc51cf032022-02-26 12:25:45 +0000902 : exe 'amenu Arg.' .. f .. ' :e ' .. f .. '<CR>'
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000903 : let i = i + 1
904 :endwhile
905< Without the {nr} argument, or when {nr} is -1, a |List| with
906 the whole |arglist| is returned.
907
908 The {winid} argument specifies the window ID, see |argc()|.
909 For the Vim command line arguments see |v:argv|.
910
Bram Moolenaar016188f2022-06-06 20:52:59 +0100911 Returns an empty string if {nr}th argument is not present in
912 the argument list. Returns an empty List if the {winid}
913 argument is invalid.
914
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000915asin({expr}) *asin()*
916 Return the arc sine of {expr} measured in radians, as a |Float|
917 in the range of [-pi/2, pi/2].
918 {expr} must evaluate to a |Float| or a |Number| in the range
919 [-1, 1].
Bram Moolenaar016188f2022-06-06 20:52:59 +0100920 Returns "nan" if {expr} is outside the range [-1, 1]. Returns
921 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000922 Examples: >
923 :echo asin(0.8)
924< 0.927295 >
925 :echo asin(-0.5)
926< -0.523599
927
928 Can also be used as a |method|: >
929 Compute()->asin()
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000930
931
932assert_ functions are documented here: |assert-functions-details|
933
934
935
936atan({expr}) *atan()*
937 Return the principal value of the arc tangent of {expr}, in
938 the range [-pi/2, +pi/2] radians, as a |Float|.
939 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar016188f2022-06-06 20:52:59 +0100940 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000941 Examples: >
942 :echo atan(100)
943< 1.560797 >
944 :echo atan(-4.01)
945< -1.326405
946
947 Can also be used as a |method|: >
948 Compute()->atan()
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000949
950
951atan2({expr1}, {expr2}) *atan2()*
952 Return the arc tangent of {expr1} / {expr2}, measured in
953 radians, as a |Float| in the range [-pi, pi].
954 {expr1} and {expr2} must evaluate to a |Float| or a |Number|.
Bram Moolenaar016188f2022-06-06 20:52:59 +0100955 Returns 0.0 if {expr1} or {expr2} is not a |Float| or a
956 |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000957 Examples: >
958 :echo atan2(-1, 1)
959< -0.785398 >
960 :echo atan2(1, -1)
961< 2.356194
962
963 Can also be used as a |method|: >
964 Compute()->atan2(1)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000965
Yegappan Lakshmanan1755a912022-05-19 10:31:47 +0100966
967autocmd_add({acmds}) *autocmd_add()*
968 Adds a List of autocmds and autocmd groups.
969
970 The {acmds} argument is a List where each item is a Dict with
971 the following optional items:
972 bufnr buffer number to add a buffer-local autocmd.
973 If this item is specified, then the "pattern"
974 item is ignored.
975 cmd Ex command to execute for this autocmd event
976 event autocmd event name. Refer to |autocmd-events|.
Yegappan Lakshmanane0ff3a72022-05-27 18:05:33 +0100977 This can be either a String with a single
978 event name or a List of event names.
Yegappan Lakshmanan1755a912022-05-19 10:31:47 +0100979 group autocmd group name. Refer to |autocmd-groups|.
980 If this group doesn't exist then it is
981 created. If not specified or empty, then the
982 default group is used.
Yegappan Lakshmanan971f6822022-05-24 11:40:11 +0100983 nested boolean flag, set to v:true to add a nested
984 autocmd. Refer to |autocmd-nested|.
LemonBoy0f7a3e12022-05-26 12:10:37 +0100985 once boolean flag, set to v:true to add an autocmd
Yegappan Lakshmanan971f6822022-05-24 11:40:11 +0100986 which executes only once. Refer to
987 |autocmd-once|.
Yegappan Lakshmanan1755a912022-05-19 10:31:47 +0100988 pattern autocmd pattern string. Refer to
989 |autocmd-patterns|. If "bufnr" item is
Yegappan Lakshmanane0ff3a72022-05-27 18:05:33 +0100990 present, then this item is ignored. This can
991 be a String with a single pattern or a List of
992 patterns.
Yegappan Lakshmanan971f6822022-05-24 11:40:11 +0100993 replace boolean flag, set to v:true to remove all the
994 commands associated with the specified autocmd
995 event and group and add the {cmd}. This is
996 useful to avoid adding the same command
LemonBoy0f7a3e12022-05-26 12:10:37 +0100997 multiple times for an autocmd event in a group.
Yegappan Lakshmanan1755a912022-05-19 10:31:47 +0100998
999 Returns v:true on success and v:false on failure.
1000 Examples: >
1001 " Create a buffer-local autocmd for buffer 5
1002 let acmd = {}
1003 let acmd.group = 'MyGroup'
1004 let acmd.event = 'BufEnter'
1005 let acmd.bufnr = 5
1006 let acmd.cmd = 'call BufEnterFunc()'
1007 call autocmd_add([acmd])
Bram Moolenaarcd9c8d42022-11-05 23:46:43 +00001008<
Yegappan Lakshmanan1755a912022-05-19 10:31:47 +01001009 Can also be used as a |method|: >
1010 GetAutocmdList()->autocmd_add()
1011<
1012autocmd_delete({acmds}) *autocmd_delete()*
1013 Deletes a List of autocmds and autocmd groups.
1014
1015 The {acmds} argument is a List where each item is a Dict with
1016 the following optional items:
1017 bufnr buffer number to delete a buffer-local autocmd.
1018 If this item is specified, then the "pattern"
1019 item is ignored.
1020 cmd Ex command for this autocmd event
1021 event autocmd event name. Refer to |autocmd-events|.
1022 If '*' then all the autocmd events in this
1023 group are deleted.
1024 group autocmd group name. Refer to |autocmd-groups|.
1025 If not specified or empty, then the default
1026 group is used.
1027 nested set to v:true for a nested autocmd.
1028 Refer to |autocmd-nested|.
1029 once set to v:true for an autocmd which executes
1030 only once. Refer to |autocmd-once|.
1031 pattern autocmd pattern string. Refer to
1032 |autocmd-patterns|. If "bufnr" item is
1033 present, then this item is ignored.
1034
1035 If only {group} is specified in a {acmds} entry and {event},
1036 {pattern} and {cmd} are not specified, then that autocmd group
1037 is deleted.
1038
Bram Moolenaar016188f2022-06-06 20:52:59 +01001039 Returns |v:true| on success and |v:false| on failure.
Yegappan Lakshmanan1755a912022-05-19 10:31:47 +01001040 Examples: >
1041 " :autocmd! BufLeave *.vim
1042 let acmd = #{event: 'BufLeave', pattern: '*.vim'}
1043 call autocmd_delete([acmd]})
1044 " :autocmd! MyGroup1 BufLeave
1045 let acmd = #{group: 'MyGroup1', event: 'BufLeave'}
1046 call autocmd_delete([acmd])
1047 " :autocmd! MyGroup2 BufEnter *.c
1048 let acmd = #{group: 'MyGroup2', event: 'BufEnter',
1049 \ pattern: '*.c'}
1050 " :autocmd! MyGroup2 * *.c
1051 let acmd = #{group: 'MyGroup2', event: '*',
1052 \ pattern: '*.c'}
1053 call autocmd_delete([acmd])
1054 " :autocmd! MyGroup3
1055 let acmd = #{group: 'MyGroup3'}
1056 call autocmd_delete([acmd])
1057<
1058 Can also be used as a |method|: >
1059 GetAutocmdList()->autocmd_delete()
1060
1061autocmd_get([{opts}]) *autocmd_get()*
1062 Returns a |List| of autocmds. If {opts} is not supplied, then
1063 returns the autocmds for all the events in all the groups.
1064
1065 The optional {opts} Dict argument supports the following
1066 items:
1067 group Autocmd group name. If specified, returns only
1068 the autocmds defined in this group. If the
1069 specified group doesn't exist, results in an
1070 error message. If set to an empty string,
1071 then the default autocmd group is used.
1072 event Autocmd event name. If specified, returns only
1073 the autocmds defined for this event. If set
1074 to "*", then returns autocmds for all the
1075 events. If the specified event doesn't exist,
1076 results in an error message.
1077 pattern Autocmd pattern. If specified, returns only
1078 the autocmds defined for this pattern.
1079 A combination of the above three times can be supplied in
1080 {opts}.
1081
1082 Each Dict in the returned List contains the following items:
1083 bufnr For buffer-local autocmds, buffer number where
1084 the autocmd is defined.
1085 cmd Command executed for this autocmd.
1086 event Autocmd event name.
1087 group Autocmd group name.
Yegappan Lakshmanan971f6822022-05-24 11:40:11 +01001088 nested Boolean flag, set to v:true for a nested
1089 autocmd. See |autocmd-nested|.
1090 once Boolean flag, set to v:true, if the autocmd
1091 will be executed only once. See |autocmd-once|.
Yegappan Lakshmanan1755a912022-05-19 10:31:47 +01001092 pattern Autocmd pattern. For a buffer-local
1093 autocmd, this will be of the form "<buffer=n>".
1094 If there are multiple commands for an autocmd event in a
1095 group, then separate items are returned for each command.
1096
Bram Moolenaar016188f2022-06-06 20:52:59 +01001097 Returns an empty List if an autocmd with the specified group
1098 or event or pattern is not found.
1099
Yegappan Lakshmanan1755a912022-05-19 10:31:47 +01001100 Examples: >
1101 " :autocmd MyGroup
1102 echo autocmd_get(#{group: 'Mygroup'})
1103 " :autocmd G BufUnload
1104 echo autocmd_get(#{group: 'G', event: 'BufUnload'})
1105 " :autocmd G * *.ts
1106 let acmd = #{group: 'G', event: '*', pattern: '*.ts'}
1107 echo autocmd_get(acmd)
1108 " :autocmd Syntax
1109 echo autocmd_get(#{event: 'Syntax'})
1110 " :autocmd G BufEnter *.ts
1111 let acmd = #{group: 'G', event: 'BufEnter',
1112 \ pattern: '*.ts'}
1113 echo autocmd_get(acmd)
1114<
1115 Can also be used as a |method|: >
1116 Getopts()->autocmd_get()
1117<
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001118balloon_gettext() *balloon_gettext()*
1119 Return the current text in the balloon. Only for the string,
Bram Moolenaar016188f2022-06-06 20:52:59 +01001120 not used for the List. Returns an empty string if balloon
1121 is not present.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001122
1123balloon_show({expr}) *balloon_show()*
1124 Show {expr} inside the balloon. For the GUI {expr} is used as
1125 a string. For a terminal {expr} can be a list, which contains
1126 the lines of the balloon. If {expr} is not a list it will be
1127 split with |balloon_split()|.
1128 If {expr} is an empty string any existing balloon is removed.
1129
1130 Example: >
1131 func GetBalloonContent()
1132 " ... initiate getting the content
1133 return ''
1134 endfunc
1135 set balloonexpr=GetBalloonContent()
1136
1137 func BalloonCallback(result)
1138 call balloon_show(a:result)
1139 endfunc
1140< Can also be used as a |method|: >
1141 GetText()->balloon_show()
1142<
1143 The intended use is that fetching the content of the balloon
1144 is initiated from 'balloonexpr'. It will invoke an
1145 asynchronous method, in which a callback invokes
1146 balloon_show(). The 'balloonexpr' itself can return an
Bram Moolenaar069a7d52022-06-27 22:16:08 +01001147 empty string or a placeholder, e.g. "loading...".
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001148
Bram Moolenaar069a7d52022-06-27 22:16:08 +01001149 When showing a balloon is not possible then nothing happens,
1150 no error message is given.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001151 {only available when compiled with the |+balloon_eval| or
1152 |+balloon_eval_term| feature}
1153
1154balloon_split({msg}) *balloon_split()*
1155 Split String {msg} into lines to be displayed in a balloon.
1156 The splits are made for the current window size and optimize
1157 to show debugger output.
Bram Moolenaar016188f2022-06-06 20:52:59 +01001158 Returns a |List| with the split lines. Returns an empty List
1159 on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001160 Can also be used as a |method|: >
1161 GetText()->balloon_split()->balloon_show()
1162
1163< {only available when compiled with the |+balloon_eval_term|
1164 feature}
1165
1166blob2list({blob}) *blob2list()*
1167 Return a List containing the number value of each byte in Blob
1168 {blob}. Examples: >
1169 blob2list(0z0102.0304) returns [1, 2, 3, 4]
1170 blob2list(0z) returns []
1171< Returns an empty List on error. |list2blob()| does the
1172 opposite.
1173
1174 Can also be used as a |method|: >
1175 GetBlob()->blob2list()
Bram Moolenaarb529cfb2022-07-25 15:42:07 +01001176<
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001177 *browse()*
1178browse({save}, {title}, {initdir}, {default})
1179 Put up a file requester. This only works when "has("browse")"
1180 returns |TRUE| (only in some GUI versions).
1181 The input fields are:
1182 {save} when |TRUE|, select file to write
1183 {title} title for the requester
1184 {initdir} directory to start browsing in
1185 {default} default file name
1186 An empty string is returned when the "Cancel" button is hit,
1187 something went wrong, or browsing is not possible.
1188
1189 *browsedir()*
1190browsedir({title}, {initdir})
1191 Put up a directory requester. This only works when
1192 "has("browse")" returns |TRUE| (only in some GUI versions).
1193 On systems where a directory browser is not supported a file
1194 browser is used. In that case: select a file in the directory
1195 to be used.
1196 The input fields are:
1197 {title} title for the requester
1198 {initdir} directory to start browsing in
1199 When the "Cancel" button is hit, something went wrong, or
1200 browsing is not possible, an empty string is returned.
1201
1202bufadd({name}) *bufadd()*
Bram Moolenaar2eddbac2022-08-25 12:45:21 +01001203 Add a buffer to the buffer list with name {name} (must be a
1204 String).
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001205 If a buffer for file {name} already exists, return that buffer
1206 number. Otherwise return the buffer number of the newly
1207 created buffer. When {name} is an empty string then a new
1208 buffer is always created.
1209 The buffer will not have 'buflisted' set and not be loaded
1210 yet. To add some text to the buffer use this: >
1211 let bufnr = bufadd('someName')
1212 call bufload(bufnr)
1213 call setbufline(bufnr, 1, ['some', 'text'])
Bram Moolenaar016188f2022-06-06 20:52:59 +01001214< Returns 0 on error.
1215 Can also be used as a |method|: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001216 let bufnr = 'somename'->bufadd()
1217
1218bufexists({buf}) *bufexists()*
1219 The result is a Number, which is |TRUE| if a buffer called
1220 {buf} exists.
1221 If the {buf} argument is a number, buffer numbers are used.
1222 Number zero is the alternate buffer for the current window.
1223
1224 If the {buf} argument is a string it must match a buffer name
1225 exactly. The name can be:
1226 - Relative to the current directory.
1227 - A full path.
1228 - The name of a buffer with 'buftype' set to "nofile".
1229 - A URL name.
1230 Unlisted buffers will be found.
1231 Note that help files are listed by their short name in the
1232 output of |:buffers|, but bufexists() requires using their
1233 long name to be able to find them.
1234 bufexists() may report a buffer exists, but to use the name
1235 with a |:buffer| command you may need to use |expand()|. Esp
1236 for MS-Windows 8.3 names in the form "c:\DOCUME~1"
1237 Use "bufexists(0)" to test for the existence of an alternate
1238 file name.
1239
1240 Can also be used as a |method|: >
1241 let exists = 'somename'->bufexists()
1242<
1243 Obsolete name: buffer_exists(). *buffer_exists()*
1244
1245buflisted({buf}) *buflisted()*
1246 The result is a Number, which is |TRUE| if a buffer called
1247 {buf} exists and is listed (has the 'buflisted' option set).
1248 The {buf} argument is used like with |bufexists()|.
1249
1250 Can also be used as a |method|: >
1251 let listed = 'somename'->buflisted()
1252
1253bufload({buf}) *bufload()*
1254 Ensure the buffer {buf} is loaded. When the buffer name
1255 refers to an existing file then the file is read. Otherwise
1256 the buffer will be empty. If the buffer was already loaded
Bram Moolenaar2eddbac2022-08-25 12:45:21 +01001257 then there is no change. If the buffer is not related to a
Daniel Steinbergc2bd2052023-08-09 12:10:59 -04001258 file then no file is read (e.g., when 'buftype' is "nofile").
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001259 If there is an existing swap file for the file of the buffer,
1260 there will be no dialog, the buffer will be loaded anyway.
1261 The {buf} argument is used like with |bufexists()|.
1262
1263 Can also be used as a |method|: >
1264 eval 'somename'->bufload()
1265
1266bufloaded({buf}) *bufloaded()*
1267 The result is a Number, which is |TRUE| if a buffer called
1268 {buf} exists and is loaded (shown in a window or hidden).
1269 The {buf} argument is used like with |bufexists()|.
1270
1271 Can also be used as a |method|: >
1272 let loaded = 'somename'->bufloaded()
1273
1274bufname([{buf}]) *bufname()*
1275 The result is the name of a buffer. Mostly as it is displayed
1276 by the `:ls` command, but not using special names such as
1277 "[No Name]".
1278 If {buf} is omitted the current buffer is used.
1279 If {buf} is a Number, that buffer number's name is given.
1280 Number zero is the alternate buffer for the current window.
1281 If {buf} is a String, it is used as a |file-pattern| to match
1282 with the buffer names. This is always done like 'magic' is
1283 set and 'cpoptions' is empty. When there is more than one
1284 match an empty string is returned.
1285 "" or "%" can be used for the current buffer, "#" for the
1286 alternate buffer.
1287 A full match is preferred, otherwise a match at the start, end
1288 or middle of the buffer name is accepted. If you only want a
1289 full match then put "^" at the start and "$" at the end of the
1290 pattern.
1291 Listed buffers are found first. If there is a single match
1292 with a listed buffer, that one is returned. Next unlisted
1293 buffers are searched for.
1294 If the {buf} is a String, but you want to use it as a buffer
1295 number, force it to be a Number by adding zero to it: >
1296 :echo bufname("3" + 0)
1297< Can also be used as a |method|: >
1298 echo bufnr->bufname()
1299
1300< If the buffer doesn't exist, or doesn't have a name, an empty
1301 string is returned. >
1302 bufname("#") alternate buffer name
1303 bufname(3) name of buffer 3
1304 bufname("%") name of current buffer
1305 bufname("file2") name of buffer where "file2" matches.
1306< *buffer_name()*
1307 Obsolete name: buffer_name().
1308
1309 *bufnr()*
1310bufnr([{buf} [, {create}]])
1311 The result is the number of a buffer, as it is displayed by
1312 the `:ls` command. For the use of {buf}, see |bufname()|
1313 above.
1314
1315 If the buffer doesn't exist, -1 is returned. Or, if the
1316 {create} argument is present and TRUE, a new, unlisted,
1317 buffer is created and its number is returned. Example: >
1318 let newbuf = bufnr('Scratch001', 1)
1319< Using an empty name uses the current buffer. To create a new
1320 buffer with an empty name use |bufadd()|.
1321
1322 bufnr("$") is the last buffer: >
1323 :let last_buffer = bufnr("$")
1324< The result is a Number, which is the highest buffer number
1325 of existing buffers. Note that not all buffers with a smaller
1326 number necessarily exist, because ":bwipeout" may have removed
1327 them. Use bufexists() to test for the existence of a buffer.
1328
1329 Can also be used as a |method|: >
1330 echo bufref->bufnr()
1331<
1332 Obsolete name: buffer_number(). *buffer_number()*
1333 *last_buffer_nr()*
1334 Obsolete name for bufnr("$"): last_buffer_nr().
1335
1336bufwinid({buf}) *bufwinid()*
1337 The result is a Number, which is the |window-ID| of the first
1338 window associated with buffer {buf}. For the use of {buf},
1339 see |bufname()| above. If buffer {buf} doesn't exist or
1340 there is no such window, -1 is returned. Example: >
1341
Bram Moolenaarc51cf032022-02-26 12:25:45 +00001342 echo "A window containing buffer 1 is " .. (bufwinid(1))
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001343<
Bram Moolenaar76db9e02022-11-09 21:21:04 +00001344 Only deals with the current tab page. See |win_findbuf()| for
1345 finding more.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001346
1347 Can also be used as a |method|: >
1348 FindBuffer()->bufwinid()
1349
1350bufwinnr({buf}) *bufwinnr()*
1351 Like |bufwinid()| but return the window number instead of the
1352 |window-ID|.
1353 If buffer {buf} doesn't exist or there is no such window, -1
1354 is returned. Example: >
1355
Bram Moolenaarc51cf032022-02-26 12:25:45 +00001356 echo "A window containing buffer 1 is " .. (bufwinnr(1))
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001357
1358< The number can be used with |CTRL-W_w| and ":wincmd w"
1359 |:wincmd|.
1360
1361 Can also be used as a |method|: >
1362 FindBuffer()->bufwinnr()
1363
1364byte2line({byte}) *byte2line()*
1365 Return the line number that contains the character at byte
1366 count {byte} in the current buffer. This includes the
1367 end-of-line character, depending on the 'fileformat' option
1368 for the current buffer. The first character has byte count
1369 one.
1370 Also see |line2byte()|, |go| and |:goto|.
1371
Bram Moolenaar016188f2022-06-06 20:52:59 +01001372 Returns -1 if the {byte} value is invalid.
1373
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001374 Can also be used as a |method|: >
1375 GetOffset()->byte2line()
1376
1377< {not available when compiled without the |+byte_offset|
1378 feature}
1379
Christian Brabandt67672ef2023-04-24 21:09:54 +01001380byteidx({expr}, {nr} [, {utf16}]) *byteidx()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001381 Return byte index of the {nr}'th character in the String
1382 {expr}. Use zero for the first character, it then returns
1383 zero.
1384 If there are no multibyte characters the returned value is
1385 equal to {nr}.
1386 Composing characters are not counted separately, their byte
1387 length is added to the preceding base character. See
1388 |byteidxcomp()| below for counting composing characters
1389 separately.
Christian Brabandt67672ef2023-04-24 21:09:54 +01001390 When {utf16} is present and TRUE, {nr} is used as the UTF-16
1391 index in the String {expr} instead of as the character index.
1392 The UTF-16 index is the index in the string when it is encoded
1393 with 16-bit words. If the specified UTF-16 index is in the
1394 middle of a character (e.g. in a 4-byte character), then the
1395 byte index of the first byte in the character is returned.
1396 Refer to |string-offset-encoding| for more information.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001397 Example : >
1398 echo matchstr(str, ".", byteidx(str, 3))
1399< will display the fourth character. Another way to do the
1400 same: >
1401 let s = strpart(str, byteidx(str, 3))
1402 echo strpart(s, 0, byteidx(s, 1))
1403< Also see |strgetchar()| and |strcharpart()|.
1404
1405 If there are less than {nr} characters -1 is returned.
1406 If there are exactly {nr} characters the length of the string
1407 in bytes is returned.
Christian Brabandt67672ef2023-04-24 21:09:54 +01001408 See |charidx()| and |utf16idx()| for getting the character and
1409 UTF-16 index respectively from the byte index.
1410 Examples: >
1411 echo byteidx('a😊😊', 2) returns 5
1412 echo byteidx('a😊😊', 2, 1) returns 1
1413 echo byteidx('a😊😊', 3, 1) returns 5
1414<
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001415 Can also be used as a |method|: >
1416 GetName()->byteidx(idx)
1417
Christian Brabandt67672ef2023-04-24 21:09:54 +01001418byteidxcomp({expr}, {nr} [, {utf16}]) *byteidxcomp()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001419 Like byteidx(), except that a composing character is counted
1420 as a separate character. Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00001421 let s = 'e' .. nr2char(0x301)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001422 echo byteidx(s, 1)
1423 echo byteidxcomp(s, 1)
1424 echo byteidxcomp(s, 2)
1425< The first and third echo result in 3 ('e' plus composing
1426 character is 3 bytes), the second echo results in 1 ('e' is
1427 one byte).
1428 Only works differently from byteidx() when 'encoding' is set
1429 to a Unicode encoding.
1430
1431 Can also be used as a |method|: >
1432 GetName()->byteidxcomp(idx)
1433
1434call({func}, {arglist} [, {dict}]) *call()* *E699*
1435 Call function {func} with the items in |List| {arglist} as
1436 arguments.
1437 {func} can either be a |Funcref| or the name of a function.
1438 a:firstline and a:lastline are set to the cursor line.
1439 Returns the return value of the called function.
1440 {dict} is for functions with the "dict" attribute. It will be
1441 used to set the local variable "self". |Dictionary-function|
1442
1443 Can also be used as a |method|: >
1444 GetFunc()->call([arg, arg], dict)
1445
1446ceil({expr}) *ceil()*
1447 Return the smallest integral value greater than or equal to
1448 {expr} as a |Float| (round up).
1449 {expr} must evaluate to a |Float| or a |Number|.
1450 Examples: >
1451 echo ceil(1.456)
1452< 2.0 >
1453 echo ceil(-5.456)
1454< -5.0 >
1455 echo ceil(4.0)
1456< 4.0
1457
Bram Moolenaar016188f2022-06-06 20:52:59 +01001458 Returns 0.0 if {expr} is not a |Float| or a |Number|.
1459
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001460 Can also be used as a |method|: >
1461 Compute()->ceil()
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001462
1463
1464ch_ functions are documented here: |channel-functions-details|
1465
1466
1467changenr() *changenr()*
1468 Return the number of the most recent change. This is the same
1469 number as what is displayed with |:undolist| and can be used
1470 with the |:undo| command.
1471 When a change was made it is the number of that change. After
1472 redo it is the number of the redone change. After undo it is
1473 one less than the number of the undone change.
Bram Moolenaar016188f2022-06-06 20:52:59 +01001474 Returns 0 if the undo list is empty.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001475
1476char2nr({string} [, {utf8}]) *char2nr()*
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01001477 Return Number value of the first char in {string}.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001478 Examples: >
1479 char2nr(" ") returns 32
1480 char2nr("ABC") returns 65
1481< When {utf8} is omitted or zero, the current 'encoding' is used.
1482 Example for "utf-8": >
1483 char2nr("á") returns 225
1484 char2nr("á"[0]) returns 195
1485< When {utf8} is TRUE, always treat as UTF-8 characters.
1486 A combining character is a separate character.
1487 |nr2char()| does the opposite.
1488 To turn a string into a list of character numbers: >
1489 let str = "ABC"
1490 let list = map(split(str, '\zs'), {_, val -> char2nr(val)})
1491< Result: [65, 66, 67]
1492
Bram Moolenaar016188f2022-06-06 20:52:59 +01001493 Returns 0 if {string} is not a |String|.
1494
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001495 Can also be used as a |method|: >
1496 GetChar()->char2nr()
1497
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001498charclass({string}) *charclass()*
1499 Return the character class of the first character in {string}.
1500 The character class is one of:
1501 0 blank
1502 1 punctuation
1503 2 word character
1504 3 emoji
1505 other specific Unicode class
1506 The class is used in patterns and word motions.
Bram Moolenaar016188f2022-06-06 20:52:59 +01001507 Returns 0 if {string} is not a |String|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001508
1509
Yegappan Lakshmanan4c8d2f02022-11-12 16:07:47 +00001510charcol({expr} [, {winid}]) *charcol()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001511 Same as |col()| but returns the character index of the column
1512 position given with {expr} instead of the byte position.
1513
1514 Example:
1515 With the cursor on '세' in line 5 with text "여보세요": >
1516 charcol('.') returns 3
1517 col('.') returns 7
1518
1519< Can also be used as a |method|: >
1520 GetPos()->col()
1521<
1522 *charidx()*
Christian Brabandt67672ef2023-04-24 21:09:54 +01001523charidx({string}, {idx} [, {countcc} [, {utf16}]])
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001524 Return the character index of the byte at {idx} in {string}.
1525 The index of the first character is zero.
1526 If there are no multibyte characters the returned value is
1527 equal to {idx}.
Christian Brabandt67672ef2023-04-24 21:09:54 +01001528
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001529 When {countcc} is omitted or |FALSE|, then composing characters
Christian Brabandt67672ef2023-04-24 21:09:54 +01001530 are not counted separately, their byte length is added to the
1531 preceding base character.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001532 When {countcc} is |TRUE|, then composing characters are
1533 counted as separate characters.
Christian Brabandt67672ef2023-04-24 21:09:54 +01001534
1535 When {utf16} is present and TRUE, {idx} is used as the UTF-16
1536 index in the String {expr} instead of as the byte index.
1537
Yegappan Lakshmanan577922b2023-06-08 17:09:45 +01001538 Returns -1 if the arguments are invalid or if there are less
1539 than {idx} bytes. If there are exactly {idx} bytes the length
1540 of the string in characters is returned.
1541
1542 An error is given and -1 is returned if the first argument is
1543 not a string, the second argument is not a number or when the
1544 third argument is present and is not zero or one.
Christian Brabandt67672ef2023-04-24 21:09:54 +01001545
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001546 See |byteidx()| and |byteidxcomp()| for getting the byte index
Christian Brabandt67672ef2023-04-24 21:09:54 +01001547 from the character index and |utf16idx()| for getting the
1548 UTF-16 index from the character index.
1549 Refer to |string-offset-encoding| for more information.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001550 Examples: >
1551 echo charidx('áb́ć', 3) returns 1
1552 echo charidx('áb́ć', 6, 1) returns 4
1553 echo charidx('áb́ć', 16) returns -1
Christian Brabandt67672ef2023-04-24 21:09:54 +01001554 echo charidx('a😊😊', 4, 0, 1) returns 2
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001555<
1556 Can also be used as a |method|: >
1557 GetName()->charidx(idx)
1558
1559chdir({dir}) *chdir()*
1560 Change the current working directory to {dir}. The scope of
1561 the directory change depends on the directory of the current
1562 window:
1563 - If the current window has a window-local directory
1564 (|:lcd|), then changes the window local directory.
1565 - Otherwise, if the current tabpage has a local
1566 directory (|:tcd|) then changes the tabpage local
1567 directory.
1568 - Otherwise, changes the global directory.
1569 {dir} must be a String.
1570 If successful, returns the previous working directory. Pass
1571 this to another chdir() to restore the directory.
1572 On failure, returns an empty string.
1573
1574 Example: >
1575 let save_dir = chdir(newdir)
1576 if save_dir != ""
1577 " ... do some work
1578 call chdir(save_dir)
1579 endif
1580
1581< Can also be used as a |method|: >
1582 GetDir()->chdir()
1583<
1584cindent({lnum}) *cindent()*
1585 Get the amount of indent for line {lnum} according the C
1586 indenting rules, as with 'cindent'.
1587 The indent is counted in spaces, the value of 'tabstop' is
1588 relevant. {lnum} is used just like in |getline()|.
Bram Moolenaar8e145b82022-05-21 20:17:31 +01001589 When {lnum} is invalid -1 is returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001590 See |C-indenting|.
1591
1592 Can also be used as a |method|: >
1593 GetLnum()->cindent()
1594
1595clearmatches([{win}]) *clearmatches()*
1596 Clears all matches previously defined for the current window
1597 by |matchadd()| and the |:match| commands.
1598 If {win} is specified, use the window with this number or
1599 window ID instead of the current window.
1600
1601 Can also be used as a |method|: >
1602 GetWin()->clearmatches()
1603<
Bram Moolenaar10e8ff92023-06-10 21:40:39 +01001604col({expr} [, {winid}]) *col()*
Yegappan Lakshmanan4c8d2f02022-11-12 16:07:47 +00001605 The result is a Number, which is the byte index of the column
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001606 position given with {expr}. The accepted positions are:
1607 . the cursor position
1608 $ the end of the cursor line (the result is the
1609 number of bytes in the cursor line plus one)
1610 'x position of mark x (if the mark is not set, 0 is
1611 returned)
1612 v In Visual mode: the start of the Visual area (the
1613 cursor is the end). When not in Visual mode
1614 returns the cursor position. Differs from |'<| in
1615 that it's updated right away.
1616 Additionally {expr} can be [lnum, col]: a |List| with the line
1617 and column number. Most useful when the column is "$", to get
1618 the last column of a specific line. When "lnum" or "col" is
1619 out of range then col() returns zero.
Yegappan Lakshmanan4c8d2f02022-11-12 16:07:47 +00001620 With the optional {winid} argument the values are obtained for
1621 that window instead of the current window.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001622 To get the line number use |line()|. To get both use
1623 |getpos()|.
1624 For the screen column position use |virtcol()|. For the
1625 character position use |charcol()|.
1626 Note that only marks in the current file can be used.
1627 Examples: >
1628 col(".") column of cursor
1629 col("$") length of cursor line plus one
1630 col("'t") column of mark t
Bram Moolenaarc51cf032022-02-26 12:25:45 +00001631 col("'" .. markname) column of mark markname
Yegappan Lakshmanan4c8d2f02022-11-12 16:07:47 +00001632< The first column is 1. Returns 0 if {expr} is invalid or when
1633 the window with ID {winid} is not found.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001634 For an uppercase mark the column may actually be in another
1635 buffer.
1636 For the cursor position, when 'virtualedit' is active, the
1637 column is one higher if the cursor is after the end of the
Bram Moolenaar6ebe4f92022-10-28 20:47:54 +01001638 line. Also, when using a <Cmd> mapping the cursor isn't
1639 moved, this can be used to obtain the column in Insert mode: >
Bram Moolenaar76db9e02022-11-09 21:21:04 +00001640 :imap <F2> <Cmd>echowin col(".")<CR>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001641
1642< Can also be used as a |method|: >
1643 GetPos()->col()
1644<
1645
1646complete({startcol}, {matches}) *complete()* *E785*
1647 Set the matches for Insert mode completion.
1648 Can only be used in Insert mode. You need to use a mapping
1649 with CTRL-R = (see |i_CTRL-R|). It does not work after CTRL-O
1650 or with an expression mapping.
1651 {startcol} is the byte offset in the line where the completed
1652 text start. The text up to the cursor is the original text
1653 that will be replaced by the matches. Use col('.') for an
1654 empty string. "col('.') - 1" will replace one character by a
1655 match.
1656 {matches} must be a |List|. Each |List| item is one match.
1657 See |complete-items| for the kind of items that are possible.
1658 "longest" in 'completeopt' is ignored.
1659 Note that the after calling this function you need to avoid
1660 inserting anything that would cause completion to stop.
1661 The match can be selected with CTRL-N and CTRL-P as usual with
1662 Insert mode completion. The popup menu will appear if
1663 specified, see |ins-completion-menu|.
1664 Example: >
1665 inoremap <F5> <C-R>=ListMonths()<CR>
1666
Bram Moolenaar10e8ff92023-06-10 21:40:39 +01001667 func ListMonths()
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001668 call complete(col('.'), ['January', 'February', 'March',
1669 \ 'April', 'May', 'June', 'July', 'August', 'September',
1670 \ 'October', 'November', 'December'])
1671 return ''
1672 endfunc
1673< This isn't very useful, but it shows how it works. Note that
1674 an empty string is returned to avoid a zero being inserted.
1675
1676 Can also be used as a |method|, the base is passed as the
1677 second argument: >
1678 GetMatches()->complete(col('.'))
1679
1680complete_add({expr}) *complete_add()*
1681 Add {expr} to the list of matches. Only to be used by the
1682 function specified with the 'completefunc' option.
1683 Returns 0 for failure (empty string or out of memory),
1684 1 when the match was added, 2 when the match was already in
1685 the list.
1686 See |complete-functions| for an explanation of {expr}. It is
1687 the same as one item in the list that 'omnifunc' would return.
1688
1689 Can also be used as a |method|: >
1690 GetMoreMatches()->complete_add()
1691
1692complete_check() *complete_check()*
1693 Check for a key typed while looking for completion matches.
1694 This is to be used when looking for matches takes some time.
1695 Returns |TRUE| when searching for matches is to be aborted,
1696 zero otherwise.
1697 Only to be used by the function specified with the
1698 'completefunc' option.
1699
1700
1701complete_info([{what}]) *complete_info()*
1702 Returns a |Dictionary| with information about Insert mode
1703 completion. See |ins-completion|.
1704 The items are:
1705 mode Current completion mode name string.
1706 See |complete_info_mode| for the values.
1707 pum_visible |TRUE| if popup menu is visible.
1708 See |pumvisible()|.
1709 items List of completion matches. Each item is a
1710 dictionary containing the entries "word",
1711 "abbr", "menu", "kind", "info" and "user_data".
1712 See |complete-items|.
1713 selected Selected item index. First index is zero.
1714 Index is -1 if no item is selected (showing
1715 typed text only, or the last completion after
1716 no item is selected when using the <Up> or
1717 <Down> keys)
Bram Moolenaar0daafaa2022-09-04 17:45:43 +01001718 inserted Inserted string. [NOT IMPLEMENTED YET]
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001719
1720 *complete_info_mode*
1721 mode values are:
1722 "" Not in completion mode
1723 "keyword" Keyword completion |i_CTRL-X_CTRL-N|
1724 "ctrl_x" Just pressed CTRL-X |i_CTRL-X|
1725 "scroll" Scrolling with |i_CTRL-X_CTRL-E| or
1726 |i_CTRL-X_CTRL-Y|
1727 "whole_line" Whole lines |i_CTRL-X_CTRL-L|
1728 "files" File names |i_CTRL-X_CTRL-F|
1729 "tags" Tags |i_CTRL-X_CTRL-]|
1730 "path_defines" Definition completion |i_CTRL-X_CTRL-D|
1731 "path_patterns" Include completion |i_CTRL-X_CTRL-I|
1732 "dictionary" Dictionary |i_CTRL-X_CTRL-K|
1733 "thesaurus" Thesaurus |i_CTRL-X_CTRL-T|
1734 "cmdline" Vim Command line |i_CTRL-X_CTRL-V|
1735 "function" User defined completion |i_CTRL-X_CTRL-U|
1736 "omni" Omni completion |i_CTRL-X_CTRL-O|
1737 "spell" Spelling suggestions |i_CTRL-X_s|
1738 "eval" |complete()| completion
1739 "unknown" Other internal modes
1740
1741 If the optional {what} list argument is supplied, then only
1742 the items listed in {what} are returned. Unsupported items in
1743 {what} are silently ignored.
1744
1745 To get the position and size of the popup menu, see
1746 |pum_getpos()|. It's also available in |v:event| during the
1747 |CompleteChanged| event.
1748
Bram Moolenaar016188f2022-06-06 20:52:59 +01001749 Returns an empty |Dictionary| on error.
1750
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001751 Examples: >
1752 " Get all items
1753 call complete_info()
1754 " Get only 'mode'
1755 call complete_info(['mode'])
1756 " Get only 'mode' and 'pum_visible'
1757 call complete_info(['mode', 'pum_visible'])
1758
1759< Can also be used as a |method|: >
1760 GetItems()->complete_info()
1761<
1762 *confirm()*
1763confirm({msg} [, {choices} [, {default} [, {type}]]])
1764 confirm() offers the user a dialog, from which a choice can be
1765 made. It returns the number of the choice. For the first
1766 choice this is 1.
1767 Note: confirm() is only supported when compiled with dialog
1768 support, see |+dialog_con| and |+dialog_gui|.
1769
1770 {msg} is displayed in a |dialog| with {choices} as the
1771 alternatives. When {choices} is missing or empty, "&OK" is
1772 used (and translated).
1773 {msg} is a String, use '\n' to include a newline. Only on
1774 some systems the string is wrapped when it doesn't fit.
1775
1776 {choices} is a String, with the individual choices separated
1777 by '\n', e.g. >
1778 confirm("Save changes?", "&Yes\n&No\n&Cancel")
1779< The letter after the '&' is the shortcut key for that choice.
1780 Thus you can type 'c' to select "Cancel". The shortcut does
1781 not need to be the first letter: >
1782 confirm("file has been modified", "&Save\nSave &All")
1783< For the console, the first letter of each choice is used as
1784 the default shortcut key. Case is ignored.
1785
1786 The optional {default} argument is the number of the choice
1787 that is made if the user hits <CR>. Use 1 to make the first
1788 choice the default one. Use 0 to not set a default. If
1789 {default} is omitted, 1 is used.
1790
1791 The optional {type} String argument gives the type of dialog.
1792 This is only used for the icon of the GTK, Mac, Motif and
1793 Win32 GUI. It can be one of these values: "Error",
1794 "Question", "Info", "Warning" or "Generic". Only the first
1795 character is relevant. When {type} is omitted, "Generic" is
1796 used.
1797
1798 If the user aborts the dialog by pressing <Esc>, CTRL-C,
1799 or another valid interrupt key, confirm() returns 0.
1800
1801 An example: >
Bram Moolenaar46eea442022-03-30 10:51:39 +01001802 let choice = confirm("What do you want?",
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01001803 \ "&Apples\n&Oranges\n&Bananas", 2)
Bram Moolenaar46eea442022-03-30 10:51:39 +01001804 if choice == 0
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01001805 echo "make up your mind!"
Bram Moolenaar46eea442022-03-30 10:51:39 +01001806 elseif choice == 3
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01001807 echo "tasteful"
Bram Moolenaar46eea442022-03-30 10:51:39 +01001808 else
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01001809 echo "I prefer bananas myself."
Bram Moolenaar46eea442022-03-30 10:51:39 +01001810 endif
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001811< In a GUI dialog, buttons are used. The layout of the buttons
1812 depends on the 'v' flag in 'guioptions'. If it is included,
1813 the buttons are always put vertically. Otherwise, confirm()
1814 tries to put the buttons in one horizontal line. If they
1815 don't fit, a vertical layout is used anyway. For some systems
1816 the horizontal layout is always used.
1817
1818 Can also be used as a |method|in: >
1819 BuildMessage()->confirm("&Yes\n&No")
1820<
1821 *copy()*
1822copy({expr}) Make a copy of {expr}. For Numbers and Strings this isn't
1823 different from using {expr} directly.
1824 When {expr} is a |List| a shallow copy is created. This means
1825 that the original |List| can be changed without changing the
1826 copy, and vice versa. But the items are identical, thus
1827 changing an item changes the contents of both |Lists|.
1828 A |Dictionary| is copied in a similar way as a |List|.
1829 Also see |deepcopy()|.
1830 Can also be used as a |method|: >
1831 mylist->copy()
1832
1833cos({expr}) *cos()*
1834 Return the cosine of {expr}, measured in radians, as a |Float|.
1835 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar016188f2022-06-06 20:52:59 +01001836 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001837 Examples: >
1838 :echo cos(100)
1839< 0.862319 >
1840 :echo cos(-4.01)
1841< -0.646043
1842
1843 Can also be used as a |method|: >
1844 Compute()->cos()
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001845
1846
1847cosh({expr}) *cosh()*
1848 Return the hyperbolic cosine of {expr} as a |Float| in the range
1849 [1, inf].
1850 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar016188f2022-06-06 20:52:59 +01001851 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001852 Examples: >
1853 :echo cosh(0.5)
1854< 1.127626 >
1855 :echo cosh(-0.5)
1856< -1.127626
1857
1858 Can also be used as a |method|: >
1859 Compute()->cosh()
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001860
1861
Yegappan Lakshmanancd39b692023-10-02 12:50:45 -07001862count({comp}, {expr} [, {ic} [, {start}]]) *count()* *E706*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001863 Return the number of times an item with value {expr} appears
1864 in |String|, |List| or |Dictionary| {comp}.
1865
1866 If {start} is given then start with the item with this index.
1867 {start} can only be used with a |List|.
1868
1869 When {ic} is given and it's |TRUE| then case is ignored.
1870
1871 When {comp} is a string then the number of not overlapping
1872 occurrences of {expr} is returned. Zero is returned when
1873 {expr} is an empty string.
1874
1875 Can also be used as a |method|: >
1876 mylist->count(val)
1877<
1878 *cscope_connection()*
1879cscope_connection([{num} , {dbpath} [, {prepend}]])
1880 Checks for the existence of a |cscope| connection. If no
1881 parameters are specified, then the function returns:
1882 0, if cscope was not available (not compiled in), or
1883 if there are no cscope connections;
1884 1, if there is at least one cscope connection.
1885
1886 If parameters are specified, then the value of {num}
1887 determines how existence of a cscope connection is checked:
1888
1889 {num} Description of existence check
1890 ----- ------------------------------
1891 0 Same as no parameters (e.g., "cscope_connection()").
1892 1 Ignore {prepend}, and use partial string matches for
1893 {dbpath}.
1894 2 Ignore {prepend}, and use exact string matches for
1895 {dbpath}.
1896 3 Use {prepend}, use partial string matches for both
1897 {dbpath} and {prepend}.
1898 4 Use {prepend}, use exact string matches for both
1899 {dbpath} and {prepend}.
1900
1901 Note: All string comparisons are case sensitive!
1902
1903 Examples. Suppose we had the following (from ":cs show"): >
1904
1905 # pid database name prepend path
1906 0 27664 cscope.out /usr/local
1907<
1908 Invocation Return Val ~
1909 ---------- ---------- >
1910 cscope_connection() 1
1911 cscope_connection(1, "out") 1
1912 cscope_connection(2, "out") 0
1913 cscope_connection(3, "out") 0
1914 cscope_connection(3, "out", "local") 1
1915 cscope_connection(4, "out") 0
1916 cscope_connection(4, "out", "local") 0
1917 cscope_connection(4, "cscope.out", "/usr/local") 1
1918<
1919cursor({lnum}, {col} [, {off}]) *cursor()*
1920cursor({list})
1921 Positions the cursor at the column (byte count) {col} in the
1922 line {lnum}. The first column is one.
1923
1924 When there is one argument {list} this is used as a |List|
1925 with two, three or four item:
1926 [{lnum}, {col}]
1927 [{lnum}, {col}, {off}]
1928 [{lnum}, {col}, {off}, {curswant}]
1929 This is like the return value of |getpos()| or |getcurpos()|,
1930 but without the first item.
1931
Bram Moolenaar10e8ff92023-06-10 21:40:39 +01001932 To position the cursor using {col} as the character count, use
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001933 |setcursorcharpos()|.
1934
1935 Does not change the jumplist.
Bram Moolenaar7c6cd442022-10-11 21:54:04 +01001936 {lnum} is used like with |getline()|, except that if {lnum} is
1937 zero, the cursor will stay in the current line.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001938 If {lnum} is greater than the number of lines in the buffer,
1939 the cursor will be positioned at the last line in the buffer.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001940 If {col} is greater than the number of bytes in the line,
1941 the cursor will be positioned at the last character in the
1942 line.
1943 If {col} is zero, the cursor will stay in the current column.
1944 If {curswant} is given it is used to set the preferred column
1945 for vertical movement. Otherwise {col} is used.
1946
1947 When 'virtualedit' is used {off} specifies the offset in
1948 screen columns from the start of the character. E.g., a
1949 position within a <Tab> or after the last character.
1950 Returns 0 when the position could be set, -1 otherwise.
1951
1952 Can also be used as a |method|: >
1953 GetCursorPos()->cursor()
1954
1955debugbreak({pid}) *debugbreak()*
1956 Specifically used to interrupt a program being debugged. It
1957 will cause process {pid} to get a SIGTRAP. Behavior for other
1958 processes is undefined. See |terminal-debugger|.
1959 {only available on MS-Windows}
1960
Bram Moolenaar016188f2022-06-06 20:52:59 +01001961 Returns |TRUE| if successfully interrupted the program.
1962 Otherwise returns |FALSE|.
1963
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001964 Can also be used as a |method|: >
1965 GetPid()->debugbreak()
1966
1967deepcopy({expr} [, {noref}]) *deepcopy()* *E698*
1968 Make a copy of {expr}. For Numbers and Strings this isn't
1969 different from using {expr} directly.
1970 When {expr} is a |List| a full copy is created. This means
1971 that the original |List| can be changed without changing the
1972 copy, and vice versa. When an item is a |List| or
1973 |Dictionary|, a copy for it is made, recursively. Thus
1974 changing an item in the copy does not change the contents of
1975 the original |List|.
1976 A |Dictionary| is copied in a similar way as a |List|.
1977
1978 When {noref} is omitted or zero a contained |List| or
1979 |Dictionary| is only copied once. All references point to
1980 this single copy. With {noref} set to 1 every occurrence of a
1981 |List| or |Dictionary| results in a new copy. This also means
1982 that a cyclic reference causes deepcopy() to fail.
1983 *E724*
1984 Nesting is possible up to 100 levels. When there is an item
1985 that refers back to a higher level making a deep copy with
1986 {noref} set to 1 will fail.
1987 Also see |copy()|.
1988
1989 Can also be used as a |method|: >
1990 GetObject()->deepcopy()
1991
1992delete({fname} [, {flags}]) *delete()*
1993 Without {flags} or with {flags} empty: Deletes the file by the
Bram Moolenaarcbaff5e2022-04-08 17:45:08 +01001994 name {fname}.
1995
1996 This also works when {fname} is a symbolic link. The symbolic
1997 link itself is deleted, not what it points to.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001998
1999 When {flags} is "d": Deletes the directory by the name
2000 {fname}. This fails when directory {fname} is not empty.
2001
2002 When {flags} is "rf": Deletes the directory by the name
2003 {fname} and everything in it, recursively. BE CAREFUL!
2004 Note: on MS-Windows it is not possible to delete a directory
2005 that is being used.
2006
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002007 The result is a Number, which is 0/false if the delete
2008 operation was successful and -1/true when the deletion failed
2009 or partly failed.
2010
2011 Use |remove()| to delete an item from a |List|.
2012 To delete a line from the buffer use |:delete| or
2013 |deletebufline()|.
2014
2015 Can also be used as a |method|: >
2016 GetName()->delete()
2017
2018deletebufline({buf}, {first} [, {last}]) *deletebufline()*
2019 Delete lines {first} to {last} (inclusive) from buffer {buf}.
2020 If {last} is omitted then delete line {first} only.
2021 On success 0 is returned, on failure 1 is returned.
2022
2023 This function works only for loaded buffers. First call
2024 |bufload()| if needed.
2025
2026 For the use of {buf}, see |bufname()| above.
2027
2028 {first} and {last} are used like with |getline()|. Note that
2029 when using |line()| this refers to the current buffer. Use "$"
2030 to refer to the last line in buffer {buf}.
2031
2032 Can also be used as a |method|: >
2033 GetBuffer()->deletebufline(1)
2034<
2035 *did_filetype()*
2036did_filetype() Returns |TRUE| when autocommands are being executed and the
2037 FileType event has been triggered at least once. Can be used
2038 to avoid triggering the FileType event again in the scripts
2039 that detect the file type. |FileType|
2040 Returns |FALSE| when `:setf FALLBACK` was used.
2041 When editing another file, the counter is reset, thus this
2042 really checks if the FileType event has been triggered for the
2043 current buffer. This allows an autocommand that starts
2044 editing another buffer to set 'filetype' and load a syntax
2045 file.
2046
2047diff_filler({lnum}) *diff_filler()*
2048 Returns the number of filler lines above line {lnum}.
2049 These are the lines that were inserted at this point in
2050 another diff'ed window. These filler lines are shown in the
2051 display but don't exist in the buffer.
2052 {lnum} is used like with |getline()|. Thus "." is the current
2053 line, "'m" mark m, etc.
2054 Returns 0 if the current window is not in diff mode.
2055
2056 Can also be used as a |method|: >
2057 GetLnum()->diff_filler()
2058
2059diff_hlID({lnum}, {col}) *diff_hlID()*
2060 Returns the highlight ID for diff mode at line {lnum} column
2061 {col} (byte index). When the current line does not have a
2062 diff change zero is returned.
2063 {lnum} is used like with |getline()|. Thus "." is the current
2064 line, "'m" mark m, etc.
2065 {col} is 1 for the leftmost column, {lnum} is 1 for the first
2066 line.
2067 The highlight ID can be used with |synIDattr()| to obtain
2068 syntax information about the highlighting.
2069
2070 Can also be used as a |method|: >
2071 GetLnum()->diff_hlID(col)
2072<
2073
2074digraph_get({chars}) *digraph_get()* *E1214*
2075 Return the digraph of {chars}. This should be a string with
2076 exactly two characters. If {chars} are not just two
2077 characters, or the digraph of {chars} does not exist, an error
2078 is given and an empty string is returned.
2079
2080 The character will be converted from Unicode to 'encoding'
2081 when needed. This does require the conversion to be
2082 available, it might fail.
2083
2084 Also see |digraph_getlist()|.
2085
2086 Examples: >
2087 " Get a built-in digraph
2088 :echo digraph_get('00') " Returns '∞'
2089
2090 " Get a user-defined digraph
2091 :call digraph_set('aa', 'あ')
2092 :echo digraph_get('aa') " Returns 'あ'
2093<
2094 Can also be used as a |method|: >
2095 GetChars()->digraph_get()
2096<
2097 This function works only when compiled with the |+digraphs|
2098 feature. If this feature is disabled, this function will
2099 display an error message.
2100
2101
2102digraph_getlist([{listall}]) *digraph_getlist()*
2103 Return a list of digraphs. If the {listall} argument is given
2104 and it is TRUE, return all digraphs, including the default
2105 digraphs. Otherwise, return only user-defined digraphs.
2106
2107 The characters will be converted from Unicode to 'encoding'
2108 when needed. This does require the conservation to be
2109 available, it might fail.
2110
2111 Also see |digraph_get()|.
2112
2113 Examples: >
2114 " Get user-defined digraphs
2115 :echo digraph_getlist()
2116
2117 " Get all the digraphs, including default digraphs
2118 :echo digraph_getlist(1)
2119<
2120 Can also be used as a |method|: >
2121 GetNumber()->digraph_getlist()
2122<
2123 This function works only when compiled with the |+digraphs|
2124 feature. If this feature is disabled, this function will
2125 display an error message.
2126
2127
Bram Moolenaara2baa732022-02-04 16:09:54 +00002128digraph_set({chars}, {digraph}) *digraph_set()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002129 Add digraph {chars} to the list. {chars} must be a string
2130 with two characters. {digraph} is a string with one UTF-8
Bram Moolenaara2baa732022-02-04 16:09:54 +00002131 encoded character. *E1215*
2132 Be careful, composing characters are NOT ignored. This
2133 function is similar to |:digraphs| command, but useful to add
2134 digraphs start with a white space.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002135
2136 The function result is v:true if |digraph| is registered. If
2137 this fails an error message is given and v:false is returned.
2138
2139 If you want to define multiple digraphs at once, you can use
2140 |digraph_setlist()|.
2141
2142 Example: >
2143 call digraph_set(' ', 'あ')
2144<
2145 Can be used as a |method|: >
2146 GetString()->digraph_set('あ')
2147<
2148 This function works only when compiled with the |+digraphs|
2149 feature. If this feature is disabled, this function will
2150 display an error message.
2151
2152
2153digraph_setlist({digraphlist}) *digraph_setlist()*
2154 Similar to |digraph_set()| but this function can add multiple
2155 digraphs at once. {digraphlist} is a list composed of lists,
2156 where each list contains two strings with {chars} and
Bram Moolenaara2baa732022-02-04 16:09:54 +00002157 {digraph} as in |digraph_set()|. *E1216*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002158 Example: >
2159 call digraph_setlist([['aa', 'あ'], ['ii', 'い']])
2160<
2161 It is similar to the following: >
2162 for [chars, digraph] in [['aa', 'あ'], ['ii', 'い']]
2163 call digraph_set(chars, digraph)
2164 endfor
2165< Except that the function returns after the first error,
2166 following digraphs will not be added.
2167
2168 Can be used as a |method|: >
2169 GetList()->digraph_setlist()
2170<
2171 This function works only when compiled with the |+digraphs|
2172 feature. If this feature is disabled, this function will
2173 display an error message.
2174
2175
2176echoraw({string}) *echoraw()*
2177 Output {string} as-is, including unprintable characters.
2178 This can be used to output a terminal code. For example, to
2179 disable modifyOtherKeys: >
2180 call echoraw(&t_TE)
2181< and to enable it again: >
2182 call echoraw(&t_TI)
2183< Use with care, you can mess up the terminal this way.
2184
2185
2186empty({expr}) *empty()*
2187 Return the Number 1 if {expr} is empty, zero otherwise.
2188 - A |List| or |Dictionary| is empty when it does not have any
2189 items.
2190 - A |String| is empty when its length is zero.
2191 - A |Number| and |Float| are empty when their value is zero.
2192 - |v:false|, |v:none| and |v:null| are empty, |v:true| is not.
2193 - A |Job| is empty when it failed to start.
2194 - A |Channel| is empty when it is closed.
2195 - A |Blob| is empty when its length is zero.
2196
2197 For a long |List| this is much faster than comparing the
2198 length with zero.
2199
2200 Can also be used as a |method|: >
2201 mylist->empty()
2202
2203environ() *environ()*
2204 Return all of environment variables as dictionary. You can
2205 check if an environment variable exists like this: >
2206 :echo has_key(environ(), 'HOME')
2207< Note that the variable name may be CamelCase; to ignore case
2208 use this: >
2209 :echo index(keys(environ()), 'HOME', 0, 1) != -1
2210
Bram Moolenaar416bd912023-07-07 23:19:18 +01002211
2212err_teapot([{expr}]) *err_teapot()*
2213 Produce an error with number 418, needed for implementation of
Christian Brabandtee17b6f2023-09-09 11:23:50 +02002214 RFC 2324.
Bram Moolenaar416bd912023-07-07 23:19:18 +01002215 If {expr} is present and it is TRUE error 503 is given,
2216 indicating that coffee is temporarily not available.
2217 If {expr} is present it must be a String.
2218
2219
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002220escape({string}, {chars}) *escape()*
2221 Escape the characters in {chars} that occur in {string} with a
2222 backslash. Example: >
2223 :echo escape('c:\program files\vim', ' \')
2224< results in: >
2225 c:\\program\ files\\vim
2226< Also see |shellescape()| and |fnameescape()|.
2227
2228 Can also be used as a |method|: >
2229 GetText()->escape(' \')
2230<
2231 *eval()*
2232eval({string}) Evaluate {string} and return the result. Especially useful to
2233 turn the result of |string()| back into the original value.
2234 This works for Numbers, Floats, Strings, Blobs and composites
2235 of them. Also works for |Funcref|s that refer to existing
2236 functions.
2237
2238 Can also be used as a |method|: >
2239 argv->join()->eval()
2240
2241eventhandler() *eventhandler()*
2242 Returns 1 when inside an event handler. That is that Vim got
2243 interrupted while waiting for the user to type a character,
2244 e.g., when dropping a file on Vim. This means interactive
2245 commands cannot be used. Otherwise zero is returned.
2246
2247executable({expr}) *executable()*
2248 This function checks if an executable with the name {expr}
2249 exists. {expr} must be the name of the program without any
2250 arguments.
2251 executable() uses the value of $PATH and/or the normal
2252 searchpath for programs. *PATHEXT*
2253 On MS-Windows the ".exe", ".bat", etc. can optionally be
2254 included. Then the extensions in $PATHEXT are tried. Thus if
2255 "foo.exe" does not exist, "foo.exe.bat" can be found. If
2256 $PATHEXT is not set then ".com;.exe;.bat;.cmd" is used. A dot
2257 by itself can be used in $PATHEXT to try using the name
2258 without an extension. When 'shell' looks like a Unix shell,
2259 then the name is also tried without adding an extension.
2260 On MS-Windows it only checks if the file exists and is not a
2261 directory, not if it's really executable.
2262 On MS-Windows an executable in the same directory as Vim is
Yasuhiro Matsumoto05cf63e2022-05-03 11:02:28 +01002263 normally found. Since this directory is added to $PATH it
2264 should also work to execute it |win32-PATH|. This can be
2265 disabled by setting the $NoDefaultCurrentDirectoryInExePath
2266 environment variable. *NoDefaultCurrentDirectoryInExePath*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002267 The result is a Number:
2268 1 exists
2269 0 does not exist
2270 -1 not implemented on this system
2271 |exepath()| can be used to get the full path of an executable.
2272
2273 Can also be used as a |method|: >
2274 GetCommand()->executable()
2275
2276execute({command} [, {silent}]) *execute()*
2277 Execute an Ex command or commands and return the output as a
2278 string.
2279 {command} can be a string or a List. In case of a List the
2280 lines are executed one by one.
Bram Moolenaarb7398fe2023-05-14 18:50:25 +01002281 This is more or less equivalent to: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002282 redir => var
2283 {command}
2284 redir END
Bram Moolenaar71badf92023-04-22 22:40:14 +01002285< Except that line continuation in {command} is not recognized.
2286
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002287 The optional {silent} argument can have these values:
2288 "" no `:silent` used
2289 "silent" `:silent` used
2290 "silent!" `:silent!` used
2291 The default is "silent". Note that with "silent!", unlike
2292 `:redir`, error messages are dropped. When using an external
2293 command the screen may be messed up, use `system()` instead.
2294 *E930*
2295 It is not possible to use `:redir` anywhere in {command}.
2296
Bram Moolenaarb7398fe2023-05-14 18:50:25 +01002297 To get a list of lines use `split()` on the result: >
Bram Moolenaar75ab5902022-04-18 15:36:40 +01002298 execute('args')->split("\n")
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002299
2300< To execute a command in another window than the current one
2301 use `win_execute()`.
2302
2303 When used recursively the output of the recursive call is not
2304 included in the output of the higher level call.
2305
2306 Can also be used as a |method|: >
2307 GetCommand()->execute()
2308
2309exepath({expr}) *exepath()*
2310 If {expr} is an executable and is either an absolute path, a
2311 relative path or found in $PATH, return the full path.
2312 Note that the current directory is used when {expr} starts
2313 with "./", which may be a problem for Vim: >
2314 echo exepath(v:progpath)
2315< If {expr} cannot be found in $PATH or is not executable then
2316 an empty string is returned.
2317
2318 Can also be used as a |method|: >
2319 GetCommand()->exepath()
2320<
2321 *exists()*
2322exists({expr}) The result is a Number, which is |TRUE| if {expr} is defined,
2323 zero otherwise.
2324
2325 Note: In a compiled |:def| function the evaluation is done at
2326 runtime. Use `exists_compiled()` to evaluate the expression
2327 at compile time.
2328
2329 For checking for a supported feature use |has()|.
2330 For checking if a file exists use |filereadable()|.
2331
2332 The {expr} argument is a string, which contains one of these:
Bram Moolenaarf10911e2022-01-29 22:20:48 +00002333 varname internal variable (see
2334 dict.key |internal-variables|). Also works
2335 list[i] for |curly-braces-names|, |Dictionary|
2336 import.Func entries, |List| items, imported
Bram Moolenaar944697a2022-02-20 19:48:20 +00002337 items, etc.
Bram Moolenaarf10911e2022-01-29 22:20:48 +00002338 Does not work for local variables in a
2339 compiled `:def` function.
Bram Moolenaar944697a2022-02-20 19:48:20 +00002340 Also works for a function in |Vim9|
2341 script, since it can be used as a
2342 function reference.
Bram Moolenaarf10911e2022-01-29 22:20:48 +00002343 Beware that evaluating an index may
2344 cause an error message for an invalid
2345 expression. E.g.: >
2346 :let l = [1, 2, 3]
2347 :echo exists("l[5]")
2348< 0 >
2349 :echo exists("l[xx]")
2350< E121: Undefined variable: xx
2351 0
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002352 &option-name Vim option (only checks if it exists,
2353 not if it really works)
2354 +option-name Vim option that works.
2355 $ENVNAME environment variable (could also be
2356 done by comparing with an empty
2357 string)
2358 *funcname built-in function (see |functions|)
2359 or user defined function (see
2360 |user-functions|) that is implemented.
2361 Also works for a variable that is a
2362 Funcref.
2363 ?funcname built-in function that could be
2364 implemented; to be used to check if
2365 "funcname" is valid
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002366 :cmdname Ex command: built-in command, user
2367 command or command modifier |:command|.
2368 Returns:
2369 1 for match with start of a command
2370 2 full match with a command
2371 3 matches several user commands
2372 To check for a supported command
2373 always check the return value to be 2.
2374 :2match The |:2match| command.
Bram Moolenaarb529cfb2022-07-25 15:42:07 +01002375 :3match The |:3match| command (but you
2376 probably should not use it, it is
2377 reserved for internal usage)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002378 #event autocommand defined for this event
2379 #event#pattern autocommand defined for this event and
2380 pattern (the pattern is taken
2381 literally and compared to the
2382 autocommand patterns character by
2383 character)
2384 #group autocommand group exists
2385 #group#event autocommand defined for this group and
2386 event.
2387 #group#event#pattern
2388 autocommand defined for this group,
2389 event and pattern.
2390 ##event autocommand for this event is
2391 supported.
2392
2393 Examples: >
2394 exists("&shortname")
2395 exists("$HOSTNAME")
2396 exists("*strftime")
Bram Moolenaar944697a2022-02-20 19:48:20 +00002397 exists("*s:MyFunc") " only for legacy script
2398 exists("*MyFunc")
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002399 exists("bufcount")
2400 exists(":Make")
2401 exists("#CursorHold")
2402 exists("#BufReadPre#*.gz")
2403 exists("#filetypeindent")
2404 exists("#filetypeindent#FileType")
2405 exists("#filetypeindent#FileType#*")
2406 exists("##ColorScheme")
2407< There must be no space between the symbol (&/$/*/#) and the
2408 name.
2409 There must be no extra characters after the name, although in
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01002410 a few cases this is ignored. That may become stricter in the
2411 future, thus don't count on it!
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002412 Working example: >
2413 exists(":make")
2414< NOT working example: >
2415 exists(":make install")
2416
2417< Note that the argument must be a string, not the name of the
2418 variable itself. For example: >
2419 exists(bufcount)
2420< This doesn't check for existence of the "bufcount" variable,
2421 but gets the value of "bufcount", and checks if that exists.
2422
2423 Can also be used as a |method|: >
2424 Varname()->exists()
2425<
2426
2427exists_compiled({expr}) *exists_compiled()*
2428 Like `exists()` but evaluated at compile time. This is useful
2429 to skip a block where a function is used that would otherwise
2430 give an error: >
2431 if exists_compiled('*ThatFunction')
2432 ThatFunction('works')
2433 endif
2434< If `exists()` were used then a compilation error would be
2435 given if ThatFunction() is not defined.
2436
2437 {expr} must be a literal string. *E1232*
2438 Can only be used in a |:def| function. *E1233*
2439 This does not work to check for arguments or local variables.
2440
2441
2442exp({expr}) *exp()*
2443 Return the exponential of {expr} as a |Float| in the range
2444 [0, inf].
2445 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar016188f2022-06-06 20:52:59 +01002446 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002447 Examples: >
2448 :echo exp(2)
2449< 7.389056 >
2450 :echo exp(-1)
2451< 0.367879
2452
2453 Can also be used as a |method|: >
2454 Compute()->exp()
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002455
2456
2457expand({string} [, {nosuf} [, {list}]]) *expand()*
2458 Expand wildcards and the following special keywords in
2459 {string}. 'wildignorecase' applies.
2460
2461 If {list} is given and it is |TRUE|, a List will be returned.
2462 Otherwise the result is a String and when there are several
2463 matches, they are separated by <NL> characters. [Note: in
2464 version 5.0 a space was used, which caused problems when a
2465 file name contains a space]
2466
2467 If the expansion fails, the result is an empty string. A name
2468 for a non-existing file is not included, unless {string} does
2469 not start with '%', '#' or '<', see below.
2470
2471 When {string} starts with '%', '#' or '<', the expansion is
2472 done like for the |cmdline-special| variables with their
2473 associated modifiers. Here is a short overview:
2474
2475 % current file name
2476 # alternate file name
2477 #n alternate file name n
2478 <cfile> file name under the cursor
2479 <afile> autocmd file name
2480 <abuf> autocmd buffer number (as a String!)
2481 <amatch> autocmd matched name
2482 <cexpr> C expression under the cursor
2483 <sfile> sourced script file or function name
2484 <slnum> sourced script line number or function
2485 line number
2486 <sflnum> script file line number, also when in
2487 a function
2488 <SID> "<SNR>123_" where "123" is the
2489 current script ID |<SID>|
Bram Moolenaar75ab5902022-04-18 15:36:40 +01002490 <script> sourced script file, or script file
2491 where the current function was defined
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002492 <stack> call stack
2493 <cword> word under the cursor
2494 <cWORD> WORD under the cursor
2495 <client> the {clientid} of the last received
2496 message |server2client()|
2497 Modifiers:
2498 :p expand to full path
2499 :h head (last path component removed)
2500 :t tail (last path component only)
2501 :r root (one extension removed)
2502 :e extension only
2503
2504 Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00002505 :let &tags = expand("%:p:h") .. "/tags"
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002506< Note that when expanding a string that starts with '%', '#' or
2507 '<', any following text is ignored. This does NOT work: >
2508 :let doesntwork = expand("%:h.bak")
2509< Use this: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00002510 :let doeswork = expand("%:h") .. ".bak"
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002511< Also note that expanding "<cfile>" and others only returns the
2512 referenced file name without further expansion. If "<cfile>"
2513 is "~/.cshrc", you need to do another expand() to have the
2514 "~/" expanded into the path of the home directory: >
2515 :echo expand(expand("<cfile>"))
2516<
2517 There cannot be white space between the variables and the
2518 following modifier. The |fnamemodify()| function can be used
2519 to modify normal file names.
2520
2521 When using '%' or '#', and the current or alternate file name
2522 is not defined, an empty string is used. Using "%:p" in a
2523 buffer with no name, results in the current directory, with a
2524 '/' added.
Bram Moolenaar57544522022-04-12 12:54:11 +01002525 When 'verbose' is set then expanding '%', '#' and <> items
2526 will result in an error message if the argument cannot be
2527 expanded.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002528
2529 When {string} does not start with '%', '#' or '<', it is
2530 expanded like a file name is expanded on the command line.
2531 'suffixes' and 'wildignore' are used, unless the optional
2532 {nosuf} argument is given and it is |TRUE|.
2533 Names for non-existing files are included. The "**" item can
2534 be used to search in a directory tree. For example, to find
2535 all "README" files in the current directory and below: >
2536 :echo expand("**/README")
2537<
2538 expand() can also be used to expand variables and environment
2539 variables that are only known in a shell. But this can be
2540 slow, because a shell may be used to do the expansion. See
2541 |expr-env-expand|.
2542 The expanded variable is still handled like a list of file
2543 names. When an environment variable cannot be expanded, it is
2544 left unchanged. Thus ":echo expand('$FOOBAR')" results in
2545 "$FOOBAR".
2546
2547 See |glob()| for finding existing files. See |system()| for
2548 getting the raw output of an external command.
2549
2550 Can also be used as a |method|: >
2551 Getpattern()->expand()
2552
Yegappan Lakshmanan2b74b682022-04-03 21:30:32 +01002553expandcmd({string} [, {options}]) *expandcmd()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002554 Expand special items in String {string} like what is done for
2555 an Ex command such as `:edit`. This expands special keywords,
2556 like with |expand()|, and environment variables, anywhere in
2557 {string}. "~user" and "~/path" are only expanded at the
2558 start.
Yegappan Lakshmanan2b74b682022-04-03 21:30:32 +01002559
2560 The following items are supported in the {options} Dict
2561 argument:
2562 errmsg If set to TRUE, error messages are displayed
2563 if an error is encountered during expansion.
2564 By default, error messages are not displayed.
2565
Yegappan Lakshmanan5018a832022-04-02 21:12:21 +01002566 Returns the expanded string. If an error is encountered
2567 during expansion, the unmodified {string} is returned.
Yegappan Lakshmanan2b74b682022-04-03 21:30:32 +01002568
Yegappan Lakshmanan5018a832022-04-02 21:12:21 +01002569 Example: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002570 :echo expandcmd('make %<.o')
Yegappan Lakshmanan2b74b682022-04-03 21:30:32 +01002571 make /path/runtime/doc/builtin.o
2572 :echo expandcmd('make %<.o', {'errmsg': v:true})
2573<
Yegappan Lakshmanan5018a832022-04-02 21:12:21 +01002574 Can also be used as a |method|: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002575 GetCommand()->expandcmd()
2576<
2577extend({expr1}, {expr2} [, {expr3}]) *extend()*
2578 {expr1} and {expr2} must be both |Lists| or both
2579 |Dictionaries|.
2580
2581 If they are |Lists|: Append {expr2} to {expr1}.
2582 If {expr3} is given insert the items of {expr2} before the
2583 item with index {expr3} in {expr1}. When {expr3} is zero
2584 insert before the first item. When {expr3} is equal to
2585 len({expr1}) then {expr2} is appended.
2586 Examples: >
2587 :echo sort(extend(mylist, [7, 5]))
2588 :call extend(mylist, [2, 3], 1)
2589< When {expr1} is the same List as {expr2} then the number of
2590 items copied is equal to the original length of the List.
2591 E.g., when {expr3} is 1 you get N new copies of the first item
2592 (where N is the original length of the List).
2593 Use |add()| to concatenate one item to a list. To concatenate
2594 two lists into a new list use the + operator: >
2595 :let newlist = [1, 2, 3] + [4, 5]
2596<
2597 If they are |Dictionaries|:
2598 Add all entries from {expr2} to {expr1}.
2599 If a key exists in both {expr1} and {expr2} then {expr3} is
2600 used to decide what to do:
2601 {expr3} = "keep": keep the value of {expr1}
2602 {expr3} = "force": use the value of {expr2}
2603 {expr3} = "error": give an error message *E737*
2604 When {expr3} is omitted then "force" is assumed.
2605
2606 {expr1} is changed when {expr2} is not empty. If necessary
2607 make a copy of {expr1} first.
2608 {expr2} remains unchanged.
2609 When {expr1} is locked and {expr2} is not empty the operation
2610 fails.
Bram Moolenaar016188f2022-06-06 20:52:59 +01002611 Returns {expr1}. Returns 0 on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002612
2613 Can also be used as a |method|: >
2614 mylist->extend(otherlist)
2615
2616
2617extendnew({expr1}, {expr2} [, {expr3}]) *extendnew()*
2618 Like |extend()| but instead of adding items to {expr1} a new
2619 List or Dictionary is created and returned. {expr1} remains
Bram Moolenaardd60c362023-02-27 15:49:53 +00002620 unchanged.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002621
2622
2623feedkeys({string} [, {mode}]) *feedkeys()*
2624 Characters in {string} are queued for processing as if they
2625 come from a mapping or were typed by the user.
2626
2627 By default the string is added to the end of the typeahead
2628 buffer, thus if a mapping is still being executed the
2629 characters come after them. Use the 'i' flag to insert before
2630 other characters, they will be executed next, before any
2631 characters from a mapping.
2632
2633 The function does not wait for processing of keys contained in
2634 {string}.
2635
2636 To include special keys into {string}, use double-quotes
2637 and "\..." notation |expr-quote|. For example,
2638 feedkeys("\<CR>") simulates pressing of the <Enter> key. But
2639 feedkeys('\<CR>') pushes 5 characters.
2640 A special code that might be useful is <Ignore>, it exits the
2641 wait for a character without doing anything. *<Ignore>*
2642
2643 {mode} is a String, which can contain these character flags:
2644 'm' Remap keys. This is default. If {mode} is absent,
2645 keys are remapped.
2646 'n' Do not remap keys.
2647 't' Handle keys as if typed; otherwise they are handled as
2648 if coming from a mapping. This matters for undo,
2649 opening folds, etc.
2650 'L' Lowlevel input. Only works for Unix or when using the
2651 GUI. Keys are used as if they were coming from the
2652 terminal. Other flags are not used. *E980*
2653 When a CTRL-C interrupts and 't' is included it sets
2654 the internal "got_int" flag.
2655 'i' Insert the string instead of appending (see above).
2656 'x' Execute commands until typeahead is empty. This is
2657 similar to using ":normal!". You can call feedkeys()
2658 several times without 'x' and then one time with 'x'
2659 (possibly with an empty {string}) to execute all the
2660 typeahead. Note that when Vim ends in Insert mode it
2661 will behave as if <Esc> is typed, to avoid getting
2662 stuck, waiting for a character to be typed before the
2663 script continues.
2664 Note that if you manage to call feedkeys() while
2665 executing commands, thus calling it recursively, then
2666 all typeahead will be consumed by the last call.
Bram Moolenaara9725222022-01-16 13:30:33 +00002667 'c' Remove any script context when executing, so that
2668 legacy script syntax applies, "s:var" does not work,
Bram Moolenaard899e512022-05-07 21:54:03 +01002669 etc. Note that if the string being fed sets a script
Bram Moolenaarce001a32022-04-27 15:25:03 +01002670 context this still applies.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002671 '!' When used with 'x' will not end Insert mode. Can be
2672 used in a test when a timer is set to exit Insert mode
2673 a little later. Useful for testing CursorHoldI.
2674
2675 Return value is always 0.
2676
2677 Can also be used as a |method|: >
2678 GetInput()->feedkeys()
2679
2680filereadable({file}) *filereadable()*
2681 The result is a Number, which is |TRUE| when a file with the
2682 name {file} exists, and can be read. If {file} doesn't exist,
2683 or is a directory, the result is |FALSE|. {file} is any
2684 expression, which is used as a String.
2685 If you don't care about the file being readable you can use
2686 |glob()|.
2687 {file} is used as-is, you may want to expand wildcards first: >
2688 echo filereadable('~/.vimrc')
2689 0
2690 echo filereadable(expand('~/.vimrc'))
2691 1
2692
2693< Can also be used as a |method|: >
2694 GetName()->filereadable()
2695< *file_readable()*
2696 Obsolete name: file_readable().
2697
2698
2699filewritable({file}) *filewritable()*
2700 The result is a Number, which is 1 when a file with the
2701 name {file} exists, and can be written. If {file} doesn't
2702 exist, or is not writable, the result is 0. If {file} is a
2703 directory, and we can write to it, the result is 2.
2704
2705 Can also be used as a |method|: >
2706 GetName()->filewritable()
2707
2708
2709filter({expr1}, {expr2}) *filter()*
2710 {expr1} must be a |List|, |String|, |Blob| or |Dictionary|.
2711 For each item in {expr1} evaluate {expr2} and when the result
2712 is zero or false remove the item from the |List| or
2713 |Dictionary|. Similarly for each byte in a |Blob| and each
Bram Moolenaar2f0936c2022-01-08 21:51:59 +00002714 character in a |String|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002715
2716 {expr2} must be a |string| or |Funcref|.
2717
2718 If {expr2} is a |string|, inside {expr2} |v:val| has the value
2719 of the current item. For a |Dictionary| |v:key| has the key
2720 of the current item and for a |List| |v:key| has the index of
2721 the current item. For a |Blob| |v:key| has the index of the
2722 current byte. For a |String| |v:key| has the index of the
2723 current character.
2724 Examples: >
2725 call filter(mylist, 'v:val !~ "OLD"')
2726< Removes the items where "OLD" appears. >
2727 call filter(mydict, 'v:key >= 8')
2728< Removes the items with a key below 8. >
2729 call filter(var, 0)
2730< Removes all the items, thus clears the |List| or |Dictionary|.
2731
2732 Note that {expr2} is the result of expression and is then
2733 used as an expression again. Often it is good to use a
2734 |literal-string| to avoid having to double backslashes.
2735
2736 If {expr2} is a |Funcref| it must take two arguments:
2737 1. the key or the index of the current item.
2738 2. the value of the current item.
2739 The function must return |TRUE| if the item should be kept.
2740 Example that keeps the odd items of a list: >
2741 func Odd(idx, val)
2742 return a:idx % 2 == 1
2743 endfunc
2744 call filter(mylist, function('Odd'))
Bram Moolenaar2f0936c2022-01-08 21:51:59 +00002745< It is shorter when using a |lambda|. In |Vim9| syntax: >
2746 call filter(myList, (idx, val) => idx * val <= 42)
2747< In legacy script syntax: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002748 call filter(myList, {idx, val -> idx * val <= 42})
2749< If you do not use "val" you can leave it out: >
2750 call filter(myList, {idx -> idx % 2 == 1})
2751<
2752 In |Vim9| script the result must be true, false, zero or one.
2753 Other values will result in a type error.
2754
2755 For a |List| and a |Dictionary| the operation is done
2756 in-place. If you want it to remain unmodified make a copy
2757 first: >
2758 :let l = filter(copy(mylist), 'v:val =~ "KEEP"')
2759
2760< Returns {expr1}, the |List| or |Dictionary| that was filtered,
naohiro ono56200ee2022-01-01 14:59:44 +00002761 or a new |Blob| or |String|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002762 When an error is encountered while evaluating {expr2} no
2763 further items in {expr1} are processed.
2764 When {expr2} is a Funcref errors inside a function are ignored,
2765 unless it was defined with the "abort" flag.
2766
2767 Can also be used as a |method|: >
2768 mylist->filter(expr2)
2769
2770finddir({name} [, {path} [, {count}]]) *finddir()*
2771 Find directory {name} in {path}. Supports both downwards and
2772 upwards recursive directory searches. See |file-searching|
2773 for the syntax of {path}.
2774
2775 Returns the path of the first found match. When the found
2776 directory is below the current directory a relative path is
2777 returned. Otherwise a full path is returned.
2778 If {path} is omitted or empty then 'path' is used.
2779
2780 If the optional {count} is given, find {count}'s occurrence of
2781 {name} in {path} instead of the first one.
2782 When {count} is negative return all the matches in a |List|.
2783
Bram Moolenaar016188f2022-06-06 20:52:59 +01002784 Returns an empty string if the directory is not found.
2785
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002786 This is quite similar to the ex-command `:find`.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002787
2788 Can also be used as a |method|: >
2789 GetName()->finddir()
2790
2791findfile({name} [, {path} [, {count}]]) *findfile()*
2792 Just like |finddir()|, but find a file instead of a directory.
2793 Uses 'suffixesadd'.
2794 Example: >
2795 :echo findfile("tags.vim", ".;")
2796< Searches from the directory of the current file upwards until
2797 it finds the file "tags.vim".
2798
2799 Can also be used as a |method|: >
2800 GetName()->findfile()
2801
2802flatten({list} [, {maxdepth}]) *flatten()*
2803 Flatten {list} up to {maxdepth} levels. Without {maxdepth}
2804 the result is a |List| without nesting, as if {maxdepth} is
2805 a very large number.
2806 The {list} is changed in place, use |flattennew()| if you do
2807 not want that.
2808 In Vim9 script flatten() cannot be used, you must always use
Bram Moolenaara2baa732022-02-04 16:09:54 +00002809 |flattennew()|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002810 *E900*
2811 {maxdepth} means how deep in nested lists changes are made.
2812 {list} is not modified when {maxdepth} is 0.
2813 {maxdepth} must be positive number.
2814
2815 If there is an error the number zero is returned.
2816
2817 Example: >
2818 :echo flatten([1, [2, [3, 4]], 5])
2819< [1, 2, 3, 4, 5] >
2820 :echo flatten([1, [2, [3, 4]], 5], 1)
2821< [1, 2, [3, 4], 5]
2822
2823 Can also be used as a |method|: >
2824 mylist->flatten()
2825<
2826flattennew({list} [, {maxdepth}]) *flattennew()*
2827 Like |flatten()| but first make a copy of {list}.
2828
2829
2830float2nr({expr}) *float2nr()*
2831 Convert {expr} to a Number by omitting the part after the
2832 decimal point.
Bram Moolenaar76db9e02022-11-09 21:21:04 +00002833 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar016188f2022-06-06 20:52:59 +01002834 Returns 0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002835 When the value of {expr} is out of range for a |Number| the
2836 result is truncated to 0x7fffffff or -0x7fffffff (or when
2837 64-bit Number support is enabled, 0x7fffffffffffffff or
2838 -0x7fffffffffffffff). NaN results in -0x80000000 (or when
2839 64-bit Number support is enabled, -0x8000000000000000).
2840 Examples: >
2841 echo float2nr(3.95)
2842< 3 >
2843 echo float2nr(-23.45)
2844< -23 >
2845 echo float2nr(1.0e100)
2846< 2147483647 (or 9223372036854775807) >
2847 echo float2nr(-1.0e150)
2848< -2147483647 (or -9223372036854775807) >
2849 echo float2nr(1.0e-100)
2850< 0
2851
2852 Can also be used as a |method|: >
2853 Compute()->float2nr()
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002854
2855
2856floor({expr}) *floor()*
2857 Return the largest integral value less than or equal to
2858 {expr} as a |Float| (round down).
2859 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar016188f2022-06-06 20:52:59 +01002860 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002861 Examples: >
2862 echo floor(1.856)
2863< 1.0 >
2864 echo floor(-5.456)
2865< -6.0 >
2866 echo floor(4.0)
2867< 4.0
2868
2869 Can also be used as a |method|: >
2870 Compute()->floor()
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002871
2872
2873fmod({expr1}, {expr2}) *fmod()*
2874 Return the remainder of {expr1} / {expr2}, even if the
2875 division is not representable. Returns {expr1} - i * {expr2}
2876 for some integer i such that if {expr2} is non-zero, the
2877 result has the same sign as {expr1} and magnitude less than
2878 the magnitude of {expr2}. If {expr2} is zero, the value
2879 returned is zero. The value returned is a |Float|.
2880 {expr1} and {expr2} must evaluate to a |Float| or a |Number|.
Bram Moolenaar016188f2022-06-06 20:52:59 +01002881 Returns 0.0 if {expr1} or {expr2} is not a |Float| or a
2882 |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002883 Examples: >
2884 :echo fmod(12.33, 1.22)
2885< 0.13 >
2886 :echo fmod(-12.33, 1.22)
2887< -0.13
2888
2889 Can also be used as a |method|: >
2890 Compute()->fmod(1.22)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002891
2892
2893fnameescape({string}) *fnameescape()*
2894 Escape {string} for use as file name command argument. All
2895 characters that have a special meaning, such as '%' and '|'
2896 are escaped with a backslash.
2897 For most systems the characters escaped are
2898 " \t\n*?[{`$\\%#'\"|!<". For systems where a backslash
2899 appears in a filename, it depends on the value of 'isfname'.
2900 A leading '+' and '>' is also escaped (special after |:edit|
2901 and |:write|). And a "-" by itself (special after |:cd|).
Bram Moolenaar016188f2022-06-06 20:52:59 +01002902 Returns an empty string on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002903 Example: >
2904 :let fname = '+some str%nge|name'
Bram Moolenaarc51cf032022-02-26 12:25:45 +00002905 :exe "edit " .. fnameescape(fname)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002906< results in executing: >
2907 edit \+some\ str\%nge\|name
2908<
2909 Can also be used as a |method|: >
2910 GetName()->fnameescape()
2911
2912fnamemodify({fname}, {mods}) *fnamemodify()*
2913 Modify file name {fname} according to {mods}. {mods} is a
2914 string of characters like it is used for file names on the
2915 command line. See |filename-modifiers|.
2916 Example: >
2917 :echo fnamemodify("main.c", ":p:h")
2918< results in: >
Bram Moolenaard799daa2022-06-20 11:17:32 +01002919 /home/user/vim/vim/src
Bram Moolenaar016188f2022-06-06 20:52:59 +01002920< If {mods} is empty or an unsupported modifier is used then
2921 {fname} is returned.
Bram Moolenaar5ed11532022-07-06 13:18:11 +01002922 When {fname} is empty then with {mods} ":h" returns ".", so
2923 that `:cd` can be used with it. This is different from
2924 expand('%:h') without a buffer name, which returns an empty
2925 string.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002926 Note: Environment variables don't work in {fname}, use
2927 |expand()| first then.
2928
2929 Can also be used as a |method|: >
2930 GetName()->fnamemodify(':p:h')
2931
2932foldclosed({lnum}) *foldclosed()*
2933 The result is a Number. If the line {lnum} is in a closed
2934 fold, the result is the number of the first line in that fold.
2935 If the line {lnum} is not in a closed fold, -1 is returned.
2936 {lnum} is used like with |getline()|. Thus "." is the current
2937 line, "'m" mark m, etc.
2938
2939 Can also be used as a |method|: >
2940 GetLnum()->foldclosed()
2941
2942foldclosedend({lnum}) *foldclosedend()*
2943 The result is a Number. If the line {lnum} is in a closed
2944 fold, the result is the number of the last line in that fold.
2945 If the line {lnum} is not in a closed fold, -1 is returned.
2946 {lnum} is used like with |getline()|. Thus "." is the current
2947 line, "'m" mark m, etc.
2948
2949 Can also be used as a |method|: >
2950 GetLnum()->foldclosedend()
2951
2952foldlevel({lnum}) *foldlevel()*
2953 The result is a Number, which is the foldlevel of line {lnum}
2954 in the current buffer. For nested folds the deepest level is
2955 returned. If there is no fold at line {lnum}, zero is
2956 returned. It doesn't matter if the folds are open or closed.
2957 When used while updating folds (from 'foldexpr') -1 is
2958 returned for lines where folds are still to be updated and the
2959 foldlevel is unknown. As a special case the level of the
2960 previous line is usually available.
2961 {lnum} is used like with |getline()|. Thus "." is the current
2962 line, "'m" mark m, etc.
2963
2964 Can also be used as a |method|: >
2965 GetLnum()->foldlevel()
2966<
2967 *foldtext()*
2968foldtext() Returns a String, to be displayed for a closed fold. This is
2969 the default function used for the 'foldtext' option and should
2970 only be called from evaluating 'foldtext'. It uses the
2971 |v:foldstart|, |v:foldend| and |v:folddashes| variables.
2972 The returned string looks like this: >
2973 +-- 45 lines: abcdef
2974< The number of leading dashes depends on the foldlevel. The
2975 "45" is the number of lines in the fold. "abcdef" is the text
2976 in the first non-blank line of the fold. Leading white space,
2977 "//" or "/*" and the text from the 'foldmarker' and
2978 'commentstring' options is removed.
2979 When used to draw the actual foldtext, the rest of the line
2980 will be filled with the fold char from the 'fillchars'
2981 setting.
Bram Moolenaar016188f2022-06-06 20:52:59 +01002982 Returns an empty string when there is no fold.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002983 {not available when compiled without the |+folding| feature}
2984
2985foldtextresult({lnum}) *foldtextresult()*
2986 Returns the text that is displayed for the closed fold at line
2987 {lnum}. Evaluates 'foldtext' in the appropriate context.
2988 When there is no closed fold at {lnum} an empty string is
2989 returned.
2990 {lnum} is used like with |getline()|. Thus "." is the current
2991 line, "'m" mark m, etc.
2992 Useful when exporting folded text, e.g., to HTML.
2993 {not available when compiled without the |+folding| feature}
2994
2995
2996 Can also be used as a |method|: >
2997 GetLnum()->foldtextresult()
2998<
2999 *foreground()*
3000foreground() Move the Vim window to the foreground. Useful when sent from
3001 a client to a Vim server. |remote_send()|
3002 On Win32 systems this might not work, the OS does not always
3003 allow a window to bring itself to the foreground. Use
3004 |remote_foreground()| instead.
Bram Moolenaarcbaff5e2022-04-08 17:45:08 +01003005 {only in the Win32, Motif and GTK GUI versions and the
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003006 Win32 console version}
3007
Bram Moolenaaraa534142022-09-15 21:46:02 +01003008fullcommand({name} [, {vim9}]) *fullcommand()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003009 Get the full command name from a short abbreviated command
3010 name; see |20.2| for details on command abbreviations.
3011
3012 The string argument {name} may start with a `:` and can
3013 include a [range], these are skipped and not returned.
Bram Moolenaaraa534142022-09-15 21:46:02 +01003014 Returns an empty string if a command doesn't exist, if it's
3015 ambiguous (for user-defined commands) or cannot be shortened
3016 this way. |vim9-no-shorten|
3017
3018 Without the {vim9} argument uses the current script version.
3019 If {vim9} is present and FALSE then legacy script rules are
3020 used. When {vim9} is present and TRUE then Vim9 rules are
3021 used, e.g. "en" is not a short form of "endif".
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003022
3023 For example `fullcommand('s')`, `fullcommand('sub')`,
3024 `fullcommand(':%substitute')` all return "substitute".
3025
3026 Can also be used as a |method|: >
3027 GetName()->fullcommand()
3028<
3029 *funcref()*
3030funcref({name} [, {arglist}] [, {dict}])
3031 Just like |function()|, but the returned Funcref will lookup
3032 the function by reference, not by name. This matters when the
3033 function {name} is redefined later.
3034
3035 Unlike |function()|, {name} must be an existing user function.
Bram Moolenaar2f0936c2022-01-08 21:51:59 +00003036 It only works for an autoloaded function if it has already
3037 been loaded (to avoid mistakenly loading the autoload script
3038 when only intending to use the function name, use |function()|
3039 instead). {name} cannot be a builtin function.
Bram Moolenaar016188f2022-06-06 20:52:59 +01003040 Returns 0 on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003041
3042 Can also be used as a |method|: >
3043 GetFuncname()->funcref([arg])
3044<
Dominique Pellee764d1b2023-03-12 21:20:59 +00003045 *function()* *partial* *E700* *E923*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003046function({name} [, {arglist}] [, {dict}])
3047 Return a |Funcref| variable that refers to function {name}.
3048 {name} can be the name of a user defined function or an
3049 internal function.
3050
3051 {name} can also be a Funcref or a partial. When it is a
3052 partial the dict stored in it will be used and the {dict}
3053 argument is not allowed. E.g.: >
3054 let FuncWithArg = function(dict.Func, [arg])
3055 let Broken = function(dict.Func, [arg], dict)
3056<
3057 When using the Funcref the function will be found by {name},
3058 also when it was redefined later. Use |funcref()| to keep the
3059 same function.
3060
3061 When {arglist} or {dict} is present this creates a partial.
3062 That means the argument list and/or the dictionary is stored in
3063 the Funcref and will be used when the Funcref is called.
3064
3065 The arguments are passed to the function in front of other
3066 arguments, but after any argument from |method|. Example: >
3067 func Callback(arg1, arg2, name)
3068 ...
3069 let Partial = function('Callback', ['one', 'two'])
3070 ...
3071 call Partial('name')
3072< Invokes the function as with: >
3073 call Callback('one', 'two', 'name')
3074
3075< With a |method|: >
3076 func Callback(one, two, three)
3077 ...
3078 let Partial = function('Callback', ['two'])
3079 ...
3080 eval 'one'->Partial('three')
3081< Invokes the function as with: >
3082 call Callback('one', 'two', 'three')
3083
3084< The function() call can be nested to add more arguments to the
3085 Funcref. The extra arguments are appended to the list of
3086 arguments. Example: >
3087 func Callback(arg1, arg2, name)
Bram Moolenaar0daafaa2022-09-04 17:45:43 +01003088 "...
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003089 let Func = function('Callback', ['one'])
3090 let Func2 = function(Func, ['two'])
Bram Moolenaar0daafaa2022-09-04 17:45:43 +01003091 "...
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003092 call Func2('name')
3093< Invokes the function as with: >
3094 call Callback('one', 'two', 'name')
3095
3096< The Dictionary is only useful when calling a "dict" function.
3097 In that case the {dict} is passed in as "self". Example: >
3098 function Callback() dict
Bram Moolenaarc51cf032022-02-26 12:25:45 +00003099 echo "called for " .. self.name
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003100 endfunction
Bram Moolenaar0daafaa2022-09-04 17:45:43 +01003101 "...
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003102 let context = {"name": "example"}
3103 let Func = function('Callback', context)
Bram Moolenaar0daafaa2022-09-04 17:45:43 +01003104 "...
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003105 call Func() " will echo: called for example
3106< The use of function() is not needed when there are no extra
Bram Moolenaar0daafaa2022-09-04 17:45:43 +01003107 arguments, these two are equivalent, if Callback() is defined
3108 as context.Callback(): >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003109 let Func = function('Callback', context)
3110 let Func = context.Callback
3111
3112< The argument list and the Dictionary can be combined: >
3113 function Callback(arg1, count) dict
Bram Moolenaar0daafaa2022-09-04 17:45:43 +01003114 "...
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003115 let context = {"name": "example"}
3116 let Func = function('Callback', ['one'], context)
Bram Moolenaar0daafaa2022-09-04 17:45:43 +01003117 "...
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003118 call Func(500)
3119< Invokes the function as with: >
3120 call context.Callback('one', 500)
3121<
Bram Moolenaar016188f2022-06-06 20:52:59 +01003122 Returns 0 on error.
3123
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003124 Can also be used as a |method|: >
3125 GetFuncname()->function([arg])
3126
3127
3128garbagecollect([{atexit}]) *garbagecollect()*
3129 Cleanup unused |Lists|, |Dictionaries|, |Channels| and |Jobs|
3130 that have circular references.
3131
3132 There is hardly ever a need to invoke this function, as it is
3133 automatically done when Vim runs out of memory or is waiting
3134 for the user to press a key after 'updatetime'. Items without
3135 circular references are always freed when they become unused.
3136 This is useful if you have deleted a very big |List| and/or
3137 |Dictionary| with circular references in a script that runs
3138 for a long time.
3139
3140 When the optional {atexit} argument is one, garbage
3141 collection will also be done when exiting Vim, if it wasn't
3142 done before. This is useful when checking for memory leaks.
3143
3144 The garbage collection is not done immediately but only when
3145 it's safe to perform. This is when waiting for the user to
3146 type a character. To force garbage collection immediately use
3147 |test_garbagecollect_now()|.
3148
3149get({list}, {idx} [, {default}]) *get()*
3150 Get item {idx} from |List| {list}. When this item is not
3151 available return {default}. Return zero when {default} is
3152 omitted.
3153 Preferably used as a |method|: >
3154 mylist->get(idx)
3155get({blob}, {idx} [, {default}])
3156 Get byte {idx} from |Blob| {blob}. When this byte is not
3157 available return {default}. Return -1 when {default} is
3158 omitted.
3159 Preferably used as a |method|: >
3160 myblob->get(idx)
3161get({dict}, {key} [, {default}])
3162 Get item with key {key} from |Dictionary| {dict}. When this
3163 item is not available return {default}. Return zero when
3164 {default} is omitted. Useful example: >
3165 let val = get(g:, 'var_name', 'default')
3166< This gets the value of g:var_name if it exists, and uses
3167 'default' when it does not exist.
3168 Preferably used as a |method|: >
3169 mydict->get(key)
3170get({func}, {what})
Bram Moolenaar6f4754b2022-01-23 12:07:04 +00003171 Get item {what} from Funcref {func}. Possible values for
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003172 {what} are:
3173 "name" The function name
3174 "func" The function
3175 "dict" The dictionary
3176 "args" The list with arguments
Bram Moolenaar016188f2022-06-06 20:52:59 +01003177 Returns zero on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003178 Preferably used as a |method|: >
3179 myfunc->get(what)
3180<
3181 *getbufinfo()*
3182getbufinfo([{buf}])
3183getbufinfo([{dict}])
3184 Get information about buffers as a List of Dictionaries.
3185
3186 Without an argument information about all the buffers is
3187 returned.
3188
3189 When the argument is a |Dictionary| only the buffers matching
3190 the specified criteria are returned. The following keys can
3191 be specified in {dict}:
3192 buflisted include only listed buffers.
3193 bufloaded include only loaded buffers.
3194 bufmodified include only modified buffers.
3195
3196 Otherwise, {buf} specifies a particular buffer to return
3197 information for. For the use of {buf}, see |bufname()|
3198 above. If the buffer is found the returned List has one item.
3199 Otherwise the result is an empty list.
3200
3201 Each returned List item is a dictionary with the following
3202 entries:
3203 bufnr Buffer number.
3204 changed TRUE if the buffer is modified.
3205 changedtick Number of changes made to the buffer.
3206 hidden TRUE if the buffer is hidden.
3207 lastused Timestamp in seconds, like
3208 |localtime()|, when the buffer was
3209 last used.
3210 {only with the |+viminfo| feature}
3211 listed TRUE if the buffer is listed.
3212 lnum Line number used for the buffer when
3213 opened in the current window.
3214 Only valid if the buffer has been
3215 displayed in the window in the past.
3216 If you want the line number of the
3217 last known cursor position in a given
3218 window, use |line()|: >
3219 :echo line('.', {winid})
3220<
3221 linecount Number of lines in the buffer (only
3222 valid when loaded)
3223 loaded TRUE if the buffer is loaded.
3224 name Full path to the file in the buffer.
3225 signs List of signs placed in the buffer.
3226 Each list item is a dictionary with
3227 the following fields:
3228 id sign identifier
3229 lnum line number
3230 name sign name
3231 variables A reference to the dictionary with
3232 buffer-local variables.
3233 windows List of |window-ID|s that display this
3234 buffer
3235 popups List of popup |window-ID|s that
3236 display this buffer
3237
3238 Examples: >
3239 for buf in getbufinfo()
3240 echo buf.name
3241 endfor
3242 for buf in getbufinfo({'buflisted':1})
3243 if buf.changed
3244 ....
3245 endif
3246 endfor
3247<
3248 To get buffer-local options use: >
3249 getbufvar({bufnr}, '&option_name')
3250<
3251 Can also be used as a |method|: >
3252 GetBufnr()->getbufinfo()
3253<
3254
3255 *getbufline()*
3256getbufline({buf}, {lnum} [, {end}])
3257 Return a |List| with the lines starting from {lnum} to {end}
3258 (inclusive) in the buffer {buf}. If {end} is omitted, a
Bram Moolenaarce30ccc2022-11-21 19:57:04 +00003259 |List| with only the line {lnum} is returned. See
3260 `getbufoneline()` for only getting the line.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003261
3262 For the use of {buf}, see |bufname()| above.
3263
3264 For {lnum} and {end} "$" can be used for the last line of the
3265 buffer. Otherwise a number must be used.
3266
3267 When {lnum} is smaller than 1 or bigger than the number of
3268 lines in the buffer, an empty |List| is returned.
3269
3270 When {end} is greater than the number of lines in the buffer,
3271 it is treated as {end} is set to the number of lines in the
3272 buffer. When {end} is before {lnum} an empty |List| is
3273 returned.
3274
3275 This function works only for loaded buffers. For unloaded and
3276 non-existing buffers, an empty |List| is returned.
3277
3278 Example: >
3279 :let lines = getbufline(bufnr("myfile"), 1, "$")
3280
3281< Can also be used as a |method|: >
3282 GetBufnr()->getbufline(lnum)
Bram Moolenaarce30ccc2022-11-21 19:57:04 +00003283<
3284 *getbufoneline()*
3285getbufoneline({buf}, {lnum})
3286 Just like `getbufline()` but only get one line and return it
3287 as a string.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003288
3289getbufvar({buf}, {varname} [, {def}]) *getbufvar()*
3290 The result is the value of option or local buffer variable
3291 {varname} in buffer {buf}. Note that the name without "b:"
3292 must be used.
3293 The {varname} argument is a string.
3294 When {varname} is empty returns a |Dictionary| with all the
3295 buffer-local variables.
3296 When {varname} is equal to "&" returns a |Dictionary| with all
3297 the buffer-local options.
3298 Otherwise, when {varname} starts with "&" returns the value of
3299 a buffer-local option.
3300 This also works for a global or buffer-local option, but it
3301 doesn't work for a global variable, window-local variable or
3302 window-local option.
3303 For the use of {buf}, see |bufname()| above.
3304 When the buffer or variable doesn't exist {def} or an empty
3305 string is returned, there is no error message.
3306 Examples: >
3307 :let bufmodified = getbufvar(1, "&mod")
Bram Moolenaarc51cf032022-02-26 12:25:45 +00003308 :echo "todo myvar = " .. getbufvar("todo", "myvar")
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003309
3310< Can also be used as a |method|: >
3311 GetBufnr()->getbufvar(varname)
3312<
Kota Kato66bb9ae2023-01-17 18:31:56 +00003313getcellwidths() *getcellwidths()*
3314 Returns a |List| of cell widths of character ranges overridden
3315 by |setcellwidths()|. The format is equal to the argument of
3316 |setcellwidths()|. If no character ranges have their cell
3317 widths overridden, an empty List is returned.
3318
3319
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003320getchangelist([{buf}]) *getchangelist()*
3321 Returns the |changelist| for the buffer {buf}. For the use
3322 of {buf}, see |bufname()| above. If buffer {buf} doesn't
3323 exist, an empty list is returned.
3324
3325 The returned list contains two entries: a list with the change
3326 locations and the current position in the list. Each
3327 entry in the change list is a dictionary with the following
3328 entries:
3329 col column number
3330 coladd column offset for 'virtualedit'
3331 lnum line number
3332 If buffer {buf} is the current buffer, then the current
3333 position refers to the position in the list. For other
3334 buffers, it is set to the length of the list.
3335
3336 Can also be used as a |method|: >
3337 GetBufnr()->getchangelist()
3338
3339getchar([expr]) *getchar()*
3340 Get a single character from the user or input stream.
3341 If [expr] is omitted, wait until a character is available.
3342 If [expr] is 0, only get a character when one is available.
3343 Return zero otherwise.
3344 If [expr] is 1, only check if a character is available, it is
3345 not consumed. Return zero if no character available.
3346 If you prefer always getting a string use |getcharstr()|.
3347
3348 Without [expr] and when [expr] is 0 a whole character or
3349 special key is returned. If it is a single character, the
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01003350 result is a Number. Use |nr2char()| to convert it to a String.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003351 Otherwise a String is returned with the encoded character.
3352 For a special key it's a String with a sequence of bytes
3353 starting with 0x80 (decimal: 128). This is the same value as
3354 the String "\<Key>", e.g., "\<Left>". The returned value is
3355 also a String when a modifier (shift, control, alt) was used
3356 that is not included in the character.
3357
3358 When [expr] is 0 and Esc is typed, there will be a short delay
3359 while Vim waits to see if this is the start of an escape
3360 sequence.
3361
3362 When [expr] is 1 only the first byte is returned. For a
3363 one-byte character it is the character itself as a number.
3364 Use nr2char() to convert it to a String.
3365
3366 Use getcharmod() to obtain any additional modifiers.
3367
3368 When the user clicks a mouse button, the mouse event will be
3369 returned. The position can then be found in |v:mouse_col|,
3370 |v:mouse_lnum|, |v:mouse_winid| and |v:mouse_win|.
3371 |getmousepos()| can also be used. Mouse move events will be
3372 ignored.
3373 This example positions the mouse as it would normally happen: >
3374 let c = getchar()
3375 if c == "\<LeftMouse>" && v:mouse_win > 0
Bram Moolenaarc51cf032022-02-26 12:25:45 +00003376 exe v:mouse_win .. "wincmd w"
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003377 exe v:mouse_lnum
Bram Moolenaarc51cf032022-02-26 12:25:45 +00003378 exe "normal " .. v:mouse_col .. "|"
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003379 endif
3380<
3381 When using bracketed paste only the first character is
3382 returned, the rest of the pasted text is dropped.
3383 |xterm-bracketed-paste|.
3384
3385 There is no prompt, you will somehow have to make clear to the
3386 user that a character has to be typed. The screen is not
3387 redrawn, e.g. when resizing the window. When using a popup
3388 window it should work better with a |popup-filter|.
3389
3390 There is no mapping for the character.
3391 Key codes are replaced, thus when the user presses the <Del>
3392 key you get the code for the <Del> key, not the raw character
3393 sequence. Examples: >
3394 getchar() == "\<Del>"
3395 getchar() == "\<S-Left>"
3396< This example redefines "f" to ignore case: >
3397 :nmap f :call FindChar()<CR>
3398 :function FindChar()
3399 : let c = nr2char(getchar())
3400 : while col('.') < col('$') - 1
3401 : normal l
3402 : if getline('.')[col('.') - 1] ==? c
3403 : break
3404 : endif
3405 : endwhile
3406 :endfunction
3407<
3408 You may also receive synthetic characters, such as
3409 |<CursorHold>|. Often you will want to ignore this and get
3410 another character: >
3411 :function GetKey()
3412 : let c = getchar()
3413 : while c == "\<CursorHold>"
3414 : let c = getchar()
3415 : endwhile
3416 : return c
3417 :endfunction
3418
3419getcharmod() *getcharmod()*
3420 The result is a Number which is the state of the modifiers for
3421 the last obtained character with getchar() or in another way.
3422 These values are added together:
3423 2 shift
3424 4 control
3425 8 alt (meta)
3426 16 meta (when it's different from ALT)
3427 32 mouse double click
3428 64 mouse triple click
3429 96 mouse quadruple click (== 32 + 64)
3430 128 command (Macintosh only)
3431 Only the modifiers that have not been included in the
3432 character itself are obtained. Thus Shift-a results in "A"
Bram Moolenaar016188f2022-06-06 20:52:59 +01003433 without a modifier. Returns 0 if no modifiers are used.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003434
3435 *getcharpos()*
3436getcharpos({expr})
3437 Get the position for String {expr}. Same as |getpos()| but the
3438 column number in the returned List is a character index
3439 instead of a byte index.
naohiro ono56200ee2022-01-01 14:59:44 +00003440 If |getpos()| returns a very large column number, equal to
3441 |v:maxcol|, then getcharpos() will return the character index
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003442 of the last character.
3443
3444 Example:
3445 With the cursor on '세' in line 5 with text "여보세요": >
3446 getcharpos('.') returns [0, 5, 3, 0]
3447 getpos('.') returns [0, 5, 7, 0]
3448<
3449 Can also be used as a |method|: >
3450 GetMark()->getcharpos()
3451
3452getcharsearch() *getcharsearch()*
3453 Return the current character search information as a {dict}
3454 with the following entries:
3455
3456 char character previously used for a character
3457 search (|t|, |f|, |T|, or |F|); empty string
3458 if no character search has been performed
3459 forward direction of character search; 1 for forward,
3460 0 for backward
3461 until type of character search; 1 for a |t| or |T|
3462 character search, 0 for an |f| or |F|
3463 character search
3464
3465 This can be useful to always have |;| and |,| search
3466 forward/backward regardless of the direction of the previous
3467 character search: >
3468 :nnoremap <expr> ; getcharsearch().forward ? ';' : ','
3469 :nnoremap <expr> , getcharsearch().forward ? ',' : ';'
3470< Also see |setcharsearch()|.
3471
3472
3473getcharstr([expr]) *getcharstr()*
3474 Get a single character from the user or input stream as a
3475 string.
3476 If [expr] is omitted, wait until a character is available.
3477 If [expr] is 0 or false, only get a character when one is
3478 available. Return an empty string otherwise.
3479 If [expr] is 1 or true, only check if a character is
3480 available, it is not consumed. Return an empty string
3481 if no character is available.
3482 Otherwise this works like |getchar()|, except that a number
3483 result is converted to a string.
3484
Shougo Matsushita79d599b2022-05-07 12:48:29 +01003485getcmdcompltype() *getcmdcompltype()*
3486 Return the type of the current command-line completion.
3487 Only works when the command line is being edited, thus
3488 requires use of |c_CTRL-\_e| or |c_CTRL-R_=|.
Bram Moolenaar921bde82022-05-09 19:50:35 +01003489 See |:command-completion| for the return string.
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01003490 Also see |getcmdtype()|, |setcmdpos()|, |getcmdline()| and
3491 |setcmdline()|.
Shougo Matsushita79d599b2022-05-07 12:48:29 +01003492 Returns an empty string when completion is not defined.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003493
3494getcmdline() *getcmdline()*
3495 Return the current command-line. Only works when the command
3496 line is being edited, thus requires use of |c_CTRL-\_e| or
3497 |c_CTRL-R_=|.
3498 Example: >
3499 :cmap <F7> <C-\>eescape(getcmdline(), ' \')<CR>
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01003500< Also see |getcmdtype()|, |getcmdpos()|, |setcmdpos()| and
3501 |setcmdline()|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003502 Returns an empty string when entering a password or using
3503 |inputsecret()|.
3504
3505getcmdpos() *getcmdpos()*
3506 Return the position of the cursor in the command line as a
3507 byte count. The first column is 1.
3508 Only works when editing the command line, thus requires use of
3509 |c_CTRL-\_e| or |c_CTRL-R_=| or an expression mapping.
3510 Returns 0 otherwise.
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01003511 Also see |getcmdtype()|, |setcmdpos()|, |getcmdline()| and
3512 |setcmdline()|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003513
Shougo Matsushita79d599b2022-05-07 12:48:29 +01003514getcmdscreenpos() *getcmdscreenpos()*
3515 Return the screen position of the cursor in the command line
3516 as a byte count. The first column is 1.
3517 Instead of |getcmdpos()|, it adds the prompt position.
3518 Only works when editing the command line, thus requires use of
3519 |c_CTRL-\_e| or |c_CTRL-R_=| or an expression mapping.
3520 Returns 0 otherwise.
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01003521 Also see |getcmdpos()|, |setcmdpos()|, |getcmdline()| and
3522 |setcmdline()|.
Shougo Matsushita79d599b2022-05-07 12:48:29 +01003523
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003524getcmdtype() *getcmdtype()*
3525 Return the current command-line type. Possible return values
3526 are:
3527 : normal Ex command
3528 > debug mode command |debug-mode|
3529 / forward search command
3530 ? backward search command
3531 @ |input()| command
3532 - |:insert| or |:append| command
3533 = |i_CTRL-R_=|
3534 Only works when editing the command line, thus requires use of
3535 |c_CTRL-\_e| or |c_CTRL-R_=| or an expression mapping.
3536 Returns an empty string otherwise.
3537 Also see |getcmdpos()|, |setcmdpos()| and |getcmdline()|.
3538
3539getcmdwintype() *getcmdwintype()*
3540 Return the current |command-line-window| type. Possible return
3541 values are the same as |getcmdtype()|. Returns an empty string
3542 when not in the command-line window.
3543
3544getcompletion({pat}, {type} [, {filtered}]) *getcompletion()*
3545 Return a list of command-line completion matches. The String
3546 {type} argument specifies what for. The following completion
3547 types are supported:
3548
3549 arglist file names in argument list
3550 augroup autocmd groups
3551 buffer buffer names
Bram Moolenaar6e2e2cc2022-03-14 19:24:46 +00003552 behave |:behave| suboptions
3553 breakpoint |:breakadd| and |:breakdel| suboptions
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003554 color color schemes
3555 command Ex command
3556 cmdline |cmdline-completion| result
3557 compiler compilers
3558 cscope |:cscope| suboptions
Shougo Matsushita92997dd2023-08-20 20:55:55 +02003559 custom,{func} custom completion, defined via {func}
3560 customlist,{func} custom completion, defined via {func}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003561 diff_buffer |:diffget| and |:diffput| completion
3562 dir directory names
3563 environment environment variable names
3564 event autocommand events
3565 expression Vim expression
3566 file file and directory names
3567 file_in_path file and directory names in |'path'|
3568 filetype filetype names |'filetype'|
3569 function function name
3570 help help subjects
3571 highlight highlight groups
Bram Moolenaar6e2e2cc2022-03-14 19:24:46 +00003572 history |:history| suboptions
Doug Kearns81642d92024-01-04 22:37:44 +01003573 keymap keyboard mappings
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003574 locale locale names (as output of locale -a)
3575 mapclear buffer argument
3576 mapping mapping name
3577 menu menus
3578 messages |:messages| suboptions
3579 option options
3580 packadd optional package |pack-add| names
zeertzjq5c8771b2023-01-24 12:34:03 +00003581 runtime |:runtime| completion
Yegappan Lakshmanan454ce672022-03-24 11:22:13 +00003582 scriptnames sourced script names |:scriptnames|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003583 shellcmd Shell command
3584 sign |:sign| suboptions
3585 syntax syntax file names |'syntax'|
3586 syntime |:syntime| suboptions
3587 tag tags
3588 tag_listfiles tags, file names
3589 user user names
3590 var user variables
3591
3592 If {pat} is an empty string, then all the matches are
3593 returned. Otherwise only items matching {pat} are returned.
3594 See |wildcards| for the use of special characters in {pat}.
3595
3596 If the optional {filtered} flag is set to 1, then 'wildignore'
3597 is applied to filter the results. Otherwise all the matches
3598 are returned. The 'wildignorecase' option always applies.
3599
Yegappan Lakshmanane7dd0fa2022-03-22 16:06:31 +00003600 If the 'wildoptions' option contains 'fuzzy', then fuzzy
3601 matching is used to get the completion matches. Otherwise
Yegappan Lakshmanan454ce672022-03-24 11:22:13 +00003602 regular expression matching is used. Thus this function
3603 follows the user preference, what happens on the command line.
3604 If you do not want this you can make 'wildoptions' empty
3605 before calling getcompletion() and restore it afterwards.
Yegappan Lakshmanane7dd0fa2022-03-22 16:06:31 +00003606
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003607 If {type} is "cmdline", then the |cmdline-completion| result is
3608 returned. For example, to complete the possible values after
3609 a ":call" command: >
3610 echo getcompletion('call ', 'cmdline')
3611<
3612 If there are no matches, an empty list is returned. An
3613 invalid value for {type} produces an error.
3614
3615 Can also be used as a |method|: >
3616 GetPattern()->getcompletion('color')
3617<
3618 *getcurpos()*
3619getcurpos([{winid}])
3620 Get the position of the cursor. This is like getpos('.'), but
3621 includes an extra "curswant" item in the list:
3622 [0, lnum, col, off, curswant] ~
3623 The "curswant" number is the preferred column when moving the
naohiro ono56200ee2022-01-01 14:59:44 +00003624 cursor vertically. After |$| command it will be a very large
3625 number equal to |v:maxcol|. Also see |getcursorcharpos()| and
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003626 |getpos()|.
3627 The first "bufnum" item is always zero. The byte position of
3628 the cursor is returned in 'col'. To get the character
3629 position, use |getcursorcharpos()|.
3630
3631 The optional {winid} argument can specify the window. It can
3632 be the window number or the |window-ID|. The last known
3633 cursor position is returned, this may be invalid for the
3634 current value of the buffer if it is not the current window.
3635 If {winid} is invalid a list with zeroes is returned.
3636
3637 This can be used to save and restore the cursor position: >
3638 let save_cursor = getcurpos()
3639 MoveTheCursorAround
3640 call setpos('.', save_cursor)
3641< Note that this only works within the window. See
3642 |winrestview()| for restoring more state.
3643
3644 Can also be used as a |method|: >
3645 GetWinid()->getcurpos()
3646<
3647 *getcursorcharpos()*
3648getcursorcharpos([{winid}])
3649 Same as |getcurpos()| but the column number in the returned
3650 List is a character index instead of a byte index.
3651
3652 Example:
3653 With the cursor on '보' in line 3 with text "여보세요": >
3654 getcursorcharpos() returns [0, 3, 2, 0, 3]
3655 getcurpos() returns [0, 3, 4, 0, 3]
3656<
3657 Can also be used as a |method|: >
3658 GetWinid()->getcursorcharpos()
3659
3660< *getcwd()*
3661getcwd([{winnr} [, {tabnr}]])
3662 The result is a String, which is the name of the current
3663 working directory. 'autochdir' is ignored.
3664
3665 With {winnr} return the local current directory of this window
3666 in the current tab page. {winnr} can be the window number or
3667 the |window-ID|.
3668 If {winnr} is -1 return the name of the global working
3669 directory. See also |haslocaldir()|.
3670
3671 With {winnr} and {tabnr} return the local current directory of
3672 the window in the specified tab page. If {winnr} is -1 return
3673 the working directory of the tabpage.
3674 If {winnr} is zero use the current window, if {tabnr} is zero
3675 use the current tabpage.
3676 Without any arguments, return the actual working directory of
3677 the current window.
3678 Return an empty string if the arguments are invalid.
3679
3680 Examples: >
3681 " Get the working directory of the current window
3682 :echo getcwd()
3683 :echo getcwd(0)
3684 :echo getcwd(0, 0)
3685 " Get the working directory of window 3 in tabpage 2
3686 :echo getcwd(3, 2)
3687 " Get the global working directory
3688 :echo getcwd(-1)
3689 " Get the working directory of tabpage 3
3690 :echo getcwd(-1, 3)
3691 " Get the working directory of current tabpage
3692 :echo getcwd(-1, 0)
3693
3694< Can also be used as a |method|: >
3695 GetWinnr()->getcwd()
3696
3697getenv({name}) *getenv()*
3698 Return the value of environment variable {name}. The {name}
3699 argument is a string, without a leading '$'. Example: >
3700 myHome = getenv('HOME')
3701
3702< When the variable does not exist |v:null| is returned. That
3703 is different from a variable set to an empty string, although
3704 some systems interpret the empty value as the variable being
3705 deleted. See also |expr-env|.
3706
3707 Can also be used as a |method|: >
3708 GetVarname()->getenv()
3709
3710getfontname([{name}]) *getfontname()*
3711 Without an argument returns the name of the normal font being
3712 used. Like what is used for the Normal highlight group
3713 |hl-Normal|.
3714 With an argument a check is done whether String {name} is a
3715 valid font name. If not then an empty string is returned.
3716 Otherwise the actual font name is returned, or {name} if the
3717 GUI does not support obtaining the real name.
3718 Only works when the GUI is running, thus not in your vimrc or
3719 gvimrc file. Use the |GUIEnter| autocommand to use this
3720 function just after the GUI has started.
3721 Note that the GTK GUI accepts any font name, thus checking for
3722 a valid name does not work.
3723
3724getfperm({fname}) *getfperm()*
3725 The result is a String, which is the read, write, and execute
3726 permissions of the given file {fname}.
3727 If {fname} does not exist or its directory cannot be read, an
3728 empty string is returned.
3729 The result is of the form "rwxrwxrwx", where each group of
3730 "rwx" flags represent, in turn, the permissions of the owner
3731 of the file, the group the file belongs to, and other users.
3732 If a user does not have a given permission the flag for this
3733 is replaced with the string "-". Examples: >
3734 :echo getfperm("/etc/passwd")
3735 :echo getfperm(expand("~/.vimrc"))
3736< This will hopefully (from a security point of view) display
3737 the string "rw-r--r--" or even "rw-------".
3738
3739 Can also be used as a |method|: >
3740 GetFilename()->getfperm()
3741<
3742 For setting permissions use |setfperm()|.
3743
3744getfsize({fname}) *getfsize()*
3745 The result is a Number, which is the size in bytes of the
3746 given file {fname}.
3747 If {fname} is a directory, 0 is returned.
3748 If the file {fname} can't be found, -1 is returned.
3749 If the size of {fname} is too big to fit in a Number then -2
3750 is returned.
3751
3752 Can also be used as a |method|: >
3753 GetFilename()->getfsize()
3754
3755getftime({fname}) *getftime()*
3756 The result is a Number, which is the last modification time of
3757 the given file {fname}. The value is measured as seconds
3758 since 1st Jan 1970, and may be passed to strftime(). See also
3759 |localtime()| and |strftime()|.
3760 If the file {fname} can't be found -1 is returned.
3761
3762 Can also be used as a |method|: >
3763 GetFilename()->getftime()
3764
3765getftype({fname}) *getftype()*
3766 The result is a String, which is a description of the kind of
3767 file of the given file {fname}.
3768 If {fname} does not exist an empty string is returned.
3769 Here is a table over different kinds of files and their
3770 results:
3771 Normal file "file"
3772 Directory "dir"
3773 Symbolic link "link"
3774 Block device "bdev"
3775 Character device "cdev"
3776 Socket "socket"
3777 FIFO "fifo"
3778 All other "other"
3779 Example: >
3780 getftype("/home")
3781< Note that a type such as "link" will only be returned on
3782 systems that support it. On some systems only "dir" and
3783 "file" are returned. On MS-Windows a symbolic link to a
3784 directory returns "dir" instead of "link".
3785
3786 Can also be used as a |method|: >
3787 GetFilename()->getftype()
3788
3789getimstatus() *getimstatus()*
3790 The result is a Number, which is |TRUE| when the IME status is
Bram Moolenaar016188f2022-06-06 20:52:59 +01003791 active and |FALSE| otherwise.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003792 See 'imstatusfunc'.
3793
3794getjumplist([{winnr} [, {tabnr}]]) *getjumplist()*
3795 Returns the |jumplist| for the specified window.
3796
3797 Without arguments use the current window.
3798 With {winnr} only use this window in the current tab page.
3799 {winnr} can also be a |window-ID|.
3800 With {winnr} and {tabnr} use the window in the specified tab
Bram Moolenaar016188f2022-06-06 20:52:59 +01003801 page. If {winnr} or {tabnr} is invalid, an empty list is
3802 returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003803
3804 The returned list contains two entries: a list with the jump
3805 locations and the last used jump position number in the list.
3806 Each entry in the jump location list is a dictionary with
3807 the following entries:
3808 bufnr buffer number
3809 col column number
3810 coladd column offset for 'virtualedit'
3811 filename filename if available
3812 lnum line number
3813
3814 Can also be used as a |method|: >
3815 GetWinnr()->getjumplist()
3816
3817< *getline()*
3818getline({lnum} [, {end}])
3819 Without {end} the result is a String, which is line {lnum}
3820 from the current buffer. Example: >
3821 getline(1)
3822< When {lnum} is a String that doesn't start with a
3823 digit, |line()| is called to translate the String into a Number.
3824 To get the line under the cursor: >
3825 getline(".")
3826< When {lnum} is a number smaller than 1 or bigger than the
3827 number of lines in the buffer, an empty string is returned.
3828
3829 When {end} is given the result is a |List| where each item is
3830 a line from the current buffer in the range {lnum} to {end},
3831 including line {end}.
3832 {end} is used in the same way as {lnum}.
3833 Non-existing lines are silently omitted.
3834 When {end} is before {lnum} an empty |List| is returned.
3835 Example: >
3836 :let start = line('.')
3837 :let end = search("^$") - 1
3838 :let lines = getline(start, end)
3839
3840< Can also be used as a |method|: >
3841 ComputeLnum()->getline()
3842
Bram Moolenaarce30ccc2022-11-21 19:57:04 +00003843< To get lines from another buffer see |getbufline()| and
3844 |getbufoneline()|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003845
3846getloclist({nr} [, {what}]) *getloclist()*
3847 Returns a |List| with all the entries in the location list for
3848 window {nr}. {nr} can be the window number or the |window-ID|.
3849 When {nr} is zero the current window is used.
3850
3851 For a location list window, the displayed location list is
3852 returned. For an invalid window number {nr}, an empty list is
3853 returned. Otherwise, same as |getqflist()|.
3854
3855 If the optional {what} dictionary argument is supplied, then
3856 returns the items listed in {what} as a dictionary. Refer to
3857 |getqflist()| for the supported items in {what}.
3858
3859 In addition to the items supported by |getqflist()| in {what},
3860 the following item is supported by |getloclist()|:
3861
3862 filewinid id of the window used to display files
3863 from the location list. This field is
3864 applicable only when called from a
3865 location list window. See
3866 |location-list-file-window| for more
3867 details.
3868
3869 Returns a |Dictionary| with default values if there is no
3870 location list for the window {nr}.
3871 Returns an empty Dictionary if window {nr} does not exist.
3872
3873 Examples (See also |getqflist-examples|): >
3874 :echo getloclist(3, {'all': 0})
3875 :echo getloclist(5, {'filewinid': 0})
3876
3877
3878getmarklist([{buf}]) *getmarklist()*
3879 Without the {buf} argument returns a |List| with information
3880 about all the global marks. |mark|
3881
3882 If the optional {buf} argument is specified, returns the
3883 local marks defined in buffer {buf}. For the use of {buf},
Bram Moolenaar016188f2022-06-06 20:52:59 +01003884 see |bufname()|. If {buf} is invalid, an empty list is
3885 returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003886
3887 Each item in the returned List is a |Dict| with the following:
3888 mark name of the mark prefixed by "'"
3889 pos a |List| with the position of the mark:
3890 [bufnum, lnum, col, off]
3891 Refer to |getpos()| for more information.
3892 file file name
3893
3894 Refer to |getpos()| for getting information about a specific
3895 mark.
3896
3897 Can also be used as a |method|: >
3898 GetBufnr()->getmarklist()
3899
3900getmatches([{win}]) *getmatches()*
3901 Returns a |List| with all matches previously defined for the
3902 current window by |matchadd()| and the |:match| commands.
3903 |getmatches()| is useful in combination with |setmatches()|,
3904 as |setmatches()| can restore a list of matches saved by
3905 |getmatches()|.
3906 If {win} is specified, use the window with this number or
Bram Moolenaar016188f2022-06-06 20:52:59 +01003907 window ID instead of the current window. If {win} is invalid,
3908 an empty list is returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003909 Example: >
3910 :echo getmatches()
3911< [{'group': 'MyGroup1', 'pattern': 'TODO',
3912 'priority': 10, 'id': 1}, {'group': 'MyGroup2',
3913 'pattern': 'FIXME', 'priority': 10, 'id': 2}] >
3914 :let m = getmatches()
3915 :call clearmatches()
3916 :echo getmatches()
3917< [] >
3918 :call setmatches(m)
3919 :echo getmatches()
3920< [{'group': 'MyGroup1', 'pattern': 'TODO',
3921 'priority': 10, 'id': 1}, {'group': 'MyGroup2',
3922 'pattern': 'FIXME', 'priority': 10, 'id': 2}] >
3923 :unlet m
3924<
3925getmousepos() *getmousepos()*
3926 Returns a |Dictionary| with the last known position of the
3927 mouse. This can be used in a mapping for a mouse click or in
3928 a filter of a popup window. The items are:
3929 screenrow screen row
3930 screencol screen column
3931 winid Window ID of the click
3932 winrow row inside "winid"
3933 wincol column inside "winid"
3934 line text line inside "winid"
3935 column text column inside "winid"
zeertzjqf5a94d52023-10-15 10:03:30 +02003936 coladd offset (in screen columns) from the
3937 start of the clicked char
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003938 All numbers are 1-based.
3939
3940 If not over a window, e.g. when in the command line, then only
3941 "screenrow" and "screencol" are valid, the others are zero.
3942
3943 When on the status line below a window or the vertical
3944 separator right of a window, the "line" and "column" values
3945 are zero.
3946
3947 When the position is after the text then "column" is the
3948 length of the text in bytes plus one.
3949
3950 If the mouse is over a popup window then that window is used.
3951
3952 When using |getchar()| the Vim variables |v:mouse_lnum|,
3953 |v:mouse_col| and |v:mouse_winid| also provide these values.
3954
Bram Moolenaar24dc19c2022-11-14 19:49:15 +00003955getmouseshape() *getmouseshape()*
3956 Returns the name of the currently showing mouse pointer.
3957 When the |+mouseshape| feature is not supported or the shape
3958 is unknown an empty string is returned.
3959 This function is mainly intended for testing.
3960
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003961 *getpid()*
3962getpid() Return a Number which is the process ID of the Vim process.
3963 On Unix and MS-Windows this is a unique number, until Vim
3964 exits.
3965
3966 *getpos()*
3967getpos({expr}) Get the position for String {expr}. For possible values of
3968 {expr} see |line()|. For getting the cursor position see
3969 |getcurpos()|.
3970 The result is a |List| with four numbers:
3971 [bufnum, lnum, col, off]
3972 "bufnum" is zero, unless a mark like '0 or 'A is used, then it
3973 is the buffer number of the mark.
3974 "lnum" and "col" are the position in the buffer. The first
3975 column is 1.
3976 The "off" number is zero, unless 'virtualedit' is used. Then
3977 it is the offset in screen columns from the start of the
3978 character. E.g., a position within a <Tab> or after the last
3979 character.
3980 Note that for '< and '> Visual mode matters: when it is "V"
3981 (visual line mode) the column of '< is zero and the column of
naohiro ono56200ee2022-01-01 14:59:44 +00003982 '> is a large number equal to |v:maxcol|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003983 The column number in the returned List is the byte position
3984 within the line. To get the character position in the line,
3985 use |getcharpos()|.
naohiro ono56200ee2022-01-01 14:59:44 +00003986 A very large column number equal to |v:maxcol| can be returned,
3987 in which case it means "after the end of the line".
Bram Moolenaar016188f2022-06-06 20:52:59 +01003988 If {expr} is invalid, returns a list with all zeros.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003989 This can be used to save and restore the position of a mark: >
3990 let save_a_mark = getpos("'a")
3991 ...
3992 call setpos("'a", save_a_mark)
3993< Also see |getcharpos()|, |getcurpos()| and |setpos()|.
3994
3995 Can also be used as a |method|: >
3996 GetMark()->getpos()
3997
3998getqflist([{what}]) *getqflist()*
3999 Returns a |List| with all the current quickfix errors. Each
4000 list item is a dictionary with these entries:
4001 bufnr number of buffer that has the file name, use
4002 bufname() to get the name
4003 module module name
4004 lnum line number in the buffer (first line is 1)
4005 end_lnum
4006 end of line number if the item is multiline
4007 col column number (first column is 1)
4008 end_col end of column number if the item has range
4009 vcol |TRUE|: "col" is visual column
4010 |FALSE|: "col" is byte index
4011 nr error number
4012 pattern search pattern used to locate the error
4013 text description of the error
4014 type type of the error, 'E', '1', etc.
4015 valid |TRUE|: recognized error message
h_east596a9f22023-11-21 21:24:23 +09004016 user_data
4017 custom data associated with the item, can be
Tom Praschanca6ac992023-08-11 23:26:12 +02004018 any type.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004019
4020 When there is no error list or it's empty, an empty list is
4021 returned. Quickfix list entries with a non-existing buffer
4022 number are returned with "bufnr" set to zero (Note: some
4023 functions accept buffer number zero for the alternate buffer,
4024 you may need to explicitly check for zero).
4025
4026 Useful application: Find pattern matches in multiple files and
4027 do something with them: >
4028 :vimgrep /theword/jg *.c
4029 :for d in getqflist()
4030 : echo bufname(d.bufnr) ':' d.lnum '=' d.text
4031 :endfor
4032<
4033 If the optional {what} dictionary argument is supplied, then
4034 returns only the items listed in {what} as a dictionary. The
4035 following string items are supported in {what}:
4036 changedtick get the total number of changes made
4037 to the list |quickfix-changedtick|
4038 context get the |quickfix-context|
4039 efm errorformat to use when parsing "lines". If
4040 not present, then the 'errorformat' option
4041 value is used.
4042 id get information for the quickfix list with
4043 |quickfix-ID|; zero means the id for the
4044 current list or the list specified by "nr"
4045 idx get information for the quickfix entry at this
4046 index in the list specified by 'id' or 'nr'.
4047 If set to zero, then uses the current entry.
4048 See |quickfix-index|
4049 items quickfix list entries
4050 lines parse a list of lines using 'efm' and return
4051 the resulting entries. Only a |List| type is
4052 accepted. The current quickfix list is not
4053 modified. See |quickfix-parse|.
4054 nr get information for this quickfix list; zero
4055 means the current quickfix list and "$" means
4056 the last quickfix list
4057 qfbufnr number of the buffer displayed in the quickfix
4058 window. Returns 0 if the quickfix buffer is
4059 not present. See |quickfix-buffer|.
4060 size number of entries in the quickfix list
4061 title get the list title |quickfix-title|
4062 winid get the quickfix |window-ID|
4063 all all of the above quickfix properties
4064 Non-string items in {what} are ignored. To get the value of a
4065 particular item, set it to zero.
4066 If "nr" is not present then the current quickfix list is used.
4067 If both "nr" and a non-zero "id" are specified, then the list
4068 specified by "id" is used.
4069 To get the number of lists in the quickfix stack, set "nr" to
4070 "$" in {what}. The "nr" value in the returned dictionary
4071 contains the quickfix stack size.
4072 When "lines" is specified, all the other items except "efm"
4073 are ignored. The returned dictionary contains the entry
4074 "items" with the list of entries.
4075
4076 The returned dictionary contains the following entries:
4077 changedtick total number of changes made to the
4078 list |quickfix-changedtick|
4079 context quickfix list context. See |quickfix-context|
4080 If not present, set to "".
4081 id quickfix list ID |quickfix-ID|. If not
4082 present, set to 0.
4083 idx index of the quickfix entry in the list. If not
4084 present, set to 0.
4085 items quickfix list entries. If not present, set to
4086 an empty list.
4087 nr quickfix list number. If not present, set to 0
4088 qfbufnr number of the buffer displayed in the quickfix
4089 window. If not present, set to 0.
4090 size number of entries in the quickfix list. If not
4091 present, set to 0.
4092 title quickfix list title text. If not present, set
4093 to "".
4094 winid quickfix |window-ID|. If not present, set to 0
4095
4096 Examples (See also |getqflist-examples|): >
4097 :echo getqflist({'all': 1})
4098 :echo getqflist({'nr': 2, 'title': 1})
4099 :echo getqflist({'lines' : ["F1:10:L10"]})
4100<
4101getreg([{regname} [, 1 [, {list}]]]) *getreg()*
4102 The result is a String, which is the contents of register
4103 {regname}. Example: >
4104 :let cliptext = getreg('*')
4105< When register {regname} was not set the result is an empty
4106 string.
Bram Moolenaara2baa732022-02-04 16:09:54 +00004107 The {regname} argument must be a string. *E1162*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004108
4109 getreg('=') returns the last evaluated value of the expression
4110 register. (For use in maps.)
4111 getreg('=', 1) returns the expression itself, so that it can
4112 be restored with |setreg()|. For other registers the extra
4113 argument is ignored, thus you can always give it.
4114
4115 If {list} is present and |TRUE|, the result type is changed
4116 to |List|. Each list item is one text line. Use it if you care
4117 about zero bytes possibly present inside register: without
4118 third argument both NLs and zero bytes are represented as NLs
4119 (see |NL-used-for-Nul|).
4120 When the register was not set an empty list is returned.
4121
4122 If {regname} is "", the unnamed register '"' is used.
4123 If {regname} is not specified, |v:register| is used.
4124 In |Vim9-script| {regname} must be one character.
4125
4126 Can also be used as a |method|: >
4127 GetRegname()->getreg()
4128
4129getreginfo([{regname}]) *getreginfo()*
4130 Returns detailed information about register {regname} as a
4131 Dictionary with the following entries:
4132 regcontents List of lines contained in register
4133 {regname}, like
4134 |getreg|({regname}, 1, 1).
4135 regtype the type of register {regname}, as in
4136 |getregtype()|.
4137 isunnamed Boolean flag, v:true if this register
4138 is currently pointed to by the unnamed
4139 register.
4140 points_to for the unnamed register, gives the
4141 single letter name of the register
4142 currently pointed to (see |quotequote|).
4143 For example, after deleting a line
4144 with `dd`, this field will be "1",
4145 which is the register that got the
4146 deleted text.
4147
4148 The {regname} argument is a string. If {regname} is invalid
4149 or not set, an empty Dictionary will be returned.
4150 If {regname} is "" or "@", the unnamed register '"' is used.
4151 If {regname} is not specified, |v:register| is used.
4152 The returned Dictionary can be passed to |setreg()|.
4153 In |Vim9-script| {regname} must be one character.
4154
4155 Can also be used as a |method|: >
4156 GetRegname()->getreginfo()
4157
4158getregtype([{regname}]) *getregtype()*
4159 The result is a String, which is type of register {regname}.
4160 The value will be one of:
4161 "v" for |characterwise| text
4162 "V" for |linewise| text
4163 "<CTRL-V>{width}" for |blockwise-visual| text
4164 "" for an empty or unknown register
4165 <CTRL-V> is one character with value 0x16.
4166 The {regname} argument is a string. If {regname} is "", the
4167 unnamed register '"' is used. If {regname} is not specified,
4168 |v:register| is used.
4169 In |Vim9-script| {regname} must be one character.
4170
4171 Can also be used as a |method|: >
4172 GetRegname()->getregtype()
4173
Bram Moolenaar71badf92023-04-22 22:40:14 +01004174getscriptinfo([{opts}]) *getscriptinfo()*
Yegappan Lakshmananf768c3d2022-08-22 13:15:13 +01004175 Returns a |List| with information about all the sourced Vim
Bram Moolenaar753885b2022-08-24 16:30:36 +01004176 scripts in the order they were sourced, like what
4177 `:scriptnames` shows.
Yegappan Lakshmananf768c3d2022-08-22 13:15:13 +01004178
Yegappan Lakshmanan2f892d82022-08-28 18:52:10 +01004179 The optional Dict argument {opts} supports the following
4180 optional items:
4181 name Script name match pattern. If specified,
4182 and "sid" is not specified, information about
Bram Moolenaar71badf92023-04-22 22:40:14 +01004183 scripts with a name that match the pattern
Yegappan Lakshmanan2f892d82022-08-28 18:52:10 +01004184 "name" are returned.
4185 sid Script ID |<SID>|. If specified, only
4186 information about the script with ID "sid" is
4187 returned and "name" is ignored.
4188
Yegappan Lakshmananf768c3d2022-08-22 13:15:13 +01004189 Each item in the returned List is a |Dict| with the following
4190 items:
Yegappan Lakshmanan2f892d82022-08-28 18:52:10 +01004191 autoload Set to TRUE for a script that was used with
Bram Moolenaar753885b2022-08-24 16:30:36 +01004192 `import autoload` but was not actually sourced
4193 yet (see |import-autoload|).
Yegappan Lakshmanan2f892d82022-08-28 18:52:10 +01004194 functions List of script-local function names defined in
4195 the script. Present only when a particular
4196 script is specified using the "sid" item in
4197 {opts}.
4198 name Vim script file name.
4199 sid Script ID |<SID>|.
4200 sourced Script ID of the actually sourced script that
Bram Moolenaarfd999452022-08-24 18:30:14 +01004201 this script name links to, if any, otherwise
4202 zero
Yegappan Lakshmanan2f892d82022-08-28 18:52:10 +01004203 variables A dictionary with the script-local variables.
Bram Moolenaarf1dcd142022-12-31 15:30:45 +00004204 Present only when a particular script is
Yegappan Lakshmanan2f892d82022-08-28 18:52:10 +01004205 specified using the "sid" item in {opts}.
4206 Note that this is a copy, the value of
4207 script-local variables cannot be changed using
4208 this dictionary.
h_east59858792023-10-25 22:47:05 +09004209 version Vim script version (|scriptversion|)
Yegappan Lakshmanan520f6ef2022-08-25 17:40:40 +01004210
Yegappan Lakshmanan2f892d82022-08-28 18:52:10 +01004211 Examples: >
4212 :echo getscriptinfo({'name': 'myscript'})
4213 :echo getscriptinfo({'sid': 15}).variables
4214<
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004215gettabinfo([{tabnr}]) *gettabinfo()*
4216 If {tabnr} is not specified, then information about all the
4217 tab pages is returned as a |List|. Each List item is a
4218 |Dictionary|. Otherwise, {tabnr} specifies the tab page
4219 number and information about that one is returned. If the tab
4220 page does not exist an empty List is returned.
4221
4222 Each List item is a |Dictionary| with the following entries:
4223 tabnr tab page number.
4224 variables a reference to the dictionary with
4225 tabpage-local variables
4226 windows List of |window-ID|s in the tab page.
4227
4228 Can also be used as a |method|: >
4229 GetTabnr()->gettabinfo()
4230
4231gettabvar({tabnr}, {varname} [, {def}]) *gettabvar()*
4232 Get the value of a tab-local variable {varname} in tab page
4233 {tabnr}. |t:var|
4234 Tabs are numbered starting with one.
4235 The {varname} argument is a string. When {varname} is empty a
4236 dictionary with all tab-local variables is returned.
4237 Note that the name without "t:" must be used.
4238 When the tab or variable doesn't exist {def} or an empty
4239 string is returned, there is no error message.
4240
4241 Can also be used as a |method|: >
4242 GetTabnr()->gettabvar(varname)
4243
4244gettabwinvar({tabnr}, {winnr}, {varname} [, {def}]) *gettabwinvar()*
4245 Get the value of window-local variable {varname} in window
4246 {winnr} in tab page {tabnr}.
4247 The {varname} argument is a string. When {varname} is empty a
4248 dictionary with all window-local variables is returned.
4249 When {varname} is equal to "&" get the values of all
4250 window-local options in a |Dictionary|.
4251 Otherwise, when {varname} starts with "&" get the value of a
4252 window-local option.
4253 Note that {varname} must be the name without "w:".
4254 Tabs are numbered starting with one. For the current tabpage
4255 use |getwinvar()|.
4256 {winnr} can be the window number or the |window-ID|.
4257 When {winnr} is zero the current window is used.
4258 This also works for a global option, buffer-local option and
4259 window-local option, but it doesn't work for a global variable
4260 or buffer-local variable.
4261 When the tab, window or variable doesn't exist {def} or an
4262 empty string is returned, there is no error message.
4263 Examples: >
4264 :let list_is_on = gettabwinvar(1, 2, '&list')
Bram Moolenaarc51cf032022-02-26 12:25:45 +00004265 :echo "myvar = " .. gettabwinvar(3, 1, 'myvar')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004266<
4267 To obtain all window-local variables use: >
4268 gettabwinvar({tabnr}, {winnr}, '&')
4269
4270< Can also be used as a |method|: >
4271 GetTabnr()->gettabwinvar(winnr, varname)
4272
4273gettagstack([{winnr}]) *gettagstack()*
4274 The result is a Dict, which is the tag stack of window {winnr}.
4275 {winnr} can be the window number or the |window-ID|.
4276 When {winnr} is not specified, the current window is used.
4277 When window {winnr} doesn't exist, an empty Dict is returned.
4278
4279 The returned dictionary contains the following entries:
4280 curidx Current index in the stack. When at
4281 top of the stack, set to (length + 1).
4282 Index of bottom of the stack is 1.
4283 items List of items in the stack. Each item
4284 is a dictionary containing the
4285 entries described below.
4286 length Number of entries in the stack.
4287
4288 Each item in the stack is a dictionary with the following
4289 entries:
4290 bufnr buffer number of the current jump
4291 from cursor position before the tag jump.
4292 See |getpos()| for the format of the
4293 returned list.
4294 matchnr current matching tag number. Used when
4295 multiple matching tags are found for a
4296 name.
4297 tagname name of the tag
4298
4299 See |tagstack| for more information about the tag stack.
4300
4301 Can also be used as a |method|: >
4302 GetWinnr()->gettagstack()
4303
4304
4305gettext({text}) *gettext()*
4306 Translate String {text} if possible.
4307 This is mainly for use in the distributed Vim scripts. When
4308 generating message translations the {text} is extracted by
4309 xgettext, the translator can add the translated message in the
4310 .po file and Vim will lookup the translation when gettext() is
4311 called.
4312 For {text} double quoted strings are preferred, because
4313 xgettext does not understand escaping in single quoted
4314 strings.
4315
4316
4317getwininfo([{winid}]) *getwininfo()*
4318 Returns information about windows as a |List| with Dictionaries.
4319
4320 If {winid} is given Information about the window with that ID
4321 is returned, as a |List| with one item. If the window does not
4322 exist the result is an empty list.
4323
4324 Without {winid} information about all the windows in all the
4325 tab pages is returned.
4326
4327 Each List item is a |Dictionary| with the following entries:
4328 botline last complete displayed buffer line
4329 bufnr number of buffer in the window
4330 height window height (excluding winbar)
4331 loclist 1 if showing a location list
4332 {only with the +quickfix feature}
4333 quickfix 1 if quickfix or location list window
4334 {only with the +quickfix feature}
4335 terminal 1 if a terminal window
4336 {only with the +terminal feature}
4337 tabnr tab page number
4338 topline first displayed buffer line
4339 variables a reference to the dictionary with
4340 window-local variables
4341 width window width
4342 winbar 1 if the window has a toolbar, 0
4343 otherwise
4344 wincol leftmost screen column of the window;
4345 "col" from |win_screenpos()|
4346 textoff number of columns occupied by any
4347 'foldcolumn', 'signcolumn' and line
4348 number in front of the text
4349 winid |window-ID|
4350 winnr window number
4351 winrow topmost screen line of the window;
4352 "row" from |win_screenpos()|
4353
4354 Can also be used as a |method|: >
4355 GetWinnr()->getwininfo()
4356
4357getwinpos([{timeout}]) *getwinpos()*
4358 The result is a |List| with two numbers, the result of
4359 |getwinposx()| and |getwinposy()| combined:
4360 [x-pos, y-pos]
4361 {timeout} can be used to specify how long to wait in msec for
4362 a response from the terminal. When omitted 100 msec is used.
4363 Use a longer time for a remote terminal.
4364 When using a value less than 10 and no response is received
4365 within that time, a previously reported position is returned,
4366 if available. This can be used to poll for the position and
4367 do some work in the meantime: >
4368 while 1
4369 let res = getwinpos(1)
4370 if res[0] >= 0
4371 break
4372 endif
4373 " Do some work here
4374 endwhile
4375<
4376
4377 Can also be used as a |method|: >
4378 GetTimeout()->getwinpos()
4379<
4380 *getwinposx()*
4381getwinposx() The result is a Number, which is the X coordinate in pixels of
4382 the left hand side of the GUI Vim window. Also works for an
4383 xterm (uses a timeout of 100 msec).
4384 The result will be -1 if the information is not available.
4385 The value can be used with `:winpos`.
4386
4387 *getwinposy()*
4388getwinposy() The result is a Number, which is the Y coordinate in pixels of
4389 the top of the GUI Vim window. Also works for an xterm (uses
4390 a timeout of 100 msec).
4391 The result will be -1 if the information is not available.
4392 The value can be used with `:winpos`.
4393
4394getwinvar({winnr}, {varname} [, {def}]) *getwinvar()*
4395 Like |gettabwinvar()| for the current tabpage.
4396 Examples: >
4397 :let list_is_on = getwinvar(2, '&list')
Bram Moolenaarc51cf032022-02-26 12:25:45 +00004398 :echo "myvar = " .. getwinvar(1, 'myvar')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004399
4400< Can also be used as a |method|: >
4401 GetWinnr()->getwinvar(varname)
4402<
4403glob({expr} [, {nosuf} [, {list} [, {alllinks}]]]) *glob()*
4404 Expand the file wildcards in {expr}. See |wildcards| for the
4405 use of special characters.
4406
4407 Unless the optional {nosuf} argument is given and is |TRUE|,
4408 the 'suffixes' and 'wildignore' options apply: Names matching
4409 one of the patterns in 'wildignore' will be skipped and
4410 'suffixes' affect the ordering of matches.
4411 'wildignorecase' always applies.
4412
4413 When {list} is present and it is |TRUE| the result is a |List|
4414 with all matching files. The advantage of using a List is,
4415 you also get filenames containing newlines correctly.
4416 Otherwise the result is a String and when there are several
4417 matches, they are separated by <NL> characters.
4418
4419 If the expansion fails, the result is an empty String or List.
4420
4421 You can also use |readdir()| if you need to do complicated
4422 things, such as limiting the number of matches.
4423
4424 A name for a non-existing file is not included. A symbolic
4425 link is only included if it points to an existing file.
4426 However, when the {alllinks} argument is present and it is
4427 |TRUE| then all symbolic links are included.
4428
4429 For most systems backticks can be used to get files names from
4430 any external command. Example: >
4431 :let tagfiles = glob("`find . -name tags -print`")
4432 :let &tags = substitute(tagfiles, "\n", ",", "g")
4433< The result of the program inside the backticks should be one
4434 item per line. Spaces inside an item are allowed.
4435
4436 See |expand()| for expanding special Vim variables. See
4437 |system()| for getting the raw output of an external command.
4438
4439 Can also be used as a |method|: >
4440 GetExpr()->glob()
4441
4442glob2regpat({string}) *glob2regpat()*
4443 Convert a file pattern, as used by glob(), into a search
4444 pattern. The result can be used to match with a string that
4445 is a file name. E.g. >
4446 if filename =~ glob2regpat('Make*.mak')
4447< This is equivalent to: >
4448 if filename =~ '^Make.*\.mak$'
4449< When {string} is an empty string the result is "^$", match an
4450 empty string.
4451 Note that the result depends on the system. On MS-Windows
4452 a backslash usually means a path separator.
4453
4454 Can also be used as a |method|: >
4455 GetExpr()->glob2regpat()
4456< *globpath()*
4457globpath({path}, {expr} [, {nosuf} [, {list} [, {alllinks}]]])
4458 Perform glob() for String {expr} on all directories in {path}
4459 and concatenate the results. Example: >
4460 :echo globpath(&rtp, "syntax/c.vim")
4461<
4462 {path} is a comma-separated list of directory names. Each
4463 directory name is prepended to {expr} and expanded like with
4464 |glob()|. A path separator is inserted when needed.
4465 To add a comma inside a directory name escape it with a
4466 backslash. Note that on MS-Windows a directory may have a
4467 trailing backslash, remove it if you put a comma after it.
4468 If the expansion fails for one of the directories, there is no
4469 error message.
4470
4471 Unless the optional {nosuf} argument is given and is |TRUE|,
4472 the 'suffixes' and 'wildignore' options apply: Names matching
4473 one of the patterns in 'wildignore' will be skipped and
4474 'suffixes' affect the ordering of matches.
4475
4476 When {list} is present and it is |TRUE| the result is a |List|
4477 with all matching files. The advantage of using a List is, you
4478 also get filenames containing newlines correctly. Otherwise
4479 the result is a String and when there are several matches,
4480 they are separated by <NL> characters. Example: >
4481 :echo globpath(&rtp, "syntax/c.vim", 0, 1)
4482<
4483 {alllinks} is used as with |glob()|.
4484
4485 The "**" item can be used to search in a directory tree.
4486 For example, to find all "README.txt" files in the directories
4487 in 'runtimepath' and below: >
4488 :echo globpath(&rtp, "**/README.txt")
4489< Upwards search and limiting the depth of "**" is not
4490 supported, thus using 'path' will not always work properly.
4491
4492 Can also be used as a |method|, the base is passed as the
4493 second argument: >
4494 GetExpr()->globpath(&rtp)
4495<
4496 *has()*
4497has({feature} [, {check}])
4498 When {check} is omitted or is zero: The result is a Number,
4499 which is 1 if the feature {feature} is supported, zero
4500 otherwise. The {feature} argument is a string, case is
4501 ignored. See |feature-list| below.
4502
4503 When {check} is present and not zero: The result is a Number,
4504 which is 1 if the feature {feature} could ever be supported,
4505 zero otherwise. This is useful to check for a typo in
4506 {feature} and to detect dead code. Keep in mind that an older
4507 Vim version will not know about a feature added later and
4508 features that have been abandoned will not be known by the
4509 current Vim version.
4510
4511 Also see |exists()| and |exists_compiled()|.
4512
4513 Note that to skip code that has a syntax error when the
4514 feature is not available, Vim may skip the rest of the line
4515 and miss a following `endif`. Therefore put the `endif` on a
4516 separate line: >
4517 if has('feature')
4518 let x = this->breaks->without->the->feature
4519 endif
4520< If the `endif` would be moved to the second line as "| endif" it
4521 would not be found.
4522
4523
4524has_key({dict}, {key}) *has_key()*
4525 The result is a Number, which is TRUE if |Dictionary| {dict}
Bram Moolenaare8008642022-08-19 17:15:35 +01004526 has an entry with key {key}. FALSE otherwise.
4527 The {key} argument is a string. In |Vim9| script a number is
4528 also accepted (and converted to a string) but no other types.
4529 In legacy script the usual automatic conversion to string is
4530 done.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004531
4532 Can also be used as a |method|: >
4533 mydict->has_key(key)
4534
4535haslocaldir([{winnr} [, {tabnr}]]) *haslocaldir()*
4536 The result is a Number:
4537 1 when the window has set a local directory via |:lcd|
4538 2 when the tab-page has set a local directory via |:tcd|
4539 0 otherwise.
4540
4541 Without arguments use the current window.
4542 With {winnr} use this window in the current tab page.
4543 With {winnr} and {tabnr} use the window in the specified tab
4544 page.
4545 {winnr} can be the window number or the |window-ID|.
4546 If {winnr} is -1 it is ignored and only the tabpage is used.
4547 Return 0 if the arguments are invalid.
4548 Examples: >
4549 if haslocaldir() == 1
4550 " window local directory case
4551 elseif haslocaldir() == 2
4552 " tab-local directory case
4553 else
4554 " global directory case
4555 endif
4556
4557 " current window
4558 :echo haslocaldir()
4559 :echo haslocaldir(0)
4560 :echo haslocaldir(0, 0)
4561 " window n in current tab page
4562 :echo haslocaldir(n)
4563 :echo haslocaldir(n, 0)
4564 " window n in tab page m
4565 :echo haslocaldir(n, m)
4566 " tab page m
4567 :echo haslocaldir(-1, m)
4568<
4569 Can also be used as a |method|: >
4570 GetWinnr()->haslocaldir()
4571
4572hasmapto({what} [, {mode} [, {abbr}]]) *hasmapto()*
4573 The result is a Number, which is TRUE if there is a mapping
4574 that contains {what} in somewhere in the rhs (what it is
4575 mapped to) and this mapping exists in one of the modes
4576 indicated by {mode}.
4577 The arguments {what} and {mode} are strings.
4578 When {abbr} is there and it is |TRUE| use abbreviations
4579 instead of mappings. Don't forget to specify Insert and/or
4580 Command-line mode.
4581 Both the global mappings and the mappings local to the current
4582 buffer are checked for a match.
4583 If no matching mapping is found FALSE is returned.
4584 The following characters are recognized in {mode}:
4585 n Normal mode
4586 v Visual and Select mode
4587 x Visual mode
4588 s Select mode
4589 o Operator-pending mode
4590 i Insert mode
4591 l Language-Argument ("r", "f", "t", etc.)
4592 c Command-line mode
4593 When {mode} is omitted, "nvo" is used.
4594
4595 This function is useful to check if a mapping already exists
4596 to a function in a Vim script. Example: >
4597 :if !hasmapto('\ABCdoit')
4598 : map <Leader>d \ABCdoit
4599 :endif
4600< This installs the mapping to "\ABCdoit" only if there isn't
4601 already a mapping to "\ABCdoit".
4602
4603 Can also be used as a |method|: >
4604 GetRHS()->hasmapto()
4605
4606histadd({history}, {item}) *histadd()*
4607 Add the String {item} to the history {history} which can be
4608 one of: *hist-names*
4609 "cmd" or ":" command line history
4610 "search" or "/" search pattern history
4611 "expr" or "=" typed expression history
4612 "input" or "@" input line history
4613 "debug" or ">" debug command history
4614 empty the current or last used history
4615 The {history} string does not need to be the whole name, one
4616 character is sufficient.
4617 If {item} does already exist in the history, it will be
4618 shifted to become the newest entry.
4619 The result is a Number: TRUE if the operation was successful,
4620 otherwise FALSE is returned.
4621
4622 Example: >
4623 :call histadd("input", strftime("%Y %b %d"))
4624 :let date=input("Enter date: ")
4625< This function is not available in the |sandbox|.
4626
4627 Can also be used as a |method|, the base is passed as the
4628 second argument: >
4629 GetHistory()->histadd('search')
4630
4631histdel({history} [, {item}]) *histdel()*
4632 Clear {history}, i.e. delete all its entries. See |hist-names|
4633 for the possible values of {history}.
4634
4635 If the parameter {item} evaluates to a String, it is used as a
4636 regular expression. All entries matching that expression will
4637 be removed from the history (if there are any).
4638 Upper/lowercase must match, unless "\c" is used |/\c|.
4639 If {item} evaluates to a Number, it will be interpreted as
4640 an index, see |:history-indexing|. The respective entry will
4641 be removed if it exists.
4642
4643 The result is TRUE for a successful operation, otherwise FALSE
4644 is returned.
4645
4646 Examples:
4647 Clear expression register history: >
4648 :call histdel("expr")
4649<
4650 Remove all entries starting with "*" from the search history: >
4651 :call histdel("/", '^\*')
4652<
4653 The following three are equivalent: >
4654 :call histdel("search", histnr("search"))
4655 :call histdel("search", -1)
Bram Moolenaarc51cf032022-02-26 12:25:45 +00004656 :call histdel("search", '^' .. histget("search", -1) .. '$')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004657<
4658 To delete the last search pattern and use the last-but-one for
4659 the "n" command and 'hlsearch': >
4660 :call histdel("search", -1)
4661 :let @/ = histget("search", -1)
4662<
4663 Can also be used as a |method|: >
4664 GetHistory()->histdel()
4665
4666histget({history} [, {index}]) *histget()*
4667 The result is a String, the entry with Number {index} from
4668 {history}. See |hist-names| for the possible values of
4669 {history}, and |:history-indexing| for {index}. If there is
4670 no such entry, an empty String is returned. When {index} is
4671 omitted, the most recent item from the history is used.
4672
4673 Examples:
4674 Redo the second last search from history. >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00004675 :execute '/' .. histget("search", -2)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004676
4677< Define an Ex command ":H {num}" that supports re-execution of
4678 the {num}th entry from the output of |:history|. >
4679 :command -nargs=1 H execute histget("cmd", 0+<args>)
4680<
4681 Can also be used as a |method|: >
4682 GetHistory()->histget()
4683
4684histnr({history}) *histnr()*
4685 The result is the Number of the current entry in {history}.
4686 See |hist-names| for the possible values of {history}.
4687 If an error occurred, -1 is returned.
4688
4689 Example: >
4690 :let inp_index = histnr("expr")
4691
4692< Can also be used as a |method|: >
4693 GetHistory()->histnr()
4694<
4695hlexists({name}) *hlexists()*
4696 The result is a Number, which is TRUE if a highlight group
4697 called {name} exists. This is when the group has been
4698 defined in some way. Not necessarily when highlighting has
4699 been defined for it, it may also have been used for a syntax
4700 item.
4701 *highlight_exists()*
4702 Obsolete name: highlight_exists().
4703
4704 Can also be used as a |method|: >
4705 GetName()->hlexists()
4706<
4707hlget([{name} [, {resolve}]]) *hlget()*
4708 Returns a List of all the highlight group attributes. If the
4709 optional {name} is specified, then returns a List with only
4710 the attributes of the specified highlight group. Returns an
4711 empty List if the highlight group {name} is not present.
4712
4713 If the optional {resolve} argument is set to v:true and the
4714 highlight group {name} is linked to another group, then the
4715 link is resolved recursively and the attributes of the
4716 resolved highlight group are returned.
4717
4718 Each entry in the returned List is a Dictionary with the
4719 following items:
4720 cleared boolean flag, set to v:true if the highlight
4721 group attributes are cleared or not yet
4722 specified. See |highlight-clear|.
4723 cterm cterm attributes. See |highlight-cterm|.
4724 ctermbg cterm background color.
4725 See |highlight-ctermbg|.
4726 ctermfg cterm foreground color.
4727 See |highlight-ctermfg|.
4728 ctermul cterm underline color. See |highlight-ctermul|.
4729 default boolean flag, set to v:true if the highlight
4730 group link is a default link. See
4731 |highlight-default|.
4732 font highlight group font. See |highlight-font|.
4733 gui gui attributes. See |highlight-gui|.
4734 guibg gui background color. See |highlight-guibg|.
4735 guifg gui foreground color. See |highlight-guifg|.
4736 guisp gui special color. See |highlight-guisp|.
4737 id highlight group ID.
4738 linksto linked highlight group name.
4739 See |:highlight-link|.
4740 name highlight group name. See |group-name|.
4741 start start terminal keycode. See |highlight-start|.
4742 stop stop terminal keycode. See |highlight-stop|.
4743 term term attributes. See |highlight-term|.
4744
4745 The 'term', 'cterm' and 'gui' items in the above Dictionary
4746 have a dictionary value with the following optional boolean
4747 items: 'bold', 'standout', 'underline', 'undercurl', 'italic',
4748 'reverse', 'inverse' and 'strikethrough'.
4749
4750 Example(s): >
4751 :echo hlget()
4752 :echo hlget('ModeMsg')
4753 :echo hlget('Number', v:true)
4754<
4755 Can also be used as a |method|: >
4756 GetName()->hlget()
4757<
4758hlset({list}) *hlset()*
4759 Creates or modifies the attributes of a List of highlight
4760 groups. Each item in {list} is a dictionary containing the
4761 attributes of a highlight group. See |hlget()| for the list of
4762 supported items in this dictionary.
4763
4764 In addition to the items described in |hlget()|, the following
4765 additional items are supported in the dictionary:
4766
4767 force boolean flag to force the creation of
4768 a link for an existing highlight group
4769 with attributes.
4770
4771 The highlight group is identified using the 'name' item and
4772 the 'id' item (if supplied) is ignored. If a highlight group
4773 with a specified name doesn't exist, then it is created.
4774 Otherwise the attributes of an existing highlight group are
4775 modified.
4776
4777 If an empty dictionary value is used for the 'term' or 'cterm'
4778 or 'gui' entries, then the corresponding attributes are
4779 cleared. If the 'cleared' item is set to v:true, then all the
4780 attributes of the highlight group are cleared.
4781
4782 The 'linksto' item can be used to link a highlight group to
4783 another highlight group. See |:highlight-link|.
4784
4785 Returns zero for success, -1 for failure.
4786
4787 Example(s): >
4788 " add bold attribute to the Visual highlight group
4789 :call hlset([#{name: 'Visual',
4790 \ term: #{reverse: 1 , bold: 1}}])
4791 :call hlset([#{name: 'Type', guifg: 'DarkGreen'}])
4792 :let l = hlget()
4793 :call hlset(l)
4794 " clear the Search highlight group
4795 :call hlset([#{name: 'Search', cleared: v:true}])
4796 " clear the 'term' attributes for a highlight group
4797 :call hlset([#{name: 'Title', term: {}}])
4798 " create the MyHlg group linking it to DiffAdd
4799 :call hlset([#{name: 'MyHlg', linksto: 'DiffAdd'}])
4800 " remove the MyHlg group link
4801 :call hlset([#{name: 'MyHlg', linksto: 'NONE'}])
4802 " clear the attributes and a link
4803 :call hlset([#{name: 'MyHlg', cleared: v:true,
4804 \ linksto: 'NONE'}])
4805<
4806 Can also be used as a |method|: >
4807 GetAttrList()->hlset()
4808<
4809 *hlID()*
4810hlID({name}) The result is a Number, which is the ID of the highlight group
4811 with name {name}. When the highlight group doesn't exist,
4812 zero is returned.
4813 This can be used to retrieve information about the highlight
4814 group. For example, to get the background color of the
4815 "Comment" group: >
4816 :echo synIDattr(synIDtrans(hlID("Comment")), "bg")
4817< *highlightID()*
4818 Obsolete name: highlightID().
4819
4820 Can also be used as a |method|: >
4821 GetName()->hlID()
4822
4823hostname() *hostname()*
4824 The result is a String, which is the name of the machine on
4825 which Vim is currently running. Machine names greater than
4826 256 characters long are truncated.
4827
4828iconv({string}, {from}, {to}) *iconv()*
4829 The result is a String, which is the text {string} converted
4830 from encoding {from} to encoding {to}.
4831 When the conversion completely fails an empty string is
4832 returned. When some characters could not be converted they
4833 are replaced with "?".
4834 The encoding names are whatever the iconv() library function
4835 can accept, see ":!man 3 iconv".
4836 Most conversions require Vim to be compiled with the |+iconv|
4837 feature. Otherwise only UTF-8 to latin1 conversion and back
4838 can be done.
4839 This can be used to display messages with special characters,
4840 no matter what 'encoding' is set to. Write the message in
4841 UTF-8 and use: >
4842 echo iconv(utf8_str, "utf-8", &enc)
4843< Note that Vim uses UTF-8 for all Unicode encodings, conversion
4844 from/to UCS-2 is automatically changed to use UTF-8. You
4845 cannot use UCS-2 in a string anyway, because of the NUL bytes.
4846
4847 Can also be used as a |method|: >
4848 GetText()->iconv('latin1', 'utf-8')
4849<
4850 *indent()*
4851indent({lnum}) The result is a Number, which is indent of line {lnum} in the
4852 current buffer. The indent is counted in spaces, the value
4853 of 'tabstop' is relevant. {lnum} is used just like in
4854 |getline()|.
4855 When {lnum} is invalid -1 is returned. In |Vim9| script an
4856 error is given.
4857
4858 Can also be used as a |method|: >
4859 GetLnum()->indent()
4860
4861index({object}, {expr} [, {start} [, {ic}]]) *index()*
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01004862 Find {expr} in {object} and return its index. See
Yegappan Lakshmanan3fbf6cd2022-08-13 21:35:13 +01004863 |indexof()| for using a lambda to select the item.
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01004864
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004865 If {object} is a |List| return the lowest index where the item
4866 has a value equal to {expr}. There is no automatic
4867 conversion, so the String "4" is different from the Number 4.
4868 And the number 4 is different from the Float 4.0. The value
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01004869 of 'ignorecase' is not used here, case matters as indicated by
4870 the {ic} argument.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004871
4872 If {object} is |Blob| return the lowest index where the byte
4873 value is equal to {expr}.
4874
4875 If {start} is given then start looking at the item with index
4876 {start} (may be negative for an item relative to the end).
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01004877
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004878 When {ic} is given and it is |TRUE|, ignore case. Otherwise
4879 case must match.
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01004880
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004881 -1 is returned when {expr} is not found in {object}.
4882 Example: >
4883 :let idx = index(words, "the")
4884 :if index(numbers, 123) >= 0
4885
4886< Can also be used as a |method|: >
4887 GetObject()->index(what)
4888
Yegappan Lakshmanan3fbf6cd2022-08-13 21:35:13 +01004889indexof({object}, {expr} [, {opts}]) *indexof()*
4890 Returns the index of an item in {object} where {expr} is
4891 v:true. {object} must be a |List| or a |Blob|.
4892
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01004893 If {object} is a |List|, evaluate {expr} for each item in the
Yegappan Lakshmanan3fbf6cd2022-08-13 21:35:13 +01004894 List until the expression is v:true and return the index of
4895 this item.
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01004896
4897 If {object} is a |Blob| evaluate {expr} for each byte in the
Yegappan Lakshmanan3fbf6cd2022-08-13 21:35:13 +01004898 Blob until the expression is v:true and return the index of
4899 this byte.
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01004900
4901 {expr} must be a |string| or |Funcref|.
4902
4903 If {expr} is a |string|: If {object} is a |List|, inside
4904 {expr} |v:key| has the index of the current List item and
4905 |v:val| has the value of the item. If {object} is a |Blob|,
4906 inside {expr} |v:key| has the index of the current byte and
4907 |v:val| has the byte value.
4908
4909 If {expr} is a |Funcref| it must take two arguments:
4910 1. the key or the index of the current item.
4911 2. the value of the current item.
4912 The function must return |TRUE| if the item is found and the
4913 search should stop.
4914
Yegappan Lakshmanan3fbf6cd2022-08-13 21:35:13 +01004915 The optional argument {opts} is a Dict and supports the
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01004916 following items:
Yegappan Lakshmanan3fbf6cd2022-08-13 21:35:13 +01004917 startidx start evaluating {expr} at the item with this
4918 index; may be negative for an item relative to
4919 the end
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01004920 Returns -1 when {expr} evaluates to v:false for all the items.
4921 Example: >
Yegappan Lakshmanan3fbf6cd2022-08-13 21:35:13 +01004922 :let l = [#{n: 10}, #{n: 20}, #{n: 30}]
4923 :echo indexof(l, "v:val.n == 20")
4924 :echo indexof(l, {i, v -> v.n == 30})
4925 :echo indexof(l, "v:val.n == 20", #{startidx: 1})
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01004926
4927< Can also be used as a |method|: >
4928 mylist->indexof(expr)
4929
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004930input({prompt} [, {text} [, {completion}]]) *input()*
4931 The result is a String, which is whatever the user typed on
4932 the command-line. The {prompt} argument is either a prompt
4933 string, or a blank string (for no prompt). A '\n' can be used
4934 in the prompt to start a new line.
4935 The highlighting set with |:echohl| is used for the prompt.
4936 The input is entered just like a command-line, with the same
4937 editing commands and mappings. There is a separate history
4938 for lines typed for input().
4939 Example: >
4940 :if input("Coffee or beer? ") == "beer"
4941 : echo "Cheers!"
4942 :endif
4943<
4944 If the optional {text} argument is present and not empty, this
4945 is used for the default reply, as if the user typed this.
4946 Example: >
4947 :let color = input("Color? ", "white")
4948
4949< The optional {completion} argument specifies the type of
4950 completion supported for the input. Without it completion is
4951 not performed. The supported completion types are the same as
4952 that can be supplied to a user-defined command using the
4953 "-complete=" argument. Refer to |:command-completion| for
4954 more information. Example: >
4955 let fname = input("File: ", "", "file")
4956<
4957 NOTE: This function must not be used in a startup file, for
4958 the versions that only run in GUI mode (e.g., the Win32 GUI).
4959 Note: When input() is called from within a mapping it will
4960 consume remaining characters from that mapping, because a
4961 mapping is handled like the characters were typed.
4962 Use |inputsave()| before input() and |inputrestore()|
4963 after input() to avoid that. Another solution is to avoid
4964 that further characters follow in the mapping, e.g., by using
4965 |:execute| or |:normal|.
4966
4967 Example with a mapping: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00004968 :nmap \x :call GetFoo()<CR>:exe "/" .. Foo<CR>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004969 :function GetFoo()
4970 : call inputsave()
4971 : let g:Foo = input("enter search pattern: ")
4972 : call inputrestore()
4973 :endfunction
4974
4975< Can also be used as a |method|: >
4976 GetPrompt()->input()
4977
4978inputdialog({prompt} [, {text} [, {cancelreturn}]]) *inputdialog()*
4979 Like |input()|, but when the GUI is running and text dialogs
4980 are supported, a dialog window pops up to input the text.
4981 Example: >
4982 :let n = inputdialog("value for shiftwidth", shiftwidth())
4983 :if n != ""
4984 : let &sw = n
4985 :endif
4986< When the dialog is cancelled {cancelreturn} is returned. When
4987 omitted an empty string is returned.
4988 Hitting <Enter> works like pressing the OK button. Hitting
4989 <Esc> works like pressing the Cancel button.
4990 NOTE: Command-line completion is not supported.
4991
4992 Can also be used as a |method|: >
4993 GetPrompt()->inputdialog()
4994
4995inputlist({textlist}) *inputlist()*
4996 {textlist} must be a |List| of strings. This |List| is
4997 displayed, one string per line. The user will be prompted to
4998 enter a number, which is returned.
4999 The user can also select an item by clicking on it with the
5000 mouse, if the mouse is enabled in the command line ('mouse' is
5001 "a" or includes "c"). For the first string 0 is returned.
5002 When clicking above the first item a negative number is
5003 returned. When clicking on the prompt one more than the
5004 length of {textlist} is returned.
5005 Make sure {textlist} has less than 'lines' entries, otherwise
5006 it won't work. It's a good idea to put the entry number at
5007 the start of the string. And put a prompt in the first item.
5008 Example: >
5009 let color = inputlist(['Select color:', '1. red',
5010 \ '2. green', '3. blue'])
5011
5012< Can also be used as a |method|: >
5013 GetChoices()->inputlist()
5014
5015inputrestore() *inputrestore()*
5016 Restore typeahead that was saved with a previous |inputsave()|.
5017 Should be called the same number of times inputsave() is
5018 called. Calling it more often is harmless though.
5019 Returns TRUE when there is nothing to restore, FALSE otherwise.
5020
5021inputsave() *inputsave()*
5022 Preserve typeahead (also from mappings) and clear it, so that
5023 a following prompt gets input from the user. Should be
5024 followed by a matching inputrestore() after the prompt. Can
5025 be used several times, in which case there must be just as
5026 many inputrestore() calls.
5027 Returns TRUE when out of memory, FALSE otherwise.
5028
5029inputsecret({prompt} [, {text}]) *inputsecret()*
5030 This function acts much like the |input()| function with but
5031 two exceptions:
5032 a) the user's response will be displayed as a sequence of
5033 asterisks ("*") thereby keeping the entry secret, and
5034 b) the user's response will not be recorded on the input
5035 |history| stack.
5036 The result is a String, which is whatever the user actually
5037 typed on the command-line in response to the issued prompt.
5038 NOTE: Command-line completion is not supported.
5039
5040 Can also be used as a |method|: >
5041 GetPrompt()->inputsecret()
5042
5043insert({object}, {item} [, {idx}]) *insert()*
5044 When {object} is a |List| or a |Blob| insert {item} at the start
5045 of it.
5046
5047 If {idx} is specified insert {item} before the item with index
5048 {idx}. If {idx} is zero it goes before the first item, just
5049 like omitting {idx}. A negative {idx} is also possible, see
5050 |list-index|. -1 inserts just before the last item.
5051
5052 Returns the resulting |List| or |Blob|. Examples: >
5053 :let mylist = insert([2, 3, 5], 1)
5054 :call insert(mylist, 4, -1)
5055 :call insert(mylist, 6, len(mylist))
5056< The last example can be done simpler with |add()|.
5057 Note that when {item} is a |List| it is inserted as a single
5058 item. Use |extend()| to concatenate |Lists|.
5059
5060 Can also be used as a |method|: >
5061 mylist->insert(item)
Yegappan Lakshmanancd39b692023-10-02 12:50:45 -07005062<
5063 *instanceof()* *E614* *E616* *E693*
5064instanceof({object}, {class})
5065 The result is a Number, which is |TRUE| when the {object}
Ernie Rael2025af12023-12-12 16:58:00 +01005066 argument is a direct or indirect instance of a |Class|,
5067 |Interface|, or class |:type| alias specified by {class}.
5068 If {class} is varargs, the function returns |TRUE| when
Yegappan Lakshmanancd39b692023-10-02 12:50:45 -07005069 {object} is an instance of any of the specified classes.
LemonBoyafe04662023-08-23 21:08:11 +02005070 Example: >
Ernie Rael2025af12023-12-12 16:58:00 +01005071 instanceof(animal, Dog, Cat)
LemonBoyafe04662023-08-23 21:08:11 +02005072
5073< Can also be used as a |method|: >
5074 myobj->instanceof(mytype)
5075
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005076interrupt() *interrupt()*
5077 Interrupt script execution. It works more or less like the
5078 user typing CTRL-C, most commands won't execute and control
5079 returns to the user. This is useful to abort execution
5080 from lower down, e.g. in an autocommand. Example: >
5081 :function s:check_typoname(file)
5082 : if fnamemodify(a:file, ':t') == '['
5083 : echomsg 'Maybe typo'
5084 : call interrupt()
5085 : endif
5086 :endfunction
5087 :au BufWritePre * call s:check_typoname(expand('<amatch>'))
5088
5089invert({expr}) *invert()*
5090 Bitwise invert. The argument is converted to a number. A
5091 List, Dict or Float argument causes an error. Example: >
5092 :let bits = invert(bits)
5093< Can also be used as a |method|: >
5094 :let bits = bits->invert()
5095
Bram Moolenaar8a3b8052022-06-26 12:21:15 +01005096isabsolutepath({path}) *isabsolutepath()*
LemonBoydca1d402022-04-28 15:26:33 +01005097 The result is a Number, which is |TRUE| when {path} is an
5098 absolute path.
Bram Moolenaar8a3b8052022-06-26 12:21:15 +01005099 On Unix, a path is considered absolute when it starts with '/'.
LemonBoydca1d402022-04-28 15:26:33 +01005100 On MS-Windows, it is considered absolute when it starts with an
5101 optional drive prefix and is followed by a '\' or '/'. UNC paths
5102 are always absolute.
5103 Example: >
5104 echo isabsolutepath('/usr/share/') " 1
5105 echo isabsolutepath('./foobar') " 0
5106 echo isabsolutepath('C:\Windows') " 1
5107 echo isabsolutepath('foobar') " 0
5108 echo isabsolutepath('\\remote\file') " 1
Bram Moolenaar8a3b8052022-06-26 12:21:15 +01005109<
LemonBoydca1d402022-04-28 15:26:33 +01005110 Can also be used as a |method|: >
5111 GetName()->isabsolutepath()
5112
5113
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005114isdirectory({directory}) *isdirectory()*
5115 The result is a Number, which is |TRUE| when a directory
5116 with the name {directory} exists. If {directory} doesn't
5117 exist, or isn't a directory, the result is |FALSE|. {directory}
5118 is any expression, which is used as a String.
5119
5120 Can also be used as a |method|: >
5121 GetName()->isdirectory()
5122
5123isinf({expr}) *isinf()*
5124 Return 1 if {expr} is a positive infinity, or -1 a negative
5125 infinity, otherwise 0. >
5126 :echo isinf(1.0 / 0.0)
5127< 1 >
5128 :echo isinf(-1.0 / 0.0)
5129< -1
5130
5131 Can also be used as a |method|: >
5132 Compute()->isinf()
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005133
5134islocked({expr}) *islocked()* *E786*
5135 The result is a Number, which is |TRUE| when {expr} is the
5136 name of a locked variable.
5137 The string argument {expr} must be the name of a variable,
5138 |List| item or |Dictionary| entry, not the variable itself!
5139 Example: >
5140 :let alist = [0, ['a', 'b'], 2, 3]
5141 :lockvar 1 alist
5142 :echo islocked('alist') " 1
5143 :echo islocked('alist[1]') " 0
5144
Bram Moolenaar9da17d72022-02-09 21:50:44 +00005145< When {expr} is a variable that does not exist -1 is returned.
5146 If {expr} uses a range, list or dict index that is out of
5147 range or does not exist you get an error message. Use
5148 |exists()| to check for existence.
5149 In Vim9 script it does not work for local function variables.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005150
5151 Can also be used as a |method|: >
5152 GetName()->islocked()
5153
5154isnan({expr}) *isnan()*
5155 Return |TRUE| if {expr} is a float with value NaN. >
5156 echo isnan(0.0 / 0.0)
5157< 1
5158
5159 Can also be used as a |method|: >
5160 Compute()->isnan()
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005161
5162items({dict}) *items()*
5163 Return a |List| with all the key-value pairs of {dict}. Each
5164 |List| item is a list with two items: the key of a {dict}
5165 entry and the value of this entry. The |List| is in arbitrary
5166 order. Also see |keys()| and |values()|.
5167 Example: >
5168 for [key, value] in items(mydict)
Bram Moolenaarc51cf032022-02-26 12:25:45 +00005169 echo key .. ': ' .. value
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005170 endfor
Yegappan Lakshmanan49cdd622023-12-24 11:01:23 +01005171<
5172 A List or a String argument is also supported. In these
5173 cases, items() returns a List with the index and the value at
5174 the index.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005175
Yegappan Lakshmanan49cdd622023-12-24 11:01:23 +01005176 Can also be used as a |method|: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005177 mydict->items()
5178
5179job_ functions are documented here: |job-functions-details|
5180
5181
5182join({list} [, {sep}]) *join()*
5183 Join the items in {list} together into one String.
5184 When {sep} is specified it is put in between the items. If
5185 {sep} is omitted a single space is used.
5186 Note that {sep} is not added at the end. You might want to
5187 add it there too: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00005188 let lines = join(mylist, "\n") .. "\n"
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005189< String items are used as-is. |Lists| and |Dictionaries| are
5190 converted into a string like with |string()|.
5191 The opposite function is |split()|.
5192
5193 Can also be used as a |method|: >
5194 mylist->join()
5195
5196js_decode({string}) *js_decode()*
5197 This is similar to |json_decode()| with these differences:
5198 - Object key names do not have to be in quotes.
5199 - Strings can be in single quotes.
5200 - Empty items in an array (between two commas) are allowed and
5201 result in v:none items.
5202
5203 Can also be used as a |method|: >
5204 ReadObject()->js_decode()
5205
5206js_encode({expr}) *js_encode()*
5207 This is similar to |json_encode()| with these differences:
5208 - Object key names are not in quotes.
5209 - v:none items in an array result in an empty item between
5210 commas.
5211 For example, the Vim object:
5212 [1,v:none,{"one":1},v:none] ~
5213 Will be encoded as:
5214 [1,,{one:1},,] ~
5215 While json_encode() would produce:
5216 [1,null,{"one":1},null] ~
5217 This encoding is valid for JavaScript. It is more efficient
5218 than JSON, especially when using an array with optional items.
5219
5220 Can also be used as a |method|: >
5221 GetObject()->js_encode()
5222
Bram Moolenaar2f0936c2022-01-08 21:51:59 +00005223json_decode({string}) *json_decode()* *E491*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005224 This parses a JSON formatted string and returns the equivalent
5225 in Vim values. See |json_encode()| for the relation between
5226 JSON and Vim values.
5227 The decoding is permissive:
5228 - A trailing comma in an array and object is ignored, e.g.
5229 "[1, 2, ]" is the same as "[1, 2]".
5230 - Integer keys are accepted in objects, e.g. {1:2} is the
5231 same as {"1":2}.
5232 - More floating point numbers are recognized, e.g. "1." for
5233 "1.0", or "001.2" for "1.2". Special floating point values
5234 "Infinity", "-Infinity" and "NaN" (capitalization ignored)
5235 are accepted.
5236 - Leading zeroes in integer numbers are ignored, e.g. "012"
5237 for "12" or "-012" for "-12".
5238 - Capitalization is ignored in literal names null, true or
5239 false, e.g. "NULL" for "null", "True" for "true".
5240 - Control characters U+0000 through U+001F which are not
5241 escaped in strings are accepted, e.g. " " (tab
5242 character in string) for "\t".
5243 - An empty JSON expression or made of only spaces is accepted
5244 and results in v:none.
5245 - Backslash in an invalid 2-character sequence escape is
5246 ignored, e.g. "\a" is decoded as "a".
5247 - A correct surrogate pair in JSON strings should normally be
5248 a 12 character sequence such as "\uD834\uDD1E", but
5249 json_decode() silently accepts truncated surrogate pairs
5250 such as "\uD834" or "\uD834\u"
5251 *E938*
5252 A duplicate key in an object, valid in rfc7159, is not
5253 accepted by json_decode() as the result must be a valid Vim
5254 type, e.g. this fails: {"a":"b", "a":"c"}
5255
5256 Can also be used as a |method|: >
5257 ReadObject()->json_decode()
5258
5259json_encode({expr}) *json_encode()*
5260 Encode {expr} as JSON and return this as a string.
5261 The encoding is specified in:
5262 https://tools.ietf.org/html/rfc7159.html
Bram Moolenaara2baa732022-02-04 16:09:54 +00005263 Vim values are converted as follows: *E1161*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005264 |Number| decimal number
5265 |Float| floating point number
5266 Float nan "NaN"
5267 Float inf "Infinity"
5268 Float -inf "-Infinity"
5269 |String| in double quotes (possibly null)
5270 |Funcref| not possible, error
5271 |List| as an array (possibly null); when
5272 used recursively: []
5273 |Dict| as an object (possibly null); when
5274 used recursively: {}
5275 |Blob| as an array of the individual bytes
5276 v:false "false"
5277 v:true "true"
5278 v:none "null"
5279 v:null "null"
5280 Note that NaN and Infinity are passed on as values. This is
5281 missing in the JSON standard, but several implementations do
5282 allow it. If not then you will get an error.
Bram Moolenaarcbaff5e2022-04-08 17:45:08 +01005283 If a string contains an illegal character then the replacement
5284 character 0xfffd is used.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005285
5286 Can also be used as a |method|: >
5287 GetObject()->json_encode()
5288
5289keys({dict}) *keys()*
5290 Return a |List| with all the keys of {dict}. The |List| is in
5291 arbitrary order. Also see |items()| and |values()|.
5292
5293 Can also be used as a |method|: >
5294 mydict->keys()
5295
zeertzjqcdc83932022-09-12 13:38:41 +01005296keytrans({string}) *keytrans()*
5297 Turn the internal byte representation of keys into a form that
5298 can be used for |:map|. E.g. >
5299 :let xx = "\<C-Home>"
5300 :echo keytrans(xx)
5301< <C-Home>
5302
5303 Can also be used as a |method|: >
5304 "\<C-Home>"->keytrans()
5305
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005306< *len()* *E701*
5307len({expr}) The result is a Number, which is the length of the argument.
5308 When {expr} is a String or a Number the length in bytes is
5309 used, as with |strlen()|.
5310 When {expr} is a |List| the number of items in the |List| is
5311 returned.
5312 When {expr} is a |Blob| the number of bytes is returned.
5313 When {expr} is a |Dictionary| the number of entries in the
5314 |Dictionary| is returned.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01005315 Otherwise an error is given and returns zero.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005316
5317 Can also be used as a |method|: >
5318 mylist->len()
5319
5320< *libcall()* *E364* *E368*
5321libcall({libname}, {funcname}, {argument})
5322 Call function {funcname} in the run-time library {libname}
5323 with single argument {argument}.
5324 This is useful to call functions in a library that you
5325 especially made to be used with Vim. Since only one argument
5326 is possible, calling standard library functions is rather
5327 limited.
5328 The result is the String returned by the function. If the
5329 function returns NULL, this will appear as an empty string ""
5330 to Vim.
5331 If the function returns a number, use libcallnr()!
5332 If {argument} is a number, it is passed to the function as an
5333 int; if {argument} is a string, it is passed as a
5334 null-terminated string.
5335 This function will fail in |restricted-mode|.
5336
5337 libcall() allows you to write your own 'plug-in' extensions to
5338 Vim without having to recompile the program. It is NOT a
5339 means to call system functions! If you try to do so Vim will
5340 very probably crash.
5341
5342 For Win32, the functions you write must be placed in a DLL
5343 and use the normal C calling convention (NOT Pascal which is
5344 used in Windows System DLLs). The function must take exactly
5345 one parameter, either a character pointer or a long integer,
5346 and must return a character pointer or NULL. The character
5347 pointer returned must point to memory that will remain valid
5348 after the function has returned (e.g. in static data in the
5349 DLL). If it points to allocated memory, that memory will
5350 leak away. Using a static buffer in the function should work,
5351 it's then freed when the DLL is unloaded.
5352
5353 WARNING: If the function returns a non-valid pointer, Vim may
5354 crash! This also happens if the function returns a number,
5355 because Vim thinks it's a pointer.
5356 For Win32 systems, {libname} should be the filename of the DLL
5357 without the ".DLL" suffix. A full path is only required if
5358 the DLL is not in the usual places.
5359 For Unix: When compiling your own plugins, remember that the
5360 object code must be compiled as position-independent ('PIC').
5361 {only in Win32 and some Unix versions, when the |+libcall|
5362 feature is present}
5363 Examples: >
5364 :echo libcall("libc.so", "getenv", "HOME")
5365
5366< Can also be used as a |method|, the base is passed as the
5367 third argument: >
5368 GetValue()->libcall("libc.so", "getenv")
5369<
5370 *libcallnr()*
5371libcallnr({libname}, {funcname}, {argument})
5372 Just like |libcall()|, but used for a function that returns an
5373 int instead of a string.
5374 {only in Win32 on some Unix versions, when the |+libcall|
5375 feature is present}
5376 Examples: >
5377 :echo libcallnr("/usr/lib/libc.so", "getpid", "")
5378 :call libcallnr("libc.so", "printf", "Hello World!\n")
5379 :call libcallnr("libc.so", "sleep", 10)
5380<
5381 Can also be used as a |method|, the base is passed as the
5382 third argument: >
5383 GetValue()->libcallnr("libc.so", "printf")
5384<
5385
5386line({expr} [, {winid}]) *line()*
5387 The result is a Number, which is the line number of the file
5388 position given with {expr}. The {expr} argument is a string.
Bram Moolenaara2baa732022-02-04 16:09:54 +00005389 The accepted positions are: *E1209*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005390 . the cursor position
5391 $ the last line in the current buffer
5392 'x position of mark x (if the mark is not set, 0 is
5393 returned)
5394 w0 first line visible in current window (one if the
5395 display isn't updated, e.g. in silent Ex mode)
5396 w$ last line visible in current window (this is one
5397 less than "w0" if no lines are visible)
5398 v In Visual mode: the start of the Visual area (the
5399 cursor is the end). When not in Visual mode
5400 returns the cursor position. Differs from |'<| in
5401 that it's updated right away.
5402 Note that a mark in another file can be used. The line number
5403 then applies to another buffer.
5404 To get the column number use |col()|. To get both use
5405 |getpos()|.
5406 With the optional {winid} argument the values are obtained for
5407 that window instead of the current window.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01005408 Returns 0 for invalid values of {expr} and {winid}.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005409 Examples: >
5410 line(".") line number of the cursor
5411 line(".", winid) idem, in window "winid"
5412 line("'t") line number of mark t
Bram Moolenaarc51cf032022-02-26 12:25:45 +00005413 line("'" .. marker) line number of mark marker
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005414<
5415 To jump to the last known position when opening a file see
5416 |last-position-jump|.
5417
5418 Can also be used as a |method|: >
5419 GetValue()->line()
5420
5421line2byte({lnum}) *line2byte()*
5422 Return the byte count from the start of the buffer for line
5423 {lnum}. This includes the end-of-line character, depending on
5424 the 'fileformat' option for the current buffer. The first
5425 line returns 1. 'encoding' matters, 'fileencoding' is ignored.
5426 This can also be used to get the byte count for the line just
5427 below the last line: >
5428 line2byte(line("$") + 1)
5429< This is the buffer size plus one. If 'fileencoding' is empty
5430 it is the file size plus one. {lnum} is used like with
5431 |getline()|. When {lnum} is invalid, or the |+byte_offset|
5432 feature has been disabled at compile time, -1 is returned.
5433 Also see |byte2line()|, |go| and |:goto|.
5434
5435 Can also be used as a |method|: >
5436 GetLnum()->line2byte()
5437
5438lispindent({lnum}) *lispindent()*
5439 Get the amount of indent for line {lnum} according the lisp
5440 indenting rules, as with 'lisp'.
5441 The indent is counted in spaces, the value of 'tabstop' is
5442 relevant. {lnum} is used just like in |getline()|.
Bram Moolenaar8e145b82022-05-21 20:17:31 +01005443 When {lnum} is invalid -1 is returned. In |Vim9| script an
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005444 error is given.
5445
5446 Can also be used as a |method|: >
5447 GetLnum()->lispindent()
5448
5449list2blob({list}) *list2blob()*
5450 Return a Blob concatenating all the number values in {list}.
5451 Examples: >
5452 list2blob([1, 2, 3, 4]) returns 0z01020304
5453 list2blob([]) returns 0z
5454< Returns an empty Blob on error. If one of the numbers is
5455 negative or more than 255 error *E1239* is given.
5456
5457 |blob2list()| does the opposite.
5458
5459 Can also be used as a |method|: >
5460 GetList()->list2blob()
5461
5462list2str({list} [, {utf8}]) *list2str()*
5463 Convert each number in {list} to a character string can
5464 concatenate them all. Examples: >
5465 list2str([32]) returns " "
5466 list2str([65, 66, 67]) returns "ABC"
5467< The same can be done (slowly) with: >
5468 join(map(list, {nr, val -> nr2char(val)}), '')
5469< |str2list()| does the opposite.
5470
5471 When {utf8} is omitted or zero, the current 'encoding' is used.
5472 When {utf8} is TRUE, always return UTF-8 characters.
5473 With UTF-8 composing characters work as expected: >
5474 list2str([97, 769]) returns "á"
5475<
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01005476 Returns an empty string on error.
5477
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005478 Can also be used as a |method|: >
5479 GetList()->list2str()
5480
5481listener_add({callback} [, {buf}]) *listener_add()*
5482 Add a callback function that will be invoked when changes have
5483 been made to buffer {buf}.
5484 {buf} refers to a buffer name or number. For the accepted
5485 values, see |bufname()|. When {buf} is omitted the current
5486 buffer is used.
5487 Returns a unique ID that can be passed to |listener_remove()|.
5488
5489 The {callback} is invoked with five arguments:
Bram Moolenaar944697a2022-02-20 19:48:20 +00005490 bufnr the buffer that was changed
5491 start first changed line number
5492 end first line number below the change
5493 added number of lines added, negative if lines were
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005494 deleted
Bram Moolenaar944697a2022-02-20 19:48:20 +00005495 changes a List of items with details about the changes
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005496
5497 Example: >
5498 func Listener(bufnr, start, end, added, changes)
5499 echo 'lines ' .. a:start .. ' until ' .. a:end .. ' changed'
5500 endfunc
5501 call listener_add('Listener', bufnr)
5502
Bram Moolenaar944697a2022-02-20 19:48:20 +00005503< The List cannot be changed. Each item in "changes" is a
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005504 dictionary with these entries:
5505 lnum the first line number of the change
5506 end the first line below the change
5507 added number of lines added; negative if lines were
5508 deleted
5509 col first column in "lnum" that was affected by
5510 the change; one if unknown or the whole line
5511 was affected; this is a byte index, first
5512 character has a value of one.
Bram Moolenaar3c053a12022-10-16 13:11:12 +01005513 When lines are inserted (not when a line is split, e.g. by
5514 typing CR in Insert mode) the values are:
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005515 lnum line above which the new line is added
5516 end equal to "lnum"
5517 added number of lines inserted
5518 col 1
5519 When lines are deleted the values are:
5520 lnum the first deleted line
5521 end the line below the first deleted line, before
5522 the deletion was done
5523 added negative, number of lines deleted
5524 col 1
5525 When lines are changed:
5526 lnum the first changed line
5527 end the line below the last changed line
5528 added 0
5529 col first column with a change or 1
5530
5531 The entries are in the order the changes were made, thus the
5532 most recent change is at the end. The line numbers are valid
5533 when the callback is invoked, but later changes may make them
5534 invalid, thus keeping a copy for later might not work.
5535
5536 The {callback} is invoked just before the screen is updated,
5537 when |listener_flush()| is called or when a change is being
5538 made that changes the line count in a way it causes a line
5539 number in the list of changes to become invalid.
5540
5541 The {callback} is invoked with the text locked, see
5542 |textlock|. If you do need to make changes to the buffer, use
5543 a timer to do this later |timer_start()|.
5544
5545 The {callback} is not invoked when the buffer is first loaded.
5546 Use the |BufReadPost| autocmd event to handle the initial text
5547 of a buffer.
5548 The {callback} is also not invoked when the buffer is
5549 unloaded, use the |BufUnload| autocmd event for that.
5550
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01005551 Returns zero if {callback} or {buf} is invalid.
5552
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005553 Can also be used as a |method|, the base is passed as the
5554 second argument: >
5555 GetBuffer()->listener_add(callback)
5556
5557listener_flush([{buf}]) *listener_flush()*
5558 Invoke listener callbacks for buffer {buf}. If there are no
5559 pending changes then no callbacks are invoked.
5560
5561 {buf} refers to a buffer name or number. For the accepted
5562 values, see |bufname()|. When {buf} is omitted the current
5563 buffer is used.
5564
5565 Can also be used as a |method|: >
5566 GetBuffer()->listener_flush()
5567
5568listener_remove({id}) *listener_remove()*
5569 Remove a listener previously added with listener_add().
5570 Returns FALSE when {id} could not be found, TRUE when {id} was
5571 removed.
5572
5573 Can also be used as a |method|: >
5574 GetListenerId()->listener_remove()
5575
5576localtime() *localtime()*
5577 Return the current time, measured as seconds since 1st Jan
5578 1970. See also |strftime()|, |strptime()| and |getftime()|.
5579
5580
5581log({expr}) *log()*
5582 Return the natural logarithm (base e) of {expr} as a |Float|.
5583 {expr} must evaluate to a |Float| or a |Number| in the range
5584 (0, inf].
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01005585 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005586 Examples: >
5587 :echo log(10)
5588< 2.302585 >
5589 :echo log(exp(5))
5590< 5.0
5591
5592 Can also be used as a |method|: >
5593 Compute()->log()
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005594
5595
5596log10({expr}) *log10()*
5597 Return the logarithm of Float {expr} to base 10 as a |Float|.
5598 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01005599 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005600 Examples: >
5601 :echo log10(1000)
5602< 3.0 >
5603 :echo log10(0.01)
5604< -2.0
5605
5606 Can also be used as a |method|: >
5607 Compute()->log10()
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005608
5609luaeval({expr} [, {expr}]) *luaeval()*
5610 Evaluate Lua expression {expr} and return its result converted
5611 to Vim data structures. Second {expr} may hold additional
5612 argument accessible as _A inside first {expr}.
5613 Strings are returned as they are.
5614 Boolean objects are converted to numbers.
Bram Moolenaar73e28dc2022-09-17 21:08:33 +01005615 Numbers are converted to |Float| values.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005616 Dictionaries and lists obtained by vim.eval() are returned
5617 as-is.
5618 Other objects are returned as zero without any errors.
5619 See |lua-luaeval| for more details.
5620 Note that in a `:def` function local variables are not visible
5621 to {expr}.
5622
5623 Can also be used as a |method|: >
5624 GetExpr()->luaeval()
5625
5626< {only available when compiled with the |+lua| feature}
5627
5628map({expr1}, {expr2}) *map()*
5629 {expr1} must be a |List|, |String|, |Blob| or |Dictionary|.
Bram Moolenaar944697a2022-02-20 19:48:20 +00005630 When {expr1} is a |List| or |Dictionary|, replace each
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005631 item in {expr1} with the result of evaluating {expr2}.
5632 For a |Blob| each byte is replaced.
5633 For a |String|, each character, including composing
5634 characters, is replaced.
5635 If the item type changes you may want to use |mapnew()| to
5636 create a new List or Dictionary. This is required when using
5637 Vim9 script.
5638
5639 {expr2} must be a |String| or |Funcref|.
5640
5641 If {expr2} is a |String|, inside {expr2} |v:val| has the value
5642 of the current item. For a |Dictionary| |v:key| has the key
5643 of the current item and for a |List| |v:key| has the index of
5644 the current item. For a |Blob| |v:key| has the index of the
5645 current byte. For a |String| |v:key| has the index of the
5646 current character.
5647 Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00005648 :call map(mylist, '"> " .. v:val .. " <"')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005649< This puts "> " before and " <" after each item in "mylist".
5650
5651 Note that {expr2} is the result of an expression and is then
5652 used as an expression again. Often it is good to use a
5653 |literal-string| to avoid having to double backslashes. You
5654 still have to double ' quotes
5655
5656 If {expr2} is a |Funcref| it is called with two arguments:
5657 1. The key or the index of the current item.
5658 2. the value of the current item.
Bram Moolenaarb59ae592022-11-23 23:46:31 +00005659 With a legacy script lambda you don't get an error if it only
5660 accepts one argument, but with a Vim9 lambda you get "E1106:
5661 One argument too many", the number of arguments must match.
5662
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005663 The function must return the new value of the item. Example
5664 that changes each value by "key-value": >
5665 func KeyValue(key, val)
Bram Moolenaarc51cf032022-02-26 12:25:45 +00005666 return a:key .. '-' .. a:val
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005667 endfunc
5668 call map(myDict, function('KeyValue'))
5669< It is shorter when using a |lambda|: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00005670 call map(myDict, {key, val -> key .. '-' .. val})
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005671< If you do not use "val" you can leave it out: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00005672 call map(myDict, {key -> 'item: ' .. key})
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005673< If you do not use "key" you can use a short name: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00005674 call map(myDict, {_, val -> 'item: ' .. val})
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005675<
5676 The operation is done in-place for a |List| and |Dictionary|.
5677 If you want it to remain unmodified make a copy first: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00005678 :let tlist = map(copy(mylist), ' v:val .. "\t"')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005679
5680< Returns {expr1}, the |List| or |Dictionary| that was filtered,
5681 or a new |Blob| or |String|.
5682 When an error is encountered while evaluating {expr2} no
5683 further items in {expr1} are processed.
5684 When {expr2} is a Funcref errors inside a function are ignored,
5685 unless it was defined with the "abort" flag.
5686
5687 Can also be used as a |method|: >
5688 mylist->map(expr2)
5689
5690
5691maparg({name} [, {mode} [, {abbr} [, {dict}]]]) *maparg()*
5692 When {dict} is omitted or zero: Return the rhs of mapping
5693 {name} in mode {mode}. The returned String has special
5694 characters translated like in the output of the ":map" command
Ernie Rael09661202022-04-25 14:40:44 +01005695 listing. When {dict} is TRUE a dictionary is returned, see
5696 below. To get a list of all mappings see |maplist()|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005697
5698 When there is no mapping for {name}, an empty String is
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01005699 returned if {dict} is FALSE, otherwise returns an empty Dict.
5700 When the mapping for {name} is empty, then "<Nop>" is
5701 returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005702
5703 The {name} can have special key names, like in the ":map"
5704 command.
5705
5706 {mode} can be one of these strings:
5707 "n" Normal
5708 "v" Visual (including Select)
5709 "o" Operator-pending
5710 "i" Insert
5711 "c" Cmd-line
5712 "s" Select
5713 "x" Visual
5714 "l" langmap |language-mapping|
5715 "t" Terminal-Job
5716 "" Normal, Visual and Operator-pending
5717 When {mode} is omitted, the modes for "" are used.
5718
5719 When {abbr} is there and it is |TRUE| use abbreviations
5720 instead of mappings.
5721
5722 When {dict} is there and it is |TRUE| return a dictionary
5723 containing all the information of the mapping with the
Ernie Rael659c2402022-04-24 18:40:28 +01005724 following items: *mapping-dict*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005725 "lhs" The {lhs} of the mapping as it would be typed
5726 "lhsraw" The {lhs} of the mapping as raw bytes
5727 "lhsrawalt" The {lhs} of the mapping as raw bytes, alternate
5728 form, only present when it differs from "lhsraw"
5729 "rhs" The {rhs} of the mapping as typed.
5730 "silent" 1 for a |:map-silent| mapping, else 0.
5731 "noremap" 1 if the {rhs} of the mapping is not remappable.
5732 "script" 1 if mapping was defined with <script>.
5733 "expr" 1 for an expression mapping (|:map-<expr>|).
5734 "buffer" 1 for a buffer local mapping (|:map-local|).
5735 "mode" Modes for which the mapping is defined. In
5736 addition to the modes mentioned above, these
5737 characters will be used:
5738 " " Normal, Visual and Operator-pending
5739 "!" Insert and Commandline mode
5740 (|mapmode-ic|)
5741 "sid" The script local ID, used for <sid> mappings
Bram Moolenaar71badf92023-04-22 22:40:14 +01005742 (|<SID>|). Negative for special contexts.
Bram Moolenaara9528b32022-01-18 20:51:35 +00005743 "scriptversion" The version of the script. 999999 for
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01005744 |Vim9| script.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005745 "lnum" The line number in "sid", zero if unknown.
5746 "nowait" Do not wait for other, longer mappings.
5747 (|:map-<nowait>|).
Bram Moolenaar921bde82022-05-09 19:50:35 +01005748 "abbr" True if this is an abbreviation |abbreviations|.
Ernie Raeld8f5f762022-05-10 17:50:39 +01005749 "mode_bits" Vim's internal binary representation of "mode".
5750 |mapset()| ignores this; only "mode" is used.
5751 See |maplist()| for usage examples. The values
5752 are from src/vim.h and may change in the future.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005753
5754 The dictionary can be used to restore a mapping with
5755 |mapset()|.
5756
5757 The mappings local to the current buffer are checked first,
5758 then the global mappings.
5759 This function can be used to map a key even when it's already
5760 mapped, and have it do the original mapping too. Sketch: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00005761 exe 'nnoremap <Tab> ==' .. maparg('<Tab>', 'n')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005762
5763< Can also be used as a |method|: >
5764 GetKey()->maparg('n')
5765
5766mapcheck({name} [, {mode} [, {abbr}]]) *mapcheck()*
5767 Check if there is a mapping that matches with {name} in mode
5768 {mode}. See |maparg()| for {mode} and special names in
5769 {name}.
5770 When {abbr} is there and it is |TRUE| use abbreviations
5771 instead of mappings.
5772 A match happens with a mapping that starts with {name} and
5773 with a mapping which is equal to the start of {name}.
5774
5775 matches mapping "a" "ab" "abc" ~
5776 mapcheck("a") yes yes yes
5777 mapcheck("abc") yes yes yes
5778 mapcheck("ax") yes no no
5779 mapcheck("b") no no no
5780
5781 The difference with maparg() is that mapcheck() finds a
5782 mapping that matches with {name}, while maparg() only finds a
5783 mapping for {name} exactly.
5784 When there is no mapping that starts with {name}, an empty
5785 String is returned. If there is one, the RHS of that mapping
5786 is returned. If there are several mappings that start with
5787 {name}, the RHS of one of them is returned. This will be
5788 "<Nop>" if the RHS is empty.
5789 The mappings local to the current buffer are checked first,
5790 then the global mappings.
5791 This function can be used to check if a mapping can be added
5792 without being ambiguous. Example: >
5793 :if mapcheck("_vv") == ""
5794 : map _vv :set guifont=7x13<CR>
5795 :endif
5796< This avoids adding the "_vv" mapping when there already is a
5797 mapping for "_v" or for "_vvv".
5798
5799 Can also be used as a |method|: >
5800 GetKey()->mapcheck('n')
5801
5802
Ernie Rael09661202022-04-25 14:40:44 +01005803maplist([{abbr}]) *maplist()*
5804 Returns a |List| of all mappings. Each List item is a |Dict|,
5805 the same as what is returned by |maparg()|, see
5806 |mapping-dict|. When {abbr} is there and it is |TRUE| use
5807 abbreviations instead of mappings.
5808
5809 Example to show all mappings with 'MultiMatch' in rhs: >
5810 vim9script
5811 echo maplist()->filter(
5812 (_, m) => match(m.rhs, 'MultiMatch') >= 0)
Ernie Raeld8f5f762022-05-10 17:50:39 +01005813< It can be tricky to find mappings for particular |:map-modes|.
5814 |mapping-dict|'s "mode_bits" can simplify this. For example,
5815 the mode_bits for Normal, Insert or Command-line modes are
5816 0x19. To find all the mappings available in those modes you
5817 can do: >
5818 vim9script
5819 var saved_maps = []
5820 for m in maplist()
5821 if and(m.mode_bits, 0x19) != 0
5822 saved_maps->add(m)
5823 endif
5824 endfor
5825 echo saved_maps->mapnew((_, m) => m.lhs)
5826< The values of the mode_bits are defined in Vim's src/vim.h
5827 file and they can be discovered at runtime using
5828 |:map-commands| and "maplist()". Example: >
5829 vim9script
5830 omap xyzzy <Nop>
5831 var op_bit = maplist()->filter(
5832 (_, m) => m.lhs == 'xyzzy')[0].mode_bits
5833 ounmap xyzzy
5834 echo printf("Operator-pending mode bit: 0x%x", op_bit)
Ernie Rael09661202022-04-25 14:40:44 +01005835
5836
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005837mapnew({expr1}, {expr2}) *mapnew()*
5838 Like |map()| but instead of replacing items in {expr1} a new
5839 List or Dictionary is created and returned. {expr1} remains
5840 unchanged. Items can still be changed by {expr2}, if you
5841 don't want that use |deepcopy()| first.
5842
5843
5844mapset({mode}, {abbr}, {dict}) *mapset()*
Ernie Rael51d04d12022-05-04 15:40:22 +01005845mapset({dict})
5846 Restore a mapping from a dictionary, possibly returned by
5847 |maparg()| or |maplist()|. A buffer mapping, when dict.buffer
5848 is true, is set on the current buffer; it is up to the caller
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01005849 to ensure that the intended buffer is the current buffer. This
Ernie Rael51d04d12022-05-04 15:40:22 +01005850 feature allows copying mappings from one buffer to another.
5851 The dict.mode value may restore a single mapping that covers
5852 more than one mode, like with mode values of '!', ' ', 'nox',
5853 or 'v'. *E1276*
5854
5855 In the first form, {mode} and {abbr} should be the same as
5856 for the call to |maparg()|. *E460*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005857 {mode} is used to define the mode in which the mapping is set,
5858 not the "mode" entry in {dict}.
5859 Example for saving and restoring a mapping: >
5860 let save_map = maparg('K', 'n', 0, 1)
5861 nnoremap K somethingelse
5862 ...
5863 call mapset('n', 0, save_map)
5864< Note that if you are going to replace a map in several modes,
Ernie Rael51d04d12022-05-04 15:40:22 +01005865 e.g. with `:map!`, you need to save/restore the mapping for
5866 all of them, when they might differ.
5867
5868 In the second form, with {dict} as the only argument, mode
5869 and abbr are taken from the dict.
5870 Example: >
5871 vim9script
5872 var save_maps = maplist()->filter(
5873 (_, m) => m.lhs == 'K')
5874 nnoremap K somethingelse
5875 cnoremap K somethingelse2
5876 # ...
5877 unmap K
5878 for d in save_maps
5879 mapset(d)
5880 endfor
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005881
5882
5883match({expr}, {pat} [, {start} [, {count}]]) *match()*
5884 When {expr} is a |List| then this returns the index of the
5885 first item where {pat} matches. Each item is used as a
5886 String, |Lists| and |Dictionaries| are used as echoed.
5887
5888 Otherwise, {expr} is used as a String. The result is a
5889 Number, which gives the index (byte offset) in {expr} where
5890 {pat} matches.
5891
5892 A match at the first character or |List| item returns zero.
5893 If there is no match -1 is returned.
5894
5895 For getting submatches see |matchlist()|.
5896 Example: >
5897 :echo match("testing", "ing") " results in 4
5898 :echo match([1, 'x'], '\a') " results in 1
5899< See |string-match| for how {pat} is used.
5900 *strpbrk()*
5901 Vim doesn't have a strpbrk() function. But you can do: >
5902 :let sepidx = match(line, '[.,;: \t]')
5903< *strcasestr()*
5904 Vim doesn't have a strcasestr() function. But you can add
5905 "\c" to the pattern to ignore case: >
5906 :let idx = match(haystack, '\cneedle')
5907<
5908 If {start} is given, the search starts from byte index
5909 {start} in a String or item {start} in a |List|.
5910 The result, however, is still the index counted from the
5911 first character/item. Example: >
5912 :echo match("testing", "ing", 2)
5913< result is again "4". >
5914 :echo match("testing", "ing", 4)
5915< result is again "4". >
5916 :echo match("testing", "t", 2)
5917< result is "3".
5918 For a String, if {start} > 0 then it is like the string starts
5919 {start} bytes later, thus "^" will match at {start}. Except
5920 when {count} is given, then it's like matches before the
5921 {start} byte are ignored (this is a bit complicated to keep it
5922 backwards compatible).
5923 For a String, if {start} < 0, it will be set to 0. For a list
5924 the index is counted from the end.
5925 If {start} is out of range ({start} > strlen({expr}) for a
5926 String or {start} > len({expr}) for a |List|) -1 is returned.
5927
5928 When {count} is given use the {count}'th match. When a match
5929 is found in a String the search for the next one starts one
5930 character further. Thus this example results in 1: >
5931 echo match("testing", "..", 0, 2)
5932< In a |List| the search continues in the next item.
5933 Note that when {count} is added the way {start} works changes,
5934 see above.
5935
5936 See |pattern| for the patterns that are accepted.
5937 The 'ignorecase' option is used to set the ignore-caseness of
5938 the pattern. 'smartcase' is NOT used. The matching is always
5939 done like 'magic' is set and 'cpoptions' is empty.
5940 Note that a match at the start is preferred, thus when the
5941 pattern is using "*" (any number of matches) it tends to find
5942 zero matches at the start instead of a number of matches
5943 further down in the text.
5944
5945 Can also be used as a |method|: >
5946 GetText()->match('word')
5947 GetList()->match('word')
5948<
Bram Moolenaar2f0936c2022-01-08 21:51:59 +00005949 *matchadd()* *E290* *E798* *E799* *E801* *E957*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005950matchadd({group}, {pattern} [, {priority} [, {id} [, {dict}]]])
5951 Defines a pattern to be highlighted in the current window (a
5952 "match"). It will be highlighted with {group}. Returns an
5953 identification number (ID), which can be used to delete the
5954 match using |matchdelete()|. The ID is bound to the window.
5955 Matching is case sensitive and magic, unless case sensitivity
5956 or magicness are explicitly overridden in {pattern}. The
5957 'magic', 'smartcase' and 'ignorecase' options are not used.
5958 The "Conceal" value is special, it causes the match to be
5959 concealed.
5960
5961 The optional {priority} argument assigns a priority to the
5962 match. A match with a high priority will have its
5963 highlighting overrule that of a match with a lower priority.
5964 A priority is specified as an integer (negative numbers are no
5965 exception). If the {priority} argument is not specified, the
5966 default priority is 10. The priority of 'hlsearch' is zero,
5967 hence all matches with a priority greater than zero will
5968 overrule it. Syntax highlighting (see 'syntax') is a separate
5969 mechanism, and regardless of the chosen priority a match will
5970 always overrule syntax highlighting.
5971
5972 The optional {id} argument allows the request for a specific
5973 match ID. If a specified ID is already taken, an error
5974 message will appear and the match will not be added. An ID
5975 is specified as a positive integer (zero excluded). IDs 1, 2
5976 and 3 are reserved for |:match|, |:2match| and |:3match|,
Bram Moolenaar2ecbe532022-07-29 21:36:21 +01005977 respectively. 3 is reserved for use by the |matchparen|
5978 plugin.
Bram Moolenaarb529cfb2022-07-25 15:42:07 +01005979 If the {id} argument is not specified or -1, |matchadd()|
Bram Moolenaar9f573a82022-09-29 13:50:08 +01005980 automatically chooses a free ID, which is at least 1000.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005981
5982 The optional {dict} argument allows for further custom
5983 values. Currently this is used to specify a match specific
5984 conceal character that will be shown for |hl-Conceal|
5985 highlighted matches. The dict can have the following members:
5986
5987 conceal Special character to show instead of the
5988 match (only for |hl-Conceal| highlighted
5989 matches, see |:syn-cchar|)
5990 window Instead of the current window use the
5991 window with this number or window ID.
5992
5993 The number of matches is not limited, as it is the case with
5994 the |:match| commands.
5995
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01005996 Returns -1 on error.
5997
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005998 Example: >
5999 :highlight MyGroup ctermbg=green guibg=green
6000 :let m = matchadd("MyGroup", "TODO")
6001< Deletion of the pattern: >
6002 :call matchdelete(m)
6003
6004< A list of matches defined by |matchadd()| and |:match| are
6005 available from |getmatches()|. All matches can be deleted in
6006 one operation by |clearmatches()|.
6007
6008 Can also be used as a |method|: >
6009 GetGroup()->matchadd('TODO')
6010<
6011 *matchaddpos()*
6012matchaddpos({group}, {pos} [, {priority} [, {id} [, {dict}]]])
6013 Same as |matchadd()|, but requires a list of positions {pos}
6014 instead of a pattern. This command is faster than |matchadd()|
6015 because it does not require to handle regular expressions and
6016 sets buffer line boundaries to redraw screen. It is supposed
6017 to be used when fast match additions and deletions are
6018 required, for example to highlight matching parentheses.
6019
6020 {pos} is a list of positions. Each position can be one of
6021 these:
6022 - A number. This whole line will be highlighted. The first
6023 line has number 1.
6024 - A list with one number, e.g., [23]. The whole line with this
6025 number will be highlighted.
6026 - A list with two numbers, e.g., [23, 11]. The first number is
6027 the line number, the second one is the column number (first
6028 column is 1, the value must correspond to the byte index as
6029 |col()| would return). The character at this position will
6030 be highlighted.
6031 - A list with three numbers, e.g., [23, 11, 3]. As above, but
6032 the third number gives the length of the highlight in bytes.
6033
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01006034 Returns -1 on error.
6035
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006036 Example: >
6037 :highlight MyGroup ctermbg=green guibg=green
6038 :let m = matchaddpos("MyGroup", [[23, 24], 34])
6039< Deletion of the pattern: >
6040 :call matchdelete(m)
6041
6042< Matches added by |matchaddpos()| are returned by
6043 |getmatches()|.
6044
6045 Can also be used as a |method|: >
6046 GetGroup()->matchaddpos([23, 11])
6047
6048matcharg({nr}) *matcharg()*
6049 Selects the {nr} match item, as set with a |:match|,
6050 |:2match| or |:3match| command.
6051 Return a |List| with two elements:
6052 The name of the highlight group used
6053 The pattern used.
6054 When {nr} is not 1, 2 or 3 returns an empty |List|.
6055 When there is no match item set returns ['', ''].
6056 This is useful to save and restore a |:match|.
6057 Highlighting matches using the |:match| commands are limited
6058 to three matches. |matchadd()| does not have this limitation.
6059
6060 Can also be used as a |method|: >
6061 GetMatch()->matcharg()
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +01006062<
6063 *matchbufline()*
6064matchbufline({buf}, {pat}, {lnum}, {end}, [, {dict}])
6065 Returns the |List| of matches in lines from {lnum} to {end} in
6066 buffer {buf} where {pat} matches.
6067
6068 {lnum} and {end} can either be a line number or the string "$"
6069 to refer to the last line in {buf}.
6070
6071 The {dict} argument supports following items:
6072 submatches include submatch information (|/\(|)
6073
6074 For each match, a |Dict| with the following items is returned:
6075 byteidx starting byte index of the match
6076    lnum line number where there is a match
6077    text matched string
6078 Note that there can be multiple matches in a single line.
6079
6080 This function works only for loaded buffers. First call
6081 |bufload()| if needed.
6082
6083 When {buf} is not a valid buffer, the buffer is not loaded or
6084 {lnum} or {end} is not valid then an error is given and an
6085 empty |List| is returned.
6086
6087 Examples: >
6088    " Assuming line 3 in buffer 5 contains "a"
6089    :echo matchbufline(5, '\<\k\+\>', 3, 3)
6090    [{'lnum': 3, 'byteidx': 0, 'text': 'a'}]
6091    " Assuming line 4 in buffer 10 contains "tik tok"
6092    :echo matchbufline(10, '\<\k\+\>', 1, 4)
6093    [{'lnum': 4, 'byteidx': 0, 'text': 'tik'}, {'lnum': 4, 'byteidx': 4, 'text': 'tok'}]
6094<
6095 If {submatch} is present and is v:true, then submatches like
6096 "\1", "\2", etc. are also returned.  Example: >
6097    " Assuming line 2 in buffer 2 contains "acd"
6098    :echo matchbufline(2, '\(a\)\?\(b\)\?\(c\)\?\(.*\)', 2, 2
6099 \ {'submatches': v:true})
6100    [{'lnum': 2, 'byteidx': 0, 'text': 'acd', 'submatches': ['a', '', 'c', 'd', '', '', '', '', '']}]
6101< The "submatches" List always contains 9 items. If a submatch
6102 is not found, then an empty string is returned for that
6103 submatch.
6104
6105 Can also be used as a |method|: >
6106 GetBuffer()->matchbufline('mypat', 1, '$')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006107
6108matchdelete({id} [, {win}) *matchdelete()* *E802* *E803*
6109 Deletes a match with ID {id} previously defined by |matchadd()|
6110 or one of the |:match| commands. Returns 0 if successful,
6111 otherwise -1. See example for |matchadd()|. All matches can
6112 be deleted in one operation by |clearmatches()|.
6113 If {win} is specified, use the window with this number or
6114 window ID instead of the current window.
6115
6116 Can also be used as a |method|: >
6117 GetMatch()->matchdelete()
6118
6119matchend({expr}, {pat} [, {start} [, {count}]]) *matchend()*
6120 Same as |match()|, but return the index of first character
6121 after the match. Example: >
6122 :echo matchend("testing", "ing")
6123< results in "7".
6124 *strspn()* *strcspn()*
6125 Vim doesn't have a strspn() or strcspn() function, but you can
6126 do it with matchend(): >
6127 :let span = matchend(line, '[a-zA-Z]')
6128 :let span = matchend(line, '[^a-zA-Z]')
6129< Except that -1 is returned when there are no matches.
6130
6131 The {start}, if given, has the same meaning as for |match()|. >
6132 :echo matchend("testing", "ing", 2)
6133< results in "7". >
6134 :echo matchend("testing", "ing", 5)
6135< result is "-1".
6136 When {expr} is a |List| the result is equal to |match()|.
6137
6138 Can also be used as a |method|: >
6139 GetText()->matchend('word')
6140
6141
6142matchfuzzy({list}, {str} [, {dict}]) *matchfuzzy()*
6143 If {list} is a list of strings, then returns a |List| with all
6144 the strings in {list} that fuzzy match {str}. The strings in
6145 the returned list are sorted based on the matching score.
6146
6147 The optional {dict} argument always supports the following
6148 items:
zeertzjq9af2bc02022-05-11 14:15:37 +01006149 matchseq When this item is present return only matches
6150 that contain the characters in {str} in the
6151 given sequence.
Kazuyuki Miyagi47f1a552022-06-17 18:30:03 +01006152 limit Maximum number of matches in {list} to be
6153 returned. Zero means no limit.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006154
6155 If {list} is a list of dictionaries, then the optional {dict}
6156 argument supports the following additional items:
Yasuhiro Matsumoto9029a6e2022-04-16 12:35:35 +01006157 key Key of the item which is fuzzy matched against
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006158 {str}. The value of this item should be a
6159 string.
6160 text_cb |Funcref| that will be called for every item
6161 in {list} to get the text for fuzzy matching.
6162 This should accept a dictionary item as the
6163 argument and return the text for that item to
6164 use for fuzzy matching.
6165
6166 {str} is treated as a literal string and regular expression
6167 matching is NOT supported. The maximum supported {str} length
6168 is 256.
6169
6170 When {str} has multiple words each separated by white space,
6171 then the list of strings that have all the words is returned.
6172
6173 If there are no matching strings or there is an error, then an
6174 empty list is returned. If length of {str} is greater than
6175 256, then returns an empty list.
6176
Yasuhiro Matsumoto9029a6e2022-04-16 12:35:35 +01006177 When {limit} is given, matchfuzzy() will find up to this
6178 number of matches in {list} and return them in sorted order.
6179
Bram Moolenaar1588bc82022-03-08 21:35:07 +00006180 Refer to |fuzzy-matching| for more information about fuzzy
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006181 matching strings.
6182
6183 Example: >
6184 :echo matchfuzzy(["clay", "crow"], "cay")
6185< results in ["clay"]. >
6186 :echo getbufinfo()->map({_, v -> v.name})->matchfuzzy("ndl")
6187< results in a list of buffer names fuzzy matching "ndl". >
6188 :echo getbufinfo()->matchfuzzy("ndl", {'key' : 'name'})
6189< results in a list of buffer information dicts with buffer
6190 names fuzzy matching "ndl". >
6191 :echo getbufinfo()->matchfuzzy("spl",
6192 \ {'text_cb' : {v -> v.name}})
6193< results in a list of buffer information dicts with buffer
6194 names fuzzy matching "spl". >
6195 :echo v:oldfiles->matchfuzzy("test")
6196< results in a list of file names fuzzy matching "test". >
6197 :let l = readfile("buffer.c")->matchfuzzy("str")
6198< results in a list of lines in "buffer.c" fuzzy matching "str". >
6199 :echo ['one two', 'two one']->matchfuzzy('two one')
6200< results in ['two one', 'one two']. >
6201 :echo ['one two', 'two one']->matchfuzzy('two one',
6202 \ {'matchseq': 1})
6203< results in ['two one'].
6204
6205matchfuzzypos({list}, {str} [, {dict}]) *matchfuzzypos()*
6206 Same as |matchfuzzy()|, but returns the list of matched
6207 strings, the list of character positions where characters
6208 in {str} matches and a list of matching scores. You can
6209 use |byteidx()| to convert a character position to a byte
6210 position.
6211
6212 If {str} matches multiple times in a string, then only the
6213 positions for the best match is returned.
6214
6215 If there are no matching strings or there is an error, then a
6216 list with three empty list items is returned.
6217
6218 Example: >
6219 :echo matchfuzzypos(['testing'], 'tsg')
6220< results in [['testing'], [[0, 2, 6]], [99]] >
6221 :echo matchfuzzypos(['clay', 'lacy'], 'la')
6222< results in [['lacy', 'clay'], [[0, 1], [1, 2]], [153, 133]] >
6223 :echo [{'text': 'hello', 'id' : 10}]->matchfuzzypos('ll', {'key' : 'text'})
6224< results in [[{'id': 10, 'text': 'hello'}], [[2, 3]], [127]]
6225
6226matchlist({expr}, {pat} [, {start} [, {count}]]) *matchlist()*
6227 Same as |match()|, but return a |List|. The first item in the
6228 list is the matched string, same as what matchstr() would
6229 return. Following items are submatches, like "\1", "\2", etc.
6230 in |:substitute|. When an optional submatch didn't match an
6231 empty string is used. Example: >
6232 echo matchlist('acd', '\(a\)\?\(b\)\?\(c\)\?\(.*\)')
6233< Results in: ['acd', 'a', '', 'c', 'd', '', '', '', '', '']
6234 When there is no match an empty list is returned.
6235
6236 You can pass in a List, but that is not very useful.
6237
6238 Can also be used as a |method|: >
6239 GetText()->matchlist('word')
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +01006240<
6241 *matchstrlist()*
6242matchstrlist({list}, {pat} [, {dict}])
6243 Returns the |List| of matches in {list} where {pat} matches.
6244 {list} is a |List| of strings. {pat} is matched against each
6245 string in {list}.
6246
6247 The {dict} argument supports following items:
6248 submatches include submatch information (|/\(|)
6249
6250 For each match, a |Dict| with the following items is returned:
6251 byteidx starting byte index of the match.
6252 idx index in {list} of the match.
6253 text matched string
6254 submatches a List of submatches. Present only if
6255 "submatches" is set to v:true in {dict}.
6256
6257 Example: >
6258    :echo matchstrlist(['tik tok'], '\<\k\+\>')
6259    [{'idx': 0, 'byteidx': 0, 'text': 'tik'}, {'idx': 0, 'byteidx': 4, 'text': 'tok'}]
6260    :echo matchstrlist(['a', 'b'], '\<\k\+\>')
6261    [{'idx': 0, 'byteidx': 0, 'text': 'a'}, {'idx': 1, 'byteidx': 0, 'text': 'b'}]
6262<
6263 If "submatches" is present and is v:true, then submatches like
6264 "\1", "\2", etc. are also returned. Example: >
6265 :echo matchstrlist(['acd'], '\(a\)\?\(b\)\?\(c\)\?\(.*\)',
6266 \ #{submatches: v:true})
6267 [{'idx': 0, 'byteidx': 0, 'text': 'acd', 'submatches': ['a', '', 'c', 'd', '', '', '', '', '']}]
6268< The "submatches" List always contains 9 items. If a submatch
6269 is not found, then an empty string is returned for that
6270 submatch.
6271
6272 Can also be used as a |method|: >
6273 GetListOfStrings()->matchstrlist('mypat')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006274
6275matchstr({expr}, {pat} [, {start} [, {count}]]) *matchstr()*
6276 Same as |match()|, but return the matched string. Example: >
6277 :echo matchstr("testing", "ing")
6278< results in "ing".
6279 When there is no match "" is returned.
6280 The {start}, if given, has the same meaning as for |match()|. >
6281 :echo matchstr("testing", "ing", 2)
6282< results in "ing". >
6283 :echo matchstr("testing", "ing", 5)
6284< result is "".
6285 When {expr} is a |List| then the matching item is returned.
6286 The type isn't changed, it's not necessarily a String.
6287
6288 Can also be used as a |method|: >
6289 GetText()->matchstr('word')
6290
6291matchstrpos({expr}, {pat} [, {start} [, {count}]]) *matchstrpos()*
6292 Same as |matchstr()|, but return the matched string, the start
6293 position and the end position of the match. Example: >
6294 :echo matchstrpos("testing", "ing")
6295< results in ["ing", 4, 7].
6296 When there is no match ["", -1, -1] is returned.
6297 The {start}, if given, has the same meaning as for |match()|. >
6298 :echo matchstrpos("testing", "ing", 2)
6299< results in ["ing", 4, 7]. >
6300 :echo matchstrpos("testing", "ing", 5)
6301< result is ["", -1, -1].
6302 When {expr} is a |List| then the matching item, the index
6303 of first item where {pat} matches, the start position and the
6304 end position of the match are returned. >
6305 :echo matchstrpos([1, '__x'], '\a')
6306< result is ["x", 1, 2, 3].
6307 The type isn't changed, it's not necessarily a String.
6308
6309 Can also be used as a |method|: >
6310 GetText()->matchstrpos('word')
6311<
6312
6313 *max()*
6314max({expr}) Return the maximum value of all items in {expr}. Example: >
6315 echo max([apples, pears, oranges])
6316
6317< {expr} can be a |List| or a |Dictionary|. For a Dictionary,
6318 it returns the maximum of all values in the Dictionary.
6319 If {expr} is neither a List nor a Dictionary, or one of the
6320 items in {expr} cannot be used as a Number this results in
6321 an error. An empty |List| or |Dictionary| results in zero.
6322
6323 Can also be used as a |method|: >
6324 mylist->max()
6325
6326
6327menu_info({name} [, {mode}]) *menu_info()*
6328 Return information about the specified menu {name} in
6329 mode {mode}. The menu name should be specified without the
6330 shortcut character ('&'). If {name} is "", then the top-level
6331 menu names are returned.
6332
6333 {mode} can be one of these strings:
6334 "n" Normal
6335 "v" Visual (including Select)
6336 "o" Operator-pending
6337 "i" Insert
6338 "c" Cmd-line
6339 "s" Select
6340 "x" Visual
6341 "t" Terminal-Job
6342 "" Normal, Visual and Operator-pending
6343 "!" Insert and Cmd-line
6344 When {mode} is omitted, the modes for "" are used.
6345
6346 Returns a |Dictionary| containing the following items:
6347 accel menu item accelerator text |menu-text|
6348 display display name (name without '&')
6349 enabled v:true if this menu item is enabled
6350 Refer to |:menu-enable|
6351 icon name of the icon file (for toolbar)
6352 |toolbar-icon|
6353 iconidx index of a built-in icon
6354 modes modes for which the menu is defined. In
6355 addition to the modes mentioned above, these
6356 characters will be used:
6357 " " Normal, Visual and Operator-pending
6358 name menu item name.
6359 noremenu v:true if the {rhs} of the menu item is not
6360 remappable else v:false.
6361 priority menu order priority |menu-priority|
6362 rhs right-hand-side of the menu item. The returned
6363 string has special characters translated like
6364 in the output of the ":menu" command listing.
6365 When the {rhs} of a menu item is empty, then
6366 "<Nop>" is returned.
6367 script v:true if script-local remapping of {rhs} is
6368 allowed else v:false. See |:menu-script|.
6369 shortcut shortcut key (character after '&' in
6370 the menu name) |menu-shortcut|
6371 silent v:true if the menu item is created
6372 with <silent> argument |:menu-silent|
6373 submenus |List| containing the names of
6374 all the submenus. Present only if the menu
6375 item has submenus.
6376
6377 Returns an empty dictionary if the menu item is not found.
6378
6379 Examples: >
6380 :echo menu_info('Edit.Cut')
6381 :echo menu_info('File.Save', 'n')
6382
6383 " Display the entire menu hierarchy in a buffer
6384 func ShowMenu(name, pfx)
6385 let m = menu_info(a:name)
6386 call append(line('$'), a:pfx .. m.display)
6387 for child in m->get('submenus', [])
6388 call ShowMenu(a:name .. '.' .. escape(child, '.'),
6389 \ a:pfx .. ' ')
6390 endfor
6391 endfunc
6392 new
6393 for topmenu in menu_info('').submenus
6394 call ShowMenu(topmenu, '')
6395 endfor
6396<
6397 Can also be used as a |method|: >
6398 GetMenuName()->menu_info('v')
6399
6400
6401< *min()*
6402min({expr}) Return the minimum value of all items in {expr}. Example: >
6403 echo min([apples, pears, oranges])
6404
6405< {expr} can be a |List| or a |Dictionary|. For a Dictionary,
6406 it returns the minimum of all values in the Dictionary.
6407 If {expr} is neither a List nor a Dictionary, or one of the
6408 items in {expr} cannot be used as a Number this results in
6409 an error. An empty |List| or |Dictionary| results in zero.
6410
6411 Can also be used as a |method|: >
6412 mylist->min()
6413
6414< *mkdir()* *E739*
Bram Moolenaar938ae282023-02-20 20:44:55 +00006415mkdir({name} [, {flags} [, {prot}]])
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006416 Create directory {name}.
6417
Bram Moolenaar938ae282023-02-20 20:44:55 +00006418 When {flags} is present it must be a string. An empty string
6419 has no effect.
Bram Moolenaar6f14da12022-09-07 21:30:44 +01006420
Bram Moolenaar938ae282023-02-20 20:44:55 +00006421 If {flags} contains "p" then intermediate directories are
6422 created as necessary.
6423
6424 If {flags} contains "D" then {name} is deleted at the end of
Bram Moolenaar6f14da12022-09-07 21:30:44 +01006425 the current function, as with: >
6426 defer delete({name}, 'd')
6427<
Bram Moolenaar938ae282023-02-20 20:44:55 +00006428 If {flags} contains "R" then {name} is deleted recursively at
Bram Moolenaar6f14da12022-09-07 21:30:44 +01006429 the end of the current function, as with: >
6430 defer delete({name}, 'rf')
6431< Note that when {name} has more than one part and "p" is used
6432 some directories may already exist. Only the first one that
6433 is created and what it contains is scheduled to be deleted.
6434 E.g. when using: >
6435 call mkdir('subdir/tmp/autoload', 'pR')
6436< and "subdir" already exists then "subdir/tmp" will be
6437 scheduled for deletion, like with: >
6438 defer delete('subdir/tmp', 'rf')
6439< Note that if scheduling the defer fails the directory is not
6440 deleted. This should only happen when out of memory.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006441
6442 If {prot} is given it is used to set the protection bits of
6443 the new directory. The default is 0o755 (rwxr-xr-x: r/w for
6444 the user, readable for others). Use 0o700 to make it
6445 unreadable for others. This is only used for the last part of
6446 {name}. Thus if you create /tmp/foo/bar then /tmp/foo will be
6447 created with 0o755.
6448 Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00006449 :call mkdir($HOME .. "/tmp/foo/bar", "p", 0o700)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006450
6451< This function is not available in the |sandbox|.
6452
6453 There is no error if the directory already exists and the "p"
6454 flag is passed (since patch 8.0.1708). However, without the
6455 "p" option the call will fail.
6456
6457 The function result is a Number, which is TRUE if the call was
6458 successful or FALSE if the directory creation failed or partly
6459 failed.
6460
6461 Not available on all systems. To check use: >
6462 :if exists("*mkdir")
6463
6464< Can also be used as a |method|: >
6465 GetName()->mkdir()
6466<
6467 *mode()*
6468mode([expr]) Return a string that indicates the current mode.
6469 If [expr] is supplied and it evaluates to a non-zero Number or
6470 a non-empty String (|non-zero-arg|), then the full mode is
6471 returned, otherwise only the first letter is returned.
6472 Also see |state()|.
6473
6474 n Normal
6475 no Operator-pending
6476 nov Operator-pending (forced characterwise |o_v|)
6477 noV Operator-pending (forced linewise |o_V|)
6478 noCTRL-V Operator-pending (forced blockwise |o_CTRL-V|);
6479 CTRL-V is one character
6480 niI Normal using |i_CTRL-O| in |Insert-mode|
6481 niR Normal using |i_CTRL-O| in |Replace-mode|
6482 niV Normal using |i_CTRL-O| in |Virtual-Replace-mode|
6483 nt Terminal-Normal (insert goes to Terminal-Job mode)
6484 v Visual by character
6485 vs Visual by character using |v_CTRL-O| in Select mode
6486 V Visual by line
6487 Vs Visual by line using |v_CTRL-O| in Select mode
6488 CTRL-V Visual blockwise
6489 CTRL-Vs Visual blockwise using |v_CTRL-O| in Select mode
6490 s Select by character
6491 S Select by line
6492 CTRL-S Select blockwise
6493 i Insert
6494 ic Insert mode completion |compl-generic|
6495 ix Insert mode |i_CTRL-X| completion
6496 R Replace |R|
6497 Rc Replace mode completion |compl-generic|
6498 Rx Replace mode |i_CTRL-X| completion
6499 Rv Virtual Replace |gR|
6500 Rvc Virtual Replace mode completion |compl-generic|
6501 Rvx Virtual Replace mode |i_CTRL-X| completion
6502 c Command-line editing
h-east71ebf3b2023-09-03 17:12:55 +02006503 ct Command-line editing via Terminal-Job mode
zeertzjqfcaeb3d2023-11-28 20:46:29 +01006504 cr Command-line editing overstrike mode |c_<Insert>|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006505 cv Vim Ex mode |gQ|
zeertzjqfcaeb3d2023-11-28 20:46:29 +01006506 cvr Vim Ex mode while in overstrike mode |c_<Insert>|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006507 ce Normal Ex mode |Q|
6508 r Hit-enter prompt
6509 rm The -- more -- prompt
6510 r? A |:confirm| query of some sort
6511 ! Shell or external command is executing
6512 t Terminal-Job mode: keys go to the job
6513
6514 This is useful in the 'statusline' option or when used
6515 with |remote_expr()| In most other places it always returns
6516 "c" or "n".
6517 Note that in the future more modes and more specific modes may
6518 be added. It's better not to compare the whole string but only
6519 the leading character(s).
6520 Also see |visualmode()|.
6521
6522 Can also be used as a |method|: >
6523 DoFull()->mode()
6524
6525mzeval({expr}) *mzeval()*
6526 Evaluate MzScheme expression {expr} and return its result
6527 converted to Vim data structures.
6528 Numbers and strings are returned as they are.
6529 Pairs (including lists and improper lists) and vectors are
6530 returned as Vim |Lists|.
6531 Hash tables are represented as Vim |Dictionary| type with keys
6532 converted to strings.
6533 All other types are converted to string with display function.
6534 Examples: >
6535 :mz (define l (list 1 2 3))
6536 :mz (define h (make-hash)) (hash-set! h "list" l)
6537 :echo mzeval("l")
6538 :echo mzeval("h")
6539<
6540 Note that in a `:def` function local variables are not visible
6541 to {expr}.
6542
6543 Can also be used as a |method|: >
6544 GetExpr()->mzeval()
6545<
6546 {only available when compiled with the |+mzscheme| feature}
6547
6548nextnonblank({lnum}) *nextnonblank()*
6549 Return the line number of the first line at or below {lnum}
6550 that is not blank. Example: >
6551 if getline(nextnonblank(1)) =~ "Java"
6552< When {lnum} is invalid or there is no non-blank line at or
6553 below it, zero is returned.
6554 {lnum} is used like with |getline()|.
6555 See also |prevnonblank()|.
6556
6557 Can also be used as a |method|: >
6558 GetLnum()->nextnonblank()
6559
6560nr2char({expr} [, {utf8}]) *nr2char()*
6561 Return a string with a single character, which has the number
6562 value {expr}. Examples: >
6563 nr2char(64) returns "@"
6564 nr2char(32) returns " "
6565< When {utf8} is omitted or zero, the current 'encoding' is used.
6566 Example for "utf-8": >
6567 nr2char(300) returns I with bow character
6568< When {utf8} is TRUE, always return UTF-8 characters.
6569 Note that a NUL character in the file is specified with
6570 nr2char(10), because NULs are represented with newline
6571 characters. nr2char(0) is a real NUL and terminates the
6572 string, thus results in an empty string.
6573 To turn a list of character numbers into a string: >
6574 let list = [65, 66, 67]
6575 let str = join(map(list, {_, val -> nr2char(val)}), '')
6576< Result: "ABC"
6577
6578 Can also be used as a |method|: >
6579 GetNumber()->nr2char()
6580
6581or({expr}, {expr}) *or()*
6582 Bitwise OR on the two arguments. The arguments are converted
6583 to a number. A List, Dict or Float argument causes an error.
Bram Moolenaar5a6ec102022-05-27 21:58:00 +01006584 Also see `and()` and `xor()`.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006585 Example: >
6586 :let bits = or(bits, 0x80)
6587< Can also be used as a |method|: >
6588 :let bits = bits->or(0x80)
6589
Bram Moolenaar5a6ec102022-05-27 21:58:00 +01006590< Rationale: The reason this is a function and not using the "|"
6591 character like many languages, is that Vi has always used "|"
6592 to separate commands. In many places it would not be clear if
6593 "|" is an operator or a command separator.
6594
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006595
6596pathshorten({path} [, {len}]) *pathshorten()*
6597 Shorten directory names in the path {path} and return the
6598 result. The tail, the file name, is kept as-is. The other
6599 components in the path are reduced to {len} letters in length.
6600 If {len} is omitted or smaller than 1 then 1 is used (single
6601 letters). Leading '~' and '.' characters are kept. Examples: >
6602 :echo pathshorten('~/.vim/autoload/myfile.vim')
6603< ~/.v/a/myfile.vim ~
6604>
6605 :echo pathshorten('~/.vim/autoload/myfile.vim', 2)
6606< ~/.vi/au/myfile.vim ~
6607 It doesn't matter if the path exists or not.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01006608 Returns an empty string on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006609
6610 Can also be used as a |method|: >
6611 GetDirectories()->pathshorten()
6612
6613perleval({expr}) *perleval()*
6614 Evaluate Perl expression {expr} in scalar context and return
6615 its result converted to Vim data structures. If value can't be
6616 converted, it is returned as a string Perl representation.
6617 Note: If you want an array or hash, {expr} must return a
6618 reference to it.
6619 Example: >
6620 :echo perleval('[1 .. 4]')
6621< [1, 2, 3, 4]
6622
6623 Note that in a `:def` function local variables are not visible
6624 to {expr}.
6625
6626 Can also be used as a |method|: >
6627 GetExpr()->perleval()
6628
6629< {only available when compiled with the |+perl| feature}
6630
6631
6632popup_ functions are documented here: |popup-functions|
6633
6634
6635pow({x}, {y}) *pow()*
6636 Return the power of {x} to the exponent {y} as a |Float|.
6637 {x} and {y} must evaluate to a |Float| or a |Number|.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01006638 Returns 0.0 if {x} or {y} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006639 Examples: >
6640 :echo pow(3, 3)
6641< 27.0 >
6642 :echo pow(2, 16)
6643< 65536.0 >
6644 :echo pow(32, 0.20)
6645< 2.0
6646
6647 Can also be used as a |method|: >
6648 Compute()->pow(3)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006649
6650prevnonblank({lnum}) *prevnonblank()*
6651 Return the line number of the first line at or above {lnum}
6652 that is not blank. Example: >
6653 let ind = indent(prevnonblank(v:lnum - 1))
6654< When {lnum} is invalid or there is no non-blank line at or
6655 above it, zero is returned.
6656 {lnum} is used like with |getline()|.
6657 Also see |nextnonblank()|.
6658
6659 Can also be used as a |method|: >
6660 GetLnum()->prevnonblank()
6661
6662printf({fmt}, {expr1} ...) *printf()*
6663 Return a String with {fmt}, where "%" items are replaced by
6664 the formatted form of their respective arguments. Example: >
6665 printf("%4d: E%d %.30s", lnum, errno, msg)
6666< May result in:
6667 " 99: E42 asdfasdfasdfasdfasdfasdfasdfas" ~
6668
6669 When used as a |method| the base is passed as the second
6670 argument: >
6671 Compute()->printf("result: %d")
Bram Moolenaarcbaff5e2022-04-08 17:45:08 +01006672<
6673 You can use `call()` to pass the items as a list.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006674
Bram Moolenaarcbaff5e2022-04-08 17:45:08 +01006675 Often used items are:
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006676 %s string
6677 %6S string right-aligned in 6 display cells
6678 %6s string right-aligned in 6 bytes
6679 %.9s string truncated to 9 bytes
6680 %c single byte
6681 %d decimal number
6682 %5d decimal number padded with spaces to 5 characters
6683 %x hex number
6684 %04x hex number padded with zeros to at least 4 characters
6685 %X hex number using upper case letters
6686 %o octal number
6687 %08b binary number padded with zeros to at least 8 chars
6688 %f floating point number as 12.23, inf, -inf or nan
6689 %F floating point number as 12.23, INF, -INF or NAN
6690 %e floating point number as 1.23e3, inf, -inf or nan
6691 %E floating point number as 1.23E3, INF, -INF or NAN
6692 %g floating point number, as %f or %e depending on value
6693 %G floating point number, as %F or %E depending on value
6694 %% the % character itself
6695
6696 Conversion specifications start with '%' and end with the
6697 conversion type. All other characters are copied unchanged to
6698 the result.
6699
6700 The "%" starts a conversion specification. The following
6701 arguments appear in sequence:
6702
Christ van Willegen0c6181f2023-08-13 18:03:14 +02006703 % [pos-argument] [flags] [field-width] [.precision] type
6704
6705 pos-argument
6706 At most one positional argument specifier. These
6707 take the form {n$}, where n is >= 1.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006708
6709 flags
6710 Zero or more of the following flags:
6711
6712 # The value should be converted to an "alternate
6713 form". For c, d, and s conversions, this option
6714 has no effect. For o conversions, the precision
6715 of the number is increased to force the first
6716 character of the output string to a zero (except
6717 if a zero value is printed with an explicit
6718 precision of zero).
6719 For b and B conversions, a non-zero result has
6720 the string "0b" (or "0B" for B conversions)
6721 prepended to it.
6722 For x and X conversions, a non-zero result has
6723 the string "0x" (or "0X" for X conversions)
6724 prepended to it.
6725
6726 0 (zero) Zero padding. For all conversions the converted
6727 value is padded on the left with zeros rather
6728 than blanks. If a precision is given with a
6729 numeric conversion (d, b, B, o, x, and X), the 0
6730 flag is ignored.
6731
6732 - A negative field width flag; the converted value
6733 is to be left adjusted on the field boundary.
6734 The converted value is padded on the right with
6735 blanks, rather than on the left with blanks or
6736 zeros. A - overrides a 0 if both are given.
6737
6738 ' ' (space) A blank should be left before a positive
6739 number produced by a signed conversion (d).
6740
6741 + A sign must always be placed before a number
6742 produced by a signed conversion. A + overrides
6743 a space if both are used.
6744
6745 field-width
6746 An optional decimal digit string specifying a minimum
6747 field width. If the converted value has fewer bytes
6748 than the field width, it will be padded with spaces on
6749 the left (or right, if the left-adjustment flag has
6750 been given) to fill out the field width. For the S
6751 conversion the count is in cells.
6752
6753 .precision
6754 An optional precision, in the form of a period '.'
6755 followed by an optional digit string. If the digit
6756 string is omitted, the precision is taken as zero.
6757 This gives the minimum number of digits to appear for
6758 d, o, x, and X conversions, the maximum number of
6759 bytes to be printed from a string for s conversions,
6760 or the maximum number of cells to be printed from a
6761 string for S conversions.
6762 For floating point it is the number of digits after
6763 the decimal point.
6764
6765 type
6766 A character that specifies the type of conversion to
6767 be applied, see below.
6768
6769 A field width or precision, or both, may be indicated by an
6770 asterisk '*' instead of a digit string. In this case, a
6771 Number argument supplies the field width or precision. A
6772 negative field width is treated as a left adjustment flag
6773 followed by a positive field width; a negative precision is
6774 treated as though it were missing. Example: >
6775 :echo printf("%d: %.*s", nr, width, line)
6776< This limits the length of the text used from "line" to
6777 "width" bytes.
6778
Dominique Pellé17dca3c2023-12-14 20:36:32 +01006779 If the argument to be formatted is specified using a
6780 positional argument specifier, and a '*' is used to indicate
6781 that a number argument is to be used to specify the width or
Christ van Willegen0c6181f2023-08-13 18:03:14 +02006782 precision, the argument(s) to be used must also be specified
6783 using a {n$} positional argument specifier. See |printf-$|.
6784
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006785 The conversion specifiers and their meanings are:
6786
6787 *printf-d* *printf-b* *printf-B* *printf-o*
6788 *printf-x* *printf-X*
6789 dbBoxX The Number argument is converted to signed decimal
6790 (d), unsigned binary (b and B), unsigned octal (o), or
6791 unsigned hexadecimal (x and X) notation. The letters
6792 "abcdef" are used for x conversions; the letters
6793 "ABCDEF" are used for X conversions.
6794 The precision, if any, gives the minimum number of
6795 digits that must appear; if the converted value
6796 requires fewer digits, it is padded on the left with
6797 zeros.
6798 In no case does a non-existent or small field width
6799 cause truncation of a numeric field; if the result of
6800 a conversion is wider than the field width, the field
6801 is expanded to contain the conversion result.
6802 The 'h' modifier indicates the argument is 16 bits.
Christ van Willegenaa90d4f2023-09-03 17:22:37 +02006803 The 'l' modifier indicates the argument is a long
6804 integer. The size will be 32 bits or 64 bits
6805 depending on your platform.
6806 The "ll" modifier indicates the argument is 64 bits.
6807 The b and B conversion specifiers never take a width
6808 modifier and always assume their argument is a 64 bit
6809 integer.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006810 Generally, these modifiers are not useful. They are
6811 ignored when type is known from the argument.
6812
6813 i alias for d
6814 D alias for ld
6815 U alias for lu
6816 O alias for lo
6817
6818 *printf-c*
6819 c The Number argument is converted to a byte, and the
6820 resulting character is written.
6821
6822 *printf-s*
6823 s The text of the String argument is used. If a
6824 precision is specified, no more bytes than the number
6825 specified are used.
6826 If the argument is not a String type, it is
6827 automatically converted to text with the same format
6828 as ":echo".
6829 *printf-S*
6830 S The text of the String argument is used. If a
6831 precision is specified, no more display cells than the
6832 number specified are used.
6833
6834 *printf-f* *E807*
6835 f F The Float argument is converted into a string of the
6836 form 123.456. The precision specifies the number of
6837 digits after the decimal point. When the precision is
6838 zero the decimal point is omitted. When the precision
6839 is not specified 6 is used. A really big number
6840 (out of range or dividing by zero) results in "inf"
6841 or "-inf" with %f (INF or -INF with %F).
6842 "0.0 / 0.0" results in "nan" with %f (NAN with %F).
6843 Example: >
6844 echo printf("%.2f", 12.115)
6845< 12.12
6846 Note that roundoff depends on the system libraries.
6847 Use |round()| when in doubt.
6848
6849 *printf-e* *printf-E*
6850 e E The Float argument is converted into a string of the
6851 form 1.234e+03 or 1.234E+03 when using 'E'. The
6852 precision specifies the number of digits after the
6853 decimal point, like with 'f'.
6854
6855 *printf-g* *printf-G*
6856 g G The Float argument is converted like with 'f' if the
6857 value is between 0.001 (inclusive) and 10000000.0
6858 (exclusive). Otherwise 'e' is used for 'g' and 'E'
6859 for 'G'. When no precision is specified superfluous
6860 zeroes and '+' signs are removed, except for the zero
6861 immediately after the decimal point. Thus 10000000.0
6862 results in 1.0e7.
6863
6864 *printf-%*
6865 % A '%' is written. No argument is converted. The
6866 complete conversion specification is "%%".
6867
6868 When a Number argument is expected a String argument is also
6869 accepted and automatically converted.
6870 When a Float or String argument is expected a Number argument
6871 is also accepted and automatically converted.
6872 Any other argument type results in an error message.
6873
6874 *E766* *E767*
6875 The number of {exprN} arguments must exactly match the number
6876 of "%" items. If there are not sufficient or too many
6877 arguments an error is given. Up to 18 arguments can be used.
6878
Christ van Willegen0c6181f2023-08-13 18:03:14 +02006879 *printf-$*
6880 In certain languages, error and informative messages are
6881 more readable when the order of words is different from the
Christian Brabandtee17b6f2023-09-09 11:23:50 +02006882 corresponding message in English. To accommodate translations
Christ van Willegen0c6181f2023-08-13 18:03:14 +02006883 having a different word order, positional arguments may be
6884 used to indicate this. For instance: >
6885
h_east596a9f22023-11-21 21:24:23 +09006886 #, c-format
6887 msgid "%s returning %s"
6888 msgstr "waarde %2$s komt terug van %1$s"
Christ van Willegen0c6181f2023-08-13 18:03:14 +02006889<
h_east596a9f22023-11-21 21:24:23 +09006890 In this example, the sentence has its 2 string arguments
6891 reversed in the output. >
Christ van Willegen0c6181f2023-08-13 18:03:14 +02006892
h_east596a9f22023-11-21 21:24:23 +09006893 echo printf(
6894 "In The Netherlands, vim's creator's name is: %1$s %2$s",
6895 "Bram", "Moolenaar")
6896< In The Netherlands, vim's creator's name is: Bram Moolenaar >
Christ van Willegen0c6181f2023-08-13 18:03:14 +02006897
h_east596a9f22023-11-21 21:24:23 +09006898 echo printf(
6899 "In Belgium, vim's creator's name is: %2$s %1$s",
6900 "Bram", "Moolenaar")
6901< In Belgium, vim's creator's name is: Moolenaar Bram
Christ van Willegen0c6181f2023-08-13 18:03:14 +02006902
6903 Width (and precision) can be specified using the '*' specifier.
6904 In this case, you must specify the field width position in the
6905 argument list. >
6906
h_east596a9f22023-11-21 21:24:23 +09006907 echo printf("%1$*2$.*3$d", 1, 2, 3)
6908< 001 >
6909 echo printf("%2$*3$.*1$d", 1, 2, 3)
6910< 2 >
6911 echo printf("%3$*1$.*2$d", 1, 2, 3)
6912< 03 >
6913 echo printf("%1$*2$.*3$g", 1.4142, 2, 3)
6914< 1.414
Christ van Willegen0c6181f2023-08-13 18:03:14 +02006915
6916 You can mix specifying the width and/or precision directly
6917 and via positional arguments: >
6918
h_east596a9f22023-11-21 21:24:23 +09006919 echo printf("%1$4.*2$f", 1.4142135, 6)
6920< 1.414214 >
6921 echo printf("%1$*2$.4f", 1.4142135, 6)
6922< 1.4142 >
6923 echo printf("%1$*2$.*3$f", 1.4142135, 6, 2)
6924< 1.41
Christ van Willegen0c6181f2023-08-13 18:03:14 +02006925
Yegappan Lakshmanan413f8392023-09-28 22:46:37 +02006926 *E1500*
Christ van Willegen0c6181f2023-08-13 18:03:14 +02006927 You cannot mix positional and non-positional arguments: >
h_east596a9f22023-11-21 21:24:23 +09006928 echo printf("%s%1$s", "One", "Two")
6929< E1500: Cannot mix positional and non-positional arguments:
6930 %s%1$s
Christ van Willegen0c6181f2023-08-13 18:03:14 +02006931
Yegappan Lakshmanan413f8392023-09-28 22:46:37 +02006932 *E1501*
Christ van Willegen0c6181f2023-08-13 18:03:14 +02006933 You cannot skip a positional argument in a format string: >
h_east596a9f22023-11-21 21:24:23 +09006934 echo printf("%3$s%1$s", "One", "Two", "Three")
6935< E1501: format argument 2 unused in $-style format:
6936 %3$s%1$s
Christ van Willegen0c6181f2023-08-13 18:03:14 +02006937
Yegappan Lakshmanan413f8392023-09-28 22:46:37 +02006938 *E1502*
Christ van Willegen0c6181f2023-08-13 18:03:14 +02006939 You can re-use a [field-width] (or [precision]) argument: >
h_east596a9f22023-11-21 21:24:23 +09006940 echo printf("%1$d at width %2$d is: %01$*2$d", 1, 2)
6941< 1 at width 2 is: 01
Christ van Willegen0c6181f2023-08-13 18:03:14 +02006942
6943 However, you can't use it as a different type: >
h_east596a9f22023-11-21 21:24:23 +09006944 echo printf("%1$d at width %2$ld is: %01$*2$d", 1, 2)
6945< E1502: Positional argument 2 used as field width reused as
6946 different type: long int/int
Christ van Willegen0c6181f2023-08-13 18:03:14 +02006947
Yegappan Lakshmanan413f8392023-09-28 22:46:37 +02006948 *E1503*
Christ van Willegen0c6181f2023-08-13 18:03:14 +02006949 When a positional argument is used, but not the correct number
6950 or arguments is given, an error is raised: >
h_east596a9f22023-11-21 21:24:23 +09006951 echo printf("%1$d at width %2$d is: %01$*2$.*3$d", 1, 2)
6952< E1503: Positional argument 3 out of bounds: %1$d at width
6953 %2$d is: %01$*2$.*3$d
Christ van Willegen0c6181f2023-08-13 18:03:14 +02006954
6955 Only the first error is reported: >
h_east596a9f22023-11-21 21:24:23 +09006956 echo printf("%01$*2$.*3$d %4$d", 1, 2)
6957< E1503: Positional argument 3 out of bounds: %01$*2$.*3$d
6958 %4$d
Christ van Willegen0c6181f2023-08-13 18:03:14 +02006959
Yegappan Lakshmanan413f8392023-09-28 22:46:37 +02006960 *E1504*
Christ van Willegen0c6181f2023-08-13 18:03:14 +02006961 A positional argument can be used more than once: >
h_east596a9f22023-11-21 21:24:23 +09006962 echo printf("%1$s %2$s %1$s", "One", "Two")
6963< One Two One
Christ van Willegen0c6181f2023-08-13 18:03:14 +02006964
6965 However, you can't use a different type the second time: >
h_east596a9f22023-11-21 21:24:23 +09006966 echo printf("%1$s %2$s %1$d", "One", "Two")
6967< E1504: Positional argument 1 type used inconsistently:
6968 int/string
Christ van Willegen0c6181f2023-08-13 18:03:14 +02006969
Yegappan Lakshmanan413f8392023-09-28 22:46:37 +02006970 *E1505*
Christ van Willegen0c6181f2023-08-13 18:03:14 +02006971 Various other errors that lead to a format string being
6972 wrongly formatted lead to: >
h_east596a9f22023-11-21 21:24:23 +09006973 echo printf("%1$d at width %2$d is: %01$*2$.3$d", 1, 2)
6974< E1505: Invalid format specifier: %1$d at width %2$d is:
6975 %01$*2$.3$d
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006976
Christ van Willegenea746f92023-10-05 20:48:36 +02006977 *E1507*
zeertzjq27e12c72023-10-07 01:34:04 +08006978 This internal error indicates that the logic to parse a
6979 positional format argument ran into a problem that couldn't be
6980 otherwise reported. Please file a bug against Vim if you run
6981 into this, copying the exact format string and parameters that
6982 were used.
Christ van Willegenea746f92023-10-05 20:48:36 +02006983
6984
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006985prompt_getprompt({buf}) *prompt_getprompt()*
6986 Returns the effective prompt text for buffer {buf}. {buf} can
6987 be a buffer name or number. See |prompt-buffer|.
6988
6989 If the buffer doesn't exist or isn't a prompt buffer, an empty
6990 string is returned.
6991
6992 Can also be used as a |method|: >
6993 GetBuffer()->prompt_getprompt()
6994
6995< {only available when compiled with the |+channel| feature}
6996
6997
6998prompt_setcallback({buf}, {expr}) *prompt_setcallback()*
6999 Set prompt callback for buffer {buf} to {expr}. When {expr}
7000 is an empty string the callback is removed. This has only
7001 effect if {buf} has 'buftype' set to "prompt".
7002
7003 The callback is invoked when pressing Enter. The current
7004 buffer will always be the prompt buffer. A new line for a
7005 prompt is added before invoking the callback, thus the prompt
7006 for which the callback was invoked will be in the last but one
7007 line.
7008 If the callback wants to add text to the buffer, it must
7009 insert it above the last line, since that is where the current
7010 prompt is. This can also be done asynchronously.
7011 The callback is invoked with one argument, which is the text
7012 that was entered at the prompt. This can be an empty string
7013 if the user only typed Enter.
7014 Example: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007015 func s:TextEntered(text)
7016 if a:text == 'exit' || a:text == 'quit'
7017 stopinsert
Bram Moolenaarb7398fe2023-05-14 18:50:25 +01007018 " Reset 'modified' to allow the buffer to be closed.
7019 " We assume there is nothing useful to be saved.
7020 set nomodified
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007021 close
7022 else
Bram Moolenaarb7398fe2023-05-14 18:50:25 +01007023 " Do something useful with "a:text". In this example
7024 " we just repeat it.
Bram Moolenaarc51cf032022-02-26 12:25:45 +00007025 call append(line('$') - 1, 'Entered: "' .. a:text .. '"')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007026 endif
7027 endfunc
Bram Moolenaarb7398fe2023-05-14 18:50:25 +01007028 call prompt_setcallback(bufnr(), function('s:TextEntered'))
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007029
7030< Can also be used as a |method|: >
7031 GetBuffer()->prompt_setcallback(callback)
7032
7033< {only available when compiled with the |+channel| feature}
7034
7035prompt_setinterrupt({buf}, {expr}) *prompt_setinterrupt()*
7036 Set a callback for buffer {buf} to {expr}. When {expr} is an
7037 empty string the callback is removed. This has only effect if
7038 {buf} has 'buftype' set to "prompt".
7039
7040 This callback will be invoked when pressing CTRL-C in Insert
7041 mode. Without setting a callback Vim will exit Insert mode,
7042 as in any buffer.
7043
7044 Can also be used as a |method|: >
7045 GetBuffer()->prompt_setinterrupt(callback)
7046
7047< {only available when compiled with the |+channel| feature}
7048
7049prompt_setprompt({buf}, {text}) *prompt_setprompt()*
7050 Set prompt for buffer {buf} to {text}. You most likely want
7051 {text} to end in a space.
7052 The result is only visible if {buf} has 'buftype' set to
7053 "prompt". Example: >
7054 call prompt_setprompt(bufnr(), 'command: ')
7055<
7056 Can also be used as a |method|: >
7057 GetBuffer()->prompt_setprompt('command: ')
7058
7059< {only available when compiled with the |+channel| feature}
7060
7061prop_ functions are documented here: |text-prop-functions|
7062
7063pum_getpos() *pum_getpos()*
7064 If the popup menu (see |ins-completion-menu|) is not visible,
7065 returns an empty |Dictionary|, otherwise, returns a
7066 |Dictionary| with the following keys:
7067 height nr of items visible
7068 width screen cells
7069 row top screen row (0 first row)
7070 col leftmost screen column (0 first col)
7071 size total nr of items
7072 scrollbar |TRUE| if scrollbar is visible
7073
7074 The values are the same as in |v:event| during
7075 |CompleteChanged|.
7076
7077pumvisible() *pumvisible()*
7078 Returns non-zero when the popup menu is visible, zero
7079 otherwise. See |ins-completion-menu|.
7080 This can be used to avoid some things that would remove the
7081 popup menu.
7082
7083py3eval({expr}) *py3eval()*
7084 Evaluate Python expression {expr} and return its result
7085 converted to Vim data structures.
7086 Numbers and strings are returned as they are (strings are
7087 copied though, Unicode strings are additionally converted to
7088 'encoding').
7089 Lists are represented as Vim |List| type.
7090 Dictionaries are represented as Vim |Dictionary| type with
7091 keys converted to strings.
7092 Note that in a `:def` function local variables are not visible
7093 to {expr}.
7094
7095 Can also be used as a |method|: >
7096 GetExpr()->py3eval()
7097
7098< {only available when compiled with the |+python3| feature}
7099
7100 *E858* *E859*
7101pyeval({expr}) *pyeval()*
7102 Evaluate Python expression {expr} and return its result
7103 converted to Vim data structures.
7104 Numbers and strings are returned as they are (strings are
7105 copied though).
7106 Lists are represented as Vim |List| type.
7107 Dictionaries are represented as Vim |Dictionary| type,
7108 non-string keys result in error.
7109 Note that in a `:def` function local variables are not visible
7110 to {expr}.
7111
7112 Can also be used as a |method|: >
7113 GetExpr()->pyeval()
7114
7115< {only available when compiled with the |+python| feature}
7116
7117pyxeval({expr}) *pyxeval()*
7118 Evaluate Python expression {expr} and return its result
7119 converted to Vim data structures.
7120 Uses Python 2 or 3, see |python_x| and 'pyxversion'.
7121 See also: |pyeval()|, |py3eval()|
7122
7123 Can also be used as a |method|: >
7124 GetExpr()->pyxeval()
7125
7126< {only available when compiled with the |+python| or the
7127 |+python3| feature}
7128
7129rand([{expr}]) *rand()* *random*
7130 Return a pseudo-random Number generated with an xoshiro128**
7131 algorithm using seed {expr}. The returned number is 32 bits,
7132 also on 64 bits systems, for consistency.
7133 {expr} can be initialized by |srand()| and will be updated by
7134 rand(). If {expr} is omitted, an internal seed value is used
7135 and updated.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01007136 Returns -1 if {expr} is invalid.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007137
7138 Examples: >
7139 :echo rand()
7140 :let seed = srand()
7141 :echo rand(seed)
7142 :echo rand(seed) % 16 " random number 0 - 15
7143<
7144
7145 *E726* *E727*
7146range({expr} [, {max} [, {stride}]]) *range()*
7147 Returns a |List| with Numbers:
7148 - If only {expr} is specified: [0, 1, ..., {expr} - 1]
7149 - If {max} is specified: [{expr}, {expr} + 1, ..., {max}]
7150 - If {stride} is specified: [{expr}, {expr} + {stride}, ...,
7151 {max}] (increasing {expr} with {stride} each time, not
7152 producing a value past {max}).
7153 When the maximum is one before the start the result is an
7154 empty list. When the maximum is more than one before the
7155 start this is an error.
7156 Examples: >
7157 range(4) " [0, 1, 2, 3]
7158 range(2, 4) " [2, 3, 4]
7159 range(2, 9, 3) " [2, 5, 8]
7160 range(2, -2, -1) " [2, 1, 0, -1, -2]
7161 range(0) " []
7162 range(2, 0) " error!
7163<
7164 Can also be used as a |method|: >
7165 GetExpr()->range()
7166<
7167
K.Takata11df3ae2022-10-19 14:02:40 +01007168readblob({fname} [, {offset} [, {size}]]) *readblob()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007169 Read file {fname} in binary mode and return a |Blob|.
K.Takata11df3ae2022-10-19 14:02:40 +01007170 If {offset} is specified, read the file from the specified
7171 offset. If it is a negative value, it is used as an offset
7172 from the end of the file. E.g., to read the last 12 bytes: >
7173 readblob('file.bin', -12)
7174< If {size} is specified, only the specified size will be read.
7175 E.g. to read the first 100 bytes of a file: >
7176 readblob('file.bin', 0, 100)
7177< If {size} is -1 or omitted, the whole data starting from
7178 {offset} will be read.
K.Takata43625762022-10-20 13:28:51 +01007179 This can be also used to read the data from a character device
7180 on Unix when {size} is explicitly set. Only if the device
7181 supports seeking {offset} can be used. Otherwise it should be
7182 zero. E.g. to read 10 bytes from a serial console: >
7183 readblob('/dev/ttyS0', 0, 10)
7184< When the file can't be opened an error message is given and
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007185 the result is an empty |Blob|.
Bram Moolenaar5b2a3d72022-10-21 11:25:30 +01007186 When the offset is beyond the end of the file the result is an
7187 empty blob.
7188 When trying to read more bytes than are available the result
7189 is truncated.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007190 Also see |readfile()| and |writefile()|.
7191
7192
7193readdir({directory} [, {expr} [, {dict}]]) *readdir()*
7194 Return a list with file and directory names in {directory}.
7195 You can also use |glob()| if you don't need to do complicated
7196 things, such as limiting the number of matches.
7197 The list will be sorted (case sensitive), see the {dict}
7198 argument below for changing the sort order.
7199
7200 When {expr} is omitted all entries are included.
7201 When {expr} is given, it is evaluated to check what to do:
7202 If {expr} results in -1 then no further entries will
7203 be handled.
7204 If {expr} results in 0 then this entry will not be
7205 added to the list.
7206 If {expr} results in 1 then this entry will be added
7207 to the list.
7208 The entries "." and ".." are always excluded.
7209 Each time {expr} is evaluated |v:val| is set to the entry name.
7210 When {expr} is a function the name is passed as the argument.
7211 For example, to get a list of files ending in ".txt": >
7212 readdir(dirname, {n -> n =~ '.txt$'})
7213< To skip hidden and backup files: >
7214 readdir(dirname, {n -> n !~ '^\.\|\~$'})
Bram Moolenaar6f4754b2022-01-23 12:07:04 +00007215< *E857*
7216 The optional {dict} argument allows for further custom
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007217 values. Currently this is used to specify if and how sorting
7218 should be performed. The dict can have the following members:
7219
7220 sort How to sort the result returned from the system.
7221 Valid values are:
7222 "none" do not sort (fastest method)
7223 "case" sort case sensitive (byte value of
7224 each character, technically, using
7225 strcmp()) (default)
7226 "icase" sort case insensitive (technically
7227 using strcasecmp())
7228 "collate" sort using the collation order
7229 of the "POSIX" or "C" |locale|
7230 (technically using strcoll())
7231 Other values are silently ignored.
7232
7233 For example, to get a list of all files in the current
7234 directory without sorting the individual entries: >
7235 readdir('.', '1', #{sort: 'none'})
7236< If you want to get a directory tree: >
7237 function! s:tree(dir)
7238 return {a:dir : map(readdir(a:dir),
7239 \ {_, x -> isdirectory(x) ?
Bram Moolenaarc51cf032022-02-26 12:25:45 +00007240 \ {x : s:tree(a:dir .. '/' .. x)} : x})}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007241 endfunction
7242 echo s:tree(".")
7243<
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01007244 Returns an empty List on error.
7245
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007246 Can also be used as a |method|: >
7247 GetDirName()->readdir()
7248<
7249readdirex({directory} [, {expr} [, {dict}]]) *readdirex()*
7250 Extended version of |readdir()|.
7251 Return a list of Dictionaries with file and directory
7252 information in {directory}.
7253 This is useful if you want to get the attributes of file and
7254 directory at the same time as getting a list of a directory.
7255 This is much faster than calling |readdir()| then calling
7256 |getfperm()|, |getfsize()|, |getftime()| and |getftype()| for
7257 each file and directory especially on MS-Windows.
7258 The list will by default be sorted by name (case sensitive),
7259 the sorting can be changed by using the optional {dict}
7260 argument, see |readdir()|.
7261
7262 The Dictionary for file and directory information has the
7263 following items:
7264 group Group name of the entry. (Only on Unix)
7265 name Name of the entry.
7266 perm Permissions of the entry. See |getfperm()|.
7267 size Size of the entry. See |getfsize()|.
7268 time Timestamp of the entry. See |getftime()|.
7269 type Type of the entry.
7270 On Unix, almost same as |getftype()| except:
7271 Symlink to a dir "linkd"
7272 Other symlink "link"
7273 On MS-Windows:
7274 Normal file "file"
7275 Directory "dir"
7276 Junction "junction"
7277 Symlink to a dir "linkd"
7278 Other symlink "link"
7279 Other reparse point "reparse"
7280 user User name of the entry's owner. (Only on Unix)
7281 On Unix, if the entry is a symlink, the Dictionary includes
7282 the information of the target (except the "type" item).
7283 On MS-Windows, it includes the information of the symlink
7284 itself because of performance reasons.
7285
7286 When {expr} is omitted all entries are included.
7287 When {expr} is given, it is evaluated to check what to do:
7288 If {expr} results in -1 then no further entries will
7289 be handled.
7290 If {expr} results in 0 then this entry will not be
7291 added to the list.
7292 If {expr} results in 1 then this entry will be added
7293 to the list.
7294 The entries "." and ".." are always excluded.
7295 Each time {expr} is evaluated |v:val| is set to a |Dictionary|
7296 of the entry.
7297 When {expr} is a function the entry is passed as the argument.
7298 For example, to get a list of files ending in ".txt": >
7299 readdirex(dirname, {e -> e.name =~ '.txt$'})
7300<
7301 For example, to get a list of all files in the current
7302 directory without sorting the individual entries: >
7303 readdirex(dirname, '1', #{sort: 'none'})
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007304<
7305 Can also be used as a |method|: >
7306 GetDirName()->readdirex()
7307<
7308
7309 *readfile()*
7310readfile({fname} [, {type} [, {max}]])
7311 Read file {fname} and return a |List|, each line of the file
7312 as an item. Lines are broken at NL characters. Macintosh
7313 files separated with CR will result in a single long line
7314 (unless a NL appears somewhere).
7315 All NUL characters are replaced with a NL character.
7316 When {type} contains "b" binary mode is used:
7317 - When the last line ends in a NL an extra empty list item is
7318 added.
7319 - No CR characters are removed.
7320 Otherwise:
7321 - CR characters that appear before a NL are removed.
7322 - Whether the last line ends in a NL or not does not matter.
7323 - When 'encoding' is Unicode any UTF-8 byte order mark is
7324 removed from the text.
7325 When {max} is given this specifies the maximum number of lines
7326 to be read. Useful if you only want to check the first ten
7327 lines of a file: >
7328 :for line in readfile(fname, '', 10)
7329 : if line =~ 'Date' | echo line | endif
7330 :endfor
7331< When {max} is negative -{max} lines from the end of the file
7332 are returned, or as many as there are.
7333 When {max} is zero the result is an empty list.
7334 Note that without {max} the whole file is read into memory.
7335 Also note that there is no recognition of encoding. Read a
7336 file into a buffer if you need to.
7337 Deprecated (use |readblob()| instead): When {type} contains
7338 "B" a |Blob| is returned with the binary data of the file
7339 unmodified.
7340 When the file can't be opened an error message is given and
7341 the result is an empty list.
7342 Also see |writefile()|.
7343
7344 Can also be used as a |method|: >
7345 GetFileName()->readfile()
7346
7347reduce({object}, {func} [, {initial}]) *reduce()* *E998*
7348 {func} is called for every item in {object}, which can be a
7349 |String|, |List| or a |Blob|. {func} is called with two
7350 arguments: the result so far and current item. After
Bram Moolenaarf10911e2022-01-29 22:20:48 +00007351 processing all items the result is returned. *E1132*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007352
7353 {initial} is the initial result. When omitted, the first item
7354 in {object} is used and {func} is first called for the second
7355 item. If {initial} is not given and {object} is empty no
7356 result can be computed, an E998 error is given.
7357
7358 Examples: >
7359 echo reduce([1, 3, 5], { acc, val -> acc + val })
7360 echo reduce(['x', 'y'], { acc, val -> acc .. val }, 'a')
7361 echo reduce(0z1122, { acc, val -> 2 * acc + val })
7362 echo reduce('xyz', { acc, val -> acc .. ',' .. val })
7363<
7364 Can also be used as a |method|: >
7365 echo mylist->reduce({ acc, val -> acc + val }, 0)
7366
7367
7368reg_executing() *reg_executing()*
7369 Returns the single letter name of the register being executed.
7370 Returns an empty string when no register is being executed.
7371 See |@|.
7372
7373reg_recording() *reg_recording()*
7374 Returns the single letter name of the register being recorded.
7375 Returns an empty string when not recording. See |q|.
7376
Bram Moolenaarf269eab2022-10-03 18:04:35 +01007377reltime()
7378reltime({start})
7379reltime({start}, {end}) *reltime()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007380 Return an item that represents a time value. The item is a
7381 list with items that depend on the system. In Vim 9 script
Bram Moolenaar71badf92023-04-22 22:40:14 +01007382 the type list<any> can be used.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007383 The item can be passed to |reltimestr()| to convert it to a
Bram Moolenaarf269eab2022-10-03 18:04:35 +01007384 string or |reltimefloat()| to convert to a Float. For
7385 example, to see the time spent in function Work(): >
7386 var startTime = reltime()
7387 Work()
7388 echo startTime->reltime()->reltimestr()
7389<
Bram Moolenaar016188f2022-06-06 20:52:59 +01007390 Without an argument reltime() returns the current time (the
Bram Moolenaareb490412022-06-28 13:44:46 +01007391 representation is system-dependent, it can not be used as the
Bram Moolenaar016188f2022-06-06 20:52:59 +01007392 wall-clock time, see |localtime()| for that).
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007393 With one argument is returns the time passed since the time
7394 specified in the argument.
7395 With two arguments it returns the time passed between {start}
7396 and {end}.
7397
7398 The {start} and {end} arguments must be values returned by
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01007399 reltime(). If there is an error an empty List is returned in
7400 legacy script, in Vim9 script an error is given.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007401
7402 Can also be used as a |method|: >
7403 GetStart()->reltime()
7404<
7405 {only available when compiled with the |+reltime| feature}
7406
7407reltimefloat({time}) *reltimefloat()*
7408 Return a Float that represents the time value of {time}.
7409 Example: >
7410 let start = reltime()
7411 call MyFunction()
7412 let seconds = reltimefloat(reltime(start))
7413< See the note of reltimestr() about overhead.
7414 Also see |profiling|.
7415 If there is an error 0.0 is returned in legacy script, in Vim9
7416 script an error is given.
7417
7418 Can also be used as a |method|: >
7419 reltime(start)->reltimefloat()
7420
7421< {only available when compiled with the |+reltime| feature}
7422
7423reltimestr({time}) *reltimestr()*
7424 Return a String that represents the time value of {time}.
7425 This is the number of seconds, a dot and the number of
7426 microseconds. Example: >
7427 let start = reltime()
7428 call MyFunction()
7429 echo reltimestr(reltime(start))
7430< Note that overhead for the commands will be added to the time.
Ernie Rael076de792023-03-16 21:43:15 +00007431 The accuracy depends on the system. Use reltimefloat() for the
7432 greatest accuracy which is nanoseconds on some systems.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007433 Leading spaces are used to make the string align nicely. You
7434 can use split() to remove it. >
7435 echo split(reltimestr(reltime(start)))[0]
7436< Also see |profiling|.
7437 If there is an error an empty string is returned in legacy
7438 script, in Vim9 script an error is given.
7439
7440 Can also be used as a |method|: >
7441 reltime(start)->reltimestr()
7442
7443< {only available when compiled with the |+reltime| feature}
7444
7445 *remote_expr()* *E449*
7446remote_expr({server}, {string} [, {idvar} [, {timeout}]])
Bram Moolenaar944697a2022-02-20 19:48:20 +00007447 Send the {string} to {server}. The {server} argument is a
7448 string, also see |{server}|.
7449
7450 The string is sent as an expression and the result is returned
7451 after evaluation. The result must be a String or a |List|. A
7452 |List| is turned into a String by joining the items with a
7453 line break in between (not at the end), like with join(expr,
7454 "\n").
7455
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007456 If {idvar} is present and not empty, it is taken as the name
7457 of a variable and a {serverid} for later use with
7458 |remote_read()| is stored there.
Bram Moolenaar944697a2022-02-20 19:48:20 +00007459
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007460 If {timeout} is given the read times out after this many
7461 seconds. Otherwise a timeout of 600 seconds is used.
Bram Moolenaar944697a2022-02-20 19:48:20 +00007462
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007463 See also |clientserver| |RemoteReply|.
7464 This function is not available in the |sandbox|.
7465 {only available when compiled with the |+clientserver| feature}
7466 Note: Any errors will cause a local error message to be issued
7467 and the result will be the empty string.
7468
7469 Variables will be evaluated in the global namespace,
7470 independent of a function currently being active. Except
7471 when in debug mode, then local function variables and
7472 arguments can be evaluated.
7473
7474 Examples: >
7475 :echo remote_expr("gvim", "2+2")
7476 :echo remote_expr("gvim1", "b:current_syntax")
7477<
7478 Can also be used as a |method|: >
7479 ServerName()->remote_expr(expr)
7480
7481remote_foreground({server}) *remote_foreground()*
7482 Move the Vim server with the name {server} to the foreground.
Bram Moolenaar944697a2022-02-20 19:48:20 +00007483 The {server} argument is a string, also see |{server}|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007484 This works like: >
7485 remote_expr({server}, "foreground()")
7486< Except that on Win32 systems the client does the work, to work
7487 around the problem that the OS doesn't always allow the server
7488 to bring itself to the foreground.
7489 Note: This does not restore the window if it was minimized,
7490 like foreground() does.
7491 This function is not available in the |sandbox|.
7492
7493 Can also be used as a |method|: >
7494 ServerName()->remote_foreground()
7495
Bram Moolenaarcbaff5e2022-04-08 17:45:08 +01007496< {only in the Win32, Motif and GTK GUI versions and the
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007497 Win32 console version}
7498
7499
7500remote_peek({serverid} [, {retvar}]) *remote_peek()*
7501 Returns a positive number if there are available strings
7502 from {serverid}. Copies any reply string into the variable
7503 {retvar} if specified. {retvar} must be a string with the
7504 name of a variable.
7505 Returns zero if none are available.
7506 Returns -1 if something is wrong.
7507 See also |clientserver|.
7508 This function is not available in the |sandbox|.
7509 {only available when compiled with the |+clientserver| feature}
7510 Examples: >
Bram Moolenaarf269eab2022-10-03 18:04:35 +01007511 :let repl = ""
7512 :echo "PEEK: " .. remote_peek(id, "repl") .. ": " .. repl
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007513
7514< Can also be used as a |method|: >
7515 ServerId()->remote_peek()
7516
7517remote_read({serverid}, [{timeout}]) *remote_read()*
7518 Return the oldest available reply from {serverid} and consume
7519 it. Unless a {timeout} in seconds is given, it blocks until a
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01007520 reply is available. Returns an empty string, if a reply is
7521 not available or on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007522 See also |clientserver|.
7523 This function is not available in the |sandbox|.
7524 {only available when compiled with the |+clientserver| feature}
7525 Example: >
7526 :echo remote_read(id)
7527
7528< Can also be used as a |method|: >
7529 ServerId()->remote_read()
7530<
7531 *remote_send()* *E241*
7532remote_send({server}, {string} [, {idvar}])
Bram Moolenaar944697a2022-02-20 19:48:20 +00007533 Send the {string} to {server}. The {server} argument is a
7534 string, also see |{server}|.
7535
7536 The string is sent as input keys and the function returns
7537 immediately. At the Vim server the keys are not mapped
7538 |:map|.
7539
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007540 If {idvar} is present, it is taken as the name of a variable
7541 and a {serverid} for later use with remote_read() is stored
7542 there.
Bram Moolenaar944697a2022-02-20 19:48:20 +00007543
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007544 See also |clientserver| |RemoteReply|.
7545 This function is not available in the |sandbox|.
7546 {only available when compiled with the |+clientserver| feature}
7547
7548 Note: Any errors will be reported in the server and may mess
7549 up the display.
7550 Examples: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00007551 :echo remote_send("gvim", ":DropAndReply " .. file, "serverid") ..
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007552 \ remote_read(serverid)
7553
7554 :autocmd NONE RemoteReply *
7555 \ echo remote_read(expand("<amatch>"))
Bram Moolenaarc51cf032022-02-26 12:25:45 +00007556 :echo remote_send("gvim", ":sleep 10 | echo " ..
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007557 \ 'server2client(expand("<client>"), "HELLO")<CR>')
7558<
7559 Can also be used as a |method|: >
7560 ServerName()->remote_send(keys)
7561<
7562 *remote_startserver()* *E941* *E942*
7563remote_startserver({name})
h-east17b69512023-05-01 22:36:56 +01007564 Become the server {name}. {name} must be a non-empty string.
7565 This fails if already running as a server, when |v:servername|
7566 is not empty.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007567
7568 Can also be used as a |method|: >
7569 ServerName()->remote_startserver()
7570
7571< {only available when compiled with the |+clientserver| feature}
7572
Bram Moolenaarf269eab2022-10-03 18:04:35 +01007573remove({list}, {idx})
7574remove({list}, {idx}, {end}) *remove()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007575 Without {end}: Remove the item at {idx} from |List| {list} and
7576 return the item.
7577 With {end}: Remove items from {idx} to {end} (inclusive) and
7578 return a |List| with these items. When {idx} points to the same
7579 item as {end} a list with one item is returned. When {end}
7580 points to an item before {idx} this is an error.
7581 See |list-index| for possible values of {idx} and {end}.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01007582 Returns zero on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007583 Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00007584 :echo "last item: " .. remove(mylist, -1)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007585 :call remove(mylist, 0, 9)
7586<
7587 Use |delete()| to remove a file.
7588
7589 Can also be used as a |method|: >
7590 mylist->remove(idx)
7591
Bram Moolenaarf269eab2022-10-03 18:04:35 +01007592remove({blob}, {idx})
7593remove({blob}, {idx}, {end})
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007594 Without {end}: Remove the byte at {idx} from |Blob| {blob} and
7595 return the byte.
7596 With {end}: Remove bytes from {idx} to {end} (inclusive) and
7597 return a |Blob| with these bytes. When {idx} points to the same
7598 byte as {end} a |Blob| with one byte is returned. When {end}
7599 points to a byte before {idx} this is an error.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01007600 Returns zero on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007601 Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00007602 :echo "last byte: " .. remove(myblob, -1)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007603 :call remove(mylist, 0, 9)
7604
7605remove({dict}, {key})
7606 Remove the entry from {dict} with key {key} and return it.
7607 Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00007608 :echo "removed " .. remove(dict, "one")
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007609< If there is no {key} in {dict} this is an error.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01007610 Returns zero on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007611
7612rename({from}, {to}) *rename()*
7613 Rename the file by the name {from} to the name {to}. This
7614 should also work to move files across file systems. The
7615 result is a Number, which is 0 if the file was renamed
7616 successfully, and non-zero when the renaming failed.
7617 NOTE: If {to} exists it is overwritten without warning.
7618 This function is not available in the |sandbox|.
7619
7620 Can also be used as a |method|: >
7621 GetOldName()->rename(newname)
7622
7623repeat({expr}, {count}) *repeat()*
7624 Repeat {expr} {count} times and return the concatenated
7625 result. Example: >
7626 :let separator = repeat('-', 80)
7627< When {count} is zero or negative the result is empty.
Bakudankun375141e2022-09-09 18:46:47 +01007628 When {expr} is a |List| or a |Blob| the result is {expr}
7629 concatenated {count} times. Example: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007630 :let longlist = repeat(['a', 'b'], 3)
7631< Results in ['a', 'b', 'a', 'b', 'a', 'b'].
7632
7633 Can also be used as a |method|: >
7634 mylist->repeat(count)
7635
7636resolve({filename}) *resolve()* *E655*
7637 On MS-Windows, when {filename} is a shortcut (a .lnk file),
7638 returns the path the shortcut points to in a simplified form.
7639 When {filename} is a symbolic link or junction point, return
7640 the full path to the target. If the target of junction is
7641 removed, return {filename}.
7642 On Unix, repeat resolving symbolic links in all path
7643 components of {filename} and return the simplified result.
7644 To cope with link cycles, resolving of symbolic links is
7645 stopped after 100 iterations.
7646 On other systems, return the simplified {filename}.
7647 The simplification step is done as by |simplify()|.
7648 resolve() keeps a leading path component specifying the
7649 current directory (provided the result is still a relative
7650 path name) and also keeps a trailing path separator.
7651
7652 Can also be used as a |method|: >
7653 GetName()->resolve()
7654
7655reverse({object}) *reverse()*
Yegappan Lakshmanan03ff1c22023-05-06 14:08:21 +01007656 Reverse the order of items in {object}. {object} can be a
7657 |List|, a |Blob| or a |String|. For a List and a Blob the
7658 items are reversed in-place and {object} is returned.
7659 For a String a new String is returned.
7660 Returns zero if {object} is not a List, Blob or a String.
7661 If you want a List or Blob to remain unmodified make a copy
7662 first: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007663 :let revlist = reverse(copy(mylist))
7664< Can also be used as a |method|: >
7665 mylist->reverse()
7666
7667round({expr}) *round()*
7668 Round off {expr} to the nearest integral value and return it
7669 as a |Float|. If {expr} lies halfway between two integral
7670 values, then use the larger one (away from zero).
7671 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01007672 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007673 Examples: >
7674 echo round(0.456)
7675< 0.0 >
7676 echo round(4.5)
7677< 5.0 >
7678 echo round(-4.5)
7679< -5.0
7680
7681 Can also be used as a |method|: >
7682 Compute()->round()
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007683
7684rubyeval({expr}) *rubyeval()*
7685 Evaluate Ruby expression {expr} and return its result
7686 converted to Vim data structures.
7687 Numbers, floats and strings are returned as they are (strings
7688 are copied though).
7689 Arrays are represented as Vim |List| type.
7690 Hashes are represented as Vim |Dictionary| type.
7691 Other objects are represented as strings resulted from their
7692 "Object#to_s" method.
7693 Note that in a `:def` function local variables are not visible
7694 to {expr}.
7695
7696 Can also be used as a |method|: >
7697 GetRubyExpr()->rubyeval()
7698
7699< {only available when compiled with the |+ruby| feature}
7700
7701screenattr({row}, {col}) *screenattr()*
7702 Like |screenchar()|, but return the attribute. This is a rather
7703 arbitrary number that can only be used to compare to the
7704 attribute at other positions.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01007705 Returns -1 when row or col is out of range.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007706
7707 Can also be used as a |method|: >
7708 GetRow()->screenattr(col)
7709
7710screenchar({row}, {col}) *screenchar()*
7711 The result is a Number, which is the character at position
7712 [row, col] on the screen. This works for every possible
7713 screen position, also status lines, window separators and the
7714 command line. The top left position is row one, column one
7715 The character excludes composing characters. For double-byte
7716 encodings it may only be the first byte.
7717 This is mainly to be used for testing.
7718 Returns -1 when row or col is out of range.
7719
7720 Can also be used as a |method|: >
7721 GetRow()->screenchar(col)
7722
7723screenchars({row}, {col}) *screenchars()*
7724 The result is a |List| of Numbers. The first number is the same
7725 as what |screenchar()| returns. Further numbers are
7726 composing characters on top of the base character.
7727 This is mainly to be used for testing.
7728 Returns an empty List when row or col is out of range.
7729
7730 Can also be used as a |method|: >
7731 GetRow()->screenchars(col)
7732
7733screencol() *screencol()*
7734 The result is a Number, which is the current screen column of
7735 the cursor. The leftmost column has number 1.
7736 This function is mainly used for testing.
7737
7738 Note: Always returns the current screen column, thus if used
7739 in a command (e.g. ":echo screencol()") it will return the
7740 column inside the command line, which is 1 when the command is
7741 executed. To get the cursor position in the file use one of
7742 the following mappings: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00007743 nnoremap <expr> GG ":echom " .. screencol() .. "\n"
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007744 nnoremap <silent> GG :echom screencol()<CR>
7745 nnoremap GG <Cmd>echom screencol()<CR>
7746<
7747screenpos({winid}, {lnum}, {col}) *screenpos()*
7748 The result is a Dict with the screen position of the text
7749 character in window {winid} at buffer line {lnum} and column
7750 {col}. {col} is a one-based byte index.
7751 The Dict has these members:
7752 row screen row
7753 col first screen column
7754 endcol last screen column
7755 curscol cursor screen column
7756 If the specified position is not visible, all values are zero.
7757 The "endcol" value differs from "col" when the character
7758 occupies more than one screen cell. E.g. for a Tab "col" can
7759 be 1 and "endcol" can be 8.
7760 The "curscol" value is where the cursor would be placed. For
7761 a Tab it would be the same as "endcol", while for a double
7762 width character it would be the same as "col".
7763 The |conceal| feature is ignored here, the column numbers are
7764 as if 'conceallevel' is zero. You can set the cursor to the
7765 right position and use |screencol()| to get the value with
7766 |conceal| taken into account.
Bram Moolenaar944697a2022-02-20 19:48:20 +00007767 If the position is in a closed fold the screen position of the
7768 first character is returned, {col} is not used.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01007769 Returns an empty Dict if {winid} is invalid.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007770
7771 Can also be used as a |method|: >
7772 GetWinid()->screenpos(lnum, col)
7773
7774screenrow() *screenrow()*
7775 The result is a Number, which is the current screen row of the
7776 cursor. The top line has number one.
7777 This function is mainly used for testing.
7778 Alternatively you can use |winline()|.
7779
7780 Note: Same restrictions as with |screencol()|.
7781
7782screenstring({row}, {col}) *screenstring()*
7783 The result is a String that contains the base character and
7784 any composing characters at position [row, col] on the screen.
7785 This is like |screenchars()| but returning a String with the
7786 characters.
7787 This is mainly to be used for testing.
7788 Returns an empty String when row or col is out of range.
7789
7790 Can also be used as a |method|: >
7791 GetRow()->screenstring(col)
7792<
7793 *search()*
7794search({pattern} [, {flags} [, {stopline} [, {timeout} [, {skip}]]]])
7795 Search for regexp pattern {pattern}. The search starts at the
7796 cursor position (you can use |cursor()| to set it).
7797
7798 When a match has been found its line number is returned.
7799 If there is no match a 0 is returned and the cursor doesn't
7800 move. No error message is given.
7801
7802 {flags} is a String, which can contain these character flags:
7803 'b' search Backward instead of forward
7804 'c' accept a match at the Cursor position
7805 'e' move to the End of the match
7806 'n' do Not move the cursor
7807 'p' return number of matching sub-Pattern (see below)
7808 's' Set the ' mark at the previous location of the cursor
7809 'w' Wrap around the end of the file
7810 'W' don't Wrap around the end of the file
7811 'z' start searching at the cursor column instead of zero
7812 If neither 'w' or 'W' is given, the 'wrapscan' option applies.
7813
7814 If the 's' flag is supplied, the ' mark is set, only if the
7815 cursor is moved. The 's' flag cannot be combined with the 'n'
7816 flag.
7817
7818 'ignorecase', 'smartcase' and 'magic' are used.
7819
7820 When the 'z' flag is not given, forward searching always
7821 starts in column zero and then matches before the cursor are
7822 skipped. When the 'c' flag is present in 'cpo' the next
7823 search starts after the match. Without the 'c' flag the next
Bram Moolenaarfd999452022-08-24 18:30:14 +01007824 search starts one column after the start of the match. This
7825 matters for overlapping matches. See |cpo-c|. You can also
7826 insert "\ze" to change where the match ends, see |/\ze|.
7827
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007828 When searching backwards and the 'z' flag is given then the
7829 search starts in column zero, thus no match in the current
7830 line will be found (unless wrapping around the end of the
7831 file).
7832
7833 When the {stopline} argument is given then the search stops
7834 after searching this line. This is useful to restrict the
7835 search to a range of lines. Examples: >
7836 let match = search('(', 'b', line("w0"))
7837 let end = search('END', '', line("w$"))
7838< When {stopline} is used and it is not zero this also implies
7839 that the search does not wrap around the end of the file.
7840 A zero value is equal to not giving the argument.
Bram Moolenaar2ecbe532022-07-29 21:36:21 +01007841 *E1285* *E1286* *E1287* *E1288* *E1289*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007842 When the {timeout} argument is given the search stops when
7843 more than this many milliseconds have passed. Thus when
7844 {timeout} is 500 the search stops after half a second.
7845 The value must not be negative. A zero value is like not
7846 giving the argument.
7847 {only available when compiled with the |+reltime| feature}
7848
7849 If the {skip} expression is given it is evaluated with the
7850 cursor positioned on the start of a match. If it evaluates to
7851 non-zero this match is skipped. This can be used, for
7852 example, to skip a match in a comment or a string.
7853 {skip} can be a string, which is evaluated as an expression, a
7854 function reference or a lambda.
7855 When {skip} is omitted or empty, every match is accepted.
7856 When evaluating {skip} causes an error the search is aborted
7857 and -1 returned.
7858 *search()-sub-match*
7859 With the 'p' flag the returned value is one more than the
7860 first sub-match in \(\). One if none of them matched but the
7861 whole pattern did match.
7862 To get the column number too use |searchpos()|.
7863
7864 The cursor will be positioned at the match, unless the 'n'
7865 flag is used.
7866
7867 Example (goes over all files in the argument list): >
7868 :let n = 1
7869 :while n <= argc() " loop over all files in arglist
Bram Moolenaarc51cf032022-02-26 12:25:45 +00007870 : exe "argument " .. n
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007871 : " start at the last char in the file and wrap for the
7872 : " first search to find match at start of file
7873 : normal G$
7874 : let flags = "w"
7875 : while search("foo", flags) > 0
7876 : s/foo/bar/g
7877 : let flags = "W"
7878 : endwhile
7879 : update " write the file if modified
7880 : let n = n + 1
7881 :endwhile
7882<
7883 Example for using some flags: >
7884 :echo search('\<if\|\(else\)\|\(endif\)', 'ncpe')
7885< This will search for the keywords "if", "else", and "endif"
7886 under or after the cursor. Because of the 'p' flag, it
7887 returns 1, 2, or 3 depending on which keyword is found, or 0
7888 if the search fails. With the cursor on the first word of the
7889 line:
7890 if (foo == 0) | let foo = foo + 1 | endif ~
7891 the function returns 1. Without the 'c' flag, the function
7892 finds the "endif" and returns 3. The same thing happens
7893 without the 'e' flag if the cursor is on the "f" of "if".
7894 The 'n' flag tells the function not to move the cursor.
7895
7896 Can also be used as a |method|: >
7897 GetPattern()->search()
7898
7899searchcount([{options}]) *searchcount()*
7900 Get or update the last search count, like what is displayed
7901 without the "S" flag in 'shortmess'. This works even if
7902 'shortmess' does contain the "S" flag.
7903
7904 This returns a |Dictionary|. The dictionary is empty if the
7905 previous pattern was not set and "pattern" was not specified.
7906
7907 key type meaning ~
7908 current |Number| current position of match;
7909 0 if the cursor position is
7910 before the first match
7911 exact_match |Boolean| 1 if "current" is matched on
7912 "pos", otherwise 0
7913 total |Number| total count of matches found
7914 incomplete |Number| 0: search was fully completed
7915 1: recomputing was timed out
7916 2: max count exceeded
7917
7918 For {options} see further down.
7919
7920 To get the last search count when |n| or |N| was pressed, call
7921 this function with `recompute: 0` . This sometimes returns
7922 wrong information because |n| and |N|'s maximum count is 99.
7923 If it exceeded 99 the result must be max count + 1 (100). If
7924 you want to get correct information, specify `recompute: 1`: >
7925
7926 " result == maxcount + 1 (100) when many matches
7927 let result = searchcount(#{recompute: 0})
7928
7929 " Below returns correct result (recompute defaults
7930 " to 1)
7931 let result = searchcount()
7932<
Bram Moolenaarb529cfb2022-07-25 15:42:07 +01007933 The function is useful to add the count to 'statusline': >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007934 function! LastSearchCount() abort
7935 let result = searchcount(#{recompute: 0})
7936 if empty(result)
7937 return ''
7938 endif
7939 if result.incomplete ==# 1 " timed out
7940 return printf(' /%s [?/??]', @/)
7941 elseif result.incomplete ==# 2 " max count exceeded
7942 if result.total > result.maxcount &&
7943 \ result.current > result.maxcount
7944 return printf(' /%s [>%d/>%d]', @/,
7945 \ result.current, result.total)
7946 elseif result.total > result.maxcount
7947 return printf(' /%s [%d/>%d]', @/,
7948 \ result.current, result.total)
7949 endif
7950 endif
7951 return printf(' /%s [%d/%d]', @/,
7952 \ result.current, result.total)
7953 endfunction
Bram Moolenaarc51cf032022-02-26 12:25:45 +00007954 let &statusline ..= '%{LastSearchCount()}'
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007955
7956 " Or if you want to show the count only when
7957 " 'hlsearch' was on
Bram Moolenaarc51cf032022-02-26 12:25:45 +00007958 " let &statusline ..=
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007959 " \ '%{v:hlsearch ? LastSearchCount() : ""}'
7960<
7961 You can also update the search count, which can be useful in a
7962 |CursorMoved| or |CursorMovedI| autocommand: >
7963
7964 autocmd CursorMoved,CursorMovedI *
7965 \ let s:searchcount_timer = timer_start(
7966 \ 200, function('s:update_searchcount'))
7967 function! s:update_searchcount(timer) abort
7968 if a:timer ==# s:searchcount_timer
7969 call searchcount(#{
7970 \ recompute: 1, maxcount: 0, timeout: 100})
7971 redrawstatus
7972 endif
7973 endfunction
7974<
7975 This can also be used to count matched texts with specified
7976 pattern in the current buffer using "pattern": >
7977
7978 " Count '\<foo\>' in this buffer
7979 " (Note that it also updates search count)
7980 let result = searchcount(#{pattern: '\<foo\>'})
7981
7982 " To restore old search count by old pattern,
7983 " search again
7984 call searchcount()
7985<
7986 {options} must be a |Dictionary|. It can contain:
7987 key type meaning ~
7988 recompute |Boolean| if |TRUE|, recompute the count
7989 like |n| or |N| was executed.
7990 otherwise returns the last
7991 computed result (when |n| or
7992 |N| was used when "S" is not
7993 in 'shortmess', or this
7994 function was called).
7995 (default: |TRUE|)
7996 pattern |String| recompute if this was given
7997 and different with |@/|.
7998 this works as same as the
7999 below command is executed
8000 before calling this function >
8001 let @/ = pattern
8002< (default: |@/|)
8003 timeout |Number| 0 or negative number is no
8004 timeout. timeout milliseconds
8005 for recomputing the result
8006 (default: 0)
8007 maxcount |Number| 0 or negative number is no
8008 limit. max count of matched
8009 text while recomputing the
8010 result. if search exceeded
8011 total count, "total" value
8012 becomes `maxcount + 1`
8013 (default: 99)
8014 pos |List| `[lnum, col, off]` value
8015 when recomputing the result.
8016 this changes "current" result
8017 value. see |cursor()|,
8018 |getpos()|
8019 (default: cursor's position)
8020
8021 Can also be used as a |method|: >
8022 GetSearchOpts()->searchcount()
8023<
8024searchdecl({name} [, {global} [, {thisblock}]]) *searchdecl()*
8025 Search for the declaration of {name}.
8026
8027 With a non-zero {global} argument it works like |gD|, find
8028 first match in the file. Otherwise it works like |gd|, find
8029 first match in the function.
8030
8031 With a non-zero {thisblock} argument matches in a {} block
8032 that ends before the cursor position are ignored. Avoids
8033 finding variable declarations only valid in another scope.
8034
8035 Moves the cursor to the found match.
8036 Returns zero for success, non-zero for failure.
8037 Example: >
8038 if searchdecl('myvar') == 0
8039 echo getline('.')
8040 endif
8041<
8042 Can also be used as a |method|: >
8043 GetName()->searchdecl()
8044<
8045 *searchpair()*
8046searchpair({start}, {middle}, {end} [, {flags} [, {skip}
8047 [, {stopline} [, {timeout}]]]])
8048 Search for the match of a nested start-end pair. This can be
8049 used to find the "endif" that matches an "if", while other
8050 if/endif pairs in between are ignored.
8051 The search starts at the cursor. The default is to search
8052 forward, include 'b' in {flags} to search backward.
8053 If a match is found, the cursor is positioned at it and the
8054 line number is returned. If no match is found 0 or -1 is
8055 returned and the cursor doesn't move. No error message is
8056 given.
8057
8058 {start}, {middle} and {end} are patterns, see |pattern|. They
8059 must not contain \( \) pairs. Use of \%( \) is allowed. When
8060 {middle} is not empty, it is found when searching from either
8061 direction, but only when not in a nested start-end pair. A
8062 typical use is: >
8063 searchpair('\<if\>', '\<else\>', '\<endif\>')
8064< By leaving {middle} empty the "else" is skipped.
8065
8066 {flags} 'b', 'c', 'n', 's', 'w' and 'W' are used like with
8067 |search()|. Additionally:
8068 'r' Repeat until no more matches found; will find the
8069 outer pair. Implies the 'W' flag.
8070 'm' Return number of matches instead of line number with
8071 the match; will be > 1 when 'r' is used.
8072 Note: it's nearly always a good idea to use the 'W' flag, to
8073 avoid wrapping around the end of the file.
8074
8075 When a match for {start}, {middle} or {end} is found, the
8076 {skip} expression is evaluated with the cursor positioned on
8077 the start of the match. It should return non-zero if this
8078 match is to be skipped. E.g., because it is inside a comment
8079 or a string.
8080 When {skip} is omitted or empty, every match is accepted.
8081 When evaluating {skip} causes an error the search is aborted
8082 and -1 returned.
8083 {skip} can be a string, a lambda, a funcref or a partial.
8084 Anything else makes the function fail.
8085 In a `:def` function when the {skip} argument is a string
8086 constant it is compiled into instructions.
8087
8088 For {stopline} and {timeout} see |search()|.
8089
8090 The value of 'ignorecase' is used. 'magic' is ignored, the
8091 patterns are used like it's on.
8092
8093 The search starts exactly at the cursor. A match with
8094 {start}, {middle} or {end} at the next character, in the
8095 direction of searching, is the first one found. Example: >
8096 if 1
8097 if 2
8098 endif 2
8099 endif 1
8100< When starting at the "if 2", with the cursor on the "i", and
8101 searching forwards, the "endif 2" is found. When starting on
8102 the character just before the "if 2", the "endif 1" will be
8103 found. That's because the "if 2" will be found first, and
8104 then this is considered to be a nested if/endif from "if 2" to
8105 "endif 2".
8106 When searching backwards and {end} is more than one character,
8107 it may be useful to put "\zs" at the end of the pattern, so
8108 that when the cursor is inside a match with the end it finds
8109 the matching start.
8110
8111 Example, to find the "endif" command in a Vim script: >
8112
8113 :echo searchpair('\<if\>', '\<el\%[seif]\>', '\<en\%[dif]\>', 'W',
8114 \ 'getline(".") =~ "^\\s*\""')
8115
8116< The cursor must be at or after the "if" for which a match is
8117 to be found. Note that single-quote strings are used to avoid
8118 having to double the backslashes. The skip expression only
8119 catches comments at the start of a line, not after a command.
8120 Also, a word "en" or "if" halfway a line is considered a
8121 match.
8122 Another example, to search for the matching "{" of a "}": >
8123
8124 :echo searchpair('{', '', '}', 'bW')
8125
8126< This works when the cursor is at or before the "}" for which a
8127 match is to be found. To reject matches that syntax
8128 highlighting recognized as strings: >
8129
8130 :echo searchpair('{', '', '}', 'bW',
8131 \ 'synIDattr(synID(line("."), col("."), 0), "name") =~? "string"')
8132<
8133 *searchpairpos()*
8134searchpairpos({start}, {middle}, {end} [, {flags} [, {skip}
8135 [, {stopline} [, {timeout}]]]])
8136 Same as |searchpair()|, but returns a |List| with the line and
8137 column position of the match. The first element of the |List|
8138 is the line number and the second element is the byte index of
8139 the column position of the match. If no match is found,
8140 returns [0, 0]. >
8141
8142 :let [lnum,col] = searchpairpos('{', '', '}', 'n')
8143<
8144 See |match-parens| for a bigger and more useful example.
8145
8146 *searchpos()*
8147searchpos({pattern} [, {flags} [, {stopline} [, {timeout} [, {skip}]]]])
8148 Same as |search()|, but returns a |List| with the line and
8149 column position of the match. The first element of the |List|
8150 is the line number and the second element is the byte index of
8151 the column position of the match. If no match is found,
8152 returns [0, 0].
8153 Example: >
8154 :let [lnum, col] = searchpos('mypattern', 'n')
8155
8156< When the 'p' flag is given then there is an extra item with
8157 the sub-pattern match number |search()-sub-match|. Example: >
8158 :let [lnum, col, submatch] = searchpos('\(\l\)\|\(\u\)', 'np')
8159< In this example "submatch" is 2 when a lowercase letter is
8160 found |/\l|, 3 when an uppercase letter is found |/\u|.
8161
8162 Can also be used as a |method|: >
8163 GetPattern()->searchpos()
8164
8165server2client({clientid}, {string}) *server2client()*
8166 Send a reply string to {clientid}. The most recent {clientid}
8167 that sent a string can be retrieved with expand("<client>").
8168 {only available when compiled with the |+clientserver| feature}
8169 Returns zero for success, -1 for failure.
8170 Note:
8171 This id has to be stored before the next command can be
8172 received. I.e. before returning from the received command and
8173 before calling any commands that waits for input.
8174 See also |clientserver|.
8175 Example: >
8176 :echo server2client(expand("<client>"), "HELLO")
8177
8178< Can also be used as a |method|: >
8179 GetClientId()->server2client(string)
8180<
8181serverlist() *serverlist()*
8182 Return a list of available server names, one per line.
8183 When there are no servers or the information is not available
8184 an empty string is returned. See also |clientserver|.
8185 {only available when compiled with the |+clientserver| feature}
8186 Example: >
8187 :echo serverlist()
8188<
8189setbufline({buf}, {lnum}, {text}) *setbufline()*
8190 Set line {lnum} to {text} in buffer {buf}. This works like
8191 |setline()| for the specified buffer.
8192
8193 This function works only for loaded buffers. First call
8194 |bufload()| if needed.
8195
8196 To insert lines use |appendbufline()|.
8197 Any text properties in {lnum} are cleared.
8198
Bram Moolenaarcd9c8d42022-11-05 23:46:43 +00008199 {text} can be a string to set one line, or a List of strings
8200 to set multiple lines. If the List extends below the last
8201 line then those lines are added. If the List is empty then
8202 nothing is changed and zero is returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008203
8204 For the use of {buf}, see |bufname()| above.
8205
8206 {lnum} is used like with |setline()|.
8207 Use "$" to refer to the last line in buffer {buf}.
8208 When {lnum} is just below the last line the {text} will be
8209 added below the last line.
8210
8211 When {buf} is not a valid buffer, the buffer is not loaded or
8212 {lnum} is not valid then 1 is returned. In |Vim9| script an
8213 error is given.
8214 On success 0 is returned.
8215
8216 Can also be used as a |method|, the base is passed as the
8217 third argument: >
8218 GetText()->setbufline(buf, lnum)
8219
8220setbufvar({buf}, {varname}, {val}) *setbufvar()*
8221 Set option or local variable {varname} in buffer {buf} to
8222 {val}.
8223 This also works for a global or local window option, but it
8224 doesn't work for a global or local window variable.
8225 For a local window option the global value is unchanged.
8226 For the use of {buf}, see |bufname()| above.
8227 The {varname} argument is a string.
8228 Note that the variable name without "b:" must be used.
8229 Examples: >
8230 :call setbufvar(1, "&mod", 1)
8231 :call setbufvar("todo", "myvar", "foobar")
8232< This function is not available in the |sandbox|.
8233
8234 Can also be used as a |method|, the base is passed as the
8235 third argument: >
8236 GetValue()->setbufvar(buf, varname)
8237
8238
8239setcellwidths({list}) *setcellwidths()*
8240 Specify overrides for cell widths of character ranges. This
Bram Moolenaarb59ae592022-11-23 23:46:31 +00008241 tells Vim how wide characters are when displayed in the
8242 terminal, counted in screen cells. The values override
8243 'ambiwidth'. Example: >
8244 call setcellwidths([
Bram Moolenaar938ae282023-02-20 20:44:55 +00008245 \ [0x111, 0x111, 1],
Bram Moolenaarb59ae592022-11-23 23:46:31 +00008246 \ [0x2194, 0x2199, 2],
8247 \ ])
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008248
Bram Moolenaarb59ae592022-11-23 23:46:31 +00008249< The {list} argument is a List of Lists with each three
8250 numbers: [{low}, {high}, {width}]. *E1109* *E1110*
8251 {low} and {high} can be the same, in which case this refers to
8252 one character. Otherwise it is the range of characters from
8253 {low} to {high} (inclusive). *E1111* *E1114*
K.Takata71933232023-01-20 16:00:55 +00008254 Only characters with value 0x80 and higher can be used.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008255
Bram Moolenaarb59ae592022-11-23 23:46:31 +00008256 {width} must be either 1 or 2, indicating the character width
8257 in screen cells. *E1112*
8258 An error is given if the argument is invalid, also when a
Bram Moolenaar938ae282023-02-20 20:44:55 +00008259 range overlaps with another. *E1113*
Bram Moolenaarb59ae592022-11-23 23:46:31 +00008260
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008261 If the new value causes 'fillchars' or 'listchars' to become
8262 invalid it is rejected and an error is given.
8263
Bram Moolenaarb59ae592022-11-23 23:46:31 +00008264 To clear the overrides pass an empty {list}: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008265 setcellwidths([]);
Bram Moolenaarb59ae592022-11-23 23:46:31 +00008266
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008267< You can use the script $VIMRUNTIME/tools/emoji_list.vim to see
Bram Moolenaarb59ae592022-11-23 23:46:31 +00008268 the effect for known emoji characters. Move the cursor
8269 through the text to check if the cell widths of your terminal
8270 match with what Vim knows about each emoji. If it doesn't
8271 look right you need to adjust the {list} argument.
8272
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008273
8274setcharpos({expr}, {list}) *setcharpos()*
8275 Same as |setpos()| but uses the specified column number as the
8276 character index instead of the byte index in the line.
8277
8278 Example:
8279 With the text "여보세요" in line 8: >
8280 call setcharpos('.', [0, 8, 4, 0])
8281< positions the cursor on the fourth character '요'. >
8282 call setpos('.', [0, 8, 4, 0])
8283< positions the cursor on the second character '보'.
8284
8285 Can also be used as a |method|: >
8286 GetPosition()->setcharpos('.')
8287
8288setcharsearch({dict}) *setcharsearch()*
8289 Set the current character search information to {dict},
8290 which contains one or more of the following entries:
8291
8292 char character which will be used for a subsequent
8293 |,| or |;| command; an empty string clears the
8294 character search
8295 forward direction of character search; 1 for forward,
8296 0 for backward
8297 until type of character search; 1 for a |t| or |T|
8298 character search, 0 for an |f| or |F|
8299 character search
8300
8301 This can be useful to save/restore a user's character search
8302 from a script: >
8303 :let prevsearch = getcharsearch()
8304 :" Perform a command which clobbers user's search
8305 :call setcharsearch(prevsearch)
8306< Also see |getcharsearch()|.
8307
8308 Can also be used as a |method|: >
8309 SavedSearch()->setcharsearch()
8310
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01008311setcmdline({str} [, {pos}]) *setcmdline()*
8312 Set the command line to {str} and set the cursor position to
8313 {pos}.
8314 If {pos} is omitted, the cursor is positioned after the text.
8315 Returns 0 when successful, 1 when not editing the command
8316 line.
8317
8318 Can also be used as a |method|: >
8319 GetText()->setcmdline()
8320
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008321setcmdpos({pos}) *setcmdpos()*
8322 Set the cursor position in the command line to byte position
8323 {pos}. The first position is 1.
8324 Use |getcmdpos()| to obtain the current position.
8325 Only works while editing the command line, thus you must use
8326 |c_CTRL-\_e|, |c_CTRL-R_=| or |c_CTRL-R_CTRL-R| with '='. For
8327 |c_CTRL-\_e| and |c_CTRL-R_CTRL-R| with '=' the position is
8328 set after the command line is set to the expression. For
8329 |c_CTRL-R_=| it is set after evaluating the expression but
8330 before inserting the resulting text.
8331 When the number is too big the cursor is put at the end of the
8332 line. A number smaller than one has undefined results.
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01008333 Returns 0 when successful, 1 when not editing the command
8334 line.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008335
8336 Can also be used as a |method|: >
8337 GetPos()->setcmdpos()
8338
8339setcursorcharpos({lnum}, {col} [, {off}]) *setcursorcharpos()*
8340setcursorcharpos({list})
8341 Same as |cursor()| but uses the specified column number as the
8342 character index instead of the byte index in the line.
8343
8344 Example:
8345 With the text "여보세요" in line 4: >
8346 call setcursorcharpos(4, 3)
8347< positions the cursor on the third character '세'. >
8348 call cursor(4, 3)
8349< positions the cursor on the first character '여'.
8350
8351 Can also be used as a |method|: >
8352 GetCursorPos()->setcursorcharpos()
8353
8354
8355setenv({name}, {val}) *setenv()*
8356 Set environment variable {name} to {val}. Example: >
8357 call setenv('HOME', '/home/myhome')
8358
8359< When {val} is |v:null| the environment variable is deleted.
8360 See also |expr-env|.
8361
8362 Can also be used as a |method|, the base is passed as the
8363 second argument: >
8364 GetPath()->setenv('PATH')
8365
8366setfperm({fname}, {mode}) *setfperm()* *chmod*
8367 Set the file permissions for {fname} to {mode}.
8368 {mode} must be a string with 9 characters. It is of the form
8369 "rwxrwxrwx", where each group of "rwx" flags represent, in
8370 turn, the permissions of the owner of the file, the group the
8371 file belongs to, and other users. A '-' character means the
8372 permission is off, any other character means on. Multi-byte
8373 characters are not supported.
8374
8375 For example "rw-r-----" means read-write for the user,
8376 readable by the group, not accessible by others. "xx-x-----"
8377 would do the same thing.
8378
8379 Returns non-zero for success, zero for failure.
8380
8381 Can also be used as a |method|: >
8382 GetFilename()->setfperm(mode)
8383<
8384 To read permissions see |getfperm()|.
8385
8386
8387setline({lnum}, {text}) *setline()*
8388 Set line {lnum} of the current buffer to {text}. To insert
8389 lines use |append()|. To set lines in another buffer use
8390 |setbufline()|. Any text properties in {lnum} are cleared.
8391
8392 {lnum} is used like with |getline()|.
8393 When {lnum} is just below the last line the {text} will be
8394 added below the last line.
8395 {text} can be any type or a List of any type, each item is
Bram Moolenaarcd9c8d42022-11-05 23:46:43 +00008396 converted to a String. When {text} is an empty List then
8397 nothing is changed and FALSE is returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008398
8399 If this succeeds, FALSE is returned. If this fails (most likely
8400 because {lnum} is invalid) TRUE is returned.
8401 In |Vim9| script an error is given if {lnum} is invalid.
8402
8403 Example: >
8404 :call setline(5, strftime("%c"))
8405
8406< When {text} is a |List| then line {lnum} and following lines
8407 will be set to the items in the list. Example: >
8408 :call setline(5, ['aaa', 'bbb', 'ccc'])
8409< This is equivalent to: >
8410 :for [n, l] in [[5, 'aaa'], [6, 'bbb'], [7, 'ccc']]
8411 : call setline(n, l)
8412 :endfor
8413
8414< Note: The '[ and '] marks are not set.
8415
8416 Can also be used as a |method|, the base is passed as the
8417 second argument: >
8418 GetText()->setline(lnum)
8419
8420setloclist({nr}, {list} [, {action} [, {what}]]) *setloclist()*
8421 Create or replace or add to the location list for window {nr}.
8422 {nr} can be the window number or the |window-ID|.
8423 When {nr} is zero the current window is used.
8424
8425 For a location list window, the displayed location list is
8426 modified. For an invalid window number {nr}, -1 is returned.
8427 Otherwise, same as |setqflist()|.
8428 Also see |location-list|.
8429
8430 For {action} see |setqflist-action|.
8431
8432 If the optional {what} dictionary argument is supplied, then
8433 only the items listed in {what} are set. Refer to |setqflist()|
8434 for the list of supported keys in {what}.
8435
8436 Can also be used as a |method|, the base is passed as the
8437 second argument: >
8438 GetLoclist()->setloclist(winnr)
8439
8440setmatches({list} [, {win}]) *setmatches()*
8441 Restores a list of matches saved by |getmatches()| for the
8442 current window. Returns 0 if successful, otherwise -1. All
8443 current matches are cleared before the list is restored. See
8444 example for |getmatches()|.
8445 If {win} is specified, use the window with this number or
8446 window ID instead of the current window.
8447
8448 Can also be used as a |method|: >
8449 GetMatches()->setmatches()
8450<
8451 *setpos()*
8452setpos({expr}, {list})
8453 Set the position for String {expr}. Possible values:
8454 . the cursor
8455 'x mark x
8456
8457 {list} must be a |List| with four or five numbers:
8458 [bufnum, lnum, col, off]
8459 [bufnum, lnum, col, off, curswant]
8460
8461 "bufnum" is the buffer number. Zero can be used for the
8462 current buffer. When setting an uppercase mark "bufnum" is
8463 used for the mark position. For other marks it specifies the
8464 buffer to set the mark in. You can use the |bufnr()| function
8465 to turn a file name into a buffer number.
8466 For setting the cursor and the ' mark "bufnum" is ignored,
8467 since these are associated with a window, not a buffer.
8468 Does not change the jumplist.
8469
8470 "lnum" and "col" are the position in the buffer. The first
8471 column is 1. Use a zero "lnum" to delete a mark. If "col" is
8472 smaller than 1 then 1 is used. To use the character count
8473 instead of the byte count, use |setcharpos()|.
8474
8475 The "off" number is only used when 'virtualedit' is set. Then
8476 it is the offset in screen columns from the start of the
8477 character. E.g., a position within a <Tab> or after the last
8478 character.
8479
8480 The "curswant" number is only used when setting the cursor
8481 position. It sets the preferred column for when moving the
8482 cursor vertically. When the "curswant" number is missing the
8483 preferred column is not set. When it is present and setting a
8484 mark position it is not used.
8485
8486 Note that for '< and '> changing the line number may result in
8487 the marks to be effectively be swapped, so that '< is always
8488 before '>.
8489
8490 Returns 0 when the position could be set, -1 otherwise.
8491 An error message is given if {expr} is invalid.
8492
8493 Also see |setcharpos()|, |getpos()| and |getcurpos()|.
8494
8495 This does not restore the preferred column for moving
8496 vertically; if you set the cursor position with this, |j| and
8497 |k| motions will jump to previous columns! Use |cursor()| to
8498 also set the preferred column. Also see the "curswant" key in
8499 |winrestview()|.
8500
8501 Can also be used as a |method|: >
8502 GetPosition()->setpos('.')
8503
8504setqflist({list} [, {action} [, {what}]]) *setqflist()*
8505 Create or replace or add to the quickfix list.
8506
8507 If the optional {what} dictionary argument is supplied, then
8508 only the items listed in {what} are set. The first {list}
8509 argument is ignored. See below for the supported items in
8510 {what}.
8511 *setqflist-what*
8512 When {what} is not present, the items in {list} are used. Each
8513 item must be a dictionary. Non-dictionary items in {list} are
8514 ignored. Each dictionary item can contain the following
8515 entries:
8516
8517 bufnr buffer number; must be the number of a valid
8518 buffer
8519 filename name of a file; only used when "bufnr" is not
8520 present or it is invalid.
8521 module name of a module; if given it will be used in
8522 quickfix error window instead of the filename.
8523 lnum line number in the file
Bram Moolenaara2baa732022-02-04 16:09:54 +00008524 end_lnum end of lines, if the item spans multiple lines
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008525 pattern search pattern used to locate the error
8526 col column number
8527 vcol when non-zero: "col" is visual column
8528 when zero: "col" is byte index
Bram Moolenaara2baa732022-02-04 16:09:54 +00008529 end_col end column, if the item spans multiple columns
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008530 nr error number
8531 text description of the error
8532 type single-character error type, 'E', 'W', etc.
8533 valid recognized error message
Tom Praschanca6ac992023-08-11 23:26:12 +02008534 user_data custom data associated with the item, can be
8535 any type.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008536
8537 The "col", "vcol", "nr", "type" and "text" entries are
8538 optional. Either "lnum" or "pattern" entry can be used to
8539 locate a matching error line.
8540 If the "filename" and "bufnr" entries are not present or
8541 neither the "lnum" or "pattern" entries are present, then the
8542 item will not be handled as an error line.
8543 If both "pattern" and "lnum" are present then "pattern" will
8544 be used.
8545 If the "valid" entry is not supplied, then the valid flag is
8546 set when "bufnr" is a valid buffer or "filename" exists.
8547 If you supply an empty {list}, the quickfix list will be
8548 cleared.
8549 Note that the list is not exactly the same as what
8550 |getqflist()| returns.
8551
8552 {action} values: *setqflist-action* *E927*
8553 'a' The items from {list} are added to the existing
8554 quickfix list. If there is no existing list, then a
8555 new list is created.
8556
8557 'r' The items from the current quickfix list are replaced
8558 with the items from {list}. This can also be used to
8559 clear the list: >
8560 :call setqflist([], 'r')
8561<
8562 'f' All the quickfix lists in the quickfix stack are
8563 freed.
8564
8565 If {action} is not present or is set to ' ', then a new list
8566 is created. The new quickfix list is added after the current
8567 quickfix list in the stack and all the following lists are
8568 freed. To add a new quickfix list at the end of the stack,
8569 set "nr" in {what} to "$".
8570
8571 The following items can be specified in dictionary {what}:
8572 context quickfix list context. See |quickfix-context|
8573 efm errorformat to use when parsing text from
8574 "lines". If this is not present, then the
8575 'errorformat' option value is used.
8576 See |quickfix-parse|
8577 id quickfix list identifier |quickfix-ID|
8578 idx index of the current entry in the quickfix
8579 list specified by 'id' or 'nr'. If set to '$',
8580 then the last entry in the list is set as the
8581 current entry. See |quickfix-index|
8582 items list of quickfix entries. Same as the {list}
8583 argument.
8584 lines use 'errorformat' to parse a list of lines and
8585 add the resulting entries to the quickfix list
8586 {nr} or {id}. Only a |List| value is supported.
8587 See |quickfix-parse|
8588 nr list number in the quickfix stack; zero
8589 means the current quickfix list and "$" means
8590 the last quickfix list.
8591 quickfixtextfunc
8592 function to get the text to display in the
8593 quickfix window. The value can be the name of
8594 a function or a funcref or a lambda. Refer to
8595 |quickfix-window-function| for an explanation
8596 of how to write the function and an example.
8597 title quickfix list title text. See |quickfix-title|
8598 Unsupported keys in {what} are ignored.
8599 If the "nr" item is not present, then the current quickfix list
8600 is modified. When creating a new quickfix list, "nr" can be
8601 set to a value one greater than the quickfix stack size.
8602 When modifying a quickfix list, to guarantee that the correct
8603 list is modified, "id" should be used instead of "nr" to
8604 specify the list.
8605
8606 Examples (See also |setqflist-examples|): >
8607 :call setqflist([], 'r', {'title': 'My search'})
8608 :call setqflist([], 'r', {'nr': 2, 'title': 'Errors'})
8609 :call setqflist([], 'a', {'id':qfid, 'lines':["F1:10:L10"]})
8610<
8611 Returns zero for success, -1 for failure.
8612
8613 This function can be used to create a quickfix list
8614 independent of the 'errorformat' setting. Use a command like
8615 `:cc 1` to jump to the first position.
8616
8617 Can also be used as a |method|, the base is passed as the
8618 second argument: >
8619 GetErrorlist()->setqflist()
8620<
8621 *setreg()*
8622setreg({regname}, {value} [, {options}])
8623 Set the register {regname} to {value}.
8624 If {regname} is "" or "@", the unnamed register '"' is used.
8625 The {regname} argument is a string. In |Vim9-script|
8626 {regname} must be one character.
8627
8628 {value} may be any value returned by |getreg()| or
8629 |getreginfo()|, including a |List| or |Dict|.
8630 If {options} contains "a" or {regname} is upper case,
8631 then the value is appended.
8632
8633 {options} can also contain a register type specification:
8634 "c" or "v" |characterwise| mode
8635 "l" or "V" |linewise| mode
8636 "b" or "<CTRL-V>" |blockwise-visual| mode
8637 If a number immediately follows "b" or "<CTRL-V>" then this is
8638 used as the width of the selection - if it is not specified
8639 then the width of the block is set to the number of characters
8640 in the longest line (counting a <Tab> as 1 character).
8641
8642 If {options} contains no register settings, then the default
8643 is to use character mode unless {value} ends in a <NL> for
8644 string {value} and linewise mode for list {value}. Blockwise
8645 mode is never selected automatically.
8646 Returns zero for success, non-zero for failure.
8647
8648 *E883*
8649 Note: you may not use |List| containing more than one item to
8650 set search and expression registers. Lists containing no
8651 items act like empty strings.
8652
8653 Examples: >
8654 :call setreg(v:register, @*)
8655 :call setreg('*', @%, 'ac')
8656 :call setreg('a', "1\n2\n3", 'b5')
8657 :call setreg('"', { 'points_to': 'a'})
8658
8659< This example shows using the functions to save and restore a
8660 register: >
8661 :let var_a = getreginfo()
8662 :call setreg('a', var_a)
8663< or: >
8664 :let var_a = getreg('a', 1, 1)
8665 :let var_amode = getregtype('a')
8666 ....
8667 :call setreg('a', var_a, var_amode)
8668< Note: you may not reliably restore register value
8669 without using the third argument to |getreg()| as without it
8670 newlines are represented as newlines AND Nul bytes are
8671 represented as newlines as well, see |NL-used-for-Nul|.
8672
8673 You can also change the type of a register by appending
8674 nothing: >
8675 :call setreg('a', '', 'al')
8676
8677< Can also be used as a |method|, the base is passed as the
8678 second argument: >
8679 GetText()->setreg('a')
8680
8681settabvar({tabnr}, {varname}, {val}) *settabvar()*
8682 Set tab-local variable {varname} to {val} in tab page {tabnr}.
8683 |t:var|
8684 The {varname} argument is a string.
8685 Note that autocommands are blocked, side effects may not be
8686 triggered, e.g. when setting 'filetype'.
8687 Note that the variable name without "t:" must be used.
8688 Tabs are numbered starting with one.
8689 This function is not available in the |sandbox|.
8690
8691 Can also be used as a |method|, the base is passed as the
8692 third argument: >
8693 GetValue()->settabvar(tab, name)
8694
8695settabwinvar({tabnr}, {winnr}, {varname}, {val}) *settabwinvar()*
8696 Set option or local variable {varname} in window {winnr} to
8697 {val}.
8698 Tabs are numbered starting with one. For the current tabpage
8699 use |setwinvar()|.
8700 {winnr} can be the window number or the |window-ID|.
8701 When {winnr} is zero the current window is used.
8702 Note that autocommands are blocked, side effects may not be
8703 triggered, e.g. when setting 'filetype' or 'syntax'.
8704 This also works for a global or local buffer option, but it
8705 doesn't work for a global or local buffer variable.
8706 For a local buffer option the global value is unchanged.
8707 Note that the variable name without "w:" must be used.
8708 Examples: >
8709 :call settabwinvar(1, 1, "&list", 0)
8710 :call settabwinvar(3, 2, "myvar", "foobar")
8711< This function is not available in the |sandbox|.
8712
8713 Can also be used as a |method|, the base is passed as the
8714 fourth argument: >
8715 GetValue()->settabwinvar(tab, winnr, name)
8716
8717settagstack({nr}, {dict} [, {action}]) *settagstack()*
8718 Modify the tag stack of the window {nr} using {dict}.
8719 {nr} can be the window number or the |window-ID|.
8720
8721 For a list of supported items in {dict}, refer to
8722 |gettagstack()|. "curidx" takes effect before changing the tag
8723 stack.
8724 *E962*
8725 How the tag stack is modified depends on the {action}
8726 argument:
8727 - If {action} is not present or is set to 'r', then the tag
8728 stack is replaced.
8729 - If {action} is set to 'a', then new entries from {dict} are
8730 pushed (added) onto the tag stack.
8731 - If {action} is set to 't', then all the entries from the
8732 current entry in the tag stack or "curidx" in {dict} are
8733 removed and then new entries are pushed to the stack.
8734
8735 The current index is set to one after the length of the tag
8736 stack after the modification.
8737
8738 Returns zero for success, -1 for failure.
8739
8740 Examples (for more examples see |tagstack-examples|):
8741 Empty the tag stack of window 3: >
8742 call settagstack(3, {'items' : []})
8743
8744< Save and restore the tag stack: >
8745 let stack = gettagstack(1003)
8746 " do something else
8747 call settagstack(1003, stack)
8748 unlet stack
8749<
8750 Can also be used as a |method|, the base is passed as the
8751 second argument: >
8752 GetStack()->settagstack(winnr)
8753
8754setwinvar({winnr}, {varname}, {val}) *setwinvar()*
8755 Like |settabwinvar()| for the current tab page.
8756 Examples: >
8757 :call setwinvar(1, "&list", 0)
8758 :call setwinvar(2, "myvar", "foobar")
8759
8760< Can also be used as a |method|, the base is passed as the
8761 third argument: >
8762 GetValue()->setwinvar(winnr, name)
8763
8764sha256({string}) *sha256()*
8765 Returns a String with 64 hex characters, which is the SHA256
8766 checksum of {string}.
8767
8768 Can also be used as a |method|: >
8769 GetText()->sha256()
8770
8771< {only available when compiled with the |+cryptv| feature}
8772
8773shellescape({string} [, {special}]) *shellescape()*
8774 Escape {string} for use as a shell command argument.
8775 When the 'shell' contains powershell (MS-Windows) or pwsh
Bram Moolenaar944697a2022-02-20 19:48:20 +00008776 (MS-Windows, Linux, and macOS) then it will enclose {string}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008777 in single quotes and will double up all internal single
8778 quotes.
8779 On MS-Windows, when 'shellslash' is not set, it will enclose
8780 {string} in double quotes and double all double quotes within
8781 {string}.
8782 Otherwise it will enclose {string} in single quotes and
8783 replace all "'" with "'\''".
8784
8785 When the {special} argument is present and it's a non-zero
8786 Number or a non-empty String (|non-zero-arg|), then special
8787 items such as "!", "%", "#" and "<cword>" will be preceded by
8788 a backslash. This backslash will be removed again by the |:!|
8789 command.
8790
8791 The "!" character will be escaped (again with a |non-zero-arg|
8792 {special}) when 'shell' contains "csh" in the tail. That is
8793 because for csh and tcsh "!" is used for history replacement
8794 even when inside single quotes.
8795
8796 With a |non-zero-arg| {special} the <NL> character is also
8797 escaped. When 'shell' containing "csh" in the tail it's
8798 escaped a second time.
8799
8800 The "\" character will be escaped when 'shell' contains "fish"
8801 in the tail. That is because for fish "\" is used as an escape
8802 character inside single quotes.
8803
8804 Example of use with a |:!| command: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00008805 :exe '!dir ' .. shellescape(expand('<cfile>'), 1)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008806< This results in a directory listing for the file under the
8807 cursor. Example of use with |system()|: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00008808 :call system("chmod +w -- " .. shellescape(expand("%")))
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008809< See also |::S|.
8810
8811 Can also be used as a |method|: >
8812 GetCommand()->shellescape()
8813
8814shiftwidth([{col}]) *shiftwidth()*
8815 Returns the effective value of 'shiftwidth'. This is the
8816 'shiftwidth' value unless it is zero, in which case it is the
8817 'tabstop' value. This function was introduced with patch
8818 7.3.694 in 2012, everybody should have it by now (however it
8819 did not allow for the optional {col} argument until 8.1.542).
8820
8821 When there is one argument {col} this is used as column number
8822 for which to return the 'shiftwidth' value. This matters for the
8823 'vartabstop' feature. If the 'vartabstop' setting is enabled and
8824 no {col} argument is given, column 1 will be assumed.
8825
8826 Can also be used as a |method|: >
8827 GetColumn()->shiftwidth()
8828
8829sign_ functions are documented here: |sign-functions-details|
8830
8831
8832simplify({filename}) *simplify()*
8833 Simplify the file name as much as possible without changing
8834 the meaning. Shortcuts (on MS-Windows) or symbolic links (on
8835 Unix) are not resolved. If the first path component in
8836 {filename} designates the current directory, this will be
8837 valid for the result as well. A trailing path separator is
8838 not removed either. On Unix "//path" is unchanged, but
8839 "///path" is simplified to "/path" (this follows the Posix
8840 standard).
8841 Example: >
8842 simplify("./dir/.././/file/") == "./file/"
8843< Note: The combination "dir/.." is only removed if "dir" is
8844 a searchable directory or does not exist. On Unix, it is also
8845 removed when "dir" is a symbolic link within the same
8846 directory. In order to resolve all the involved symbolic
8847 links before simplifying the path name, use |resolve()|.
8848
8849 Can also be used as a |method|: >
8850 GetName()->simplify()
8851
8852sin({expr}) *sin()*
8853 Return the sine of {expr}, measured in radians, as a |Float|.
8854 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01008855 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008856 Examples: >
8857 :echo sin(100)
8858< -0.506366 >
8859 :echo sin(-4.01)
8860< 0.763301
8861
8862 Can also be used as a |method|: >
8863 Compute()->sin()
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008864
8865
8866sinh({expr}) *sinh()*
8867 Return the hyperbolic sine of {expr} as a |Float| in the range
8868 [-inf, inf].
8869 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01008870 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008871 Examples: >
8872 :echo sinh(0.5)
8873< 0.521095 >
8874 :echo sinh(-0.9)
8875< -1.026517
8876
8877 Can also be used as a |method|: >
8878 Compute()->sinh()
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008879
8880
8881slice({expr}, {start} [, {end}]) *slice()*
8882 Similar to using a |slice| "expr[start : end]", but "end" is
8883 used exclusive. And for a string the indexes are used as
8884 character indexes instead of byte indexes, like in
8885 |vim9script|. Also, composing characters are not counted.
8886 When {end} is omitted the slice continues to the last item.
8887 When {end} is -1 the last item is omitted.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01008888 Returns an empty value if {start} or {end} are invalid.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008889
8890 Can also be used as a |method|: >
8891 GetList()->slice(offset)
8892
8893
Bram Moolenaar2007dd42022-02-23 13:17:47 +00008894sort({list} [, {how} [, {dict}]]) *sort()* *E702*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008895 Sort the items in {list} in-place. Returns {list}.
8896
8897 If you want a list to remain unmodified make a copy first: >
8898 :let sortedlist = sort(copy(mylist))
8899
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01008900< When {how} is omitted or is a string, then sort() uses the
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008901 string representation of each item to sort on. Numbers sort
8902 after Strings, |Lists| after Numbers. For sorting text in the
8903 current buffer use |:sort|.
8904
Bram Moolenaar2007dd42022-02-23 13:17:47 +00008905 When {how} is given and it is 'i' then case is ignored.
8906 In legacy script, for backwards compatibility, the value one
8907 can be used to ignore case. Zero means to not ignore case.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008908
Bram Moolenaar2007dd42022-02-23 13:17:47 +00008909 When {how} is given and it is 'l' then the current collation
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008910 locale is used for ordering. Implementation details: strcoll()
8911 is used to compare strings. See |:language| check or set the
8912 collation locale. |v:collate| can also be used to check the
8913 current locale. Sorting using the locale typically ignores
8914 case. Example: >
8915 " ö is sorted similarly to o with English locale.
8916 :language collate en_US.UTF8
8917 :echo sort(['n', 'o', 'O', 'ö', 'p', 'z'], 'l')
8918< ['n', 'o', 'O', 'ö', 'p', 'z'] ~
8919>
8920 " ö is sorted after z with Swedish locale.
8921 :language collate sv_SE.UTF8
8922 :echo sort(['n', 'o', 'O', 'ö', 'p', 'z'], 'l')
8923< ['n', 'o', 'O', 'p', 'z', 'ö'] ~
8924 This does not work properly on Mac.
8925
Bram Moolenaar2007dd42022-02-23 13:17:47 +00008926 When {how} is given and it is 'n' then all items will be
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008927 sorted numerical (Implementation detail: this uses the
Bram Moolenaarbe19d782023-03-09 22:06:49 +00008928 strtod() function to parse numbers. Strings, Lists, Dicts and
8929 Funcrefs will be considered as being 0). Note that this won't
8930 sort a list of strings with numbers!
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008931
Bram Moolenaar2007dd42022-02-23 13:17:47 +00008932 When {how} is given and it is 'N' then all items will be
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008933 sorted numerical. This is like 'n' but a string containing
8934 digits will be used as the number they represent.
8935
Bram Moolenaar2007dd42022-02-23 13:17:47 +00008936 When {how} is given and it is 'f' then all items will be
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008937 sorted numerical. All values must be a Number or a Float.
8938
Bram Moolenaar2007dd42022-02-23 13:17:47 +00008939 When {how} is a |Funcref| or a function name, this function
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008940 is called to compare items. The function is invoked with two
8941 items as argument and must return zero if they are equal, 1 or
8942 bigger if the first one sorts after the second one, -1 or
8943 smaller if the first one sorts before the second one.
8944
8945 {dict} is for functions with the "dict" attribute. It will be
8946 used to set the local variable "self". |Dictionary-function|
8947
8948 The sort is stable, items which compare equal (as number or as
8949 string) will keep their relative position. E.g., when sorting
8950 on numbers, text strings will sort next to each other, in the
8951 same order as they were originally.
8952
8953 Can also be used as a |method|: >
8954 mylist->sort()
8955
8956< Also see |uniq()|.
8957
8958 Example: >
8959 func MyCompare(i1, i2)
8960 return a:i1 == a:i2 ? 0 : a:i1 > a:i2 ? 1 : -1
8961 endfunc
8962 eval mylist->sort("MyCompare")
8963< A shorter compare version for this specific simple case, which
8964 ignores overflow: >
8965 func MyCompare(i1, i2)
8966 return a:i1 - a:i2
8967 endfunc
8968< For a simple expression you can use a lambda: >
8969 eval mylist->sort({i1, i2 -> i1 - i2})
8970<
8971sound_clear() *sound_clear()*
8972 Stop playing all sounds.
8973
8974 On some Linux systems you may need the libcanberra-pulse
8975 package, otherwise sound may not stop.
8976
8977 {only available when compiled with the |+sound| feature}
8978
8979 *sound_playevent()*
8980sound_playevent({name} [, {callback}])
8981 Play a sound identified by {name}. Which event names are
8982 supported depends on the system. Often the XDG sound names
8983 are used. On Ubuntu they may be found in
8984 /usr/share/sounds/freedesktop/stereo. Example: >
8985 call sound_playevent('bell')
8986< On MS-Windows, {name} can be SystemAsterisk, SystemDefault,
8987 SystemExclamation, SystemExit, SystemHand, SystemQuestion,
8988 SystemStart, SystemWelcome, etc.
Yee Cheng Chin4314e4f2022-10-08 13:50:05 +01008989 On macOS, {name} refers to files located in
8990 /System/Library/Sounds (e.g. "Tink"). It will also work for
8991 custom installed sounds in folders like ~/Library/Sounds.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008992
8993 When {callback} is specified it is invoked when the sound is
8994 finished. The first argument is the sound ID, the second
8995 argument is the status:
8996 0 sound was played to the end
8997 1 sound was interrupted
8998 2 error occurred after sound started
8999 Example: >
9000 func Callback(id, status)
9001 echomsg "sound " .. a:id .. " finished with " .. a:status
9002 endfunc
9003 call sound_playevent('bell', 'Callback')
9004
9005< MS-Windows: {callback} doesn't work for this function.
9006
9007 Returns the sound ID, which can be passed to `sound_stop()`.
9008 Returns zero if the sound could not be played.
9009
9010 Can also be used as a |method|: >
9011 GetSoundName()->sound_playevent()
9012
9013< {only available when compiled with the |+sound| feature}
9014
9015 *sound_playfile()*
9016sound_playfile({path} [, {callback}])
9017 Like `sound_playevent()` but play sound file {path}. {path}
9018 must be a full path. On Ubuntu you may find files to play
9019 with this command: >
9020 :!find /usr/share/sounds -type f | grep -v index.theme
9021
9022< Can also be used as a |method|: >
9023 GetSoundPath()->sound_playfile()
9024
Bram Moolenaar1588bc82022-03-08 21:35:07 +00009025< {only available when compiled with the |+sound| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009026
9027
9028sound_stop({id}) *sound_stop()*
9029 Stop playing sound {id}. {id} must be previously returned by
9030 `sound_playevent()` or `sound_playfile()`.
9031
9032 On some Linux systems you may need the libcanberra-pulse
9033 package, otherwise sound may not stop.
9034
9035 On MS-Windows, this does not work for event sound started by
9036 `sound_playevent()`. To stop event sounds, use `sound_clear()`.
9037
9038 Can also be used as a |method|: >
9039 soundid->sound_stop()
9040
9041< {only available when compiled with the |+sound| feature}
9042
9043 *soundfold()*
9044soundfold({word})
9045 Return the sound-folded equivalent of {word}. Uses the first
9046 language in 'spelllang' for the current window that supports
9047 soundfolding. 'spell' must be set. When no sound folding is
9048 possible the {word} is returned unmodified.
9049 This can be used for making spelling suggestions. Note that
9050 the method can be quite slow.
9051
9052 Can also be used as a |method|: >
9053 GetWord()->soundfold()
9054<
9055 *spellbadword()*
9056spellbadword([{sentence}])
9057 Without argument: The result is the badly spelled word under
9058 or after the cursor. The cursor is moved to the start of the
9059 bad word. When no bad word is found in the cursor line the
9060 result is an empty string and the cursor doesn't move.
9061
9062 With argument: The result is the first word in {sentence} that
9063 is badly spelled. If there are no spelling mistakes the
9064 result is an empty string.
9065
9066 The return value is a list with two items:
9067 - The badly spelled word or an empty string.
9068 - The type of the spelling error:
9069 "bad" spelling mistake
9070 "rare" rare word
9071 "local" word only valid in another region
9072 "caps" word should start with Capital
9073 Example: >
9074 echo spellbadword("the quik brown fox")
9075< ['quik', 'bad'] ~
9076
9077 The spelling information for the current window and the value
9078 of 'spelllang' are used.
9079
9080 Can also be used as a |method|: >
9081 GetText()->spellbadword()
9082<
9083 *spellsuggest()*
9084spellsuggest({word} [, {max} [, {capital}]])
9085 Return a |List| with spelling suggestions to replace {word}.
9086 When {max} is given up to this number of suggestions are
9087 returned. Otherwise up to 25 suggestions are returned.
9088
9089 When the {capital} argument is given and it's non-zero only
9090 suggestions with a leading capital will be given. Use this
9091 after a match with 'spellcapcheck'.
9092
9093 {word} can be a badly spelled word followed by other text.
9094 This allows for joining two words that were split. The
9095 suggestions also include the following text, thus you can
9096 replace a line.
9097
9098 {word} may also be a good word. Similar words will then be
9099 returned. {word} itself is not included in the suggestions,
9100 although it may appear capitalized.
9101
9102 The spelling information for the current window is used. The
9103 values of 'spelllang' and 'spellsuggest' are used.
9104
9105 Can also be used as a |method|: >
9106 GetWord()->spellsuggest()
9107
9108split({string} [, {pattern} [, {keepempty}]]) *split()*
9109 Make a |List| out of {string}. When {pattern} is omitted or
9110 empty each white-separated sequence of characters becomes an
9111 item.
9112 Otherwise the string is split where {pattern} matches,
9113 removing the matched characters. 'ignorecase' is not used
9114 here, add \c to ignore case. |/\c|
9115 When the first or last item is empty it is omitted, unless the
9116 {keepempty} argument is given and it's non-zero.
9117 Other empty items are kept when {pattern} matches at least one
9118 character or when {keepempty} is non-zero.
9119 Example: >
9120 :let words = split(getline('.'), '\W\+')
9121< To split a string in individual characters: >
9122 :for c in split(mystring, '\zs')
9123< If you want to keep the separator you can also use '\zs' at
9124 the end of the pattern: >
9125 :echo split('abc:def:ghi', ':\zs')
9126< ['abc:', 'def:', 'ghi'] ~
9127 Splitting a table where the first element can be empty: >
9128 :let items = split(line, ':', 1)
9129< The opposite function is |join()|.
9130
9131 Can also be used as a |method|: >
9132 GetString()->split()
9133
9134sqrt({expr}) *sqrt()*
9135 Return the non-negative square root of Float {expr} as a
9136 |Float|.
9137 {expr} must evaluate to a |Float| or a |Number|. When {expr}
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01009138 is negative the result is NaN (Not a Number). Returns 0.0 if
9139 {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009140 Examples: >
9141 :echo sqrt(100)
9142< 10.0 >
9143 :echo sqrt(-4.01)
9144< nan
9145 "nan" may be different, it depends on system libraries.
9146
9147 Can also be used as a |method|: >
9148 Compute()->sqrt()
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009149
9150
9151srand([{expr}]) *srand()*
9152 Initialize seed used by |rand()|:
9153 - If {expr} is not given, seed values are initialized by
9154 reading from /dev/urandom, if possible, or using time(NULL)
9155 a.k.a. epoch time otherwise; this only has second accuracy.
9156 - If {expr} is given it must be a Number. It is used to
9157 initialize the seed values. This is useful for testing or
9158 when a predictable sequence is intended.
9159
9160 Examples: >
9161 :let seed = srand()
9162 :let seed = srand(userinput)
9163 :echo rand(seed)
9164
9165state([{what}]) *state()*
9166 Return a string which contains characters indicating the
9167 current state. Mostly useful in callbacks that want to do
9168 work that may not always be safe. Roughly this works like:
9169 - callback uses state() to check if work is safe to do.
9170 Yes: then do it right away.
9171 No: add to work queue and add a |SafeState| and/or
9172 |SafeStateAgain| autocommand (|SafeState| triggers at
9173 toplevel, |SafeStateAgain| triggers after handling
9174 messages and callbacks).
9175 - When SafeState or SafeStateAgain is triggered and executes
9176 your autocommand, check with `state()` if the work can be
9177 done now, and if yes remove it from the queue and execute.
9178 Remove the autocommand if the queue is now empty.
9179 Also see |mode()|.
9180
9181 When {what} is given only characters in this string will be
9182 added. E.g, this checks if the screen has scrolled: >
9183 if state('s') == ''
9184 " screen has not scrolled
9185<
9186 These characters indicate the state, generally indicating that
9187 something is busy:
9188 m halfway a mapping, :normal command, feedkeys() or
9189 stuffed command
9190 o operator pending, e.g. after |d|
9191 a Insert mode autocomplete active
9192 x executing an autocommand
9193 w blocked on waiting, e.g. ch_evalexpr(), ch_read() and
9194 ch_readraw() when reading json
9195 S not triggering SafeState or SafeStateAgain, e.g. after
9196 |f| or a count
9197 c callback invoked, including timer (repeats for
9198 recursiveness up to "ccc")
9199 s screen has scrolled for messages
9200
9201str2float({string} [, {quoted}]) *str2float()*
9202 Convert String {string} to a Float. This mostly works the
9203 same as when using a floating point number in an expression,
9204 see |floating-point-format|. But it's a bit more permissive.
9205 E.g., "1e40" is accepted, while in an expression you need to
9206 write "1.0e40". The hexadecimal form "0x123" is also
9207 accepted, but not others, like binary or octal.
9208 When {quoted} is present and non-zero then embedded single
9209 quotes before the dot are ignored, thus "1'000.0" is a
9210 thousand.
9211 Text after the number is silently ignored.
9212 The decimal point is always '.', no matter what the locale is
9213 set to. A comma ends the number: "12,345.67" is converted to
9214 12.0. You can strip out thousands separators with
9215 |substitute()|: >
9216 let f = str2float(substitute(text, ',', '', 'g'))
9217<
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01009218 Returns 0.0 if the conversion fails.
9219
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009220 Can also be used as a |method|: >
9221 let f = text->substitute(',', '', 'g')->str2float()
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009222
9223str2list({string} [, {utf8}]) *str2list()*
9224 Return a list containing the number values which represent
9225 each character in String {string}. Examples: >
9226 str2list(" ") returns [32]
9227 str2list("ABC") returns [65, 66, 67]
9228< |list2str()| does the opposite.
9229
9230 When {utf8} is omitted or zero, the current 'encoding' is used.
9231 When {utf8} is TRUE, always treat the String as UTF-8
9232 characters. With UTF-8 composing characters are handled
9233 properly: >
9234 str2list("á") returns [97, 769]
9235
9236< Can also be used as a |method|: >
9237 GetString()->str2list()
9238
9239
9240str2nr({string} [, {base} [, {quoted}]]) *str2nr()*
9241 Convert string {string} to a number.
9242 {base} is the conversion base, it can be 2, 8, 10 or 16.
9243 When {quoted} is present and non-zero then embedded single
9244 quotes are ignored, thus "1'000'000" is a million.
9245
9246 When {base} is omitted base 10 is used. This also means that
9247 a leading zero doesn't cause octal conversion to be used, as
9248 with the default String to Number conversion. Example: >
9249 let nr = str2nr('0123')
9250<
9251 When {base} is 16 a leading "0x" or "0X" is ignored. With a
9252 different base the result will be zero. Similarly, when
9253 {base} is 8 a leading "0", "0o" or "0O" is ignored, and when
9254 {base} is 2 a leading "0b" or "0B" is ignored.
9255 Text after the number is silently ignored.
9256
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01009257 Returns 0 if {string} is empty or on error.
9258
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009259 Can also be used as a |method|: >
9260 GetText()->str2nr()
9261
9262
9263strcharlen({string}) *strcharlen()*
9264 The result is a Number, which is the number of characters
9265 in String {string}. Composing characters are ignored.
9266 |strchars()| can count the number of characters, counting
9267 composing characters separately.
9268
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01009269 Returns 0 if {string} is empty or on error.
9270
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009271 Also see |strlen()|, |strdisplaywidth()| and |strwidth()|.
9272
9273 Can also be used as a |method|: >
9274 GetText()->strcharlen()
9275
9276
9277strcharpart({src}, {start} [, {len} [, {skipcc}]]) *strcharpart()*
9278 Like |strpart()| but using character index and length instead
9279 of byte index and length.
9280 When {skipcc} is omitted or zero, composing characters are
9281 counted separately.
9282 When {skipcc} set to 1, Composing characters are ignored,
9283 similar to |slice()|.
9284 When a character index is used where a character does not
9285 exist it is omitted and counted as one character. For
9286 example: >
9287 strcharpart('abc', -1, 2)
9288< results in 'a'.
9289
Bram Moolenaard592deb2022-06-17 15:42:40 +01009290 Returns an empty string on error.
9291
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009292 Can also be used as a |method|: >
9293 GetText()->strcharpart(5)
9294
9295
9296strchars({string} [, {skipcc}]) *strchars()*
9297 The result is a Number, which is the number of characters
9298 in String {string}.
9299 When {skipcc} is omitted or zero, composing characters are
9300 counted separately.
9301 When {skipcc} set to 1, Composing characters are ignored.
9302 |strcharlen()| always does this.
9303
Bram Moolenaard592deb2022-06-17 15:42:40 +01009304 Returns zero on error.
9305
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009306 Also see |strlen()|, |strdisplaywidth()| and |strwidth()|.
9307
9308 {skipcc} is only available after 7.4.755. For backward
9309 compatibility, you can define a wrapper function: >
9310 if has("patch-7.4.755")
9311 function s:strchars(str, skipcc)
9312 return strchars(a:str, a:skipcc)
9313 endfunction
9314 else
9315 function s:strchars(str, skipcc)
9316 if a:skipcc
9317 return strlen(substitute(a:str, ".", "x", "g"))
9318 else
9319 return strchars(a:str)
9320 endif
9321 endfunction
9322 endif
9323<
9324 Can also be used as a |method|: >
9325 GetText()->strchars()
9326
9327strdisplaywidth({string} [, {col}]) *strdisplaywidth()*
9328 The result is a Number, which is the number of display cells
9329 String {string} occupies on the screen when it starts at {col}
9330 (first column is zero). When {col} is omitted zero is used.
9331 Otherwise it is the screen column where to start. This
9332 matters for Tab characters.
9333 The option settings of the current window are used. This
9334 matters for anything that's displayed differently, such as
9335 'tabstop' and 'display'.
9336 When {string} contains characters with East Asian Width Class
9337 Ambiguous, this function's return value depends on 'ambiwidth'.
Bram Moolenaard592deb2022-06-17 15:42:40 +01009338 Returns zero on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009339 Also see |strlen()|, |strwidth()| and |strchars()|.
9340
9341 Can also be used as a |method|: >
9342 GetText()->strdisplaywidth()
9343
9344strftime({format} [, {time}]) *strftime()*
9345 The result is a String, which is a formatted date and time, as
9346 specified by the {format} string. The given {time} is used,
9347 or the current time if no time is given. The accepted
9348 {format} depends on your system, thus this is not portable!
9349 See the manual page of the C function strftime() for the
9350 format. The maximum length of the result is 80 characters.
9351 See also |localtime()|, |getftime()| and |strptime()|.
9352 The language can be changed with the |:language| command.
9353 Examples: >
9354 :echo strftime("%c") Sun Apr 27 11:49:23 1997
9355 :echo strftime("%Y %b %d %X") 1997 Apr 27 11:53:25
9356 :echo strftime("%y%m%d %T") 970427 11:53:55
9357 :echo strftime("%H:%M") 11:55
9358 :echo strftime("%c", getftime("file.c"))
9359 Show mod time of file.c.
9360< Not available on all systems. To check use: >
9361 :if exists("*strftime")
9362
9363< Can also be used as a |method|: >
9364 GetFormat()->strftime()
9365
9366strgetchar({str}, {index}) *strgetchar()*
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01009367 Get a Number corresponding to the character at {index} in
9368 {str}. This uses a zero-based character index, not a byte
9369 index. Composing characters are considered separate
9370 characters here. Use |nr2char()| to convert the Number to a
9371 String.
Bram Moolenaard592deb2022-06-17 15:42:40 +01009372 Returns -1 if {index} is invalid.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009373 Also see |strcharpart()| and |strchars()|.
9374
9375 Can also be used as a |method|: >
9376 GetText()->strgetchar(5)
9377
9378stridx({haystack}, {needle} [, {start}]) *stridx()*
9379 The result is a Number, which gives the byte index in
9380 {haystack} of the first occurrence of the String {needle}.
9381 If {start} is specified, the search starts at index {start}.
9382 This can be used to find a second match: >
9383 :let colon1 = stridx(line, ":")
9384 :let colon2 = stridx(line, ":", colon1 + 1)
9385< The search is done case-sensitive.
9386 For pattern searches use |match()|.
9387 -1 is returned if the {needle} does not occur in {haystack}.
9388 See also |strridx()|.
9389 Examples: >
9390 :echo stridx("An Example", "Example") 3
9391 :echo stridx("Starting point", "Start") 0
9392 :echo stridx("Starting point", "start") -1
9393< *strstr()* *strchr()*
9394 stridx() works similar to the C function strstr(). When used
9395 with a single character it works similar to strchr().
9396
9397 Can also be used as a |method|: >
9398 GetHaystack()->stridx(needle)
9399<
9400 *string()*
9401string({expr}) Return {expr} converted to a String. If {expr} is a Number,
9402 Float, String, Blob or a composition of them, then the result
9403 can be parsed back with |eval()|.
9404 {expr} type result ~
9405 String 'string' (single quotes are doubled)
9406 Number 123
9407 Float 123.123456 or 1.123456e8
9408 Funcref function('name')
9409 Blob 0z00112233.44556677.8899
9410 List [item, item]
9411 Dictionary {key: value, key: value}
Bram Moolenaarf1dcd142022-12-31 15:30:45 +00009412 Class class SomeName
9413 Object object of SomeName {lnum: 1, col: 3}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009414
9415 When a |List| or |Dictionary| has a recursive reference it is
9416 replaced by "[...]" or "{...}". Using eval() on the result
9417 will then fail.
9418
9419 Can also be used as a |method|: >
9420 mylist->string()
9421
9422< Also see |strtrans()|.
9423
9424
9425strlen({string}) *strlen()*
9426 The result is a Number, which is the length of the String
9427 {string} in bytes.
9428 If the argument is a Number it is first converted to a String.
Bram Moolenaard592deb2022-06-17 15:42:40 +01009429 For other types an error is given and zero is returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009430 If you want to count the number of multibyte characters use
9431 |strchars()|.
9432 Also see |len()|, |strdisplaywidth()| and |strwidth()|.
9433
9434 Can also be used as a |method|: >
9435 GetString()->strlen()
9436
9437strpart({src}, {start} [, {len} [, {chars}]]) *strpart()*
9438 The result is a String, which is part of {src}, starting from
9439 byte {start}, with the byte length {len}.
9440 When {chars} is present and TRUE then {len} is the number of
9441 characters positions (composing characters are not counted
9442 separately, thus "1" means one base character and any
9443 following composing characters).
9444 To count {start} as characters instead of bytes use
9445 |strcharpart()|.
9446
9447 When bytes are selected which do not exist, this doesn't
9448 result in an error, the bytes are simply omitted.
9449 If {len} is missing, the copy continues from {start} till the
9450 end of the {src}. >
9451 strpart("abcdefg", 3, 2) == "de"
9452 strpart("abcdefg", -2, 4) == "ab"
9453 strpart("abcdefg", 5, 4) == "fg"
9454 strpart("abcdefg", 3) == "defg"
9455
9456< Note: To get the first character, {start} must be 0. For
9457 example, to get the character under the cursor: >
9458 strpart(getline("."), col(".") - 1, 1, v:true)
9459<
Bram Moolenaard592deb2022-06-17 15:42:40 +01009460 Returns an empty string on error.
9461
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009462 Can also be used as a |method|: >
9463 GetText()->strpart(5)
9464
9465strptime({format}, {timestring}) *strptime()*
9466 The result is a Number, which is a unix timestamp representing
9467 the date and time in {timestring}, which is expected to match
9468 the format specified in {format}.
9469
9470 The accepted {format} depends on your system, thus this is not
9471 portable! See the manual page of the C function strptime()
9472 for the format. Especially avoid "%c". The value of $TZ also
9473 matters.
9474
9475 If the {timestring} cannot be parsed with {format} zero is
9476 returned. If you do not know the format of {timestring} you
9477 can try different {format} values until you get a non-zero
9478 result.
9479
9480 See also |strftime()|.
9481 Examples: >
9482 :echo strptime("%Y %b %d %X", "1997 Apr 27 11:49:23")
9483< 862156163 >
9484 :echo strftime("%c", strptime("%y%m%d %T", "970427 11:53:55"))
9485< Sun Apr 27 11:53:55 1997 >
9486 :echo strftime("%c", strptime("%Y%m%d%H%M%S", "19970427115355") + 3600)
9487< Sun Apr 27 12:53:55 1997
9488
9489 Can also be used as a |method|: >
9490 GetFormat()->strptime(timestring)
9491<
9492 Not available on all systems. To check use: >
9493 :if exists("*strptime")
9494
9495strridx({haystack}, {needle} [, {start}]) *strridx()*
9496 The result is a Number, which gives the byte index in
9497 {haystack} of the last occurrence of the String {needle}.
9498 When {start} is specified, matches beyond this index are
9499 ignored. This can be used to find a match before a previous
9500 match: >
9501 :let lastcomma = strridx(line, ",")
9502 :let comma2 = strridx(line, ",", lastcomma - 1)
9503< The search is done case-sensitive.
9504 For pattern searches use |match()|.
9505 -1 is returned if the {needle} does not occur in {haystack}.
9506 If the {needle} is empty the length of {haystack} is returned.
9507 See also |stridx()|. Examples: >
9508 :echo strridx("an angry armadillo", "an") 3
9509< *strrchr()*
9510 When used with a single character it works similar to the C
9511 function strrchr().
9512
9513 Can also be used as a |method|: >
9514 GetHaystack()->strridx(needle)
9515
9516strtrans({string}) *strtrans()*
9517 The result is a String, which is {string} with all unprintable
9518 characters translated into printable characters |'isprint'|.
9519 Like they are shown in a window. Example: >
9520 echo strtrans(@a)
9521< This displays a newline in register a as "^@" instead of
9522 starting a new line.
9523
Bram Moolenaard592deb2022-06-17 15:42:40 +01009524 Returns an empty string on error.
9525
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009526 Can also be used as a |method|: >
9527 GetString()->strtrans()
9528
Christian Brabandt67672ef2023-04-24 21:09:54 +01009529strutf16len({string} [, {countcc}]) *strutf16len()*
9530 The result is a Number, which is the number of UTF-16 code
9531 units in String {string} (after converting it to UTF-16).
9532
9533 When {countcc} is TRUE, composing characters are counted
9534 separately.
9535 When {countcc} is omitted or FALSE, composing characters are
9536 ignored.
9537
9538 Returns zero on error.
9539
9540 Also see |strlen()| and |strcharlen()|.
9541 Examples: >
9542 echo strutf16len('a') returns 1
9543 echo strutf16len('©') returns 1
9544 echo strutf16len('😊') returns 2
9545 echo strutf16len('ą́') returns 1
9546 echo strutf16len('ą́', v:true) returns 3
a5ob7r790f9a82023-09-25 06:05:47 +09009547<
Christian Brabandt67672ef2023-04-24 21:09:54 +01009548 Can also be used as a |method|: >
9549 GetText()->strutf16len()
9550<
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009551strwidth({string}) *strwidth()*
9552 The result is a Number, which is the number of display cells
9553 String {string} occupies. A Tab character is counted as one
9554 cell, alternatively use |strdisplaywidth()|.
9555 When {string} contains characters with East Asian Width Class
9556 Ambiguous, this function's return value depends on 'ambiwidth'.
Bram Moolenaard592deb2022-06-17 15:42:40 +01009557 Returns zero on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009558 Also see |strlen()|, |strdisplaywidth()| and |strchars()|.
9559
9560 Can also be used as a |method|: >
9561 GetString()->strwidth()
9562
9563submatch({nr} [, {list}]) *submatch()* *E935*
9564 Only for an expression in a |:substitute| command or
9565 substitute() function.
9566 Returns the {nr}'th submatch of the matched text. When {nr}
9567 is 0 the whole matched text is returned.
9568 Note that a NL in the string can stand for a line break of a
9569 multi-line match or a NUL character in the text.
9570 Also see |sub-replace-expression|.
9571
9572 If {list} is present and non-zero then submatch() returns
9573 a list of strings, similar to |getline()| with two arguments.
9574 NL characters in the text represent NUL characters in the
9575 text.
9576 Only returns more than one item for |:substitute|, inside
9577 |substitute()| this list will always contain one or zero
9578 items, since there are no real line breaks.
9579
9580 When substitute() is used recursively only the submatches in
9581 the current (deepest) call can be obtained.
9582
Bram Moolenaard592deb2022-06-17 15:42:40 +01009583 Returns an empty string or list on error.
9584
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009585 Examples: >
9586 :s/\d\+/\=submatch(0) + 1/
9587 :echo substitute(text, '\d\+', '\=submatch(0) + 1', '')
9588< This finds the first number in the line and adds one to it.
9589 A line break is included as a newline character.
9590
9591 Can also be used as a |method|: >
9592 GetNr()->submatch()
9593
9594substitute({string}, {pat}, {sub}, {flags}) *substitute()*
9595 The result is a String, which is a copy of {string}, in which
9596 the first match of {pat} is replaced with {sub}.
9597 When {flags} is "g", all matches of {pat} in {string} are
9598 replaced. Otherwise {flags} should be "".
9599
9600 This works like the ":substitute" command (without any flags).
9601 But the matching with {pat} is always done like the 'magic'
9602 option is set and 'cpoptions' is empty (to make scripts
9603 portable). 'ignorecase' is still relevant, use |/\c| or |/\C|
9604 if you want to ignore or match case and ignore 'ignorecase'.
9605 'smartcase' is not used. See |string-match| for how {pat} is
9606 used.
9607
9608 A "~" in {sub} is not replaced with the previous {sub}.
9609 Note that some codes in {sub} have a special meaning
9610 |sub-replace-special|. For example, to replace something with
9611 "\n" (two characters), use "\\\\n" or '\\n'.
9612
9613 When {pat} does not match in {string}, {string} is returned
9614 unmodified.
9615
9616 Example: >
9617 :let &path = substitute(&path, ",\\=[^,]*$", "", "")
9618< This removes the last component of the 'path' option. >
9619 :echo substitute("testing", ".*", "\\U\\0", "")
9620< results in "TESTING".
9621
9622 When {sub} starts with "\=", the remainder is interpreted as
9623 an expression. See |sub-replace-expression|. Example: >
9624 :echo substitute(s, '%\(\x\x\)',
Bram Moolenaarc51cf032022-02-26 12:25:45 +00009625 \ '\=nr2char("0x" .. submatch(1))', 'g')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009626
9627< When {sub} is a Funcref that function is called, with one
9628 optional argument. Example: >
9629 :echo substitute(s, '%\(\x\x\)', SubNr, 'g')
9630< The optional argument is a list which contains the whole
9631 matched string and up to nine submatches, like what
9632 |submatch()| returns. Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00009633 :echo substitute(s, '%\(\x\x\)', {m -> '0x' .. m[1]}, 'g')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009634
Bram Moolenaard592deb2022-06-17 15:42:40 +01009635< Returns an empty string on error.
9636
9637 Can also be used as a |method|: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009638 GetString()->substitute(pat, sub, flags)
9639
Bram Moolenaarc216a7a2022-12-05 13:50:55 +00009640swapfilelist() *swapfilelist()*
9641 Returns a list of swap file names, like what "vim -r" shows.
9642 See the |-r| command argument. The 'directory' option is used
9643 for the directories to inspect. If you only want to get a
9644 list of swap files in the current directory then temporarily
9645 set 'directory' to a dot: >
9646 let save_dir = &directory
9647 let &directory = '.'
9648 let swapfiles = swapfilelist()
9649 let &directory = save_dir
9650
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009651swapinfo({fname}) *swapinfo()*
9652 The result is a dictionary, which holds information about the
9653 swapfile {fname}. The available fields are:
9654 version Vim version
9655 user user name
9656 host host name
9657 fname original file name
9658 pid PID of the Vim process that created the swap
9659 file
9660 mtime last modification time in seconds
9661 inode Optional: INODE number of the file
9662 dirty 1 if file was modified, 0 if not
9663 Note that "user" and "host" are truncated to at most 39 bytes.
9664 In case of failure an "error" item is added with the reason:
9665 Cannot open file: file not found or in accessible
9666 Cannot read file: cannot read first block
9667 Not a swap file: does not contain correct block ID
9668 Magic number mismatch: Info in first block is invalid
9669
9670 Can also be used as a |method|: >
9671 GetFilename()->swapinfo()
9672
9673swapname({buf}) *swapname()*
9674 The result is the swap file path of the buffer {expr}.
9675 For the use of {buf}, see |bufname()| above.
9676 If buffer {buf} is the current buffer, the result is equal to
9677 |:swapname| (unless there is no swap file).
9678 If buffer {buf} has no swap file, returns an empty string.
9679
9680 Can also be used as a |method|: >
9681 GetBufname()->swapname()
9682
9683synID({lnum}, {col}, {trans}) *synID()*
9684 The result is a Number, which is the syntax ID at the position
9685 {lnum} and {col} in the current window.
9686 The syntax ID can be used with |synIDattr()| and
9687 |synIDtrans()| to obtain syntax information about text.
9688
9689 {col} is 1 for the leftmost column, {lnum} is 1 for the first
9690 line. 'synmaxcol' applies, in a longer line zero is returned.
9691 Note that when the position is after the last character,
9692 that's where the cursor can be in Insert mode, synID() returns
9693 zero. {lnum} is used like with |getline()|.
9694
9695 When {trans} is |TRUE|, transparent items are reduced to the
9696 item that they reveal. This is useful when wanting to know
9697 the effective color. When {trans} is |FALSE|, the transparent
9698 item is returned. This is useful when wanting to know which
9699 syntax item is effective (e.g. inside parens).
9700 Warning: This function can be very slow. Best speed is
9701 obtained by going through the file in forward direction.
9702
Bram Moolenaard592deb2022-06-17 15:42:40 +01009703 Returns zero on error.
9704
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009705 Example (echoes the name of the syntax item under the cursor): >
9706 :echo synIDattr(synID(line("."), col("."), 1), "name")
9707<
9708
9709synIDattr({synID}, {what} [, {mode}]) *synIDattr()*
9710 The result is a String, which is the {what} attribute of
9711 syntax ID {synID}. This can be used to obtain information
9712 about a syntax item.
9713 {mode} can be "gui", "cterm" or "term", to get the attributes
9714 for that mode. When {mode} is omitted, or an invalid value is
9715 used, the attributes for the currently active highlighting are
9716 used (GUI, cterm or term).
9717 Use synIDtrans() to follow linked highlight groups.
9718 {what} result
9719 "name" the name of the syntax item
9720 "fg" foreground color (GUI: color name used to set
9721 the color, cterm: color number as a string,
9722 term: empty string)
9723 "bg" background color (as with "fg")
9724 "font" font name (only available in the GUI)
9725 |highlight-font|
9726 "sp" special color for the GUI (as with "fg")
9727 |highlight-guisp|
9728 "ul" underline color for cterm: number as a string
9729 "fg#" like "fg", but for the GUI and the GUI is
9730 running the name in "#RRGGBB" form
9731 "bg#" like "fg#" for "bg"
9732 "sp#" like "fg#" for "sp"
9733 "bold" "1" if bold
9734 "italic" "1" if italic
9735 "reverse" "1" if reverse
9736 "inverse" "1" if inverse (= reverse)
9737 "standout" "1" if standout
9738 "underline" "1" if underlined
9739 "undercurl" "1" if undercurled
9740 "strike" "1" if strikethrough
Bram Moolenaarde786322022-07-30 14:56:17 +01009741 "nocombine" "1" if nocombine
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009742
Bram Moolenaard592deb2022-06-17 15:42:40 +01009743 Returns an empty string on error.
9744
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009745 Example (echoes the color of the syntax item under the
9746 cursor): >
9747 :echo synIDattr(synIDtrans(synID(line("."), col("."), 1)), "fg")
9748<
9749 Can also be used as a |method|: >
9750 :echo synID(line("."), col("."), 1)->synIDtrans()->synIDattr("fg")
9751
9752
9753synIDtrans({synID}) *synIDtrans()*
9754 The result is a Number, which is the translated syntax ID of
9755 {synID}. This is the syntax group ID of what is being used to
9756 highlight the character. Highlight links given with
9757 ":highlight link" are followed.
9758
Bram Moolenaard592deb2022-06-17 15:42:40 +01009759 Returns zero on error.
9760
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009761 Can also be used as a |method|: >
9762 :echo synID(line("."), col("."), 1)->synIDtrans()->synIDattr("fg")
9763
9764synconcealed({lnum}, {col}) *synconcealed()*
9765 The result is a |List| with currently three items:
9766 1. The first item in the list is 0 if the character at the
9767 position {lnum} and {col} is not part of a concealable
9768 region, 1 if it is. {lnum} is used like with |getline()|.
9769 2. The second item in the list is a string. If the first item
9770 is 1, the second item contains the text which will be
9771 displayed in place of the concealed text, depending on the
9772 current setting of 'conceallevel' and 'listchars'.
9773 3. The third and final item in the list is a number
9774 representing the specific syntax region matched in the
9775 line. When the character is not concealed the value is
9776 zero. This allows detection of the beginning of a new
9777 concealable region if there are two consecutive regions
9778 with the same replacement character. For an example, if
9779 the text is "123456" and both "23" and "45" are concealed
9780 and replaced by the character "X", then:
9781 call returns ~
9782 synconcealed(lnum, 1) [0, '', 0]
9783 synconcealed(lnum, 2) [1, 'X', 1]
9784 synconcealed(lnum, 3) [1, 'X', 1]
9785 synconcealed(lnum, 4) [1, 'X', 2]
9786 synconcealed(lnum, 5) [1, 'X', 2]
9787 synconcealed(lnum, 6) [0, '', 0]
9788
9789
9790synstack({lnum}, {col}) *synstack()*
9791 Return a |List|, which is the stack of syntax items at the
9792 position {lnum} and {col} in the current window. {lnum} is
9793 used like with |getline()|. Each item in the List is an ID
9794 like what |synID()| returns.
9795 The first item in the List is the outer region, following are
9796 items contained in that one. The last one is what |synID()|
9797 returns, unless not the whole item is highlighted or it is a
9798 transparent item.
9799 This function is useful for debugging a syntax file.
9800 Example that shows the syntax stack under the cursor: >
9801 for id in synstack(line("."), col("."))
9802 echo synIDattr(id, "name")
9803 endfor
9804< When the position specified with {lnum} and {col} is invalid
Bram Moolenaard592deb2022-06-17 15:42:40 +01009805 an empty List is returned. The position just after the last
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009806 character in a line and the first column in an empty line are
9807 valid positions.
9808
9809system({expr} [, {input}]) *system()* *E677*
9810 Get the output of the shell command {expr} as a |String|. See
9811 |systemlist()| to get the output as a |List|.
9812
9813 When {input} is given and is a |String| this string is written
9814 to a file and passed as stdin to the command. The string is
9815 written as-is, you need to take care of using the correct line
9816 separators yourself.
9817 If {input} is given and is a |List| it is written to the file
9818 in a way |writefile()| does with {binary} set to "b" (i.e.
9819 with a newline between each list item with newlines inside
9820 list items converted to NULs).
9821 When {input} is given and is a number that is a valid id for
9822 an existing buffer then the content of the buffer is written
9823 to the file line by line, each line terminated by a NL and
9824 NULs characters where the text has a NL.
9825
9826 Pipes are not used, the 'shelltemp' option is not used.
9827
9828 When prepended by |:silent| the terminal will not be set to
9829 cooked mode. This is meant to be used for commands that do
9830 not need the user to type. It avoids stray characters showing
9831 up on the screen which require |CTRL-L| to remove. >
9832 :silent let f = system('ls *.vim')
9833<
9834 Note: Use |shellescape()| or |::S| with |expand()| or
9835 |fnamemodify()| to escape special characters in a command
9836 argument. Newlines in {expr} may cause the command to fail.
9837 The characters in 'shellquote' and 'shellxquote' may also
9838 cause trouble.
9839 This is not to be used for interactive commands.
9840
9841 The result is a String. Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00009842 :let files = system('ls ' .. shellescape(expand('%:h')))
9843 :let files = system('ls ' .. expand('%:h:S'))
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009844
9845< To make the result more system-independent, the shell output
9846 is filtered to replace <CR> with <NL> for Macintosh, and
9847 <CR><NL> with <NL> for DOS-like systems.
9848 To avoid the string being truncated at a NUL, all NUL
9849 characters are replaced with SOH (0x01).
9850
9851 The command executed is constructed using several options:
9852 'shell' 'shellcmdflag' 'shellxquote' {expr} 'shellredir' {tmp} 'shellxquote'
9853 ({tmp} is an automatically generated file name).
9854 For Unix, braces are put around {expr} to allow for
9855 concatenated commands.
9856
9857 The command will be executed in "cooked" mode, so that a
9858 CTRL-C will interrupt the command (on Unix at least).
9859
9860 The resulting error code can be found in |v:shell_error|.
9861 This function will fail in |restricted-mode|.
9862
9863 Note that any wrong value in the options mentioned above may
9864 make the function fail. It has also been reported to fail
9865 when using a security agent application.
9866 Unlike ":!cmd" there is no automatic check for changed files.
9867 Use |:checktime| to force a check.
9868
9869 Can also be used as a |method|: >
9870 :echo GetCmd()->system()
9871
9872
9873systemlist({expr} [, {input}]) *systemlist()*
9874 Same as |system()|, but returns a |List| with lines (parts of
9875 output separated by NL) with NULs transformed into NLs. Output
9876 is the same as |readfile()| will output with {binary} argument
9877 set to "b", except that there is no extra empty item when the
9878 result ends in a NL.
9879 Note that on MS-Windows you may get trailing CR characters.
9880
9881 To see the difference between "echo hello" and "echo -n hello"
9882 use |system()| and |split()|: >
9883 echo system('echo hello')->split('\n', 1)
9884<
9885 Returns an empty string on error.
9886
9887 Can also be used as a |method|: >
9888 :echo GetCmd()->systemlist()
9889
9890
9891tabpagebuflist([{arg}]) *tabpagebuflist()*
9892 The result is a |List|, where each item is the number of the
9893 buffer associated with each window in the current tab page.
9894 {arg} specifies the number of the tab page to be used. When
9895 omitted the current tab page is used.
9896 When {arg} is invalid the number zero is returned.
9897 To get a list of all buffers in all tabs use this: >
9898 let buflist = []
9899 for i in range(tabpagenr('$'))
9900 call extend(buflist, tabpagebuflist(i + 1))
9901 endfor
9902< Note that a buffer may appear in more than one window.
9903
9904 Can also be used as a |method|: >
9905 GetTabpage()->tabpagebuflist()
9906
9907tabpagenr([{arg}]) *tabpagenr()*
9908 The result is a Number, which is the number of the current
9909 tab page. The first tab page has number 1.
9910
9911 The optional argument {arg} supports the following values:
9912 $ the number of the last tab page (the tab page
9913 count).
9914 # the number of the last accessed tab page
9915 (where |g<Tab>| goes to). if there is no
9916 previous tab page 0 is returned.
9917 The number can be used with the |:tab| command.
9918
Bram Moolenaard592deb2022-06-17 15:42:40 +01009919 Returns zero on error.
9920
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009921
9922tabpagewinnr({tabarg} [, {arg}]) *tabpagewinnr()*
9923 Like |winnr()| but for tab page {tabarg}.
9924 {tabarg} specifies the number of tab page to be used.
9925 {arg} is used like with |winnr()|:
9926 - When omitted the current window number is returned. This is
9927 the window which will be used when going to this tab page.
9928 - When "$" the number of windows is returned.
9929 - When "#" the previous window nr is returned.
9930 Useful examples: >
9931 tabpagewinnr(1) " current window of tab page 1
9932 tabpagewinnr(4, '$') " number of windows in tab page 4
9933< When {tabarg} is invalid zero is returned.
9934
9935 Can also be used as a |method|: >
9936 GetTabpage()->tabpagewinnr()
9937<
9938 *tagfiles()*
9939tagfiles() Returns a |List| with the file names used to search for tags
9940 for the current buffer. This is the 'tags' option expanded.
9941
9942
9943taglist({expr} [, {filename}]) *taglist()*
9944 Returns a |List| of tags matching the regular expression {expr}.
9945
9946 If {filename} is passed it is used to prioritize the results
9947 in the same way that |:tselect| does. See |tag-priority|.
9948 {filename} should be the full path of the file.
9949
9950 Each list item is a dictionary with at least the following
9951 entries:
9952 name Name of the tag.
9953 filename Name of the file where the tag is
9954 defined. It is either relative to the
9955 current directory or a full path.
9956 cmd Ex command used to locate the tag in
9957 the file.
9958 kind Type of the tag. The value for this
9959 entry depends on the language specific
9960 kind values. Only available when
9961 using a tags file generated by
Bram Moolenaar47c532e2022-03-19 15:18:53 +00009962 Universal/Exuberant ctags or hdrtag.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009963 static A file specific tag. Refer to
9964 |static-tag| for more information.
9965 More entries may be present, depending on the content of the
9966 tags file: access, implementation, inherits and signature.
9967 Refer to the ctags documentation for information about these
9968 fields. For C code the fields "struct", "class" and "enum"
9969 may appear, they give the name of the entity the tag is
9970 contained in.
9971
9972 The ex-command "cmd" can be either an ex search pattern, a
9973 line number or a line number followed by a byte number.
9974
9975 If there are no matching tags, then an empty list is returned.
9976
9977 To get an exact tag match, the anchors '^' and '$' should be
9978 used in {expr}. This also make the function work faster.
9979 Refer to |tag-regexp| for more information about the tag
9980 search regular expression pattern.
9981
9982 Refer to |'tags'| for information about how the tags file is
9983 located by Vim. Refer to |tags-file-format| for the format of
9984 the tags file generated by the different ctags tools.
9985
9986 Can also be used as a |method|: >
9987 GetTagpattern()->taglist()
9988
9989tan({expr}) *tan()*
9990 Return the tangent of {expr}, measured in radians, as a |Float|
9991 in the range [-inf, inf].
9992 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaard592deb2022-06-17 15:42:40 +01009993 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009994 Examples: >
9995 :echo tan(10)
9996< 0.648361 >
9997 :echo tan(-4.01)
9998< -1.181502
9999
10000 Can also be used as a |method|: >
10001 Compute()->tan()
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010002
10003
10004tanh({expr}) *tanh()*
10005 Return the hyperbolic tangent of {expr} as a |Float| in the
10006 range [-1, 1].
10007 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaard592deb2022-06-17 15:42:40 +010010008 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010009 Examples: >
10010 :echo tanh(0.5)
10011< 0.462117 >
10012 :echo tanh(-1)
10013< -0.761594
10014
10015 Can also be used as a |method|: >
10016 Compute()->tanh()
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010017
10018
10019tempname() *tempname()* *temp-file-name*
10020 The result is a String, which is the name of a file that
10021 doesn't exist. It can be used for a temporary file. The name
10022 is different for at least 26 consecutive calls. Example: >
10023 :let tmpfile = tempname()
Bram Moolenaarc51cf032022-02-26 12:25:45 +000010024 :exe "redir > " .. tmpfile
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010025< For Unix, the file will be in a private directory |tempfile|.
10026 For MS-Windows forward slashes are used when the 'shellslash'
10027 option is set, or when 'shellcmdflag' starts with '-' and
10028 'shell' does not contain powershell or pwsh.
10029
10030
10031term_ functions are documented here: |terminal-function-details|
10032
10033
10034terminalprops() *terminalprops()*
10035 Returns a |Dictionary| with properties of the terminal that Vim
10036 detected from the response to |t_RV| request. See
10037 |v:termresponse| for the response itself. If |v:termresponse|
10038 is empty most values here will be 'u' for unknown.
10039 cursor_style whether sending |t_RS| works **
10040 cursor_blink_mode whether sending |t_RC| works **
10041 underline_rgb whether |t_8u| works **
10042 mouse mouse type supported
Bram Moolenaar4bc85f22022-10-21 14:17:24 +010010043 kitty whether Kitty terminal was detected
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010044
10045 ** value 'u' for unknown, 'y' for yes, 'n' for no
10046
10047 If the |+termresponse| feature is missing then the result is
10048 an empty dictionary.
10049
10050 If "cursor_style" is 'y' then |t_RS| will be sent to request the
10051 current cursor style.
10052 If "cursor_blink_mode" is 'y' then |t_RC| will be sent to
10053 request the cursor blink status.
10054 "cursor_style" and "cursor_blink_mode" are also set if |t_u7|
10055 is not empty, Vim will detect the working of sending |t_RS|
10056 and |t_RC| on startup.
10057
10058 When "underline_rgb" is not 'y', then |t_8u| will be made empty.
10059 This avoids sending it to xterm, which would clear the colors.
10060
10061 For "mouse" the value 'u' is unknown
10062
10063 Also see:
10064 - 'ambiwidth' - detected by using |t_u7|.
10065 - |v:termstyleresp| and |v:termblinkresp| for the response to
10066 |t_RS| and |t_RC|.
10067
10068
10069test_ functions are documented here: |test-functions-details|
10070
10071
10072 *timer_info()*
10073timer_info([{id}])
10074 Return a list with information about timers.
10075 When {id} is given only information about this timer is
10076 returned. When timer {id} does not exist an empty list is
10077 returned.
10078 When {id} is omitted information about all timers is returned.
10079
10080 For each timer the information is stored in a |Dictionary| with
10081 these items:
10082 "id" the timer ID
10083 "time" time the timer was started with
10084 "remaining" time until the timer fires
10085 "repeat" number of times the timer will still fire;
10086 -1 means forever
10087 "callback" the callback
10088 "paused" 1 if the timer is paused, 0 otherwise
10089
10090 Can also be used as a |method|: >
10091 GetTimer()->timer_info()
10092
10093< {only available when compiled with the |+timers| feature}
10094
10095timer_pause({timer}, {paused}) *timer_pause()*
10096 Pause or unpause a timer. A paused timer does not invoke its
10097 callback when its time expires. Unpausing a timer may cause
10098 the callback to be invoked almost immediately if enough time
10099 has passed.
10100
10101 Pausing a timer is useful to avoid the callback to be called
10102 for a short time.
10103
10104 If {paused} evaluates to a non-zero Number or a non-empty
10105 String, then the timer is paused, otherwise it is unpaused.
10106 See |non-zero-arg|.
10107
10108 Can also be used as a |method|: >
10109 GetTimer()->timer_pause(1)
10110
10111< {only available when compiled with the |+timers| feature}
10112
10113 *timer_start()* *timer* *timers*
10114timer_start({time}, {callback} [, {options}])
10115 Create a timer and return the timer ID.
10116
10117 {time} is the waiting time in milliseconds. This is the
10118 minimum time before invoking the callback. When the system is
10119 busy or Vim is not waiting for input the time will be longer.
Bram Moolenaardd60c362023-02-27 15:49:53 +000010120 Zero can be used to execute the callback when Vim is back in
10121 the main loop.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010122
10123 {callback} is the function to call. It can be the name of a
10124 function or a |Funcref|. It is called with one argument, which
10125 is the timer ID. The callback is only invoked when Vim is
10126 waiting for input.
10127 If you want to show a message look at |popup_notification()|
10128 to avoid interfering with what the user is doing.
10129
10130 {options} is a dictionary. Supported entries:
10131 "repeat" Number of times to repeat calling the
10132 callback. -1 means forever. When not present
10133 the callback will be called once.
10134 If the timer causes an error three times in a
10135 row the repeat is cancelled. This avoids that
10136 Vim becomes unusable because of all the error
10137 messages.
10138
Bram Moolenaard592deb2022-06-17 15:42:40 +010010139 Returns -1 on error.
10140
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010141 Example: >
10142 func MyHandler(timer)
10143 echo 'Handler called'
10144 endfunc
10145 let timer = timer_start(500, 'MyHandler',
10146 \ {'repeat': 3})
10147< This will invoke MyHandler() three times at 500 msec
10148 intervals.
10149
10150 Can also be used as a |method|: >
10151 GetMsec()->timer_start(callback)
10152
10153< Not available in the |sandbox|.
10154 {only available when compiled with the |+timers| feature}
10155
10156timer_stop({timer}) *timer_stop()*
10157 Stop a timer. The timer callback will no longer be invoked.
10158 {timer} is an ID returned by timer_start(), thus it must be a
10159 Number. If {timer} does not exist there is no error.
10160
10161 Can also be used as a |method|: >
10162 GetTimer()->timer_stop()
10163
10164< {only available when compiled with the |+timers| feature}
10165
10166timer_stopall() *timer_stopall()*
10167 Stop all timers. The timer callbacks will no longer be
10168 invoked. Useful if a timer is misbehaving. If there are no
10169 timers there is no error.
10170
10171 {only available when compiled with the |+timers| feature}
10172
10173tolower({expr}) *tolower()*
10174 The result is a copy of the String given, with all uppercase
10175 characters turned into lowercase (just like applying |gu| to
Bram Moolenaard592deb2022-06-17 15:42:40 +010010176 the string). Returns an empty string on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010177
10178 Can also be used as a |method|: >
10179 GetText()->tolower()
10180
10181toupper({expr}) *toupper()*
10182 The result is a copy of the String given, with all lowercase
10183 characters turned into uppercase (just like applying |gU| to
Bram Moolenaard592deb2022-06-17 15:42:40 +010010184 the string). Returns an empty string on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010185
10186 Can also be used as a |method|: >
10187 GetText()->toupper()
10188
10189tr({src}, {fromstr}, {tostr}) *tr()*
10190 The result is a copy of the {src} string with all characters
10191 which appear in {fromstr} replaced by the character in that
10192 position in the {tostr} string. Thus the first character in
10193 {fromstr} is translated into the first character in {tostr}
10194 and so on. Exactly like the unix "tr" command.
10195 This code also deals with multibyte characters properly.
10196
Bram Moolenaard592deb2022-06-17 15:42:40 +010010197 Returns an empty string on error.
10198
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010199 Examples: >
10200 echo tr("hello there", "ht", "HT")
10201< returns "Hello THere" >
10202 echo tr("<blob>", "<>", "{}")
10203< returns "{blob}"
10204
10205 Can also be used as a |method|: >
10206 GetText()->tr(from, to)
10207
10208trim({text} [, {mask} [, {dir}]]) *trim()*
10209 Return {text} as a String where any character in {mask} is
10210 removed from the beginning and/or end of {text}.
10211
Illia Bobyr80799172023-10-17 18:00:50 +020010212 If {mask} is not given, or is an empty string, {mask} is all
10213 characters up to 0x20, which includes Tab, space, NL and CR,
10214 plus the non-breaking space character 0xa0.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010215
10216 The optional {dir} argument specifies where to remove the
10217 characters:
10218 0 remove from the beginning and end of {text}
10219 1 remove only at the beginning of {text}
10220 2 remove only at the end of {text}
10221 When omitted both ends are trimmed.
10222
10223 This function deals with multibyte characters properly.
Bram Moolenaard592deb2022-06-17 15:42:40 +010010224 Returns an empty string on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010225
10226 Examples: >
10227 echo trim(" some text ")
10228< returns "some text" >
Bram Moolenaarc51cf032022-02-26 12:25:45 +000010229 echo trim(" \r\t\t\r RESERVE \t\n\x0B\xA0") .. "_TAIL"
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010230< returns "RESERVE_TAIL" >
10231 echo trim("rm<Xrm<>X>rrm", "rm<>")
10232< returns "Xrm<>X" (characters in the middle are not removed) >
10233 echo trim(" vim ", " ", 2)
10234< returns " vim"
10235
10236 Can also be used as a |method|: >
10237 GetText()->trim()
10238
10239trunc({expr}) *trunc()*
10240 Return the largest integral value with magnitude less than or
10241 equal to {expr} as a |Float| (truncate towards zero).
10242 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaard592deb2022-06-17 15:42:40 +010010243 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010244 Examples: >
10245 echo trunc(1.456)
10246< 1.0 >
10247 echo trunc(-5.456)
10248< -5.0 >
10249 echo trunc(4.0)
10250< 4.0
10251
10252 Can also be used as a |method|: >
10253 Compute()->trunc()
10254<
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010255 *type()*
10256type({expr}) The result is a Number representing the type of {expr}.
10257 Instead of using the number directly, it is better to use the
10258 v:t_ variable that has the value:
10259 Number: 0 |v:t_number|
10260 String: 1 |v:t_string|
10261 Funcref: 2 |v:t_func|
10262 List: 3 |v:t_list|
10263 Dictionary: 4 |v:t_dict|
10264 Float: 5 |v:t_float|
10265 Boolean: 6 |v:t_bool| (v:false and v:true)
10266 None: 7 |v:t_none| (v:null and v:none)
10267 Job: 8 |v:t_job|
10268 Channel: 9 |v:t_channel|
10269 Blob: 10 |v:t_blob|
h_east596a9f22023-11-21 21:24:23 +090010270 Class: 12 |v:t_class|
10271 Object: 13 |v:t_object|
Yegappan Lakshmanan2a71b542023-12-14 20:03:03 +010010272 Typealias: 14 |v:t_typealias|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010273 For backward compatibility, this method can be used: >
10274 :if type(myvar) == type(0)
10275 :if type(myvar) == type("")
10276 :if type(myvar) == type(function("tr"))
10277 :if type(myvar) == type([])
10278 :if type(myvar) == type({})
10279 :if type(myvar) == type(0.0)
10280 :if type(myvar) == type(v:false)
10281 :if type(myvar) == type(v:none)
10282< To check if the v:t_ variables exist use this: >
10283 :if exists('v:t_number')
10284
10285< Can also be used as a |method|: >
10286 mylist->type()
10287
10288
10289typename({expr}) *typename()*
10290 Return a string representation of the type of {expr}.
10291 Example: >
10292 echo typename([1, 2, 3])
Kota Kato66bb9ae2023-01-17 18:31:56 +000010293< list<number> ~
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010294
10295
10296undofile({name}) *undofile()*
10297 Return the name of the undo file that would be used for a file
10298 with name {name} when writing. This uses the 'undodir'
10299 option, finding directories that exist. It does not check if
10300 the undo file exists.
10301 {name} is always expanded to the full path, since that is what
10302 is used internally.
10303 If {name} is empty undofile() returns an empty string, since a
10304 buffer without a file name will not write an undo file.
10305 Useful in combination with |:wundo| and |:rundo|.
10306 When compiled without the |+persistent_undo| option this always
10307 returns an empty string.
10308
10309 Can also be used as a |method|: >
10310 GetFilename()->undofile()
10311
Devin J. Pohly5fee1112023-04-23 20:26:59 -050010312undotree([{buf}]) *undotree()*
10313 Return the current state of the undo tree for the current
10314 buffer, or for a specific buffer if {buf} is given. The
10315 result is a dictionary with the following items:
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010316 "seq_last" The highest undo sequence number used.
10317 "seq_cur" The sequence number of the current position in
10318 the undo tree. This differs from "seq_last"
10319 when some changes were undone.
10320 "time_cur" Time last used for |:earlier| and related
10321 commands. Use |strftime()| to convert to
10322 something readable.
10323 "save_last" Number of the last file write. Zero when no
10324 write yet.
10325 "save_cur" Number of the current position in the undo
10326 tree.
10327 "synced" Non-zero when the last undo block was synced.
10328 This happens when waiting from input from the
10329 user. See |undo-blocks|.
10330 "entries" A list of dictionaries with information about
10331 undo blocks.
10332
10333 The first item in the "entries" list is the oldest undo item.
10334 Each List item is a |Dictionary| with these items:
10335 "seq" Undo sequence number. Same as what appears in
10336 |:undolist|.
10337 "time" Timestamp when the change happened. Use
10338 |strftime()| to convert to something readable.
10339 "newhead" Only appears in the item that is the last one
10340 that was added. This marks the last change
10341 and where further changes will be added.
10342 "curhead" Only appears in the item that is the last one
10343 that was undone. This marks the current
10344 position in the undo tree, the block that will
10345 be used by a redo command. When nothing was
10346 undone after the last change this item will
10347 not appear anywhere.
10348 "save" Only appears on the last block before a file
10349 write. The number is the write count. The
10350 first write has number 1, the last one the
10351 "save_last" mentioned above.
10352 "alt" Alternate entry. This is again a List of undo
10353 blocks. Each item may again have an "alt"
10354 item.
10355
10356uniq({list} [, {func} [, {dict}]]) *uniq()* *E882*
10357 Remove second and succeeding copies of repeated adjacent
10358 {list} items in-place. Returns {list}. If you want a list
10359 to remain unmodified make a copy first: >
10360 :let newlist = uniq(copy(mylist))
10361< The default compare function uses the string representation of
10362 each item. For the use of {func} and {dict} see |sort()|.
10363
Bram Moolenaard592deb2022-06-17 15:42:40 +010010364 Returns zero if {list} is not a |List|.
10365
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010366 Can also be used as a |method|: >
10367 mylist->uniq()
Christian Brabandt67672ef2023-04-24 21:09:54 +010010368<
10369 *utf16idx()*
10370utf16idx({string}, {idx} [, {countcc} [, {charidx}]])
Yegappan Lakshmanan577922b2023-06-08 17:09:45 +010010371 Same as |charidx()| but returns the UTF-16 code unit index of
10372 the byte at {idx} in {string} (after converting it to UTF-16).
Christian Brabandt67672ef2023-04-24 21:09:54 +010010373
10374 When {charidx} is present and TRUE, {idx} is used as the
10375 character index in the String {string} instead of as the byte
10376 index.
Yegappan Lakshmanan95707032023-06-14 13:10:15 +010010377 An {idx} in the middle of a UTF-8 sequence is rounded
10378 downwards to the beginning of that sequence.
Christian Brabandt67672ef2023-04-24 21:09:54 +010010379
Yegappan Lakshmanan577922b2023-06-08 17:09:45 +010010380 Returns -1 if the arguments are invalid or if there are less
10381 than {idx} bytes in {string}. If there are exactly {idx} bytes
10382 the length of the string in UTF-16 code units is returned.
10383
Christian Brabandt67672ef2023-04-24 21:09:54 +010010384 See |byteidx()| and |byteidxcomp()| for getting the byte index
10385 from the UTF-16 index and |charidx()| for getting the
10386 character index from the UTF-16 index.
10387 Refer to |string-offset-encoding| for more information.
10388 Examples: >
10389 echo utf16idx('a😊😊', 3) returns 2
10390 echo utf16idx('a😊😊', 7) returns 4
10391 echo utf16idx('a😊😊', 1, 0, 1) returns 2
10392 echo utf16idx('a😊😊', 2, 0, 1) returns 4
10393 echo utf16idx('aą́c', 6) returns 2
10394 echo utf16idx('aą́c', 6, 1) returns 4
10395 echo utf16idx('a😊😊', 9) returns -1
10396<
10397 Can also be used as a |method|: >
10398 GetName()->utf16idx(idx)
10399
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010400
10401values({dict}) *values()*
10402 Return a |List| with all the values of {dict}. The |List| is
10403 in arbitrary order. Also see |items()| and |keys()|.
Bram Moolenaard592deb2022-06-17 15:42:40 +010010404 Returns zero if {dict} is not a |Dict|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010405
10406 Can also be used as a |method|: >
10407 mydict->values()
10408
zeertzjq825cf812023-08-17 22:55:25 +020010409virtcol({expr} [, {list} [, {winid}]]) *virtcol()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010410 The result is a Number, which is the screen column of the file
10411 position given with {expr}. That is, the last screen position
10412 occupied by the character at that position, when the screen
10413 would be of unlimited width. When there is a <Tab> at the
10414 position, the returned Number will be the column at the end of
10415 the <Tab>. For example, for a <Tab> in column 1, with 'ts'
10416 set to 8, it returns 8. |conceal| is ignored.
10417 For the byte position use |col()|.
LemonBoy0f7a3e12022-05-26 12:10:37 +010010418
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010419 For the use of {expr} see |col()|.
LemonBoy0f7a3e12022-05-26 12:10:37 +010010420
10421 When 'virtualedit' is used {expr} can be [lnum, col, off],
10422 where "off" is the offset in screen columns from the start of
10423 the character. E.g., a position within a <Tab> or after the
10424 last character. When "off" is omitted zero is used. When
10425 Virtual editing is active in the current mode, a position
10426 beyond the end of the line can be returned. Also see
10427 |'virtualedit'|
10428
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010429 The accepted positions are:
10430 . the cursor position
10431 $ the end of the cursor line (the result is the
10432 number of displayed characters in the cursor line
10433 plus one)
10434 'x position of mark x (if the mark is not set, 0 is
10435 returned)
10436 v In Visual mode: the start of the Visual area (the
10437 cursor is the end). When not in Visual mode
10438 returns the cursor position. Differs from |'<| in
10439 that it's updated right away.
LemonBoy0f7a3e12022-05-26 12:10:37 +010010440
zeertzjq825cf812023-08-17 22:55:25 +020010441 If {list} is present and non-zero then virtcol() returns a
10442 List with the first and last screen position occupied by the
LemonBoy0f7a3e12022-05-26 12:10:37 +010010443 character.
10444
zeertzjq825cf812023-08-17 22:55:25 +020010445 With the optional {winid} argument the values are obtained for
10446 that window instead of the current window.
10447
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010448 Note that only marks in the current file can be used.
10449 Examples: >
LemonBoy0f7a3e12022-05-26 12:10:37 +010010450 " With text "foo^Lbar" and cursor on the "^L":
10451
10452 virtcol(".") " returns 5
10453 virtcol(".", 1) " returns [4, 5]
10454 virtcol("$") " returns 9
10455
10456 " With text " there", with 't at 'h':
10457
10458 virtcol("'t") " returns 6
zeertzjq825cf812023-08-17 22:55:25 +020010459< The first column is 1. 0 or [0, 0] is returned for an error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010460 A more advanced example that echoes the maximum length of
10461 all lines: >
10462 echo max(map(range(1, line('$')), "virtcol([v:val, '$'])"))
10463
10464< Can also be used as a |method|: >
10465 GetPos()->virtcol()
10466
Bram Moolenaar5a6ec102022-05-27 21:58:00 +010010467virtcol2col({winid}, {lnum}, {col}) *virtcol2col()*
10468 The result is a Number, which is the byte index of the
10469 character in window {winid} at buffer line {lnum} and virtual
10470 column {col}.
10471
zeertzjqb583eda2023-10-14 11:32:28 +020010472 If buffer line {lnum} is an empty line, 0 is returned.
10473
Bram Moolenaar5a6ec102022-05-27 21:58:00 +010010474 If {col} is greater than the last virtual column in line
10475 {lnum}, then the byte index of the character at the last
10476 virtual column is returned.
10477
Yegappan Lakshmananb209b862023-08-15 23:01:44 +020010478 For a multi-byte character, the column number of the first
10479 byte in the character is returned.
10480
Bram Moolenaar5a6ec102022-05-27 21:58:00 +010010481 The {winid} argument can be the window number or the
10482 |window-ID|. If this is zero, then the current window is used.
10483
10484 Returns -1 if the window {winid} doesn't exist or the buffer
10485 line {lnum} or virtual column {col} is invalid.
10486
10487 See also |screenpos()|, |virtcol()| and |col()|.
10488
10489 Can also be used as a |method|: >
10490 GetWinid()->virtcol2col(lnum, col)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010491
10492visualmode([{expr}]) *visualmode()*
10493 The result is a String, which describes the last Visual mode
10494 used in the current buffer. Initially it returns an empty
10495 string, but once Visual mode has been used, it returns "v",
10496 "V", or "<CTRL-V>" (a single CTRL-V character) for
10497 character-wise, line-wise, or block-wise Visual mode
10498 respectively.
10499 Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +000010500 :exe "normal " .. visualmode()
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010501< This enters the same Visual mode as before. It is also useful
10502 in scripts if you wish to act differently depending on the
10503 Visual mode that was used.
10504 If Visual mode is active, use |mode()| to get the Visual mode
10505 (e.g., in a |:vmap|).
10506 If {expr} is supplied and it evaluates to a non-zero Number or
10507 a non-empty String, then the Visual mode will be cleared and
10508 the old value is returned. See |non-zero-arg|.
10509
10510wildmenumode() *wildmenumode()*
10511 Returns |TRUE| when the wildmenu is active and |FALSE|
10512 otherwise. See 'wildmenu' and 'wildmode'.
10513 This can be used in mappings to handle the 'wildcharm' option
10514 gracefully. (Makes only sense with |mapmode-c| mappings).
10515
10516 For example to make <c-j> work like <down> in wildmode, use: >
10517 :cnoremap <expr> <C-j> wildmenumode() ? "\<Down>\<Tab>" : "\<c-j>"
10518<
10519 (Note, this needs the 'wildcharm' option set appropriately).
10520
10521win_execute({id}, {command} [, {silent}]) *win_execute()*
10522 Like `execute()` but in the context of window {id}.
10523 The window will temporarily be made the current window,
10524 without triggering autocommands or changing directory. When
10525 executing {command} autocommands will be triggered, this may
Bram Moolenaarb7398fe2023-05-14 18:50:25 +010010526 have unexpected side effects. Use `:noautocmd` if needed.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010527 Example: >
10528 call win_execute(winid, 'set syntax=python')
10529< Doing the same with `setwinvar()` would not trigger
10530 autocommands and not actually show syntax highlighting.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010531 *E994*
10532 Not all commands are allowed in popup windows.
10533 When window {id} does not exist then no error is given and
10534 an empty string is returned.
10535
10536 Can also be used as a |method|, the base is passed as the
10537 second argument: >
10538 GetCommand()->win_execute(winid)
10539
10540win_findbuf({bufnr}) *win_findbuf()*
10541 Returns a |List| with |window-ID|s for windows that contain
10542 buffer {bufnr}. When there is none the list is empty.
10543
10544 Can also be used as a |method|: >
10545 GetBufnr()->win_findbuf()
10546
10547win_getid([{win} [, {tab}]]) *win_getid()*
10548 Get the |window-ID| for the specified window.
10549 When {win} is missing use the current window.
10550 With {win} this is the window number. The top window has
10551 number 1.
10552 Without {tab} use the current tab, otherwise the tab with
10553 number {tab}. The first tab has number one.
10554 Return zero if the window cannot be found.
10555
10556 Can also be used as a |method|: >
10557 GetWinnr()->win_getid()
10558
10559
10560win_gettype([{nr}]) *win_gettype()*
10561 Return the type of the window:
10562 "autocmd" autocommand window. Temporary window
10563 used to execute autocommands.
10564 "command" command-line window |cmdwin|
10565 (empty) normal window
10566 "loclist" |location-list-window|
10567 "popup" popup window |popup|
10568 "preview" preview window |preview-window|
10569 "quickfix" |quickfix-window|
10570 "unknown" window {nr} not found
10571
10572 When {nr} is omitted return the type of the current window.
10573 When {nr} is given return the type of this window by number or
10574 |window-ID|.
10575
10576 Also see the 'buftype' option. When running a terminal in a
10577 popup window then 'buftype' is "terminal" and win_gettype()
10578 returns "popup".
10579
10580 Can also be used as a |method|: >
10581 GetWinid()->win_gettype()
10582<
10583win_gotoid({expr}) *win_gotoid()*
10584 Go to window with ID {expr}. This may also change the current
10585 tabpage.
10586 Return TRUE if successful, FALSE if the window cannot be found.
10587
10588 Can also be used as a |method|: >
10589 GetWinid()->win_gotoid()
10590
10591win_id2tabwin({expr}) *win_id2tabwin()*
10592 Return a list with the tab number and window number of window
10593 with ID {expr}: [tabnr, winnr].
10594 Return [0, 0] if the window cannot be found.
10595
10596 Can also be used as a |method|: >
10597 GetWinid()->win_id2tabwin()
10598
10599win_id2win({expr}) *win_id2win()*
10600 Return the window number of window with ID {expr}.
10601 Return 0 if the window cannot be found in the current tabpage.
10602
10603 Can also be used as a |method|: >
10604 GetWinid()->win_id2win()
10605
Daniel Steinbergee630312022-01-10 13:36:34 +000010606win_move_separator({nr}, {offset}) *win_move_separator()*
10607 Move window {nr}'s vertical separator (i.e., the right border)
10608 by {offset} columns, as if being dragged by the mouse. {nr}
10609 can be a window number or |window-ID|. A positive {offset}
10610 moves right and a negative {offset} moves left. Moving a
10611 window's vertical separator will change the width of the
10612 window and the width of other windows adjacent to the vertical
10613 separator. The magnitude of movement may be smaller than
10614 specified (e.g., as a consequence of maintaining
10615 'winminwidth'). Returns TRUE if the window can be found and
10616 FALSE otherwise.
Bram Moolenaard592deb2022-06-17 15:42:40 +010010617 This will fail for the rightmost window and a full-width
10618 window, since it has no separator on the right.
Bram Moolenaar76db9e02022-11-09 21:21:04 +000010619 Only works for the current tab page. *E1308*
Daniel Steinbergee630312022-01-10 13:36:34 +000010620
10621 Can also be used as a |method|: >
10622 GetWinnr()->win_move_separator(offset)
10623
10624win_move_statusline({nr}, {offset}) *win_move_statusline()*
10625 Move window {nr}'s status line (i.e., the bottom border) by
10626 {offset} rows, as if being dragged by the mouse. {nr} can be a
10627 window number or |window-ID|. A positive {offset} moves down
10628 and a negative {offset} moves up. Moving a window's status
10629 line will change the height of the window and the height of
10630 other windows adjacent to the status line. The magnitude of
10631 movement may be smaller than specified (e.g., as a consequence
10632 of maintaining 'winminheight'). Returns TRUE if the window can
10633 be found and FALSE otherwise.
Bram Moolenaar76db9e02022-11-09 21:21:04 +000010634 Only works for the current tab page.
Daniel Steinbergee630312022-01-10 13:36:34 +000010635
10636 Can also be used as a |method|: >
10637 GetWinnr()->win_move_statusline(offset)
10638
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010639win_screenpos({nr}) *win_screenpos()*
10640 Return the screen position of window {nr} as a list with two
10641 numbers: [row, col]. The first window always has position
10642 [1, 1], unless there is a tabline, then it is [2, 1].
10643 {nr} can be the window number or the |window-ID|. Use zero
10644 for the current window.
10645 Returns [0, 0] if the window cannot be found in the current
10646 tabpage.
10647
10648 Can also be used as a |method|: >
10649 GetWinid()->win_screenpos()
10650<
10651win_splitmove({nr}, {target} [, {options}]) *win_splitmove()*
10652 Move the window {nr} to a new split of the window {target}.
10653 This is similar to moving to {target}, creating a new window
10654 using |:split| but having the same contents as window {nr}, and
10655 then closing {nr}.
10656
10657 Both {nr} and {target} can be window numbers or |window-ID|s.
10658 Both must be in the current tab page.
10659
10660 Returns zero for success, non-zero for failure.
10661
10662 {options} is a |Dictionary| with the following optional entries:
10663 "vertical" When TRUE, the split is created vertically,
10664 like with |:vsplit|.
10665 "rightbelow" When TRUE, the split is made below or to the
10666 right (if vertical). When FALSE, it is done
10667 above or to the left (if vertical). When not
10668 present, the values of 'splitbelow' and
10669 'splitright' are used.
10670
10671 Can also be used as a |method|: >
10672 GetWinid()->win_splitmove(target)
10673<
10674
10675 *winbufnr()*
10676winbufnr({nr}) The result is a Number, which is the number of the buffer
10677 associated with window {nr}. {nr} can be the window number or
10678 the |window-ID|.
10679 When {nr} is zero, the number of the buffer in the current
10680 window is returned.
10681 When window {nr} doesn't exist, -1 is returned.
10682 Example: >
10683 :echo "The file in the current window is " . bufname(winbufnr(0))
10684<
10685 Can also be used as a |method|: >
10686 FindWindow()->winbufnr()->bufname()
10687<
10688 *wincol()*
10689wincol() The result is a Number, which is the virtual column of the
10690 cursor in the window. This is counting screen cells from the
10691 left side of the window. The leftmost column is one.
10692
10693 *windowsversion()*
10694windowsversion()
10695 The result is a String. For MS-Windows it indicates the OS
10696 version. E.g, Windows 10 is "10.0", Windows 8 is "6.2",
10697 Windows XP is "5.1". For non-MS-Windows systems the result is
10698 an empty string.
10699
10700winheight({nr}) *winheight()*
10701 The result is a Number, which is the height of window {nr}.
10702 {nr} can be the window number or the |window-ID|.
10703 When {nr} is zero, the height of the current window is
10704 returned. When window {nr} doesn't exist, -1 is returned.
10705 An existing window always has a height of zero or more.
10706 This excludes any window toolbar line.
10707 Examples: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +000010708 :echo "The current window has " .. winheight(0) .. " lines."
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010709
10710< Can also be used as a |method|: >
10711 GetWinid()->winheight()
10712<
10713winlayout([{tabnr}]) *winlayout()*
10714 The result is a nested List containing the layout of windows
10715 in a tabpage.
10716
10717 Without {tabnr} use the current tabpage, otherwise the tabpage
10718 with number {tabnr}. If the tabpage {tabnr} is not found,
10719 returns an empty list.
10720
10721 For a leaf window, it returns:
10722 ['leaf', {winid}]
10723 For horizontally split windows, which form a column, it
10724 returns:
10725 ['col', [{nested list of windows}]]
10726 For vertically split windows, which form a row, it returns:
10727 ['row', [{nested list of windows}]]
10728
10729 Example: >
10730 " Only one window in the tab page
10731 :echo winlayout()
10732 ['leaf', 1000]
10733 " Two horizontally split windows
10734 :echo winlayout()
10735 ['col', [['leaf', 1000], ['leaf', 1001]]]
10736 " The second tab page, with three horizontally split
10737 " windows, with two vertically split windows in the
10738 " middle window
10739 :echo winlayout(2)
10740 ['col', [['leaf', 1002], ['row', [['leaf', 1003],
10741 ['leaf', 1001]]], ['leaf', 1000]]]
10742<
10743 Can also be used as a |method|: >
10744 GetTabnr()->winlayout()
10745<
10746 *winline()*
10747winline() The result is a Number, which is the screen line of the cursor
10748 in the window. This is counting screen lines from the top of
10749 the window. The first line is one.
10750 If the cursor was moved the view on the file will be updated
10751 first, this may cause a scroll.
10752
10753 *winnr()*
10754winnr([{arg}]) The result is a Number, which is the number of the current
10755 window. The top window has number 1.
10756 Returns zero for a popup window.
10757
10758 The optional argument {arg} supports the following values:
10759 $ the number of the last window (the window
10760 count).
10761 # the number of the last accessed window (where
10762 |CTRL-W_p| goes to). If there is no previous
10763 window or it is in another tab page 0 is
10764 returned.
10765 {N}j the number of the Nth window below the
10766 current window (where |CTRL-W_j| goes to).
10767 {N}k the number of the Nth window above the current
10768 window (where |CTRL-W_k| goes to).
10769 {N}h the number of the Nth window left of the
10770 current window (where |CTRL-W_h| goes to).
10771 {N}l the number of the Nth window right of the
10772 current window (where |CTRL-W_l| goes to).
10773 The number can be used with |CTRL-W_w| and ":wincmd w"
10774 |:wincmd|.
Bram Moolenaar016188f2022-06-06 20:52:59 +010010775 When {arg} is invalid an error is given and zero is returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010776 Also see |tabpagewinnr()| and |win_getid()|.
10777 Examples: >
10778 let window_count = winnr('$')
10779 let prev_window = winnr('#')
10780 let wnum = winnr('3k')
10781
10782< Can also be used as a |method|: >
10783 GetWinval()->winnr()
10784<
10785 *winrestcmd()*
10786winrestcmd() Returns a sequence of |:resize| commands that should restore
10787 the current window sizes. Only works properly when no windows
10788 are opened or closed and the current window and tab page is
10789 unchanged.
10790 Example: >
10791 :let cmd = winrestcmd()
10792 :call MessWithWindowSizes()
10793 :exe cmd
10794<
10795 *winrestview()*
10796winrestview({dict})
10797 Uses the |Dictionary| returned by |winsaveview()| to restore
10798 the view of the current window.
10799 Note: The {dict} does not have to contain all values, that are
10800 returned by |winsaveview()|. If values are missing, those
10801 settings won't be restored. So you can use: >
10802 :call winrestview({'curswant': 4})
10803<
10804 This will only set the curswant value (the column the cursor
10805 wants to move on vertical movements) of the cursor to column 5
10806 (yes, that is 5), while all other settings will remain the
10807 same. This is useful, if you set the cursor position manually.
10808
10809 If you have changed the values the result is unpredictable.
10810 If the window size changed the result won't be the same.
10811
10812 Can also be used as a |method|: >
10813 GetView()->winrestview()
10814<
10815 *winsaveview()*
10816winsaveview() Returns a |Dictionary| that contains information to restore
10817 the view of the current window. Use |winrestview()| to
10818 restore the view.
10819 This is useful if you have a mapping that jumps around in the
10820 buffer and you want to go back to the original view.
10821 This does not save fold information. Use the 'foldenable'
10822 option to temporarily switch off folding, so that folds are
10823 not opened when moving around. This may have side effects.
10824 The return value includes:
10825 lnum cursor line number
10826 col cursor column (Note: the first column
naohiro ono56200ee2022-01-01 14:59:44 +000010827 zero, as opposed to what |getcurpos()|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010828 returns)
10829 coladd cursor column offset for 'virtualedit'
naohiro ono56200ee2022-01-01 14:59:44 +000010830 curswant column for vertical movement (Note:
10831 the first column is zero, as opposed
10832 to what |getcurpos()| returns). After
10833 |$| command it will be a very large
10834 number equal to |v:maxcol|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010835 topline first line in the window
10836 topfill filler lines, only in diff mode
10837 leftcol first column displayed; only used when
10838 'wrap' is off
10839 skipcol columns skipped
10840 Note that no option values are saved.
10841
10842
10843winwidth({nr}) *winwidth()*
10844 The result is a Number, which is the width of window {nr}.
10845 {nr} can be the window number or the |window-ID|.
10846 When {nr} is zero, the width of the current window is
10847 returned. When window {nr} doesn't exist, -1 is returned.
10848 An existing window always has a width of zero or more.
10849 Examples: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +000010850 :echo "The current window has " .. winwidth(0) .. " columns."
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010851 :if winwidth(0) <= 50
10852 : 50 wincmd |
10853 :endif
10854< For getting the terminal or screen size, see the 'columns'
10855 option.
10856
10857 Can also be used as a |method|: >
10858 GetWinid()->winwidth()
10859
10860
10861wordcount() *wordcount()*
10862 The result is a dictionary of byte/chars/word statistics for
10863 the current buffer. This is the same info as provided by
10864 |g_CTRL-G|
10865 The return value includes:
10866 bytes Number of bytes in the buffer
10867 chars Number of chars in the buffer
10868 words Number of words in the buffer
10869 cursor_bytes Number of bytes before cursor position
10870 (not in Visual mode)
10871 cursor_chars Number of chars before cursor position
10872 (not in Visual mode)
10873 cursor_words Number of words before cursor position
10874 (not in Visual mode)
10875 visual_bytes Number of bytes visually selected
10876 (only in Visual mode)
10877 visual_chars Number of chars visually selected
10878 (only in Visual mode)
10879 visual_words Number of words visually selected
10880 (only in Visual mode)
10881
10882
10883 *writefile()*
10884writefile({object}, {fname} [, {flags}])
10885 When {object} is a |List| write it to file {fname}. Each list
10886 item is separated with a NL. Each list item must be a String
10887 or Number.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010888 All NL characters are replaced with a NUL character.
10889 Inserting CR characters needs to be done before passing {list}
10890 to writefile().
Bram Moolenaar806a2732022-09-04 15:40:36 +010010891
10892 When {object} is a |Blob| write the bytes to file {fname}
10893 unmodified, also when binary mode is not specified.
10894
10895 {flags} must be a String. These characters are recognized:
10896
10897 'b' Binary mode is used: There will not be a NL after the
10898 last list item. An empty item at the end does cause the
10899 last line in the file to end in a NL.
10900
10901 'a' Append mode is used, lines are appended to the file: >
10902 :call writefile(["foo"], "event.log", "a")
10903 :call writefile(["bar"], "event.log", "a")
10904<
10905 'D' Delete the file when the current function ends. This
10906 works like: >
Bram Moolenaar938ae282023-02-20 20:44:55 +000010907 :defer delete({fname})
Bram Moolenaar806a2732022-09-04 15:40:36 +010010908< Fails when not in a function. Also see |:defer|.
10909
10910 's' fsync() is called after writing the file. This flushes
10911 the file to disk, if possible. This takes more time but
10912 avoids losing the file if the system crashes.
10913
10914 'S' fsync() is not called, even when 'fsync' is set.
10915
10916 When {flags} does not contain "S" or "s" then fsync() is
10917 called if the 'fsync' option is set.
10918
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010919 An existing file is overwritten, if possible.
Bram Moolenaar806a2732022-09-04 15:40:36 +010010920
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010921 When the write fails -1 is returned, otherwise 0. There is an
10922 error message if the file can't be created or when writing
10923 fails.
Bram Moolenaar806a2732022-09-04 15:40:36 +010010924
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010925 Also see |readfile()|.
10926 To copy a file byte for byte: >
10927 :let fl = readfile("foo", "b")
10928 :call writefile(fl, "foocopy", "b")
10929
10930< Can also be used as a |method|: >
10931 GetText()->writefile("thefile")
10932
10933
10934xor({expr}, {expr}) *xor()*
10935 Bitwise XOR on the two arguments. The arguments are converted
10936 to a number. A List, Dict or Float argument causes an error.
Bram Moolenaar5a6ec102022-05-27 21:58:00 +010010937 Also see `and()` and `or()`.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010938 Example: >
10939 :let bits = xor(bits, 0x80)
10940<
10941 Can also be used as a |method|: >
10942 :let bits = bits->xor(0x80)
10943<
10944
10945==============================================================================
109463. Feature list *feature-list*
10947
10948There are three types of features:
109491. Features that are only supported when they have been enabled when Vim
10950 was compiled |+feature-list|. Example: >
10951 :if has("cindent")
10952< *gui_running*
109532. Features that are only supported when certain conditions have been met.
10954 Example: >
10955 :if has("gui_running")
10956< *has-patch*
109573. Beyond a certain version or at a certain version and including a specific
10958 patch. The "patch-7.4.248" feature means that the Vim version is 7.5 or
10959 later, or it is version 7.4 and patch 248 was included. Example: >
10960 :if has("patch-7.4.248")
10961< Note that it's possible for patch 248 to be omitted even though 249 is
10962 included. Only happens when cherry-picking patches.
10963 Note that this form only works for patch 7.4.237 and later, before that
10964 you need to check for the patch and the v:version. Example (checking
10965 version 6.2.148 or later): >
10966 :if v:version > 602 || (v:version == 602 && has("patch148"))
10967
10968Hint: To find out if Vim supports backslashes in a file name (MS-Windows),
10969use: `if exists('+shellslash')`
10970
10971
10972acl Compiled with |ACL| support.
Bram Moolenaar2ee347f2022-08-26 17:53:44 +010010973all_builtin_terms Compiled with all builtin terminals enabled. (always
10974 true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010975amiga Amiga version of Vim.
10976arabic Compiled with Arabic support |Arabic|.
10977arp Compiled with ARP support (Amiga).
10978autocmd Compiled with autocommand support. (always true)
10979autochdir Compiled with support for 'autochdir'
10980autoservername Automatically enable |clientserver|
10981balloon_eval Compiled with |balloon-eval| support.
10982balloon_multiline GUI supports multiline balloons.
10983beos BeOS version of Vim.
10984browse Compiled with |:browse| support, and browse() will
10985 work.
10986browsefilter Compiled with support for |browsefilter|.
10987bsd Compiled on an OS in the BSD family (excluding macOS).
Bram Moolenaar2ee347f2022-08-26 17:53:44 +010010988builtin_terms Compiled with some builtin terminals. (always true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010989byte_offset Compiled with support for 'o' in 'statusline'
10990channel Compiled with support for |channel| and |job|
Bram Moolenaare1dc76f2022-06-25 18:01:32 +010010991cindent Compiled with 'cindent' support. (always true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010992clientserver Compiled with remote invocation support |clientserver|.
10993clipboard Compiled with 'clipboard' support.
10994clipboard_working Compiled with 'clipboard' support and it can be used.
10995cmdline_compl Compiled with |cmdline-completion| support.
10996cmdline_hist Compiled with |cmdline-history| support.
10997cmdline_info Compiled with 'showcmd' and 'ruler' support.
10998comments Compiled with |'comments'| support.
10999compatible Compiled to be very Vi compatible.
11000conpty Platform where |ConPTY| can be used.
11001cryptv Compiled with encryption support |encryption|.
11002cscope Compiled with |cscope| support.
11003cursorbind Compiled with |'cursorbind'| (always true)
11004debug Compiled with "DEBUG" defined.
11005dialog_con Compiled with console dialog support.
11006dialog_gui Compiled with GUI dialog support.
11007diff Compiled with |vimdiff| and 'diff' support.
11008digraphs Compiled with support for digraphs.
11009directx Compiled with support for DirectX and 'renderoptions'.
11010dnd Compiled with support for the "~ register |quote_~|.
11011drop_file Compiled with |drop_file| support.
11012ebcdic Compiled on a machine with ebcdic character set.
11013emacs_tags Compiled with support for Emacs tags.
11014eval Compiled with expression evaluation support. Always
11015 true, of course!
11016ex_extra |+ex_extra| (always true)
11017extra_search Compiled with support for |'incsearch'| and
11018 |'hlsearch'|
11019farsi Support for Farsi was removed |farsi|.
Bram Moolenaarf80f40a2022-08-25 16:02:23 +010011020file_in_path Compiled with support for |gf| and |<cfile>| (always
11021 true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011022filterpipe When 'shelltemp' is off pipes are used for shell
11023 read/write/filter commands
11024find_in_path Compiled with support for include file searches
11025 |+find_in_path|.
11026float Compiled with support for |Float|.
11027fname_case Case in file names matters (for Amiga and MS-Windows
11028 this is not present).
11029folding Compiled with |folding| support.
11030footer Compiled with GUI footer support. |gui-footer|
11031fork Compiled to use fork()/exec() instead of system().
11032gettext Compiled with message translation |multi-lang|
11033gui Compiled with GUI enabled.
Bram Moolenaarcbaff5e2022-04-08 17:45:08 +010011034gui_athena Compiled with Athena GUI (always false).
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011035gui_gnome Compiled with Gnome support (gui_gtk is also defined).
11036gui_gtk Compiled with GTK+ GUI (any version).
11037gui_gtk2 Compiled with GTK+ 2 GUI (gui_gtk is also defined).
11038gui_gtk3 Compiled with GTK+ 3 GUI (gui_gtk is also defined).
11039gui_haiku Compiled with Haiku GUI.
11040gui_mac Compiled with Macintosh GUI.
11041gui_motif Compiled with Motif GUI.
11042gui_photon Compiled with Photon GUI.
11043gui_running Vim is running in the GUI, or it will start soon.
11044gui_win32 Compiled with MS-Windows Win32 GUI.
11045gui_win32s idem, and Win32s system being used (Windows 3.1)
11046haiku Haiku version of Vim.
11047hangul_input Compiled with Hangul input support. |hangul|
11048hpux HP-UX version of Vim.
11049iconv Can use iconv() for conversion.
11050insert_expand Compiled with support for CTRL-X expansion commands in
11051 Insert mode. (always true)
11052job Compiled with support for |channel| and |job|
11053ipv6 Compiled with support for IPv6 networking in |channel|.
Bram Moolenaare1dc76f2022-06-25 18:01:32 +010011054jumplist Compiled with |jumplist| support. (always true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011055keymap Compiled with 'keymap' support.
11056lambda Compiled with |lambda| support.
11057langmap Compiled with 'langmap' support.
11058libcall Compiled with |libcall()| support.
11059linebreak Compiled with 'linebreak', 'breakat', 'showbreak' and
11060 'breakindent' support.
11061linux Linux version of Vim.
11062lispindent Compiled with support for lisp indenting.
Bram Moolenaare1dc76f2022-06-25 18:01:32 +010011063 (always true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011064listcmds Compiled with commands for the buffer list |:files|
11065 and the argument list |arglist|.
11066localmap Compiled with local mappings and abbr. |:map-local|
11067lua Compiled with Lua interface |Lua|.
11068mac Any Macintosh version of Vim cf. osx
11069macunix Synonym for osxdarwin
11070menu Compiled with support for |:menu|.
11071mksession Compiled with support for |:mksession|.
11072modify_fname Compiled with file name modifiers. |filename-modifiers|
11073 (always true)
11074mouse Compiled with support for mouse.
11075mouse_dec Compiled with support for Dec terminal mouse.
11076mouse_gpm Compiled with support for gpm (Linux console mouse)
11077mouse_gpm_enabled GPM mouse is working
11078mouse_netterm Compiled with support for netterm mouse.
11079mouse_pterm Compiled with support for qnx pterm mouse.
11080mouse_sysmouse Compiled with support for sysmouse (*BSD console mouse)
11081mouse_sgr Compiled with support for sgr mouse.
11082mouse_urxvt Compiled with support for urxvt mouse.
11083mouse_xterm Compiled with support for xterm mouse.
11084mouseshape Compiled with support for 'mouseshape'.
11085multi_byte Compiled with support for 'encoding' (always true)
11086multi_byte_encoding 'encoding' is set to a multibyte encoding.
11087multi_byte_ime Compiled with support for IME input method.
11088multi_lang Compiled with support for multiple languages.
11089mzscheme Compiled with MzScheme interface |mzscheme|.
11090nanotime Compiled with sub-second time stamp checks.
11091netbeans_enabled Compiled with support for |netbeans| and connected.
11092netbeans_intg Compiled with support for |netbeans|.
Bram Moolenaare1dc76f2022-06-25 18:01:32 +010011093num64 Compiled with 64-bit |Number| support. (always true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011094ole Compiled with OLE automation support for Win32.
11095osx Compiled for macOS cf. mac
11096osxdarwin Compiled for macOS, with |mac-darwin-feature|
11097packages Compiled with |packages| support.
11098path_extra Compiled with up/downwards search in 'path' and 'tags'
11099perl Compiled with Perl interface.
11100persistent_undo Compiled with support for persistent undo history.
11101postscript Compiled with PostScript file printing.
11102printer Compiled with |:hardcopy| support.
11103profile Compiled with |:profile| support.
Bram Moolenaar71badf92023-04-22 22:40:14 +010011104prof_nsec Profile results are in nanoseconds.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011105python Python 2.x interface available. |has-python|
11106python_compiled Compiled with Python 2.x interface. |has-python|
11107python_dynamic Python 2.x interface is dynamically loaded. |has-python|
11108python3 Python 3.x interface available. |has-python|
11109python3_compiled Compiled with Python 3.x interface. |has-python|
11110python3_dynamic Python 3.x interface is dynamically loaded. |has-python|
Yee Cheng Chinc13b3d12023-08-20 21:18:38 +020011111python3_stable Python 3.x interface is using Python Stable ABI. |has-python|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011112pythonx Python 2.x and/or 3.x interface available. |python_x|
11113qnx QNX version of Vim.
11114quickfix Compiled with |quickfix| support.
11115reltime Compiled with |reltime()| support.
11116rightleft Compiled with 'rightleft' support.
11117ruby Compiled with Ruby interface |ruby|.
11118scrollbind Compiled with 'scrollbind' support. (always true)
11119showcmd Compiled with 'showcmd' support.
11120signs Compiled with |:sign| support.
Bram Moolenaare1dc76f2022-06-25 18:01:32 +010011121smartindent Compiled with 'smartindent' support. (always true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011122sodium Compiled with libsodium for better crypt support
11123sound Compiled with sound support, e.g. `sound_playevent()`
11124spell Compiled with spell checking support |spell|.
11125startuptime Compiled with |--startuptime| support.
11126statusline Compiled with support for 'statusline', 'rulerformat'
11127 and special formats of 'titlestring' and 'iconstring'.
11128sun SunOS version of Vim.
11129sun_workshop Support for Sun |workshop| has been removed.
11130syntax Compiled with syntax highlighting support |syntax|.
11131syntax_items There are active syntax highlighting items for the
11132 current buffer.
11133system Compiled to use system() instead of fork()/exec().
11134tag_binary Compiled with binary searching in tags files
Bram Moolenaare1dc76f2022-06-25 18:01:32 +010011135 |tag-binary-search|. (always true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011136tag_old_static Support for old static tags was removed, see
11137 |tag-old-static|.
11138tcl Compiled with Tcl interface.
11139termguicolors Compiled with true color in terminal support.
11140terminal Compiled with |terminal| support.
11141terminfo Compiled with terminfo instead of termcap.
11142termresponse Compiled with support for |t_RV| and |v:termresponse|.
11143textobjects Compiled with support for |text-objects|.
11144textprop Compiled with support for |text-properties|.
11145tgetent Compiled with tgetent support, able to use a termcap
11146 or terminfo file.
11147timers Compiled with |timer_start()| support.
11148title Compiled with window title support |'title'|.
Bram Moolenaare1dc76f2022-06-25 18:01:32 +010011149 (always true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011150toolbar Compiled with support for |gui-toolbar|.
11151ttyin input is a terminal (tty)
11152ttyout output is a terminal (tty)
11153unix Unix version of Vim. *+unix*
11154unnamedplus Compiled with support for "unnamedplus" in 'clipboard'
11155user_commands User-defined commands. (always true)
11156vartabs Compiled with variable tabstop support |'vartabstop'|.
11157vcon Win32: Virtual console support is working, can use
11158 'termguicolors'. Also see |+vtp|.
11159vertsplit Compiled with vertically split windows |:vsplit|.
11160 (always true)
11161vim_starting True while initial source'ing takes place. |startup|
11162 *vim_starting*
Bram Moolenaara6feb162022-01-02 12:06:33 +000011163vim9script Compiled with |Vim9| script support
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011164viminfo Compiled with viminfo support.
11165vimscript-1 Compiled Vim script version 1 support
11166vimscript-2 Compiled Vim script version 2 support
11167vimscript-3 Compiled Vim script version 3 support
Bram Moolenaar8a3b8052022-06-26 12:21:15 +010011168vimscript-4 Compiled Vim script version 4 support
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011169virtualedit Compiled with 'virtualedit' option. (always true)
11170visual Compiled with Visual mode. (always true)
11171visualextra Compiled with extra Visual mode commands. (always
11172 true) |blockwise-operators|.
11173vms VMS version of Vim.
11174vreplace Compiled with |gR| and |gr| commands. (always true)
11175vtp Compiled for vcon support |+vtp| (check vcon to find
11176 out if it works in the current console).
11177wildignore Compiled with 'wildignore' option.
11178wildmenu Compiled with 'wildmenu' option.
11179win16 old version for MS-Windows 3.1 (always false)
11180win32 Win32 version of Vim (MS-Windows 95 and later, 32 or
11181 64 bits)
11182win32unix Win32 version of Vim, using Unix files (Cygwin)
11183win64 Win64 version of Vim (MS-Windows 64 bit).
11184win95 Win32 version for MS-Windows 95/98/ME (always false)
11185winaltkeys Compiled with 'winaltkeys' option.
11186windows Compiled with support for more than one window.
11187 (always true)
11188writebackup Compiled with 'writebackup' default on.
Christian Brabandte085dfd2023-09-30 12:49:18 +020011189xattr Compiled with extended attributes support |xattr|
11190 (currently only supported on Linux).
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011191xfontset Compiled with X fontset support |xfontset|.
11192xim Compiled with X input method support |xim|.
11193xpm Compiled with pixmap support.
11194xpm_w32 Compiled with pixmap support for Win32. (Only for
11195 backward compatibility. Use "xpm" instead.)
11196xsmp Compiled with X session management support.
11197xsmp_interact Compiled with interactive X session management support.
11198xterm_clipboard Compiled with support for xterm clipboard.
11199xterm_save Compiled with support for saving and restoring the
11200 xterm screen.
11201x11 Compiled with X11 support.
11202
11203
11204==============================================================================
112054. Matching a pattern in a String *string-match*
11206
11207This is common between several functions. A regexp pattern as explained at
11208|pattern| is normally used to find a match in the buffer lines. When a
11209pattern is used to find a match in a String, almost everything works in the
11210same way. The difference is that a String is handled like it is one line.
11211When it contains a "\n" character, this is not seen as a line break for the
11212pattern. It can be matched with a "\n" in the pattern, or with ".". Example:
11213>
11214 :let a = "aaaa\nxxxx"
11215 :echo matchstr(a, "..\n..")
11216 aa
11217 xx
11218 :echo matchstr(a, "a.x")
11219 a
11220 x
11221
11222Don't forget that "^" will only match at the first character of the String and
11223"$" at the last character of the string. They don't match after or before a
11224"\n".
11225
11226 vim:tw=78:ts=8:noet:ft=help:norl: