blob: 7ff969d7cb16fca11062315b34ccc7eaee82de39 [file] [log] [blame]
Bram Moolenaar86b48162022-12-06 18:20:10 +00001*builtin.txt* For Vim version 9.0. Last change: 2022 Dec 05
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}
84byteidx({expr}, {nr}) Number byte index of {nr}'th char in {expr}
85byteidxcomp({expr}, {nr}) Number byte index of {nr}'th char in {expr}
86call({func}, {arglist} [, {dict}])
87 any call {func} with arguments {arglist}
88ceil({expr}) Float round {expr} up
89ch_canread({handle}) Number check if there is something to read
90ch_close({handle}) none close {handle}
91ch_close_in({handle}) none close in part of {handle}
92ch_evalexpr({handle}, {expr} [, {options}])
93 any evaluate {expr} on JSON {handle}
94ch_evalraw({handle}, {string} [, {options}])
95 any evaluate {string} on raw {handle}
96ch_getbufnr({handle}, {what}) Number get buffer number for {handle}/{what}
97ch_getjob({channel}) Job get the Job of {channel}
98ch_info({handle}) String info about channel {handle}
99ch_log({msg} [, {handle}]) none write {msg} in the channel log file
100ch_logfile({fname} [, {mode}]) none start logging channel activity
101ch_open({address} [, {options}])
102 Channel open a channel to {address}
103ch_read({handle} [, {options}]) String read from {handle}
104ch_readblob({handle} [, {options}])
105 Blob read Blob from {handle}
106ch_readraw({handle} [, {options}])
107 String read raw from {handle}
108ch_sendexpr({handle}, {expr} [, {options}])
109 any send {expr} over JSON {handle}
110ch_sendraw({handle}, {expr} [, {options}])
111 any send {expr} over raw {handle}
112ch_setoptions({handle}, {options})
113 none set options for {handle}
114ch_status({handle} [, {options}])
115 String status of channel {handle}
116changenr() Number current change number
117char2nr({expr} [, {utf8}]) Number ASCII/UTF-8 value of first char in {expr}
118charclass({string}) Number character class of {string}
Yegappan Lakshmanan4c8d2f02022-11-12 16:07:47 +0000119charcol({expr} [, {winid}]) Number column number of cursor or mark
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000120charidx({string}, {idx} [, {countcc}])
121 Number char index of byte {idx} in {string}
122chdir({dir}) String change current working directory
123cindent({lnum}) Number C indent for line {lnum}
124clearmatches([{win}]) none clear all matches
Yegappan Lakshmanan4c8d2f02022-11-12 16:07:47 +0000125col({expr} [, {winid}]) Number column byte index of cursor or mark
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000126complete({startcol}, {matches}) none set Insert mode completion
127complete_add({expr}) Number add completion match
128complete_check() Number check for key typed during completion
129complete_info([{what}]) Dict get current completion information
130confirm({msg} [, {choices} [, {default} [, {type}]]])
131 Number number of choice picked by user
132copy({expr}) any make a shallow copy of {expr}
133cos({expr}) Float cosine of {expr}
134cosh({expr}) Float hyperbolic cosine of {expr}
135count({comp}, {expr} [, {ic} [, {start}]])
136 Number count how many {expr} are in {comp}
137cscope_connection([{num}, {dbpath} [, {prepend}]])
138 Number checks existence of cscope connection
139cursor({lnum}, {col} [, {off}])
140 Number move cursor to {lnum}, {col}, {off}
141cursor({list}) Number move cursor to position in {list}
142debugbreak({pid}) Number interrupt process being debugged
143deepcopy({expr} [, {noref}]) any make a full copy of {expr}
144delete({fname} [, {flags}]) Number delete the file or directory {fname}
145deletebufline({buf}, {first} [, {last}])
146 Number delete lines from buffer {buf}
147did_filetype() Number |TRUE| if FileType autocmd event used
148diff_filler({lnum}) Number diff filler lines about {lnum}
149diff_hlID({lnum}, {col}) Number diff highlighting at {lnum}/{col}
150digraph_get({chars}) String get the |digraph| of {chars}
151digraph_getlist([{listall}]) List get all |digraph|s
152digraph_set({chars}, {digraph}) Boolean register |digraph|
153digraph_setlist({digraphlist}) Boolean register multiple |digraph|s
154echoraw({expr}) none output {expr} as-is
155empty({expr}) Number |TRUE| if {expr} is empty
156environ() Dict return environment variables
157escape({string}, {chars}) String escape {chars} in {string} with '\'
158eval({string}) any evaluate {string} into its value
159eventhandler() Number |TRUE| if inside an event handler
160executable({expr}) Number 1 if executable {expr} exists
161execute({command}) String execute {command} and get the output
162exepath({expr}) String full path of the command {expr}
163exists({expr}) Number |TRUE| if {expr} exists
164exists_compiled({expr}) Number |TRUE| if {expr} exists at compile time
165exp({expr}) Float exponential of {expr}
166expand({expr} [, {nosuf} [, {list}]])
167 any expand special keywords in {expr}
Yegappan Lakshmanan2b74b682022-04-03 21:30:32 +0100168expandcmd({string} [, {options}])
169 String expand {string} like with `:edit`
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000170extend({expr1}, {expr2} [, {expr3}])
171 List/Dict insert items of {expr2} into {expr1}
172extendnew({expr1}, {expr2} [, {expr3}])
173 List/Dict like |extend()| but creates a new
174 List or Dictionary
175feedkeys({string} [, {mode}]) Number add key sequence to typeahead buffer
176filereadable({file}) Number |TRUE| if {file} is a readable file
177filewritable({file}) Number |TRUE| if {file} is a writable file
178filter({expr1}, {expr2}) List/Dict/Blob/String
179 remove items from {expr1} where
180 {expr2} is 0
181finddir({name} [, {path} [, {count}]])
182 String find directory {name} in {path}
183findfile({name} [, {path} [, {count}]])
184 String find file {name} in {path}
185flatten({list} [, {maxdepth}]) List flatten {list} up to {maxdepth} levels
186flattennew({list} [, {maxdepth}])
187 List flatten a copy of {list}
188float2nr({expr}) Number convert Float {expr} to a Number
189floor({expr}) Float round {expr} down
190fmod({expr1}, {expr2}) Float remainder of {expr1} / {expr2}
191fnameescape({fname}) String escape special characters in {fname}
192fnamemodify({fname}, {mods}) String modify file name
193foldclosed({lnum}) Number first line of fold at {lnum} if closed
194foldclosedend({lnum}) Number last line of fold at {lnum} if closed
195foldlevel({lnum}) Number fold level at {lnum}
196foldtext() String line displayed for closed fold
197foldtextresult({lnum}) String text for closed fold at {lnum}
198foreground() Number bring the Vim window to the foreground
Bram Moolenaaraa534142022-09-15 21:46:02 +0100199fullcommand({name} [, {vim9}]) String get full command from {name}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000200funcref({name} [, {arglist}] [, {dict}])
201 Funcref reference to function {name}
202function({name} [, {arglist}] [, {dict}])
203 Funcref named reference to function {name}
204garbagecollect([{atexit}]) none free memory, breaking cyclic references
205get({list}, {idx} [, {def}]) any get item {idx} from {list} or {def}
206get({dict}, {key} [, {def}]) any get item {key} from {dict} or {def}
207get({func}, {what}) any get property of funcref/partial {func}
208getbufinfo([{buf}]) List information about buffers
209getbufline({buf}, {lnum} [, {end}])
210 List lines {lnum} to {end} of buffer {buf}
Bram Moolenaarce30ccc2022-11-21 19:57:04 +0000211getbufoneline({buf}, {lnum}) String line {lnum} of buffer {buf}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000212getbufvar({buf}, {varname} [, {def}])
213 any variable {varname} in buffer {buf}
214getchangelist([{buf}]) List list of change list items
215getchar([expr]) Number or String
216 get one character from the user
217getcharmod() Number modifiers for the last typed character
218getcharpos({expr}) List position of cursor, mark, etc.
219getcharsearch() Dict last character search
220getcharstr([expr]) String get one character from the user
Shougo Matsushita79d599b2022-05-07 12:48:29 +0100221getcmdcompltype() String return the type of the current
222 command-line completion
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000223getcmdline() String return the current command-line
224getcmdpos() Number return cursor position in command-line
Shougo Matsushita79d599b2022-05-07 12:48:29 +0100225getcmdscreenpos() Number return cursor screen position in
226 command-line
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000227getcmdtype() String return current command-line type
228getcmdwintype() String return current command-line window type
229getcompletion({pat}, {type} [, {filtered}])
230 List list of cmdline completion matches
231getcurpos([{winnr}]) List position of the cursor
232getcursorcharpos([{winnr}]) List character position of the cursor
233getcwd([{winnr} [, {tabnr}]]) String get the current working directory
234getenv({name}) String return environment variable
235getfontname([{name}]) String name of font being used
236getfperm({fname}) String file permissions of file {fname}
237getfsize({fname}) Number size in bytes of file {fname}
238getftime({fname}) Number last modification time of file
239getftype({fname}) String description of type of file {fname}
240getimstatus() Number |TRUE| if the IME status is active
241getjumplist([{winnr} [, {tabnr}]])
242 List list of jump list items
243getline({lnum}) String line {lnum} of current buffer
244getline({lnum}, {end}) List lines {lnum} to {end} of current buffer
245getloclist({nr}) List list of location list items
246getloclist({nr}, {what}) Dict get specific location list properties
247getmarklist([{buf}]) List list of global/local marks
248getmatches([{win}]) List list of current matches
249getmousepos() Dict last known mouse position
Bram Moolenaar24dc19c2022-11-14 19:49:15 +0000250getmouseshape() String current mouse shape name
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000251getpid() Number process ID of Vim
252getpos({expr}) List position of cursor, mark, etc.
253getqflist() List list of quickfix items
254getqflist({what}) Dict get specific quickfix list properties
255getreg([{regname} [, 1 [, {list}]]])
256 String or List contents of a register
257getreginfo([{regname}]) Dict information about a register
258getregtype([{regname}]) String type of a register
Yegappan Lakshmanan520f6ef2022-08-25 17:40:40 +0100259getscriptinfo([{opts}]) List list of sourced scripts
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000260gettabinfo([{expr}]) List list of tab pages
261gettabvar({nr}, {varname} [, {def}])
262 any variable {varname} in tab {nr} or {def}
263gettabwinvar({tabnr}, {winnr}, {name} [, {def}])
264 any {name} in {winnr} in tab page {tabnr}
265gettagstack([{nr}]) Dict get the tag stack of window {nr}
266gettext({text}) String lookup translation of {text}
267getwininfo([{winid}]) List list of info about each window
268getwinpos([{timeout}]) List X and Y coord in pixels of the Vim window
269getwinposx() Number X coord in pixels of the Vim window
270getwinposy() Number Y coord in pixels of the Vim window
271getwinvar({nr}, {varname} [, {def}])
272 any variable {varname} in window {nr}
273glob({expr} [, {nosuf} [, {list} [, {alllinks}]]])
274 any expand file wildcards in {expr}
275glob2regpat({expr}) String convert a glob pat into a search pat
276globpath({path}, {expr} [, {nosuf} [, {list} [, {alllinks}]]])
277 String do glob({expr}) for all dirs in {path}
278has({feature} [, {check}]) Number |TRUE| if feature {feature} supported
279has_key({dict}, {key}) Number |TRUE| if {dict} has entry {key}
280haslocaldir([{winnr} [, {tabnr}]])
281 Number |TRUE| if the window executed |:lcd|
282 or |:tcd|
283hasmapto({what} [, {mode} [, {abbr}]])
284 Number |TRUE| if mapping to {what} exists
285histadd({history}, {item}) Number add an item to a history
286histdel({history} [, {item}]) Number remove an item from a history
287histget({history} [, {index}]) String get the item {index} from a history
288histnr({history}) Number highest index of a history
289hlID({name}) Number syntax ID of highlight group {name}
290hlexists({name}) Number |TRUE| if highlight group {name} exists
291hlget([{name} [, {resolve}]]) List get highlight group attributes
292hlset({list}) Number set highlight group attributes
293hostname() String name of the machine Vim is running on
294iconv({expr}, {from}, {to}) String convert encoding of {expr}
295indent({lnum}) Number indent of line {lnum}
296index({object}, {expr} [, {start} [, {ic}]])
297 Number index in {object} where {expr} appears
Yegappan Lakshmananb2186552022-08-13 13:09:20 +0100298indexof({object}, {expr} [, {opts}]])
299 Number index in {object} where {expr} is true
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000300input({prompt} [, {text} [, {completion}]])
301 String get input from the user
Bram Moolenaarb529cfb2022-07-25 15:42:07 +0100302inputdialog({prompt} [, {text} [, {cancelreturn}]])
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000303 String like input() but in a GUI dialog
304inputlist({textlist}) Number let the user pick from a choice list
305inputrestore() Number restore typeahead
306inputsave() Number save and clear typeahead
307inputsecret({prompt} [, {text}]) String like input() but hiding the text
308insert({object}, {item} [, {idx}]) List insert {item} in {object} [before {idx}]
309interrupt() none interrupt script execution
310invert({expr}) Number bitwise invert
LemonBoydca1d402022-04-28 15:26:33 +0100311isabsolutepath({path}) Number |TRUE| if {path} is an absolute path
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000312isdirectory({directory}) Number |TRUE| if {directory} is a directory
313isinf({expr}) Number determine if {expr} is infinity value
314 (positive or negative)
315islocked({expr}) Number |TRUE| if {expr} is locked
316isnan({expr}) Number |TRUE| if {expr} is NaN
317items({dict}) List key-value pairs in {dict}
318job_getchannel({job}) Channel get the channel handle for {job}
319job_info([{job}]) Dict get information about {job}
320job_setoptions({job}, {options}) none set options for {job}
321job_start({command} [, {options}])
322 Job start a job
323job_status({job}) String get the status of {job}
324job_stop({job} [, {how}]) Number stop {job}
325join({list} [, {sep}]) String join {list} items into one String
326js_decode({string}) any decode JS style JSON
327js_encode({expr}) String encode JS style JSON
328json_decode({string}) any decode JSON
329json_encode({expr}) String encode JSON
330keys({dict}) List keys in {dict}
zeertzjqcdc83932022-09-12 13:38:41 +0100331keytrans({string}) String translate internal keycodes to a form
332 that can be used by |:map|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000333len({expr}) Number the length of {expr}
334libcall({lib}, {func}, {arg}) String call {func} in library {lib} with {arg}
335libcallnr({lib}, {func}, {arg}) Number idem, but return a Number
336line({expr} [, {winid}]) Number line nr of cursor, last line or mark
337line2byte({lnum}) Number byte count of line {lnum}
338lispindent({lnum}) Number Lisp indent for line {lnum}
339list2blob({list}) Blob turn {list} of numbers into a Blob
340list2str({list} [, {utf8}]) String turn {list} of numbers into a String
341listener_add({callback} [, {buf}])
342 Number add a callback to listen to changes
343listener_flush([{buf}]) none invoke listener callbacks
344listener_remove({id}) none remove a listener callback
345localtime() Number current time
346log({expr}) Float natural logarithm (base e) of {expr}
347log10({expr}) Float logarithm of Float {expr} to base 10
348luaeval({expr} [, {expr}]) any evaluate |Lua| expression
349map({expr1}, {expr2}) List/Dict/Blob/String
350 change each item in {expr1} to {expr2}
351maparg({name} [, {mode} [, {abbr} [, {dict}]]])
352 String or Dict
353 rhs of mapping {name} in mode {mode}
354mapcheck({name} [, {mode} [, {abbr}]])
355 String check for mappings matching {name}
Ernie Rael09661202022-04-25 14:40:44 +0100356maplist([{abbr}]) List list of all mappings, a dict for each
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000357mapnew({expr1}, {expr2}) List/Dict/Blob/String
358 like |map()| but creates a new List or
359 Dictionary
360mapset({mode}, {abbr}, {dict}) none restore mapping from |maparg()| result
361match({expr}, {pat} [, {start} [, {count}]])
362 Number position where {pat} matches in {expr}
363matchadd({group}, {pattern} [, {priority} [, {id} [, {dict}]]])
364 Number highlight {pattern} with {group}
365matchaddpos({group}, {pos} [, {priority} [, {id} [, {dict}]]])
366 Number highlight positions with {group}
367matcharg({nr}) List arguments of |:match|
368matchdelete({id} [, {win}]) Number delete match identified by {id}
369matchend({expr}, {pat} [, {start} [, {count}]])
370 Number position where {pat} ends in {expr}
371matchfuzzy({list}, {str} [, {dict}])
372 List fuzzy match {str} in {list}
373matchfuzzypos({list}, {str} [, {dict}])
374 List fuzzy match {str} in {list}
375matchlist({expr}, {pat} [, {start} [, {count}]])
376 List match and submatches of {pat} in {expr}
377matchstr({expr}, {pat} [, {start} [, {count}]])
378 String {count}'th match of {pat} in {expr}
379matchstrpos({expr}, {pat} [, {start} [, {count}]])
380 List {count}'th match of {pat} in {expr}
381max({expr}) Number maximum value of items in {expr}
382menu_info({name} [, {mode}]) Dict get menu item information
383min({expr}) Number minimum value of items in {expr}
384mkdir({name} [, {path} [, {prot}]])
385 Number create directory {name}
386mode([expr]) String current editing mode
387mzeval({expr}) any evaluate |MzScheme| expression
388nextnonblank({lnum}) Number line nr of non-blank line >= {lnum}
389nr2char({expr} [, {utf8}]) String single char with ASCII/UTF-8 value {expr}
390or({expr}, {expr}) Number bitwise OR
391pathshorten({expr} [, {len}]) String shorten directory names in a path
392perleval({expr}) any evaluate |Perl| expression
393popup_atcursor({what}, {options}) Number create popup window near the cursor
394popup_beval({what}, {options}) Number create popup window for 'ballooneval'
395popup_clear() none close all popup windows
396popup_close({id} [, {result}]) none close popup window {id}
397popup_create({what}, {options}) Number create a popup window
398popup_dialog({what}, {options}) Number create a popup window used as a dialog
399popup_filter_menu({id}, {key}) Number filter for a menu popup window
400popup_filter_yesno({id}, {key}) Number filter for a dialog popup window
Bram Moolenaarbdc09a12022-10-07 14:31:45 +0100401popup_findecho() Number get window ID of popup for `:echowin`
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000402popup_findinfo() Number get window ID of info popup window
403popup_findpreview() Number get window ID of preview popup window
404popup_getoptions({id}) Dict get options of popup window {id}
405popup_getpos({id}) Dict get position of popup window {id}
406popup_hide({id}) none hide popup menu {id}
407popup_list() List get a list of window IDs of all popups
408popup_locate({row}, {col}) Number get window ID of popup at position
409popup_menu({what}, {options}) Number create a popup window used as a menu
410popup_move({id}, {options}) none set position of popup window {id}
411popup_notification({what}, {options})
412 Number create a notification popup window
413popup_setoptions({id}, {options})
414 none set options for popup window {id}
415popup_settext({id}, {text}) none set the text of popup window {id}
416popup_show({id}) none unhide popup window {id}
417pow({x}, {y}) Float {x} to the power of {y}
418prevnonblank({lnum}) Number line nr of non-blank line <= {lnum}
419printf({fmt}, {expr1}...) String format text
420prompt_getprompt({buf}) String get prompt text
421prompt_setcallback({buf}, {expr}) none set prompt callback function
422prompt_setinterrupt({buf}, {text}) none set prompt interrupt function
423prompt_setprompt({buf}, {text}) none set prompt text
424prop_add({lnum}, {col}, {props}) none add one text property
425prop_add_list({props}, [[{lnum}, {col}, {end-lnum}, {end-col}], ...])
426 none add multiple text properties
427prop_clear({lnum} [, {lnum-end} [, {props}]])
428 none remove all text properties
429prop_find({props} [, {direction}])
430 Dict search for a text property
431prop_list({lnum} [, {props}]) List text properties in {lnum}
432prop_remove({props} [, {lnum} [, {lnum-end}]])
433 Number remove a text property
434prop_type_add({name}, {props}) none define a new property type
435prop_type_change({name}, {props})
436 none change an existing property type
437prop_type_delete({name} [, {props}])
438 none delete a property type
439prop_type_get({name} [, {props}])
440 Dict get property type values
441prop_type_list([{props}]) List get list of property types
442pum_getpos() Dict position and size of pum if visible
443pumvisible() Number whether popup menu is visible
444py3eval({expr}) any evaluate |python3| expression
445pyeval({expr}) any evaluate |Python| expression
446pyxeval({expr}) any evaluate |python_x| expression
447rand([{expr}]) Number get pseudo-random number
448range({expr} [, {max} [, {stride}]])
449 List items from {expr} to {max}
K.Takata11df3ae2022-10-19 14:02:40 +0100450readblob({fname} [, {offset} [, {size}]])
451 Blob read a |Blob| from {fname}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000452readdir({dir} [, {expr} [, {dict}]])
453 List file names in {dir} selected by {expr}
454readdirex({dir} [, {expr} [, {dict}]])
455 List file info in {dir} selected by {expr}
456readfile({fname} [, {type} [, {max}]])
457 List get list of lines from file {fname}
458reduce({object}, {func} [, {initial}])
459 any reduce {object} using {func}
460reg_executing() String get the executing register name
461reg_recording() String get the recording register name
462reltime([{start} [, {end}]]) List get time value
463reltimefloat({time}) Float turn the time value into a Float
464reltimestr({time}) String turn time value into a String
465remote_expr({server}, {string} [, {idvar} [, {timeout}]])
466 String send expression
467remote_foreground({server}) Number bring Vim server to the foreground
468remote_peek({serverid} [, {retvar}])
469 Number check for reply string
470remote_read({serverid} [, {timeout}])
471 String read reply string
472remote_send({server}, {string} [, {idvar}])
473 String send key sequence
474remote_startserver({name}) none become server {name}
475remove({list}, {idx} [, {end}]) any/List
476 remove items {idx}-{end} from {list}
477remove({blob}, {idx} [, {end}]) Number/Blob
478 remove bytes {idx}-{end} from {blob}
479remove({dict}, {key}) any remove entry {key} from {dict}
480rename({from}, {to}) Number rename (move) file from {from} to {to}
Bakudankun375141e2022-09-09 18:46:47 +0100481repeat({expr}, {count}) List/Blob/String
482 repeat {expr} {count} times
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000483resolve({filename}) String get filename a shortcut points to
484reverse({list}) List reverse {list} in-place
485round({expr}) Float round off {expr}
486rubyeval({expr}) any evaluate |Ruby| expression
487screenattr({row}, {col}) Number attribute at screen position
488screenchar({row}, {col}) Number character at screen position
489screenchars({row}, {col}) List List of characters at screen position
490screencol() Number current cursor column
491screenpos({winid}, {lnum}, {col}) Dict screen row and col of a text character
492screenrow() Number current cursor row
493screenstring({row}, {col}) String characters at screen position
494search({pattern} [, {flags} [, {stopline} [, {timeout} [, {skip}]]]])
495 Number search for {pattern}
496searchcount([{options}]) Dict get or update search stats
497searchdecl({name} [, {global} [, {thisblock}]])
498 Number search for variable declaration
499searchpair({start}, {middle}, {end} [, {flags} [, {skip} [...]]])
500 Number search for other end of start/end pair
501searchpairpos({start}, {middle}, {end} [, {flags} [, {skip} [...]]])
502 List search for other end of start/end pair
503searchpos({pattern} [, {flags} [, {stopline} [, {timeout} [, {skip}]]]])
504 List search for {pattern}
505server2client({clientid}, {string})
506 Number send reply string
507serverlist() String get a list of available servers
508setbufline({expr}, {lnum}, {text})
509 Number set line {lnum} to {text} in buffer
510 {expr}
511setbufvar({buf}, {varname}, {val})
512 none set {varname} in buffer {buf} to {val}
513setcellwidths({list}) none set character cell width overrides
514setcharpos({expr}, {list}) Number set the {expr} position to {list}
515setcharsearch({dict}) Dict set character search from {dict}
Shougo Matsushita07ea5f12022-08-27 12:22:25 +0100516setcmdline({str} [, {pos}]) Number set command-line
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000517setcmdpos({pos}) Number set cursor position in command-line
518setcursorcharpos({list}) Number move cursor to position in {list}
519setenv({name}, {val}) none set environment variable
520setfperm({fname}, {mode}) Number set {fname} file permissions to {mode}
521setline({lnum}, {line}) Number set line {lnum} to {line}
522setloclist({nr}, {list} [, {action}])
523 Number modify location list using {list}
524setloclist({nr}, {list}, {action}, {what})
525 Number modify specific location list props
526setmatches({list} [, {win}]) Number restore a list of matches
527setpos({expr}, {list}) Number set the {expr} position to {list}
528setqflist({list} [, {action}]) Number modify quickfix list using {list}
529setqflist({list}, {action}, {what})
530 Number modify specific quickfix list props
531setreg({n}, {v} [, {opt}]) Number set register to value and type
532settabvar({nr}, {varname}, {val}) none set {varname} in tab page {nr} to {val}
533settabwinvar({tabnr}, {winnr}, {varname}, {val})
534 none set {varname} in window {winnr} in tab
535 page {tabnr} to {val}
536settagstack({nr}, {dict} [, {action}])
537 Number modify tag stack using {dict}
538setwinvar({nr}, {varname}, {val}) none set {varname} in window {nr} to {val}
539sha256({string}) String SHA256 checksum of {string}
540shellescape({string} [, {special}])
541 String escape {string} for use as shell
542 command argument
543shiftwidth([{col}]) Number effective value of 'shiftwidth'
544sign_define({name} [, {dict}]) Number define or update a sign
545sign_define({list}) List define or update a list of signs
546sign_getdefined([{name}]) List get a list of defined signs
547sign_getplaced([{buf} [, {dict}]])
548 List get a list of placed signs
549sign_jump({id}, {group}, {buf})
550 Number jump to a sign
551sign_place({id}, {group}, {name}, {buf} [, {dict}])
552 Number place a sign
553sign_placelist({list}) List place a list of signs
554sign_undefine([{name}]) Number undefine a sign
555sign_undefine({list}) List undefine a list of signs
556sign_unplace({group} [, {dict}])
557 Number unplace a sign
558sign_unplacelist({list}) List unplace a list of signs
559simplify({filename}) String simplify filename as much as possible
560sin({expr}) Float sine of {expr}
561sinh({expr}) Float hyperbolic sine of {expr}
562slice({expr}, {start} [, {end}]) String, List or Blob
563 slice of a String, List or Blob
Bram Moolenaar2007dd42022-02-23 13:17:47 +0000564sort({list} [, {how} [, {dict}]])
565 List sort {list}, compare with {how}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000566sound_clear() none stop playing all sounds
567sound_playevent({name} [, {callback}])
568 Number play an event sound
569sound_playfile({path} [, {callback}])
570 Number play sound file {path}
571sound_stop({id}) none stop playing sound {id}
572soundfold({word}) String sound-fold {word}
573spellbadword() String badly spelled word at cursor
574spellsuggest({word} [, {max} [, {capital}]])
575 List spelling suggestions
576split({expr} [, {pat} [, {keepempty}]])
577 List make |List| from {pat} separated {expr}
578sqrt({expr}) Float square root of {expr}
579srand([{expr}]) List get seed for |rand()|
580state([{what}]) String current state of Vim
581str2float({expr} [, {quoted}]) Float convert String to Float
582str2list({expr} [, {utf8}]) List convert each character of {expr} to
583 ASCII/UTF-8 value
584str2nr({expr} [, {base} [, {quoted}]])
585 Number convert String to Number
586strcharlen({expr}) Number character length of the String {expr}
587strcharpart({str}, {start} [, {len} [, {skipcc}]])
588 String {len} characters of {str} at
589 character {start}
590strchars({expr} [, {skipcc}]) Number character count of the String {expr}
591strdisplaywidth({expr} [, {col}]) Number display length of the String {expr}
592strftime({format} [, {time}]) String format time with a specified format
593strgetchar({str}, {index}) Number get char {index} from {str}
594stridx({haystack}, {needle} [, {start}])
595 Number index of {needle} in {haystack}
596string({expr}) String String representation of {expr} value
597strlen({expr}) Number length of the String {expr}
598strpart({str}, {start} [, {len} [, {chars}]])
599 String {len} bytes/chars of {str} at
600 byte {start}
601strptime({format}, {timestring})
602 Number Convert {timestring} to unix timestamp
603strridx({haystack}, {needle} [, {start}])
604 Number last index of {needle} in {haystack}
605strtrans({expr}) String translate string to make it printable
606strwidth({expr}) Number display cell length of the String {expr}
607submatch({nr} [, {list}]) String or List
608 specific match in ":s" or substitute()
609substitute({expr}, {pat}, {sub}, {flags})
610 String all {pat} in {expr} replaced with {sub}
Bram Moolenaarc216a7a2022-12-05 13:50:55 +0000611swapfilelist() List swap files found in 'directory'
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000612swapinfo({fname}) Dict information about swap file {fname}
613swapname({buf}) String swap file of buffer {buf}
614synID({lnum}, {col}, {trans}) Number syntax ID at {lnum} and {col}
615synIDattr({synID}, {what} [, {mode}])
616 String attribute {what} of syntax ID {synID}
617synIDtrans({synID}) Number translated syntax ID of {synID}
618synconcealed({lnum}, {col}) List info about concealing
619synstack({lnum}, {col}) List stack of syntax IDs at {lnum} and {col}
620system({expr} [, {input}]) String output of shell command/filter {expr}
621systemlist({expr} [, {input}]) List output of shell command/filter {expr}
622tabpagebuflist([{arg}]) List list of buffer numbers in tab page
623tabpagenr([{arg}]) Number number of current or last tab page
624tabpagewinnr({tabarg} [, {arg}]) Number number of current window in tab page
625tagfiles() List tags files used
626taglist({expr} [, {filename}]) List list of tags matching {expr}
627tan({expr}) Float tangent of {expr}
628tanh({expr}) Float hyperbolic tangent of {expr}
629tempname() String name for a temporary file
630term_dumpdiff({filename}, {filename} [, {options}])
631 Number display difference between two dumps
632term_dumpload({filename} [, {options}])
633 Number displaying a screen dump
634term_dumpwrite({buf}, {filename} [, {options}])
635 none dump terminal window contents
636term_getaltscreen({buf}) Number get the alternate screen flag
637term_getansicolors({buf}) List get ANSI palette in GUI color mode
638term_getattr({attr}, {what}) Number get the value of attribute {what}
639term_getcursor({buf}) List get the cursor position of a terminal
640term_getjob({buf}) Job get the job associated with a terminal
641term_getline({buf}, {row}) String get a line of text from a terminal
642term_getscrolled({buf}) Number get the scroll count of a terminal
643term_getsize({buf}) List get the size of a terminal
644term_getstatus({buf}) String get the status of a terminal
645term_gettitle({buf}) String get the title of a terminal
646term_gettty({buf}, [{input}]) String get the tty name of a terminal
647term_list() List get the list of terminal buffers
648term_scrape({buf}, {row}) List get row of a terminal screen
649term_sendkeys({buf}, {keys}) none send keystrokes to a terminal
650term_setansicolors({buf}, {colors})
651 none set ANSI palette in GUI color mode
652term_setapi({buf}, {expr}) none set |terminal-api| function name prefix
653term_setkill({buf}, {how}) none set signal to stop job in terminal
654term_setrestore({buf}, {command}) none set command to restore terminal
655term_setsize({buf}, {rows}, {cols})
656 none set the size of a terminal
657term_start({cmd} [, {options}]) Number open a terminal window and run a job
658term_wait({buf} [, {time}]) Number wait for screen to be updated
659terminalprops() Dict properties of the terminal
660test_alloc_fail({id}, {countdown}, {repeat})
661 none make memory allocation fail
662test_autochdir() none enable 'autochdir' during startup
663test_feedinput({string}) none add key sequence to input buffer
664test_garbagecollect_now() none free memory right now for testing
665test_garbagecollect_soon() none free memory soon for testing
666test_getvalue({string}) any get value of an internal variable
Yegappan Lakshmanan06011e12022-01-30 12:37:29 +0000667test_gui_event({event}, {args}) bool generate a GUI event for testing
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000668test_ignore_error({expr}) none ignore a specific error
669test_null_blob() Blob null value for testing
670test_null_channel() Channel null value for testing
671test_null_dict() Dict null value for testing
672test_null_function() Funcref null value for testing
673test_null_job() Job null value for testing
674test_null_list() List null value for testing
675test_null_partial() Funcref null value for testing
676test_null_string() String null value for testing
677test_option_not_set({name}) none reset flag indicating option was set
678test_override({expr}, {val}) none test with Vim internal overrides
679test_refcount({expr}) Number get the reference count of {expr}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000680test_setmouse({row}, {col}) none set the mouse position for testing
681test_settime({expr}) none set current time for testing
682test_srand_seed([seed]) none set seed for testing srand()
683test_unknown() any unknown value for testing
684test_void() any void value for testing
685timer_info([{id}]) List information about timers
686timer_pause({id}, {pause}) none pause or unpause a timer
687timer_start({time}, {callback} [, {options}])
688 Number create a timer
689timer_stop({timer}) none stop a timer
690timer_stopall() none stop all timers
691tolower({expr}) String the String {expr} switched to lowercase
692toupper({expr}) String the String {expr} switched to uppercase
693tr({src}, {fromstr}, {tostr}) String translate chars of {src} in {fromstr}
694 to chars in {tostr}
695trim({text} [, {mask} [, {dir}]])
696 String trim characters in {mask} from {text}
697trunc({expr}) Float truncate Float {expr}
698type({expr}) Number type of value {expr}
699typename({expr}) String representation of the type of {expr}
700undofile({name}) String undo file name for {name}
701undotree() List undo file tree
702uniq({list} [, {func} [, {dict}]])
703 List remove adjacent duplicates from a list
704values({dict}) List values in {dict}
LemonBoy0f7a3e12022-05-26 12:10:37 +0100705virtcol({expr} [, {list}]) Number or List
706 screen column of cursor or mark
Bram Moolenaar5a6ec102022-05-27 21:58:00 +0100707virtcol2col({winid}, {lnum}, {col})
708 Number byte index of a character on screen
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000709visualmode([expr]) String last visual mode used
710wildmenumode() Number whether 'wildmenu' mode is active
711win_execute({id}, {command} [, {silent}])
712 String execute {command} in window {id}
713win_findbuf({bufnr}) List find windows containing {bufnr}
714win_getid([{win} [, {tab}]]) Number get window ID for {win} in {tab}
715win_gettype([{nr}]) String type of window {nr}
716win_gotoid({expr}) Number go to window with ID {expr}
717win_id2tabwin({expr}) List get tab and window nr from window ID
718win_id2win({expr}) Number get window nr from window ID
Daniel Steinbergee630312022-01-10 13:36:34 +0000719win_move_separator({nr}) Number move window vertical separator
720win_move_statusline({nr}) Number move window status line
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000721win_screenpos({nr}) List get screen position of window {nr}
722win_splitmove({nr}, {target} [, {options}])
723 Number move window {nr} to split of {target}
724winbufnr({nr}) Number buffer number of window {nr}
725wincol() Number window column of the cursor
726windowsversion() String MS-Windows OS version
727winheight({nr}) Number height of window {nr}
728winlayout([{tabnr}]) List layout of windows in tab {tabnr}
729winline() Number window line of the cursor
730winnr([{expr}]) Number number of current window
731winrestcmd() String returns command to restore window sizes
732winrestview({dict}) none restore view of current window
733winsaveview() Dict save view of current window
734winwidth({nr}) Number width of window {nr}
735wordcount() Dict get byte/char/word statistics
736writefile({object}, {fname} [, {flags}])
737 Number write |Blob| or |List| of lines to file
738xor({expr}, {expr}) Number bitwise XOR
739
740==============================================================================
7412. Details *builtin-function-details*
742
743Not all functions are here, some have been moved to a help file covering the
744specific functionality.
745
746abs({expr}) *abs()*
747 Return the absolute value of {expr}. When {expr} evaluates to
748 a |Float| abs() returns a |Float|. When {expr} can be
749 converted to a |Number| abs() returns a |Number|. Otherwise
750 abs() gives an error message and returns -1.
751 Examples: >
752 echo abs(1.456)
753< 1.456 >
754 echo abs(-5.456)
755< 5.456 >
756 echo abs(-4)
757< 4
758
759 Can also be used as a |method|: >
760 Compute()->abs()
761
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000762
763acos({expr}) *acos()*
764 Return the arc cosine of {expr} measured in radians, as a
765 |Float| in the range of [0, pi].
766 {expr} must evaluate to a |Float| or a |Number| in the range
Bram Moolenaar016188f2022-06-06 20:52:59 +0100767 [-1, 1]. Otherwise acos() returns "nan".
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000768 Examples: >
769 :echo acos(0)
770< 1.570796 >
771 :echo acos(-0.5)
772< 2.094395
773
774 Can also be used as a |method|: >
775 Compute()->acos()
776
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000777
778add({object}, {expr}) *add()*
779 Append the item {expr} to |List| or |Blob| {object}. Returns
780 the resulting |List| or |Blob|. Examples: >
781 :let alist = add([1, 2, 3], item)
782 :call add(mylist, "woodstock")
783< Note that when {expr} is a |List| it is appended as a single
784 item. Use |extend()| to concatenate |Lists|.
785 When {object} is a |Blob| then {expr} must be a number.
786 Use |insert()| to add an item at another position.
Bram Moolenaar016188f2022-06-06 20:52:59 +0100787 Returns 1 if {object} is not a |List| or a |Blob|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000788
789 Can also be used as a |method|: >
790 mylist->add(val1)->add(val2)
791
792
793and({expr}, {expr}) *and()*
794 Bitwise AND on the two arguments. The arguments are converted
795 to a number. A List, Dict or Float argument causes an error.
LemonBoy0f7a3e12022-05-26 12:10:37 +0100796 Also see `or()` and `xor()`.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000797 Example: >
798 :let flag = and(bits, 0x80)
799< Can also be used as a |method|: >
800 :let flag = bits->and(0x80)
801
802
803append({lnum}, {text}) *append()*
804 When {text} is a |List|: Append each item of the |List| as a
805 text line below line {lnum} in the current buffer.
806 Otherwise append {text} as one text line below line {lnum} in
807 the current buffer.
808 Any type of item is accepted and converted to a String.
809 {lnum} can be zero to insert a line before the first one.
810 {lnum} is used like with |getline()|.
811 Returns 1 for failure ({lnum} out of range or out of memory),
Bram Moolenaarcd9c8d42022-11-05 23:46:43 +0000812 0 for success. When {text} is an empty list zero is returned,
813 no matter the value of {lnum}.
814 In |Vim9| script an invalid argument or negative number
815 results in an error. Example: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000816 :let failed = append(line('$'), "# THE END")
817 :let failed = append(0, ["Chapter 1", "the beginning"])
818
819< Can also be used as a |method| after a List, the base is
820 passed as the second argument: >
821 mylist->append(lnum)
822
823
824appendbufline({buf}, {lnum}, {text}) *appendbufline()*
825 Like |append()| but append the text in buffer {buf}.
826
827 This function works only for loaded buffers. First call
828 |bufload()| if needed.
829
830 For the use of {buf}, see |bufname()|.
831
Bram Moolenaar8b6256f2021-12-28 11:24:49 +0000832 {lnum} is the line number to append below. Note that using
833 |line()| would use the current buffer, not the one appending
834 to. Use "$" to append at the end of the buffer. Other string
835 values are not supported.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000836
837 On success 0 is returned, on failure 1 is returned.
838 In |Vim9| script an error is given for an invalid {lnum}.
839
840 If {buf} is not a valid buffer or {lnum} is not valid, an
841 error message is given. Example: >
842 :let failed = appendbufline(13, 0, "# THE START")
Bram Moolenaarcd9c8d42022-11-05 23:46:43 +0000843< However, when {text} is an empty list then no error is given
844 for an invalid {lnum}, since {lnum} isn't actually used.
845
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000846 Can also be used as a |method| after a List, the base is
847 passed as the second argument: >
848 mylist->appendbufline(buf, lnum)
849
850
851argc([{winid}]) *argc()*
852 The result is the number of files in the argument list. See
853 |arglist|.
854 If {winid} is not supplied, the argument list of the current
855 window is used.
856 If {winid} is -1, the global argument list is used.
857 Otherwise {winid} specifies the window of which the argument
858 list is used: either the window number or the window ID.
859 Returns -1 if the {winid} argument is invalid.
860
861 *argidx()*
862argidx() The result is the current index in the argument list. 0 is
863 the first file. argc() - 1 is the last one. See |arglist|.
864
865 *arglistid()*
866arglistid([{winnr} [, {tabnr}]])
867 Return the argument list ID. This is a number which
868 identifies the argument list being used. Zero is used for the
869 global argument list. See |arglist|.
870 Returns -1 if the arguments are invalid.
871
872 Without arguments use the current window.
873 With {winnr} only use this window in the current tab page.
874 With {winnr} and {tabnr} use the window in the specified tab
875 page.
876 {winnr} can be the window number or the |window-ID|.
877
878 *argv()*
879argv([{nr} [, {winid}]])
880 The result is the {nr}th file in the argument list. See
881 |arglist|. "argv(0)" is the first one. Example: >
882 :let i = 0
883 :while i < argc()
884 : let f = escape(fnameescape(argv(i)), '.')
Bram Moolenaarc51cf032022-02-26 12:25:45 +0000885 : exe 'amenu Arg.' .. f .. ' :e ' .. f .. '<CR>'
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000886 : let i = i + 1
887 :endwhile
888< Without the {nr} argument, or when {nr} is -1, a |List| with
889 the whole |arglist| is returned.
890
891 The {winid} argument specifies the window ID, see |argc()|.
892 For the Vim command line arguments see |v:argv|.
893
Bram Moolenaar016188f2022-06-06 20:52:59 +0100894 Returns an empty string if {nr}th argument is not present in
895 the argument list. Returns an empty List if the {winid}
896 argument is invalid.
897
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000898asin({expr}) *asin()*
899 Return the arc sine of {expr} measured in radians, as a |Float|
900 in the range of [-pi/2, pi/2].
901 {expr} must evaluate to a |Float| or a |Number| in the range
902 [-1, 1].
Bram Moolenaar016188f2022-06-06 20:52:59 +0100903 Returns "nan" if {expr} is outside the range [-1, 1]. Returns
904 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000905 Examples: >
906 :echo asin(0.8)
907< 0.927295 >
908 :echo asin(-0.5)
909< -0.523599
910
911 Can also be used as a |method|: >
912 Compute()->asin()
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000913
914
915assert_ functions are documented here: |assert-functions-details|
916
917
918
919atan({expr}) *atan()*
920 Return the principal value of the arc tangent of {expr}, in
921 the range [-pi/2, +pi/2] radians, as a |Float|.
922 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar016188f2022-06-06 20:52:59 +0100923 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000924 Examples: >
925 :echo atan(100)
926< 1.560797 >
927 :echo atan(-4.01)
928< -1.326405
929
930 Can also be used as a |method|: >
931 Compute()->atan()
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000932
933
934atan2({expr1}, {expr2}) *atan2()*
935 Return the arc tangent of {expr1} / {expr2}, measured in
936 radians, as a |Float| in the range [-pi, pi].
937 {expr1} and {expr2} must evaluate to a |Float| or a |Number|.
Bram Moolenaar016188f2022-06-06 20:52:59 +0100938 Returns 0.0 if {expr1} or {expr2} is not a |Float| or a
939 |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000940 Examples: >
941 :echo atan2(-1, 1)
942< -0.785398 >
943 :echo atan2(1, -1)
944< 2.356194
945
946 Can also be used as a |method|: >
947 Compute()->atan2(1)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000948
Yegappan Lakshmanan1755a912022-05-19 10:31:47 +0100949
950autocmd_add({acmds}) *autocmd_add()*
951 Adds a List of autocmds and autocmd groups.
952
953 The {acmds} argument is a List where each item is a Dict with
954 the following optional items:
955 bufnr buffer number to add a buffer-local autocmd.
956 If this item is specified, then the "pattern"
957 item is ignored.
958 cmd Ex command to execute for this autocmd event
959 event autocmd event name. Refer to |autocmd-events|.
Yegappan Lakshmanane0ff3a72022-05-27 18:05:33 +0100960 This can be either a String with a single
961 event name or a List of event names.
Yegappan Lakshmanan1755a912022-05-19 10:31:47 +0100962 group autocmd group name. Refer to |autocmd-groups|.
963 If this group doesn't exist then it is
964 created. If not specified or empty, then the
965 default group is used.
Yegappan Lakshmanan971f6822022-05-24 11:40:11 +0100966 nested boolean flag, set to v:true to add a nested
967 autocmd. Refer to |autocmd-nested|.
LemonBoy0f7a3e12022-05-26 12:10:37 +0100968 once boolean flag, set to v:true to add an autocmd
Yegappan Lakshmanan971f6822022-05-24 11:40:11 +0100969 which executes only once. Refer to
970 |autocmd-once|.
Yegappan Lakshmanan1755a912022-05-19 10:31:47 +0100971 pattern autocmd pattern string. Refer to
972 |autocmd-patterns|. If "bufnr" item is
Yegappan Lakshmanane0ff3a72022-05-27 18:05:33 +0100973 present, then this item is ignored. This can
974 be a String with a single pattern or a List of
975 patterns.
Yegappan Lakshmanan971f6822022-05-24 11:40:11 +0100976 replace boolean flag, set to v:true to remove all the
977 commands associated with the specified autocmd
978 event and group and add the {cmd}. This is
979 useful to avoid adding the same command
LemonBoy0f7a3e12022-05-26 12:10:37 +0100980 multiple times for an autocmd event in a group.
Yegappan Lakshmanan1755a912022-05-19 10:31:47 +0100981
982 Returns v:true on success and v:false on failure.
983 Examples: >
984 " Create a buffer-local autocmd for buffer 5
985 let acmd = {}
986 let acmd.group = 'MyGroup'
987 let acmd.event = 'BufEnter'
988 let acmd.bufnr = 5
989 let acmd.cmd = 'call BufEnterFunc()'
990 call autocmd_add([acmd])
Bram Moolenaarcd9c8d42022-11-05 23:46:43 +0000991<
Yegappan Lakshmanan1755a912022-05-19 10:31:47 +0100992 Can also be used as a |method|: >
993 GetAutocmdList()->autocmd_add()
994<
995autocmd_delete({acmds}) *autocmd_delete()*
996 Deletes a List of autocmds and autocmd groups.
997
998 The {acmds} argument is a List where each item is a Dict with
999 the following optional items:
1000 bufnr buffer number to delete a buffer-local autocmd.
1001 If this item is specified, then the "pattern"
1002 item is ignored.
1003 cmd Ex command for this autocmd event
1004 event autocmd event name. Refer to |autocmd-events|.
1005 If '*' then all the autocmd events in this
1006 group are deleted.
1007 group autocmd group name. Refer to |autocmd-groups|.
1008 If not specified or empty, then the default
1009 group is used.
1010 nested set to v:true for a nested autocmd.
1011 Refer to |autocmd-nested|.
1012 once set to v:true for an autocmd which executes
1013 only once. Refer to |autocmd-once|.
1014 pattern autocmd pattern string. Refer to
1015 |autocmd-patterns|. If "bufnr" item is
1016 present, then this item is ignored.
1017
1018 If only {group} is specified in a {acmds} entry and {event},
1019 {pattern} and {cmd} are not specified, then that autocmd group
1020 is deleted.
1021
Bram Moolenaar016188f2022-06-06 20:52:59 +01001022 Returns |v:true| on success and |v:false| on failure.
Yegappan Lakshmanan1755a912022-05-19 10:31:47 +01001023 Examples: >
1024 " :autocmd! BufLeave *.vim
1025 let acmd = #{event: 'BufLeave', pattern: '*.vim'}
1026 call autocmd_delete([acmd]})
1027 " :autocmd! MyGroup1 BufLeave
1028 let acmd = #{group: 'MyGroup1', event: 'BufLeave'}
1029 call autocmd_delete([acmd])
1030 " :autocmd! MyGroup2 BufEnter *.c
1031 let acmd = #{group: 'MyGroup2', event: 'BufEnter',
1032 \ pattern: '*.c'}
1033 " :autocmd! MyGroup2 * *.c
1034 let acmd = #{group: 'MyGroup2', event: '*',
1035 \ pattern: '*.c'}
1036 call autocmd_delete([acmd])
1037 " :autocmd! MyGroup3
1038 let acmd = #{group: 'MyGroup3'}
1039 call autocmd_delete([acmd])
1040<
1041 Can also be used as a |method|: >
1042 GetAutocmdList()->autocmd_delete()
1043
1044autocmd_get([{opts}]) *autocmd_get()*
1045 Returns a |List| of autocmds. If {opts} is not supplied, then
1046 returns the autocmds for all the events in all the groups.
1047
1048 The optional {opts} Dict argument supports the following
1049 items:
1050 group Autocmd group name. If specified, returns only
1051 the autocmds defined in this group. If the
1052 specified group doesn't exist, results in an
1053 error message. If set to an empty string,
1054 then the default autocmd group is used.
1055 event Autocmd event name. If specified, returns only
1056 the autocmds defined for this event. If set
1057 to "*", then returns autocmds for all the
1058 events. If the specified event doesn't exist,
1059 results in an error message.
1060 pattern Autocmd pattern. If specified, returns only
1061 the autocmds defined for this pattern.
1062 A combination of the above three times can be supplied in
1063 {opts}.
1064
1065 Each Dict in the returned List contains the following items:
1066 bufnr For buffer-local autocmds, buffer number where
1067 the autocmd is defined.
1068 cmd Command executed for this autocmd.
1069 event Autocmd event name.
1070 group Autocmd group name.
Yegappan Lakshmanan971f6822022-05-24 11:40:11 +01001071 nested Boolean flag, set to v:true for a nested
1072 autocmd. See |autocmd-nested|.
1073 once Boolean flag, set to v:true, if the autocmd
1074 will be executed only once. See |autocmd-once|.
Yegappan Lakshmanan1755a912022-05-19 10:31:47 +01001075 pattern Autocmd pattern. For a buffer-local
1076 autocmd, this will be of the form "<buffer=n>".
1077 If there are multiple commands for an autocmd event in a
1078 group, then separate items are returned for each command.
1079
Bram Moolenaar016188f2022-06-06 20:52:59 +01001080 Returns an empty List if an autocmd with the specified group
1081 or event or pattern is not found.
1082
Yegappan Lakshmanan1755a912022-05-19 10:31:47 +01001083 Examples: >
1084 " :autocmd MyGroup
1085 echo autocmd_get(#{group: 'Mygroup'})
1086 " :autocmd G BufUnload
1087 echo autocmd_get(#{group: 'G', event: 'BufUnload'})
1088 " :autocmd G * *.ts
1089 let acmd = #{group: 'G', event: '*', pattern: '*.ts'}
1090 echo autocmd_get(acmd)
1091 " :autocmd Syntax
1092 echo autocmd_get(#{event: 'Syntax'})
1093 " :autocmd G BufEnter *.ts
1094 let acmd = #{group: 'G', event: 'BufEnter',
1095 \ pattern: '*.ts'}
1096 echo autocmd_get(acmd)
1097<
1098 Can also be used as a |method|: >
1099 Getopts()->autocmd_get()
1100<
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001101balloon_gettext() *balloon_gettext()*
1102 Return the current text in the balloon. Only for the string,
Bram Moolenaar016188f2022-06-06 20:52:59 +01001103 not used for the List. Returns an empty string if balloon
1104 is not present.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001105
1106balloon_show({expr}) *balloon_show()*
1107 Show {expr} inside the balloon. For the GUI {expr} is used as
1108 a string. For a terminal {expr} can be a list, which contains
1109 the lines of the balloon. If {expr} is not a list it will be
1110 split with |balloon_split()|.
1111 If {expr} is an empty string any existing balloon is removed.
1112
1113 Example: >
1114 func GetBalloonContent()
1115 " ... initiate getting the content
1116 return ''
1117 endfunc
1118 set balloonexpr=GetBalloonContent()
1119
1120 func BalloonCallback(result)
1121 call balloon_show(a:result)
1122 endfunc
1123< Can also be used as a |method|: >
1124 GetText()->balloon_show()
1125<
1126 The intended use is that fetching the content of the balloon
1127 is initiated from 'balloonexpr'. It will invoke an
1128 asynchronous method, in which a callback invokes
1129 balloon_show(). The 'balloonexpr' itself can return an
Bram Moolenaar069a7d52022-06-27 22:16:08 +01001130 empty string or a placeholder, e.g. "loading...".
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001131
Bram Moolenaar069a7d52022-06-27 22:16:08 +01001132 When showing a balloon is not possible then nothing happens,
1133 no error message is given.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001134 {only available when compiled with the |+balloon_eval| or
1135 |+balloon_eval_term| feature}
1136
1137balloon_split({msg}) *balloon_split()*
1138 Split String {msg} into lines to be displayed in a balloon.
1139 The splits are made for the current window size and optimize
1140 to show debugger output.
Bram Moolenaar016188f2022-06-06 20:52:59 +01001141 Returns a |List| with the split lines. Returns an empty List
1142 on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001143 Can also be used as a |method|: >
1144 GetText()->balloon_split()->balloon_show()
1145
1146< {only available when compiled with the |+balloon_eval_term|
1147 feature}
1148
1149blob2list({blob}) *blob2list()*
1150 Return a List containing the number value of each byte in Blob
1151 {blob}. Examples: >
1152 blob2list(0z0102.0304) returns [1, 2, 3, 4]
1153 blob2list(0z) returns []
1154< Returns an empty List on error. |list2blob()| does the
1155 opposite.
1156
1157 Can also be used as a |method|: >
1158 GetBlob()->blob2list()
Bram Moolenaarb529cfb2022-07-25 15:42:07 +01001159<
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001160 *browse()*
1161browse({save}, {title}, {initdir}, {default})
1162 Put up a file requester. This only works when "has("browse")"
1163 returns |TRUE| (only in some GUI versions).
1164 The input fields are:
1165 {save} when |TRUE|, select file to write
1166 {title} title for the requester
1167 {initdir} directory to start browsing in
1168 {default} default file name
1169 An empty string is returned when the "Cancel" button is hit,
1170 something went wrong, or browsing is not possible.
1171
1172 *browsedir()*
1173browsedir({title}, {initdir})
1174 Put up a directory requester. This only works when
1175 "has("browse")" returns |TRUE| (only in some GUI versions).
1176 On systems where a directory browser is not supported a file
1177 browser is used. In that case: select a file in the directory
1178 to be used.
1179 The input fields are:
1180 {title} title for the requester
1181 {initdir} directory to start browsing in
1182 When the "Cancel" button is hit, something went wrong, or
1183 browsing is not possible, an empty string is returned.
1184
1185bufadd({name}) *bufadd()*
Bram Moolenaar2eddbac2022-08-25 12:45:21 +01001186 Add a buffer to the buffer list with name {name} (must be a
1187 String).
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001188 If a buffer for file {name} already exists, return that buffer
1189 number. Otherwise return the buffer number of the newly
1190 created buffer. When {name} is an empty string then a new
1191 buffer is always created.
1192 The buffer will not have 'buflisted' set and not be loaded
1193 yet. To add some text to the buffer use this: >
1194 let bufnr = bufadd('someName')
1195 call bufload(bufnr)
1196 call setbufline(bufnr, 1, ['some', 'text'])
Bram Moolenaar016188f2022-06-06 20:52:59 +01001197< Returns 0 on error.
1198 Can also be used as a |method|: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001199 let bufnr = 'somename'->bufadd()
1200
1201bufexists({buf}) *bufexists()*
1202 The result is a Number, which is |TRUE| if a buffer called
1203 {buf} exists.
1204 If the {buf} argument is a number, buffer numbers are used.
1205 Number zero is the alternate buffer for the current window.
1206
1207 If the {buf} argument is a string it must match a buffer name
1208 exactly. The name can be:
1209 - Relative to the current directory.
1210 - A full path.
1211 - The name of a buffer with 'buftype' set to "nofile".
1212 - A URL name.
1213 Unlisted buffers will be found.
1214 Note that help files are listed by their short name in the
1215 output of |:buffers|, but bufexists() requires using their
1216 long name to be able to find them.
1217 bufexists() may report a buffer exists, but to use the name
1218 with a |:buffer| command you may need to use |expand()|. Esp
1219 for MS-Windows 8.3 names in the form "c:\DOCUME~1"
1220 Use "bufexists(0)" to test for the existence of an alternate
1221 file name.
1222
1223 Can also be used as a |method|: >
1224 let exists = 'somename'->bufexists()
1225<
1226 Obsolete name: buffer_exists(). *buffer_exists()*
1227
1228buflisted({buf}) *buflisted()*
1229 The result is a Number, which is |TRUE| if a buffer called
1230 {buf} exists and is listed (has the 'buflisted' option set).
1231 The {buf} argument is used like with |bufexists()|.
1232
1233 Can also be used as a |method|: >
1234 let listed = 'somename'->buflisted()
1235
1236bufload({buf}) *bufload()*
1237 Ensure the buffer {buf} is loaded. When the buffer name
1238 refers to an existing file then the file is read. Otherwise
1239 the buffer will be empty. If the buffer was already loaded
Bram Moolenaar2eddbac2022-08-25 12:45:21 +01001240 then there is no change. If the buffer is not related to a
1241 file the no file is read (e.g., when 'buftype' is "nofile").
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001242 If there is an existing swap file for the file of the buffer,
1243 there will be no dialog, the buffer will be loaded anyway.
1244 The {buf} argument is used like with |bufexists()|.
1245
1246 Can also be used as a |method|: >
1247 eval 'somename'->bufload()
1248
1249bufloaded({buf}) *bufloaded()*
1250 The result is a Number, which is |TRUE| if a buffer called
1251 {buf} exists and is loaded (shown in a window or hidden).
1252 The {buf} argument is used like with |bufexists()|.
1253
1254 Can also be used as a |method|: >
1255 let loaded = 'somename'->bufloaded()
1256
1257bufname([{buf}]) *bufname()*
1258 The result is the name of a buffer. Mostly as it is displayed
1259 by the `:ls` command, but not using special names such as
1260 "[No Name]".
1261 If {buf} is omitted the current buffer is used.
1262 If {buf} is a Number, that buffer number's name is given.
1263 Number zero is the alternate buffer for the current window.
1264 If {buf} is a String, it is used as a |file-pattern| to match
1265 with the buffer names. This is always done like 'magic' is
1266 set and 'cpoptions' is empty. When there is more than one
1267 match an empty string is returned.
1268 "" or "%" can be used for the current buffer, "#" for the
1269 alternate buffer.
1270 A full match is preferred, otherwise a match at the start, end
1271 or middle of the buffer name is accepted. If you only want a
1272 full match then put "^" at the start and "$" at the end of the
1273 pattern.
1274 Listed buffers are found first. If there is a single match
1275 with a listed buffer, that one is returned. Next unlisted
1276 buffers are searched for.
1277 If the {buf} is a String, but you want to use it as a buffer
1278 number, force it to be a Number by adding zero to it: >
1279 :echo bufname("3" + 0)
1280< Can also be used as a |method|: >
1281 echo bufnr->bufname()
1282
1283< If the buffer doesn't exist, or doesn't have a name, an empty
1284 string is returned. >
1285 bufname("#") alternate buffer name
1286 bufname(3) name of buffer 3
1287 bufname("%") name of current buffer
1288 bufname("file2") name of buffer where "file2" matches.
1289< *buffer_name()*
1290 Obsolete name: buffer_name().
1291
1292 *bufnr()*
1293bufnr([{buf} [, {create}]])
1294 The result is the number of a buffer, as it is displayed by
1295 the `:ls` command. For the use of {buf}, see |bufname()|
1296 above.
1297
1298 If the buffer doesn't exist, -1 is returned. Or, if the
1299 {create} argument is present and TRUE, a new, unlisted,
1300 buffer is created and its number is returned. Example: >
1301 let newbuf = bufnr('Scratch001', 1)
1302< Using an empty name uses the current buffer. To create a new
1303 buffer with an empty name use |bufadd()|.
1304
1305 bufnr("$") is the last buffer: >
1306 :let last_buffer = bufnr("$")
1307< The result is a Number, which is the highest buffer number
1308 of existing buffers. Note that not all buffers with a smaller
1309 number necessarily exist, because ":bwipeout" may have removed
1310 them. Use bufexists() to test for the existence of a buffer.
1311
1312 Can also be used as a |method|: >
1313 echo bufref->bufnr()
1314<
1315 Obsolete name: buffer_number(). *buffer_number()*
1316 *last_buffer_nr()*
1317 Obsolete name for bufnr("$"): last_buffer_nr().
1318
1319bufwinid({buf}) *bufwinid()*
1320 The result is a Number, which is the |window-ID| of the first
1321 window associated with buffer {buf}. For the use of {buf},
1322 see |bufname()| above. If buffer {buf} doesn't exist or
1323 there is no such window, -1 is returned. Example: >
1324
Bram Moolenaarc51cf032022-02-26 12:25:45 +00001325 echo "A window containing buffer 1 is " .. (bufwinid(1))
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001326<
Bram Moolenaar76db9e02022-11-09 21:21:04 +00001327 Only deals with the current tab page. See |win_findbuf()| for
1328 finding more.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001329
1330 Can also be used as a |method|: >
1331 FindBuffer()->bufwinid()
1332
1333bufwinnr({buf}) *bufwinnr()*
1334 Like |bufwinid()| but return the window number instead of the
1335 |window-ID|.
1336 If buffer {buf} doesn't exist or there is no such window, -1
1337 is returned. Example: >
1338
Bram Moolenaarc51cf032022-02-26 12:25:45 +00001339 echo "A window containing buffer 1 is " .. (bufwinnr(1))
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001340
1341< The number can be used with |CTRL-W_w| and ":wincmd w"
1342 |:wincmd|.
1343
1344 Can also be used as a |method|: >
1345 FindBuffer()->bufwinnr()
1346
1347byte2line({byte}) *byte2line()*
1348 Return the line number that contains the character at byte
1349 count {byte} in the current buffer. This includes the
1350 end-of-line character, depending on the 'fileformat' option
1351 for the current buffer. The first character has byte count
1352 one.
1353 Also see |line2byte()|, |go| and |:goto|.
1354
Bram Moolenaar016188f2022-06-06 20:52:59 +01001355 Returns -1 if the {byte} value is invalid.
1356
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001357 Can also be used as a |method|: >
1358 GetOffset()->byte2line()
1359
1360< {not available when compiled without the |+byte_offset|
1361 feature}
1362
1363byteidx({expr}, {nr}) *byteidx()*
1364 Return byte index of the {nr}'th character in the String
1365 {expr}. Use zero for the first character, it then returns
1366 zero.
1367 If there are no multibyte characters the returned value is
1368 equal to {nr}.
1369 Composing characters are not counted separately, their byte
1370 length is added to the preceding base character. See
1371 |byteidxcomp()| below for counting composing characters
1372 separately.
1373 Example : >
1374 echo matchstr(str, ".", byteidx(str, 3))
1375< will display the fourth character. Another way to do the
1376 same: >
1377 let s = strpart(str, byteidx(str, 3))
1378 echo strpart(s, 0, byteidx(s, 1))
1379< Also see |strgetchar()| and |strcharpart()|.
1380
1381 If there are less than {nr} characters -1 is returned.
1382 If there are exactly {nr} characters the length of the string
1383 in bytes is returned.
1384
1385 Can also be used as a |method|: >
1386 GetName()->byteidx(idx)
1387
1388byteidxcomp({expr}, {nr}) *byteidxcomp()*
1389 Like byteidx(), except that a composing character is counted
1390 as a separate character. Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00001391 let s = 'e' .. nr2char(0x301)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001392 echo byteidx(s, 1)
1393 echo byteidxcomp(s, 1)
1394 echo byteidxcomp(s, 2)
1395< The first and third echo result in 3 ('e' plus composing
1396 character is 3 bytes), the second echo results in 1 ('e' is
1397 one byte).
1398 Only works differently from byteidx() when 'encoding' is set
1399 to a Unicode encoding.
1400
1401 Can also be used as a |method|: >
1402 GetName()->byteidxcomp(idx)
1403
1404call({func}, {arglist} [, {dict}]) *call()* *E699*
1405 Call function {func} with the items in |List| {arglist} as
1406 arguments.
1407 {func} can either be a |Funcref| or the name of a function.
1408 a:firstline and a:lastline are set to the cursor line.
1409 Returns the return value of the called function.
1410 {dict} is for functions with the "dict" attribute. It will be
1411 used to set the local variable "self". |Dictionary-function|
1412
1413 Can also be used as a |method|: >
1414 GetFunc()->call([arg, arg], dict)
1415
1416ceil({expr}) *ceil()*
1417 Return the smallest integral value greater than or equal to
1418 {expr} as a |Float| (round up).
1419 {expr} must evaluate to a |Float| or a |Number|.
1420 Examples: >
1421 echo ceil(1.456)
1422< 2.0 >
1423 echo ceil(-5.456)
1424< -5.0 >
1425 echo ceil(4.0)
1426< 4.0
1427
Bram Moolenaar016188f2022-06-06 20:52:59 +01001428 Returns 0.0 if {expr} is not a |Float| or a |Number|.
1429
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001430 Can also be used as a |method|: >
1431 Compute()->ceil()
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001432
1433
1434ch_ functions are documented here: |channel-functions-details|
1435
1436
1437changenr() *changenr()*
1438 Return the number of the most recent change. This is the same
1439 number as what is displayed with |:undolist| and can be used
1440 with the |:undo| command.
1441 When a change was made it is the number of that change. After
1442 redo it is the number of the redone change. After undo it is
1443 one less than the number of the undone change.
Bram Moolenaar016188f2022-06-06 20:52:59 +01001444 Returns 0 if the undo list is empty.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001445
1446char2nr({string} [, {utf8}]) *char2nr()*
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01001447 Return Number value of the first char in {string}.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001448 Examples: >
1449 char2nr(" ") returns 32
1450 char2nr("ABC") returns 65
1451< When {utf8} is omitted or zero, the current 'encoding' is used.
1452 Example for "utf-8": >
1453 char2nr("á") returns 225
1454 char2nr("á"[0]) returns 195
1455< When {utf8} is TRUE, always treat as UTF-8 characters.
1456 A combining character is a separate character.
1457 |nr2char()| does the opposite.
1458 To turn a string into a list of character numbers: >
1459 let str = "ABC"
1460 let list = map(split(str, '\zs'), {_, val -> char2nr(val)})
1461< Result: [65, 66, 67]
1462
Bram Moolenaar016188f2022-06-06 20:52:59 +01001463 Returns 0 if {string} is not a |String|.
1464
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001465 Can also be used as a |method|: >
1466 GetChar()->char2nr()
1467
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001468charclass({string}) *charclass()*
1469 Return the character class of the first character in {string}.
1470 The character class is one of:
1471 0 blank
1472 1 punctuation
1473 2 word character
1474 3 emoji
1475 other specific Unicode class
1476 The class is used in patterns and word motions.
Bram Moolenaar016188f2022-06-06 20:52:59 +01001477 Returns 0 if {string} is not a |String|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001478
1479
Yegappan Lakshmanan4c8d2f02022-11-12 16:07:47 +00001480charcol({expr} [, {winid}]) *charcol()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001481 Same as |col()| but returns the character index of the column
1482 position given with {expr} instead of the byte position.
1483
1484 Example:
1485 With the cursor on '세' in line 5 with text "여보세요": >
1486 charcol('.') returns 3
1487 col('.') returns 7
1488
1489< Can also be used as a |method|: >
1490 GetPos()->col()
1491<
1492 *charidx()*
1493charidx({string}, {idx} [, {countcc}])
1494 Return the character index of the byte at {idx} in {string}.
1495 The index of the first character is zero.
1496 If there are no multibyte characters the returned value is
1497 equal to {idx}.
1498 When {countcc} is omitted or |FALSE|, then composing characters
1499 are not counted separately, their byte length is
1500 added to the preceding base character.
1501 When {countcc} is |TRUE|, then composing characters are
1502 counted as separate characters.
1503 Returns -1 if the arguments are invalid or if {idx} is greater
1504 than the index of the last byte in {string}. An error is
1505 given if the first argument is not a string, the second
1506 argument is not a number or when the third argument is present
1507 and is not zero or one.
1508 See |byteidx()| and |byteidxcomp()| for getting the byte index
1509 from the character index.
1510 Examples: >
1511 echo charidx('áb́ć', 3) returns 1
1512 echo charidx('áb́ć', 6, 1) returns 4
1513 echo charidx('áb́ć', 16) returns -1
1514<
1515 Can also be used as a |method|: >
1516 GetName()->charidx(idx)
1517
1518chdir({dir}) *chdir()*
1519 Change the current working directory to {dir}. The scope of
1520 the directory change depends on the directory of the current
1521 window:
1522 - If the current window has a window-local directory
1523 (|:lcd|), then changes the window local directory.
1524 - Otherwise, if the current tabpage has a local
1525 directory (|:tcd|) then changes the tabpage local
1526 directory.
1527 - Otherwise, changes the global directory.
1528 {dir} must be a String.
1529 If successful, returns the previous working directory. Pass
1530 this to another chdir() to restore the directory.
1531 On failure, returns an empty string.
1532
1533 Example: >
1534 let save_dir = chdir(newdir)
1535 if save_dir != ""
1536 " ... do some work
1537 call chdir(save_dir)
1538 endif
1539
1540< Can also be used as a |method|: >
1541 GetDir()->chdir()
1542<
1543cindent({lnum}) *cindent()*
1544 Get the amount of indent for line {lnum} according the C
1545 indenting rules, as with 'cindent'.
1546 The indent is counted in spaces, the value of 'tabstop' is
1547 relevant. {lnum} is used just like in |getline()|.
Bram Moolenaar8e145b82022-05-21 20:17:31 +01001548 When {lnum} is invalid -1 is returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001549 See |C-indenting|.
1550
1551 Can also be used as a |method|: >
1552 GetLnum()->cindent()
1553
1554clearmatches([{win}]) *clearmatches()*
1555 Clears all matches previously defined for the current window
1556 by |matchadd()| and the |:match| commands.
1557 If {win} is specified, use the window with this number or
1558 window ID instead of the current window.
1559
1560 Can also be used as a |method|: >
1561 GetWin()->clearmatches()
1562<
Yegappan Lakshmanan4c8d2f02022-11-12 16:07:47 +00001563col({expr} [, {winid}) *col()*
1564 The result is a Number, which is the byte index of the column
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001565 position given with {expr}. The accepted positions are:
1566 . the cursor position
1567 $ the end of the cursor line (the result is the
1568 number of bytes in the cursor line plus one)
1569 'x position of mark x (if the mark is not set, 0 is
1570 returned)
1571 v In Visual mode: the start of the Visual area (the
1572 cursor is the end). When not in Visual mode
1573 returns the cursor position. Differs from |'<| in
1574 that it's updated right away.
1575 Additionally {expr} can be [lnum, col]: a |List| with the line
1576 and column number. Most useful when the column is "$", to get
1577 the last column of a specific line. When "lnum" or "col" is
1578 out of range then col() returns zero.
Yegappan Lakshmanan4c8d2f02022-11-12 16:07:47 +00001579 With the optional {winid} argument the values are obtained for
1580 that window instead of the current window.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001581 To get the line number use |line()|. To get both use
1582 |getpos()|.
1583 For the screen column position use |virtcol()|. For the
1584 character position use |charcol()|.
1585 Note that only marks in the current file can be used.
1586 Examples: >
1587 col(".") column of cursor
1588 col("$") length of cursor line plus one
1589 col("'t") column of mark t
Bram Moolenaarc51cf032022-02-26 12:25:45 +00001590 col("'" .. markname) column of mark markname
Yegappan Lakshmanan4c8d2f02022-11-12 16:07:47 +00001591< The first column is 1. Returns 0 if {expr} is invalid or when
1592 the window with ID {winid} is not found.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001593 For an uppercase mark the column may actually be in another
1594 buffer.
1595 For the cursor position, when 'virtualedit' is active, the
1596 column is one higher if the cursor is after the end of the
Bram Moolenaar6ebe4f92022-10-28 20:47:54 +01001597 line. Also, when using a <Cmd> mapping the cursor isn't
1598 moved, this can be used to obtain the column in Insert mode: >
Bram Moolenaar76db9e02022-11-09 21:21:04 +00001599 :imap <F2> <Cmd>echowin col(".")<CR>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001600
1601< Can also be used as a |method|: >
1602 GetPos()->col()
1603<
1604
1605complete({startcol}, {matches}) *complete()* *E785*
1606 Set the matches for Insert mode completion.
1607 Can only be used in Insert mode. You need to use a mapping
1608 with CTRL-R = (see |i_CTRL-R|). It does not work after CTRL-O
1609 or with an expression mapping.
1610 {startcol} is the byte offset in the line where the completed
1611 text start. The text up to the cursor is the original text
1612 that will be replaced by the matches. Use col('.') for an
1613 empty string. "col('.') - 1" will replace one character by a
1614 match.
1615 {matches} must be a |List|. Each |List| item is one match.
1616 See |complete-items| for the kind of items that are possible.
1617 "longest" in 'completeopt' is ignored.
1618 Note that the after calling this function you need to avoid
1619 inserting anything that would cause completion to stop.
1620 The match can be selected with CTRL-N and CTRL-P as usual with
1621 Insert mode completion. The popup menu will appear if
1622 specified, see |ins-completion-menu|.
1623 Example: >
1624 inoremap <F5> <C-R>=ListMonths()<CR>
1625
1626 func! ListMonths()
1627 call complete(col('.'), ['January', 'February', 'March',
1628 \ 'April', 'May', 'June', 'July', 'August', 'September',
1629 \ 'October', 'November', 'December'])
1630 return ''
1631 endfunc
1632< This isn't very useful, but it shows how it works. Note that
1633 an empty string is returned to avoid a zero being inserted.
1634
1635 Can also be used as a |method|, the base is passed as the
1636 second argument: >
1637 GetMatches()->complete(col('.'))
1638
1639complete_add({expr}) *complete_add()*
1640 Add {expr} to the list of matches. Only to be used by the
1641 function specified with the 'completefunc' option.
1642 Returns 0 for failure (empty string or out of memory),
1643 1 when the match was added, 2 when the match was already in
1644 the list.
1645 See |complete-functions| for an explanation of {expr}. It is
1646 the same as one item in the list that 'omnifunc' would return.
1647
1648 Can also be used as a |method|: >
1649 GetMoreMatches()->complete_add()
1650
1651complete_check() *complete_check()*
1652 Check for a key typed while looking for completion matches.
1653 This is to be used when looking for matches takes some time.
1654 Returns |TRUE| when searching for matches is to be aborted,
1655 zero otherwise.
1656 Only to be used by the function specified with the
1657 'completefunc' option.
1658
1659
1660complete_info([{what}]) *complete_info()*
1661 Returns a |Dictionary| with information about Insert mode
1662 completion. See |ins-completion|.
1663 The items are:
1664 mode Current completion mode name string.
1665 See |complete_info_mode| for the values.
1666 pum_visible |TRUE| if popup menu is visible.
1667 See |pumvisible()|.
1668 items List of completion matches. Each item is a
1669 dictionary containing the entries "word",
1670 "abbr", "menu", "kind", "info" and "user_data".
1671 See |complete-items|.
1672 selected Selected item index. First index is zero.
1673 Index is -1 if no item is selected (showing
1674 typed text only, or the last completion after
1675 no item is selected when using the <Up> or
1676 <Down> keys)
Bram Moolenaar0daafaa2022-09-04 17:45:43 +01001677 inserted Inserted string. [NOT IMPLEMENTED YET]
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001678
1679 *complete_info_mode*
1680 mode values are:
1681 "" Not in completion mode
1682 "keyword" Keyword completion |i_CTRL-X_CTRL-N|
1683 "ctrl_x" Just pressed CTRL-X |i_CTRL-X|
1684 "scroll" Scrolling with |i_CTRL-X_CTRL-E| or
1685 |i_CTRL-X_CTRL-Y|
1686 "whole_line" Whole lines |i_CTRL-X_CTRL-L|
1687 "files" File names |i_CTRL-X_CTRL-F|
1688 "tags" Tags |i_CTRL-X_CTRL-]|
1689 "path_defines" Definition completion |i_CTRL-X_CTRL-D|
1690 "path_patterns" Include completion |i_CTRL-X_CTRL-I|
1691 "dictionary" Dictionary |i_CTRL-X_CTRL-K|
1692 "thesaurus" Thesaurus |i_CTRL-X_CTRL-T|
1693 "cmdline" Vim Command line |i_CTRL-X_CTRL-V|
1694 "function" User defined completion |i_CTRL-X_CTRL-U|
1695 "omni" Omni completion |i_CTRL-X_CTRL-O|
1696 "spell" Spelling suggestions |i_CTRL-X_s|
1697 "eval" |complete()| completion
1698 "unknown" Other internal modes
1699
1700 If the optional {what} list argument is supplied, then only
1701 the items listed in {what} are returned. Unsupported items in
1702 {what} are silently ignored.
1703
1704 To get the position and size of the popup menu, see
1705 |pum_getpos()|. It's also available in |v:event| during the
1706 |CompleteChanged| event.
1707
Bram Moolenaar016188f2022-06-06 20:52:59 +01001708 Returns an empty |Dictionary| on error.
1709
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001710 Examples: >
1711 " Get all items
1712 call complete_info()
1713 " Get only 'mode'
1714 call complete_info(['mode'])
1715 " Get only 'mode' and 'pum_visible'
1716 call complete_info(['mode', 'pum_visible'])
1717
1718< Can also be used as a |method|: >
1719 GetItems()->complete_info()
1720<
1721 *confirm()*
1722confirm({msg} [, {choices} [, {default} [, {type}]]])
1723 confirm() offers the user a dialog, from which a choice can be
1724 made. It returns the number of the choice. For the first
1725 choice this is 1.
1726 Note: confirm() is only supported when compiled with dialog
1727 support, see |+dialog_con| and |+dialog_gui|.
1728
1729 {msg} is displayed in a |dialog| with {choices} as the
1730 alternatives. When {choices} is missing or empty, "&OK" is
1731 used (and translated).
1732 {msg} is a String, use '\n' to include a newline. Only on
1733 some systems the string is wrapped when it doesn't fit.
1734
1735 {choices} is a String, with the individual choices separated
1736 by '\n', e.g. >
1737 confirm("Save changes?", "&Yes\n&No\n&Cancel")
1738< The letter after the '&' is the shortcut key for that choice.
1739 Thus you can type 'c' to select "Cancel". The shortcut does
1740 not need to be the first letter: >
1741 confirm("file has been modified", "&Save\nSave &All")
1742< For the console, the first letter of each choice is used as
1743 the default shortcut key. Case is ignored.
1744
1745 The optional {default} argument is the number of the choice
1746 that is made if the user hits <CR>. Use 1 to make the first
1747 choice the default one. Use 0 to not set a default. If
1748 {default} is omitted, 1 is used.
1749
1750 The optional {type} String argument gives the type of dialog.
1751 This is only used for the icon of the GTK, Mac, Motif and
1752 Win32 GUI. It can be one of these values: "Error",
1753 "Question", "Info", "Warning" or "Generic". Only the first
1754 character is relevant. When {type} is omitted, "Generic" is
1755 used.
1756
1757 If the user aborts the dialog by pressing <Esc>, CTRL-C,
1758 or another valid interrupt key, confirm() returns 0.
1759
1760 An example: >
Bram Moolenaar46eea442022-03-30 10:51:39 +01001761 let choice = confirm("What do you want?",
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01001762 \ "&Apples\n&Oranges\n&Bananas", 2)
Bram Moolenaar46eea442022-03-30 10:51:39 +01001763 if choice == 0
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01001764 echo "make up your mind!"
Bram Moolenaar46eea442022-03-30 10:51:39 +01001765 elseif choice == 3
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01001766 echo "tasteful"
Bram Moolenaar46eea442022-03-30 10:51:39 +01001767 else
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01001768 echo "I prefer bananas myself."
Bram Moolenaar46eea442022-03-30 10:51:39 +01001769 endif
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001770< In a GUI dialog, buttons are used. The layout of the buttons
1771 depends on the 'v' flag in 'guioptions'. If it is included,
1772 the buttons are always put vertically. Otherwise, confirm()
1773 tries to put the buttons in one horizontal line. If they
1774 don't fit, a vertical layout is used anyway. For some systems
1775 the horizontal layout is always used.
1776
1777 Can also be used as a |method|in: >
1778 BuildMessage()->confirm("&Yes\n&No")
1779<
1780 *copy()*
1781copy({expr}) Make a copy of {expr}. For Numbers and Strings this isn't
1782 different from using {expr} directly.
1783 When {expr} is a |List| a shallow copy is created. This means
1784 that the original |List| can be changed without changing the
1785 copy, and vice versa. But the items are identical, thus
1786 changing an item changes the contents of both |Lists|.
1787 A |Dictionary| is copied in a similar way as a |List|.
1788 Also see |deepcopy()|.
1789 Can also be used as a |method|: >
1790 mylist->copy()
1791
1792cos({expr}) *cos()*
1793 Return the cosine of {expr}, measured in radians, as a |Float|.
1794 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar016188f2022-06-06 20:52:59 +01001795 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001796 Examples: >
1797 :echo cos(100)
1798< 0.862319 >
1799 :echo cos(-4.01)
1800< -0.646043
1801
1802 Can also be used as a |method|: >
1803 Compute()->cos()
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001804
1805
1806cosh({expr}) *cosh()*
1807 Return the hyperbolic cosine of {expr} as a |Float| in the range
1808 [1, inf].
1809 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar016188f2022-06-06 20:52:59 +01001810 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001811 Examples: >
1812 :echo cosh(0.5)
1813< 1.127626 >
1814 :echo cosh(-0.5)
1815< -1.127626
1816
1817 Can also be used as a |method|: >
1818 Compute()->cosh()
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001819
1820
1821count({comp}, {expr} [, {ic} [, {start}]]) *count()*
1822 Return the number of times an item with value {expr} appears
1823 in |String|, |List| or |Dictionary| {comp}.
1824
1825 If {start} is given then start with the item with this index.
1826 {start} can only be used with a |List|.
1827
1828 When {ic} is given and it's |TRUE| then case is ignored.
1829
1830 When {comp} is a string then the number of not overlapping
1831 occurrences of {expr} is returned. Zero is returned when
1832 {expr} is an empty string.
1833
1834 Can also be used as a |method|: >
1835 mylist->count(val)
1836<
1837 *cscope_connection()*
1838cscope_connection([{num} , {dbpath} [, {prepend}]])
1839 Checks for the existence of a |cscope| connection. If no
1840 parameters are specified, then the function returns:
1841 0, if cscope was not available (not compiled in), or
1842 if there are no cscope connections;
1843 1, if there is at least one cscope connection.
1844
1845 If parameters are specified, then the value of {num}
1846 determines how existence of a cscope connection is checked:
1847
1848 {num} Description of existence check
1849 ----- ------------------------------
1850 0 Same as no parameters (e.g., "cscope_connection()").
1851 1 Ignore {prepend}, and use partial string matches for
1852 {dbpath}.
1853 2 Ignore {prepend}, and use exact string matches for
1854 {dbpath}.
1855 3 Use {prepend}, use partial string matches for both
1856 {dbpath} and {prepend}.
1857 4 Use {prepend}, use exact string matches for both
1858 {dbpath} and {prepend}.
1859
1860 Note: All string comparisons are case sensitive!
1861
1862 Examples. Suppose we had the following (from ":cs show"): >
1863
1864 # pid database name prepend path
1865 0 27664 cscope.out /usr/local
1866<
1867 Invocation Return Val ~
1868 ---------- ---------- >
1869 cscope_connection() 1
1870 cscope_connection(1, "out") 1
1871 cscope_connection(2, "out") 0
1872 cscope_connection(3, "out") 0
1873 cscope_connection(3, "out", "local") 1
1874 cscope_connection(4, "out") 0
1875 cscope_connection(4, "out", "local") 0
1876 cscope_connection(4, "cscope.out", "/usr/local") 1
1877<
1878cursor({lnum}, {col} [, {off}]) *cursor()*
1879cursor({list})
1880 Positions the cursor at the column (byte count) {col} in the
1881 line {lnum}. The first column is one.
1882
1883 When there is one argument {list} this is used as a |List|
1884 with two, three or four item:
1885 [{lnum}, {col}]
1886 [{lnum}, {col}, {off}]
1887 [{lnum}, {col}, {off}, {curswant}]
1888 This is like the return value of |getpos()| or |getcurpos()|,
1889 but without the first item.
1890
1891 To position the cursor using the character count, use
1892 |setcursorcharpos()|.
1893
1894 Does not change the jumplist.
Bram Moolenaar7c6cd442022-10-11 21:54:04 +01001895 {lnum} is used like with |getline()|, except that if {lnum} is
1896 zero, the cursor will stay in the current line.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001897 If {lnum} is greater than the number of lines in the buffer,
1898 the cursor will be positioned at the last line in the buffer.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001899 If {col} is greater than the number of bytes in the line,
1900 the cursor will be positioned at the last character in the
1901 line.
1902 If {col} is zero, the cursor will stay in the current column.
1903 If {curswant} is given it is used to set the preferred column
1904 for vertical movement. Otherwise {col} is used.
1905
1906 When 'virtualedit' is used {off} specifies the offset in
1907 screen columns from the start of the character. E.g., a
1908 position within a <Tab> or after the last character.
1909 Returns 0 when the position could be set, -1 otherwise.
1910
1911 Can also be used as a |method|: >
1912 GetCursorPos()->cursor()
1913
1914debugbreak({pid}) *debugbreak()*
1915 Specifically used to interrupt a program being debugged. It
1916 will cause process {pid} to get a SIGTRAP. Behavior for other
1917 processes is undefined. See |terminal-debugger|.
1918 {only available on MS-Windows}
1919
Bram Moolenaar016188f2022-06-06 20:52:59 +01001920 Returns |TRUE| if successfully interrupted the program.
1921 Otherwise returns |FALSE|.
1922
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001923 Can also be used as a |method|: >
1924 GetPid()->debugbreak()
1925
1926deepcopy({expr} [, {noref}]) *deepcopy()* *E698*
1927 Make a copy of {expr}. For Numbers and Strings this isn't
1928 different from using {expr} directly.
1929 When {expr} is a |List| a full copy is created. This means
1930 that the original |List| can be changed without changing the
1931 copy, and vice versa. When an item is a |List| or
1932 |Dictionary|, a copy for it is made, recursively. Thus
1933 changing an item in the copy does not change the contents of
1934 the original |List|.
1935 A |Dictionary| is copied in a similar way as a |List|.
1936
1937 When {noref} is omitted or zero a contained |List| or
1938 |Dictionary| is only copied once. All references point to
1939 this single copy. With {noref} set to 1 every occurrence of a
1940 |List| or |Dictionary| results in a new copy. This also means
1941 that a cyclic reference causes deepcopy() to fail.
1942 *E724*
1943 Nesting is possible up to 100 levels. When there is an item
1944 that refers back to a higher level making a deep copy with
1945 {noref} set to 1 will fail.
1946 Also see |copy()|.
1947
1948 Can also be used as a |method|: >
1949 GetObject()->deepcopy()
1950
1951delete({fname} [, {flags}]) *delete()*
1952 Without {flags} or with {flags} empty: Deletes the file by the
Bram Moolenaarcbaff5e2022-04-08 17:45:08 +01001953 name {fname}.
1954
1955 This also works when {fname} is a symbolic link. The symbolic
1956 link itself is deleted, not what it points to.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001957
1958 When {flags} is "d": Deletes the directory by the name
1959 {fname}. This fails when directory {fname} is not empty.
1960
1961 When {flags} is "rf": Deletes the directory by the name
1962 {fname} and everything in it, recursively. BE CAREFUL!
1963 Note: on MS-Windows it is not possible to delete a directory
1964 that is being used.
1965
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001966 The result is a Number, which is 0/false if the delete
1967 operation was successful and -1/true when the deletion failed
1968 or partly failed.
1969
1970 Use |remove()| to delete an item from a |List|.
1971 To delete a line from the buffer use |:delete| or
1972 |deletebufline()|.
1973
1974 Can also be used as a |method|: >
1975 GetName()->delete()
1976
1977deletebufline({buf}, {first} [, {last}]) *deletebufline()*
1978 Delete lines {first} to {last} (inclusive) from buffer {buf}.
1979 If {last} is omitted then delete line {first} only.
1980 On success 0 is returned, on failure 1 is returned.
1981
1982 This function works only for loaded buffers. First call
1983 |bufload()| if needed.
1984
1985 For the use of {buf}, see |bufname()| above.
1986
1987 {first} and {last} are used like with |getline()|. Note that
1988 when using |line()| this refers to the current buffer. Use "$"
1989 to refer to the last line in buffer {buf}.
1990
1991 Can also be used as a |method|: >
1992 GetBuffer()->deletebufline(1)
1993<
1994 *did_filetype()*
1995did_filetype() Returns |TRUE| when autocommands are being executed and the
1996 FileType event has been triggered at least once. Can be used
1997 to avoid triggering the FileType event again in the scripts
1998 that detect the file type. |FileType|
1999 Returns |FALSE| when `:setf FALLBACK` was used.
2000 When editing another file, the counter is reset, thus this
2001 really checks if the FileType event has been triggered for the
2002 current buffer. This allows an autocommand that starts
2003 editing another buffer to set 'filetype' and load a syntax
2004 file.
2005
2006diff_filler({lnum}) *diff_filler()*
2007 Returns the number of filler lines above line {lnum}.
2008 These are the lines that were inserted at this point in
2009 another diff'ed window. These filler lines are shown in the
2010 display but don't exist in the buffer.
2011 {lnum} is used like with |getline()|. Thus "." is the current
2012 line, "'m" mark m, etc.
2013 Returns 0 if the current window is not in diff mode.
2014
2015 Can also be used as a |method|: >
2016 GetLnum()->diff_filler()
2017
2018diff_hlID({lnum}, {col}) *diff_hlID()*
2019 Returns the highlight ID for diff mode at line {lnum} column
2020 {col} (byte index). When the current line does not have a
2021 diff change zero is returned.
2022 {lnum} is used like with |getline()|. Thus "." is the current
2023 line, "'m" mark m, etc.
2024 {col} is 1 for the leftmost column, {lnum} is 1 for the first
2025 line.
2026 The highlight ID can be used with |synIDattr()| to obtain
2027 syntax information about the highlighting.
2028
2029 Can also be used as a |method|: >
2030 GetLnum()->diff_hlID(col)
2031<
2032
2033digraph_get({chars}) *digraph_get()* *E1214*
2034 Return the digraph of {chars}. This should be a string with
2035 exactly two characters. If {chars} are not just two
2036 characters, or the digraph of {chars} does not exist, an error
2037 is given and an empty string is returned.
2038
2039 The character will be converted from Unicode to 'encoding'
2040 when needed. This does require the conversion to be
2041 available, it might fail.
2042
2043 Also see |digraph_getlist()|.
2044
2045 Examples: >
2046 " Get a built-in digraph
2047 :echo digraph_get('00') " Returns '∞'
2048
2049 " Get a user-defined digraph
2050 :call digraph_set('aa', 'あ')
2051 :echo digraph_get('aa') " Returns 'あ'
2052<
2053 Can also be used as a |method|: >
2054 GetChars()->digraph_get()
2055<
2056 This function works only when compiled with the |+digraphs|
2057 feature. If this feature is disabled, this function will
2058 display an error message.
2059
2060
2061digraph_getlist([{listall}]) *digraph_getlist()*
2062 Return a list of digraphs. If the {listall} argument is given
2063 and it is TRUE, return all digraphs, including the default
2064 digraphs. Otherwise, return only user-defined digraphs.
2065
2066 The characters will be converted from Unicode to 'encoding'
2067 when needed. This does require the conservation to be
2068 available, it might fail.
2069
2070 Also see |digraph_get()|.
2071
2072 Examples: >
2073 " Get user-defined digraphs
2074 :echo digraph_getlist()
2075
2076 " Get all the digraphs, including default digraphs
2077 :echo digraph_getlist(1)
2078<
2079 Can also be used as a |method|: >
2080 GetNumber()->digraph_getlist()
2081<
2082 This function works only when compiled with the |+digraphs|
2083 feature. If this feature is disabled, this function will
2084 display an error message.
2085
2086
Bram Moolenaara2baa732022-02-04 16:09:54 +00002087digraph_set({chars}, {digraph}) *digraph_set()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002088 Add digraph {chars} to the list. {chars} must be a string
2089 with two characters. {digraph} is a string with one UTF-8
Bram Moolenaara2baa732022-02-04 16:09:54 +00002090 encoded character. *E1215*
2091 Be careful, composing characters are NOT ignored. This
2092 function is similar to |:digraphs| command, but useful to add
2093 digraphs start with a white space.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002094
2095 The function result is v:true if |digraph| is registered. If
2096 this fails an error message is given and v:false is returned.
2097
2098 If you want to define multiple digraphs at once, you can use
2099 |digraph_setlist()|.
2100
2101 Example: >
2102 call digraph_set(' ', 'あ')
2103<
2104 Can be used as a |method|: >
2105 GetString()->digraph_set('あ')
2106<
2107 This function works only when compiled with the |+digraphs|
2108 feature. If this feature is disabled, this function will
2109 display an error message.
2110
2111
2112digraph_setlist({digraphlist}) *digraph_setlist()*
2113 Similar to |digraph_set()| but this function can add multiple
2114 digraphs at once. {digraphlist} is a list composed of lists,
2115 where each list contains two strings with {chars} and
Bram Moolenaara2baa732022-02-04 16:09:54 +00002116 {digraph} as in |digraph_set()|. *E1216*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002117 Example: >
2118 call digraph_setlist([['aa', 'あ'], ['ii', 'い']])
2119<
2120 It is similar to the following: >
2121 for [chars, digraph] in [['aa', 'あ'], ['ii', 'い']]
2122 call digraph_set(chars, digraph)
2123 endfor
2124< Except that the function returns after the first error,
2125 following digraphs will not be added.
2126
2127 Can be used as a |method|: >
2128 GetList()->digraph_setlist()
2129<
2130 This function works only when compiled with the |+digraphs|
2131 feature. If this feature is disabled, this function will
2132 display an error message.
2133
2134
2135echoraw({string}) *echoraw()*
2136 Output {string} as-is, including unprintable characters.
2137 This can be used to output a terminal code. For example, to
2138 disable modifyOtherKeys: >
2139 call echoraw(&t_TE)
2140< and to enable it again: >
2141 call echoraw(&t_TI)
2142< Use with care, you can mess up the terminal this way.
2143
2144
2145empty({expr}) *empty()*
2146 Return the Number 1 if {expr} is empty, zero otherwise.
2147 - A |List| or |Dictionary| is empty when it does not have any
2148 items.
2149 - A |String| is empty when its length is zero.
2150 - A |Number| and |Float| are empty when their value is zero.
2151 - |v:false|, |v:none| and |v:null| are empty, |v:true| is not.
2152 - A |Job| is empty when it failed to start.
2153 - A |Channel| is empty when it is closed.
2154 - A |Blob| is empty when its length is zero.
2155
2156 For a long |List| this is much faster than comparing the
2157 length with zero.
2158
2159 Can also be used as a |method|: >
2160 mylist->empty()
2161
2162environ() *environ()*
2163 Return all of environment variables as dictionary. You can
2164 check if an environment variable exists like this: >
2165 :echo has_key(environ(), 'HOME')
2166< Note that the variable name may be CamelCase; to ignore case
2167 use this: >
2168 :echo index(keys(environ()), 'HOME', 0, 1) != -1
2169
2170escape({string}, {chars}) *escape()*
2171 Escape the characters in {chars} that occur in {string} with a
2172 backslash. Example: >
2173 :echo escape('c:\program files\vim', ' \')
2174< results in: >
2175 c:\\program\ files\\vim
2176< Also see |shellescape()| and |fnameescape()|.
2177
2178 Can also be used as a |method|: >
2179 GetText()->escape(' \')
2180<
2181 *eval()*
2182eval({string}) Evaluate {string} and return the result. Especially useful to
2183 turn the result of |string()| back into the original value.
2184 This works for Numbers, Floats, Strings, Blobs and composites
2185 of them. Also works for |Funcref|s that refer to existing
2186 functions.
2187
2188 Can also be used as a |method|: >
2189 argv->join()->eval()
2190
2191eventhandler() *eventhandler()*
2192 Returns 1 when inside an event handler. That is that Vim got
2193 interrupted while waiting for the user to type a character,
2194 e.g., when dropping a file on Vim. This means interactive
2195 commands cannot be used. Otherwise zero is returned.
2196
2197executable({expr}) *executable()*
2198 This function checks if an executable with the name {expr}
2199 exists. {expr} must be the name of the program without any
2200 arguments.
2201 executable() uses the value of $PATH and/or the normal
2202 searchpath for programs. *PATHEXT*
2203 On MS-Windows the ".exe", ".bat", etc. can optionally be
2204 included. Then the extensions in $PATHEXT are tried. Thus if
2205 "foo.exe" does not exist, "foo.exe.bat" can be found. If
2206 $PATHEXT is not set then ".com;.exe;.bat;.cmd" is used. A dot
2207 by itself can be used in $PATHEXT to try using the name
2208 without an extension. When 'shell' looks like a Unix shell,
2209 then the name is also tried without adding an extension.
2210 On MS-Windows it only checks if the file exists and is not a
2211 directory, not if it's really executable.
2212 On MS-Windows an executable in the same directory as Vim is
Yasuhiro Matsumoto05cf63e2022-05-03 11:02:28 +01002213 normally found. Since this directory is added to $PATH it
2214 should also work to execute it |win32-PATH|. This can be
2215 disabled by setting the $NoDefaultCurrentDirectoryInExePath
2216 environment variable. *NoDefaultCurrentDirectoryInExePath*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002217 The result is a Number:
2218 1 exists
2219 0 does not exist
2220 -1 not implemented on this system
2221 |exepath()| can be used to get the full path of an executable.
2222
2223 Can also be used as a |method|: >
2224 GetCommand()->executable()
2225
2226execute({command} [, {silent}]) *execute()*
2227 Execute an Ex command or commands and return the output as a
2228 string.
2229 {command} can be a string or a List. In case of a List the
2230 lines are executed one by one.
2231 This is equivalent to: >
2232 redir => var
2233 {command}
2234 redir END
2235<
2236 The optional {silent} argument can have these values:
2237 "" no `:silent` used
2238 "silent" `:silent` used
2239 "silent!" `:silent!` used
2240 The default is "silent". Note that with "silent!", unlike
2241 `:redir`, error messages are dropped. When using an external
2242 command the screen may be messed up, use `system()` instead.
2243 *E930*
2244 It is not possible to use `:redir` anywhere in {command}.
2245
2246 To get a list of lines use |split()| on the result: >
Bram Moolenaar75ab5902022-04-18 15:36:40 +01002247 execute('args')->split("\n")
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002248
2249< To execute a command in another window than the current one
2250 use `win_execute()`.
2251
2252 When used recursively the output of the recursive call is not
2253 included in the output of the higher level call.
2254
2255 Can also be used as a |method|: >
2256 GetCommand()->execute()
2257
2258exepath({expr}) *exepath()*
2259 If {expr} is an executable and is either an absolute path, a
2260 relative path or found in $PATH, return the full path.
2261 Note that the current directory is used when {expr} starts
2262 with "./", which may be a problem for Vim: >
2263 echo exepath(v:progpath)
2264< If {expr} cannot be found in $PATH or is not executable then
2265 an empty string is returned.
2266
2267 Can also be used as a |method|: >
2268 GetCommand()->exepath()
2269<
2270 *exists()*
2271exists({expr}) The result is a Number, which is |TRUE| if {expr} is defined,
2272 zero otherwise.
2273
2274 Note: In a compiled |:def| function the evaluation is done at
2275 runtime. Use `exists_compiled()` to evaluate the expression
2276 at compile time.
2277
2278 For checking for a supported feature use |has()|.
2279 For checking if a file exists use |filereadable()|.
2280
2281 The {expr} argument is a string, which contains one of these:
Bram Moolenaarf10911e2022-01-29 22:20:48 +00002282 varname internal variable (see
2283 dict.key |internal-variables|). Also works
2284 list[i] for |curly-braces-names|, |Dictionary|
2285 import.Func entries, |List| items, imported
Bram Moolenaar944697a2022-02-20 19:48:20 +00002286 items, etc.
Bram Moolenaarf10911e2022-01-29 22:20:48 +00002287 Does not work for local variables in a
2288 compiled `:def` function.
Bram Moolenaar944697a2022-02-20 19:48:20 +00002289 Also works for a function in |Vim9|
2290 script, since it can be used as a
2291 function reference.
Bram Moolenaarf10911e2022-01-29 22:20:48 +00002292 Beware that evaluating an index may
2293 cause an error message for an invalid
2294 expression. E.g.: >
2295 :let l = [1, 2, 3]
2296 :echo exists("l[5]")
2297< 0 >
2298 :echo exists("l[xx]")
2299< E121: Undefined variable: xx
2300 0
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002301 &option-name Vim option (only checks if it exists,
2302 not if it really works)
2303 +option-name Vim option that works.
2304 $ENVNAME environment variable (could also be
2305 done by comparing with an empty
2306 string)
2307 *funcname built-in function (see |functions|)
2308 or user defined function (see
2309 |user-functions|) that is implemented.
2310 Also works for a variable that is a
2311 Funcref.
2312 ?funcname built-in function that could be
2313 implemented; to be used to check if
2314 "funcname" is valid
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002315 :cmdname Ex command: built-in command, user
2316 command or command modifier |:command|.
2317 Returns:
2318 1 for match with start of a command
2319 2 full match with a command
2320 3 matches several user commands
2321 To check for a supported command
2322 always check the return value to be 2.
2323 :2match The |:2match| command.
Bram Moolenaarb529cfb2022-07-25 15:42:07 +01002324 :3match The |:3match| command (but you
2325 probably should not use it, it is
2326 reserved for internal usage)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002327 #event autocommand defined for this event
2328 #event#pattern autocommand defined for this event and
2329 pattern (the pattern is taken
2330 literally and compared to the
2331 autocommand patterns character by
2332 character)
2333 #group autocommand group exists
2334 #group#event autocommand defined for this group and
2335 event.
2336 #group#event#pattern
2337 autocommand defined for this group,
2338 event and pattern.
2339 ##event autocommand for this event is
2340 supported.
2341
2342 Examples: >
2343 exists("&shortname")
2344 exists("$HOSTNAME")
2345 exists("*strftime")
Bram Moolenaar944697a2022-02-20 19:48:20 +00002346 exists("*s:MyFunc") " only for legacy script
2347 exists("*MyFunc")
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002348 exists("bufcount")
2349 exists(":Make")
2350 exists("#CursorHold")
2351 exists("#BufReadPre#*.gz")
2352 exists("#filetypeindent")
2353 exists("#filetypeindent#FileType")
2354 exists("#filetypeindent#FileType#*")
2355 exists("##ColorScheme")
2356< There must be no space between the symbol (&/$/*/#) and the
2357 name.
2358 There must be no extra characters after the name, although in
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01002359 a few cases this is ignored. That may become stricter in the
2360 future, thus don't count on it!
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002361 Working example: >
2362 exists(":make")
2363< NOT working example: >
2364 exists(":make install")
2365
2366< Note that the argument must be a string, not the name of the
2367 variable itself. For example: >
2368 exists(bufcount)
2369< This doesn't check for existence of the "bufcount" variable,
2370 but gets the value of "bufcount", and checks if that exists.
2371
2372 Can also be used as a |method|: >
2373 Varname()->exists()
2374<
2375
2376exists_compiled({expr}) *exists_compiled()*
2377 Like `exists()` but evaluated at compile time. This is useful
2378 to skip a block where a function is used that would otherwise
2379 give an error: >
2380 if exists_compiled('*ThatFunction')
2381 ThatFunction('works')
2382 endif
2383< If `exists()` were used then a compilation error would be
2384 given if ThatFunction() is not defined.
2385
2386 {expr} must be a literal string. *E1232*
2387 Can only be used in a |:def| function. *E1233*
2388 This does not work to check for arguments or local variables.
2389
2390
2391exp({expr}) *exp()*
2392 Return the exponential of {expr} as a |Float| in the range
2393 [0, inf].
2394 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar016188f2022-06-06 20:52:59 +01002395 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002396 Examples: >
2397 :echo exp(2)
2398< 7.389056 >
2399 :echo exp(-1)
2400< 0.367879
2401
2402 Can also be used as a |method|: >
2403 Compute()->exp()
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002404
2405
2406expand({string} [, {nosuf} [, {list}]]) *expand()*
2407 Expand wildcards and the following special keywords in
2408 {string}. 'wildignorecase' applies.
2409
2410 If {list} is given and it is |TRUE|, a List will be returned.
2411 Otherwise the result is a String and when there are several
2412 matches, they are separated by <NL> characters. [Note: in
2413 version 5.0 a space was used, which caused problems when a
2414 file name contains a space]
2415
2416 If the expansion fails, the result is an empty string. A name
2417 for a non-existing file is not included, unless {string} does
2418 not start with '%', '#' or '<', see below.
2419
2420 When {string} starts with '%', '#' or '<', the expansion is
2421 done like for the |cmdline-special| variables with their
2422 associated modifiers. Here is a short overview:
2423
2424 % current file name
2425 # alternate file name
2426 #n alternate file name n
2427 <cfile> file name under the cursor
2428 <afile> autocmd file name
2429 <abuf> autocmd buffer number (as a String!)
2430 <amatch> autocmd matched name
2431 <cexpr> C expression under the cursor
2432 <sfile> sourced script file or function name
2433 <slnum> sourced script line number or function
2434 line number
2435 <sflnum> script file line number, also when in
2436 a function
2437 <SID> "<SNR>123_" where "123" is the
2438 current script ID |<SID>|
Bram Moolenaar75ab5902022-04-18 15:36:40 +01002439 <script> sourced script file, or script file
2440 where the current function was defined
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002441 <stack> call stack
2442 <cword> word under the cursor
2443 <cWORD> WORD under the cursor
2444 <client> the {clientid} of the last received
2445 message |server2client()|
2446 Modifiers:
2447 :p expand to full path
2448 :h head (last path component removed)
2449 :t tail (last path component only)
2450 :r root (one extension removed)
2451 :e extension only
2452
2453 Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00002454 :let &tags = expand("%:p:h") .. "/tags"
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002455< Note that when expanding a string that starts with '%', '#' or
2456 '<', any following text is ignored. This does NOT work: >
2457 :let doesntwork = expand("%:h.bak")
2458< Use this: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00002459 :let doeswork = expand("%:h") .. ".bak"
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002460< Also note that expanding "<cfile>" and others only returns the
2461 referenced file name without further expansion. If "<cfile>"
2462 is "~/.cshrc", you need to do another expand() to have the
2463 "~/" expanded into the path of the home directory: >
2464 :echo expand(expand("<cfile>"))
2465<
2466 There cannot be white space between the variables and the
2467 following modifier. The |fnamemodify()| function can be used
2468 to modify normal file names.
2469
2470 When using '%' or '#', and the current or alternate file name
2471 is not defined, an empty string is used. Using "%:p" in a
2472 buffer with no name, results in the current directory, with a
2473 '/' added.
Bram Moolenaar57544522022-04-12 12:54:11 +01002474 When 'verbose' is set then expanding '%', '#' and <> items
2475 will result in an error message if the argument cannot be
2476 expanded.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002477
2478 When {string} does not start with '%', '#' or '<', it is
2479 expanded like a file name is expanded on the command line.
2480 'suffixes' and 'wildignore' are used, unless the optional
2481 {nosuf} argument is given and it is |TRUE|.
2482 Names for non-existing files are included. The "**" item can
2483 be used to search in a directory tree. For example, to find
2484 all "README" files in the current directory and below: >
2485 :echo expand("**/README")
2486<
2487 expand() can also be used to expand variables and environment
2488 variables that are only known in a shell. But this can be
2489 slow, because a shell may be used to do the expansion. See
2490 |expr-env-expand|.
2491 The expanded variable is still handled like a list of file
2492 names. When an environment variable cannot be expanded, it is
2493 left unchanged. Thus ":echo expand('$FOOBAR')" results in
2494 "$FOOBAR".
2495
2496 See |glob()| for finding existing files. See |system()| for
2497 getting the raw output of an external command.
2498
2499 Can also be used as a |method|: >
2500 Getpattern()->expand()
2501
Yegappan Lakshmanan2b74b682022-04-03 21:30:32 +01002502expandcmd({string} [, {options}]) *expandcmd()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002503 Expand special items in String {string} like what is done for
2504 an Ex command such as `:edit`. This expands special keywords,
2505 like with |expand()|, and environment variables, anywhere in
2506 {string}. "~user" and "~/path" are only expanded at the
2507 start.
Yegappan Lakshmanan2b74b682022-04-03 21:30:32 +01002508
2509 The following items are supported in the {options} Dict
2510 argument:
2511 errmsg If set to TRUE, error messages are displayed
2512 if an error is encountered during expansion.
2513 By default, error messages are not displayed.
2514
Yegappan Lakshmanan5018a832022-04-02 21:12:21 +01002515 Returns the expanded string. If an error is encountered
2516 during expansion, the unmodified {string} is returned.
Yegappan Lakshmanan2b74b682022-04-03 21:30:32 +01002517
Yegappan Lakshmanan5018a832022-04-02 21:12:21 +01002518 Example: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002519 :echo expandcmd('make %<.o')
Yegappan Lakshmanan2b74b682022-04-03 21:30:32 +01002520 make /path/runtime/doc/builtin.o
2521 :echo expandcmd('make %<.o', {'errmsg': v:true})
2522<
Yegappan Lakshmanan5018a832022-04-02 21:12:21 +01002523 Can also be used as a |method|: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002524 GetCommand()->expandcmd()
2525<
2526extend({expr1}, {expr2} [, {expr3}]) *extend()*
2527 {expr1} and {expr2} must be both |Lists| or both
2528 |Dictionaries|.
2529
2530 If they are |Lists|: Append {expr2} to {expr1}.
2531 If {expr3} is given insert the items of {expr2} before the
2532 item with index {expr3} in {expr1}. When {expr3} is zero
2533 insert before the first item. When {expr3} is equal to
2534 len({expr1}) then {expr2} is appended.
2535 Examples: >
2536 :echo sort(extend(mylist, [7, 5]))
2537 :call extend(mylist, [2, 3], 1)
2538< When {expr1} is the same List as {expr2} then the number of
2539 items copied is equal to the original length of the List.
2540 E.g., when {expr3} is 1 you get N new copies of the first item
2541 (where N is the original length of the List).
2542 Use |add()| to concatenate one item to a list. To concatenate
2543 two lists into a new list use the + operator: >
2544 :let newlist = [1, 2, 3] + [4, 5]
2545<
2546 If they are |Dictionaries|:
2547 Add all entries from {expr2} to {expr1}.
2548 If a key exists in both {expr1} and {expr2} then {expr3} is
2549 used to decide what to do:
2550 {expr3} = "keep": keep the value of {expr1}
2551 {expr3} = "force": use the value of {expr2}
2552 {expr3} = "error": give an error message *E737*
2553 When {expr3} is omitted then "force" is assumed.
2554
2555 {expr1} is changed when {expr2} is not empty. If necessary
2556 make a copy of {expr1} first.
2557 {expr2} remains unchanged.
2558 When {expr1} is locked and {expr2} is not empty the operation
2559 fails.
Bram Moolenaar016188f2022-06-06 20:52:59 +01002560 Returns {expr1}. Returns 0 on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002561
2562 Can also be used as a |method|: >
2563 mylist->extend(otherlist)
2564
2565
2566extendnew({expr1}, {expr2} [, {expr3}]) *extendnew()*
2567 Like |extend()| but instead of adding items to {expr1} a new
2568 List or Dictionary is created and returned. {expr1} remains
2569 unchanged. Items can still be changed by {expr2}, if you
2570 don't want that use |deepcopy()| first.
2571
2572
2573feedkeys({string} [, {mode}]) *feedkeys()*
2574 Characters in {string} are queued for processing as if they
2575 come from a mapping or were typed by the user.
2576
2577 By default the string is added to the end of the typeahead
2578 buffer, thus if a mapping is still being executed the
2579 characters come after them. Use the 'i' flag to insert before
2580 other characters, they will be executed next, before any
2581 characters from a mapping.
2582
2583 The function does not wait for processing of keys contained in
2584 {string}.
2585
2586 To include special keys into {string}, use double-quotes
2587 and "\..." notation |expr-quote|. For example,
2588 feedkeys("\<CR>") simulates pressing of the <Enter> key. But
2589 feedkeys('\<CR>') pushes 5 characters.
2590 A special code that might be useful is <Ignore>, it exits the
2591 wait for a character without doing anything. *<Ignore>*
2592
2593 {mode} is a String, which can contain these character flags:
2594 'm' Remap keys. This is default. If {mode} is absent,
2595 keys are remapped.
2596 'n' Do not remap keys.
2597 't' Handle keys as if typed; otherwise they are handled as
2598 if coming from a mapping. This matters for undo,
2599 opening folds, etc.
2600 'L' Lowlevel input. Only works for Unix or when using the
2601 GUI. Keys are used as if they were coming from the
2602 terminal. Other flags are not used. *E980*
2603 When a CTRL-C interrupts and 't' is included it sets
2604 the internal "got_int" flag.
2605 'i' Insert the string instead of appending (see above).
2606 'x' Execute commands until typeahead is empty. This is
2607 similar to using ":normal!". You can call feedkeys()
2608 several times without 'x' and then one time with 'x'
2609 (possibly with an empty {string}) to execute all the
2610 typeahead. Note that when Vim ends in Insert mode it
2611 will behave as if <Esc> is typed, to avoid getting
2612 stuck, waiting for a character to be typed before the
2613 script continues.
2614 Note that if you manage to call feedkeys() while
2615 executing commands, thus calling it recursively, then
2616 all typeahead will be consumed by the last call.
Bram Moolenaara9725222022-01-16 13:30:33 +00002617 'c' Remove any script context when executing, so that
2618 legacy script syntax applies, "s:var" does not work,
Bram Moolenaard899e512022-05-07 21:54:03 +01002619 etc. Note that if the string being fed sets a script
Bram Moolenaarce001a32022-04-27 15:25:03 +01002620 context this still applies.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002621 '!' When used with 'x' will not end Insert mode. Can be
2622 used in a test when a timer is set to exit Insert mode
2623 a little later. Useful for testing CursorHoldI.
2624
2625 Return value is always 0.
2626
2627 Can also be used as a |method|: >
2628 GetInput()->feedkeys()
2629
2630filereadable({file}) *filereadable()*
2631 The result is a Number, which is |TRUE| when a file with the
2632 name {file} exists, and can be read. If {file} doesn't exist,
2633 or is a directory, the result is |FALSE|. {file} is any
2634 expression, which is used as a String.
2635 If you don't care about the file being readable you can use
2636 |glob()|.
2637 {file} is used as-is, you may want to expand wildcards first: >
2638 echo filereadable('~/.vimrc')
2639 0
2640 echo filereadable(expand('~/.vimrc'))
2641 1
2642
2643< Can also be used as a |method|: >
2644 GetName()->filereadable()
2645< *file_readable()*
2646 Obsolete name: file_readable().
2647
2648
2649filewritable({file}) *filewritable()*
2650 The result is a Number, which is 1 when a file with the
2651 name {file} exists, and can be written. If {file} doesn't
2652 exist, or is not writable, the result is 0. If {file} is a
2653 directory, and we can write to it, the result is 2.
2654
2655 Can also be used as a |method|: >
2656 GetName()->filewritable()
2657
2658
2659filter({expr1}, {expr2}) *filter()*
2660 {expr1} must be a |List|, |String|, |Blob| or |Dictionary|.
2661 For each item in {expr1} evaluate {expr2} and when the result
2662 is zero or false remove the item from the |List| or
2663 |Dictionary|. Similarly for each byte in a |Blob| and each
Bram Moolenaar2f0936c2022-01-08 21:51:59 +00002664 character in a |String|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002665
2666 {expr2} must be a |string| or |Funcref|.
2667
2668 If {expr2} is a |string|, inside {expr2} |v:val| has the value
2669 of the current item. For a |Dictionary| |v:key| has the key
2670 of the current item and for a |List| |v:key| has the index of
2671 the current item. For a |Blob| |v:key| has the index of the
2672 current byte. For a |String| |v:key| has the index of the
2673 current character.
2674 Examples: >
2675 call filter(mylist, 'v:val !~ "OLD"')
2676< Removes the items where "OLD" appears. >
2677 call filter(mydict, 'v:key >= 8')
2678< Removes the items with a key below 8. >
2679 call filter(var, 0)
2680< Removes all the items, thus clears the |List| or |Dictionary|.
2681
2682 Note that {expr2} is the result of expression and is then
2683 used as an expression again. Often it is good to use a
2684 |literal-string| to avoid having to double backslashes.
2685
2686 If {expr2} is a |Funcref| it must take two arguments:
2687 1. the key or the index of the current item.
2688 2. the value of the current item.
2689 The function must return |TRUE| if the item should be kept.
2690 Example that keeps the odd items of a list: >
2691 func Odd(idx, val)
2692 return a:idx % 2 == 1
2693 endfunc
2694 call filter(mylist, function('Odd'))
Bram Moolenaar2f0936c2022-01-08 21:51:59 +00002695< It is shorter when using a |lambda|. In |Vim9| syntax: >
2696 call filter(myList, (idx, val) => idx * val <= 42)
2697< In legacy script syntax: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002698 call filter(myList, {idx, val -> idx * val <= 42})
2699< If you do not use "val" you can leave it out: >
2700 call filter(myList, {idx -> idx % 2 == 1})
2701<
2702 In |Vim9| script the result must be true, false, zero or one.
2703 Other values will result in a type error.
2704
2705 For a |List| and a |Dictionary| the operation is done
2706 in-place. If you want it to remain unmodified make a copy
2707 first: >
2708 :let l = filter(copy(mylist), 'v:val =~ "KEEP"')
2709
2710< Returns {expr1}, the |List| or |Dictionary| that was filtered,
naohiro ono56200ee2022-01-01 14:59:44 +00002711 or a new |Blob| or |String|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002712 When an error is encountered while evaluating {expr2} no
2713 further items in {expr1} are processed.
2714 When {expr2} is a Funcref errors inside a function are ignored,
2715 unless it was defined with the "abort" flag.
2716
2717 Can also be used as a |method|: >
2718 mylist->filter(expr2)
2719
2720finddir({name} [, {path} [, {count}]]) *finddir()*
2721 Find directory {name} in {path}. Supports both downwards and
2722 upwards recursive directory searches. See |file-searching|
2723 for the syntax of {path}.
2724
2725 Returns the path of the first found match. When the found
2726 directory is below the current directory a relative path is
2727 returned. Otherwise a full path is returned.
2728 If {path} is omitted or empty then 'path' is used.
2729
2730 If the optional {count} is given, find {count}'s occurrence of
2731 {name} in {path} instead of the first one.
2732 When {count} is negative return all the matches in a |List|.
2733
Bram Moolenaar016188f2022-06-06 20:52:59 +01002734 Returns an empty string if the directory is not found.
2735
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002736 This is quite similar to the ex-command `:find`.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002737
2738 Can also be used as a |method|: >
2739 GetName()->finddir()
2740
2741findfile({name} [, {path} [, {count}]]) *findfile()*
2742 Just like |finddir()|, but find a file instead of a directory.
2743 Uses 'suffixesadd'.
2744 Example: >
2745 :echo findfile("tags.vim", ".;")
2746< Searches from the directory of the current file upwards until
2747 it finds the file "tags.vim".
2748
2749 Can also be used as a |method|: >
2750 GetName()->findfile()
2751
2752flatten({list} [, {maxdepth}]) *flatten()*
2753 Flatten {list} up to {maxdepth} levels. Without {maxdepth}
2754 the result is a |List| without nesting, as if {maxdepth} is
2755 a very large number.
2756 The {list} is changed in place, use |flattennew()| if you do
2757 not want that.
2758 In Vim9 script flatten() cannot be used, you must always use
Bram Moolenaara2baa732022-02-04 16:09:54 +00002759 |flattennew()|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002760 *E900*
2761 {maxdepth} means how deep in nested lists changes are made.
2762 {list} is not modified when {maxdepth} is 0.
2763 {maxdepth} must be positive number.
2764
2765 If there is an error the number zero is returned.
2766
2767 Example: >
2768 :echo flatten([1, [2, [3, 4]], 5])
2769< [1, 2, 3, 4, 5] >
2770 :echo flatten([1, [2, [3, 4]], 5], 1)
2771< [1, 2, [3, 4], 5]
2772
2773 Can also be used as a |method|: >
2774 mylist->flatten()
2775<
2776flattennew({list} [, {maxdepth}]) *flattennew()*
2777 Like |flatten()| but first make a copy of {list}.
2778
2779
2780float2nr({expr}) *float2nr()*
2781 Convert {expr} to a Number by omitting the part after the
2782 decimal point.
Bram Moolenaar76db9e02022-11-09 21:21:04 +00002783 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar016188f2022-06-06 20:52:59 +01002784 Returns 0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002785 When the value of {expr} is out of range for a |Number| the
2786 result is truncated to 0x7fffffff or -0x7fffffff (or when
2787 64-bit Number support is enabled, 0x7fffffffffffffff or
2788 -0x7fffffffffffffff). NaN results in -0x80000000 (or when
2789 64-bit Number support is enabled, -0x8000000000000000).
2790 Examples: >
2791 echo float2nr(3.95)
2792< 3 >
2793 echo float2nr(-23.45)
2794< -23 >
2795 echo float2nr(1.0e100)
2796< 2147483647 (or 9223372036854775807) >
2797 echo float2nr(-1.0e150)
2798< -2147483647 (or -9223372036854775807) >
2799 echo float2nr(1.0e-100)
2800< 0
2801
2802 Can also be used as a |method|: >
2803 Compute()->float2nr()
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002804
2805
2806floor({expr}) *floor()*
2807 Return the largest integral value less than or equal to
2808 {expr} as a |Float| (round down).
2809 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar016188f2022-06-06 20:52:59 +01002810 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002811 Examples: >
2812 echo floor(1.856)
2813< 1.0 >
2814 echo floor(-5.456)
2815< -6.0 >
2816 echo floor(4.0)
2817< 4.0
2818
2819 Can also be used as a |method|: >
2820 Compute()->floor()
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002821
2822
2823fmod({expr1}, {expr2}) *fmod()*
2824 Return the remainder of {expr1} / {expr2}, even if the
2825 division is not representable. Returns {expr1} - i * {expr2}
2826 for some integer i such that if {expr2} is non-zero, the
2827 result has the same sign as {expr1} and magnitude less than
2828 the magnitude of {expr2}. If {expr2} is zero, the value
2829 returned is zero. The value returned is a |Float|.
2830 {expr1} and {expr2} must evaluate to a |Float| or a |Number|.
Bram Moolenaar016188f2022-06-06 20:52:59 +01002831 Returns 0.0 if {expr1} or {expr2} is not a |Float| or a
2832 |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002833 Examples: >
2834 :echo fmod(12.33, 1.22)
2835< 0.13 >
2836 :echo fmod(-12.33, 1.22)
2837< -0.13
2838
2839 Can also be used as a |method|: >
2840 Compute()->fmod(1.22)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002841
2842
2843fnameescape({string}) *fnameescape()*
2844 Escape {string} for use as file name command argument. All
2845 characters that have a special meaning, such as '%' and '|'
2846 are escaped with a backslash.
2847 For most systems the characters escaped are
2848 " \t\n*?[{`$\\%#'\"|!<". For systems where a backslash
2849 appears in a filename, it depends on the value of 'isfname'.
2850 A leading '+' and '>' is also escaped (special after |:edit|
2851 and |:write|). And a "-" by itself (special after |:cd|).
Bram Moolenaar016188f2022-06-06 20:52:59 +01002852 Returns an empty string on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002853 Example: >
2854 :let fname = '+some str%nge|name'
Bram Moolenaarc51cf032022-02-26 12:25:45 +00002855 :exe "edit " .. fnameescape(fname)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002856< results in executing: >
2857 edit \+some\ str\%nge\|name
2858<
2859 Can also be used as a |method|: >
2860 GetName()->fnameescape()
2861
2862fnamemodify({fname}, {mods}) *fnamemodify()*
2863 Modify file name {fname} according to {mods}. {mods} is a
2864 string of characters like it is used for file names on the
2865 command line. See |filename-modifiers|.
2866 Example: >
2867 :echo fnamemodify("main.c", ":p:h")
2868< results in: >
Bram Moolenaard799daa2022-06-20 11:17:32 +01002869 /home/user/vim/vim/src
Bram Moolenaar016188f2022-06-06 20:52:59 +01002870< If {mods} is empty or an unsupported modifier is used then
2871 {fname} is returned.
Bram Moolenaar5ed11532022-07-06 13:18:11 +01002872 When {fname} is empty then with {mods} ":h" returns ".", so
2873 that `:cd` can be used with it. This is different from
2874 expand('%:h') without a buffer name, which returns an empty
2875 string.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002876 Note: Environment variables don't work in {fname}, use
2877 |expand()| first then.
2878
2879 Can also be used as a |method|: >
2880 GetName()->fnamemodify(':p:h')
2881
2882foldclosed({lnum}) *foldclosed()*
2883 The result is a Number. If the line {lnum} is in a closed
2884 fold, the result is the number of the first line in that fold.
2885 If the line {lnum} is not in a closed fold, -1 is returned.
2886 {lnum} is used like with |getline()|. Thus "." is the current
2887 line, "'m" mark m, etc.
2888
2889 Can also be used as a |method|: >
2890 GetLnum()->foldclosed()
2891
2892foldclosedend({lnum}) *foldclosedend()*
2893 The result is a Number. If the line {lnum} is in a closed
2894 fold, the result is the number of the last line in that fold.
2895 If the line {lnum} is not in a closed fold, -1 is returned.
2896 {lnum} is used like with |getline()|. Thus "." is the current
2897 line, "'m" mark m, etc.
2898
2899 Can also be used as a |method|: >
2900 GetLnum()->foldclosedend()
2901
2902foldlevel({lnum}) *foldlevel()*
2903 The result is a Number, which is the foldlevel of line {lnum}
2904 in the current buffer. For nested folds the deepest level is
2905 returned. If there is no fold at line {lnum}, zero is
2906 returned. It doesn't matter if the folds are open or closed.
2907 When used while updating folds (from 'foldexpr') -1 is
2908 returned for lines where folds are still to be updated and the
2909 foldlevel is unknown. As a special case the level of the
2910 previous line is usually available.
2911 {lnum} is used like with |getline()|. Thus "." is the current
2912 line, "'m" mark m, etc.
2913
2914 Can also be used as a |method|: >
2915 GetLnum()->foldlevel()
2916<
2917 *foldtext()*
2918foldtext() Returns a String, to be displayed for a closed fold. This is
2919 the default function used for the 'foldtext' option and should
2920 only be called from evaluating 'foldtext'. It uses the
2921 |v:foldstart|, |v:foldend| and |v:folddashes| variables.
2922 The returned string looks like this: >
2923 +-- 45 lines: abcdef
2924< The number of leading dashes depends on the foldlevel. The
2925 "45" is the number of lines in the fold. "abcdef" is the text
2926 in the first non-blank line of the fold. Leading white space,
2927 "//" or "/*" and the text from the 'foldmarker' and
2928 'commentstring' options is removed.
2929 When used to draw the actual foldtext, the rest of the line
2930 will be filled with the fold char from the 'fillchars'
2931 setting.
Bram Moolenaar016188f2022-06-06 20:52:59 +01002932 Returns an empty string when there is no fold.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002933 {not available when compiled without the |+folding| feature}
2934
2935foldtextresult({lnum}) *foldtextresult()*
2936 Returns the text that is displayed for the closed fold at line
2937 {lnum}. Evaluates 'foldtext' in the appropriate context.
2938 When there is no closed fold at {lnum} an empty string is
2939 returned.
2940 {lnum} is used like with |getline()|. Thus "." is the current
2941 line, "'m" mark m, etc.
2942 Useful when exporting folded text, e.g., to HTML.
2943 {not available when compiled without the |+folding| feature}
2944
2945
2946 Can also be used as a |method|: >
2947 GetLnum()->foldtextresult()
2948<
2949 *foreground()*
2950foreground() Move the Vim window to the foreground. Useful when sent from
2951 a client to a Vim server. |remote_send()|
2952 On Win32 systems this might not work, the OS does not always
2953 allow a window to bring itself to the foreground. Use
2954 |remote_foreground()| instead.
Bram Moolenaarcbaff5e2022-04-08 17:45:08 +01002955 {only in the Win32, Motif and GTK GUI versions and the
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002956 Win32 console version}
2957
Bram Moolenaaraa534142022-09-15 21:46:02 +01002958fullcommand({name} [, {vim9}]) *fullcommand()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002959 Get the full command name from a short abbreviated command
2960 name; see |20.2| for details on command abbreviations.
2961
2962 The string argument {name} may start with a `:` and can
2963 include a [range], these are skipped and not returned.
Bram Moolenaaraa534142022-09-15 21:46:02 +01002964 Returns an empty string if a command doesn't exist, if it's
2965 ambiguous (for user-defined commands) or cannot be shortened
2966 this way. |vim9-no-shorten|
2967
2968 Without the {vim9} argument uses the current script version.
2969 If {vim9} is present and FALSE then legacy script rules are
2970 used. When {vim9} is present and TRUE then Vim9 rules are
2971 used, e.g. "en" is not a short form of "endif".
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002972
2973 For example `fullcommand('s')`, `fullcommand('sub')`,
2974 `fullcommand(':%substitute')` all return "substitute".
2975
2976 Can also be used as a |method|: >
2977 GetName()->fullcommand()
2978<
2979 *funcref()*
2980funcref({name} [, {arglist}] [, {dict}])
2981 Just like |function()|, but the returned Funcref will lookup
2982 the function by reference, not by name. This matters when the
2983 function {name} is redefined later.
2984
2985 Unlike |function()|, {name} must be an existing user function.
Bram Moolenaar2f0936c2022-01-08 21:51:59 +00002986 It only works for an autoloaded function if it has already
2987 been loaded (to avoid mistakenly loading the autoload script
2988 when only intending to use the function name, use |function()|
2989 instead). {name} cannot be a builtin function.
Bram Moolenaar016188f2022-06-06 20:52:59 +01002990 Returns 0 on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002991
2992 Can also be used as a |method|: >
2993 GetFuncname()->funcref([arg])
2994<
2995 *function()* *partial* *E700* *E922* *E923*
2996function({name} [, {arglist}] [, {dict}])
2997 Return a |Funcref| variable that refers to function {name}.
2998 {name} can be the name of a user defined function or an
2999 internal function.
3000
3001 {name} can also be a Funcref or a partial. When it is a
3002 partial the dict stored in it will be used and the {dict}
3003 argument is not allowed. E.g.: >
3004 let FuncWithArg = function(dict.Func, [arg])
3005 let Broken = function(dict.Func, [arg], dict)
3006<
3007 When using the Funcref the function will be found by {name},
3008 also when it was redefined later. Use |funcref()| to keep the
3009 same function.
3010
3011 When {arglist} or {dict} is present this creates a partial.
3012 That means the argument list and/or the dictionary is stored in
3013 the Funcref and will be used when the Funcref is called.
3014
3015 The arguments are passed to the function in front of other
3016 arguments, but after any argument from |method|. Example: >
3017 func Callback(arg1, arg2, name)
3018 ...
3019 let Partial = function('Callback', ['one', 'two'])
3020 ...
3021 call Partial('name')
3022< Invokes the function as with: >
3023 call Callback('one', 'two', 'name')
3024
3025< With a |method|: >
3026 func Callback(one, two, three)
3027 ...
3028 let Partial = function('Callback', ['two'])
3029 ...
3030 eval 'one'->Partial('three')
3031< Invokes the function as with: >
3032 call Callback('one', 'two', 'three')
3033
3034< The function() call can be nested to add more arguments to the
3035 Funcref. The extra arguments are appended to the list of
3036 arguments. Example: >
3037 func Callback(arg1, arg2, name)
Bram Moolenaar0daafaa2022-09-04 17:45:43 +01003038 "...
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003039 let Func = function('Callback', ['one'])
3040 let Func2 = function(Func, ['two'])
Bram Moolenaar0daafaa2022-09-04 17:45:43 +01003041 "...
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003042 call Func2('name')
3043< Invokes the function as with: >
3044 call Callback('one', 'two', 'name')
3045
3046< The Dictionary is only useful when calling a "dict" function.
3047 In that case the {dict} is passed in as "self". Example: >
3048 function Callback() dict
Bram Moolenaarc51cf032022-02-26 12:25:45 +00003049 echo "called for " .. self.name
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003050 endfunction
Bram Moolenaar0daafaa2022-09-04 17:45:43 +01003051 "...
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003052 let context = {"name": "example"}
3053 let Func = function('Callback', context)
Bram Moolenaar0daafaa2022-09-04 17:45:43 +01003054 "...
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003055 call Func() " will echo: called for example
3056< The use of function() is not needed when there are no extra
Bram Moolenaar0daafaa2022-09-04 17:45:43 +01003057 arguments, these two are equivalent, if Callback() is defined
3058 as context.Callback(): >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003059 let Func = function('Callback', context)
3060 let Func = context.Callback
3061
3062< The argument list and the Dictionary can be combined: >
3063 function Callback(arg1, count) dict
Bram Moolenaar0daafaa2022-09-04 17:45:43 +01003064 "...
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003065 let context = {"name": "example"}
3066 let Func = function('Callback', ['one'], context)
Bram Moolenaar0daafaa2022-09-04 17:45:43 +01003067 "...
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003068 call Func(500)
3069< Invokes the function as with: >
3070 call context.Callback('one', 500)
3071<
Bram Moolenaar016188f2022-06-06 20:52:59 +01003072 Returns 0 on error.
3073
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003074 Can also be used as a |method|: >
3075 GetFuncname()->function([arg])
3076
3077
3078garbagecollect([{atexit}]) *garbagecollect()*
3079 Cleanup unused |Lists|, |Dictionaries|, |Channels| and |Jobs|
3080 that have circular references.
3081
3082 There is hardly ever a need to invoke this function, as it is
3083 automatically done when Vim runs out of memory or is waiting
3084 for the user to press a key after 'updatetime'. Items without
3085 circular references are always freed when they become unused.
3086 This is useful if you have deleted a very big |List| and/or
3087 |Dictionary| with circular references in a script that runs
3088 for a long time.
3089
3090 When the optional {atexit} argument is one, garbage
3091 collection will also be done when exiting Vim, if it wasn't
3092 done before. This is useful when checking for memory leaks.
3093
3094 The garbage collection is not done immediately but only when
3095 it's safe to perform. This is when waiting for the user to
3096 type a character. To force garbage collection immediately use
3097 |test_garbagecollect_now()|.
3098
3099get({list}, {idx} [, {default}]) *get()*
3100 Get item {idx} from |List| {list}. When this item is not
3101 available return {default}. Return zero when {default} is
3102 omitted.
3103 Preferably used as a |method|: >
3104 mylist->get(idx)
3105get({blob}, {idx} [, {default}])
3106 Get byte {idx} from |Blob| {blob}. When this byte is not
3107 available return {default}. Return -1 when {default} is
3108 omitted.
3109 Preferably used as a |method|: >
3110 myblob->get(idx)
3111get({dict}, {key} [, {default}])
3112 Get item with key {key} from |Dictionary| {dict}. When this
3113 item is not available return {default}. Return zero when
3114 {default} is omitted. Useful example: >
3115 let val = get(g:, 'var_name', 'default')
3116< This gets the value of g:var_name if it exists, and uses
3117 'default' when it does not exist.
3118 Preferably used as a |method|: >
3119 mydict->get(key)
3120get({func}, {what})
Bram Moolenaar6f4754b2022-01-23 12:07:04 +00003121 Get item {what} from Funcref {func}. Possible values for
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003122 {what} are:
3123 "name" The function name
3124 "func" The function
3125 "dict" The dictionary
3126 "args" The list with arguments
Bram Moolenaar016188f2022-06-06 20:52:59 +01003127 Returns zero on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003128 Preferably used as a |method|: >
3129 myfunc->get(what)
3130<
3131 *getbufinfo()*
3132getbufinfo([{buf}])
3133getbufinfo([{dict}])
3134 Get information about buffers as a List of Dictionaries.
3135
3136 Without an argument information about all the buffers is
3137 returned.
3138
3139 When the argument is a |Dictionary| only the buffers matching
3140 the specified criteria are returned. The following keys can
3141 be specified in {dict}:
3142 buflisted include only listed buffers.
3143 bufloaded include only loaded buffers.
3144 bufmodified include only modified buffers.
3145
3146 Otherwise, {buf} specifies a particular buffer to return
3147 information for. For the use of {buf}, see |bufname()|
3148 above. If the buffer is found the returned List has one item.
3149 Otherwise the result is an empty list.
3150
3151 Each returned List item is a dictionary with the following
3152 entries:
3153 bufnr Buffer number.
3154 changed TRUE if the buffer is modified.
3155 changedtick Number of changes made to the buffer.
3156 hidden TRUE if the buffer is hidden.
3157 lastused Timestamp in seconds, like
3158 |localtime()|, when the buffer was
3159 last used.
3160 {only with the |+viminfo| feature}
3161 listed TRUE if the buffer is listed.
3162 lnum Line number used for the buffer when
3163 opened in the current window.
3164 Only valid if the buffer has been
3165 displayed in the window in the past.
3166 If you want the line number of the
3167 last known cursor position in a given
3168 window, use |line()|: >
3169 :echo line('.', {winid})
3170<
3171 linecount Number of lines in the buffer (only
3172 valid when loaded)
3173 loaded TRUE if the buffer is loaded.
3174 name Full path to the file in the buffer.
3175 signs List of signs placed in the buffer.
3176 Each list item is a dictionary with
3177 the following fields:
3178 id sign identifier
3179 lnum line number
3180 name sign name
3181 variables A reference to the dictionary with
3182 buffer-local variables.
3183 windows List of |window-ID|s that display this
3184 buffer
3185 popups List of popup |window-ID|s that
3186 display this buffer
3187
3188 Examples: >
3189 for buf in getbufinfo()
3190 echo buf.name
3191 endfor
3192 for buf in getbufinfo({'buflisted':1})
3193 if buf.changed
3194 ....
3195 endif
3196 endfor
3197<
3198 To get buffer-local options use: >
3199 getbufvar({bufnr}, '&option_name')
3200<
3201 Can also be used as a |method|: >
3202 GetBufnr()->getbufinfo()
3203<
3204
3205 *getbufline()*
3206getbufline({buf}, {lnum} [, {end}])
3207 Return a |List| with the lines starting from {lnum} to {end}
3208 (inclusive) in the buffer {buf}. If {end} is omitted, a
Bram Moolenaarce30ccc2022-11-21 19:57:04 +00003209 |List| with only the line {lnum} is returned. See
3210 `getbufoneline()` for only getting the line.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003211
3212 For the use of {buf}, see |bufname()| above.
3213
3214 For {lnum} and {end} "$" can be used for the last line of the
3215 buffer. Otherwise a number must be used.
3216
3217 When {lnum} is smaller than 1 or bigger than the number of
3218 lines in the buffer, an empty |List| is returned.
3219
3220 When {end} is greater than the number of lines in the buffer,
3221 it is treated as {end} is set to the number of lines in the
3222 buffer. When {end} is before {lnum} an empty |List| is
3223 returned.
3224
3225 This function works only for loaded buffers. For unloaded and
3226 non-existing buffers, an empty |List| is returned.
3227
3228 Example: >
3229 :let lines = getbufline(bufnr("myfile"), 1, "$")
3230
3231< Can also be used as a |method|: >
3232 GetBufnr()->getbufline(lnum)
Bram Moolenaarce30ccc2022-11-21 19:57:04 +00003233<
3234 *getbufoneline()*
3235getbufoneline({buf}, {lnum})
3236 Just like `getbufline()` but only get one line and return it
3237 as a string.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003238
3239getbufvar({buf}, {varname} [, {def}]) *getbufvar()*
3240 The result is the value of option or local buffer variable
3241 {varname} in buffer {buf}. Note that the name without "b:"
3242 must be used.
3243 The {varname} argument is a string.
3244 When {varname} is empty returns a |Dictionary| with all the
3245 buffer-local variables.
3246 When {varname} is equal to "&" returns a |Dictionary| with all
3247 the buffer-local options.
3248 Otherwise, when {varname} starts with "&" returns the value of
3249 a buffer-local option.
3250 This also works for a global or buffer-local option, but it
3251 doesn't work for a global variable, window-local variable or
3252 window-local option.
3253 For the use of {buf}, see |bufname()| above.
3254 When the buffer or variable doesn't exist {def} or an empty
3255 string is returned, there is no error message.
3256 Examples: >
3257 :let bufmodified = getbufvar(1, "&mod")
Bram Moolenaarc51cf032022-02-26 12:25:45 +00003258 :echo "todo myvar = " .. getbufvar("todo", "myvar")
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003259
3260< Can also be used as a |method|: >
3261 GetBufnr()->getbufvar(varname)
3262<
3263getchangelist([{buf}]) *getchangelist()*
3264 Returns the |changelist| for the buffer {buf}. For the use
3265 of {buf}, see |bufname()| above. If buffer {buf} doesn't
3266 exist, an empty list is returned.
3267
3268 The returned list contains two entries: a list with the change
3269 locations and the current position in the list. Each
3270 entry in the change list is a dictionary with the following
3271 entries:
3272 col column number
3273 coladd column offset for 'virtualedit'
3274 lnum line number
3275 If buffer {buf} is the current buffer, then the current
3276 position refers to the position in the list. For other
3277 buffers, it is set to the length of the list.
3278
3279 Can also be used as a |method|: >
3280 GetBufnr()->getchangelist()
3281
3282getchar([expr]) *getchar()*
3283 Get a single character from the user or input stream.
3284 If [expr] is omitted, wait until a character is available.
3285 If [expr] is 0, only get a character when one is available.
3286 Return zero otherwise.
3287 If [expr] is 1, only check if a character is available, it is
3288 not consumed. Return zero if no character available.
3289 If you prefer always getting a string use |getcharstr()|.
3290
3291 Without [expr] and when [expr] is 0 a whole character or
3292 special key is returned. If it is a single character, the
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01003293 result is a Number. Use |nr2char()| to convert it to a String.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003294 Otherwise a String is returned with the encoded character.
3295 For a special key it's a String with a sequence of bytes
3296 starting with 0x80 (decimal: 128). This is the same value as
3297 the String "\<Key>", e.g., "\<Left>". The returned value is
3298 also a String when a modifier (shift, control, alt) was used
3299 that is not included in the character.
3300
3301 When [expr] is 0 and Esc is typed, there will be a short delay
3302 while Vim waits to see if this is the start of an escape
3303 sequence.
3304
3305 When [expr] is 1 only the first byte is returned. For a
3306 one-byte character it is the character itself as a number.
3307 Use nr2char() to convert it to a String.
3308
3309 Use getcharmod() to obtain any additional modifiers.
3310
3311 When the user clicks a mouse button, the mouse event will be
3312 returned. The position can then be found in |v:mouse_col|,
3313 |v:mouse_lnum|, |v:mouse_winid| and |v:mouse_win|.
3314 |getmousepos()| can also be used. Mouse move events will be
3315 ignored.
3316 This example positions the mouse as it would normally happen: >
3317 let c = getchar()
3318 if c == "\<LeftMouse>" && v:mouse_win > 0
Bram Moolenaarc51cf032022-02-26 12:25:45 +00003319 exe v:mouse_win .. "wincmd w"
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003320 exe v:mouse_lnum
Bram Moolenaarc51cf032022-02-26 12:25:45 +00003321 exe "normal " .. v:mouse_col .. "|"
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003322 endif
3323<
3324 When using bracketed paste only the first character is
3325 returned, the rest of the pasted text is dropped.
3326 |xterm-bracketed-paste|.
3327
3328 There is no prompt, you will somehow have to make clear to the
3329 user that a character has to be typed. The screen is not
3330 redrawn, e.g. when resizing the window. When using a popup
3331 window it should work better with a |popup-filter|.
3332
3333 There is no mapping for the character.
3334 Key codes are replaced, thus when the user presses the <Del>
3335 key you get the code for the <Del> key, not the raw character
3336 sequence. Examples: >
3337 getchar() == "\<Del>"
3338 getchar() == "\<S-Left>"
3339< This example redefines "f" to ignore case: >
3340 :nmap f :call FindChar()<CR>
3341 :function FindChar()
3342 : let c = nr2char(getchar())
3343 : while col('.') < col('$') - 1
3344 : normal l
3345 : if getline('.')[col('.') - 1] ==? c
3346 : break
3347 : endif
3348 : endwhile
3349 :endfunction
3350<
3351 You may also receive synthetic characters, such as
3352 |<CursorHold>|. Often you will want to ignore this and get
3353 another character: >
3354 :function GetKey()
3355 : let c = getchar()
3356 : while c == "\<CursorHold>"
3357 : let c = getchar()
3358 : endwhile
3359 : return c
3360 :endfunction
3361
3362getcharmod() *getcharmod()*
3363 The result is a Number which is the state of the modifiers for
3364 the last obtained character with getchar() or in another way.
3365 These values are added together:
3366 2 shift
3367 4 control
3368 8 alt (meta)
3369 16 meta (when it's different from ALT)
3370 32 mouse double click
3371 64 mouse triple click
3372 96 mouse quadruple click (== 32 + 64)
3373 128 command (Macintosh only)
3374 Only the modifiers that have not been included in the
3375 character itself are obtained. Thus Shift-a results in "A"
Bram Moolenaar016188f2022-06-06 20:52:59 +01003376 without a modifier. Returns 0 if no modifiers are used.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003377
3378 *getcharpos()*
3379getcharpos({expr})
3380 Get the position for String {expr}. Same as |getpos()| but the
3381 column number in the returned List is a character index
3382 instead of a byte index.
naohiro ono56200ee2022-01-01 14:59:44 +00003383 If |getpos()| returns a very large column number, equal to
3384 |v:maxcol|, then getcharpos() will return the character index
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003385 of the last character.
3386
3387 Example:
3388 With the cursor on '세' in line 5 with text "여보세요": >
3389 getcharpos('.') returns [0, 5, 3, 0]
3390 getpos('.') returns [0, 5, 7, 0]
3391<
3392 Can also be used as a |method|: >
3393 GetMark()->getcharpos()
3394
3395getcharsearch() *getcharsearch()*
3396 Return the current character search information as a {dict}
3397 with the following entries:
3398
3399 char character previously used for a character
3400 search (|t|, |f|, |T|, or |F|); empty string
3401 if no character search has been performed
3402 forward direction of character search; 1 for forward,
3403 0 for backward
3404 until type of character search; 1 for a |t| or |T|
3405 character search, 0 for an |f| or |F|
3406 character search
3407
3408 This can be useful to always have |;| and |,| search
3409 forward/backward regardless of the direction of the previous
3410 character search: >
3411 :nnoremap <expr> ; getcharsearch().forward ? ';' : ','
3412 :nnoremap <expr> , getcharsearch().forward ? ',' : ';'
3413< Also see |setcharsearch()|.
3414
3415
3416getcharstr([expr]) *getcharstr()*
3417 Get a single character from the user or input stream as a
3418 string.
3419 If [expr] is omitted, wait until a character is available.
3420 If [expr] is 0 or false, only get a character when one is
3421 available. Return an empty string otherwise.
3422 If [expr] is 1 or true, only check if a character is
3423 available, it is not consumed. Return an empty string
3424 if no character is available.
3425 Otherwise this works like |getchar()|, except that a number
3426 result is converted to a string.
3427
Shougo Matsushita79d599b2022-05-07 12:48:29 +01003428getcmdcompltype() *getcmdcompltype()*
3429 Return the type of the current command-line completion.
3430 Only works when the command line is being edited, thus
3431 requires use of |c_CTRL-\_e| or |c_CTRL-R_=|.
Bram Moolenaar921bde82022-05-09 19:50:35 +01003432 See |:command-completion| for the return string.
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01003433 Also see |getcmdtype()|, |setcmdpos()|, |getcmdline()| and
3434 |setcmdline()|.
Shougo Matsushita79d599b2022-05-07 12:48:29 +01003435 Returns an empty string when completion is not defined.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003436
3437getcmdline() *getcmdline()*
3438 Return the current command-line. Only works when the command
3439 line is being edited, thus requires use of |c_CTRL-\_e| or
3440 |c_CTRL-R_=|.
3441 Example: >
3442 :cmap <F7> <C-\>eescape(getcmdline(), ' \')<CR>
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01003443< Also see |getcmdtype()|, |getcmdpos()|, |setcmdpos()| and
3444 |setcmdline()|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003445 Returns an empty string when entering a password or using
3446 |inputsecret()|.
3447
3448getcmdpos() *getcmdpos()*
3449 Return the position of the cursor in the command line as a
3450 byte count. The first column is 1.
3451 Only works when editing the command line, thus requires use of
3452 |c_CTRL-\_e| or |c_CTRL-R_=| or an expression mapping.
3453 Returns 0 otherwise.
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01003454 Also see |getcmdtype()|, |setcmdpos()|, |getcmdline()| and
3455 |setcmdline()|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003456
Shougo Matsushita79d599b2022-05-07 12:48:29 +01003457getcmdscreenpos() *getcmdscreenpos()*
3458 Return the screen position of the cursor in the command line
3459 as a byte count. The first column is 1.
3460 Instead of |getcmdpos()|, it adds the prompt position.
3461 Only works when editing the command line, thus requires use of
3462 |c_CTRL-\_e| or |c_CTRL-R_=| or an expression mapping.
3463 Returns 0 otherwise.
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01003464 Also see |getcmdpos()|, |setcmdpos()|, |getcmdline()| and
3465 |setcmdline()|.
Shougo Matsushita79d599b2022-05-07 12:48:29 +01003466
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003467getcmdtype() *getcmdtype()*
3468 Return the current command-line type. Possible return values
3469 are:
3470 : normal Ex command
3471 > debug mode command |debug-mode|
3472 / forward search command
3473 ? backward search command
3474 @ |input()| command
3475 - |:insert| or |:append| command
3476 = |i_CTRL-R_=|
3477 Only works when editing the command line, thus requires use of
3478 |c_CTRL-\_e| or |c_CTRL-R_=| or an expression mapping.
3479 Returns an empty string otherwise.
3480 Also see |getcmdpos()|, |setcmdpos()| and |getcmdline()|.
3481
3482getcmdwintype() *getcmdwintype()*
3483 Return the current |command-line-window| type. Possible return
3484 values are the same as |getcmdtype()|. Returns an empty string
3485 when not in the command-line window.
3486
3487getcompletion({pat}, {type} [, {filtered}]) *getcompletion()*
3488 Return a list of command-line completion matches. The String
3489 {type} argument specifies what for. The following completion
3490 types are supported:
3491
3492 arglist file names in argument list
3493 augroup autocmd groups
3494 buffer buffer names
Bram Moolenaar6e2e2cc2022-03-14 19:24:46 +00003495 behave |:behave| suboptions
3496 breakpoint |:breakadd| and |:breakdel| suboptions
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003497 color color schemes
3498 command Ex command
3499 cmdline |cmdline-completion| result
3500 compiler compilers
3501 cscope |:cscope| suboptions
3502 diff_buffer |:diffget| and |:diffput| completion
3503 dir directory names
3504 environment environment variable names
3505 event autocommand events
3506 expression Vim expression
3507 file file and directory names
3508 file_in_path file and directory names in |'path'|
3509 filetype filetype names |'filetype'|
3510 function function name
3511 help help subjects
3512 highlight highlight groups
Bram Moolenaar6e2e2cc2022-03-14 19:24:46 +00003513 history |:history| suboptions
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003514 locale locale names (as output of locale -a)
3515 mapclear buffer argument
3516 mapping mapping name
3517 menu menus
3518 messages |:messages| suboptions
3519 option options
3520 packadd optional package |pack-add| names
Yegappan Lakshmanan454ce672022-03-24 11:22:13 +00003521 scriptnames sourced script names |:scriptnames|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003522 shellcmd Shell command
3523 sign |:sign| suboptions
3524 syntax syntax file names |'syntax'|
3525 syntime |:syntime| suboptions
3526 tag tags
3527 tag_listfiles tags, file names
3528 user user names
3529 var user variables
3530
3531 If {pat} is an empty string, then all the matches are
3532 returned. Otherwise only items matching {pat} are returned.
3533 See |wildcards| for the use of special characters in {pat}.
3534
3535 If the optional {filtered} flag is set to 1, then 'wildignore'
3536 is applied to filter the results. Otherwise all the matches
3537 are returned. The 'wildignorecase' option always applies.
3538
Yegappan Lakshmanane7dd0fa2022-03-22 16:06:31 +00003539 If the 'wildoptions' option contains 'fuzzy', then fuzzy
3540 matching is used to get the completion matches. Otherwise
Yegappan Lakshmanan454ce672022-03-24 11:22:13 +00003541 regular expression matching is used. Thus this function
3542 follows the user preference, what happens on the command line.
3543 If you do not want this you can make 'wildoptions' empty
3544 before calling getcompletion() and restore it afterwards.
Yegappan Lakshmanane7dd0fa2022-03-22 16:06:31 +00003545
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003546 If {type} is "cmdline", then the |cmdline-completion| result is
3547 returned. For example, to complete the possible values after
3548 a ":call" command: >
3549 echo getcompletion('call ', 'cmdline')
3550<
3551 If there are no matches, an empty list is returned. An
3552 invalid value for {type} produces an error.
3553
3554 Can also be used as a |method|: >
3555 GetPattern()->getcompletion('color')
3556<
3557 *getcurpos()*
3558getcurpos([{winid}])
3559 Get the position of the cursor. This is like getpos('.'), but
3560 includes an extra "curswant" item in the list:
3561 [0, lnum, col, off, curswant] ~
3562 The "curswant" number is the preferred column when moving the
naohiro ono56200ee2022-01-01 14:59:44 +00003563 cursor vertically. After |$| command it will be a very large
3564 number equal to |v:maxcol|. Also see |getcursorcharpos()| and
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003565 |getpos()|.
3566 The first "bufnum" item is always zero. The byte position of
3567 the cursor is returned in 'col'. To get the character
3568 position, use |getcursorcharpos()|.
3569
3570 The optional {winid} argument can specify the window. It can
3571 be the window number or the |window-ID|. The last known
3572 cursor position is returned, this may be invalid for the
3573 current value of the buffer if it is not the current window.
3574 If {winid} is invalid a list with zeroes is returned.
3575
3576 This can be used to save and restore the cursor position: >
3577 let save_cursor = getcurpos()
3578 MoveTheCursorAround
3579 call setpos('.', save_cursor)
3580< Note that this only works within the window. See
3581 |winrestview()| for restoring more state.
3582
3583 Can also be used as a |method|: >
3584 GetWinid()->getcurpos()
3585<
3586 *getcursorcharpos()*
3587getcursorcharpos([{winid}])
3588 Same as |getcurpos()| but the column number in the returned
3589 List is a character index instead of a byte index.
3590
3591 Example:
3592 With the cursor on '보' in line 3 with text "여보세요": >
3593 getcursorcharpos() returns [0, 3, 2, 0, 3]
3594 getcurpos() returns [0, 3, 4, 0, 3]
3595<
3596 Can also be used as a |method|: >
3597 GetWinid()->getcursorcharpos()
3598
3599< *getcwd()*
3600getcwd([{winnr} [, {tabnr}]])
3601 The result is a String, which is the name of the current
3602 working directory. 'autochdir' is ignored.
3603
3604 With {winnr} return the local current directory of this window
3605 in the current tab page. {winnr} can be the window number or
3606 the |window-ID|.
3607 If {winnr} is -1 return the name of the global working
3608 directory. See also |haslocaldir()|.
3609
3610 With {winnr} and {tabnr} return the local current directory of
3611 the window in the specified tab page. If {winnr} is -1 return
3612 the working directory of the tabpage.
3613 If {winnr} is zero use the current window, if {tabnr} is zero
3614 use the current tabpage.
3615 Without any arguments, return the actual working directory of
3616 the current window.
3617 Return an empty string if the arguments are invalid.
3618
3619 Examples: >
3620 " Get the working directory of the current window
3621 :echo getcwd()
3622 :echo getcwd(0)
3623 :echo getcwd(0, 0)
3624 " Get the working directory of window 3 in tabpage 2
3625 :echo getcwd(3, 2)
3626 " Get the global working directory
3627 :echo getcwd(-1)
3628 " Get the working directory of tabpage 3
3629 :echo getcwd(-1, 3)
3630 " Get the working directory of current tabpage
3631 :echo getcwd(-1, 0)
3632
3633< Can also be used as a |method|: >
3634 GetWinnr()->getcwd()
3635
3636getenv({name}) *getenv()*
3637 Return the value of environment variable {name}. The {name}
3638 argument is a string, without a leading '$'. Example: >
3639 myHome = getenv('HOME')
3640
3641< When the variable does not exist |v:null| is returned. That
3642 is different from a variable set to an empty string, although
3643 some systems interpret the empty value as the variable being
3644 deleted. See also |expr-env|.
3645
3646 Can also be used as a |method|: >
3647 GetVarname()->getenv()
3648
3649getfontname([{name}]) *getfontname()*
3650 Without an argument returns the name of the normal font being
3651 used. Like what is used for the Normal highlight group
3652 |hl-Normal|.
3653 With an argument a check is done whether String {name} is a
3654 valid font name. If not then an empty string is returned.
3655 Otherwise the actual font name is returned, or {name} if the
3656 GUI does not support obtaining the real name.
3657 Only works when the GUI is running, thus not in your vimrc or
3658 gvimrc file. Use the |GUIEnter| autocommand to use this
3659 function just after the GUI has started.
3660 Note that the GTK GUI accepts any font name, thus checking for
3661 a valid name does not work.
3662
3663getfperm({fname}) *getfperm()*
3664 The result is a String, which is the read, write, and execute
3665 permissions of the given file {fname}.
3666 If {fname} does not exist or its directory cannot be read, an
3667 empty string is returned.
3668 The result is of the form "rwxrwxrwx", where each group of
3669 "rwx" flags represent, in turn, the permissions of the owner
3670 of the file, the group the file belongs to, and other users.
3671 If a user does not have a given permission the flag for this
3672 is replaced with the string "-". Examples: >
3673 :echo getfperm("/etc/passwd")
3674 :echo getfperm(expand("~/.vimrc"))
3675< This will hopefully (from a security point of view) display
3676 the string "rw-r--r--" or even "rw-------".
3677
3678 Can also be used as a |method|: >
3679 GetFilename()->getfperm()
3680<
3681 For setting permissions use |setfperm()|.
3682
3683getfsize({fname}) *getfsize()*
3684 The result is a Number, which is the size in bytes of the
3685 given file {fname}.
3686 If {fname} is a directory, 0 is returned.
3687 If the file {fname} can't be found, -1 is returned.
3688 If the size of {fname} is too big to fit in a Number then -2
3689 is returned.
3690
3691 Can also be used as a |method|: >
3692 GetFilename()->getfsize()
3693
3694getftime({fname}) *getftime()*
3695 The result is a Number, which is the last modification time of
3696 the given file {fname}. The value is measured as seconds
3697 since 1st Jan 1970, and may be passed to strftime(). See also
3698 |localtime()| and |strftime()|.
3699 If the file {fname} can't be found -1 is returned.
3700
3701 Can also be used as a |method|: >
3702 GetFilename()->getftime()
3703
3704getftype({fname}) *getftype()*
3705 The result is a String, which is a description of the kind of
3706 file of the given file {fname}.
3707 If {fname} does not exist an empty string is returned.
3708 Here is a table over different kinds of files and their
3709 results:
3710 Normal file "file"
3711 Directory "dir"
3712 Symbolic link "link"
3713 Block device "bdev"
3714 Character device "cdev"
3715 Socket "socket"
3716 FIFO "fifo"
3717 All other "other"
3718 Example: >
3719 getftype("/home")
3720< Note that a type such as "link" will only be returned on
3721 systems that support it. On some systems only "dir" and
3722 "file" are returned. On MS-Windows a symbolic link to a
3723 directory returns "dir" instead of "link".
3724
3725 Can also be used as a |method|: >
3726 GetFilename()->getftype()
3727
3728getimstatus() *getimstatus()*
3729 The result is a Number, which is |TRUE| when the IME status is
Bram Moolenaar016188f2022-06-06 20:52:59 +01003730 active and |FALSE| otherwise.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003731 See 'imstatusfunc'.
3732
3733getjumplist([{winnr} [, {tabnr}]]) *getjumplist()*
3734 Returns the |jumplist| for the specified window.
3735
3736 Without arguments use the current window.
3737 With {winnr} only use this window in the current tab page.
3738 {winnr} can also be a |window-ID|.
3739 With {winnr} and {tabnr} use the window in the specified tab
Bram Moolenaar016188f2022-06-06 20:52:59 +01003740 page. If {winnr} or {tabnr} is invalid, an empty list is
3741 returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003742
3743 The returned list contains two entries: a list with the jump
3744 locations and the last used jump position number in the list.
3745 Each entry in the jump location list is a dictionary with
3746 the following entries:
3747 bufnr buffer number
3748 col column number
3749 coladd column offset for 'virtualedit'
3750 filename filename if available
3751 lnum line number
3752
3753 Can also be used as a |method|: >
3754 GetWinnr()->getjumplist()
3755
3756< *getline()*
3757getline({lnum} [, {end}])
3758 Without {end} the result is a String, which is line {lnum}
3759 from the current buffer. Example: >
3760 getline(1)
3761< When {lnum} is a String that doesn't start with a
3762 digit, |line()| is called to translate the String into a Number.
3763 To get the line under the cursor: >
3764 getline(".")
3765< When {lnum} is a number smaller than 1 or bigger than the
3766 number of lines in the buffer, an empty string is returned.
3767
3768 When {end} is given the result is a |List| where each item is
3769 a line from the current buffer in the range {lnum} to {end},
3770 including line {end}.
3771 {end} is used in the same way as {lnum}.
3772 Non-existing lines are silently omitted.
3773 When {end} is before {lnum} an empty |List| is returned.
3774 Example: >
3775 :let start = line('.')
3776 :let end = search("^$") - 1
3777 :let lines = getline(start, end)
3778
3779< Can also be used as a |method|: >
3780 ComputeLnum()->getline()
3781
Bram Moolenaarce30ccc2022-11-21 19:57:04 +00003782< To get lines from another buffer see |getbufline()| and
3783 |getbufoneline()|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003784
3785getloclist({nr} [, {what}]) *getloclist()*
3786 Returns a |List| with all the entries in the location list for
3787 window {nr}. {nr} can be the window number or the |window-ID|.
3788 When {nr} is zero the current window is used.
3789
3790 For a location list window, the displayed location list is
3791 returned. For an invalid window number {nr}, an empty list is
3792 returned. Otherwise, same as |getqflist()|.
3793
3794 If the optional {what} dictionary argument is supplied, then
3795 returns the items listed in {what} as a dictionary. Refer to
3796 |getqflist()| for the supported items in {what}.
3797
3798 In addition to the items supported by |getqflist()| in {what},
3799 the following item is supported by |getloclist()|:
3800
3801 filewinid id of the window used to display files
3802 from the location list. This field is
3803 applicable only when called from a
3804 location list window. See
3805 |location-list-file-window| for more
3806 details.
3807
3808 Returns a |Dictionary| with default values if there is no
3809 location list for the window {nr}.
3810 Returns an empty Dictionary if window {nr} does not exist.
3811
3812 Examples (See also |getqflist-examples|): >
3813 :echo getloclist(3, {'all': 0})
3814 :echo getloclist(5, {'filewinid': 0})
3815
3816
3817getmarklist([{buf}]) *getmarklist()*
3818 Without the {buf} argument returns a |List| with information
3819 about all the global marks. |mark|
3820
3821 If the optional {buf} argument is specified, returns the
3822 local marks defined in buffer {buf}. For the use of {buf},
Bram Moolenaar016188f2022-06-06 20:52:59 +01003823 see |bufname()|. If {buf} is invalid, an empty list is
3824 returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003825
3826 Each item in the returned List is a |Dict| with the following:
3827 mark name of the mark prefixed by "'"
3828 pos a |List| with the position of the mark:
3829 [bufnum, lnum, col, off]
3830 Refer to |getpos()| for more information.
3831 file file name
3832
3833 Refer to |getpos()| for getting information about a specific
3834 mark.
3835
3836 Can also be used as a |method|: >
3837 GetBufnr()->getmarklist()
3838
3839getmatches([{win}]) *getmatches()*
3840 Returns a |List| with all matches previously defined for the
3841 current window by |matchadd()| and the |:match| commands.
3842 |getmatches()| is useful in combination with |setmatches()|,
3843 as |setmatches()| can restore a list of matches saved by
3844 |getmatches()|.
3845 If {win} is specified, use the window with this number or
Bram Moolenaar016188f2022-06-06 20:52:59 +01003846 window ID instead of the current window. If {win} is invalid,
3847 an empty list is returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003848 Example: >
3849 :echo getmatches()
3850< [{'group': 'MyGroup1', 'pattern': 'TODO',
3851 'priority': 10, 'id': 1}, {'group': 'MyGroup2',
3852 'pattern': 'FIXME', 'priority': 10, 'id': 2}] >
3853 :let m = getmatches()
3854 :call clearmatches()
3855 :echo getmatches()
3856< [] >
3857 :call setmatches(m)
3858 :echo getmatches()
3859< [{'group': 'MyGroup1', 'pattern': 'TODO',
3860 'priority': 10, 'id': 1}, {'group': 'MyGroup2',
3861 'pattern': 'FIXME', 'priority': 10, 'id': 2}] >
3862 :unlet m
3863<
3864getmousepos() *getmousepos()*
3865 Returns a |Dictionary| with the last known position of the
3866 mouse. This can be used in a mapping for a mouse click or in
3867 a filter of a popup window. The items are:
3868 screenrow screen row
3869 screencol screen column
3870 winid Window ID of the click
3871 winrow row inside "winid"
3872 wincol column inside "winid"
3873 line text line inside "winid"
3874 column text column inside "winid"
3875 All numbers are 1-based.
3876
3877 If not over a window, e.g. when in the command line, then only
3878 "screenrow" and "screencol" are valid, the others are zero.
3879
3880 When on the status line below a window or the vertical
3881 separator right of a window, the "line" and "column" values
3882 are zero.
3883
3884 When the position is after the text then "column" is the
3885 length of the text in bytes plus one.
3886
3887 If the mouse is over a popup window then that window is used.
3888
3889 When using |getchar()| the Vim variables |v:mouse_lnum|,
3890 |v:mouse_col| and |v:mouse_winid| also provide these values.
3891
Bram Moolenaar24dc19c2022-11-14 19:49:15 +00003892getmouseshape() *getmouseshape()*
3893 Returns the name of the currently showing mouse pointer.
3894 When the |+mouseshape| feature is not supported or the shape
3895 is unknown an empty string is returned.
3896 This function is mainly intended for testing.
3897
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003898 *getpid()*
3899getpid() Return a Number which is the process ID of the Vim process.
3900 On Unix and MS-Windows this is a unique number, until Vim
3901 exits.
3902
3903 *getpos()*
3904getpos({expr}) Get the position for String {expr}. For possible values of
3905 {expr} see |line()|. For getting the cursor position see
3906 |getcurpos()|.
3907 The result is a |List| with four numbers:
3908 [bufnum, lnum, col, off]
3909 "bufnum" is zero, unless a mark like '0 or 'A is used, then it
3910 is the buffer number of the mark.
3911 "lnum" and "col" are the position in the buffer. The first
3912 column is 1.
3913 The "off" number is zero, unless 'virtualedit' is used. Then
3914 it is the offset in screen columns from the start of the
3915 character. E.g., a position within a <Tab> or after the last
3916 character.
3917 Note that for '< and '> Visual mode matters: when it is "V"
3918 (visual line mode) the column of '< is zero and the column of
naohiro ono56200ee2022-01-01 14:59:44 +00003919 '> is a large number equal to |v:maxcol|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003920 The column number in the returned List is the byte position
3921 within the line. To get the character position in the line,
3922 use |getcharpos()|.
naohiro ono56200ee2022-01-01 14:59:44 +00003923 A very large column number equal to |v:maxcol| can be returned,
3924 in which case it means "after the end of the line".
Bram Moolenaar016188f2022-06-06 20:52:59 +01003925 If {expr} is invalid, returns a list with all zeros.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003926 This can be used to save and restore the position of a mark: >
3927 let save_a_mark = getpos("'a")
3928 ...
3929 call setpos("'a", save_a_mark)
3930< Also see |getcharpos()|, |getcurpos()| and |setpos()|.
3931
3932 Can also be used as a |method|: >
3933 GetMark()->getpos()
3934
3935getqflist([{what}]) *getqflist()*
3936 Returns a |List| with all the current quickfix errors. Each
3937 list item is a dictionary with these entries:
3938 bufnr number of buffer that has the file name, use
3939 bufname() to get the name
3940 module module name
3941 lnum line number in the buffer (first line is 1)
3942 end_lnum
3943 end of line number if the item is multiline
3944 col column number (first column is 1)
3945 end_col end of column number if the item has range
3946 vcol |TRUE|: "col" is visual column
3947 |FALSE|: "col" is byte index
3948 nr error number
3949 pattern search pattern used to locate the error
3950 text description of the error
3951 type type of the error, 'E', '1', etc.
3952 valid |TRUE|: recognized error message
3953
3954 When there is no error list or it's empty, an empty list is
3955 returned. Quickfix list entries with a non-existing buffer
3956 number are returned with "bufnr" set to zero (Note: some
3957 functions accept buffer number zero for the alternate buffer,
3958 you may need to explicitly check for zero).
3959
3960 Useful application: Find pattern matches in multiple files and
3961 do something with them: >
3962 :vimgrep /theword/jg *.c
3963 :for d in getqflist()
3964 : echo bufname(d.bufnr) ':' d.lnum '=' d.text
3965 :endfor
3966<
3967 If the optional {what} dictionary argument is supplied, then
3968 returns only the items listed in {what} as a dictionary. The
3969 following string items are supported in {what}:
3970 changedtick get the total number of changes made
3971 to the list |quickfix-changedtick|
3972 context get the |quickfix-context|
3973 efm errorformat to use when parsing "lines". If
3974 not present, then the 'errorformat' option
3975 value is used.
3976 id get information for the quickfix list with
3977 |quickfix-ID|; zero means the id for the
3978 current list or the list specified by "nr"
3979 idx get information for the quickfix entry at this
3980 index in the list specified by 'id' or 'nr'.
3981 If set to zero, then uses the current entry.
3982 See |quickfix-index|
3983 items quickfix list entries
3984 lines parse a list of lines using 'efm' and return
3985 the resulting entries. Only a |List| type is
3986 accepted. The current quickfix list is not
3987 modified. See |quickfix-parse|.
3988 nr get information for this quickfix list; zero
3989 means the current quickfix list and "$" means
3990 the last quickfix list
3991 qfbufnr number of the buffer displayed in the quickfix
3992 window. Returns 0 if the quickfix buffer is
3993 not present. See |quickfix-buffer|.
3994 size number of entries in the quickfix list
3995 title get the list title |quickfix-title|
3996 winid get the quickfix |window-ID|
3997 all all of the above quickfix properties
3998 Non-string items in {what} are ignored. To get the value of a
3999 particular item, set it to zero.
4000 If "nr" is not present then the current quickfix list is used.
4001 If both "nr" and a non-zero "id" are specified, then the list
4002 specified by "id" is used.
4003 To get the number of lists in the quickfix stack, set "nr" to
4004 "$" in {what}. The "nr" value in the returned dictionary
4005 contains the quickfix stack size.
4006 When "lines" is specified, all the other items except "efm"
4007 are ignored. The returned dictionary contains the entry
4008 "items" with the list of entries.
4009
4010 The returned dictionary contains the following entries:
4011 changedtick total number of changes made to the
4012 list |quickfix-changedtick|
4013 context quickfix list context. See |quickfix-context|
4014 If not present, set to "".
4015 id quickfix list ID |quickfix-ID|. If not
4016 present, set to 0.
4017 idx index of the quickfix entry in the list. If not
4018 present, set to 0.
4019 items quickfix list entries. If not present, set to
4020 an empty list.
4021 nr quickfix list number. If not present, set to 0
4022 qfbufnr number of the buffer displayed in the quickfix
4023 window. If not present, set to 0.
4024 size number of entries in the quickfix list. If not
4025 present, set to 0.
4026 title quickfix list title text. If not present, set
4027 to "".
4028 winid quickfix |window-ID|. If not present, set to 0
4029
4030 Examples (See also |getqflist-examples|): >
4031 :echo getqflist({'all': 1})
4032 :echo getqflist({'nr': 2, 'title': 1})
4033 :echo getqflist({'lines' : ["F1:10:L10"]})
4034<
4035getreg([{regname} [, 1 [, {list}]]]) *getreg()*
4036 The result is a String, which is the contents of register
4037 {regname}. Example: >
4038 :let cliptext = getreg('*')
4039< When register {regname} was not set the result is an empty
4040 string.
Bram Moolenaara2baa732022-02-04 16:09:54 +00004041 The {regname} argument must be a string. *E1162*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004042
4043 getreg('=') returns the last evaluated value of the expression
4044 register. (For use in maps.)
4045 getreg('=', 1) returns the expression itself, so that it can
4046 be restored with |setreg()|. For other registers the extra
4047 argument is ignored, thus you can always give it.
4048
4049 If {list} is present and |TRUE|, the result type is changed
4050 to |List|. Each list item is one text line. Use it if you care
4051 about zero bytes possibly present inside register: without
4052 third argument both NLs and zero bytes are represented as NLs
4053 (see |NL-used-for-Nul|).
4054 When the register was not set an empty list is returned.
4055
4056 If {regname} is "", the unnamed register '"' is used.
4057 If {regname} is not specified, |v:register| is used.
4058 In |Vim9-script| {regname} must be one character.
4059
4060 Can also be used as a |method|: >
4061 GetRegname()->getreg()
4062
4063getreginfo([{regname}]) *getreginfo()*
4064 Returns detailed information about register {regname} as a
4065 Dictionary with the following entries:
4066 regcontents List of lines contained in register
4067 {regname}, like
4068 |getreg|({regname}, 1, 1).
4069 regtype the type of register {regname}, as in
4070 |getregtype()|.
4071 isunnamed Boolean flag, v:true if this register
4072 is currently pointed to by the unnamed
4073 register.
4074 points_to for the unnamed register, gives the
4075 single letter name of the register
4076 currently pointed to (see |quotequote|).
4077 For example, after deleting a line
4078 with `dd`, this field will be "1",
4079 which is the register that got the
4080 deleted text.
4081
4082 The {regname} argument is a string. If {regname} is invalid
4083 or not set, an empty Dictionary will be returned.
4084 If {regname} is "" or "@", the unnamed register '"' is used.
4085 If {regname} is not specified, |v:register| is used.
4086 The returned Dictionary can be passed to |setreg()|.
4087 In |Vim9-script| {regname} must be one character.
4088
4089 Can also be used as a |method|: >
4090 GetRegname()->getreginfo()
4091
4092getregtype([{regname}]) *getregtype()*
4093 The result is a String, which is type of register {regname}.
4094 The value will be one of:
4095 "v" for |characterwise| text
4096 "V" for |linewise| text
4097 "<CTRL-V>{width}" for |blockwise-visual| text
4098 "" for an empty or unknown register
4099 <CTRL-V> is one character with value 0x16.
4100 The {regname} argument is a string. If {regname} is "", the
4101 unnamed register '"' is used. If {regname} is not specified,
4102 |v:register| is used.
4103 In |Vim9-script| {regname} must be one character.
4104
4105 Can also be used as a |method|: >
4106 GetRegname()->getregtype()
4107
Yegappan Lakshmanan520f6ef2022-08-25 17:40:40 +01004108getscriptinfo([{opts}) *getscriptinfo()*
Yegappan Lakshmananf768c3d2022-08-22 13:15:13 +01004109 Returns a |List| with information about all the sourced Vim
Bram Moolenaar753885b2022-08-24 16:30:36 +01004110 scripts in the order they were sourced, like what
4111 `:scriptnames` shows.
Yegappan Lakshmananf768c3d2022-08-22 13:15:13 +01004112
Yegappan Lakshmanan2f892d82022-08-28 18:52:10 +01004113 The optional Dict argument {opts} supports the following
4114 optional items:
4115 name Script name match pattern. If specified,
4116 and "sid" is not specified, information about
4117 scripts with name that match the pattern
4118 "name" are returned.
4119 sid Script ID |<SID>|. If specified, only
4120 information about the script with ID "sid" is
4121 returned and "name" is ignored.
4122
Yegappan Lakshmananf768c3d2022-08-22 13:15:13 +01004123 Each item in the returned List is a |Dict| with the following
4124 items:
Yegappan Lakshmanan2f892d82022-08-28 18:52:10 +01004125 autoload Set to TRUE for a script that was used with
Bram Moolenaar753885b2022-08-24 16:30:36 +01004126 `import autoload` but was not actually sourced
4127 yet (see |import-autoload|).
Yegappan Lakshmanan2f892d82022-08-28 18:52:10 +01004128 functions List of script-local function names defined in
4129 the script. Present only when a particular
4130 script is specified using the "sid" item in
4131 {opts}.
4132 name Vim script file name.
4133 sid Script ID |<SID>|.
4134 sourced Script ID of the actually sourced script that
Bram Moolenaarfd999452022-08-24 18:30:14 +01004135 this script name links to, if any, otherwise
4136 zero
Yegappan Lakshmanan2f892d82022-08-28 18:52:10 +01004137 variables A dictionary with the script-local variables.
4138 Present only when the a particular script is
4139 specified using the "sid" item in {opts}.
4140 Note that this is a copy, the value of
4141 script-local variables cannot be changed using
4142 this dictionary.
4143 version Vimscript version (|scriptversion|)
Yegappan Lakshmanan520f6ef2022-08-25 17:40:40 +01004144
Yegappan Lakshmanan2f892d82022-08-28 18:52:10 +01004145 Examples: >
4146 :echo getscriptinfo({'name': 'myscript'})
4147 :echo getscriptinfo({'sid': 15}).variables
4148<
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004149gettabinfo([{tabnr}]) *gettabinfo()*
4150 If {tabnr} is not specified, then information about all the
4151 tab pages is returned as a |List|. Each List item is a
4152 |Dictionary|. Otherwise, {tabnr} specifies the tab page
4153 number and information about that one is returned. If the tab
4154 page does not exist an empty List is returned.
4155
4156 Each List item is a |Dictionary| with the following entries:
4157 tabnr tab page number.
4158 variables a reference to the dictionary with
4159 tabpage-local variables
4160 windows List of |window-ID|s in the tab page.
4161
4162 Can also be used as a |method|: >
4163 GetTabnr()->gettabinfo()
4164
4165gettabvar({tabnr}, {varname} [, {def}]) *gettabvar()*
4166 Get the value of a tab-local variable {varname} in tab page
4167 {tabnr}. |t:var|
4168 Tabs are numbered starting with one.
4169 The {varname} argument is a string. When {varname} is empty a
4170 dictionary with all tab-local variables is returned.
4171 Note that the name without "t:" must be used.
4172 When the tab or variable doesn't exist {def} or an empty
4173 string is returned, there is no error message.
4174
4175 Can also be used as a |method|: >
4176 GetTabnr()->gettabvar(varname)
4177
4178gettabwinvar({tabnr}, {winnr}, {varname} [, {def}]) *gettabwinvar()*
4179 Get the value of window-local variable {varname} in window
4180 {winnr} in tab page {tabnr}.
4181 The {varname} argument is a string. When {varname} is empty a
4182 dictionary with all window-local variables is returned.
4183 When {varname} is equal to "&" get the values of all
4184 window-local options in a |Dictionary|.
4185 Otherwise, when {varname} starts with "&" get the value of a
4186 window-local option.
4187 Note that {varname} must be the name without "w:".
4188 Tabs are numbered starting with one. For the current tabpage
4189 use |getwinvar()|.
4190 {winnr} can be the window number or the |window-ID|.
4191 When {winnr} is zero the current window is used.
4192 This also works for a global option, buffer-local option and
4193 window-local option, but it doesn't work for a global variable
4194 or buffer-local variable.
4195 When the tab, window or variable doesn't exist {def} or an
4196 empty string is returned, there is no error message.
4197 Examples: >
4198 :let list_is_on = gettabwinvar(1, 2, '&list')
Bram Moolenaarc51cf032022-02-26 12:25:45 +00004199 :echo "myvar = " .. gettabwinvar(3, 1, 'myvar')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004200<
4201 To obtain all window-local variables use: >
4202 gettabwinvar({tabnr}, {winnr}, '&')
4203
4204< Can also be used as a |method|: >
4205 GetTabnr()->gettabwinvar(winnr, varname)
4206
4207gettagstack([{winnr}]) *gettagstack()*
4208 The result is a Dict, which is the tag stack of window {winnr}.
4209 {winnr} can be the window number or the |window-ID|.
4210 When {winnr} is not specified, the current window is used.
4211 When window {winnr} doesn't exist, an empty Dict is returned.
4212
4213 The returned dictionary contains the following entries:
4214 curidx Current index in the stack. When at
4215 top of the stack, set to (length + 1).
4216 Index of bottom of the stack is 1.
4217 items List of items in the stack. Each item
4218 is a dictionary containing the
4219 entries described below.
4220 length Number of entries in the stack.
4221
4222 Each item in the stack is a dictionary with the following
4223 entries:
4224 bufnr buffer number of the current jump
4225 from cursor position before the tag jump.
4226 See |getpos()| for the format of the
4227 returned list.
4228 matchnr current matching tag number. Used when
4229 multiple matching tags are found for a
4230 name.
4231 tagname name of the tag
4232
4233 See |tagstack| for more information about the tag stack.
4234
4235 Can also be used as a |method|: >
4236 GetWinnr()->gettagstack()
4237
4238
4239gettext({text}) *gettext()*
4240 Translate String {text} if possible.
4241 This is mainly for use in the distributed Vim scripts. When
4242 generating message translations the {text} is extracted by
4243 xgettext, the translator can add the translated message in the
4244 .po file and Vim will lookup the translation when gettext() is
4245 called.
4246 For {text} double quoted strings are preferred, because
4247 xgettext does not understand escaping in single quoted
4248 strings.
4249
4250
4251getwininfo([{winid}]) *getwininfo()*
4252 Returns information about windows as a |List| with Dictionaries.
4253
4254 If {winid} is given Information about the window with that ID
4255 is returned, as a |List| with one item. If the window does not
4256 exist the result is an empty list.
4257
4258 Without {winid} information about all the windows in all the
4259 tab pages is returned.
4260
4261 Each List item is a |Dictionary| with the following entries:
4262 botline last complete displayed buffer line
4263 bufnr number of buffer in the window
4264 height window height (excluding winbar)
4265 loclist 1 if showing a location list
4266 {only with the +quickfix feature}
4267 quickfix 1 if quickfix or location list window
4268 {only with the +quickfix feature}
4269 terminal 1 if a terminal window
4270 {only with the +terminal feature}
4271 tabnr tab page number
4272 topline first displayed buffer line
4273 variables a reference to the dictionary with
4274 window-local variables
4275 width window width
4276 winbar 1 if the window has a toolbar, 0
4277 otherwise
4278 wincol leftmost screen column of the window;
4279 "col" from |win_screenpos()|
4280 textoff number of columns occupied by any
4281 'foldcolumn', 'signcolumn' and line
4282 number in front of the text
4283 winid |window-ID|
4284 winnr window number
4285 winrow topmost screen line of the window;
4286 "row" from |win_screenpos()|
4287
4288 Can also be used as a |method|: >
4289 GetWinnr()->getwininfo()
4290
4291getwinpos([{timeout}]) *getwinpos()*
4292 The result is a |List| with two numbers, the result of
4293 |getwinposx()| and |getwinposy()| combined:
4294 [x-pos, y-pos]
4295 {timeout} can be used to specify how long to wait in msec for
4296 a response from the terminal. When omitted 100 msec is used.
4297 Use a longer time for a remote terminal.
4298 When using a value less than 10 and no response is received
4299 within that time, a previously reported position is returned,
4300 if available. This can be used to poll for the position and
4301 do some work in the meantime: >
4302 while 1
4303 let res = getwinpos(1)
4304 if res[0] >= 0
4305 break
4306 endif
4307 " Do some work here
4308 endwhile
4309<
4310
4311 Can also be used as a |method|: >
4312 GetTimeout()->getwinpos()
4313<
4314 *getwinposx()*
4315getwinposx() The result is a Number, which is the X coordinate in pixels of
4316 the left hand side of the GUI Vim window. Also works for an
4317 xterm (uses a timeout of 100 msec).
4318 The result will be -1 if the information is not available.
4319 The value can be used with `:winpos`.
4320
4321 *getwinposy()*
4322getwinposy() The result is a Number, which is the Y coordinate in pixels of
4323 the top of the GUI Vim window. Also works for an xterm (uses
4324 a timeout of 100 msec).
4325 The result will be -1 if the information is not available.
4326 The value can be used with `:winpos`.
4327
4328getwinvar({winnr}, {varname} [, {def}]) *getwinvar()*
4329 Like |gettabwinvar()| for the current tabpage.
4330 Examples: >
4331 :let list_is_on = getwinvar(2, '&list')
Bram Moolenaarc51cf032022-02-26 12:25:45 +00004332 :echo "myvar = " .. getwinvar(1, 'myvar')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004333
4334< Can also be used as a |method|: >
4335 GetWinnr()->getwinvar(varname)
4336<
4337glob({expr} [, {nosuf} [, {list} [, {alllinks}]]]) *glob()*
4338 Expand the file wildcards in {expr}. See |wildcards| for the
4339 use of special characters.
4340
4341 Unless the optional {nosuf} argument is given and is |TRUE|,
4342 the 'suffixes' and 'wildignore' options apply: Names matching
4343 one of the patterns in 'wildignore' will be skipped and
4344 'suffixes' affect the ordering of matches.
4345 'wildignorecase' always applies.
4346
4347 When {list} is present and it is |TRUE| the result is a |List|
4348 with all matching files. The advantage of using a List is,
4349 you also get filenames containing newlines correctly.
4350 Otherwise the result is a String and when there are several
4351 matches, they are separated by <NL> characters.
4352
4353 If the expansion fails, the result is an empty String or List.
4354
4355 You can also use |readdir()| if you need to do complicated
4356 things, such as limiting the number of matches.
4357
4358 A name for a non-existing file is not included. A symbolic
4359 link is only included if it points to an existing file.
4360 However, when the {alllinks} argument is present and it is
4361 |TRUE| then all symbolic links are included.
4362
4363 For most systems backticks can be used to get files names from
4364 any external command. Example: >
4365 :let tagfiles = glob("`find . -name tags -print`")
4366 :let &tags = substitute(tagfiles, "\n", ",", "g")
4367< The result of the program inside the backticks should be one
4368 item per line. Spaces inside an item are allowed.
4369
4370 See |expand()| for expanding special Vim variables. See
4371 |system()| for getting the raw output of an external command.
4372
4373 Can also be used as a |method|: >
4374 GetExpr()->glob()
4375
4376glob2regpat({string}) *glob2regpat()*
4377 Convert a file pattern, as used by glob(), into a search
4378 pattern. The result can be used to match with a string that
4379 is a file name. E.g. >
4380 if filename =~ glob2regpat('Make*.mak')
4381< This is equivalent to: >
4382 if filename =~ '^Make.*\.mak$'
4383< When {string} is an empty string the result is "^$", match an
4384 empty string.
4385 Note that the result depends on the system. On MS-Windows
4386 a backslash usually means a path separator.
4387
4388 Can also be used as a |method|: >
4389 GetExpr()->glob2regpat()
4390< *globpath()*
4391globpath({path}, {expr} [, {nosuf} [, {list} [, {alllinks}]]])
4392 Perform glob() for String {expr} on all directories in {path}
4393 and concatenate the results. Example: >
4394 :echo globpath(&rtp, "syntax/c.vim")
4395<
4396 {path} is a comma-separated list of directory names. Each
4397 directory name is prepended to {expr} and expanded like with
4398 |glob()|. A path separator is inserted when needed.
4399 To add a comma inside a directory name escape it with a
4400 backslash. Note that on MS-Windows a directory may have a
4401 trailing backslash, remove it if you put a comma after it.
4402 If the expansion fails for one of the directories, there is no
4403 error message.
4404
4405 Unless the optional {nosuf} argument is given and is |TRUE|,
4406 the 'suffixes' and 'wildignore' options apply: Names matching
4407 one of the patterns in 'wildignore' will be skipped and
4408 'suffixes' affect the ordering of matches.
4409
4410 When {list} is present and it is |TRUE| the result is a |List|
4411 with all matching files. The advantage of using a List is, you
4412 also get filenames containing newlines correctly. Otherwise
4413 the result is a String and when there are several matches,
4414 they are separated by <NL> characters. Example: >
4415 :echo globpath(&rtp, "syntax/c.vim", 0, 1)
4416<
4417 {alllinks} is used as with |glob()|.
4418
4419 The "**" item can be used to search in a directory tree.
4420 For example, to find all "README.txt" files in the directories
4421 in 'runtimepath' and below: >
4422 :echo globpath(&rtp, "**/README.txt")
4423< Upwards search and limiting the depth of "**" is not
4424 supported, thus using 'path' will not always work properly.
4425
4426 Can also be used as a |method|, the base is passed as the
4427 second argument: >
4428 GetExpr()->globpath(&rtp)
4429<
4430 *has()*
4431has({feature} [, {check}])
4432 When {check} is omitted or is zero: The result is a Number,
4433 which is 1 if the feature {feature} is supported, zero
4434 otherwise. The {feature} argument is a string, case is
4435 ignored. See |feature-list| below.
4436
4437 When {check} is present and not zero: The result is a Number,
4438 which is 1 if the feature {feature} could ever be supported,
4439 zero otherwise. This is useful to check for a typo in
4440 {feature} and to detect dead code. Keep in mind that an older
4441 Vim version will not know about a feature added later and
4442 features that have been abandoned will not be known by the
4443 current Vim version.
4444
4445 Also see |exists()| and |exists_compiled()|.
4446
4447 Note that to skip code that has a syntax error when the
4448 feature is not available, Vim may skip the rest of the line
4449 and miss a following `endif`. Therefore put the `endif` on a
4450 separate line: >
4451 if has('feature')
4452 let x = this->breaks->without->the->feature
4453 endif
4454< If the `endif` would be moved to the second line as "| endif" it
4455 would not be found.
4456
4457
4458has_key({dict}, {key}) *has_key()*
4459 The result is a Number, which is TRUE if |Dictionary| {dict}
Bram Moolenaare8008642022-08-19 17:15:35 +01004460 has an entry with key {key}. FALSE otherwise.
4461 The {key} argument is a string. In |Vim9| script a number is
4462 also accepted (and converted to a string) but no other types.
4463 In legacy script the usual automatic conversion to string is
4464 done.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004465
4466 Can also be used as a |method|: >
4467 mydict->has_key(key)
4468
4469haslocaldir([{winnr} [, {tabnr}]]) *haslocaldir()*
4470 The result is a Number:
4471 1 when the window has set a local directory via |:lcd|
4472 2 when the tab-page has set a local directory via |:tcd|
4473 0 otherwise.
4474
4475 Without arguments use the current window.
4476 With {winnr} use this window in the current tab page.
4477 With {winnr} and {tabnr} use the window in the specified tab
4478 page.
4479 {winnr} can be the window number or the |window-ID|.
4480 If {winnr} is -1 it is ignored and only the tabpage is used.
4481 Return 0 if the arguments are invalid.
4482 Examples: >
4483 if haslocaldir() == 1
4484 " window local directory case
4485 elseif haslocaldir() == 2
4486 " tab-local directory case
4487 else
4488 " global directory case
4489 endif
4490
4491 " current window
4492 :echo haslocaldir()
4493 :echo haslocaldir(0)
4494 :echo haslocaldir(0, 0)
4495 " window n in current tab page
4496 :echo haslocaldir(n)
4497 :echo haslocaldir(n, 0)
4498 " window n in tab page m
4499 :echo haslocaldir(n, m)
4500 " tab page m
4501 :echo haslocaldir(-1, m)
4502<
4503 Can also be used as a |method|: >
4504 GetWinnr()->haslocaldir()
4505
4506hasmapto({what} [, {mode} [, {abbr}]]) *hasmapto()*
4507 The result is a Number, which is TRUE if there is a mapping
4508 that contains {what} in somewhere in the rhs (what it is
4509 mapped to) and this mapping exists in one of the modes
4510 indicated by {mode}.
4511 The arguments {what} and {mode} are strings.
4512 When {abbr} is there and it is |TRUE| use abbreviations
4513 instead of mappings. Don't forget to specify Insert and/or
4514 Command-line mode.
4515 Both the global mappings and the mappings local to the current
4516 buffer are checked for a match.
4517 If no matching mapping is found FALSE is returned.
4518 The following characters are recognized in {mode}:
4519 n Normal mode
4520 v Visual and Select mode
4521 x Visual mode
4522 s Select mode
4523 o Operator-pending mode
4524 i Insert mode
4525 l Language-Argument ("r", "f", "t", etc.)
4526 c Command-line mode
4527 When {mode} is omitted, "nvo" is used.
4528
4529 This function is useful to check if a mapping already exists
4530 to a function in a Vim script. Example: >
4531 :if !hasmapto('\ABCdoit')
4532 : map <Leader>d \ABCdoit
4533 :endif
4534< This installs the mapping to "\ABCdoit" only if there isn't
4535 already a mapping to "\ABCdoit".
4536
4537 Can also be used as a |method|: >
4538 GetRHS()->hasmapto()
4539
4540histadd({history}, {item}) *histadd()*
4541 Add the String {item} to the history {history} which can be
4542 one of: *hist-names*
4543 "cmd" or ":" command line history
4544 "search" or "/" search pattern history
4545 "expr" or "=" typed expression history
4546 "input" or "@" input line history
4547 "debug" or ">" debug command history
4548 empty the current or last used history
4549 The {history} string does not need to be the whole name, one
4550 character is sufficient.
4551 If {item} does already exist in the history, it will be
4552 shifted to become the newest entry.
4553 The result is a Number: TRUE if the operation was successful,
4554 otherwise FALSE is returned.
4555
4556 Example: >
4557 :call histadd("input", strftime("%Y %b %d"))
4558 :let date=input("Enter date: ")
4559< This function is not available in the |sandbox|.
4560
4561 Can also be used as a |method|, the base is passed as the
4562 second argument: >
4563 GetHistory()->histadd('search')
4564
4565histdel({history} [, {item}]) *histdel()*
4566 Clear {history}, i.e. delete all its entries. See |hist-names|
4567 for the possible values of {history}.
4568
4569 If the parameter {item} evaluates to a String, it is used as a
4570 regular expression. All entries matching that expression will
4571 be removed from the history (if there are any).
4572 Upper/lowercase must match, unless "\c" is used |/\c|.
4573 If {item} evaluates to a Number, it will be interpreted as
4574 an index, see |:history-indexing|. The respective entry will
4575 be removed if it exists.
4576
4577 The result is TRUE for a successful operation, otherwise FALSE
4578 is returned.
4579
4580 Examples:
4581 Clear expression register history: >
4582 :call histdel("expr")
4583<
4584 Remove all entries starting with "*" from the search history: >
4585 :call histdel("/", '^\*')
4586<
4587 The following three are equivalent: >
4588 :call histdel("search", histnr("search"))
4589 :call histdel("search", -1)
Bram Moolenaarc51cf032022-02-26 12:25:45 +00004590 :call histdel("search", '^' .. histget("search", -1) .. '$')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004591<
4592 To delete the last search pattern and use the last-but-one for
4593 the "n" command and 'hlsearch': >
4594 :call histdel("search", -1)
4595 :let @/ = histget("search", -1)
4596<
4597 Can also be used as a |method|: >
4598 GetHistory()->histdel()
4599
4600histget({history} [, {index}]) *histget()*
4601 The result is a String, the entry with Number {index} from
4602 {history}. See |hist-names| for the possible values of
4603 {history}, and |:history-indexing| for {index}. If there is
4604 no such entry, an empty String is returned. When {index} is
4605 omitted, the most recent item from the history is used.
4606
4607 Examples:
4608 Redo the second last search from history. >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00004609 :execute '/' .. histget("search", -2)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004610
4611< Define an Ex command ":H {num}" that supports re-execution of
4612 the {num}th entry from the output of |:history|. >
4613 :command -nargs=1 H execute histget("cmd", 0+<args>)
4614<
4615 Can also be used as a |method|: >
4616 GetHistory()->histget()
4617
4618histnr({history}) *histnr()*
4619 The result is the Number of the current entry in {history}.
4620 See |hist-names| for the possible values of {history}.
4621 If an error occurred, -1 is returned.
4622
4623 Example: >
4624 :let inp_index = histnr("expr")
4625
4626< Can also be used as a |method|: >
4627 GetHistory()->histnr()
4628<
4629hlexists({name}) *hlexists()*
4630 The result is a Number, which is TRUE if a highlight group
4631 called {name} exists. This is when the group has been
4632 defined in some way. Not necessarily when highlighting has
4633 been defined for it, it may also have been used for a syntax
4634 item.
4635 *highlight_exists()*
4636 Obsolete name: highlight_exists().
4637
4638 Can also be used as a |method|: >
4639 GetName()->hlexists()
4640<
4641hlget([{name} [, {resolve}]]) *hlget()*
4642 Returns a List of all the highlight group attributes. If the
4643 optional {name} is specified, then returns a List with only
4644 the attributes of the specified highlight group. Returns an
4645 empty List if the highlight group {name} is not present.
4646
4647 If the optional {resolve} argument is set to v:true and the
4648 highlight group {name} is linked to another group, then the
4649 link is resolved recursively and the attributes of the
4650 resolved highlight group are returned.
4651
4652 Each entry in the returned List is a Dictionary with the
4653 following items:
4654 cleared boolean flag, set to v:true if the highlight
4655 group attributes are cleared or not yet
4656 specified. See |highlight-clear|.
4657 cterm cterm attributes. See |highlight-cterm|.
4658 ctermbg cterm background color.
4659 See |highlight-ctermbg|.
4660 ctermfg cterm foreground color.
4661 See |highlight-ctermfg|.
4662 ctermul cterm underline color. See |highlight-ctermul|.
4663 default boolean flag, set to v:true if the highlight
4664 group link is a default link. See
4665 |highlight-default|.
4666 font highlight group font. See |highlight-font|.
4667 gui gui attributes. See |highlight-gui|.
4668 guibg gui background color. See |highlight-guibg|.
4669 guifg gui foreground color. See |highlight-guifg|.
4670 guisp gui special color. See |highlight-guisp|.
4671 id highlight group ID.
4672 linksto linked highlight group name.
4673 See |:highlight-link|.
4674 name highlight group name. See |group-name|.
4675 start start terminal keycode. See |highlight-start|.
4676 stop stop terminal keycode. See |highlight-stop|.
4677 term term attributes. See |highlight-term|.
4678
4679 The 'term', 'cterm' and 'gui' items in the above Dictionary
4680 have a dictionary value with the following optional boolean
4681 items: 'bold', 'standout', 'underline', 'undercurl', 'italic',
4682 'reverse', 'inverse' and 'strikethrough'.
4683
4684 Example(s): >
4685 :echo hlget()
4686 :echo hlget('ModeMsg')
4687 :echo hlget('Number', v:true)
4688<
4689 Can also be used as a |method|: >
4690 GetName()->hlget()
4691<
4692hlset({list}) *hlset()*
4693 Creates or modifies the attributes of a List of highlight
4694 groups. Each item in {list} is a dictionary containing the
4695 attributes of a highlight group. See |hlget()| for the list of
4696 supported items in this dictionary.
4697
4698 In addition to the items described in |hlget()|, the following
4699 additional items are supported in the dictionary:
4700
4701 force boolean flag to force the creation of
4702 a link for an existing highlight group
4703 with attributes.
4704
4705 The highlight group is identified using the 'name' item and
4706 the 'id' item (if supplied) is ignored. If a highlight group
4707 with a specified name doesn't exist, then it is created.
4708 Otherwise the attributes of an existing highlight group are
4709 modified.
4710
4711 If an empty dictionary value is used for the 'term' or 'cterm'
4712 or 'gui' entries, then the corresponding attributes are
4713 cleared. If the 'cleared' item is set to v:true, then all the
4714 attributes of the highlight group are cleared.
4715
4716 The 'linksto' item can be used to link a highlight group to
4717 another highlight group. See |:highlight-link|.
4718
4719 Returns zero for success, -1 for failure.
4720
4721 Example(s): >
4722 " add bold attribute to the Visual highlight group
4723 :call hlset([#{name: 'Visual',
4724 \ term: #{reverse: 1 , bold: 1}}])
4725 :call hlset([#{name: 'Type', guifg: 'DarkGreen'}])
4726 :let l = hlget()
4727 :call hlset(l)
4728 " clear the Search highlight group
4729 :call hlset([#{name: 'Search', cleared: v:true}])
4730 " clear the 'term' attributes for a highlight group
4731 :call hlset([#{name: 'Title', term: {}}])
4732 " create the MyHlg group linking it to DiffAdd
4733 :call hlset([#{name: 'MyHlg', linksto: 'DiffAdd'}])
4734 " remove the MyHlg group link
4735 :call hlset([#{name: 'MyHlg', linksto: 'NONE'}])
4736 " clear the attributes and a link
4737 :call hlset([#{name: 'MyHlg', cleared: v:true,
4738 \ linksto: 'NONE'}])
4739<
4740 Can also be used as a |method|: >
4741 GetAttrList()->hlset()
4742<
4743 *hlID()*
4744hlID({name}) The result is a Number, which is the ID of the highlight group
4745 with name {name}. When the highlight group doesn't exist,
4746 zero is returned.
4747 This can be used to retrieve information about the highlight
4748 group. For example, to get the background color of the
4749 "Comment" group: >
4750 :echo synIDattr(synIDtrans(hlID("Comment")), "bg")
4751< *highlightID()*
4752 Obsolete name: highlightID().
4753
4754 Can also be used as a |method|: >
4755 GetName()->hlID()
4756
4757hostname() *hostname()*
4758 The result is a String, which is the name of the machine on
4759 which Vim is currently running. Machine names greater than
4760 256 characters long are truncated.
4761
4762iconv({string}, {from}, {to}) *iconv()*
4763 The result is a String, which is the text {string} converted
4764 from encoding {from} to encoding {to}.
4765 When the conversion completely fails an empty string is
4766 returned. When some characters could not be converted they
4767 are replaced with "?".
4768 The encoding names are whatever the iconv() library function
4769 can accept, see ":!man 3 iconv".
4770 Most conversions require Vim to be compiled with the |+iconv|
4771 feature. Otherwise only UTF-8 to latin1 conversion and back
4772 can be done.
4773 This can be used to display messages with special characters,
4774 no matter what 'encoding' is set to. Write the message in
4775 UTF-8 and use: >
4776 echo iconv(utf8_str, "utf-8", &enc)
4777< Note that Vim uses UTF-8 for all Unicode encodings, conversion
4778 from/to UCS-2 is automatically changed to use UTF-8. You
4779 cannot use UCS-2 in a string anyway, because of the NUL bytes.
4780
4781 Can also be used as a |method|: >
4782 GetText()->iconv('latin1', 'utf-8')
4783<
4784 *indent()*
4785indent({lnum}) The result is a Number, which is indent of line {lnum} in the
4786 current buffer. The indent is counted in spaces, the value
4787 of 'tabstop' is relevant. {lnum} is used just like in
4788 |getline()|.
4789 When {lnum} is invalid -1 is returned. In |Vim9| script an
4790 error is given.
4791
4792 Can also be used as a |method|: >
4793 GetLnum()->indent()
4794
4795index({object}, {expr} [, {start} [, {ic}]]) *index()*
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01004796 Find {expr} in {object} and return its index. See
Yegappan Lakshmanan3fbf6cd2022-08-13 21:35:13 +01004797 |indexof()| for using a lambda to select the item.
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01004798
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004799 If {object} is a |List| return the lowest index where the item
4800 has a value equal to {expr}. There is no automatic
4801 conversion, so the String "4" is different from the Number 4.
4802 And the number 4 is different from the Float 4.0. The value
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01004803 of 'ignorecase' is not used here, case matters as indicated by
4804 the {ic} argument.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004805
4806 If {object} is |Blob| return the lowest index where the byte
4807 value is equal to {expr}.
4808
4809 If {start} is given then start looking at the item with index
4810 {start} (may be negative for an item relative to the end).
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01004811
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004812 When {ic} is given and it is |TRUE|, ignore case. Otherwise
4813 case must match.
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01004814
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004815 -1 is returned when {expr} is not found in {object}.
4816 Example: >
4817 :let idx = index(words, "the")
4818 :if index(numbers, 123) >= 0
4819
4820< Can also be used as a |method|: >
4821 GetObject()->index(what)
4822
Yegappan Lakshmanan3fbf6cd2022-08-13 21:35:13 +01004823indexof({object}, {expr} [, {opts}]) *indexof()*
4824 Returns the index of an item in {object} where {expr} is
4825 v:true. {object} must be a |List| or a |Blob|.
4826
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01004827 If {object} is a |List|, evaluate {expr} for each item in the
Yegappan Lakshmanan3fbf6cd2022-08-13 21:35:13 +01004828 List until the expression is v:true and return the index of
4829 this item.
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01004830
4831 If {object} is a |Blob| evaluate {expr} for each byte in the
Yegappan Lakshmanan3fbf6cd2022-08-13 21:35:13 +01004832 Blob until the expression is v:true and return the index of
4833 this byte.
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01004834
4835 {expr} must be a |string| or |Funcref|.
4836
4837 If {expr} is a |string|: If {object} is a |List|, inside
4838 {expr} |v:key| has the index of the current List item and
4839 |v:val| has the value of the item. If {object} is a |Blob|,
4840 inside {expr} |v:key| has the index of the current byte and
4841 |v:val| has the byte value.
4842
4843 If {expr} is a |Funcref| it must take two arguments:
4844 1. the key or the index of the current item.
4845 2. the value of the current item.
4846 The function must return |TRUE| if the item is found and the
4847 search should stop.
4848
Yegappan Lakshmanan3fbf6cd2022-08-13 21:35:13 +01004849 The optional argument {opts} is a Dict and supports the
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01004850 following items:
Yegappan Lakshmanan3fbf6cd2022-08-13 21:35:13 +01004851 startidx start evaluating {expr} at the item with this
4852 index; may be negative for an item relative to
4853 the end
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01004854 Returns -1 when {expr} evaluates to v:false for all the items.
4855 Example: >
Yegappan Lakshmanan3fbf6cd2022-08-13 21:35:13 +01004856 :let l = [#{n: 10}, #{n: 20}, #{n: 30}]
4857 :echo indexof(l, "v:val.n == 20")
4858 :echo indexof(l, {i, v -> v.n == 30})
4859 :echo indexof(l, "v:val.n == 20", #{startidx: 1})
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01004860
4861< Can also be used as a |method|: >
4862 mylist->indexof(expr)
4863
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004864input({prompt} [, {text} [, {completion}]]) *input()*
4865 The result is a String, which is whatever the user typed on
4866 the command-line. The {prompt} argument is either a prompt
4867 string, or a blank string (for no prompt). A '\n' can be used
4868 in the prompt to start a new line.
4869 The highlighting set with |:echohl| is used for the prompt.
4870 The input is entered just like a command-line, with the same
4871 editing commands and mappings. There is a separate history
4872 for lines typed for input().
4873 Example: >
4874 :if input("Coffee or beer? ") == "beer"
4875 : echo "Cheers!"
4876 :endif
4877<
4878 If the optional {text} argument is present and not empty, this
4879 is used for the default reply, as if the user typed this.
4880 Example: >
4881 :let color = input("Color? ", "white")
4882
4883< The optional {completion} argument specifies the type of
4884 completion supported for the input. Without it completion is
4885 not performed. The supported completion types are the same as
4886 that can be supplied to a user-defined command using the
4887 "-complete=" argument. Refer to |:command-completion| for
4888 more information. Example: >
4889 let fname = input("File: ", "", "file")
4890<
4891 NOTE: This function must not be used in a startup file, for
4892 the versions that only run in GUI mode (e.g., the Win32 GUI).
4893 Note: When input() is called from within a mapping it will
4894 consume remaining characters from that mapping, because a
4895 mapping is handled like the characters were typed.
4896 Use |inputsave()| before input() and |inputrestore()|
4897 after input() to avoid that. Another solution is to avoid
4898 that further characters follow in the mapping, e.g., by using
4899 |:execute| or |:normal|.
4900
4901 Example with a mapping: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00004902 :nmap \x :call GetFoo()<CR>:exe "/" .. Foo<CR>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004903 :function GetFoo()
4904 : call inputsave()
4905 : let g:Foo = input("enter search pattern: ")
4906 : call inputrestore()
4907 :endfunction
4908
4909< Can also be used as a |method|: >
4910 GetPrompt()->input()
4911
4912inputdialog({prompt} [, {text} [, {cancelreturn}]]) *inputdialog()*
4913 Like |input()|, but when the GUI is running and text dialogs
4914 are supported, a dialog window pops up to input the text.
4915 Example: >
4916 :let n = inputdialog("value for shiftwidth", shiftwidth())
4917 :if n != ""
4918 : let &sw = n
4919 :endif
4920< When the dialog is cancelled {cancelreturn} is returned. When
4921 omitted an empty string is returned.
4922 Hitting <Enter> works like pressing the OK button. Hitting
4923 <Esc> works like pressing the Cancel button.
4924 NOTE: Command-line completion is not supported.
4925
4926 Can also be used as a |method|: >
4927 GetPrompt()->inputdialog()
4928
4929inputlist({textlist}) *inputlist()*
4930 {textlist} must be a |List| of strings. This |List| is
4931 displayed, one string per line. The user will be prompted to
4932 enter a number, which is returned.
4933 The user can also select an item by clicking on it with the
4934 mouse, if the mouse is enabled in the command line ('mouse' is
4935 "a" or includes "c"). For the first string 0 is returned.
4936 When clicking above the first item a negative number is
4937 returned. When clicking on the prompt one more than the
4938 length of {textlist} is returned.
4939 Make sure {textlist} has less than 'lines' entries, otherwise
4940 it won't work. It's a good idea to put the entry number at
4941 the start of the string. And put a prompt in the first item.
4942 Example: >
4943 let color = inputlist(['Select color:', '1. red',
4944 \ '2. green', '3. blue'])
4945
4946< Can also be used as a |method|: >
4947 GetChoices()->inputlist()
4948
4949inputrestore() *inputrestore()*
4950 Restore typeahead that was saved with a previous |inputsave()|.
4951 Should be called the same number of times inputsave() is
4952 called. Calling it more often is harmless though.
4953 Returns TRUE when there is nothing to restore, FALSE otherwise.
4954
4955inputsave() *inputsave()*
4956 Preserve typeahead (also from mappings) and clear it, so that
4957 a following prompt gets input from the user. Should be
4958 followed by a matching inputrestore() after the prompt. Can
4959 be used several times, in which case there must be just as
4960 many inputrestore() calls.
4961 Returns TRUE when out of memory, FALSE otherwise.
4962
4963inputsecret({prompt} [, {text}]) *inputsecret()*
4964 This function acts much like the |input()| function with but
4965 two exceptions:
4966 a) the user's response will be displayed as a sequence of
4967 asterisks ("*") thereby keeping the entry secret, and
4968 b) the user's response will not be recorded on the input
4969 |history| stack.
4970 The result is a String, which is whatever the user actually
4971 typed on the command-line in response to the issued prompt.
4972 NOTE: Command-line completion is not supported.
4973
4974 Can also be used as a |method|: >
4975 GetPrompt()->inputsecret()
4976
4977insert({object}, {item} [, {idx}]) *insert()*
4978 When {object} is a |List| or a |Blob| insert {item} at the start
4979 of it.
4980
4981 If {idx} is specified insert {item} before the item with index
4982 {idx}. If {idx} is zero it goes before the first item, just
4983 like omitting {idx}. A negative {idx} is also possible, see
4984 |list-index|. -1 inserts just before the last item.
4985
4986 Returns the resulting |List| or |Blob|. Examples: >
4987 :let mylist = insert([2, 3, 5], 1)
4988 :call insert(mylist, 4, -1)
4989 :call insert(mylist, 6, len(mylist))
4990< The last example can be done simpler with |add()|.
4991 Note that when {item} is a |List| it is inserted as a single
4992 item. Use |extend()| to concatenate |Lists|.
4993
4994 Can also be used as a |method|: >
4995 mylist->insert(item)
4996
4997interrupt() *interrupt()*
4998 Interrupt script execution. It works more or less like the
4999 user typing CTRL-C, most commands won't execute and control
5000 returns to the user. This is useful to abort execution
5001 from lower down, e.g. in an autocommand. Example: >
5002 :function s:check_typoname(file)
5003 : if fnamemodify(a:file, ':t') == '['
5004 : echomsg 'Maybe typo'
5005 : call interrupt()
5006 : endif
5007 :endfunction
5008 :au BufWritePre * call s:check_typoname(expand('<amatch>'))
5009
5010invert({expr}) *invert()*
5011 Bitwise invert. The argument is converted to a number. A
5012 List, Dict or Float argument causes an error. Example: >
5013 :let bits = invert(bits)
5014< Can also be used as a |method|: >
5015 :let bits = bits->invert()
5016
Bram Moolenaar8a3b8052022-06-26 12:21:15 +01005017isabsolutepath({path}) *isabsolutepath()*
LemonBoydca1d402022-04-28 15:26:33 +01005018 The result is a Number, which is |TRUE| when {path} is an
5019 absolute path.
Bram Moolenaar8a3b8052022-06-26 12:21:15 +01005020 On Unix, a path is considered absolute when it starts with '/'.
LemonBoydca1d402022-04-28 15:26:33 +01005021 On MS-Windows, it is considered absolute when it starts with an
5022 optional drive prefix and is followed by a '\' or '/'. UNC paths
5023 are always absolute.
5024 Example: >
5025 echo isabsolutepath('/usr/share/') " 1
5026 echo isabsolutepath('./foobar') " 0
5027 echo isabsolutepath('C:\Windows') " 1
5028 echo isabsolutepath('foobar') " 0
5029 echo isabsolutepath('\\remote\file') " 1
Bram Moolenaar8a3b8052022-06-26 12:21:15 +01005030<
LemonBoydca1d402022-04-28 15:26:33 +01005031 Can also be used as a |method|: >
5032 GetName()->isabsolutepath()
5033
5034
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005035isdirectory({directory}) *isdirectory()*
5036 The result is a Number, which is |TRUE| when a directory
5037 with the name {directory} exists. If {directory} doesn't
5038 exist, or isn't a directory, the result is |FALSE|. {directory}
5039 is any expression, which is used as a String.
5040
5041 Can also be used as a |method|: >
5042 GetName()->isdirectory()
5043
5044isinf({expr}) *isinf()*
5045 Return 1 if {expr} is a positive infinity, or -1 a negative
5046 infinity, otherwise 0. >
5047 :echo isinf(1.0 / 0.0)
5048< 1 >
5049 :echo isinf(-1.0 / 0.0)
5050< -1
5051
5052 Can also be used as a |method|: >
5053 Compute()->isinf()
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005054
5055islocked({expr}) *islocked()* *E786*
5056 The result is a Number, which is |TRUE| when {expr} is the
5057 name of a locked variable.
5058 The string argument {expr} must be the name of a variable,
5059 |List| item or |Dictionary| entry, not the variable itself!
5060 Example: >
5061 :let alist = [0, ['a', 'b'], 2, 3]
5062 :lockvar 1 alist
5063 :echo islocked('alist') " 1
5064 :echo islocked('alist[1]') " 0
5065
Bram Moolenaar9da17d72022-02-09 21:50:44 +00005066< When {expr} is a variable that does not exist -1 is returned.
5067 If {expr} uses a range, list or dict index that is out of
5068 range or does not exist you get an error message. Use
5069 |exists()| to check for existence.
5070 In Vim9 script it does not work for local function variables.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005071
5072 Can also be used as a |method|: >
5073 GetName()->islocked()
5074
5075isnan({expr}) *isnan()*
5076 Return |TRUE| if {expr} is a float with value NaN. >
5077 echo isnan(0.0 / 0.0)
5078< 1
5079
5080 Can also be used as a |method|: >
5081 Compute()->isnan()
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005082
5083items({dict}) *items()*
5084 Return a |List| with all the key-value pairs of {dict}. Each
5085 |List| item is a list with two items: the key of a {dict}
5086 entry and the value of this entry. The |List| is in arbitrary
5087 order. Also see |keys()| and |values()|.
5088 Example: >
5089 for [key, value] in items(mydict)
Bram Moolenaarc51cf032022-02-26 12:25:45 +00005090 echo key .. ': ' .. value
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005091 endfor
5092
5093< Can also be used as a |method|: >
5094 mydict->items()
5095
5096job_ functions are documented here: |job-functions-details|
5097
5098
5099join({list} [, {sep}]) *join()*
5100 Join the items in {list} together into one String.
5101 When {sep} is specified it is put in between the items. If
5102 {sep} is omitted a single space is used.
5103 Note that {sep} is not added at the end. You might want to
5104 add it there too: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00005105 let lines = join(mylist, "\n") .. "\n"
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005106< String items are used as-is. |Lists| and |Dictionaries| are
5107 converted into a string like with |string()|.
5108 The opposite function is |split()|.
5109
5110 Can also be used as a |method|: >
5111 mylist->join()
5112
5113js_decode({string}) *js_decode()*
5114 This is similar to |json_decode()| with these differences:
5115 - Object key names do not have to be in quotes.
5116 - Strings can be in single quotes.
5117 - Empty items in an array (between two commas) are allowed and
5118 result in v:none items.
5119
5120 Can also be used as a |method|: >
5121 ReadObject()->js_decode()
5122
5123js_encode({expr}) *js_encode()*
5124 This is similar to |json_encode()| with these differences:
5125 - Object key names are not in quotes.
5126 - v:none items in an array result in an empty item between
5127 commas.
5128 For example, the Vim object:
5129 [1,v:none,{"one":1},v:none] ~
5130 Will be encoded as:
5131 [1,,{one:1},,] ~
5132 While json_encode() would produce:
5133 [1,null,{"one":1},null] ~
5134 This encoding is valid for JavaScript. It is more efficient
5135 than JSON, especially when using an array with optional items.
5136
5137 Can also be used as a |method|: >
5138 GetObject()->js_encode()
5139
Bram Moolenaar2f0936c2022-01-08 21:51:59 +00005140json_decode({string}) *json_decode()* *E491*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005141 This parses a JSON formatted string and returns the equivalent
5142 in Vim values. See |json_encode()| for the relation between
5143 JSON and Vim values.
5144 The decoding is permissive:
5145 - A trailing comma in an array and object is ignored, e.g.
5146 "[1, 2, ]" is the same as "[1, 2]".
5147 - Integer keys are accepted in objects, e.g. {1:2} is the
5148 same as {"1":2}.
5149 - More floating point numbers are recognized, e.g. "1." for
5150 "1.0", or "001.2" for "1.2". Special floating point values
5151 "Infinity", "-Infinity" and "NaN" (capitalization ignored)
5152 are accepted.
5153 - Leading zeroes in integer numbers are ignored, e.g. "012"
5154 for "12" or "-012" for "-12".
5155 - Capitalization is ignored in literal names null, true or
5156 false, e.g. "NULL" for "null", "True" for "true".
5157 - Control characters U+0000 through U+001F which are not
5158 escaped in strings are accepted, e.g. " " (tab
5159 character in string) for "\t".
5160 - An empty JSON expression or made of only spaces is accepted
5161 and results in v:none.
5162 - Backslash in an invalid 2-character sequence escape is
5163 ignored, e.g. "\a" is decoded as "a".
5164 - A correct surrogate pair in JSON strings should normally be
5165 a 12 character sequence such as "\uD834\uDD1E", but
5166 json_decode() silently accepts truncated surrogate pairs
5167 such as "\uD834" or "\uD834\u"
5168 *E938*
5169 A duplicate key in an object, valid in rfc7159, is not
5170 accepted by json_decode() as the result must be a valid Vim
5171 type, e.g. this fails: {"a":"b", "a":"c"}
5172
5173 Can also be used as a |method|: >
5174 ReadObject()->json_decode()
5175
5176json_encode({expr}) *json_encode()*
5177 Encode {expr} as JSON and return this as a string.
5178 The encoding is specified in:
5179 https://tools.ietf.org/html/rfc7159.html
Bram Moolenaara2baa732022-02-04 16:09:54 +00005180 Vim values are converted as follows: *E1161*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005181 |Number| decimal number
5182 |Float| floating point number
5183 Float nan "NaN"
5184 Float inf "Infinity"
5185 Float -inf "-Infinity"
5186 |String| in double quotes (possibly null)
5187 |Funcref| not possible, error
5188 |List| as an array (possibly null); when
5189 used recursively: []
5190 |Dict| as an object (possibly null); when
5191 used recursively: {}
5192 |Blob| as an array of the individual bytes
5193 v:false "false"
5194 v:true "true"
5195 v:none "null"
5196 v:null "null"
5197 Note that NaN and Infinity are passed on as values. This is
5198 missing in the JSON standard, but several implementations do
5199 allow it. If not then you will get an error.
Bram Moolenaarcbaff5e2022-04-08 17:45:08 +01005200 If a string contains an illegal character then the replacement
5201 character 0xfffd is used.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005202
5203 Can also be used as a |method|: >
5204 GetObject()->json_encode()
5205
5206keys({dict}) *keys()*
5207 Return a |List| with all the keys of {dict}. The |List| is in
5208 arbitrary order. Also see |items()| and |values()|.
5209
5210 Can also be used as a |method|: >
5211 mydict->keys()
5212
zeertzjqcdc83932022-09-12 13:38:41 +01005213keytrans({string}) *keytrans()*
5214 Turn the internal byte representation of keys into a form that
5215 can be used for |:map|. E.g. >
5216 :let xx = "\<C-Home>"
5217 :echo keytrans(xx)
5218< <C-Home>
5219
5220 Can also be used as a |method|: >
5221 "\<C-Home>"->keytrans()
5222
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005223< *len()* *E701*
5224len({expr}) The result is a Number, which is the length of the argument.
5225 When {expr} is a String or a Number the length in bytes is
5226 used, as with |strlen()|.
5227 When {expr} is a |List| the number of items in the |List| is
5228 returned.
5229 When {expr} is a |Blob| the number of bytes is returned.
5230 When {expr} is a |Dictionary| the number of entries in the
5231 |Dictionary| is returned.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01005232 Otherwise an error is given and returns zero.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005233
5234 Can also be used as a |method|: >
5235 mylist->len()
5236
5237< *libcall()* *E364* *E368*
5238libcall({libname}, {funcname}, {argument})
5239 Call function {funcname} in the run-time library {libname}
5240 with single argument {argument}.
5241 This is useful to call functions in a library that you
5242 especially made to be used with Vim. Since only one argument
5243 is possible, calling standard library functions is rather
5244 limited.
5245 The result is the String returned by the function. If the
5246 function returns NULL, this will appear as an empty string ""
5247 to Vim.
5248 If the function returns a number, use libcallnr()!
5249 If {argument} is a number, it is passed to the function as an
5250 int; if {argument} is a string, it is passed as a
5251 null-terminated string.
5252 This function will fail in |restricted-mode|.
5253
5254 libcall() allows you to write your own 'plug-in' extensions to
5255 Vim without having to recompile the program. It is NOT a
5256 means to call system functions! If you try to do so Vim will
5257 very probably crash.
5258
5259 For Win32, the functions you write must be placed in a DLL
5260 and use the normal C calling convention (NOT Pascal which is
5261 used in Windows System DLLs). The function must take exactly
5262 one parameter, either a character pointer or a long integer,
5263 and must return a character pointer or NULL. The character
5264 pointer returned must point to memory that will remain valid
5265 after the function has returned (e.g. in static data in the
5266 DLL). If it points to allocated memory, that memory will
5267 leak away. Using a static buffer in the function should work,
5268 it's then freed when the DLL is unloaded.
5269
5270 WARNING: If the function returns a non-valid pointer, Vim may
5271 crash! This also happens if the function returns a number,
5272 because Vim thinks it's a pointer.
5273 For Win32 systems, {libname} should be the filename of the DLL
5274 without the ".DLL" suffix. A full path is only required if
5275 the DLL is not in the usual places.
5276 For Unix: When compiling your own plugins, remember that the
5277 object code must be compiled as position-independent ('PIC').
5278 {only in Win32 and some Unix versions, when the |+libcall|
5279 feature is present}
5280 Examples: >
5281 :echo libcall("libc.so", "getenv", "HOME")
5282
5283< Can also be used as a |method|, the base is passed as the
5284 third argument: >
5285 GetValue()->libcall("libc.so", "getenv")
5286<
5287 *libcallnr()*
5288libcallnr({libname}, {funcname}, {argument})
5289 Just like |libcall()|, but used for a function that returns an
5290 int instead of a string.
5291 {only in Win32 on some Unix versions, when the |+libcall|
5292 feature is present}
5293 Examples: >
5294 :echo libcallnr("/usr/lib/libc.so", "getpid", "")
5295 :call libcallnr("libc.so", "printf", "Hello World!\n")
5296 :call libcallnr("libc.so", "sleep", 10)
5297<
5298 Can also be used as a |method|, the base is passed as the
5299 third argument: >
5300 GetValue()->libcallnr("libc.so", "printf")
5301<
5302
5303line({expr} [, {winid}]) *line()*
5304 The result is a Number, which is the line number of the file
5305 position given with {expr}. The {expr} argument is a string.
Bram Moolenaara2baa732022-02-04 16:09:54 +00005306 The accepted positions are: *E1209*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005307 . the cursor position
5308 $ the last line in the current buffer
5309 'x position of mark x (if the mark is not set, 0 is
5310 returned)
5311 w0 first line visible in current window (one if the
5312 display isn't updated, e.g. in silent Ex mode)
5313 w$ last line visible in current window (this is one
5314 less than "w0" if no lines are visible)
5315 v In Visual mode: the start of the Visual area (the
5316 cursor is the end). When not in Visual mode
5317 returns the cursor position. Differs from |'<| in
5318 that it's updated right away.
5319 Note that a mark in another file can be used. The line number
5320 then applies to another buffer.
5321 To get the column number use |col()|. To get both use
5322 |getpos()|.
5323 With the optional {winid} argument the values are obtained for
5324 that window instead of the current window.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01005325 Returns 0 for invalid values of {expr} and {winid}.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005326 Examples: >
5327 line(".") line number of the cursor
5328 line(".", winid) idem, in window "winid"
5329 line("'t") line number of mark t
Bram Moolenaarc51cf032022-02-26 12:25:45 +00005330 line("'" .. marker) line number of mark marker
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005331<
5332 To jump to the last known position when opening a file see
5333 |last-position-jump|.
5334
5335 Can also be used as a |method|: >
5336 GetValue()->line()
5337
5338line2byte({lnum}) *line2byte()*
5339 Return the byte count from the start of the buffer for line
5340 {lnum}. This includes the end-of-line character, depending on
5341 the 'fileformat' option for the current buffer. The first
5342 line returns 1. 'encoding' matters, 'fileencoding' is ignored.
5343 This can also be used to get the byte count for the line just
5344 below the last line: >
5345 line2byte(line("$") + 1)
5346< This is the buffer size plus one. If 'fileencoding' is empty
5347 it is the file size plus one. {lnum} is used like with
5348 |getline()|. When {lnum} is invalid, or the |+byte_offset|
5349 feature has been disabled at compile time, -1 is returned.
5350 Also see |byte2line()|, |go| and |:goto|.
5351
5352 Can also be used as a |method|: >
5353 GetLnum()->line2byte()
5354
5355lispindent({lnum}) *lispindent()*
5356 Get the amount of indent for line {lnum} according the lisp
5357 indenting rules, as with 'lisp'.
5358 The indent is counted in spaces, the value of 'tabstop' is
5359 relevant. {lnum} is used just like in |getline()|.
Bram Moolenaar8e145b82022-05-21 20:17:31 +01005360 When {lnum} is invalid -1 is returned. In |Vim9| script an
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005361 error is given.
5362
5363 Can also be used as a |method|: >
5364 GetLnum()->lispindent()
5365
5366list2blob({list}) *list2blob()*
5367 Return a Blob concatenating all the number values in {list}.
5368 Examples: >
5369 list2blob([1, 2, 3, 4]) returns 0z01020304
5370 list2blob([]) returns 0z
5371< Returns an empty Blob on error. If one of the numbers is
5372 negative or more than 255 error *E1239* is given.
5373
5374 |blob2list()| does the opposite.
5375
5376 Can also be used as a |method|: >
5377 GetList()->list2blob()
5378
5379list2str({list} [, {utf8}]) *list2str()*
5380 Convert each number in {list} to a character string can
5381 concatenate them all. Examples: >
5382 list2str([32]) returns " "
5383 list2str([65, 66, 67]) returns "ABC"
5384< The same can be done (slowly) with: >
5385 join(map(list, {nr, val -> nr2char(val)}), '')
5386< |str2list()| does the opposite.
5387
5388 When {utf8} is omitted or zero, the current 'encoding' is used.
5389 When {utf8} is TRUE, always return UTF-8 characters.
5390 With UTF-8 composing characters work as expected: >
5391 list2str([97, 769]) returns "á"
5392<
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01005393 Returns an empty string on error.
5394
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005395 Can also be used as a |method|: >
5396 GetList()->list2str()
5397
5398listener_add({callback} [, {buf}]) *listener_add()*
5399 Add a callback function that will be invoked when changes have
5400 been made to buffer {buf}.
5401 {buf} refers to a buffer name or number. For the accepted
5402 values, see |bufname()|. When {buf} is omitted the current
5403 buffer is used.
5404 Returns a unique ID that can be passed to |listener_remove()|.
5405
5406 The {callback} is invoked with five arguments:
Bram Moolenaar944697a2022-02-20 19:48:20 +00005407 bufnr the buffer that was changed
5408 start first changed line number
5409 end first line number below the change
5410 added number of lines added, negative if lines were
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005411 deleted
Bram Moolenaar944697a2022-02-20 19:48:20 +00005412 changes a List of items with details about the changes
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005413
5414 Example: >
5415 func Listener(bufnr, start, end, added, changes)
5416 echo 'lines ' .. a:start .. ' until ' .. a:end .. ' changed'
5417 endfunc
5418 call listener_add('Listener', bufnr)
5419
Bram Moolenaar944697a2022-02-20 19:48:20 +00005420< The List cannot be changed. Each item in "changes" is a
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005421 dictionary with these entries:
5422 lnum the first line number of the change
5423 end the first line below the change
5424 added number of lines added; negative if lines were
5425 deleted
5426 col first column in "lnum" that was affected by
5427 the change; one if unknown or the whole line
5428 was affected; this is a byte index, first
5429 character has a value of one.
Bram Moolenaar3c053a12022-10-16 13:11:12 +01005430 When lines are inserted (not when a line is split, e.g. by
5431 typing CR in Insert mode) the values are:
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005432 lnum line above which the new line is added
5433 end equal to "lnum"
5434 added number of lines inserted
5435 col 1
5436 When lines are deleted the values are:
5437 lnum the first deleted line
5438 end the line below the first deleted line, before
5439 the deletion was done
5440 added negative, number of lines deleted
5441 col 1
5442 When lines are changed:
5443 lnum the first changed line
5444 end the line below the last changed line
5445 added 0
5446 col first column with a change or 1
5447
5448 The entries are in the order the changes were made, thus the
5449 most recent change is at the end. The line numbers are valid
5450 when the callback is invoked, but later changes may make them
5451 invalid, thus keeping a copy for later might not work.
5452
5453 The {callback} is invoked just before the screen is updated,
5454 when |listener_flush()| is called or when a change is being
5455 made that changes the line count in a way it causes a line
5456 number in the list of changes to become invalid.
5457
5458 The {callback} is invoked with the text locked, see
5459 |textlock|. If you do need to make changes to the buffer, use
5460 a timer to do this later |timer_start()|.
5461
5462 The {callback} is not invoked when the buffer is first loaded.
5463 Use the |BufReadPost| autocmd event to handle the initial text
5464 of a buffer.
5465 The {callback} is also not invoked when the buffer is
5466 unloaded, use the |BufUnload| autocmd event for that.
5467
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01005468 Returns zero if {callback} or {buf} is invalid.
5469
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005470 Can also be used as a |method|, the base is passed as the
5471 second argument: >
5472 GetBuffer()->listener_add(callback)
5473
5474listener_flush([{buf}]) *listener_flush()*
5475 Invoke listener callbacks for buffer {buf}. If there are no
5476 pending changes then no callbacks are invoked.
5477
5478 {buf} refers to a buffer name or number. For the accepted
5479 values, see |bufname()|. When {buf} is omitted the current
5480 buffer is used.
5481
5482 Can also be used as a |method|: >
5483 GetBuffer()->listener_flush()
5484
5485listener_remove({id}) *listener_remove()*
5486 Remove a listener previously added with listener_add().
5487 Returns FALSE when {id} could not be found, TRUE when {id} was
5488 removed.
5489
5490 Can also be used as a |method|: >
5491 GetListenerId()->listener_remove()
5492
5493localtime() *localtime()*
5494 Return the current time, measured as seconds since 1st Jan
5495 1970. See also |strftime()|, |strptime()| and |getftime()|.
5496
5497
5498log({expr}) *log()*
5499 Return the natural logarithm (base e) of {expr} as a |Float|.
5500 {expr} must evaluate to a |Float| or a |Number| in the range
5501 (0, inf].
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01005502 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005503 Examples: >
5504 :echo log(10)
5505< 2.302585 >
5506 :echo log(exp(5))
5507< 5.0
5508
5509 Can also be used as a |method|: >
5510 Compute()->log()
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005511
5512
5513log10({expr}) *log10()*
5514 Return the logarithm of Float {expr} to base 10 as a |Float|.
5515 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01005516 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005517 Examples: >
5518 :echo log10(1000)
5519< 3.0 >
5520 :echo log10(0.01)
5521< -2.0
5522
5523 Can also be used as a |method|: >
5524 Compute()->log10()
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005525
5526luaeval({expr} [, {expr}]) *luaeval()*
5527 Evaluate Lua expression {expr} and return its result converted
5528 to Vim data structures. Second {expr} may hold additional
5529 argument accessible as _A inside first {expr}.
5530 Strings are returned as they are.
5531 Boolean objects are converted to numbers.
Bram Moolenaar73e28dc2022-09-17 21:08:33 +01005532 Numbers are converted to |Float| values.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005533 Dictionaries and lists obtained by vim.eval() are returned
5534 as-is.
5535 Other objects are returned as zero without any errors.
5536 See |lua-luaeval| for more details.
5537 Note that in a `:def` function local variables are not visible
5538 to {expr}.
5539
5540 Can also be used as a |method|: >
5541 GetExpr()->luaeval()
5542
5543< {only available when compiled with the |+lua| feature}
5544
5545map({expr1}, {expr2}) *map()*
5546 {expr1} must be a |List|, |String|, |Blob| or |Dictionary|.
Bram Moolenaar944697a2022-02-20 19:48:20 +00005547 When {expr1} is a |List| or |Dictionary|, replace each
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005548 item in {expr1} with the result of evaluating {expr2}.
5549 For a |Blob| each byte is replaced.
5550 For a |String|, each character, including composing
5551 characters, is replaced.
5552 If the item type changes you may want to use |mapnew()| to
5553 create a new List or Dictionary. This is required when using
5554 Vim9 script.
5555
5556 {expr2} must be a |String| or |Funcref|.
5557
5558 If {expr2} is a |String|, inside {expr2} |v:val| has the value
5559 of the current item. For a |Dictionary| |v:key| has the key
5560 of the current item and for a |List| |v:key| has the index of
5561 the current item. For a |Blob| |v:key| has the index of the
5562 current byte. For a |String| |v:key| has the index of the
5563 current character.
5564 Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00005565 :call map(mylist, '"> " .. v:val .. " <"')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005566< This puts "> " before and " <" after each item in "mylist".
5567
5568 Note that {expr2} is the result of an expression and is then
5569 used as an expression again. Often it is good to use a
5570 |literal-string| to avoid having to double backslashes. You
5571 still have to double ' quotes
5572
5573 If {expr2} is a |Funcref| it is called with two arguments:
5574 1. The key or the index of the current item.
5575 2. the value of the current item.
Bram Moolenaarb59ae592022-11-23 23:46:31 +00005576 With a legacy script lambda you don't get an error if it only
5577 accepts one argument, but with a Vim9 lambda you get "E1106:
5578 One argument too many", the number of arguments must match.
5579
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005580 The function must return the new value of the item. Example
5581 that changes each value by "key-value": >
5582 func KeyValue(key, val)
Bram Moolenaarc51cf032022-02-26 12:25:45 +00005583 return a:key .. '-' .. a:val
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005584 endfunc
5585 call map(myDict, function('KeyValue'))
5586< It is shorter when using a |lambda|: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00005587 call map(myDict, {key, val -> key .. '-' .. val})
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005588< If you do not use "val" you can leave it out: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00005589 call map(myDict, {key -> 'item: ' .. key})
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005590< If you do not use "key" you can use a short name: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00005591 call map(myDict, {_, val -> 'item: ' .. val})
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005592<
5593 The operation is done in-place for a |List| and |Dictionary|.
5594 If you want it to remain unmodified make a copy first: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00005595 :let tlist = map(copy(mylist), ' v:val .. "\t"')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005596
5597< Returns {expr1}, the |List| or |Dictionary| that was filtered,
5598 or a new |Blob| or |String|.
5599 When an error is encountered while evaluating {expr2} no
5600 further items in {expr1} are processed.
5601 When {expr2} is a Funcref errors inside a function are ignored,
5602 unless it was defined with the "abort" flag.
5603
5604 Can also be used as a |method|: >
5605 mylist->map(expr2)
5606
5607
5608maparg({name} [, {mode} [, {abbr} [, {dict}]]]) *maparg()*
5609 When {dict} is omitted or zero: Return the rhs of mapping
5610 {name} in mode {mode}. The returned String has special
5611 characters translated like in the output of the ":map" command
Ernie Rael09661202022-04-25 14:40:44 +01005612 listing. When {dict} is TRUE a dictionary is returned, see
5613 below. To get a list of all mappings see |maplist()|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005614
5615 When there is no mapping for {name}, an empty String is
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01005616 returned if {dict} is FALSE, otherwise returns an empty Dict.
5617 When the mapping for {name} is empty, then "<Nop>" is
5618 returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005619
5620 The {name} can have special key names, like in the ":map"
5621 command.
5622
5623 {mode} can be one of these strings:
5624 "n" Normal
5625 "v" Visual (including Select)
5626 "o" Operator-pending
5627 "i" Insert
5628 "c" Cmd-line
5629 "s" Select
5630 "x" Visual
5631 "l" langmap |language-mapping|
5632 "t" Terminal-Job
5633 "" Normal, Visual and Operator-pending
5634 When {mode} is omitted, the modes for "" are used.
5635
5636 When {abbr} is there and it is |TRUE| use abbreviations
5637 instead of mappings.
5638
5639 When {dict} is there and it is |TRUE| return a dictionary
5640 containing all the information of the mapping with the
Ernie Rael659c2402022-04-24 18:40:28 +01005641 following items: *mapping-dict*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005642 "lhs" The {lhs} of the mapping as it would be typed
5643 "lhsraw" The {lhs} of the mapping as raw bytes
5644 "lhsrawalt" The {lhs} of the mapping as raw bytes, alternate
5645 form, only present when it differs from "lhsraw"
5646 "rhs" The {rhs} of the mapping as typed.
5647 "silent" 1 for a |:map-silent| mapping, else 0.
5648 "noremap" 1 if the {rhs} of the mapping is not remappable.
5649 "script" 1 if mapping was defined with <script>.
5650 "expr" 1 for an expression mapping (|:map-<expr>|).
5651 "buffer" 1 for a buffer local mapping (|:map-local|).
5652 "mode" Modes for which the mapping is defined. In
5653 addition to the modes mentioned above, these
5654 characters will be used:
5655 " " Normal, Visual and Operator-pending
5656 "!" Insert and Commandline mode
5657 (|mapmode-ic|)
5658 "sid" The script local ID, used for <sid> mappings
5659 (|<SID>|).
Bram Moolenaara9528b32022-01-18 20:51:35 +00005660 "scriptversion" The version of the script. 999999 for
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01005661 |Vim9| script.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005662 "lnum" The line number in "sid", zero if unknown.
5663 "nowait" Do not wait for other, longer mappings.
5664 (|:map-<nowait>|).
Bram Moolenaar921bde82022-05-09 19:50:35 +01005665 "abbr" True if this is an abbreviation |abbreviations|.
Ernie Raeld8f5f762022-05-10 17:50:39 +01005666 "mode_bits" Vim's internal binary representation of "mode".
5667 |mapset()| ignores this; only "mode" is used.
5668 See |maplist()| for usage examples. The values
5669 are from src/vim.h and may change in the future.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005670
5671 The dictionary can be used to restore a mapping with
5672 |mapset()|.
5673
5674 The mappings local to the current buffer are checked first,
5675 then the global mappings.
5676 This function can be used to map a key even when it's already
5677 mapped, and have it do the original mapping too. Sketch: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00005678 exe 'nnoremap <Tab> ==' .. maparg('<Tab>', 'n')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005679
5680< Can also be used as a |method|: >
5681 GetKey()->maparg('n')
5682
5683mapcheck({name} [, {mode} [, {abbr}]]) *mapcheck()*
5684 Check if there is a mapping that matches with {name} in mode
5685 {mode}. See |maparg()| for {mode} and special names in
5686 {name}.
5687 When {abbr} is there and it is |TRUE| use abbreviations
5688 instead of mappings.
5689 A match happens with a mapping that starts with {name} and
5690 with a mapping which is equal to the start of {name}.
5691
5692 matches mapping "a" "ab" "abc" ~
5693 mapcheck("a") yes yes yes
5694 mapcheck("abc") yes yes yes
5695 mapcheck("ax") yes no no
5696 mapcheck("b") no no no
5697
5698 The difference with maparg() is that mapcheck() finds a
5699 mapping that matches with {name}, while maparg() only finds a
5700 mapping for {name} exactly.
5701 When there is no mapping that starts with {name}, an empty
5702 String is returned. If there is one, the RHS of that mapping
5703 is returned. If there are several mappings that start with
5704 {name}, the RHS of one of them is returned. This will be
5705 "<Nop>" if the RHS is empty.
5706 The mappings local to the current buffer are checked first,
5707 then the global mappings.
5708 This function can be used to check if a mapping can be added
5709 without being ambiguous. Example: >
5710 :if mapcheck("_vv") == ""
5711 : map _vv :set guifont=7x13<CR>
5712 :endif
5713< This avoids adding the "_vv" mapping when there already is a
5714 mapping for "_v" or for "_vvv".
5715
5716 Can also be used as a |method|: >
5717 GetKey()->mapcheck('n')
5718
5719
Ernie Rael09661202022-04-25 14:40:44 +01005720maplist([{abbr}]) *maplist()*
5721 Returns a |List| of all mappings. Each List item is a |Dict|,
5722 the same as what is returned by |maparg()|, see
5723 |mapping-dict|. When {abbr} is there and it is |TRUE| use
5724 abbreviations instead of mappings.
5725
5726 Example to show all mappings with 'MultiMatch' in rhs: >
5727 vim9script
5728 echo maplist()->filter(
5729 (_, m) => match(m.rhs, 'MultiMatch') >= 0)
Ernie Raeld8f5f762022-05-10 17:50:39 +01005730< It can be tricky to find mappings for particular |:map-modes|.
5731 |mapping-dict|'s "mode_bits" can simplify this. For example,
5732 the mode_bits for Normal, Insert or Command-line modes are
5733 0x19. To find all the mappings available in those modes you
5734 can do: >
5735 vim9script
5736 var saved_maps = []
5737 for m in maplist()
5738 if and(m.mode_bits, 0x19) != 0
5739 saved_maps->add(m)
5740 endif
5741 endfor
5742 echo saved_maps->mapnew((_, m) => m.lhs)
5743< The values of the mode_bits are defined in Vim's src/vim.h
5744 file and they can be discovered at runtime using
5745 |:map-commands| and "maplist()". Example: >
5746 vim9script
5747 omap xyzzy <Nop>
5748 var op_bit = maplist()->filter(
5749 (_, m) => m.lhs == 'xyzzy')[0].mode_bits
5750 ounmap xyzzy
5751 echo printf("Operator-pending mode bit: 0x%x", op_bit)
Ernie Rael09661202022-04-25 14:40:44 +01005752
5753
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005754mapnew({expr1}, {expr2}) *mapnew()*
5755 Like |map()| but instead of replacing items in {expr1} a new
5756 List or Dictionary is created and returned. {expr1} remains
5757 unchanged. Items can still be changed by {expr2}, if you
5758 don't want that use |deepcopy()| first.
5759
5760
5761mapset({mode}, {abbr}, {dict}) *mapset()*
Ernie Rael51d04d12022-05-04 15:40:22 +01005762mapset({dict})
5763 Restore a mapping from a dictionary, possibly returned by
5764 |maparg()| or |maplist()|. A buffer mapping, when dict.buffer
5765 is true, is set on the current buffer; it is up to the caller
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01005766 to ensure that the intended buffer is the current buffer. This
Ernie Rael51d04d12022-05-04 15:40:22 +01005767 feature allows copying mappings from one buffer to another.
5768 The dict.mode value may restore a single mapping that covers
5769 more than one mode, like with mode values of '!', ' ', 'nox',
5770 or 'v'. *E1276*
5771
5772 In the first form, {mode} and {abbr} should be the same as
5773 for the call to |maparg()|. *E460*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005774 {mode} is used to define the mode in which the mapping is set,
5775 not the "mode" entry in {dict}.
5776 Example for saving and restoring a mapping: >
5777 let save_map = maparg('K', 'n', 0, 1)
5778 nnoremap K somethingelse
5779 ...
5780 call mapset('n', 0, save_map)
5781< Note that if you are going to replace a map in several modes,
Ernie Rael51d04d12022-05-04 15:40:22 +01005782 e.g. with `:map!`, you need to save/restore the mapping for
5783 all of them, when they might differ.
5784
5785 In the second form, with {dict} as the only argument, mode
5786 and abbr are taken from the dict.
5787 Example: >
5788 vim9script
5789 var save_maps = maplist()->filter(
5790 (_, m) => m.lhs == 'K')
5791 nnoremap K somethingelse
5792 cnoremap K somethingelse2
5793 # ...
5794 unmap K
5795 for d in save_maps
5796 mapset(d)
5797 endfor
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005798
5799
5800match({expr}, {pat} [, {start} [, {count}]]) *match()*
5801 When {expr} is a |List| then this returns the index of the
5802 first item where {pat} matches. Each item is used as a
5803 String, |Lists| and |Dictionaries| are used as echoed.
5804
5805 Otherwise, {expr} is used as a String. The result is a
5806 Number, which gives the index (byte offset) in {expr} where
5807 {pat} matches.
5808
5809 A match at the first character or |List| item returns zero.
5810 If there is no match -1 is returned.
5811
5812 For getting submatches see |matchlist()|.
5813 Example: >
5814 :echo match("testing", "ing") " results in 4
5815 :echo match([1, 'x'], '\a') " results in 1
5816< See |string-match| for how {pat} is used.
5817 *strpbrk()*
5818 Vim doesn't have a strpbrk() function. But you can do: >
5819 :let sepidx = match(line, '[.,;: \t]')
5820< *strcasestr()*
5821 Vim doesn't have a strcasestr() function. But you can add
5822 "\c" to the pattern to ignore case: >
5823 :let idx = match(haystack, '\cneedle')
5824<
5825 If {start} is given, the search starts from byte index
5826 {start} in a String or item {start} in a |List|.
5827 The result, however, is still the index counted from the
5828 first character/item. Example: >
5829 :echo match("testing", "ing", 2)
5830< result is again "4". >
5831 :echo match("testing", "ing", 4)
5832< result is again "4". >
5833 :echo match("testing", "t", 2)
5834< result is "3".
5835 For a String, if {start} > 0 then it is like the string starts
5836 {start} bytes later, thus "^" will match at {start}. Except
5837 when {count} is given, then it's like matches before the
5838 {start} byte are ignored (this is a bit complicated to keep it
5839 backwards compatible).
5840 For a String, if {start} < 0, it will be set to 0. For a list
5841 the index is counted from the end.
5842 If {start} is out of range ({start} > strlen({expr}) for a
5843 String or {start} > len({expr}) for a |List|) -1 is returned.
5844
5845 When {count} is given use the {count}'th match. When a match
5846 is found in a String the search for the next one starts one
5847 character further. Thus this example results in 1: >
5848 echo match("testing", "..", 0, 2)
5849< In a |List| the search continues in the next item.
5850 Note that when {count} is added the way {start} works changes,
5851 see above.
5852
5853 See |pattern| for the patterns that are accepted.
5854 The 'ignorecase' option is used to set the ignore-caseness of
5855 the pattern. 'smartcase' is NOT used. The matching is always
5856 done like 'magic' is set and 'cpoptions' is empty.
5857 Note that a match at the start is preferred, thus when the
5858 pattern is using "*" (any number of matches) it tends to find
5859 zero matches at the start instead of a number of matches
5860 further down in the text.
5861
5862 Can also be used as a |method|: >
5863 GetText()->match('word')
5864 GetList()->match('word')
5865<
Bram Moolenaar2f0936c2022-01-08 21:51:59 +00005866 *matchadd()* *E290* *E798* *E799* *E801* *E957*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005867matchadd({group}, {pattern} [, {priority} [, {id} [, {dict}]]])
5868 Defines a pattern to be highlighted in the current window (a
5869 "match"). It will be highlighted with {group}. Returns an
5870 identification number (ID), which can be used to delete the
5871 match using |matchdelete()|. The ID is bound to the window.
5872 Matching is case sensitive and magic, unless case sensitivity
5873 or magicness are explicitly overridden in {pattern}. The
5874 'magic', 'smartcase' and 'ignorecase' options are not used.
5875 The "Conceal" value is special, it causes the match to be
5876 concealed.
5877
5878 The optional {priority} argument assigns a priority to the
5879 match. A match with a high priority will have its
5880 highlighting overrule that of a match with a lower priority.
5881 A priority is specified as an integer (negative numbers are no
5882 exception). If the {priority} argument is not specified, the
5883 default priority is 10. The priority of 'hlsearch' is zero,
5884 hence all matches with a priority greater than zero will
5885 overrule it. Syntax highlighting (see 'syntax') is a separate
5886 mechanism, and regardless of the chosen priority a match will
5887 always overrule syntax highlighting.
5888
5889 The optional {id} argument allows the request for a specific
5890 match ID. If a specified ID is already taken, an error
5891 message will appear and the match will not be added. An ID
5892 is specified as a positive integer (zero excluded). IDs 1, 2
5893 and 3 are reserved for |:match|, |:2match| and |:3match|,
Bram Moolenaar2ecbe532022-07-29 21:36:21 +01005894 respectively. 3 is reserved for use by the |matchparen|
5895 plugin.
Bram Moolenaarb529cfb2022-07-25 15:42:07 +01005896 If the {id} argument is not specified or -1, |matchadd()|
Bram Moolenaar9f573a82022-09-29 13:50:08 +01005897 automatically chooses a free ID, which is at least 1000.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005898
5899 The optional {dict} argument allows for further custom
5900 values. Currently this is used to specify a match specific
5901 conceal character that will be shown for |hl-Conceal|
5902 highlighted matches. The dict can have the following members:
5903
5904 conceal Special character to show instead of the
5905 match (only for |hl-Conceal| highlighted
5906 matches, see |:syn-cchar|)
5907 window Instead of the current window use the
5908 window with this number or window ID.
5909
5910 The number of matches is not limited, as it is the case with
5911 the |:match| commands.
5912
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01005913 Returns -1 on error.
5914
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005915 Example: >
5916 :highlight MyGroup ctermbg=green guibg=green
5917 :let m = matchadd("MyGroup", "TODO")
5918< Deletion of the pattern: >
5919 :call matchdelete(m)
5920
5921< A list of matches defined by |matchadd()| and |:match| are
5922 available from |getmatches()|. All matches can be deleted in
5923 one operation by |clearmatches()|.
5924
5925 Can also be used as a |method|: >
5926 GetGroup()->matchadd('TODO')
5927<
5928 *matchaddpos()*
5929matchaddpos({group}, {pos} [, {priority} [, {id} [, {dict}]]])
5930 Same as |matchadd()|, but requires a list of positions {pos}
5931 instead of a pattern. This command is faster than |matchadd()|
5932 because it does not require to handle regular expressions and
5933 sets buffer line boundaries to redraw screen. It is supposed
5934 to be used when fast match additions and deletions are
5935 required, for example to highlight matching parentheses.
5936
5937 {pos} is a list of positions. Each position can be one of
5938 these:
5939 - A number. This whole line will be highlighted. The first
5940 line has number 1.
5941 - A list with one number, e.g., [23]. The whole line with this
5942 number will be highlighted.
5943 - A list with two numbers, e.g., [23, 11]. The first number is
5944 the line number, the second one is the column number (first
5945 column is 1, the value must correspond to the byte index as
5946 |col()| would return). The character at this position will
5947 be highlighted.
5948 - A list with three numbers, e.g., [23, 11, 3]. As above, but
5949 the third number gives the length of the highlight in bytes.
5950
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01005951 Returns -1 on error.
5952
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005953 Example: >
5954 :highlight MyGroup ctermbg=green guibg=green
5955 :let m = matchaddpos("MyGroup", [[23, 24], 34])
5956< Deletion of the pattern: >
5957 :call matchdelete(m)
5958
5959< Matches added by |matchaddpos()| are returned by
5960 |getmatches()|.
5961
5962 Can also be used as a |method|: >
5963 GetGroup()->matchaddpos([23, 11])
5964
5965matcharg({nr}) *matcharg()*
5966 Selects the {nr} match item, as set with a |:match|,
5967 |:2match| or |:3match| command.
5968 Return a |List| with two elements:
5969 The name of the highlight group used
5970 The pattern used.
5971 When {nr} is not 1, 2 or 3 returns an empty |List|.
5972 When there is no match item set returns ['', ''].
5973 This is useful to save and restore a |:match|.
5974 Highlighting matches using the |:match| commands are limited
5975 to three matches. |matchadd()| does not have this limitation.
5976
5977 Can also be used as a |method|: >
5978 GetMatch()->matcharg()
5979
5980matchdelete({id} [, {win}) *matchdelete()* *E802* *E803*
5981 Deletes a match with ID {id} previously defined by |matchadd()|
5982 or one of the |:match| commands. Returns 0 if successful,
5983 otherwise -1. See example for |matchadd()|. All matches can
5984 be deleted in one operation by |clearmatches()|.
5985 If {win} is specified, use the window with this number or
5986 window ID instead of the current window.
5987
5988 Can also be used as a |method|: >
5989 GetMatch()->matchdelete()
5990
5991matchend({expr}, {pat} [, {start} [, {count}]]) *matchend()*
5992 Same as |match()|, but return the index of first character
5993 after the match. Example: >
5994 :echo matchend("testing", "ing")
5995< results in "7".
5996 *strspn()* *strcspn()*
5997 Vim doesn't have a strspn() or strcspn() function, but you can
5998 do it with matchend(): >
5999 :let span = matchend(line, '[a-zA-Z]')
6000 :let span = matchend(line, '[^a-zA-Z]')
6001< Except that -1 is returned when there are no matches.
6002
6003 The {start}, if given, has the same meaning as for |match()|. >
6004 :echo matchend("testing", "ing", 2)
6005< results in "7". >
6006 :echo matchend("testing", "ing", 5)
6007< result is "-1".
6008 When {expr} is a |List| the result is equal to |match()|.
6009
6010 Can also be used as a |method|: >
6011 GetText()->matchend('word')
6012
6013
6014matchfuzzy({list}, {str} [, {dict}]) *matchfuzzy()*
6015 If {list} is a list of strings, then returns a |List| with all
6016 the strings in {list} that fuzzy match {str}. The strings in
6017 the returned list are sorted based on the matching score.
6018
6019 The optional {dict} argument always supports the following
6020 items:
zeertzjq9af2bc02022-05-11 14:15:37 +01006021 matchseq When this item is present return only matches
6022 that contain the characters in {str} in the
6023 given sequence.
Kazuyuki Miyagi47f1a552022-06-17 18:30:03 +01006024 limit Maximum number of matches in {list} to be
6025 returned. Zero means no limit.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006026
6027 If {list} is a list of dictionaries, then the optional {dict}
6028 argument supports the following additional items:
Yasuhiro Matsumoto9029a6e2022-04-16 12:35:35 +01006029 key Key of the item which is fuzzy matched against
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006030 {str}. The value of this item should be a
6031 string.
6032 text_cb |Funcref| that will be called for every item
6033 in {list} to get the text for fuzzy matching.
6034 This should accept a dictionary item as the
6035 argument and return the text for that item to
6036 use for fuzzy matching.
6037
6038 {str} is treated as a literal string and regular expression
6039 matching is NOT supported. The maximum supported {str} length
6040 is 256.
6041
6042 When {str} has multiple words each separated by white space,
6043 then the list of strings that have all the words is returned.
6044
6045 If there are no matching strings or there is an error, then an
6046 empty list is returned. If length of {str} is greater than
6047 256, then returns an empty list.
6048
Yasuhiro Matsumoto9029a6e2022-04-16 12:35:35 +01006049 When {limit} is given, matchfuzzy() will find up to this
6050 number of matches in {list} and return them in sorted order.
6051
Bram Moolenaar1588bc82022-03-08 21:35:07 +00006052 Refer to |fuzzy-matching| for more information about fuzzy
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006053 matching strings.
6054
6055 Example: >
6056 :echo matchfuzzy(["clay", "crow"], "cay")
6057< results in ["clay"]. >
6058 :echo getbufinfo()->map({_, v -> v.name})->matchfuzzy("ndl")
6059< results in a list of buffer names fuzzy matching "ndl". >
6060 :echo getbufinfo()->matchfuzzy("ndl", {'key' : 'name'})
6061< results in a list of buffer information dicts with buffer
6062 names fuzzy matching "ndl". >
6063 :echo getbufinfo()->matchfuzzy("spl",
6064 \ {'text_cb' : {v -> v.name}})
6065< results in a list of buffer information dicts with buffer
6066 names fuzzy matching "spl". >
6067 :echo v:oldfiles->matchfuzzy("test")
6068< results in a list of file names fuzzy matching "test". >
6069 :let l = readfile("buffer.c")->matchfuzzy("str")
6070< results in a list of lines in "buffer.c" fuzzy matching "str". >
6071 :echo ['one two', 'two one']->matchfuzzy('two one')
6072< results in ['two one', 'one two']. >
6073 :echo ['one two', 'two one']->matchfuzzy('two one',
6074 \ {'matchseq': 1})
6075< results in ['two one'].
6076
6077matchfuzzypos({list}, {str} [, {dict}]) *matchfuzzypos()*
6078 Same as |matchfuzzy()|, but returns the list of matched
6079 strings, the list of character positions where characters
6080 in {str} matches and a list of matching scores. You can
6081 use |byteidx()| to convert a character position to a byte
6082 position.
6083
6084 If {str} matches multiple times in a string, then only the
6085 positions for the best match is returned.
6086
6087 If there are no matching strings or there is an error, then a
6088 list with three empty list items is returned.
6089
6090 Example: >
6091 :echo matchfuzzypos(['testing'], 'tsg')
6092< results in [['testing'], [[0, 2, 6]], [99]] >
6093 :echo matchfuzzypos(['clay', 'lacy'], 'la')
6094< results in [['lacy', 'clay'], [[0, 1], [1, 2]], [153, 133]] >
6095 :echo [{'text': 'hello', 'id' : 10}]->matchfuzzypos('ll', {'key' : 'text'})
6096< results in [[{'id': 10, 'text': 'hello'}], [[2, 3]], [127]]
6097
6098matchlist({expr}, {pat} [, {start} [, {count}]]) *matchlist()*
6099 Same as |match()|, but return a |List|. The first item in the
6100 list is the matched string, same as what matchstr() would
6101 return. Following items are submatches, like "\1", "\2", etc.
6102 in |:substitute|. When an optional submatch didn't match an
6103 empty string is used. Example: >
6104 echo matchlist('acd', '\(a\)\?\(b\)\?\(c\)\?\(.*\)')
6105< Results in: ['acd', 'a', '', 'c', 'd', '', '', '', '', '']
6106 When there is no match an empty list is returned.
6107
6108 You can pass in a List, but that is not very useful.
6109
6110 Can also be used as a |method|: >
6111 GetText()->matchlist('word')
6112
6113matchstr({expr}, {pat} [, {start} [, {count}]]) *matchstr()*
6114 Same as |match()|, but return the matched string. Example: >
6115 :echo matchstr("testing", "ing")
6116< results in "ing".
6117 When there is no match "" is returned.
6118 The {start}, if given, has the same meaning as for |match()|. >
6119 :echo matchstr("testing", "ing", 2)
6120< results in "ing". >
6121 :echo matchstr("testing", "ing", 5)
6122< result is "".
6123 When {expr} is a |List| then the matching item is returned.
6124 The type isn't changed, it's not necessarily a String.
6125
6126 Can also be used as a |method|: >
6127 GetText()->matchstr('word')
6128
6129matchstrpos({expr}, {pat} [, {start} [, {count}]]) *matchstrpos()*
6130 Same as |matchstr()|, but return the matched string, the start
6131 position and the end position of the match. Example: >
6132 :echo matchstrpos("testing", "ing")
6133< results in ["ing", 4, 7].
6134 When there is no match ["", -1, -1] is returned.
6135 The {start}, if given, has the same meaning as for |match()|. >
6136 :echo matchstrpos("testing", "ing", 2)
6137< results in ["ing", 4, 7]. >
6138 :echo matchstrpos("testing", "ing", 5)
6139< result is ["", -1, -1].
6140 When {expr} is a |List| then the matching item, the index
6141 of first item where {pat} matches, the start position and the
6142 end position of the match are returned. >
6143 :echo matchstrpos([1, '__x'], '\a')
6144< result is ["x", 1, 2, 3].
6145 The type isn't changed, it's not necessarily a String.
6146
6147 Can also be used as a |method|: >
6148 GetText()->matchstrpos('word')
6149<
6150
6151 *max()*
6152max({expr}) Return the maximum value of all items in {expr}. Example: >
6153 echo max([apples, pears, oranges])
6154
6155< {expr} can be a |List| or a |Dictionary|. For a Dictionary,
6156 it returns the maximum of all values in the Dictionary.
6157 If {expr} is neither a List nor a Dictionary, or one of the
6158 items in {expr} cannot be used as a Number this results in
6159 an error. An empty |List| or |Dictionary| results in zero.
6160
6161 Can also be used as a |method|: >
6162 mylist->max()
6163
6164
6165menu_info({name} [, {mode}]) *menu_info()*
6166 Return information about the specified menu {name} in
6167 mode {mode}. The menu name should be specified without the
6168 shortcut character ('&'). If {name} is "", then the top-level
6169 menu names are returned.
6170
6171 {mode} can be one of these strings:
6172 "n" Normal
6173 "v" Visual (including Select)
6174 "o" Operator-pending
6175 "i" Insert
6176 "c" Cmd-line
6177 "s" Select
6178 "x" Visual
6179 "t" Terminal-Job
6180 "" Normal, Visual and Operator-pending
6181 "!" Insert and Cmd-line
6182 When {mode} is omitted, the modes for "" are used.
6183
6184 Returns a |Dictionary| containing the following items:
6185 accel menu item accelerator text |menu-text|
6186 display display name (name without '&')
6187 enabled v:true if this menu item is enabled
6188 Refer to |:menu-enable|
6189 icon name of the icon file (for toolbar)
6190 |toolbar-icon|
6191 iconidx index of a built-in icon
6192 modes modes for which the menu is defined. In
6193 addition to the modes mentioned above, these
6194 characters will be used:
6195 " " Normal, Visual and Operator-pending
6196 name menu item name.
6197 noremenu v:true if the {rhs} of the menu item is not
6198 remappable else v:false.
6199 priority menu order priority |menu-priority|
6200 rhs right-hand-side of the menu item. The returned
6201 string has special characters translated like
6202 in the output of the ":menu" command listing.
6203 When the {rhs} of a menu item is empty, then
6204 "<Nop>" is returned.
6205 script v:true if script-local remapping of {rhs} is
6206 allowed else v:false. See |:menu-script|.
6207 shortcut shortcut key (character after '&' in
6208 the menu name) |menu-shortcut|
6209 silent v:true if the menu item is created
6210 with <silent> argument |:menu-silent|
6211 submenus |List| containing the names of
6212 all the submenus. Present only if the menu
6213 item has submenus.
6214
6215 Returns an empty dictionary if the menu item is not found.
6216
6217 Examples: >
6218 :echo menu_info('Edit.Cut')
6219 :echo menu_info('File.Save', 'n')
6220
6221 " Display the entire menu hierarchy in a buffer
6222 func ShowMenu(name, pfx)
6223 let m = menu_info(a:name)
6224 call append(line('$'), a:pfx .. m.display)
6225 for child in m->get('submenus', [])
6226 call ShowMenu(a:name .. '.' .. escape(child, '.'),
6227 \ a:pfx .. ' ')
6228 endfor
6229 endfunc
6230 new
6231 for topmenu in menu_info('').submenus
6232 call ShowMenu(topmenu, '')
6233 endfor
6234<
6235 Can also be used as a |method|: >
6236 GetMenuName()->menu_info('v')
6237
6238
6239< *min()*
6240min({expr}) Return the minimum value of all items in {expr}. Example: >
6241 echo min([apples, pears, oranges])
6242
6243< {expr} can be a |List| or a |Dictionary|. For a Dictionary,
6244 it returns the minimum of all values in the Dictionary.
6245 If {expr} is neither a List nor a Dictionary, or one of the
6246 items in {expr} cannot be used as a Number this results in
6247 an error. An empty |List| or |Dictionary| results in zero.
6248
6249 Can also be used as a |method|: >
6250 mylist->min()
6251
6252< *mkdir()* *E739*
6253mkdir({name} [, {path} [, {prot}]])
6254 Create directory {name}.
6255
Bram Moolenaar6f14da12022-09-07 21:30:44 +01006256 If {path} contains "p" then intermediate directories are
6257 created as necessary. Otherwise it must be "".
6258
6259 If {path} contains "D" then {name} is deleted at the end of
6260 the current function, as with: >
6261 defer delete({name}, 'd')
6262<
6263 If {path} contains "R" then {name} is deleted recursively at
6264 the end of the current function, as with: >
6265 defer delete({name}, 'rf')
6266< Note that when {name} has more than one part and "p" is used
6267 some directories may already exist. Only the first one that
6268 is created and what it contains is scheduled to be deleted.
6269 E.g. when using: >
6270 call mkdir('subdir/tmp/autoload', 'pR')
6271< and "subdir" already exists then "subdir/tmp" will be
6272 scheduled for deletion, like with: >
6273 defer delete('subdir/tmp', 'rf')
6274< Note that if scheduling the defer fails the directory is not
6275 deleted. This should only happen when out of memory.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006276
6277 If {prot} is given it is used to set the protection bits of
6278 the new directory. The default is 0o755 (rwxr-xr-x: r/w for
6279 the user, readable for others). Use 0o700 to make it
6280 unreadable for others. This is only used for the last part of
6281 {name}. Thus if you create /tmp/foo/bar then /tmp/foo will be
6282 created with 0o755.
6283 Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00006284 :call mkdir($HOME .. "/tmp/foo/bar", "p", 0o700)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006285
6286< This function is not available in the |sandbox|.
6287
6288 There is no error if the directory already exists and the "p"
6289 flag is passed (since patch 8.0.1708). However, without the
6290 "p" option the call will fail.
6291
6292 The function result is a Number, which is TRUE if the call was
6293 successful or FALSE if the directory creation failed or partly
6294 failed.
6295
6296 Not available on all systems. To check use: >
6297 :if exists("*mkdir")
6298
6299< Can also be used as a |method|: >
6300 GetName()->mkdir()
6301<
6302 *mode()*
6303mode([expr]) Return a string that indicates the current mode.
6304 If [expr] is supplied and it evaluates to a non-zero Number or
6305 a non-empty String (|non-zero-arg|), then the full mode is
6306 returned, otherwise only the first letter is returned.
6307 Also see |state()|.
6308
6309 n Normal
6310 no Operator-pending
6311 nov Operator-pending (forced characterwise |o_v|)
6312 noV Operator-pending (forced linewise |o_V|)
6313 noCTRL-V Operator-pending (forced blockwise |o_CTRL-V|);
6314 CTRL-V is one character
6315 niI Normal using |i_CTRL-O| in |Insert-mode|
6316 niR Normal using |i_CTRL-O| in |Replace-mode|
6317 niV Normal using |i_CTRL-O| in |Virtual-Replace-mode|
6318 nt Terminal-Normal (insert goes to Terminal-Job mode)
6319 v Visual by character
6320 vs Visual by character using |v_CTRL-O| in Select mode
6321 V Visual by line
6322 Vs Visual by line using |v_CTRL-O| in Select mode
6323 CTRL-V Visual blockwise
6324 CTRL-Vs Visual blockwise using |v_CTRL-O| in Select mode
6325 s Select by character
6326 S Select by line
6327 CTRL-S Select blockwise
6328 i Insert
6329 ic Insert mode completion |compl-generic|
6330 ix Insert mode |i_CTRL-X| completion
6331 R Replace |R|
6332 Rc Replace mode completion |compl-generic|
6333 Rx Replace mode |i_CTRL-X| completion
6334 Rv Virtual Replace |gR|
6335 Rvc Virtual Replace mode completion |compl-generic|
6336 Rvx Virtual Replace mode |i_CTRL-X| completion
6337 c Command-line editing
6338 cv Vim Ex mode |gQ|
6339 ce Normal Ex mode |Q|
6340 r Hit-enter prompt
6341 rm The -- more -- prompt
6342 r? A |:confirm| query of some sort
6343 ! Shell or external command is executing
6344 t Terminal-Job mode: keys go to the job
6345
6346 This is useful in the 'statusline' option or when used
6347 with |remote_expr()| In most other places it always returns
6348 "c" or "n".
6349 Note that in the future more modes and more specific modes may
6350 be added. It's better not to compare the whole string but only
6351 the leading character(s).
6352 Also see |visualmode()|.
6353
6354 Can also be used as a |method|: >
6355 DoFull()->mode()
6356
6357mzeval({expr}) *mzeval()*
6358 Evaluate MzScheme expression {expr} and return its result
6359 converted to Vim data structures.
6360 Numbers and strings are returned as they are.
6361 Pairs (including lists and improper lists) and vectors are
6362 returned as Vim |Lists|.
6363 Hash tables are represented as Vim |Dictionary| type with keys
6364 converted to strings.
6365 All other types are converted to string with display function.
6366 Examples: >
6367 :mz (define l (list 1 2 3))
6368 :mz (define h (make-hash)) (hash-set! h "list" l)
6369 :echo mzeval("l")
6370 :echo mzeval("h")
6371<
6372 Note that in a `:def` function local variables are not visible
6373 to {expr}.
6374
6375 Can also be used as a |method|: >
6376 GetExpr()->mzeval()
6377<
6378 {only available when compiled with the |+mzscheme| feature}
6379
6380nextnonblank({lnum}) *nextnonblank()*
6381 Return the line number of the first line at or below {lnum}
6382 that is not blank. Example: >
6383 if getline(nextnonblank(1)) =~ "Java"
6384< When {lnum} is invalid or there is no non-blank line at or
6385 below it, zero is returned.
6386 {lnum} is used like with |getline()|.
6387 See also |prevnonblank()|.
6388
6389 Can also be used as a |method|: >
6390 GetLnum()->nextnonblank()
6391
6392nr2char({expr} [, {utf8}]) *nr2char()*
6393 Return a string with a single character, which has the number
6394 value {expr}. Examples: >
6395 nr2char(64) returns "@"
6396 nr2char(32) returns " "
6397< When {utf8} is omitted or zero, the current 'encoding' is used.
6398 Example for "utf-8": >
6399 nr2char(300) returns I with bow character
6400< When {utf8} is TRUE, always return UTF-8 characters.
6401 Note that a NUL character in the file is specified with
6402 nr2char(10), because NULs are represented with newline
6403 characters. nr2char(0) is a real NUL and terminates the
6404 string, thus results in an empty string.
6405 To turn a list of character numbers into a string: >
6406 let list = [65, 66, 67]
6407 let str = join(map(list, {_, val -> nr2char(val)}), '')
6408< Result: "ABC"
6409
6410 Can also be used as a |method|: >
6411 GetNumber()->nr2char()
6412
6413or({expr}, {expr}) *or()*
6414 Bitwise OR on the two arguments. The arguments are converted
6415 to a number. A List, Dict or Float argument causes an error.
Bram Moolenaar5a6ec102022-05-27 21:58:00 +01006416 Also see `and()` and `xor()`.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006417 Example: >
6418 :let bits = or(bits, 0x80)
6419< Can also be used as a |method|: >
6420 :let bits = bits->or(0x80)
6421
Bram Moolenaar5a6ec102022-05-27 21:58:00 +01006422< Rationale: The reason this is a function and not using the "|"
6423 character like many languages, is that Vi has always used "|"
6424 to separate commands. In many places it would not be clear if
6425 "|" is an operator or a command separator.
6426
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006427
6428pathshorten({path} [, {len}]) *pathshorten()*
6429 Shorten directory names in the path {path} and return the
6430 result. The tail, the file name, is kept as-is. The other
6431 components in the path are reduced to {len} letters in length.
6432 If {len} is omitted or smaller than 1 then 1 is used (single
6433 letters). Leading '~' and '.' characters are kept. Examples: >
6434 :echo pathshorten('~/.vim/autoload/myfile.vim')
6435< ~/.v/a/myfile.vim ~
6436>
6437 :echo pathshorten('~/.vim/autoload/myfile.vim', 2)
6438< ~/.vi/au/myfile.vim ~
6439 It doesn't matter if the path exists or not.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01006440 Returns an empty string on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006441
6442 Can also be used as a |method|: >
6443 GetDirectories()->pathshorten()
6444
6445perleval({expr}) *perleval()*
6446 Evaluate Perl expression {expr} in scalar context and return
6447 its result converted to Vim data structures. If value can't be
6448 converted, it is returned as a string Perl representation.
6449 Note: If you want an array or hash, {expr} must return a
6450 reference to it.
6451 Example: >
6452 :echo perleval('[1 .. 4]')
6453< [1, 2, 3, 4]
6454
6455 Note that in a `:def` function local variables are not visible
6456 to {expr}.
6457
6458 Can also be used as a |method|: >
6459 GetExpr()->perleval()
6460
6461< {only available when compiled with the |+perl| feature}
6462
6463
6464popup_ functions are documented here: |popup-functions|
6465
6466
6467pow({x}, {y}) *pow()*
6468 Return the power of {x} to the exponent {y} as a |Float|.
6469 {x} and {y} must evaluate to a |Float| or a |Number|.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01006470 Returns 0.0 if {x} or {y} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006471 Examples: >
6472 :echo pow(3, 3)
6473< 27.0 >
6474 :echo pow(2, 16)
6475< 65536.0 >
6476 :echo pow(32, 0.20)
6477< 2.0
6478
6479 Can also be used as a |method|: >
6480 Compute()->pow(3)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006481
6482prevnonblank({lnum}) *prevnonblank()*
6483 Return the line number of the first line at or above {lnum}
6484 that is not blank. Example: >
6485 let ind = indent(prevnonblank(v:lnum - 1))
6486< When {lnum} is invalid or there is no non-blank line at or
6487 above it, zero is returned.
6488 {lnum} is used like with |getline()|.
6489 Also see |nextnonblank()|.
6490
6491 Can also be used as a |method|: >
6492 GetLnum()->prevnonblank()
6493
6494printf({fmt}, {expr1} ...) *printf()*
6495 Return a String with {fmt}, where "%" items are replaced by
6496 the formatted form of their respective arguments. Example: >
6497 printf("%4d: E%d %.30s", lnum, errno, msg)
6498< May result in:
6499 " 99: E42 asdfasdfasdfasdfasdfasdfasdfas" ~
6500
6501 When used as a |method| the base is passed as the second
6502 argument: >
6503 Compute()->printf("result: %d")
Bram Moolenaarcbaff5e2022-04-08 17:45:08 +01006504<
6505 You can use `call()` to pass the items as a list.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006506
Bram Moolenaarcbaff5e2022-04-08 17:45:08 +01006507 Often used items are:
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006508 %s string
6509 %6S string right-aligned in 6 display cells
6510 %6s string right-aligned in 6 bytes
6511 %.9s string truncated to 9 bytes
6512 %c single byte
6513 %d decimal number
6514 %5d decimal number padded with spaces to 5 characters
6515 %x hex number
6516 %04x hex number padded with zeros to at least 4 characters
6517 %X hex number using upper case letters
6518 %o octal number
6519 %08b binary number padded with zeros to at least 8 chars
6520 %f floating point number as 12.23, inf, -inf or nan
6521 %F floating point number as 12.23, INF, -INF or NAN
6522 %e floating point number as 1.23e3, inf, -inf or nan
6523 %E floating point number as 1.23E3, INF, -INF or NAN
6524 %g floating point number, as %f or %e depending on value
6525 %G floating point number, as %F or %E depending on value
6526 %% the % character itself
6527
6528 Conversion specifications start with '%' and end with the
6529 conversion type. All other characters are copied unchanged to
6530 the result.
6531
6532 The "%" starts a conversion specification. The following
6533 arguments appear in sequence:
6534
6535 % [flags] [field-width] [.precision] type
6536
6537 flags
6538 Zero or more of the following flags:
6539
6540 # The value should be converted to an "alternate
6541 form". For c, d, and s conversions, this option
6542 has no effect. For o conversions, the precision
6543 of the number is increased to force the first
6544 character of the output string to a zero (except
6545 if a zero value is printed with an explicit
6546 precision of zero).
6547 For b and B conversions, a non-zero result has
6548 the string "0b" (or "0B" for B conversions)
6549 prepended to it.
6550 For x and X conversions, a non-zero result has
6551 the string "0x" (or "0X" for X conversions)
6552 prepended to it.
6553
6554 0 (zero) Zero padding. For all conversions the converted
6555 value is padded on the left with zeros rather
6556 than blanks. If a precision is given with a
6557 numeric conversion (d, b, B, o, x, and X), the 0
6558 flag is ignored.
6559
6560 - A negative field width flag; the converted value
6561 is to be left adjusted on the field boundary.
6562 The converted value is padded on the right with
6563 blanks, rather than on the left with blanks or
6564 zeros. A - overrides a 0 if both are given.
6565
6566 ' ' (space) A blank should be left before a positive
6567 number produced by a signed conversion (d).
6568
6569 + A sign must always be placed before a number
6570 produced by a signed conversion. A + overrides
6571 a space if both are used.
6572
6573 field-width
6574 An optional decimal digit string specifying a minimum
6575 field width. If the converted value has fewer bytes
6576 than the field width, it will be padded with spaces on
6577 the left (or right, if the left-adjustment flag has
6578 been given) to fill out the field width. For the S
6579 conversion the count is in cells.
6580
6581 .precision
6582 An optional precision, in the form of a period '.'
6583 followed by an optional digit string. If the digit
6584 string is omitted, the precision is taken as zero.
6585 This gives the minimum number of digits to appear for
6586 d, o, x, and X conversions, the maximum number of
6587 bytes to be printed from a string for s conversions,
6588 or the maximum number of cells to be printed from a
6589 string for S conversions.
6590 For floating point it is the number of digits after
6591 the decimal point.
6592
6593 type
6594 A character that specifies the type of conversion to
6595 be applied, see below.
6596
6597 A field width or precision, or both, may be indicated by an
6598 asterisk '*' instead of a digit string. In this case, a
6599 Number argument supplies the field width or precision. A
6600 negative field width is treated as a left adjustment flag
6601 followed by a positive field width; a negative precision is
6602 treated as though it were missing. Example: >
6603 :echo printf("%d: %.*s", nr, width, line)
6604< This limits the length of the text used from "line" to
6605 "width" bytes.
6606
6607 The conversion specifiers and their meanings are:
6608
6609 *printf-d* *printf-b* *printf-B* *printf-o*
6610 *printf-x* *printf-X*
6611 dbBoxX The Number argument is converted to signed decimal
6612 (d), unsigned binary (b and B), unsigned octal (o), or
6613 unsigned hexadecimal (x and X) notation. The letters
6614 "abcdef" are used for x conversions; the letters
6615 "ABCDEF" are used for X conversions.
6616 The precision, if any, gives the minimum number of
6617 digits that must appear; if the converted value
6618 requires fewer digits, it is padded on the left with
6619 zeros.
6620 In no case does a non-existent or small field width
6621 cause truncation of a numeric field; if the result of
6622 a conversion is wider than the field width, the field
6623 is expanded to contain the conversion result.
6624 The 'h' modifier indicates the argument is 16 bits.
6625 The 'l' modifier indicates the argument is 32 bits.
6626 The 'L' modifier indicates the argument is 64 bits.
6627 Generally, these modifiers are not useful. They are
6628 ignored when type is known from the argument.
6629
6630 i alias for d
6631 D alias for ld
6632 U alias for lu
6633 O alias for lo
6634
6635 *printf-c*
6636 c The Number argument is converted to a byte, and the
6637 resulting character is written.
6638
6639 *printf-s*
6640 s The text of the String argument is used. If a
6641 precision is specified, no more bytes than the number
6642 specified are used.
6643 If the argument is not a String type, it is
6644 automatically converted to text with the same format
6645 as ":echo".
6646 *printf-S*
6647 S The text of the String argument is used. If a
6648 precision is specified, no more display cells than the
6649 number specified are used.
6650
6651 *printf-f* *E807*
6652 f F The Float argument is converted into a string of the
6653 form 123.456. The precision specifies the number of
6654 digits after the decimal point. When the precision is
6655 zero the decimal point is omitted. When the precision
6656 is not specified 6 is used. A really big number
6657 (out of range or dividing by zero) results in "inf"
6658 or "-inf" with %f (INF or -INF with %F).
6659 "0.0 / 0.0" results in "nan" with %f (NAN with %F).
6660 Example: >
6661 echo printf("%.2f", 12.115)
6662< 12.12
6663 Note that roundoff depends on the system libraries.
6664 Use |round()| when in doubt.
6665
6666 *printf-e* *printf-E*
6667 e E The Float argument is converted into a string of the
6668 form 1.234e+03 or 1.234E+03 when using 'E'. The
6669 precision specifies the number of digits after the
6670 decimal point, like with 'f'.
6671
6672 *printf-g* *printf-G*
6673 g G The Float argument is converted like with 'f' if the
6674 value is between 0.001 (inclusive) and 10000000.0
6675 (exclusive). Otherwise 'e' is used for 'g' and 'E'
6676 for 'G'. When no precision is specified superfluous
6677 zeroes and '+' signs are removed, except for the zero
6678 immediately after the decimal point. Thus 10000000.0
6679 results in 1.0e7.
6680
6681 *printf-%*
6682 % A '%' is written. No argument is converted. The
6683 complete conversion specification is "%%".
6684
6685 When a Number argument is expected a String argument is also
6686 accepted and automatically converted.
6687 When a Float or String argument is expected a Number argument
6688 is also accepted and automatically converted.
6689 Any other argument type results in an error message.
6690
6691 *E766* *E767*
6692 The number of {exprN} arguments must exactly match the number
6693 of "%" items. If there are not sufficient or too many
6694 arguments an error is given. Up to 18 arguments can be used.
6695
6696
6697prompt_getprompt({buf}) *prompt_getprompt()*
6698 Returns the effective prompt text for buffer {buf}. {buf} can
6699 be a buffer name or number. See |prompt-buffer|.
6700
6701 If the buffer doesn't exist or isn't a prompt buffer, an empty
6702 string is returned.
6703
6704 Can also be used as a |method|: >
6705 GetBuffer()->prompt_getprompt()
6706
6707< {only available when compiled with the |+channel| feature}
6708
6709
6710prompt_setcallback({buf}, {expr}) *prompt_setcallback()*
6711 Set prompt callback for buffer {buf} to {expr}. When {expr}
6712 is an empty string the callback is removed. This has only
6713 effect if {buf} has 'buftype' set to "prompt".
6714
6715 The callback is invoked when pressing Enter. The current
6716 buffer will always be the prompt buffer. A new line for a
6717 prompt is added before invoking the callback, thus the prompt
6718 for which the callback was invoked will be in the last but one
6719 line.
6720 If the callback wants to add text to the buffer, it must
6721 insert it above the last line, since that is where the current
6722 prompt is. This can also be done asynchronously.
6723 The callback is invoked with one argument, which is the text
6724 that was entered at the prompt. This can be an empty string
6725 if the user only typed Enter.
6726 Example: >
6727 call prompt_setcallback(bufnr(), function('s:TextEntered'))
6728 func s:TextEntered(text)
6729 if a:text == 'exit' || a:text == 'quit'
6730 stopinsert
6731 close
6732 else
Bram Moolenaarc51cf032022-02-26 12:25:45 +00006733 call append(line('$') - 1, 'Entered: "' .. a:text .. '"')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006734 " Reset 'modified' to allow the buffer to be closed.
6735 set nomodified
6736 endif
6737 endfunc
6738
6739< Can also be used as a |method|: >
6740 GetBuffer()->prompt_setcallback(callback)
6741
6742< {only available when compiled with the |+channel| feature}
6743
6744prompt_setinterrupt({buf}, {expr}) *prompt_setinterrupt()*
6745 Set a callback for buffer {buf} to {expr}. When {expr} is an
6746 empty string the callback is removed. This has only effect if
6747 {buf} has 'buftype' set to "prompt".
6748
6749 This callback will be invoked when pressing CTRL-C in Insert
6750 mode. Without setting a callback Vim will exit Insert mode,
6751 as in any buffer.
6752
6753 Can also be used as a |method|: >
6754 GetBuffer()->prompt_setinterrupt(callback)
6755
6756< {only available when compiled with the |+channel| feature}
6757
6758prompt_setprompt({buf}, {text}) *prompt_setprompt()*
6759 Set prompt for buffer {buf} to {text}. You most likely want
6760 {text} to end in a space.
6761 The result is only visible if {buf} has 'buftype' set to
6762 "prompt". Example: >
6763 call prompt_setprompt(bufnr(), 'command: ')
6764<
6765 Can also be used as a |method|: >
6766 GetBuffer()->prompt_setprompt('command: ')
6767
6768< {only available when compiled with the |+channel| feature}
6769
6770prop_ functions are documented here: |text-prop-functions|
6771
6772pum_getpos() *pum_getpos()*
6773 If the popup menu (see |ins-completion-menu|) is not visible,
6774 returns an empty |Dictionary|, otherwise, returns a
6775 |Dictionary| with the following keys:
6776 height nr of items visible
6777 width screen cells
6778 row top screen row (0 first row)
6779 col leftmost screen column (0 first col)
6780 size total nr of items
6781 scrollbar |TRUE| if scrollbar is visible
6782
6783 The values are the same as in |v:event| during
6784 |CompleteChanged|.
6785
6786pumvisible() *pumvisible()*
6787 Returns non-zero when the popup menu is visible, zero
6788 otherwise. See |ins-completion-menu|.
6789 This can be used to avoid some things that would remove the
6790 popup menu.
6791
6792py3eval({expr}) *py3eval()*
6793 Evaluate Python expression {expr} and return its result
6794 converted to Vim data structures.
6795 Numbers and strings are returned as they are (strings are
6796 copied though, Unicode strings are additionally converted to
6797 'encoding').
6798 Lists are represented as Vim |List| type.
6799 Dictionaries are represented as Vim |Dictionary| type with
6800 keys converted to strings.
6801 Note that in a `:def` function local variables are not visible
6802 to {expr}.
6803
6804 Can also be used as a |method|: >
6805 GetExpr()->py3eval()
6806
6807< {only available when compiled with the |+python3| feature}
6808
6809 *E858* *E859*
6810pyeval({expr}) *pyeval()*
6811 Evaluate Python expression {expr} and return its result
6812 converted to Vim data structures.
6813 Numbers and strings are returned as they are (strings are
6814 copied though).
6815 Lists are represented as Vim |List| type.
6816 Dictionaries are represented as Vim |Dictionary| type,
6817 non-string keys result in error.
6818 Note that in a `:def` function local variables are not visible
6819 to {expr}.
6820
6821 Can also be used as a |method|: >
6822 GetExpr()->pyeval()
6823
6824< {only available when compiled with the |+python| feature}
6825
6826pyxeval({expr}) *pyxeval()*
6827 Evaluate Python expression {expr} and return its result
6828 converted to Vim data structures.
6829 Uses Python 2 or 3, see |python_x| and 'pyxversion'.
6830 See also: |pyeval()|, |py3eval()|
6831
6832 Can also be used as a |method|: >
6833 GetExpr()->pyxeval()
6834
6835< {only available when compiled with the |+python| or the
6836 |+python3| feature}
6837
6838rand([{expr}]) *rand()* *random*
6839 Return a pseudo-random Number generated with an xoshiro128**
6840 algorithm using seed {expr}. The returned number is 32 bits,
6841 also on 64 bits systems, for consistency.
6842 {expr} can be initialized by |srand()| and will be updated by
6843 rand(). If {expr} is omitted, an internal seed value is used
6844 and updated.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01006845 Returns -1 if {expr} is invalid.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006846
6847 Examples: >
6848 :echo rand()
6849 :let seed = srand()
6850 :echo rand(seed)
6851 :echo rand(seed) % 16 " random number 0 - 15
6852<
6853
6854 *E726* *E727*
6855range({expr} [, {max} [, {stride}]]) *range()*
6856 Returns a |List| with Numbers:
6857 - If only {expr} is specified: [0, 1, ..., {expr} - 1]
6858 - If {max} is specified: [{expr}, {expr} + 1, ..., {max}]
6859 - If {stride} is specified: [{expr}, {expr} + {stride}, ...,
6860 {max}] (increasing {expr} with {stride} each time, not
6861 producing a value past {max}).
6862 When the maximum is one before the start the result is an
6863 empty list. When the maximum is more than one before the
6864 start this is an error.
6865 Examples: >
6866 range(4) " [0, 1, 2, 3]
6867 range(2, 4) " [2, 3, 4]
6868 range(2, 9, 3) " [2, 5, 8]
6869 range(2, -2, -1) " [2, 1, 0, -1, -2]
6870 range(0) " []
6871 range(2, 0) " error!
6872<
6873 Can also be used as a |method|: >
6874 GetExpr()->range()
6875<
6876
K.Takata11df3ae2022-10-19 14:02:40 +01006877readblob({fname} [, {offset} [, {size}]]) *readblob()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006878 Read file {fname} in binary mode and return a |Blob|.
K.Takata11df3ae2022-10-19 14:02:40 +01006879 If {offset} is specified, read the file from the specified
6880 offset. If it is a negative value, it is used as an offset
6881 from the end of the file. E.g., to read the last 12 bytes: >
6882 readblob('file.bin', -12)
6883< If {size} is specified, only the specified size will be read.
6884 E.g. to read the first 100 bytes of a file: >
6885 readblob('file.bin', 0, 100)
6886< If {size} is -1 or omitted, the whole data starting from
6887 {offset} will be read.
K.Takata43625762022-10-20 13:28:51 +01006888 This can be also used to read the data from a character device
6889 on Unix when {size} is explicitly set. Only if the device
6890 supports seeking {offset} can be used. Otherwise it should be
6891 zero. E.g. to read 10 bytes from a serial console: >
6892 readblob('/dev/ttyS0', 0, 10)
6893< When the file can't be opened an error message is given and
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006894 the result is an empty |Blob|.
Bram Moolenaar5b2a3d72022-10-21 11:25:30 +01006895 When the offset is beyond the end of the file the result is an
6896 empty blob.
6897 When trying to read more bytes than are available the result
6898 is truncated.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006899 Also see |readfile()| and |writefile()|.
6900
6901
6902readdir({directory} [, {expr} [, {dict}]]) *readdir()*
6903 Return a list with file and directory names in {directory}.
6904 You can also use |glob()| if you don't need to do complicated
6905 things, such as limiting the number of matches.
6906 The list will be sorted (case sensitive), see the {dict}
6907 argument below for changing the sort order.
6908
6909 When {expr} is omitted all entries are included.
6910 When {expr} is given, it is evaluated to check what to do:
6911 If {expr} results in -1 then no further entries will
6912 be handled.
6913 If {expr} results in 0 then this entry will not be
6914 added to the list.
6915 If {expr} results in 1 then this entry will be added
6916 to the list.
6917 The entries "." and ".." are always excluded.
6918 Each time {expr} is evaluated |v:val| is set to the entry name.
6919 When {expr} is a function the name is passed as the argument.
6920 For example, to get a list of files ending in ".txt": >
6921 readdir(dirname, {n -> n =~ '.txt$'})
6922< To skip hidden and backup files: >
6923 readdir(dirname, {n -> n !~ '^\.\|\~$'})
Bram Moolenaar6f4754b2022-01-23 12:07:04 +00006924< *E857*
6925 The optional {dict} argument allows for further custom
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006926 values. Currently this is used to specify if and how sorting
6927 should be performed. The dict can have the following members:
6928
6929 sort How to sort the result returned from the system.
6930 Valid values are:
6931 "none" do not sort (fastest method)
6932 "case" sort case sensitive (byte value of
6933 each character, technically, using
6934 strcmp()) (default)
6935 "icase" sort case insensitive (technically
6936 using strcasecmp())
6937 "collate" sort using the collation order
6938 of the "POSIX" or "C" |locale|
6939 (technically using strcoll())
6940 Other values are silently ignored.
6941
6942 For example, to get a list of all files in the current
6943 directory without sorting the individual entries: >
6944 readdir('.', '1', #{sort: 'none'})
6945< If you want to get a directory tree: >
6946 function! s:tree(dir)
6947 return {a:dir : map(readdir(a:dir),
6948 \ {_, x -> isdirectory(x) ?
Bram Moolenaarc51cf032022-02-26 12:25:45 +00006949 \ {x : s:tree(a:dir .. '/' .. x)} : x})}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006950 endfunction
6951 echo s:tree(".")
6952<
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01006953 Returns an empty List on error.
6954
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006955 Can also be used as a |method|: >
6956 GetDirName()->readdir()
6957<
6958readdirex({directory} [, {expr} [, {dict}]]) *readdirex()*
6959 Extended version of |readdir()|.
6960 Return a list of Dictionaries with file and directory
6961 information in {directory}.
6962 This is useful if you want to get the attributes of file and
6963 directory at the same time as getting a list of a directory.
6964 This is much faster than calling |readdir()| then calling
6965 |getfperm()|, |getfsize()|, |getftime()| and |getftype()| for
6966 each file and directory especially on MS-Windows.
6967 The list will by default be sorted by name (case sensitive),
6968 the sorting can be changed by using the optional {dict}
6969 argument, see |readdir()|.
6970
6971 The Dictionary for file and directory information has the
6972 following items:
6973 group Group name of the entry. (Only on Unix)
6974 name Name of the entry.
6975 perm Permissions of the entry. See |getfperm()|.
6976 size Size of the entry. See |getfsize()|.
6977 time Timestamp of the entry. See |getftime()|.
6978 type Type of the entry.
6979 On Unix, almost same as |getftype()| except:
6980 Symlink to a dir "linkd"
6981 Other symlink "link"
6982 On MS-Windows:
6983 Normal file "file"
6984 Directory "dir"
6985 Junction "junction"
6986 Symlink to a dir "linkd"
6987 Other symlink "link"
6988 Other reparse point "reparse"
6989 user User name of the entry's owner. (Only on Unix)
6990 On Unix, if the entry is a symlink, the Dictionary includes
6991 the information of the target (except the "type" item).
6992 On MS-Windows, it includes the information of the symlink
6993 itself because of performance reasons.
6994
6995 When {expr} is omitted all entries are included.
6996 When {expr} is given, it is evaluated to check what to do:
6997 If {expr} results in -1 then no further entries will
6998 be handled.
6999 If {expr} results in 0 then this entry will not be
7000 added to the list.
7001 If {expr} results in 1 then this entry will be added
7002 to the list.
7003 The entries "." and ".." are always excluded.
7004 Each time {expr} is evaluated |v:val| is set to a |Dictionary|
7005 of the entry.
7006 When {expr} is a function the entry is passed as the argument.
7007 For example, to get a list of files ending in ".txt": >
7008 readdirex(dirname, {e -> e.name =~ '.txt$'})
7009<
7010 For example, to get a list of all files in the current
7011 directory without sorting the individual entries: >
7012 readdirex(dirname, '1', #{sort: 'none'})
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007013<
7014 Can also be used as a |method|: >
7015 GetDirName()->readdirex()
7016<
7017
7018 *readfile()*
7019readfile({fname} [, {type} [, {max}]])
7020 Read file {fname} and return a |List|, each line of the file
7021 as an item. Lines are broken at NL characters. Macintosh
7022 files separated with CR will result in a single long line
7023 (unless a NL appears somewhere).
7024 All NUL characters are replaced with a NL character.
7025 When {type} contains "b" binary mode is used:
7026 - When the last line ends in a NL an extra empty list item is
7027 added.
7028 - No CR characters are removed.
7029 Otherwise:
7030 - CR characters that appear before a NL are removed.
7031 - Whether the last line ends in a NL or not does not matter.
7032 - When 'encoding' is Unicode any UTF-8 byte order mark is
7033 removed from the text.
7034 When {max} is given this specifies the maximum number of lines
7035 to be read. Useful if you only want to check the first ten
7036 lines of a file: >
7037 :for line in readfile(fname, '', 10)
7038 : if line =~ 'Date' | echo line | endif
7039 :endfor
7040< When {max} is negative -{max} lines from the end of the file
7041 are returned, or as many as there are.
7042 When {max} is zero the result is an empty list.
7043 Note that without {max} the whole file is read into memory.
7044 Also note that there is no recognition of encoding. Read a
7045 file into a buffer if you need to.
7046 Deprecated (use |readblob()| instead): When {type} contains
7047 "B" a |Blob| is returned with the binary data of the file
7048 unmodified.
7049 When the file can't be opened an error message is given and
7050 the result is an empty list.
7051 Also see |writefile()|.
7052
7053 Can also be used as a |method|: >
7054 GetFileName()->readfile()
7055
7056reduce({object}, {func} [, {initial}]) *reduce()* *E998*
7057 {func} is called for every item in {object}, which can be a
7058 |String|, |List| or a |Blob|. {func} is called with two
7059 arguments: the result so far and current item. After
Bram Moolenaarf10911e2022-01-29 22:20:48 +00007060 processing all items the result is returned. *E1132*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007061
7062 {initial} is the initial result. When omitted, the first item
7063 in {object} is used and {func} is first called for the second
7064 item. If {initial} is not given and {object} is empty no
7065 result can be computed, an E998 error is given.
7066
7067 Examples: >
7068 echo reduce([1, 3, 5], { acc, val -> acc + val })
7069 echo reduce(['x', 'y'], { acc, val -> acc .. val }, 'a')
7070 echo reduce(0z1122, { acc, val -> 2 * acc + val })
7071 echo reduce('xyz', { acc, val -> acc .. ',' .. val })
7072<
7073 Can also be used as a |method|: >
7074 echo mylist->reduce({ acc, val -> acc + val }, 0)
7075
7076
7077reg_executing() *reg_executing()*
7078 Returns the single letter name of the register being executed.
7079 Returns an empty string when no register is being executed.
7080 See |@|.
7081
7082reg_recording() *reg_recording()*
7083 Returns the single letter name of the register being recorded.
7084 Returns an empty string when not recording. See |q|.
7085
Bram Moolenaarf269eab2022-10-03 18:04:35 +01007086reltime()
7087reltime({start})
7088reltime({start}, {end}) *reltime()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007089 Return an item that represents a time value. The item is a
7090 list with items that depend on the system. In Vim 9 script
7091 list<any> can be used.
7092 The item can be passed to |reltimestr()| to convert it to a
Bram Moolenaarf269eab2022-10-03 18:04:35 +01007093 string or |reltimefloat()| to convert to a Float. For
7094 example, to see the time spent in function Work(): >
7095 var startTime = reltime()
7096 Work()
7097 echo startTime->reltime()->reltimestr()
7098<
Bram Moolenaar016188f2022-06-06 20:52:59 +01007099 Without an argument reltime() returns the current time (the
Bram Moolenaareb490412022-06-28 13:44:46 +01007100 representation is system-dependent, it can not be used as the
Bram Moolenaar016188f2022-06-06 20:52:59 +01007101 wall-clock time, see |localtime()| for that).
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007102 With one argument is returns the time passed since the time
7103 specified in the argument.
7104 With two arguments it returns the time passed between {start}
7105 and {end}.
7106
7107 The {start} and {end} arguments must be values returned by
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01007108 reltime(). If there is an error an empty List is returned in
7109 legacy script, in Vim9 script an error is given.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007110
7111 Can also be used as a |method|: >
7112 GetStart()->reltime()
7113<
7114 {only available when compiled with the |+reltime| feature}
7115
7116reltimefloat({time}) *reltimefloat()*
7117 Return a Float that represents the time value of {time}.
7118 Example: >
7119 let start = reltime()
7120 call MyFunction()
7121 let seconds = reltimefloat(reltime(start))
7122< See the note of reltimestr() about overhead.
7123 Also see |profiling|.
7124 If there is an error 0.0 is returned in legacy script, in Vim9
7125 script an error is given.
7126
7127 Can also be used as a |method|: >
7128 reltime(start)->reltimefloat()
7129
7130< {only available when compiled with the |+reltime| feature}
7131
7132reltimestr({time}) *reltimestr()*
7133 Return a String that represents the time value of {time}.
7134 This is the number of seconds, a dot and the number of
7135 microseconds. Example: >
7136 let start = reltime()
7137 call MyFunction()
7138 echo reltimestr(reltime(start))
7139< Note that overhead for the commands will be added to the time.
7140 The accuracy depends on the system.
7141 Leading spaces are used to make the string align nicely. You
7142 can use split() to remove it. >
7143 echo split(reltimestr(reltime(start)))[0]
7144< Also see |profiling|.
7145 If there is an error an empty string is returned in legacy
7146 script, in Vim9 script an error is given.
7147
7148 Can also be used as a |method|: >
7149 reltime(start)->reltimestr()
7150
7151< {only available when compiled with the |+reltime| feature}
7152
7153 *remote_expr()* *E449*
7154remote_expr({server}, {string} [, {idvar} [, {timeout}]])
Bram Moolenaar944697a2022-02-20 19:48:20 +00007155 Send the {string} to {server}. The {server} argument is a
7156 string, also see |{server}|.
7157
7158 The string is sent as an expression and the result is returned
7159 after evaluation. The result must be a String or a |List|. A
7160 |List| is turned into a String by joining the items with a
7161 line break in between (not at the end), like with join(expr,
7162 "\n").
7163
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007164 If {idvar} is present and not empty, it is taken as the name
7165 of a variable and a {serverid} for later use with
7166 |remote_read()| is stored there.
Bram Moolenaar944697a2022-02-20 19:48:20 +00007167
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007168 If {timeout} is given the read times out after this many
7169 seconds. Otherwise a timeout of 600 seconds is used.
Bram Moolenaar944697a2022-02-20 19:48:20 +00007170
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007171 See also |clientserver| |RemoteReply|.
7172 This function is not available in the |sandbox|.
7173 {only available when compiled with the |+clientserver| feature}
7174 Note: Any errors will cause a local error message to be issued
7175 and the result will be the empty string.
7176
7177 Variables will be evaluated in the global namespace,
7178 independent of a function currently being active. Except
7179 when in debug mode, then local function variables and
7180 arguments can be evaluated.
7181
7182 Examples: >
7183 :echo remote_expr("gvim", "2+2")
7184 :echo remote_expr("gvim1", "b:current_syntax")
7185<
7186 Can also be used as a |method|: >
7187 ServerName()->remote_expr(expr)
7188
7189remote_foreground({server}) *remote_foreground()*
7190 Move the Vim server with the name {server} to the foreground.
Bram Moolenaar944697a2022-02-20 19:48:20 +00007191 The {server} argument is a string, also see |{server}|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007192 This works like: >
7193 remote_expr({server}, "foreground()")
7194< Except that on Win32 systems the client does the work, to work
7195 around the problem that the OS doesn't always allow the server
7196 to bring itself to the foreground.
7197 Note: This does not restore the window if it was minimized,
7198 like foreground() does.
7199 This function is not available in the |sandbox|.
7200
7201 Can also be used as a |method|: >
7202 ServerName()->remote_foreground()
7203
Bram Moolenaarcbaff5e2022-04-08 17:45:08 +01007204< {only in the Win32, Motif and GTK GUI versions and the
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007205 Win32 console version}
7206
7207
7208remote_peek({serverid} [, {retvar}]) *remote_peek()*
7209 Returns a positive number if there are available strings
7210 from {serverid}. Copies any reply string into the variable
7211 {retvar} if specified. {retvar} must be a string with the
7212 name of a variable.
7213 Returns zero if none are available.
7214 Returns -1 if something is wrong.
7215 See also |clientserver|.
7216 This function is not available in the |sandbox|.
7217 {only available when compiled with the |+clientserver| feature}
7218 Examples: >
Bram Moolenaarf269eab2022-10-03 18:04:35 +01007219 :let repl = ""
7220 :echo "PEEK: " .. remote_peek(id, "repl") .. ": " .. repl
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007221
7222< Can also be used as a |method|: >
7223 ServerId()->remote_peek()
7224
7225remote_read({serverid}, [{timeout}]) *remote_read()*
7226 Return the oldest available reply from {serverid} and consume
7227 it. Unless a {timeout} in seconds is given, it blocks until a
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01007228 reply is available. Returns an empty string, if a reply is
7229 not available or on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007230 See also |clientserver|.
7231 This function is not available in the |sandbox|.
7232 {only available when compiled with the |+clientserver| feature}
7233 Example: >
7234 :echo remote_read(id)
7235
7236< Can also be used as a |method|: >
7237 ServerId()->remote_read()
7238<
7239 *remote_send()* *E241*
7240remote_send({server}, {string} [, {idvar}])
Bram Moolenaar944697a2022-02-20 19:48:20 +00007241 Send the {string} to {server}. The {server} argument is a
7242 string, also see |{server}|.
7243
7244 The string is sent as input keys and the function returns
7245 immediately. At the Vim server the keys are not mapped
7246 |:map|.
7247
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007248 If {idvar} is present, it is taken as the name of a variable
7249 and a {serverid} for later use with remote_read() is stored
7250 there.
Bram Moolenaar944697a2022-02-20 19:48:20 +00007251
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007252 See also |clientserver| |RemoteReply|.
7253 This function is not available in the |sandbox|.
7254 {only available when compiled with the |+clientserver| feature}
7255
7256 Note: Any errors will be reported in the server and may mess
7257 up the display.
7258 Examples: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00007259 :echo remote_send("gvim", ":DropAndReply " .. file, "serverid") ..
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007260 \ remote_read(serverid)
7261
7262 :autocmd NONE RemoteReply *
7263 \ echo remote_read(expand("<amatch>"))
Bram Moolenaarc51cf032022-02-26 12:25:45 +00007264 :echo remote_send("gvim", ":sleep 10 | echo " ..
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007265 \ 'server2client(expand("<client>"), "HELLO")<CR>')
7266<
7267 Can also be used as a |method|: >
7268 ServerName()->remote_send(keys)
7269<
7270 *remote_startserver()* *E941* *E942*
7271remote_startserver({name})
7272 Become the server {name}. This fails if already running as a
7273 server, when |v:servername| is not empty.
7274
7275 Can also be used as a |method|: >
7276 ServerName()->remote_startserver()
7277
7278< {only available when compiled with the |+clientserver| feature}
7279
Bram Moolenaarf269eab2022-10-03 18:04:35 +01007280remove({list}, {idx})
7281remove({list}, {idx}, {end}) *remove()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007282 Without {end}: Remove the item at {idx} from |List| {list} and
7283 return the item.
7284 With {end}: Remove items from {idx} to {end} (inclusive) and
7285 return a |List| with these items. When {idx} points to the same
7286 item as {end} a list with one item is returned. When {end}
7287 points to an item before {idx} this is an error.
7288 See |list-index| for possible values of {idx} and {end}.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01007289 Returns zero on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007290 Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00007291 :echo "last item: " .. remove(mylist, -1)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007292 :call remove(mylist, 0, 9)
7293<
7294 Use |delete()| to remove a file.
7295
7296 Can also be used as a |method|: >
7297 mylist->remove(idx)
7298
Bram Moolenaarf269eab2022-10-03 18:04:35 +01007299remove({blob}, {idx})
7300remove({blob}, {idx}, {end})
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007301 Without {end}: Remove the byte at {idx} from |Blob| {blob} and
7302 return the byte.
7303 With {end}: Remove bytes from {idx} to {end} (inclusive) and
7304 return a |Blob| with these bytes. When {idx} points to the same
7305 byte as {end} a |Blob| with one byte is returned. When {end}
7306 points to a byte before {idx} this is an error.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01007307 Returns zero on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007308 Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00007309 :echo "last byte: " .. remove(myblob, -1)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007310 :call remove(mylist, 0, 9)
7311
7312remove({dict}, {key})
7313 Remove the entry from {dict} with key {key} and return it.
7314 Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00007315 :echo "removed " .. remove(dict, "one")
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007316< If there is no {key} in {dict} this is an error.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01007317 Returns zero on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007318
7319rename({from}, {to}) *rename()*
7320 Rename the file by the name {from} to the name {to}. This
7321 should also work to move files across file systems. The
7322 result is a Number, which is 0 if the file was renamed
7323 successfully, and non-zero when the renaming failed.
7324 NOTE: If {to} exists it is overwritten without warning.
7325 This function is not available in the |sandbox|.
7326
7327 Can also be used as a |method|: >
7328 GetOldName()->rename(newname)
7329
7330repeat({expr}, {count}) *repeat()*
7331 Repeat {expr} {count} times and return the concatenated
7332 result. Example: >
7333 :let separator = repeat('-', 80)
7334< When {count} is zero or negative the result is empty.
Bakudankun375141e2022-09-09 18:46:47 +01007335 When {expr} is a |List| or a |Blob| the result is {expr}
7336 concatenated {count} times. Example: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007337 :let longlist = repeat(['a', 'b'], 3)
7338< Results in ['a', 'b', 'a', 'b', 'a', 'b'].
7339
7340 Can also be used as a |method|: >
7341 mylist->repeat(count)
7342
7343resolve({filename}) *resolve()* *E655*
7344 On MS-Windows, when {filename} is a shortcut (a .lnk file),
7345 returns the path the shortcut points to in a simplified form.
7346 When {filename} is a symbolic link or junction point, return
7347 the full path to the target. If the target of junction is
7348 removed, return {filename}.
7349 On Unix, repeat resolving symbolic links in all path
7350 components of {filename} and return the simplified result.
7351 To cope with link cycles, resolving of symbolic links is
7352 stopped after 100 iterations.
7353 On other systems, return the simplified {filename}.
7354 The simplification step is done as by |simplify()|.
7355 resolve() keeps a leading path component specifying the
7356 current directory (provided the result is still a relative
7357 path name) and also keeps a trailing path separator.
7358
7359 Can also be used as a |method|: >
7360 GetName()->resolve()
7361
7362reverse({object}) *reverse()*
7363 Reverse the order of items in {object} in-place.
7364 {object} can be a |List| or a |Blob|.
7365 Returns {object}.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01007366 Returns zero if {object} is not a List or a Blob.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007367 If you want an object to remain unmodified make a copy first: >
7368 :let revlist = reverse(copy(mylist))
7369< Can also be used as a |method|: >
7370 mylist->reverse()
7371
7372round({expr}) *round()*
7373 Round off {expr} to the nearest integral value and return it
7374 as a |Float|. If {expr} lies halfway between two integral
7375 values, then use the larger one (away from zero).
7376 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01007377 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007378 Examples: >
7379 echo round(0.456)
7380< 0.0 >
7381 echo round(4.5)
7382< 5.0 >
7383 echo round(-4.5)
7384< -5.0
7385
7386 Can also be used as a |method|: >
7387 Compute()->round()
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007388
7389rubyeval({expr}) *rubyeval()*
7390 Evaluate Ruby expression {expr} and return its result
7391 converted to Vim data structures.
7392 Numbers, floats and strings are returned as they are (strings
7393 are copied though).
7394 Arrays are represented as Vim |List| type.
7395 Hashes are represented as Vim |Dictionary| type.
7396 Other objects are represented as strings resulted from their
7397 "Object#to_s" method.
7398 Note that in a `:def` function local variables are not visible
7399 to {expr}.
7400
7401 Can also be used as a |method|: >
7402 GetRubyExpr()->rubyeval()
7403
7404< {only available when compiled with the |+ruby| feature}
7405
7406screenattr({row}, {col}) *screenattr()*
7407 Like |screenchar()|, but return the attribute. This is a rather
7408 arbitrary number that can only be used to compare to the
7409 attribute at other positions.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01007410 Returns -1 when row or col is out of range.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007411
7412 Can also be used as a |method|: >
7413 GetRow()->screenattr(col)
7414
7415screenchar({row}, {col}) *screenchar()*
7416 The result is a Number, which is the character at position
7417 [row, col] on the screen. This works for every possible
7418 screen position, also status lines, window separators and the
7419 command line. The top left position is row one, column one
7420 The character excludes composing characters. For double-byte
7421 encodings it may only be the first byte.
7422 This is mainly to be used for testing.
7423 Returns -1 when row or col is out of range.
7424
7425 Can also be used as a |method|: >
7426 GetRow()->screenchar(col)
7427
7428screenchars({row}, {col}) *screenchars()*
7429 The result is a |List| of Numbers. The first number is the same
7430 as what |screenchar()| returns. Further numbers are
7431 composing characters on top of the base character.
7432 This is mainly to be used for testing.
7433 Returns an empty List when row or col is out of range.
7434
7435 Can also be used as a |method|: >
7436 GetRow()->screenchars(col)
7437
7438screencol() *screencol()*
7439 The result is a Number, which is the current screen column of
7440 the cursor. The leftmost column has number 1.
7441 This function is mainly used for testing.
7442
7443 Note: Always returns the current screen column, thus if used
7444 in a command (e.g. ":echo screencol()") it will return the
7445 column inside the command line, which is 1 when the command is
7446 executed. To get the cursor position in the file use one of
7447 the following mappings: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00007448 nnoremap <expr> GG ":echom " .. screencol() .. "\n"
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007449 nnoremap <silent> GG :echom screencol()<CR>
7450 nnoremap GG <Cmd>echom screencol()<CR>
7451<
7452screenpos({winid}, {lnum}, {col}) *screenpos()*
7453 The result is a Dict with the screen position of the text
7454 character in window {winid} at buffer line {lnum} and column
7455 {col}. {col} is a one-based byte index.
7456 The Dict has these members:
7457 row screen row
7458 col first screen column
7459 endcol last screen column
7460 curscol cursor screen column
7461 If the specified position is not visible, all values are zero.
7462 The "endcol" value differs from "col" when the character
7463 occupies more than one screen cell. E.g. for a Tab "col" can
7464 be 1 and "endcol" can be 8.
7465 The "curscol" value is where the cursor would be placed. For
7466 a Tab it would be the same as "endcol", while for a double
7467 width character it would be the same as "col".
7468 The |conceal| feature is ignored here, the column numbers are
7469 as if 'conceallevel' is zero. You can set the cursor to the
7470 right position and use |screencol()| to get the value with
7471 |conceal| taken into account.
Bram Moolenaar944697a2022-02-20 19:48:20 +00007472 If the position is in a closed fold the screen position of the
7473 first character is returned, {col} is not used.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01007474 Returns an empty Dict if {winid} is invalid.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007475
7476 Can also be used as a |method|: >
7477 GetWinid()->screenpos(lnum, col)
7478
7479screenrow() *screenrow()*
7480 The result is a Number, which is the current screen row of the
7481 cursor. The top line has number one.
7482 This function is mainly used for testing.
7483 Alternatively you can use |winline()|.
7484
7485 Note: Same restrictions as with |screencol()|.
7486
7487screenstring({row}, {col}) *screenstring()*
7488 The result is a String that contains the base character and
7489 any composing characters at position [row, col] on the screen.
7490 This is like |screenchars()| but returning a String with the
7491 characters.
7492 This is mainly to be used for testing.
7493 Returns an empty String when row or col is out of range.
7494
7495 Can also be used as a |method|: >
7496 GetRow()->screenstring(col)
7497<
7498 *search()*
7499search({pattern} [, {flags} [, {stopline} [, {timeout} [, {skip}]]]])
7500 Search for regexp pattern {pattern}. The search starts at the
7501 cursor position (you can use |cursor()| to set it).
7502
7503 When a match has been found its line number is returned.
7504 If there is no match a 0 is returned and the cursor doesn't
7505 move. No error message is given.
7506
7507 {flags} is a String, which can contain these character flags:
7508 'b' search Backward instead of forward
7509 'c' accept a match at the Cursor position
7510 'e' move to the End of the match
7511 'n' do Not move the cursor
7512 'p' return number of matching sub-Pattern (see below)
7513 's' Set the ' mark at the previous location of the cursor
7514 'w' Wrap around the end of the file
7515 'W' don't Wrap around the end of the file
7516 'z' start searching at the cursor column instead of zero
7517 If neither 'w' or 'W' is given, the 'wrapscan' option applies.
7518
7519 If the 's' flag is supplied, the ' mark is set, only if the
7520 cursor is moved. The 's' flag cannot be combined with the 'n'
7521 flag.
7522
7523 'ignorecase', 'smartcase' and 'magic' are used.
7524
7525 When the 'z' flag is not given, forward searching always
7526 starts in column zero and then matches before the cursor are
7527 skipped. When the 'c' flag is present in 'cpo' the next
7528 search starts after the match. Without the 'c' flag the next
Bram Moolenaarfd999452022-08-24 18:30:14 +01007529 search starts one column after the start of the match. This
7530 matters for overlapping matches. See |cpo-c|. You can also
7531 insert "\ze" to change where the match ends, see |/\ze|.
7532
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007533 When searching backwards and the 'z' flag is given then the
7534 search starts in column zero, thus no match in the current
7535 line will be found (unless wrapping around the end of the
7536 file).
7537
7538 When the {stopline} argument is given then the search stops
7539 after searching this line. This is useful to restrict the
7540 search to a range of lines. Examples: >
7541 let match = search('(', 'b', line("w0"))
7542 let end = search('END', '', line("w$"))
7543< When {stopline} is used and it is not zero this also implies
7544 that the search does not wrap around the end of the file.
7545 A zero value is equal to not giving the argument.
Bram Moolenaar2ecbe532022-07-29 21:36:21 +01007546 *E1285* *E1286* *E1287* *E1288* *E1289*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007547 When the {timeout} argument is given the search stops when
7548 more than this many milliseconds have passed. Thus when
7549 {timeout} is 500 the search stops after half a second.
7550 The value must not be negative. A zero value is like not
7551 giving the argument.
7552 {only available when compiled with the |+reltime| feature}
7553
7554 If the {skip} expression is given it is evaluated with the
7555 cursor positioned on the start of a match. If it evaluates to
7556 non-zero this match is skipped. This can be used, for
7557 example, to skip a match in a comment or a string.
7558 {skip} can be a string, which is evaluated as an expression, a
7559 function reference or a lambda.
7560 When {skip} is omitted or empty, every match is accepted.
7561 When evaluating {skip} causes an error the search is aborted
7562 and -1 returned.
7563 *search()-sub-match*
7564 With the 'p' flag the returned value is one more than the
7565 first sub-match in \(\). One if none of them matched but the
7566 whole pattern did match.
7567 To get the column number too use |searchpos()|.
7568
7569 The cursor will be positioned at the match, unless the 'n'
7570 flag is used.
7571
7572 Example (goes over all files in the argument list): >
7573 :let n = 1
7574 :while n <= argc() " loop over all files in arglist
Bram Moolenaarc51cf032022-02-26 12:25:45 +00007575 : exe "argument " .. n
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007576 : " start at the last char in the file and wrap for the
7577 : " first search to find match at start of file
7578 : normal G$
7579 : let flags = "w"
7580 : while search("foo", flags) > 0
7581 : s/foo/bar/g
7582 : let flags = "W"
7583 : endwhile
7584 : update " write the file if modified
7585 : let n = n + 1
7586 :endwhile
7587<
7588 Example for using some flags: >
7589 :echo search('\<if\|\(else\)\|\(endif\)', 'ncpe')
7590< This will search for the keywords "if", "else", and "endif"
7591 under or after the cursor. Because of the 'p' flag, it
7592 returns 1, 2, or 3 depending on which keyword is found, or 0
7593 if the search fails. With the cursor on the first word of the
7594 line:
7595 if (foo == 0) | let foo = foo + 1 | endif ~
7596 the function returns 1. Without the 'c' flag, the function
7597 finds the "endif" and returns 3. The same thing happens
7598 without the 'e' flag if the cursor is on the "f" of "if".
7599 The 'n' flag tells the function not to move the cursor.
7600
7601 Can also be used as a |method|: >
7602 GetPattern()->search()
7603
7604searchcount([{options}]) *searchcount()*
7605 Get or update the last search count, like what is displayed
7606 without the "S" flag in 'shortmess'. This works even if
7607 'shortmess' does contain the "S" flag.
7608
7609 This returns a |Dictionary|. The dictionary is empty if the
7610 previous pattern was not set and "pattern" was not specified.
7611
7612 key type meaning ~
7613 current |Number| current position of match;
7614 0 if the cursor position is
7615 before the first match
7616 exact_match |Boolean| 1 if "current" is matched on
7617 "pos", otherwise 0
7618 total |Number| total count of matches found
7619 incomplete |Number| 0: search was fully completed
7620 1: recomputing was timed out
7621 2: max count exceeded
7622
7623 For {options} see further down.
7624
7625 To get the last search count when |n| or |N| was pressed, call
7626 this function with `recompute: 0` . This sometimes returns
7627 wrong information because |n| and |N|'s maximum count is 99.
7628 If it exceeded 99 the result must be max count + 1 (100). If
7629 you want to get correct information, specify `recompute: 1`: >
7630
7631 " result == maxcount + 1 (100) when many matches
7632 let result = searchcount(#{recompute: 0})
7633
7634 " Below returns correct result (recompute defaults
7635 " to 1)
7636 let result = searchcount()
7637<
Bram Moolenaarb529cfb2022-07-25 15:42:07 +01007638 The function is useful to add the count to 'statusline': >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007639 function! LastSearchCount() abort
7640 let result = searchcount(#{recompute: 0})
7641 if empty(result)
7642 return ''
7643 endif
7644 if result.incomplete ==# 1 " timed out
7645 return printf(' /%s [?/??]', @/)
7646 elseif result.incomplete ==# 2 " max count exceeded
7647 if result.total > result.maxcount &&
7648 \ result.current > result.maxcount
7649 return printf(' /%s [>%d/>%d]', @/,
7650 \ result.current, result.total)
7651 elseif result.total > result.maxcount
7652 return printf(' /%s [%d/>%d]', @/,
7653 \ result.current, result.total)
7654 endif
7655 endif
7656 return printf(' /%s [%d/%d]', @/,
7657 \ result.current, result.total)
7658 endfunction
Bram Moolenaarc51cf032022-02-26 12:25:45 +00007659 let &statusline ..= '%{LastSearchCount()}'
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007660
7661 " Or if you want to show the count only when
7662 " 'hlsearch' was on
Bram Moolenaarc51cf032022-02-26 12:25:45 +00007663 " let &statusline ..=
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007664 " \ '%{v:hlsearch ? LastSearchCount() : ""}'
7665<
7666 You can also update the search count, which can be useful in a
7667 |CursorMoved| or |CursorMovedI| autocommand: >
7668
7669 autocmd CursorMoved,CursorMovedI *
7670 \ let s:searchcount_timer = timer_start(
7671 \ 200, function('s:update_searchcount'))
7672 function! s:update_searchcount(timer) abort
7673 if a:timer ==# s:searchcount_timer
7674 call searchcount(#{
7675 \ recompute: 1, maxcount: 0, timeout: 100})
7676 redrawstatus
7677 endif
7678 endfunction
7679<
7680 This can also be used to count matched texts with specified
7681 pattern in the current buffer using "pattern": >
7682
7683 " Count '\<foo\>' in this buffer
7684 " (Note that it also updates search count)
7685 let result = searchcount(#{pattern: '\<foo\>'})
7686
7687 " To restore old search count by old pattern,
7688 " search again
7689 call searchcount()
7690<
7691 {options} must be a |Dictionary|. It can contain:
7692 key type meaning ~
7693 recompute |Boolean| if |TRUE|, recompute the count
7694 like |n| or |N| was executed.
7695 otherwise returns the last
7696 computed result (when |n| or
7697 |N| was used when "S" is not
7698 in 'shortmess', or this
7699 function was called).
7700 (default: |TRUE|)
7701 pattern |String| recompute if this was given
7702 and different with |@/|.
7703 this works as same as the
7704 below command is executed
7705 before calling this function >
7706 let @/ = pattern
7707< (default: |@/|)
7708 timeout |Number| 0 or negative number is no
7709 timeout. timeout milliseconds
7710 for recomputing the result
7711 (default: 0)
7712 maxcount |Number| 0 or negative number is no
7713 limit. max count of matched
7714 text while recomputing the
7715 result. if search exceeded
7716 total count, "total" value
7717 becomes `maxcount + 1`
7718 (default: 99)
7719 pos |List| `[lnum, col, off]` value
7720 when recomputing the result.
7721 this changes "current" result
7722 value. see |cursor()|,
7723 |getpos()|
7724 (default: cursor's position)
7725
7726 Can also be used as a |method|: >
7727 GetSearchOpts()->searchcount()
7728<
7729searchdecl({name} [, {global} [, {thisblock}]]) *searchdecl()*
7730 Search for the declaration of {name}.
7731
7732 With a non-zero {global} argument it works like |gD|, find
7733 first match in the file. Otherwise it works like |gd|, find
7734 first match in the function.
7735
7736 With a non-zero {thisblock} argument matches in a {} block
7737 that ends before the cursor position are ignored. Avoids
7738 finding variable declarations only valid in another scope.
7739
7740 Moves the cursor to the found match.
7741 Returns zero for success, non-zero for failure.
7742 Example: >
7743 if searchdecl('myvar') == 0
7744 echo getline('.')
7745 endif
7746<
7747 Can also be used as a |method|: >
7748 GetName()->searchdecl()
7749<
7750 *searchpair()*
7751searchpair({start}, {middle}, {end} [, {flags} [, {skip}
7752 [, {stopline} [, {timeout}]]]])
7753 Search for the match of a nested start-end pair. This can be
7754 used to find the "endif" that matches an "if", while other
7755 if/endif pairs in between are ignored.
7756 The search starts at the cursor. The default is to search
7757 forward, include 'b' in {flags} to search backward.
7758 If a match is found, the cursor is positioned at it and the
7759 line number is returned. If no match is found 0 or -1 is
7760 returned and the cursor doesn't move. No error message is
7761 given.
7762
7763 {start}, {middle} and {end} are patterns, see |pattern|. They
7764 must not contain \( \) pairs. Use of \%( \) is allowed. When
7765 {middle} is not empty, it is found when searching from either
7766 direction, but only when not in a nested start-end pair. A
7767 typical use is: >
7768 searchpair('\<if\>', '\<else\>', '\<endif\>')
7769< By leaving {middle} empty the "else" is skipped.
7770
7771 {flags} 'b', 'c', 'n', 's', 'w' and 'W' are used like with
7772 |search()|. Additionally:
7773 'r' Repeat until no more matches found; will find the
7774 outer pair. Implies the 'W' flag.
7775 'm' Return number of matches instead of line number with
7776 the match; will be > 1 when 'r' is used.
7777 Note: it's nearly always a good idea to use the 'W' flag, to
7778 avoid wrapping around the end of the file.
7779
7780 When a match for {start}, {middle} or {end} is found, the
7781 {skip} expression is evaluated with the cursor positioned on
7782 the start of the match. It should return non-zero if this
7783 match is to be skipped. E.g., because it is inside a comment
7784 or a string.
7785 When {skip} is omitted or empty, every match is accepted.
7786 When evaluating {skip} causes an error the search is aborted
7787 and -1 returned.
7788 {skip} can be a string, a lambda, a funcref or a partial.
7789 Anything else makes the function fail.
7790 In a `:def` function when the {skip} argument is a string
7791 constant it is compiled into instructions.
7792
7793 For {stopline} and {timeout} see |search()|.
7794
7795 The value of 'ignorecase' is used. 'magic' is ignored, the
7796 patterns are used like it's on.
7797
7798 The search starts exactly at the cursor. A match with
7799 {start}, {middle} or {end} at the next character, in the
7800 direction of searching, is the first one found. Example: >
7801 if 1
7802 if 2
7803 endif 2
7804 endif 1
7805< When starting at the "if 2", with the cursor on the "i", and
7806 searching forwards, the "endif 2" is found. When starting on
7807 the character just before the "if 2", the "endif 1" will be
7808 found. That's because the "if 2" will be found first, and
7809 then this is considered to be a nested if/endif from "if 2" to
7810 "endif 2".
7811 When searching backwards and {end} is more than one character,
7812 it may be useful to put "\zs" at the end of the pattern, so
7813 that when the cursor is inside a match with the end it finds
7814 the matching start.
7815
7816 Example, to find the "endif" command in a Vim script: >
7817
7818 :echo searchpair('\<if\>', '\<el\%[seif]\>', '\<en\%[dif]\>', 'W',
7819 \ 'getline(".") =~ "^\\s*\""')
7820
7821< The cursor must be at or after the "if" for which a match is
7822 to be found. Note that single-quote strings are used to avoid
7823 having to double the backslashes. The skip expression only
7824 catches comments at the start of a line, not after a command.
7825 Also, a word "en" or "if" halfway a line is considered a
7826 match.
7827 Another example, to search for the matching "{" of a "}": >
7828
7829 :echo searchpair('{', '', '}', 'bW')
7830
7831< This works when the cursor is at or before the "}" for which a
7832 match is to be found. To reject matches that syntax
7833 highlighting recognized as strings: >
7834
7835 :echo searchpair('{', '', '}', 'bW',
7836 \ 'synIDattr(synID(line("."), col("."), 0), "name") =~? "string"')
7837<
7838 *searchpairpos()*
7839searchpairpos({start}, {middle}, {end} [, {flags} [, {skip}
7840 [, {stopline} [, {timeout}]]]])
7841 Same as |searchpair()|, but returns a |List| with the line and
7842 column position of the match. The first element of the |List|
7843 is the line number and the second element is the byte index of
7844 the column position of the match. If no match is found,
7845 returns [0, 0]. >
7846
7847 :let [lnum,col] = searchpairpos('{', '', '}', 'n')
7848<
7849 See |match-parens| for a bigger and more useful example.
7850
7851 *searchpos()*
7852searchpos({pattern} [, {flags} [, {stopline} [, {timeout} [, {skip}]]]])
7853 Same as |search()|, but returns a |List| with the line and
7854 column position of the match. The first element of the |List|
7855 is the line number and the second element is the byte index of
7856 the column position of the match. If no match is found,
7857 returns [0, 0].
7858 Example: >
7859 :let [lnum, col] = searchpos('mypattern', 'n')
7860
7861< When the 'p' flag is given then there is an extra item with
7862 the sub-pattern match number |search()-sub-match|. Example: >
7863 :let [lnum, col, submatch] = searchpos('\(\l\)\|\(\u\)', 'np')
7864< In this example "submatch" is 2 when a lowercase letter is
7865 found |/\l|, 3 when an uppercase letter is found |/\u|.
7866
7867 Can also be used as a |method|: >
7868 GetPattern()->searchpos()
7869
7870server2client({clientid}, {string}) *server2client()*
7871 Send a reply string to {clientid}. The most recent {clientid}
7872 that sent a string can be retrieved with expand("<client>").
7873 {only available when compiled with the |+clientserver| feature}
7874 Returns zero for success, -1 for failure.
7875 Note:
7876 This id has to be stored before the next command can be
7877 received. I.e. before returning from the received command and
7878 before calling any commands that waits for input.
7879 See also |clientserver|.
7880 Example: >
7881 :echo server2client(expand("<client>"), "HELLO")
7882
7883< Can also be used as a |method|: >
7884 GetClientId()->server2client(string)
7885<
7886serverlist() *serverlist()*
7887 Return a list of available server names, one per line.
7888 When there are no servers or the information is not available
7889 an empty string is returned. See also |clientserver|.
7890 {only available when compiled with the |+clientserver| feature}
7891 Example: >
7892 :echo serverlist()
7893<
7894setbufline({buf}, {lnum}, {text}) *setbufline()*
7895 Set line {lnum} to {text} in buffer {buf}. This works like
7896 |setline()| for the specified buffer.
7897
7898 This function works only for loaded buffers. First call
7899 |bufload()| if needed.
7900
7901 To insert lines use |appendbufline()|.
7902 Any text properties in {lnum} are cleared.
7903
Bram Moolenaarcd9c8d42022-11-05 23:46:43 +00007904 {text} can be a string to set one line, or a List of strings
7905 to set multiple lines. If the List extends below the last
7906 line then those lines are added. If the List is empty then
7907 nothing is changed and zero is returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007908
7909 For the use of {buf}, see |bufname()| above.
7910
7911 {lnum} is used like with |setline()|.
7912 Use "$" to refer to the last line in buffer {buf}.
7913 When {lnum} is just below the last line the {text} will be
7914 added below the last line.
7915
7916 When {buf} is not a valid buffer, the buffer is not loaded or
7917 {lnum} is not valid then 1 is returned. In |Vim9| script an
7918 error is given.
7919 On success 0 is returned.
7920
7921 Can also be used as a |method|, the base is passed as the
7922 third argument: >
7923 GetText()->setbufline(buf, lnum)
7924
7925setbufvar({buf}, {varname}, {val}) *setbufvar()*
7926 Set option or local variable {varname} in buffer {buf} to
7927 {val}.
7928 This also works for a global or local window option, but it
7929 doesn't work for a global or local window variable.
7930 For a local window option the global value is unchanged.
7931 For the use of {buf}, see |bufname()| above.
7932 The {varname} argument is a string.
7933 Note that the variable name without "b:" must be used.
7934 Examples: >
7935 :call setbufvar(1, "&mod", 1)
7936 :call setbufvar("todo", "myvar", "foobar")
7937< This function is not available in the |sandbox|.
7938
7939 Can also be used as a |method|, the base is passed as the
7940 third argument: >
7941 GetValue()->setbufvar(buf, varname)
7942
7943
7944setcellwidths({list}) *setcellwidths()*
7945 Specify overrides for cell widths of character ranges. This
Bram Moolenaarb59ae592022-11-23 23:46:31 +00007946 tells Vim how wide characters are when displayed in the
7947 terminal, counted in screen cells. The values override
7948 'ambiwidth'. Example: >
7949 call setcellwidths([
7950 \ [0x111, 0x111, 1],
7951 \ [0x2194, 0x2199, 2],
7952 \ ])
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007953
Bram Moolenaarb59ae592022-11-23 23:46:31 +00007954< The {list} argument is a List of Lists with each three
7955 numbers: [{low}, {high}, {width}]. *E1109* *E1110*
7956 {low} and {high} can be the same, in which case this refers to
7957 one character. Otherwise it is the range of characters from
7958 {low} to {high} (inclusive). *E1111* *E1114*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007959 Only characters with value 0x100 and higher can be used.
7960
Bram Moolenaarb59ae592022-11-23 23:46:31 +00007961 {width} must be either 1 or 2, indicating the character width
7962 in screen cells. *E1112*
7963 An error is given if the argument is invalid, also when a
7964 range overlaps with another. *E1113*
7965
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007966 If the new value causes 'fillchars' or 'listchars' to become
7967 invalid it is rejected and an error is given.
7968
Bram Moolenaarb59ae592022-11-23 23:46:31 +00007969 To clear the overrides pass an empty {list}: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007970 setcellwidths([]);
Bram Moolenaarb59ae592022-11-23 23:46:31 +00007971
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007972< You can use the script $VIMRUNTIME/tools/emoji_list.vim to see
Bram Moolenaarb59ae592022-11-23 23:46:31 +00007973 the effect for known emoji characters. Move the cursor
7974 through the text to check if the cell widths of your terminal
7975 match with what Vim knows about each emoji. If it doesn't
7976 look right you need to adjust the {list} argument.
7977
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007978
7979setcharpos({expr}, {list}) *setcharpos()*
7980 Same as |setpos()| but uses the specified column number as the
7981 character index instead of the byte index in the line.
7982
7983 Example:
7984 With the text "여보세요" in line 8: >
7985 call setcharpos('.', [0, 8, 4, 0])
7986< positions the cursor on the fourth character '요'. >
7987 call setpos('.', [0, 8, 4, 0])
7988< positions the cursor on the second character '보'.
7989
7990 Can also be used as a |method|: >
7991 GetPosition()->setcharpos('.')
7992
7993setcharsearch({dict}) *setcharsearch()*
7994 Set the current character search information to {dict},
7995 which contains one or more of the following entries:
7996
7997 char character which will be used for a subsequent
7998 |,| or |;| command; an empty string clears the
7999 character search
8000 forward direction of character search; 1 for forward,
8001 0 for backward
8002 until type of character search; 1 for a |t| or |T|
8003 character search, 0 for an |f| or |F|
8004 character search
8005
8006 This can be useful to save/restore a user's character search
8007 from a script: >
8008 :let prevsearch = getcharsearch()
8009 :" Perform a command which clobbers user's search
8010 :call setcharsearch(prevsearch)
8011< Also see |getcharsearch()|.
8012
8013 Can also be used as a |method|: >
8014 SavedSearch()->setcharsearch()
8015
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01008016setcmdline({str} [, {pos}]) *setcmdline()*
8017 Set the command line to {str} and set the cursor position to
8018 {pos}.
8019 If {pos} is omitted, the cursor is positioned after the text.
8020 Returns 0 when successful, 1 when not editing the command
8021 line.
8022
8023 Can also be used as a |method|: >
8024 GetText()->setcmdline()
8025
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008026setcmdpos({pos}) *setcmdpos()*
8027 Set the cursor position in the command line to byte position
8028 {pos}. The first position is 1.
8029 Use |getcmdpos()| to obtain the current position.
8030 Only works while editing the command line, thus you must use
8031 |c_CTRL-\_e|, |c_CTRL-R_=| or |c_CTRL-R_CTRL-R| with '='. For
8032 |c_CTRL-\_e| and |c_CTRL-R_CTRL-R| with '=' the position is
8033 set after the command line is set to the expression. For
8034 |c_CTRL-R_=| it is set after evaluating the expression but
8035 before inserting the resulting text.
8036 When the number is too big the cursor is put at the end of the
8037 line. A number smaller than one has undefined results.
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01008038 Returns 0 when successful, 1 when not editing the command
8039 line.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008040
8041 Can also be used as a |method|: >
8042 GetPos()->setcmdpos()
8043
8044setcursorcharpos({lnum}, {col} [, {off}]) *setcursorcharpos()*
8045setcursorcharpos({list})
8046 Same as |cursor()| but uses the specified column number as the
8047 character index instead of the byte index in the line.
8048
8049 Example:
8050 With the text "여보세요" in line 4: >
8051 call setcursorcharpos(4, 3)
8052< positions the cursor on the third character '세'. >
8053 call cursor(4, 3)
8054< positions the cursor on the first character '여'.
8055
8056 Can also be used as a |method|: >
8057 GetCursorPos()->setcursorcharpos()
8058
8059
8060setenv({name}, {val}) *setenv()*
8061 Set environment variable {name} to {val}. Example: >
8062 call setenv('HOME', '/home/myhome')
8063
8064< When {val} is |v:null| the environment variable is deleted.
8065 See also |expr-env|.
8066
8067 Can also be used as a |method|, the base is passed as the
8068 second argument: >
8069 GetPath()->setenv('PATH')
8070
8071setfperm({fname}, {mode}) *setfperm()* *chmod*
8072 Set the file permissions for {fname} to {mode}.
8073 {mode} must be a string with 9 characters. It is of the form
8074 "rwxrwxrwx", where each group of "rwx" flags represent, in
8075 turn, the permissions of the owner of the file, the group the
8076 file belongs to, and other users. A '-' character means the
8077 permission is off, any other character means on. Multi-byte
8078 characters are not supported.
8079
8080 For example "rw-r-----" means read-write for the user,
8081 readable by the group, not accessible by others. "xx-x-----"
8082 would do the same thing.
8083
8084 Returns non-zero for success, zero for failure.
8085
8086 Can also be used as a |method|: >
8087 GetFilename()->setfperm(mode)
8088<
8089 To read permissions see |getfperm()|.
8090
8091
8092setline({lnum}, {text}) *setline()*
8093 Set line {lnum} of the current buffer to {text}. To insert
8094 lines use |append()|. To set lines in another buffer use
8095 |setbufline()|. Any text properties in {lnum} are cleared.
8096
8097 {lnum} is used like with |getline()|.
8098 When {lnum} is just below the last line the {text} will be
8099 added below the last line.
8100 {text} can be any type or a List of any type, each item is
Bram Moolenaarcd9c8d42022-11-05 23:46:43 +00008101 converted to a String. When {text} is an empty List then
8102 nothing is changed and FALSE is returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008103
8104 If this succeeds, FALSE is returned. If this fails (most likely
8105 because {lnum} is invalid) TRUE is returned.
8106 In |Vim9| script an error is given if {lnum} is invalid.
8107
8108 Example: >
8109 :call setline(5, strftime("%c"))
8110
8111< When {text} is a |List| then line {lnum} and following lines
8112 will be set to the items in the list. Example: >
8113 :call setline(5, ['aaa', 'bbb', 'ccc'])
8114< This is equivalent to: >
8115 :for [n, l] in [[5, 'aaa'], [6, 'bbb'], [7, 'ccc']]
8116 : call setline(n, l)
8117 :endfor
8118
8119< Note: The '[ and '] marks are not set.
8120
8121 Can also be used as a |method|, the base is passed as the
8122 second argument: >
8123 GetText()->setline(lnum)
8124
8125setloclist({nr}, {list} [, {action} [, {what}]]) *setloclist()*
8126 Create or replace or add to the location list for window {nr}.
8127 {nr} can be the window number or the |window-ID|.
8128 When {nr} is zero the current window is used.
8129
8130 For a location list window, the displayed location list is
8131 modified. For an invalid window number {nr}, -1 is returned.
8132 Otherwise, same as |setqflist()|.
8133 Also see |location-list|.
8134
8135 For {action} see |setqflist-action|.
8136
8137 If the optional {what} dictionary argument is supplied, then
8138 only the items listed in {what} are set. Refer to |setqflist()|
8139 for the list of supported keys in {what}.
8140
8141 Can also be used as a |method|, the base is passed as the
8142 second argument: >
8143 GetLoclist()->setloclist(winnr)
8144
8145setmatches({list} [, {win}]) *setmatches()*
8146 Restores a list of matches saved by |getmatches()| for the
8147 current window. Returns 0 if successful, otherwise -1. All
8148 current matches are cleared before the list is restored. See
8149 example for |getmatches()|.
8150 If {win} is specified, use the window with this number or
8151 window ID instead of the current window.
8152
8153 Can also be used as a |method|: >
8154 GetMatches()->setmatches()
8155<
8156 *setpos()*
8157setpos({expr}, {list})
8158 Set the position for String {expr}. Possible values:
8159 . the cursor
8160 'x mark x
8161
8162 {list} must be a |List| with four or five numbers:
8163 [bufnum, lnum, col, off]
8164 [bufnum, lnum, col, off, curswant]
8165
8166 "bufnum" is the buffer number. Zero can be used for the
8167 current buffer. When setting an uppercase mark "bufnum" is
8168 used for the mark position. For other marks it specifies the
8169 buffer to set the mark in. You can use the |bufnr()| function
8170 to turn a file name into a buffer number.
8171 For setting the cursor and the ' mark "bufnum" is ignored,
8172 since these are associated with a window, not a buffer.
8173 Does not change the jumplist.
8174
8175 "lnum" and "col" are the position in the buffer. The first
8176 column is 1. Use a zero "lnum" to delete a mark. If "col" is
8177 smaller than 1 then 1 is used. To use the character count
8178 instead of the byte count, use |setcharpos()|.
8179
8180 The "off" number is only used when 'virtualedit' is set. Then
8181 it is the offset in screen columns from the start of the
8182 character. E.g., a position within a <Tab> or after the last
8183 character.
8184
8185 The "curswant" number is only used when setting the cursor
8186 position. It sets the preferred column for when moving the
8187 cursor vertically. When the "curswant" number is missing the
8188 preferred column is not set. When it is present and setting a
8189 mark position it is not used.
8190
8191 Note that for '< and '> changing the line number may result in
8192 the marks to be effectively be swapped, so that '< is always
8193 before '>.
8194
8195 Returns 0 when the position could be set, -1 otherwise.
8196 An error message is given if {expr} is invalid.
8197
8198 Also see |setcharpos()|, |getpos()| and |getcurpos()|.
8199
8200 This does not restore the preferred column for moving
8201 vertically; if you set the cursor position with this, |j| and
8202 |k| motions will jump to previous columns! Use |cursor()| to
8203 also set the preferred column. Also see the "curswant" key in
8204 |winrestview()|.
8205
8206 Can also be used as a |method|: >
8207 GetPosition()->setpos('.')
8208
8209setqflist({list} [, {action} [, {what}]]) *setqflist()*
8210 Create or replace or add to the quickfix list.
8211
8212 If the optional {what} dictionary argument is supplied, then
8213 only the items listed in {what} are set. The first {list}
8214 argument is ignored. See below for the supported items in
8215 {what}.
8216 *setqflist-what*
8217 When {what} is not present, the items in {list} are used. Each
8218 item must be a dictionary. Non-dictionary items in {list} are
8219 ignored. Each dictionary item can contain the following
8220 entries:
8221
8222 bufnr buffer number; must be the number of a valid
8223 buffer
8224 filename name of a file; only used when "bufnr" is not
8225 present or it is invalid.
8226 module name of a module; if given it will be used in
8227 quickfix error window instead of the filename.
8228 lnum line number in the file
Bram Moolenaara2baa732022-02-04 16:09:54 +00008229 end_lnum end of lines, if the item spans multiple lines
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008230 pattern search pattern used to locate the error
8231 col column number
8232 vcol when non-zero: "col" is visual column
8233 when zero: "col" is byte index
Bram Moolenaara2baa732022-02-04 16:09:54 +00008234 end_col end column, if the item spans multiple columns
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008235 nr error number
8236 text description of the error
8237 type single-character error type, 'E', 'W', etc.
8238 valid recognized error message
8239
8240 The "col", "vcol", "nr", "type" and "text" entries are
8241 optional. Either "lnum" or "pattern" entry can be used to
8242 locate a matching error line.
8243 If the "filename" and "bufnr" entries are not present or
8244 neither the "lnum" or "pattern" entries are present, then the
8245 item will not be handled as an error line.
8246 If both "pattern" and "lnum" are present then "pattern" will
8247 be used.
8248 If the "valid" entry is not supplied, then the valid flag is
8249 set when "bufnr" is a valid buffer or "filename" exists.
8250 If you supply an empty {list}, the quickfix list will be
8251 cleared.
8252 Note that the list is not exactly the same as what
8253 |getqflist()| returns.
8254
8255 {action} values: *setqflist-action* *E927*
8256 'a' The items from {list} are added to the existing
8257 quickfix list. If there is no existing list, then a
8258 new list is created.
8259
8260 'r' The items from the current quickfix list are replaced
8261 with the items from {list}. This can also be used to
8262 clear the list: >
8263 :call setqflist([], 'r')
8264<
8265 'f' All the quickfix lists in the quickfix stack are
8266 freed.
8267
8268 If {action} is not present or is set to ' ', then a new list
8269 is created. The new quickfix list is added after the current
8270 quickfix list in the stack and all the following lists are
8271 freed. To add a new quickfix list at the end of the stack,
8272 set "nr" in {what} to "$".
8273
8274 The following items can be specified in dictionary {what}:
8275 context quickfix list context. See |quickfix-context|
8276 efm errorformat to use when parsing text from
8277 "lines". If this is not present, then the
8278 'errorformat' option value is used.
8279 See |quickfix-parse|
8280 id quickfix list identifier |quickfix-ID|
8281 idx index of the current entry in the quickfix
8282 list specified by 'id' or 'nr'. If set to '$',
8283 then the last entry in the list is set as the
8284 current entry. See |quickfix-index|
8285 items list of quickfix entries. Same as the {list}
8286 argument.
8287 lines use 'errorformat' to parse a list of lines and
8288 add the resulting entries to the quickfix list
8289 {nr} or {id}. Only a |List| value is supported.
8290 See |quickfix-parse|
8291 nr list number in the quickfix stack; zero
8292 means the current quickfix list and "$" means
8293 the last quickfix list.
8294 quickfixtextfunc
8295 function to get the text to display in the
8296 quickfix window. The value can be the name of
8297 a function or a funcref or a lambda. Refer to
8298 |quickfix-window-function| for an explanation
8299 of how to write the function and an example.
8300 title quickfix list title text. See |quickfix-title|
8301 Unsupported keys in {what} are ignored.
8302 If the "nr" item is not present, then the current quickfix list
8303 is modified. When creating a new quickfix list, "nr" can be
8304 set to a value one greater than the quickfix stack size.
8305 When modifying a quickfix list, to guarantee that the correct
8306 list is modified, "id" should be used instead of "nr" to
8307 specify the list.
8308
8309 Examples (See also |setqflist-examples|): >
8310 :call setqflist([], 'r', {'title': 'My search'})
8311 :call setqflist([], 'r', {'nr': 2, 'title': 'Errors'})
8312 :call setqflist([], 'a', {'id':qfid, 'lines':["F1:10:L10"]})
8313<
8314 Returns zero for success, -1 for failure.
8315
8316 This function can be used to create a quickfix list
8317 independent of the 'errorformat' setting. Use a command like
8318 `:cc 1` to jump to the first position.
8319
8320 Can also be used as a |method|, the base is passed as the
8321 second argument: >
8322 GetErrorlist()->setqflist()
8323<
8324 *setreg()*
8325setreg({regname}, {value} [, {options}])
8326 Set the register {regname} to {value}.
8327 If {regname} is "" or "@", the unnamed register '"' is used.
8328 The {regname} argument is a string. In |Vim9-script|
8329 {regname} must be one character.
8330
8331 {value} may be any value returned by |getreg()| or
8332 |getreginfo()|, including a |List| or |Dict|.
8333 If {options} contains "a" or {regname} is upper case,
8334 then the value is appended.
8335
8336 {options} can also contain a register type specification:
8337 "c" or "v" |characterwise| mode
8338 "l" or "V" |linewise| mode
8339 "b" or "<CTRL-V>" |blockwise-visual| mode
8340 If a number immediately follows "b" or "<CTRL-V>" then this is
8341 used as the width of the selection - if it is not specified
8342 then the width of the block is set to the number of characters
8343 in the longest line (counting a <Tab> as 1 character).
8344
8345 If {options} contains no register settings, then the default
8346 is to use character mode unless {value} ends in a <NL> for
8347 string {value} and linewise mode for list {value}. Blockwise
8348 mode is never selected automatically.
8349 Returns zero for success, non-zero for failure.
8350
8351 *E883*
8352 Note: you may not use |List| containing more than one item to
8353 set search and expression registers. Lists containing no
8354 items act like empty strings.
8355
8356 Examples: >
8357 :call setreg(v:register, @*)
8358 :call setreg('*', @%, 'ac')
8359 :call setreg('a', "1\n2\n3", 'b5')
8360 :call setreg('"', { 'points_to': 'a'})
8361
8362< This example shows using the functions to save and restore a
8363 register: >
8364 :let var_a = getreginfo()
8365 :call setreg('a', var_a)
8366< or: >
8367 :let var_a = getreg('a', 1, 1)
8368 :let var_amode = getregtype('a')
8369 ....
8370 :call setreg('a', var_a, var_amode)
8371< Note: you may not reliably restore register value
8372 without using the third argument to |getreg()| as without it
8373 newlines are represented as newlines AND Nul bytes are
8374 represented as newlines as well, see |NL-used-for-Nul|.
8375
8376 You can also change the type of a register by appending
8377 nothing: >
8378 :call setreg('a', '', 'al')
8379
8380< Can also be used as a |method|, the base is passed as the
8381 second argument: >
8382 GetText()->setreg('a')
8383
8384settabvar({tabnr}, {varname}, {val}) *settabvar()*
8385 Set tab-local variable {varname} to {val} in tab page {tabnr}.
8386 |t:var|
8387 The {varname} argument is a string.
8388 Note that autocommands are blocked, side effects may not be
8389 triggered, e.g. when setting 'filetype'.
8390 Note that the variable name without "t:" must be used.
8391 Tabs are numbered starting with one.
8392 This function is not available in the |sandbox|.
8393
8394 Can also be used as a |method|, the base is passed as the
8395 third argument: >
8396 GetValue()->settabvar(tab, name)
8397
8398settabwinvar({tabnr}, {winnr}, {varname}, {val}) *settabwinvar()*
8399 Set option or local variable {varname} in window {winnr} to
8400 {val}.
8401 Tabs are numbered starting with one. For the current tabpage
8402 use |setwinvar()|.
8403 {winnr} can be the window number or the |window-ID|.
8404 When {winnr} is zero the current window is used.
8405 Note that autocommands are blocked, side effects may not be
8406 triggered, e.g. when setting 'filetype' or 'syntax'.
8407 This also works for a global or local buffer option, but it
8408 doesn't work for a global or local buffer variable.
8409 For a local buffer option the global value is unchanged.
8410 Note that the variable name without "w:" must be used.
8411 Examples: >
8412 :call settabwinvar(1, 1, "&list", 0)
8413 :call settabwinvar(3, 2, "myvar", "foobar")
8414< This function is not available in the |sandbox|.
8415
8416 Can also be used as a |method|, the base is passed as the
8417 fourth argument: >
8418 GetValue()->settabwinvar(tab, winnr, name)
8419
8420settagstack({nr}, {dict} [, {action}]) *settagstack()*
8421 Modify the tag stack of the window {nr} using {dict}.
8422 {nr} can be the window number or the |window-ID|.
8423
8424 For a list of supported items in {dict}, refer to
8425 |gettagstack()|. "curidx" takes effect before changing the tag
8426 stack.
8427 *E962*
8428 How the tag stack is modified depends on the {action}
8429 argument:
8430 - If {action} is not present or is set to 'r', then the tag
8431 stack is replaced.
8432 - If {action} is set to 'a', then new entries from {dict} are
8433 pushed (added) onto the tag stack.
8434 - If {action} is set to 't', then all the entries from the
8435 current entry in the tag stack or "curidx" in {dict} are
8436 removed and then new entries are pushed to the stack.
8437
8438 The current index is set to one after the length of the tag
8439 stack after the modification.
8440
8441 Returns zero for success, -1 for failure.
8442
8443 Examples (for more examples see |tagstack-examples|):
8444 Empty the tag stack of window 3: >
8445 call settagstack(3, {'items' : []})
8446
8447< Save and restore the tag stack: >
8448 let stack = gettagstack(1003)
8449 " do something else
8450 call settagstack(1003, stack)
8451 unlet stack
8452<
8453 Can also be used as a |method|, the base is passed as the
8454 second argument: >
8455 GetStack()->settagstack(winnr)
8456
8457setwinvar({winnr}, {varname}, {val}) *setwinvar()*
8458 Like |settabwinvar()| for the current tab page.
8459 Examples: >
8460 :call setwinvar(1, "&list", 0)
8461 :call setwinvar(2, "myvar", "foobar")
8462
8463< Can also be used as a |method|, the base is passed as the
8464 third argument: >
8465 GetValue()->setwinvar(winnr, name)
8466
8467sha256({string}) *sha256()*
8468 Returns a String with 64 hex characters, which is the SHA256
8469 checksum of {string}.
8470
8471 Can also be used as a |method|: >
8472 GetText()->sha256()
8473
8474< {only available when compiled with the |+cryptv| feature}
8475
8476shellescape({string} [, {special}]) *shellescape()*
8477 Escape {string} for use as a shell command argument.
8478 When the 'shell' contains powershell (MS-Windows) or pwsh
Bram Moolenaar944697a2022-02-20 19:48:20 +00008479 (MS-Windows, Linux, and macOS) then it will enclose {string}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008480 in single quotes and will double up all internal single
8481 quotes.
8482 On MS-Windows, when 'shellslash' is not set, it will enclose
8483 {string} in double quotes and double all double quotes within
8484 {string}.
8485 Otherwise it will enclose {string} in single quotes and
8486 replace all "'" with "'\''".
8487
8488 When the {special} argument is present and it's a non-zero
8489 Number or a non-empty String (|non-zero-arg|), then special
8490 items such as "!", "%", "#" and "<cword>" will be preceded by
8491 a backslash. This backslash will be removed again by the |:!|
8492 command.
8493
8494 The "!" character will be escaped (again with a |non-zero-arg|
8495 {special}) when 'shell' contains "csh" in the tail. That is
8496 because for csh and tcsh "!" is used for history replacement
8497 even when inside single quotes.
8498
8499 With a |non-zero-arg| {special} the <NL> character is also
8500 escaped. When 'shell' containing "csh" in the tail it's
8501 escaped a second time.
8502
8503 The "\" character will be escaped when 'shell' contains "fish"
8504 in the tail. That is because for fish "\" is used as an escape
8505 character inside single quotes.
8506
8507 Example of use with a |:!| command: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00008508 :exe '!dir ' .. shellescape(expand('<cfile>'), 1)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008509< This results in a directory listing for the file under the
8510 cursor. Example of use with |system()|: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00008511 :call system("chmod +w -- " .. shellescape(expand("%")))
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008512< See also |::S|.
8513
8514 Can also be used as a |method|: >
8515 GetCommand()->shellescape()
8516
8517shiftwidth([{col}]) *shiftwidth()*
8518 Returns the effective value of 'shiftwidth'. This is the
8519 'shiftwidth' value unless it is zero, in which case it is the
8520 'tabstop' value. This function was introduced with patch
8521 7.3.694 in 2012, everybody should have it by now (however it
8522 did not allow for the optional {col} argument until 8.1.542).
8523
8524 When there is one argument {col} this is used as column number
8525 for which to return the 'shiftwidth' value. This matters for the
8526 'vartabstop' feature. If the 'vartabstop' setting is enabled and
8527 no {col} argument is given, column 1 will be assumed.
8528
8529 Can also be used as a |method|: >
8530 GetColumn()->shiftwidth()
8531
8532sign_ functions are documented here: |sign-functions-details|
8533
8534
8535simplify({filename}) *simplify()*
8536 Simplify the file name as much as possible without changing
8537 the meaning. Shortcuts (on MS-Windows) or symbolic links (on
8538 Unix) are not resolved. If the first path component in
8539 {filename} designates the current directory, this will be
8540 valid for the result as well. A trailing path separator is
8541 not removed either. On Unix "//path" is unchanged, but
8542 "///path" is simplified to "/path" (this follows the Posix
8543 standard).
8544 Example: >
8545 simplify("./dir/.././/file/") == "./file/"
8546< Note: The combination "dir/.." is only removed if "dir" is
8547 a searchable directory or does not exist. On Unix, it is also
8548 removed when "dir" is a symbolic link within the same
8549 directory. In order to resolve all the involved symbolic
8550 links before simplifying the path name, use |resolve()|.
8551
8552 Can also be used as a |method|: >
8553 GetName()->simplify()
8554
8555sin({expr}) *sin()*
8556 Return the sine of {expr}, measured in radians, as a |Float|.
8557 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01008558 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008559 Examples: >
8560 :echo sin(100)
8561< -0.506366 >
8562 :echo sin(-4.01)
8563< 0.763301
8564
8565 Can also be used as a |method|: >
8566 Compute()->sin()
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008567
8568
8569sinh({expr}) *sinh()*
8570 Return the hyperbolic sine of {expr} as a |Float| in the range
8571 [-inf, inf].
8572 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01008573 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008574 Examples: >
8575 :echo sinh(0.5)
8576< 0.521095 >
8577 :echo sinh(-0.9)
8578< -1.026517
8579
8580 Can also be used as a |method|: >
8581 Compute()->sinh()
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008582
8583
8584slice({expr}, {start} [, {end}]) *slice()*
8585 Similar to using a |slice| "expr[start : end]", but "end" is
8586 used exclusive. And for a string the indexes are used as
8587 character indexes instead of byte indexes, like in
8588 |vim9script|. Also, composing characters are not counted.
8589 When {end} is omitted the slice continues to the last item.
8590 When {end} is -1 the last item is omitted.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01008591 Returns an empty value if {start} or {end} are invalid.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008592
8593 Can also be used as a |method|: >
8594 GetList()->slice(offset)
8595
8596
Bram Moolenaar2007dd42022-02-23 13:17:47 +00008597sort({list} [, {how} [, {dict}]]) *sort()* *E702*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008598 Sort the items in {list} in-place. Returns {list}.
8599
8600 If you want a list to remain unmodified make a copy first: >
8601 :let sortedlist = sort(copy(mylist))
8602
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01008603< When {how} is omitted or is a string, then sort() uses the
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008604 string representation of each item to sort on. Numbers sort
8605 after Strings, |Lists| after Numbers. For sorting text in the
8606 current buffer use |:sort|.
8607
Bram Moolenaar2007dd42022-02-23 13:17:47 +00008608 When {how} is given and it is 'i' then case is ignored.
8609 In legacy script, for backwards compatibility, the value one
8610 can be used to ignore case. Zero means to not ignore case.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008611
Bram Moolenaar2007dd42022-02-23 13:17:47 +00008612 When {how} is given and it is 'l' then the current collation
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008613 locale is used for ordering. Implementation details: strcoll()
8614 is used to compare strings. See |:language| check or set the
8615 collation locale. |v:collate| can also be used to check the
8616 current locale. Sorting using the locale typically ignores
8617 case. Example: >
8618 " ö is sorted similarly to o with English locale.
8619 :language collate en_US.UTF8
8620 :echo sort(['n', 'o', 'O', 'ö', 'p', 'z'], 'l')
8621< ['n', 'o', 'O', 'ö', 'p', 'z'] ~
8622>
8623 " ö is sorted after z with Swedish locale.
8624 :language collate sv_SE.UTF8
8625 :echo sort(['n', 'o', 'O', 'ö', 'p', 'z'], 'l')
8626< ['n', 'o', 'O', 'p', 'z', 'ö'] ~
8627 This does not work properly on Mac.
8628
Bram Moolenaar2007dd42022-02-23 13:17:47 +00008629 When {how} is given and it is 'n' then all items will be
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008630 sorted numerical (Implementation detail: this uses the
8631 strtod() function to parse numbers, Strings, Lists, Dicts and
8632 Funcrefs will be considered as being 0).
8633
Bram Moolenaar2007dd42022-02-23 13:17:47 +00008634 When {how} is given and it is 'N' then all items will be
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008635 sorted numerical. This is like 'n' but a string containing
8636 digits will be used as the number they represent.
8637
Bram Moolenaar2007dd42022-02-23 13:17:47 +00008638 When {how} is given and it is 'f' then all items will be
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008639 sorted numerical. All values must be a Number or a Float.
8640
Bram Moolenaar2007dd42022-02-23 13:17:47 +00008641 When {how} is a |Funcref| or a function name, this function
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008642 is called to compare items. The function is invoked with two
8643 items as argument and must return zero if they are equal, 1 or
8644 bigger if the first one sorts after the second one, -1 or
8645 smaller if the first one sorts before the second one.
8646
8647 {dict} is for functions with the "dict" attribute. It will be
8648 used to set the local variable "self". |Dictionary-function|
8649
8650 The sort is stable, items which compare equal (as number or as
8651 string) will keep their relative position. E.g., when sorting
8652 on numbers, text strings will sort next to each other, in the
8653 same order as they were originally.
8654
8655 Can also be used as a |method|: >
8656 mylist->sort()
8657
8658< Also see |uniq()|.
8659
8660 Example: >
8661 func MyCompare(i1, i2)
8662 return a:i1 == a:i2 ? 0 : a:i1 > a:i2 ? 1 : -1
8663 endfunc
8664 eval mylist->sort("MyCompare")
8665< A shorter compare version for this specific simple case, which
8666 ignores overflow: >
8667 func MyCompare(i1, i2)
8668 return a:i1 - a:i2
8669 endfunc
8670< For a simple expression you can use a lambda: >
8671 eval mylist->sort({i1, i2 -> i1 - i2})
8672<
8673sound_clear() *sound_clear()*
8674 Stop playing all sounds.
8675
8676 On some Linux systems you may need the libcanberra-pulse
8677 package, otherwise sound may not stop.
8678
8679 {only available when compiled with the |+sound| feature}
8680
8681 *sound_playevent()*
8682sound_playevent({name} [, {callback}])
8683 Play a sound identified by {name}. Which event names are
8684 supported depends on the system. Often the XDG sound names
8685 are used. On Ubuntu they may be found in
8686 /usr/share/sounds/freedesktop/stereo. Example: >
8687 call sound_playevent('bell')
8688< On MS-Windows, {name} can be SystemAsterisk, SystemDefault,
8689 SystemExclamation, SystemExit, SystemHand, SystemQuestion,
8690 SystemStart, SystemWelcome, etc.
Yee Cheng Chin4314e4f2022-10-08 13:50:05 +01008691 On macOS, {name} refers to files located in
8692 /System/Library/Sounds (e.g. "Tink"). It will also work for
8693 custom installed sounds in folders like ~/Library/Sounds.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008694
8695 When {callback} is specified it is invoked when the sound is
8696 finished. The first argument is the sound ID, the second
8697 argument is the status:
8698 0 sound was played to the end
8699 1 sound was interrupted
8700 2 error occurred after sound started
8701 Example: >
8702 func Callback(id, status)
8703 echomsg "sound " .. a:id .. " finished with " .. a:status
8704 endfunc
8705 call sound_playevent('bell', 'Callback')
8706
8707< MS-Windows: {callback} doesn't work for this function.
8708
8709 Returns the sound ID, which can be passed to `sound_stop()`.
8710 Returns zero if the sound could not be played.
8711
8712 Can also be used as a |method|: >
8713 GetSoundName()->sound_playevent()
8714
8715< {only available when compiled with the |+sound| feature}
8716
8717 *sound_playfile()*
8718sound_playfile({path} [, {callback}])
8719 Like `sound_playevent()` but play sound file {path}. {path}
8720 must be a full path. On Ubuntu you may find files to play
8721 with this command: >
8722 :!find /usr/share/sounds -type f | grep -v index.theme
8723
8724< Can also be used as a |method|: >
8725 GetSoundPath()->sound_playfile()
8726
Bram Moolenaar1588bc82022-03-08 21:35:07 +00008727< {only available when compiled with the |+sound| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008728
8729
8730sound_stop({id}) *sound_stop()*
8731 Stop playing sound {id}. {id} must be previously returned by
8732 `sound_playevent()` or `sound_playfile()`.
8733
8734 On some Linux systems you may need the libcanberra-pulse
8735 package, otherwise sound may not stop.
8736
8737 On MS-Windows, this does not work for event sound started by
8738 `sound_playevent()`. To stop event sounds, use `sound_clear()`.
8739
8740 Can also be used as a |method|: >
8741 soundid->sound_stop()
8742
8743< {only available when compiled with the |+sound| feature}
8744
8745 *soundfold()*
8746soundfold({word})
8747 Return the sound-folded equivalent of {word}. Uses the first
8748 language in 'spelllang' for the current window that supports
8749 soundfolding. 'spell' must be set. When no sound folding is
8750 possible the {word} is returned unmodified.
8751 This can be used for making spelling suggestions. Note that
8752 the method can be quite slow.
8753
8754 Can also be used as a |method|: >
8755 GetWord()->soundfold()
8756<
8757 *spellbadword()*
8758spellbadword([{sentence}])
8759 Without argument: The result is the badly spelled word under
8760 or after the cursor. The cursor is moved to the start of the
8761 bad word. When no bad word is found in the cursor line the
8762 result is an empty string and the cursor doesn't move.
8763
8764 With argument: The result is the first word in {sentence} that
8765 is badly spelled. If there are no spelling mistakes the
8766 result is an empty string.
8767
8768 The return value is a list with two items:
8769 - The badly spelled word or an empty string.
8770 - The type of the spelling error:
8771 "bad" spelling mistake
8772 "rare" rare word
8773 "local" word only valid in another region
8774 "caps" word should start with Capital
8775 Example: >
8776 echo spellbadword("the quik brown fox")
8777< ['quik', 'bad'] ~
8778
8779 The spelling information for the current window and the value
8780 of 'spelllang' are used.
8781
8782 Can also be used as a |method|: >
8783 GetText()->spellbadword()
8784<
8785 *spellsuggest()*
8786spellsuggest({word} [, {max} [, {capital}]])
8787 Return a |List| with spelling suggestions to replace {word}.
8788 When {max} is given up to this number of suggestions are
8789 returned. Otherwise up to 25 suggestions are returned.
8790
8791 When the {capital} argument is given and it's non-zero only
8792 suggestions with a leading capital will be given. Use this
8793 after a match with 'spellcapcheck'.
8794
8795 {word} can be a badly spelled word followed by other text.
8796 This allows for joining two words that were split. The
8797 suggestions also include the following text, thus you can
8798 replace a line.
8799
8800 {word} may also be a good word. Similar words will then be
8801 returned. {word} itself is not included in the suggestions,
8802 although it may appear capitalized.
8803
8804 The spelling information for the current window is used. The
8805 values of 'spelllang' and 'spellsuggest' are used.
8806
8807 Can also be used as a |method|: >
8808 GetWord()->spellsuggest()
8809
8810split({string} [, {pattern} [, {keepempty}]]) *split()*
8811 Make a |List| out of {string}. When {pattern} is omitted or
8812 empty each white-separated sequence of characters becomes an
8813 item.
8814 Otherwise the string is split where {pattern} matches,
8815 removing the matched characters. 'ignorecase' is not used
8816 here, add \c to ignore case. |/\c|
8817 When the first or last item is empty it is omitted, unless the
8818 {keepempty} argument is given and it's non-zero.
8819 Other empty items are kept when {pattern} matches at least one
8820 character or when {keepempty} is non-zero.
8821 Example: >
8822 :let words = split(getline('.'), '\W\+')
8823< To split a string in individual characters: >
8824 :for c in split(mystring, '\zs')
8825< If you want to keep the separator you can also use '\zs' at
8826 the end of the pattern: >
8827 :echo split('abc:def:ghi', ':\zs')
8828< ['abc:', 'def:', 'ghi'] ~
8829 Splitting a table where the first element can be empty: >
8830 :let items = split(line, ':', 1)
8831< The opposite function is |join()|.
8832
8833 Can also be used as a |method|: >
8834 GetString()->split()
8835
8836sqrt({expr}) *sqrt()*
8837 Return the non-negative square root of Float {expr} as a
8838 |Float|.
8839 {expr} must evaluate to a |Float| or a |Number|. When {expr}
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01008840 is negative the result is NaN (Not a Number). Returns 0.0 if
8841 {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008842 Examples: >
8843 :echo sqrt(100)
8844< 10.0 >
8845 :echo sqrt(-4.01)
8846< nan
8847 "nan" may be different, it depends on system libraries.
8848
8849 Can also be used as a |method|: >
8850 Compute()->sqrt()
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008851
8852
8853srand([{expr}]) *srand()*
8854 Initialize seed used by |rand()|:
8855 - If {expr} is not given, seed values are initialized by
8856 reading from /dev/urandom, if possible, or using time(NULL)
8857 a.k.a. epoch time otherwise; this only has second accuracy.
8858 - If {expr} is given it must be a Number. It is used to
8859 initialize the seed values. This is useful for testing or
8860 when a predictable sequence is intended.
8861
8862 Examples: >
8863 :let seed = srand()
8864 :let seed = srand(userinput)
8865 :echo rand(seed)
8866
8867state([{what}]) *state()*
8868 Return a string which contains characters indicating the
8869 current state. Mostly useful in callbacks that want to do
8870 work that may not always be safe. Roughly this works like:
8871 - callback uses state() to check if work is safe to do.
8872 Yes: then do it right away.
8873 No: add to work queue and add a |SafeState| and/or
8874 |SafeStateAgain| autocommand (|SafeState| triggers at
8875 toplevel, |SafeStateAgain| triggers after handling
8876 messages and callbacks).
8877 - When SafeState or SafeStateAgain is triggered and executes
8878 your autocommand, check with `state()` if the work can be
8879 done now, and if yes remove it from the queue and execute.
8880 Remove the autocommand if the queue is now empty.
8881 Also see |mode()|.
8882
8883 When {what} is given only characters in this string will be
8884 added. E.g, this checks if the screen has scrolled: >
8885 if state('s') == ''
8886 " screen has not scrolled
8887<
8888 These characters indicate the state, generally indicating that
8889 something is busy:
8890 m halfway a mapping, :normal command, feedkeys() or
8891 stuffed command
8892 o operator pending, e.g. after |d|
8893 a Insert mode autocomplete active
8894 x executing an autocommand
8895 w blocked on waiting, e.g. ch_evalexpr(), ch_read() and
8896 ch_readraw() when reading json
8897 S not triggering SafeState or SafeStateAgain, e.g. after
8898 |f| or a count
8899 c callback invoked, including timer (repeats for
8900 recursiveness up to "ccc")
8901 s screen has scrolled for messages
8902
8903str2float({string} [, {quoted}]) *str2float()*
8904 Convert String {string} to a Float. This mostly works the
8905 same as when using a floating point number in an expression,
8906 see |floating-point-format|. But it's a bit more permissive.
8907 E.g., "1e40" is accepted, while in an expression you need to
8908 write "1.0e40". The hexadecimal form "0x123" is also
8909 accepted, but not others, like binary or octal.
8910 When {quoted} is present and non-zero then embedded single
8911 quotes before the dot are ignored, thus "1'000.0" is a
8912 thousand.
8913 Text after the number is silently ignored.
8914 The decimal point is always '.', no matter what the locale is
8915 set to. A comma ends the number: "12,345.67" is converted to
8916 12.0. You can strip out thousands separators with
8917 |substitute()|: >
8918 let f = str2float(substitute(text, ',', '', 'g'))
8919<
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01008920 Returns 0.0 if the conversion fails.
8921
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008922 Can also be used as a |method|: >
8923 let f = text->substitute(',', '', 'g')->str2float()
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008924
8925str2list({string} [, {utf8}]) *str2list()*
8926 Return a list containing the number values which represent
8927 each character in String {string}. Examples: >
8928 str2list(" ") returns [32]
8929 str2list("ABC") returns [65, 66, 67]
8930< |list2str()| does the opposite.
8931
8932 When {utf8} is omitted or zero, the current 'encoding' is used.
8933 When {utf8} is TRUE, always treat the String as UTF-8
8934 characters. With UTF-8 composing characters are handled
8935 properly: >
8936 str2list("á") returns [97, 769]
8937
8938< Can also be used as a |method|: >
8939 GetString()->str2list()
8940
8941
8942str2nr({string} [, {base} [, {quoted}]]) *str2nr()*
8943 Convert string {string} to a number.
8944 {base} is the conversion base, it can be 2, 8, 10 or 16.
8945 When {quoted} is present and non-zero then embedded single
8946 quotes are ignored, thus "1'000'000" is a million.
8947
8948 When {base} is omitted base 10 is used. This also means that
8949 a leading zero doesn't cause octal conversion to be used, as
8950 with the default String to Number conversion. Example: >
8951 let nr = str2nr('0123')
8952<
8953 When {base} is 16 a leading "0x" or "0X" is ignored. With a
8954 different base the result will be zero. Similarly, when
8955 {base} is 8 a leading "0", "0o" or "0O" is ignored, and when
8956 {base} is 2 a leading "0b" or "0B" is ignored.
8957 Text after the number is silently ignored.
8958
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01008959 Returns 0 if {string} is empty or on error.
8960
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008961 Can also be used as a |method|: >
8962 GetText()->str2nr()
8963
8964
8965strcharlen({string}) *strcharlen()*
8966 The result is a Number, which is the number of characters
8967 in String {string}. Composing characters are ignored.
8968 |strchars()| can count the number of characters, counting
8969 composing characters separately.
8970
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01008971 Returns 0 if {string} is empty or on error.
8972
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008973 Also see |strlen()|, |strdisplaywidth()| and |strwidth()|.
8974
8975 Can also be used as a |method|: >
8976 GetText()->strcharlen()
8977
8978
8979strcharpart({src}, {start} [, {len} [, {skipcc}]]) *strcharpart()*
8980 Like |strpart()| but using character index and length instead
8981 of byte index and length.
8982 When {skipcc} is omitted or zero, composing characters are
8983 counted separately.
8984 When {skipcc} set to 1, Composing characters are ignored,
8985 similar to |slice()|.
8986 When a character index is used where a character does not
8987 exist it is omitted and counted as one character. For
8988 example: >
8989 strcharpart('abc', -1, 2)
8990< results in 'a'.
8991
Bram Moolenaard592deb2022-06-17 15:42:40 +01008992 Returns an empty string on error.
8993
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008994 Can also be used as a |method|: >
8995 GetText()->strcharpart(5)
8996
8997
8998strchars({string} [, {skipcc}]) *strchars()*
8999 The result is a Number, which is the number of characters
9000 in String {string}.
9001 When {skipcc} is omitted or zero, composing characters are
9002 counted separately.
9003 When {skipcc} set to 1, Composing characters are ignored.
9004 |strcharlen()| always does this.
9005
Bram Moolenaard592deb2022-06-17 15:42:40 +01009006 Returns zero on error.
9007
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009008 Also see |strlen()|, |strdisplaywidth()| and |strwidth()|.
9009
9010 {skipcc} is only available after 7.4.755. For backward
9011 compatibility, you can define a wrapper function: >
9012 if has("patch-7.4.755")
9013 function s:strchars(str, skipcc)
9014 return strchars(a:str, a:skipcc)
9015 endfunction
9016 else
9017 function s:strchars(str, skipcc)
9018 if a:skipcc
9019 return strlen(substitute(a:str, ".", "x", "g"))
9020 else
9021 return strchars(a:str)
9022 endif
9023 endfunction
9024 endif
9025<
9026 Can also be used as a |method|: >
9027 GetText()->strchars()
9028
9029strdisplaywidth({string} [, {col}]) *strdisplaywidth()*
9030 The result is a Number, which is the number of display cells
9031 String {string} occupies on the screen when it starts at {col}
9032 (first column is zero). When {col} is omitted zero is used.
9033 Otherwise it is the screen column where to start. This
9034 matters for Tab characters.
9035 The option settings of the current window are used. This
9036 matters for anything that's displayed differently, such as
9037 'tabstop' and 'display'.
9038 When {string} contains characters with East Asian Width Class
9039 Ambiguous, this function's return value depends on 'ambiwidth'.
Bram Moolenaard592deb2022-06-17 15:42:40 +01009040 Returns zero on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009041 Also see |strlen()|, |strwidth()| and |strchars()|.
9042
9043 Can also be used as a |method|: >
9044 GetText()->strdisplaywidth()
9045
9046strftime({format} [, {time}]) *strftime()*
9047 The result is a String, which is a formatted date and time, as
9048 specified by the {format} string. The given {time} is used,
9049 or the current time if no time is given. The accepted
9050 {format} depends on your system, thus this is not portable!
9051 See the manual page of the C function strftime() for the
9052 format. The maximum length of the result is 80 characters.
9053 See also |localtime()|, |getftime()| and |strptime()|.
9054 The language can be changed with the |:language| command.
9055 Examples: >
9056 :echo strftime("%c") Sun Apr 27 11:49:23 1997
9057 :echo strftime("%Y %b %d %X") 1997 Apr 27 11:53:25
9058 :echo strftime("%y%m%d %T") 970427 11:53:55
9059 :echo strftime("%H:%M") 11:55
9060 :echo strftime("%c", getftime("file.c"))
9061 Show mod time of file.c.
9062< Not available on all systems. To check use: >
9063 :if exists("*strftime")
9064
9065< Can also be used as a |method|: >
9066 GetFormat()->strftime()
9067
9068strgetchar({str}, {index}) *strgetchar()*
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01009069 Get a Number corresponding to the character at {index} in
9070 {str}. This uses a zero-based character index, not a byte
9071 index. Composing characters are considered separate
9072 characters here. Use |nr2char()| to convert the Number to a
9073 String.
Bram Moolenaard592deb2022-06-17 15:42:40 +01009074 Returns -1 if {index} is invalid.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009075 Also see |strcharpart()| and |strchars()|.
9076
9077 Can also be used as a |method|: >
9078 GetText()->strgetchar(5)
9079
9080stridx({haystack}, {needle} [, {start}]) *stridx()*
9081 The result is a Number, which gives the byte index in
9082 {haystack} of the first occurrence of the String {needle}.
9083 If {start} is specified, the search starts at index {start}.
9084 This can be used to find a second match: >
9085 :let colon1 = stridx(line, ":")
9086 :let colon2 = stridx(line, ":", colon1 + 1)
9087< The search is done case-sensitive.
9088 For pattern searches use |match()|.
9089 -1 is returned if the {needle} does not occur in {haystack}.
9090 See also |strridx()|.
9091 Examples: >
9092 :echo stridx("An Example", "Example") 3
9093 :echo stridx("Starting point", "Start") 0
9094 :echo stridx("Starting point", "start") -1
9095< *strstr()* *strchr()*
9096 stridx() works similar to the C function strstr(). When used
9097 with a single character it works similar to strchr().
9098
9099 Can also be used as a |method|: >
9100 GetHaystack()->stridx(needle)
9101<
9102 *string()*
9103string({expr}) Return {expr} converted to a String. If {expr} is a Number,
9104 Float, String, Blob or a composition of them, then the result
9105 can be parsed back with |eval()|.
9106 {expr} type result ~
9107 String 'string' (single quotes are doubled)
9108 Number 123
9109 Float 123.123456 or 1.123456e8
9110 Funcref function('name')
9111 Blob 0z00112233.44556677.8899
9112 List [item, item]
9113 Dictionary {key: value, key: value}
9114
9115 When a |List| or |Dictionary| has a recursive reference it is
9116 replaced by "[...]" or "{...}". Using eval() on the result
9117 will then fail.
9118
9119 Can also be used as a |method|: >
9120 mylist->string()
9121
9122< Also see |strtrans()|.
9123
9124
9125strlen({string}) *strlen()*
9126 The result is a Number, which is the length of the String
9127 {string} in bytes.
9128 If the argument is a Number it is first converted to a String.
Bram Moolenaard592deb2022-06-17 15:42:40 +01009129 For other types an error is given and zero is returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009130 If you want to count the number of multibyte characters use
9131 |strchars()|.
9132 Also see |len()|, |strdisplaywidth()| and |strwidth()|.
9133
9134 Can also be used as a |method|: >
9135 GetString()->strlen()
9136
9137strpart({src}, {start} [, {len} [, {chars}]]) *strpart()*
9138 The result is a String, which is part of {src}, starting from
9139 byte {start}, with the byte length {len}.
9140 When {chars} is present and TRUE then {len} is the number of
9141 characters positions (composing characters are not counted
9142 separately, thus "1" means one base character and any
9143 following composing characters).
9144 To count {start} as characters instead of bytes use
9145 |strcharpart()|.
9146
9147 When bytes are selected which do not exist, this doesn't
9148 result in an error, the bytes are simply omitted.
9149 If {len} is missing, the copy continues from {start} till the
9150 end of the {src}. >
9151 strpart("abcdefg", 3, 2) == "de"
9152 strpart("abcdefg", -2, 4) == "ab"
9153 strpart("abcdefg", 5, 4) == "fg"
9154 strpart("abcdefg", 3) == "defg"
9155
9156< Note: To get the first character, {start} must be 0. For
9157 example, to get the character under the cursor: >
9158 strpart(getline("."), col(".") - 1, 1, v:true)
9159<
Bram Moolenaard592deb2022-06-17 15:42:40 +01009160 Returns an empty string on error.
9161
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009162 Can also be used as a |method|: >
9163 GetText()->strpart(5)
9164
9165strptime({format}, {timestring}) *strptime()*
9166 The result is a Number, which is a unix timestamp representing
9167 the date and time in {timestring}, which is expected to match
9168 the format specified in {format}.
9169
9170 The accepted {format} depends on your system, thus this is not
9171 portable! See the manual page of the C function strptime()
9172 for the format. Especially avoid "%c". The value of $TZ also
9173 matters.
9174
9175 If the {timestring} cannot be parsed with {format} zero is
9176 returned. If you do not know the format of {timestring} you
9177 can try different {format} values until you get a non-zero
9178 result.
9179
9180 See also |strftime()|.
9181 Examples: >
9182 :echo strptime("%Y %b %d %X", "1997 Apr 27 11:49:23")
9183< 862156163 >
9184 :echo strftime("%c", strptime("%y%m%d %T", "970427 11:53:55"))
9185< Sun Apr 27 11:53:55 1997 >
9186 :echo strftime("%c", strptime("%Y%m%d%H%M%S", "19970427115355") + 3600)
9187< Sun Apr 27 12:53:55 1997
9188
9189 Can also be used as a |method|: >
9190 GetFormat()->strptime(timestring)
9191<
9192 Not available on all systems. To check use: >
9193 :if exists("*strptime")
9194
9195strridx({haystack}, {needle} [, {start}]) *strridx()*
9196 The result is a Number, which gives the byte index in
9197 {haystack} of the last occurrence of the String {needle}.
9198 When {start} is specified, matches beyond this index are
9199 ignored. This can be used to find a match before a previous
9200 match: >
9201 :let lastcomma = strridx(line, ",")
9202 :let comma2 = strridx(line, ",", lastcomma - 1)
9203< The search is done case-sensitive.
9204 For pattern searches use |match()|.
9205 -1 is returned if the {needle} does not occur in {haystack}.
9206 If the {needle} is empty the length of {haystack} is returned.
9207 See also |stridx()|. Examples: >
9208 :echo strridx("an angry armadillo", "an") 3
9209< *strrchr()*
9210 When used with a single character it works similar to the C
9211 function strrchr().
9212
9213 Can also be used as a |method|: >
9214 GetHaystack()->strridx(needle)
9215
9216strtrans({string}) *strtrans()*
9217 The result is a String, which is {string} with all unprintable
9218 characters translated into printable characters |'isprint'|.
9219 Like they are shown in a window. Example: >
9220 echo strtrans(@a)
9221< This displays a newline in register a as "^@" instead of
9222 starting a new line.
9223
Bram Moolenaard592deb2022-06-17 15:42:40 +01009224 Returns an empty string on error.
9225
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009226 Can also be used as a |method|: >
9227 GetString()->strtrans()
9228
9229strwidth({string}) *strwidth()*
9230 The result is a Number, which is the number of display cells
9231 String {string} occupies. A Tab character is counted as one
9232 cell, alternatively use |strdisplaywidth()|.
9233 When {string} contains characters with East Asian Width Class
9234 Ambiguous, this function's return value depends on 'ambiwidth'.
Bram Moolenaard592deb2022-06-17 15:42:40 +01009235 Returns zero on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009236 Also see |strlen()|, |strdisplaywidth()| and |strchars()|.
9237
9238 Can also be used as a |method|: >
9239 GetString()->strwidth()
9240
9241submatch({nr} [, {list}]) *submatch()* *E935*
9242 Only for an expression in a |:substitute| command or
9243 substitute() function.
9244 Returns the {nr}'th submatch of the matched text. When {nr}
9245 is 0 the whole matched text is returned.
9246 Note that a NL in the string can stand for a line break of a
9247 multi-line match or a NUL character in the text.
9248 Also see |sub-replace-expression|.
9249
9250 If {list} is present and non-zero then submatch() returns
9251 a list of strings, similar to |getline()| with two arguments.
9252 NL characters in the text represent NUL characters in the
9253 text.
9254 Only returns more than one item for |:substitute|, inside
9255 |substitute()| this list will always contain one or zero
9256 items, since there are no real line breaks.
9257
9258 When substitute() is used recursively only the submatches in
9259 the current (deepest) call can be obtained.
9260
Bram Moolenaard592deb2022-06-17 15:42:40 +01009261 Returns an empty string or list on error.
9262
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009263 Examples: >
9264 :s/\d\+/\=submatch(0) + 1/
9265 :echo substitute(text, '\d\+', '\=submatch(0) + 1', '')
9266< This finds the first number in the line and adds one to it.
9267 A line break is included as a newline character.
9268
9269 Can also be used as a |method|: >
9270 GetNr()->submatch()
9271
9272substitute({string}, {pat}, {sub}, {flags}) *substitute()*
9273 The result is a String, which is a copy of {string}, in which
9274 the first match of {pat} is replaced with {sub}.
9275 When {flags} is "g", all matches of {pat} in {string} are
9276 replaced. Otherwise {flags} should be "".
9277
9278 This works like the ":substitute" command (without any flags).
9279 But the matching with {pat} is always done like the 'magic'
9280 option is set and 'cpoptions' is empty (to make scripts
9281 portable). 'ignorecase' is still relevant, use |/\c| or |/\C|
9282 if you want to ignore or match case and ignore 'ignorecase'.
9283 'smartcase' is not used. See |string-match| for how {pat} is
9284 used.
9285
9286 A "~" in {sub} is not replaced with the previous {sub}.
9287 Note that some codes in {sub} have a special meaning
9288 |sub-replace-special|. For example, to replace something with
9289 "\n" (two characters), use "\\\\n" or '\\n'.
9290
9291 When {pat} does not match in {string}, {string} is returned
9292 unmodified.
9293
9294 Example: >
9295 :let &path = substitute(&path, ",\\=[^,]*$", "", "")
9296< This removes the last component of the 'path' option. >
9297 :echo substitute("testing", ".*", "\\U\\0", "")
9298< results in "TESTING".
9299
9300 When {sub} starts with "\=", the remainder is interpreted as
9301 an expression. See |sub-replace-expression|. Example: >
9302 :echo substitute(s, '%\(\x\x\)',
Bram Moolenaarc51cf032022-02-26 12:25:45 +00009303 \ '\=nr2char("0x" .. submatch(1))', 'g')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009304
9305< When {sub} is a Funcref that function is called, with one
9306 optional argument. Example: >
9307 :echo substitute(s, '%\(\x\x\)', SubNr, 'g')
9308< The optional argument is a list which contains the whole
9309 matched string and up to nine submatches, like what
9310 |submatch()| returns. Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00009311 :echo substitute(s, '%\(\x\x\)', {m -> '0x' .. m[1]}, 'g')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009312
Bram Moolenaard592deb2022-06-17 15:42:40 +01009313< Returns an empty string on error.
9314
9315 Can also be used as a |method|: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009316 GetString()->substitute(pat, sub, flags)
9317
Bram Moolenaarc216a7a2022-12-05 13:50:55 +00009318swapfilelist() *swapfilelist()*
9319 Returns a list of swap file names, like what "vim -r" shows.
9320 See the |-r| command argument. The 'directory' option is used
9321 for the directories to inspect. If you only want to get a
9322 list of swap files in the current directory then temporarily
9323 set 'directory' to a dot: >
9324 let save_dir = &directory
9325 let &directory = '.'
9326 let swapfiles = swapfilelist()
9327 let &directory = save_dir
9328
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009329swapinfo({fname}) *swapinfo()*
9330 The result is a dictionary, which holds information about the
9331 swapfile {fname}. The available fields are:
9332 version Vim version
9333 user user name
9334 host host name
9335 fname original file name
9336 pid PID of the Vim process that created the swap
9337 file
9338 mtime last modification time in seconds
9339 inode Optional: INODE number of the file
9340 dirty 1 if file was modified, 0 if not
9341 Note that "user" and "host" are truncated to at most 39 bytes.
9342 In case of failure an "error" item is added with the reason:
9343 Cannot open file: file not found or in accessible
9344 Cannot read file: cannot read first block
9345 Not a swap file: does not contain correct block ID
9346 Magic number mismatch: Info in first block is invalid
9347
9348 Can also be used as a |method|: >
9349 GetFilename()->swapinfo()
9350
9351swapname({buf}) *swapname()*
9352 The result is the swap file path of the buffer {expr}.
9353 For the use of {buf}, see |bufname()| above.
9354 If buffer {buf} is the current buffer, the result is equal to
9355 |:swapname| (unless there is no swap file).
9356 If buffer {buf} has no swap file, returns an empty string.
9357
9358 Can also be used as a |method|: >
9359 GetBufname()->swapname()
9360
9361synID({lnum}, {col}, {trans}) *synID()*
9362 The result is a Number, which is the syntax ID at the position
9363 {lnum} and {col} in the current window.
9364 The syntax ID can be used with |synIDattr()| and
9365 |synIDtrans()| to obtain syntax information about text.
9366
9367 {col} is 1 for the leftmost column, {lnum} is 1 for the first
9368 line. 'synmaxcol' applies, in a longer line zero is returned.
9369 Note that when the position is after the last character,
9370 that's where the cursor can be in Insert mode, synID() returns
9371 zero. {lnum} is used like with |getline()|.
9372
9373 When {trans} is |TRUE|, transparent items are reduced to the
9374 item that they reveal. This is useful when wanting to know
9375 the effective color. When {trans} is |FALSE|, the transparent
9376 item is returned. This is useful when wanting to know which
9377 syntax item is effective (e.g. inside parens).
9378 Warning: This function can be very slow. Best speed is
9379 obtained by going through the file in forward direction.
9380
Bram Moolenaard592deb2022-06-17 15:42:40 +01009381 Returns zero on error.
9382
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009383 Example (echoes the name of the syntax item under the cursor): >
9384 :echo synIDattr(synID(line("."), col("."), 1), "name")
9385<
9386
9387synIDattr({synID}, {what} [, {mode}]) *synIDattr()*
9388 The result is a String, which is the {what} attribute of
9389 syntax ID {synID}. This can be used to obtain information
9390 about a syntax item.
9391 {mode} can be "gui", "cterm" or "term", to get the attributes
9392 for that mode. When {mode} is omitted, or an invalid value is
9393 used, the attributes for the currently active highlighting are
9394 used (GUI, cterm or term).
9395 Use synIDtrans() to follow linked highlight groups.
9396 {what} result
9397 "name" the name of the syntax item
9398 "fg" foreground color (GUI: color name used to set
9399 the color, cterm: color number as a string,
9400 term: empty string)
9401 "bg" background color (as with "fg")
9402 "font" font name (only available in the GUI)
9403 |highlight-font|
9404 "sp" special color for the GUI (as with "fg")
9405 |highlight-guisp|
9406 "ul" underline color for cterm: number as a string
9407 "fg#" like "fg", but for the GUI and the GUI is
9408 running the name in "#RRGGBB" form
9409 "bg#" like "fg#" for "bg"
9410 "sp#" like "fg#" for "sp"
9411 "bold" "1" if bold
9412 "italic" "1" if italic
9413 "reverse" "1" if reverse
9414 "inverse" "1" if inverse (= reverse)
9415 "standout" "1" if standout
9416 "underline" "1" if underlined
9417 "undercurl" "1" if undercurled
9418 "strike" "1" if strikethrough
Bram Moolenaarde786322022-07-30 14:56:17 +01009419 "nocombine" "1" if nocombine
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009420
Bram Moolenaard592deb2022-06-17 15:42:40 +01009421 Returns an empty string on error.
9422
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009423 Example (echoes the color of the syntax item under the
9424 cursor): >
9425 :echo synIDattr(synIDtrans(synID(line("."), col("."), 1)), "fg")
9426<
9427 Can also be used as a |method|: >
9428 :echo synID(line("."), col("."), 1)->synIDtrans()->synIDattr("fg")
9429
9430
9431synIDtrans({synID}) *synIDtrans()*
9432 The result is a Number, which is the translated syntax ID of
9433 {synID}. This is the syntax group ID of what is being used to
9434 highlight the character. Highlight links given with
9435 ":highlight link" are followed.
9436
Bram Moolenaard592deb2022-06-17 15:42:40 +01009437 Returns zero on error.
9438
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009439 Can also be used as a |method|: >
9440 :echo synID(line("."), col("."), 1)->synIDtrans()->synIDattr("fg")
9441
9442synconcealed({lnum}, {col}) *synconcealed()*
9443 The result is a |List| with currently three items:
9444 1. The first item in the list is 0 if the character at the
9445 position {lnum} and {col} is not part of a concealable
9446 region, 1 if it is. {lnum} is used like with |getline()|.
9447 2. The second item in the list is a string. If the first item
9448 is 1, the second item contains the text which will be
9449 displayed in place of the concealed text, depending on the
9450 current setting of 'conceallevel' and 'listchars'.
9451 3. The third and final item in the list is a number
9452 representing the specific syntax region matched in the
9453 line. When the character is not concealed the value is
9454 zero. This allows detection of the beginning of a new
9455 concealable region if there are two consecutive regions
9456 with the same replacement character. For an example, if
9457 the text is "123456" and both "23" and "45" are concealed
9458 and replaced by the character "X", then:
9459 call returns ~
9460 synconcealed(lnum, 1) [0, '', 0]
9461 synconcealed(lnum, 2) [1, 'X', 1]
9462 synconcealed(lnum, 3) [1, 'X', 1]
9463 synconcealed(lnum, 4) [1, 'X', 2]
9464 synconcealed(lnum, 5) [1, 'X', 2]
9465 synconcealed(lnum, 6) [0, '', 0]
9466
9467
9468synstack({lnum}, {col}) *synstack()*
9469 Return a |List|, which is the stack of syntax items at the
9470 position {lnum} and {col} in the current window. {lnum} is
9471 used like with |getline()|. Each item in the List is an ID
9472 like what |synID()| returns.
9473 The first item in the List is the outer region, following are
9474 items contained in that one. The last one is what |synID()|
9475 returns, unless not the whole item is highlighted or it is a
9476 transparent item.
9477 This function is useful for debugging a syntax file.
9478 Example that shows the syntax stack under the cursor: >
9479 for id in synstack(line("."), col("."))
9480 echo synIDattr(id, "name")
9481 endfor
9482< When the position specified with {lnum} and {col} is invalid
Bram Moolenaard592deb2022-06-17 15:42:40 +01009483 an empty List is returned. The position just after the last
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009484 character in a line and the first column in an empty line are
9485 valid positions.
9486
9487system({expr} [, {input}]) *system()* *E677*
9488 Get the output of the shell command {expr} as a |String|. See
9489 |systemlist()| to get the output as a |List|.
9490
9491 When {input} is given and is a |String| this string is written
9492 to a file and passed as stdin to the command. The string is
9493 written as-is, you need to take care of using the correct line
9494 separators yourself.
9495 If {input} is given and is a |List| it is written to the file
9496 in a way |writefile()| does with {binary} set to "b" (i.e.
9497 with a newline between each list item with newlines inside
9498 list items converted to NULs).
9499 When {input} is given and is a number that is a valid id for
9500 an existing buffer then the content of the buffer is written
9501 to the file line by line, each line terminated by a NL and
9502 NULs characters where the text has a NL.
9503
9504 Pipes are not used, the 'shelltemp' option is not used.
9505
9506 When prepended by |:silent| the terminal will not be set to
9507 cooked mode. This is meant to be used for commands that do
9508 not need the user to type. It avoids stray characters showing
9509 up on the screen which require |CTRL-L| to remove. >
9510 :silent let f = system('ls *.vim')
9511<
9512 Note: Use |shellescape()| or |::S| with |expand()| or
9513 |fnamemodify()| to escape special characters in a command
9514 argument. Newlines in {expr} may cause the command to fail.
9515 The characters in 'shellquote' and 'shellxquote' may also
9516 cause trouble.
9517 This is not to be used for interactive commands.
9518
9519 The result is a String. Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00009520 :let files = system('ls ' .. shellescape(expand('%:h')))
9521 :let files = system('ls ' .. expand('%:h:S'))
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009522
9523< To make the result more system-independent, the shell output
9524 is filtered to replace <CR> with <NL> for Macintosh, and
9525 <CR><NL> with <NL> for DOS-like systems.
9526 To avoid the string being truncated at a NUL, all NUL
9527 characters are replaced with SOH (0x01).
9528
9529 The command executed is constructed using several options:
9530 'shell' 'shellcmdflag' 'shellxquote' {expr} 'shellredir' {tmp} 'shellxquote'
9531 ({tmp} is an automatically generated file name).
9532 For Unix, braces are put around {expr} to allow for
9533 concatenated commands.
9534
9535 The command will be executed in "cooked" mode, so that a
9536 CTRL-C will interrupt the command (on Unix at least).
9537
9538 The resulting error code can be found in |v:shell_error|.
9539 This function will fail in |restricted-mode|.
9540
9541 Note that any wrong value in the options mentioned above may
9542 make the function fail. It has also been reported to fail
9543 when using a security agent application.
9544 Unlike ":!cmd" there is no automatic check for changed files.
9545 Use |:checktime| to force a check.
9546
9547 Can also be used as a |method|: >
9548 :echo GetCmd()->system()
9549
9550
9551systemlist({expr} [, {input}]) *systemlist()*
9552 Same as |system()|, but returns a |List| with lines (parts of
9553 output separated by NL) with NULs transformed into NLs. Output
9554 is the same as |readfile()| will output with {binary} argument
9555 set to "b", except that there is no extra empty item when the
9556 result ends in a NL.
9557 Note that on MS-Windows you may get trailing CR characters.
9558
9559 To see the difference between "echo hello" and "echo -n hello"
9560 use |system()| and |split()|: >
9561 echo system('echo hello')->split('\n', 1)
9562<
9563 Returns an empty string on error.
9564
9565 Can also be used as a |method|: >
9566 :echo GetCmd()->systemlist()
9567
9568
9569tabpagebuflist([{arg}]) *tabpagebuflist()*
9570 The result is a |List|, where each item is the number of the
9571 buffer associated with each window in the current tab page.
9572 {arg} specifies the number of the tab page to be used. When
9573 omitted the current tab page is used.
9574 When {arg} is invalid the number zero is returned.
9575 To get a list of all buffers in all tabs use this: >
9576 let buflist = []
9577 for i in range(tabpagenr('$'))
9578 call extend(buflist, tabpagebuflist(i + 1))
9579 endfor
9580< Note that a buffer may appear in more than one window.
9581
9582 Can also be used as a |method|: >
9583 GetTabpage()->tabpagebuflist()
9584
9585tabpagenr([{arg}]) *tabpagenr()*
9586 The result is a Number, which is the number of the current
9587 tab page. The first tab page has number 1.
9588
9589 The optional argument {arg} supports the following values:
9590 $ the number of the last tab page (the tab page
9591 count).
9592 # the number of the last accessed tab page
9593 (where |g<Tab>| goes to). if there is no
9594 previous tab page 0 is returned.
9595 The number can be used with the |:tab| command.
9596
Bram Moolenaard592deb2022-06-17 15:42:40 +01009597 Returns zero on error.
9598
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009599
9600tabpagewinnr({tabarg} [, {arg}]) *tabpagewinnr()*
9601 Like |winnr()| but for tab page {tabarg}.
9602 {tabarg} specifies the number of tab page to be used.
9603 {arg} is used like with |winnr()|:
9604 - When omitted the current window number is returned. This is
9605 the window which will be used when going to this tab page.
9606 - When "$" the number of windows is returned.
9607 - When "#" the previous window nr is returned.
9608 Useful examples: >
9609 tabpagewinnr(1) " current window of tab page 1
9610 tabpagewinnr(4, '$') " number of windows in tab page 4
9611< When {tabarg} is invalid zero is returned.
9612
9613 Can also be used as a |method|: >
9614 GetTabpage()->tabpagewinnr()
9615<
9616 *tagfiles()*
9617tagfiles() Returns a |List| with the file names used to search for tags
9618 for the current buffer. This is the 'tags' option expanded.
9619
9620
9621taglist({expr} [, {filename}]) *taglist()*
9622 Returns a |List| of tags matching the regular expression {expr}.
9623
9624 If {filename} is passed it is used to prioritize the results
9625 in the same way that |:tselect| does. See |tag-priority|.
9626 {filename} should be the full path of the file.
9627
9628 Each list item is a dictionary with at least the following
9629 entries:
9630 name Name of the tag.
9631 filename Name of the file where the tag is
9632 defined. It is either relative to the
9633 current directory or a full path.
9634 cmd Ex command used to locate the tag in
9635 the file.
9636 kind Type of the tag. The value for this
9637 entry depends on the language specific
9638 kind values. Only available when
9639 using a tags file generated by
Bram Moolenaar47c532e2022-03-19 15:18:53 +00009640 Universal/Exuberant ctags or hdrtag.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009641 static A file specific tag. Refer to
9642 |static-tag| for more information.
9643 More entries may be present, depending on the content of the
9644 tags file: access, implementation, inherits and signature.
9645 Refer to the ctags documentation for information about these
9646 fields. For C code the fields "struct", "class" and "enum"
9647 may appear, they give the name of the entity the tag is
9648 contained in.
9649
9650 The ex-command "cmd" can be either an ex search pattern, a
9651 line number or a line number followed by a byte number.
9652
9653 If there are no matching tags, then an empty list is returned.
9654
9655 To get an exact tag match, the anchors '^' and '$' should be
9656 used in {expr}. This also make the function work faster.
9657 Refer to |tag-regexp| for more information about the tag
9658 search regular expression pattern.
9659
9660 Refer to |'tags'| for information about how the tags file is
9661 located by Vim. Refer to |tags-file-format| for the format of
9662 the tags file generated by the different ctags tools.
9663
9664 Can also be used as a |method|: >
9665 GetTagpattern()->taglist()
9666
9667tan({expr}) *tan()*
9668 Return the tangent of {expr}, measured in radians, as a |Float|
9669 in the range [-inf, inf].
9670 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaard592deb2022-06-17 15:42:40 +01009671 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009672 Examples: >
9673 :echo tan(10)
9674< 0.648361 >
9675 :echo tan(-4.01)
9676< -1.181502
9677
9678 Can also be used as a |method|: >
9679 Compute()->tan()
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009680
9681
9682tanh({expr}) *tanh()*
9683 Return the hyperbolic tangent of {expr} as a |Float| in the
9684 range [-1, 1].
9685 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaard592deb2022-06-17 15:42:40 +01009686 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009687 Examples: >
9688 :echo tanh(0.5)
9689< 0.462117 >
9690 :echo tanh(-1)
9691< -0.761594
9692
9693 Can also be used as a |method|: >
9694 Compute()->tanh()
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009695
9696
9697tempname() *tempname()* *temp-file-name*
9698 The result is a String, which is the name of a file that
9699 doesn't exist. It can be used for a temporary file. The name
9700 is different for at least 26 consecutive calls. Example: >
9701 :let tmpfile = tempname()
Bram Moolenaarc51cf032022-02-26 12:25:45 +00009702 :exe "redir > " .. tmpfile
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009703< For Unix, the file will be in a private directory |tempfile|.
9704 For MS-Windows forward slashes are used when the 'shellslash'
9705 option is set, or when 'shellcmdflag' starts with '-' and
9706 'shell' does not contain powershell or pwsh.
9707
9708
9709term_ functions are documented here: |terminal-function-details|
9710
9711
9712terminalprops() *terminalprops()*
9713 Returns a |Dictionary| with properties of the terminal that Vim
9714 detected from the response to |t_RV| request. See
9715 |v:termresponse| for the response itself. If |v:termresponse|
9716 is empty most values here will be 'u' for unknown.
9717 cursor_style whether sending |t_RS| works **
9718 cursor_blink_mode whether sending |t_RC| works **
9719 underline_rgb whether |t_8u| works **
9720 mouse mouse type supported
Bram Moolenaar4bc85f22022-10-21 14:17:24 +01009721 kitty whether Kitty terminal was detected
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009722
9723 ** value 'u' for unknown, 'y' for yes, 'n' for no
9724
9725 If the |+termresponse| feature is missing then the result is
9726 an empty dictionary.
9727
9728 If "cursor_style" is 'y' then |t_RS| will be sent to request the
9729 current cursor style.
9730 If "cursor_blink_mode" is 'y' then |t_RC| will be sent to
9731 request the cursor blink status.
9732 "cursor_style" and "cursor_blink_mode" are also set if |t_u7|
9733 is not empty, Vim will detect the working of sending |t_RS|
9734 and |t_RC| on startup.
9735
9736 When "underline_rgb" is not 'y', then |t_8u| will be made empty.
9737 This avoids sending it to xterm, which would clear the colors.
9738
9739 For "mouse" the value 'u' is unknown
9740
9741 Also see:
9742 - 'ambiwidth' - detected by using |t_u7|.
9743 - |v:termstyleresp| and |v:termblinkresp| for the response to
9744 |t_RS| and |t_RC|.
9745
9746
9747test_ functions are documented here: |test-functions-details|
9748
9749
9750 *timer_info()*
9751timer_info([{id}])
9752 Return a list with information about timers.
9753 When {id} is given only information about this timer is
9754 returned. When timer {id} does not exist an empty list is
9755 returned.
9756 When {id} is omitted information about all timers is returned.
9757
9758 For each timer the information is stored in a |Dictionary| with
9759 these items:
9760 "id" the timer ID
9761 "time" time the timer was started with
9762 "remaining" time until the timer fires
9763 "repeat" number of times the timer will still fire;
9764 -1 means forever
9765 "callback" the callback
9766 "paused" 1 if the timer is paused, 0 otherwise
9767
9768 Can also be used as a |method|: >
9769 GetTimer()->timer_info()
9770
9771< {only available when compiled with the |+timers| feature}
9772
9773timer_pause({timer}, {paused}) *timer_pause()*
9774 Pause or unpause a timer. A paused timer does not invoke its
9775 callback when its time expires. Unpausing a timer may cause
9776 the callback to be invoked almost immediately if enough time
9777 has passed.
9778
9779 Pausing a timer is useful to avoid the callback to be called
9780 for a short time.
9781
9782 If {paused} evaluates to a non-zero Number or a non-empty
9783 String, then the timer is paused, otherwise it is unpaused.
9784 See |non-zero-arg|.
9785
9786 Can also be used as a |method|: >
9787 GetTimer()->timer_pause(1)
9788
9789< {only available when compiled with the |+timers| feature}
9790
9791 *timer_start()* *timer* *timers*
9792timer_start({time}, {callback} [, {options}])
9793 Create a timer and return the timer ID.
9794
9795 {time} is the waiting time in milliseconds. This is the
9796 minimum time before invoking the callback. When the system is
9797 busy or Vim is not waiting for input the time will be longer.
9798
9799 {callback} is the function to call. It can be the name of a
9800 function or a |Funcref|. It is called with one argument, which
9801 is the timer ID. The callback is only invoked when Vim is
9802 waiting for input.
9803 If you want to show a message look at |popup_notification()|
9804 to avoid interfering with what the user is doing.
9805
9806 {options} is a dictionary. Supported entries:
9807 "repeat" Number of times to repeat calling the
9808 callback. -1 means forever. When not present
9809 the callback will be called once.
9810 If the timer causes an error three times in a
9811 row the repeat is cancelled. This avoids that
9812 Vim becomes unusable because of all the error
9813 messages.
9814
Bram Moolenaard592deb2022-06-17 15:42:40 +01009815 Returns -1 on error.
9816
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009817 Example: >
9818 func MyHandler(timer)
9819 echo 'Handler called'
9820 endfunc
9821 let timer = timer_start(500, 'MyHandler',
9822 \ {'repeat': 3})
9823< This will invoke MyHandler() three times at 500 msec
9824 intervals.
9825
9826 Can also be used as a |method|: >
9827 GetMsec()->timer_start(callback)
9828
9829< Not available in the |sandbox|.
9830 {only available when compiled with the |+timers| feature}
9831
9832timer_stop({timer}) *timer_stop()*
9833 Stop a timer. The timer callback will no longer be invoked.
9834 {timer} is an ID returned by timer_start(), thus it must be a
9835 Number. If {timer} does not exist there is no error.
9836
9837 Can also be used as a |method|: >
9838 GetTimer()->timer_stop()
9839
9840< {only available when compiled with the |+timers| feature}
9841
9842timer_stopall() *timer_stopall()*
9843 Stop all timers. The timer callbacks will no longer be
9844 invoked. Useful if a timer is misbehaving. If there are no
9845 timers there is no error.
9846
9847 {only available when compiled with the |+timers| feature}
9848
9849tolower({expr}) *tolower()*
9850 The result is a copy of the String given, with all uppercase
9851 characters turned into lowercase (just like applying |gu| to
Bram Moolenaard592deb2022-06-17 15:42:40 +01009852 the string). Returns an empty string on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009853
9854 Can also be used as a |method|: >
9855 GetText()->tolower()
9856
9857toupper({expr}) *toupper()*
9858 The result is a copy of the String given, with all lowercase
9859 characters turned into uppercase (just like applying |gU| to
Bram Moolenaard592deb2022-06-17 15:42:40 +01009860 the string). Returns an empty string on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009861
9862 Can also be used as a |method|: >
9863 GetText()->toupper()
9864
9865tr({src}, {fromstr}, {tostr}) *tr()*
9866 The result is a copy of the {src} string with all characters
9867 which appear in {fromstr} replaced by the character in that
9868 position in the {tostr} string. Thus the first character in
9869 {fromstr} is translated into the first character in {tostr}
9870 and so on. Exactly like the unix "tr" command.
9871 This code also deals with multibyte characters properly.
9872
Bram Moolenaard592deb2022-06-17 15:42:40 +01009873 Returns an empty string on error.
9874
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009875 Examples: >
9876 echo tr("hello there", "ht", "HT")
9877< returns "Hello THere" >
9878 echo tr("<blob>", "<>", "{}")
9879< returns "{blob}"
9880
9881 Can also be used as a |method|: >
9882 GetText()->tr(from, to)
9883
9884trim({text} [, {mask} [, {dir}]]) *trim()*
9885 Return {text} as a String where any character in {mask} is
9886 removed from the beginning and/or end of {text}.
9887
9888 If {mask} is not given, {mask} is all characters up to 0x20,
9889 which includes Tab, space, NL and CR, plus the non-breaking
9890 space character 0xa0.
9891
9892 The optional {dir} argument specifies where to remove the
9893 characters:
9894 0 remove from the beginning and end of {text}
9895 1 remove only at the beginning of {text}
9896 2 remove only at the end of {text}
9897 When omitted both ends are trimmed.
9898
9899 This function deals with multibyte characters properly.
Bram Moolenaard592deb2022-06-17 15:42:40 +01009900 Returns an empty string on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009901
9902 Examples: >
9903 echo trim(" some text ")
9904< returns "some text" >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00009905 echo trim(" \r\t\t\r RESERVE \t\n\x0B\xA0") .. "_TAIL"
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009906< returns "RESERVE_TAIL" >
9907 echo trim("rm<Xrm<>X>rrm", "rm<>")
9908< returns "Xrm<>X" (characters in the middle are not removed) >
9909 echo trim(" vim ", " ", 2)
9910< returns " vim"
9911
9912 Can also be used as a |method|: >
9913 GetText()->trim()
9914
9915trunc({expr}) *trunc()*
9916 Return the largest integral value with magnitude less than or
9917 equal to {expr} as a |Float| (truncate towards zero).
9918 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaard592deb2022-06-17 15:42:40 +01009919 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009920 Examples: >
9921 echo trunc(1.456)
9922< 1.0 >
9923 echo trunc(-5.456)
9924< -5.0 >
9925 echo trunc(4.0)
9926< 4.0
9927
9928 Can also be used as a |method|: >
9929 Compute()->trunc()
9930<
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009931 *type()*
9932type({expr}) The result is a Number representing the type of {expr}.
9933 Instead of using the number directly, it is better to use the
9934 v:t_ variable that has the value:
9935 Number: 0 |v:t_number|
9936 String: 1 |v:t_string|
9937 Funcref: 2 |v:t_func|
9938 List: 3 |v:t_list|
9939 Dictionary: 4 |v:t_dict|
9940 Float: 5 |v:t_float|
9941 Boolean: 6 |v:t_bool| (v:false and v:true)
9942 None: 7 |v:t_none| (v:null and v:none)
9943 Job: 8 |v:t_job|
9944 Channel: 9 |v:t_channel|
9945 Blob: 10 |v:t_blob|
9946 For backward compatibility, this method can be used: >
9947 :if type(myvar) == type(0)
9948 :if type(myvar) == type("")
9949 :if type(myvar) == type(function("tr"))
9950 :if type(myvar) == type([])
9951 :if type(myvar) == type({})
9952 :if type(myvar) == type(0.0)
9953 :if type(myvar) == type(v:false)
9954 :if type(myvar) == type(v:none)
9955< To check if the v:t_ variables exist use this: >
9956 :if exists('v:t_number')
9957
9958< Can also be used as a |method|: >
9959 mylist->type()
9960
9961
9962typename({expr}) *typename()*
9963 Return a string representation of the type of {expr}.
9964 Example: >
9965 echo typename([1, 2, 3])
9966 list<number>
9967
9968
9969undofile({name}) *undofile()*
9970 Return the name of the undo file that would be used for a file
9971 with name {name} when writing. This uses the 'undodir'
9972 option, finding directories that exist. It does not check if
9973 the undo file exists.
9974 {name} is always expanded to the full path, since that is what
9975 is used internally.
9976 If {name} is empty undofile() returns an empty string, since a
9977 buffer without a file name will not write an undo file.
9978 Useful in combination with |:wundo| and |:rundo|.
9979 When compiled without the |+persistent_undo| option this always
9980 returns an empty string.
9981
9982 Can also be used as a |method|: >
9983 GetFilename()->undofile()
9984
9985undotree() *undotree()*
9986 Return the current state of the undo tree in a dictionary with
9987 the following items:
9988 "seq_last" The highest undo sequence number used.
9989 "seq_cur" The sequence number of the current position in
9990 the undo tree. This differs from "seq_last"
9991 when some changes were undone.
9992 "time_cur" Time last used for |:earlier| and related
9993 commands. Use |strftime()| to convert to
9994 something readable.
9995 "save_last" Number of the last file write. Zero when no
9996 write yet.
9997 "save_cur" Number of the current position in the undo
9998 tree.
9999 "synced" Non-zero when the last undo block was synced.
10000 This happens when waiting from input from the
10001 user. See |undo-blocks|.
10002 "entries" A list of dictionaries with information about
10003 undo blocks.
10004
10005 The first item in the "entries" list is the oldest undo item.
10006 Each List item is a |Dictionary| with these items:
10007 "seq" Undo sequence number. Same as what appears in
10008 |:undolist|.
10009 "time" Timestamp when the change happened. Use
10010 |strftime()| to convert to something readable.
10011 "newhead" Only appears in the item that is the last one
10012 that was added. This marks the last change
10013 and where further changes will be added.
10014 "curhead" Only appears in the item that is the last one
10015 that was undone. This marks the current
10016 position in the undo tree, the block that will
10017 be used by a redo command. When nothing was
10018 undone after the last change this item will
10019 not appear anywhere.
10020 "save" Only appears on the last block before a file
10021 write. The number is the write count. The
10022 first write has number 1, the last one the
10023 "save_last" mentioned above.
10024 "alt" Alternate entry. This is again a List of undo
10025 blocks. Each item may again have an "alt"
10026 item.
10027
10028uniq({list} [, {func} [, {dict}]]) *uniq()* *E882*
10029 Remove second and succeeding copies of repeated adjacent
10030 {list} items in-place. Returns {list}. If you want a list
10031 to remain unmodified make a copy first: >
10032 :let newlist = uniq(copy(mylist))
10033< The default compare function uses the string representation of
10034 each item. For the use of {func} and {dict} see |sort()|.
10035
Bram Moolenaard592deb2022-06-17 15:42:40 +010010036 Returns zero if {list} is not a |List|.
10037
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010038 Can also be used as a |method|: >
10039 mylist->uniq()
10040
10041values({dict}) *values()*
10042 Return a |List| with all the values of {dict}. The |List| is
10043 in arbitrary order. Also see |items()| and |keys()|.
Bram Moolenaard592deb2022-06-17 15:42:40 +010010044 Returns zero if {dict} is not a |Dict|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010045
10046 Can also be used as a |method|: >
10047 mydict->values()
10048
LemonBoy0f7a3e12022-05-26 12:10:37 +010010049virtcol({expr} [, {list}]) *virtcol()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010050 The result is a Number, which is the screen column of the file
10051 position given with {expr}. That is, the last screen position
10052 occupied by the character at that position, when the screen
10053 would be of unlimited width. When there is a <Tab> at the
10054 position, the returned Number will be the column at the end of
10055 the <Tab>. For example, for a <Tab> in column 1, with 'ts'
10056 set to 8, it returns 8. |conceal| is ignored.
10057 For the byte position use |col()|.
LemonBoy0f7a3e12022-05-26 12:10:37 +010010058
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010059 For the use of {expr} see |col()|.
LemonBoy0f7a3e12022-05-26 12:10:37 +010010060
10061 When 'virtualedit' is used {expr} can be [lnum, col, off],
10062 where "off" is the offset in screen columns from the start of
10063 the character. E.g., a position within a <Tab> or after the
10064 last character. When "off" is omitted zero is used. When
10065 Virtual editing is active in the current mode, a position
10066 beyond the end of the line can be returned. Also see
10067 |'virtualedit'|
10068
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010069 The accepted positions are:
10070 . the cursor position
10071 $ the end of the cursor line (the result is the
10072 number of displayed characters in the cursor line
10073 plus one)
10074 'x position of mark x (if the mark is not set, 0 is
10075 returned)
10076 v In Visual mode: the start of the Visual area (the
10077 cursor is the end). When not in Visual mode
10078 returns the cursor position. Differs from |'<| in
10079 that it's updated right away.
LemonBoy0f7a3e12022-05-26 12:10:37 +010010080
10081 If {list} is present and non-zero then virtcol() returns a List
10082 with the first and last screen position occupied by the
10083 character.
10084
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010085 Note that only marks in the current file can be used.
10086 Examples: >
LemonBoy0f7a3e12022-05-26 12:10:37 +010010087 " With text "foo^Lbar" and cursor on the "^L":
10088
10089 virtcol(".") " returns 5
10090 virtcol(".", 1) " returns [4, 5]
10091 virtcol("$") " returns 9
10092
10093 " With text " there", with 't at 'h':
10094
10095 virtcol("'t") " returns 6
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010096< The first column is 1. 0 is returned for an error.
10097 A more advanced example that echoes the maximum length of
10098 all lines: >
10099 echo max(map(range(1, line('$')), "virtcol([v:val, '$'])"))
10100
10101< Can also be used as a |method|: >
10102 GetPos()->virtcol()
10103
Bram Moolenaar5a6ec102022-05-27 21:58:00 +010010104virtcol2col({winid}, {lnum}, {col}) *virtcol2col()*
10105 The result is a Number, which is the byte index of the
10106 character in window {winid} at buffer line {lnum} and virtual
10107 column {col}.
10108
10109 If {col} is greater than the last virtual column in line
10110 {lnum}, then the byte index of the character at the last
10111 virtual column is returned.
10112
10113 The {winid} argument can be the window number or the
10114 |window-ID|. If this is zero, then the current window is used.
10115
10116 Returns -1 if the window {winid} doesn't exist or the buffer
10117 line {lnum} or virtual column {col} is invalid.
10118
10119 See also |screenpos()|, |virtcol()| and |col()|.
10120
10121 Can also be used as a |method|: >
10122 GetWinid()->virtcol2col(lnum, col)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010123
10124visualmode([{expr}]) *visualmode()*
10125 The result is a String, which describes the last Visual mode
10126 used in the current buffer. Initially it returns an empty
10127 string, but once Visual mode has been used, it returns "v",
10128 "V", or "<CTRL-V>" (a single CTRL-V character) for
10129 character-wise, line-wise, or block-wise Visual mode
10130 respectively.
10131 Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +000010132 :exe "normal " .. visualmode()
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010133< This enters the same Visual mode as before. It is also useful
10134 in scripts if you wish to act differently depending on the
10135 Visual mode that was used.
10136 If Visual mode is active, use |mode()| to get the Visual mode
10137 (e.g., in a |:vmap|).
10138 If {expr} is supplied and it evaluates to a non-zero Number or
10139 a non-empty String, then the Visual mode will be cleared and
10140 the old value is returned. See |non-zero-arg|.
10141
10142wildmenumode() *wildmenumode()*
10143 Returns |TRUE| when the wildmenu is active and |FALSE|
10144 otherwise. See 'wildmenu' and 'wildmode'.
10145 This can be used in mappings to handle the 'wildcharm' option
10146 gracefully. (Makes only sense with |mapmode-c| mappings).
10147
10148 For example to make <c-j> work like <down> in wildmode, use: >
10149 :cnoremap <expr> <C-j> wildmenumode() ? "\<Down>\<Tab>" : "\<c-j>"
10150<
10151 (Note, this needs the 'wildcharm' option set appropriately).
10152
10153win_execute({id}, {command} [, {silent}]) *win_execute()*
10154 Like `execute()` but in the context of window {id}.
10155 The window will temporarily be made the current window,
10156 without triggering autocommands or changing directory. When
10157 executing {command} autocommands will be triggered, this may
10158 have unexpected side effects. Use |:noautocmd| if needed.
10159 Example: >
10160 call win_execute(winid, 'set syntax=python')
10161< Doing the same with `setwinvar()` would not trigger
10162 autocommands and not actually show syntax highlighting.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010163 *E994*
10164 Not all commands are allowed in popup windows.
10165 When window {id} does not exist then no error is given and
10166 an empty string is returned.
10167
10168 Can also be used as a |method|, the base is passed as the
10169 second argument: >
10170 GetCommand()->win_execute(winid)
10171
10172win_findbuf({bufnr}) *win_findbuf()*
10173 Returns a |List| with |window-ID|s for windows that contain
10174 buffer {bufnr}. When there is none the list is empty.
10175
10176 Can also be used as a |method|: >
10177 GetBufnr()->win_findbuf()
10178
10179win_getid([{win} [, {tab}]]) *win_getid()*
10180 Get the |window-ID| for the specified window.
10181 When {win} is missing use the current window.
10182 With {win} this is the window number. The top window has
10183 number 1.
10184 Without {tab} use the current tab, otherwise the tab with
10185 number {tab}. The first tab has number one.
10186 Return zero if the window cannot be found.
10187
10188 Can also be used as a |method|: >
10189 GetWinnr()->win_getid()
10190
10191
10192win_gettype([{nr}]) *win_gettype()*
10193 Return the type of the window:
10194 "autocmd" autocommand window. Temporary window
10195 used to execute autocommands.
10196 "command" command-line window |cmdwin|
10197 (empty) normal window
10198 "loclist" |location-list-window|
10199 "popup" popup window |popup|
10200 "preview" preview window |preview-window|
10201 "quickfix" |quickfix-window|
10202 "unknown" window {nr} not found
10203
10204 When {nr} is omitted return the type of the current window.
10205 When {nr} is given return the type of this window by number or
10206 |window-ID|.
10207
10208 Also see the 'buftype' option. When running a terminal in a
10209 popup window then 'buftype' is "terminal" and win_gettype()
10210 returns "popup".
10211
10212 Can also be used as a |method|: >
10213 GetWinid()->win_gettype()
10214<
10215win_gotoid({expr}) *win_gotoid()*
10216 Go to window with ID {expr}. This may also change the current
10217 tabpage.
10218 Return TRUE if successful, FALSE if the window cannot be found.
10219
10220 Can also be used as a |method|: >
10221 GetWinid()->win_gotoid()
10222
10223win_id2tabwin({expr}) *win_id2tabwin()*
10224 Return a list with the tab number and window number of window
10225 with ID {expr}: [tabnr, winnr].
10226 Return [0, 0] if the window cannot be found.
10227
10228 Can also be used as a |method|: >
10229 GetWinid()->win_id2tabwin()
10230
10231win_id2win({expr}) *win_id2win()*
10232 Return the window number of window with ID {expr}.
10233 Return 0 if the window cannot be found in the current tabpage.
10234
10235 Can also be used as a |method|: >
10236 GetWinid()->win_id2win()
10237
Daniel Steinbergee630312022-01-10 13:36:34 +000010238win_move_separator({nr}, {offset}) *win_move_separator()*
10239 Move window {nr}'s vertical separator (i.e., the right border)
10240 by {offset} columns, as if being dragged by the mouse. {nr}
10241 can be a window number or |window-ID|. A positive {offset}
10242 moves right and a negative {offset} moves left. Moving a
10243 window's vertical separator will change the width of the
10244 window and the width of other windows adjacent to the vertical
10245 separator. The magnitude of movement may be smaller than
10246 specified (e.g., as a consequence of maintaining
10247 'winminwidth'). Returns TRUE if the window can be found and
10248 FALSE otherwise.
Bram Moolenaard592deb2022-06-17 15:42:40 +010010249 This will fail for the rightmost window and a full-width
10250 window, since it has no separator on the right.
Bram Moolenaar76db9e02022-11-09 21:21:04 +000010251 Only works for the current tab page. *E1308*
Daniel Steinbergee630312022-01-10 13:36:34 +000010252
10253 Can also be used as a |method|: >
10254 GetWinnr()->win_move_separator(offset)
10255
10256win_move_statusline({nr}, {offset}) *win_move_statusline()*
10257 Move window {nr}'s status line (i.e., the bottom border) by
10258 {offset} rows, as if being dragged by the mouse. {nr} can be a
10259 window number or |window-ID|. A positive {offset} moves down
10260 and a negative {offset} moves up. Moving a window's status
10261 line will change the height of the window and the height of
10262 other windows adjacent to the status line. The magnitude of
10263 movement may be smaller than specified (e.g., as a consequence
10264 of maintaining 'winminheight'). Returns TRUE if the window can
10265 be found and FALSE otherwise.
Bram Moolenaar76db9e02022-11-09 21:21:04 +000010266 Only works for the current tab page.
Daniel Steinbergee630312022-01-10 13:36:34 +000010267
10268 Can also be used as a |method|: >
10269 GetWinnr()->win_move_statusline(offset)
10270
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010271win_screenpos({nr}) *win_screenpos()*
10272 Return the screen position of window {nr} as a list with two
10273 numbers: [row, col]. The first window always has position
10274 [1, 1], unless there is a tabline, then it is [2, 1].
10275 {nr} can be the window number or the |window-ID|. Use zero
10276 for the current window.
10277 Returns [0, 0] if the window cannot be found in the current
10278 tabpage.
10279
10280 Can also be used as a |method|: >
10281 GetWinid()->win_screenpos()
10282<
10283win_splitmove({nr}, {target} [, {options}]) *win_splitmove()*
10284 Move the window {nr} to a new split of the window {target}.
10285 This is similar to moving to {target}, creating a new window
10286 using |:split| but having the same contents as window {nr}, and
10287 then closing {nr}.
10288
10289 Both {nr} and {target} can be window numbers or |window-ID|s.
10290 Both must be in the current tab page.
10291
10292 Returns zero for success, non-zero for failure.
10293
10294 {options} is a |Dictionary| with the following optional entries:
10295 "vertical" When TRUE, the split is created vertically,
10296 like with |:vsplit|.
10297 "rightbelow" When TRUE, the split is made below or to the
10298 right (if vertical). When FALSE, it is done
10299 above or to the left (if vertical). When not
10300 present, the values of 'splitbelow' and
10301 'splitright' are used.
10302
10303 Can also be used as a |method|: >
10304 GetWinid()->win_splitmove(target)
10305<
10306
10307 *winbufnr()*
10308winbufnr({nr}) The result is a Number, which is the number of the buffer
10309 associated with window {nr}. {nr} can be the window number or
10310 the |window-ID|.
10311 When {nr} is zero, the number of the buffer in the current
10312 window is returned.
10313 When window {nr} doesn't exist, -1 is returned.
10314 Example: >
10315 :echo "The file in the current window is " . bufname(winbufnr(0))
10316<
10317 Can also be used as a |method|: >
10318 FindWindow()->winbufnr()->bufname()
10319<
10320 *wincol()*
10321wincol() The result is a Number, which is the virtual column of the
10322 cursor in the window. This is counting screen cells from the
10323 left side of the window. The leftmost column is one.
10324
10325 *windowsversion()*
10326windowsversion()
10327 The result is a String. For MS-Windows it indicates the OS
10328 version. E.g, Windows 10 is "10.0", Windows 8 is "6.2",
10329 Windows XP is "5.1". For non-MS-Windows systems the result is
10330 an empty string.
10331
10332winheight({nr}) *winheight()*
10333 The result is a Number, which is the height of window {nr}.
10334 {nr} can be the window number or the |window-ID|.
10335 When {nr} is zero, the height of the current window is
10336 returned. When window {nr} doesn't exist, -1 is returned.
10337 An existing window always has a height of zero or more.
10338 This excludes any window toolbar line.
10339 Examples: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +000010340 :echo "The current window has " .. winheight(0) .. " lines."
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010341
10342< Can also be used as a |method|: >
10343 GetWinid()->winheight()
10344<
10345winlayout([{tabnr}]) *winlayout()*
10346 The result is a nested List containing the layout of windows
10347 in a tabpage.
10348
10349 Without {tabnr} use the current tabpage, otherwise the tabpage
10350 with number {tabnr}. If the tabpage {tabnr} is not found,
10351 returns an empty list.
10352
10353 For a leaf window, it returns:
10354 ['leaf', {winid}]
10355 For horizontally split windows, which form a column, it
10356 returns:
10357 ['col', [{nested list of windows}]]
10358 For vertically split windows, which form a row, it returns:
10359 ['row', [{nested list of windows}]]
10360
10361 Example: >
10362 " Only one window in the tab page
10363 :echo winlayout()
10364 ['leaf', 1000]
10365 " Two horizontally split windows
10366 :echo winlayout()
10367 ['col', [['leaf', 1000], ['leaf', 1001]]]
10368 " The second tab page, with three horizontally split
10369 " windows, with two vertically split windows in the
10370 " middle window
10371 :echo winlayout(2)
10372 ['col', [['leaf', 1002], ['row', [['leaf', 1003],
10373 ['leaf', 1001]]], ['leaf', 1000]]]
10374<
10375 Can also be used as a |method|: >
10376 GetTabnr()->winlayout()
10377<
10378 *winline()*
10379winline() The result is a Number, which is the screen line of the cursor
10380 in the window. This is counting screen lines from the top of
10381 the window. The first line is one.
10382 If the cursor was moved the view on the file will be updated
10383 first, this may cause a scroll.
10384
10385 *winnr()*
10386winnr([{arg}]) The result is a Number, which is the number of the current
10387 window. The top window has number 1.
10388 Returns zero for a popup window.
10389
10390 The optional argument {arg} supports the following values:
10391 $ the number of the last window (the window
10392 count).
10393 # the number of the last accessed window (where
10394 |CTRL-W_p| goes to). If there is no previous
10395 window or it is in another tab page 0 is
10396 returned.
10397 {N}j the number of the Nth window below the
10398 current window (where |CTRL-W_j| goes to).
10399 {N}k the number of the Nth window above the current
10400 window (where |CTRL-W_k| goes to).
10401 {N}h the number of the Nth window left of the
10402 current window (where |CTRL-W_h| goes to).
10403 {N}l the number of the Nth window right of the
10404 current window (where |CTRL-W_l| goes to).
10405 The number can be used with |CTRL-W_w| and ":wincmd w"
10406 |:wincmd|.
Bram Moolenaar016188f2022-06-06 20:52:59 +010010407 When {arg} is invalid an error is given and zero is returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010408 Also see |tabpagewinnr()| and |win_getid()|.
10409 Examples: >
10410 let window_count = winnr('$')
10411 let prev_window = winnr('#')
10412 let wnum = winnr('3k')
10413
10414< Can also be used as a |method|: >
10415 GetWinval()->winnr()
10416<
10417 *winrestcmd()*
10418winrestcmd() Returns a sequence of |:resize| commands that should restore
10419 the current window sizes. Only works properly when no windows
10420 are opened or closed and the current window and tab page is
10421 unchanged.
10422 Example: >
10423 :let cmd = winrestcmd()
10424 :call MessWithWindowSizes()
10425 :exe cmd
10426<
10427 *winrestview()*
10428winrestview({dict})
10429 Uses the |Dictionary| returned by |winsaveview()| to restore
10430 the view of the current window.
10431 Note: The {dict} does not have to contain all values, that are
10432 returned by |winsaveview()|. If values are missing, those
10433 settings won't be restored. So you can use: >
10434 :call winrestview({'curswant': 4})
10435<
10436 This will only set the curswant value (the column the cursor
10437 wants to move on vertical movements) of the cursor to column 5
10438 (yes, that is 5), while all other settings will remain the
10439 same. This is useful, if you set the cursor position manually.
10440
10441 If you have changed the values the result is unpredictable.
10442 If the window size changed the result won't be the same.
10443
10444 Can also be used as a |method|: >
10445 GetView()->winrestview()
10446<
10447 *winsaveview()*
10448winsaveview() Returns a |Dictionary| that contains information to restore
10449 the view of the current window. Use |winrestview()| to
10450 restore the view.
10451 This is useful if you have a mapping that jumps around in the
10452 buffer and you want to go back to the original view.
10453 This does not save fold information. Use the 'foldenable'
10454 option to temporarily switch off folding, so that folds are
10455 not opened when moving around. This may have side effects.
10456 The return value includes:
10457 lnum cursor line number
10458 col cursor column (Note: the first column
naohiro ono56200ee2022-01-01 14:59:44 +000010459 zero, as opposed to what |getcurpos()|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010460 returns)
10461 coladd cursor column offset for 'virtualedit'
naohiro ono56200ee2022-01-01 14:59:44 +000010462 curswant column for vertical movement (Note:
10463 the first column is zero, as opposed
10464 to what |getcurpos()| returns). After
10465 |$| command it will be a very large
10466 number equal to |v:maxcol|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010467 topline first line in the window
10468 topfill filler lines, only in diff mode
10469 leftcol first column displayed; only used when
10470 'wrap' is off
10471 skipcol columns skipped
10472 Note that no option values are saved.
10473
10474
10475winwidth({nr}) *winwidth()*
10476 The result is a Number, which is the width of window {nr}.
10477 {nr} can be the window number or the |window-ID|.
10478 When {nr} is zero, the width of the current window is
10479 returned. When window {nr} doesn't exist, -1 is returned.
10480 An existing window always has a width of zero or more.
10481 Examples: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +000010482 :echo "The current window has " .. winwidth(0) .. " columns."
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010483 :if winwidth(0) <= 50
10484 : 50 wincmd |
10485 :endif
10486< For getting the terminal or screen size, see the 'columns'
10487 option.
10488
10489 Can also be used as a |method|: >
10490 GetWinid()->winwidth()
10491
10492
10493wordcount() *wordcount()*
10494 The result is a dictionary of byte/chars/word statistics for
10495 the current buffer. This is the same info as provided by
10496 |g_CTRL-G|
10497 The return value includes:
10498 bytes Number of bytes in the buffer
10499 chars Number of chars in the buffer
10500 words Number of words in the buffer
10501 cursor_bytes Number of bytes before cursor position
10502 (not in Visual mode)
10503 cursor_chars Number of chars before cursor position
10504 (not in Visual mode)
10505 cursor_words Number of words before cursor position
10506 (not in Visual mode)
10507 visual_bytes Number of bytes visually selected
10508 (only in Visual mode)
10509 visual_chars Number of chars visually selected
10510 (only in Visual mode)
10511 visual_words Number of words visually selected
10512 (only in Visual mode)
10513
10514
10515 *writefile()*
10516writefile({object}, {fname} [, {flags}])
10517 When {object} is a |List| write it to file {fname}. Each list
10518 item is separated with a NL. Each list item must be a String
10519 or Number.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010520 All NL characters are replaced with a NUL character.
10521 Inserting CR characters needs to be done before passing {list}
10522 to writefile().
Bram Moolenaar806a2732022-09-04 15:40:36 +010010523
10524 When {object} is a |Blob| write the bytes to file {fname}
10525 unmodified, also when binary mode is not specified.
10526
10527 {flags} must be a String. These characters are recognized:
10528
10529 'b' Binary mode is used: There will not be a NL after the
10530 last list item. An empty item at the end does cause the
10531 last line in the file to end in a NL.
10532
10533 'a' Append mode is used, lines are appended to the file: >
10534 :call writefile(["foo"], "event.log", "a")
10535 :call writefile(["bar"], "event.log", "a")
10536<
10537 'D' Delete the file when the current function ends. This
10538 works like: >
10539 :defer delete({fname})
10540< Fails when not in a function. Also see |:defer|.
10541
10542 's' fsync() is called after writing the file. This flushes
10543 the file to disk, if possible. This takes more time but
10544 avoids losing the file if the system crashes.
10545
10546 'S' fsync() is not called, even when 'fsync' is set.
10547
10548 When {flags} does not contain "S" or "s" then fsync() is
10549 called if the 'fsync' option is set.
10550
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010551 An existing file is overwritten, if possible.
Bram Moolenaar806a2732022-09-04 15:40:36 +010010552
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010553 When the write fails -1 is returned, otherwise 0. There is an
10554 error message if the file can't be created or when writing
10555 fails.
Bram Moolenaar806a2732022-09-04 15:40:36 +010010556
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010557 Also see |readfile()|.
10558 To copy a file byte for byte: >
10559 :let fl = readfile("foo", "b")
10560 :call writefile(fl, "foocopy", "b")
10561
10562< Can also be used as a |method|: >
10563 GetText()->writefile("thefile")
10564
10565
10566xor({expr}, {expr}) *xor()*
10567 Bitwise XOR on the two arguments. The arguments are converted
10568 to a number. A List, Dict or Float argument causes an error.
Bram Moolenaar5a6ec102022-05-27 21:58:00 +010010569 Also see `and()` and `or()`.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010570 Example: >
10571 :let bits = xor(bits, 0x80)
10572<
10573 Can also be used as a |method|: >
10574 :let bits = bits->xor(0x80)
10575<
10576
10577==============================================================================
105783. Feature list *feature-list*
10579
10580There are three types of features:
105811. Features that are only supported when they have been enabled when Vim
10582 was compiled |+feature-list|. Example: >
10583 :if has("cindent")
10584< *gui_running*
105852. Features that are only supported when certain conditions have been met.
10586 Example: >
10587 :if has("gui_running")
10588< *has-patch*
105893. Beyond a certain version or at a certain version and including a specific
10590 patch. The "patch-7.4.248" feature means that the Vim version is 7.5 or
10591 later, or it is version 7.4 and patch 248 was included. Example: >
10592 :if has("patch-7.4.248")
10593< Note that it's possible for patch 248 to be omitted even though 249 is
10594 included. Only happens when cherry-picking patches.
10595 Note that this form only works for patch 7.4.237 and later, before that
10596 you need to check for the patch and the v:version. Example (checking
10597 version 6.2.148 or later): >
10598 :if v:version > 602 || (v:version == 602 && has("patch148"))
10599
10600Hint: To find out if Vim supports backslashes in a file name (MS-Windows),
10601use: `if exists('+shellslash')`
10602
10603
10604acl Compiled with |ACL| support.
Bram Moolenaar2ee347f2022-08-26 17:53:44 +010010605all_builtin_terms Compiled with all builtin terminals enabled. (always
10606 true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010607amiga Amiga version of Vim.
10608arabic Compiled with Arabic support |Arabic|.
10609arp Compiled with ARP support (Amiga).
10610autocmd Compiled with autocommand support. (always true)
10611autochdir Compiled with support for 'autochdir'
10612autoservername Automatically enable |clientserver|
10613balloon_eval Compiled with |balloon-eval| support.
10614balloon_multiline GUI supports multiline balloons.
10615beos BeOS version of Vim.
10616browse Compiled with |:browse| support, and browse() will
10617 work.
10618browsefilter Compiled with support for |browsefilter|.
10619bsd Compiled on an OS in the BSD family (excluding macOS).
Bram Moolenaar2ee347f2022-08-26 17:53:44 +010010620builtin_terms Compiled with some builtin terminals. (always true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010621byte_offset Compiled with support for 'o' in 'statusline'
10622channel Compiled with support for |channel| and |job|
Bram Moolenaare1dc76f2022-06-25 18:01:32 +010010623cindent Compiled with 'cindent' support. (always true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010624clientserver Compiled with remote invocation support |clientserver|.
10625clipboard Compiled with 'clipboard' support.
10626clipboard_working Compiled with 'clipboard' support and it can be used.
10627cmdline_compl Compiled with |cmdline-completion| support.
10628cmdline_hist Compiled with |cmdline-history| support.
10629cmdline_info Compiled with 'showcmd' and 'ruler' support.
10630comments Compiled with |'comments'| support.
10631compatible Compiled to be very Vi compatible.
10632conpty Platform where |ConPTY| can be used.
10633cryptv Compiled with encryption support |encryption|.
10634cscope Compiled with |cscope| support.
10635cursorbind Compiled with |'cursorbind'| (always true)
10636debug Compiled with "DEBUG" defined.
10637dialog_con Compiled with console dialog support.
10638dialog_gui Compiled with GUI dialog support.
10639diff Compiled with |vimdiff| and 'diff' support.
10640digraphs Compiled with support for digraphs.
10641directx Compiled with support for DirectX and 'renderoptions'.
10642dnd Compiled with support for the "~ register |quote_~|.
10643drop_file Compiled with |drop_file| support.
10644ebcdic Compiled on a machine with ebcdic character set.
10645emacs_tags Compiled with support for Emacs tags.
10646eval Compiled with expression evaluation support. Always
10647 true, of course!
10648ex_extra |+ex_extra| (always true)
10649extra_search Compiled with support for |'incsearch'| and
10650 |'hlsearch'|
10651farsi Support for Farsi was removed |farsi|.
Bram Moolenaarf80f40a2022-08-25 16:02:23 +010010652file_in_path Compiled with support for |gf| and |<cfile>| (always
10653 true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010654filterpipe When 'shelltemp' is off pipes are used for shell
10655 read/write/filter commands
10656find_in_path Compiled with support for include file searches
10657 |+find_in_path|.
10658float Compiled with support for |Float|.
10659fname_case Case in file names matters (for Amiga and MS-Windows
10660 this is not present).
10661folding Compiled with |folding| support.
10662footer Compiled with GUI footer support. |gui-footer|
10663fork Compiled to use fork()/exec() instead of system().
10664gettext Compiled with message translation |multi-lang|
10665gui Compiled with GUI enabled.
Bram Moolenaarcbaff5e2022-04-08 17:45:08 +010010666gui_athena Compiled with Athena GUI (always false).
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010667gui_gnome Compiled with Gnome support (gui_gtk is also defined).
10668gui_gtk Compiled with GTK+ GUI (any version).
10669gui_gtk2 Compiled with GTK+ 2 GUI (gui_gtk is also defined).
10670gui_gtk3 Compiled with GTK+ 3 GUI (gui_gtk is also defined).
10671gui_haiku Compiled with Haiku GUI.
10672gui_mac Compiled with Macintosh GUI.
10673gui_motif Compiled with Motif GUI.
10674gui_photon Compiled with Photon GUI.
10675gui_running Vim is running in the GUI, or it will start soon.
10676gui_win32 Compiled with MS-Windows Win32 GUI.
10677gui_win32s idem, and Win32s system being used (Windows 3.1)
10678haiku Haiku version of Vim.
10679hangul_input Compiled with Hangul input support. |hangul|
10680hpux HP-UX version of Vim.
10681iconv Can use iconv() for conversion.
10682insert_expand Compiled with support for CTRL-X expansion commands in
10683 Insert mode. (always true)
10684job Compiled with support for |channel| and |job|
10685ipv6 Compiled with support for IPv6 networking in |channel|.
Bram Moolenaare1dc76f2022-06-25 18:01:32 +010010686jumplist Compiled with |jumplist| support. (always true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010687keymap Compiled with 'keymap' support.
10688lambda Compiled with |lambda| support.
10689langmap Compiled with 'langmap' support.
10690libcall Compiled with |libcall()| support.
10691linebreak Compiled with 'linebreak', 'breakat', 'showbreak' and
10692 'breakindent' support.
10693linux Linux version of Vim.
10694lispindent Compiled with support for lisp indenting.
Bram Moolenaare1dc76f2022-06-25 18:01:32 +010010695 (always true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010696listcmds Compiled with commands for the buffer list |:files|
10697 and the argument list |arglist|.
10698localmap Compiled with local mappings and abbr. |:map-local|
10699lua Compiled with Lua interface |Lua|.
10700mac Any Macintosh version of Vim cf. osx
10701macunix Synonym for osxdarwin
10702menu Compiled with support for |:menu|.
10703mksession Compiled with support for |:mksession|.
10704modify_fname Compiled with file name modifiers. |filename-modifiers|
10705 (always true)
10706mouse Compiled with support for mouse.
10707mouse_dec Compiled with support for Dec terminal mouse.
10708mouse_gpm Compiled with support for gpm (Linux console mouse)
10709mouse_gpm_enabled GPM mouse is working
10710mouse_netterm Compiled with support for netterm mouse.
10711mouse_pterm Compiled with support for qnx pterm mouse.
10712mouse_sysmouse Compiled with support for sysmouse (*BSD console mouse)
10713mouse_sgr Compiled with support for sgr mouse.
10714mouse_urxvt Compiled with support for urxvt mouse.
10715mouse_xterm Compiled with support for xterm mouse.
10716mouseshape Compiled with support for 'mouseshape'.
10717multi_byte Compiled with support for 'encoding' (always true)
10718multi_byte_encoding 'encoding' is set to a multibyte encoding.
10719multi_byte_ime Compiled with support for IME input method.
10720multi_lang Compiled with support for multiple languages.
10721mzscheme Compiled with MzScheme interface |mzscheme|.
10722nanotime Compiled with sub-second time stamp checks.
10723netbeans_enabled Compiled with support for |netbeans| and connected.
10724netbeans_intg Compiled with support for |netbeans|.
Bram Moolenaare1dc76f2022-06-25 18:01:32 +010010725num64 Compiled with 64-bit |Number| support. (always true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010726ole Compiled with OLE automation support for Win32.
10727osx Compiled for macOS cf. mac
10728osxdarwin Compiled for macOS, with |mac-darwin-feature|
10729packages Compiled with |packages| support.
10730path_extra Compiled with up/downwards search in 'path' and 'tags'
10731perl Compiled with Perl interface.
10732persistent_undo Compiled with support for persistent undo history.
10733postscript Compiled with PostScript file printing.
10734printer Compiled with |:hardcopy| support.
10735profile Compiled with |:profile| support.
10736python Python 2.x interface available. |has-python|
10737python_compiled Compiled with Python 2.x interface. |has-python|
10738python_dynamic Python 2.x interface is dynamically loaded. |has-python|
10739python3 Python 3.x interface available. |has-python|
10740python3_compiled Compiled with Python 3.x interface. |has-python|
10741python3_dynamic Python 3.x interface is dynamically loaded. |has-python|
10742pythonx Python 2.x and/or 3.x interface available. |python_x|
10743qnx QNX version of Vim.
10744quickfix Compiled with |quickfix| support.
10745reltime Compiled with |reltime()| support.
10746rightleft Compiled with 'rightleft' support.
10747ruby Compiled with Ruby interface |ruby|.
10748scrollbind Compiled with 'scrollbind' support. (always true)
10749showcmd Compiled with 'showcmd' support.
10750signs Compiled with |:sign| support.
Bram Moolenaare1dc76f2022-06-25 18:01:32 +010010751smartindent Compiled with 'smartindent' support. (always true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010752sodium Compiled with libsodium for better crypt support
10753sound Compiled with sound support, e.g. `sound_playevent()`
10754spell Compiled with spell checking support |spell|.
10755startuptime Compiled with |--startuptime| support.
10756statusline Compiled with support for 'statusline', 'rulerformat'
10757 and special formats of 'titlestring' and 'iconstring'.
10758sun SunOS version of Vim.
10759sun_workshop Support for Sun |workshop| has been removed.
10760syntax Compiled with syntax highlighting support |syntax|.
10761syntax_items There are active syntax highlighting items for the
10762 current buffer.
10763system Compiled to use system() instead of fork()/exec().
10764tag_binary Compiled with binary searching in tags files
Bram Moolenaare1dc76f2022-06-25 18:01:32 +010010765 |tag-binary-search|. (always true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010766tag_old_static Support for old static tags was removed, see
10767 |tag-old-static|.
10768tcl Compiled with Tcl interface.
10769termguicolors Compiled with true color in terminal support.
10770terminal Compiled with |terminal| support.
10771terminfo Compiled with terminfo instead of termcap.
10772termresponse Compiled with support for |t_RV| and |v:termresponse|.
10773textobjects Compiled with support for |text-objects|.
10774textprop Compiled with support for |text-properties|.
10775tgetent Compiled with tgetent support, able to use a termcap
10776 or terminfo file.
10777timers Compiled with |timer_start()| support.
10778title Compiled with window title support |'title'|.
Bram Moolenaare1dc76f2022-06-25 18:01:32 +010010779 (always true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010780toolbar Compiled with support for |gui-toolbar|.
10781ttyin input is a terminal (tty)
10782ttyout output is a terminal (tty)
10783unix Unix version of Vim. *+unix*
10784unnamedplus Compiled with support for "unnamedplus" in 'clipboard'
10785user_commands User-defined commands. (always true)
10786vartabs Compiled with variable tabstop support |'vartabstop'|.
10787vcon Win32: Virtual console support is working, can use
10788 'termguicolors'. Also see |+vtp|.
10789vertsplit Compiled with vertically split windows |:vsplit|.
10790 (always true)
10791vim_starting True while initial source'ing takes place. |startup|
10792 *vim_starting*
Bram Moolenaara6feb162022-01-02 12:06:33 +000010793vim9script Compiled with |Vim9| script support
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010794viminfo Compiled with viminfo support.
10795vimscript-1 Compiled Vim script version 1 support
10796vimscript-2 Compiled Vim script version 2 support
10797vimscript-3 Compiled Vim script version 3 support
Bram Moolenaar8a3b8052022-06-26 12:21:15 +010010798vimscript-4 Compiled Vim script version 4 support
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010799virtualedit Compiled with 'virtualedit' option. (always true)
10800visual Compiled with Visual mode. (always true)
10801visualextra Compiled with extra Visual mode commands. (always
10802 true) |blockwise-operators|.
10803vms VMS version of Vim.
10804vreplace Compiled with |gR| and |gr| commands. (always true)
10805vtp Compiled for vcon support |+vtp| (check vcon to find
10806 out if it works in the current console).
10807wildignore Compiled with 'wildignore' option.
10808wildmenu Compiled with 'wildmenu' option.
10809win16 old version for MS-Windows 3.1 (always false)
10810win32 Win32 version of Vim (MS-Windows 95 and later, 32 or
10811 64 bits)
10812win32unix Win32 version of Vim, using Unix files (Cygwin)
10813win64 Win64 version of Vim (MS-Windows 64 bit).
10814win95 Win32 version for MS-Windows 95/98/ME (always false)
10815winaltkeys Compiled with 'winaltkeys' option.
10816windows Compiled with support for more than one window.
10817 (always true)
10818writebackup Compiled with 'writebackup' default on.
10819xfontset Compiled with X fontset support |xfontset|.
10820xim Compiled with X input method support |xim|.
10821xpm Compiled with pixmap support.
10822xpm_w32 Compiled with pixmap support for Win32. (Only for
10823 backward compatibility. Use "xpm" instead.)
10824xsmp Compiled with X session management support.
10825xsmp_interact Compiled with interactive X session management support.
10826xterm_clipboard Compiled with support for xterm clipboard.
10827xterm_save Compiled with support for saving and restoring the
10828 xterm screen.
10829x11 Compiled with X11 support.
10830
10831
10832==============================================================================
108334. Matching a pattern in a String *string-match*
10834
10835This is common between several functions. A regexp pattern as explained at
10836|pattern| is normally used to find a match in the buffer lines. When a
10837pattern is used to find a match in a String, almost everything works in the
10838same way. The difference is that a String is handled like it is one line.
10839When it contains a "\n" character, this is not seen as a line break for the
10840pattern. It can be matched with a "\n" in the pattern, or with ".". Example:
10841>
10842 :let a = "aaaa\nxxxx"
10843 :echo matchstr(a, "..\n..")
10844 aa
10845 xx
10846 :echo matchstr(a, "a.x")
10847 a
10848 x
10849
10850Don't forget that "^" will only match at the first character of the String and
10851"$" at the last character of the string. They don't match after or before a
10852"\n".
10853
10854 vim:tw=78:ts=8:noet:ft=help:norl: