blob: acd0f5caa300fbe7fc487e90a32d32d70d6b6253 [file] [log] [blame]
Bram Moolenaarce001a32022-04-27 15:25:03 +01001*builtin.txt* For Vim version 8.2. Last change: 2022 Apr 25
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002
3
4 VIM REFERENCE MANUAL by Bram Moolenaar
5
6
7Builtin functions *builtin-functions*
8
9Note: Expression evaluation can be disabled at compile time. If this has been
10done, the builtin functions are not available. See |+eval| and
11|no-eval-feature|.
12
131. Overview |builtin-function-list|
142. Details |builtin-function-details|
153. Feature list |feature-list|
164. Matching a pattern in a String |string-match|
17
18==============================================================================
191. Overview *builtin-function-list*
20
21Use CTRL-] on the function name to jump to the full explanation.
22
23USAGE RESULT DESCRIPTION ~
24
25abs({expr}) Float or Number absolute value of {expr}
26acos({expr}) Float arc cosine of {expr}
27add({object}, {item}) List/Blob append {item} to {object}
28and({expr}, {expr}) Number bitwise AND
29append({lnum}, {text}) Number append {text} below line {lnum}
30appendbufline({expr}, {lnum}, {text})
31 Number append {text} below line {lnum}
32 in buffer {expr}
33argc([{winid}]) Number number of files in the argument list
34argidx() Number current index in the argument list
35arglistid([{winnr} [, {tabnr}]]) Number argument list id
36argv({nr} [, {winid}]) String {nr} entry of the argument list
37argv([-1, {winid}]) List the argument list
38asin({expr}) Float arc sine of {expr}
39assert_beeps({cmd}) Number assert {cmd} causes a beep
40assert_equal({exp}, {act} [, {msg}])
41 Number assert {exp} is equal to {act}
42assert_equalfile({fname-one}, {fname-two} [, {msg}])
43 Number assert file contents are equal
44assert_exception({error} [, {msg}])
45 Number assert {error} is in v:exception
46assert_fails({cmd} [, {error} [, {msg} [, {lnum} [, {context}]]]])
47 Number assert {cmd} fails
48assert_false({actual} [, {msg}])
49 Number assert {actual} is false
50assert_inrange({lower}, {upper}, {actual} [, {msg}])
51 Number assert {actual} is inside the range
52assert_match({pat}, {text} [, {msg}])
53 Number assert {pat} matches {text}
54assert_nobeep({cmd}) Number assert {cmd} does not cause a beep
55assert_notequal({exp}, {act} [, {msg}])
56 Number assert {exp} is not equal {act}
57assert_notmatch({pat}, {text} [, {msg}])
58 Number assert {pat} not matches {text}
59assert_report({msg}) Number report a test failure
60assert_true({actual} [, {msg}]) Number assert {actual} is true
61atan({expr}) Float arc tangent of {expr}
62atan2({expr1}, {expr2}) Float arc tangent of {expr1} / {expr2}
63balloon_gettext() String current text in the balloon
64balloon_show({expr}) none show {expr} inside the balloon
65balloon_split({msg}) List split {msg} as used for a balloon
66blob2list({blob}) List convert {blob} into a list of numbers
67browse({save}, {title}, {initdir}, {default})
68 String put up a file requester
69browsedir({title}, {initdir}) String put up a directory requester
70bufadd({name}) Number add a buffer to the buffer list
71bufexists({buf}) Number |TRUE| if buffer {buf} exists
72buflisted({buf}) Number |TRUE| if buffer {buf} is listed
73bufload({buf}) Number load buffer {buf} if not loaded yet
74bufloaded({buf}) Number |TRUE| if buffer {buf} is loaded
75bufname([{buf}]) String Name of the buffer {buf}
76bufnr([{buf} [, {create}]]) Number Number of the buffer {buf}
77bufwinid({buf}) Number window ID of buffer {buf}
78bufwinnr({buf}) Number window number of buffer {buf}
79byte2line({byte}) Number line number at byte count {byte}
80byteidx({expr}, {nr}) Number byte index of {nr}'th char in {expr}
81byteidxcomp({expr}, {nr}) Number byte index of {nr}'th char in {expr}
82call({func}, {arglist} [, {dict}])
83 any call {func} with arguments {arglist}
84ceil({expr}) Float round {expr} up
85ch_canread({handle}) Number check if there is something to read
86ch_close({handle}) none close {handle}
87ch_close_in({handle}) none close in part of {handle}
88ch_evalexpr({handle}, {expr} [, {options}])
89 any evaluate {expr} on JSON {handle}
90ch_evalraw({handle}, {string} [, {options}])
91 any evaluate {string} on raw {handle}
92ch_getbufnr({handle}, {what}) Number get buffer number for {handle}/{what}
93ch_getjob({channel}) Job get the Job of {channel}
94ch_info({handle}) String info about channel {handle}
95ch_log({msg} [, {handle}]) none write {msg} in the channel log file
96ch_logfile({fname} [, {mode}]) none start logging channel activity
97ch_open({address} [, {options}])
98 Channel open a channel to {address}
99ch_read({handle} [, {options}]) String read from {handle}
100ch_readblob({handle} [, {options}])
101 Blob read Blob from {handle}
102ch_readraw({handle} [, {options}])
103 String read raw from {handle}
104ch_sendexpr({handle}, {expr} [, {options}])
105 any send {expr} over JSON {handle}
106ch_sendraw({handle}, {expr} [, {options}])
107 any send {expr} over raw {handle}
108ch_setoptions({handle}, {options})
109 none set options for {handle}
110ch_status({handle} [, {options}])
111 String status of channel {handle}
112changenr() Number current change number
113char2nr({expr} [, {utf8}]) Number ASCII/UTF-8 value of first char in {expr}
114charclass({string}) Number character class of {string}
115charcol({expr}) Number column number of cursor or mark
116charidx({string}, {idx} [, {countcc}])
117 Number char index of byte {idx} in {string}
118chdir({dir}) String change current working directory
119cindent({lnum}) Number C indent for line {lnum}
120clearmatches([{win}]) none clear all matches
121col({expr}) Number column byte index of cursor or mark
122complete({startcol}, {matches}) none set Insert mode completion
123complete_add({expr}) Number add completion match
124complete_check() Number check for key typed during completion
125complete_info([{what}]) Dict get current completion information
126confirm({msg} [, {choices} [, {default} [, {type}]]])
127 Number number of choice picked by user
128copy({expr}) any make a shallow copy of {expr}
129cos({expr}) Float cosine of {expr}
130cosh({expr}) Float hyperbolic cosine of {expr}
131count({comp}, {expr} [, {ic} [, {start}]])
132 Number count how many {expr} are in {comp}
133cscope_connection([{num}, {dbpath} [, {prepend}]])
134 Number checks existence of cscope connection
135cursor({lnum}, {col} [, {off}])
136 Number move cursor to {lnum}, {col}, {off}
137cursor({list}) Number move cursor to position in {list}
138debugbreak({pid}) Number interrupt process being debugged
139deepcopy({expr} [, {noref}]) any make a full copy of {expr}
140delete({fname} [, {flags}]) Number delete the file or directory {fname}
141deletebufline({buf}, {first} [, {last}])
142 Number delete lines from buffer {buf}
143did_filetype() Number |TRUE| if FileType autocmd event used
144diff_filler({lnum}) Number diff filler lines about {lnum}
145diff_hlID({lnum}, {col}) Number diff highlighting at {lnum}/{col}
146digraph_get({chars}) String get the |digraph| of {chars}
147digraph_getlist([{listall}]) List get all |digraph|s
148digraph_set({chars}, {digraph}) Boolean register |digraph|
149digraph_setlist({digraphlist}) Boolean register multiple |digraph|s
150echoraw({expr}) none output {expr} as-is
151empty({expr}) Number |TRUE| if {expr} is empty
152environ() Dict return environment variables
153escape({string}, {chars}) String escape {chars} in {string} with '\'
154eval({string}) any evaluate {string} into its value
155eventhandler() Number |TRUE| if inside an event handler
156executable({expr}) Number 1 if executable {expr} exists
157execute({command}) String execute {command} and get the output
158exepath({expr}) String full path of the command {expr}
159exists({expr}) Number |TRUE| if {expr} exists
160exists_compiled({expr}) Number |TRUE| if {expr} exists at compile time
161exp({expr}) Float exponential of {expr}
162expand({expr} [, {nosuf} [, {list}]])
163 any expand special keywords in {expr}
Yegappan Lakshmanan2b74b682022-04-03 21:30:32 +0100164expandcmd({string} [, {options}])
165 String expand {string} like with `:edit`
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000166extend({expr1}, {expr2} [, {expr3}])
167 List/Dict insert items of {expr2} into {expr1}
168extendnew({expr1}, {expr2} [, {expr3}])
169 List/Dict like |extend()| but creates a new
170 List or Dictionary
171feedkeys({string} [, {mode}]) Number add key sequence to typeahead buffer
172filereadable({file}) Number |TRUE| if {file} is a readable file
173filewritable({file}) Number |TRUE| if {file} is a writable file
174filter({expr1}, {expr2}) List/Dict/Blob/String
175 remove items from {expr1} where
176 {expr2} is 0
177finddir({name} [, {path} [, {count}]])
178 String find directory {name} in {path}
179findfile({name} [, {path} [, {count}]])
180 String find file {name} in {path}
181flatten({list} [, {maxdepth}]) List flatten {list} up to {maxdepth} levels
182flattennew({list} [, {maxdepth}])
183 List flatten a copy of {list}
184float2nr({expr}) Number convert Float {expr} to a Number
185floor({expr}) Float round {expr} down
186fmod({expr1}, {expr2}) Float remainder of {expr1} / {expr2}
187fnameescape({fname}) String escape special characters in {fname}
188fnamemodify({fname}, {mods}) String modify file name
189foldclosed({lnum}) Number first line of fold at {lnum} if closed
190foldclosedend({lnum}) Number last line of fold at {lnum} if closed
191foldlevel({lnum}) Number fold level at {lnum}
192foldtext() String line displayed for closed fold
193foldtextresult({lnum}) String text for closed fold at {lnum}
194foreground() Number bring the Vim window to the foreground
195fullcommand({name}) String get full command from {name}
196funcref({name} [, {arglist}] [, {dict}])
197 Funcref reference to function {name}
198function({name} [, {arglist}] [, {dict}])
199 Funcref named reference to function {name}
200garbagecollect([{atexit}]) none free memory, breaking cyclic references
201get({list}, {idx} [, {def}]) any get item {idx} from {list} or {def}
202get({dict}, {key} [, {def}]) any get item {key} from {dict} or {def}
203get({func}, {what}) any get property of funcref/partial {func}
204getbufinfo([{buf}]) List information about buffers
205getbufline({buf}, {lnum} [, {end}])
206 List lines {lnum} to {end} of buffer {buf}
207getbufvar({buf}, {varname} [, {def}])
208 any variable {varname} in buffer {buf}
209getchangelist([{buf}]) List list of change list items
210getchar([expr]) Number or String
211 get one character from the user
212getcharmod() Number modifiers for the last typed character
213getcharpos({expr}) List position of cursor, mark, etc.
214getcharsearch() Dict last character search
215getcharstr([expr]) String get one character from the user
Shougo Matsushita79d599b2022-05-07 12:48:29 +0100216getcmdcompltype() String return the type of the current
217 command-line completion
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000218getcmdline() String return the current command-line
219getcmdpos() Number return cursor position in command-line
Shougo Matsushita79d599b2022-05-07 12:48:29 +0100220getcmdscreenpos() Number return cursor screen position in
221 command-line
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000222getcmdtype() String return current command-line type
223getcmdwintype() String return current command-line window type
224getcompletion({pat}, {type} [, {filtered}])
225 List list of cmdline completion matches
226getcurpos([{winnr}]) List position of the cursor
227getcursorcharpos([{winnr}]) List character position of the cursor
228getcwd([{winnr} [, {tabnr}]]) String get the current working directory
229getenv({name}) String return environment variable
230getfontname([{name}]) String name of font being used
231getfperm({fname}) String file permissions of file {fname}
232getfsize({fname}) Number size in bytes of file {fname}
233getftime({fname}) Number last modification time of file
234getftype({fname}) String description of type of file {fname}
235getimstatus() Number |TRUE| if the IME status is active
236getjumplist([{winnr} [, {tabnr}]])
237 List list of jump list items
238getline({lnum}) String line {lnum} of current buffer
239getline({lnum}, {end}) List lines {lnum} to {end} of current buffer
240getloclist({nr}) List list of location list items
241getloclist({nr}, {what}) Dict get specific location list properties
242getmarklist([{buf}]) List list of global/local marks
243getmatches([{win}]) List list of current matches
244getmousepos() Dict last known mouse position
245getpid() Number process ID of Vim
246getpos({expr}) List position of cursor, mark, etc.
247getqflist() List list of quickfix items
248getqflist({what}) Dict get specific quickfix list properties
249getreg([{regname} [, 1 [, {list}]]])
250 String or List contents of a register
251getreginfo([{regname}]) Dict information about a register
252getregtype([{regname}]) String type of a register
253gettabinfo([{expr}]) List list of tab pages
254gettabvar({nr}, {varname} [, {def}])
255 any variable {varname} in tab {nr} or {def}
256gettabwinvar({tabnr}, {winnr}, {name} [, {def}])
257 any {name} in {winnr} in tab page {tabnr}
258gettagstack([{nr}]) Dict get the tag stack of window {nr}
259gettext({text}) String lookup translation of {text}
260getwininfo([{winid}]) List list of info about each window
261getwinpos([{timeout}]) List X and Y coord in pixels of the Vim window
262getwinposx() Number X coord in pixels of the Vim window
263getwinposy() Number Y coord in pixels of the Vim window
264getwinvar({nr}, {varname} [, {def}])
265 any variable {varname} in window {nr}
266glob({expr} [, {nosuf} [, {list} [, {alllinks}]]])
267 any expand file wildcards in {expr}
268glob2regpat({expr}) String convert a glob pat into a search pat
269globpath({path}, {expr} [, {nosuf} [, {list} [, {alllinks}]]])
270 String do glob({expr}) for all dirs in {path}
271has({feature} [, {check}]) Number |TRUE| if feature {feature} supported
272has_key({dict}, {key}) Number |TRUE| if {dict} has entry {key}
273haslocaldir([{winnr} [, {tabnr}]])
274 Number |TRUE| if the window executed |:lcd|
275 or |:tcd|
276hasmapto({what} [, {mode} [, {abbr}]])
277 Number |TRUE| if mapping to {what} exists
278histadd({history}, {item}) Number add an item to a history
279histdel({history} [, {item}]) Number remove an item from a history
280histget({history} [, {index}]) String get the item {index} from a history
281histnr({history}) Number highest index of a history
282hlID({name}) Number syntax ID of highlight group {name}
283hlexists({name}) Number |TRUE| if highlight group {name} exists
284hlget([{name} [, {resolve}]]) List get highlight group attributes
285hlset({list}) Number set highlight group attributes
286hostname() String name of the machine Vim is running on
287iconv({expr}, {from}, {to}) String convert encoding of {expr}
288indent({lnum}) Number indent of line {lnum}
289index({object}, {expr} [, {start} [, {ic}]])
290 Number index in {object} where {expr} appears
291input({prompt} [, {text} [, {completion}]])
292 String get input from the user
293inputdialog({prompt} [, {text} [, {completion}]])
294 String like input() but in a GUI dialog
295inputlist({textlist}) Number let the user pick from a choice list
296inputrestore() Number restore typeahead
297inputsave() Number save and clear typeahead
298inputsecret({prompt} [, {text}]) String like input() but hiding the text
299insert({object}, {item} [, {idx}]) List insert {item} in {object} [before {idx}]
300interrupt() none interrupt script execution
301invert({expr}) Number bitwise invert
LemonBoydca1d402022-04-28 15:26:33 +0100302isabsolutepath({path}) Number |TRUE| if {path} is an absolute path
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000303isdirectory({directory}) Number |TRUE| if {directory} is a directory
304isinf({expr}) Number determine if {expr} is infinity value
305 (positive or negative)
306islocked({expr}) Number |TRUE| if {expr} is locked
307isnan({expr}) Number |TRUE| if {expr} is NaN
308items({dict}) List key-value pairs in {dict}
309job_getchannel({job}) Channel get the channel handle for {job}
310job_info([{job}]) Dict get information about {job}
311job_setoptions({job}, {options}) none set options for {job}
312job_start({command} [, {options}])
313 Job start a job
314job_status({job}) String get the status of {job}
315job_stop({job} [, {how}]) Number stop {job}
316join({list} [, {sep}]) String join {list} items into one String
317js_decode({string}) any decode JS style JSON
318js_encode({expr}) String encode JS style JSON
319json_decode({string}) any decode JSON
320json_encode({expr}) String encode JSON
321keys({dict}) List keys in {dict}
322len({expr}) Number the length of {expr}
323libcall({lib}, {func}, {arg}) String call {func} in library {lib} with {arg}
324libcallnr({lib}, {func}, {arg}) Number idem, but return a Number
325line({expr} [, {winid}]) Number line nr of cursor, last line or mark
326line2byte({lnum}) Number byte count of line {lnum}
327lispindent({lnum}) Number Lisp indent for line {lnum}
328list2blob({list}) Blob turn {list} of numbers into a Blob
329list2str({list} [, {utf8}]) String turn {list} of numbers into a String
330listener_add({callback} [, {buf}])
331 Number add a callback to listen to changes
332listener_flush([{buf}]) none invoke listener callbacks
333listener_remove({id}) none remove a listener callback
334localtime() Number current time
335log({expr}) Float natural logarithm (base e) of {expr}
336log10({expr}) Float logarithm of Float {expr} to base 10
337luaeval({expr} [, {expr}]) any evaluate |Lua| expression
338map({expr1}, {expr2}) List/Dict/Blob/String
339 change each item in {expr1} to {expr2}
340maparg({name} [, {mode} [, {abbr} [, {dict}]]])
341 String or Dict
342 rhs of mapping {name} in mode {mode}
343mapcheck({name} [, {mode} [, {abbr}]])
344 String check for mappings matching {name}
Ernie Rael09661202022-04-25 14:40:44 +0100345maplist([{abbr}]) List list of all mappings, a dict for each
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000346mapnew({expr1}, {expr2}) List/Dict/Blob/String
347 like |map()| but creates a new List or
348 Dictionary
349mapset({mode}, {abbr}, {dict}) none restore mapping from |maparg()| result
350match({expr}, {pat} [, {start} [, {count}]])
351 Number position where {pat} matches in {expr}
352matchadd({group}, {pattern} [, {priority} [, {id} [, {dict}]]])
353 Number highlight {pattern} with {group}
354matchaddpos({group}, {pos} [, {priority} [, {id} [, {dict}]]])
355 Number highlight positions with {group}
356matcharg({nr}) List arguments of |:match|
357matchdelete({id} [, {win}]) Number delete match identified by {id}
358matchend({expr}, {pat} [, {start} [, {count}]])
359 Number position where {pat} ends in {expr}
360matchfuzzy({list}, {str} [, {dict}])
361 List fuzzy match {str} in {list}
362matchfuzzypos({list}, {str} [, {dict}])
363 List fuzzy match {str} in {list}
364matchlist({expr}, {pat} [, {start} [, {count}]])
365 List match and submatches of {pat} in {expr}
366matchstr({expr}, {pat} [, {start} [, {count}]])
367 String {count}'th match of {pat} in {expr}
368matchstrpos({expr}, {pat} [, {start} [, {count}]])
369 List {count}'th match of {pat} in {expr}
370max({expr}) Number maximum value of items in {expr}
371menu_info({name} [, {mode}]) Dict get menu item information
372min({expr}) Number minimum value of items in {expr}
373mkdir({name} [, {path} [, {prot}]])
374 Number create directory {name}
375mode([expr]) String current editing mode
376mzeval({expr}) any evaluate |MzScheme| expression
377nextnonblank({lnum}) Number line nr of non-blank line >= {lnum}
378nr2char({expr} [, {utf8}]) String single char with ASCII/UTF-8 value {expr}
379or({expr}, {expr}) Number bitwise OR
380pathshorten({expr} [, {len}]) String shorten directory names in a path
381perleval({expr}) any evaluate |Perl| expression
382popup_atcursor({what}, {options}) Number create popup window near the cursor
383popup_beval({what}, {options}) Number create popup window for 'ballooneval'
384popup_clear() none close all popup windows
385popup_close({id} [, {result}]) none close popup window {id}
386popup_create({what}, {options}) Number create a popup window
387popup_dialog({what}, {options}) Number create a popup window used as a dialog
388popup_filter_menu({id}, {key}) Number filter for a menu popup window
389popup_filter_yesno({id}, {key}) Number filter for a dialog popup window
390popup_findinfo() Number get window ID of info popup window
391popup_findpreview() Number get window ID of preview popup window
392popup_getoptions({id}) Dict get options of popup window {id}
393popup_getpos({id}) Dict get position of popup window {id}
394popup_hide({id}) none hide popup menu {id}
395popup_list() List get a list of window IDs of all popups
396popup_locate({row}, {col}) Number get window ID of popup at position
397popup_menu({what}, {options}) Number create a popup window used as a menu
398popup_move({id}, {options}) none set position of popup window {id}
399popup_notification({what}, {options})
400 Number create a notification popup window
401popup_setoptions({id}, {options})
402 none set options for popup window {id}
403popup_settext({id}, {text}) none set the text of popup window {id}
404popup_show({id}) none unhide popup window {id}
405pow({x}, {y}) Float {x} to the power of {y}
406prevnonblank({lnum}) Number line nr of non-blank line <= {lnum}
407printf({fmt}, {expr1}...) String format text
408prompt_getprompt({buf}) String get prompt text
409prompt_setcallback({buf}, {expr}) none set prompt callback function
410prompt_setinterrupt({buf}, {text}) none set prompt interrupt function
411prompt_setprompt({buf}, {text}) none set prompt text
412prop_add({lnum}, {col}, {props}) none add one text property
413prop_add_list({props}, [[{lnum}, {col}, {end-lnum}, {end-col}], ...])
414 none add multiple text properties
415prop_clear({lnum} [, {lnum-end} [, {props}]])
416 none remove all text properties
417prop_find({props} [, {direction}])
418 Dict search for a text property
419prop_list({lnum} [, {props}]) List text properties in {lnum}
420prop_remove({props} [, {lnum} [, {lnum-end}]])
421 Number remove a text property
422prop_type_add({name}, {props}) none define a new property type
423prop_type_change({name}, {props})
424 none change an existing property type
425prop_type_delete({name} [, {props}])
426 none delete a property type
427prop_type_get({name} [, {props}])
428 Dict get property type values
429prop_type_list([{props}]) List get list of property types
430pum_getpos() Dict position and size of pum if visible
431pumvisible() Number whether popup menu is visible
432py3eval({expr}) any evaluate |python3| expression
433pyeval({expr}) any evaluate |Python| expression
434pyxeval({expr}) any evaluate |python_x| expression
435rand([{expr}]) Number get pseudo-random number
436range({expr} [, {max} [, {stride}]])
437 List items from {expr} to {max}
438readblob({fname}) Blob read a |Blob| from {fname}
439readdir({dir} [, {expr} [, {dict}]])
440 List file names in {dir} selected by {expr}
441readdirex({dir} [, {expr} [, {dict}]])
442 List file info in {dir} selected by {expr}
443readfile({fname} [, {type} [, {max}]])
444 List get list of lines from file {fname}
445reduce({object}, {func} [, {initial}])
446 any reduce {object} using {func}
447reg_executing() String get the executing register name
448reg_recording() String get the recording register name
449reltime([{start} [, {end}]]) List get time value
450reltimefloat({time}) Float turn the time value into a Float
451reltimestr({time}) String turn time value into a String
452remote_expr({server}, {string} [, {idvar} [, {timeout}]])
453 String send expression
454remote_foreground({server}) Number bring Vim server to the foreground
455remote_peek({serverid} [, {retvar}])
456 Number check for reply string
457remote_read({serverid} [, {timeout}])
458 String read reply string
459remote_send({server}, {string} [, {idvar}])
460 String send key sequence
461remote_startserver({name}) none become server {name}
462remove({list}, {idx} [, {end}]) any/List
463 remove items {idx}-{end} from {list}
464remove({blob}, {idx} [, {end}]) Number/Blob
465 remove bytes {idx}-{end} from {blob}
466remove({dict}, {key}) any remove entry {key} from {dict}
467rename({from}, {to}) Number rename (move) file from {from} to {to}
468repeat({expr}, {count}) String repeat {expr} {count} times
469resolve({filename}) String get filename a shortcut points to
470reverse({list}) List reverse {list} in-place
471round({expr}) Float round off {expr}
472rubyeval({expr}) any evaluate |Ruby| expression
473screenattr({row}, {col}) Number attribute at screen position
474screenchar({row}, {col}) Number character at screen position
475screenchars({row}, {col}) List List of characters at screen position
476screencol() Number current cursor column
477screenpos({winid}, {lnum}, {col}) Dict screen row and col of a text character
478screenrow() Number current cursor row
479screenstring({row}, {col}) String characters at screen position
480search({pattern} [, {flags} [, {stopline} [, {timeout} [, {skip}]]]])
481 Number search for {pattern}
482searchcount([{options}]) Dict get or update search stats
483searchdecl({name} [, {global} [, {thisblock}]])
484 Number search for variable declaration
485searchpair({start}, {middle}, {end} [, {flags} [, {skip} [...]]])
486 Number search for other end of start/end pair
487searchpairpos({start}, {middle}, {end} [, {flags} [, {skip} [...]]])
488 List search for other end of start/end pair
489searchpos({pattern} [, {flags} [, {stopline} [, {timeout} [, {skip}]]]])
490 List search for {pattern}
491server2client({clientid}, {string})
492 Number send reply string
493serverlist() String get a list of available servers
494setbufline({expr}, {lnum}, {text})
495 Number set line {lnum} to {text} in buffer
496 {expr}
497setbufvar({buf}, {varname}, {val})
498 none set {varname} in buffer {buf} to {val}
499setcellwidths({list}) none set character cell width overrides
500setcharpos({expr}, {list}) Number set the {expr} position to {list}
501setcharsearch({dict}) Dict set character search from {dict}
502setcmdpos({pos}) Number set cursor position in command-line
503setcursorcharpos({list}) Number move cursor to position in {list}
504setenv({name}, {val}) none set environment variable
505setfperm({fname}, {mode}) Number set {fname} file permissions to {mode}
506setline({lnum}, {line}) Number set line {lnum} to {line}
507setloclist({nr}, {list} [, {action}])
508 Number modify location list using {list}
509setloclist({nr}, {list}, {action}, {what})
510 Number modify specific location list props
511setmatches({list} [, {win}]) Number restore a list of matches
512setpos({expr}, {list}) Number set the {expr} position to {list}
513setqflist({list} [, {action}]) Number modify quickfix list using {list}
514setqflist({list}, {action}, {what})
515 Number modify specific quickfix list props
516setreg({n}, {v} [, {opt}]) Number set register to value and type
517settabvar({nr}, {varname}, {val}) none set {varname} in tab page {nr} to {val}
518settabwinvar({tabnr}, {winnr}, {varname}, {val})
519 none set {varname} in window {winnr} in tab
520 page {tabnr} to {val}
521settagstack({nr}, {dict} [, {action}])
522 Number modify tag stack using {dict}
523setwinvar({nr}, {varname}, {val}) none set {varname} in window {nr} to {val}
524sha256({string}) String SHA256 checksum of {string}
525shellescape({string} [, {special}])
526 String escape {string} for use as shell
527 command argument
528shiftwidth([{col}]) Number effective value of 'shiftwidth'
529sign_define({name} [, {dict}]) Number define or update a sign
530sign_define({list}) List define or update a list of signs
531sign_getdefined([{name}]) List get a list of defined signs
532sign_getplaced([{buf} [, {dict}]])
533 List get a list of placed signs
534sign_jump({id}, {group}, {buf})
535 Number jump to a sign
536sign_place({id}, {group}, {name}, {buf} [, {dict}])
537 Number place a sign
538sign_placelist({list}) List place a list of signs
539sign_undefine([{name}]) Number undefine a sign
540sign_undefine({list}) List undefine a list of signs
541sign_unplace({group} [, {dict}])
542 Number unplace a sign
543sign_unplacelist({list}) List unplace a list of signs
544simplify({filename}) String simplify filename as much as possible
545sin({expr}) Float sine of {expr}
546sinh({expr}) Float hyperbolic sine of {expr}
547slice({expr}, {start} [, {end}]) String, List or Blob
548 slice of a String, List or Blob
Bram Moolenaar2007dd42022-02-23 13:17:47 +0000549sort({list} [, {how} [, {dict}]])
550 List sort {list}, compare with {how}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000551sound_clear() none stop playing all sounds
552sound_playevent({name} [, {callback}])
553 Number play an event sound
554sound_playfile({path} [, {callback}])
555 Number play sound file {path}
556sound_stop({id}) none stop playing sound {id}
557soundfold({word}) String sound-fold {word}
558spellbadword() String badly spelled word at cursor
559spellsuggest({word} [, {max} [, {capital}]])
560 List spelling suggestions
561split({expr} [, {pat} [, {keepempty}]])
562 List make |List| from {pat} separated {expr}
563sqrt({expr}) Float square root of {expr}
564srand([{expr}]) List get seed for |rand()|
565state([{what}]) String current state of Vim
566str2float({expr} [, {quoted}]) Float convert String to Float
567str2list({expr} [, {utf8}]) List convert each character of {expr} to
568 ASCII/UTF-8 value
569str2nr({expr} [, {base} [, {quoted}]])
570 Number convert String to Number
571strcharlen({expr}) Number character length of the String {expr}
572strcharpart({str}, {start} [, {len} [, {skipcc}]])
573 String {len} characters of {str} at
574 character {start}
575strchars({expr} [, {skipcc}]) Number character count of the String {expr}
576strdisplaywidth({expr} [, {col}]) Number display length of the String {expr}
577strftime({format} [, {time}]) String format time with a specified format
578strgetchar({str}, {index}) Number get char {index} from {str}
579stridx({haystack}, {needle} [, {start}])
580 Number index of {needle} in {haystack}
581string({expr}) String String representation of {expr} value
582strlen({expr}) Number length of the String {expr}
583strpart({str}, {start} [, {len} [, {chars}]])
584 String {len} bytes/chars of {str} at
585 byte {start}
586strptime({format}, {timestring})
587 Number Convert {timestring} to unix timestamp
588strridx({haystack}, {needle} [, {start}])
589 Number last index of {needle} in {haystack}
590strtrans({expr}) String translate string to make it printable
591strwidth({expr}) Number display cell length of the String {expr}
592submatch({nr} [, {list}]) String or List
593 specific match in ":s" or substitute()
594substitute({expr}, {pat}, {sub}, {flags})
595 String all {pat} in {expr} replaced with {sub}
596swapinfo({fname}) Dict information about swap file {fname}
597swapname({buf}) String swap file of buffer {buf}
598synID({lnum}, {col}, {trans}) Number syntax ID at {lnum} and {col}
599synIDattr({synID}, {what} [, {mode}])
600 String attribute {what} of syntax ID {synID}
601synIDtrans({synID}) Number translated syntax ID of {synID}
602synconcealed({lnum}, {col}) List info about concealing
603synstack({lnum}, {col}) List stack of syntax IDs at {lnum} and {col}
604system({expr} [, {input}]) String output of shell command/filter {expr}
605systemlist({expr} [, {input}]) List output of shell command/filter {expr}
606tabpagebuflist([{arg}]) List list of buffer numbers in tab page
607tabpagenr([{arg}]) Number number of current or last tab page
608tabpagewinnr({tabarg} [, {arg}]) Number number of current window in tab page
609tagfiles() List tags files used
610taglist({expr} [, {filename}]) List list of tags matching {expr}
611tan({expr}) Float tangent of {expr}
612tanh({expr}) Float hyperbolic tangent of {expr}
613tempname() String name for a temporary file
614term_dumpdiff({filename}, {filename} [, {options}])
615 Number display difference between two dumps
616term_dumpload({filename} [, {options}])
617 Number displaying a screen dump
618term_dumpwrite({buf}, {filename} [, {options}])
619 none dump terminal window contents
620term_getaltscreen({buf}) Number get the alternate screen flag
621term_getansicolors({buf}) List get ANSI palette in GUI color mode
622term_getattr({attr}, {what}) Number get the value of attribute {what}
623term_getcursor({buf}) List get the cursor position of a terminal
624term_getjob({buf}) Job get the job associated with a terminal
625term_getline({buf}, {row}) String get a line of text from a terminal
626term_getscrolled({buf}) Number get the scroll count of a terminal
627term_getsize({buf}) List get the size of a terminal
628term_getstatus({buf}) String get the status of a terminal
629term_gettitle({buf}) String get the title of a terminal
630term_gettty({buf}, [{input}]) String get the tty name of a terminal
631term_list() List get the list of terminal buffers
632term_scrape({buf}, {row}) List get row of a terminal screen
633term_sendkeys({buf}, {keys}) none send keystrokes to a terminal
634term_setansicolors({buf}, {colors})
635 none set ANSI palette in GUI color mode
636term_setapi({buf}, {expr}) none set |terminal-api| function name prefix
637term_setkill({buf}, {how}) none set signal to stop job in terminal
638term_setrestore({buf}, {command}) none set command to restore terminal
639term_setsize({buf}, {rows}, {cols})
640 none set the size of a terminal
641term_start({cmd} [, {options}]) Number open a terminal window and run a job
642term_wait({buf} [, {time}]) Number wait for screen to be updated
643terminalprops() Dict properties of the terminal
644test_alloc_fail({id}, {countdown}, {repeat})
645 none make memory allocation fail
646test_autochdir() none enable 'autochdir' during startup
647test_feedinput({string}) none add key sequence to input buffer
648test_garbagecollect_now() none free memory right now for testing
649test_garbagecollect_soon() none free memory soon for testing
650test_getvalue({string}) any get value of an internal variable
Yegappan Lakshmanan06011e12022-01-30 12:37:29 +0000651test_gui_event({event}, {args}) bool generate a GUI event for testing
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000652test_ignore_error({expr}) none ignore a specific error
653test_null_blob() Blob null value for testing
654test_null_channel() Channel null value for testing
655test_null_dict() Dict null value for testing
656test_null_function() Funcref null value for testing
657test_null_job() Job null value for testing
658test_null_list() List null value for testing
659test_null_partial() Funcref null value for testing
660test_null_string() String null value for testing
661test_option_not_set({name}) none reset flag indicating option was set
662test_override({expr}, {val}) none test with Vim internal overrides
663test_refcount({expr}) Number get the reference count of {expr}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000664test_setmouse({row}, {col}) none set the mouse position for testing
665test_settime({expr}) none set current time for testing
666test_srand_seed([seed]) none set seed for testing srand()
667test_unknown() any unknown value for testing
668test_void() any void value for testing
669timer_info([{id}]) List information about timers
670timer_pause({id}, {pause}) none pause or unpause a timer
671timer_start({time}, {callback} [, {options}])
672 Number create a timer
673timer_stop({timer}) none stop a timer
674timer_stopall() none stop all timers
675tolower({expr}) String the String {expr} switched to lowercase
676toupper({expr}) String the String {expr} switched to uppercase
677tr({src}, {fromstr}, {tostr}) String translate chars of {src} in {fromstr}
678 to chars in {tostr}
679trim({text} [, {mask} [, {dir}]])
680 String trim characters in {mask} from {text}
681trunc({expr}) Float truncate Float {expr}
682type({expr}) Number type of value {expr}
683typename({expr}) String representation of the type of {expr}
684undofile({name}) String undo file name for {name}
685undotree() List undo file tree
686uniq({list} [, {func} [, {dict}]])
687 List remove adjacent duplicates from a list
688values({dict}) List values in {dict}
689virtcol({expr}) Number screen column of cursor or mark
690visualmode([expr]) String last visual mode used
691wildmenumode() Number whether 'wildmenu' mode is active
692win_execute({id}, {command} [, {silent}])
693 String execute {command} in window {id}
694win_findbuf({bufnr}) List find windows containing {bufnr}
695win_getid([{win} [, {tab}]]) Number get window ID for {win} in {tab}
696win_gettype([{nr}]) String type of window {nr}
697win_gotoid({expr}) Number go to window with ID {expr}
698win_id2tabwin({expr}) List get tab and window nr from window ID
699win_id2win({expr}) Number get window nr from window ID
Daniel Steinbergee630312022-01-10 13:36:34 +0000700win_move_separator({nr}) Number move window vertical separator
701win_move_statusline({nr}) Number move window status line
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000702win_screenpos({nr}) List get screen position of window {nr}
703win_splitmove({nr}, {target} [, {options}])
704 Number move window {nr} to split of {target}
705winbufnr({nr}) Number buffer number of window {nr}
706wincol() Number window column of the cursor
707windowsversion() String MS-Windows OS version
708winheight({nr}) Number height of window {nr}
709winlayout([{tabnr}]) List layout of windows in tab {tabnr}
710winline() Number window line of the cursor
711winnr([{expr}]) Number number of current window
712winrestcmd() String returns command to restore window sizes
713winrestview({dict}) none restore view of current window
714winsaveview() Dict save view of current window
715winwidth({nr}) Number width of window {nr}
716wordcount() Dict get byte/char/word statistics
717writefile({object}, {fname} [, {flags}])
718 Number write |Blob| or |List| of lines to file
719xor({expr}, {expr}) Number bitwise XOR
720
721==============================================================================
7222. Details *builtin-function-details*
723
724Not all functions are here, some have been moved to a help file covering the
725specific functionality.
726
727abs({expr}) *abs()*
728 Return the absolute value of {expr}. When {expr} evaluates to
729 a |Float| abs() returns a |Float|. When {expr} can be
730 converted to a |Number| abs() returns a |Number|. Otherwise
731 abs() gives an error message and returns -1.
732 Examples: >
733 echo abs(1.456)
734< 1.456 >
735 echo abs(-5.456)
736< 5.456 >
737 echo abs(-4)
738< 4
739
740 Can also be used as a |method|: >
741 Compute()->abs()
742
743< {only available when compiled with the |+float| feature}
744
745
746acos({expr}) *acos()*
747 Return the arc cosine of {expr} measured in radians, as a
748 |Float| in the range of [0, pi].
749 {expr} must evaluate to a |Float| or a |Number| in the range
750 [-1, 1].
751 Examples: >
752 :echo acos(0)
753< 1.570796 >
754 :echo acos(-0.5)
755< 2.094395
756
757 Can also be used as a |method|: >
758 Compute()->acos()
759
760< {only available when compiled with the |+float| feature}
761
762
763add({object}, {expr}) *add()*
764 Append the item {expr} to |List| or |Blob| {object}. Returns
765 the resulting |List| or |Blob|. Examples: >
766 :let alist = add([1, 2, 3], item)
767 :call add(mylist, "woodstock")
768< Note that when {expr} is a |List| it is appended as a single
769 item. Use |extend()| to concatenate |Lists|.
770 When {object} is a |Blob| then {expr} must be a number.
771 Use |insert()| to add an item at another position.
772
773 Can also be used as a |method|: >
774 mylist->add(val1)->add(val2)
775
776
777and({expr}, {expr}) *and()*
778 Bitwise AND on the two arguments. The arguments are converted
779 to a number. A List, Dict or Float argument causes an error.
780 Example: >
781 :let flag = and(bits, 0x80)
782< Can also be used as a |method|: >
783 :let flag = bits->and(0x80)
784
785
786append({lnum}, {text}) *append()*
787 When {text} is a |List|: Append each item of the |List| as a
788 text line below line {lnum} in the current buffer.
789 Otherwise append {text} as one text line below line {lnum} in
790 the current buffer.
791 Any type of item is accepted and converted to a String.
792 {lnum} can be zero to insert a line before the first one.
793 {lnum} is used like with |getline()|.
794 Returns 1 for failure ({lnum} out of range or out of memory),
795 0 for success. In |Vim9| script an invalid argument or
796 negative number results in an error. Example: >
797 :let failed = append(line('$'), "# THE END")
798 :let failed = append(0, ["Chapter 1", "the beginning"])
799
800< Can also be used as a |method| after a List, the base is
801 passed as the second argument: >
802 mylist->append(lnum)
803
804
805appendbufline({buf}, {lnum}, {text}) *appendbufline()*
806 Like |append()| but append the text in buffer {buf}.
807
808 This function works only for loaded buffers. First call
809 |bufload()| if needed.
810
811 For the use of {buf}, see |bufname()|.
812
Bram Moolenaar8b6256f2021-12-28 11:24:49 +0000813 {lnum} is the line number to append below. Note that using
814 |line()| would use the current buffer, not the one appending
815 to. Use "$" to append at the end of the buffer. Other string
816 values are not supported.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000817
818 On success 0 is returned, on failure 1 is returned.
819 In |Vim9| script an error is given for an invalid {lnum}.
820
821 If {buf} is not a valid buffer or {lnum} is not valid, an
822 error message is given. Example: >
823 :let failed = appendbufline(13, 0, "# THE START")
824<
825 Can also be used as a |method| after a List, the base is
826 passed as the second argument: >
827 mylist->appendbufline(buf, lnum)
828
829
830argc([{winid}]) *argc()*
831 The result is the number of files in the argument list. See
832 |arglist|.
833 If {winid} is not supplied, the argument list of the current
834 window is used.
835 If {winid} is -1, the global argument list is used.
836 Otherwise {winid} specifies the window of which the argument
837 list is used: either the window number or the window ID.
838 Returns -1 if the {winid} argument is invalid.
839
840 *argidx()*
841argidx() The result is the current index in the argument list. 0 is
842 the first file. argc() - 1 is the last one. See |arglist|.
843
844 *arglistid()*
845arglistid([{winnr} [, {tabnr}]])
846 Return the argument list ID. This is a number which
847 identifies the argument list being used. Zero is used for the
848 global argument list. See |arglist|.
849 Returns -1 if the arguments are invalid.
850
851 Without arguments use the current window.
852 With {winnr} only use this window in the current tab page.
853 With {winnr} and {tabnr} use the window in the specified tab
854 page.
855 {winnr} can be the window number or the |window-ID|.
856
857 *argv()*
858argv([{nr} [, {winid}]])
859 The result is the {nr}th file in the argument list. See
860 |arglist|. "argv(0)" is the first one. Example: >
861 :let i = 0
862 :while i < argc()
863 : let f = escape(fnameescape(argv(i)), '.')
Bram Moolenaarc51cf032022-02-26 12:25:45 +0000864 : exe 'amenu Arg.' .. f .. ' :e ' .. f .. '<CR>'
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000865 : let i = i + 1
866 :endwhile
867< Without the {nr} argument, or when {nr} is -1, a |List| with
868 the whole |arglist| is returned.
869
870 The {winid} argument specifies the window ID, see |argc()|.
871 For the Vim command line arguments see |v:argv|.
872
873asin({expr}) *asin()*
874 Return the arc sine of {expr} measured in radians, as a |Float|
875 in the range of [-pi/2, pi/2].
876 {expr} must evaluate to a |Float| or a |Number| in the range
877 [-1, 1].
878 Examples: >
879 :echo asin(0.8)
880< 0.927295 >
881 :echo asin(-0.5)
882< -0.523599
883
884 Can also be used as a |method|: >
885 Compute()->asin()
886<
887 {only available when compiled with the |+float| feature}
888
889
890assert_ functions are documented here: |assert-functions-details|
891
892
893
894atan({expr}) *atan()*
895 Return the principal value of the arc tangent of {expr}, in
896 the range [-pi/2, +pi/2] radians, as a |Float|.
897 {expr} must evaluate to a |Float| or a |Number|.
898 Examples: >
899 :echo atan(100)
900< 1.560797 >
901 :echo atan(-4.01)
902< -1.326405
903
904 Can also be used as a |method|: >
905 Compute()->atan()
906<
907 {only available when compiled with the |+float| feature}
908
909
910atan2({expr1}, {expr2}) *atan2()*
911 Return the arc tangent of {expr1} / {expr2}, measured in
912 radians, as a |Float| in the range [-pi, pi].
913 {expr1} and {expr2} must evaluate to a |Float| or a |Number|.
914 Examples: >
915 :echo atan2(-1, 1)
916< -0.785398 >
917 :echo atan2(1, -1)
918< 2.356194
919
920 Can also be used as a |method|: >
921 Compute()->atan2(1)
922<
923 {only available when compiled with the |+float| feature}
924
925balloon_gettext() *balloon_gettext()*
926 Return the current text in the balloon. Only for the string,
927 not used for the List.
928
929balloon_show({expr}) *balloon_show()*
930 Show {expr} inside the balloon. For the GUI {expr} is used as
931 a string. For a terminal {expr} can be a list, which contains
932 the lines of the balloon. If {expr} is not a list it will be
933 split with |balloon_split()|.
934 If {expr} is an empty string any existing balloon is removed.
935
936 Example: >
937 func GetBalloonContent()
938 " ... initiate getting the content
939 return ''
940 endfunc
941 set balloonexpr=GetBalloonContent()
942
943 func BalloonCallback(result)
944 call balloon_show(a:result)
945 endfunc
946< Can also be used as a |method|: >
947 GetText()->balloon_show()
948<
949 The intended use is that fetching the content of the balloon
950 is initiated from 'balloonexpr'. It will invoke an
951 asynchronous method, in which a callback invokes
952 balloon_show(). The 'balloonexpr' itself can return an
953 empty string or a placeholder.
954
955 When showing a balloon is not possible nothing happens, no
956 error message.
957 {only available when compiled with the |+balloon_eval| or
958 |+balloon_eval_term| feature}
959
960balloon_split({msg}) *balloon_split()*
961 Split String {msg} into lines to be displayed in a balloon.
962 The splits are made for the current window size and optimize
963 to show debugger output.
964 Returns a |List| with the split lines.
965 Can also be used as a |method|: >
966 GetText()->balloon_split()->balloon_show()
967
968< {only available when compiled with the |+balloon_eval_term|
969 feature}
970
971blob2list({blob}) *blob2list()*
972 Return a List containing the number value of each byte in Blob
973 {blob}. Examples: >
974 blob2list(0z0102.0304) returns [1, 2, 3, 4]
975 blob2list(0z) returns []
976< Returns an empty List on error. |list2blob()| does the
977 opposite.
978
979 Can also be used as a |method|: >
980 GetBlob()->blob2list()
981
982 *browse()*
983browse({save}, {title}, {initdir}, {default})
984 Put up a file requester. This only works when "has("browse")"
985 returns |TRUE| (only in some GUI versions).
986 The input fields are:
987 {save} when |TRUE|, select file to write
988 {title} title for the requester
989 {initdir} directory to start browsing in
990 {default} default file name
991 An empty string is returned when the "Cancel" button is hit,
992 something went wrong, or browsing is not possible.
993
994 *browsedir()*
995browsedir({title}, {initdir})
996 Put up a directory requester. This only works when
997 "has("browse")" returns |TRUE| (only in some GUI versions).
998 On systems where a directory browser is not supported a file
999 browser is used. In that case: select a file in the directory
1000 to be used.
1001 The input fields are:
1002 {title} title for the requester
1003 {initdir} directory to start browsing in
1004 When the "Cancel" button is hit, something went wrong, or
1005 browsing is not possible, an empty string is returned.
1006
1007bufadd({name}) *bufadd()*
1008 Add a buffer to the buffer list with String {name}.
1009 If a buffer for file {name} already exists, return that buffer
1010 number. Otherwise return the buffer number of the newly
1011 created buffer. When {name} is an empty string then a new
1012 buffer is always created.
1013 The buffer will not have 'buflisted' set and not be loaded
1014 yet. To add some text to the buffer use this: >
1015 let bufnr = bufadd('someName')
1016 call bufload(bufnr)
1017 call setbufline(bufnr, 1, ['some', 'text'])
1018< Can also be used as a |method|: >
1019 let bufnr = 'somename'->bufadd()
1020
1021bufexists({buf}) *bufexists()*
1022 The result is a Number, which is |TRUE| if a buffer called
1023 {buf} exists.
1024 If the {buf} argument is a number, buffer numbers are used.
1025 Number zero is the alternate buffer for the current window.
1026
1027 If the {buf} argument is a string it must match a buffer name
1028 exactly. The name can be:
1029 - Relative to the current directory.
1030 - A full path.
1031 - The name of a buffer with 'buftype' set to "nofile".
1032 - A URL name.
1033 Unlisted buffers will be found.
1034 Note that help files are listed by their short name in the
1035 output of |:buffers|, but bufexists() requires using their
1036 long name to be able to find them.
1037 bufexists() may report a buffer exists, but to use the name
1038 with a |:buffer| command you may need to use |expand()|. Esp
1039 for MS-Windows 8.3 names in the form "c:\DOCUME~1"
1040 Use "bufexists(0)" to test for the existence of an alternate
1041 file name.
1042
1043 Can also be used as a |method|: >
1044 let exists = 'somename'->bufexists()
1045<
1046 Obsolete name: buffer_exists(). *buffer_exists()*
1047
1048buflisted({buf}) *buflisted()*
1049 The result is a Number, which is |TRUE| if a buffer called
1050 {buf} exists and is listed (has the 'buflisted' option set).
1051 The {buf} argument is used like with |bufexists()|.
1052
1053 Can also be used as a |method|: >
1054 let listed = 'somename'->buflisted()
1055
1056bufload({buf}) *bufload()*
1057 Ensure the buffer {buf} is loaded. When the buffer name
1058 refers to an existing file then the file is read. Otherwise
1059 the buffer will be empty. If the buffer was already loaded
1060 then there is no change.
1061 If there is an existing swap file for the file of the buffer,
1062 there will be no dialog, the buffer will be loaded anyway.
1063 The {buf} argument is used like with |bufexists()|.
1064
1065 Can also be used as a |method|: >
1066 eval 'somename'->bufload()
1067
1068bufloaded({buf}) *bufloaded()*
1069 The result is a Number, which is |TRUE| if a buffer called
1070 {buf} exists and is loaded (shown in a window or hidden).
1071 The {buf} argument is used like with |bufexists()|.
1072
1073 Can also be used as a |method|: >
1074 let loaded = 'somename'->bufloaded()
1075
1076bufname([{buf}]) *bufname()*
1077 The result is the name of a buffer. Mostly as it is displayed
1078 by the `:ls` command, but not using special names such as
1079 "[No Name]".
1080 If {buf} is omitted the current buffer is used.
1081 If {buf} is a Number, that buffer number's name is given.
1082 Number zero is the alternate buffer for the current window.
1083 If {buf} is a String, it is used as a |file-pattern| to match
1084 with the buffer names. This is always done like 'magic' is
1085 set and 'cpoptions' is empty. When there is more than one
1086 match an empty string is returned.
1087 "" or "%" can be used for the current buffer, "#" for the
1088 alternate buffer.
1089 A full match is preferred, otherwise a match at the start, end
1090 or middle of the buffer name is accepted. If you only want a
1091 full match then put "^" at the start and "$" at the end of the
1092 pattern.
1093 Listed buffers are found first. If there is a single match
1094 with a listed buffer, that one is returned. Next unlisted
1095 buffers are searched for.
1096 If the {buf} is a String, but you want to use it as a buffer
1097 number, force it to be a Number by adding zero to it: >
1098 :echo bufname("3" + 0)
1099< Can also be used as a |method|: >
1100 echo bufnr->bufname()
1101
1102< If the buffer doesn't exist, or doesn't have a name, an empty
1103 string is returned. >
1104 bufname("#") alternate buffer name
1105 bufname(3) name of buffer 3
1106 bufname("%") name of current buffer
1107 bufname("file2") name of buffer where "file2" matches.
1108< *buffer_name()*
1109 Obsolete name: buffer_name().
1110
1111 *bufnr()*
1112bufnr([{buf} [, {create}]])
1113 The result is the number of a buffer, as it is displayed by
1114 the `:ls` command. For the use of {buf}, see |bufname()|
1115 above.
1116
1117 If the buffer doesn't exist, -1 is returned. Or, if the
1118 {create} argument is present and TRUE, a new, unlisted,
1119 buffer is created and its number is returned. Example: >
1120 let newbuf = bufnr('Scratch001', 1)
1121< Using an empty name uses the current buffer. To create a new
1122 buffer with an empty name use |bufadd()|.
1123
1124 bufnr("$") is the last buffer: >
1125 :let last_buffer = bufnr("$")
1126< The result is a Number, which is the highest buffer number
1127 of existing buffers. Note that not all buffers with a smaller
1128 number necessarily exist, because ":bwipeout" may have removed
1129 them. Use bufexists() to test for the existence of a buffer.
1130
1131 Can also be used as a |method|: >
1132 echo bufref->bufnr()
1133<
1134 Obsolete name: buffer_number(). *buffer_number()*
1135 *last_buffer_nr()*
1136 Obsolete name for bufnr("$"): last_buffer_nr().
1137
1138bufwinid({buf}) *bufwinid()*
1139 The result is a Number, which is the |window-ID| of the first
1140 window associated with buffer {buf}. For the use of {buf},
1141 see |bufname()| above. If buffer {buf} doesn't exist or
1142 there is no such window, -1 is returned. Example: >
1143
Bram Moolenaarc51cf032022-02-26 12:25:45 +00001144 echo "A window containing buffer 1 is " .. (bufwinid(1))
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001145<
1146 Only deals with the current tab page.
1147
1148 Can also be used as a |method|: >
1149 FindBuffer()->bufwinid()
1150
1151bufwinnr({buf}) *bufwinnr()*
1152 Like |bufwinid()| but return the window number instead of the
1153 |window-ID|.
1154 If buffer {buf} doesn't exist or there is no such window, -1
1155 is returned. Example: >
1156
Bram Moolenaarc51cf032022-02-26 12:25:45 +00001157 echo "A window containing buffer 1 is " .. (bufwinnr(1))
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001158
1159< The number can be used with |CTRL-W_w| and ":wincmd w"
1160 |:wincmd|.
1161
1162 Can also be used as a |method|: >
1163 FindBuffer()->bufwinnr()
1164
1165byte2line({byte}) *byte2line()*
1166 Return the line number that contains the character at byte
1167 count {byte} in the current buffer. This includes the
1168 end-of-line character, depending on the 'fileformat' option
1169 for the current buffer. The first character has byte count
1170 one.
1171 Also see |line2byte()|, |go| and |:goto|.
1172
1173 Can also be used as a |method|: >
1174 GetOffset()->byte2line()
1175
1176< {not available when compiled without the |+byte_offset|
1177 feature}
1178
1179byteidx({expr}, {nr}) *byteidx()*
1180 Return byte index of the {nr}'th character in the String
1181 {expr}. Use zero for the first character, it then returns
1182 zero.
1183 If there are no multibyte characters the returned value is
1184 equal to {nr}.
1185 Composing characters are not counted separately, their byte
1186 length is added to the preceding base character. See
1187 |byteidxcomp()| below for counting composing characters
1188 separately.
1189 Example : >
1190 echo matchstr(str, ".", byteidx(str, 3))
1191< will display the fourth character. Another way to do the
1192 same: >
1193 let s = strpart(str, byteidx(str, 3))
1194 echo strpart(s, 0, byteidx(s, 1))
1195< Also see |strgetchar()| and |strcharpart()|.
1196
1197 If there are less than {nr} characters -1 is returned.
1198 If there are exactly {nr} characters the length of the string
1199 in bytes is returned.
1200
1201 Can also be used as a |method|: >
1202 GetName()->byteidx(idx)
1203
1204byteidxcomp({expr}, {nr}) *byteidxcomp()*
1205 Like byteidx(), except that a composing character is counted
1206 as a separate character. Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00001207 let s = 'e' .. nr2char(0x301)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001208 echo byteidx(s, 1)
1209 echo byteidxcomp(s, 1)
1210 echo byteidxcomp(s, 2)
1211< The first and third echo result in 3 ('e' plus composing
1212 character is 3 bytes), the second echo results in 1 ('e' is
1213 one byte).
1214 Only works differently from byteidx() when 'encoding' is set
1215 to a Unicode encoding.
1216
1217 Can also be used as a |method|: >
1218 GetName()->byteidxcomp(idx)
1219
1220call({func}, {arglist} [, {dict}]) *call()* *E699*
1221 Call function {func} with the items in |List| {arglist} as
1222 arguments.
1223 {func} can either be a |Funcref| or the name of a function.
1224 a:firstline and a:lastline are set to the cursor line.
1225 Returns the return value of the called function.
1226 {dict} is for functions with the "dict" attribute. It will be
1227 used to set the local variable "self". |Dictionary-function|
1228
1229 Can also be used as a |method|: >
1230 GetFunc()->call([arg, arg], dict)
1231
1232ceil({expr}) *ceil()*
1233 Return the smallest integral value greater than or equal to
1234 {expr} as a |Float| (round up).
1235 {expr} must evaluate to a |Float| or a |Number|.
1236 Examples: >
1237 echo ceil(1.456)
1238< 2.0 >
1239 echo ceil(-5.456)
1240< -5.0 >
1241 echo ceil(4.0)
1242< 4.0
1243
1244 Can also be used as a |method|: >
1245 Compute()->ceil()
1246<
1247 {only available when compiled with the |+float| feature}
1248
1249
1250ch_ functions are documented here: |channel-functions-details|
1251
1252
1253changenr() *changenr()*
1254 Return the number of the most recent change. This is the same
1255 number as what is displayed with |:undolist| and can be used
1256 with the |:undo| command.
1257 When a change was made it is the number of that change. After
1258 redo it is the number of the redone change. After undo it is
1259 one less than the number of the undone change.
1260
1261char2nr({string} [, {utf8}]) *char2nr()*
1262 Return number value of the first char in {string}.
1263 Examples: >
1264 char2nr(" ") returns 32
1265 char2nr("ABC") returns 65
1266< When {utf8} is omitted or zero, the current 'encoding' is used.
1267 Example for "utf-8": >
1268 char2nr("á") returns 225
1269 char2nr("á"[0]) returns 195
1270< When {utf8} is TRUE, always treat as UTF-8 characters.
1271 A combining character is a separate character.
1272 |nr2char()| does the opposite.
1273 To turn a string into a list of character numbers: >
1274 let str = "ABC"
1275 let list = map(split(str, '\zs'), {_, val -> char2nr(val)})
1276< Result: [65, 66, 67]
1277
1278 Can also be used as a |method|: >
1279 GetChar()->char2nr()
1280
1281
1282charclass({string}) *charclass()*
1283 Return the character class of the first character in {string}.
1284 The character class is one of:
1285 0 blank
1286 1 punctuation
1287 2 word character
1288 3 emoji
1289 other specific Unicode class
1290 The class is used in patterns and word motions.
1291
1292
1293charcol({expr}) *charcol()*
1294 Same as |col()| but returns the character index of the column
1295 position given with {expr} instead of the byte position.
1296
1297 Example:
1298 With the cursor on '세' in line 5 with text "여보세요": >
1299 charcol('.') returns 3
1300 col('.') returns 7
1301
1302< Can also be used as a |method|: >
1303 GetPos()->col()
1304<
1305 *charidx()*
1306charidx({string}, {idx} [, {countcc}])
1307 Return the character index of the byte at {idx} in {string}.
1308 The index of the first character is zero.
1309 If there are no multibyte characters the returned value is
1310 equal to {idx}.
1311 When {countcc} is omitted or |FALSE|, then composing characters
1312 are not counted separately, their byte length is
1313 added to the preceding base character.
1314 When {countcc} is |TRUE|, then composing characters are
1315 counted as separate characters.
1316 Returns -1 if the arguments are invalid or if {idx} is greater
1317 than the index of the last byte in {string}. An error is
1318 given if the first argument is not a string, the second
1319 argument is not a number or when the third argument is present
1320 and is not zero or one.
1321 See |byteidx()| and |byteidxcomp()| for getting the byte index
1322 from the character index.
1323 Examples: >
1324 echo charidx('áb́ć', 3) returns 1
1325 echo charidx('áb́ć', 6, 1) returns 4
1326 echo charidx('áb́ć', 16) returns -1
1327<
1328 Can also be used as a |method|: >
1329 GetName()->charidx(idx)
1330
1331chdir({dir}) *chdir()*
1332 Change the current working directory to {dir}. The scope of
1333 the directory change depends on the directory of the current
1334 window:
1335 - If the current window has a window-local directory
1336 (|:lcd|), then changes the window local directory.
1337 - Otherwise, if the current tabpage has a local
1338 directory (|:tcd|) then changes the tabpage local
1339 directory.
1340 - Otherwise, changes the global directory.
1341 {dir} must be a String.
1342 If successful, returns the previous working directory. Pass
1343 this to another chdir() to restore the directory.
1344 On failure, returns an empty string.
1345
1346 Example: >
1347 let save_dir = chdir(newdir)
1348 if save_dir != ""
1349 " ... do some work
1350 call chdir(save_dir)
1351 endif
1352
1353< Can also be used as a |method|: >
1354 GetDir()->chdir()
1355<
1356cindent({lnum}) *cindent()*
1357 Get the amount of indent for line {lnum} according the C
1358 indenting rules, as with 'cindent'.
1359 The indent is counted in spaces, the value of 'tabstop' is
1360 relevant. {lnum} is used just like in |getline()|.
1361 When {lnum} is invalid or Vim was not compiled the |+cindent|
1362 feature, -1 is returned.
1363 See |C-indenting|.
1364
1365 Can also be used as a |method|: >
1366 GetLnum()->cindent()
1367
1368clearmatches([{win}]) *clearmatches()*
1369 Clears all matches previously defined for the current window
1370 by |matchadd()| and the |:match| commands.
1371 If {win} is specified, use the window with this number or
1372 window ID instead of the current window.
1373
1374 Can also be used as a |method|: >
1375 GetWin()->clearmatches()
1376<
1377 *col()*
1378col({expr}) The result is a Number, which is the byte index of the column
1379 position given with {expr}. The accepted positions are:
1380 . the cursor position
1381 $ the end of the cursor line (the result is the
1382 number of bytes in the cursor line plus one)
1383 'x position of mark x (if the mark is not set, 0 is
1384 returned)
1385 v In Visual mode: the start of the Visual area (the
1386 cursor is the end). When not in Visual mode
1387 returns the cursor position. Differs from |'<| in
1388 that it's updated right away.
1389 Additionally {expr} can be [lnum, col]: a |List| with the line
1390 and column number. Most useful when the column is "$", to get
1391 the last column of a specific line. When "lnum" or "col" is
1392 out of range then col() returns zero.
1393 To get the line number use |line()|. To get both use
1394 |getpos()|.
1395 For the screen column position use |virtcol()|. For the
1396 character position use |charcol()|.
1397 Note that only marks in the current file can be used.
1398 Examples: >
1399 col(".") column of cursor
1400 col("$") length of cursor line plus one
1401 col("'t") column of mark t
Bram Moolenaarc51cf032022-02-26 12:25:45 +00001402 col("'" .. markname) column of mark markname
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001403< The first column is 1. 0 is returned for an error.
1404 For an uppercase mark the column may actually be in another
1405 buffer.
1406 For the cursor position, when 'virtualedit' is active, the
1407 column is one higher if the cursor is after the end of the
1408 line. This can be used to obtain the column in Insert mode: >
1409 :imap <F2> <C-O>:let save_ve = &ve<CR>
1410 \<C-O>:set ve=all<CR>
Bram Moolenaarc51cf032022-02-26 12:25:45 +00001411 \<C-O>:echo col(".") .. "\n" <Bar>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001412 \let &ve = save_ve<CR>
1413
1414< Can also be used as a |method|: >
1415 GetPos()->col()
1416<
1417
1418complete({startcol}, {matches}) *complete()* *E785*
1419 Set the matches for Insert mode completion.
1420 Can only be used in Insert mode. You need to use a mapping
1421 with CTRL-R = (see |i_CTRL-R|). It does not work after CTRL-O
1422 or with an expression mapping.
1423 {startcol} is the byte offset in the line where the completed
1424 text start. The text up to the cursor is the original text
1425 that will be replaced by the matches. Use col('.') for an
1426 empty string. "col('.') - 1" will replace one character by a
1427 match.
1428 {matches} must be a |List|. Each |List| item is one match.
1429 See |complete-items| for the kind of items that are possible.
1430 "longest" in 'completeopt' is ignored.
1431 Note that the after calling this function you need to avoid
1432 inserting anything that would cause completion to stop.
1433 The match can be selected with CTRL-N and CTRL-P as usual with
1434 Insert mode completion. The popup menu will appear if
1435 specified, see |ins-completion-menu|.
1436 Example: >
1437 inoremap <F5> <C-R>=ListMonths()<CR>
1438
1439 func! ListMonths()
1440 call complete(col('.'), ['January', 'February', 'March',
1441 \ 'April', 'May', 'June', 'July', 'August', 'September',
1442 \ 'October', 'November', 'December'])
1443 return ''
1444 endfunc
1445< This isn't very useful, but it shows how it works. Note that
1446 an empty string is returned to avoid a zero being inserted.
1447
1448 Can also be used as a |method|, the base is passed as the
1449 second argument: >
1450 GetMatches()->complete(col('.'))
1451
1452complete_add({expr}) *complete_add()*
1453 Add {expr} to the list of matches. Only to be used by the
1454 function specified with the 'completefunc' option.
1455 Returns 0 for failure (empty string or out of memory),
1456 1 when the match was added, 2 when the match was already in
1457 the list.
1458 See |complete-functions| for an explanation of {expr}. It is
1459 the same as one item in the list that 'omnifunc' would return.
1460
1461 Can also be used as a |method|: >
1462 GetMoreMatches()->complete_add()
1463
1464complete_check() *complete_check()*
1465 Check for a key typed while looking for completion matches.
1466 This is to be used when looking for matches takes some time.
1467 Returns |TRUE| when searching for matches is to be aborted,
1468 zero otherwise.
1469 Only to be used by the function specified with the
1470 'completefunc' option.
1471
1472
1473complete_info([{what}]) *complete_info()*
1474 Returns a |Dictionary| with information about Insert mode
1475 completion. See |ins-completion|.
1476 The items are:
1477 mode Current completion mode name string.
1478 See |complete_info_mode| for the values.
1479 pum_visible |TRUE| if popup menu is visible.
1480 See |pumvisible()|.
1481 items List of completion matches. Each item is a
1482 dictionary containing the entries "word",
1483 "abbr", "menu", "kind", "info" and "user_data".
1484 See |complete-items|.
1485 selected Selected item index. First index is zero.
1486 Index is -1 if no item is selected (showing
1487 typed text only, or the last completion after
1488 no item is selected when using the <Up> or
1489 <Down> keys)
1490 inserted Inserted string. [NOT IMPLEMENT YET]
1491
1492 *complete_info_mode*
1493 mode values are:
1494 "" Not in completion mode
1495 "keyword" Keyword completion |i_CTRL-X_CTRL-N|
1496 "ctrl_x" Just pressed CTRL-X |i_CTRL-X|
1497 "scroll" Scrolling with |i_CTRL-X_CTRL-E| or
1498 |i_CTRL-X_CTRL-Y|
1499 "whole_line" Whole lines |i_CTRL-X_CTRL-L|
1500 "files" File names |i_CTRL-X_CTRL-F|
1501 "tags" Tags |i_CTRL-X_CTRL-]|
1502 "path_defines" Definition completion |i_CTRL-X_CTRL-D|
1503 "path_patterns" Include completion |i_CTRL-X_CTRL-I|
1504 "dictionary" Dictionary |i_CTRL-X_CTRL-K|
1505 "thesaurus" Thesaurus |i_CTRL-X_CTRL-T|
1506 "cmdline" Vim Command line |i_CTRL-X_CTRL-V|
1507 "function" User defined completion |i_CTRL-X_CTRL-U|
1508 "omni" Omni completion |i_CTRL-X_CTRL-O|
1509 "spell" Spelling suggestions |i_CTRL-X_s|
1510 "eval" |complete()| completion
1511 "unknown" Other internal modes
1512
1513 If the optional {what} list argument is supplied, then only
1514 the items listed in {what} are returned. Unsupported items in
1515 {what} are silently ignored.
1516
1517 To get the position and size of the popup menu, see
1518 |pum_getpos()|. It's also available in |v:event| during the
1519 |CompleteChanged| event.
1520
1521 Examples: >
1522 " Get all items
1523 call complete_info()
1524 " Get only 'mode'
1525 call complete_info(['mode'])
1526 " Get only 'mode' and 'pum_visible'
1527 call complete_info(['mode', 'pum_visible'])
1528
1529< Can also be used as a |method|: >
1530 GetItems()->complete_info()
1531<
1532 *confirm()*
1533confirm({msg} [, {choices} [, {default} [, {type}]]])
1534 confirm() offers the user a dialog, from which a choice can be
1535 made. It returns the number of the choice. For the first
1536 choice this is 1.
1537 Note: confirm() is only supported when compiled with dialog
1538 support, see |+dialog_con| and |+dialog_gui|.
1539
1540 {msg} is displayed in a |dialog| with {choices} as the
1541 alternatives. When {choices} is missing or empty, "&OK" is
1542 used (and translated).
1543 {msg} is a String, use '\n' to include a newline. Only on
1544 some systems the string is wrapped when it doesn't fit.
1545
1546 {choices} is a String, with the individual choices separated
1547 by '\n', e.g. >
1548 confirm("Save changes?", "&Yes\n&No\n&Cancel")
1549< The letter after the '&' is the shortcut key for that choice.
1550 Thus you can type 'c' to select "Cancel". The shortcut does
1551 not need to be the first letter: >
1552 confirm("file has been modified", "&Save\nSave &All")
1553< For the console, the first letter of each choice is used as
1554 the default shortcut key. Case is ignored.
1555
1556 The optional {default} argument is the number of the choice
1557 that is made if the user hits <CR>. Use 1 to make the first
1558 choice the default one. Use 0 to not set a default. If
1559 {default} is omitted, 1 is used.
1560
1561 The optional {type} String argument gives the type of dialog.
1562 This is only used for the icon of the GTK, Mac, Motif and
1563 Win32 GUI. It can be one of these values: "Error",
1564 "Question", "Info", "Warning" or "Generic". Only the first
1565 character is relevant. When {type} is omitted, "Generic" is
1566 used.
1567
1568 If the user aborts the dialog by pressing <Esc>, CTRL-C,
1569 or another valid interrupt key, confirm() returns 0.
1570
1571 An example: >
Bram Moolenaar46eea442022-03-30 10:51:39 +01001572 let choice = confirm("What do you want?",
1573 \ "&Apples\n&Oranges\n&Bananas", 2)
1574 if choice == 0
1575 echo "make up your mind!"
1576 elseif choice == 3
1577 echo "tasteful"
1578 else
1579 echo "I prefer bananas myself."
1580 endif
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001581< In a GUI dialog, buttons are used. The layout of the buttons
1582 depends on the 'v' flag in 'guioptions'. If it is included,
1583 the buttons are always put vertically. Otherwise, confirm()
1584 tries to put the buttons in one horizontal line. If they
1585 don't fit, a vertical layout is used anyway. For some systems
1586 the horizontal layout is always used.
1587
1588 Can also be used as a |method|in: >
1589 BuildMessage()->confirm("&Yes\n&No")
1590<
1591 *copy()*
1592copy({expr}) Make a copy of {expr}. For Numbers and Strings this isn't
1593 different from using {expr} directly.
1594 When {expr} is a |List| a shallow copy is created. This means
1595 that the original |List| can be changed without changing the
1596 copy, and vice versa. But the items are identical, thus
1597 changing an item changes the contents of both |Lists|.
1598 A |Dictionary| is copied in a similar way as a |List|.
1599 Also see |deepcopy()|.
1600 Can also be used as a |method|: >
1601 mylist->copy()
1602
1603cos({expr}) *cos()*
1604 Return the cosine of {expr}, measured in radians, as a |Float|.
1605 {expr} must evaluate to a |Float| or a |Number|.
1606 Examples: >
1607 :echo cos(100)
1608< 0.862319 >
1609 :echo cos(-4.01)
1610< -0.646043
1611
1612 Can also be used as a |method|: >
1613 Compute()->cos()
1614<
1615 {only available when compiled with the |+float| feature}
1616
1617
1618cosh({expr}) *cosh()*
1619 Return the hyperbolic cosine of {expr} as a |Float| in the range
1620 [1, inf].
1621 {expr} must evaluate to a |Float| or a |Number|.
1622 Examples: >
1623 :echo cosh(0.5)
1624< 1.127626 >
1625 :echo cosh(-0.5)
1626< -1.127626
1627
1628 Can also be used as a |method|: >
1629 Compute()->cosh()
1630<
1631 {only available when compiled with the |+float| feature}
1632
1633
1634count({comp}, {expr} [, {ic} [, {start}]]) *count()*
1635 Return the number of times an item with value {expr} appears
1636 in |String|, |List| or |Dictionary| {comp}.
1637
1638 If {start} is given then start with the item with this index.
1639 {start} can only be used with a |List|.
1640
1641 When {ic} is given and it's |TRUE| then case is ignored.
1642
1643 When {comp} is a string then the number of not overlapping
1644 occurrences of {expr} is returned. Zero is returned when
1645 {expr} is an empty string.
1646
1647 Can also be used as a |method|: >
1648 mylist->count(val)
1649<
1650 *cscope_connection()*
1651cscope_connection([{num} , {dbpath} [, {prepend}]])
1652 Checks for the existence of a |cscope| connection. If no
1653 parameters are specified, then the function returns:
1654 0, if cscope was not available (not compiled in), or
1655 if there are no cscope connections;
1656 1, if there is at least one cscope connection.
1657
1658 If parameters are specified, then the value of {num}
1659 determines how existence of a cscope connection is checked:
1660
1661 {num} Description of existence check
1662 ----- ------------------------------
1663 0 Same as no parameters (e.g., "cscope_connection()").
1664 1 Ignore {prepend}, and use partial string matches for
1665 {dbpath}.
1666 2 Ignore {prepend}, and use exact string matches for
1667 {dbpath}.
1668 3 Use {prepend}, use partial string matches for both
1669 {dbpath} and {prepend}.
1670 4 Use {prepend}, use exact string matches for both
1671 {dbpath} and {prepend}.
1672
1673 Note: All string comparisons are case sensitive!
1674
1675 Examples. Suppose we had the following (from ":cs show"): >
1676
1677 # pid database name prepend path
1678 0 27664 cscope.out /usr/local
1679<
1680 Invocation Return Val ~
1681 ---------- ---------- >
1682 cscope_connection() 1
1683 cscope_connection(1, "out") 1
1684 cscope_connection(2, "out") 0
1685 cscope_connection(3, "out") 0
1686 cscope_connection(3, "out", "local") 1
1687 cscope_connection(4, "out") 0
1688 cscope_connection(4, "out", "local") 0
1689 cscope_connection(4, "cscope.out", "/usr/local") 1
1690<
1691cursor({lnum}, {col} [, {off}]) *cursor()*
1692cursor({list})
1693 Positions the cursor at the column (byte count) {col} in the
1694 line {lnum}. The first column is one.
1695
1696 When there is one argument {list} this is used as a |List|
1697 with two, three or four item:
1698 [{lnum}, {col}]
1699 [{lnum}, {col}, {off}]
1700 [{lnum}, {col}, {off}, {curswant}]
1701 This is like the return value of |getpos()| or |getcurpos()|,
1702 but without the first item.
1703
1704 To position the cursor using the character count, use
1705 |setcursorcharpos()|.
1706
1707 Does not change the jumplist.
1708 {lnum} is used like with |getline()|.
1709 If {lnum} is greater than the number of lines in the buffer,
1710 the cursor will be positioned at the last line in the buffer.
1711 If {lnum} is zero, the cursor will stay in the current line.
1712 If {col} is greater than the number of bytes in the line,
1713 the cursor will be positioned at the last character in the
1714 line.
1715 If {col} is zero, the cursor will stay in the current column.
1716 If {curswant} is given it is used to set the preferred column
1717 for vertical movement. Otherwise {col} is used.
1718
1719 When 'virtualedit' is used {off} specifies the offset in
1720 screen columns from the start of the character. E.g., a
1721 position within a <Tab> or after the last character.
1722 Returns 0 when the position could be set, -1 otherwise.
1723
1724 Can also be used as a |method|: >
1725 GetCursorPos()->cursor()
1726
1727debugbreak({pid}) *debugbreak()*
1728 Specifically used to interrupt a program being debugged. It
1729 will cause process {pid} to get a SIGTRAP. Behavior for other
1730 processes is undefined. See |terminal-debugger|.
1731 {only available on MS-Windows}
1732
1733 Can also be used as a |method|: >
1734 GetPid()->debugbreak()
1735
1736deepcopy({expr} [, {noref}]) *deepcopy()* *E698*
1737 Make a copy of {expr}. For Numbers and Strings this isn't
1738 different from using {expr} directly.
1739 When {expr} is a |List| a full copy is created. This means
1740 that the original |List| can be changed without changing the
1741 copy, and vice versa. When an item is a |List| or
1742 |Dictionary|, a copy for it is made, recursively. Thus
1743 changing an item in the copy does not change the contents of
1744 the original |List|.
1745 A |Dictionary| is copied in a similar way as a |List|.
1746
1747 When {noref} is omitted or zero a contained |List| or
1748 |Dictionary| is only copied once. All references point to
1749 this single copy. With {noref} set to 1 every occurrence of a
1750 |List| or |Dictionary| results in a new copy. This also means
1751 that a cyclic reference causes deepcopy() to fail.
1752 *E724*
1753 Nesting is possible up to 100 levels. When there is an item
1754 that refers back to a higher level making a deep copy with
1755 {noref} set to 1 will fail.
1756 Also see |copy()|.
1757
1758 Can also be used as a |method|: >
1759 GetObject()->deepcopy()
1760
1761delete({fname} [, {flags}]) *delete()*
1762 Without {flags} or with {flags} empty: Deletes the file by the
Bram Moolenaarcbaff5e2022-04-08 17:45:08 +01001763 name {fname}.
1764
1765 This also works when {fname} is a symbolic link. The symbolic
1766 link itself is deleted, not what it points to.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001767
1768 When {flags} is "d": Deletes the directory by the name
1769 {fname}. This fails when directory {fname} is not empty.
1770
1771 When {flags} is "rf": Deletes the directory by the name
1772 {fname} and everything in it, recursively. BE CAREFUL!
1773 Note: on MS-Windows it is not possible to delete a directory
1774 that is being used.
1775
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001776 The result is a Number, which is 0/false if the delete
1777 operation was successful and -1/true when the deletion failed
1778 or partly failed.
1779
1780 Use |remove()| to delete an item from a |List|.
1781 To delete a line from the buffer use |:delete| or
1782 |deletebufline()|.
1783
1784 Can also be used as a |method|: >
1785 GetName()->delete()
1786
1787deletebufline({buf}, {first} [, {last}]) *deletebufline()*
1788 Delete lines {first} to {last} (inclusive) from buffer {buf}.
1789 If {last} is omitted then delete line {first} only.
1790 On success 0 is returned, on failure 1 is returned.
1791
1792 This function works only for loaded buffers. First call
1793 |bufload()| if needed.
1794
1795 For the use of {buf}, see |bufname()| above.
1796
1797 {first} and {last} are used like with |getline()|. Note that
1798 when using |line()| this refers to the current buffer. Use "$"
1799 to refer to the last line in buffer {buf}.
1800
1801 Can also be used as a |method|: >
1802 GetBuffer()->deletebufline(1)
1803<
1804 *did_filetype()*
1805did_filetype() Returns |TRUE| when autocommands are being executed and the
1806 FileType event has been triggered at least once. Can be used
1807 to avoid triggering the FileType event again in the scripts
1808 that detect the file type. |FileType|
1809 Returns |FALSE| when `:setf FALLBACK` was used.
1810 When editing another file, the counter is reset, thus this
1811 really checks if the FileType event has been triggered for the
1812 current buffer. This allows an autocommand that starts
1813 editing another buffer to set 'filetype' and load a syntax
1814 file.
1815
1816diff_filler({lnum}) *diff_filler()*
1817 Returns the number of filler lines above line {lnum}.
1818 These are the lines that were inserted at this point in
1819 another diff'ed window. These filler lines are shown in the
1820 display but don't exist in the buffer.
1821 {lnum} is used like with |getline()|. Thus "." is the current
1822 line, "'m" mark m, etc.
1823 Returns 0 if the current window is not in diff mode.
1824
1825 Can also be used as a |method|: >
1826 GetLnum()->diff_filler()
1827
1828diff_hlID({lnum}, {col}) *diff_hlID()*
1829 Returns the highlight ID for diff mode at line {lnum} column
1830 {col} (byte index). When the current line does not have a
1831 diff change zero is returned.
1832 {lnum} is used like with |getline()|. Thus "." is the current
1833 line, "'m" mark m, etc.
1834 {col} is 1 for the leftmost column, {lnum} is 1 for the first
1835 line.
1836 The highlight ID can be used with |synIDattr()| to obtain
1837 syntax information about the highlighting.
1838
1839 Can also be used as a |method|: >
1840 GetLnum()->diff_hlID(col)
1841<
1842
1843digraph_get({chars}) *digraph_get()* *E1214*
1844 Return the digraph of {chars}. This should be a string with
1845 exactly two characters. If {chars} are not just two
1846 characters, or the digraph of {chars} does not exist, an error
1847 is given and an empty string is returned.
1848
1849 The character will be converted from Unicode to 'encoding'
1850 when needed. This does require the conversion to be
1851 available, it might fail.
1852
1853 Also see |digraph_getlist()|.
1854
1855 Examples: >
1856 " Get a built-in digraph
1857 :echo digraph_get('00') " Returns '∞'
1858
1859 " Get a user-defined digraph
1860 :call digraph_set('aa', 'あ')
1861 :echo digraph_get('aa') " Returns 'あ'
1862<
1863 Can also be used as a |method|: >
1864 GetChars()->digraph_get()
1865<
1866 This function works only when compiled with the |+digraphs|
1867 feature. If this feature is disabled, this function will
1868 display an error message.
1869
1870
1871digraph_getlist([{listall}]) *digraph_getlist()*
1872 Return a list of digraphs. If the {listall} argument is given
1873 and it is TRUE, return all digraphs, including the default
1874 digraphs. Otherwise, return only user-defined digraphs.
1875
1876 The characters will be converted from Unicode to 'encoding'
1877 when needed. This does require the conservation to be
1878 available, it might fail.
1879
1880 Also see |digraph_get()|.
1881
1882 Examples: >
1883 " Get user-defined digraphs
1884 :echo digraph_getlist()
1885
1886 " Get all the digraphs, including default digraphs
1887 :echo digraph_getlist(1)
1888<
1889 Can also be used as a |method|: >
1890 GetNumber()->digraph_getlist()
1891<
1892 This function works only when compiled with the |+digraphs|
1893 feature. If this feature is disabled, this function will
1894 display an error message.
1895
1896
Bram Moolenaara2baa732022-02-04 16:09:54 +00001897digraph_set({chars}, {digraph}) *digraph_set()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001898 Add digraph {chars} to the list. {chars} must be a string
1899 with two characters. {digraph} is a string with one UTF-8
Bram Moolenaara2baa732022-02-04 16:09:54 +00001900 encoded character. *E1215*
1901 Be careful, composing characters are NOT ignored. This
1902 function is similar to |:digraphs| command, but useful to add
1903 digraphs start with a white space.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001904
1905 The function result is v:true if |digraph| is registered. If
1906 this fails an error message is given and v:false is returned.
1907
1908 If you want to define multiple digraphs at once, you can use
1909 |digraph_setlist()|.
1910
1911 Example: >
1912 call digraph_set(' ', 'あ')
1913<
1914 Can be used as a |method|: >
1915 GetString()->digraph_set('あ')
1916<
1917 This function works only when compiled with the |+digraphs|
1918 feature. If this feature is disabled, this function will
1919 display an error message.
1920
1921
1922digraph_setlist({digraphlist}) *digraph_setlist()*
1923 Similar to |digraph_set()| but this function can add multiple
1924 digraphs at once. {digraphlist} is a list composed of lists,
1925 where each list contains two strings with {chars} and
Bram Moolenaara2baa732022-02-04 16:09:54 +00001926 {digraph} as in |digraph_set()|. *E1216*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001927 Example: >
1928 call digraph_setlist([['aa', 'あ'], ['ii', 'い']])
1929<
1930 It is similar to the following: >
1931 for [chars, digraph] in [['aa', 'あ'], ['ii', 'い']]
1932 call digraph_set(chars, digraph)
1933 endfor
1934< Except that the function returns after the first error,
1935 following digraphs will not be added.
1936
1937 Can be used as a |method|: >
1938 GetList()->digraph_setlist()
1939<
1940 This function works only when compiled with the |+digraphs|
1941 feature. If this feature is disabled, this function will
1942 display an error message.
1943
1944
1945echoraw({string}) *echoraw()*
1946 Output {string} as-is, including unprintable characters.
1947 This can be used to output a terminal code. For example, to
1948 disable modifyOtherKeys: >
1949 call echoraw(&t_TE)
1950< and to enable it again: >
1951 call echoraw(&t_TI)
1952< Use with care, you can mess up the terminal this way.
1953
1954
1955empty({expr}) *empty()*
1956 Return the Number 1 if {expr} is empty, zero otherwise.
1957 - A |List| or |Dictionary| is empty when it does not have any
1958 items.
1959 - A |String| is empty when its length is zero.
1960 - A |Number| and |Float| are empty when their value is zero.
1961 - |v:false|, |v:none| and |v:null| are empty, |v:true| is not.
1962 - A |Job| is empty when it failed to start.
1963 - A |Channel| is empty when it is closed.
1964 - A |Blob| is empty when its length is zero.
1965
1966 For a long |List| this is much faster than comparing the
1967 length with zero.
1968
1969 Can also be used as a |method|: >
1970 mylist->empty()
1971
1972environ() *environ()*
1973 Return all of environment variables as dictionary. You can
1974 check if an environment variable exists like this: >
1975 :echo has_key(environ(), 'HOME')
1976< Note that the variable name may be CamelCase; to ignore case
1977 use this: >
1978 :echo index(keys(environ()), 'HOME', 0, 1) != -1
1979
1980escape({string}, {chars}) *escape()*
1981 Escape the characters in {chars} that occur in {string} with a
1982 backslash. Example: >
1983 :echo escape('c:\program files\vim', ' \')
1984< results in: >
1985 c:\\program\ files\\vim
1986< Also see |shellescape()| and |fnameescape()|.
1987
1988 Can also be used as a |method|: >
1989 GetText()->escape(' \')
1990<
1991 *eval()*
1992eval({string}) Evaluate {string} and return the result. Especially useful to
1993 turn the result of |string()| back into the original value.
1994 This works for Numbers, Floats, Strings, Blobs and composites
1995 of them. Also works for |Funcref|s that refer to existing
1996 functions.
1997
1998 Can also be used as a |method|: >
1999 argv->join()->eval()
2000
2001eventhandler() *eventhandler()*
2002 Returns 1 when inside an event handler. That is that Vim got
2003 interrupted while waiting for the user to type a character,
2004 e.g., when dropping a file on Vim. This means interactive
2005 commands cannot be used. Otherwise zero is returned.
2006
2007executable({expr}) *executable()*
2008 This function checks if an executable with the name {expr}
2009 exists. {expr} must be the name of the program without any
2010 arguments.
2011 executable() uses the value of $PATH and/or the normal
2012 searchpath for programs. *PATHEXT*
2013 On MS-Windows the ".exe", ".bat", etc. can optionally be
2014 included. Then the extensions in $PATHEXT are tried. Thus if
2015 "foo.exe" does not exist, "foo.exe.bat" can be found. If
2016 $PATHEXT is not set then ".com;.exe;.bat;.cmd" is used. A dot
2017 by itself can be used in $PATHEXT to try using the name
2018 without an extension. When 'shell' looks like a Unix shell,
2019 then the name is also tried without adding an extension.
2020 On MS-Windows it only checks if the file exists and is not a
2021 directory, not if it's really executable.
2022 On MS-Windows an executable in the same directory as Vim is
Yasuhiro Matsumoto05cf63e2022-05-03 11:02:28 +01002023 normally found. Since this directory is added to $PATH it
2024 should also work to execute it |win32-PATH|. This can be
2025 disabled by setting the $NoDefaultCurrentDirectoryInExePath
2026 environment variable. *NoDefaultCurrentDirectoryInExePath*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002027 The result is a Number:
2028 1 exists
2029 0 does not exist
2030 -1 not implemented on this system
2031 |exepath()| can be used to get the full path of an executable.
2032
2033 Can also be used as a |method|: >
2034 GetCommand()->executable()
2035
2036execute({command} [, {silent}]) *execute()*
2037 Execute an Ex command or commands and return the output as a
2038 string.
2039 {command} can be a string or a List. In case of a List the
2040 lines are executed one by one.
2041 This is equivalent to: >
2042 redir => var
2043 {command}
2044 redir END
2045<
2046 The optional {silent} argument can have these values:
2047 "" no `:silent` used
2048 "silent" `:silent` used
2049 "silent!" `:silent!` used
2050 The default is "silent". Note that with "silent!", unlike
2051 `:redir`, error messages are dropped. When using an external
2052 command the screen may be messed up, use `system()` instead.
2053 *E930*
2054 It is not possible to use `:redir` anywhere in {command}.
2055
2056 To get a list of lines use |split()| on the result: >
Bram Moolenaar75ab5902022-04-18 15:36:40 +01002057 execute('args')->split("\n")
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002058
2059< To execute a command in another window than the current one
2060 use `win_execute()`.
2061
2062 When used recursively the output of the recursive call is not
2063 included in the output of the higher level call.
2064
2065 Can also be used as a |method|: >
2066 GetCommand()->execute()
2067
2068exepath({expr}) *exepath()*
2069 If {expr} is an executable and is either an absolute path, a
2070 relative path or found in $PATH, return the full path.
2071 Note that the current directory is used when {expr} starts
2072 with "./", which may be a problem for Vim: >
2073 echo exepath(v:progpath)
2074< If {expr} cannot be found in $PATH or is not executable then
2075 an empty string is returned.
2076
2077 Can also be used as a |method|: >
2078 GetCommand()->exepath()
2079<
2080 *exists()*
2081exists({expr}) The result is a Number, which is |TRUE| if {expr} is defined,
2082 zero otherwise.
2083
2084 Note: In a compiled |:def| function the evaluation is done at
2085 runtime. Use `exists_compiled()` to evaluate the expression
2086 at compile time.
2087
2088 For checking for a supported feature use |has()|.
2089 For checking if a file exists use |filereadable()|.
2090
2091 The {expr} argument is a string, which contains one of these:
Bram Moolenaarf10911e2022-01-29 22:20:48 +00002092 varname internal variable (see
2093 dict.key |internal-variables|). Also works
2094 list[i] for |curly-braces-names|, |Dictionary|
2095 import.Func entries, |List| items, imported
Bram Moolenaar944697a2022-02-20 19:48:20 +00002096 items, etc.
Bram Moolenaarf10911e2022-01-29 22:20:48 +00002097 Does not work for local variables in a
2098 compiled `:def` function.
Bram Moolenaar944697a2022-02-20 19:48:20 +00002099 Also works for a function in |Vim9|
2100 script, since it can be used as a
2101 function reference.
Bram Moolenaarf10911e2022-01-29 22:20:48 +00002102 Beware that evaluating an index may
2103 cause an error message for an invalid
2104 expression. E.g.: >
2105 :let l = [1, 2, 3]
2106 :echo exists("l[5]")
2107< 0 >
2108 :echo exists("l[xx]")
2109< E121: Undefined variable: xx
2110 0
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002111 &option-name Vim option (only checks if it exists,
2112 not if it really works)
2113 +option-name Vim option that works.
2114 $ENVNAME environment variable (could also be
2115 done by comparing with an empty
2116 string)
2117 *funcname built-in function (see |functions|)
2118 or user defined function (see
2119 |user-functions|) that is implemented.
2120 Also works for a variable that is a
2121 Funcref.
2122 ?funcname built-in function that could be
2123 implemented; to be used to check if
2124 "funcname" is valid
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002125 :cmdname Ex command: built-in command, user
2126 command or command modifier |:command|.
2127 Returns:
2128 1 for match with start of a command
2129 2 full match with a command
2130 3 matches several user commands
2131 To check for a supported command
2132 always check the return value to be 2.
2133 :2match The |:2match| command.
2134 :3match The |:3match| command.
2135 #event autocommand defined for this event
2136 #event#pattern autocommand defined for this event and
2137 pattern (the pattern is taken
2138 literally and compared to the
2139 autocommand patterns character by
2140 character)
2141 #group autocommand group exists
2142 #group#event autocommand defined for this group and
2143 event.
2144 #group#event#pattern
2145 autocommand defined for this group,
2146 event and pattern.
2147 ##event autocommand for this event is
2148 supported.
2149
2150 Examples: >
2151 exists("&shortname")
2152 exists("$HOSTNAME")
2153 exists("*strftime")
Bram Moolenaar944697a2022-02-20 19:48:20 +00002154 exists("*s:MyFunc") " only for legacy script
2155 exists("*MyFunc")
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002156 exists("bufcount")
2157 exists(":Make")
2158 exists("#CursorHold")
2159 exists("#BufReadPre#*.gz")
2160 exists("#filetypeindent")
2161 exists("#filetypeindent#FileType")
2162 exists("#filetypeindent#FileType#*")
2163 exists("##ColorScheme")
2164< There must be no space between the symbol (&/$/*/#) and the
2165 name.
2166 There must be no extra characters after the name, although in
2167 a few cases this is ignored. That may become more strict in
2168 the future, thus don't count on it!
2169 Working example: >
2170 exists(":make")
2171< NOT working example: >
2172 exists(":make install")
2173
2174< Note that the argument must be a string, not the name of the
2175 variable itself. For example: >
2176 exists(bufcount)
2177< This doesn't check for existence of the "bufcount" variable,
2178 but gets the value of "bufcount", and checks if that exists.
2179
2180 Can also be used as a |method|: >
2181 Varname()->exists()
2182<
2183
2184exists_compiled({expr}) *exists_compiled()*
2185 Like `exists()` but evaluated at compile time. This is useful
2186 to skip a block where a function is used that would otherwise
2187 give an error: >
2188 if exists_compiled('*ThatFunction')
2189 ThatFunction('works')
2190 endif
2191< If `exists()` were used then a compilation error would be
2192 given if ThatFunction() is not defined.
2193
2194 {expr} must be a literal string. *E1232*
2195 Can only be used in a |:def| function. *E1233*
2196 This does not work to check for arguments or local variables.
2197
2198
2199exp({expr}) *exp()*
2200 Return the exponential of {expr} as a |Float| in the range
2201 [0, inf].
2202 {expr} must evaluate to a |Float| or a |Number|.
2203 Examples: >
2204 :echo exp(2)
2205< 7.389056 >
2206 :echo exp(-1)
2207< 0.367879
2208
2209 Can also be used as a |method|: >
2210 Compute()->exp()
2211<
2212 {only available when compiled with the |+float| feature}
2213
2214
2215expand({string} [, {nosuf} [, {list}]]) *expand()*
2216 Expand wildcards and the following special keywords in
2217 {string}. 'wildignorecase' applies.
2218
2219 If {list} is given and it is |TRUE|, a List will be returned.
2220 Otherwise the result is a String and when there are several
2221 matches, they are separated by <NL> characters. [Note: in
2222 version 5.0 a space was used, which caused problems when a
2223 file name contains a space]
2224
2225 If the expansion fails, the result is an empty string. A name
2226 for a non-existing file is not included, unless {string} does
2227 not start with '%', '#' or '<', see below.
2228
2229 When {string} starts with '%', '#' or '<', the expansion is
2230 done like for the |cmdline-special| variables with their
2231 associated modifiers. Here is a short overview:
2232
2233 % current file name
2234 # alternate file name
2235 #n alternate file name n
2236 <cfile> file name under the cursor
2237 <afile> autocmd file name
2238 <abuf> autocmd buffer number (as a String!)
2239 <amatch> autocmd matched name
2240 <cexpr> C expression under the cursor
2241 <sfile> sourced script file or function name
2242 <slnum> sourced script line number or function
2243 line number
2244 <sflnum> script file line number, also when in
2245 a function
2246 <SID> "<SNR>123_" where "123" is the
2247 current script ID |<SID>|
Bram Moolenaar75ab5902022-04-18 15:36:40 +01002248 <script> sourced script file, or script file
2249 where the current function was defined
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002250 <stack> call stack
2251 <cword> word under the cursor
2252 <cWORD> WORD under the cursor
2253 <client> the {clientid} of the last received
2254 message |server2client()|
2255 Modifiers:
2256 :p expand to full path
2257 :h head (last path component removed)
2258 :t tail (last path component only)
2259 :r root (one extension removed)
2260 :e extension only
2261
2262 Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00002263 :let &tags = expand("%:p:h") .. "/tags"
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002264< Note that when expanding a string that starts with '%', '#' or
2265 '<', any following text is ignored. This does NOT work: >
2266 :let doesntwork = expand("%:h.bak")
2267< Use this: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00002268 :let doeswork = expand("%:h") .. ".bak"
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002269< Also note that expanding "<cfile>" and others only returns the
2270 referenced file name without further expansion. If "<cfile>"
2271 is "~/.cshrc", you need to do another expand() to have the
2272 "~/" expanded into the path of the home directory: >
2273 :echo expand(expand("<cfile>"))
2274<
2275 There cannot be white space between the variables and the
2276 following modifier. The |fnamemodify()| function can be used
2277 to modify normal file names.
2278
2279 When using '%' or '#', and the current or alternate file name
2280 is not defined, an empty string is used. Using "%:p" in a
2281 buffer with no name, results in the current directory, with a
2282 '/' added.
Bram Moolenaar57544522022-04-12 12:54:11 +01002283 When 'verbose' is set then expanding '%', '#' and <> items
2284 will result in an error message if the argument cannot be
2285 expanded.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002286
2287 When {string} does not start with '%', '#' or '<', it is
2288 expanded like a file name is expanded on the command line.
2289 'suffixes' and 'wildignore' are used, unless the optional
2290 {nosuf} argument is given and it is |TRUE|.
2291 Names for non-existing files are included. The "**" item can
2292 be used to search in a directory tree. For example, to find
2293 all "README" files in the current directory and below: >
2294 :echo expand("**/README")
2295<
2296 expand() can also be used to expand variables and environment
2297 variables that are only known in a shell. But this can be
2298 slow, because a shell may be used to do the expansion. See
2299 |expr-env-expand|.
2300 The expanded variable is still handled like a list of file
2301 names. When an environment variable cannot be expanded, it is
2302 left unchanged. Thus ":echo expand('$FOOBAR')" results in
2303 "$FOOBAR".
2304
2305 See |glob()| for finding existing files. See |system()| for
2306 getting the raw output of an external command.
2307
2308 Can also be used as a |method|: >
2309 Getpattern()->expand()
2310
Yegappan Lakshmanan2b74b682022-04-03 21:30:32 +01002311expandcmd({string} [, {options}]) *expandcmd()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002312 Expand special items in String {string} like what is done for
2313 an Ex command such as `:edit`. This expands special keywords,
2314 like with |expand()|, and environment variables, anywhere in
2315 {string}. "~user" and "~/path" are only expanded at the
2316 start.
Yegappan Lakshmanan2b74b682022-04-03 21:30:32 +01002317
2318 The following items are supported in the {options} Dict
2319 argument:
2320 errmsg If set to TRUE, error messages are displayed
2321 if an error is encountered during expansion.
2322 By default, error messages are not displayed.
2323
Yegappan Lakshmanan5018a832022-04-02 21:12:21 +01002324 Returns the expanded string. If an error is encountered
2325 during expansion, the unmodified {string} is returned.
Yegappan Lakshmanan2b74b682022-04-03 21:30:32 +01002326
Yegappan Lakshmanan5018a832022-04-02 21:12:21 +01002327 Example: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002328 :echo expandcmd('make %<.o')
Yegappan Lakshmanan2b74b682022-04-03 21:30:32 +01002329 make /path/runtime/doc/builtin.o
2330 :echo expandcmd('make %<.o', {'errmsg': v:true})
2331<
Yegappan Lakshmanan5018a832022-04-02 21:12:21 +01002332 Can also be used as a |method|: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002333 GetCommand()->expandcmd()
2334<
2335extend({expr1}, {expr2} [, {expr3}]) *extend()*
2336 {expr1} and {expr2} must be both |Lists| or both
2337 |Dictionaries|.
2338
2339 If they are |Lists|: Append {expr2} to {expr1}.
2340 If {expr3} is given insert the items of {expr2} before the
2341 item with index {expr3} in {expr1}. When {expr3} is zero
2342 insert before the first item. When {expr3} is equal to
2343 len({expr1}) then {expr2} is appended.
2344 Examples: >
2345 :echo sort(extend(mylist, [7, 5]))
2346 :call extend(mylist, [2, 3], 1)
2347< When {expr1} is the same List as {expr2} then the number of
2348 items copied is equal to the original length of the List.
2349 E.g., when {expr3} is 1 you get N new copies of the first item
2350 (where N is the original length of the List).
2351 Use |add()| to concatenate one item to a list. To concatenate
2352 two lists into a new list use the + operator: >
2353 :let newlist = [1, 2, 3] + [4, 5]
2354<
2355 If they are |Dictionaries|:
2356 Add all entries from {expr2} to {expr1}.
2357 If a key exists in both {expr1} and {expr2} then {expr3} is
2358 used to decide what to do:
2359 {expr3} = "keep": keep the value of {expr1}
2360 {expr3} = "force": use the value of {expr2}
2361 {expr3} = "error": give an error message *E737*
2362 When {expr3} is omitted then "force" is assumed.
2363
2364 {expr1} is changed when {expr2} is not empty. If necessary
2365 make a copy of {expr1} first.
2366 {expr2} remains unchanged.
2367 When {expr1} is locked and {expr2} is not empty the operation
2368 fails.
2369 Returns {expr1}.
2370
2371 Can also be used as a |method|: >
2372 mylist->extend(otherlist)
2373
2374
2375extendnew({expr1}, {expr2} [, {expr3}]) *extendnew()*
2376 Like |extend()| but instead of adding items to {expr1} a new
2377 List or Dictionary is created and returned. {expr1} remains
2378 unchanged. Items can still be changed by {expr2}, if you
2379 don't want that use |deepcopy()| first.
2380
2381
2382feedkeys({string} [, {mode}]) *feedkeys()*
2383 Characters in {string} are queued for processing as if they
2384 come from a mapping or were typed by the user.
2385
2386 By default the string is added to the end of the typeahead
2387 buffer, thus if a mapping is still being executed the
2388 characters come after them. Use the 'i' flag to insert before
2389 other characters, they will be executed next, before any
2390 characters from a mapping.
2391
2392 The function does not wait for processing of keys contained in
2393 {string}.
2394
2395 To include special keys into {string}, use double-quotes
2396 and "\..." notation |expr-quote|. For example,
2397 feedkeys("\<CR>") simulates pressing of the <Enter> key. But
2398 feedkeys('\<CR>') pushes 5 characters.
2399 A special code that might be useful is <Ignore>, it exits the
2400 wait for a character without doing anything. *<Ignore>*
2401
2402 {mode} is a String, which can contain these character flags:
2403 'm' Remap keys. This is default. If {mode} is absent,
2404 keys are remapped.
2405 'n' Do not remap keys.
2406 't' Handle keys as if typed; otherwise they are handled as
2407 if coming from a mapping. This matters for undo,
2408 opening folds, etc.
2409 'L' Lowlevel input. Only works for Unix or when using the
2410 GUI. Keys are used as if they were coming from the
2411 terminal. Other flags are not used. *E980*
2412 When a CTRL-C interrupts and 't' is included it sets
2413 the internal "got_int" flag.
2414 'i' Insert the string instead of appending (see above).
2415 'x' Execute commands until typeahead is empty. This is
2416 similar to using ":normal!". You can call feedkeys()
2417 several times without 'x' and then one time with 'x'
2418 (possibly with an empty {string}) to execute all the
2419 typeahead. Note that when Vim ends in Insert mode it
2420 will behave as if <Esc> is typed, to avoid getting
2421 stuck, waiting for a character to be typed before the
2422 script continues.
2423 Note that if you manage to call feedkeys() while
2424 executing commands, thus calling it recursively, then
2425 all typeahead will be consumed by the last call.
Bram Moolenaara9725222022-01-16 13:30:33 +00002426 'c' Remove any script context when executing, so that
2427 legacy script syntax applies, "s:var" does not work,
Bram Moolenaarce001a32022-04-27 15:25:03 +01002428 etc. Note that if the keys being using set a script
2429 context this still applies.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002430 '!' When used with 'x' will not end Insert mode. Can be
2431 used in a test when a timer is set to exit Insert mode
2432 a little later. Useful for testing CursorHoldI.
2433
2434 Return value is always 0.
2435
2436 Can also be used as a |method|: >
2437 GetInput()->feedkeys()
2438
2439filereadable({file}) *filereadable()*
2440 The result is a Number, which is |TRUE| when a file with the
2441 name {file} exists, and can be read. If {file} doesn't exist,
2442 or is a directory, the result is |FALSE|. {file} is any
2443 expression, which is used as a String.
2444 If you don't care about the file being readable you can use
2445 |glob()|.
2446 {file} is used as-is, you may want to expand wildcards first: >
2447 echo filereadable('~/.vimrc')
2448 0
2449 echo filereadable(expand('~/.vimrc'))
2450 1
2451
2452< Can also be used as a |method|: >
2453 GetName()->filereadable()
2454< *file_readable()*
2455 Obsolete name: file_readable().
2456
2457
2458filewritable({file}) *filewritable()*
2459 The result is a Number, which is 1 when a file with the
2460 name {file} exists, and can be written. If {file} doesn't
2461 exist, or is not writable, the result is 0. If {file} is a
2462 directory, and we can write to it, the result is 2.
2463
2464 Can also be used as a |method|: >
2465 GetName()->filewritable()
2466
2467
2468filter({expr1}, {expr2}) *filter()*
2469 {expr1} must be a |List|, |String|, |Blob| or |Dictionary|.
2470 For each item in {expr1} evaluate {expr2} and when the result
2471 is zero or false remove the item from the |List| or
2472 |Dictionary|. Similarly for each byte in a |Blob| and each
Bram Moolenaar2f0936c2022-01-08 21:51:59 +00002473 character in a |String|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002474
2475 {expr2} must be a |string| or |Funcref|.
2476
2477 If {expr2} is a |string|, inside {expr2} |v:val| has the value
2478 of the current item. For a |Dictionary| |v:key| has the key
2479 of the current item and for a |List| |v:key| has the index of
2480 the current item. For a |Blob| |v:key| has the index of the
2481 current byte. For a |String| |v:key| has the index of the
2482 current character.
2483 Examples: >
2484 call filter(mylist, 'v:val !~ "OLD"')
2485< Removes the items where "OLD" appears. >
2486 call filter(mydict, 'v:key >= 8')
2487< Removes the items with a key below 8. >
2488 call filter(var, 0)
2489< Removes all the items, thus clears the |List| or |Dictionary|.
2490
2491 Note that {expr2} is the result of expression and is then
2492 used as an expression again. Often it is good to use a
2493 |literal-string| to avoid having to double backslashes.
2494
2495 If {expr2} is a |Funcref| it must take two arguments:
2496 1. the key or the index of the current item.
2497 2. the value of the current item.
2498 The function must return |TRUE| if the item should be kept.
2499 Example that keeps the odd items of a list: >
2500 func Odd(idx, val)
2501 return a:idx % 2 == 1
2502 endfunc
2503 call filter(mylist, function('Odd'))
Bram Moolenaar2f0936c2022-01-08 21:51:59 +00002504< It is shorter when using a |lambda|. In |Vim9| syntax: >
2505 call filter(myList, (idx, val) => idx * val <= 42)
2506< In legacy script syntax: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002507 call filter(myList, {idx, val -> idx * val <= 42})
2508< If you do not use "val" you can leave it out: >
2509 call filter(myList, {idx -> idx % 2 == 1})
2510<
2511 In |Vim9| script the result must be true, false, zero or one.
2512 Other values will result in a type error.
2513
2514 For a |List| and a |Dictionary| the operation is done
2515 in-place. If you want it to remain unmodified make a copy
2516 first: >
2517 :let l = filter(copy(mylist), 'v:val =~ "KEEP"')
2518
2519< Returns {expr1}, the |List| or |Dictionary| that was filtered,
naohiro ono56200ee2022-01-01 14:59:44 +00002520 or a new |Blob| or |String|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002521 When an error is encountered while evaluating {expr2} no
2522 further items in {expr1} are processed.
2523 When {expr2} is a Funcref errors inside a function are ignored,
2524 unless it was defined with the "abort" flag.
2525
2526 Can also be used as a |method|: >
2527 mylist->filter(expr2)
2528
2529finddir({name} [, {path} [, {count}]]) *finddir()*
2530 Find directory {name} in {path}. Supports both downwards and
2531 upwards recursive directory searches. See |file-searching|
2532 for the syntax of {path}.
2533
2534 Returns the path of the first found match. When the found
2535 directory is below the current directory a relative path is
2536 returned. Otherwise a full path is returned.
2537 If {path} is omitted or empty then 'path' is used.
2538
2539 If the optional {count} is given, find {count}'s occurrence of
2540 {name} in {path} instead of the first one.
2541 When {count} is negative return all the matches in a |List|.
2542
2543 This is quite similar to the ex-command `:find`.
2544 {only available when compiled with the |+file_in_path|
2545 feature}
2546
2547 Can also be used as a |method|: >
2548 GetName()->finddir()
2549
2550findfile({name} [, {path} [, {count}]]) *findfile()*
2551 Just like |finddir()|, but find a file instead of a directory.
2552 Uses 'suffixesadd'.
2553 Example: >
2554 :echo findfile("tags.vim", ".;")
2555< Searches from the directory of the current file upwards until
2556 it finds the file "tags.vim".
2557
2558 Can also be used as a |method|: >
2559 GetName()->findfile()
2560
2561flatten({list} [, {maxdepth}]) *flatten()*
2562 Flatten {list} up to {maxdepth} levels. Without {maxdepth}
2563 the result is a |List| without nesting, as if {maxdepth} is
2564 a very large number.
2565 The {list} is changed in place, use |flattennew()| if you do
2566 not want that.
2567 In Vim9 script flatten() cannot be used, you must always use
Bram Moolenaara2baa732022-02-04 16:09:54 +00002568 |flattennew()|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002569 *E900*
2570 {maxdepth} means how deep in nested lists changes are made.
2571 {list} is not modified when {maxdepth} is 0.
2572 {maxdepth} must be positive number.
2573
2574 If there is an error the number zero is returned.
2575
2576 Example: >
2577 :echo flatten([1, [2, [3, 4]], 5])
2578< [1, 2, 3, 4, 5] >
2579 :echo flatten([1, [2, [3, 4]], 5], 1)
2580< [1, 2, [3, 4], 5]
2581
2582 Can also be used as a |method|: >
2583 mylist->flatten()
2584<
2585flattennew({list} [, {maxdepth}]) *flattennew()*
2586 Like |flatten()| but first make a copy of {list}.
2587
2588
2589float2nr({expr}) *float2nr()*
2590 Convert {expr} to a Number by omitting the part after the
2591 decimal point.
2592 {expr} must evaluate to a |Float| or a Number.
2593 When the value of {expr} is out of range for a |Number| the
2594 result is truncated to 0x7fffffff or -0x7fffffff (or when
2595 64-bit Number support is enabled, 0x7fffffffffffffff or
2596 -0x7fffffffffffffff). NaN results in -0x80000000 (or when
2597 64-bit Number support is enabled, -0x8000000000000000).
2598 Examples: >
2599 echo float2nr(3.95)
2600< 3 >
2601 echo float2nr(-23.45)
2602< -23 >
2603 echo float2nr(1.0e100)
2604< 2147483647 (or 9223372036854775807) >
2605 echo float2nr(-1.0e150)
2606< -2147483647 (or -9223372036854775807) >
2607 echo float2nr(1.0e-100)
2608< 0
2609
2610 Can also be used as a |method|: >
2611 Compute()->float2nr()
2612<
2613 {only available when compiled with the |+float| feature}
2614
2615
2616floor({expr}) *floor()*
2617 Return the largest integral value less than or equal to
2618 {expr} as a |Float| (round down).
2619 {expr} must evaluate to a |Float| or a |Number|.
2620 Examples: >
2621 echo floor(1.856)
2622< 1.0 >
2623 echo floor(-5.456)
2624< -6.0 >
2625 echo floor(4.0)
2626< 4.0
2627
2628 Can also be used as a |method|: >
2629 Compute()->floor()
2630<
2631 {only available when compiled with the |+float| feature}
2632
2633
2634fmod({expr1}, {expr2}) *fmod()*
2635 Return the remainder of {expr1} / {expr2}, even if the
2636 division is not representable. Returns {expr1} - i * {expr2}
2637 for some integer i such that if {expr2} is non-zero, the
2638 result has the same sign as {expr1} and magnitude less than
2639 the magnitude of {expr2}. If {expr2} is zero, the value
2640 returned is zero. The value returned is a |Float|.
2641 {expr1} and {expr2} must evaluate to a |Float| or a |Number|.
2642 Examples: >
2643 :echo fmod(12.33, 1.22)
2644< 0.13 >
2645 :echo fmod(-12.33, 1.22)
2646< -0.13
2647
2648 Can also be used as a |method|: >
2649 Compute()->fmod(1.22)
2650<
2651 {only available when compiled with |+float| feature}
2652
2653
2654fnameescape({string}) *fnameescape()*
2655 Escape {string} for use as file name command argument. All
2656 characters that have a special meaning, such as '%' and '|'
2657 are escaped with a backslash.
2658 For most systems the characters escaped are
2659 " \t\n*?[{`$\\%#'\"|!<". For systems where a backslash
2660 appears in a filename, it depends on the value of 'isfname'.
2661 A leading '+' and '>' is also escaped (special after |:edit|
2662 and |:write|). And a "-" by itself (special after |:cd|).
2663 Example: >
2664 :let fname = '+some str%nge|name'
Bram Moolenaarc51cf032022-02-26 12:25:45 +00002665 :exe "edit " .. fnameescape(fname)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002666< results in executing: >
2667 edit \+some\ str\%nge\|name
2668<
2669 Can also be used as a |method|: >
2670 GetName()->fnameescape()
2671
2672fnamemodify({fname}, {mods}) *fnamemodify()*
2673 Modify file name {fname} according to {mods}. {mods} is a
2674 string of characters like it is used for file names on the
2675 command line. See |filename-modifiers|.
2676 Example: >
2677 :echo fnamemodify("main.c", ":p:h")
2678< results in: >
2679 /home/mool/vim/vim/src
2680< If {mods} is empty then {fname} is returned.
2681 Note: Environment variables don't work in {fname}, use
2682 |expand()| first then.
2683
2684 Can also be used as a |method|: >
2685 GetName()->fnamemodify(':p:h')
2686
2687foldclosed({lnum}) *foldclosed()*
2688 The result is a Number. If the line {lnum} is in a closed
2689 fold, the result is the number of the first line in that fold.
2690 If the line {lnum} is not in a closed fold, -1 is returned.
2691 {lnum} is used like with |getline()|. Thus "." is the current
2692 line, "'m" mark m, etc.
2693
2694 Can also be used as a |method|: >
2695 GetLnum()->foldclosed()
2696
2697foldclosedend({lnum}) *foldclosedend()*
2698 The result is a Number. If the line {lnum} is in a closed
2699 fold, the result is the number of the last line in that fold.
2700 If the line {lnum} is not in a closed fold, -1 is returned.
2701 {lnum} is used like with |getline()|. Thus "." is the current
2702 line, "'m" mark m, etc.
2703
2704 Can also be used as a |method|: >
2705 GetLnum()->foldclosedend()
2706
2707foldlevel({lnum}) *foldlevel()*
2708 The result is a Number, which is the foldlevel of line {lnum}
2709 in the current buffer. For nested folds the deepest level is
2710 returned. If there is no fold at line {lnum}, zero is
2711 returned. It doesn't matter if the folds are open or closed.
2712 When used while updating folds (from 'foldexpr') -1 is
2713 returned for lines where folds are still to be updated and the
2714 foldlevel is unknown. As a special case the level of the
2715 previous line is usually available.
2716 {lnum} is used like with |getline()|. Thus "." is the current
2717 line, "'m" mark m, etc.
2718
2719 Can also be used as a |method|: >
2720 GetLnum()->foldlevel()
2721<
2722 *foldtext()*
2723foldtext() Returns a String, to be displayed for a closed fold. This is
2724 the default function used for the 'foldtext' option and should
2725 only be called from evaluating 'foldtext'. It uses the
2726 |v:foldstart|, |v:foldend| and |v:folddashes| variables.
2727 The returned string looks like this: >
2728 +-- 45 lines: abcdef
2729< The number of leading dashes depends on the foldlevel. The
2730 "45" is the number of lines in the fold. "abcdef" is the text
2731 in the first non-blank line of the fold. Leading white space,
2732 "//" or "/*" and the text from the 'foldmarker' and
2733 'commentstring' options is removed.
2734 When used to draw the actual foldtext, the rest of the line
2735 will be filled with the fold char from the 'fillchars'
2736 setting.
2737 {not available when compiled without the |+folding| feature}
2738
2739foldtextresult({lnum}) *foldtextresult()*
2740 Returns the text that is displayed for the closed fold at line
2741 {lnum}. Evaluates 'foldtext' in the appropriate context.
2742 When there is no closed fold at {lnum} an empty string is
2743 returned.
2744 {lnum} is used like with |getline()|. Thus "." is the current
2745 line, "'m" mark m, etc.
2746 Useful when exporting folded text, e.g., to HTML.
2747 {not available when compiled without the |+folding| feature}
2748
2749
2750 Can also be used as a |method|: >
2751 GetLnum()->foldtextresult()
2752<
2753 *foreground()*
2754foreground() Move the Vim window to the foreground. Useful when sent from
2755 a client to a Vim server. |remote_send()|
2756 On Win32 systems this might not work, the OS does not always
2757 allow a window to bring itself to the foreground. Use
2758 |remote_foreground()| instead.
Bram Moolenaarcbaff5e2022-04-08 17:45:08 +01002759 {only in the Win32, Motif and GTK GUI versions and the
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002760 Win32 console version}
2761
2762fullcommand({name}) *fullcommand()*
2763 Get the full command name from a short abbreviated command
2764 name; see |20.2| for details on command abbreviations.
2765
2766 The string argument {name} may start with a `:` and can
2767 include a [range], these are skipped and not returned.
2768 Returns an empty string if a command doesn't exist or if it's
2769 ambiguous (for user-defined commands).
2770
2771 For example `fullcommand('s')`, `fullcommand('sub')`,
2772 `fullcommand(':%substitute')` all return "substitute".
2773
2774 Can also be used as a |method|: >
2775 GetName()->fullcommand()
2776<
2777 *funcref()*
2778funcref({name} [, {arglist}] [, {dict}])
2779 Just like |function()|, but the returned Funcref will lookup
2780 the function by reference, not by name. This matters when the
2781 function {name} is redefined later.
2782
2783 Unlike |function()|, {name} must be an existing user function.
Bram Moolenaar2f0936c2022-01-08 21:51:59 +00002784 It only works for an autoloaded function if it has already
2785 been loaded (to avoid mistakenly loading the autoload script
2786 when only intending to use the function name, use |function()|
2787 instead). {name} cannot be a builtin function.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002788
2789 Can also be used as a |method|: >
2790 GetFuncname()->funcref([arg])
2791<
2792 *function()* *partial* *E700* *E922* *E923*
2793function({name} [, {arglist}] [, {dict}])
2794 Return a |Funcref| variable that refers to function {name}.
2795 {name} can be the name of a user defined function or an
2796 internal function.
2797
2798 {name} can also be a Funcref or a partial. When it is a
2799 partial the dict stored in it will be used and the {dict}
2800 argument is not allowed. E.g.: >
2801 let FuncWithArg = function(dict.Func, [arg])
2802 let Broken = function(dict.Func, [arg], dict)
2803<
2804 When using the Funcref the function will be found by {name},
2805 also when it was redefined later. Use |funcref()| to keep the
2806 same function.
2807
2808 When {arglist} or {dict} is present this creates a partial.
2809 That means the argument list and/or the dictionary is stored in
2810 the Funcref and will be used when the Funcref is called.
2811
2812 The arguments are passed to the function in front of other
2813 arguments, but after any argument from |method|. Example: >
2814 func Callback(arg1, arg2, name)
2815 ...
2816 let Partial = function('Callback', ['one', 'two'])
2817 ...
2818 call Partial('name')
2819< Invokes the function as with: >
2820 call Callback('one', 'two', 'name')
2821
2822< With a |method|: >
2823 func Callback(one, two, three)
2824 ...
2825 let Partial = function('Callback', ['two'])
2826 ...
2827 eval 'one'->Partial('three')
2828< Invokes the function as with: >
2829 call Callback('one', 'two', 'three')
2830
2831< The function() call can be nested to add more arguments to the
2832 Funcref. The extra arguments are appended to the list of
2833 arguments. Example: >
2834 func Callback(arg1, arg2, name)
2835 ...
2836 let Func = function('Callback', ['one'])
2837 let Func2 = function(Func, ['two'])
2838 ...
2839 call Func2('name')
2840< Invokes the function as with: >
2841 call Callback('one', 'two', 'name')
2842
2843< The Dictionary is only useful when calling a "dict" function.
2844 In that case the {dict} is passed in as "self". Example: >
2845 function Callback() dict
Bram Moolenaarc51cf032022-02-26 12:25:45 +00002846 echo "called for " .. self.name
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002847 endfunction
2848 ...
2849 let context = {"name": "example"}
2850 let Func = function('Callback', context)
2851 ...
2852 call Func() " will echo: called for example
2853< The use of function() is not needed when there are no extra
2854 arguments, these two are equivalent: >
2855 let Func = function('Callback', context)
2856 let Func = context.Callback
2857
2858< The argument list and the Dictionary can be combined: >
2859 function Callback(arg1, count) dict
2860 ...
2861 let context = {"name": "example"}
2862 let Func = function('Callback', ['one'], context)
2863 ...
2864 call Func(500)
2865< Invokes the function as with: >
2866 call context.Callback('one', 500)
2867<
2868 Can also be used as a |method|: >
2869 GetFuncname()->function([arg])
2870
2871
2872garbagecollect([{atexit}]) *garbagecollect()*
2873 Cleanup unused |Lists|, |Dictionaries|, |Channels| and |Jobs|
2874 that have circular references.
2875
2876 There is hardly ever a need to invoke this function, as it is
2877 automatically done when Vim runs out of memory or is waiting
2878 for the user to press a key after 'updatetime'. Items without
2879 circular references are always freed when they become unused.
2880 This is useful if you have deleted a very big |List| and/or
2881 |Dictionary| with circular references in a script that runs
2882 for a long time.
2883
2884 When the optional {atexit} argument is one, garbage
2885 collection will also be done when exiting Vim, if it wasn't
2886 done before. This is useful when checking for memory leaks.
2887
2888 The garbage collection is not done immediately but only when
2889 it's safe to perform. This is when waiting for the user to
2890 type a character. To force garbage collection immediately use
2891 |test_garbagecollect_now()|.
2892
2893get({list}, {idx} [, {default}]) *get()*
2894 Get item {idx} from |List| {list}. When this item is not
2895 available return {default}. Return zero when {default} is
2896 omitted.
2897 Preferably used as a |method|: >
2898 mylist->get(idx)
2899get({blob}, {idx} [, {default}])
2900 Get byte {idx} from |Blob| {blob}. When this byte is not
2901 available return {default}. Return -1 when {default} is
2902 omitted.
2903 Preferably used as a |method|: >
2904 myblob->get(idx)
2905get({dict}, {key} [, {default}])
2906 Get item with key {key} from |Dictionary| {dict}. When this
2907 item is not available return {default}. Return zero when
2908 {default} is omitted. Useful example: >
2909 let val = get(g:, 'var_name', 'default')
2910< This gets the value of g:var_name if it exists, and uses
2911 'default' when it does not exist.
2912 Preferably used as a |method|: >
2913 mydict->get(key)
2914get({func}, {what})
Bram Moolenaar6f4754b2022-01-23 12:07:04 +00002915 Get item {what} from Funcref {func}. Possible values for
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002916 {what} are:
2917 "name" The function name
2918 "func" The function
2919 "dict" The dictionary
2920 "args" The list with arguments
2921 Preferably used as a |method|: >
2922 myfunc->get(what)
2923<
2924 *getbufinfo()*
2925getbufinfo([{buf}])
2926getbufinfo([{dict}])
2927 Get information about buffers as a List of Dictionaries.
2928
2929 Without an argument information about all the buffers is
2930 returned.
2931
2932 When the argument is a |Dictionary| only the buffers matching
2933 the specified criteria are returned. The following keys can
2934 be specified in {dict}:
2935 buflisted include only listed buffers.
2936 bufloaded include only loaded buffers.
2937 bufmodified include only modified buffers.
2938
2939 Otherwise, {buf} specifies a particular buffer to return
2940 information for. For the use of {buf}, see |bufname()|
2941 above. If the buffer is found the returned List has one item.
2942 Otherwise the result is an empty list.
2943
2944 Each returned List item is a dictionary with the following
2945 entries:
2946 bufnr Buffer number.
2947 changed TRUE if the buffer is modified.
2948 changedtick Number of changes made to the buffer.
2949 hidden TRUE if the buffer is hidden.
2950 lastused Timestamp in seconds, like
2951 |localtime()|, when the buffer was
2952 last used.
2953 {only with the |+viminfo| feature}
2954 listed TRUE if the buffer is listed.
2955 lnum Line number used for the buffer when
2956 opened in the current window.
2957 Only valid if the buffer has been
2958 displayed in the window in the past.
2959 If you want the line number of the
2960 last known cursor position in a given
2961 window, use |line()|: >
2962 :echo line('.', {winid})
2963<
2964 linecount Number of lines in the buffer (only
2965 valid when loaded)
2966 loaded TRUE if the buffer is loaded.
2967 name Full path to the file in the buffer.
2968 signs List of signs placed in the buffer.
2969 Each list item is a dictionary with
2970 the following fields:
2971 id sign identifier
2972 lnum line number
2973 name sign name
2974 variables A reference to the dictionary with
2975 buffer-local variables.
2976 windows List of |window-ID|s that display this
2977 buffer
2978 popups List of popup |window-ID|s that
2979 display this buffer
2980
2981 Examples: >
2982 for buf in getbufinfo()
2983 echo buf.name
2984 endfor
2985 for buf in getbufinfo({'buflisted':1})
2986 if buf.changed
2987 ....
2988 endif
2989 endfor
2990<
2991 To get buffer-local options use: >
2992 getbufvar({bufnr}, '&option_name')
2993<
2994 Can also be used as a |method|: >
2995 GetBufnr()->getbufinfo()
2996<
2997
2998 *getbufline()*
2999getbufline({buf}, {lnum} [, {end}])
3000 Return a |List| with the lines starting from {lnum} to {end}
3001 (inclusive) in the buffer {buf}. If {end} is omitted, a
3002 |List| with only the line {lnum} is returned.
3003
3004 For the use of {buf}, see |bufname()| above.
3005
3006 For {lnum} and {end} "$" can be used for the last line of the
3007 buffer. Otherwise a number must be used.
3008
3009 When {lnum} is smaller than 1 or bigger than the number of
3010 lines in the buffer, an empty |List| is returned.
3011
3012 When {end} is greater than the number of lines in the buffer,
3013 it is treated as {end} is set to the number of lines in the
3014 buffer. When {end} is before {lnum} an empty |List| is
3015 returned.
3016
3017 This function works only for loaded buffers. For unloaded and
3018 non-existing buffers, an empty |List| is returned.
3019
3020 Example: >
3021 :let lines = getbufline(bufnr("myfile"), 1, "$")
3022
3023< Can also be used as a |method|: >
3024 GetBufnr()->getbufline(lnum)
3025
3026getbufvar({buf}, {varname} [, {def}]) *getbufvar()*
3027 The result is the value of option or local buffer variable
3028 {varname} in buffer {buf}. Note that the name without "b:"
3029 must be used.
3030 The {varname} argument is a string.
3031 When {varname} is empty returns a |Dictionary| with all the
3032 buffer-local variables.
3033 When {varname} is equal to "&" returns a |Dictionary| with all
3034 the buffer-local options.
3035 Otherwise, when {varname} starts with "&" returns the value of
3036 a buffer-local option.
3037 This also works for a global or buffer-local option, but it
3038 doesn't work for a global variable, window-local variable or
3039 window-local option.
3040 For the use of {buf}, see |bufname()| above.
3041 When the buffer or variable doesn't exist {def} or an empty
3042 string is returned, there is no error message.
3043 Examples: >
3044 :let bufmodified = getbufvar(1, "&mod")
Bram Moolenaarc51cf032022-02-26 12:25:45 +00003045 :echo "todo myvar = " .. getbufvar("todo", "myvar")
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003046
3047< Can also be used as a |method|: >
3048 GetBufnr()->getbufvar(varname)
3049<
3050getchangelist([{buf}]) *getchangelist()*
3051 Returns the |changelist| for the buffer {buf}. For the use
3052 of {buf}, see |bufname()| above. If buffer {buf} doesn't
3053 exist, an empty list is returned.
3054
3055 The returned list contains two entries: a list with the change
3056 locations and the current position in the list. Each
3057 entry in the change list is a dictionary with the following
3058 entries:
3059 col column number
3060 coladd column offset for 'virtualedit'
3061 lnum line number
3062 If buffer {buf} is the current buffer, then the current
3063 position refers to the position in the list. For other
3064 buffers, it is set to the length of the list.
3065
3066 Can also be used as a |method|: >
3067 GetBufnr()->getchangelist()
3068
3069getchar([expr]) *getchar()*
3070 Get a single character from the user or input stream.
3071 If [expr] is omitted, wait until a character is available.
3072 If [expr] is 0, only get a character when one is available.
3073 Return zero otherwise.
3074 If [expr] is 1, only check if a character is available, it is
3075 not consumed. Return zero if no character available.
3076 If you prefer always getting a string use |getcharstr()|.
3077
3078 Without [expr] and when [expr] is 0 a whole character or
3079 special key is returned. If it is a single character, the
3080 result is a number. Use nr2char() to convert it to a String.
3081 Otherwise a String is returned with the encoded character.
3082 For a special key it's a String with a sequence of bytes
3083 starting with 0x80 (decimal: 128). This is the same value as
3084 the String "\<Key>", e.g., "\<Left>". The returned value is
3085 also a String when a modifier (shift, control, alt) was used
3086 that is not included in the character.
3087
3088 When [expr] is 0 and Esc is typed, there will be a short delay
3089 while Vim waits to see if this is the start of an escape
3090 sequence.
3091
3092 When [expr] is 1 only the first byte is returned. For a
3093 one-byte character it is the character itself as a number.
3094 Use nr2char() to convert it to a String.
3095
3096 Use getcharmod() to obtain any additional modifiers.
3097
3098 When the user clicks a mouse button, the mouse event will be
3099 returned. The position can then be found in |v:mouse_col|,
3100 |v:mouse_lnum|, |v:mouse_winid| and |v:mouse_win|.
3101 |getmousepos()| can also be used. Mouse move events will be
3102 ignored.
3103 This example positions the mouse as it would normally happen: >
3104 let c = getchar()
3105 if c == "\<LeftMouse>" && v:mouse_win > 0
Bram Moolenaarc51cf032022-02-26 12:25:45 +00003106 exe v:mouse_win .. "wincmd w"
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003107 exe v:mouse_lnum
Bram Moolenaarc51cf032022-02-26 12:25:45 +00003108 exe "normal " .. v:mouse_col .. "|"
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003109 endif
3110<
3111 When using bracketed paste only the first character is
3112 returned, the rest of the pasted text is dropped.
3113 |xterm-bracketed-paste|.
3114
3115 There is no prompt, you will somehow have to make clear to the
3116 user that a character has to be typed. The screen is not
3117 redrawn, e.g. when resizing the window. When using a popup
3118 window it should work better with a |popup-filter|.
3119
3120 There is no mapping for the character.
3121 Key codes are replaced, thus when the user presses the <Del>
3122 key you get the code for the <Del> key, not the raw character
3123 sequence. Examples: >
3124 getchar() == "\<Del>"
3125 getchar() == "\<S-Left>"
3126< This example redefines "f" to ignore case: >
3127 :nmap f :call FindChar()<CR>
3128 :function FindChar()
3129 : let c = nr2char(getchar())
3130 : while col('.') < col('$') - 1
3131 : normal l
3132 : if getline('.')[col('.') - 1] ==? c
3133 : break
3134 : endif
3135 : endwhile
3136 :endfunction
3137<
3138 You may also receive synthetic characters, such as
3139 |<CursorHold>|. Often you will want to ignore this and get
3140 another character: >
3141 :function GetKey()
3142 : let c = getchar()
3143 : while c == "\<CursorHold>"
3144 : let c = getchar()
3145 : endwhile
3146 : return c
3147 :endfunction
3148
3149getcharmod() *getcharmod()*
3150 The result is a Number which is the state of the modifiers for
3151 the last obtained character with getchar() or in another way.
3152 These values are added together:
3153 2 shift
3154 4 control
3155 8 alt (meta)
3156 16 meta (when it's different from ALT)
3157 32 mouse double click
3158 64 mouse triple click
3159 96 mouse quadruple click (== 32 + 64)
3160 128 command (Macintosh only)
3161 Only the modifiers that have not been included in the
3162 character itself are obtained. Thus Shift-a results in "A"
3163 without a modifier.
3164
3165 *getcharpos()*
3166getcharpos({expr})
3167 Get the position for String {expr}. Same as |getpos()| but the
3168 column number in the returned List is a character index
3169 instead of a byte index.
naohiro ono56200ee2022-01-01 14:59:44 +00003170 If |getpos()| returns a very large column number, equal to
3171 |v:maxcol|, then getcharpos() will return the character index
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003172 of the last character.
3173
3174 Example:
3175 With the cursor on '세' in line 5 with text "여보세요": >
3176 getcharpos('.') returns [0, 5, 3, 0]
3177 getpos('.') returns [0, 5, 7, 0]
3178<
3179 Can also be used as a |method|: >
3180 GetMark()->getcharpos()
3181
3182getcharsearch() *getcharsearch()*
3183 Return the current character search information as a {dict}
3184 with the following entries:
3185
3186 char character previously used for a character
3187 search (|t|, |f|, |T|, or |F|); empty string
3188 if no character search has been performed
3189 forward direction of character search; 1 for forward,
3190 0 for backward
3191 until type of character search; 1 for a |t| or |T|
3192 character search, 0 for an |f| or |F|
3193 character search
3194
3195 This can be useful to always have |;| and |,| search
3196 forward/backward regardless of the direction of the previous
3197 character search: >
3198 :nnoremap <expr> ; getcharsearch().forward ? ';' : ','
3199 :nnoremap <expr> , getcharsearch().forward ? ',' : ';'
3200< Also see |setcharsearch()|.
3201
3202
3203getcharstr([expr]) *getcharstr()*
3204 Get a single character from the user or input stream as a
3205 string.
3206 If [expr] is omitted, wait until a character is available.
3207 If [expr] is 0 or false, only get a character when one is
3208 available. Return an empty string otherwise.
3209 If [expr] is 1 or true, only check if a character is
3210 available, it is not consumed. Return an empty string
3211 if no character is available.
3212 Otherwise this works like |getchar()|, except that a number
3213 result is converted to a string.
3214
Shougo Matsushita79d599b2022-05-07 12:48:29 +01003215getcmdcompltype() *getcmdcompltype()*
3216 Return the type of the current command-line completion.
3217 Only works when the command line is being edited, thus
3218 requires use of |c_CTRL-\_e| or |c_CTRL-R_=|.
3219 See |command-completion| for the return string.
3220 Also see |getcmdtype()|, |setcmdpos()| and |getcmdline()|.
3221 Returns an empty string when completion is not defined.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003222
3223getcmdline() *getcmdline()*
3224 Return the current command-line. Only works when the command
3225 line is being edited, thus requires use of |c_CTRL-\_e| or
3226 |c_CTRL-R_=|.
3227 Example: >
3228 :cmap <F7> <C-\>eescape(getcmdline(), ' \')<CR>
3229< Also see |getcmdtype()|, |getcmdpos()| and |setcmdpos()|.
3230 Returns an empty string when entering a password or using
3231 |inputsecret()|.
3232
3233getcmdpos() *getcmdpos()*
3234 Return the position of the cursor in the command line as a
3235 byte count. The first column is 1.
3236 Only works when editing the command line, thus requires use of
3237 |c_CTRL-\_e| or |c_CTRL-R_=| or an expression mapping.
3238 Returns 0 otherwise.
3239 Also see |getcmdtype()|, |setcmdpos()| and |getcmdline()|.
3240
Shougo Matsushita79d599b2022-05-07 12:48:29 +01003241getcmdscreenpos() *getcmdscreenpos()*
3242 Return the screen position of the cursor in the command line
3243 as a byte count. The first column is 1.
3244 Instead of |getcmdpos()|, it adds the prompt position.
3245 Only works when editing the command line, thus requires use of
3246 |c_CTRL-\_e| or |c_CTRL-R_=| or an expression mapping.
3247 Returns 0 otherwise.
3248 Also see |getcmdpos()|, |setcmdpos()|.
3249
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003250getcmdtype() *getcmdtype()*
3251 Return the current command-line type. Possible return values
3252 are:
3253 : normal Ex command
3254 > debug mode command |debug-mode|
3255 / forward search command
3256 ? backward search command
3257 @ |input()| command
3258 - |:insert| or |:append| command
3259 = |i_CTRL-R_=|
3260 Only works when editing the command line, thus requires use of
3261 |c_CTRL-\_e| or |c_CTRL-R_=| or an expression mapping.
3262 Returns an empty string otherwise.
3263 Also see |getcmdpos()|, |setcmdpos()| and |getcmdline()|.
3264
3265getcmdwintype() *getcmdwintype()*
3266 Return the current |command-line-window| type. Possible return
3267 values are the same as |getcmdtype()|. Returns an empty string
3268 when not in the command-line window.
3269
3270getcompletion({pat}, {type} [, {filtered}]) *getcompletion()*
3271 Return a list of command-line completion matches. The String
3272 {type} argument specifies what for. The following completion
3273 types are supported:
3274
3275 arglist file names in argument list
3276 augroup autocmd groups
3277 buffer buffer names
Bram Moolenaar6e2e2cc2022-03-14 19:24:46 +00003278 behave |:behave| suboptions
3279 breakpoint |:breakadd| and |:breakdel| suboptions
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003280 color color schemes
3281 command Ex command
3282 cmdline |cmdline-completion| result
3283 compiler compilers
3284 cscope |:cscope| suboptions
3285 diff_buffer |:diffget| and |:diffput| completion
3286 dir directory names
3287 environment environment variable names
3288 event autocommand events
3289 expression Vim expression
3290 file file and directory names
3291 file_in_path file and directory names in |'path'|
3292 filetype filetype names |'filetype'|
3293 function function name
3294 help help subjects
3295 highlight highlight groups
Bram Moolenaar6e2e2cc2022-03-14 19:24:46 +00003296 history |:history| suboptions
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003297 locale locale names (as output of locale -a)
3298 mapclear buffer argument
3299 mapping mapping name
3300 menu menus
3301 messages |:messages| suboptions
3302 option options
3303 packadd optional package |pack-add| names
Yegappan Lakshmanan454ce672022-03-24 11:22:13 +00003304 scriptnames sourced script names |:scriptnames|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003305 shellcmd Shell command
3306 sign |:sign| suboptions
3307 syntax syntax file names |'syntax'|
3308 syntime |:syntime| suboptions
3309 tag tags
3310 tag_listfiles tags, file names
3311 user user names
3312 var user variables
3313
3314 If {pat} is an empty string, then all the matches are
3315 returned. Otherwise only items matching {pat} are returned.
3316 See |wildcards| for the use of special characters in {pat}.
3317
3318 If the optional {filtered} flag is set to 1, then 'wildignore'
3319 is applied to filter the results. Otherwise all the matches
3320 are returned. The 'wildignorecase' option always applies.
3321
Yegappan Lakshmanane7dd0fa2022-03-22 16:06:31 +00003322 If the 'wildoptions' option contains 'fuzzy', then fuzzy
3323 matching is used to get the completion matches. Otherwise
Yegappan Lakshmanan454ce672022-03-24 11:22:13 +00003324 regular expression matching is used. Thus this function
3325 follows the user preference, what happens on the command line.
3326 If you do not want this you can make 'wildoptions' empty
3327 before calling getcompletion() and restore it afterwards.
Yegappan Lakshmanane7dd0fa2022-03-22 16:06:31 +00003328
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003329 If {type} is "cmdline", then the |cmdline-completion| result is
3330 returned. For example, to complete the possible values after
3331 a ":call" command: >
3332 echo getcompletion('call ', 'cmdline')
3333<
3334 If there are no matches, an empty list is returned. An
3335 invalid value for {type} produces an error.
3336
3337 Can also be used as a |method|: >
3338 GetPattern()->getcompletion('color')
3339<
3340 *getcurpos()*
3341getcurpos([{winid}])
3342 Get the position of the cursor. This is like getpos('.'), but
3343 includes an extra "curswant" item in the list:
3344 [0, lnum, col, off, curswant] ~
3345 The "curswant" number is the preferred column when moving the
naohiro ono56200ee2022-01-01 14:59:44 +00003346 cursor vertically. After |$| command it will be a very large
3347 number equal to |v:maxcol|. Also see |getcursorcharpos()| and
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003348 |getpos()|.
3349 The first "bufnum" item is always zero. The byte position of
3350 the cursor is returned in 'col'. To get the character
3351 position, use |getcursorcharpos()|.
3352
3353 The optional {winid} argument can specify the window. It can
3354 be the window number or the |window-ID|. The last known
3355 cursor position is returned, this may be invalid for the
3356 current value of the buffer if it is not the current window.
3357 If {winid} is invalid a list with zeroes is returned.
3358
3359 This can be used to save and restore the cursor position: >
3360 let save_cursor = getcurpos()
3361 MoveTheCursorAround
3362 call setpos('.', save_cursor)
3363< Note that this only works within the window. See
3364 |winrestview()| for restoring more state.
3365
3366 Can also be used as a |method|: >
3367 GetWinid()->getcurpos()
3368<
3369 *getcursorcharpos()*
3370getcursorcharpos([{winid}])
3371 Same as |getcurpos()| but the column number in the returned
3372 List is a character index instead of a byte index.
3373
3374 Example:
3375 With the cursor on '보' in line 3 with text "여보세요": >
3376 getcursorcharpos() returns [0, 3, 2, 0, 3]
3377 getcurpos() returns [0, 3, 4, 0, 3]
3378<
3379 Can also be used as a |method|: >
3380 GetWinid()->getcursorcharpos()
3381
3382< *getcwd()*
3383getcwd([{winnr} [, {tabnr}]])
3384 The result is a String, which is the name of the current
3385 working directory. 'autochdir' is ignored.
3386
3387 With {winnr} return the local current directory of this window
3388 in the current tab page. {winnr} can be the window number or
3389 the |window-ID|.
3390 If {winnr} is -1 return the name of the global working
3391 directory. See also |haslocaldir()|.
3392
3393 With {winnr} and {tabnr} return the local current directory of
3394 the window in the specified tab page. If {winnr} is -1 return
3395 the working directory of the tabpage.
3396 If {winnr} is zero use the current window, if {tabnr} is zero
3397 use the current tabpage.
3398 Without any arguments, return the actual working directory of
3399 the current window.
3400 Return an empty string if the arguments are invalid.
3401
3402 Examples: >
3403 " Get the working directory of the current window
3404 :echo getcwd()
3405 :echo getcwd(0)
3406 :echo getcwd(0, 0)
3407 " Get the working directory of window 3 in tabpage 2
3408 :echo getcwd(3, 2)
3409 " Get the global working directory
3410 :echo getcwd(-1)
3411 " Get the working directory of tabpage 3
3412 :echo getcwd(-1, 3)
3413 " Get the working directory of current tabpage
3414 :echo getcwd(-1, 0)
3415
3416< Can also be used as a |method|: >
3417 GetWinnr()->getcwd()
3418
3419getenv({name}) *getenv()*
3420 Return the value of environment variable {name}. The {name}
3421 argument is a string, without a leading '$'. Example: >
3422 myHome = getenv('HOME')
3423
3424< When the variable does not exist |v:null| is returned. That
3425 is different from a variable set to an empty string, although
3426 some systems interpret the empty value as the variable being
3427 deleted. See also |expr-env|.
3428
3429 Can also be used as a |method|: >
3430 GetVarname()->getenv()
3431
3432getfontname([{name}]) *getfontname()*
3433 Without an argument returns the name of the normal font being
3434 used. Like what is used for the Normal highlight group
3435 |hl-Normal|.
3436 With an argument a check is done whether String {name} is a
3437 valid font name. If not then an empty string is returned.
3438 Otherwise the actual font name is returned, or {name} if the
3439 GUI does not support obtaining the real name.
3440 Only works when the GUI is running, thus not in your vimrc or
3441 gvimrc file. Use the |GUIEnter| autocommand to use this
3442 function just after the GUI has started.
3443 Note that the GTK GUI accepts any font name, thus checking for
3444 a valid name does not work.
3445
3446getfperm({fname}) *getfperm()*
3447 The result is a String, which is the read, write, and execute
3448 permissions of the given file {fname}.
3449 If {fname} does not exist or its directory cannot be read, an
3450 empty string is returned.
3451 The result is of the form "rwxrwxrwx", where each group of
3452 "rwx" flags represent, in turn, the permissions of the owner
3453 of the file, the group the file belongs to, and other users.
3454 If a user does not have a given permission the flag for this
3455 is replaced with the string "-". Examples: >
3456 :echo getfperm("/etc/passwd")
3457 :echo getfperm(expand("~/.vimrc"))
3458< This will hopefully (from a security point of view) display
3459 the string "rw-r--r--" or even "rw-------".
3460
3461 Can also be used as a |method|: >
3462 GetFilename()->getfperm()
3463<
3464 For setting permissions use |setfperm()|.
3465
3466getfsize({fname}) *getfsize()*
3467 The result is a Number, which is the size in bytes of the
3468 given file {fname}.
3469 If {fname} is a directory, 0 is returned.
3470 If the file {fname} can't be found, -1 is returned.
3471 If the size of {fname} is too big to fit in a Number then -2
3472 is returned.
3473
3474 Can also be used as a |method|: >
3475 GetFilename()->getfsize()
3476
3477getftime({fname}) *getftime()*
3478 The result is a Number, which is the last modification time of
3479 the given file {fname}. The value is measured as seconds
3480 since 1st Jan 1970, and may be passed to strftime(). See also
3481 |localtime()| and |strftime()|.
3482 If the file {fname} can't be found -1 is returned.
3483
3484 Can also be used as a |method|: >
3485 GetFilename()->getftime()
3486
3487getftype({fname}) *getftype()*
3488 The result is a String, which is a description of the kind of
3489 file of the given file {fname}.
3490 If {fname} does not exist an empty string is returned.
3491 Here is a table over different kinds of files and their
3492 results:
3493 Normal file "file"
3494 Directory "dir"
3495 Symbolic link "link"
3496 Block device "bdev"
3497 Character device "cdev"
3498 Socket "socket"
3499 FIFO "fifo"
3500 All other "other"
3501 Example: >
3502 getftype("/home")
3503< Note that a type such as "link" will only be returned on
3504 systems that support it. On some systems only "dir" and
3505 "file" are returned. On MS-Windows a symbolic link to a
3506 directory returns "dir" instead of "link".
3507
3508 Can also be used as a |method|: >
3509 GetFilename()->getftype()
3510
3511getimstatus() *getimstatus()*
3512 The result is a Number, which is |TRUE| when the IME status is
3513 active.
3514 See 'imstatusfunc'.
3515
3516getjumplist([{winnr} [, {tabnr}]]) *getjumplist()*
3517 Returns the |jumplist| for the specified window.
3518
3519 Without arguments use the current window.
3520 With {winnr} only use this window in the current tab page.
3521 {winnr} can also be a |window-ID|.
3522 With {winnr} and {tabnr} use the window in the specified tab
3523 page.
3524
3525 The returned list contains two entries: a list with the jump
3526 locations and the last used jump position number in the list.
3527 Each entry in the jump location list is a dictionary with
3528 the following entries:
3529 bufnr buffer number
3530 col column number
3531 coladd column offset for 'virtualedit'
3532 filename filename if available
3533 lnum line number
3534
3535 Can also be used as a |method|: >
3536 GetWinnr()->getjumplist()
3537
3538< *getline()*
3539getline({lnum} [, {end}])
3540 Without {end} the result is a String, which is line {lnum}
3541 from the current buffer. Example: >
3542 getline(1)
3543< When {lnum} is a String that doesn't start with a
3544 digit, |line()| is called to translate the String into a Number.
3545 To get the line under the cursor: >
3546 getline(".")
3547< When {lnum} is a number smaller than 1 or bigger than the
3548 number of lines in the buffer, an empty string is returned.
3549
3550 When {end} is given the result is a |List| where each item is
3551 a line from the current buffer in the range {lnum} to {end},
3552 including line {end}.
3553 {end} is used in the same way as {lnum}.
3554 Non-existing lines are silently omitted.
3555 When {end} is before {lnum} an empty |List| is returned.
3556 Example: >
3557 :let start = line('.')
3558 :let end = search("^$") - 1
3559 :let lines = getline(start, end)
3560
3561< Can also be used as a |method|: >
3562 ComputeLnum()->getline()
3563
3564< To get lines from another buffer see |getbufline()|
3565
3566getloclist({nr} [, {what}]) *getloclist()*
3567 Returns a |List| with all the entries in the location list for
3568 window {nr}. {nr} can be the window number or the |window-ID|.
3569 When {nr} is zero the current window is used.
3570
3571 For a location list window, the displayed location list is
3572 returned. For an invalid window number {nr}, an empty list is
3573 returned. Otherwise, same as |getqflist()|.
3574
3575 If the optional {what} dictionary argument is supplied, then
3576 returns the items listed in {what} as a dictionary. Refer to
3577 |getqflist()| for the supported items in {what}.
3578
3579 In addition to the items supported by |getqflist()| in {what},
3580 the following item is supported by |getloclist()|:
3581
3582 filewinid id of the window used to display files
3583 from the location list. This field is
3584 applicable only when called from a
3585 location list window. See
3586 |location-list-file-window| for more
3587 details.
3588
3589 Returns a |Dictionary| with default values if there is no
3590 location list for the window {nr}.
3591 Returns an empty Dictionary if window {nr} does not exist.
3592
3593 Examples (See also |getqflist-examples|): >
3594 :echo getloclist(3, {'all': 0})
3595 :echo getloclist(5, {'filewinid': 0})
3596
3597
3598getmarklist([{buf}]) *getmarklist()*
3599 Without the {buf} argument returns a |List| with information
3600 about all the global marks. |mark|
3601
3602 If the optional {buf} argument is specified, returns the
3603 local marks defined in buffer {buf}. For the use of {buf},
3604 see |bufname()|.
3605
3606 Each item in the returned List is a |Dict| with the following:
3607 mark name of the mark prefixed by "'"
3608 pos a |List| with the position of the mark:
3609 [bufnum, lnum, col, off]
3610 Refer to |getpos()| for more information.
3611 file file name
3612
3613 Refer to |getpos()| for getting information about a specific
3614 mark.
3615
3616 Can also be used as a |method|: >
3617 GetBufnr()->getmarklist()
3618
3619getmatches([{win}]) *getmatches()*
3620 Returns a |List| with all matches previously defined for the
3621 current window by |matchadd()| and the |:match| commands.
3622 |getmatches()| is useful in combination with |setmatches()|,
3623 as |setmatches()| can restore a list of matches saved by
3624 |getmatches()|.
3625 If {win} is specified, use the window with this number or
3626 window ID instead of the current window.
3627 Example: >
3628 :echo getmatches()
3629< [{'group': 'MyGroup1', 'pattern': 'TODO',
3630 'priority': 10, 'id': 1}, {'group': 'MyGroup2',
3631 'pattern': 'FIXME', 'priority': 10, 'id': 2}] >
3632 :let m = getmatches()
3633 :call clearmatches()
3634 :echo getmatches()
3635< [] >
3636 :call setmatches(m)
3637 :echo getmatches()
3638< [{'group': 'MyGroup1', 'pattern': 'TODO',
3639 'priority': 10, 'id': 1}, {'group': 'MyGroup2',
3640 'pattern': 'FIXME', 'priority': 10, 'id': 2}] >
3641 :unlet m
3642<
3643getmousepos() *getmousepos()*
3644 Returns a |Dictionary| with the last known position of the
3645 mouse. This can be used in a mapping for a mouse click or in
3646 a filter of a popup window. The items are:
3647 screenrow screen row
3648 screencol screen column
3649 winid Window ID of the click
3650 winrow row inside "winid"
3651 wincol column inside "winid"
3652 line text line inside "winid"
3653 column text column inside "winid"
3654 All numbers are 1-based.
3655
3656 If not over a window, e.g. when in the command line, then only
3657 "screenrow" and "screencol" are valid, the others are zero.
3658
3659 When on the status line below a window or the vertical
3660 separator right of a window, the "line" and "column" values
3661 are zero.
3662
3663 When the position is after the text then "column" is the
3664 length of the text in bytes plus one.
3665
3666 If the mouse is over a popup window then that window is used.
3667
3668 When using |getchar()| the Vim variables |v:mouse_lnum|,
3669 |v:mouse_col| and |v:mouse_winid| also provide these values.
3670
3671 *getpid()*
3672getpid() Return a Number which is the process ID of the Vim process.
3673 On Unix and MS-Windows this is a unique number, until Vim
3674 exits.
3675
3676 *getpos()*
3677getpos({expr}) Get the position for String {expr}. For possible values of
3678 {expr} see |line()|. For getting the cursor position see
3679 |getcurpos()|.
3680 The result is a |List| with four numbers:
3681 [bufnum, lnum, col, off]
3682 "bufnum" is zero, unless a mark like '0 or 'A is used, then it
3683 is the buffer number of the mark.
3684 "lnum" and "col" are the position in the buffer. The first
3685 column is 1.
3686 The "off" number is zero, unless 'virtualedit' is used. Then
3687 it is the offset in screen columns from the start of the
3688 character. E.g., a position within a <Tab> or after the last
3689 character.
3690 Note that for '< and '> Visual mode matters: when it is "V"
3691 (visual line mode) the column of '< is zero and the column of
naohiro ono56200ee2022-01-01 14:59:44 +00003692 '> is a large number equal to |v:maxcol|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003693 The column number in the returned List is the byte position
3694 within the line. To get the character position in the line,
3695 use |getcharpos()|.
naohiro ono56200ee2022-01-01 14:59:44 +00003696 A very large column number equal to |v:maxcol| can be returned,
3697 in which case it means "after the end of the line".
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003698 This can be used to save and restore the position of a mark: >
3699 let save_a_mark = getpos("'a")
3700 ...
3701 call setpos("'a", save_a_mark)
3702< Also see |getcharpos()|, |getcurpos()| and |setpos()|.
3703
3704 Can also be used as a |method|: >
3705 GetMark()->getpos()
3706
3707getqflist([{what}]) *getqflist()*
3708 Returns a |List| with all the current quickfix errors. Each
3709 list item is a dictionary with these entries:
3710 bufnr number of buffer that has the file name, use
3711 bufname() to get the name
3712 module module name
3713 lnum line number in the buffer (first line is 1)
3714 end_lnum
3715 end of line number if the item is multiline
3716 col column number (first column is 1)
3717 end_col end of column number if the item has range
3718 vcol |TRUE|: "col" is visual column
3719 |FALSE|: "col" is byte index
3720 nr error number
3721 pattern search pattern used to locate the error
3722 text description of the error
3723 type type of the error, 'E', '1', etc.
3724 valid |TRUE|: recognized error message
3725
3726 When there is no error list or it's empty, an empty list is
3727 returned. Quickfix list entries with a non-existing buffer
3728 number are returned with "bufnr" set to zero (Note: some
3729 functions accept buffer number zero for the alternate buffer,
3730 you may need to explicitly check for zero).
3731
3732 Useful application: Find pattern matches in multiple files and
3733 do something with them: >
3734 :vimgrep /theword/jg *.c
3735 :for d in getqflist()
3736 : echo bufname(d.bufnr) ':' d.lnum '=' d.text
3737 :endfor
3738<
3739 If the optional {what} dictionary argument is supplied, then
3740 returns only the items listed in {what} as a dictionary. The
3741 following string items are supported in {what}:
3742 changedtick get the total number of changes made
3743 to the list |quickfix-changedtick|
3744 context get the |quickfix-context|
3745 efm errorformat to use when parsing "lines". If
3746 not present, then the 'errorformat' option
3747 value is used.
3748 id get information for the quickfix list with
3749 |quickfix-ID|; zero means the id for the
3750 current list or the list specified by "nr"
3751 idx get information for the quickfix entry at this
3752 index in the list specified by 'id' or 'nr'.
3753 If set to zero, then uses the current entry.
3754 See |quickfix-index|
3755 items quickfix list entries
3756 lines parse a list of lines using 'efm' and return
3757 the resulting entries. Only a |List| type is
3758 accepted. The current quickfix list is not
3759 modified. See |quickfix-parse|.
3760 nr get information for this quickfix list; zero
3761 means the current quickfix list and "$" means
3762 the last quickfix list
3763 qfbufnr number of the buffer displayed in the quickfix
3764 window. Returns 0 if the quickfix buffer is
3765 not present. See |quickfix-buffer|.
3766 size number of entries in the quickfix list
3767 title get the list title |quickfix-title|
3768 winid get the quickfix |window-ID|
3769 all all of the above quickfix properties
3770 Non-string items in {what} are ignored. To get the value of a
3771 particular item, set it to zero.
3772 If "nr" is not present then the current quickfix list is used.
3773 If both "nr" and a non-zero "id" are specified, then the list
3774 specified by "id" is used.
3775 To get the number of lists in the quickfix stack, set "nr" to
3776 "$" in {what}. The "nr" value in the returned dictionary
3777 contains the quickfix stack size.
3778 When "lines" is specified, all the other items except "efm"
3779 are ignored. The returned dictionary contains the entry
3780 "items" with the list of entries.
3781
3782 The returned dictionary contains the following entries:
3783 changedtick total number of changes made to the
3784 list |quickfix-changedtick|
3785 context quickfix list context. See |quickfix-context|
3786 If not present, set to "".
3787 id quickfix list ID |quickfix-ID|. If not
3788 present, set to 0.
3789 idx index of the quickfix entry in the list. If not
3790 present, set to 0.
3791 items quickfix list entries. If not present, set to
3792 an empty list.
3793 nr quickfix list number. If not present, set to 0
3794 qfbufnr number of the buffer displayed in the quickfix
3795 window. If not present, set to 0.
3796 size number of entries in the quickfix list. If not
3797 present, set to 0.
3798 title quickfix list title text. If not present, set
3799 to "".
3800 winid quickfix |window-ID|. If not present, set to 0
3801
3802 Examples (See also |getqflist-examples|): >
3803 :echo getqflist({'all': 1})
3804 :echo getqflist({'nr': 2, 'title': 1})
3805 :echo getqflist({'lines' : ["F1:10:L10"]})
3806<
3807getreg([{regname} [, 1 [, {list}]]]) *getreg()*
3808 The result is a String, which is the contents of register
3809 {regname}. Example: >
3810 :let cliptext = getreg('*')
3811< When register {regname} was not set the result is an empty
3812 string.
Bram Moolenaara2baa732022-02-04 16:09:54 +00003813 The {regname} argument must be a string. *E1162*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003814
3815 getreg('=') returns the last evaluated value of the expression
3816 register. (For use in maps.)
3817 getreg('=', 1) returns the expression itself, so that it can
3818 be restored with |setreg()|. For other registers the extra
3819 argument is ignored, thus you can always give it.
3820
3821 If {list} is present and |TRUE|, the result type is changed
3822 to |List|. Each list item is one text line. Use it if you care
3823 about zero bytes possibly present inside register: without
3824 third argument both NLs and zero bytes are represented as NLs
3825 (see |NL-used-for-Nul|).
3826 When the register was not set an empty list is returned.
3827
3828 If {regname} is "", the unnamed register '"' is used.
3829 If {regname} is not specified, |v:register| is used.
3830 In |Vim9-script| {regname} must be one character.
3831
3832 Can also be used as a |method|: >
3833 GetRegname()->getreg()
3834
3835getreginfo([{regname}]) *getreginfo()*
3836 Returns detailed information about register {regname} as a
3837 Dictionary with the following entries:
3838 regcontents List of lines contained in register
3839 {regname}, like
3840 |getreg|({regname}, 1, 1).
3841 regtype the type of register {regname}, as in
3842 |getregtype()|.
3843 isunnamed Boolean flag, v:true if this register
3844 is currently pointed to by the unnamed
3845 register.
3846 points_to for the unnamed register, gives the
3847 single letter name of the register
3848 currently pointed to (see |quotequote|).
3849 For example, after deleting a line
3850 with `dd`, this field will be "1",
3851 which is the register that got the
3852 deleted text.
3853
3854 The {regname} argument is a string. If {regname} is invalid
3855 or not set, an empty Dictionary will be returned.
3856 If {regname} is "" or "@", the unnamed register '"' is used.
3857 If {regname} is not specified, |v:register| is used.
3858 The returned Dictionary can be passed to |setreg()|.
3859 In |Vim9-script| {regname} must be one character.
3860
3861 Can also be used as a |method|: >
3862 GetRegname()->getreginfo()
3863
3864getregtype([{regname}]) *getregtype()*
3865 The result is a String, which is type of register {regname}.
3866 The value will be one of:
3867 "v" for |characterwise| text
3868 "V" for |linewise| text
3869 "<CTRL-V>{width}" for |blockwise-visual| text
3870 "" for an empty or unknown register
3871 <CTRL-V> is one character with value 0x16.
3872 The {regname} argument is a string. If {regname} is "", the
3873 unnamed register '"' is used. If {regname} is not specified,
3874 |v:register| is used.
3875 In |Vim9-script| {regname} must be one character.
3876
3877 Can also be used as a |method|: >
3878 GetRegname()->getregtype()
3879
3880gettabinfo([{tabnr}]) *gettabinfo()*
3881 If {tabnr} is not specified, then information about all the
3882 tab pages is returned as a |List|. Each List item is a
3883 |Dictionary|. Otherwise, {tabnr} specifies the tab page
3884 number and information about that one is returned. If the tab
3885 page does not exist an empty List is returned.
3886
3887 Each List item is a |Dictionary| with the following entries:
3888 tabnr tab page number.
3889 variables a reference to the dictionary with
3890 tabpage-local variables
3891 windows List of |window-ID|s in the tab page.
3892
3893 Can also be used as a |method|: >
3894 GetTabnr()->gettabinfo()
3895
3896gettabvar({tabnr}, {varname} [, {def}]) *gettabvar()*
3897 Get the value of a tab-local variable {varname} in tab page
3898 {tabnr}. |t:var|
3899 Tabs are numbered starting with one.
3900 The {varname} argument is a string. When {varname} is empty a
3901 dictionary with all tab-local variables is returned.
3902 Note that the name without "t:" must be used.
3903 When the tab or variable doesn't exist {def} or an empty
3904 string is returned, there is no error message.
3905
3906 Can also be used as a |method|: >
3907 GetTabnr()->gettabvar(varname)
3908
3909gettabwinvar({tabnr}, {winnr}, {varname} [, {def}]) *gettabwinvar()*
3910 Get the value of window-local variable {varname} in window
3911 {winnr} in tab page {tabnr}.
3912 The {varname} argument is a string. When {varname} is empty a
3913 dictionary with all window-local variables is returned.
3914 When {varname} is equal to "&" get the values of all
3915 window-local options in a |Dictionary|.
3916 Otherwise, when {varname} starts with "&" get the value of a
3917 window-local option.
3918 Note that {varname} must be the name without "w:".
3919 Tabs are numbered starting with one. For the current tabpage
3920 use |getwinvar()|.
3921 {winnr} can be the window number or the |window-ID|.
3922 When {winnr} is zero the current window is used.
3923 This also works for a global option, buffer-local option and
3924 window-local option, but it doesn't work for a global variable
3925 or buffer-local variable.
3926 When the tab, window or variable doesn't exist {def} or an
3927 empty string is returned, there is no error message.
3928 Examples: >
3929 :let list_is_on = gettabwinvar(1, 2, '&list')
Bram Moolenaarc51cf032022-02-26 12:25:45 +00003930 :echo "myvar = " .. gettabwinvar(3, 1, 'myvar')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003931<
3932 To obtain all window-local variables use: >
3933 gettabwinvar({tabnr}, {winnr}, '&')
3934
3935< Can also be used as a |method|: >
3936 GetTabnr()->gettabwinvar(winnr, varname)
3937
3938gettagstack([{winnr}]) *gettagstack()*
3939 The result is a Dict, which is the tag stack of window {winnr}.
3940 {winnr} can be the window number or the |window-ID|.
3941 When {winnr} is not specified, the current window is used.
3942 When window {winnr} doesn't exist, an empty Dict is returned.
3943
3944 The returned dictionary contains the following entries:
3945 curidx Current index in the stack. When at
3946 top of the stack, set to (length + 1).
3947 Index of bottom of the stack is 1.
3948 items List of items in the stack. Each item
3949 is a dictionary containing the
3950 entries described below.
3951 length Number of entries in the stack.
3952
3953 Each item in the stack is a dictionary with the following
3954 entries:
3955 bufnr buffer number of the current jump
3956 from cursor position before the tag jump.
3957 See |getpos()| for the format of the
3958 returned list.
3959 matchnr current matching tag number. Used when
3960 multiple matching tags are found for a
3961 name.
3962 tagname name of the tag
3963
3964 See |tagstack| for more information about the tag stack.
3965
3966 Can also be used as a |method|: >
3967 GetWinnr()->gettagstack()
3968
3969
3970gettext({text}) *gettext()*
3971 Translate String {text} if possible.
3972 This is mainly for use in the distributed Vim scripts. When
3973 generating message translations the {text} is extracted by
3974 xgettext, the translator can add the translated message in the
3975 .po file and Vim will lookup the translation when gettext() is
3976 called.
3977 For {text} double quoted strings are preferred, because
3978 xgettext does not understand escaping in single quoted
3979 strings.
3980
3981
3982getwininfo([{winid}]) *getwininfo()*
3983 Returns information about windows as a |List| with Dictionaries.
3984
3985 If {winid} is given Information about the window with that ID
3986 is returned, as a |List| with one item. If the window does not
3987 exist the result is an empty list.
3988
3989 Without {winid} information about all the windows in all the
3990 tab pages is returned.
3991
3992 Each List item is a |Dictionary| with the following entries:
3993 botline last complete displayed buffer line
3994 bufnr number of buffer in the window
3995 height window height (excluding winbar)
3996 loclist 1 if showing a location list
3997 {only with the +quickfix feature}
3998 quickfix 1 if quickfix or location list window
3999 {only with the +quickfix feature}
4000 terminal 1 if a terminal window
4001 {only with the +terminal feature}
4002 tabnr tab page number
4003 topline first displayed buffer line
4004 variables a reference to the dictionary with
4005 window-local variables
4006 width window width
4007 winbar 1 if the window has a toolbar, 0
4008 otherwise
4009 wincol leftmost screen column of the window;
4010 "col" from |win_screenpos()|
4011 textoff number of columns occupied by any
4012 'foldcolumn', 'signcolumn' and line
4013 number in front of the text
4014 winid |window-ID|
4015 winnr window number
4016 winrow topmost screen line of the window;
4017 "row" from |win_screenpos()|
4018
4019 Can also be used as a |method|: >
4020 GetWinnr()->getwininfo()
4021
4022getwinpos([{timeout}]) *getwinpos()*
4023 The result is a |List| with two numbers, the result of
4024 |getwinposx()| and |getwinposy()| combined:
4025 [x-pos, y-pos]
4026 {timeout} can be used to specify how long to wait in msec for
4027 a response from the terminal. When omitted 100 msec is used.
4028 Use a longer time for a remote terminal.
4029 When using a value less than 10 and no response is received
4030 within that time, a previously reported position is returned,
4031 if available. This can be used to poll for the position and
4032 do some work in the meantime: >
4033 while 1
4034 let res = getwinpos(1)
4035 if res[0] >= 0
4036 break
4037 endif
4038 " Do some work here
4039 endwhile
4040<
4041
4042 Can also be used as a |method|: >
4043 GetTimeout()->getwinpos()
4044<
4045 *getwinposx()*
4046getwinposx() The result is a Number, which is the X coordinate in pixels of
4047 the left hand side of the GUI Vim window. Also works for an
4048 xterm (uses a timeout of 100 msec).
4049 The result will be -1 if the information is not available.
4050 The value can be used with `:winpos`.
4051
4052 *getwinposy()*
4053getwinposy() The result is a Number, which is the Y coordinate in pixels of
4054 the top of the GUI Vim window. Also works for an xterm (uses
4055 a timeout of 100 msec).
4056 The result will be -1 if the information is not available.
4057 The value can be used with `:winpos`.
4058
4059getwinvar({winnr}, {varname} [, {def}]) *getwinvar()*
4060 Like |gettabwinvar()| for the current tabpage.
4061 Examples: >
4062 :let list_is_on = getwinvar(2, '&list')
Bram Moolenaarc51cf032022-02-26 12:25:45 +00004063 :echo "myvar = " .. getwinvar(1, 'myvar')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004064
4065< Can also be used as a |method|: >
4066 GetWinnr()->getwinvar(varname)
4067<
4068glob({expr} [, {nosuf} [, {list} [, {alllinks}]]]) *glob()*
4069 Expand the file wildcards in {expr}. See |wildcards| for the
4070 use of special characters.
4071
4072 Unless the optional {nosuf} argument is given and is |TRUE|,
4073 the 'suffixes' and 'wildignore' options apply: Names matching
4074 one of the patterns in 'wildignore' will be skipped and
4075 'suffixes' affect the ordering of matches.
4076 'wildignorecase' always applies.
4077
4078 When {list} is present and it is |TRUE| the result is a |List|
4079 with all matching files. The advantage of using a List is,
4080 you also get filenames containing newlines correctly.
4081 Otherwise the result is a String and when there are several
4082 matches, they are separated by <NL> characters.
4083
4084 If the expansion fails, the result is an empty String or List.
4085
4086 You can also use |readdir()| if you need to do complicated
4087 things, such as limiting the number of matches.
4088
4089 A name for a non-existing file is not included. A symbolic
4090 link is only included if it points to an existing file.
4091 However, when the {alllinks} argument is present and it is
4092 |TRUE| then all symbolic links are included.
4093
4094 For most systems backticks can be used to get files names from
4095 any external command. Example: >
4096 :let tagfiles = glob("`find . -name tags -print`")
4097 :let &tags = substitute(tagfiles, "\n", ",", "g")
4098< The result of the program inside the backticks should be one
4099 item per line. Spaces inside an item are allowed.
4100
4101 See |expand()| for expanding special Vim variables. See
4102 |system()| for getting the raw output of an external command.
4103
4104 Can also be used as a |method|: >
4105 GetExpr()->glob()
4106
4107glob2regpat({string}) *glob2regpat()*
4108 Convert a file pattern, as used by glob(), into a search
4109 pattern. The result can be used to match with a string that
4110 is a file name. E.g. >
4111 if filename =~ glob2regpat('Make*.mak')
4112< This is equivalent to: >
4113 if filename =~ '^Make.*\.mak$'
4114< When {string} is an empty string the result is "^$", match an
4115 empty string.
4116 Note that the result depends on the system. On MS-Windows
4117 a backslash usually means a path separator.
4118
4119 Can also be used as a |method|: >
4120 GetExpr()->glob2regpat()
4121< *globpath()*
4122globpath({path}, {expr} [, {nosuf} [, {list} [, {alllinks}]]])
4123 Perform glob() for String {expr} on all directories in {path}
4124 and concatenate the results. Example: >
4125 :echo globpath(&rtp, "syntax/c.vim")
4126<
4127 {path} is a comma-separated list of directory names. Each
4128 directory name is prepended to {expr} and expanded like with
4129 |glob()|. A path separator is inserted when needed.
4130 To add a comma inside a directory name escape it with a
4131 backslash. Note that on MS-Windows a directory may have a
4132 trailing backslash, remove it if you put a comma after it.
4133 If the expansion fails for one of the directories, there is no
4134 error message.
4135
4136 Unless the optional {nosuf} argument is given and is |TRUE|,
4137 the 'suffixes' and 'wildignore' options apply: Names matching
4138 one of the patterns in 'wildignore' will be skipped and
4139 'suffixes' affect the ordering of matches.
4140
4141 When {list} is present and it is |TRUE| the result is a |List|
4142 with all matching files. The advantage of using a List is, you
4143 also get filenames containing newlines correctly. Otherwise
4144 the result is a String and when there are several matches,
4145 they are separated by <NL> characters. Example: >
4146 :echo globpath(&rtp, "syntax/c.vim", 0, 1)
4147<
4148 {alllinks} is used as with |glob()|.
4149
4150 The "**" item can be used to search in a directory tree.
4151 For example, to find all "README.txt" files in the directories
4152 in 'runtimepath' and below: >
4153 :echo globpath(&rtp, "**/README.txt")
4154< Upwards search and limiting the depth of "**" is not
4155 supported, thus using 'path' will not always work properly.
4156
4157 Can also be used as a |method|, the base is passed as the
4158 second argument: >
4159 GetExpr()->globpath(&rtp)
4160<
4161 *has()*
4162has({feature} [, {check}])
4163 When {check} is omitted or is zero: The result is a Number,
4164 which is 1 if the feature {feature} is supported, zero
4165 otherwise. The {feature} argument is a string, case is
4166 ignored. See |feature-list| below.
4167
4168 When {check} is present and not zero: The result is a Number,
4169 which is 1 if the feature {feature} could ever be supported,
4170 zero otherwise. This is useful to check for a typo in
4171 {feature} and to detect dead code. Keep in mind that an older
4172 Vim version will not know about a feature added later and
4173 features that have been abandoned will not be known by the
4174 current Vim version.
4175
4176 Also see |exists()| and |exists_compiled()|.
4177
4178 Note that to skip code that has a syntax error when the
4179 feature is not available, Vim may skip the rest of the line
4180 and miss a following `endif`. Therefore put the `endif` on a
4181 separate line: >
4182 if has('feature')
4183 let x = this->breaks->without->the->feature
4184 endif
4185< If the `endif` would be moved to the second line as "| endif" it
4186 would not be found.
4187
4188
4189has_key({dict}, {key}) *has_key()*
4190 The result is a Number, which is TRUE if |Dictionary| {dict}
4191 has an entry with key {key}. FALSE otherwise. The {key}
4192 argument is a string.
4193
4194 Can also be used as a |method|: >
4195 mydict->has_key(key)
4196
4197haslocaldir([{winnr} [, {tabnr}]]) *haslocaldir()*
4198 The result is a Number:
4199 1 when the window has set a local directory via |:lcd|
4200 2 when the tab-page has set a local directory via |:tcd|
4201 0 otherwise.
4202
4203 Without arguments use the current window.
4204 With {winnr} use this window in the current tab page.
4205 With {winnr} and {tabnr} use the window in the specified tab
4206 page.
4207 {winnr} can be the window number or the |window-ID|.
4208 If {winnr} is -1 it is ignored and only the tabpage is used.
4209 Return 0 if the arguments are invalid.
4210 Examples: >
4211 if haslocaldir() == 1
4212 " window local directory case
4213 elseif haslocaldir() == 2
4214 " tab-local directory case
4215 else
4216 " global directory case
4217 endif
4218
4219 " current window
4220 :echo haslocaldir()
4221 :echo haslocaldir(0)
4222 :echo haslocaldir(0, 0)
4223 " window n in current tab page
4224 :echo haslocaldir(n)
4225 :echo haslocaldir(n, 0)
4226 " window n in tab page m
4227 :echo haslocaldir(n, m)
4228 " tab page m
4229 :echo haslocaldir(-1, m)
4230<
4231 Can also be used as a |method|: >
4232 GetWinnr()->haslocaldir()
4233
4234hasmapto({what} [, {mode} [, {abbr}]]) *hasmapto()*
4235 The result is a Number, which is TRUE if there is a mapping
4236 that contains {what} in somewhere in the rhs (what it is
4237 mapped to) and this mapping exists in one of the modes
4238 indicated by {mode}.
4239 The arguments {what} and {mode} are strings.
4240 When {abbr} is there and it is |TRUE| use abbreviations
4241 instead of mappings. Don't forget to specify Insert and/or
4242 Command-line mode.
4243 Both the global mappings and the mappings local to the current
4244 buffer are checked for a match.
4245 If no matching mapping is found FALSE is returned.
4246 The following characters are recognized in {mode}:
4247 n Normal mode
4248 v Visual and Select mode
4249 x Visual mode
4250 s Select mode
4251 o Operator-pending mode
4252 i Insert mode
4253 l Language-Argument ("r", "f", "t", etc.)
4254 c Command-line mode
4255 When {mode} is omitted, "nvo" is used.
4256
4257 This function is useful to check if a mapping already exists
4258 to a function in a Vim script. Example: >
4259 :if !hasmapto('\ABCdoit')
4260 : map <Leader>d \ABCdoit
4261 :endif
4262< This installs the mapping to "\ABCdoit" only if there isn't
4263 already a mapping to "\ABCdoit".
4264
4265 Can also be used as a |method|: >
4266 GetRHS()->hasmapto()
4267
4268histadd({history}, {item}) *histadd()*
4269 Add the String {item} to the history {history} which can be
4270 one of: *hist-names*
4271 "cmd" or ":" command line history
4272 "search" or "/" search pattern history
4273 "expr" or "=" typed expression history
4274 "input" or "@" input line history
4275 "debug" or ">" debug command history
4276 empty the current or last used history
4277 The {history} string does not need to be the whole name, one
4278 character is sufficient.
4279 If {item} does already exist in the history, it will be
4280 shifted to become the newest entry.
4281 The result is a Number: TRUE if the operation was successful,
4282 otherwise FALSE is returned.
4283
4284 Example: >
4285 :call histadd("input", strftime("%Y %b %d"))
4286 :let date=input("Enter date: ")
4287< This function is not available in the |sandbox|.
4288
4289 Can also be used as a |method|, the base is passed as the
4290 second argument: >
4291 GetHistory()->histadd('search')
4292
4293histdel({history} [, {item}]) *histdel()*
4294 Clear {history}, i.e. delete all its entries. See |hist-names|
4295 for the possible values of {history}.
4296
4297 If the parameter {item} evaluates to a String, it is used as a
4298 regular expression. All entries matching that expression will
4299 be removed from the history (if there are any).
4300 Upper/lowercase must match, unless "\c" is used |/\c|.
4301 If {item} evaluates to a Number, it will be interpreted as
4302 an index, see |:history-indexing|. The respective entry will
4303 be removed if it exists.
4304
4305 The result is TRUE for a successful operation, otherwise FALSE
4306 is returned.
4307
4308 Examples:
4309 Clear expression register history: >
4310 :call histdel("expr")
4311<
4312 Remove all entries starting with "*" from the search history: >
4313 :call histdel("/", '^\*')
4314<
4315 The following three are equivalent: >
4316 :call histdel("search", histnr("search"))
4317 :call histdel("search", -1)
Bram Moolenaarc51cf032022-02-26 12:25:45 +00004318 :call histdel("search", '^' .. histget("search", -1) .. '$')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004319<
4320 To delete the last search pattern and use the last-but-one for
4321 the "n" command and 'hlsearch': >
4322 :call histdel("search", -1)
4323 :let @/ = histget("search", -1)
4324<
4325 Can also be used as a |method|: >
4326 GetHistory()->histdel()
4327
4328histget({history} [, {index}]) *histget()*
4329 The result is a String, the entry with Number {index} from
4330 {history}. See |hist-names| for the possible values of
4331 {history}, and |:history-indexing| for {index}. If there is
4332 no such entry, an empty String is returned. When {index} is
4333 omitted, the most recent item from the history is used.
4334
4335 Examples:
4336 Redo the second last search from history. >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00004337 :execute '/' .. histget("search", -2)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004338
4339< Define an Ex command ":H {num}" that supports re-execution of
4340 the {num}th entry from the output of |:history|. >
4341 :command -nargs=1 H execute histget("cmd", 0+<args>)
4342<
4343 Can also be used as a |method|: >
4344 GetHistory()->histget()
4345
4346histnr({history}) *histnr()*
4347 The result is the Number of the current entry in {history}.
4348 See |hist-names| for the possible values of {history}.
4349 If an error occurred, -1 is returned.
4350
4351 Example: >
4352 :let inp_index = histnr("expr")
4353
4354< Can also be used as a |method|: >
4355 GetHistory()->histnr()
4356<
4357hlexists({name}) *hlexists()*
4358 The result is a Number, which is TRUE if a highlight group
4359 called {name} exists. This is when the group has been
4360 defined in some way. Not necessarily when highlighting has
4361 been defined for it, it may also have been used for a syntax
4362 item.
4363 *highlight_exists()*
4364 Obsolete name: highlight_exists().
4365
4366 Can also be used as a |method|: >
4367 GetName()->hlexists()
4368<
4369hlget([{name} [, {resolve}]]) *hlget()*
4370 Returns a List of all the highlight group attributes. If the
4371 optional {name} is specified, then returns a List with only
4372 the attributes of the specified highlight group. Returns an
4373 empty List if the highlight group {name} is not present.
4374
4375 If the optional {resolve} argument is set to v:true and the
4376 highlight group {name} is linked to another group, then the
4377 link is resolved recursively and the attributes of the
4378 resolved highlight group are returned.
4379
4380 Each entry in the returned List is a Dictionary with the
4381 following items:
4382 cleared boolean flag, set to v:true if the highlight
4383 group attributes are cleared or not yet
4384 specified. See |highlight-clear|.
4385 cterm cterm attributes. See |highlight-cterm|.
4386 ctermbg cterm background color.
4387 See |highlight-ctermbg|.
4388 ctermfg cterm foreground color.
4389 See |highlight-ctermfg|.
4390 ctermul cterm underline color. See |highlight-ctermul|.
4391 default boolean flag, set to v:true if the highlight
4392 group link is a default link. See
4393 |highlight-default|.
4394 font highlight group font. See |highlight-font|.
4395 gui gui attributes. See |highlight-gui|.
4396 guibg gui background color. See |highlight-guibg|.
4397 guifg gui foreground color. See |highlight-guifg|.
4398 guisp gui special color. See |highlight-guisp|.
4399 id highlight group ID.
4400 linksto linked highlight group name.
4401 See |:highlight-link|.
4402 name highlight group name. See |group-name|.
4403 start start terminal keycode. See |highlight-start|.
4404 stop stop terminal keycode. See |highlight-stop|.
4405 term term attributes. See |highlight-term|.
4406
4407 The 'term', 'cterm' and 'gui' items in the above Dictionary
4408 have a dictionary value with the following optional boolean
4409 items: 'bold', 'standout', 'underline', 'undercurl', 'italic',
4410 'reverse', 'inverse' and 'strikethrough'.
4411
4412 Example(s): >
4413 :echo hlget()
4414 :echo hlget('ModeMsg')
4415 :echo hlget('Number', v:true)
4416<
4417 Can also be used as a |method|: >
4418 GetName()->hlget()
4419<
4420hlset({list}) *hlset()*
4421 Creates or modifies the attributes of a List of highlight
4422 groups. Each item in {list} is a dictionary containing the
4423 attributes of a highlight group. See |hlget()| for the list of
4424 supported items in this dictionary.
4425
4426 In addition to the items described in |hlget()|, the following
4427 additional items are supported in the dictionary:
4428
4429 force boolean flag to force the creation of
4430 a link for an existing highlight group
4431 with attributes.
4432
4433 The highlight group is identified using the 'name' item and
4434 the 'id' item (if supplied) is ignored. If a highlight group
4435 with a specified name doesn't exist, then it is created.
4436 Otherwise the attributes of an existing highlight group are
4437 modified.
4438
4439 If an empty dictionary value is used for the 'term' or 'cterm'
4440 or 'gui' entries, then the corresponding attributes are
4441 cleared. If the 'cleared' item is set to v:true, then all the
4442 attributes of the highlight group are cleared.
4443
4444 The 'linksto' item can be used to link a highlight group to
4445 another highlight group. See |:highlight-link|.
4446
4447 Returns zero for success, -1 for failure.
4448
4449 Example(s): >
4450 " add bold attribute to the Visual highlight group
4451 :call hlset([#{name: 'Visual',
4452 \ term: #{reverse: 1 , bold: 1}}])
4453 :call hlset([#{name: 'Type', guifg: 'DarkGreen'}])
4454 :let l = hlget()
4455 :call hlset(l)
4456 " clear the Search highlight group
4457 :call hlset([#{name: 'Search', cleared: v:true}])
4458 " clear the 'term' attributes for a highlight group
4459 :call hlset([#{name: 'Title', term: {}}])
4460 " create the MyHlg group linking it to DiffAdd
4461 :call hlset([#{name: 'MyHlg', linksto: 'DiffAdd'}])
4462 " remove the MyHlg group link
4463 :call hlset([#{name: 'MyHlg', linksto: 'NONE'}])
4464 " clear the attributes and a link
4465 :call hlset([#{name: 'MyHlg', cleared: v:true,
4466 \ linksto: 'NONE'}])
4467<
4468 Can also be used as a |method|: >
4469 GetAttrList()->hlset()
4470<
4471 *hlID()*
4472hlID({name}) The result is a Number, which is the ID of the highlight group
4473 with name {name}. When the highlight group doesn't exist,
4474 zero is returned.
4475 This can be used to retrieve information about the highlight
4476 group. For example, to get the background color of the
4477 "Comment" group: >
4478 :echo synIDattr(synIDtrans(hlID("Comment")), "bg")
4479< *highlightID()*
4480 Obsolete name: highlightID().
4481
4482 Can also be used as a |method|: >
4483 GetName()->hlID()
4484
4485hostname() *hostname()*
4486 The result is a String, which is the name of the machine on
4487 which Vim is currently running. Machine names greater than
4488 256 characters long are truncated.
4489
4490iconv({string}, {from}, {to}) *iconv()*
4491 The result is a String, which is the text {string} converted
4492 from encoding {from} to encoding {to}.
4493 When the conversion completely fails an empty string is
4494 returned. When some characters could not be converted they
4495 are replaced with "?".
4496 The encoding names are whatever the iconv() library function
4497 can accept, see ":!man 3 iconv".
4498 Most conversions require Vim to be compiled with the |+iconv|
4499 feature. Otherwise only UTF-8 to latin1 conversion and back
4500 can be done.
4501 This can be used to display messages with special characters,
4502 no matter what 'encoding' is set to. Write the message in
4503 UTF-8 and use: >
4504 echo iconv(utf8_str, "utf-8", &enc)
4505< Note that Vim uses UTF-8 for all Unicode encodings, conversion
4506 from/to UCS-2 is automatically changed to use UTF-8. You
4507 cannot use UCS-2 in a string anyway, because of the NUL bytes.
4508
4509 Can also be used as a |method|: >
4510 GetText()->iconv('latin1', 'utf-8')
4511<
4512 *indent()*
4513indent({lnum}) The result is a Number, which is indent of line {lnum} in the
4514 current buffer. The indent is counted in spaces, the value
4515 of 'tabstop' is relevant. {lnum} is used just like in
4516 |getline()|.
4517 When {lnum} is invalid -1 is returned. In |Vim9| script an
4518 error is given.
4519
4520 Can also be used as a |method|: >
4521 GetLnum()->indent()
4522
4523index({object}, {expr} [, {start} [, {ic}]]) *index()*
4524 If {object} is a |List| return the lowest index where the item
4525 has a value equal to {expr}. There is no automatic
4526 conversion, so the String "4" is different from the Number 4.
4527 And the number 4 is different from the Float 4.0. The value
4528 of 'ignorecase' is not used here, case always matters.
4529
4530 If {object} is |Blob| return the lowest index where the byte
4531 value is equal to {expr}.
4532
4533 If {start} is given then start looking at the item with index
4534 {start} (may be negative for an item relative to the end).
4535 When {ic} is given and it is |TRUE|, ignore case. Otherwise
4536 case must match.
4537 -1 is returned when {expr} is not found in {object}.
4538 Example: >
4539 :let idx = index(words, "the")
4540 :if index(numbers, 123) >= 0
4541
4542< Can also be used as a |method|: >
4543 GetObject()->index(what)
4544
4545input({prompt} [, {text} [, {completion}]]) *input()*
4546 The result is a String, which is whatever the user typed on
4547 the command-line. The {prompt} argument is either a prompt
4548 string, or a blank string (for no prompt). A '\n' can be used
4549 in the prompt to start a new line.
4550 The highlighting set with |:echohl| is used for the prompt.
4551 The input is entered just like a command-line, with the same
4552 editing commands and mappings. There is a separate history
4553 for lines typed for input().
4554 Example: >
4555 :if input("Coffee or beer? ") == "beer"
4556 : echo "Cheers!"
4557 :endif
4558<
4559 If the optional {text} argument is present and not empty, this
4560 is used for the default reply, as if the user typed this.
4561 Example: >
4562 :let color = input("Color? ", "white")
4563
4564< The optional {completion} argument specifies the type of
4565 completion supported for the input. Without it completion is
4566 not performed. The supported completion types are the same as
4567 that can be supplied to a user-defined command using the
4568 "-complete=" argument. Refer to |:command-completion| for
4569 more information. Example: >
4570 let fname = input("File: ", "", "file")
4571<
4572 NOTE: This function must not be used in a startup file, for
4573 the versions that only run in GUI mode (e.g., the Win32 GUI).
4574 Note: When input() is called from within a mapping it will
4575 consume remaining characters from that mapping, because a
4576 mapping is handled like the characters were typed.
4577 Use |inputsave()| before input() and |inputrestore()|
4578 after input() to avoid that. Another solution is to avoid
4579 that further characters follow in the mapping, e.g., by using
4580 |:execute| or |:normal|.
4581
4582 Example with a mapping: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00004583 :nmap \x :call GetFoo()<CR>:exe "/" .. Foo<CR>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004584 :function GetFoo()
4585 : call inputsave()
4586 : let g:Foo = input("enter search pattern: ")
4587 : call inputrestore()
4588 :endfunction
4589
4590< Can also be used as a |method|: >
4591 GetPrompt()->input()
4592
4593inputdialog({prompt} [, {text} [, {cancelreturn}]]) *inputdialog()*
4594 Like |input()|, but when the GUI is running and text dialogs
4595 are supported, a dialog window pops up to input the text.
4596 Example: >
4597 :let n = inputdialog("value for shiftwidth", shiftwidth())
4598 :if n != ""
4599 : let &sw = n
4600 :endif
4601< When the dialog is cancelled {cancelreturn} is returned. When
4602 omitted an empty string is returned.
4603 Hitting <Enter> works like pressing the OK button. Hitting
4604 <Esc> works like pressing the Cancel button.
4605 NOTE: Command-line completion is not supported.
4606
4607 Can also be used as a |method|: >
4608 GetPrompt()->inputdialog()
4609
4610inputlist({textlist}) *inputlist()*
4611 {textlist} must be a |List| of strings. This |List| is
4612 displayed, one string per line. The user will be prompted to
4613 enter a number, which is returned.
4614 The user can also select an item by clicking on it with the
4615 mouse, if the mouse is enabled in the command line ('mouse' is
4616 "a" or includes "c"). For the first string 0 is returned.
4617 When clicking above the first item a negative number is
4618 returned. When clicking on the prompt one more than the
4619 length of {textlist} is returned.
4620 Make sure {textlist} has less than 'lines' entries, otherwise
4621 it won't work. It's a good idea to put the entry number at
4622 the start of the string. And put a prompt in the first item.
4623 Example: >
4624 let color = inputlist(['Select color:', '1. red',
4625 \ '2. green', '3. blue'])
4626
4627< Can also be used as a |method|: >
4628 GetChoices()->inputlist()
4629
4630inputrestore() *inputrestore()*
4631 Restore typeahead that was saved with a previous |inputsave()|.
4632 Should be called the same number of times inputsave() is
4633 called. Calling it more often is harmless though.
4634 Returns TRUE when there is nothing to restore, FALSE otherwise.
4635
4636inputsave() *inputsave()*
4637 Preserve typeahead (also from mappings) and clear it, so that
4638 a following prompt gets input from the user. Should be
4639 followed by a matching inputrestore() after the prompt. Can
4640 be used several times, in which case there must be just as
4641 many inputrestore() calls.
4642 Returns TRUE when out of memory, FALSE otherwise.
4643
4644inputsecret({prompt} [, {text}]) *inputsecret()*
4645 This function acts much like the |input()| function with but
4646 two exceptions:
4647 a) the user's response will be displayed as a sequence of
4648 asterisks ("*") thereby keeping the entry secret, and
4649 b) the user's response will not be recorded on the input
4650 |history| stack.
4651 The result is a String, which is whatever the user actually
4652 typed on the command-line in response to the issued prompt.
4653 NOTE: Command-line completion is not supported.
4654
4655 Can also be used as a |method|: >
4656 GetPrompt()->inputsecret()
4657
4658insert({object}, {item} [, {idx}]) *insert()*
4659 When {object} is a |List| or a |Blob| insert {item} at the start
4660 of it.
4661
4662 If {idx} is specified insert {item} before the item with index
4663 {idx}. If {idx} is zero it goes before the first item, just
4664 like omitting {idx}. A negative {idx} is also possible, see
4665 |list-index|. -1 inserts just before the last item.
4666
4667 Returns the resulting |List| or |Blob|. Examples: >
4668 :let mylist = insert([2, 3, 5], 1)
4669 :call insert(mylist, 4, -1)
4670 :call insert(mylist, 6, len(mylist))
4671< The last example can be done simpler with |add()|.
4672 Note that when {item} is a |List| it is inserted as a single
4673 item. Use |extend()| to concatenate |Lists|.
4674
4675 Can also be used as a |method|: >
4676 mylist->insert(item)
4677
4678interrupt() *interrupt()*
4679 Interrupt script execution. It works more or less like the
4680 user typing CTRL-C, most commands won't execute and control
4681 returns to the user. This is useful to abort execution
4682 from lower down, e.g. in an autocommand. Example: >
4683 :function s:check_typoname(file)
4684 : if fnamemodify(a:file, ':t') == '['
4685 : echomsg 'Maybe typo'
4686 : call interrupt()
4687 : endif
4688 :endfunction
4689 :au BufWritePre * call s:check_typoname(expand('<amatch>'))
4690
4691invert({expr}) *invert()*
4692 Bitwise invert. The argument is converted to a number. A
4693 List, Dict or Float argument causes an error. Example: >
4694 :let bits = invert(bits)
4695< Can also be used as a |method|: >
4696 :let bits = bits->invert()
4697
LemonBoydca1d402022-04-28 15:26:33 +01004698isabsolutepath({directory}) *isabsolutepath()*
4699 The result is a Number, which is |TRUE| when {path} is an
4700 absolute path.
4701< On Unix, a path is considered absolute when it starts with '/'.
4702 On MS-Windows, it is considered absolute when it starts with an
4703 optional drive prefix and is followed by a '\' or '/'. UNC paths
4704 are always absolute.
4705 Example: >
4706 echo isabsolutepath('/usr/share/') " 1
4707 echo isabsolutepath('./foobar') " 0
4708 echo isabsolutepath('C:\Windows') " 1
4709 echo isabsolutepath('foobar') " 0
4710 echo isabsolutepath('\\remote\file') " 1
4711
4712 Can also be used as a |method|: >
4713 GetName()->isabsolutepath()
4714
4715
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004716isdirectory({directory}) *isdirectory()*
4717 The result is a Number, which is |TRUE| when a directory
4718 with the name {directory} exists. If {directory} doesn't
4719 exist, or isn't a directory, the result is |FALSE|. {directory}
4720 is any expression, which is used as a String.
4721
4722 Can also be used as a |method|: >
4723 GetName()->isdirectory()
4724
4725isinf({expr}) *isinf()*
4726 Return 1 if {expr} is a positive infinity, or -1 a negative
4727 infinity, otherwise 0. >
4728 :echo isinf(1.0 / 0.0)
4729< 1 >
4730 :echo isinf(-1.0 / 0.0)
4731< -1
4732
4733 Can also be used as a |method|: >
4734 Compute()->isinf()
4735<
4736 {only available when compiled with the |+float| feature}
4737
4738islocked({expr}) *islocked()* *E786*
4739 The result is a Number, which is |TRUE| when {expr} is the
4740 name of a locked variable.
4741 The string argument {expr} must be the name of a variable,
4742 |List| item or |Dictionary| entry, not the variable itself!
4743 Example: >
4744 :let alist = [0, ['a', 'b'], 2, 3]
4745 :lockvar 1 alist
4746 :echo islocked('alist') " 1
4747 :echo islocked('alist[1]') " 0
4748
Bram Moolenaar9da17d72022-02-09 21:50:44 +00004749< When {expr} is a variable that does not exist -1 is returned.
4750 If {expr} uses a range, list or dict index that is out of
4751 range or does not exist you get an error message. Use
4752 |exists()| to check for existence.
4753 In Vim9 script it does not work for local function variables.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004754
4755 Can also be used as a |method|: >
4756 GetName()->islocked()
4757
4758isnan({expr}) *isnan()*
4759 Return |TRUE| if {expr} is a float with value NaN. >
4760 echo isnan(0.0 / 0.0)
4761< 1
4762
4763 Can also be used as a |method|: >
4764 Compute()->isnan()
4765<
4766 {only available when compiled with the |+float| feature}
4767
4768items({dict}) *items()*
4769 Return a |List| with all the key-value pairs of {dict}. Each
4770 |List| item is a list with two items: the key of a {dict}
4771 entry and the value of this entry. The |List| is in arbitrary
4772 order. Also see |keys()| and |values()|.
4773 Example: >
4774 for [key, value] in items(mydict)
Bram Moolenaarc51cf032022-02-26 12:25:45 +00004775 echo key .. ': ' .. value
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004776 endfor
4777
4778< Can also be used as a |method|: >
4779 mydict->items()
4780
4781job_ functions are documented here: |job-functions-details|
4782
4783
4784join({list} [, {sep}]) *join()*
4785 Join the items in {list} together into one String.
4786 When {sep} is specified it is put in between the items. If
4787 {sep} is omitted a single space is used.
4788 Note that {sep} is not added at the end. You might want to
4789 add it there too: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00004790 let lines = join(mylist, "\n") .. "\n"
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004791< String items are used as-is. |Lists| and |Dictionaries| are
4792 converted into a string like with |string()|.
4793 The opposite function is |split()|.
4794
4795 Can also be used as a |method|: >
4796 mylist->join()
4797
4798js_decode({string}) *js_decode()*
4799 This is similar to |json_decode()| with these differences:
4800 - Object key names do not have to be in quotes.
4801 - Strings can be in single quotes.
4802 - Empty items in an array (between two commas) are allowed and
4803 result in v:none items.
4804
4805 Can also be used as a |method|: >
4806 ReadObject()->js_decode()
4807
4808js_encode({expr}) *js_encode()*
4809 This is similar to |json_encode()| with these differences:
4810 - Object key names are not in quotes.
4811 - v:none items in an array result in an empty item between
4812 commas.
4813 For example, the Vim object:
4814 [1,v:none,{"one":1},v:none] ~
4815 Will be encoded as:
4816 [1,,{one:1},,] ~
4817 While json_encode() would produce:
4818 [1,null,{"one":1},null] ~
4819 This encoding is valid for JavaScript. It is more efficient
4820 than JSON, especially when using an array with optional items.
4821
4822 Can also be used as a |method|: >
4823 GetObject()->js_encode()
4824
Bram Moolenaar2f0936c2022-01-08 21:51:59 +00004825json_decode({string}) *json_decode()* *E491*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004826 This parses a JSON formatted string and returns the equivalent
4827 in Vim values. See |json_encode()| for the relation between
4828 JSON and Vim values.
4829 The decoding is permissive:
4830 - A trailing comma in an array and object is ignored, e.g.
4831 "[1, 2, ]" is the same as "[1, 2]".
4832 - Integer keys are accepted in objects, e.g. {1:2} is the
4833 same as {"1":2}.
4834 - More floating point numbers are recognized, e.g. "1." for
4835 "1.0", or "001.2" for "1.2". Special floating point values
4836 "Infinity", "-Infinity" and "NaN" (capitalization ignored)
4837 are accepted.
4838 - Leading zeroes in integer numbers are ignored, e.g. "012"
4839 for "12" or "-012" for "-12".
4840 - Capitalization is ignored in literal names null, true or
4841 false, e.g. "NULL" for "null", "True" for "true".
4842 - Control characters U+0000 through U+001F which are not
4843 escaped in strings are accepted, e.g. " " (tab
4844 character in string) for "\t".
4845 - An empty JSON expression or made of only spaces is accepted
4846 and results in v:none.
4847 - Backslash in an invalid 2-character sequence escape is
4848 ignored, e.g. "\a" is decoded as "a".
4849 - A correct surrogate pair in JSON strings should normally be
4850 a 12 character sequence such as "\uD834\uDD1E", but
4851 json_decode() silently accepts truncated surrogate pairs
4852 such as "\uD834" or "\uD834\u"
4853 *E938*
4854 A duplicate key in an object, valid in rfc7159, is not
4855 accepted by json_decode() as the result must be a valid Vim
4856 type, e.g. this fails: {"a":"b", "a":"c"}
4857
4858 Can also be used as a |method|: >
4859 ReadObject()->json_decode()
4860
4861json_encode({expr}) *json_encode()*
4862 Encode {expr} as JSON and return this as a string.
4863 The encoding is specified in:
4864 https://tools.ietf.org/html/rfc7159.html
Bram Moolenaara2baa732022-02-04 16:09:54 +00004865 Vim values are converted as follows: *E1161*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004866 |Number| decimal number
4867 |Float| floating point number
4868 Float nan "NaN"
4869 Float inf "Infinity"
4870 Float -inf "-Infinity"
4871 |String| in double quotes (possibly null)
4872 |Funcref| not possible, error
4873 |List| as an array (possibly null); when
4874 used recursively: []
4875 |Dict| as an object (possibly null); when
4876 used recursively: {}
4877 |Blob| as an array of the individual bytes
4878 v:false "false"
4879 v:true "true"
4880 v:none "null"
4881 v:null "null"
4882 Note that NaN and Infinity are passed on as values. This is
4883 missing in the JSON standard, but several implementations do
4884 allow it. If not then you will get an error.
Bram Moolenaarcbaff5e2022-04-08 17:45:08 +01004885 If a string contains an illegal character then the replacement
4886 character 0xfffd is used.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004887
4888 Can also be used as a |method|: >
4889 GetObject()->json_encode()
4890
4891keys({dict}) *keys()*
4892 Return a |List| with all the keys of {dict}. The |List| is in
4893 arbitrary order. Also see |items()| and |values()|.
4894
4895 Can also be used as a |method|: >
4896 mydict->keys()
4897
4898< *len()* *E701*
4899len({expr}) The result is a Number, which is the length of the argument.
4900 When {expr} is a String or a Number the length in bytes is
4901 used, as with |strlen()|.
4902 When {expr} is a |List| the number of items in the |List| is
4903 returned.
4904 When {expr} is a |Blob| the number of bytes is returned.
4905 When {expr} is a |Dictionary| the number of entries in the
4906 |Dictionary| is returned.
4907 Otherwise an error is given.
4908
4909 Can also be used as a |method|: >
4910 mylist->len()
4911
4912< *libcall()* *E364* *E368*
4913libcall({libname}, {funcname}, {argument})
4914 Call function {funcname} in the run-time library {libname}
4915 with single argument {argument}.
4916 This is useful to call functions in a library that you
4917 especially made to be used with Vim. Since only one argument
4918 is possible, calling standard library functions is rather
4919 limited.
4920 The result is the String returned by the function. If the
4921 function returns NULL, this will appear as an empty string ""
4922 to Vim.
4923 If the function returns a number, use libcallnr()!
4924 If {argument} is a number, it is passed to the function as an
4925 int; if {argument} is a string, it is passed as a
4926 null-terminated string.
4927 This function will fail in |restricted-mode|.
4928
4929 libcall() allows you to write your own 'plug-in' extensions to
4930 Vim without having to recompile the program. It is NOT a
4931 means to call system functions! If you try to do so Vim will
4932 very probably crash.
4933
4934 For Win32, the functions you write must be placed in a DLL
4935 and use the normal C calling convention (NOT Pascal which is
4936 used in Windows System DLLs). The function must take exactly
4937 one parameter, either a character pointer or a long integer,
4938 and must return a character pointer or NULL. The character
4939 pointer returned must point to memory that will remain valid
4940 after the function has returned (e.g. in static data in the
4941 DLL). If it points to allocated memory, that memory will
4942 leak away. Using a static buffer in the function should work,
4943 it's then freed when the DLL is unloaded.
4944
4945 WARNING: If the function returns a non-valid pointer, Vim may
4946 crash! This also happens if the function returns a number,
4947 because Vim thinks it's a pointer.
4948 For Win32 systems, {libname} should be the filename of the DLL
4949 without the ".DLL" suffix. A full path is only required if
4950 the DLL is not in the usual places.
4951 For Unix: When compiling your own plugins, remember that the
4952 object code must be compiled as position-independent ('PIC').
4953 {only in Win32 and some Unix versions, when the |+libcall|
4954 feature is present}
4955 Examples: >
4956 :echo libcall("libc.so", "getenv", "HOME")
4957
4958< Can also be used as a |method|, the base is passed as the
4959 third argument: >
4960 GetValue()->libcall("libc.so", "getenv")
4961<
4962 *libcallnr()*
4963libcallnr({libname}, {funcname}, {argument})
4964 Just like |libcall()|, but used for a function that returns an
4965 int instead of a string.
4966 {only in Win32 on some Unix versions, when the |+libcall|
4967 feature is present}
4968 Examples: >
4969 :echo libcallnr("/usr/lib/libc.so", "getpid", "")
4970 :call libcallnr("libc.so", "printf", "Hello World!\n")
4971 :call libcallnr("libc.so", "sleep", 10)
4972<
4973 Can also be used as a |method|, the base is passed as the
4974 third argument: >
4975 GetValue()->libcallnr("libc.so", "printf")
4976<
4977
4978line({expr} [, {winid}]) *line()*
4979 The result is a Number, which is the line number of the file
4980 position given with {expr}. The {expr} argument is a string.
Bram Moolenaara2baa732022-02-04 16:09:54 +00004981 The accepted positions are: *E1209*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004982 . the cursor position
4983 $ the last line in the current buffer
4984 'x position of mark x (if the mark is not set, 0 is
4985 returned)
4986 w0 first line visible in current window (one if the
4987 display isn't updated, e.g. in silent Ex mode)
4988 w$ last line visible in current window (this is one
4989 less than "w0" if no lines are visible)
4990 v In Visual mode: the start of the Visual area (the
4991 cursor is the end). When not in Visual mode
4992 returns the cursor position. Differs from |'<| in
4993 that it's updated right away.
4994 Note that a mark in another file can be used. The line number
4995 then applies to another buffer.
4996 To get the column number use |col()|. To get both use
4997 |getpos()|.
4998 With the optional {winid} argument the values are obtained for
4999 that window instead of the current window.
5000 Examples: >
5001 line(".") line number of the cursor
5002 line(".", winid) idem, in window "winid"
5003 line("'t") line number of mark t
Bram Moolenaarc51cf032022-02-26 12:25:45 +00005004 line("'" .. marker) line number of mark marker
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005005<
5006 To jump to the last known position when opening a file see
5007 |last-position-jump|.
5008
5009 Can also be used as a |method|: >
5010 GetValue()->line()
5011
5012line2byte({lnum}) *line2byte()*
5013 Return the byte count from the start of the buffer for line
5014 {lnum}. This includes the end-of-line character, depending on
5015 the 'fileformat' option for the current buffer. The first
5016 line returns 1. 'encoding' matters, 'fileencoding' is ignored.
5017 This can also be used to get the byte count for the line just
5018 below the last line: >
5019 line2byte(line("$") + 1)
5020< This is the buffer size plus one. If 'fileencoding' is empty
5021 it is the file size plus one. {lnum} is used like with
5022 |getline()|. When {lnum} is invalid, or the |+byte_offset|
5023 feature has been disabled at compile time, -1 is returned.
5024 Also see |byte2line()|, |go| and |:goto|.
5025
5026 Can also be used as a |method|: >
5027 GetLnum()->line2byte()
5028
5029lispindent({lnum}) *lispindent()*
5030 Get the amount of indent for line {lnum} according the lisp
5031 indenting rules, as with 'lisp'.
5032 The indent is counted in spaces, the value of 'tabstop' is
5033 relevant. {lnum} is used just like in |getline()|.
5034 When {lnum} is invalid or Vim was not compiled the
5035 |+lispindent| feature, -1 is returned. In |Vim9| script an
5036 error is given.
5037
5038 Can also be used as a |method|: >
5039 GetLnum()->lispindent()
5040
5041list2blob({list}) *list2blob()*
5042 Return a Blob concatenating all the number values in {list}.
5043 Examples: >
5044 list2blob([1, 2, 3, 4]) returns 0z01020304
5045 list2blob([]) returns 0z
5046< Returns an empty Blob on error. If one of the numbers is
5047 negative or more than 255 error *E1239* is given.
5048
5049 |blob2list()| does the opposite.
5050
5051 Can also be used as a |method|: >
5052 GetList()->list2blob()
5053
5054list2str({list} [, {utf8}]) *list2str()*
5055 Convert each number in {list} to a character string can
5056 concatenate them all. Examples: >
5057 list2str([32]) returns " "
5058 list2str([65, 66, 67]) returns "ABC"
5059< The same can be done (slowly) with: >
5060 join(map(list, {nr, val -> nr2char(val)}), '')
5061< |str2list()| does the opposite.
5062
5063 When {utf8} is omitted or zero, the current 'encoding' is used.
5064 When {utf8} is TRUE, always return UTF-8 characters.
5065 With UTF-8 composing characters work as expected: >
5066 list2str([97, 769]) returns "á"
5067<
5068 Can also be used as a |method|: >
5069 GetList()->list2str()
5070
5071listener_add({callback} [, {buf}]) *listener_add()*
5072 Add a callback function that will be invoked when changes have
5073 been made to buffer {buf}.
5074 {buf} refers to a buffer name or number. For the accepted
5075 values, see |bufname()|. When {buf} is omitted the current
5076 buffer is used.
5077 Returns a unique ID that can be passed to |listener_remove()|.
5078
5079 The {callback} is invoked with five arguments:
Bram Moolenaar944697a2022-02-20 19:48:20 +00005080 bufnr the buffer that was changed
5081 start first changed line number
5082 end first line number below the change
5083 added number of lines added, negative if lines were
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005084 deleted
Bram Moolenaar944697a2022-02-20 19:48:20 +00005085 changes a List of items with details about the changes
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005086
5087 Example: >
5088 func Listener(bufnr, start, end, added, changes)
5089 echo 'lines ' .. a:start .. ' until ' .. a:end .. ' changed'
5090 endfunc
5091 call listener_add('Listener', bufnr)
5092
Bram Moolenaar944697a2022-02-20 19:48:20 +00005093< The List cannot be changed. Each item in "changes" is a
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005094 dictionary with these entries:
5095 lnum the first line number of the change
5096 end the first line below the change
5097 added number of lines added; negative if lines were
5098 deleted
5099 col first column in "lnum" that was affected by
5100 the change; one if unknown or the whole line
5101 was affected; this is a byte index, first
5102 character has a value of one.
5103 When lines are inserted the values are:
5104 lnum line above which the new line is added
5105 end equal to "lnum"
5106 added number of lines inserted
5107 col 1
5108 When lines are deleted the values are:
5109 lnum the first deleted line
5110 end the line below the first deleted line, before
5111 the deletion was done
5112 added negative, number of lines deleted
5113 col 1
5114 When lines are changed:
5115 lnum the first changed line
5116 end the line below the last changed line
5117 added 0
5118 col first column with a change or 1
5119
5120 The entries are in the order the changes were made, thus the
5121 most recent change is at the end. The line numbers are valid
5122 when the callback is invoked, but later changes may make them
5123 invalid, thus keeping a copy for later might not work.
5124
5125 The {callback} is invoked just before the screen is updated,
5126 when |listener_flush()| is called or when a change is being
5127 made that changes the line count in a way it causes a line
5128 number in the list of changes to become invalid.
5129
5130 The {callback} is invoked with the text locked, see
5131 |textlock|. If you do need to make changes to the buffer, use
5132 a timer to do this later |timer_start()|.
5133
5134 The {callback} is not invoked when the buffer is first loaded.
5135 Use the |BufReadPost| autocmd event to handle the initial text
5136 of a buffer.
5137 The {callback} is also not invoked when the buffer is
5138 unloaded, use the |BufUnload| autocmd event for that.
5139
5140 Can also be used as a |method|, the base is passed as the
5141 second argument: >
5142 GetBuffer()->listener_add(callback)
5143
5144listener_flush([{buf}]) *listener_flush()*
5145 Invoke listener callbacks for buffer {buf}. If there are no
5146 pending changes then no callbacks are invoked.
5147
5148 {buf} refers to a buffer name or number. For the accepted
5149 values, see |bufname()|. When {buf} is omitted the current
5150 buffer is used.
5151
5152 Can also be used as a |method|: >
5153 GetBuffer()->listener_flush()
5154
5155listener_remove({id}) *listener_remove()*
5156 Remove a listener previously added with listener_add().
5157 Returns FALSE when {id} could not be found, TRUE when {id} was
5158 removed.
5159
5160 Can also be used as a |method|: >
5161 GetListenerId()->listener_remove()
5162
5163localtime() *localtime()*
5164 Return the current time, measured as seconds since 1st Jan
5165 1970. See also |strftime()|, |strptime()| and |getftime()|.
5166
5167
5168log({expr}) *log()*
5169 Return the natural logarithm (base e) of {expr} as a |Float|.
5170 {expr} must evaluate to a |Float| or a |Number| in the range
5171 (0, inf].
5172 Examples: >
5173 :echo log(10)
5174< 2.302585 >
5175 :echo log(exp(5))
5176< 5.0
5177
5178 Can also be used as a |method|: >
5179 Compute()->log()
5180<
5181 {only available when compiled with the |+float| feature}
5182
5183
5184log10({expr}) *log10()*
5185 Return the logarithm of Float {expr} to base 10 as a |Float|.
5186 {expr} must evaluate to a |Float| or a |Number|.
5187 Examples: >
5188 :echo log10(1000)
5189< 3.0 >
5190 :echo log10(0.01)
5191< -2.0
5192
5193 Can also be used as a |method|: >
5194 Compute()->log10()
5195<
5196 {only available when compiled with the |+float| feature}
5197
5198luaeval({expr} [, {expr}]) *luaeval()*
5199 Evaluate Lua expression {expr} and return its result converted
5200 to Vim data structures. Second {expr} may hold additional
5201 argument accessible as _A inside first {expr}.
5202 Strings are returned as they are.
5203 Boolean objects are converted to numbers.
5204 Numbers are converted to |Float| values if vim was compiled
5205 with |+float| and to numbers otherwise.
5206 Dictionaries and lists obtained by vim.eval() are returned
5207 as-is.
5208 Other objects are returned as zero without any errors.
5209 See |lua-luaeval| for more details.
5210 Note that in a `:def` function local variables are not visible
5211 to {expr}.
5212
5213 Can also be used as a |method|: >
5214 GetExpr()->luaeval()
5215
5216< {only available when compiled with the |+lua| feature}
5217
5218map({expr1}, {expr2}) *map()*
5219 {expr1} must be a |List|, |String|, |Blob| or |Dictionary|.
Bram Moolenaar944697a2022-02-20 19:48:20 +00005220 When {expr1} is a |List| or |Dictionary|, replace each
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005221 item in {expr1} with the result of evaluating {expr2}.
5222 For a |Blob| each byte is replaced.
5223 For a |String|, each character, including composing
5224 characters, is replaced.
5225 If the item type changes you may want to use |mapnew()| to
5226 create a new List or Dictionary. This is required when using
5227 Vim9 script.
5228
5229 {expr2} must be a |String| or |Funcref|.
5230
5231 If {expr2} is a |String|, inside {expr2} |v:val| has the value
5232 of the current item. For a |Dictionary| |v:key| has the key
5233 of the current item and for a |List| |v:key| has the index of
5234 the current item. For a |Blob| |v:key| has the index of the
5235 current byte. For a |String| |v:key| has the index of the
5236 current character.
5237 Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00005238 :call map(mylist, '"> " .. v:val .. " <"')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005239< This puts "> " before and " <" after each item in "mylist".
5240
5241 Note that {expr2} is the result of an expression and is then
5242 used as an expression again. Often it is good to use a
5243 |literal-string| to avoid having to double backslashes. You
5244 still have to double ' quotes
5245
5246 If {expr2} is a |Funcref| it is called with two arguments:
5247 1. The key or the index of the current item.
5248 2. the value of the current item.
5249 The function must return the new value of the item. Example
5250 that changes each value by "key-value": >
5251 func KeyValue(key, val)
Bram Moolenaarc51cf032022-02-26 12:25:45 +00005252 return a:key .. '-' .. a:val
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005253 endfunc
5254 call map(myDict, function('KeyValue'))
5255< It is shorter when using a |lambda|: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00005256 call map(myDict, {key, val -> key .. '-' .. val})
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005257< If you do not use "val" you can leave it out: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00005258 call map(myDict, {key -> 'item: ' .. key})
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005259< If you do not use "key" you can use a short name: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00005260 call map(myDict, {_, val -> 'item: ' .. val})
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005261<
5262 The operation is done in-place for a |List| and |Dictionary|.
5263 If you want it to remain unmodified make a copy first: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00005264 :let tlist = map(copy(mylist), ' v:val .. "\t"')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005265
5266< Returns {expr1}, the |List| or |Dictionary| that was filtered,
5267 or a new |Blob| or |String|.
5268 When an error is encountered while evaluating {expr2} no
5269 further items in {expr1} are processed.
5270 When {expr2} is a Funcref errors inside a function are ignored,
5271 unless it was defined with the "abort" flag.
5272
5273 Can also be used as a |method|: >
5274 mylist->map(expr2)
5275
5276
5277maparg({name} [, {mode} [, {abbr} [, {dict}]]]) *maparg()*
5278 When {dict} is omitted or zero: Return the rhs of mapping
5279 {name} in mode {mode}. The returned String has special
5280 characters translated like in the output of the ":map" command
Ernie Rael09661202022-04-25 14:40:44 +01005281 listing. When {dict} is TRUE a dictionary is returned, see
5282 below. To get a list of all mappings see |maplist()|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005283
5284 When there is no mapping for {name}, an empty String is
5285 returned. When the mapping for {name} is empty, then "<Nop>"
5286 is returned.
5287
5288 The {name} can have special key names, like in the ":map"
5289 command.
5290
5291 {mode} can be one of these strings:
5292 "n" Normal
5293 "v" Visual (including Select)
5294 "o" Operator-pending
5295 "i" Insert
5296 "c" Cmd-line
5297 "s" Select
5298 "x" Visual
5299 "l" langmap |language-mapping|
5300 "t" Terminal-Job
5301 "" Normal, Visual and Operator-pending
5302 When {mode} is omitted, the modes for "" are used.
5303
5304 When {abbr} is there and it is |TRUE| use abbreviations
5305 instead of mappings.
5306
5307 When {dict} is there and it is |TRUE| return a dictionary
5308 containing all the information of the mapping with the
Ernie Rael659c2402022-04-24 18:40:28 +01005309 following items: *mapping-dict*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005310 "lhs" The {lhs} of the mapping as it would be typed
5311 "lhsraw" The {lhs} of the mapping as raw bytes
5312 "lhsrawalt" The {lhs} of the mapping as raw bytes, alternate
5313 form, only present when it differs from "lhsraw"
5314 "rhs" The {rhs} of the mapping as typed.
5315 "silent" 1 for a |:map-silent| mapping, else 0.
5316 "noremap" 1 if the {rhs} of the mapping is not remappable.
5317 "script" 1 if mapping was defined with <script>.
5318 "expr" 1 for an expression mapping (|:map-<expr>|).
5319 "buffer" 1 for a buffer local mapping (|:map-local|).
5320 "mode" Modes for which the mapping is defined. In
5321 addition to the modes mentioned above, these
5322 characters will be used:
5323 " " Normal, Visual and Operator-pending
5324 "!" Insert and Commandline mode
5325 (|mapmode-ic|)
5326 "sid" The script local ID, used for <sid> mappings
5327 (|<SID>|).
Bram Moolenaara9528b32022-01-18 20:51:35 +00005328 "scriptversion" The version of the script. 999999 for
5329 |Vim9| script.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005330 "lnum" The line number in "sid", zero if unknown.
5331 "nowait" Do not wait for other, longer mappings.
5332 (|:map-<nowait>|).
Ernie Rael51d04d12022-05-04 15:40:22 +01005333 "abbr" True if this is an |abbreviation|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005334
5335 The dictionary can be used to restore a mapping with
5336 |mapset()|.
5337
5338 The mappings local to the current buffer are checked first,
5339 then the global mappings.
5340 This function can be used to map a key even when it's already
5341 mapped, and have it do the original mapping too. Sketch: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00005342 exe 'nnoremap <Tab> ==' .. maparg('<Tab>', 'n')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005343
5344< Can also be used as a |method|: >
5345 GetKey()->maparg('n')
5346
5347mapcheck({name} [, {mode} [, {abbr}]]) *mapcheck()*
5348 Check if there is a mapping that matches with {name} in mode
5349 {mode}. See |maparg()| for {mode} and special names in
5350 {name}.
5351 When {abbr} is there and it is |TRUE| use abbreviations
5352 instead of mappings.
5353 A match happens with a mapping that starts with {name} and
5354 with a mapping which is equal to the start of {name}.
5355
5356 matches mapping "a" "ab" "abc" ~
5357 mapcheck("a") yes yes yes
5358 mapcheck("abc") yes yes yes
5359 mapcheck("ax") yes no no
5360 mapcheck("b") no no no
5361
5362 The difference with maparg() is that mapcheck() finds a
5363 mapping that matches with {name}, while maparg() only finds a
5364 mapping for {name} exactly.
5365 When there is no mapping that starts with {name}, an empty
5366 String is returned. If there is one, the RHS of that mapping
5367 is returned. If there are several mappings that start with
5368 {name}, the RHS of one of them is returned. This will be
5369 "<Nop>" if the RHS is empty.
5370 The mappings local to the current buffer are checked first,
5371 then the global mappings.
5372 This function can be used to check if a mapping can be added
5373 without being ambiguous. Example: >
5374 :if mapcheck("_vv") == ""
5375 : map _vv :set guifont=7x13<CR>
5376 :endif
5377< This avoids adding the "_vv" mapping when there already is a
5378 mapping for "_v" or for "_vvv".
5379
5380 Can also be used as a |method|: >
5381 GetKey()->mapcheck('n')
5382
5383
Ernie Rael09661202022-04-25 14:40:44 +01005384maplist([{abbr}]) *maplist()*
5385 Returns a |List| of all mappings. Each List item is a |Dict|,
5386 the same as what is returned by |maparg()|, see
5387 |mapping-dict|. When {abbr} is there and it is |TRUE| use
5388 abbreviations instead of mappings.
5389
5390 Example to show all mappings with 'MultiMatch' in rhs: >
5391 vim9script
5392 echo maplist()->filter(
5393 (_, m) => match(m.rhs, 'MultiMatch') >= 0)
5394
5395
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005396mapnew({expr1}, {expr2}) *mapnew()*
5397 Like |map()| but instead of replacing items in {expr1} a new
5398 List or Dictionary is created and returned. {expr1} remains
5399 unchanged. Items can still be changed by {expr2}, if you
5400 don't want that use |deepcopy()| first.
5401
5402
5403mapset({mode}, {abbr}, {dict}) *mapset()*
Ernie Rael51d04d12022-05-04 15:40:22 +01005404mapset({dict})
5405 Restore a mapping from a dictionary, possibly returned by
5406 |maparg()| or |maplist()|. A buffer mapping, when dict.buffer
5407 is true, is set on the current buffer; it is up to the caller
5408 to insure that the intended buffer is the current buffer. This
5409 feature allows copying mappings from one buffer to another.
5410 The dict.mode value may restore a single mapping that covers
5411 more than one mode, like with mode values of '!', ' ', 'nox',
5412 or 'v'. *E1276*
5413
5414 In the first form, {mode} and {abbr} should be the same as
5415 for the call to |maparg()|. *E460*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005416 {mode} is used to define the mode in which the mapping is set,
5417 not the "mode" entry in {dict}.
5418 Example for saving and restoring a mapping: >
5419 let save_map = maparg('K', 'n', 0, 1)
5420 nnoremap K somethingelse
5421 ...
5422 call mapset('n', 0, save_map)
5423< Note that if you are going to replace a map in several modes,
Ernie Rael51d04d12022-05-04 15:40:22 +01005424 e.g. with `:map!`, you need to save/restore the mapping for
5425 all of them, when they might differ.
5426
5427 In the second form, with {dict} as the only argument, mode
5428 and abbr are taken from the dict.
5429 Example: >
5430 vim9script
5431 var save_maps = maplist()->filter(
5432 (_, m) => m.lhs == 'K')
5433 nnoremap K somethingelse
5434 cnoremap K somethingelse2
5435 # ...
5436 unmap K
5437 for d in save_maps
5438 mapset(d)
5439 endfor
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005440
5441
5442match({expr}, {pat} [, {start} [, {count}]]) *match()*
5443 When {expr} is a |List| then this returns the index of the
5444 first item where {pat} matches. Each item is used as a
5445 String, |Lists| and |Dictionaries| are used as echoed.
5446
5447 Otherwise, {expr} is used as a String. The result is a
5448 Number, which gives the index (byte offset) in {expr} where
5449 {pat} matches.
5450
5451 A match at the first character or |List| item returns zero.
5452 If there is no match -1 is returned.
5453
5454 For getting submatches see |matchlist()|.
5455 Example: >
5456 :echo match("testing", "ing") " results in 4
5457 :echo match([1, 'x'], '\a') " results in 1
5458< See |string-match| for how {pat} is used.
5459 *strpbrk()*
5460 Vim doesn't have a strpbrk() function. But you can do: >
5461 :let sepidx = match(line, '[.,;: \t]')
5462< *strcasestr()*
5463 Vim doesn't have a strcasestr() function. But you can add
5464 "\c" to the pattern to ignore case: >
5465 :let idx = match(haystack, '\cneedle')
5466<
5467 If {start} is given, the search starts from byte index
5468 {start} in a String or item {start} in a |List|.
5469 The result, however, is still the index counted from the
5470 first character/item. Example: >
5471 :echo match("testing", "ing", 2)
5472< result is again "4". >
5473 :echo match("testing", "ing", 4)
5474< result is again "4". >
5475 :echo match("testing", "t", 2)
5476< result is "3".
5477 For a String, if {start} > 0 then it is like the string starts
5478 {start} bytes later, thus "^" will match at {start}. Except
5479 when {count} is given, then it's like matches before the
5480 {start} byte are ignored (this is a bit complicated to keep it
5481 backwards compatible).
5482 For a String, if {start} < 0, it will be set to 0. For a list
5483 the index is counted from the end.
5484 If {start} is out of range ({start} > strlen({expr}) for a
5485 String or {start} > len({expr}) for a |List|) -1 is returned.
5486
5487 When {count} is given use the {count}'th match. When a match
5488 is found in a String the search for the next one starts one
5489 character further. Thus this example results in 1: >
5490 echo match("testing", "..", 0, 2)
5491< In a |List| the search continues in the next item.
5492 Note that when {count} is added the way {start} works changes,
5493 see above.
5494
5495 See |pattern| for the patterns that are accepted.
5496 The 'ignorecase' option is used to set the ignore-caseness of
5497 the pattern. 'smartcase' is NOT used. The matching is always
5498 done like 'magic' is set and 'cpoptions' is empty.
5499 Note that a match at the start is preferred, thus when the
5500 pattern is using "*" (any number of matches) it tends to find
5501 zero matches at the start instead of a number of matches
5502 further down in the text.
5503
5504 Can also be used as a |method|: >
5505 GetText()->match('word')
5506 GetList()->match('word')
5507<
Bram Moolenaar2f0936c2022-01-08 21:51:59 +00005508 *matchadd()* *E290* *E798* *E799* *E801* *E957*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005509matchadd({group}, {pattern} [, {priority} [, {id} [, {dict}]]])
5510 Defines a pattern to be highlighted in the current window (a
5511 "match"). It will be highlighted with {group}. Returns an
5512 identification number (ID), which can be used to delete the
5513 match using |matchdelete()|. The ID is bound to the window.
5514 Matching is case sensitive and magic, unless case sensitivity
5515 or magicness are explicitly overridden in {pattern}. The
5516 'magic', 'smartcase' and 'ignorecase' options are not used.
5517 The "Conceal" value is special, it causes the match to be
5518 concealed.
5519
5520 The optional {priority} argument assigns a priority to the
5521 match. A match with a high priority will have its
5522 highlighting overrule that of a match with a lower priority.
5523 A priority is specified as an integer (negative numbers are no
5524 exception). If the {priority} argument is not specified, the
5525 default priority is 10. The priority of 'hlsearch' is zero,
5526 hence all matches with a priority greater than zero will
5527 overrule it. Syntax highlighting (see 'syntax') is a separate
5528 mechanism, and regardless of the chosen priority a match will
5529 always overrule syntax highlighting.
5530
5531 The optional {id} argument allows the request for a specific
5532 match ID. If a specified ID is already taken, an error
5533 message will appear and the match will not be added. An ID
5534 is specified as a positive integer (zero excluded). IDs 1, 2
5535 and 3 are reserved for |:match|, |:2match| and |:3match|,
5536 respectively. If the {id} argument is not specified or -1,
5537 |matchadd()| automatically chooses a free ID.
5538
5539 The optional {dict} argument allows for further custom
5540 values. Currently this is used to specify a match specific
5541 conceal character that will be shown for |hl-Conceal|
5542 highlighted matches. The dict can have the following members:
5543
5544 conceal Special character to show instead of the
5545 match (only for |hl-Conceal| highlighted
5546 matches, see |:syn-cchar|)
5547 window Instead of the current window use the
5548 window with this number or window ID.
5549
5550 The number of matches is not limited, as it is the case with
5551 the |:match| commands.
5552
5553 Example: >
5554 :highlight MyGroup ctermbg=green guibg=green
5555 :let m = matchadd("MyGroup", "TODO")
5556< Deletion of the pattern: >
5557 :call matchdelete(m)
5558
5559< A list of matches defined by |matchadd()| and |:match| are
5560 available from |getmatches()|. All matches can be deleted in
5561 one operation by |clearmatches()|.
5562
5563 Can also be used as a |method|: >
5564 GetGroup()->matchadd('TODO')
5565<
5566 *matchaddpos()*
5567matchaddpos({group}, {pos} [, {priority} [, {id} [, {dict}]]])
5568 Same as |matchadd()|, but requires a list of positions {pos}
5569 instead of a pattern. This command is faster than |matchadd()|
5570 because it does not require to handle regular expressions and
5571 sets buffer line boundaries to redraw screen. It is supposed
5572 to be used when fast match additions and deletions are
5573 required, for example to highlight matching parentheses.
5574
5575 {pos} is a list of positions. Each position can be one of
5576 these:
5577 - A number. This whole line will be highlighted. The first
5578 line has number 1.
5579 - A list with one number, e.g., [23]. The whole line with this
5580 number will be highlighted.
5581 - A list with two numbers, e.g., [23, 11]. The first number is
5582 the line number, the second one is the column number (first
5583 column is 1, the value must correspond to the byte index as
5584 |col()| would return). The character at this position will
5585 be highlighted.
5586 - A list with three numbers, e.g., [23, 11, 3]. As above, but
5587 the third number gives the length of the highlight in bytes.
5588
5589 The maximum number of positions in {pos} is 8.
5590
5591 Example: >
5592 :highlight MyGroup ctermbg=green guibg=green
5593 :let m = matchaddpos("MyGroup", [[23, 24], 34])
5594< Deletion of the pattern: >
5595 :call matchdelete(m)
5596
5597< Matches added by |matchaddpos()| are returned by
5598 |getmatches()|.
5599
5600 Can also be used as a |method|: >
5601 GetGroup()->matchaddpos([23, 11])
5602
5603matcharg({nr}) *matcharg()*
5604 Selects the {nr} match item, as set with a |:match|,
5605 |:2match| or |:3match| command.
5606 Return a |List| with two elements:
5607 The name of the highlight group used
5608 The pattern used.
5609 When {nr} is not 1, 2 or 3 returns an empty |List|.
5610 When there is no match item set returns ['', ''].
5611 This is useful to save and restore a |:match|.
5612 Highlighting matches using the |:match| commands are limited
5613 to three matches. |matchadd()| does not have this limitation.
5614
5615 Can also be used as a |method|: >
5616 GetMatch()->matcharg()
5617
5618matchdelete({id} [, {win}) *matchdelete()* *E802* *E803*
5619 Deletes a match with ID {id} previously defined by |matchadd()|
5620 or one of the |:match| commands. Returns 0 if successful,
5621 otherwise -1. See example for |matchadd()|. All matches can
5622 be deleted in one operation by |clearmatches()|.
5623 If {win} is specified, use the window with this number or
5624 window ID instead of the current window.
5625
5626 Can also be used as a |method|: >
5627 GetMatch()->matchdelete()
5628
5629matchend({expr}, {pat} [, {start} [, {count}]]) *matchend()*
5630 Same as |match()|, but return the index of first character
5631 after the match. Example: >
5632 :echo matchend("testing", "ing")
5633< results in "7".
5634 *strspn()* *strcspn()*
5635 Vim doesn't have a strspn() or strcspn() function, but you can
5636 do it with matchend(): >
5637 :let span = matchend(line, '[a-zA-Z]')
5638 :let span = matchend(line, '[^a-zA-Z]')
5639< Except that -1 is returned when there are no matches.
5640
5641 The {start}, if given, has the same meaning as for |match()|. >
5642 :echo matchend("testing", "ing", 2)
5643< results in "7". >
5644 :echo matchend("testing", "ing", 5)
5645< result is "-1".
5646 When {expr} is a |List| the result is equal to |match()|.
5647
5648 Can also be used as a |method|: >
5649 GetText()->matchend('word')
5650
5651
5652matchfuzzy({list}, {str} [, {dict}]) *matchfuzzy()*
5653 If {list} is a list of strings, then returns a |List| with all
5654 the strings in {list} that fuzzy match {str}. The strings in
5655 the returned list are sorted based on the matching score.
5656
5657 The optional {dict} argument always supports the following
5658 items:
5659 matchseq When this item is present and {str} contains
5660 multiple words separated by white space, then
5661 returns only matches that contain the words in
5662 the given sequence.
5663
5664 If {list} is a list of dictionaries, then the optional {dict}
5665 argument supports the following additional items:
Yasuhiro Matsumoto9029a6e2022-04-16 12:35:35 +01005666 key Key of the item which is fuzzy matched against
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005667 {str}. The value of this item should be a
5668 string.
5669 text_cb |Funcref| that will be called for every item
5670 in {list} to get the text for fuzzy matching.
5671 This should accept a dictionary item as the
5672 argument and return the text for that item to
5673 use for fuzzy matching.
Yasuhiro Matsumoto9029a6e2022-04-16 12:35:35 +01005674 limit Maximum number of matches in {list} to be
5675 returned. Zero means no limit.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005676
5677 {str} is treated as a literal string and regular expression
5678 matching is NOT supported. The maximum supported {str} length
5679 is 256.
5680
5681 When {str} has multiple words each separated by white space,
5682 then the list of strings that have all the words is returned.
5683
5684 If there are no matching strings or there is an error, then an
5685 empty list is returned. If length of {str} is greater than
5686 256, then returns an empty list.
5687
Yasuhiro Matsumoto9029a6e2022-04-16 12:35:35 +01005688 When {limit} is given, matchfuzzy() will find up to this
5689 number of matches in {list} and return them in sorted order.
5690
Bram Moolenaar1588bc82022-03-08 21:35:07 +00005691 Refer to |fuzzy-matching| for more information about fuzzy
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005692 matching strings.
5693
5694 Example: >
5695 :echo matchfuzzy(["clay", "crow"], "cay")
5696< results in ["clay"]. >
5697 :echo getbufinfo()->map({_, v -> v.name})->matchfuzzy("ndl")
5698< results in a list of buffer names fuzzy matching "ndl". >
5699 :echo getbufinfo()->matchfuzzy("ndl", {'key' : 'name'})
5700< results in a list of buffer information dicts with buffer
5701 names fuzzy matching "ndl". >
5702 :echo getbufinfo()->matchfuzzy("spl",
5703 \ {'text_cb' : {v -> v.name}})
5704< results in a list of buffer information dicts with buffer
5705 names fuzzy matching "spl". >
5706 :echo v:oldfiles->matchfuzzy("test")
5707< results in a list of file names fuzzy matching "test". >
5708 :let l = readfile("buffer.c")->matchfuzzy("str")
5709< results in a list of lines in "buffer.c" fuzzy matching "str". >
5710 :echo ['one two', 'two one']->matchfuzzy('two one')
5711< results in ['two one', 'one two']. >
5712 :echo ['one two', 'two one']->matchfuzzy('two one',
5713 \ {'matchseq': 1})
5714< results in ['two one'].
5715
5716matchfuzzypos({list}, {str} [, {dict}]) *matchfuzzypos()*
5717 Same as |matchfuzzy()|, but returns the list of matched
5718 strings, the list of character positions where characters
5719 in {str} matches and a list of matching scores. You can
5720 use |byteidx()| to convert a character position to a byte
5721 position.
5722
5723 If {str} matches multiple times in a string, then only the
5724 positions for the best match is returned.
5725
5726 If there are no matching strings or there is an error, then a
5727 list with three empty list items is returned.
5728
5729 Example: >
5730 :echo matchfuzzypos(['testing'], 'tsg')
5731< results in [['testing'], [[0, 2, 6]], [99]] >
5732 :echo matchfuzzypos(['clay', 'lacy'], 'la')
5733< results in [['lacy', 'clay'], [[0, 1], [1, 2]], [153, 133]] >
5734 :echo [{'text': 'hello', 'id' : 10}]->matchfuzzypos('ll', {'key' : 'text'})
5735< results in [[{'id': 10, 'text': 'hello'}], [[2, 3]], [127]]
5736
5737matchlist({expr}, {pat} [, {start} [, {count}]]) *matchlist()*
5738 Same as |match()|, but return a |List|. The first item in the
5739 list is the matched string, same as what matchstr() would
5740 return. Following items are submatches, like "\1", "\2", etc.
5741 in |:substitute|. When an optional submatch didn't match an
5742 empty string is used. Example: >
5743 echo matchlist('acd', '\(a\)\?\(b\)\?\(c\)\?\(.*\)')
5744< Results in: ['acd', 'a', '', 'c', 'd', '', '', '', '', '']
5745 When there is no match an empty list is returned.
5746
5747 You can pass in a List, but that is not very useful.
5748
5749 Can also be used as a |method|: >
5750 GetText()->matchlist('word')
5751
5752matchstr({expr}, {pat} [, {start} [, {count}]]) *matchstr()*
5753 Same as |match()|, but return the matched string. Example: >
5754 :echo matchstr("testing", "ing")
5755< results in "ing".
5756 When there is no match "" is returned.
5757 The {start}, if given, has the same meaning as for |match()|. >
5758 :echo matchstr("testing", "ing", 2)
5759< results in "ing". >
5760 :echo matchstr("testing", "ing", 5)
5761< result is "".
5762 When {expr} is a |List| then the matching item is returned.
5763 The type isn't changed, it's not necessarily a String.
5764
5765 Can also be used as a |method|: >
5766 GetText()->matchstr('word')
5767
5768matchstrpos({expr}, {pat} [, {start} [, {count}]]) *matchstrpos()*
5769 Same as |matchstr()|, but return the matched string, the start
5770 position and the end position of the match. Example: >
5771 :echo matchstrpos("testing", "ing")
5772< results in ["ing", 4, 7].
5773 When there is no match ["", -1, -1] is returned.
5774 The {start}, if given, has the same meaning as for |match()|. >
5775 :echo matchstrpos("testing", "ing", 2)
5776< results in ["ing", 4, 7]. >
5777 :echo matchstrpos("testing", "ing", 5)
5778< result is ["", -1, -1].
5779 When {expr} is a |List| then the matching item, the index
5780 of first item where {pat} matches, the start position and the
5781 end position of the match are returned. >
5782 :echo matchstrpos([1, '__x'], '\a')
5783< result is ["x", 1, 2, 3].
5784 The type isn't changed, it's not necessarily a String.
5785
5786 Can also be used as a |method|: >
5787 GetText()->matchstrpos('word')
5788<
5789
5790 *max()*
5791max({expr}) Return the maximum value of all items in {expr}. Example: >
5792 echo max([apples, pears, oranges])
5793
5794< {expr} can be a |List| or a |Dictionary|. For a Dictionary,
5795 it returns the maximum of all values in the Dictionary.
5796 If {expr} is neither a List nor a Dictionary, or one of the
5797 items in {expr} cannot be used as a Number this results in
5798 an error. An empty |List| or |Dictionary| results in zero.
5799
5800 Can also be used as a |method|: >
5801 mylist->max()
5802
5803
5804menu_info({name} [, {mode}]) *menu_info()*
5805 Return information about the specified menu {name} in
5806 mode {mode}. The menu name should be specified without the
5807 shortcut character ('&'). If {name} is "", then the top-level
5808 menu names are returned.
5809
5810 {mode} can be one of these strings:
5811 "n" Normal
5812 "v" Visual (including Select)
5813 "o" Operator-pending
5814 "i" Insert
5815 "c" Cmd-line
5816 "s" Select
5817 "x" Visual
5818 "t" Terminal-Job
5819 "" Normal, Visual and Operator-pending
5820 "!" Insert and Cmd-line
5821 When {mode} is omitted, the modes for "" are used.
5822
5823 Returns a |Dictionary| containing the following items:
5824 accel menu item accelerator text |menu-text|
5825 display display name (name without '&')
5826 enabled v:true if this menu item is enabled
5827 Refer to |:menu-enable|
5828 icon name of the icon file (for toolbar)
5829 |toolbar-icon|
5830 iconidx index of a built-in icon
5831 modes modes for which the menu is defined. In
5832 addition to the modes mentioned above, these
5833 characters will be used:
5834 " " Normal, Visual and Operator-pending
5835 name menu item name.
5836 noremenu v:true if the {rhs} of the menu item is not
5837 remappable else v:false.
5838 priority menu order priority |menu-priority|
5839 rhs right-hand-side of the menu item. The returned
5840 string has special characters translated like
5841 in the output of the ":menu" command listing.
5842 When the {rhs} of a menu item is empty, then
5843 "<Nop>" is returned.
5844 script v:true if script-local remapping of {rhs} is
5845 allowed else v:false. See |:menu-script|.
5846 shortcut shortcut key (character after '&' in
5847 the menu name) |menu-shortcut|
5848 silent v:true if the menu item is created
5849 with <silent> argument |:menu-silent|
5850 submenus |List| containing the names of
5851 all the submenus. Present only if the menu
5852 item has submenus.
5853
5854 Returns an empty dictionary if the menu item is not found.
5855
5856 Examples: >
5857 :echo menu_info('Edit.Cut')
5858 :echo menu_info('File.Save', 'n')
5859
5860 " Display the entire menu hierarchy in a buffer
5861 func ShowMenu(name, pfx)
5862 let m = menu_info(a:name)
5863 call append(line('$'), a:pfx .. m.display)
5864 for child in m->get('submenus', [])
5865 call ShowMenu(a:name .. '.' .. escape(child, '.'),
5866 \ a:pfx .. ' ')
5867 endfor
5868 endfunc
5869 new
5870 for topmenu in menu_info('').submenus
5871 call ShowMenu(topmenu, '')
5872 endfor
5873<
5874 Can also be used as a |method|: >
5875 GetMenuName()->menu_info('v')
5876
5877
5878< *min()*
5879min({expr}) Return the minimum value of all items in {expr}. Example: >
5880 echo min([apples, pears, oranges])
5881
5882< {expr} can be a |List| or a |Dictionary|. For a Dictionary,
5883 it returns the minimum of all values in the Dictionary.
5884 If {expr} is neither a List nor a Dictionary, or one of the
5885 items in {expr} cannot be used as a Number this results in
5886 an error. An empty |List| or |Dictionary| results in zero.
5887
5888 Can also be used as a |method|: >
5889 mylist->min()
5890
5891< *mkdir()* *E739*
5892mkdir({name} [, {path} [, {prot}]])
5893 Create directory {name}.
5894
5895 If {path} is "p" then intermediate directories are created as
5896 necessary. Otherwise it must be "".
5897
5898 If {prot} is given it is used to set the protection bits of
5899 the new directory. The default is 0o755 (rwxr-xr-x: r/w for
5900 the user, readable for others). Use 0o700 to make it
5901 unreadable for others. This is only used for the last part of
5902 {name}. Thus if you create /tmp/foo/bar then /tmp/foo will be
5903 created with 0o755.
5904 Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00005905 :call mkdir($HOME .. "/tmp/foo/bar", "p", 0o700)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005906
5907< This function is not available in the |sandbox|.
5908
5909 There is no error if the directory already exists and the "p"
5910 flag is passed (since patch 8.0.1708). However, without the
5911 "p" option the call will fail.
5912
5913 The function result is a Number, which is TRUE if the call was
5914 successful or FALSE if the directory creation failed or partly
5915 failed.
5916
5917 Not available on all systems. To check use: >
5918 :if exists("*mkdir")
5919
5920< Can also be used as a |method|: >
5921 GetName()->mkdir()
5922<
5923 *mode()*
5924mode([expr]) Return a string that indicates the current mode.
5925 If [expr] is supplied and it evaluates to a non-zero Number or
5926 a non-empty String (|non-zero-arg|), then the full mode is
5927 returned, otherwise only the first letter is returned.
5928 Also see |state()|.
5929
5930 n Normal
5931 no Operator-pending
5932 nov Operator-pending (forced characterwise |o_v|)
5933 noV Operator-pending (forced linewise |o_V|)
5934 noCTRL-V Operator-pending (forced blockwise |o_CTRL-V|);
5935 CTRL-V is one character
5936 niI Normal using |i_CTRL-O| in |Insert-mode|
5937 niR Normal using |i_CTRL-O| in |Replace-mode|
5938 niV Normal using |i_CTRL-O| in |Virtual-Replace-mode|
5939 nt Terminal-Normal (insert goes to Terminal-Job mode)
5940 v Visual by character
5941 vs Visual by character using |v_CTRL-O| in Select mode
5942 V Visual by line
5943 Vs Visual by line using |v_CTRL-O| in Select mode
5944 CTRL-V Visual blockwise
5945 CTRL-Vs Visual blockwise using |v_CTRL-O| in Select mode
5946 s Select by character
5947 S Select by line
5948 CTRL-S Select blockwise
5949 i Insert
5950 ic Insert mode completion |compl-generic|
5951 ix Insert mode |i_CTRL-X| completion
5952 R Replace |R|
5953 Rc Replace mode completion |compl-generic|
5954 Rx Replace mode |i_CTRL-X| completion
5955 Rv Virtual Replace |gR|
5956 Rvc Virtual Replace mode completion |compl-generic|
5957 Rvx Virtual Replace mode |i_CTRL-X| completion
5958 c Command-line editing
5959 cv Vim Ex mode |gQ|
5960 ce Normal Ex mode |Q|
5961 r Hit-enter prompt
5962 rm The -- more -- prompt
5963 r? A |:confirm| query of some sort
5964 ! Shell or external command is executing
5965 t Terminal-Job mode: keys go to the job
5966
5967 This is useful in the 'statusline' option or when used
5968 with |remote_expr()| In most other places it always returns
5969 "c" or "n".
5970 Note that in the future more modes and more specific modes may
5971 be added. It's better not to compare the whole string but only
5972 the leading character(s).
5973 Also see |visualmode()|.
5974
5975 Can also be used as a |method|: >
5976 DoFull()->mode()
5977
5978mzeval({expr}) *mzeval()*
5979 Evaluate MzScheme expression {expr} and return its result
5980 converted to Vim data structures.
5981 Numbers and strings are returned as they are.
5982 Pairs (including lists and improper lists) and vectors are
5983 returned as Vim |Lists|.
5984 Hash tables are represented as Vim |Dictionary| type with keys
5985 converted to strings.
5986 All other types are converted to string with display function.
5987 Examples: >
5988 :mz (define l (list 1 2 3))
5989 :mz (define h (make-hash)) (hash-set! h "list" l)
5990 :echo mzeval("l")
5991 :echo mzeval("h")
5992<
5993 Note that in a `:def` function local variables are not visible
5994 to {expr}.
5995
5996 Can also be used as a |method|: >
5997 GetExpr()->mzeval()
5998<
5999 {only available when compiled with the |+mzscheme| feature}
6000
6001nextnonblank({lnum}) *nextnonblank()*
6002 Return the line number of the first line at or below {lnum}
6003 that is not blank. Example: >
6004 if getline(nextnonblank(1)) =~ "Java"
6005< When {lnum} is invalid or there is no non-blank line at or
6006 below it, zero is returned.
6007 {lnum} is used like with |getline()|.
6008 See also |prevnonblank()|.
6009
6010 Can also be used as a |method|: >
6011 GetLnum()->nextnonblank()
6012
6013nr2char({expr} [, {utf8}]) *nr2char()*
6014 Return a string with a single character, which has the number
6015 value {expr}. Examples: >
6016 nr2char(64) returns "@"
6017 nr2char(32) returns " "
6018< When {utf8} is omitted or zero, the current 'encoding' is used.
6019 Example for "utf-8": >
6020 nr2char(300) returns I with bow character
6021< When {utf8} is TRUE, always return UTF-8 characters.
6022 Note that a NUL character in the file is specified with
6023 nr2char(10), because NULs are represented with newline
6024 characters. nr2char(0) is a real NUL and terminates the
6025 string, thus results in an empty string.
6026 To turn a list of character numbers into a string: >
6027 let list = [65, 66, 67]
6028 let str = join(map(list, {_, val -> nr2char(val)}), '')
6029< Result: "ABC"
6030
6031 Can also be used as a |method|: >
6032 GetNumber()->nr2char()
6033
6034or({expr}, {expr}) *or()*
6035 Bitwise OR on the two arguments. The arguments are converted
6036 to a number. A List, Dict or Float argument causes an error.
6037 Example: >
6038 :let bits = or(bits, 0x80)
6039< Can also be used as a |method|: >
6040 :let bits = bits->or(0x80)
6041
6042
6043pathshorten({path} [, {len}]) *pathshorten()*
6044 Shorten directory names in the path {path} and return the
6045 result. The tail, the file name, is kept as-is. The other
6046 components in the path are reduced to {len} letters in length.
6047 If {len} is omitted or smaller than 1 then 1 is used (single
6048 letters). Leading '~' and '.' characters are kept. Examples: >
6049 :echo pathshorten('~/.vim/autoload/myfile.vim')
6050< ~/.v/a/myfile.vim ~
6051>
6052 :echo pathshorten('~/.vim/autoload/myfile.vim', 2)
6053< ~/.vi/au/myfile.vim ~
6054 It doesn't matter if the path exists or not.
6055
6056 Can also be used as a |method|: >
6057 GetDirectories()->pathshorten()
6058
6059perleval({expr}) *perleval()*
6060 Evaluate Perl expression {expr} in scalar context and return
6061 its result converted to Vim data structures. If value can't be
6062 converted, it is returned as a string Perl representation.
6063 Note: If you want an array or hash, {expr} must return a
6064 reference to it.
6065 Example: >
6066 :echo perleval('[1 .. 4]')
6067< [1, 2, 3, 4]
6068
6069 Note that in a `:def` function local variables are not visible
6070 to {expr}.
6071
6072 Can also be used as a |method|: >
6073 GetExpr()->perleval()
6074
6075< {only available when compiled with the |+perl| feature}
6076
6077
6078popup_ functions are documented here: |popup-functions|
6079
6080
6081pow({x}, {y}) *pow()*
6082 Return the power of {x} to the exponent {y} as a |Float|.
6083 {x} and {y} must evaluate to a |Float| or a |Number|.
6084 Examples: >
6085 :echo pow(3, 3)
6086< 27.0 >
6087 :echo pow(2, 16)
6088< 65536.0 >
6089 :echo pow(32, 0.20)
6090< 2.0
6091
6092 Can also be used as a |method|: >
6093 Compute()->pow(3)
6094<
6095 {only available when compiled with the |+float| feature}
6096
6097prevnonblank({lnum}) *prevnonblank()*
6098 Return the line number of the first line at or above {lnum}
6099 that is not blank. Example: >
6100 let ind = indent(prevnonblank(v:lnum - 1))
6101< When {lnum} is invalid or there is no non-blank line at or
6102 above it, zero is returned.
6103 {lnum} is used like with |getline()|.
6104 Also see |nextnonblank()|.
6105
6106 Can also be used as a |method|: >
6107 GetLnum()->prevnonblank()
6108
6109printf({fmt}, {expr1} ...) *printf()*
6110 Return a String with {fmt}, where "%" items are replaced by
6111 the formatted form of their respective arguments. Example: >
6112 printf("%4d: E%d %.30s", lnum, errno, msg)
6113< May result in:
6114 " 99: E42 asdfasdfasdfasdfasdfasdfasdfas" ~
6115
6116 When used as a |method| the base is passed as the second
6117 argument: >
6118 Compute()->printf("result: %d")
Bram Moolenaarcbaff5e2022-04-08 17:45:08 +01006119<
6120 You can use `call()` to pass the items as a list.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006121
Bram Moolenaarcbaff5e2022-04-08 17:45:08 +01006122 Often used items are:
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006123 %s string
6124 %6S string right-aligned in 6 display cells
6125 %6s string right-aligned in 6 bytes
6126 %.9s string truncated to 9 bytes
6127 %c single byte
6128 %d decimal number
6129 %5d decimal number padded with spaces to 5 characters
6130 %x hex number
6131 %04x hex number padded with zeros to at least 4 characters
6132 %X hex number using upper case letters
6133 %o octal number
6134 %08b binary number padded with zeros to at least 8 chars
6135 %f floating point number as 12.23, inf, -inf or nan
6136 %F floating point number as 12.23, INF, -INF or NAN
6137 %e floating point number as 1.23e3, inf, -inf or nan
6138 %E floating point number as 1.23E3, INF, -INF or NAN
6139 %g floating point number, as %f or %e depending on value
6140 %G floating point number, as %F or %E depending on value
6141 %% the % character itself
6142
6143 Conversion specifications start with '%' and end with the
6144 conversion type. All other characters are copied unchanged to
6145 the result.
6146
6147 The "%" starts a conversion specification. The following
6148 arguments appear in sequence:
6149
6150 % [flags] [field-width] [.precision] type
6151
6152 flags
6153 Zero or more of the following flags:
6154
6155 # The value should be converted to an "alternate
6156 form". For c, d, and s conversions, this option
6157 has no effect. For o conversions, the precision
6158 of the number is increased to force the first
6159 character of the output string to a zero (except
6160 if a zero value is printed with an explicit
6161 precision of zero).
6162 For b and B conversions, a non-zero result has
6163 the string "0b" (or "0B" for B conversions)
6164 prepended to it.
6165 For x and X conversions, a non-zero result has
6166 the string "0x" (or "0X" for X conversions)
6167 prepended to it.
6168
6169 0 (zero) Zero padding. For all conversions the converted
6170 value is padded on the left with zeros rather
6171 than blanks. If a precision is given with a
6172 numeric conversion (d, b, B, o, x, and X), the 0
6173 flag is ignored.
6174
6175 - A negative field width flag; the converted value
6176 is to be left adjusted on the field boundary.
6177 The converted value is padded on the right with
6178 blanks, rather than on the left with blanks or
6179 zeros. A - overrides a 0 if both are given.
6180
6181 ' ' (space) A blank should be left before a positive
6182 number produced by a signed conversion (d).
6183
6184 + A sign must always be placed before a number
6185 produced by a signed conversion. A + overrides
6186 a space if both are used.
6187
6188 field-width
6189 An optional decimal digit string specifying a minimum
6190 field width. If the converted value has fewer bytes
6191 than the field width, it will be padded with spaces on
6192 the left (or right, if the left-adjustment flag has
6193 been given) to fill out the field width. For the S
6194 conversion the count is in cells.
6195
6196 .precision
6197 An optional precision, in the form of a period '.'
6198 followed by an optional digit string. If the digit
6199 string is omitted, the precision is taken as zero.
6200 This gives the minimum number of digits to appear for
6201 d, o, x, and X conversions, the maximum number of
6202 bytes to be printed from a string for s conversions,
6203 or the maximum number of cells to be printed from a
6204 string for S conversions.
6205 For floating point it is the number of digits after
6206 the decimal point.
6207
6208 type
6209 A character that specifies the type of conversion to
6210 be applied, see below.
6211
6212 A field width or precision, or both, may be indicated by an
6213 asterisk '*' instead of a digit string. In this case, a
6214 Number argument supplies the field width or precision. A
6215 negative field width is treated as a left adjustment flag
6216 followed by a positive field width; a negative precision is
6217 treated as though it were missing. Example: >
6218 :echo printf("%d: %.*s", nr, width, line)
6219< This limits the length of the text used from "line" to
6220 "width" bytes.
6221
6222 The conversion specifiers and their meanings are:
6223
6224 *printf-d* *printf-b* *printf-B* *printf-o*
6225 *printf-x* *printf-X*
6226 dbBoxX The Number argument is converted to signed decimal
6227 (d), unsigned binary (b and B), unsigned octal (o), or
6228 unsigned hexadecimal (x and X) notation. The letters
6229 "abcdef" are used for x conversions; the letters
6230 "ABCDEF" are used for X conversions.
6231 The precision, if any, gives the minimum number of
6232 digits that must appear; if the converted value
6233 requires fewer digits, it is padded on the left with
6234 zeros.
6235 In no case does a non-existent or small field width
6236 cause truncation of a numeric field; if the result of
6237 a conversion is wider than the field width, the field
6238 is expanded to contain the conversion result.
6239 The 'h' modifier indicates the argument is 16 bits.
6240 The 'l' modifier indicates the argument is 32 bits.
6241 The 'L' modifier indicates the argument is 64 bits.
6242 Generally, these modifiers are not useful. They are
6243 ignored when type is known from the argument.
6244
6245 i alias for d
6246 D alias for ld
6247 U alias for lu
6248 O alias for lo
6249
6250 *printf-c*
6251 c The Number argument is converted to a byte, and the
6252 resulting character is written.
6253
6254 *printf-s*
6255 s The text of the String argument is used. If a
6256 precision is specified, no more bytes than the number
6257 specified are used.
6258 If the argument is not a String type, it is
6259 automatically converted to text with the same format
6260 as ":echo".
6261 *printf-S*
6262 S The text of the String argument is used. If a
6263 precision is specified, no more display cells than the
6264 number specified are used.
6265
6266 *printf-f* *E807*
6267 f F The Float argument is converted into a string of the
6268 form 123.456. The precision specifies the number of
6269 digits after the decimal point. When the precision is
6270 zero the decimal point is omitted. When the precision
6271 is not specified 6 is used. A really big number
6272 (out of range or dividing by zero) results in "inf"
6273 or "-inf" with %f (INF or -INF with %F).
6274 "0.0 / 0.0" results in "nan" with %f (NAN with %F).
6275 Example: >
6276 echo printf("%.2f", 12.115)
6277< 12.12
6278 Note that roundoff depends on the system libraries.
6279 Use |round()| when in doubt.
6280
6281 *printf-e* *printf-E*
6282 e E The Float argument is converted into a string of the
6283 form 1.234e+03 or 1.234E+03 when using 'E'. The
6284 precision specifies the number of digits after the
6285 decimal point, like with 'f'.
6286
6287 *printf-g* *printf-G*
6288 g G The Float argument is converted like with 'f' if the
6289 value is between 0.001 (inclusive) and 10000000.0
6290 (exclusive). Otherwise 'e' is used for 'g' and 'E'
6291 for 'G'. When no precision is specified superfluous
6292 zeroes and '+' signs are removed, except for the zero
6293 immediately after the decimal point. Thus 10000000.0
6294 results in 1.0e7.
6295
6296 *printf-%*
6297 % A '%' is written. No argument is converted. The
6298 complete conversion specification is "%%".
6299
6300 When a Number argument is expected a String argument is also
6301 accepted and automatically converted.
6302 When a Float or String argument is expected a Number argument
6303 is also accepted and automatically converted.
6304 Any other argument type results in an error message.
6305
6306 *E766* *E767*
6307 The number of {exprN} arguments must exactly match the number
6308 of "%" items. If there are not sufficient or too many
6309 arguments an error is given. Up to 18 arguments can be used.
6310
6311
6312prompt_getprompt({buf}) *prompt_getprompt()*
6313 Returns the effective prompt text for buffer {buf}. {buf} can
6314 be a buffer name or number. See |prompt-buffer|.
6315
6316 If the buffer doesn't exist or isn't a prompt buffer, an empty
6317 string is returned.
6318
6319 Can also be used as a |method|: >
6320 GetBuffer()->prompt_getprompt()
6321
6322< {only available when compiled with the |+channel| feature}
6323
6324
6325prompt_setcallback({buf}, {expr}) *prompt_setcallback()*
6326 Set prompt callback for buffer {buf} to {expr}. When {expr}
6327 is an empty string the callback is removed. This has only
6328 effect if {buf} has 'buftype' set to "prompt".
6329
6330 The callback is invoked when pressing Enter. The current
6331 buffer will always be the prompt buffer. A new line for a
6332 prompt is added before invoking the callback, thus the prompt
6333 for which the callback was invoked will be in the last but one
6334 line.
6335 If the callback wants to add text to the buffer, it must
6336 insert it above the last line, since that is where the current
6337 prompt is. This can also be done asynchronously.
6338 The callback is invoked with one argument, which is the text
6339 that was entered at the prompt. This can be an empty string
6340 if the user only typed Enter.
6341 Example: >
6342 call prompt_setcallback(bufnr(), function('s:TextEntered'))
6343 func s:TextEntered(text)
6344 if a:text == 'exit' || a:text == 'quit'
6345 stopinsert
6346 close
6347 else
Bram Moolenaarc51cf032022-02-26 12:25:45 +00006348 call append(line('$') - 1, 'Entered: "' .. a:text .. '"')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006349 " Reset 'modified' to allow the buffer to be closed.
6350 set nomodified
6351 endif
6352 endfunc
6353
6354< Can also be used as a |method|: >
6355 GetBuffer()->prompt_setcallback(callback)
6356
6357< {only available when compiled with the |+channel| feature}
6358
6359prompt_setinterrupt({buf}, {expr}) *prompt_setinterrupt()*
6360 Set a callback for buffer {buf} to {expr}. When {expr} is an
6361 empty string the callback is removed. This has only effect if
6362 {buf} has 'buftype' set to "prompt".
6363
6364 This callback will be invoked when pressing CTRL-C in Insert
6365 mode. Without setting a callback Vim will exit Insert mode,
6366 as in any buffer.
6367
6368 Can also be used as a |method|: >
6369 GetBuffer()->prompt_setinterrupt(callback)
6370
6371< {only available when compiled with the |+channel| feature}
6372
6373prompt_setprompt({buf}, {text}) *prompt_setprompt()*
6374 Set prompt for buffer {buf} to {text}. You most likely want
6375 {text} to end in a space.
6376 The result is only visible if {buf} has 'buftype' set to
6377 "prompt". Example: >
6378 call prompt_setprompt(bufnr(), 'command: ')
6379<
6380 Can also be used as a |method|: >
6381 GetBuffer()->prompt_setprompt('command: ')
6382
6383< {only available when compiled with the |+channel| feature}
6384
6385prop_ functions are documented here: |text-prop-functions|
6386
6387pum_getpos() *pum_getpos()*
6388 If the popup menu (see |ins-completion-menu|) is not visible,
6389 returns an empty |Dictionary|, otherwise, returns a
6390 |Dictionary| with the following keys:
6391 height nr of items visible
6392 width screen cells
6393 row top screen row (0 first row)
6394 col leftmost screen column (0 first col)
6395 size total nr of items
6396 scrollbar |TRUE| if scrollbar is visible
6397
6398 The values are the same as in |v:event| during
6399 |CompleteChanged|.
6400
6401pumvisible() *pumvisible()*
6402 Returns non-zero when the popup menu is visible, zero
6403 otherwise. See |ins-completion-menu|.
6404 This can be used to avoid some things that would remove the
6405 popup menu.
6406
6407py3eval({expr}) *py3eval()*
6408 Evaluate Python expression {expr} and return its result
6409 converted to Vim data structures.
6410 Numbers and strings are returned as they are (strings are
6411 copied though, Unicode strings are additionally converted to
6412 'encoding').
6413 Lists are represented as Vim |List| type.
6414 Dictionaries are represented as Vim |Dictionary| type with
6415 keys converted to strings.
6416 Note that in a `:def` function local variables are not visible
6417 to {expr}.
6418
6419 Can also be used as a |method|: >
6420 GetExpr()->py3eval()
6421
6422< {only available when compiled with the |+python3| feature}
6423
6424 *E858* *E859*
6425pyeval({expr}) *pyeval()*
6426 Evaluate Python expression {expr} and return its result
6427 converted to Vim data structures.
6428 Numbers and strings are returned as they are (strings are
6429 copied though).
6430 Lists are represented as Vim |List| type.
6431 Dictionaries are represented as Vim |Dictionary| type,
6432 non-string keys result in error.
6433 Note that in a `:def` function local variables are not visible
6434 to {expr}.
6435
6436 Can also be used as a |method|: >
6437 GetExpr()->pyeval()
6438
6439< {only available when compiled with the |+python| feature}
6440
6441pyxeval({expr}) *pyxeval()*
6442 Evaluate Python expression {expr} and return its result
6443 converted to Vim data structures.
6444 Uses Python 2 or 3, see |python_x| and 'pyxversion'.
6445 See also: |pyeval()|, |py3eval()|
6446
6447 Can also be used as a |method|: >
6448 GetExpr()->pyxeval()
6449
6450< {only available when compiled with the |+python| or the
6451 |+python3| feature}
6452
6453rand([{expr}]) *rand()* *random*
6454 Return a pseudo-random Number generated with an xoshiro128**
6455 algorithm using seed {expr}. The returned number is 32 bits,
6456 also on 64 bits systems, for consistency.
6457 {expr} can be initialized by |srand()| and will be updated by
6458 rand(). If {expr} is omitted, an internal seed value is used
6459 and updated.
6460
6461 Examples: >
6462 :echo rand()
6463 :let seed = srand()
6464 :echo rand(seed)
6465 :echo rand(seed) % 16 " random number 0 - 15
6466<
6467
6468 *E726* *E727*
6469range({expr} [, {max} [, {stride}]]) *range()*
6470 Returns a |List| with Numbers:
6471 - If only {expr} is specified: [0, 1, ..., {expr} - 1]
6472 - If {max} is specified: [{expr}, {expr} + 1, ..., {max}]
6473 - If {stride} is specified: [{expr}, {expr} + {stride}, ...,
6474 {max}] (increasing {expr} with {stride} each time, not
6475 producing a value past {max}).
6476 When the maximum is one before the start the result is an
6477 empty list. When the maximum is more than one before the
6478 start this is an error.
6479 Examples: >
6480 range(4) " [0, 1, 2, 3]
6481 range(2, 4) " [2, 3, 4]
6482 range(2, 9, 3) " [2, 5, 8]
6483 range(2, -2, -1) " [2, 1, 0, -1, -2]
6484 range(0) " []
6485 range(2, 0) " error!
6486<
6487 Can also be used as a |method|: >
6488 GetExpr()->range()
6489<
6490
6491readblob({fname}) *readblob()*
6492 Read file {fname} in binary mode and return a |Blob|.
6493 When the file can't be opened an error message is given and
6494 the result is an empty |Blob|.
6495 Also see |readfile()| and |writefile()|.
6496
6497
6498readdir({directory} [, {expr} [, {dict}]]) *readdir()*
6499 Return a list with file and directory names in {directory}.
6500 You can also use |glob()| if you don't need to do complicated
6501 things, such as limiting the number of matches.
6502 The list will be sorted (case sensitive), see the {dict}
6503 argument below for changing the sort order.
6504
6505 When {expr} is omitted all entries are included.
6506 When {expr} is given, it is evaluated to check what to do:
6507 If {expr} results in -1 then no further entries will
6508 be handled.
6509 If {expr} results in 0 then this entry will not be
6510 added to the list.
6511 If {expr} results in 1 then this entry will be added
6512 to the list.
6513 The entries "." and ".." are always excluded.
6514 Each time {expr} is evaluated |v:val| is set to the entry name.
6515 When {expr} is a function the name is passed as the argument.
6516 For example, to get a list of files ending in ".txt": >
6517 readdir(dirname, {n -> n =~ '.txt$'})
6518< To skip hidden and backup files: >
6519 readdir(dirname, {n -> n !~ '^\.\|\~$'})
Bram Moolenaar6f4754b2022-01-23 12:07:04 +00006520< *E857*
6521 The optional {dict} argument allows for further custom
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006522 values. Currently this is used to specify if and how sorting
6523 should be performed. The dict can have the following members:
6524
6525 sort How to sort the result returned from the system.
6526 Valid values are:
6527 "none" do not sort (fastest method)
6528 "case" sort case sensitive (byte value of
6529 each character, technically, using
6530 strcmp()) (default)
6531 "icase" sort case insensitive (technically
6532 using strcasecmp())
6533 "collate" sort using the collation order
6534 of the "POSIX" or "C" |locale|
6535 (technically using strcoll())
6536 Other values are silently ignored.
6537
6538 For example, to get a list of all files in the current
6539 directory without sorting the individual entries: >
6540 readdir('.', '1', #{sort: 'none'})
6541< If you want to get a directory tree: >
6542 function! s:tree(dir)
6543 return {a:dir : map(readdir(a:dir),
6544 \ {_, x -> isdirectory(x) ?
Bram Moolenaarc51cf032022-02-26 12:25:45 +00006545 \ {x : s:tree(a:dir .. '/' .. x)} : x})}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006546 endfunction
6547 echo s:tree(".")
6548<
6549 Can also be used as a |method|: >
6550 GetDirName()->readdir()
6551<
6552readdirex({directory} [, {expr} [, {dict}]]) *readdirex()*
6553 Extended version of |readdir()|.
6554 Return a list of Dictionaries with file and directory
6555 information in {directory}.
6556 This is useful if you want to get the attributes of file and
6557 directory at the same time as getting a list of a directory.
6558 This is much faster than calling |readdir()| then calling
6559 |getfperm()|, |getfsize()|, |getftime()| and |getftype()| for
6560 each file and directory especially on MS-Windows.
6561 The list will by default be sorted by name (case sensitive),
6562 the sorting can be changed by using the optional {dict}
6563 argument, see |readdir()|.
6564
6565 The Dictionary for file and directory information has the
6566 following items:
6567 group Group name of the entry. (Only on Unix)
6568 name Name of the entry.
6569 perm Permissions of the entry. See |getfperm()|.
6570 size Size of the entry. See |getfsize()|.
6571 time Timestamp of the entry. See |getftime()|.
6572 type Type of the entry.
6573 On Unix, almost same as |getftype()| except:
6574 Symlink to a dir "linkd"
6575 Other symlink "link"
6576 On MS-Windows:
6577 Normal file "file"
6578 Directory "dir"
6579 Junction "junction"
6580 Symlink to a dir "linkd"
6581 Other symlink "link"
6582 Other reparse point "reparse"
6583 user User name of the entry's owner. (Only on Unix)
6584 On Unix, if the entry is a symlink, the Dictionary includes
6585 the information of the target (except the "type" item).
6586 On MS-Windows, it includes the information of the symlink
6587 itself because of performance reasons.
6588
6589 When {expr} is omitted all entries are included.
6590 When {expr} is given, it is evaluated to check what to do:
6591 If {expr} results in -1 then no further entries will
6592 be handled.
6593 If {expr} results in 0 then this entry will not be
6594 added to the list.
6595 If {expr} results in 1 then this entry will be added
6596 to the list.
6597 The entries "." and ".." are always excluded.
6598 Each time {expr} is evaluated |v:val| is set to a |Dictionary|
6599 of the entry.
6600 When {expr} is a function the entry is passed as the argument.
6601 For example, to get a list of files ending in ".txt": >
6602 readdirex(dirname, {e -> e.name =~ '.txt$'})
6603<
6604 For example, to get a list of all files in the current
6605 directory without sorting the individual entries: >
6606 readdirex(dirname, '1', #{sort: 'none'})
6607
6608<
6609 Can also be used as a |method|: >
6610 GetDirName()->readdirex()
6611<
6612
6613 *readfile()*
6614readfile({fname} [, {type} [, {max}]])
6615 Read file {fname} and return a |List|, each line of the file
6616 as an item. Lines are broken at NL characters. Macintosh
6617 files separated with CR will result in a single long line
6618 (unless a NL appears somewhere).
6619 All NUL characters are replaced with a NL character.
6620 When {type} contains "b" binary mode is used:
6621 - When the last line ends in a NL an extra empty list item is
6622 added.
6623 - No CR characters are removed.
6624 Otherwise:
6625 - CR characters that appear before a NL are removed.
6626 - Whether the last line ends in a NL or not does not matter.
6627 - When 'encoding' is Unicode any UTF-8 byte order mark is
6628 removed from the text.
6629 When {max} is given this specifies the maximum number of lines
6630 to be read. Useful if you only want to check the first ten
6631 lines of a file: >
6632 :for line in readfile(fname, '', 10)
6633 : if line =~ 'Date' | echo line | endif
6634 :endfor
6635< When {max} is negative -{max} lines from the end of the file
6636 are returned, or as many as there are.
6637 When {max} is zero the result is an empty list.
6638 Note that without {max} the whole file is read into memory.
6639 Also note that there is no recognition of encoding. Read a
6640 file into a buffer if you need to.
6641 Deprecated (use |readblob()| instead): When {type} contains
6642 "B" a |Blob| is returned with the binary data of the file
6643 unmodified.
6644 When the file can't be opened an error message is given and
6645 the result is an empty list.
6646 Also see |writefile()|.
6647
6648 Can also be used as a |method|: >
6649 GetFileName()->readfile()
6650
6651reduce({object}, {func} [, {initial}]) *reduce()* *E998*
6652 {func} is called for every item in {object}, which can be a
6653 |String|, |List| or a |Blob|. {func} is called with two
6654 arguments: the result so far and current item. After
Bram Moolenaarf10911e2022-01-29 22:20:48 +00006655 processing all items the result is returned. *E1132*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006656
6657 {initial} is the initial result. When omitted, the first item
6658 in {object} is used and {func} is first called for the second
6659 item. If {initial} is not given and {object} is empty no
6660 result can be computed, an E998 error is given.
6661
6662 Examples: >
6663 echo reduce([1, 3, 5], { acc, val -> acc + val })
6664 echo reduce(['x', 'y'], { acc, val -> acc .. val }, 'a')
6665 echo reduce(0z1122, { acc, val -> 2 * acc + val })
6666 echo reduce('xyz', { acc, val -> acc .. ',' .. val })
6667<
6668 Can also be used as a |method|: >
6669 echo mylist->reduce({ acc, val -> acc + val }, 0)
6670
6671
6672reg_executing() *reg_executing()*
6673 Returns the single letter name of the register being executed.
6674 Returns an empty string when no register is being executed.
6675 See |@|.
6676
6677reg_recording() *reg_recording()*
6678 Returns the single letter name of the register being recorded.
6679 Returns an empty string when not recording. See |q|.
6680
6681reltime([{start} [, {end}]]) *reltime()*
6682 Return an item that represents a time value. The item is a
6683 list with items that depend on the system. In Vim 9 script
6684 list<any> can be used.
6685 The item can be passed to |reltimestr()| to convert it to a
6686 string or |reltimefloat()| to convert to a Float.
6687
6688 Without an argument reltime() returns the current time.
6689 With one argument is returns the time passed since the time
6690 specified in the argument.
6691 With two arguments it returns the time passed between {start}
6692 and {end}.
6693
6694 The {start} and {end} arguments must be values returned by
6695 reltime(). If there is an error zero is returned in legacy
6696 script, in Vim9 script an error is given.
6697
6698 Can also be used as a |method|: >
6699 GetStart()->reltime()
6700<
6701 {only available when compiled with the |+reltime| feature}
6702
6703reltimefloat({time}) *reltimefloat()*
6704 Return a Float that represents the time value of {time}.
6705 Example: >
6706 let start = reltime()
6707 call MyFunction()
6708 let seconds = reltimefloat(reltime(start))
6709< See the note of reltimestr() about overhead.
6710 Also see |profiling|.
6711 If there is an error 0.0 is returned in legacy script, in Vim9
6712 script an error is given.
6713
6714 Can also be used as a |method|: >
6715 reltime(start)->reltimefloat()
6716
6717< {only available when compiled with the |+reltime| feature}
6718
6719reltimestr({time}) *reltimestr()*
6720 Return a String that represents the time value of {time}.
6721 This is the number of seconds, a dot and the number of
6722 microseconds. Example: >
6723 let start = reltime()
6724 call MyFunction()
6725 echo reltimestr(reltime(start))
6726< Note that overhead for the commands will be added to the time.
6727 The accuracy depends on the system.
6728 Leading spaces are used to make the string align nicely. You
6729 can use split() to remove it. >
6730 echo split(reltimestr(reltime(start)))[0]
6731< Also see |profiling|.
6732 If there is an error an empty string is returned in legacy
6733 script, in Vim9 script an error is given.
6734
6735 Can also be used as a |method|: >
6736 reltime(start)->reltimestr()
6737
6738< {only available when compiled with the |+reltime| feature}
6739
6740 *remote_expr()* *E449*
6741remote_expr({server}, {string} [, {idvar} [, {timeout}]])
Bram Moolenaar944697a2022-02-20 19:48:20 +00006742 Send the {string} to {server}. The {server} argument is a
6743 string, also see |{server}|.
6744
6745 The string is sent as an expression and the result is returned
6746 after evaluation. The result must be a String or a |List|. A
6747 |List| is turned into a String by joining the items with a
6748 line break in between (not at the end), like with join(expr,
6749 "\n").
6750
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006751 If {idvar} is present and not empty, it is taken as the name
6752 of a variable and a {serverid} for later use with
6753 |remote_read()| is stored there.
Bram Moolenaar944697a2022-02-20 19:48:20 +00006754
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006755 If {timeout} is given the read times out after this many
6756 seconds. Otherwise a timeout of 600 seconds is used.
Bram Moolenaar944697a2022-02-20 19:48:20 +00006757
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006758 See also |clientserver| |RemoteReply|.
6759 This function is not available in the |sandbox|.
6760 {only available when compiled with the |+clientserver| feature}
6761 Note: Any errors will cause a local error message to be issued
6762 and the result will be the empty string.
6763
6764 Variables will be evaluated in the global namespace,
6765 independent of a function currently being active. Except
6766 when in debug mode, then local function variables and
6767 arguments can be evaluated.
6768
6769 Examples: >
6770 :echo remote_expr("gvim", "2+2")
6771 :echo remote_expr("gvim1", "b:current_syntax")
6772<
6773 Can also be used as a |method|: >
6774 ServerName()->remote_expr(expr)
6775
6776remote_foreground({server}) *remote_foreground()*
6777 Move the Vim server with the name {server} to the foreground.
Bram Moolenaar944697a2022-02-20 19:48:20 +00006778 The {server} argument is a string, also see |{server}|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006779 This works like: >
6780 remote_expr({server}, "foreground()")
6781< Except that on Win32 systems the client does the work, to work
6782 around the problem that the OS doesn't always allow the server
6783 to bring itself to the foreground.
6784 Note: This does not restore the window if it was minimized,
6785 like foreground() does.
6786 This function is not available in the |sandbox|.
6787
6788 Can also be used as a |method|: >
6789 ServerName()->remote_foreground()
6790
Bram Moolenaarcbaff5e2022-04-08 17:45:08 +01006791< {only in the Win32, Motif and GTK GUI versions and the
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006792 Win32 console version}
6793
6794
6795remote_peek({serverid} [, {retvar}]) *remote_peek()*
6796 Returns a positive number if there are available strings
6797 from {serverid}. Copies any reply string into the variable
6798 {retvar} if specified. {retvar} must be a string with the
6799 name of a variable.
6800 Returns zero if none are available.
6801 Returns -1 if something is wrong.
6802 See also |clientserver|.
6803 This function is not available in the |sandbox|.
6804 {only available when compiled with the |+clientserver| feature}
6805 Examples: >
6806 :let repl = ""
Bram Moolenaarc51cf032022-02-26 12:25:45 +00006807 :echo "PEEK: " .. remote_peek(id, "repl") .. ": " .. repl
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006808
6809< Can also be used as a |method|: >
6810 ServerId()->remote_peek()
6811
6812remote_read({serverid}, [{timeout}]) *remote_read()*
6813 Return the oldest available reply from {serverid} and consume
6814 it. Unless a {timeout} in seconds is given, it blocks until a
6815 reply is available.
6816 See also |clientserver|.
6817 This function is not available in the |sandbox|.
6818 {only available when compiled with the |+clientserver| feature}
6819 Example: >
6820 :echo remote_read(id)
6821
6822< Can also be used as a |method|: >
6823 ServerId()->remote_read()
6824<
6825 *remote_send()* *E241*
6826remote_send({server}, {string} [, {idvar}])
Bram Moolenaar944697a2022-02-20 19:48:20 +00006827 Send the {string} to {server}. The {server} argument is a
6828 string, also see |{server}|.
6829
6830 The string is sent as input keys and the function returns
6831 immediately. At the Vim server the keys are not mapped
6832 |:map|.
6833
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006834 If {idvar} is present, it is taken as the name of a variable
6835 and a {serverid} for later use with remote_read() is stored
6836 there.
Bram Moolenaar944697a2022-02-20 19:48:20 +00006837
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006838 See also |clientserver| |RemoteReply|.
6839 This function is not available in the |sandbox|.
6840 {only available when compiled with the |+clientserver| feature}
6841
6842 Note: Any errors will be reported in the server and may mess
6843 up the display.
6844 Examples: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00006845 :echo remote_send("gvim", ":DropAndReply " .. file, "serverid") ..
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006846 \ remote_read(serverid)
6847
6848 :autocmd NONE RemoteReply *
6849 \ echo remote_read(expand("<amatch>"))
Bram Moolenaarc51cf032022-02-26 12:25:45 +00006850 :echo remote_send("gvim", ":sleep 10 | echo " ..
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006851 \ 'server2client(expand("<client>"), "HELLO")<CR>')
6852<
6853 Can also be used as a |method|: >
6854 ServerName()->remote_send(keys)
6855<
6856 *remote_startserver()* *E941* *E942*
6857remote_startserver({name})
6858 Become the server {name}. This fails if already running as a
6859 server, when |v:servername| is not empty.
6860
6861 Can also be used as a |method|: >
6862 ServerName()->remote_startserver()
6863
6864< {only available when compiled with the |+clientserver| feature}
6865
6866remove({list}, {idx} [, {end}]) *remove()*
6867 Without {end}: Remove the item at {idx} from |List| {list} and
6868 return the item.
6869 With {end}: Remove items from {idx} to {end} (inclusive) and
6870 return a |List| with these items. When {idx} points to the same
6871 item as {end} a list with one item is returned. When {end}
6872 points to an item before {idx} this is an error.
6873 See |list-index| for possible values of {idx} and {end}.
6874 Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00006875 :echo "last item: " .. remove(mylist, -1)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006876 :call remove(mylist, 0, 9)
6877<
6878 Use |delete()| to remove a file.
6879
6880 Can also be used as a |method|: >
6881 mylist->remove(idx)
6882
6883remove({blob}, {idx} [, {end}])
6884 Without {end}: Remove the byte at {idx} from |Blob| {blob} and
6885 return the byte.
6886 With {end}: Remove bytes from {idx} to {end} (inclusive) and
6887 return a |Blob| with these bytes. When {idx} points to the same
6888 byte as {end} a |Blob| with one byte is returned. When {end}
6889 points to a byte before {idx} this is an error.
6890 Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00006891 :echo "last byte: " .. remove(myblob, -1)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006892 :call remove(mylist, 0, 9)
6893
6894remove({dict}, {key})
6895 Remove the entry from {dict} with key {key} and return it.
6896 Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00006897 :echo "removed " .. remove(dict, "one")
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006898< If there is no {key} in {dict} this is an error.
6899
6900rename({from}, {to}) *rename()*
6901 Rename the file by the name {from} to the name {to}. This
6902 should also work to move files across file systems. The
6903 result is a Number, which is 0 if the file was renamed
6904 successfully, and non-zero when the renaming failed.
6905 NOTE: If {to} exists it is overwritten without warning.
6906 This function is not available in the |sandbox|.
6907
6908 Can also be used as a |method|: >
6909 GetOldName()->rename(newname)
6910
6911repeat({expr}, {count}) *repeat()*
6912 Repeat {expr} {count} times and return the concatenated
6913 result. Example: >
6914 :let separator = repeat('-', 80)
6915< When {count} is zero or negative the result is empty.
6916 When {expr} is a |List| the result is {expr} concatenated
6917 {count} times. Example: >
6918 :let longlist = repeat(['a', 'b'], 3)
6919< Results in ['a', 'b', 'a', 'b', 'a', 'b'].
6920
6921 Can also be used as a |method|: >
6922 mylist->repeat(count)
6923
6924resolve({filename}) *resolve()* *E655*
6925 On MS-Windows, when {filename} is a shortcut (a .lnk file),
6926 returns the path the shortcut points to in a simplified form.
6927 When {filename} is a symbolic link or junction point, return
6928 the full path to the target. If the target of junction is
6929 removed, return {filename}.
6930 On Unix, repeat resolving symbolic links in all path
6931 components of {filename} and return the simplified result.
6932 To cope with link cycles, resolving of symbolic links is
6933 stopped after 100 iterations.
6934 On other systems, return the simplified {filename}.
6935 The simplification step is done as by |simplify()|.
6936 resolve() keeps a leading path component specifying the
6937 current directory (provided the result is still a relative
6938 path name) and also keeps a trailing path separator.
6939
6940 Can also be used as a |method|: >
6941 GetName()->resolve()
6942
6943reverse({object}) *reverse()*
6944 Reverse the order of items in {object} in-place.
6945 {object} can be a |List| or a |Blob|.
6946 Returns {object}.
6947 If you want an object to remain unmodified make a copy first: >
6948 :let revlist = reverse(copy(mylist))
6949< Can also be used as a |method|: >
6950 mylist->reverse()
6951
6952round({expr}) *round()*
6953 Round off {expr} to the nearest integral value and return it
6954 as a |Float|. If {expr} lies halfway between two integral
6955 values, then use the larger one (away from zero).
6956 {expr} must evaluate to a |Float| or a |Number|.
6957 Examples: >
6958 echo round(0.456)
6959< 0.0 >
6960 echo round(4.5)
6961< 5.0 >
6962 echo round(-4.5)
6963< -5.0
6964
6965 Can also be used as a |method|: >
6966 Compute()->round()
6967<
6968 {only available when compiled with the |+float| feature}
6969
6970rubyeval({expr}) *rubyeval()*
6971 Evaluate Ruby expression {expr} and return its result
6972 converted to Vim data structures.
6973 Numbers, floats and strings are returned as they are (strings
6974 are copied though).
6975 Arrays are represented as Vim |List| type.
6976 Hashes are represented as Vim |Dictionary| type.
6977 Other objects are represented as strings resulted from their
6978 "Object#to_s" method.
6979 Note that in a `:def` function local variables are not visible
6980 to {expr}.
6981
6982 Can also be used as a |method|: >
6983 GetRubyExpr()->rubyeval()
6984
6985< {only available when compiled with the |+ruby| feature}
6986
6987screenattr({row}, {col}) *screenattr()*
6988 Like |screenchar()|, but return the attribute. This is a rather
6989 arbitrary number that can only be used to compare to the
6990 attribute at other positions.
6991
6992 Can also be used as a |method|: >
6993 GetRow()->screenattr(col)
6994
6995screenchar({row}, {col}) *screenchar()*
6996 The result is a Number, which is the character at position
6997 [row, col] on the screen. This works for every possible
6998 screen position, also status lines, window separators and the
6999 command line. The top left position is row one, column one
7000 The character excludes composing characters. For double-byte
7001 encodings it may only be the first byte.
7002 This is mainly to be used for testing.
7003 Returns -1 when row or col is out of range.
7004
7005 Can also be used as a |method|: >
7006 GetRow()->screenchar(col)
7007
7008screenchars({row}, {col}) *screenchars()*
7009 The result is a |List| of Numbers. The first number is the same
7010 as what |screenchar()| returns. Further numbers are
7011 composing characters on top of the base character.
7012 This is mainly to be used for testing.
7013 Returns an empty List when row or col is out of range.
7014
7015 Can also be used as a |method|: >
7016 GetRow()->screenchars(col)
7017
7018screencol() *screencol()*
7019 The result is a Number, which is the current screen column of
7020 the cursor. The leftmost column has number 1.
7021 This function is mainly used for testing.
7022
7023 Note: Always returns the current screen column, thus if used
7024 in a command (e.g. ":echo screencol()") it will return the
7025 column inside the command line, which is 1 when the command is
7026 executed. To get the cursor position in the file use one of
7027 the following mappings: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00007028 nnoremap <expr> GG ":echom " .. screencol() .. "\n"
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007029 nnoremap <silent> GG :echom screencol()<CR>
7030 nnoremap GG <Cmd>echom screencol()<CR>
7031<
7032screenpos({winid}, {lnum}, {col}) *screenpos()*
7033 The result is a Dict with the screen position of the text
7034 character in window {winid} at buffer line {lnum} and column
7035 {col}. {col} is a one-based byte index.
7036 The Dict has these members:
7037 row screen row
7038 col first screen column
7039 endcol last screen column
7040 curscol cursor screen column
7041 If the specified position is not visible, all values are zero.
7042 The "endcol" value differs from "col" when the character
7043 occupies more than one screen cell. E.g. for a Tab "col" can
7044 be 1 and "endcol" can be 8.
7045 The "curscol" value is where the cursor would be placed. For
7046 a Tab it would be the same as "endcol", while for a double
7047 width character it would be the same as "col".
7048 The |conceal| feature is ignored here, the column numbers are
7049 as if 'conceallevel' is zero. You can set the cursor to the
7050 right position and use |screencol()| to get the value with
7051 |conceal| taken into account.
Bram Moolenaar944697a2022-02-20 19:48:20 +00007052 If the position is in a closed fold the screen position of the
7053 first character is returned, {col} is not used.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007054
7055 Can also be used as a |method|: >
7056 GetWinid()->screenpos(lnum, col)
7057
7058screenrow() *screenrow()*
7059 The result is a Number, which is the current screen row of the
7060 cursor. The top line has number one.
7061 This function is mainly used for testing.
7062 Alternatively you can use |winline()|.
7063
7064 Note: Same restrictions as with |screencol()|.
7065
7066screenstring({row}, {col}) *screenstring()*
7067 The result is a String that contains the base character and
7068 any composing characters at position [row, col] on the screen.
7069 This is like |screenchars()| but returning a String with the
7070 characters.
7071 This is mainly to be used for testing.
7072 Returns an empty String when row or col is out of range.
7073
7074 Can also be used as a |method|: >
7075 GetRow()->screenstring(col)
7076<
7077 *search()*
7078search({pattern} [, {flags} [, {stopline} [, {timeout} [, {skip}]]]])
7079 Search for regexp pattern {pattern}. The search starts at the
7080 cursor position (you can use |cursor()| to set it).
7081
7082 When a match has been found its line number is returned.
7083 If there is no match a 0 is returned and the cursor doesn't
7084 move. No error message is given.
7085
7086 {flags} is a String, which can contain these character flags:
7087 'b' search Backward instead of forward
7088 'c' accept a match at the Cursor position
7089 'e' move to the End of the match
7090 'n' do Not move the cursor
7091 'p' return number of matching sub-Pattern (see below)
7092 's' Set the ' mark at the previous location of the cursor
7093 'w' Wrap around the end of the file
7094 'W' don't Wrap around the end of the file
7095 'z' start searching at the cursor column instead of zero
7096 If neither 'w' or 'W' is given, the 'wrapscan' option applies.
7097
7098 If the 's' flag is supplied, the ' mark is set, only if the
7099 cursor is moved. The 's' flag cannot be combined with the 'n'
7100 flag.
7101
7102 'ignorecase', 'smartcase' and 'magic' are used.
7103
7104 When the 'z' flag is not given, forward searching always
7105 starts in column zero and then matches before the cursor are
7106 skipped. When the 'c' flag is present in 'cpo' the next
7107 search starts after the match. Without the 'c' flag the next
7108 search starts one column further. This matters for
7109 overlapping matches.
7110 When searching backwards and the 'z' flag is given then the
7111 search starts in column zero, thus no match in the current
7112 line will be found (unless wrapping around the end of the
7113 file).
7114
7115 When the {stopline} argument is given then the search stops
7116 after searching this line. This is useful to restrict the
7117 search to a range of lines. Examples: >
7118 let match = search('(', 'b', line("w0"))
7119 let end = search('END', '', line("w$"))
7120< When {stopline} is used and it is not zero this also implies
7121 that the search does not wrap around the end of the file.
7122 A zero value is equal to not giving the argument.
7123
7124 When the {timeout} argument is given the search stops when
7125 more than this many milliseconds have passed. Thus when
7126 {timeout} is 500 the search stops after half a second.
7127 The value must not be negative. A zero value is like not
7128 giving the argument.
7129 {only available when compiled with the |+reltime| feature}
7130
7131 If the {skip} expression is given it is evaluated with the
7132 cursor positioned on the start of a match. If it evaluates to
7133 non-zero this match is skipped. This can be used, for
7134 example, to skip a match in a comment or a string.
7135 {skip} can be a string, which is evaluated as an expression, a
7136 function reference or a lambda.
7137 When {skip} is omitted or empty, every match is accepted.
7138 When evaluating {skip} causes an error the search is aborted
7139 and -1 returned.
7140 *search()-sub-match*
7141 With the 'p' flag the returned value is one more than the
7142 first sub-match in \(\). One if none of them matched but the
7143 whole pattern did match.
7144 To get the column number too use |searchpos()|.
7145
7146 The cursor will be positioned at the match, unless the 'n'
7147 flag is used.
7148
7149 Example (goes over all files in the argument list): >
7150 :let n = 1
7151 :while n <= argc() " loop over all files in arglist
Bram Moolenaarc51cf032022-02-26 12:25:45 +00007152 : exe "argument " .. n
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007153 : " start at the last char in the file and wrap for the
7154 : " first search to find match at start of file
7155 : normal G$
7156 : let flags = "w"
7157 : while search("foo", flags) > 0
7158 : s/foo/bar/g
7159 : let flags = "W"
7160 : endwhile
7161 : update " write the file if modified
7162 : let n = n + 1
7163 :endwhile
7164<
7165 Example for using some flags: >
7166 :echo search('\<if\|\(else\)\|\(endif\)', 'ncpe')
7167< This will search for the keywords "if", "else", and "endif"
7168 under or after the cursor. Because of the 'p' flag, it
7169 returns 1, 2, or 3 depending on which keyword is found, or 0
7170 if the search fails. With the cursor on the first word of the
7171 line:
7172 if (foo == 0) | let foo = foo + 1 | endif ~
7173 the function returns 1. Without the 'c' flag, the function
7174 finds the "endif" and returns 3. The same thing happens
7175 without the 'e' flag if the cursor is on the "f" of "if".
7176 The 'n' flag tells the function not to move the cursor.
7177
7178 Can also be used as a |method|: >
7179 GetPattern()->search()
7180
7181searchcount([{options}]) *searchcount()*
7182 Get or update the last search count, like what is displayed
7183 without the "S" flag in 'shortmess'. This works even if
7184 'shortmess' does contain the "S" flag.
7185
7186 This returns a |Dictionary|. The dictionary is empty if the
7187 previous pattern was not set and "pattern" was not specified.
7188
7189 key type meaning ~
7190 current |Number| current position of match;
7191 0 if the cursor position is
7192 before the first match
7193 exact_match |Boolean| 1 if "current" is matched on
7194 "pos", otherwise 0
7195 total |Number| total count of matches found
7196 incomplete |Number| 0: search was fully completed
7197 1: recomputing was timed out
7198 2: max count exceeded
7199
7200 For {options} see further down.
7201
7202 To get the last search count when |n| or |N| was pressed, call
7203 this function with `recompute: 0` . This sometimes returns
7204 wrong information because |n| and |N|'s maximum count is 99.
7205 If it exceeded 99 the result must be max count + 1 (100). If
7206 you want to get correct information, specify `recompute: 1`: >
7207
7208 " result == maxcount + 1 (100) when many matches
7209 let result = searchcount(#{recompute: 0})
7210
7211 " Below returns correct result (recompute defaults
7212 " to 1)
7213 let result = searchcount()
7214<
7215 The function is useful to add the count to |statusline|: >
7216 function! LastSearchCount() abort
7217 let result = searchcount(#{recompute: 0})
7218 if empty(result)
7219 return ''
7220 endif
7221 if result.incomplete ==# 1 " timed out
7222 return printf(' /%s [?/??]', @/)
7223 elseif result.incomplete ==# 2 " max count exceeded
7224 if result.total > result.maxcount &&
7225 \ result.current > result.maxcount
7226 return printf(' /%s [>%d/>%d]', @/,
7227 \ result.current, result.total)
7228 elseif result.total > result.maxcount
7229 return printf(' /%s [%d/>%d]', @/,
7230 \ result.current, result.total)
7231 endif
7232 endif
7233 return printf(' /%s [%d/%d]', @/,
7234 \ result.current, result.total)
7235 endfunction
Bram Moolenaarc51cf032022-02-26 12:25:45 +00007236 let &statusline ..= '%{LastSearchCount()}'
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007237
7238 " Or if you want to show the count only when
7239 " 'hlsearch' was on
Bram Moolenaarc51cf032022-02-26 12:25:45 +00007240 " let &statusline ..=
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007241 " \ '%{v:hlsearch ? LastSearchCount() : ""}'
7242<
7243 You can also update the search count, which can be useful in a
7244 |CursorMoved| or |CursorMovedI| autocommand: >
7245
7246 autocmd CursorMoved,CursorMovedI *
7247 \ let s:searchcount_timer = timer_start(
7248 \ 200, function('s:update_searchcount'))
7249 function! s:update_searchcount(timer) abort
7250 if a:timer ==# s:searchcount_timer
7251 call searchcount(#{
7252 \ recompute: 1, maxcount: 0, timeout: 100})
7253 redrawstatus
7254 endif
7255 endfunction
7256<
7257 This can also be used to count matched texts with specified
7258 pattern in the current buffer using "pattern": >
7259
7260 " Count '\<foo\>' in this buffer
7261 " (Note that it also updates search count)
7262 let result = searchcount(#{pattern: '\<foo\>'})
7263
7264 " To restore old search count by old pattern,
7265 " search again
7266 call searchcount()
7267<
7268 {options} must be a |Dictionary|. It can contain:
7269 key type meaning ~
7270 recompute |Boolean| if |TRUE|, recompute the count
7271 like |n| or |N| was executed.
7272 otherwise returns the last
7273 computed result (when |n| or
7274 |N| was used when "S" is not
7275 in 'shortmess', or this
7276 function was called).
7277 (default: |TRUE|)
7278 pattern |String| recompute if this was given
7279 and different with |@/|.
7280 this works as same as the
7281 below command is executed
7282 before calling this function >
7283 let @/ = pattern
7284< (default: |@/|)
7285 timeout |Number| 0 or negative number is no
7286 timeout. timeout milliseconds
7287 for recomputing the result
7288 (default: 0)
7289 maxcount |Number| 0 or negative number is no
7290 limit. max count of matched
7291 text while recomputing the
7292 result. if search exceeded
7293 total count, "total" value
7294 becomes `maxcount + 1`
7295 (default: 99)
7296 pos |List| `[lnum, col, off]` value
7297 when recomputing the result.
7298 this changes "current" result
7299 value. see |cursor()|,
7300 |getpos()|
7301 (default: cursor's position)
7302
7303 Can also be used as a |method|: >
7304 GetSearchOpts()->searchcount()
7305<
7306searchdecl({name} [, {global} [, {thisblock}]]) *searchdecl()*
7307 Search for the declaration of {name}.
7308
7309 With a non-zero {global} argument it works like |gD|, find
7310 first match in the file. Otherwise it works like |gd|, find
7311 first match in the function.
7312
7313 With a non-zero {thisblock} argument matches in a {} block
7314 that ends before the cursor position are ignored. Avoids
7315 finding variable declarations only valid in another scope.
7316
7317 Moves the cursor to the found match.
7318 Returns zero for success, non-zero for failure.
7319 Example: >
7320 if searchdecl('myvar') == 0
7321 echo getline('.')
7322 endif
7323<
7324 Can also be used as a |method|: >
7325 GetName()->searchdecl()
7326<
7327 *searchpair()*
7328searchpair({start}, {middle}, {end} [, {flags} [, {skip}
7329 [, {stopline} [, {timeout}]]]])
7330 Search for the match of a nested start-end pair. This can be
7331 used to find the "endif" that matches an "if", while other
7332 if/endif pairs in between are ignored.
7333 The search starts at the cursor. The default is to search
7334 forward, include 'b' in {flags} to search backward.
7335 If a match is found, the cursor is positioned at it and the
7336 line number is returned. If no match is found 0 or -1 is
7337 returned and the cursor doesn't move. No error message is
7338 given.
7339
7340 {start}, {middle} and {end} are patterns, see |pattern|. They
7341 must not contain \( \) pairs. Use of \%( \) is allowed. When
7342 {middle} is not empty, it is found when searching from either
7343 direction, but only when not in a nested start-end pair. A
7344 typical use is: >
7345 searchpair('\<if\>', '\<else\>', '\<endif\>')
7346< By leaving {middle} empty the "else" is skipped.
7347
7348 {flags} 'b', 'c', 'n', 's', 'w' and 'W' are used like with
7349 |search()|. Additionally:
7350 'r' Repeat until no more matches found; will find the
7351 outer pair. Implies the 'W' flag.
7352 'm' Return number of matches instead of line number with
7353 the match; will be > 1 when 'r' is used.
7354 Note: it's nearly always a good idea to use the 'W' flag, to
7355 avoid wrapping around the end of the file.
7356
7357 When a match for {start}, {middle} or {end} is found, the
7358 {skip} expression is evaluated with the cursor positioned on
7359 the start of the match. It should return non-zero if this
7360 match is to be skipped. E.g., because it is inside a comment
7361 or a string.
7362 When {skip} is omitted or empty, every match is accepted.
7363 When evaluating {skip} causes an error the search is aborted
7364 and -1 returned.
7365 {skip} can be a string, a lambda, a funcref or a partial.
7366 Anything else makes the function fail.
7367 In a `:def` function when the {skip} argument is a string
7368 constant it is compiled into instructions.
7369
7370 For {stopline} and {timeout} see |search()|.
7371
7372 The value of 'ignorecase' is used. 'magic' is ignored, the
7373 patterns are used like it's on.
7374
7375 The search starts exactly at the cursor. A match with
7376 {start}, {middle} or {end} at the next character, in the
7377 direction of searching, is the first one found. Example: >
7378 if 1
7379 if 2
7380 endif 2
7381 endif 1
7382< When starting at the "if 2", with the cursor on the "i", and
7383 searching forwards, the "endif 2" is found. When starting on
7384 the character just before the "if 2", the "endif 1" will be
7385 found. That's because the "if 2" will be found first, and
7386 then this is considered to be a nested if/endif from "if 2" to
7387 "endif 2".
7388 When searching backwards and {end} is more than one character,
7389 it may be useful to put "\zs" at the end of the pattern, so
7390 that when the cursor is inside a match with the end it finds
7391 the matching start.
7392
7393 Example, to find the "endif" command in a Vim script: >
7394
7395 :echo searchpair('\<if\>', '\<el\%[seif]\>', '\<en\%[dif]\>', 'W',
7396 \ 'getline(".") =~ "^\\s*\""')
7397
7398< The cursor must be at or after the "if" for which a match is
7399 to be found. Note that single-quote strings are used to avoid
7400 having to double the backslashes. The skip expression only
7401 catches comments at the start of a line, not after a command.
7402 Also, a word "en" or "if" halfway a line is considered a
7403 match.
7404 Another example, to search for the matching "{" of a "}": >
7405
7406 :echo searchpair('{', '', '}', 'bW')
7407
7408< This works when the cursor is at or before the "}" for which a
7409 match is to be found. To reject matches that syntax
7410 highlighting recognized as strings: >
7411
7412 :echo searchpair('{', '', '}', 'bW',
7413 \ 'synIDattr(synID(line("."), col("."), 0), "name") =~? "string"')
7414<
7415 *searchpairpos()*
7416searchpairpos({start}, {middle}, {end} [, {flags} [, {skip}
7417 [, {stopline} [, {timeout}]]]])
7418 Same as |searchpair()|, but returns a |List| with the line and
7419 column position of the match. The first element of the |List|
7420 is the line number and the second element is the byte index of
7421 the column position of the match. If no match is found,
7422 returns [0, 0]. >
7423
7424 :let [lnum,col] = searchpairpos('{', '', '}', 'n')
7425<
7426 See |match-parens| for a bigger and more useful example.
7427
7428 *searchpos()*
7429searchpos({pattern} [, {flags} [, {stopline} [, {timeout} [, {skip}]]]])
7430 Same as |search()|, but returns a |List| with the line and
7431 column position of the match. The first element of the |List|
7432 is the line number and the second element is the byte index of
7433 the column position of the match. If no match is found,
7434 returns [0, 0].
7435 Example: >
7436 :let [lnum, col] = searchpos('mypattern', 'n')
7437
7438< When the 'p' flag is given then there is an extra item with
7439 the sub-pattern match number |search()-sub-match|. Example: >
7440 :let [lnum, col, submatch] = searchpos('\(\l\)\|\(\u\)', 'np')
7441< In this example "submatch" is 2 when a lowercase letter is
7442 found |/\l|, 3 when an uppercase letter is found |/\u|.
7443
7444 Can also be used as a |method|: >
7445 GetPattern()->searchpos()
7446
7447server2client({clientid}, {string}) *server2client()*
7448 Send a reply string to {clientid}. The most recent {clientid}
7449 that sent a string can be retrieved with expand("<client>").
7450 {only available when compiled with the |+clientserver| feature}
7451 Returns zero for success, -1 for failure.
7452 Note:
7453 This id has to be stored before the next command can be
7454 received. I.e. before returning from the received command and
7455 before calling any commands that waits for input.
7456 See also |clientserver|.
7457 Example: >
7458 :echo server2client(expand("<client>"), "HELLO")
7459
7460< Can also be used as a |method|: >
7461 GetClientId()->server2client(string)
7462<
7463serverlist() *serverlist()*
7464 Return a list of available server names, one per line.
7465 When there are no servers or the information is not available
7466 an empty string is returned. See also |clientserver|.
7467 {only available when compiled with the |+clientserver| feature}
7468 Example: >
7469 :echo serverlist()
7470<
7471setbufline({buf}, {lnum}, {text}) *setbufline()*
7472 Set line {lnum} to {text} in buffer {buf}. This works like
7473 |setline()| for the specified buffer.
7474
7475 This function works only for loaded buffers. First call
7476 |bufload()| if needed.
7477
7478 To insert lines use |appendbufline()|.
7479 Any text properties in {lnum} are cleared.
7480
7481 {text} can be a string to set one line, or a list of strings
7482 to set multiple lines. If the list extends below the last
7483 line then those lines are added.
7484
7485 For the use of {buf}, see |bufname()| above.
7486
7487 {lnum} is used like with |setline()|.
7488 Use "$" to refer to the last line in buffer {buf}.
7489 When {lnum} is just below the last line the {text} will be
7490 added below the last line.
7491
7492 When {buf} is not a valid buffer, the buffer is not loaded or
7493 {lnum} is not valid then 1 is returned. In |Vim9| script an
7494 error is given.
7495 On success 0 is returned.
7496
7497 Can also be used as a |method|, the base is passed as the
7498 third argument: >
7499 GetText()->setbufline(buf, lnum)
7500
7501setbufvar({buf}, {varname}, {val}) *setbufvar()*
7502 Set option or local variable {varname} in buffer {buf} to
7503 {val}.
7504 This also works for a global or local window option, but it
7505 doesn't work for a global or local window variable.
7506 For a local window option the global value is unchanged.
7507 For the use of {buf}, see |bufname()| above.
7508 The {varname} argument is a string.
7509 Note that the variable name without "b:" must be used.
7510 Examples: >
7511 :call setbufvar(1, "&mod", 1)
7512 :call setbufvar("todo", "myvar", "foobar")
7513< This function is not available in the |sandbox|.
7514
7515 Can also be used as a |method|, the base is passed as the
7516 third argument: >
7517 GetValue()->setbufvar(buf, varname)
7518
7519
7520setcellwidths({list}) *setcellwidths()*
7521 Specify overrides for cell widths of character ranges. This
7522 tells Vim how wide characters are, counted in screen cells.
7523 This overrides 'ambiwidth'. Example: >
7524 setcellwidths([[0xad, 0xad, 1],
7525 \ [0x2194, 0x2199, 2]])
7526
Bram Moolenaarf10911e2022-01-29 22:20:48 +00007527< *E1109* *E1110* *E1111* *E1112* *E1113* *E1114*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007528 The {list} argument is a list of lists with each three
7529 numbers. These three numbers are [low, high, width]. "low"
7530 and "high" can be the same, in which case this refers to one
7531 character. Otherwise it is the range of characters from "low"
7532 to "high" (inclusive). "width" is either 1 or 2, indicating
7533 the character width in screen cells.
7534 An error is given if the argument is invalid, also when a
7535 range overlaps with another.
7536 Only characters with value 0x100 and higher can be used.
7537
7538 If the new value causes 'fillchars' or 'listchars' to become
7539 invalid it is rejected and an error is given.
7540
7541 To clear the overrides pass an empty list: >
7542 setcellwidths([]);
7543< You can use the script $VIMRUNTIME/tools/emoji_list.vim to see
7544 the effect for known emoji characters.
7545
7546setcharpos({expr}, {list}) *setcharpos()*
7547 Same as |setpos()| but uses the specified column number as the
7548 character index instead of the byte index in the line.
7549
7550 Example:
7551 With the text "여보세요" in line 8: >
7552 call setcharpos('.', [0, 8, 4, 0])
7553< positions the cursor on the fourth character '요'. >
7554 call setpos('.', [0, 8, 4, 0])
7555< positions the cursor on the second character '보'.
7556
7557 Can also be used as a |method|: >
7558 GetPosition()->setcharpos('.')
7559
7560setcharsearch({dict}) *setcharsearch()*
7561 Set the current character search information to {dict},
7562 which contains one or more of the following entries:
7563
7564 char character which will be used for a subsequent
7565 |,| or |;| command; an empty string clears the
7566 character search
7567 forward direction of character search; 1 for forward,
7568 0 for backward
7569 until type of character search; 1 for a |t| or |T|
7570 character search, 0 for an |f| or |F|
7571 character search
7572
7573 This can be useful to save/restore a user's character search
7574 from a script: >
7575 :let prevsearch = getcharsearch()
7576 :" Perform a command which clobbers user's search
7577 :call setcharsearch(prevsearch)
7578< Also see |getcharsearch()|.
7579
7580 Can also be used as a |method|: >
7581 SavedSearch()->setcharsearch()
7582
7583setcmdpos({pos}) *setcmdpos()*
7584 Set the cursor position in the command line to byte position
7585 {pos}. The first position is 1.
7586 Use |getcmdpos()| to obtain the current position.
7587 Only works while editing the command line, thus you must use
7588 |c_CTRL-\_e|, |c_CTRL-R_=| or |c_CTRL-R_CTRL-R| with '='. For
7589 |c_CTRL-\_e| and |c_CTRL-R_CTRL-R| with '=' the position is
7590 set after the command line is set to the expression. For
7591 |c_CTRL-R_=| it is set after evaluating the expression but
7592 before inserting the resulting text.
7593 When the number is too big the cursor is put at the end of the
7594 line. A number smaller than one has undefined results.
7595 Returns FALSE when successful, TRUE when not editing the
7596 command line.
7597
7598 Can also be used as a |method|: >
7599 GetPos()->setcmdpos()
7600
7601setcursorcharpos({lnum}, {col} [, {off}]) *setcursorcharpos()*
7602setcursorcharpos({list})
7603 Same as |cursor()| but uses the specified column number as the
7604 character index instead of the byte index in the line.
7605
7606 Example:
7607 With the text "여보세요" in line 4: >
7608 call setcursorcharpos(4, 3)
7609< positions the cursor on the third character '세'. >
7610 call cursor(4, 3)
7611< positions the cursor on the first character '여'.
7612
7613 Can also be used as a |method|: >
7614 GetCursorPos()->setcursorcharpos()
7615
7616
7617setenv({name}, {val}) *setenv()*
7618 Set environment variable {name} to {val}. Example: >
7619 call setenv('HOME', '/home/myhome')
7620
7621< When {val} is |v:null| the environment variable is deleted.
7622 See also |expr-env|.
7623
7624 Can also be used as a |method|, the base is passed as the
7625 second argument: >
7626 GetPath()->setenv('PATH')
7627
7628setfperm({fname}, {mode}) *setfperm()* *chmod*
7629 Set the file permissions for {fname} to {mode}.
7630 {mode} must be a string with 9 characters. It is of the form
7631 "rwxrwxrwx", where each group of "rwx" flags represent, in
7632 turn, the permissions of the owner of the file, the group the
7633 file belongs to, and other users. A '-' character means the
7634 permission is off, any other character means on. Multi-byte
7635 characters are not supported.
7636
7637 For example "rw-r-----" means read-write for the user,
7638 readable by the group, not accessible by others. "xx-x-----"
7639 would do the same thing.
7640
7641 Returns non-zero for success, zero for failure.
7642
7643 Can also be used as a |method|: >
7644 GetFilename()->setfperm(mode)
7645<
7646 To read permissions see |getfperm()|.
7647
7648
7649setline({lnum}, {text}) *setline()*
7650 Set line {lnum} of the current buffer to {text}. To insert
7651 lines use |append()|. To set lines in another buffer use
7652 |setbufline()|. Any text properties in {lnum} are cleared.
7653
7654 {lnum} is used like with |getline()|.
7655 When {lnum} is just below the last line the {text} will be
7656 added below the last line.
7657 {text} can be any type or a List of any type, each item is
7658 converted to a String.
7659
7660 If this succeeds, FALSE is returned. If this fails (most likely
7661 because {lnum} is invalid) TRUE is returned.
7662 In |Vim9| script an error is given if {lnum} is invalid.
7663
7664 Example: >
7665 :call setline(5, strftime("%c"))
7666
7667< When {text} is a |List| then line {lnum} and following lines
7668 will be set to the items in the list. Example: >
7669 :call setline(5, ['aaa', 'bbb', 'ccc'])
7670< This is equivalent to: >
7671 :for [n, l] in [[5, 'aaa'], [6, 'bbb'], [7, 'ccc']]
7672 : call setline(n, l)
7673 :endfor
7674
7675< Note: The '[ and '] marks are not set.
7676
7677 Can also be used as a |method|, the base is passed as the
7678 second argument: >
7679 GetText()->setline(lnum)
7680
7681setloclist({nr}, {list} [, {action} [, {what}]]) *setloclist()*
7682 Create or replace or add to the location list for window {nr}.
7683 {nr} can be the window number or the |window-ID|.
7684 When {nr} is zero the current window is used.
7685
7686 For a location list window, the displayed location list is
7687 modified. For an invalid window number {nr}, -1 is returned.
7688 Otherwise, same as |setqflist()|.
7689 Also see |location-list|.
7690
7691 For {action} see |setqflist-action|.
7692
7693 If the optional {what} dictionary argument is supplied, then
7694 only the items listed in {what} are set. Refer to |setqflist()|
7695 for the list of supported keys in {what}.
7696
7697 Can also be used as a |method|, the base is passed as the
7698 second argument: >
7699 GetLoclist()->setloclist(winnr)
7700
7701setmatches({list} [, {win}]) *setmatches()*
7702 Restores a list of matches saved by |getmatches()| for the
7703 current window. Returns 0 if successful, otherwise -1. All
7704 current matches are cleared before the list is restored. See
7705 example for |getmatches()|.
7706 If {win} is specified, use the window with this number or
7707 window ID instead of the current window.
7708
7709 Can also be used as a |method|: >
7710 GetMatches()->setmatches()
7711<
7712 *setpos()*
7713setpos({expr}, {list})
7714 Set the position for String {expr}. Possible values:
7715 . the cursor
7716 'x mark x
7717
7718 {list} must be a |List| with four or five numbers:
7719 [bufnum, lnum, col, off]
7720 [bufnum, lnum, col, off, curswant]
7721
7722 "bufnum" is the buffer number. Zero can be used for the
7723 current buffer. When setting an uppercase mark "bufnum" is
7724 used for the mark position. For other marks it specifies the
7725 buffer to set the mark in. You can use the |bufnr()| function
7726 to turn a file name into a buffer number.
7727 For setting the cursor and the ' mark "bufnum" is ignored,
7728 since these are associated with a window, not a buffer.
7729 Does not change the jumplist.
7730
7731 "lnum" and "col" are the position in the buffer. The first
7732 column is 1. Use a zero "lnum" to delete a mark. If "col" is
7733 smaller than 1 then 1 is used. To use the character count
7734 instead of the byte count, use |setcharpos()|.
7735
7736 The "off" number is only used when 'virtualedit' is set. Then
7737 it is the offset in screen columns from the start of the
7738 character. E.g., a position within a <Tab> or after the last
7739 character.
7740
7741 The "curswant" number is only used when setting the cursor
7742 position. It sets the preferred column for when moving the
7743 cursor vertically. When the "curswant" number is missing the
7744 preferred column is not set. When it is present and setting a
7745 mark position it is not used.
7746
7747 Note that for '< and '> changing the line number may result in
7748 the marks to be effectively be swapped, so that '< is always
7749 before '>.
7750
7751 Returns 0 when the position could be set, -1 otherwise.
7752 An error message is given if {expr} is invalid.
7753
7754 Also see |setcharpos()|, |getpos()| and |getcurpos()|.
7755
7756 This does not restore the preferred column for moving
7757 vertically; if you set the cursor position with this, |j| and
7758 |k| motions will jump to previous columns! Use |cursor()| to
7759 also set the preferred column. Also see the "curswant" key in
7760 |winrestview()|.
7761
7762 Can also be used as a |method|: >
7763 GetPosition()->setpos('.')
7764
7765setqflist({list} [, {action} [, {what}]]) *setqflist()*
7766 Create or replace or add to the quickfix list.
7767
7768 If the optional {what} dictionary argument is supplied, then
7769 only the items listed in {what} are set. The first {list}
7770 argument is ignored. See below for the supported items in
7771 {what}.
7772 *setqflist-what*
7773 When {what} is not present, the items in {list} are used. Each
7774 item must be a dictionary. Non-dictionary items in {list} are
7775 ignored. Each dictionary item can contain the following
7776 entries:
7777
7778 bufnr buffer number; must be the number of a valid
7779 buffer
7780 filename name of a file; only used when "bufnr" is not
7781 present or it is invalid.
7782 module name of a module; if given it will be used in
7783 quickfix error window instead of the filename.
7784 lnum line number in the file
Bram Moolenaara2baa732022-02-04 16:09:54 +00007785 end_lnum end of lines, if the item spans multiple lines
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007786 pattern search pattern used to locate the error
7787 col column number
7788 vcol when non-zero: "col" is visual column
7789 when zero: "col" is byte index
Bram Moolenaara2baa732022-02-04 16:09:54 +00007790 end_col end column, if the item spans multiple columns
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007791 nr error number
7792 text description of the error
7793 type single-character error type, 'E', 'W', etc.
7794 valid recognized error message
7795
7796 The "col", "vcol", "nr", "type" and "text" entries are
7797 optional. Either "lnum" or "pattern" entry can be used to
7798 locate a matching error line.
7799 If the "filename" and "bufnr" entries are not present or
7800 neither the "lnum" or "pattern" entries are present, then the
7801 item will not be handled as an error line.
7802 If both "pattern" and "lnum" are present then "pattern" will
7803 be used.
7804 If the "valid" entry is not supplied, then the valid flag is
7805 set when "bufnr" is a valid buffer or "filename" exists.
7806 If you supply an empty {list}, the quickfix list will be
7807 cleared.
7808 Note that the list is not exactly the same as what
7809 |getqflist()| returns.
7810
7811 {action} values: *setqflist-action* *E927*
7812 'a' The items from {list} are added to the existing
7813 quickfix list. If there is no existing list, then a
7814 new list is created.
7815
7816 'r' The items from the current quickfix list are replaced
7817 with the items from {list}. This can also be used to
7818 clear the list: >
7819 :call setqflist([], 'r')
7820<
7821 'f' All the quickfix lists in the quickfix stack are
7822 freed.
7823
7824 If {action} is not present or is set to ' ', then a new list
7825 is created. The new quickfix list is added after the current
7826 quickfix list in the stack and all the following lists are
7827 freed. To add a new quickfix list at the end of the stack,
7828 set "nr" in {what} to "$".
7829
7830 The following items can be specified in dictionary {what}:
7831 context quickfix list context. See |quickfix-context|
7832 efm errorformat to use when parsing text from
7833 "lines". If this is not present, then the
7834 'errorformat' option value is used.
7835 See |quickfix-parse|
7836 id quickfix list identifier |quickfix-ID|
7837 idx index of the current entry in the quickfix
7838 list specified by 'id' or 'nr'. If set to '$',
7839 then the last entry in the list is set as the
7840 current entry. See |quickfix-index|
7841 items list of quickfix entries. Same as the {list}
7842 argument.
7843 lines use 'errorformat' to parse a list of lines and
7844 add the resulting entries to the quickfix list
7845 {nr} or {id}. Only a |List| value is supported.
7846 See |quickfix-parse|
7847 nr list number in the quickfix stack; zero
7848 means the current quickfix list and "$" means
7849 the last quickfix list.
7850 quickfixtextfunc
7851 function to get the text to display in the
7852 quickfix window. The value can be the name of
7853 a function or a funcref or a lambda. Refer to
7854 |quickfix-window-function| for an explanation
7855 of how to write the function and an example.
7856 title quickfix list title text. See |quickfix-title|
7857 Unsupported keys in {what} are ignored.
7858 If the "nr" item is not present, then the current quickfix list
7859 is modified. When creating a new quickfix list, "nr" can be
7860 set to a value one greater than the quickfix stack size.
7861 When modifying a quickfix list, to guarantee that the correct
7862 list is modified, "id" should be used instead of "nr" to
7863 specify the list.
7864
7865 Examples (See also |setqflist-examples|): >
7866 :call setqflist([], 'r', {'title': 'My search'})
7867 :call setqflist([], 'r', {'nr': 2, 'title': 'Errors'})
7868 :call setqflist([], 'a', {'id':qfid, 'lines':["F1:10:L10"]})
7869<
7870 Returns zero for success, -1 for failure.
7871
7872 This function can be used to create a quickfix list
7873 independent of the 'errorformat' setting. Use a command like
7874 `:cc 1` to jump to the first position.
7875
7876 Can also be used as a |method|, the base is passed as the
7877 second argument: >
7878 GetErrorlist()->setqflist()
7879<
7880 *setreg()*
7881setreg({regname}, {value} [, {options}])
7882 Set the register {regname} to {value}.
7883 If {regname} is "" or "@", the unnamed register '"' is used.
7884 The {regname} argument is a string. In |Vim9-script|
7885 {regname} must be one character.
7886
7887 {value} may be any value returned by |getreg()| or
7888 |getreginfo()|, including a |List| or |Dict|.
7889 If {options} contains "a" or {regname} is upper case,
7890 then the value is appended.
7891
7892 {options} can also contain a register type specification:
7893 "c" or "v" |characterwise| mode
7894 "l" or "V" |linewise| mode
7895 "b" or "<CTRL-V>" |blockwise-visual| mode
7896 If a number immediately follows "b" or "<CTRL-V>" then this is
7897 used as the width of the selection - if it is not specified
7898 then the width of the block is set to the number of characters
7899 in the longest line (counting a <Tab> as 1 character).
7900
7901 If {options} contains no register settings, then the default
7902 is to use character mode unless {value} ends in a <NL> for
7903 string {value} and linewise mode for list {value}. Blockwise
7904 mode is never selected automatically.
7905 Returns zero for success, non-zero for failure.
7906
7907 *E883*
7908 Note: you may not use |List| containing more than one item to
7909 set search and expression registers. Lists containing no
7910 items act like empty strings.
7911
7912 Examples: >
7913 :call setreg(v:register, @*)
7914 :call setreg('*', @%, 'ac')
7915 :call setreg('a', "1\n2\n3", 'b5')
7916 :call setreg('"', { 'points_to': 'a'})
7917
7918< This example shows using the functions to save and restore a
7919 register: >
7920 :let var_a = getreginfo()
7921 :call setreg('a', var_a)
7922< or: >
7923 :let var_a = getreg('a', 1, 1)
7924 :let var_amode = getregtype('a')
7925 ....
7926 :call setreg('a', var_a, var_amode)
7927< Note: you may not reliably restore register value
7928 without using the third argument to |getreg()| as without it
7929 newlines are represented as newlines AND Nul bytes are
7930 represented as newlines as well, see |NL-used-for-Nul|.
7931
7932 You can also change the type of a register by appending
7933 nothing: >
7934 :call setreg('a', '', 'al')
7935
7936< Can also be used as a |method|, the base is passed as the
7937 second argument: >
7938 GetText()->setreg('a')
7939
7940settabvar({tabnr}, {varname}, {val}) *settabvar()*
7941 Set tab-local variable {varname} to {val} in tab page {tabnr}.
7942 |t:var|
7943 The {varname} argument is a string.
7944 Note that autocommands are blocked, side effects may not be
7945 triggered, e.g. when setting 'filetype'.
7946 Note that the variable name without "t:" must be used.
7947 Tabs are numbered starting with one.
7948 This function is not available in the |sandbox|.
7949
7950 Can also be used as a |method|, the base is passed as the
7951 third argument: >
7952 GetValue()->settabvar(tab, name)
7953
7954settabwinvar({tabnr}, {winnr}, {varname}, {val}) *settabwinvar()*
7955 Set option or local variable {varname} in window {winnr} to
7956 {val}.
7957 Tabs are numbered starting with one. For the current tabpage
7958 use |setwinvar()|.
7959 {winnr} can be the window number or the |window-ID|.
7960 When {winnr} is zero the current window is used.
7961 Note that autocommands are blocked, side effects may not be
7962 triggered, e.g. when setting 'filetype' or 'syntax'.
7963 This also works for a global or local buffer option, but it
7964 doesn't work for a global or local buffer variable.
7965 For a local buffer option the global value is unchanged.
7966 Note that the variable name without "w:" must be used.
7967 Examples: >
7968 :call settabwinvar(1, 1, "&list", 0)
7969 :call settabwinvar(3, 2, "myvar", "foobar")
7970< This function is not available in the |sandbox|.
7971
7972 Can also be used as a |method|, the base is passed as the
7973 fourth argument: >
7974 GetValue()->settabwinvar(tab, winnr, name)
7975
7976settagstack({nr}, {dict} [, {action}]) *settagstack()*
7977 Modify the tag stack of the window {nr} using {dict}.
7978 {nr} can be the window number or the |window-ID|.
7979
7980 For a list of supported items in {dict}, refer to
7981 |gettagstack()|. "curidx" takes effect before changing the tag
7982 stack.
7983 *E962*
7984 How the tag stack is modified depends on the {action}
7985 argument:
7986 - If {action} is not present or is set to 'r', then the tag
7987 stack is replaced.
7988 - If {action} is set to 'a', then new entries from {dict} are
7989 pushed (added) onto the tag stack.
7990 - If {action} is set to 't', then all the entries from the
7991 current entry in the tag stack or "curidx" in {dict} are
7992 removed and then new entries are pushed to the stack.
7993
7994 The current index is set to one after the length of the tag
7995 stack after the modification.
7996
7997 Returns zero for success, -1 for failure.
7998
7999 Examples (for more examples see |tagstack-examples|):
8000 Empty the tag stack of window 3: >
8001 call settagstack(3, {'items' : []})
8002
8003< Save and restore the tag stack: >
8004 let stack = gettagstack(1003)
8005 " do something else
8006 call settagstack(1003, stack)
8007 unlet stack
8008<
8009 Can also be used as a |method|, the base is passed as the
8010 second argument: >
8011 GetStack()->settagstack(winnr)
8012
8013setwinvar({winnr}, {varname}, {val}) *setwinvar()*
8014 Like |settabwinvar()| for the current tab page.
8015 Examples: >
8016 :call setwinvar(1, "&list", 0)
8017 :call setwinvar(2, "myvar", "foobar")
8018
8019< Can also be used as a |method|, the base is passed as the
8020 third argument: >
8021 GetValue()->setwinvar(winnr, name)
8022
8023sha256({string}) *sha256()*
8024 Returns a String with 64 hex characters, which is the SHA256
8025 checksum of {string}.
8026
8027 Can also be used as a |method|: >
8028 GetText()->sha256()
8029
8030< {only available when compiled with the |+cryptv| feature}
8031
8032shellescape({string} [, {special}]) *shellescape()*
8033 Escape {string} for use as a shell command argument.
8034 When the 'shell' contains powershell (MS-Windows) or pwsh
Bram Moolenaar944697a2022-02-20 19:48:20 +00008035 (MS-Windows, Linux, and macOS) then it will enclose {string}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008036 in single quotes and will double up all internal single
8037 quotes.
8038 On MS-Windows, when 'shellslash' is not set, it will enclose
8039 {string} in double quotes and double all double quotes within
8040 {string}.
8041 Otherwise it will enclose {string} in single quotes and
8042 replace all "'" with "'\''".
8043
8044 When the {special} argument is present and it's a non-zero
8045 Number or a non-empty String (|non-zero-arg|), then special
8046 items such as "!", "%", "#" and "<cword>" will be preceded by
8047 a backslash. This backslash will be removed again by the |:!|
8048 command.
8049
8050 The "!" character will be escaped (again with a |non-zero-arg|
8051 {special}) when 'shell' contains "csh" in the tail. That is
8052 because for csh and tcsh "!" is used for history replacement
8053 even when inside single quotes.
8054
8055 With a |non-zero-arg| {special} the <NL> character is also
8056 escaped. When 'shell' containing "csh" in the tail it's
8057 escaped a second time.
8058
8059 The "\" character will be escaped when 'shell' contains "fish"
8060 in the tail. That is because for fish "\" is used as an escape
8061 character inside single quotes.
8062
8063 Example of use with a |:!| command: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00008064 :exe '!dir ' .. shellescape(expand('<cfile>'), 1)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008065< This results in a directory listing for the file under the
8066 cursor. Example of use with |system()|: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00008067 :call system("chmod +w -- " .. shellescape(expand("%")))
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008068< See also |::S|.
8069
8070 Can also be used as a |method|: >
8071 GetCommand()->shellescape()
8072
8073shiftwidth([{col}]) *shiftwidth()*
8074 Returns the effective value of 'shiftwidth'. This is the
8075 'shiftwidth' value unless it is zero, in which case it is the
8076 'tabstop' value. This function was introduced with patch
8077 7.3.694 in 2012, everybody should have it by now (however it
8078 did not allow for the optional {col} argument until 8.1.542).
8079
8080 When there is one argument {col} this is used as column number
8081 for which to return the 'shiftwidth' value. This matters for the
8082 'vartabstop' feature. If the 'vartabstop' setting is enabled and
8083 no {col} argument is given, column 1 will be assumed.
8084
8085 Can also be used as a |method|: >
8086 GetColumn()->shiftwidth()
8087
8088sign_ functions are documented here: |sign-functions-details|
8089
8090
8091simplify({filename}) *simplify()*
8092 Simplify the file name as much as possible without changing
8093 the meaning. Shortcuts (on MS-Windows) or symbolic links (on
8094 Unix) are not resolved. If the first path component in
8095 {filename} designates the current directory, this will be
8096 valid for the result as well. A trailing path separator is
8097 not removed either. On Unix "//path" is unchanged, but
8098 "///path" is simplified to "/path" (this follows the Posix
8099 standard).
8100 Example: >
8101 simplify("./dir/.././/file/") == "./file/"
8102< Note: The combination "dir/.." is only removed if "dir" is
8103 a searchable directory or does not exist. On Unix, it is also
8104 removed when "dir" is a symbolic link within the same
8105 directory. In order to resolve all the involved symbolic
8106 links before simplifying the path name, use |resolve()|.
8107
8108 Can also be used as a |method|: >
8109 GetName()->simplify()
8110
8111sin({expr}) *sin()*
8112 Return the sine of {expr}, measured in radians, as a |Float|.
8113 {expr} must evaluate to a |Float| or a |Number|.
8114 Examples: >
8115 :echo sin(100)
8116< -0.506366 >
8117 :echo sin(-4.01)
8118< 0.763301
8119
8120 Can also be used as a |method|: >
8121 Compute()->sin()
8122<
8123 {only available when compiled with the |+float| feature}
8124
8125
8126sinh({expr}) *sinh()*
8127 Return the hyperbolic sine of {expr} as a |Float| in the range
8128 [-inf, inf].
8129 {expr} must evaluate to a |Float| or a |Number|.
8130 Examples: >
8131 :echo sinh(0.5)
8132< 0.521095 >
8133 :echo sinh(-0.9)
8134< -1.026517
8135
8136 Can also be used as a |method|: >
8137 Compute()->sinh()
8138<
8139 {only available when compiled with the |+float| feature}
8140
8141
8142slice({expr}, {start} [, {end}]) *slice()*
8143 Similar to using a |slice| "expr[start : end]", but "end" is
8144 used exclusive. And for a string the indexes are used as
8145 character indexes instead of byte indexes, like in
8146 |vim9script|. Also, composing characters are not counted.
8147 When {end} is omitted the slice continues to the last item.
8148 When {end} is -1 the last item is omitted.
8149
8150 Can also be used as a |method|: >
8151 GetList()->slice(offset)
8152
8153
Bram Moolenaar2007dd42022-02-23 13:17:47 +00008154sort({list} [, {how} [, {dict}]]) *sort()* *E702*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008155 Sort the items in {list} in-place. Returns {list}.
8156
8157 If you want a list to remain unmodified make a copy first: >
8158 :let sortedlist = sort(copy(mylist))
8159
Bram Moolenaar2007dd42022-02-23 13:17:47 +00008160< When {how} is omitted or is an string, then sort() uses the
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008161 string representation of each item to sort on. Numbers sort
8162 after Strings, |Lists| after Numbers. For sorting text in the
8163 current buffer use |:sort|.
8164
Bram Moolenaar2007dd42022-02-23 13:17:47 +00008165 When {how} is given and it is 'i' then case is ignored.
8166 In legacy script, for backwards compatibility, the value one
8167 can be used to ignore case. Zero means to not ignore case.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008168
Bram Moolenaar2007dd42022-02-23 13:17:47 +00008169 When {how} is given and it is 'l' then the current collation
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008170 locale is used for ordering. Implementation details: strcoll()
8171 is used to compare strings. See |:language| check or set the
8172 collation locale. |v:collate| can also be used to check the
8173 current locale. Sorting using the locale typically ignores
8174 case. Example: >
8175 " ö is sorted similarly to o with English locale.
8176 :language collate en_US.UTF8
8177 :echo sort(['n', 'o', 'O', 'ö', 'p', 'z'], 'l')
8178< ['n', 'o', 'O', 'ö', 'p', 'z'] ~
8179>
8180 " ö is sorted after z with Swedish locale.
8181 :language collate sv_SE.UTF8
8182 :echo sort(['n', 'o', 'O', 'ö', 'p', 'z'], 'l')
8183< ['n', 'o', 'O', 'p', 'z', 'ö'] ~
8184 This does not work properly on Mac.
8185
Bram Moolenaar2007dd42022-02-23 13:17:47 +00008186 When {how} is given and it is 'n' then all items will be
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008187 sorted numerical (Implementation detail: this uses the
8188 strtod() function to parse numbers, Strings, Lists, Dicts and
8189 Funcrefs will be considered as being 0).
8190
Bram Moolenaar2007dd42022-02-23 13:17:47 +00008191 When {how} is given and it is 'N' then all items will be
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008192 sorted numerical. This is like 'n' but a string containing
8193 digits will be used as the number they represent.
8194
Bram Moolenaar2007dd42022-02-23 13:17:47 +00008195 When {how} is given and it is 'f' then all items will be
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008196 sorted numerical. All values must be a Number or a Float.
8197
Bram Moolenaar2007dd42022-02-23 13:17:47 +00008198 When {how} is a |Funcref| or a function name, this function
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008199 is called to compare items. The function is invoked with two
8200 items as argument and must return zero if they are equal, 1 or
8201 bigger if the first one sorts after the second one, -1 or
8202 smaller if the first one sorts before the second one.
8203
8204 {dict} is for functions with the "dict" attribute. It will be
8205 used to set the local variable "self". |Dictionary-function|
8206
8207 The sort is stable, items which compare equal (as number or as
8208 string) will keep their relative position. E.g., when sorting
8209 on numbers, text strings will sort next to each other, in the
8210 same order as they were originally.
8211
8212 Can also be used as a |method|: >
8213 mylist->sort()
8214
8215< Also see |uniq()|.
8216
8217 Example: >
8218 func MyCompare(i1, i2)
8219 return a:i1 == a:i2 ? 0 : a:i1 > a:i2 ? 1 : -1
8220 endfunc
8221 eval mylist->sort("MyCompare")
8222< A shorter compare version for this specific simple case, which
8223 ignores overflow: >
8224 func MyCompare(i1, i2)
8225 return a:i1 - a:i2
8226 endfunc
8227< For a simple expression you can use a lambda: >
8228 eval mylist->sort({i1, i2 -> i1 - i2})
8229<
8230sound_clear() *sound_clear()*
8231 Stop playing all sounds.
8232
8233 On some Linux systems you may need the libcanberra-pulse
8234 package, otherwise sound may not stop.
8235
8236 {only available when compiled with the |+sound| feature}
8237
8238 *sound_playevent()*
8239sound_playevent({name} [, {callback}])
8240 Play a sound identified by {name}. Which event names are
8241 supported depends on the system. Often the XDG sound names
8242 are used. On Ubuntu they may be found in
8243 /usr/share/sounds/freedesktop/stereo. Example: >
8244 call sound_playevent('bell')
8245< On MS-Windows, {name} can be SystemAsterisk, SystemDefault,
8246 SystemExclamation, SystemExit, SystemHand, SystemQuestion,
8247 SystemStart, SystemWelcome, etc.
8248
8249 When {callback} is specified it is invoked when the sound is
8250 finished. The first argument is the sound ID, the second
8251 argument is the status:
8252 0 sound was played to the end
8253 1 sound was interrupted
8254 2 error occurred after sound started
8255 Example: >
8256 func Callback(id, status)
8257 echomsg "sound " .. a:id .. " finished with " .. a:status
8258 endfunc
8259 call sound_playevent('bell', 'Callback')
8260
8261< MS-Windows: {callback} doesn't work for this function.
8262
8263 Returns the sound ID, which can be passed to `sound_stop()`.
8264 Returns zero if the sound could not be played.
8265
8266 Can also be used as a |method|: >
8267 GetSoundName()->sound_playevent()
8268
8269< {only available when compiled with the |+sound| feature}
8270
8271 *sound_playfile()*
8272sound_playfile({path} [, {callback}])
8273 Like `sound_playevent()` but play sound file {path}. {path}
8274 must be a full path. On Ubuntu you may find files to play
8275 with this command: >
8276 :!find /usr/share/sounds -type f | grep -v index.theme
8277
8278< Can also be used as a |method|: >
8279 GetSoundPath()->sound_playfile()
8280
Bram Moolenaar1588bc82022-03-08 21:35:07 +00008281< {only available when compiled with the |+sound| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008282
8283
8284sound_stop({id}) *sound_stop()*
8285 Stop playing sound {id}. {id} must be previously returned by
8286 `sound_playevent()` or `sound_playfile()`.
8287
8288 On some Linux systems you may need the libcanberra-pulse
8289 package, otherwise sound may not stop.
8290
8291 On MS-Windows, this does not work for event sound started by
8292 `sound_playevent()`. To stop event sounds, use `sound_clear()`.
8293
8294 Can also be used as a |method|: >
8295 soundid->sound_stop()
8296
8297< {only available when compiled with the |+sound| feature}
8298
8299 *soundfold()*
8300soundfold({word})
8301 Return the sound-folded equivalent of {word}. Uses the first
8302 language in 'spelllang' for the current window that supports
8303 soundfolding. 'spell' must be set. When no sound folding is
8304 possible the {word} is returned unmodified.
8305 This can be used for making spelling suggestions. Note that
8306 the method can be quite slow.
8307
8308 Can also be used as a |method|: >
8309 GetWord()->soundfold()
8310<
8311 *spellbadword()*
8312spellbadword([{sentence}])
8313 Without argument: The result is the badly spelled word under
8314 or after the cursor. The cursor is moved to the start of the
8315 bad word. When no bad word is found in the cursor line the
8316 result is an empty string and the cursor doesn't move.
8317
8318 With argument: The result is the first word in {sentence} that
8319 is badly spelled. If there are no spelling mistakes the
8320 result is an empty string.
8321
8322 The return value is a list with two items:
8323 - The badly spelled word or an empty string.
8324 - The type of the spelling error:
8325 "bad" spelling mistake
8326 "rare" rare word
8327 "local" word only valid in another region
8328 "caps" word should start with Capital
8329 Example: >
8330 echo spellbadword("the quik brown fox")
8331< ['quik', 'bad'] ~
8332
8333 The spelling information for the current window and the value
8334 of 'spelllang' are used.
8335
8336 Can also be used as a |method|: >
8337 GetText()->spellbadword()
8338<
8339 *spellsuggest()*
8340spellsuggest({word} [, {max} [, {capital}]])
8341 Return a |List| with spelling suggestions to replace {word}.
8342 When {max} is given up to this number of suggestions are
8343 returned. Otherwise up to 25 suggestions are returned.
8344
8345 When the {capital} argument is given and it's non-zero only
8346 suggestions with a leading capital will be given. Use this
8347 after a match with 'spellcapcheck'.
8348
8349 {word} can be a badly spelled word followed by other text.
8350 This allows for joining two words that were split. The
8351 suggestions also include the following text, thus you can
8352 replace a line.
8353
8354 {word} may also be a good word. Similar words will then be
8355 returned. {word} itself is not included in the suggestions,
8356 although it may appear capitalized.
8357
8358 The spelling information for the current window is used. The
8359 values of 'spelllang' and 'spellsuggest' are used.
8360
8361 Can also be used as a |method|: >
8362 GetWord()->spellsuggest()
8363
8364split({string} [, {pattern} [, {keepempty}]]) *split()*
8365 Make a |List| out of {string}. When {pattern} is omitted or
8366 empty each white-separated sequence of characters becomes an
8367 item.
8368 Otherwise the string is split where {pattern} matches,
8369 removing the matched characters. 'ignorecase' is not used
8370 here, add \c to ignore case. |/\c|
8371 When the first or last item is empty it is omitted, unless the
8372 {keepempty} argument is given and it's non-zero.
8373 Other empty items are kept when {pattern} matches at least one
8374 character or when {keepempty} is non-zero.
8375 Example: >
8376 :let words = split(getline('.'), '\W\+')
8377< To split a string in individual characters: >
8378 :for c in split(mystring, '\zs')
8379< If you want to keep the separator you can also use '\zs' at
8380 the end of the pattern: >
8381 :echo split('abc:def:ghi', ':\zs')
8382< ['abc:', 'def:', 'ghi'] ~
8383 Splitting a table where the first element can be empty: >
8384 :let items = split(line, ':', 1)
8385< The opposite function is |join()|.
8386
8387 Can also be used as a |method|: >
8388 GetString()->split()
8389
8390sqrt({expr}) *sqrt()*
8391 Return the non-negative square root of Float {expr} as a
8392 |Float|.
8393 {expr} must evaluate to a |Float| or a |Number|. When {expr}
8394 is negative the result is NaN (Not a Number).
8395 Examples: >
8396 :echo sqrt(100)
8397< 10.0 >
8398 :echo sqrt(-4.01)
8399< nan
8400 "nan" may be different, it depends on system libraries.
8401
8402 Can also be used as a |method|: >
8403 Compute()->sqrt()
8404<
8405 {only available when compiled with the |+float| feature}
8406
8407
8408srand([{expr}]) *srand()*
8409 Initialize seed used by |rand()|:
8410 - If {expr} is not given, seed values are initialized by
8411 reading from /dev/urandom, if possible, or using time(NULL)
8412 a.k.a. epoch time otherwise; this only has second accuracy.
8413 - If {expr} is given it must be a Number. It is used to
8414 initialize the seed values. This is useful for testing or
8415 when a predictable sequence is intended.
8416
8417 Examples: >
8418 :let seed = srand()
8419 :let seed = srand(userinput)
8420 :echo rand(seed)
8421
8422state([{what}]) *state()*
8423 Return a string which contains characters indicating the
8424 current state. Mostly useful in callbacks that want to do
8425 work that may not always be safe. Roughly this works like:
8426 - callback uses state() to check if work is safe to do.
8427 Yes: then do it right away.
8428 No: add to work queue and add a |SafeState| and/or
8429 |SafeStateAgain| autocommand (|SafeState| triggers at
8430 toplevel, |SafeStateAgain| triggers after handling
8431 messages and callbacks).
8432 - When SafeState or SafeStateAgain is triggered and executes
8433 your autocommand, check with `state()` if the work can be
8434 done now, and if yes remove it from the queue and execute.
8435 Remove the autocommand if the queue is now empty.
8436 Also see |mode()|.
8437
8438 When {what} is given only characters in this string will be
8439 added. E.g, this checks if the screen has scrolled: >
8440 if state('s') == ''
8441 " screen has not scrolled
8442<
8443 These characters indicate the state, generally indicating that
8444 something is busy:
8445 m halfway a mapping, :normal command, feedkeys() or
8446 stuffed command
8447 o operator pending, e.g. after |d|
8448 a Insert mode autocomplete active
8449 x executing an autocommand
8450 w blocked on waiting, e.g. ch_evalexpr(), ch_read() and
8451 ch_readraw() when reading json
8452 S not triggering SafeState or SafeStateAgain, e.g. after
8453 |f| or a count
8454 c callback invoked, including timer (repeats for
8455 recursiveness up to "ccc")
8456 s screen has scrolled for messages
8457
8458str2float({string} [, {quoted}]) *str2float()*
8459 Convert String {string} to a Float. This mostly works the
8460 same as when using a floating point number in an expression,
8461 see |floating-point-format|. But it's a bit more permissive.
8462 E.g., "1e40" is accepted, while in an expression you need to
8463 write "1.0e40". The hexadecimal form "0x123" is also
8464 accepted, but not others, like binary or octal.
8465 When {quoted} is present and non-zero then embedded single
8466 quotes before the dot are ignored, thus "1'000.0" is a
8467 thousand.
8468 Text after the number is silently ignored.
8469 The decimal point is always '.', no matter what the locale is
8470 set to. A comma ends the number: "12,345.67" is converted to
8471 12.0. You can strip out thousands separators with
8472 |substitute()|: >
8473 let f = str2float(substitute(text, ',', '', 'g'))
8474<
8475 Can also be used as a |method|: >
8476 let f = text->substitute(',', '', 'g')->str2float()
8477<
8478 {only available when compiled with the |+float| feature}
8479
8480str2list({string} [, {utf8}]) *str2list()*
8481 Return a list containing the number values which represent
8482 each character in String {string}. Examples: >
8483 str2list(" ") returns [32]
8484 str2list("ABC") returns [65, 66, 67]
8485< |list2str()| does the opposite.
8486
8487 When {utf8} is omitted or zero, the current 'encoding' is used.
8488 When {utf8} is TRUE, always treat the String as UTF-8
8489 characters. With UTF-8 composing characters are handled
8490 properly: >
8491 str2list("á") returns [97, 769]
8492
8493< Can also be used as a |method|: >
8494 GetString()->str2list()
8495
8496
8497str2nr({string} [, {base} [, {quoted}]]) *str2nr()*
8498 Convert string {string} to a number.
8499 {base} is the conversion base, it can be 2, 8, 10 or 16.
8500 When {quoted} is present and non-zero then embedded single
8501 quotes are ignored, thus "1'000'000" is a million.
8502
8503 When {base} is omitted base 10 is used. This also means that
8504 a leading zero doesn't cause octal conversion to be used, as
8505 with the default String to Number conversion. Example: >
8506 let nr = str2nr('0123')
8507<
8508 When {base} is 16 a leading "0x" or "0X" is ignored. With a
8509 different base the result will be zero. Similarly, when
8510 {base} is 8 a leading "0", "0o" or "0O" is ignored, and when
8511 {base} is 2 a leading "0b" or "0B" is ignored.
8512 Text after the number is silently ignored.
8513
8514 Can also be used as a |method|: >
8515 GetText()->str2nr()
8516
8517
8518strcharlen({string}) *strcharlen()*
8519 The result is a Number, which is the number of characters
8520 in String {string}. Composing characters are ignored.
8521 |strchars()| can count the number of characters, counting
8522 composing characters separately.
8523
8524 Also see |strlen()|, |strdisplaywidth()| and |strwidth()|.
8525
8526 Can also be used as a |method|: >
8527 GetText()->strcharlen()
8528
8529
8530strcharpart({src}, {start} [, {len} [, {skipcc}]]) *strcharpart()*
8531 Like |strpart()| but using character index and length instead
8532 of byte index and length.
8533 When {skipcc} is omitted or zero, composing characters are
8534 counted separately.
8535 When {skipcc} set to 1, Composing characters are ignored,
8536 similar to |slice()|.
8537 When a character index is used where a character does not
8538 exist it is omitted and counted as one character. For
8539 example: >
8540 strcharpart('abc', -1, 2)
8541< results in 'a'.
8542
8543 Can also be used as a |method|: >
8544 GetText()->strcharpart(5)
8545
8546
8547strchars({string} [, {skipcc}]) *strchars()*
8548 The result is a Number, which is the number of characters
8549 in String {string}.
8550 When {skipcc} is omitted or zero, composing characters are
8551 counted separately.
8552 When {skipcc} set to 1, Composing characters are ignored.
8553 |strcharlen()| always does this.
8554
8555 Also see |strlen()|, |strdisplaywidth()| and |strwidth()|.
8556
8557 {skipcc} is only available after 7.4.755. For backward
8558 compatibility, you can define a wrapper function: >
8559 if has("patch-7.4.755")
8560 function s:strchars(str, skipcc)
8561 return strchars(a:str, a:skipcc)
8562 endfunction
8563 else
8564 function s:strchars(str, skipcc)
8565 if a:skipcc
8566 return strlen(substitute(a:str, ".", "x", "g"))
8567 else
8568 return strchars(a:str)
8569 endif
8570 endfunction
8571 endif
8572<
8573 Can also be used as a |method|: >
8574 GetText()->strchars()
8575
8576strdisplaywidth({string} [, {col}]) *strdisplaywidth()*
8577 The result is a Number, which is the number of display cells
8578 String {string} occupies on the screen when it starts at {col}
8579 (first column is zero). When {col} is omitted zero is used.
8580 Otherwise it is the screen column where to start. This
8581 matters for Tab characters.
8582 The option settings of the current window are used. This
8583 matters for anything that's displayed differently, such as
8584 'tabstop' and 'display'.
8585 When {string} contains characters with East Asian Width Class
8586 Ambiguous, this function's return value depends on 'ambiwidth'.
8587 Also see |strlen()|, |strwidth()| and |strchars()|.
8588
8589 Can also be used as a |method|: >
8590 GetText()->strdisplaywidth()
8591
8592strftime({format} [, {time}]) *strftime()*
8593 The result is a String, which is a formatted date and time, as
8594 specified by the {format} string. The given {time} is used,
8595 or the current time if no time is given. The accepted
8596 {format} depends on your system, thus this is not portable!
8597 See the manual page of the C function strftime() for the
8598 format. The maximum length of the result is 80 characters.
8599 See also |localtime()|, |getftime()| and |strptime()|.
8600 The language can be changed with the |:language| command.
8601 Examples: >
8602 :echo strftime("%c") Sun Apr 27 11:49:23 1997
8603 :echo strftime("%Y %b %d %X") 1997 Apr 27 11:53:25
8604 :echo strftime("%y%m%d %T") 970427 11:53:55
8605 :echo strftime("%H:%M") 11:55
8606 :echo strftime("%c", getftime("file.c"))
8607 Show mod time of file.c.
8608< Not available on all systems. To check use: >
8609 :if exists("*strftime")
8610
8611< Can also be used as a |method|: >
8612 GetFormat()->strftime()
8613
8614strgetchar({str}, {index}) *strgetchar()*
8615 Get character {index} from {str}. This uses a character
8616 index, not a byte index. Composing characters are considered
8617 separate characters here.
8618 Also see |strcharpart()| and |strchars()|.
8619
8620 Can also be used as a |method|: >
8621 GetText()->strgetchar(5)
8622
8623stridx({haystack}, {needle} [, {start}]) *stridx()*
8624 The result is a Number, which gives the byte index in
8625 {haystack} of the first occurrence of the String {needle}.
8626 If {start} is specified, the search starts at index {start}.
8627 This can be used to find a second match: >
8628 :let colon1 = stridx(line, ":")
8629 :let colon2 = stridx(line, ":", colon1 + 1)
8630< The search is done case-sensitive.
8631 For pattern searches use |match()|.
8632 -1 is returned if the {needle} does not occur in {haystack}.
8633 See also |strridx()|.
8634 Examples: >
8635 :echo stridx("An Example", "Example") 3
8636 :echo stridx("Starting point", "Start") 0
8637 :echo stridx("Starting point", "start") -1
8638< *strstr()* *strchr()*
8639 stridx() works similar to the C function strstr(). When used
8640 with a single character it works similar to strchr().
8641
8642 Can also be used as a |method|: >
8643 GetHaystack()->stridx(needle)
8644<
8645 *string()*
8646string({expr}) Return {expr} converted to a String. If {expr} is a Number,
8647 Float, String, Blob or a composition of them, then the result
8648 can be parsed back with |eval()|.
8649 {expr} type result ~
8650 String 'string' (single quotes are doubled)
8651 Number 123
8652 Float 123.123456 or 1.123456e8
8653 Funcref function('name')
8654 Blob 0z00112233.44556677.8899
8655 List [item, item]
8656 Dictionary {key: value, key: value}
8657
8658 When a |List| or |Dictionary| has a recursive reference it is
8659 replaced by "[...]" or "{...}". Using eval() on the result
8660 will then fail.
8661
8662 Can also be used as a |method|: >
8663 mylist->string()
8664
8665< Also see |strtrans()|.
8666
8667
8668strlen({string}) *strlen()*
8669 The result is a Number, which is the length of the String
8670 {string} in bytes.
8671 If the argument is a Number it is first converted to a String.
8672 For other types an error is given.
8673 If you want to count the number of multibyte characters use
8674 |strchars()|.
8675 Also see |len()|, |strdisplaywidth()| and |strwidth()|.
8676
8677 Can also be used as a |method|: >
8678 GetString()->strlen()
8679
8680strpart({src}, {start} [, {len} [, {chars}]]) *strpart()*
8681 The result is a String, which is part of {src}, starting from
8682 byte {start}, with the byte length {len}.
8683 When {chars} is present and TRUE then {len} is the number of
8684 characters positions (composing characters are not counted
8685 separately, thus "1" means one base character and any
8686 following composing characters).
8687 To count {start} as characters instead of bytes use
8688 |strcharpart()|.
8689
8690 When bytes are selected which do not exist, this doesn't
8691 result in an error, the bytes are simply omitted.
8692 If {len} is missing, the copy continues from {start} till the
8693 end of the {src}. >
8694 strpart("abcdefg", 3, 2) == "de"
8695 strpart("abcdefg", -2, 4) == "ab"
8696 strpart("abcdefg", 5, 4) == "fg"
8697 strpart("abcdefg", 3) == "defg"
8698
8699< Note: To get the first character, {start} must be 0. For
8700 example, to get the character under the cursor: >
8701 strpart(getline("."), col(".") - 1, 1, v:true)
8702<
8703 Can also be used as a |method|: >
8704 GetText()->strpart(5)
8705
8706strptime({format}, {timestring}) *strptime()*
8707 The result is a Number, which is a unix timestamp representing
8708 the date and time in {timestring}, which is expected to match
8709 the format specified in {format}.
8710
8711 The accepted {format} depends on your system, thus this is not
8712 portable! See the manual page of the C function strptime()
8713 for the format. Especially avoid "%c". The value of $TZ also
8714 matters.
8715
8716 If the {timestring} cannot be parsed with {format} zero is
8717 returned. If you do not know the format of {timestring} you
8718 can try different {format} values until you get a non-zero
8719 result.
8720
8721 See also |strftime()|.
8722 Examples: >
8723 :echo strptime("%Y %b %d %X", "1997 Apr 27 11:49:23")
8724< 862156163 >
8725 :echo strftime("%c", strptime("%y%m%d %T", "970427 11:53:55"))
8726< Sun Apr 27 11:53:55 1997 >
8727 :echo strftime("%c", strptime("%Y%m%d%H%M%S", "19970427115355") + 3600)
8728< Sun Apr 27 12:53:55 1997
8729
8730 Can also be used as a |method|: >
8731 GetFormat()->strptime(timestring)
8732<
8733 Not available on all systems. To check use: >
8734 :if exists("*strptime")
8735
8736strridx({haystack}, {needle} [, {start}]) *strridx()*
8737 The result is a Number, which gives the byte index in
8738 {haystack} of the last occurrence of the String {needle}.
8739 When {start} is specified, matches beyond this index are
8740 ignored. This can be used to find a match before a previous
8741 match: >
8742 :let lastcomma = strridx(line, ",")
8743 :let comma2 = strridx(line, ",", lastcomma - 1)
8744< The search is done case-sensitive.
8745 For pattern searches use |match()|.
8746 -1 is returned if the {needle} does not occur in {haystack}.
8747 If the {needle} is empty the length of {haystack} is returned.
8748 See also |stridx()|. Examples: >
8749 :echo strridx("an angry armadillo", "an") 3
8750< *strrchr()*
8751 When used with a single character it works similar to the C
8752 function strrchr().
8753
8754 Can also be used as a |method|: >
8755 GetHaystack()->strridx(needle)
8756
8757strtrans({string}) *strtrans()*
8758 The result is a String, which is {string} with all unprintable
8759 characters translated into printable characters |'isprint'|.
8760 Like they are shown in a window. Example: >
8761 echo strtrans(@a)
8762< This displays a newline in register a as "^@" instead of
8763 starting a new line.
8764
8765 Can also be used as a |method|: >
8766 GetString()->strtrans()
8767
8768strwidth({string}) *strwidth()*
8769 The result is a Number, which is the number of display cells
8770 String {string} occupies. A Tab character is counted as one
8771 cell, alternatively use |strdisplaywidth()|.
8772 When {string} contains characters with East Asian Width Class
8773 Ambiguous, this function's return value depends on 'ambiwidth'.
8774 Also see |strlen()|, |strdisplaywidth()| and |strchars()|.
8775
8776 Can also be used as a |method|: >
8777 GetString()->strwidth()
8778
8779submatch({nr} [, {list}]) *submatch()* *E935*
8780 Only for an expression in a |:substitute| command or
8781 substitute() function.
8782 Returns the {nr}'th submatch of the matched text. When {nr}
8783 is 0 the whole matched text is returned.
8784 Note that a NL in the string can stand for a line break of a
8785 multi-line match or a NUL character in the text.
8786 Also see |sub-replace-expression|.
8787
8788 If {list} is present and non-zero then submatch() returns
8789 a list of strings, similar to |getline()| with two arguments.
8790 NL characters in the text represent NUL characters in the
8791 text.
8792 Only returns more than one item for |:substitute|, inside
8793 |substitute()| this list will always contain one or zero
8794 items, since there are no real line breaks.
8795
8796 When substitute() is used recursively only the submatches in
8797 the current (deepest) call can be obtained.
8798
8799 Examples: >
8800 :s/\d\+/\=submatch(0) + 1/
8801 :echo substitute(text, '\d\+', '\=submatch(0) + 1', '')
8802< This finds the first number in the line and adds one to it.
8803 A line break is included as a newline character.
8804
8805 Can also be used as a |method|: >
8806 GetNr()->submatch()
8807
8808substitute({string}, {pat}, {sub}, {flags}) *substitute()*
8809 The result is a String, which is a copy of {string}, in which
8810 the first match of {pat} is replaced with {sub}.
8811 When {flags} is "g", all matches of {pat} in {string} are
8812 replaced. Otherwise {flags} should be "".
8813
8814 This works like the ":substitute" command (without any flags).
8815 But the matching with {pat} is always done like the 'magic'
8816 option is set and 'cpoptions' is empty (to make scripts
8817 portable). 'ignorecase' is still relevant, use |/\c| or |/\C|
8818 if you want to ignore or match case and ignore 'ignorecase'.
8819 'smartcase' is not used. See |string-match| for how {pat} is
8820 used.
8821
8822 A "~" in {sub} is not replaced with the previous {sub}.
8823 Note that some codes in {sub} have a special meaning
8824 |sub-replace-special|. For example, to replace something with
8825 "\n" (two characters), use "\\\\n" or '\\n'.
8826
8827 When {pat} does not match in {string}, {string} is returned
8828 unmodified.
8829
8830 Example: >
8831 :let &path = substitute(&path, ",\\=[^,]*$", "", "")
8832< This removes the last component of the 'path' option. >
8833 :echo substitute("testing", ".*", "\\U\\0", "")
8834< results in "TESTING".
8835
8836 When {sub} starts with "\=", the remainder is interpreted as
8837 an expression. See |sub-replace-expression|. Example: >
8838 :echo substitute(s, '%\(\x\x\)',
Bram Moolenaarc51cf032022-02-26 12:25:45 +00008839 \ '\=nr2char("0x" .. submatch(1))', 'g')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008840
8841< When {sub} is a Funcref that function is called, with one
8842 optional argument. Example: >
8843 :echo substitute(s, '%\(\x\x\)', SubNr, 'g')
8844< The optional argument is a list which contains the whole
8845 matched string and up to nine submatches, like what
8846 |submatch()| returns. Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00008847 :echo substitute(s, '%\(\x\x\)', {m -> '0x' .. m[1]}, 'g')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008848
8849< Can also be used as a |method|: >
8850 GetString()->substitute(pat, sub, flags)
8851
8852swapinfo({fname}) *swapinfo()*
8853 The result is a dictionary, which holds information about the
8854 swapfile {fname}. The available fields are:
8855 version Vim version
8856 user user name
8857 host host name
8858 fname original file name
8859 pid PID of the Vim process that created the swap
8860 file
8861 mtime last modification time in seconds
8862 inode Optional: INODE number of the file
8863 dirty 1 if file was modified, 0 if not
8864 Note that "user" and "host" are truncated to at most 39 bytes.
8865 In case of failure an "error" item is added with the reason:
8866 Cannot open file: file not found or in accessible
8867 Cannot read file: cannot read first block
8868 Not a swap file: does not contain correct block ID
8869 Magic number mismatch: Info in first block is invalid
8870
8871 Can also be used as a |method|: >
8872 GetFilename()->swapinfo()
8873
8874swapname({buf}) *swapname()*
8875 The result is the swap file path of the buffer {expr}.
8876 For the use of {buf}, see |bufname()| above.
8877 If buffer {buf} is the current buffer, the result is equal to
8878 |:swapname| (unless there is no swap file).
8879 If buffer {buf} has no swap file, returns an empty string.
8880
8881 Can also be used as a |method|: >
8882 GetBufname()->swapname()
8883
8884synID({lnum}, {col}, {trans}) *synID()*
8885 The result is a Number, which is the syntax ID at the position
8886 {lnum} and {col} in the current window.
8887 The syntax ID can be used with |synIDattr()| and
8888 |synIDtrans()| to obtain syntax information about text.
8889
8890 {col} is 1 for the leftmost column, {lnum} is 1 for the first
8891 line. 'synmaxcol' applies, in a longer line zero is returned.
8892 Note that when the position is after the last character,
8893 that's where the cursor can be in Insert mode, synID() returns
8894 zero. {lnum} is used like with |getline()|.
8895
8896 When {trans} is |TRUE|, transparent items are reduced to the
8897 item that they reveal. This is useful when wanting to know
8898 the effective color. When {trans} is |FALSE|, the transparent
8899 item is returned. This is useful when wanting to know which
8900 syntax item is effective (e.g. inside parens).
8901 Warning: This function can be very slow. Best speed is
8902 obtained by going through the file in forward direction.
8903
8904 Example (echoes the name of the syntax item under the cursor): >
8905 :echo synIDattr(synID(line("."), col("."), 1), "name")
8906<
8907
8908synIDattr({synID}, {what} [, {mode}]) *synIDattr()*
8909 The result is a String, which is the {what} attribute of
8910 syntax ID {synID}. This can be used to obtain information
8911 about a syntax item.
8912 {mode} can be "gui", "cterm" or "term", to get the attributes
8913 for that mode. When {mode} is omitted, or an invalid value is
8914 used, the attributes for the currently active highlighting are
8915 used (GUI, cterm or term).
8916 Use synIDtrans() to follow linked highlight groups.
8917 {what} result
8918 "name" the name of the syntax item
8919 "fg" foreground color (GUI: color name used to set
8920 the color, cterm: color number as a string,
8921 term: empty string)
8922 "bg" background color (as with "fg")
8923 "font" font name (only available in the GUI)
8924 |highlight-font|
8925 "sp" special color for the GUI (as with "fg")
8926 |highlight-guisp|
8927 "ul" underline color for cterm: number as a string
8928 "fg#" like "fg", but for the GUI and the GUI is
8929 running the name in "#RRGGBB" form
8930 "bg#" like "fg#" for "bg"
8931 "sp#" like "fg#" for "sp"
8932 "bold" "1" if bold
8933 "italic" "1" if italic
8934 "reverse" "1" if reverse
8935 "inverse" "1" if inverse (= reverse)
8936 "standout" "1" if standout
8937 "underline" "1" if underlined
8938 "undercurl" "1" if undercurled
8939 "strike" "1" if strikethrough
8940
8941 Example (echoes the color of the syntax item under the
8942 cursor): >
8943 :echo synIDattr(synIDtrans(synID(line("."), col("."), 1)), "fg")
8944<
8945 Can also be used as a |method|: >
8946 :echo synID(line("."), col("."), 1)->synIDtrans()->synIDattr("fg")
8947
8948
8949synIDtrans({synID}) *synIDtrans()*
8950 The result is a Number, which is the translated syntax ID of
8951 {synID}. This is the syntax group ID of what is being used to
8952 highlight the character. Highlight links given with
8953 ":highlight link" are followed.
8954
8955 Can also be used as a |method|: >
8956 :echo synID(line("."), col("."), 1)->synIDtrans()->synIDattr("fg")
8957
8958synconcealed({lnum}, {col}) *synconcealed()*
8959 The result is a |List| with currently three items:
8960 1. The first item in the list is 0 if the character at the
8961 position {lnum} and {col} is not part of a concealable
8962 region, 1 if it is. {lnum} is used like with |getline()|.
8963 2. The second item in the list is a string. If the first item
8964 is 1, the second item contains the text which will be
8965 displayed in place of the concealed text, depending on the
8966 current setting of 'conceallevel' and 'listchars'.
8967 3. The third and final item in the list is a number
8968 representing the specific syntax region matched in the
8969 line. When the character is not concealed the value is
8970 zero. This allows detection of the beginning of a new
8971 concealable region if there are two consecutive regions
8972 with the same replacement character. For an example, if
8973 the text is "123456" and both "23" and "45" are concealed
8974 and replaced by the character "X", then:
8975 call returns ~
8976 synconcealed(lnum, 1) [0, '', 0]
8977 synconcealed(lnum, 2) [1, 'X', 1]
8978 synconcealed(lnum, 3) [1, 'X', 1]
8979 synconcealed(lnum, 4) [1, 'X', 2]
8980 synconcealed(lnum, 5) [1, 'X', 2]
8981 synconcealed(lnum, 6) [0, '', 0]
8982
8983
8984synstack({lnum}, {col}) *synstack()*
8985 Return a |List|, which is the stack of syntax items at the
8986 position {lnum} and {col} in the current window. {lnum} is
8987 used like with |getline()|. Each item in the List is an ID
8988 like what |synID()| returns.
8989 The first item in the List is the outer region, following are
8990 items contained in that one. The last one is what |synID()|
8991 returns, unless not the whole item is highlighted or it is a
8992 transparent item.
8993 This function is useful for debugging a syntax file.
8994 Example that shows the syntax stack under the cursor: >
8995 for id in synstack(line("."), col("."))
8996 echo synIDattr(id, "name")
8997 endfor
8998< When the position specified with {lnum} and {col} is invalid
8999 nothing is returned. The position just after the last
9000 character in a line and the first column in an empty line are
9001 valid positions.
9002
9003system({expr} [, {input}]) *system()* *E677*
9004 Get the output of the shell command {expr} as a |String|. See
9005 |systemlist()| to get the output as a |List|.
9006
9007 When {input} is given and is a |String| this string is written
9008 to a file and passed as stdin to the command. The string is
9009 written as-is, you need to take care of using the correct line
9010 separators yourself.
9011 If {input} is given and is a |List| it is written to the file
9012 in a way |writefile()| does with {binary} set to "b" (i.e.
9013 with a newline between each list item with newlines inside
9014 list items converted to NULs).
9015 When {input} is given and is a number that is a valid id for
9016 an existing buffer then the content of the buffer is written
9017 to the file line by line, each line terminated by a NL and
9018 NULs characters where the text has a NL.
9019
9020 Pipes are not used, the 'shelltemp' option is not used.
9021
9022 When prepended by |:silent| the terminal will not be set to
9023 cooked mode. This is meant to be used for commands that do
9024 not need the user to type. It avoids stray characters showing
9025 up on the screen which require |CTRL-L| to remove. >
9026 :silent let f = system('ls *.vim')
9027<
9028 Note: Use |shellescape()| or |::S| with |expand()| or
9029 |fnamemodify()| to escape special characters in a command
9030 argument. Newlines in {expr} may cause the command to fail.
9031 The characters in 'shellquote' and 'shellxquote' may also
9032 cause trouble.
9033 This is not to be used for interactive commands.
9034
9035 The result is a String. Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00009036 :let files = system('ls ' .. shellescape(expand('%:h')))
9037 :let files = system('ls ' .. expand('%:h:S'))
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009038
9039< To make the result more system-independent, the shell output
9040 is filtered to replace <CR> with <NL> for Macintosh, and
9041 <CR><NL> with <NL> for DOS-like systems.
9042 To avoid the string being truncated at a NUL, all NUL
9043 characters are replaced with SOH (0x01).
9044
9045 The command executed is constructed using several options:
9046 'shell' 'shellcmdflag' 'shellxquote' {expr} 'shellredir' {tmp} 'shellxquote'
9047 ({tmp} is an automatically generated file name).
9048 For Unix, braces are put around {expr} to allow for
9049 concatenated commands.
9050
9051 The command will be executed in "cooked" mode, so that a
9052 CTRL-C will interrupt the command (on Unix at least).
9053
9054 The resulting error code can be found in |v:shell_error|.
9055 This function will fail in |restricted-mode|.
9056
9057 Note that any wrong value in the options mentioned above may
9058 make the function fail. It has also been reported to fail
9059 when using a security agent application.
9060 Unlike ":!cmd" there is no automatic check for changed files.
9061 Use |:checktime| to force a check.
9062
9063 Can also be used as a |method|: >
9064 :echo GetCmd()->system()
9065
9066
9067systemlist({expr} [, {input}]) *systemlist()*
9068 Same as |system()|, but returns a |List| with lines (parts of
9069 output separated by NL) with NULs transformed into NLs. Output
9070 is the same as |readfile()| will output with {binary} argument
9071 set to "b", except that there is no extra empty item when the
9072 result ends in a NL.
9073 Note that on MS-Windows you may get trailing CR characters.
9074
9075 To see the difference between "echo hello" and "echo -n hello"
9076 use |system()| and |split()|: >
9077 echo system('echo hello')->split('\n', 1)
9078<
9079 Returns an empty string on error.
9080
9081 Can also be used as a |method|: >
9082 :echo GetCmd()->systemlist()
9083
9084
9085tabpagebuflist([{arg}]) *tabpagebuflist()*
9086 The result is a |List|, where each item is the number of the
9087 buffer associated with each window in the current tab page.
9088 {arg} specifies the number of the tab page to be used. When
9089 omitted the current tab page is used.
9090 When {arg} is invalid the number zero is returned.
9091 To get a list of all buffers in all tabs use this: >
9092 let buflist = []
9093 for i in range(tabpagenr('$'))
9094 call extend(buflist, tabpagebuflist(i + 1))
9095 endfor
9096< Note that a buffer may appear in more than one window.
9097
9098 Can also be used as a |method|: >
9099 GetTabpage()->tabpagebuflist()
9100
9101tabpagenr([{arg}]) *tabpagenr()*
9102 The result is a Number, which is the number of the current
9103 tab page. The first tab page has number 1.
9104
9105 The optional argument {arg} supports the following values:
9106 $ the number of the last tab page (the tab page
9107 count).
9108 # the number of the last accessed tab page
9109 (where |g<Tab>| goes to). if there is no
9110 previous tab page 0 is returned.
9111 The number can be used with the |:tab| command.
9112
9113
9114tabpagewinnr({tabarg} [, {arg}]) *tabpagewinnr()*
9115 Like |winnr()| but for tab page {tabarg}.
9116 {tabarg} specifies the number of tab page to be used.
9117 {arg} is used like with |winnr()|:
9118 - When omitted the current window number is returned. This is
9119 the window which will be used when going to this tab page.
9120 - When "$" the number of windows is returned.
9121 - When "#" the previous window nr is returned.
9122 Useful examples: >
9123 tabpagewinnr(1) " current window of tab page 1
9124 tabpagewinnr(4, '$') " number of windows in tab page 4
9125< When {tabarg} is invalid zero is returned.
9126
9127 Can also be used as a |method|: >
9128 GetTabpage()->tabpagewinnr()
9129<
9130 *tagfiles()*
9131tagfiles() Returns a |List| with the file names used to search for tags
9132 for the current buffer. This is the 'tags' option expanded.
9133
9134
9135taglist({expr} [, {filename}]) *taglist()*
9136 Returns a |List| of tags matching the regular expression {expr}.
9137
9138 If {filename} is passed it is used to prioritize the results
9139 in the same way that |:tselect| does. See |tag-priority|.
9140 {filename} should be the full path of the file.
9141
9142 Each list item is a dictionary with at least the following
9143 entries:
9144 name Name of the tag.
9145 filename Name of the file where the tag is
9146 defined. It is either relative to the
9147 current directory or a full path.
9148 cmd Ex command used to locate the tag in
9149 the file.
9150 kind Type of the tag. The value for this
9151 entry depends on the language specific
9152 kind values. Only available when
9153 using a tags file generated by
Bram Moolenaar47c532e2022-03-19 15:18:53 +00009154 Universal/Exuberant ctags or hdrtag.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009155 static A file specific tag. Refer to
9156 |static-tag| for more information.
9157 More entries may be present, depending on the content of the
9158 tags file: access, implementation, inherits and signature.
9159 Refer to the ctags documentation for information about these
9160 fields. For C code the fields "struct", "class" and "enum"
9161 may appear, they give the name of the entity the tag is
9162 contained in.
9163
9164 The ex-command "cmd" can be either an ex search pattern, a
9165 line number or a line number followed by a byte number.
9166
9167 If there are no matching tags, then an empty list is returned.
9168
9169 To get an exact tag match, the anchors '^' and '$' should be
9170 used in {expr}. This also make the function work faster.
9171 Refer to |tag-regexp| for more information about the tag
9172 search regular expression pattern.
9173
9174 Refer to |'tags'| for information about how the tags file is
9175 located by Vim. Refer to |tags-file-format| for the format of
9176 the tags file generated by the different ctags tools.
9177
9178 Can also be used as a |method|: >
9179 GetTagpattern()->taglist()
9180
9181tan({expr}) *tan()*
9182 Return the tangent of {expr}, measured in radians, as a |Float|
9183 in the range [-inf, inf].
9184 {expr} must evaluate to a |Float| or a |Number|.
9185 Examples: >
9186 :echo tan(10)
9187< 0.648361 >
9188 :echo tan(-4.01)
9189< -1.181502
9190
9191 Can also be used as a |method|: >
9192 Compute()->tan()
9193<
9194 {only available when compiled with the |+float| feature}
9195
9196
9197tanh({expr}) *tanh()*
9198 Return the hyperbolic tangent of {expr} as a |Float| in the
9199 range [-1, 1].
9200 {expr} must evaluate to a |Float| or a |Number|.
9201 Examples: >
9202 :echo tanh(0.5)
9203< 0.462117 >
9204 :echo tanh(-1)
9205< -0.761594
9206
9207 Can also be used as a |method|: >
9208 Compute()->tanh()
9209<
9210 {only available when compiled with the |+float| feature}
9211
9212
9213tempname() *tempname()* *temp-file-name*
9214 The result is a String, which is the name of a file that
9215 doesn't exist. It can be used for a temporary file. The name
9216 is different for at least 26 consecutive calls. Example: >
9217 :let tmpfile = tempname()
Bram Moolenaarc51cf032022-02-26 12:25:45 +00009218 :exe "redir > " .. tmpfile
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009219< For Unix, the file will be in a private directory |tempfile|.
9220 For MS-Windows forward slashes are used when the 'shellslash'
9221 option is set, or when 'shellcmdflag' starts with '-' and
9222 'shell' does not contain powershell or pwsh.
9223
9224
9225term_ functions are documented here: |terminal-function-details|
9226
9227
9228terminalprops() *terminalprops()*
9229 Returns a |Dictionary| with properties of the terminal that Vim
9230 detected from the response to |t_RV| request. See
9231 |v:termresponse| for the response itself. If |v:termresponse|
9232 is empty most values here will be 'u' for unknown.
9233 cursor_style whether sending |t_RS| works **
9234 cursor_blink_mode whether sending |t_RC| works **
9235 underline_rgb whether |t_8u| works **
9236 mouse mouse type supported
9237
9238 ** value 'u' for unknown, 'y' for yes, 'n' for no
9239
9240 If the |+termresponse| feature is missing then the result is
9241 an empty dictionary.
9242
9243 If "cursor_style" is 'y' then |t_RS| will be sent to request the
9244 current cursor style.
9245 If "cursor_blink_mode" is 'y' then |t_RC| will be sent to
9246 request the cursor blink status.
9247 "cursor_style" and "cursor_blink_mode" are also set if |t_u7|
9248 is not empty, Vim will detect the working of sending |t_RS|
9249 and |t_RC| on startup.
9250
9251 When "underline_rgb" is not 'y', then |t_8u| will be made empty.
9252 This avoids sending it to xterm, which would clear the colors.
9253
9254 For "mouse" the value 'u' is unknown
9255
9256 Also see:
9257 - 'ambiwidth' - detected by using |t_u7|.
9258 - |v:termstyleresp| and |v:termblinkresp| for the response to
9259 |t_RS| and |t_RC|.
9260
9261
9262test_ functions are documented here: |test-functions-details|
9263
9264
9265 *timer_info()*
9266timer_info([{id}])
9267 Return a list with information about timers.
9268 When {id} is given only information about this timer is
9269 returned. When timer {id} does not exist an empty list is
9270 returned.
9271 When {id} is omitted information about all timers is returned.
9272
9273 For each timer the information is stored in a |Dictionary| with
9274 these items:
9275 "id" the timer ID
9276 "time" time the timer was started with
9277 "remaining" time until the timer fires
9278 "repeat" number of times the timer will still fire;
9279 -1 means forever
9280 "callback" the callback
9281 "paused" 1 if the timer is paused, 0 otherwise
9282
9283 Can also be used as a |method|: >
9284 GetTimer()->timer_info()
9285
9286< {only available when compiled with the |+timers| feature}
9287
9288timer_pause({timer}, {paused}) *timer_pause()*
9289 Pause or unpause a timer. A paused timer does not invoke its
9290 callback when its time expires. Unpausing a timer may cause
9291 the callback to be invoked almost immediately if enough time
9292 has passed.
9293
9294 Pausing a timer is useful to avoid the callback to be called
9295 for a short time.
9296
9297 If {paused} evaluates to a non-zero Number or a non-empty
9298 String, then the timer is paused, otherwise it is unpaused.
9299 See |non-zero-arg|.
9300
9301 Can also be used as a |method|: >
9302 GetTimer()->timer_pause(1)
9303
9304< {only available when compiled with the |+timers| feature}
9305
9306 *timer_start()* *timer* *timers*
9307timer_start({time}, {callback} [, {options}])
9308 Create a timer and return the timer ID.
9309
9310 {time} is the waiting time in milliseconds. This is the
9311 minimum time before invoking the callback. When the system is
9312 busy or Vim is not waiting for input the time will be longer.
9313
9314 {callback} is the function to call. It can be the name of a
9315 function or a |Funcref|. It is called with one argument, which
9316 is the timer ID. The callback is only invoked when Vim is
9317 waiting for input.
9318 If you want to show a message look at |popup_notification()|
9319 to avoid interfering with what the user is doing.
9320
9321 {options} is a dictionary. Supported entries:
9322 "repeat" Number of times to repeat calling the
9323 callback. -1 means forever. When not present
9324 the callback will be called once.
9325 If the timer causes an error three times in a
9326 row the repeat is cancelled. This avoids that
9327 Vim becomes unusable because of all the error
9328 messages.
9329
9330 Example: >
9331 func MyHandler(timer)
9332 echo 'Handler called'
9333 endfunc
9334 let timer = timer_start(500, 'MyHandler',
9335 \ {'repeat': 3})
9336< This will invoke MyHandler() three times at 500 msec
9337 intervals.
9338
9339 Can also be used as a |method|: >
9340 GetMsec()->timer_start(callback)
9341
9342< Not available in the |sandbox|.
9343 {only available when compiled with the |+timers| feature}
9344
9345timer_stop({timer}) *timer_stop()*
9346 Stop a timer. The timer callback will no longer be invoked.
9347 {timer} is an ID returned by timer_start(), thus it must be a
9348 Number. If {timer} does not exist there is no error.
9349
9350 Can also be used as a |method|: >
9351 GetTimer()->timer_stop()
9352
9353< {only available when compiled with the |+timers| feature}
9354
9355timer_stopall() *timer_stopall()*
9356 Stop all timers. The timer callbacks will no longer be
9357 invoked. Useful if a timer is misbehaving. If there are no
9358 timers there is no error.
9359
9360 {only available when compiled with the |+timers| feature}
9361
9362tolower({expr}) *tolower()*
9363 The result is a copy of the String given, with all uppercase
9364 characters turned into lowercase (just like applying |gu| to
9365 the string).
9366
9367 Can also be used as a |method|: >
9368 GetText()->tolower()
9369
9370toupper({expr}) *toupper()*
9371 The result is a copy of the String given, with all lowercase
9372 characters turned into uppercase (just like applying |gU| to
9373 the string).
9374
9375 Can also be used as a |method|: >
9376 GetText()->toupper()
9377
9378tr({src}, {fromstr}, {tostr}) *tr()*
9379 The result is a copy of the {src} string with all characters
9380 which appear in {fromstr} replaced by the character in that
9381 position in the {tostr} string. Thus the first character in
9382 {fromstr} is translated into the first character in {tostr}
9383 and so on. Exactly like the unix "tr" command.
9384 This code also deals with multibyte characters properly.
9385
9386 Examples: >
9387 echo tr("hello there", "ht", "HT")
9388< returns "Hello THere" >
9389 echo tr("<blob>", "<>", "{}")
9390< returns "{blob}"
9391
9392 Can also be used as a |method|: >
9393 GetText()->tr(from, to)
9394
9395trim({text} [, {mask} [, {dir}]]) *trim()*
9396 Return {text} as a String where any character in {mask} is
9397 removed from the beginning and/or end of {text}.
9398
9399 If {mask} is not given, {mask} is all characters up to 0x20,
9400 which includes Tab, space, NL and CR, plus the non-breaking
9401 space character 0xa0.
9402
9403 The optional {dir} argument specifies where to remove the
9404 characters:
9405 0 remove from the beginning and end of {text}
9406 1 remove only at the beginning of {text}
9407 2 remove only at the end of {text}
9408 When omitted both ends are trimmed.
9409
9410 This function deals with multibyte characters properly.
9411
9412 Examples: >
9413 echo trim(" some text ")
9414< returns "some text" >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00009415 echo trim(" \r\t\t\r RESERVE \t\n\x0B\xA0") .. "_TAIL"
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009416< returns "RESERVE_TAIL" >
9417 echo trim("rm<Xrm<>X>rrm", "rm<>")
9418< returns "Xrm<>X" (characters in the middle are not removed) >
9419 echo trim(" vim ", " ", 2)
9420< returns " vim"
9421
9422 Can also be used as a |method|: >
9423 GetText()->trim()
9424
9425trunc({expr}) *trunc()*
9426 Return the largest integral value with magnitude less than or
9427 equal to {expr} as a |Float| (truncate towards zero).
9428 {expr} must evaluate to a |Float| or a |Number|.
9429 Examples: >
9430 echo trunc(1.456)
9431< 1.0 >
9432 echo trunc(-5.456)
9433< -5.0 >
9434 echo trunc(4.0)
9435< 4.0
9436
9437 Can also be used as a |method|: >
9438 Compute()->trunc()
9439<
9440 {only available when compiled with the |+float| feature}
9441
9442 *type()*
9443type({expr}) The result is a Number representing the type of {expr}.
9444 Instead of using the number directly, it is better to use the
9445 v:t_ variable that has the value:
9446 Number: 0 |v:t_number|
9447 String: 1 |v:t_string|
9448 Funcref: 2 |v:t_func|
9449 List: 3 |v:t_list|
9450 Dictionary: 4 |v:t_dict|
9451 Float: 5 |v:t_float|
9452 Boolean: 6 |v:t_bool| (v:false and v:true)
9453 None: 7 |v:t_none| (v:null and v:none)
9454 Job: 8 |v:t_job|
9455 Channel: 9 |v:t_channel|
9456 Blob: 10 |v:t_blob|
9457 For backward compatibility, this method can be used: >
9458 :if type(myvar) == type(0)
9459 :if type(myvar) == type("")
9460 :if type(myvar) == type(function("tr"))
9461 :if type(myvar) == type([])
9462 :if type(myvar) == type({})
9463 :if type(myvar) == type(0.0)
9464 :if type(myvar) == type(v:false)
9465 :if type(myvar) == type(v:none)
9466< To check if the v:t_ variables exist use this: >
9467 :if exists('v:t_number')
9468
9469< Can also be used as a |method|: >
9470 mylist->type()
9471
9472
9473typename({expr}) *typename()*
9474 Return a string representation of the type of {expr}.
9475 Example: >
9476 echo typename([1, 2, 3])
9477 list<number>
9478
9479
9480undofile({name}) *undofile()*
9481 Return the name of the undo file that would be used for a file
9482 with name {name} when writing. This uses the 'undodir'
9483 option, finding directories that exist. It does not check if
9484 the undo file exists.
9485 {name} is always expanded to the full path, since that is what
9486 is used internally.
9487 If {name} is empty undofile() returns an empty string, since a
9488 buffer without a file name will not write an undo file.
9489 Useful in combination with |:wundo| and |:rundo|.
9490 When compiled without the |+persistent_undo| option this always
9491 returns an empty string.
9492
9493 Can also be used as a |method|: >
9494 GetFilename()->undofile()
9495
9496undotree() *undotree()*
9497 Return the current state of the undo tree in a dictionary with
9498 the following items:
9499 "seq_last" The highest undo sequence number used.
9500 "seq_cur" The sequence number of the current position in
9501 the undo tree. This differs from "seq_last"
9502 when some changes were undone.
9503 "time_cur" Time last used for |:earlier| and related
9504 commands. Use |strftime()| to convert to
9505 something readable.
9506 "save_last" Number of the last file write. Zero when no
9507 write yet.
9508 "save_cur" Number of the current position in the undo
9509 tree.
9510 "synced" Non-zero when the last undo block was synced.
9511 This happens when waiting from input from the
9512 user. See |undo-blocks|.
9513 "entries" A list of dictionaries with information about
9514 undo blocks.
9515
9516 The first item in the "entries" list is the oldest undo item.
9517 Each List item is a |Dictionary| with these items:
9518 "seq" Undo sequence number. Same as what appears in
9519 |:undolist|.
9520 "time" Timestamp when the change happened. Use
9521 |strftime()| to convert to something readable.
9522 "newhead" Only appears in the item that is the last one
9523 that was added. This marks the last change
9524 and where further changes will be added.
9525 "curhead" Only appears in the item that is the last one
9526 that was undone. This marks the current
9527 position in the undo tree, the block that will
9528 be used by a redo command. When nothing was
9529 undone after the last change this item will
9530 not appear anywhere.
9531 "save" Only appears on the last block before a file
9532 write. The number is the write count. The
9533 first write has number 1, the last one the
9534 "save_last" mentioned above.
9535 "alt" Alternate entry. This is again a List of undo
9536 blocks. Each item may again have an "alt"
9537 item.
9538
9539uniq({list} [, {func} [, {dict}]]) *uniq()* *E882*
9540 Remove second and succeeding copies of repeated adjacent
9541 {list} items in-place. Returns {list}. If you want a list
9542 to remain unmodified make a copy first: >
9543 :let newlist = uniq(copy(mylist))
9544< The default compare function uses the string representation of
9545 each item. For the use of {func} and {dict} see |sort()|.
9546
9547 Can also be used as a |method|: >
9548 mylist->uniq()
9549
9550values({dict}) *values()*
9551 Return a |List| with all the values of {dict}. The |List| is
9552 in arbitrary order. Also see |items()| and |keys()|.
9553
9554 Can also be used as a |method|: >
9555 mydict->values()
9556
9557virtcol({expr}) *virtcol()*
9558 The result is a Number, which is the screen column of the file
9559 position given with {expr}. That is, the last screen position
9560 occupied by the character at that position, when the screen
9561 would be of unlimited width. When there is a <Tab> at the
9562 position, the returned Number will be the column at the end of
9563 the <Tab>. For example, for a <Tab> in column 1, with 'ts'
9564 set to 8, it returns 8. |conceal| is ignored.
9565 For the byte position use |col()|.
9566 For the use of {expr} see |col()|.
9567 When 'virtualedit' is used {expr} can be [lnum, col, off], where
9568 "off" is the offset in screen columns from the start of the
9569 character. E.g., a position within a <Tab> or after the last
9570 character. When "off" is omitted zero is used.
9571 When Virtual editing is active in the current mode, a position
9572 beyond the end of the line can be returned. |'virtualedit'|
9573 The accepted positions are:
9574 . the cursor position
9575 $ the end of the cursor line (the result is the
9576 number of displayed characters in the cursor line
9577 plus one)
9578 'x position of mark x (if the mark is not set, 0 is
9579 returned)
9580 v In Visual mode: the start of the Visual area (the
9581 cursor is the end). When not in Visual mode
9582 returns the cursor position. Differs from |'<| in
9583 that it's updated right away.
9584 Note that only marks in the current file can be used.
9585 Examples: >
9586 virtcol(".") with text "foo^Lbar", with cursor on the "^L", returns 5
9587 virtcol("$") with text "foo^Lbar", returns 9
9588 virtcol("'t") with text " there", with 't at 'h', returns 6
9589< The first column is 1. 0 is returned for an error.
9590 A more advanced example that echoes the maximum length of
9591 all lines: >
9592 echo max(map(range(1, line('$')), "virtcol([v:val, '$'])"))
9593
9594< Can also be used as a |method|: >
9595 GetPos()->virtcol()
9596
9597
9598visualmode([{expr}]) *visualmode()*
9599 The result is a String, which describes the last Visual mode
9600 used in the current buffer. Initially it returns an empty
9601 string, but once Visual mode has been used, it returns "v",
9602 "V", or "<CTRL-V>" (a single CTRL-V character) for
9603 character-wise, line-wise, or block-wise Visual mode
9604 respectively.
9605 Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00009606 :exe "normal " .. visualmode()
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009607< This enters the same Visual mode as before. It is also useful
9608 in scripts if you wish to act differently depending on the
9609 Visual mode that was used.
9610 If Visual mode is active, use |mode()| to get the Visual mode
9611 (e.g., in a |:vmap|).
9612 If {expr} is supplied and it evaluates to a non-zero Number or
9613 a non-empty String, then the Visual mode will be cleared and
9614 the old value is returned. See |non-zero-arg|.
9615
9616wildmenumode() *wildmenumode()*
9617 Returns |TRUE| when the wildmenu is active and |FALSE|
9618 otherwise. See 'wildmenu' and 'wildmode'.
9619 This can be used in mappings to handle the 'wildcharm' option
9620 gracefully. (Makes only sense with |mapmode-c| mappings).
9621
9622 For example to make <c-j> work like <down> in wildmode, use: >
9623 :cnoremap <expr> <C-j> wildmenumode() ? "\<Down>\<Tab>" : "\<c-j>"
9624<
9625 (Note, this needs the 'wildcharm' option set appropriately).
9626
9627win_execute({id}, {command} [, {silent}]) *win_execute()*
9628 Like `execute()` but in the context of window {id}.
9629 The window will temporarily be made the current window,
9630 without triggering autocommands or changing directory. When
9631 executing {command} autocommands will be triggered, this may
9632 have unexpected side effects. Use |:noautocmd| if needed.
9633 Example: >
9634 call win_execute(winid, 'set syntax=python')
9635< Doing the same with `setwinvar()` would not trigger
9636 autocommands and not actually show syntax highlighting.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009637 *E994*
9638 Not all commands are allowed in popup windows.
9639 When window {id} does not exist then no error is given and
9640 an empty string is returned.
9641
9642 Can also be used as a |method|, the base is passed as the
9643 second argument: >
9644 GetCommand()->win_execute(winid)
9645
9646win_findbuf({bufnr}) *win_findbuf()*
9647 Returns a |List| with |window-ID|s for windows that contain
9648 buffer {bufnr}. When there is none the list is empty.
9649
9650 Can also be used as a |method|: >
9651 GetBufnr()->win_findbuf()
9652
9653win_getid([{win} [, {tab}]]) *win_getid()*
9654 Get the |window-ID| for the specified window.
9655 When {win} is missing use the current window.
9656 With {win} this is the window number. The top window has
9657 number 1.
9658 Without {tab} use the current tab, otherwise the tab with
9659 number {tab}. The first tab has number one.
9660 Return zero if the window cannot be found.
9661
9662 Can also be used as a |method|: >
9663 GetWinnr()->win_getid()
9664
9665
9666win_gettype([{nr}]) *win_gettype()*
9667 Return the type of the window:
9668 "autocmd" autocommand window. Temporary window
9669 used to execute autocommands.
9670 "command" command-line window |cmdwin|
9671 (empty) normal window
9672 "loclist" |location-list-window|
9673 "popup" popup window |popup|
9674 "preview" preview window |preview-window|
9675 "quickfix" |quickfix-window|
9676 "unknown" window {nr} not found
9677
9678 When {nr} is omitted return the type of the current window.
9679 When {nr} is given return the type of this window by number or
9680 |window-ID|.
9681
9682 Also see the 'buftype' option. When running a terminal in a
9683 popup window then 'buftype' is "terminal" and win_gettype()
9684 returns "popup".
9685
9686 Can also be used as a |method|: >
9687 GetWinid()->win_gettype()
9688<
9689win_gotoid({expr}) *win_gotoid()*
9690 Go to window with ID {expr}. This may also change the current
9691 tabpage.
9692 Return TRUE if successful, FALSE if the window cannot be found.
9693
9694 Can also be used as a |method|: >
9695 GetWinid()->win_gotoid()
9696
9697win_id2tabwin({expr}) *win_id2tabwin()*
9698 Return a list with the tab number and window number of window
9699 with ID {expr}: [tabnr, winnr].
9700 Return [0, 0] if the window cannot be found.
9701
9702 Can also be used as a |method|: >
9703 GetWinid()->win_id2tabwin()
9704
9705win_id2win({expr}) *win_id2win()*
9706 Return the window number of window with ID {expr}.
9707 Return 0 if the window cannot be found in the current tabpage.
9708
9709 Can also be used as a |method|: >
9710 GetWinid()->win_id2win()
9711
Daniel Steinbergee630312022-01-10 13:36:34 +00009712win_move_separator({nr}, {offset}) *win_move_separator()*
9713 Move window {nr}'s vertical separator (i.e., the right border)
9714 by {offset} columns, as if being dragged by the mouse. {nr}
9715 can be a window number or |window-ID|. A positive {offset}
9716 moves right and a negative {offset} moves left. Moving a
9717 window's vertical separator will change the width of the
9718 window and the width of other windows adjacent to the vertical
9719 separator. The magnitude of movement may be smaller than
9720 specified (e.g., as a consequence of maintaining
9721 'winminwidth'). Returns TRUE if the window can be found and
9722 FALSE otherwise.
9723
9724 Can also be used as a |method|: >
9725 GetWinnr()->win_move_separator(offset)
9726
9727win_move_statusline({nr}, {offset}) *win_move_statusline()*
9728 Move window {nr}'s status line (i.e., the bottom border) by
9729 {offset} rows, as if being dragged by the mouse. {nr} can be a
9730 window number or |window-ID|. A positive {offset} moves down
9731 and a negative {offset} moves up. Moving a window's status
9732 line will change the height of the window and the height of
9733 other windows adjacent to the status line. The magnitude of
9734 movement may be smaller than specified (e.g., as a consequence
9735 of maintaining 'winminheight'). Returns TRUE if the window can
9736 be found and FALSE otherwise.
9737
9738 Can also be used as a |method|: >
9739 GetWinnr()->win_move_statusline(offset)
9740
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009741win_screenpos({nr}) *win_screenpos()*
9742 Return the screen position of window {nr} as a list with two
9743 numbers: [row, col]. The first window always has position
9744 [1, 1], unless there is a tabline, then it is [2, 1].
9745 {nr} can be the window number or the |window-ID|. Use zero
9746 for the current window.
9747 Returns [0, 0] if the window cannot be found in the current
9748 tabpage.
9749
9750 Can also be used as a |method|: >
9751 GetWinid()->win_screenpos()
9752<
9753win_splitmove({nr}, {target} [, {options}]) *win_splitmove()*
9754 Move the window {nr} to a new split of the window {target}.
9755 This is similar to moving to {target}, creating a new window
9756 using |:split| but having the same contents as window {nr}, and
9757 then closing {nr}.
9758
9759 Both {nr} and {target} can be window numbers or |window-ID|s.
9760 Both must be in the current tab page.
9761
9762 Returns zero for success, non-zero for failure.
9763
9764 {options} is a |Dictionary| with the following optional entries:
9765 "vertical" When TRUE, the split is created vertically,
9766 like with |:vsplit|.
9767 "rightbelow" When TRUE, the split is made below or to the
9768 right (if vertical). When FALSE, it is done
9769 above or to the left (if vertical). When not
9770 present, the values of 'splitbelow' and
9771 'splitright' are used.
9772
9773 Can also be used as a |method|: >
9774 GetWinid()->win_splitmove(target)
9775<
9776
9777 *winbufnr()*
9778winbufnr({nr}) The result is a Number, which is the number of the buffer
9779 associated with window {nr}. {nr} can be the window number or
9780 the |window-ID|.
9781 When {nr} is zero, the number of the buffer in the current
9782 window is returned.
9783 When window {nr} doesn't exist, -1 is returned.
9784 Example: >
9785 :echo "The file in the current window is " . bufname(winbufnr(0))
9786<
9787 Can also be used as a |method|: >
9788 FindWindow()->winbufnr()->bufname()
9789<
9790 *wincol()*
9791wincol() The result is a Number, which is the virtual column of the
9792 cursor in the window. This is counting screen cells from the
9793 left side of the window. The leftmost column is one.
9794
9795 *windowsversion()*
9796windowsversion()
9797 The result is a String. For MS-Windows it indicates the OS
9798 version. E.g, Windows 10 is "10.0", Windows 8 is "6.2",
9799 Windows XP is "5.1". For non-MS-Windows systems the result is
9800 an empty string.
9801
9802winheight({nr}) *winheight()*
9803 The result is a Number, which is the height of window {nr}.
9804 {nr} can be the window number or the |window-ID|.
9805 When {nr} is zero, the height of the current window is
9806 returned. When window {nr} doesn't exist, -1 is returned.
9807 An existing window always has a height of zero or more.
9808 This excludes any window toolbar line.
9809 Examples: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00009810 :echo "The current window has " .. winheight(0) .. " lines."
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009811
9812< Can also be used as a |method|: >
9813 GetWinid()->winheight()
9814<
9815winlayout([{tabnr}]) *winlayout()*
9816 The result is a nested List containing the layout of windows
9817 in a tabpage.
9818
9819 Without {tabnr} use the current tabpage, otherwise the tabpage
9820 with number {tabnr}. If the tabpage {tabnr} is not found,
9821 returns an empty list.
9822
9823 For a leaf window, it returns:
9824 ['leaf', {winid}]
9825 For horizontally split windows, which form a column, it
9826 returns:
9827 ['col', [{nested list of windows}]]
9828 For vertically split windows, which form a row, it returns:
9829 ['row', [{nested list of windows}]]
9830
9831 Example: >
9832 " Only one window in the tab page
9833 :echo winlayout()
9834 ['leaf', 1000]
9835 " Two horizontally split windows
9836 :echo winlayout()
9837 ['col', [['leaf', 1000], ['leaf', 1001]]]
9838 " The second tab page, with three horizontally split
9839 " windows, with two vertically split windows in the
9840 " middle window
9841 :echo winlayout(2)
9842 ['col', [['leaf', 1002], ['row', [['leaf', 1003],
9843 ['leaf', 1001]]], ['leaf', 1000]]]
9844<
9845 Can also be used as a |method|: >
9846 GetTabnr()->winlayout()
9847<
9848 *winline()*
9849winline() The result is a Number, which is the screen line of the cursor
9850 in the window. This is counting screen lines from the top of
9851 the window. The first line is one.
9852 If the cursor was moved the view on the file will be updated
9853 first, this may cause a scroll.
9854
9855 *winnr()*
9856winnr([{arg}]) The result is a Number, which is the number of the current
9857 window. The top window has number 1.
9858 Returns zero for a popup window.
9859
9860 The optional argument {arg} supports the following values:
9861 $ the number of the last window (the window
9862 count).
9863 # the number of the last accessed window (where
9864 |CTRL-W_p| goes to). If there is no previous
9865 window or it is in another tab page 0 is
9866 returned.
9867 {N}j the number of the Nth window below the
9868 current window (where |CTRL-W_j| goes to).
9869 {N}k the number of the Nth window above the current
9870 window (where |CTRL-W_k| goes to).
9871 {N}h the number of the Nth window left of the
9872 current window (where |CTRL-W_h| goes to).
9873 {N}l the number of the Nth window right of the
9874 current window (where |CTRL-W_l| goes to).
9875 The number can be used with |CTRL-W_w| and ":wincmd w"
9876 |:wincmd|.
9877 Also see |tabpagewinnr()| and |win_getid()|.
9878 Examples: >
9879 let window_count = winnr('$')
9880 let prev_window = winnr('#')
9881 let wnum = winnr('3k')
9882
9883< Can also be used as a |method|: >
9884 GetWinval()->winnr()
9885<
9886 *winrestcmd()*
9887winrestcmd() Returns a sequence of |:resize| commands that should restore
9888 the current window sizes. Only works properly when no windows
9889 are opened or closed and the current window and tab page is
9890 unchanged.
9891 Example: >
9892 :let cmd = winrestcmd()
9893 :call MessWithWindowSizes()
9894 :exe cmd
9895<
9896 *winrestview()*
9897winrestview({dict})
9898 Uses the |Dictionary| returned by |winsaveview()| to restore
9899 the view of the current window.
9900 Note: The {dict} does not have to contain all values, that are
9901 returned by |winsaveview()|. If values are missing, those
9902 settings won't be restored. So you can use: >
9903 :call winrestview({'curswant': 4})
9904<
9905 This will only set the curswant value (the column the cursor
9906 wants to move on vertical movements) of the cursor to column 5
9907 (yes, that is 5), while all other settings will remain the
9908 same. This is useful, if you set the cursor position manually.
9909
9910 If you have changed the values the result is unpredictable.
9911 If the window size changed the result won't be the same.
9912
9913 Can also be used as a |method|: >
9914 GetView()->winrestview()
9915<
9916 *winsaveview()*
9917winsaveview() Returns a |Dictionary| that contains information to restore
9918 the view of the current window. Use |winrestview()| to
9919 restore the view.
9920 This is useful if you have a mapping that jumps around in the
9921 buffer and you want to go back to the original view.
9922 This does not save fold information. Use the 'foldenable'
9923 option to temporarily switch off folding, so that folds are
9924 not opened when moving around. This may have side effects.
9925 The return value includes:
9926 lnum cursor line number
9927 col cursor column (Note: the first column
naohiro ono56200ee2022-01-01 14:59:44 +00009928 zero, as opposed to what |getcurpos()|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009929 returns)
9930 coladd cursor column offset for 'virtualedit'
naohiro ono56200ee2022-01-01 14:59:44 +00009931 curswant column for vertical movement (Note:
9932 the first column is zero, as opposed
9933 to what |getcurpos()| returns). After
9934 |$| command it will be a very large
9935 number equal to |v:maxcol|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009936 topline first line in the window
9937 topfill filler lines, only in diff mode
9938 leftcol first column displayed; only used when
9939 'wrap' is off
9940 skipcol columns skipped
9941 Note that no option values are saved.
9942
9943
9944winwidth({nr}) *winwidth()*
9945 The result is a Number, which is the width of window {nr}.
9946 {nr} can be the window number or the |window-ID|.
9947 When {nr} is zero, the width of the current window is
9948 returned. When window {nr} doesn't exist, -1 is returned.
9949 An existing window always has a width of zero or more.
9950 Examples: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00009951 :echo "The current window has " .. winwidth(0) .. " columns."
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009952 :if winwidth(0) <= 50
9953 : 50 wincmd |
9954 :endif
9955< For getting the terminal or screen size, see the 'columns'
9956 option.
9957
9958 Can also be used as a |method|: >
9959 GetWinid()->winwidth()
9960
9961
9962wordcount() *wordcount()*
9963 The result is a dictionary of byte/chars/word statistics for
9964 the current buffer. This is the same info as provided by
9965 |g_CTRL-G|
9966 The return value includes:
9967 bytes Number of bytes in the buffer
9968 chars Number of chars in the buffer
9969 words Number of words in the buffer
9970 cursor_bytes Number of bytes before cursor position
9971 (not in Visual mode)
9972 cursor_chars Number of chars before cursor position
9973 (not in Visual mode)
9974 cursor_words Number of words before cursor position
9975 (not in Visual mode)
9976 visual_bytes Number of bytes visually selected
9977 (only in Visual mode)
9978 visual_chars Number of chars visually selected
9979 (only in Visual mode)
9980 visual_words Number of words visually selected
9981 (only in Visual mode)
9982
9983
9984 *writefile()*
9985writefile({object}, {fname} [, {flags}])
9986 When {object} is a |List| write it to file {fname}. Each list
9987 item is separated with a NL. Each list item must be a String
9988 or Number.
9989 When {flags} contains "b" then binary mode is used: There will
9990 not be a NL after the last list item. An empty item at the
9991 end does cause the last line in the file to end in a NL.
9992
9993 When {object} is a |Blob| write the bytes to file {fname}
9994 unmodified.
9995
9996 When {flags} contains "a" then append mode is used, lines are
9997 appended to the file: >
9998 :call writefile(["foo"], "event.log", "a")
9999 :call writefile(["bar"], "event.log", "a")
10000<
10001 When {flags} contains "s" then fsync() is called after writing
10002 the file. This flushes the file to disk, if possible. This
10003 takes more time but avoids losing the file if the system
10004 crashes.
10005 When {flags} does not contain "S" or "s" then fsync() is
10006 called if the 'fsync' option is set.
10007 When {flags} contains "S" then fsync() is not called, even
10008 when 'fsync' is set.
10009
10010 All NL characters are replaced with a NUL character.
10011 Inserting CR characters needs to be done before passing {list}
10012 to writefile().
10013 An existing file is overwritten, if possible.
10014 When the write fails -1 is returned, otherwise 0. There is an
10015 error message if the file can't be created or when writing
10016 fails.
10017 Also see |readfile()|.
10018 To copy a file byte for byte: >
10019 :let fl = readfile("foo", "b")
10020 :call writefile(fl, "foocopy", "b")
10021
10022< Can also be used as a |method|: >
10023 GetText()->writefile("thefile")
10024
10025
10026xor({expr}, {expr}) *xor()*
10027 Bitwise XOR on the two arguments. The arguments are converted
10028 to a number. A List, Dict or Float argument causes an error.
10029 Example: >
10030 :let bits = xor(bits, 0x80)
10031<
10032 Can also be used as a |method|: >
10033 :let bits = bits->xor(0x80)
10034<
10035
10036==============================================================================
100373. Feature list *feature-list*
10038
10039There are three types of features:
100401. Features that are only supported when they have been enabled when Vim
10041 was compiled |+feature-list|. Example: >
10042 :if has("cindent")
10043< *gui_running*
100442. Features that are only supported when certain conditions have been met.
10045 Example: >
10046 :if has("gui_running")
10047< *has-patch*
100483. Beyond a certain version or at a certain version and including a specific
10049 patch. The "patch-7.4.248" feature means that the Vim version is 7.5 or
10050 later, or it is version 7.4 and patch 248 was included. Example: >
10051 :if has("patch-7.4.248")
10052< Note that it's possible for patch 248 to be omitted even though 249 is
10053 included. Only happens when cherry-picking patches.
10054 Note that this form only works for patch 7.4.237 and later, before that
10055 you need to check for the patch and the v:version. Example (checking
10056 version 6.2.148 or later): >
10057 :if v:version > 602 || (v:version == 602 && has("patch148"))
10058
10059Hint: To find out if Vim supports backslashes in a file name (MS-Windows),
10060use: `if exists('+shellslash')`
10061
10062
10063acl Compiled with |ACL| support.
10064all_builtin_terms Compiled with all builtin terminals enabled.
10065amiga Amiga version of Vim.
10066arabic Compiled with Arabic support |Arabic|.
10067arp Compiled with ARP support (Amiga).
10068autocmd Compiled with autocommand support. (always true)
10069autochdir Compiled with support for 'autochdir'
10070autoservername Automatically enable |clientserver|
10071balloon_eval Compiled with |balloon-eval| support.
10072balloon_multiline GUI supports multiline balloons.
10073beos BeOS version of Vim.
10074browse Compiled with |:browse| support, and browse() will
10075 work.
10076browsefilter Compiled with support for |browsefilter|.
10077bsd Compiled on an OS in the BSD family (excluding macOS).
10078builtin_terms Compiled with some builtin terminals.
10079byte_offset Compiled with support for 'o' in 'statusline'
10080channel Compiled with support for |channel| and |job|
10081cindent Compiled with 'cindent' support.
10082clientserver Compiled with remote invocation support |clientserver|.
10083clipboard Compiled with 'clipboard' support.
10084clipboard_working Compiled with 'clipboard' support and it can be used.
10085cmdline_compl Compiled with |cmdline-completion| support.
10086cmdline_hist Compiled with |cmdline-history| support.
10087cmdline_info Compiled with 'showcmd' and 'ruler' support.
10088comments Compiled with |'comments'| support.
10089compatible Compiled to be very Vi compatible.
10090conpty Platform where |ConPTY| can be used.
10091cryptv Compiled with encryption support |encryption|.
10092cscope Compiled with |cscope| support.
10093cursorbind Compiled with |'cursorbind'| (always true)
10094debug Compiled with "DEBUG" defined.
10095dialog_con Compiled with console dialog support.
10096dialog_gui Compiled with GUI dialog support.
10097diff Compiled with |vimdiff| and 'diff' support.
10098digraphs Compiled with support for digraphs.
10099directx Compiled with support for DirectX and 'renderoptions'.
10100dnd Compiled with support for the "~ register |quote_~|.
10101drop_file Compiled with |drop_file| support.
10102ebcdic Compiled on a machine with ebcdic character set.
10103emacs_tags Compiled with support for Emacs tags.
10104eval Compiled with expression evaluation support. Always
10105 true, of course!
10106ex_extra |+ex_extra| (always true)
10107extra_search Compiled with support for |'incsearch'| and
10108 |'hlsearch'|
10109farsi Support for Farsi was removed |farsi|.
10110file_in_path Compiled with support for |gf| and |<cfile>|
10111filterpipe When 'shelltemp' is off pipes are used for shell
10112 read/write/filter commands
10113find_in_path Compiled with support for include file searches
10114 |+find_in_path|.
10115float Compiled with support for |Float|.
10116fname_case Case in file names matters (for Amiga and MS-Windows
10117 this is not present).
10118folding Compiled with |folding| support.
10119footer Compiled with GUI footer support. |gui-footer|
10120fork Compiled to use fork()/exec() instead of system().
10121gettext Compiled with message translation |multi-lang|
10122gui Compiled with GUI enabled.
Bram Moolenaarcbaff5e2022-04-08 17:45:08 +010010123gui_athena Compiled with Athena GUI (always false).
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010124gui_gnome Compiled with Gnome support (gui_gtk is also defined).
10125gui_gtk Compiled with GTK+ GUI (any version).
10126gui_gtk2 Compiled with GTK+ 2 GUI (gui_gtk is also defined).
10127gui_gtk3 Compiled with GTK+ 3 GUI (gui_gtk is also defined).
10128gui_haiku Compiled with Haiku GUI.
10129gui_mac Compiled with Macintosh GUI.
10130gui_motif Compiled with Motif GUI.
10131gui_photon Compiled with Photon GUI.
10132gui_running Vim is running in the GUI, or it will start soon.
10133gui_win32 Compiled with MS-Windows Win32 GUI.
10134gui_win32s idem, and Win32s system being used (Windows 3.1)
10135haiku Haiku version of Vim.
10136hangul_input Compiled with Hangul input support. |hangul|
10137hpux HP-UX version of Vim.
10138iconv Can use iconv() for conversion.
10139insert_expand Compiled with support for CTRL-X expansion commands in
10140 Insert mode. (always true)
10141job Compiled with support for |channel| and |job|
10142ipv6 Compiled with support for IPv6 networking in |channel|.
10143jumplist Compiled with |jumplist| support.
10144keymap Compiled with 'keymap' support.
10145lambda Compiled with |lambda| support.
10146langmap Compiled with 'langmap' support.
10147libcall Compiled with |libcall()| support.
10148linebreak Compiled with 'linebreak', 'breakat', 'showbreak' and
10149 'breakindent' support.
10150linux Linux version of Vim.
10151lispindent Compiled with support for lisp indenting.
10152listcmds Compiled with commands for the buffer list |:files|
10153 and the argument list |arglist|.
10154localmap Compiled with local mappings and abbr. |:map-local|
10155lua Compiled with Lua interface |Lua|.
10156mac Any Macintosh version of Vim cf. osx
10157macunix Synonym for osxdarwin
10158menu Compiled with support for |:menu|.
10159mksession Compiled with support for |:mksession|.
10160modify_fname Compiled with file name modifiers. |filename-modifiers|
10161 (always true)
10162mouse Compiled with support for mouse.
10163mouse_dec Compiled with support for Dec terminal mouse.
10164mouse_gpm Compiled with support for gpm (Linux console mouse)
10165mouse_gpm_enabled GPM mouse is working
10166mouse_netterm Compiled with support for netterm mouse.
10167mouse_pterm Compiled with support for qnx pterm mouse.
10168mouse_sysmouse Compiled with support for sysmouse (*BSD console mouse)
10169mouse_sgr Compiled with support for sgr mouse.
10170mouse_urxvt Compiled with support for urxvt mouse.
10171mouse_xterm Compiled with support for xterm mouse.
10172mouseshape Compiled with support for 'mouseshape'.
10173multi_byte Compiled with support for 'encoding' (always true)
10174multi_byte_encoding 'encoding' is set to a multibyte encoding.
10175multi_byte_ime Compiled with support for IME input method.
10176multi_lang Compiled with support for multiple languages.
10177mzscheme Compiled with MzScheme interface |mzscheme|.
10178nanotime Compiled with sub-second time stamp checks.
10179netbeans_enabled Compiled with support for |netbeans| and connected.
10180netbeans_intg Compiled with support for |netbeans|.
10181num64 Compiled with 64-bit |Number| support.
10182ole Compiled with OLE automation support for Win32.
10183osx Compiled for macOS cf. mac
10184osxdarwin Compiled for macOS, with |mac-darwin-feature|
10185packages Compiled with |packages| support.
10186path_extra Compiled with up/downwards search in 'path' and 'tags'
10187perl Compiled with Perl interface.
10188persistent_undo Compiled with support for persistent undo history.
10189postscript Compiled with PostScript file printing.
10190printer Compiled with |:hardcopy| support.
10191profile Compiled with |:profile| support.
10192python Python 2.x interface available. |has-python|
10193python_compiled Compiled with Python 2.x interface. |has-python|
10194python_dynamic Python 2.x interface is dynamically loaded. |has-python|
10195python3 Python 3.x interface available. |has-python|
10196python3_compiled Compiled with Python 3.x interface. |has-python|
10197python3_dynamic Python 3.x interface is dynamically loaded. |has-python|
10198pythonx Python 2.x and/or 3.x interface available. |python_x|
10199qnx QNX version of Vim.
10200quickfix Compiled with |quickfix| support.
10201reltime Compiled with |reltime()| support.
10202rightleft Compiled with 'rightleft' support.
10203ruby Compiled with Ruby interface |ruby|.
10204scrollbind Compiled with 'scrollbind' support. (always true)
10205showcmd Compiled with 'showcmd' support.
10206signs Compiled with |:sign| support.
10207smartindent Compiled with 'smartindent' support.
10208sodium Compiled with libsodium for better crypt support
10209sound Compiled with sound support, e.g. `sound_playevent()`
10210spell Compiled with spell checking support |spell|.
10211startuptime Compiled with |--startuptime| support.
10212statusline Compiled with support for 'statusline', 'rulerformat'
10213 and special formats of 'titlestring' and 'iconstring'.
10214sun SunOS version of Vim.
10215sun_workshop Support for Sun |workshop| has been removed.
10216syntax Compiled with syntax highlighting support |syntax|.
10217syntax_items There are active syntax highlighting items for the
10218 current buffer.
10219system Compiled to use system() instead of fork()/exec().
10220tag_binary Compiled with binary searching in tags files
10221 |tag-binary-search|.
10222tag_old_static Support for old static tags was removed, see
10223 |tag-old-static|.
10224tcl Compiled with Tcl interface.
10225termguicolors Compiled with true color in terminal support.
10226terminal Compiled with |terminal| support.
10227terminfo Compiled with terminfo instead of termcap.
10228termresponse Compiled with support for |t_RV| and |v:termresponse|.
10229textobjects Compiled with support for |text-objects|.
10230textprop Compiled with support for |text-properties|.
10231tgetent Compiled with tgetent support, able to use a termcap
10232 or terminfo file.
10233timers Compiled with |timer_start()| support.
10234title Compiled with window title support |'title'|.
10235toolbar Compiled with support for |gui-toolbar|.
10236ttyin input is a terminal (tty)
10237ttyout output is a terminal (tty)
10238unix Unix version of Vim. *+unix*
10239unnamedplus Compiled with support for "unnamedplus" in 'clipboard'
10240user_commands User-defined commands. (always true)
10241vartabs Compiled with variable tabstop support |'vartabstop'|.
10242vcon Win32: Virtual console support is working, can use
10243 'termguicolors'. Also see |+vtp|.
10244vertsplit Compiled with vertically split windows |:vsplit|.
10245 (always true)
10246vim_starting True while initial source'ing takes place. |startup|
10247 *vim_starting*
Bram Moolenaara6feb162022-01-02 12:06:33 +000010248vim9script Compiled with |Vim9| script support
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010249viminfo Compiled with viminfo support.
10250vimscript-1 Compiled Vim script version 1 support
10251vimscript-2 Compiled Vim script version 2 support
10252vimscript-3 Compiled Vim script version 3 support
10253virtualedit Compiled with 'virtualedit' option. (always true)
10254visual Compiled with Visual mode. (always true)
10255visualextra Compiled with extra Visual mode commands. (always
10256 true) |blockwise-operators|.
10257vms VMS version of Vim.
10258vreplace Compiled with |gR| and |gr| commands. (always true)
10259vtp Compiled for vcon support |+vtp| (check vcon to find
10260 out if it works in the current console).
10261wildignore Compiled with 'wildignore' option.
10262wildmenu Compiled with 'wildmenu' option.
10263win16 old version for MS-Windows 3.1 (always false)
10264win32 Win32 version of Vim (MS-Windows 95 and later, 32 or
10265 64 bits)
10266win32unix Win32 version of Vim, using Unix files (Cygwin)
10267win64 Win64 version of Vim (MS-Windows 64 bit).
10268win95 Win32 version for MS-Windows 95/98/ME (always false)
10269winaltkeys Compiled with 'winaltkeys' option.
10270windows Compiled with support for more than one window.
10271 (always true)
10272writebackup Compiled with 'writebackup' default on.
10273xfontset Compiled with X fontset support |xfontset|.
10274xim Compiled with X input method support |xim|.
10275xpm Compiled with pixmap support.
10276xpm_w32 Compiled with pixmap support for Win32. (Only for
10277 backward compatibility. Use "xpm" instead.)
10278xsmp Compiled with X session management support.
10279xsmp_interact Compiled with interactive X session management support.
10280xterm_clipboard Compiled with support for xterm clipboard.
10281xterm_save Compiled with support for saving and restoring the
10282 xterm screen.
10283x11 Compiled with X11 support.
10284
10285
10286==============================================================================
102874. Matching a pattern in a String *string-match*
10288
10289This is common between several functions. A regexp pattern as explained at
10290|pattern| is normally used to find a match in the buffer lines. When a
10291pattern is used to find a match in a String, almost everything works in the
10292same way. The difference is that a String is handled like it is one line.
10293When it contains a "\n" character, this is not seen as a line break for the
10294pattern. It can be matched with a "\n" in the pattern, or with ".". Example:
10295>
10296 :let a = "aaaa\nxxxx"
10297 :echo matchstr(a, "..\n..")
10298 aa
10299 xx
10300 :echo matchstr(a, "a.x")
10301 a
10302 x
10303
10304Don't forget that "^" will only match at the first character of the String and
10305"$" at the last character of the string. They don't match after or before a
10306"\n".
10307
10308 vim:tw=78:ts=8:noet:ft=help:norl: