blob: cc4e7c4a89c5ee5d9bef0ff445ae906a76b55f89 [file] [log] [blame]
Bram Moolenaareb490412022-06-28 13:44:46 +01001*builtin.txt* For Vim version 9.0. Last change: 2022 Jun 27
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}
Yegappan Lakshmanan1755a912022-05-19 10:31:47 +010063autocmd_add({acmds}) Bool add a list of autocmds and groups
64autocmd_delete({acmds}) Bool delete a list of autocmds and groups
65autocmd_get([{opts}]) List return a list of autocmds
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000066balloon_gettext() String current text in the balloon
67balloon_show({expr}) none show {expr} inside the balloon
68balloon_split({msg}) List split {msg} as used for a balloon
69blob2list({blob}) List convert {blob} into a list of numbers
70browse({save}, {title}, {initdir}, {default})
71 String put up a file requester
72browsedir({title}, {initdir}) String put up a directory requester
73bufadd({name}) Number add a buffer to the buffer list
74bufexists({buf}) Number |TRUE| if buffer {buf} exists
75buflisted({buf}) Number |TRUE| if buffer {buf} is listed
76bufload({buf}) Number load buffer {buf} if not loaded yet
77bufloaded({buf}) Number |TRUE| if buffer {buf} is loaded
78bufname([{buf}]) String Name of the buffer {buf}
79bufnr([{buf} [, {create}]]) Number Number of the buffer {buf}
80bufwinid({buf}) Number window ID of buffer {buf}
81bufwinnr({buf}) Number window number of buffer {buf}
82byte2line({byte}) Number line number at byte count {byte}
83byteidx({expr}, {nr}) Number byte index of {nr}'th char in {expr}
84byteidxcomp({expr}, {nr}) Number byte index of {nr}'th char in {expr}
85call({func}, {arglist} [, {dict}])
86 any call {func} with arguments {arglist}
87ceil({expr}) Float round {expr} up
88ch_canread({handle}) Number check if there is something to read
89ch_close({handle}) none close {handle}
90ch_close_in({handle}) none close in part of {handle}
91ch_evalexpr({handle}, {expr} [, {options}])
92 any evaluate {expr} on JSON {handle}
93ch_evalraw({handle}, {string} [, {options}])
94 any evaluate {string} on raw {handle}
95ch_getbufnr({handle}, {what}) Number get buffer number for {handle}/{what}
96ch_getjob({channel}) Job get the Job of {channel}
97ch_info({handle}) String info about channel {handle}
98ch_log({msg} [, {handle}]) none write {msg} in the channel log file
99ch_logfile({fname} [, {mode}]) none start logging channel activity
100ch_open({address} [, {options}])
101 Channel open a channel to {address}
102ch_read({handle} [, {options}]) String read from {handle}
103ch_readblob({handle} [, {options}])
104 Blob read Blob from {handle}
105ch_readraw({handle} [, {options}])
106 String read raw from {handle}
107ch_sendexpr({handle}, {expr} [, {options}])
108 any send {expr} over JSON {handle}
109ch_sendraw({handle}, {expr} [, {options}])
110 any send {expr} over raw {handle}
111ch_setoptions({handle}, {options})
112 none set options for {handle}
113ch_status({handle} [, {options}])
114 String status of channel {handle}
115changenr() Number current change number
116char2nr({expr} [, {utf8}]) Number ASCII/UTF-8 value of first char in {expr}
117charclass({string}) Number character class of {string}
118charcol({expr}) Number column number of cursor or mark
119charidx({string}, {idx} [, {countcc}])
120 Number char index of byte {idx} in {string}
121chdir({dir}) String change current working directory
122cindent({lnum}) Number C indent for line {lnum}
123clearmatches([{win}]) none clear all matches
124col({expr}) Number column byte index of cursor or mark
125complete({startcol}, {matches}) none set Insert mode completion
126complete_add({expr}) Number add completion match
127complete_check() Number check for key typed during completion
128complete_info([{what}]) Dict get current completion information
129confirm({msg} [, {choices} [, {default} [, {type}]]])
130 Number number of choice picked by user
131copy({expr}) any make a shallow copy of {expr}
132cos({expr}) Float cosine of {expr}
133cosh({expr}) Float hyperbolic cosine of {expr}
134count({comp}, {expr} [, {ic} [, {start}]])
135 Number count how many {expr} are in {comp}
136cscope_connection([{num}, {dbpath} [, {prepend}]])
137 Number checks existence of cscope connection
138cursor({lnum}, {col} [, {off}])
139 Number move cursor to {lnum}, {col}, {off}
140cursor({list}) Number move cursor to position in {list}
141debugbreak({pid}) Number interrupt process being debugged
142deepcopy({expr} [, {noref}]) any make a full copy of {expr}
143delete({fname} [, {flags}]) Number delete the file or directory {fname}
144deletebufline({buf}, {first} [, {last}])
145 Number delete lines from buffer {buf}
146did_filetype() Number |TRUE| if FileType autocmd event used
147diff_filler({lnum}) Number diff filler lines about {lnum}
148diff_hlID({lnum}, {col}) Number diff highlighting at {lnum}/{col}
149digraph_get({chars}) String get the |digraph| of {chars}
150digraph_getlist([{listall}]) List get all |digraph|s
151digraph_set({chars}, {digraph}) Boolean register |digraph|
152digraph_setlist({digraphlist}) Boolean register multiple |digraph|s
153echoraw({expr}) none output {expr} as-is
154empty({expr}) Number |TRUE| if {expr} is empty
155environ() Dict return environment variables
156escape({string}, {chars}) String escape {chars} in {string} with '\'
157eval({string}) any evaluate {string} into its value
158eventhandler() Number |TRUE| if inside an event handler
159executable({expr}) Number 1 if executable {expr} exists
160execute({command}) String execute {command} and get the output
161exepath({expr}) String full path of the command {expr}
162exists({expr}) Number |TRUE| if {expr} exists
163exists_compiled({expr}) Number |TRUE| if {expr} exists at compile time
164exp({expr}) Float exponential of {expr}
165expand({expr} [, {nosuf} [, {list}]])
166 any expand special keywords in {expr}
Yegappan Lakshmanan2b74b682022-04-03 21:30:32 +0100167expandcmd({string} [, {options}])
168 String expand {string} like with `:edit`
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000169extend({expr1}, {expr2} [, {expr3}])
170 List/Dict insert items of {expr2} into {expr1}
171extendnew({expr1}, {expr2} [, {expr3}])
172 List/Dict like |extend()| but creates a new
173 List or Dictionary
174feedkeys({string} [, {mode}]) Number add key sequence to typeahead buffer
175filereadable({file}) Number |TRUE| if {file} is a readable file
176filewritable({file}) Number |TRUE| if {file} is a writable file
177filter({expr1}, {expr2}) List/Dict/Blob/String
178 remove items from {expr1} where
179 {expr2} is 0
180finddir({name} [, {path} [, {count}]])
181 String find directory {name} in {path}
182findfile({name} [, {path} [, {count}]])
183 String find file {name} in {path}
184flatten({list} [, {maxdepth}]) List flatten {list} up to {maxdepth} levels
185flattennew({list} [, {maxdepth}])
186 List flatten a copy of {list}
187float2nr({expr}) Number convert Float {expr} to a Number
188floor({expr}) Float round {expr} down
189fmod({expr1}, {expr2}) Float remainder of {expr1} / {expr2}
190fnameescape({fname}) String escape special characters in {fname}
191fnamemodify({fname}, {mods}) String modify file name
192foldclosed({lnum}) Number first line of fold at {lnum} if closed
193foldclosedend({lnum}) Number last line of fold at {lnum} if closed
194foldlevel({lnum}) Number fold level at {lnum}
195foldtext() String line displayed for closed fold
196foldtextresult({lnum}) String text for closed fold at {lnum}
197foreground() Number bring the Vim window to the foreground
198fullcommand({name}) String get full command from {name}
199funcref({name} [, {arglist}] [, {dict}])
200 Funcref reference to function {name}
201function({name} [, {arglist}] [, {dict}])
202 Funcref named reference to function {name}
203garbagecollect([{atexit}]) none free memory, breaking cyclic references
204get({list}, {idx} [, {def}]) any get item {idx} from {list} or {def}
205get({dict}, {key} [, {def}]) any get item {key} from {dict} or {def}
206get({func}, {what}) any get property of funcref/partial {func}
207getbufinfo([{buf}]) List information about buffers
208getbufline({buf}, {lnum} [, {end}])
209 List lines {lnum} to {end} of buffer {buf}
210getbufvar({buf}, {varname} [, {def}])
211 any variable {varname} in buffer {buf}
212getchangelist([{buf}]) List list of change list items
213getchar([expr]) Number or String
214 get one character from the user
215getcharmod() Number modifiers for the last typed character
216getcharpos({expr}) List position of cursor, mark, etc.
217getcharsearch() Dict last character search
218getcharstr([expr]) String get one character from the user
Shougo Matsushita79d599b2022-05-07 12:48:29 +0100219getcmdcompltype() String return the type of the current
220 command-line completion
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000221getcmdline() String return the current command-line
222getcmdpos() Number return cursor position in command-line
Shougo Matsushita79d599b2022-05-07 12:48:29 +0100223getcmdscreenpos() Number return cursor screen position in
224 command-line
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000225getcmdtype() String return current command-line type
226getcmdwintype() String return current command-line window type
227getcompletion({pat}, {type} [, {filtered}])
228 List list of cmdline completion matches
229getcurpos([{winnr}]) List position of the cursor
230getcursorcharpos([{winnr}]) List character position of the cursor
231getcwd([{winnr} [, {tabnr}]]) String get the current working directory
232getenv({name}) String return environment variable
233getfontname([{name}]) String name of font being used
234getfperm({fname}) String file permissions of file {fname}
235getfsize({fname}) Number size in bytes of file {fname}
236getftime({fname}) Number last modification time of file
237getftype({fname}) String description of type of file {fname}
238getimstatus() Number |TRUE| if the IME status is active
239getjumplist([{winnr} [, {tabnr}]])
240 List list of jump list items
241getline({lnum}) String line {lnum} of current buffer
242getline({lnum}, {end}) List lines {lnum} to {end} of current buffer
243getloclist({nr}) List list of location list items
244getloclist({nr}, {what}) Dict get specific location list properties
245getmarklist([{buf}]) List list of global/local marks
246getmatches([{win}]) List list of current matches
247getmousepos() Dict last known mouse position
248getpid() Number process ID of Vim
249getpos({expr}) List position of cursor, mark, etc.
250getqflist() List list of quickfix items
251getqflist({what}) Dict get specific quickfix list properties
252getreg([{regname} [, 1 [, {list}]]])
253 String or List contents of a register
254getreginfo([{regname}]) Dict information about a register
255getregtype([{regname}]) String type of a register
256gettabinfo([{expr}]) List list of tab pages
257gettabvar({nr}, {varname} [, {def}])
258 any variable {varname} in tab {nr} or {def}
259gettabwinvar({tabnr}, {winnr}, {name} [, {def}])
260 any {name} in {winnr} in tab page {tabnr}
261gettagstack([{nr}]) Dict get the tag stack of window {nr}
262gettext({text}) String lookup translation of {text}
263getwininfo([{winid}]) List list of info about each window
264getwinpos([{timeout}]) List X and Y coord in pixels of the Vim window
265getwinposx() Number X coord in pixels of the Vim window
266getwinposy() Number Y coord in pixels of the Vim window
267getwinvar({nr}, {varname} [, {def}])
268 any variable {varname} in window {nr}
269glob({expr} [, {nosuf} [, {list} [, {alllinks}]]])
270 any expand file wildcards in {expr}
271glob2regpat({expr}) String convert a glob pat into a search pat
272globpath({path}, {expr} [, {nosuf} [, {list} [, {alllinks}]]])
273 String do glob({expr}) for all dirs in {path}
274has({feature} [, {check}]) Number |TRUE| if feature {feature} supported
275has_key({dict}, {key}) Number |TRUE| if {dict} has entry {key}
276haslocaldir([{winnr} [, {tabnr}]])
277 Number |TRUE| if the window executed |:lcd|
278 or |:tcd|
279hasmapto({what} [, {mode} [, {abbr}]])
280 Number |TRUE| if mapping to {what} exists
281histadd({history}, {item}) Number add an item to a history
282histdel({history} [, {item}]) Number remove an item from a history
283histget({history} [, {index}]) String get the item {index} from a history
284histnr({history}) Number highest index of a history
285hlID({name}) Number syntax ID of highlight group {name}
286hlexists({name}) Number |TRUE| if highlight group {name} exists
287hlget([{name} [, {resolve}]]) List get highlight group attributes
288hlset({list}) Number set highlight group attributes
289hostname() String name of the machine Vim is running on
290iconv({expr}, {from}, {to}) String convert encoding of {expr}
291indent({lnum}) Number indent of line {lnum}
292index({object}, {expr} [, {start} [, {ic}]])
293 Number index in {object} where {expr} appears
Yegappan Lakshmananb2186552022-08-13 13:09:20 +0100294indexof({object}, {expr} [, {opts}]])
295 Number index in {object} where {expr} is true
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000296input({prompt} [, {text} [, {completion}]])
297 String get input from the user
Bram Moolenaarb529cfb2022-07-25 15:42:07 +0100298inputdialog({prompt} [, {text} [, {cancelreturn}]])
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000299 String like input() but in a GUI dialog
300inputlist({textlist}) Number let the user pick from a choice list
301inputrestore() Number restore typeahead
302inputsave() Number save and clear typeahead
303inputsecret({prompt} [, {text}]) String like input() but hiding the text
304insert({object}, {item} [, {idx}]) List insert {item} in {object} [before {idx}]
305interrupt() none interrupt script execution
306invert({expr}) Number bitwise invert
LemonBoydca1d402022-04-28 15:26:33 +0100307isabsolutepath({path}) Number |TRUE| if {path} is an absolute path
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000308isdirectory({directory}) Number |TRUE| if {directory} is a directory
309isinf({expr}) Number determine if {expr} is infinity value
310 (positive or negative)
311islocked({expr}) Number |TRUE| if {expr} is locked
312isnan({expr}) Number |TRUE| if {expr} is NaN
313items({dict}) List key-value pairs in {dict}
314job_getchannel({job}) Channel get the channel handle for {job}
315job_info([{job}]) Dict get information about {job}
316job_setoptions({job}, {options}) none set options for {job}
317job_start({command} [, {options}])
318 Job start a job
319job_status({job}) String get the status of {job}
320job_stop({job} [, {how}]) Number stop {job}
321join({list} [, {sep}]) String join {list} items into one String
322js_decode({string}) any decode JS style JSON
323js_encode({expr}) String encode JS style JSON
324json_decode({string}) any decode JSON
325json_encode({expr}) String encode JSON
326keys({dict}) List keys in {dict}
327len({expr}) Number the length of {expr}
328libcall({lib}, {func}, {arg}) String call {func} in library {lib} with {arg}
329libcallnr({lib}, {func}, {arg}) Number idem, but return a Number
330line({expr} [, {winid}]) Number line nr of cursor, last line or mark
331line2byte({lnum}) Number byte count of line {lnum}
332lispindent({lnum}) Number Lisp indent for line {lnum}
333list2blob({list}) Blob turn {list} of numbers into a Blob
334list2str({list} [, {utf8}]) String turn {list} of numbers into a String
335listener_add({callback} [, {buf}])
336 Number add a callback to listen to changes
337listener_flush([{buf}]) none invoke listener callbacks
338listener_remove({id}) none remove a listener callback
339localtime() Number current time
340log({expr}) Float natural logarithm (base e) of {expr}
341log10({expr}) Float logarithm of Float {expr} to base 10
342luaeval({expr} [, {expr}]) any evaluate |Lua| expression
343map({expr1}, {expr2}) List/Dict/Blob/String
344 change each item in {expr1} to {expr2}
345maparg({name} [, {mode} [, {abbr} [, {dict}]]])
346 String or Dict
347 rhs of mapping {name} in mode {mode}
348mapcheck({name} [, {mode} [, {abbr}]])
349 String check for mappings matching {name}
Ernie Rael09661202022-04-25 14:40:44 +0100350maplist([{abbr}]) List list of all mappings, a dict for each
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000351mapnew({expr1}, {expr2}) List/Dict/Blob/String
352 like |map()| but creates a new List or
353 Dictionary
354mapset({mode}, {abbr}, {dict}) none restore mapping from |maparg()| result
355match({expr}, {pat} [, {start} [, {count}]])
356 Number position where {pat} matches in {expr}
357matchadd({group}, {pattern} [, {priority} [, {id} [, {dict}]]])
358 Number highlight {pattern} with {group}
359matchaddpos({group}, {pos} [, {priority} [, {id} [, {dict}]]])
360 Number highlight positions with {group}
361matcharg({nr}) List arguments of |:match|
362matchdelete({id} [, {win}]) Number delete match identified by {id}
363matchend({expr}, {pat} [, {start} [, {count}]])
364 Number position where {pat} ends in {expr}
365matchfuzzy({list}, {str} [, {dict}])
366 List fuzzy match {str} in {list}
367matchfuzzypos({list}, {str} [, {dict}])
368 List fuzzy match {str} in {list}
369matchlist({expr}, {pat} [, {start} [, {count}]])
370 List match and submatches of {pat} in {expr}
371matchstr({expr}, {pat} [, {start} [, {count}]])
372 String {count}'th match of {pat} in {expr}
373matchstrpos({expr}, {pat} [, {start} [, {count}]])
374 List {count}'th match of {pat} in {expr}
375max({expr}) Number maximum value of items in {expr}
376menu_info({name} [, {mode}]) Dict get menu item information
377min({expr}) Number minimum value of items in {expr}
378mkdir({name} [, {path} [, {prot}]])
379 Number create directory {name}
380mode([expr]) String current editing mode
381mzeval({expr}) any evaluate |MzScheme| expression
382nextnonblank({lnum}) Number line nr of non-blank line >= {lnum}
383nr2char({expr} [, {utf8}]) String single char with ASCII/UTF-8 value {expr}
384or({expr}, {expr}) Number bitwise OR
385pathshorten({expr} [, {len}]) String shorten directory names in a path
386perleval({expr}) any evaluate |Perl| expression
387popup_atcursor({what}, {options}) Number create popup window near the cursor
388popup_beval({what}, {options}) Number create popup window for 'ballooneval'
389popup_clear() none close all popup windows
390popup_close({id} [, {result}]) none close popup window {id}
391popup_create({what}, {options}) Number create a popup window
392popup_dialog({what}, {options}) Number create a popup window used as a dialog
393popup_filter_menu({id}, {key}) Number filter for a menu popup window
394popup_filter_yesno({id}, {key}) Number filter for a dialog popup window
395popup_findinfo() Number get window ID of info popup window
396popup_findpreview() Number get window ID of preview popup window
397popup_getoptions({id}) Dict get options of popup window {id}
398popup_getpos({id}) Dict get position of popup window {id}
399popup_hide({id}) none hide popup menu {id}
400popup_list() List get a list of window IDs of all popups
401popup_locate({row}, {col}) Number get window ID of popup at position
402popup_menu({what}, {options}) Number create a popup window used as a menu
403popup_move({id}, {options}) none set position of popup window {id}
404popup_notification({what}, {options})
405 Number create a notification popup window
406popup_setoptions({id}, {options})
407 none set options for popup window {id}
408popup_settext({id}, {text}) none set the text of popup window {id}
409popup_show({id}) none unhide popup window {id}
410pow({x}, {y}) Float {x} to the power of {y}
411prevnonblank({lnum}) Number line nr of non-blank line <= {lnum}
412printf({fmt}, {expr1}...) String format text
413prompt_getprompt({buf}) String get prompt text
414prompt_setcallback({buf}, {expr}) none set prompt callback function
415prompt_setinterrupt({buf}, {text}) none set prompt interrupt function
416prompt_setprompt({buf}, {text}) none set prompt text
417prop_add({lnum}, {col}, {props}) none add one text property
418prop_add_list({props}, [[{lnum}, {col}, {end-lnum}, {end-col}], ...])
419 none add multiple text properties
420prop_clear({lnum} [, {lnum-end} [, {props}]])
421 none remove all text properties
422prop_find({props} [, {direction}])
423 Dict search for a text property
424prop_list({lnum} [, {props}]) List text properties in {lnum}
425prop_remove({props} [, {lnum} [, {lnum-end}]])
426 Number remove a text property
427prop_type_add({name}, {props}) none define a new property type
428prop_type_change({name}, {props})
429 none change an existing property type
430prop_type_delete({name} [, {props}])
431 none delete a property type
432prop_type_get({name} [, {props}])
433 Dict get property type values
434prop_type_list([{props}]) List get list of property types
435pum_getpos() Dict position and size of pum if visible
436pumvisible() Number whether popup menu is visible
437py3eval({expr}) any evaluate |python3| expression
438pyeval({expr}) any evaluate |Python| expression
439pyxeval({expr}) any evaluate |python_x| expression
440rand([{expr}]) Number get pseudo-random number
441range({expr} [, {max} [, {stride}]])
442 List items from {expr} to {max}
443readblob({fname}) Blob read a |Blob| from {fname}
444readdir({dir} [, {expr} [, {dict}]])
445 List file names in {dir} selected by {expr}
446readdirex({dir} [, {expr} [, {dict}]])
447 List file info in {dir} selected by {expr}
448readfile({fname} [, {type} [, {max}]])
449 List get list of lines from file {fname}
450reduce({object}, {func} [, {initial}])
451 any reduce {object} using {func}
452reg_executing() String get the executing register name
453reg_recording() String get the recording register name
454reltime([{start} [, {end}]]) List get time value
455reltimefloat({time}) Float turn the time value into a Float
456reltimestr({time}) String turn time value into a String
457remote_expr({server}, {string} [, {idvar} [, {timeout}]])
458 String send expression
459remote_foreground({server}) Number bring Vim server to the foreground
460remote_peek({serverid} [, {retvar}])
461 Number check for reply string
462remote_read({serverid} [, {timeout}])
463 String read reply string
464remote_send({server}, {string} [, {idvar}])
465 String send key sequence
466remote_startserver({name}) none become server {name}
467remove({list}, {idx} [, {end}]) any/List
468 remove items {idx}-{end} from {list}
469remove({blob}, {idx} [, {end}]) Number/Blob
470 remove bytes {idx}-{end} from {blob}
471remove({dict}, {key}) any remove entry {key} from {dict}
472rename({from}, {to}) Number rename (move) file from {from} to {to}
473repeat({expr}, {count}) String repeat {expr} {count} times
474resolve({filename}) String get filename a shortcut points to
475reverse({list}) List reverse {list} in-place
476round({expr}) Float round off {expr}
477rubyeval({expr}) any evaluate |Ruby| expression
478screenattr({row}, {col}) Number attribute at screen position
479screenchar({row}, {col}) Number character at screen position
480screenchars({row}, {col}) List List of characters at screen position
481screencol() Number current cursor column
482screenpos({winid}, {lnum}, {col}) Dict screen row and col of a text character
483screenrow() Number current cursor row
484screenstring({row}, {col}) String characters at screen position
485search({pattern} [, {flags} [, {stopline} [, {timeout} [, {skip}]]]])
486 Number search for {pattern}
487searchcount([{options}]) Dict get or update search stats
488searchdecl({name} [, {global} [, {thisblock}]])
489 Number search for variable declaration
490searchpair({start}, {middle}, {end} [, {flags} [, {skip} [...]]])
491 Number search for other end of start/end pair
492searchpairpos({start}, {middle}, {end} [, {flags} [, {skip} [...]]])
493 List search for other end of start/end pair
494searchpos({pattern} [, {flags} [, {stopline} [, {timeout} [, {skip}]]]])
495 List search for {pattern}
496server2client({clientid}, {string})
497 Number send reply string
498serverlist() String get a list of available servers
499setbufline({expr}, {lnum}, {text})
500 Number set line {lnum} to {text} in buffer
501 {expr}
502setbufvar({buf}, {varname}, {val})
503 none set {varname} in buffer {buf} to {val}
504setcellwidths({list}) none set character cell width overrides
505setcharpos({expr}, {list}) Number set the {expr} position to {list}
506setcharsearch({dict}) Dict set character search from {dict}
507setcmdpos({pos}) Number set cursor position in command-line
508setcursorcharpos({list}) Number move cursor to position in {list}
509setenv({name}, {val}) none set environment variable
510setfperm({fname}, {mode}) Number set {fname} file permissions to {mode}
511setline({lnum}, {line}) Number set line {lnum} to {line}
512setloclist({nr}, {list} [, {action}])
513 Number modify location list using {list}
514setloclist({nr}, {list}, {action}, {what})
515 Number modify specific location list props
516setmatches({list} [, {win}]) Number restore a list of matches
517setpos({expr}, {list}) Number set the {expr} position to {list}
518setqflist({list} [, {action}]) Number modify quickfix list using {list}
519setqflist({list}, {action}, {what})
520 Number modify specific quickfix list props
521setreg({n}, {v} [, {opt}]) Number set register to value and type
522settabvar({nr}, {varname}, {val}) none set {varname} in tab page {nr} to {val}
523settabwinvar({tabnr}, {winnr}, {varname}, {val})
524 none set {varname} in window {winnr} in tab
525 page {tabnr} to {val}
526settagstack({nr}, {dict} [, {action}])
527 Number modify tag stack using {dict}
528setwinvar({nr}, {varname}, {val}) none set {varname} in window {nr} to {val}
529sha256({string}) String SHA256 checksum of {string}
530shellescape({string} [, {special}])
531 String escape {string} for use as shell
532 command argument
533shiftwidth([{col}]) Number effective value of 'shiftwidth'
534sign_define({name} [, {dict}]) Number define or update a sign
535sign_define({list}) List define or update a list of signs
536sign_getdefined([{name}]) List get a list of defined signs
537sign_getplaced([{buf} [, {dict}]])
538 List get a list of placed signs
539sign_jump({id}, {group}, {buf})
540 Number jump to a sign
541sign_place({id}, {group}, {name}, {buf} [, {dict}])
542 Number place a sign
543sign_placelist({list}) List place a list of signs
544sign_undefine([{name}]) Number undefine a sign
545sign_undefine({list}) List undefine a list of signs
546sign_unplace({group} [, {dict}])
547 Number unplace a sign
548sign_unplacelist({list}) List unplace a list of signs
549simplify({filename}) String simplify filename as much as possible
550sin({expr}) Float sine of {expr}
551sinh({expr}) Float hyperbolic sine of {expr}
552slice({expr}, {start} [, {end}]) String, List or Blob
553 slice of a String, List or Blob
Bram Moolenaar2007dd42022-02-23 13:17:47 +0000554sort({list} [, {how} [, {dict}]])
555 List sort {list}, compare with {how}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000556sound_clear() none stop playing all sounds
557sound_playevent({name} [, {callback}])
558 Number play an event sound
559sound_playfile({path} [, {callback}])
560 Number play sound file {path}
561sound_stop({id}) none stop playing sound {id}
562soundfold({word}) String sound-fold {word}
563spellbadword() String badly spelled word at cursor
564spellsuggest({word} [, {max} [, {capital}]])
565 List spelling suggestions
566split({expr} [, {pat} [, {keepempty}]])
567 List make |List| from {pat} separated {expr}
568sqrt({expr}) Float square root of {expr}
569srand([{expr}]) List get seed for |rand()|
570state([{what}]) String current state of Vim
571str2float({expr} [, {quoted}]) Float convert String to Float
572str2list({expr} [, {utf8}]) List convert each character of {expr} to
573 ASCII/UTF-8 value
574str2nr({expr} [, {base} [, {quoted}]])
575 Number convert String to Number
576strcharlen({expr}) Number character length of the String {expr}
577strcharpart({str}, {start} [, {len} [, {skipcc}]])
578 String {len} characters of {str} at
579 character {start}
580strchars({expr} [, {skipcc}]) Number character count of the String {expr}
581strdisplaywidth({expr} [, {col}]) Number display length of the String {expr}
582strftime({format} [, {time}]) String format time with a specified format
583strgetchar({str}, {index}) Number get char {index} from {str}
584stridx({haystack}, {needle} [, {start}])
585 Number index of {needle} in {haystack}
586string({expr}) String String representation of {expr} value
587strlen({expr}) Number length of the String {expr}
588strpart({str}, {start} [, {len} [, {chars}]])
589 String {len} bytes/chars of {str} at
590 byte {start}
591strptime({format}, {timestring})
592 Number Convert {timestring} to unix timestamp
593strridx({haystack}, {needle} [, {start}])
594 Number last index of {needle} in {haystack}
595strtrans({expr}) String translate string to make it printable
596strwidth({expr}) Number display cell length of the String {expr}
597submatch({nr} [, {list}]) String or List
598 specific match in ":s" or substitute()
599substitute({expr}, {pat}, {sub}, {flags})
600 String all {pat} in {expr} replaced with {sub}
601swapinfo({fname}) Dict information about swap file {fname}
602swapname({buf}) String swap file of buffer {buf}
603synID({lnum}, {col}, {trans}) Number syntax ID at {lnum} and {col}
604synIDattr({synID}, {what} [, {mode}])
605 String attribute {what} of syntax ID {synID}
606synIDtrans({synID}) Number translated syntax ID of {synID}
607synconcealed({lnum}, {col}) List info about concealing
608synstack({lnum}, {col}) List stack of syntax IDs at {lnum} and {col}
609system({expr} [, {input}]) String output of shell command/filter {expr}
610systemlist({expr} [, {input}]) List output of shell command/filter {expr}
611tabpagebuflist([{arg}]) List list of buffer numbers in tab page
612tabpagenr([{arg}]) Number number of current or last tab page
613tabpagewinnr({tabarg} [, {arg}]) Number number of current window in tab page
614tagfiles() List tags files used
615taglist({expr} [, {filename}]) List list of tags matching {expr}
616tan({expr}) Float tangent of {expr}
617tanh({expr}) Float hyperbolic tangent of {expr}
618tempname() String name for a temporary file
619term_dumpdiff({filename}, {filename} [, {options}])
620 Number display difference between two dumps
621term_dumpload({filename} [, {options}])
622 Number displaying a screen dump
623term_dumpwrite({buf}, {filename} [, {options}])
624 none dump terminal window contents
625term_getaltscreen({buf}) Number get the alternate screen flag
626term_getansicolors({buf}) List get ANSI palette in GUI color mode
627term_getattr({attr}, {what}) Number get the value of attribute {what}
628term_getcursor({buf}) List get the cursor position of a terminal
629term_getjob({buf}) Job get the job associated with a terminal
630term_getline({buf}, {row}) String get a line of text from a terminal
631term_getscrolled({buf}) Number get the scroll count of a terminal
632term_getsize({buf}) List get the size of a terminal
633term_getstatus({buf}) String get the status of a terminal
634term_gettitle({buf}) String get the title of a terminal
635term_gettty({buf}, [{input}]) String get the tty name of a terminal
636term_list() List get the list of terminal buffers
637term_scrape({buf}, {row}) List get row of a terminal screen
638term_sendkeys({buf}, {keys}) none send keystrokes to a terminal
639term_setansicolors({buf}, {colors})
640 none set ANSI palette in GUI color mode
641term_setapi({buf}, {expr}) none set |terminal-api| function name prefix
642term_setkill({buf}, {how}) none set signal to stop job in terminal
643term_setrestore({buf}, {command}) none set command to restore terminal
644term_setsize({buf}, {rows}, {cols})
645 none set the size of a terminal
646term_start({cmd} [, {options}]) Number open a terminal window and run a job
647term_wait({buf} [, {time}]) Number wait for screen to be updated
648terminalprops() Dict properties of the terminal
649test_alloc_fail({id}, {countdown}, {repeat})
650 none make memory allocation fail
651test_autochdir() none enable 'autochdir' during startup
652test_feedinput({string}) none add key sequence to input buffer
653test_garbagecollect_now() none free memory right now for testing
654test_garbagecollect_soon() none free memory soon for testing
655test_getvalue({string}) any get value of an internal variable
Yegappan Lakshmanan06011e12022-01-30 12:37:29 +0000656test_gui_event({event}, {args}) bool generate a GUI event for testing
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000657test_ignore_error({expr}) none ignore a specific error
658test_null_blob() Blob null value for testing
659test_null_channel() Channel null value for testing
660test_null_dict() Dict null value for testing
661test_null_function() Funcref null value for testing
662test_null_job() Job null value for testing
663test_null_list() List null value for testing
664test_null_partial() Funcref null value for testing
665test_null_string() String null value for testing
666test_option_not_set({name}) none reset flag indicating option was set
667test_override({expr}, {val}) none test with Vim internal overrides
668test_refcount({expr}) Number get the reference count of {expr}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000669test_setmouse({row}, {col}) none set the mouse position for testing
670test_settime({expr}) none set current time for testing
671test_srand_seed([seed]) none set seed for testing srand()
672test_unknown() any unknown value for testing
673test_void() any void value for testing
674timer_info([{id}]) List information about timers
675timer_pause({id}, {pause}) none pause or unpause a timer
676timer_start({time}, {callback} [, {options}])
677 Number create a timer
678timer_stop({timer}) none stop a timer
679timer_stopall() none stop all timers
680tolower({expr}) String the String {expr} switched to lowercase
681toupper({expr}) String the String {expr} switched to uppercase
682tr({src}, {fromstr}, {tostr}) String translate chars of {src} in {fromstr}
683 to chars in {tostr}
684trim({text} [, {mask} [, {dir}]])
685 String trim characters in {mask} from {text}
686trunc({expr}) Float truncate Float {expr}
687type({expr}) Number type of value {expr}
688typename({expr}) String representation of the type of {expr}
689undofile({name}) String undo file name for {name}
690undotree() List undo file tree
691uniq({list} [, {func} [, {dict}]])
692 List remove adjacent duplicates from a list
693values({dict}) List values in {dict}
LemonBoy0f7a3e12022-05-26 12:10:37 +0100694virtcol({expr} [, {list}]) Number or List
695 screen column of cursor or mark
Bram Moolenaar5a6ec102022-05-27 21:58:00 +0100696virtcol2col({winid}, {lnum}, {col})
697 Number byte index of a character on screen
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000698visualmode([expr]) String last visual mode used
699wildmenumode() Number whether 'wildmenu' mode is active
700win_execute({id}, {command} [, {silent}])
701 String execute {command} in window {id}
702win_findbuf({bufnr}) List find windows containing {bufnr}
703win_getid([{win} [, {tab}]]) Number get window ID for {win} in {tab}
704win_gettype([{nr}]) String type of window {nr}
705win_gotoid({expr}) Number go to window with ID {expr}
706win_id2tabwin({expr}) List get tab and window nr from window ID
707win_id2win({expr}) Number get window nr from window ID
Daniel Steinbergee630312022-01-10 13:36:34 +0000708win_move_separator({nr}) Number move window vertical separator
709win_move_statusline({nr}) Number move window status line
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000710win_screenpos({nr}) List get screen position of window {nr}
711win_splitmove({nr}, {target} [, {options}])
712 Number move window {nr} to split of {target}
713winbufnr({nr}) Number buffer number of window {nr}
714wincol() Number window column of the cursor
715windowsversion() String MS-Windows OS version
716winheight({nr}) Number height of window {nr}
717winlayout([{tabnr}]) List layout of windows in tab {tabnr}
718winline() Number window line of the cursor
719winnr([{expr}]) Number number of current window
720winrestcmd() String returns command to restore window sizes
721winrestview({dict}) none restore view of current window
722winsaveview() Dict save view of current window
723winwidth({nr}) Number width of window {nr}
724wordcount() Dict get byte/char/word statistics
725writefile({object}, {fname} [, {flags}])
726 Number write |Blob| or |List| of lines to file
727xor({expr}, {expr}) Number bitwise XOR
728
729==============================================================================
7302. Details *builtin-function-details*
731
732Not all functions are here, some have been moved to a help file covering the
733specific functionality.
734
735abs({expr}) *abs()*
736 Return the absolute value of {expr}. When {expr} evaluates to
737 a |Float| abs() returns a |Float|. When {expr} can be
738 converted to a |Number| abs() returns a |Number|. Otherwise
739 abs() gives an error message and returns -1.
740 Examples: >
741 echo abs(1.456)
742< 1.456 >
743 echo abs(-5.456)
744< 5.456 >
745 echo abs(-4)
746< 4
747
748 Can also be used as a |method|: >
749 Compute()->abs()
750
751< {only available when compiled with the |+float| feature}
752
753
754acos({expr}) *acos()*
755 Return the arc cosine of {expr} measured in radians, as a
756 |Float| in the range of [0, pi].
757 {expr} must evaluate to a |Float| or a |Number| in the range
Bram Moolenaar016188f2022-06-06 20:52:59 +0100758 [-1, 1]. Otherwise acos() returns "nan".
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000759 Examples: >
760 :echo acos(0)
761< 1.570796 >
762 :echo acos(-0.5)
763< 2.094395
764
765 Can also be used as a |method|: >
766 Compute()->acos()
767
768< {only available when compiled with the |+float| feature}
769
770
771add({object}, {expr}) *add()*
772 Append the item {expr} to |List| or |Blob| {object}. Returns
773 the resulting |List| or |Blob|. Examples: >
774 :let alist = add([1, 2, 3], item)
775 :call add(mylist, "woodstock")
776< Note that when {expr} is a |List| it is appended as a single
777 item. Use |extend()| to concatenate |Lists|.
778 When {object} is a |Blob| then {expr} must be a number.
779 Use |insert()| to add an item at another position.
Bram Moolenaar016188f2022-06-06 20:52:59 +0100780 Returns 1 if {object} is not a |List| or a |Blob|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000781
782 Can also be used as a |method|: >
783 mylist->add(val1)->add(val2)
784
785
786and({expr}, {expr}) *and()*
787 Bitwise AND on the two arguments. The arguments are converted
788 to a number. A List, Dict or Float argument causes an error.
LemonBoy0f7a3e12022-05-26 12:10:37 +0100789 Also see `or()` and `xor()`.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000790 Example: >
791 :let flag = and(bits, 0x80)
792< Can also be used as a |method|: >
793 :let flag = bits->and(0x80)
794
795
796append({lnum}, {text}) *append()*
797 When {text} is a |List|: Append each item of the |List| as a
798 text line below line {lnum} in the current buffer.
799 Otherwise append {text} as one text line below line {lnum} in
800 the current buffer.
801 Any type of item is accepted and converted to a String.
802 {lnum} can be zero to insert a line before the first one.
803 {lnum} is used like with |getline()|.
804 Returns 1 for failure ({lnum} out of range or out of memory),
805 0 for success. In |Vim9| script an invalid argument or
806 negative number results in an error. Example: >
807 :let failed = append(line('$'), "# THE END")
808 :let failed = append(0, ["Chapter 1", "the beginning"])
809
810< Can also be used as a |method| after a List, the base is
811 passed as the second argument: >
812 mylist->append(lnum)
813
814
815appendbufline({buf}, {lnum}, {text}) *appendbufline()*
816 Like |append()| but append the text in buffer {buf}.
817
818 This function works only for loaded buffers. First call
819 |bufload()| if needed.
820
821 For the use of {buf}, see |bufname()|.
822
Bram Moolenaar8b6256f2021-12-28 11:24:49 +0000823 {lnum} is the line number to append below. Note that using
824 |line()| would use the current buffer, not the one appending
825 to. Use "$" to append at the end of the buffer. Other string
826 values are not supported.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000827
828 On success 0 is returned, on failure 1 is returned.
829 In |Vim9| script an error is given for an invalid {lnum}.
830
831 If {buf} is not a valid buffer or {lnum} is not valid, an
832 error message is given. Example: >
833 :let failed = appendbufline(13, 0, "# THE START")
834<
835 Can also be used as a |method| after a List, the base is
836 passed as the second argument: >
837 mylist->appendbufline(buf, lnum)
838
839
840argc([{winid}]) *argc()*
841 The result is the number of files in the argument list. See
842 |arglist|.
843 If {winid} is not supplied, the argument list of the current
844 window is used.
845 If {winid} is -1, the global argument list is used.
846 Otherwise {winid} specifies the window of which the argument
847 list is used: either the window number or the window ID.
848 Returns -1 if the {winid} argument is invalid.
849
850 *argidx()*
851argidx() The result is the current index in the argument list. 0 is
852 the first file. argc() - 1 is the last one. See |arglist|.
853
854 *arglistid()*
855arglistid([{winnr} [, {tabnr}]])
856 Return the argument list ID. This is a number which
857 identifies the argument list being used. Zero is used for the
858 global argument list. See |arglist|.
859 Returns -1 if the arguments are invalid.
860
861 Without arguments use the current window.
862 With {winnr} only use this window in the current tab page.
863 With {winnr} and {tabnr} use the window in the specified tab
864 page.
865 {winnr} can be the window number or the |window-ID|.
866
867 *argv()*
868argv([{nr} [, {winid}]])
869 The result is the {nr}th file in the argument list. See
870 |arglist|. "argv(0)" is the first one. Example: >
871 :let i = 0
872 :while i < argc()
873 : let f = escape(fnameescape(argv(i)), '.')
Bram Moolenaarc51cf032022-02-26 12:25:45 +0000874 : exe 'amenu Arg.' .. f .. ' :e ' .. f .. '<CR>'
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000875 : let i = i + 1
876 :endwhile
877< Without the {nr} argument, or when {nr} is -1, a |List| with
878 the whole |arglist| is returned.
879
880 The {winid} argument specifies the window ID, see |argc()|.
881 For the Vim command line arguments see |v:argv|.
882
Bram Moolenaar016188f2022-06-06 20:52:59 +0100883 Returns an empty string if {nr}th argument is not present in
884 the argument list. Returns an empty List if the {winid}
885 argument is invalid.
886
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000887asin({expr}) *asin()*
888 Return the arc sine of {expr} measured in radians, as a |Float|
889 in the range of [-pi/2, pi/2].
890 {expr} must evaluate to a |Float| or a |Number| in the range
891 [-1, 1].
Bram Moolenaar016188f2022-06-06 20:52:59 +0100892 Returns "nan" if {expr} is outside the range [-1, 1]. Returns
893 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000894 Examples: >
895 :echo asin(0.8)
896< 0.927295 >
897 :echo asin(-0.5)
898< -0.523599
899
900 Can also be used as a |method|: >
901 Compute()->asin()
902<
903 {only available when compiled with the |+float| feature}
904
905
906assert_ functions are documented here: |assert-functions-details|
907
908
909
910atan({expr}) *atan()*
911 Return the principal value of the arc tangent of {expr}, in
912 the range [-pi/2, +pi/2] radians, as a |Float|.
913 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar016188f2022-06-06 20:52:59 +0100914 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000915 Examples: >
916 :echo atan(100)
917< 1.560797 >
918 :echo atan(-4.01)
919< -1.326405
920
921 Can also be used as a |method|: >
922 Compute()->atan()
923<
924 {only available when compiled with the |+float| feature}
925
926
927atan2({expr1}, {expr2}) *atan2()*
928 Return the arc tangent of {expr1} / {expr2}, measured in
929 radians, as a |Float| in the range [-pi, pi].
930 {expr1} and {expr2} must evaluate to a |Float| or a |Number|.
Bram Moolenaar016188f2022-06-06 20:52:59 +0100931 Returns 0.0 if {expr1} or {expr2} is not a |Float| or a
932 |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000933 Examples: >
934 :echo atan2(-1, 1)
935< -0.785398 >
936 :echo atan2(1, -1)
937< 2.356194
938
939 Can also be used as a |method|: >
940 Compute()->atan2(1)
941<
942 {only available when compiled with the |+float| feature}
943
Yegappan Lakshmanan1755a912022-05-19 10:31:47 +0100944
945autocmd_add({acmds}) *autocmd_add()*
946 Adds a List of autocmds and autocmd groups.
947
948 The {acmds} argument is a List where each item is a Dict with
949 the following optional items:
950 bufnr buffer number to add a buffer-local autocmd.
951 If this item is specified, then the "pattern"
952 item is ignored.
953 cmd Ex command to execute for this autocmd event
954 event autocmd event name. Refer to |autocmd-events|.
Yegappan Lakshmanane0ff3a72022-05-27 18:05:33 +0100955 This can be either a String with a single
956 event name or a List of event names.
Yegappan Lakshmanan1755a912022-05-19 10:31:47 +0100957 group autocmd group name. Refer to |autocmd-groups|.
958 If this group doesn't exist then it is
959 created. If not specified or empty, then the
960 default group is used.
Yegappan Lakshmanan971f6822022-05-24 11:40:11 +0100961 nested boolean flag, set to v:true to add a nested
962 autocmd. Refer to |autocmd-nested|.
LemonBoy0f7a3e12022-05-26 12:10:37 +0100963 once boolean flag, set to v:true to add an autocmd
Yegappan Lakshmanan971f6822022-05-24 11:40:11 +0100964 which executes only once. Refer to
965 |autocmd-once|.
Yegappan Lakshmanan1755a912022-05-19 10:31:47 +0100966 pattern autocmd pattern string. Refer to
967 |autocmd-patterns|. If "bufnr" item is
Yegappan Lakshmanane0ff3a72022-05-27 18:05:33 +0100968 present, then this item is ignored. This can
969 be a String with a single pattern or a List of
970 patterns.
Yegappan Lakshmanan971f6822022-05-24 11:40:11 +0100971 replace boolean flag, set to v:true to remove all the
972 commands associated with the specified autocmd
973 event and group and add the {cmd}. This is
974 useful to avoid adding the same command
LemonBoy0f7a3e12022-05-26 12:10:37 +0100975 multiple times for an autocmd event in a group.
Yegappan Lakshmanan1755a912022-05-19 10:31:47 +0100976
977 Returns v:true on success and v:false on failure.
978 Examples: >
979 " Create a buffer-local autocmd for buffer 5
980 let acmd = {}
981 let acmd.group = 'MyGroup'
982 let acmd.event = 'BufEnter'
983 let acmd.bufnr = 5
984 let acmd.cmd = 'call BufEnterFunc()'
985 call autocmd_add([acmd])
986
987 Can also be used as a |method|: >
988 GetAutocmdList()->autocmd_add()
989<
990autocmd_delete({acmds}) *autocmd_delete()*
991 Deletes a List of autocmds and autocmd groups.
992
993 The {acmds} argument is a List where each item is a Dict with
994 the following optional items:
995 bufnr buffer number to delete a buffer-local autocmd.
996 If this item is specified, then the "pattern"
997 item is ignored.
998 cmd Ex command for this autocmd event
999 event autocmd event name. Refer to |autocmd-events|.
1000 If '*' then all the autocmd events in this
1001 group are deleted.
1002 group autocmd group name. Refer to |autocmd-groups|.
1003 If not specified or empty, then the default
1004 group is used.
1005 nested set to v:true for a nested autocmd.
1006 Refer to |autocmd-nested|.
1007 once set to v:true for an autocmd which executes
1008 only once. Refer to |autocmd-once|.
1009 pattern autocmd pattern string. Refer to
1010 |autocmd-patterns|. If "bufnr" item is
1011 present, then this item is ignored.
1012
1013 If only {group} is specified in a {acmds} entry and {event},
1014 {pattern} and {cmd} are not specified, then that autocmd group
1015 is deleted.
1016
Bram Moolenaar016188f2022-06-06 20:52:59 +01001017 Returns |v:true| on success and |v:false| on failure.
Yegappan Lakshmanan1755a912022-05-19 10:31:47 +01001018 Examples: >
1019 " :autocmd! BufLeave *.vim
1020 let acmd = #{event: 'BufLeave', pattern: '*.vim'}
1021 call autocmd_delete([acmd]})
1022 " :autocmd! MyGroup1 BufLeave
1023 let acmd = #{group: 'MyGroup1', event: 'BufLeave'}
1024 call autocmd_delete([acmd])
1025 " :autocmd! MyGroup2 BufEnter *.c
1026 let acmd = #{group: 'MyGroup2', event: 'BufEnter',
1027 \ pattern: '*.c'}
1028 " :autocmd! MyGroup2 * *.c
1029 let acmd = #{group: 'MyGroup2', event: '*',
1030 \ pattern: '*.c'}
1031 call autocmd_delete([acmd])
1032 " :autocmd! MyGroup3
1033 let acmd = #{group: 'MyGroup3'}
1034 call autocmd_delete([acmd])
1035<
1036 Can also be used as a |method|: >
1037 GetAutocmdList()->autocmd_delete()
1038
1039autocmd_get([{opts}]) *autocmd_get()*
1040 Returns a |List| of autocmds. If {opts} is not supplied, then
1041 returns the autocmds for all the events in all the groups.
1042
1043 The optional {opts} Dict argument supports the following
1044 items:
1045 group Autocmd group name. If specified, returns only
1046 the autocmds defined in this group. If the
1047 specified group doesn't exist, results in an
1048 error message. If set to an empty string,
1049 then the default autocmd group is used.
1050 event Autocmd event name. If specified, returns only
1051 the autocmds defined for this event. If set
1052 to "*", then returns autocmds for all the
1053 events. If the specified event doesn't exist,
1054 results in an error message.
1055 pattern Autocmd pattern. If specified, returns only
1056 the autocmds defined for this pattern.
1057 A combination of the above three times can be supplied in
1058 {opts}.
1059
1060 Each Dict in the returned List contains the following items:
1061 bufnr For buffer-local autocmds, buffer number where
1062 the autocmd is defined.
1063 cmd Command executed for this autocmd.
1064 event Autocmd event name.
1065 group Autocmd group name.
Yegappan Lakshmanan971f6822022-05-24 11:40:11 +01001066 nested Boolean flag, set to v:true for a nested
1067 autocmd. See |autocmd-nested|.
1068 once Boolean flag, set to v:true, if the autocmd
1069 will be executed only once. See |autocmd-once|.
Yegappan Lakshmanan1755a912022-05-19 10:31:47 +01001070 pattern Autocmd pattern. For a buffer-local
1071 autocmd, this will be of the form "<buffer=n>".
1072 If there are multiple commands for an autocmd event in a
1073 group, then separate items are returned for each command.
1074
Bram Moolenaar016188f2022-06-06 20:52:59 +01001075 Returns an empty List if an autocmd with the specified group
1076 or event or pattern is not found.
1077
Yegappan Lakshmanan1755a912022-05-19 10:31:47 +01001078 Examples: >
1079 " :autocmd MyGroup
1080 echo autocmd_get(#{group: 'Mygroup'})
1081 " :autocmd G BufUnload
1082 echo autocmd_get(#{group: 'G', event: 'BufUnload'})
1083 " :autocmd G * *.ts
1084 let acmd = #{group: 'G', event: '*', pattern: '*.ts'}
1085 echo autocmd_get(acmd)
1086 " :autocmd Syntax
1087 echo autocmd_get(#{event: 'Syntax'})
1088 " :autocmd G BufEnter *.ts
1089 let acmd = #{group: 'G', event: 'BufEnter',
1090 \ pattern: '*.ts'}
1091 echo autocmd_get(acmd)
1092<
1093 Can also be used as a |method|: >
1094 Getopts()->autocmd_get()
1095<
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001096balloon_gettext() *balloon_gettext()*
1097 Return the current text in the balloon. Only for the string,
Bram Moolenaar016188f2022-06-06 20:52:59 +01001098 not used for the List. Returns an empty string if balloon
1099 is not present.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001100
1101balloon_show({expr}) *balloon_show()*
1102 Show {expr} inside the balloon. For the GUI {expr} is used as
1103 a string. For a terminal {expr} can be a list, which contains
1104 the lines of the balloon. If {expr} is not a list it will be
1105 split with |balloon_split()|.
1106 If {expr} is an empty string any existing balloon is removed.
1107
1108 Example: >
1109 func GetBalloonContent()
1110 " ... initiate getting the content
1111 return ''
1112 endfunc
1113 set balloonexpr=GetBalloonContent()
1114
1115 func BalloonCallback(result)
1116 call balloon_show(a:result)
1117 endfunc
1118< Can also be used as a |method|: >
1119 GetText()->balloon_show()
1120<
1121 The intended use is that fetching the content of the balloon
1122 is initiated from 'balloonexpr'. It will invoke an
1123 asynchronous method, in which a callback invokes
1124 balloon_show(). The 'balloonexpr' itself can return an
Bram Moolenaar069a7d52022-06-27 22:16:08 +01001125 empty string or a placeholder, e.g. "loading...".
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001126
Bram Moolenaar069a7d52022-06-27 22:16:08 +01001127 When showing a balloon is not possible then nothing happens,
1128 no error message is given.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001129 {only available when compiled with the |+balloon_eval| or
1130 |+balloon_eval_term| feature}
1131
1132balloon_split({msg}) *balloon_split()*
1133 Split String {msg} into lines to be displayed in a balloon.
1134 The splits are made for the current window size and optimize
1135 to show debugger output.
Bram Moolenaar016188f2022-06-06 20:52:59 +01001136 Returns a |List| with the split lines. Returns an empty List
1137 on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001138 Can also be used as a |method|: >
1139 GetText()->balloon_split()->balloon_show()
1140
1141< {only available when compiled with the |+balloon_eval_term|
1142 feature}
1143
1144blob2list({blob}) *blob2list()*
1145 Return a List containing the number value of each byte in Blob
1146 {blob}. Examples: >
1147 blob2list(0z0102.0304) returns [1, 2, 3, 4]
1148 blob2list(0z) returns []
1149< Returns an empty List on error. |list2blob()| does the
1150 opposite.
1151
1152 Can also be used as a |method|: >
1153 GetBlob()->blob2list()
Bram Moolenaarb529cfb2022-07-25 15:42:07 +01001154<
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001155 *browse()*
1156browse({save}, {title}, {initdir}, {default})
1157 Put up a file requester. This only works when "has("browse")"
1158 returns |TRUE| (only in some GUI versions).
1159 The input fields are:
1160 {save} when |TRUE|, select file to write
1161 {title} title for the requester
1162 {initdir} directory to start browsing in
1163 {default} default file name
1164 An empty string is returned when the "Cancel" button is hit,
1165 something went wrong, or browsing is not possible.
1166
1167 *browsedir()*
1168browsedir({title}, {initdir})
1169 Put up a directory requester. This only works when
1170 "has("browse")" returns |TRUE| (only in some GUI versions).
1171 On systems where a directory browser is not supported a file
1172 browser is used. In that case: select a file in the directory
1173 to be used.
1174 The input fields are:
1175 {title} title for the requester
1176 {initdir} directory to start browsing in
1177 When the "Cancel" button is hit, something went wrong, or
1178 browsing is not possible, an empty string is returned.
1179
1180bufadd({name}) *bufadd()*
1181 Add a buffer to the buffer list with String {name}.
1182 If a buffer for file {name} already exists, return that buffer
1183 number. Otherwise return the buffer number of the newly
1184 created buffer. When {name} is an empty string then a new
1185 buffer is always created.
1186 The buffer will not have 'buflisted' set and not be loaded
1187 yet. To add some text to the buffer use this: >
1188 let bufnr = bufadd('someName')
1189 call bufload(bufnr)
1190 call setbufline(bufnr, 1, ['some', 'text'])
Bram Moolenaar016188f2022-06-06 20:52:59 +01001191< Returns 0 on error.
1192 Can also be used as a |method|: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001193 let bufnr = 'somename'->bufadd()
1194
1195bufexists({buf}) *bufexists()*
1196 The result is a Number, which is |TRUE| if a buffer called
1197 {buf} exists.
1198 If the {buf} argument is a number, buffer numbers are used.
1199 Number zero is the alternate buffer for the current window.
1200
1201 If the {buf} argument is a string it must match a buffer name
1202 exactly. The name can be:
1203 - Relative to the current directory.
1204 - A full path.
1205 - The name of a buffer with 'buftype' set to "nofile".
1206 - A URL name.
1207 Unlisted buffers will be found.
1208 Note that help files are listed by their short name in the
1209 output of |:buffers|, but bufexists() requires using their
1210 long name to be able to find them.
1211 bufexists() may report a buffer exists, but to use the name
1212 with a |:buffer| command you may need to use |expand()|. Esp
1213 for MS-Windows 8.3 names in the form "c:\DOCUME~1"
1214 Use "bufexists(0)" to test for the existence of an alternate
1215 file name.
1216
1217 Can also be used as a |method|: >
1218 let exists = 'somename'->bufexists()
1219<
1220 Obsolete name: buffer_exists(). *buffer_exists()*
1221
1222buflisted({buf}) *buflisted()*
1223 The result is a Number, which is |TRUE| if a buffer called
1224 {buf} exists and is listed (has the 'buflisted' option set).
1225 The {buf} argument is used like with |bufexists()|.
1226
1227 Can also be used as a |method|: >
1228 let listed = 'somename'->buflisted()
1229
1230bufload({buf}) *bufload()*
1231 Ensure the buffer {buf} is loaded. When the buffer name
1232 refers to an existing file then the file is read. Otherwise
1233 the buffer will be empty. If the buffer was already loaded
1234 then there is no change.
1235 If there is an existing swap file for the file of the buffer,
1236 there will be no dialog, the buffer will be loaded anyway.
1237 The {buf} argument is used like with |bufexists()|.
1238
1239 Can also be used as a |method|: >
1240 eval 'somename'->bufload()
1241
1242bufloaded({buf}) *bufloaded()*
1243 The result is a Number, which is |TRUE| if a buffer called
1244 {buf} exists and is loaded (shown in a window or hidden).
1245 The {buf} argument is used like with |bufexists()|.
1246
1247 Can also be used as a |method|: >
1248 let loaded = 'somename'->bufloaded()
1249
1250bufname([{buf}]) *bufname()*
1251 The result is the name of a buffer. Mostly as it is displayed
1252 by the `:ls` command, but not using special names such as
1253 "[No Name]".
1254 If {buf} is omitted the current buffer is used.
1255 If {buf} is a Number, that buffer number's name is given.
1256 Number zero is the alternate buffer for the current window.
1257 If {buf} is a String, it is used as a |file-pattern| to match
1258 with the buffer names. This is always done like 'magic' is
1259 set and 'cpoptions' is empty. When there is more than one
1260 match an empty string is returned.
1261 "" or "%" can be used for the current buffer, "#" for the
1262 alternate buffer.
1263 A full match is preferred, otherwise a match at the start, end
1264 or middle of the buffer name is accepted. If you only want a
1265 full match then put "^" at the start and "$" at the end of the
1266 pattern.
1267 Listed buffers are found first. If there is a single match
1268 with a listed buffer, that one is returned. Next unlisted
1269 buffers are searched for.
1270 If the {buf} is a String, but you want to use it as a buffer
1271 number, force it to be a Number by adding zero to it: >
1272 :echo bufname("3" + 0)
1273< Can also be used as a |method|: >
1274 echo bufnr->bufname()
1275
1276< If the buffer doesn't exist, or doesn't have a name, an empty
1277 string is returned. >
1278 bufname("#") alternate buffer name
1279 bufname(3) name of buffer 3
1280 bufname("%") name of current buffer
1281 bufname("file2") name of buffer where "file2" matches.
1282< *buffer_name()*
1283 Obsolete name: buffer_name().
1284
1285 *bufnr()*
1286bufnr([{buf} [, {create}]])
1287 The result is the number of a buffer, as it is displayed by
1288 the `:ls` command. For the use of {buf}, see |bufname()|
1289 above.
1290
1291 If the buffer doesn't exist, -1 is returned. Or, if the
1292 {create} argument is present and TRUE, a new, unlisted,
1293 buffer is created and its number is returned. Example: >
1294 let newbuf = bufnr('Scratch001', 1)
1295< Using an empty name uses the current buffer. To create a new
1296 buffer with an empty name use |bufadd()|.
1297
1298 bufnr("$") is the last buffer: >
1299 :let last_buffer = bufnr("$")
1300< The result is a Number, which is the highest buffer number
1301 of existing buffers. Note that not all buffers with a smaller
1302 number necessarily exist, because ":bwipeout" may have removed
1303 them. Use bufexists() to test for the existence of a buffer.
1304
1305 Can also be used as a |method|: >
1306 echo bufref->bufnr()
1307<
1308 Obsolete name: buffer_number(). *buffer_number()*
1309 *last_buffer_nr()*
1310 Obsolete name for bufnr("$"): last_buffer_nr().
1311
1312bufwinid({buf}) *bufwinid()*
1313 The result is a Number, which is the |window-ID| of the first
1314 window associated with buffer {buf}. For the use of {buf},
1315 see |bufname()| above. If buffer {buf} doesn't exist or
1316 there is no such window, -1 is returned. Example: >
1317
Bram Moolenaarc51cf032022-02-26 12:25:45 +00001318 echo "A window containing buffer 1 is " .. (bufwinid(1))
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001319<
1320 Only deals with the current tab page.
1321
1322 Can also be used as a |method|: >
1323 FindBuffer()->bufwinid()
1324
1325bufwinnr({buf}) *bufwinnr()*
1326 Like |bufwinid()| but return the window number instead of the
1327 |window-ID|.
1328 If buffer {buf} doesn't exist or there is no such window, -1
1329 is returned. Example: >
1330
Bram Moolenaarc51cf032022-02-26 12:25:45 +00001331 echo "A window containing buffer 1 is " .. (bufwinnr(1))
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001332
1333< The number can be used with |CTRL-W_w| and ":wincmd w"
1334 |:wincmd|.
1335
1336 Can also be used as a |method|: >
1337 FindBuffer()->bufwinnr()
1338
1339byte2line({byte}) *byte2line()*
1340 Return the line number that contains the character at byte
1341 count {byte} in the current buffer. This includes the
1342 end-of-line character, depending on the 'fileformat' option
1343 for the current buffer. The first character has byte count
1344 one.
1345 Also see |line2byte()|, |go| and |:goto|.
1346
Bram Moolenaar016188f2022-06-06 20:52:59 +01001347 Returns -1 if the {byte} value is invalid.
1348
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001349 Can also be used as a |method|: >
1350 GetOffset()->byte2line()
1351
1352< {not available when compiled without the |+byte_offset|
1353 feature}
1354
1355byteidx({expr}, {nr}) *byteidx()*
1356 Return byte index of the {nr}'th character in the String
1357 {expr}. Use zero for the first character, it then returns
1358 zero.
1359 If there are no multibyte characters the returned value is
1360 equal to {nr}.
1361 Composing characters are not counted separately, their byte
1362 length is added to the preceding base character. See
1363 |byteidxcomp()| below for counting composing characters
1364 separately.
1365 Example : >
1366 echo matchstr(str, ".", byteidx(str, 3))
1367< will display the fourth character. Another way to do the
1368 same: >
1369 let s = strpart(str, byteidx(str, 3))
1370 echo strpart(s, 0, byteidx(s, 1))
1371< Also see |strgetchar()| and |strcharpart()|.
1372
1373 If there are less than {nr} characters -1 is returned.
1374 If there are exactly {nr} characters the length of the string
1375 in bytes is returned.
1376
1377 Can also be used as a |method|: >
1378 GetName()->byteidx(idx)
1379
1380byteidxcomp({expr}, {nr}) *byteidxcomp()*
1381 Like byteidx(), except that a composing character is counted
1382 as a separate character. Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00001383 let s = 'e' .. nr2char(0x301)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001384 echo byteidx(s, 1)
1385 echo byteidxcomp(s, 1)
1386 echo byteidxcomp(s, 2)
1387< The first and third echo result in 3 ('e' plus composing
1388 character is 3 bytes), the second echo results in 1 ('e' is
1389 one byte).
1390 Only works differently from byteidx() when 'encoding' is set
1391 to a Unicode encoding.
1392
1393 Can also be used as a |method|: >
1394 GetName()->byteidxcomp(idx)
1395
1396call({func}, {arglist} [, {dict}]) *call()* *E699*
1397 Call function {func} with the items in |List| {arglist} as
1398 arguments.
1399 {func} can either be a |Funcref| or the name of a function.
1400 a:firstline and a:lastline are set to the cursor line.
1401 Returns the return value of the called function.
1402 {dict} is for functions with the "dict" attribute. It will be
1403 used to set the local variable "self". |Dictionary-function|
1404
1405 Can also be used as a |method|: >
1406 GetFunc()->call([arg, arg], dict)
1407
1408ceil({expr}) *ceil()*
1409 Return the smallest integral value greater than or equal to
1410 {expr} as a |Float| (round up).
1411 {expr} must evaluate to a |Float| or a |Number|.
1412 Examples: >
1413 echo ceil(1.456)
1414< 2.0 >
1415 echo ceil(-5.456)
1416< -5.0 >
1417 echo ceil(4.0)
1418< 4.0
1419
Bram Moolenaar016188f2022-06-06 20:52:59 +01001420 Returns 0.0 if {expr} is not a |Float| or a |Number|.
1421
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001422 Can also be used as a |method|: >
1423 Compute()->ceil()
1424<
1425 {only available when compiled with the |+float| feature}
1426
1427
1428ch_ functions are documented here: |channel-functions-details|
1429
1430
1431changenr() *changenr()*
1432 Return the number of the most recent change. This is the same
1433 number as what is displayed with |:undolist| and can be used
1434 with the |:undo| command.
1435 When a change was made it is the number of that change. After
1436 redo it is the number of the redone change. After undo it is
1437 one less than the number of the undone change.
Bram Moolenaar016188f2022-06-06 20:52:59 +01001438 Returns 0 if the undo list is empty.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001439
1440char2nr({string} [, {utf8}]) *char2nr()*
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01001441 Return Number value of the first char in {string}.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001442 Examples: >
1443 char2nr(" ") returns 32
1444 char2nr("ABC") returns 65
1445< When {utf8} is omitted or zero, the current 'encoding' is used.
1446 Example for "utf-8": >
1447 char2nr("á") returns 225
1448 char2nr("á"[0]) returns 195
1449< When {utf8} is TRUE, always treat as UTF-8 characters.
1450 A combining character is a separate character.
1451 |nr2char()| does the opposite.
1452 To turn a string into a list of character numbers: >
1453 let str = "ABC"
1454 let list = map(split(str, '\zs'), {_, val -> char2nr(val)})
1455< Result: [65, 66, 67]
1456
Bram Moolenaar016188f2022-06-06 20:52:59 +01001457 Returns 0 if {string} is not a |String|.
1458
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001459 Can also be used as a |method|: >
1460 GetChar()->char2nr()
1461
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001462charclass({string}) *charclass()*
1463 Return the character class of the first character in {string}.
1464 The character class is one of:
1465 0 blank
1466 1 punctuation
1467 2 word character
1468 3 emoji
1469 other specific Unicode class
1470 The class is used in patterns and word motions.
Bram Moolenaar016188f2022-06-06 20:52:59 +01001471 Returns 0 if {string} is not a |String|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001472
1473
1474charcol({expr}) *charcol()*
1475 Same as |col()| but returns the character index of the column
1476 position given with {expr} instead of the byte position.
1477
1478 Example:
1479 With the cursor on '세' in line 5 with text "여보세요": >
1480 charcol('.') returns 3
1481 col('.') returns 7
1482
1483< Can also be used as a |method|: >
1484 GetPos()->col()
1485<
1486 *charidx()*
1487charidx({string}, {idx} [, {countcc}])
1488 Return the character index of the byte at {idx} in {string}.
1489 The index of the first character is zero.
1490 If there are no multibyte characters the returned value is
1491 equal to {idx}.
1492 When {countcc} is omitted or |FALSE|, then composing characters
1493 are not counted separately, their byte length is
1494 added to the preceding base character.
1495 When {countcc} is |TRUE|, then composing characters are
1496 counted as separate characters.
1497 Returns -1 if the arguments are invalid or if {idx} is greater
1498 than the index of the last byte in {string}. An error is
1499 given if the first argument is not a string, the second
1500 argument is not a number or when the third argument is present
1501 and is not zero or one.
1502 See |byteidx()| and |byteidxcomp()| for getting the byte index
1503 from the character index.
1504 Examples: >
1505 echo charidx('áb́ć', 3) returns 1
1506 echo charidx('áb́ć', 6, 1) returns 4
1507 echo charidx('áb́ć', 16) returns -1
1508<
1509 Can also be used as a |method|: >
1510 GetName()->charidx(idx)
1511
1512chdir({dir}) *chdir()*
1513 Change the current working directory to {dir}. The scope of
1514 the directory change depends on the directory of the current
1515 window:
1516 - If the current window has a window-local directory
1517 (|:lcd|), then changes the window local directory.
1518 - Otherwise, if the current tabpage has a local
1519 directory (|:tcd|) then changes the tabpage local
1520 directory.
1521 - Otherwise, changes the global directory.
1522 {dir} must be a String.
1523 If successful, returns the previous working directory. Pass
1524 this to another chdir() to restore the directory.
1525 On failure, returns an empty string.
1526
1527 Example: >
1528 let save_dir = chdir(newdir)
1529 if save_dir != ""
1530 " ... do some work
1531 call chdir(save_dir)
1532 endif
1533
1534< Can also be used as a |method|: >
1535 GetDir()->chdir()
1536<
1537cindent({lnum}) *cindent()*
1538 Get the amount of indent for line {lnum} according the C
1539 indenting rules, as with 'cindent'.
1540 The indent is counted in spaces, the value of 'tabstop' is
1541 relevant. {lnum} is used just like in |getline()|.
Bram Moolenaar8e145b82022-05-21 20:17:31 +01001542 When {lnum} is invalid -1 is returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001543 See |C-indenting|.
1544
1545 Can also be used as a |method|: >
1546 GetLnum()->cindent()
1547
1548clearmatches([{win}]) *clearmatches()*
1549 Clears all matches previously defined for the current window
1550 by |matchadd()| and the |:match| commands.
1551 If {win} is specified, use the window with this number or
1552 window ID instead of the current window.
1553
1554 Can also be used as a |method|: >
1555 GetWin()->clearmatches()
1556<
1557 *col()*
1558col({expr}) The result is a Number, which is the byte index of the column
1559 position given with {expr}. The accepted positions are:
1560 . the cursor position
1561 $ the end of the cursor line (the result is the
1562 number of bytes in the cursor line plus one)
1563 'x position of mark x (if the mark is not set, 0 is
1564 returned)
1565 v In Visual mode: the start of the Visual area (the
1566 cursor is the end). When not in Visual mode
1567 returns the cursor position. Differs from |'<| in
1568 that it's updated right away.
1569 Additionally {expr} can be [lnum, col]: a |List| with the line
1570 and column number. Most useful when the column is "$", to get
1571 the last column of a specific line. When "lnum" or "col" is
1572 out of range then col() returns zero.
1573 To get the line number use |line()|. To get both use
1574 |getpos()|.
1575 For the screen column position use |virtcol()|. For the
1576 character position use |charcol()|.
1577 Note that only marks in the current file can be used.
1578 Examples: >
1579 col(".") column of cursor
1580 col("$") length of cursor line plus one
1581 col("'t") column of mark t
Bram Moolenaarc51cf032022-02-26 12:25:45 +00001582 col("'" .. markname) column of mark markname
Bram Moolenaar016188f2022-06-06 20:52:59 +01001583< The first column is 1. Returns 0 if {expr} is invalid.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001584 For an uppercase mark the column may actually be in another
1585 buffer.
1586 For the cursor position, when 'virtualedit' is active, the
1587 column is one higher if the cursor is after the end of the
1588 line. This can be used to obtain the column in Insert mode: >
1589 :imap <F2> <C-O>:let save_ve = &ve<CR>
1590 \<C-O>:set ve=all<CR>
Bram Moolenaarc51cf032022-02-26 12:25:45 +00001591 \<C-O>:echo col(".") .. "\n" <Bar>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001592 \let &ve = save_ve<CR>
1593
1594< Can also be used as a |method|: >
1595 GetPos()->col()
1596<
1597
1598complete({startcol}, {matches}) *complete()* *E785*
1599 Set the matches for Insert mode completion.
1600 Can only be used in Insert mode. You need to use a mapping
1601 with CTRL-R = (see |i_CTRL-R|). It does not work after CTRL-O
1602 or with an expression mapping.
1603 {startcol} is the byte offset in the line where the completed
1604 text start. The text up to the cursor is the original text
1605 that will be replaced by the matches. Use col('.') for an
1606 empty string. "col('.') - 1" will replace one character by a
1607 match.
1608 {matches} must be a |List|. Each |List| item is one match.
1609 See |complete-items| for the kind of items that are possible.
1610 "longest" in 'completeopt' is ignored.
1611 Note that the after calling this function you need to avoid
1612 inserting anything that would cause completion to stop.
1613 The match can be selected with CTRL-N and CTRL-P as usual with
1614 Insert mode completion. The popup menu will appear if
1615 specified, see |ins-completion-menu|.
1616 Example: >
1617 inoremap <F5> <C-R>=ListMonths()<CR>
1618
1619 func! ListMonths()
1620 call complete(col('.'), ['January', 'February', 'March',
1621 \ 'April', 'May', 'June', 'July', 'August', 'September',
1622 \ 'October', 'November', 'December'])
1623 return ''
1624 endfunc
1625< This isn't very useful, but it shows how it works. Note that
1626 an empty string is returned to avoid a zero being inserted.
1627
1628 Can also be used as a |method|, the base is passed as the
1629 second argument: >
1630 GetMatches()->complete(col('.'))
1631
1632complete_add({expr}) *complete_add()*
1633 Add {expr} to the list of matches. Only to be used by the
1634 function specified with the 'completefunc' option.
1635 Returns 0 for failure (empty string or out of memory),
1636 1 when the match was added, 2 when the match was already in
1637 the list.
1638 See |complete-functions| for an explanation of {expr}. It is
1639 the same as one item in the list that 'omnifunc' would return.
1640
1641 Can also be used as a |method|: >
1642 GetMoreMatches()->complete_add()
1643
1644complete_check() *complete_check()*
1645 Check for a key typed while looking for completion matches.
1646 This is to be used when looking for matches takes some time.
1647 Returns |TRUE| when searching for matches is to be aborted,
1648 zero otherwise.
1649 Only to be used by the function specified with the
1650 'completefunc' option.
1651
1652
1653complete_info([{what}]) *complete_info()*
1654 Returns a |Dictionary| with information about Insert mode
1655 completion. See |ins-completion|.
1656 The items are:
1657 mode Current completion mode name string.
1658 See |complete_info_mode| for the values.
1659 pum_visible |TRUE| if popup menu is visible.
1660 See |pumvisible()|.
1661 items List of completion matches. Each item is a
1662 dictionary containing the entries "word",
1663 "abbr", "menu", "kind", "info" and "user_data".
1664 See |complete-items|.
1665 selected Selected item index. First index is zero.
1666 Index is -1 if no item is selected (showing
1667 typed text only, or the last completion after
1668 no item is selected when using the <Up> or
1669 <Down> keys)
1670 inserted Inserted string. [NOT IMPLEMENT YET]
1671
1672 *complete_info_mode*
1673 mode values are:
1674 "" Not in completion mode
1675 "keyword" Keyword completion |i_CTRL-X_CTRL-N|
1676 "ctrl_x" Just pressed CTRL-X |i_CTRL-X|
1677 "scroll" Scrolling with |i_CTRL-X_CTRL-E| or
1678 |i_CTRL-X_CTRL-Y|
1679 "whole_line" Whole lines |i_CTRL-X_CTRL-L|
1680 "files" File names |i_CTRL-X_CTRL-F|
1681 "tags" Tags |i_CTRL-X_CTRL-]|
1682 "path_defines" Definition completion |i_CTRL-X_CTRL-D|
1683 "path_patterns" Include completion |i_CTRL-X_CTRL-I|
1684 "dictionary" Dictionary |i_CTRL-X_CTRL-K|
1685 "thesaurus" Thesaurus |i_CTRL-X_CTRL-T|
1686 "cmdline" Vim Command line |i_CTRL-X_CTRL-V|
1687 "function" User defined completion |i_CTRL-X_CTRL-U|
1688 "omni" Omni completion |i_CTRL-X_CTRL-O|
1689 "spell" Spelling suggestions |i_CTRL-X_s|
1690 "eval" |complete()| completion
1691 "unknown" Other internal modes
1692
1693 If the optional {what} list argument is supplied, then only
1694 the items listed in {what} are returned. Unsupported items in
1695 {what} are silently ignored.
1696
1697 To get the position and size of the popup menu, see
1698 |pum_getpos()|. It's also available in |v:event| during the
1699 |CompleteChanged| event.
1700
Bram Moolenaar016188f2022-06-06 20:52:59 +01001701 Returns an empty |Dictionary| on error.
1702
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001703 Examples: >
1704 " Get all items
1705 call complete_info()
1706 " Get only 'mode'
1707 call complete_info(['mode'])
1708 " Get only 'mode' and 'pum_visible'
1709 call complete_info(['mode', 'pum_visible'])
1710
1711< Can also be used as a |method|: >
1712 GetItems()->complete_info()
1713<
1714 *confirm()*
1715confirm({msg} [, {choices} [, {default} [, {type}]]])
1716 confirm() offers the user a dialog, from which a choice can be
1717 made. It returns the number of the choice. For the first
1718 choice this is 1.
1719 Note: confirm() is only supported when compiled with dialog
1720 support, see |+dialog_con| and |+dialog_gui|.
1721
1722 {msg} is displayed in a |dialog| with {choices} as the
1723 alternatives. When {choices} is missing or empty, "&OK" is
1724 used (and translated).
1725 {msg} is a String, use '\n' to include a newline. Only on
1726 some systems the string is wrapped when it doesn't fit.
1727
1728 {choices} is a String, with the individual choices separated
1729 by '\n', e.g. >
1730 confirm("Save changes?", "&Yes\n&No\n&Cancel")
1731< The letter after the '&' is the shortcut key for that choice.
1732 Thus you can type 'c' to select "Cancel". The shortcut does
1733 not need to be the first letter: >
1734 confirm("file has been modified", "&Save\nSave &All")
1735< For the console, the first letter of each choice is used as
1736 the default shortcut key. Case is ignored.
1737
1738 The optional {default} argument is the number of the choice
1739 that is made if the user hits <CR>. Use 1 to make the first
1740 choice the default one. Use 0 to not set a default. If
1741 {default} is omitted, 1 is used.
1742
1743 The optional {type} String argument gives the type of dialog.
1744 This is only used for the icon of the GTK, Mac, Motif and
1745 Win32 GUI. It can be one of these values: "Error",
1746 "Question", "Info", "Warning" or "Generic". Only the first
1747 character is relevant. When {type} is omitted, "Generic" is
1748 used.
1749
1750 If the user aborts the dialog by pressing <Esc>, CTRL-C,
1751 or another valid interrupt key, confirm() returns 0.
1752
1753 An example: >
Bram Moolenaar46eea442022-03-30 10:51:39 +01001754 let choice = confirm("What do you want?",
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01001755 \ "&Apples\n&Oranges\n&Bananas", 2)
Bram Moolenaar46eea442022-03-30 10:51:39 +01001756 if choice == 0
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01001757 echo "make up your mind!"
Bram Moolenaar46eea442022-03-30 10:51:39 +01001758 elseif choice == 3
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01001759 echo "tasteful"
Bram Moolenaar46eea442022-03-30 10:51:39 +01001760 else
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01001761 echo "I prefer bananas myself."
Bram Moolenaar46eea442022-03-30 10:51:39 +01001762 endif
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001763< In a GUI dialog, buttons are used. The layout of the buttons
1764 depends on the 'v' flag in 'guioptions'. If it is included,
1765 the buttons are always put vertically. Otherwise, confirm()
1766 tries to put the buttons in one horizontal line. If they
1767 don't fit, a vertical layout is used anyway. For some systems
1768 the horizontal layout is always used.
1769
1770 Can also be used as a |method|in: >
1771 BuildMessage()->confirm("&Yes\n&No")
1772<
1773 *copy()*
1774copy({expr}) Make a copy of {expr}. For Numbers and Strings this isn't
1775 different from using {expr} directly.
1776 When {expr} is a |List| a shallow copy is created. This means
1777 that the original |List| can be changed without changing the
1778 copy, and vice versa. But the items are identical, thus
1779 changing an item changes the contents of both |Lists|.
1780 A |Dictionary| is copied in a similar way as a |List|.
1781 Also see |deepcopy()|.
1782 Can also be used as a |method|: >
1783 mylist->copy()
1784
1785cos({expr}) *cos()*
1786 Return the cosine of {expr}, measured in radians, as a |Float|.
1787 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar016188f2022-06-06 20:52:59 +01001788 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001789 Examples: >
1790 :echo cos(100)
1791< 0.862319 >
1792 :echo cos(-4.01)
1793< -0.646043
1794
1795 Can also be used as a |method|: >
1796 Compute()->cos()
1797<
1798 {only available when compiled with the |+float| feature}
1799
1800
1801cosh({expr}) *cosh()*
1802 Return the hyperbolic cosine of {expr} as a |Float| in the range
1803 [1, inf].
1804 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar016188f2022-06-06 20:52:59 +01001805 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001806 Examples: >
1807 :echo cosh(0.5)
1808< 1.127626 >
1809 :echo cosh(-0.5)
1810< -1.127626
1811
1812 Can also be used as a |method|: >
1813 Compute()->cosh()
1814<
1815 {only available when compiled with the |+float| feature}
1816
1817
1818count({comp}, {expr} [, {ic} [, {start}]]) *count()*
1819 Return the number of times an item with value {expr} appears
1820 in |String|, |List| or |Dictionary| {comp}.
1821
1822 If {start} is given then start with the item with this index.
1823 {start} can only be used with a |List|.
1824
1825 When {ic} is given and it's |TRUE| then case is ignored.
1826
1827 When {comp} is a string then the number of not overlapping
1828 occurrences of {expr} is returned. Zero is returned when
1829 {expr} is an empty string.
1830
1831 Can also be used as a |method|: >
1832 mylist->count(val)
1833<
1834 *cscope_connection()*
1835cscope_connection([{num} , {dbpath} [, {prepend}]])
1836 Checks for the existence of a |cscope| connection. If no
1837 parameters are specified, then the function returns:
1838 0, if cscope was not available (not compiled in), or
1839 if there are no cscope connections;
1840 1, if there is at least one cscope connection.
1841
1842 If parameters are specified, then the value of {num}
1843 determines how existence of a cscope connection is checked:
1844
1845 {num} Description of existence check
1846 ----- ------------------------------
1847 0 Same as no parameters (e.g., "cscope_connection()").
1848 1 Ignore {prepend}, and use partial string matches for
1849 {dbpath}.
1850 2 Ignore {prepend}, and use exact string matches for
1851 {dbpath}.
1852 3 Use {prepend}, use partial string matches for both
1853 {dbpath} and {prepend}.
1854 4 Use {prepend}, use exact string matches for both
1855 {dbpath} and {prepend}.
1856
1857 Note: All string comparisons are case sensitive!
1858
1859 Examples. Suppose we had the following (from ":cs show"): >
1860
1861 # pid database name prepend path
1862 0 27664 cscope.out /usr/local
1863<
1864 Invocation Return Val ~
1865 ---------- ---------- >
1866 cscope_connection() 1
1867 cscope_connection(1, "out") 1
1868 cscope_connection(2, "out") 0
1869 cscope_connection(3, "out") 0
1870 cscope_connection(3, "out", "local") 1
1871 cscope_connection(4, "out") 0
1872 cscope_connection(4, "out", "local") 0
1873 cscope_connection(4, "cscope.out", "/usr/local") 1
1874<
1875cursor({lnum}, {col} [, {off}]) *cursor()*
1876cursor({list})
1877 Positions the cursor at the column (byte count) {col} in the
1878 line {lnum}. The first column is one.
1879
1880 When there is one argument {list} this is used as a |List|
1881 with two, three or four item:
1882 [{lnum}, {col}]
1883 [{lnum}, {col}, {off}]
1884 [{lnum}, {col}, {off}, {curswant}]
1885 This is like the return value of |getpos()| or |getcurpos()|,
1886 but without the first item.
1887
1888 To position the cursor using the character count, use
1889 |setcursorcharpos()|.
1890
1891 Does not change the jumplist.
1892 {lnum} is used like with |getline()|.
1893 If {lnum} is greater than the number of lines in the buffer,
1894 the cursor will be positioned at the last line in the buffer.
1895 If {lnum} is zero, the cursor will stay in the current line.
1896 If {col} is greater than the number of bytes in the line,
1897 the cursor will be positioned at the last character in the
1898 line.
1899 If {col} is zero, the cursor will stay in the current column.
1900 If {curswant} is given it is used to set the preferred column
1901 for vertical movement. Otherwise {col} is used.
1902
1903 When 'virtualedit' is used {off} specifies the offset in
1904 screen columns from the start of the character. E.g., a
1905 position within a <Tab> or after the last character.
1906 Returns 0 when the position could be set, -1 otherwise.
1907
1908 Can also be used as a |method|: >
1909 GetCursorPos()->cursor()
1910
1911debugbreak({pid}) *debugbreak()*
1912 Specifically used to interrupt a program being debugged. It
1913 will cause process {pid} to get a SIGTRAP. Behavior for other
1914 processes is undefined. See |terminal-debugger|.
1915 {only available on MS-Windows}
1916
Bram Moolenaar016188f2022-06-06 20:52:59 +01001917 Returns |TRUE| if successfully interrupted the program.
1918 Otherwise returns |FALSE|.
1919
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001920 Can also be used as a |method|: >
1921 GetPid()->debugbreak()
1922
1923deepcopy({expr} [, {noref}]) *deepcopy()* *E698*
1924 Make a copy of {expr}. For Numbers and Strings this isn't
1925 different from using {expr} directly.
1926 When {expr} is a |List| a full copy is created. This means
1927 that the original |List| can be changed without changing the
1928 copy, and vice versa. When an item is a |List| or
1929 |Dictionary|, a copy for it is made, recursively. Thus
1930 changing an item in the copy does not change the contents of
1931 the original |List|.
1932 A |Dictionary| is copied in a similar way as a |List|.
1933
1934 When {noref} is omitted or zero a contained |List| or
1935 |Dictionary| is only copied once. All references point to
1936 this single copy. With {noref} set to 1 every occurrence of a
1937 |List| or |Dictionary| results in a new copy. This also means
1938 that a cyclic reference causes deepcopy() to fail.
1939 *E724*
1940 Nesting is possible up to 100 levels. When there is an item
1941 that refers back to a higher level making a deep copy with
1942 {noref} set to 1 will fail.
1943 Also see |copy()|.
1944
1945 Can also be used as a |method|: >
1946 GetObject()->deepcopy()
1947
1948delete({fname} [, {flags}]) *delete()*
1949 Without {flags} or with {flags} empty: Deletes the file by the
Bram Moolenaarcbaff5e2022-04-08 17:45:08 +01001950 name {fname}.
1951
1952 This also works when {fname} is a symbolic link. The symbolic
1953 link itself is deleted, not what it points to.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001954
1955 When {flags} is "d": Deletes the directory by the name
1956 {fname}. This fails when directory {fname} is not empty.
1957
1958 When {flags} is "rf": Deletes the directory by the name
1959 {fname} and everything in it, recursively. BE CAREFUL!
1960 Note: on MS-Windows it is not possible to delete a directory
1961 that is being used.
1962
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001963 The result is a Number, which is 0/false if the delete
1964 operation was successful and -1/true when the deletion failed
1965 or partly failed.
1966
1967 Use |remove()| to delete an item from a |List|.
1968 To delete a line from the buffer use |:delete| or
1969 |deletebufline()|.
1970
1971 Can also be used as a |method|: >
1972 GetName()->delete()
1973
1974deletebufline({buf}, {first} [, {last}]) *deletebufline()*
1975 Delete lines {first} to {last} (inclusive) from buffer {buf}.
1976 If {last} is omitted then delete line {first} only.
1977 On success 0 is returned, on failure 1 is returned.
1978
1979 This function works only for loaded buffers. First call
1980 |bufload()| if needed.
1981
1982 For the use of {buf}, see |bufname()| above.
1983
1984 {first} and {last} are used like with |getline()|. Note that
1985 when using |line()| this refers to the current buffer. Use "$"
1986 to refer to the last line in buffer {buf}.
1987
1988 Can also be used as a |method|: >
1989 GetBuffer()->deletebufline(1)
1990<
1991 *did_filetype()*
1992did_filetype() Returns |TRUE| when autocommands are being executed and the
1993 FileType event has been triggered at least once. Can be used
1994 to avoid triggering the FileType event again in the scripts
1995 that detect the file type. |FileType|
1996 Returns |FALSE| when `:setf FALLBACK` was used.
1997 When editing another file, the counter is reset, thus this
1998 really checks if the FileType event has been triggered for the
1999 current buffer. This allows an autocommand that starts
2000 editing another buffer to set 'filetype' and load a syntax
2001 file.
2002
2003diff_filler({lnum}) *diff_filler()*
2004 Returns the number of filler lines above line {lnum}.
2005 These are the lines that were inserted at this point in
2006 another diff'ed window. These filler lines are shown in the
2007 display but don't exist in the buffer.
2008 {lnum} is used like with |getline()|. Thus "." is the current
2009 line, "'m" mark m, etc.
2010 Returns 0 if the current window is not in diff mode.
2011
2012 Can also be used as a |method|: >
2013 GetLnum()->diff_filler()
2014
2015diff_hlID({lnum}, {col}) *diff_hlID()*
2016 Returns the highlight ID for diff mode at line {lnum} column
2017 {col} (byte index). When the current line does not have a
2018 diff change zero is returned.
2019 {lnum} is used like with |getline()|. Thus "." is the current
2020 line, "'m" mark m, etc.
2021 {col} is 1 for the leftmost column, {lnum} is 1 for the first
2022 line.
2023 The highlight ID can be used with |synIDattr()| to obtain
2024 syntax information about the highlighting.
2025
2026 Can also be used as a |method|: >
2027 GetLnum()->diff_hlID(col)
2028<
2029
2030digraph_get({chars}) *digraph_get()* *E1214*
2031 Return the digraph of {chars}. This should be a string with
2032 exactly two characters. If {chars} are not just two
2033 characters, or the digraph of {chars} does not exist, an error
2034 is given and an empty string is returned.
2035
2036 The character will be converted from Unicode to 'encoding'
2037 when needed. This does require the conversion to be
2038 available, it might fail.
2039
2040 Also see |digraph_getlist()|.
2041
2042 Examples: >
2043 " Get a built-in digraph
2044 :echo digraph_get('00') " Returns '∞'
2045
2046 " Get a user-defined digraph
2047 :call digraph_set('aa', 'あ')
2048 :echo digraph_get('aa') " Returns 'あ'
2049<
2050 Can also be used as a |method|: >
2051 GetChars()->digraph_get()
2052<
2053 This function works only when compiled with the |+digraphs|
2054 feature. If this feature is disabled, this function will
2055 display an error message.
2056
2057
2058digraph_getlist([{listall}]) *digraph_getlist()*
2059 Return a list of digraphs. If the {listall} argument is given
2060 and it is TRUE, return all digraphs, including the default
2061 digraphs. Otherwise, return only user-defined digraphs.
2062
2063 The characters will be converted from Unicode to 'encoding'
2064 when needed. This does require the conservation to be
2065 available, it might fail.
2066
2067 Also see |digraph_get()|.
2068
2069 Examples: >
2070 " Get user-defined digraphs
2071 :echo digraph_getlist()
2072
2073 " Get all the digraphs, including default digraphs
2074 :echo digraph_getlist(1)
2075<
2076 Can also be used as a |method|: >
2077 GetNumber()->digraph_getlist()
2078<
2079 This function works only when compiled with the |+digraphs|
2080 feature. If this feature is disabled, this function will
2081 display an error message.
2082
2083
Bram Moolenaara2baa732022-02-04 16:09:54 +00002084digraph_set({chars}, {digraph}) *digraph_set()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002085 Add digraph {chars} to the list. {chars} must be a string
2086 with two characters. {digraph} is a string with one UTF-8
Bram Moolenaara2baa732022-02-04 16:09:54 +00002087 encoded character. *E1215*
2088 Be careful, composing characters are NOT ignored. This
2089 function is similar to |:digraphs| command, but useful to add
2090 digraphs start with a white space.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002091
2092 The function result is v:true if |digraph| is registered. If
2093 this fails an error message is given and v:false is returned.
2094
2095 If you want to define multiple digraphs at once, you can use
2096 |digraph_setlist()|.
2097
2098 Example: >
2099 call digraph_set(' ', 'あ')
2100<
2101 Can be used as a |method|: >
2102 GetString()->digraph_set('あ')
2103<
2104 This function works only when compiled with the |+digraphs|
2105 feature. If this feature is disabled, this function will
2106 display an error message.
2107
2108
2109digraph_setlist({digraphlist}) *digraph_setlist()*
2110 Similar to |digraph_set()| but this function can add multiple
2111 digraphs at once. {digraphlist} is a list composed of lists,
2112 where each list contains two strings with {chars} and
Bram Moolenaara2baa732022-02-04 16:09:54 +00002113 {digraph} as in |digraph_set()|. *E1216*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002114 Example: >
2115 call digraph_setlist([['aa', 'あ'], ['ii', 'い']])
2116<
2117 It is similar to the following: >
2118 for [chars, digraph] in [['aa', 'あ'], ['ii', 'い']]
2119 call digraph_set(chars, digraph)
2120 endfor
2121< Except that the function returns after the first error,
2122 following digraphs will not be added.
2123
2124 Can be used as a |method|: >
2125 GetList()->digraph_setlist()
2126<
2127 This function works only when compiled with the |+digraphs|
2128 feature. If this feature is disabled, this function will
2129 display an error message.
2130
2131
2132echoraw({string}) *echoraw()*
2133 Output {string} as-is, including unprintable characters.
2134 This can be used to output a terminal code. For example, to
2135 disable modifyOtherKeys: >
2136 call echoraw(&t_TE)
2137< and to enable it again: >
2138 call echoraw(&t_TI)
2139< Use with care, you can mess up the terminal this way.
2140
2141
2142empty({expr}) *empty()*
2143 Return the Number 1 if {expr} is empty, zero otherwise.
2144 - A |List| or |Dictionary| is empty when it does not have any
2145 items.
2146 - A |String| is empty when its length is zero.
2147 - A |Number| and |Float| are empty when their value is zero.
2148 - |v:false|, |v:none| and |v:null| are empty, |v:true| is not.
2149 - A |Job| is empty when it failed to start.
2150 - A |Channel| is empty when it is closed.
2151 - A |Blob| is empty when its length is zero.
2152
2153 For a long |List| this is much faster than comparing the
2154 length with zero.
2155
2156 Can also be used as a |method|: >
2157 mylist->empty()
2158
2159environ() *environ()*
2160 Return all of environment variables as dictionary. You can
2161 check if an environment variable exists like this: >
2162 :echo has_key(environ(), 'HOME')
2163< Note that the variable name may be CamelCase; to ignore case
2164 use this: >
2165 :echo index(keys(environ()), 'HOME', 0, 1) != -1
2166
2167escape({string}, {chars}) *escape()*
2168 Escape the characters in {chars} that occur in {string} with a
2169 backslash. Example: >
2170 :echo escape('c:\program files\vim', ' \')
2171< results in: >
2172 c:\\program\ files\\vim
2173< Also see |shellescape()| and |fnameescape()|.
2174
2175 Can also be used as a |method|: >
2176 GetText()->escape(' \')
2177<
2178 *eval()*
2179eval({string}) Evaluate {string} and return the result. Especially useful to
2180 turn the result of |string()| back into the original value.
2181 This works for Numbers, Floats, Strings, Blobs and composites
2182 of them. Also works for |Funcref|s that refer to existing
2183 functions.
2184
2185 Can also be used as a |method|: >
2186 argv->join()->eval()
2187
2188eventhandler() *eventhandler()*
2189 Returns 1 when inside an event handler. That is that Vim got
2190 interrupted while waiting for the user to type a character,
2191 e.g., when dropping a file on Vim. This means interactive
2192 commands cannot be used. Otherwise zero is returned.
2193
2194executable({expr}) *executable()*
2195 This function checks if an executable with the name {expr}
2196 exists. {expr} must be the name of the program without any
2197 arguments.
2198 executable() uses the value of $PATH and/or the normal
2199 searchpath for programs. *PATHEXT*
2200 On MS-Windows the ".exe", ".bat", etc. can optionally be
2201 included. Then the extensions in $PATHEXT are tried. Thus if
2202 "foo.exe" does not exist, "foo.exe.bat" can be found. If
2203 $PATHEXT is not set then ".com;.exe;.bat;.cmd" is used. A dot
2204 by itself can be used in $PATHEXT to try using the name
2205 without an extension. When 'shell' looks like a Unix shell,
2206 then the name is also tried without adding an extension.
2207 On MS-Windows it only checks if the file exists and is not a
2208 directory, not if it's really executable.
2209 On MS-Windows an executable in the same directory as Vim is
Yasuhiro Matsumoto05cf63e2022-05-03 11:02:28 +01002210 normally found. Since this directory is added to $PATH it
2211 should also work to execute it |win32-PATH|. This can be
2212 disabled by setting the $NoDefaultCurrentDirectoryInExePath
2213 environment variable. *NoDefaultCurrentDirectoryInExePath*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002214 The result is a Number:
2215 1 exists
2216 0 does not exist
2217 -1 not implemented on this system
2218 |exepath()| can be used to get the full path of an executable.
2219
2220 Can also be used as a |method|: >
2221 GetCommand()->executable()
2222
2223execute({command} [, {silent}]) *execute()*
2224 Execute an Ex command or commands and return the output as a
2225 string.
2226 {command} can be a string or a List. In case of a List the
2227 lines are executed one by one.
2228 This is equivalent to: >
2229 redir => var
2230 {command}
2231 redir END
2232<
2233 The optional {silent} argument can have these values:
2234 "" no `:silent` used
2235 "silent" `:silent` used
2236 "silent!" `:silent!` used
2237 The default is "silent". Note that with "silent!", unlike
2238 `:redir`, error messages are dropped. When using an external
2239 command the screen may be messed up, use `system()` instead.
2240 *E930*
2241 It is not possible to use `:redir` anywhere in {command}.
2242
2243 To get a list of lines use |split()| on the result: >
Bram Moolenaar75ab5902022-04-18 15:36:40 +01002244 execute('args')->split("\n")
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002245
2246< To execute a command in another window than the current one
2247 use `win_execute()`.
2248
2249 When used recursively the output of the recursive call is not
2250 included in the output of the higher level call.
2251
2252 Can also be used as a |method|: >
2253 GetCommand()->execute()
2254
2255exepath({expr}) *exepath()*
2256 If {expr} is an executable and is either an absolute path, a
2257 relative path or found in $PATH, return the full path.
2258 Note that the current directory is used when {expr} starts
2259 with "./", which may be a problem for Vim: >
2260 echo exepath(v:progpath)
2261< If {expr} cannot be found in $PATH or is not executable then
2262 an empty string is returned.
2263
2264 Can also be used as a |method|: >
2265 GetCommand()->exepath()
2266<
2267 *exists()*
2268exists({expr}) The result is a Number, which is |TRUE| if {expr} is defined,
2269 zero otherwise.
2270
2271 Note: In a compiled |:def| function the evaluation is done at
2272 runtime. Use `exists_compiled()` to evaluate the expression
2273 at compile time.
2274
2275 For checking for a supported feature use |has()|.
2276 For checking if a file exists use |filereadable()|.
2277
2278 The {expr} argument is a string, which contains one of these:
Bram Moolenaarf10911e2022-01-29 22:20:48 +00002279 varname internal variable (see
2280 dict.key |internal-variables|). Also works
2281 list[i] for |curly-braces-names|, |Dictionary|
2282 import.Func entries, |List| items, imported
Bram Moolenaar944697a2022-02-20 19:48:20 +00002283 items, etc.
Bram Moolenaarf10911e2022-01-29 22:20:48 +00002284 Does not work for local variables in a
2285 compiled `:def` function.
Bram Moolenaar944697a2022-02-20 19:48:20 +00002286 Also works for a function in |Vim9|
2287 script, since it can be used as a
2288 function reference.
Bram Moolenaarf10911e2022-01-29 22:20:48 +00002289 Beware that evaluating an index may
2290 cause an error message for an invalid
2291 expression. E.g.: >
2292 :let l = [1, 2, 3]
2293 :echo exists("l[5]")
2294< 0 >
2295 :echo exists("l[xx]")
2296< E121: Undefined variable: xx
2297 0
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002298 &option-name Vim option (only checks if it exists,
2299 not if it really works)
2300 +option-name Vim option that works.
2301 $ENVNAME environment variable (could also be
2302 done by comparing with an empty
2303 string)
2304 *funcname built-in function (see |functions|)
2305 or user defined function (see
2306 |user-functions|) that is implemented.
2307 Also works for a variable that is a
2308 Funcref.
2309 ?funcname built-in function that could be
2310 implemented; to be used to check if
2311 "funcname" is valid
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002312 :cmdname Ex command: built-in command, user
2313 command or command modifier |:command|.
2314 Returns:
2315 1 for match with start of a command
2316 2 full match with a command
2317 3 matches several user commands
2318 To check for a supported command
2319 always check the return value to be 2.
2320 :2match The |:2match| command.
Bram Moolenaarb529cfb2022-07-25 15:42:07 +01002321 :3match The |:3match| command (but you
2322 probably should not use it, it is
2323 reserved for internal usage)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002324 #event autocommand defined for this event
2325 #event#pattern autocommand defined for this event and
2326 pattern (the pattern is taken
2327 literally and compared to the
2328 autocommand patterns character by
2329 character)
2330 #group autocommand group exists
2331 #group#event autocommand defined for this group and
2332 event.
2333 #group#event#pattern
2334 autocommand defined for this group,
2335 event and pattern.
2336 ##event autocommand for this event is
2337 supported.
2338
2339 Examples: >
2340 exists("&shortname")
2341 exists("$HOSTNAME")
2342 exists("*strftime")
Bram Moolenaar944697a2022-02-20 19:48:20 +00002343 exists("*s:MyFunc") " only for legacy script
2344 exists("*MyFunc")
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002345 exists("bufcount")
2346 exists(":Make")
2347 exists("#CursorHold")
2348 exists("#BufReadPre#*.gz")
2349 exists("#filetypeindent")
2350 exists("#filetypeindent#FileType")
2351 exists("#filetypeindent#FileType#*")
2352 exists("##ColorScheme")
2353< There must be no space between the symbol (&/$/*/#) and the
2354 name.
2355 There must be no extra characters after the name, although in
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01002356 a few cases this is ignored. That may become stricter in the
2357 future, thus don't count on it!
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002358 Working example: >
2359 exists(":make")
2360< NOT working example: >
2361 exists(":make install")
2362
2363< Note that the argument must be a string, not the name of the
2364 variable itself. For example: >
2365 exists(bufcount)
2366< This doesn't check for existence of the "bufcount" variable,
2367 but gets the value of "bufcount", and checks if that exists.
2368
2369 Can also be used as a |method|: >
2370 Varname()->exists()
2371<
2372
2373exists_compiled({expr}) *exists_compiled()*
2374 Like `exists()` but evaluated at compile time. This is useful
2375 to skip a block where a function is used that would otherwise
2376 give an error: >
2377 if exists_compiled('*ThatFunction')
2378 ThatFunction('works')
2379 endif
2380< If `exists()` were used then a compilation error would be
2381 given if ThatFunction() is not defined.
2382
2383 {expr} must be a literal string. *E1232*
2384 Can only be used in a |:def| function. *E1233*
2385 This does not work to check for arguments or local variables.
2386
2387
2388exp({expr}) *exp()*
2389 Return the exponential of {expr} as a |Float| in the range
2390 [0, inf].
2391 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar016188f2022-06-06 20:52:59 +01002392 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002393 Examples: >
2394 :echo exp(2)
2395< 7.389056 >
2396 :echo exp(-1)
2397< 0.367879
2398
2399 Can also be used as a |method|: >
2400 Compute()->exp()
2401<
2402 {only available when compiled with the |+float| feature}
2403
2404
2405expand({string} [, {nosuf} [, {list}]]) *expand()*
2406 Expand wildcards and the following special keywords in
2407 {string}. 'wildignorecase' applies.
2408
2409 If {list} is given and it is |TRUE|, a List will be returned.
2410 Otherwise the result is a String and when there are several
2411 matches, they are separated by <NL> characters. [Note: in
2412 version 5.0 a space was used, which caused problems when a
2413 file name contains a space]
2414
2415 If the expansion fails, the result is an empty string. A name
2416 for a non-existing file is not included, unless {string} does
2417 not start with '%', '#' or '<', see below.
2418
2419 When {string} starts with '%', '#' or '<', the expansion is
2420 done like for the |cmdline-special| variables with their
2421 associated modifiers. Here is a short overview:
2422
2423 % current file name
2424 # alternate file name
2425 #n alternate file name n
2426 <cfile> file name under the cursor
2427 <afile> autocmd file name
2428 <abuf> autocmd buffer number (as a String!)
2429 <amatch> autocmd matched name
2430 <cexpr> C expression under the cursor
2431 <sfile> sourced script file or function name
2432 <slnum> sourced script line number or function
2433 line number
2434 <sflnum> script file line number, also when in
2435 a function
2436 <SID> "<SNR>123_" where "123" is the
2437 current script ID |<SID>|
Bram Moolenaar75ab5902022-04-18 15:36:40 +01002438 <script> sourced script file, or script file
2439 where the current function was defined
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002440 <stack> call stack
2441 <cword> word under the cursor
2442 <cWORD> WORD under the cursor
2443 <client> the {clientid} of the last received
2444 message |server2client()|
2445 Modifiers:
2446 :p expand to full path
2447 :h head (last path component removed)
2448 :t tail (last path component only)
2449 :r root (one extension removed)
2450 :e extension only
2451
2452 Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00002453 :let &tags = expand("%:p:h") .. "/tags"
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002454< Note that when expanding a string that starts with '%', '#' or
2455 '<', any following text is ignored. This does NOT work: >
2456 :let doesntwork = expand("%:h.bak")
2457< Use this: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00002458 :let doeswork = expand("%:h") .. ".bak"
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002459< Also note that expanding "<cfile>" and others only returns the
2460 referenced file name without further expansion. If "<cfile>"
2461 is "~/.cshrc", you need to do another expand() to have the
2462 "~/" expanded into the path of the home directory: >
2463 :echo expand(expand("<cfile>"))
2464<
2465 There cannot be white space between the variables and the
2466 following modifier. The |fnamemodify()| function can be used
2467 to modify normal file names.
2468
2469 When using '%' or '#', and the current or alternate file name
2470 is not defined, an empty string is used. Using "%:p" in a
2471 buffer with no name, results in the current directory, with a
2472 '/' added.
Bram Moolenaar57544522022-04-12 12:54:11 +01002473 When 'verbose' is set then expanding '%', '#' and <> items
2474 will result in an error message if the argument cannot be
2475 expanded.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002476
2477 When {string} does not start with '%', '#' or '<', it is
2478 expanded like a file name is expanded on the command line.
2479 'suffixes' and 'wildignore' are used, unless the optional
2480 {nosuf} argument is given and it is |TRUE|.
2481 Names for non-existing files are included. The "**" item can
2482 be used to search in a directory tree. For example, to find
2483 all "README" files in the current directory and below: >
2484 :echo expand("**/README")
2485<
2486 expand() can also be used to expand variables and environment
2487 variables that are only known in a shell. But this can be
2488 slow, because a shell may be used to do the expansion. See
2489 |expr-env-expand|.
2490 The expanded variable is still handled like a list of file
2491 names. When an environment variable cannot be expanded, it is
2492 left unchanged. Thus ":echo expand('$FOOBAR')" results in
2493 "$FOOBAR".
2494
2495 See |glob()| for finding existing files. See |system()| for
2496 getting the raw output of an external command.
2497
2498 Can also be used as a |method|: >
2499 Getpattern()->expand()
2500
Yegappan Lakshmanan2b74b682022-04-03 21:30:32 +01002501expandcmd({string} [, {options}]) *expandcmd()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002502 Expand special items in String {string} like what is done for
2503 an Ex command such as `:edit`. This expands special keywords,
2504 like with |expand()|, and environment variables, anywhere in
2505 {string}. "~user" and "~/path" are only expanded at the
2506 start.
Yegappan Lakshmanan2b74b682022-04-03 21:30:32 +01002507
2508 The following items are supported in the {options} Dict
2509 argument:
2510 errmsg If set to TRUE, error messages are displayed
2511 if an error is encountered during expansion.
2512 By default, error messages are not displayed.
2513
Yegappan Lakshmanan5018a832022-04-02 21:12:21 +01002514 Returns the expanded string. If an error is encountered
2515 during expansion, the unmodified {string} is returned.
Yegappan Lakshmanan2b74b682022-04-03 21:30:32 +01002516
Yegappan Lakshmanan5018a832022-04-02 21:12:21 +01002517 Example: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002518 :echo expandcmd('make %<.o')
Yegappan Lakshmanan2b74b682022-04-03 21:30:32 +01002519 make /path/runtime/doc/builtin.o
2520 :echo expandcmd('make %<.o', {'errmsg': v:true})
2521<
Yegappan Lakshmanan5018a832022-04-02 21:12:21 +01002522 Can also be used as a |method|: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002523 GetCommand()->expandcmd()
2524<
2525extend({expr1}, {expr2} [, {expr3}]) *extend()*
2526 {expr1} and {expr2} must be both |Lists| or both
2527 |Dictionaries|.
2528
2529 If they are |Lists|: Append {expr2} to {expr1}.
2530 If {expr3} is given insert the items of {expr2} before the
2531 item with index {expr3} in {expr1}. When {expr3} is zero
2532 insert before the first item. When {expr3} is equal to
2533 len({expr1}) then {expr2} is appended.
2534 Examples: >
2535 :echo sort(extend(mylist, [7, 5]))
2536 :call extend(mylist, [2, 3], 1)
2537< When {expr1} is the same List as {expr2} then the number of
2538 items copied is equal to the original length of the List.
2539 E.g., when {expr3} is 1 you get N new copies of the first item
2540 (where N is the original length of the List).
2541 Use |add()| to concatenate one item to a list. To concatenate
2542 two lists into a new list use the + operator: >
2543 :let newlist = [1, 2, 3] + [4, 5]
2544<
2545 If they are |Dictionaries|:
2546 Add all entries from {expr2} to {expr1}.
2547 If a key exists in both {expr1} and {expr2} then {expr3} is
2548 used to decide what to do:
2549 {expr3} = "keep": keep the value of {expr1}
2550 {expr3} = "force": use the value of {expr2}
2551 {expr3} = "error": give an error message *E737*
2552 When {expr3} is omitted then "force" is assumed.
2553
2554 {expr1} is changed when {expr2} is not empty. If necessary
2555 make a copy of {expr1} first.
2556 {expr2} remains unchanged.
2557 When {expr1} is locked and {expr2} is not empty the operation
2558 fails.
Bram Moolenaar016188f2022-06-06 20:52:59 +01002559 Returns {expr1}. Returns 0 on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002560
2561 Can also be used as a |method|: >
2562 mylist->extend(otherlist)
2563
2564
2565extendnew({expr1}, {expr2} [, {expr3}]) *extendnew()*
2566 Like |extend()| but instead of adding items to {expr1} a new
2567 List or Dictionary is created and returned. {expr1} remains
2568 unchanged. Items can still be changed by {expr2}, if you
2569 don't want that use |deepcopy()| first.
2570
2571
2572feedkeys({string} [, {mode}]) *feedkeys()*
2573 Characters in {string} are queued for processing as if they
2574 come from a mapping or were typed by the user.
2575
2576 By default the string is added to the end of the typeahead
2577 buffer, thus if a mapping is still being executed the
2578 characters come after them. Use the 'i' flag to insert before
2579 other characters, they will be executed next, before any
2580 characters from a mapping.
2581
2582 The function does not wait for processing of keys contained in
2583 {string}.
2584
2585 To include special keys into {string}, use double-quotes
2586 and "\..." notation |expr-quote|. For example,
2587 feedkeys("\<CR>") simulates pressing of the <Enter> key. But
2588 feedkeys('\<CR>') pushes 5 characters.
2589 A special code that might be useful is <Ignore>, it exits the
2590 wait for a character without doing anything. *<Ignore>*
2591
2592 {mode} is a String, which can contain these character flags:
2593 'm' Remap keys. This is default. If {mode} is absent,
2594 keys are remapped.
2595 'n' Do not remap keys.
2596 't' Handle keys as if typed; otherwise they are handled as
2597 if coming from a mapping. This matters for undo,
2598 opening folds, etc.
2599 'L' Lowlevel input. Only works for Unix or when using the
2600 GUI. Keys are used as if they were coming from the
2601 terminal. Other flags are not used. *E980*
2602 When a CTRL-C interrupts and 't' is included it sets
2603 the internal "got_int" flag.
2604 'i' Insert the string instead of appending (see above).
2605 'x' Execute commands until typeahead is empty. This is
2606 similar to using ":normal!". You can call feedkeys()
2607 several times without 'x' and then one time with 'x'
2608 (possibly with an empty {string}) to execute all the
2609 typeahead. Note that when Vim ends in Insert mode it
2610 will behave as if <Esc> is typed, to avoid getting
2611 stuck, waiting for a character to be typed before the
2612 script continues.
2613 Note that if you manage to call feedkeys() while
2614 executing commands, thus calling it recursively, then
2615 all typeahead will be consumed by the last call.
Bram Moolenaara9725222022-01-16 13:30:33 +00002616 'c' Remove any script context when executing, so that
2617 legacy script syntax applies, "s:var" does not work,
Bram Moolenaard899e512022-05-07 21:54:03 +01002618 etc. Note that if the string being fed sets a script
Bram Moolenaarce001a32022-04-27 15:25:03 +01002619 context this still applies.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002620 '!' When used with 'x' will not end Insert mode. Can be
2621 used in a test when a timer is set to exit Insert mode
2622 a little later. Useful for testing CursorHoldI.
2623
2624 Return value is always 0.
2625
2626 Can also be used as a |method|: >
2627 GetInput()->feedkeys()
2628
2629filereadable({file}) *filereadable()*
2630 The result is a Number, which is |TRUE| when a file with the
2631 name {file} exists, and can be read. If {file} doesn't exist,
2632 or is a directory, the result is |FALSE|. {file} is any
2633 expression, which is used as a String.
2634 If you don't care about the file being readable you can use
2635 |glob()|.
2636 {file} is used as-is, you may want to expand wildcards first: >
2637 echo filereadable('~/.vimrc')
2638 0
2639 echo filereadable(expand('~/.vimrc'))
2640 1
2641
2642< Can also be used as a |method|: >
2643 GetName()->filereadable()
2644< *file_readable()*
2645 Obsolete name: file_readable().
2646
2647
2648filewritable({file}) *filewritable()*
2649 The result is a Number, which is 1 when a file with the
2650 name {file} exists, and can be written. If {file} doesn't
2651 exist, or is not writable, the result is 0. If {file} is a
2652 directory, and we can write to it, the result is 2.
2653
2654 Can also be used as a |method|: >
2655 GetName()->filewritable()
2656
2657
2658filter({expr1}, {expr2}) *filter()*
2659 {expr1} must be a |List|, |String|, |Blob| or |Dictionary|.
2660 For each item in {expr1} evaluate {expr2} and when the result
2661 is zero or false remove the item from the |List| or
2662 |Dictionary|. Similarly for each byte in a |Blob| and each
Bram Moolenaar2f0936c2022-01-08 21:51:59 +00002663 character in a |String|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002664
2665 {expr2} must be a |string| or |Funcref|.
2666
2667 If {expr2} is a |string|, inside {expr2} |v:val| has the value
2668 of the current item. For a |Dictionary| |v:key| has the key
2669 of the current item and for a |List| |v:key| has the index of
2670 the current item. For a |Blob| |v:key| has the index of the
2671 current byte. For a |String| |v:key| has the index of the
2672 current character.
2673 Examples: >
2674 call filter(mylist, 'v:val !~ "OLD"')
2675< Removes the items where "OLD" appears. >
2676 call filter(mydict, 'v:key >= 8')
2677< Removes the items with a key below 8. >
2678 call filter(var, 0)
2679< Removes all the items, thus clears the |List| or |Dictionary|.
2680
2681 Note that {expr2} is the result of expression and is then
2682 used as an expression again. Often it is good to use a
2683 |literal-string| to avoid having to double backslashes.
2684
2685 If {expr2} is a |Funcref| it must take two arguments:
2686 1. the key or the index of the current item.
2687 2. the value of the current item.
2688 The function must return |TRUE| if the item should be kept.
2689 Example that keeps the odd items of a list: >
2690 func Odd(idx, val)
2691 return a:idx % 2 == 1
2692 endfunc
2693 call filter(mylist, function('Odd'))
Bram Moolenaar2f0936c2022-01-08 21:51:59 +00002694< It is shorter when using a |lambda|. In |Vim9| syntax: >
2695 call filter(myList, (idx, val) => idx * val <= 42)
2696< In legacy script syntax: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002697 call filter(myList, {idx, val -> idx * val <= 42})
2698< If you do not use "val" you can leave it out: >
2699 call filter(myList, {idx -> idx % 2 == 1})
2700<
2701 In |Vim9| script the result must be true, false, zero or one.
2702 Other values will result in a type error.
2703
2704 For a |List| and a |Dictionary| the operation is done
2705 in-place. If you want it to remain unmodified make a copy
2706 first: >
2707 :let l = filter(copy(mylist), 'v:val =~ "KEEP"')
2708
2709< Returns {expr1}, the |List| or |Dictionary| that was filtered,
naohiro ono56200ee2022-01-01 14:59:44 +00002710 or a new |Blob| or |String|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002711 When an error is encountered while evaluating {expr2} no
2712 further items in {expr1} are processed.
2713 When {expr2} is a Funcref errors inside a function are ignored,
2714 unless it was defined with the "abort" flag.
2715
2716 Can also be used as a |method|: >
2717 mylist->filter(expr2)
2718
2719finddir({name} [, {path} [, {count}]]) *finddir()*
2720 Find directory {name} in {path}. Supports both downwards and
2721 upwards recursive directory searches. See |file-searching|
2722 for the syntax of {path}.
2723
2724 Returns the path of the first found match. When the found
2725 directory is below the current directory a relative path is
2726 returned. Otherwise a full path is returned.
2727 If {path} is omitted or empty then 'path' is used.
2728
2729 If the optional {count} is given, find {count}'s occurrence of
2730 {name} in {path} instead of the first one.
2731 When {count} is negative return all the matches in a |List|.
2732
Bram Moolenaar016188f2022-06-06 20:52:59 +01002733 Returns an empty string if the directory is not found.
2734
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002735 This is quite similar to the ex-command `:find`.
2736 {only available when compiled with the |+file_in_path|
2737 feature}
2738
2739 Can also be used as a |method|: >
2740 GetName()->finddir()
2741
2742findfile({name} [, {path} [, {count}]]) *findfile()*
2743 Just like |finddir()|, but find a file instead of a directory.
2744 Uses 'suffixesadd'.
2745 Example: >
2746 :echo findfile("tags.vim", ".;")
2747< Searches from the directory of the current file upwards until
2748 it finds the file "tags.vim".
2749
2750 Can also be used as a |method|: >
2751 GetName()->findfile()
2752
2753flatten({list} [, {maxdepth}]) *flatten()*
2754 Flatten {list} up to {maxdepth} levels. Without {maxdepth}
2755 the result is a |List| without nesting, as if {maxdepth} is
2756 a very large number.
2757 The {list} is changed in place, use |flattennew()| if you do
2758 not want that.
2759 In Vim9 script flatten() cannot be used, you must always use
Bram Moolenaara2baa732022-02-04 16:09:54 +00002760 |flattennew()|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002761 *E900*
2762 {maxdepth} means how deep in nested lists changes are made.
2763 {list} is not modified when {maxdepth} is 0.
2764 {maxdepth} must be positive number.
2765
2766 If there is an error the number zero is returned.
2767
2768 Example: >
2769 :echo flatten([1, [2, [3, 4]], 5])
2770< [1, 2, 3, 4, 5] >
2771 :echo flatten([1, [2, [3, 4]], 5], 1)
2772< [1, 2, [3, 4], 5]
2773
2774 Can also be used as a |method|: >
2775 mylist->flatten()
2776<
2777flattennew({list} [, {maxdepth}]) *flattennew()*
2778 Like |flatten()| but first make a copy of {list}.
2779
2780
2781float2nr({expr}) *float2nr()*
2782 Convert {expr} to a Number by omitting the part after the
2783 decimal point.
2784 {expr} must evaluate to a |Float| or a Number.
Bram Moolenaar016188f2022-06-06 20:52:59 +01002785 Returns 0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002786 When the value of {expr} is out of range for a |Number| the
2787 result is truncated to 0x7fffffff or -0x7fffffff (or when
2788 64-bit Number support is enabled, 0x7fffffffffffffff or
2789 -0x7fffffffffffffff). NaN results in -0x80000000 (or when
2790 64-bit Number support is enabled, -0x8000000000000000).
2791 Examples: >
2792 echo float2nr(3.95)
2793< 3 >
2794 echo float2nr(-23.45)
2795< -23 >
2796 echo float2nr(1.0e100)
2797< 2147483647 (or 9223372036854775807) >
2798 echo float2nr(-1.0e150)
2799< -2147483647 (or -9223372036854775807) >
2800 echo float2nr(1.0e-100)
2801< 0
2802
2803 Can also be used as a |method|: >
2804 Compute()->float2nr()
2805<
2806 {only available when compiled with the |+float| feature}
2807
2808
2809floor({expr}) *floor()*
2810 Return the largest integral value less than or equal to
2811 {expr} as a |Float| (round down).
2812 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar016188f2022-06-06 20:52:59 +01002813 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002814 Examples: >
2815 echo floor(1.856)
2816< 1.0 >
2817 echo floor(-5.456)
2818< -6.0 >
2819 echo floor(4.0)
2820< 4.0
2821
2822 Can also be used as a |method|: >
2823 Compute()->floor()
2824<
2825 {only available when compiled with the |+float| feature}
2826
2827
2828fmod({expr1}, {expr2}) *fmod()*
2829 Return the remainder of {expr1} / {expr2}, even if the
2830 division is not representable. Returns {expr1} - i * {expr2}
2831 for some integer i such that if {expr2} is non-zero, the
2832 result has the same sign as {expr1} and magnitude less than
2833 the magnitude of {expr2}. If {expr2} is zero, the value
2834 returned is zero. The value returned is a |Float|.
2835 {expr1} and {expr2} must evaluate to a |Float| or a |Number|.
Bram Moolenaar016188f2022-06-06 20:52:59 +01002836 Returns 0.0 if {expr1} or {expr2} is not a |Float| or a
2837 |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002838 Examples: >
2839 :echo fmod(12.33, 1.22)
2840< 0.13 >
2841 :echo fmod(-12.33, 1.22)
2842< -0.13
2843
2844 Can also be used as a |method|: >
2845 Compute()->fmod(1.22)
2846<
2847 {only available when compiled with |+float| feature}
2848
2849
2850fnameescape({string}) *fnameescape()*
2851 Escape {string} for use as file name command argument. All
2852 characters that have a special meaning, such as '%' and '|'
2853 are escaped with a backslash.
2854 For most systems the characters escaped are
2855 " \t\n*?[{`$\\%#'\"|!<". For systems where a backslash
2856 appears in a filename, it depends on the value of 'isfname'.
2857 A leading '+' and '>' is also escaped (special after |:edit|
2858 and |:write|). And a "-" by itself (special after |:cd|).
Bram Moolenaar016188f2022-06-06 20:52:59 +01002859 Returns an empty string on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002860 Example: >
2861 :let fname = '+some str%nge|name'
Bram Moolenaarc51cf032022-02-26 12:25:45 +00002862 :exe "edit " .. fnameescape(fname)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002863< results in executing: >
2864 edit \+some\ str\%nge\|name
2865<
2866 Can also be used as a |method|: >
2867 GetName()->fnameescape()
2868
2869fnamemodify({fname}, {mods}) *fnamemodify()*
2870 Modify file name {fname} according to {mods}. {mods} is a
2871 string of characters like it is used for file names on the
2872 command line. See |filename-modifiers|.
2873 Example: >
2874 :echo fnamemodify("main.c", ":p:h")
2875< results in: >
Bram Moolenaard799daa2022-06-20 11:17:32 +01002876 /home/user/vim/vim/src
Bram Moolenaar016188f2022-06-06 20:52:59 +01002877< If {mods} is empty or an unsupported modifier is used then
2878 {fname} is returned.
Bram Moolenaar5ed11532022-07-06 13:18:11 +01002879 When {fname} is empty then with {mods} ":h" returns ".", so
2880 that `:cd` can be used with it. This is different from
2881 expand('%:h') without a buffer name, which returns an empty
2882 string.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002883 Note: Environment variables don't work in {fname}, use
2884 |expand()| first then.
2885
2886 Can also be used as a |method|: >
2887 GetName()->fnamemodify(':p:h')
2888
2889foldclosed({lnum}) *foldclosed()*
2890 The result is a Number. If the line {lnum} is in a closed
2891 fold, the result is the number of the first line in that fold.
2892 If the line {lnum} is not in a closed fold, -1 is returned.
2893 {lnum} is used like with |getline()|. Thus "." is the current
2894 line, "'m" mark m, etc.
2895
2896 Can also be used as a |method|: >
2897 GetLnum()->foldclosed()
2898
2899foldclosedend({lnum}) *foldclosedend()*
2900 The result is a Number. If the line {lnum} is in a closed
2901 fold, the result is the number of the last line in that fold.
2902 If the line {lnum} is not in a closed fold, -1 is returned.
2903 {lnum} is used like with |getline()|. Thus "." is the current
2904 line, "'m" mark m, etc.
2905
2906 Can also be used as a |method|: >
2907 GetLnum()->foldclosedend()
2908
2909foldlevel({lnum}) *foldlevel()*
2910 The result is a Number, which is the foldlevel of line {lnum}
2911 in the current buffer. For nested folds the deepest level is
2912 returned. If there is no fold at line {lnum}, zero is
2913 returned. It doesn't matter if the folds are open or closed.
2914 When used while updating folds (from 'foldexpr') -1 is
2915 returned for lines where folds are still to be updated and the
2916 foldlevel is unknown. As a special case the level of the
2917 previous line is usually available.
2918 {lnum} is used like with |getline()|. Thus "." is the current
2919 line, "'m" mark m, etc.
2920
2921 Can also be used as a |method|: >
2922 GetLnum()->foldlevel()
2923<
2924 *foldtext()*
2925foldtext() Returns a String, to be displayed for a closed fold. This is
2926 the default function used for the 'foldtext' option and should
2927 only be called from evaluating 'foldtext'. It uses the
2928 |v:foldstart|, |v:foldend| and |v:folddashes| variables.
2929 The returned string looks like this: >
2930 +-- 45 lines: abcdef
2931< The number of leading dashes depends on the foldlevel. The
2932 "45" is the number of lines in the fold. "abcdef" is the text
2933 in the first non-blank line of the fold. Leading white space,
2934 "//" or "/*" and the text from the 'foldmarker' and
2935 'commentstring' options is removed.
2936 When used to draw the actual foldtext, the rest of the line
2937 will be filled with the fold char from the 'fillchars'
2938 setting.
Bram Moolenaar016188f2022-06-06 20:52:59 +01002939 Returns an empty string when there is no fold.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002940 {not available when compiled without the |+folding| feature}
2941
2942foldtextresult({lnum}) *foldtextresult()*
2943 Returns the text that is displayed for the closed fold at line
2944 {lnum}. Evaluates 'foldtext' in the appropriate context.
2945 When there is no closed fold at {lnum} an empty string is
2946 returned.
2947 {lnum} is used like with |getline()|. Thus "." is the current
2948 line, "'m" mark m, etc.
2949 Useful when exporting folded text, e.g., to HTML.
2950 {not available when compiled without the |+folding| feature}
2951
2952
2953 Can also be used as a |method|: >
2954 GetLnum()->foldtextresult()
2955<
2956 *foreground()*
2957foreground() Move the Vim window to the foreground. Useful when sent from
2958 a client to a Vim server. |remote_send()|
2959 On Win32 systems this might not work, the OS does not always
2960 allow a window to bring itself to the foreground. Use
2961 |remote_foreground()| instead.
Bram Moolenaarcbaff5e2022-04-08 17:45:08 +01002962 {only in the Win32, Motif and GTK GUI versions and the
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002963 Win32 console version}
2964
2965fullcommand({name}) *fullcommand()*
2966 Get the full command name from a short abbreviated command
2967 name; see |20.2| for details on command abbreviations.
2968
2969 The string argument {name} may start with a `:` and can
2970 include a [range], these are skipped and not returned.
2971 Returns an empty string if a command doesn't exist or if it's
2972 ambiguous (for user-defined commands).
2973
2974 For example `fullcommand('s')`, `fullcommand('sub')`,
2975 `fullcommand(':%substitute')` all return "substitute".
2976
2977 Can also be used as a |method|: >
2978 GetName()->fullcommand()
2979<
2980 *funcref()*
2981funcref({name} [, {arglist}] [, {dict}])
2982 Just like |function()|, but the returned Funcref will lookup
2983 the function by reference, not by name. This matters when the
2984 function {name} is redefined later.
2985
2986 Unlike |function()|, {name} must be an existing user function.
Bram Moolenaar2f0936c2022-01-08 21:51:59 +00002987 It only works for an autoloaded function if it has already
2988 been loaded (to avoid mistakenly loading the autoload script
2989 when only intending to use the function name, use |function()|
2990 instead). {name} cannot be a builtin function.
Bram Moolenaar016188f2022-06-06 20:52:59 +01002991 Returns 0 on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002992
2993 Can also be used as a |method|: >
2994 GetFuncname()->funcref([arg])
2995<
2996 *function()* *partial* *E700* *E922* *E923*
2997function({name} [, {arglist}] [, {dict}])
2998 Return a |Funcref| variable that refers to function {name}.
2999 {name} can be the name of a user defined function or an
3000 internal function.
3001
3002 {name} can also be a Funcref or a partial. When it is a
3003 partial the dict stored in it will be used and the {dict}
3004 argument is not allowed. E.g.: >
3005 let FuncWithArg = function(dict.Func, [arg])
3006 let Broken = function(dict.Func, [arg], dict)
3007<
3008 When using the Funcref the function will be found by {name},
3009 also when it was redefined later. Use |funcref()| to keep the
3010 same function.
3011
3012 When {arglist} or {dict} is present this creates a partial.
3013 That means the argument list and/or the dictionary is stored in
3014 the Funcref and will be used when the Funcref is called.
3015
3016 The arguments are passed to the function in front of other
3017 arguments, but after any argument from |method|. Example: >
3018 func Callback(arg1, arg2, name)
3019 ...
3020 let Partial = function('Callback', ['one', 'two'])
3021 ...
3022 call Partial('name')
3023< Invokes the function as with: >
3024 call Callback('one', 'two', 'name')
3025
3026< With a |method|: >
3027 func Callback(one, two, three)
3028 ...
3029 let Partial = function('Callback', ['two'])
3030 ...
3031 eval 'one'->Partial('three')
3032< Invokes the function as with: >
3033 call Callback('one', 'two', 'three')
3034
3035< The function() call can be nested to add more arguments to the
3036 Funcref. The extra arguments are appended to the list of
3037 arguments. Example: >
3038 func Callback(arg1, arg2, name)
3039 ...
3040 let Func = function('Callback', ['one'])
3041 let Func2 = function(Func, ['two'])
3042 ...
3043 call Func2('name')
3044< Invokes the function as with: >
3045 call Callback('one', 'two', 'name')
3046
3047< The Dictionary is only useful when calling a "dict" function.
3048 In that case the {dict} is passed in as "self". Example: >
3049 function Callback() dict
Bram Moolenaarc51cf032022-02-26 12:25:45 +00003050 echo "called for " .. self.name
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003051 endfunction
3052 ...
3053 let context = {"name": "example"}
3054 let Func = function('Callback', context)
3055 ...
3056 call Func() " will echo: called for example
3057< The use of function() is not needed when there are no extra
3058 arguments, these two are equivalent: >
3059 let Func = function('Callback', context)
3060 let Func = context.Callback
3061
3062< The argument list and the Dictionary can be combined: >
3063 function Callback(arg1, count) dict
3064 ...
3065 let context = {"name": "example"}
3066 let Func = function('Callback', ['one'], context)
3067 ...
3068 call Func(500)
3069< Invokes the function as with: >
3070 call context.Callback('one', 500)
3071<
Bram Moolenaar016188f2022-06-06 20:52:59 +01003072 Returns 0 on error.
3073
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003074 Can also be used as a |method|: >
3075 GetFuncname()->function([arg])
3076
3077
3078garbagecollect([{atexit}]) *garbagecollect()*
3079 Cleanup unused |Lists|, |Dictionaries|, |Channels| and |Jobs|
3080 that have circular references.
3081
3082 There is hardly ever a need to invoke this function, as it is
3083 automatically done when Vim runs out of memory or is waiting
3084 for the user to press a key after 'updatetime'. Items without
3085 circular references are always freed when they become unused.
3086 This is useful if you have deleted a very big |List| and/or
3087 |Dictionary| with circular references in a script that runs
3088 for a long time.
3089
3090 When the optional {atexit} argument is one, garbage
3091 collection will also be done when exiting Vim, if it wasn't
3092 done before. This is useful when checking for memory leaks.
3093
3094 The garbage collection is not done immediately but only when
3095 it's safe to perform. This is when waiting for the user to
3096 type a character. To force garbage collection immediately use
3097 |test_garbagecollect_now()|.
3098
3099get({list}, {idx} [, {default}]) *get()*
3100 Get item {idx} from |List| {list}. When this item is not
3101 available return {default}. Return zero when {default} is
3102 omitted.
3103 Preferably used as a |method|: >
3104 mylist->get(idx)
3105get({blob}, {idx} [, {default}])
3106 Get byte {idx} from |Blob| {blob}. When this byte is not
3107 available return {default}. Return -1 when {default} is
3108 omitted.
3109 Preferably used as a |method|: >
3110 myblob->get(idx)
3111get({dict}, {key} [, {default}])
3112 Get item with key {key} from |Dictionary| {dict}. When this
3113 item is not available return {default}. Return zero when
3114 {default} is omitted. Useful example: >
3115 let val = get(g:, 'var_name', 'default')
3116< This gets the value of g:var_name if it exists, and uses
3117 'default' when it does not exist.
3118 Preferably used as a |method|: >
3119 mydict->get(key)
3120get({func}, {what})
Bram Moolenaar6f4754b2022-01-23 12:07:04 +00003121 Get item {what} from Funcref {func}. Possible values for
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003122 {what} are:
3123 "name" The function name
3124 "func" The function
3125 "dict" The dictionary
3126 "args" The list with arguments
Bram Moolenaar016188f2022-06-06 20:52:59 +01003127 Returns zero on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003128 Preferably used as a |method|: >
3129 myfunc->get(what)
3130<
3131 *getbufinfo()*
3132getbufinfo([{buf}])
3133getbufinfo([{dict}])
3134 Get information about buffers as a List of Dictionaries.
3135
3136 Without an argument information about all the buffers is
3137 returned.
3138
3139 When the argument is a |Dictionary| only the buffers matching
3140 the specified criteria are returned. The following keys can
3141 be specified in {dict}:
3142 buflisted include only listed buffers.
3143 bufloaded include only loaded buffers.
3144 bufmodified include only modified buffers.
3145
3146 Otherwise, {buf} specifies a particular buffer to return
3147 information for. For the use of {buf}, see |bufname()|
3148 above. If the buffer is found the returned List has one item.
3149 Otherwise the result is an empty list.
3150
3151 Each returned List item is a dictionary with the following
3152 entries:
3153 bufnr Buffer number.
3154 changed TRUE if the buffer is modified.
3155 changedtick Number of changes made to the buffer.
3156 hidden TRUE if the buffer is hidden.
3157 lastused Timestamp in seconds, like
3158 |localtime()|, when the buffer was
3159 last used.
3160 {only with the |+viminfo| feature}
3161 listed TRUE if the buffer is listed.
3162 lnum Line number used for the buffer when
3163 opened in the current window.
3164 Only valid if the buffer has been
3165 displayed in the window in the past.
3166 If you want the line number of the
3167 last known cursor position in a given
3168 window, use |line()|: >
3169 :echo line('.', {winid})
3170<
3171 linecount Number of lines in the buffer (only
3172 valid when loaded)
3173 loaded TRUE if the buffer is loaded.
3174 name Full path to the file in the buffer.
3175 signs List of signs placed in the buffer.
3176 Each list item is a dictionary with
3177 the following fields:
3178 id sign identifier
3179 lnum line number
3180 name sign name
3181 variables A reference to the dictionary with
3182 buffer-local variables.
3183 windows List of |window-ID|s that display this
3184 buffer
3185 popups List of popup |window-ID|s that
3186 display this buffer
3187
3188 Examples: >
3189 for buf in getbufinfo()
3190 echo buf.name
3191 endfor
3192 for buf in getbufinfo({'buflisted':1})
3193 if buf.changed
3194 ....
3195 endif
3196 endfor
3197<
3198 To get buffer-local options use: >
3199 getbufvar({bufnr}, '&option_name')
3200<
3201 Can also be used as a |method|: >
3202 GetBufnr()->getbufinfo()
3203<
3204
3205 *getbufline()*
3206getbufline({buf}, {lnum} [, {end}])
3207 Return a |List| with the lines starting from {lnum} to {end}
3208 (inclusive) in the buffer {buf}. If {end} is omitted, a
3209 |List| with only the line {lnum} is returned.
3210
3211 For the use of {buf}, see |bufname()| above.
3212
3213 For {lnum} and {end} "$" can be used for the last line of the
3214 buffer. Otherwise a number must be used.
3215
3216 When {lnum} is smaller than 1 or bigger than the number of
3217 lines in the buffer, an empty |List| is returned.
3218
3219 When {end} is greater than the number of lines in the buffer,
3220 it is treated as {end} is set to the number of lines in the
3221 buffer. When {end} is before {lnum} an empty |List| is
3222 returned.
3223
3224 This function works only for loaded buffers. For unloaded and
3225 non-existing buffers, an empty |List| is returned.
3226
3227 Example: >
3228 :let lines = getbufline(bufnr("myfile"), 1, "$")
3229
3230< Can also be used as a |method|: >
3231 GetBufnr()->getbufline(lnum)
3232
3233getbufvar({buf}, {varname} [, {def}]) *getbufvar()*
3234 The result is the value of option or local buffer variable
3235 {varname} in buffer {buf}. Note that the name without "b:"
3236 must be used.
3237 The {varname} argument is a string.
3238 When {varname} is empty returns a |Dictionary| with all the
3239 buffer-local variables.
3240 When {varname} is equal to "&" returns a |Dictionary| with all
3241 the buffer-local options.
3242 Otherwise, when {varname} starts with "&" returns the value of
3243 a buffer-local option.
3244 This also works for a global or buffer-local option, but it
3245 doesn't work for a global variable, window-local variable or
3246 window-local option.
3247 For the use of {buf}, see |bufname()| above.
3248 When the buffer or variable doesn't exist {def} or an empty
3249 string is returned, there is no error message.
3250 Examples: >
3251 :let bufmodified = getbufvar(1, "&mod")
Bram Moolenaarc51cf032022-02-26 12:25:45 +00003252 :echo "todo myvar = " .. getbufvar("todo", "myvar")
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003253
3254< Can also be used as a |method|: >
3255 GetBufnr()->getbufvar(varname)
3256<
3257getchangelist([{buf}]) *getchangelist()*
3258 Returns the |changelist| for the buffer {buf}. For the use
3259 of {buf}, see |bufname()| above. If buffer {buf} doesn't
3260 exist, an empty list is returned.
3261
3262 The returned list contains two entries: a list with the change
3263 locations and the current position in the list. Each
3264 entry in the change list is a dictionary with the following
3265 entries:
3266 col column number
3267 coladd column offset for 'virtualedit'
3268 lnum line number
3269 If buffer {buf} is the current buffer, then the current
3270 position refers to the position in the list. For other
3271 buffers, it is set to the length of the list.
3272
3273 Can also be used as a |method|: >
3274 GetBufnr()->getchangelist()
3275
3276getchar([expr]) *getchar()*
3277 Get a single character from the user or input stream.
3278 If [expr] is omitted, wait until a character is available.
3279 If [expr] is 0, only get a character when one is available.
3280 Return zero otherwise.
3281 If [expr] is 1, only check if a character is available, it is
3282 not consumed. Return zero if no character available.
3283 If you prefer always getting a string use |getcharstr()|.
3284
3285 Without [expr] and when [expr] is 0 a whole character or
3286 special key is returned. If it is a single character, the
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01003287 result is a Number. Use |nr2char()| to convert it to a String.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003288 Otherwise a String is returned with the encoded character.
3289 For a special key it's a String with a sequence of bytes
3290 starting with 0x80 (decimal: 128). This is the same value as
3291 the String "\<Key>", e.g., "\<Left>". The returned value is
3292 also a String when a modifier (shift, control, alt) was used
3293 that is not included in the character.
3294
3295 When [expr] is 0 and Esc is typed, there will be a short delay
3296 while Vim waits to see if this is the start of an escape
3297 sequence.
3298
3299 When [expr] is 1 only the first byte is returned. For a
3300 one-byte character it is the character itself as a number.
3301 Use nr2char() to convert it to a String.
3302
3303 Use getcharmod() to obtain any additional modifiers.
3304
3305 When the user clicks a mouse button, the mouse event will be
3306 returned. The position can then be found in |v:mouse_col|,
3307 |v:mouse_lnum|, |v:mouse_winid| and |v:mouse_win|.
3308 |getmousepos()| can also be used. Mouse move events will be
3309 ignored.
3310 This example positions the mouse as it would normally happen: >
3311 let c = getchar()
3312 if c == "\<LeftMouse>" && v:mouse_win > 0
Bram Moolenaarc51cf032022-02-26 12:25:45 +00003313 exe v:mouse_win .. "wincmd w"
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003314 exe v:mouse_lnum
Bram Moolenaarc51cf032022-02-26 12:25:45 +00003315 exe "normal " .. v:mouse_col .. "|"
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003316 endif
3317<
3318 When using bracketed paste only the first character is
3319 returned, the rest of the pasted text is dropped.
3320 |xterm-bracketed-paste|.
3321
3322 There is no prompt, you will somehow have to make clear to the
3323 user that a character has to be typed. The screen is not
3324 redrawn, e.g. when resizing the window. When using a popup
3325 window it should work better with a |popup-filter|.
3326
3327 There is no mapping for the character.
3328 Key codes are replaced, thus when the user presses the <Del>
3329 key you get the code for the <Del> key, not the raw character
3330 sequence. Examples: >
3331 getchar() == "\<Del>"
3332 getchar() == "\<S-Left>"
3333< This example redefines "f" to ignore case: >
3334 :nmap f :call FindChar()<CR>
3335 :function FindChar()
3336 : let c = nr2char(getchar())
3337 : while col('.') < col('$') - 1
3338 : normal l
3339 : if getline('.')[col('.') - 1] ==? c
3340 : break
3341 : endif
3342 : endwhile
3343 :endfunction
3344<
3345 You may also receive synthetic characters, such as
3346 |<CursorHold>|. Often you will want to ignore this and get
3347 another character: >
3348 :function GetKey()
3349 : let c = getchar()
3350 : while c == "\<CursorHold>"
3351 : let c = getchar()
3352 : endwhile
3353 : return c
3354 :endfunction
3355
3356getcharmod() *getcharmod()*
3357 The result is a Number which is the state of the modifiers for
3358 the last obtained character with getchar() or in another way.
3359 These values are added together:
3360 2 shift
3361 4 control
3362 8 alt (meta)
3363 16 meta (when it's different from ALT)
3364 32 mouse double click
3365 64 mouse triple click
3366 96 mouse quadruple click (== 32 + 64)
3367 128 command (Macintosh only)
3368 Only the modifiers that have not been included in the
3369 character itself are obtained. Thus Shift-a results in "A"
Bram Moolenaar016188f2022-06-06 20:52:59 +01003370 without a modifier. Returns 0 if no modifiers are used.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003371
3372 *getcharpos()*
3373getcharpos({expr})
3374 Get the position for String {expr}. Same as |getpos()| but the
3375 column number in the returned List is a character index
3376 instead of a byte index.
naohiro ono56200ee2022-01-01 14:59:44 +00003377 If |getpos()| returns a very large column number, equal to
3378 |v:maxcol|, then getcharpos() will return the character index
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003379 of the last character.
3380
3381 Example:
3382 With the cursor on '세' in line 5 with text "여보세요": >
3383 getcharpos('.') returns [0, 5, 3, 0]
3384 getpos('.') returns [0, 5, 7, 0]
3385<
3386 Can also be used as a |method|: >
3387 GetMark()->getcharpos()
3388
3389getcharsearch() *getcharsearch()*
3390 Return the current character search information as a {dict}
3391 with the following entries:
3392
3393 char character previously used for a character
3394 search (|t|, |f|, |T|, or |F|); empty string
3395 if no character search has been performed
3396 forward direction of character search; 1 for forward,
3397 0 for backward
3398 until type of character search; 1 for a |t| or |T|
3399 character search, 0 for an |f| or |F|
3400 character search
3401
3402 This can be useful to always have |;| and |,| search
3403 forward/backward regardless of the direction of the previous
3404 character search: >
3405 :nnoremap <expr> ; getcharsearch().forward ? ';' : ','
3406 :nnoremap <expr> , getcharsearch().forward ? ',' : ';'
3407< Also see |setcharsearch()|.
3408
3409
3410getcharstr([expr]) *getcharstr()*
3411 Get a single character from the user or input stream as a
3412 string.
3413 If [expr] is omitted, wait until a character is available.
3414 If [expr] is 0 or false, only get a character when one is
3415 available. Return an empty string otherwise.
3416 If [expr] is 1 or true, only check if a character is
3417 available, it is not consumed. Return an empty string
3418 if no character is available.
3419 Otherwise this works like |getchar()|, except that a number
3420 result is converted to a string.
3421
Shougo Matsushita79d599b2022-05-07 12:48:29 +01003422getcmdcompltype() *getcmdcompltype()*
3423 Return the type of the current command-line completion.
3424 Only works when the command line is being edited, thus
3425 requires use of |c_CTRL-\_e| or |c_CTRL-R_=|.
Bram Moolenaar921bde82022-05-09 19:50:35 +01003426 See |:command-completion| for the return string.
Shougo Matsushita79d599b2022-05-07 12:48:29 +01003427 Also see |getcmdtype()|, |setcmdpos()| and |getcmdline()|.
3428 Returns an empty string when completion is not defined.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003429
3430getcmdline() *getcmdline()*
3431 Return the current command-line. Only works when the command
3432 line is being edited, thus requires use of |c_CTRL-\_e| or
3433 |c_CTRL-R_=|.
3434 Example: >
3435 :cmap <F7> <C-\>eescape(getcmdline(), ' \')<CR>
3436< Also see |getcmdtype()|, |getcmdpos()| and |setcmdpos()|.
3437 Returns an empty string when entering a password or using
3438 |inputsecret()|.
3439
3440getcmdpos() *getcmdpos()*
3441 Return the position of the cursor in the command line as a
3442 byte count. The first column is 1.
3443 Only works when editing the command line, thus requires use of
3444 |c_CTRL-\_e| or |c_CTRL-R_=| or an expression mapping.
3445 Returns 0 otherwise.
3446 Also see |getcmdtype()|, |setcmdpos()| and |getcmdline()|.
3447
Shougo Matsushita79d599b2022-05-07 12:48:29 +01003448getcmdscreenpos() *getcmdscreenpos()*
3449 Return the screen position of the cursor in the command line
3450 as a byte count. The first column is 1.
3451 Instead of |getcmdpos()|, it adds the prompt position.
3452 Only works when editing the command line, thus requires use of
3453 |c_CTRL-\_e| or |c_CTRL-R_=| or an expression mapping.
3454 Returns 0 otherwise.
3455 Also see |getcmdpos()|, |setcmdpos()|.
3456
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003457getcmdtype() *getcmdtype()*
3458 Return the current command-line type. Possible return values
3459 are:
3460 : normal Ex command
3461 > debug mode command |debug-mode|
3462 / forward search command
3463 ? backward search command
3464 @ |input()| command
3465 - |:insert| or |:append| command
3466 = |i_CTRL-R_=|
3467 Only works when editing the command line, thus requires use of
3468 |c_CTRL-\_e| or |c_CTRL-R_=| or an expression mapping.
3469 Returns an empty string otherwise.
3470 Also see |getcmdpos()|, |setcmdpos()| and |getcmdline()|.
3471
3472getcmdwintype() *getcmdwintype()*
3473 Return the current |command-line-window| type. Possible return
3474 values are the same as |getcmdtype()|. Returns an empty string
3475 when not in the command-line window.
3476
3477getcompletion({pat}, {type} [, {filtered}]) *getcompletion()*
3478 Return a list of command-line completion matches. The String
3479 {type} argument specifies what for. The following completion
3480 types are supported:
3481
3482 arglist file names in argument list
3483 augroup autocmd groups
3484 buffer buffer names
Bram Moolenaar6e2e2cc2022-03-14 19:24:46 +00003485 behave |:behave| suboptions
3486 breakpoint |:breakadd| and |:breakdel| suboptions
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003487 color color schemes
3488 command Ex command
3489 cmdline |cmdline-completion| result
3490 compiler compilers
3491 cscope |:cscope| suboptions
3492 diff_buffer |:diffget| and |:diffput| completion
3493 dir directory names
3494 environment environment variable names
3495 event autocommand events
3496 expression Vim expression
3497 file file and directory names
3498 file_in_path file and directory names in |'path'|
3499 filetype filetype names |'filetype'|
3500 function function name
3501 help help subjects
3502 highlight highlight groups
Bram Moolenaar6e2e2cc2022-03-14 19:24:46 +00003503 history |:history| suboptions
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003504 locale locale names (as output of locale -a)
3505 mapclear buffer argument
3506 mapping mapping name
3507 menu menus
3508 messages |:messages| suboptions
3509 option options
3510 packadd optional package |pack-add| names
Yegappan Lakshmanan454ce672022-03-24 11:22:13 +00003511 scriptnames sourced script names |:scriptnames|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003512 shellcmd Shell command
3513 sign |:sign| suboptions
3514 syntax syntax file names |'syntax'|
3515 syntime |:syntime| suboptions
3516 tag tags
3517 tag_listfiles tags, file names
3518 user user names
3519 var user variables
3520
3521 If {pat} is an empty string, then all the matches are
3522 returned. Otherwise only items matching {pat} are returned.
3523 See |wildcards| for the use of special characters in {pat}.
3524
3525 If the optional {filtered} flag is set to 1, then 'wildignore'
3526 is applied to filter the results. Otherwise all the matches
3527 are returned. The 'wildignorecase' option always applies.
3528
Yegappan Lakshmanane7dd0fa2022-03-22 16:06:31 +00003529 If the 'wildoptions' option contains 'fuzzy', then fuzzy
3530 matching is used to get the completion matches. Otherwise
Yegappan Lakshmanan454ce672022-03-24 11:22:13 +00003531 regular expression matching is used. Thus this function
3532 follows the user preference, what happens on the command line.
3533 If you do not want this you can make 'wildoptions' empty
3534 before calling getcompletion() and restore it afterwards.
Yegappan Lakshmanane7dd0fa2022-03-22 16:06:31 +00003535
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003536 If {type} is "cmdline", then the |cmdline-completion| result is
3537 returned. For example, to complete the possible values after
3538 a ":call" command: >
3539 echo getcompletion('call ', 'cmdline')
3540<
3541 If there are no matches, an empty list is returned. An
3542 invalid value for {type} produces an error.
3543
3544 Can also be used as a |method|: >
3545 GetPattern()->getcompletion('color')
3546<
3547 *getcurpos()*
3548getcurpos([{winid}])
3549 Get the position of the cursor. This is like getpos('.'), but
3550 includes an extra "curswant" item in the list:
3551 [0, lnum, col, off, curswant] ~
3552 The "curswant" number is the preferred column when moving the
naohiro ono56200ee2022-01-01 14:59:44 +00003553 cursor vertically. After |$| command it will be a very large
3554 number equal to |v:maxcol|. Also see |getcursorcharpos()| and
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003555 |getpos()|.
3556 The first "bufnum" item is always zero. The byte position of
3557 the cursor is returned in 'col'. To get the character
3558 position, use |getcursorcharpos()|.
3559
3560 The optional {winid} argument can specify the window. It can
3561 be the window number or the |window-ID|. The last known
3562 cursor position is returned, this may be invalid for the
3563 current value of the buffer if it is not the current window.
3564 If {winid} is invalid a list with zeroes is returned.
3565
3566 This can be used to save and restore the cursor position: >
3567 let save_cursor = getcurpos()
3568 MoveTheCursorAround
3569 call setpos('.', save_cursor)
3570< Note that this only works within the window. See
3571 |winrestview()| for restoring more state.
3572
3573 Can also be used as a |method|: >
3574 GetWinid()->getcurpos()
3575<
3576 *getcursorcharpos()*
3577getcursorcharpos([{winid}])
3578 Same as |getcurpos()| but the column number in the returned
3579 List is a character index instead of a byte index.
3580
3581 Example:
3582 With the cursor on '보' in line 3 with text "여보세요": >
3583 getcursorcharpos() returns [0, 3, 2, 0, 3]
3584 getcurpos() returns [0, 3, 4, 0, 3]
3585<
3586 Can also be used as a |method|: >
3587 GetWinid()->getcursorcharpos()
3588
3589< *getcwd()*
3590getcwd([{winnr} [, {tabnr}]])
3591 The result is a String, which is the name of the current
3592 working directory. 'autochdir' is ignored.
3593
3594 With {winnr} return the local current directory of this window
3595 in the current tab page. {winnr} can be the window number or
3596 the |window-ID|.
3597 If {winnr} is -1 return the name of the global working
3598 directory. See also |haslocaldir()|.
3599
3600 With {winnr} and {tabnr} return the local current directory of
3601 the window in the specified tab page. If {winnr} is -1 return
3602 the working directory of the tabpage.
3603 If {winnr} is zero use the current window, if {tabnr} is zero
3604 use the current tabpage.
3605 Without any arguments, return the actual working directory of
3606 the current window.
3607 Return an empty string if the arguments are invalid.
3608
3609 Examples: >
3610 " Get the working directory of the current window
3611 :echo getcwd()
3612 :echo getcwd(0)
3613 :echo getcwd(0, 0)
3614 " Get the working directory of window 3 in tabpage 2
3615 :echo getcwd(3, 2)
3616 " Get the global working directory
3617 :echo getcwd(-1)
3618 " Get the working directory of tabpage 3
3619 :echo getcwd(-1, 3)
3620 " Get the working directory of current tabpage
3621 :echo getcwd(-1, 0)
3622
3623< Can also be used as a |method|: >
3624 GetWinnr()->getcwd()
3625
3626getenv({name}) *getenv()*
3627 Return the value of environment variable {name}. The {name}
3628 argument is a string, without a leading '$'. Example: >
3629 myHome = getenv('HOME')
3630
3631< When the variable does not exist |v:null| is returned. That
3632 is different from a variable set to an empty string, although
3633 some systems interpret the empty value as the variable being
3634 deleted. See also |expr-env|.
3635
3636 Can also be used as a |method|: >
3637 GetVarname()->getenv()
3638
3639getfontname([{name}]) *getfontname()*
3640 Without an argument returns the name of the normal font being
3641 used. Like what is used for the Normal highlight group
3642 |hl-Normal|.
3643 With an argument a check is done whether String {name} is a
3644 valid font name. If not then an empty string is returned.
3645 Otherwise the actual font name is returned, or {name} if the
3646 GUI does not support obtaining the real name.
3647 Only works when the GUI is running, thus not in your vimrc or
3648 gvimrc file. Use the |GUIEnter| autocommand to use this
3649 function just after the GUI has started.
3650 Note that the GTK GUI accepts any font name, thus checking for
3651 a valid name does not work.
3652
3653getfperm({fname}) *getfperm()*
3654 The result is a String, which is the read, write, and execute
3655 permissions of the given file {fname}.
3656 If {fname} does not exist or its directory cannot be read, an
3657 empty string is returned.
3658 The result is of the form "rwxrwxrwx", where each group of
3659 "rwx" flags represent, in turn, the permissions of the owner
3660 of the file, the group the file belongs to, and other users.
3661 If a user does not have a given permission the flag for this
3662 is replaced with the string "-". Examples: >
3663 :echo getfperm("/etc/passwd")
3664 :echo getfperm(expand("~/.vimrc"))
3665< This will hopefully (from a security point of view) display
3666 the string "rw-r--r--" or even "rw-------".
3667
3668 Can also be used as a |method|: >
3669 GetFilename()->getfperm()
3670<
3671 For setting permissions use |setfperm()|.
3672
3673getfsize({fname}) *getfsize()*
3674 The result is a Number, which is the size in bytes of the
3675 given file {fname}.
3676 If {fname} is a directory, 0 is returned.
3677 If the file {fname} can't be found, -1 is returned.
3678 If the size of {fname} is too big to fit in a Number then -2
3679 is returned.
3680
3681 Can also be used as a |method|: >
3682 GetFilename()->getfsize()
3683
3684getftime({fname}) *getftime()*
3685 The result is a Number, which is the last modification time of
3686 the given file {fname}. The value is measured as seconds
3687 since 1st Jan 1970, and may be passed to strftime(). See also
3688 |localtime()| and |strftime()|.
3689 If the file {fname} can't be found -1 is returned.
3690
3691 Can also be used as a |method|: >
3692 GetFilename()->getftime()
3693
3694getftype({fname}) *getftype()*
3695 The result is a String, which is a description of the kind of
3696 file of the given file {fname}.
3697 If {fname} does not exist an empty string is returned.
3698 Here is a table over different kinds of files and their
3699 results:
3700 Normal file "file"
3701 Directory "dir"
3702 Symbolic link "link"
3703 Block device "bdev"
3704 Character device "cdev"
3705 Socket "socket"
3706 FIFO "fifo"
3707 All other "other"
3708 Example: >
3709 getftype("/home")
3710< Note that a type such as "link" will only be returned on
3711 systems that support it. On some systems only "dir" and
3712 "file" are returned. On MS-Windows a symbolic link to a
3713 directory returns "dir" instead of "link".
3714
3715 Can also be used as a |method|: >
3716 GetFilename()->getftype()
3717
3718getimstatus() *getimstatus()*
3719 The result is a Number, which is |TRUE| when the IME status is
Bram Moolenaar016188f2022-06-06 20:52:59 +01003720 active and |FALSE| otherwise.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003721 See 'imstatusfunc'.
3722
3723getjumplist([{winnr} [, {tabnr}]]) *getjumplist()*
3724 Returns the |jumplist| for the specified window.
3725
3726 Without arguments use the current window.
3727 With {winnr} only use this window in the current tab page.
3728 {winnr} can also be a |window-ID|.
3729 With {winnr} and {tabnr} use the window in the specified tab
Bram Moolenaar016188f2022-06-06 20:52:59 +01003730 page. If {winnr} or {tabnr} is invalid, an empty list is
3731 returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003732
3733 The returned list contains two entries: a list with the jump
3734 locations and the last used jump position number in the list.
3735 Each entry in the jump location list is a dictionary with
3736 the following entries:
3737 bufnr buffer number
3738 col column number
3739 coladd column offset for 'virtualedit'
3740 filename filename if available
3741 lnum line number
3742
3743 Can also be used as a |method|: >
3744 GetWinnr()->getjumplist()
3745
3746< *getline()*
3747getline({lnum} [, {end}])
3748 Without {end} the result is a String, which is line {lnum}
3749 from the current buffer. Example: >
3750 getline(1)
3751< When {lnum} is a String that doesn't start with a
3752 digit, |line()| is called to translate the String into a Number.
3753 To get the line under the cursor: >
3754 getline(".")
3755< When {lnum} is a number smaller than 1 or bigger than the
3756 number of lines in the buffer, an empty string is returned.
3757
3758 When {end} is given the result is a |List| where each item is
3759 a line from the current buffer in the range {lnum} to {end},
3760 including line {end}.
3761 {end} is used in the same way as {lnum}.
3762 Non-existing lines are silently omitted.
3763 When {end} is before {lnum} an empty |List| is returned.
3764 Example: >
3765 :let start = line('.')
3766 :let end = search("^$") - 1
3767 :let lines = getline(start, end)
3768
3769< Can also be used as a |method|: >
3770 ComputeLnum()->getline()
3771
3772< To get lines from another buffer see |getbufline()|
3773
3774getloclist({nr} [, {what}]) *getloclist()*
3775 Returns a |List| with all the entries in the location list for
3776 window {nr}. {nr} can be the window number or the |window-ID|.
3777 When {nr} is zero the current window is used.
3778
3779 For a location list window, the displayed location list is
3780 returned. For an invalid window number {nr}, an empty list is
3781 returned. Otherwise, same as |getqflist()|.
3782
3783 If the optional {what} dictionary argument is supplied, then
3784 returns the items listed in {what} as a dictionary. Refer to
3785 |getqflist()| for the supported items in {what}.
3786
3787 In addition to the items supported by |getqflist()| in {what},
3788 the following item is supported by |getloclist()|:
3789
3790 filewinid id of the window used to display files
3791 from the location list. This field is
3792 applicable only when called from a
3793 location list window. See
3794 |location-list-file-window| for more
3795 details.
3796
3797 Returns a |Dictionary| with default values if there is no
3798 location list for the window {nr}.
3799 Returns an empty Dictionary if window {nr} does not exist.
3800
3801 Examples (See also |getqflist-examples|): >
3802 :echo getloclist(3, {'all': 0})
3803 :echo getloclist(5, {'filewinid': 0})
3804
3805
3806getmarklist([{buf}]) *getmarklist()*
3807 Without the {buf} argument returns a |List| with information
3808 about all the global marks. |mark|
3809
3810 If the optional {buf} argument is specified, returns the
3811 local marks defined in buffer {buf}. For the use of {buf},
Bram Moolenaar016188f2022-06-06 20:52:59 +01003812 see |bufname()|. If {buf} is invalid, an empty list is
3813 returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003814
3815 Each item in the returned List is a |Dict| with the following:
3816 mark name of the mark prefixed by "'"
3817 pos a |List| with the position of the mark:
3818 [bufnum, lnum, col, off]
3819 Refer to |getpos()| for more information.
3820 file file name
3821
3822 Refer to |getpos()| for getting information about a specific
3823 mark.
3824
3825 Can also be used as a |method|: >
3826 GetBufnr()->getmarklist()
3827
3828getmatches([{win}]) *getmatches()*
3829 Returns a |List| with all matches previously defined for the
3830 current window by |matchadd()| and the |:match| commands.
3831 |getmatches()| is useful in combination with |setmatches()|,
3832 as |setmatches()| can restore a list of matches saved by
3833 |getmatches()|.
3834 If {win} is specified, use the window with this number or
Bram Moolenaar016188f2022-06-06 20:52:59 +01003835 window ID instead of the current window. If {win} is invalid,
3836 an empty list is returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003837 Example: >
3838 :echo getmatches()
3839< [{'group': 'MyGroup1', 'pattern': 'TODO',
3840 'priority': 10, 'id': 1}, {'group': 'MyGroup2',
3841 'pattern': 'FIXME', 'priority': 10, 'id': 2}] >
3842 :let m = getmatches()
3843 :call clearmatches()
3844 :echo getmatches()
3845< [] >
3846 :call setmatches(m)
3847 :echo getmatches()
3848< [{'group': 'MyGroup1', 'pattern': 'TODO',
3849 'priority': 10, 'id': 1}, {'group': 'MyGroup2',
3850 'pattern': 'FIXME', 'priority': 10, 'id': 2}] >
3851 :unlet m
3852<
3853getmousepos() *getmousepos()*
3854 Returns a |Dictionary| with the last known position of the
3855 mouse. This can be used in a mapping for a mouse click or in
3856 a filter of a popup window. The items are:
3857 screenrow screen row
3858 screencol screen column
3859 winid Window ID of the click
3860 winrow row inside "winid"
3861 wincol column inside "winid"
3862 line text line inside "winid"
3863 column text column inside "winid"
3864 All numbers are 1-based.
3865
3866 If not over a window, e.g. when in the command line, then only
3867 "screenrow" and "screencol" are valid, the others are zero.
3868
3869 When on the status line below a window or the vertical
3870 separator right of a window, the "line" and "column" values
3871 are zero.
3872
3873 When the position is after the text then "column" is the
3874 length of the text in bytes plus one.
3875
3876 If the mouse is over a popup window then that window is used.
3877
3878 When using |getchar()| the Vim variables |v:mouse_lnum|,
3879 |v:mouse_col| and |v:mouse_winid| also provide these values.
3880
3881 *getpid()*
3882getpid() Return a Number which is the process ID of the Vim process.
3883 On Unix and MS-Windows this is a unique number, until Vim
3884 exits.
3885
3886 *getpos()*
3887getpos({expr}) Get the position for String {expr}. For possible values of
3888 {expr} see |line()|. For getting the cursor position see
3889 |getcurpos()|.
3890 The result is a |List| with four numbers:
3891 [bufnum, lnum, col, off]
3892 "bufnum" is zero, unless a mark like '0 or 'A is used, then it
3893 is the buffer number of the mark.
3894 "lnum" and "col" are the position in the buffer. The first
3895 column is 1.
3896 The "off" number is zero, unless 'virtualedit' is used. Then
3897 it is the offset in screen columns from the start of the
3898 character. E.g., a position within a <Tab> or after the last
3899 character.
3900 Note that for '< and '> Visual mode matters: when it is "V"
3901 (visual line mode) the column of '< is zero and the column of
naohiro ono56200ee2022-01-01 14:59:44 +00003902 '> is a large number equal to |v:maxcol|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003903 The column number in the returned List is the byte position
3904 within the line. To get the character position in the line,
3905 use |getcharpos()|.
naohiro ono56200ee2022-01-01 14:59:44 +00003906 A very large column number equal to |v:maxcol| can be returned,
3907 in which case it means "after the end of the line".
Bram Moolenaar016188f2022-06-06 20:52:59 +01003908 If {expr} is invalid, returns a list with all zeros.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003909 This can be used to save and restore the position of a mark: >
3910 let save_a_mark = getpos("'a")
3911 ...
3912 call setpos("'a", save_a_mark)
3913< Also see |getcharpos()|, |getcurpos()| and |setpos()|.
3914
3915 Can also be used as a |method|: >
3916 GetMark()->getpos()
3917
3918getqflist([{what}]) *getqflist()*
3919 Returns a |List| with all the current quickfix errors. Each
3920 list item is a dictionary with these entries:
3921 bufnr number of buffer that has the file name, use
3922 bufname() to get the name
3923 module module name
3924 lnum line number in the buffer (first line is 1)
3925 end_lnum
3926 end of line number if the item is multiline
3927 col column number (first column is 1)
3928 end_col end of column number if the item has range
3929 vcol |TRUE|: "col" is visual column
3930 |FALSE|: "col" is byte index
3931 nr error number
3932 pattern search pattern used to locate the error
3933 text description of the error
3934 type type of the error, 'E', '1', etc.
3935 valid |TRUE|: recognized error message
3936
3937 When there is no error list or it's empty, an empty list is
3938 returned. Quickfix list entries with a non-existing buffer
3939 number are returned with "bufnr" set to zero (Note: some
3940 functions accept buffer number zero for the alternate buffer,
3941 you may need to explicitly check for zero).
3942
3943 Useful application: Find pattern matches in multiple files and
3944 do something with them: >
3945 :vimgrep /theword/jg *.c
3946 :for d in getqflist()
3947 : echo bufname(d.bufnr) ':' d.lnum '=' d.text
3948 :endfor
3949<
3950 If the optional {what} dictionary argument is supplied, then
3951 returns only the items listed in {what} as a dictionary. The
3952 following string items are supported in {what}:
3953 changedtick get the total number of changes made
3954 to the list |quickfix-changedtick|
3955 context get the |quickfix-context|
3956 efm errorformat to use when parsing "lines". If
3957 not present, then the 'errorformat' option
3958 value is used.
3959 id get information for the quickfix list with
3960 |quickfix-ID|; zero means the id for the
3961 current list or the list specified by "nr"
3962 idx get information for the quickfix entry at this
3963 index in the list specified by 'id' or 'nr'.
3964 If set to zero, then uses the current entry.
3965 See |quickfix-index|
3966 items quickfix list entries
3967 lines parse a list of lines using 'efm' and return
3968 the resulting entries. Only a |List| type is
3969 accepted. The current quickfix list is not
3970 modified. See |quickfix-parse|.
3971 nr get information for this quickfix list; zero
3972 means the current quickfix list and "$" means
3973 the last quickfix list
3974 qfbufnr number of the buffer displayed in the quickfix
3975 window. Returns 0 if the quickfix buffer is
3976 not present. See |quickfix-buffer|.
3977 size number of entries in the quickfix list
3978 title get the list title |quickfix-title|
3979 winid get the quickfix |window-ID|
3980 all all of the above quickfix properties
3981 Non-string items in {what} are ignored. To get the value of a
3982 particular item, set it to zero.
3983 If "nr" is not present then the current quickfix list is used.
3984 If both "nr" and a non-zero "id" are specified, then the list
3985 specified by "id" is used.
3986 To get the number of lists in the quickfix stack, set "nr" to
3987 "$" in {what}. The "nr" value in the returned dictionary
3988 contains the quickfix stack size.
3989 When "lines" is specified, all the other items except "efm"
3990 are ignored. The returned dictionary contains the entry
3991 "items" with the list of entries.
3992
3993 The returned dictionary contains the following entries:
3994 changedtick total number of changes made to the
3995 list |quickfix-changedtick|
3996 context quickfix list context. See |quickfix-context|
3997 If not present, set to "".
3998 id quickfix list ID |quickfix-ID|. If not
3999 present, set to 0.
4000 idx index of the quickfix entry in the list. If not
4001 present, set to 0.
4002 items quickfix list entries. If not present, set to
4003 an empty list.
4004 nr quickfix list number. If not present, set to 0
4005 qfbufnr number of the buffer displayed in the quickfix
4006 window. If not present, set to 0.
4007 size number of entries in the quickfix list. If not
4008 present, set to 0.
4009 title quickfix list title text. If not present, set
4010 to "".
4011 winid quickfix |window-ID|. If not present, set to 0
4012
4013 Examples (See also |getqflist-examples|): >
4014 :echo getqflist({'all': 1})
4015 :echo getqflist({'nr': 2, 'title': 1})
4016 :echo getqflist({'lines' : ["F1:10:L10"]})
4017<
4018getreg([{regname} [, 1 [, {list}]]]) *getreg()*
4019 The result is a String, which is the contents of register
4020 {regname}. Example: >
4021 :let cliptext = getreg('*')
4022< When register {regname} was not set the result is an empty
4023 string.
Bram Moolenaara2baa732022-02-04 16:09:54 +00004024 The {regname} argument must be a string. *E1162*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004025
4026 getreg('=') returns the last evaluated value of the expression
4027 register. (For use in maps.)
4028 getreg('=', 1) returns the expression itself, so that it can
4029 be restored with |setreg()|. For other registers the extra
4030 argument is ignored, thus you can always give it.
4031
4032 If {list} is present and |TRUE|, the result type is changed
4033 to |List|. Each list item is one text line. Use it if you care
4034 about zero bytes possibly present inside register: without
4035 third argument both NLs and zero bytes are represented as NLs
4036 (see |NL-used-for-Nul|).
4037 When the register was not set an empty list is returned.
4038
4039 If {regname} is "", the unnamed register '"' is used.
4040 If {regname} is not specified, |v:register| is used.
4041 In |Vim9-script| {regname} must be one character.
4042
4043 Can also be used as a |method|: >
4044 GetRegname()->getreg()
4045
4046getreginfo([{regname}]) *getreginfo()*
4047 Returns detailed information about register {regname} as a
4048 Dictionary with the following entries:
4049 regcontents List of lines contained in register
4050 {regname}, like
4051 |getreg|({regname}, 1, 1).
4052 regtype the type of register {regname}, as in
4053 |getregtype()|.
4054 isunnamed Boolean flag, v:true if this register
4055 is currently pointed to by the unnamed
4056 register.
4057 points_to for the unnamed register, gives the
4058 single letter name of the register
4059 currently pointed to (see |quotequote|).
4060 For example, after deleting a line
4061 with `dd`, this field will be "1",
4062 which is the register that got the
4063 deleted text.
4064
4065 The {regname} argument is a string. If {regname} is invalid
4066 or not set, an empty Dictionary will be returned.
4067 If {regname} is "" or "@", the unnamed register '"' is used.
4068 If {regname} is not specified, |v:register| is used.
4069 The returned Dictionary can be passed to |setreg()|.
4070 In |Vim9-script| {regname} must be one character.
4071
4072 Can also be used as a |method|: >
4073 GetRegname()->getreginfo()
4074
4075getregtype([{regname}]) *getregtype()*
4076 The result is a String, which is type of register {regname}.
4077 The value will be one of:
4078 "v" for |characterwise| text
4079 "V" for |linewise| text
4080 "<CTRL-V>{width}" for |blockwise-visual| text
4081 "" for an empty or unknown register
4082 <CTRL-V> is one character with value 0x16.
4083 The {regname} argument is a string. If {regname} is "", the
4084 unnamed register '"' is used. If {regname} is not specified,
4085 |v:register| is used.
4086 In |Vim9-script| {regname} must be one character.
4087
4088 Can also be used as a |method|: >
4089 GetRegname()->getregtype()
4090
4091gettabinfo([{tabnr}]) *gettabinfo()*
4092 If {tabnr} is not specified, then information about all the
4093 tab pages is returned as a |List|. Each List item is a
4094 |Dictionary|. Otherwise, {tabnr} specifies the tab page
4095 number and information about that one is returned. If the tab
4096 page does not exist an empty List is returned.
4097
4098 Each List item is a |Dictionary| with the following entries:
4099 tabnr tab page number.
4100 variables a reference to the dictionary with
4101 tabpage-local variables
4102 windows List of |window-ID|s in the tab page.
4103
4104 Can also be used as a |method|: >
4105 GetTabnr()->gettabinfo()
4106
4107gettabvar({tabnr}, {varname} [, {def}]) *gettabvar()*
4108 Get the value of a tab-local variable {varname} in tab page
4109 {tabnr}. |t:var|
4110 Tabs are numbered starting with one.
4111 The {varname} argument is a string. When {varname} is empty a
4112 dictionary with all tab-local variables is returned.
4113 Note that the name without "t:" must be used.
4114 When the tab or variable doesn't exist {def} or an empty
4115 string is returned, there is no error message.
4116
4117 Can also be used as a |method|: >
4118 GetTabnr()->gettabvar(varname)
4119
4120gettabwinvar({tabnr}, {winnr}, {varname} [, {def}]) *gettabwinvar()*
4121 Get the value of window-local variable {varname} in window
4122 {winnr} in tab page {tabnr}.
4123 The {varname} argument is a string. When {varname} is empty a
4124 dictionary with all window-local variables is returned.
4125 When {varname} is equal to "&" get the values of all
4126 window-local options in a |Dictionary|.
4127 Otherwise, when {varname} starts with "&" get the value of a
4128 window-local option.
4129 Note that {varname} must be the name without "w:".
4130 Tabs are numbered starting with one. For the current tabpage
4131 use |getwinvar()|.
4132 {winnr} can be the window number or the |window-ID|.
4133 When {winnr} is zero the current window is used.
4134 This also works for a global option, buffer-local option and
4135 window-local option, but it doesn't work for a global variable
4136 or buffer-local variable.
4137 When the tab, window or variable doesn't exist {def} or an
4138 empty string is returned, there is no error message.
4139 Examples: >
4140 :let list_is_on = gettabwinvar(1, 2, '&list')
Bram Moolenaarc51cf032022-02-26 12:25:45 +00004141 :echo "myvar = " .. gettabwinvar(3, 1, 'myvar')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004142<
4143 To obtain all window-local variables use: >
4144 gettabwinvar({tabnr}, {winnr}, '&')
4145
4146< Can also be used as a |method|: >
4147 GetTabnr()->gettabwinvar(winnr, varname)
4148
4149gettagstack([{winnr}]) *gettagstack()*
4150 The result is a Dict, which is the tag stack of window {winnr}.
4151 {winnr} can be the window number or the |window-ID|.
4152 When {winnr} is not specified, the current window is used.
4153 When window {winnr} doesn't exist, an empty Dict is returned.
4154
4155 The returned dictionary contains the following entries:
4156 curidx Current index in the stack. When at
4157 top of the stack, set to (length + 1).
4158 Index of bottom of the stack is 1.
4159 items List of items in the stack. Each item
4160 is a dictionary containing the
4161 entries described below.
4162 length Number of entries in the stack.
4163
4164 Each item in the stack is a dictionary with the following
4165 entries:
4166 bufnr buffer number of the current jump
4167 from cursor position before the tag jump.
4168 See |getpos()| for the format of the
4169 returned list.
4170 matchnr current matching tag number. Used when
4171 multiple matching tags are found for a
4172 name.
4173 tagname name of the tag
4174
4175 See |tagstack| for more information about the tag stack.
4176
4177 Can also be used as a |method|: >
4178 GetWinnr()->gettagstack()
4179
4180
4181gettext({text}) *gettext()*
4182 Translate String {text} if possible.
4183 This is mainly for use in the distributed Vim scripts. When
4184 generating message translations the {text} is extracted by
4185 xgettext, the translator can add the translated message in the
4186 .po file and Vim will lookup the translation when gettext() is
4187 called.
4188 For {text} double quoted strings are preferred, because
4189 xgettext does not understand escaping in single quoted
4190 strings.
4191
4192
4193getwininfo([{winid}]) *getwininfo()*
4194 Returns information about windows as a |List| with Dictionaries.
4195
4196 If {winid} is given Information about the window with that ID
4197 is returned, as a |List| with one item. If the window does not
4198 exist the result is an empty list.
4199
4200 Without {winid} information about all the windows in all the
4201 tab pages is returned.
4202
4203 Each List item is a |Dictionary| with the following entries:
4204 botline last complete displayed buffer line
4205 bufnr number of buffer in the window
4206 height window height (excluding winbar)
4207 loclist 1 if showing a location list
4208 {only with the +quickfix feature}
4209 quickfix 1 if quickfix or location list window
4210 {only with the +quickfix feature}
4211 terminal 1 if a terminal window
4212 {only with the +terminal feature}
4213 tabnr tab page number
4214 topline first displayed buffer line
4215 variables a reference to the dictionary with
4216 window-local variables
4217 width window width
4218 winbar 1 if the window has a toolbar, 0
4219 otherwise
4220 wincol leftmost screen column of the window;
4221 "col" from |win_screenpos()|
4222 textoff number of columns occupied by any
4223 'foldcolumn', 'signcolumn' and line
4224 number in front of the text
4225 winid |window-ID|
4226 winnr window number
4227 winrow topmost screen line of the window;
4228 "row" from |win_screenpos()|
4229
4230 Can also be used as a |method|: >
4231 GetWinnr()->getwininfo()
4232
4233getwinpos([{timeout}]) *getwinpos()*
4234 The result is a |List| with two numbers, the result of
4235 |getwinposx()| and |getwinposy()| combined:
4236 [x-pos, y-pos]
4237 {timeout} can be used to specify how long to wait in msec for
4238 a response from the terminal. When omitted 100 msec is used.
4239 Use a longer time for a remote terminal.
4240 When using a value less than 10 and no response is received
4241 within that time, a previously reported position is returned,
4242 if available. This can be used to poll for the position and
4243 do some work in the meantime: >
4244 while 1
4245 let res = getwinpos(1)
4246 if res[0] >= 0
4247 break
4248 endif
4249 " Do some work here
4250 endwhile
4251<
4252
4253 Can also be used as a |method|: >
4254 GetTimeout()->getwinpos()
4255<
4256 *getwinposx()*
4257getwinposx() The result is a Number, which is the X coordinate in pixels of
4258 the left hand side of the GUI Vim window. Also works for an
4259 xterm (uses a timeout of 100 msec).
4260 The result will be -1 if the information is not available.
4261 The value can be used with `:winpos`.
4262
4263 *getwinposy()*
4264getwinposy() The result is a Number, which is the Y coordinate in pixels of
4265 the top of the GUI Vim window. Also works for an xterm (uses
4266 a timeout of 100 msec).
4267 The result will be -1 if the information is not available.
4268 The value can be used with `:winpos`.
4269
4270getwinvar({winnr}, {varname} [, {def}]) *getwinvar()*
4271 Like |gettabwinvar()| for the current tabpage.
4272 Examples: >
4273 :let list_is_on = getwinvar(2, '&list')
Bram Moolenaarc51cf032022-02-26 12:25:45 +00004274 :echo "myvar = " .. getwinvar(1, 'myvar')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004275
4276< Can also be used as a |method|: >
4277 GetWinnr()->getwinvar(varname)
4278<
4279glob({expr} [, {nosuf} [, {list} [, {alllinks}]]]) *glob()*
4280 Expand the file wildcards in {expr}. See |wildcards| for the
4281 use of special characters.
4282
4283 Unless the optional {nosuf} argument is given and is |TRUE|,
4284 the 'suffixes' and 'wildignore' options apply: Names matching
4285 one of the patterns in 'wildignore' will be skipped and
4286 'suffixes' affect the ordering of matches.
4287 'wildignorecase' always applies.
4288
4289 When {list} is present and it is |TRUE| the result is a |List|
4290 with all matching files. The advantage of using a List is,
4291 you also get filenames containing newlines correctly.
4292 Otherwise the result is a String and when there are several
4293 matches, they are separated by <NL> characters.
4294
4295 If the expansion fails, the result is an empty String or List.
4296
4297 You can also use |readdir()| if you need to do complicated
4298 things, such as limiting the number of matches.
4299
4300 A name for a non-existing file is not included. A symbolic
4301 link is only included if it points to an existing file.
4302 However, when the {alllinks} argument is present and it is
4303 |TRUE| then all symbolic links are included.
4304
4305 For most systems backticks can be used to get files names from
4306 any external command. Example: >
4307 :let tagfiles = glob("`find . -name tags -print`")
4308 :let &tags = substitute(tagfiles, "\n", ",", "g")
4309< The result of the program inside the backticks should be one
4310 item per line. Spaces inside an item are allowed.
4311
4312 See |expand()| for expanding special Vim variables. See
4313 |system()| for getting the raw output of an external command.
4314
4315 Can also be used as a |method|: >
4316 GetExpr()->glob()
4317
4318glob2regpat({string}) *glob2regpat()*
4319 Convert a file pattern, as used by glob(), into a search
4320 pattern. The result can be used to match with a string that
4321 is a file name. E.g. >
4322 if filename =~ glob2regpat('Make*.mak')
4323< This is equivalent to: >
4324 if filename =~ '^Make.*\.mak$'
4325< When {string} is an empty string the result is "^$", match an
4326 empty string.
4327 Note that the result depends on the system. On MS-Windows
4328 a backslash usually means a path separator.
4329
4330 Can also be used as a |method|: >
4331 GetExpr()->glob2regpat()
4332< *globpath()*
4333globpath({path}, {expr} [, {nosuf} [, {list} [, {alllinks}]]])
4334 Perform glob() for String {expr} on all directories in {path}
4335 and concatenate the results. Example: >
4336 :echo globpath(&rtp, "syntax/c.vim")
4337<
4338 {path} is a comma-separated list of directory names. Each
4339 directory name is prepended to {expr} and expanded like with
4340 |glob()|. A path separator is inserted when needed.
4341 To add a comma inside a directory name escape it with a
4342 backslash. Note that on MS-Windows a directory may have a
4343 trailing backslash, remove it if you put a comma after it.
4344 If the expansion fails for one of the directories, there is no
4345 error message.
4346
4347 Unless the optional {nosuf} argument is given and is |TRUE|,
4348 the 'suffixes' and 'wildignore' options apply: Names matching
4349 one of the patterns in 'wildignore' will be skipped and
4350 'suffixes' affect the ordering of matches.
4351
4352 When {list} is present and it is |TRUE| the result is a |List|
4353 with all matching files. The advantage of using a List is, you
4354 also get filenames containing newlines correctly. Otherwise
4355 the result is a String and when there are several matches,
4356 they are separated by <NL> characters. Example: >
4357 :echo globpath(&rtp, "syntax/c.vim", 0, 1)
4358<
4359 {alllinks} is used as with |glob()|.
4360
4361 The "**" item can be used to search in a directory tree.
4362 For example, to find all "README.txt" files in the directories
4363 in 'runtimepath' and below: >
4364 :echo globpath(&rtp, "**/README.txt")
4365< Upwards search and limiting the depth of "**" is not
4366 supported, thus using 'path' will not always work properly.
4367
4368 Can also be used as a |method|, the base is passed as the
4369 second argument: >
4370 GetExpr()->globpath(&rtp)
4371<
4372 *has()*
4373has({feature} [, {check}])
4374 When {check} is omitted or is zero: The result is a Number,
4375 which is 1 if the feature {feature} is supported, zero
4376 otherwise. The {feature} argument is a string, case is
4377 ignored. See |feature-list| below.
4378
4379 When {check} is present and not zero: The result is a Number,
4380 which is 1 if the feature {feature} could ever be supported,
4381 zero otherwise. This is useful to check for a typo in
4382 {feature} and to detect dead code. Keep in mind that an older
4383 Vim version will not know about a feature added later and
4384 features that have been abandoned will not be known by the
4385 current Vim version.
4386
4387 Also see |exists()| and |exists_compiled()|.
4388
4389 Note that to skip code that has a syntax error when the
4390 feature is not available, Vim may skip the rest of the line
4391 and miss a following `endif`. Therefore put the `endif` on a
4392 separate line: >
4393 if has('feature')
4394 let x = this->breaks->without->the->feature
4395 endif
4396< If the `endif` would be moved to the second line as "| endif" it
4397 would not be found.
4398
4399
4400has_key({dict}, {key}) *has_key()*
4401 The result is a Number, which is TRUE if |Dictionary| {dict}
4402 has an entry with key {key}. FALSE otherwise. The {key}
4403 argument is a string.
4404
4405 Can also be used as a |method|: >
4406 mydict->has_key(key)
4407
4408haslocaldir([{winnr} [, {tabnr}]]) *haslocaldir()*
4409 The result is a Number:
4410 1 when the window has set a local directory via |:lcd|
4411 2 when the tab-page has set a local directory via |:tcd|
4412 0 otherwise.
4413
4414 Without arguments use the current window.
4415 With {winnr} use this window in the current tab page.
4416 With {winnr} and {tabnr} use the window in the specified tab
4417 page.
4418 {winnr} can be the window number or the |window-ID|.
4419 If {winnr} is -1 it is ignored and only the tabpage is used.
4420 Return 0 if the arguments are invalid.
4421 Examples: >
4422 if haslocaldir() == 1
4423 " window local directory case
4424 elseif haslocaldir() == 2
4425 " tab-local directory case
4426 else
4427 " global directory case
4428 endif
4429
4430 " current window
4431 :echo haslocaldir()
4432 :echo haslocaldir(0)
4433 :echo haslocaldir(0, 0)
4434 " window n in current tab page
4435 :echo haslocaldir(n)
4436 :echo haslocaldir(n, 0)
4437 " window n in tab page m
4438 :echo haslocaldir(n, m)
4439 " tab page m
4440 :echo haslocaldir(-1, m)
4441<
4442 Can also be used as a |method|: >
4443 GetWinnr()->haslocaldir()
4444
4445hasmapto({what} [, {mode} [, {abbr}]]) *hasmapto()*
4446 The result is a Number, which is TRUE if there is a mapping
4447 that contains {what} in somewhere in the rhs (what it is
4448 mapped to) and this mapping exists in one of the modes
4449 indicated by {mode}.
4450 The arguments {what} and {mode} are strings.
4451 When {abbr} is there and it is |TRUE| use abbreviations
4452 instead of mappings. Don't forget to specify Insert and/or
4453 Command-line mode.
4454 Both the global mappings and the mappings local to the current
4455 buffer are checked for a match.
4456 If no matching mapping is found FALSE is returned.
4457 The following characters are recognized in {mode}:
4458 n Normal mode
4459 v Visual and Select mode
4460 x Visual mode
4461 s Select mode
4462 o Operator-pending mode
4463 i Insert mode
4464 l Language-Argument ("r", "f", "t", etc.)
4465 c Command-line mode
4466 When {mode} is omitted, "nvo" is used.
4467
4468 This function is useful to check if a mapping already exists
4469 to a function in a Vim script. Example: >
4470 :if !hasmapto('\ABCdoit')
4471 : map <Leader>d \ABCdoit
4472 :endif
4473< This installs the mapping to "\ABCdoit" only if there isn't
4474 already a mapping to "\ABCdoit".
4475
4476 Can also be used as a |method|: >
4477 GetRHS()->hasmapto()
4478
4479histadd({history}, {item}) *histadd()*
4480 Add the String {item} to the history {history} which can be
4481 one of: *hist-names*
4482 "cmd" or ":" command line history
4483 "search" or "/" search pattern history
4484 "expr" or "=" typed expression history
4485 "input" or "@" input line history
4486 "debug" or ">" debug command history
4487 empty the current or last used history
4488 The {history} string does not need to be the whole name, one
4489 character is sufficient.
4490 If {item} does already exist in the history, it will be
4491 shifted to become the newest entry.
4492 The result is a Number: TRUE if the operation was successful,
4493 otherwise FALSE is returned.
4494
4495 Example: >
4496 :call histadd("input", strftime("%Y %b %d"))
4497 :let date=input("Enter date: ")
4498< This function is not available in the |sandbox|.
4499
4500 Can also be used as a |method|, the base is passed as the
4501 second argument: >
4502 GetHistory()->histadd('search')
4503
4504histdel({history} [, {item}]) *histdel()*
4505 Clear {history}, i.e. delete all its entries. See |hist-names|
4506 for the possible values of {history}.
4507
4508 If the parameter {item} evaluates to a String, it is used as a
4509 regular expression. All entries matching that expression will
4510 be removed from the history (if there are any).
4511 Upper/lowercase must match, unless "\c" is used |/\c|.
4512 If {item} evaluates to a Number, it will be interpreted as
4513 an index, see |:history-indexing|. The respective entry will
4514 be removed if it exists.
4515
4516 The result is TRUE for a successful operation, otherwise FALSE
4517 is returned.
4518
4519 Examples:
4520 Clear expression register history: >
4521 :call histdel("expr")
4522<
4523 Remove all entries starting with "*" from the search history: >
4524 :call histdel("/", '^\*')
4525<
4526 The following three are equivalent: >
4527 :call histdel("search", histnr("search"))
4528 :call histdel("search", -1)
Bram Moolenaarc51cf032022-02-26 12:25:45 +00004529 :call histdel("search", '^' .. histget("search", -1) .. '$')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004530<
4531 To delete the last search pattern and use the last-but-one for
4532 the "n" command and 'hlsearch': >
4533 :call histdel("search", -1)
4534 :let @/ = histget("search", -1)
4535<
4536 Can also be used as a |method|: >
4537 GetHistory()->histdel()
4538
4539histget({history} [, {index}]) *histget()*
4540 The result is a String, the entry with Number {index} from
4541 {history}. See |hist-names| for the possible values of
4542 {history}, and |:history-indexing| for {index}. If there is
4543 no such entry, an empty String is returned. When {index} is
4544 omitted, the most recent item from the history is used.
4545
4546 Examples:
4547 Redo the second last search from history. >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00004548 :execute '/' .. histget("search", -2)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004549
4550< Define an Ex command ":H {num}" that supports re-execution of
4551 the {num}th entry from the output of |:history|. >
4552 :command -nargs=1 H execute histget("cmd", 0+<args>)
4553<
4554 Can also be used as a |method|: >
4555 GetHistory()->histget()
4556
4557histnr({history}) *histnr()*
4558 The result is the Number of the current entry in {history}.
4559 See |hist-names| for the possible values of {history}.
4560 If an error occurred, -1 is returned.
4561
4562 Example: >
4563 :let inp_index = histnr("expr")
4564
4565< Can also be used as a |method|: >
4566 GetHistory()->histnr()
4567<
4568hlexists({name}) *hlexists()*
4569 The result is a Number, which is TRUE if a highlight group
4570 called {name} exists. This is when the group has been
4571 defined in some way. Not necessarily when highlighting has
4572 been defined for it, it may also have been used for a syntax
4573 item.
4574 *highlight_exists()*
4575 Obsolete name: highlight_exists().
4576
4577 Can also be used as a |method|: >
4578 GetName()->hlexists()
4579<
4580hlget([{name} [, {resolve}]]) *hlget()*
4581 Returns a List of all the highlight group attributes. If the
4582 optional {name} is specified, then returns a List with only
4583 the attributes of the specified highlight group. Returns an
4584 empty List if the highlight group {name} is not present.
4585
4586 If the optional {resolve} argument is set to v:true and the
4587 highlight group {name} is linked to another group, then the
4588 link is resolved recursively and the attributes of the
4589 resolved highlight group are returned.
4590
4591 Each entry in the returned List is a Dictionary with the
4592 following items:
4593 cleared boolean flag, set to v:true if the highlight
4594 group attributes are cleared or not yet
4595 specified. See |highlight-clear|.
4596 cterm cterm attributes. See |highlight-cterm|.
4597 ctermbg cterm background color.
4598 See |highlight-ctermbg|.
4599 ctermfg cterm foreground color.
4600 See |highlight-ctermfg|.
4601 ctermul cterm underline color. See |highlight-ctermul|.
4602 default boolean flag, set to v:true if the highlight
4603 group link is a default link. See
4604 |highlight-default|.
4605 font highlight group font. See |highlight-font|.
4606 gui gui attributes. See |highlight-gui|.
4607 guibg gui background color. See |highlight-guibg|.
4608 guifg gui foreground color. See |highlight-guifg|.
4609 guisp gui special color. See |highlight-guisp|.
4610 id highlight group ID.
4611 linksto linked highlight group name.
4612 See |:highlight-link|.
4613 name highlight group name. See |group-name|.
4614 start start terminal keycode. See |highlight-start|.
4615 stop stop terminal keycode. See |highlight-stop|.
4616 term term attributes. See |highlight-term|.
4617
4618 The 'term', 'cterm' and 'gui' items in the above Dictionary
4619 have a dictionary value with the following optional boolean
4620 items: 'bold', 'standout', 'underline', 'undercurl', 'italic',
4621 'reverse', 'inverse' and 'strikethrough'.
4622
4623 Example(s): >
4624 :echo hlget()
4625 :echo hlget('ModeMsg')
4626 :echo hlget('Number', v:true)
4627<
4628 Can also be used as a |method|: >
4629 GetName()->hlget()
4630<
4631hlset({list}) *hlset()*
4632 Creates or modifies the attributes of a List of highlight
4633 groups. Each item in {list} is a dictionary containing the
4634 attributes of a highlight group. See |hlget()| for the list of
4635 supported items in this dictionary.
4636
4637 In addition to the items described in |hlget()|, the following
4638 additional items are supported in the dictionary:
4639
4640 force boolean flag to force the creation of
4641 a link for an existing highlight group
4642 with attributes.
4643
4644 The highlight group is identified using the 'name' item and
4645 the 'id' item (if supplied) is ignored. If a highlight group
4646 with a specified name doesn't exist, then it is created.
4647 Otherwise the attributes of an existing highlight group are
4648 modified.
4649
4650 If an empty dictionary value is used for the 'term' or 'cterm'
4651 or 'gui' entries, then the corresponding attributes are
4652 cleared. If the 'cleared' item is set to v:true, then all the
4653 attributes of the highlight group are cleared.
4654
4655 The 'linksto' item can be used to link a highlight group to
4656 another highlight group. See |:highlight-link|.
4657
4658 Returns zero for success, -1 for failure.
4659
4660 Example(s): >
4661 " add bold attribute to the Visual highlight group
4662 :call hlset([#{name: 'Visual',
4663 \ term: #{reverse: 1 , bold: 1}}])
4664 :call hlset([#{name: 'Type', guifg: 'DarkGreen'}])
4665 :let l = hlget()
4666 :call hlset(l)
4667 " clear the Search highlight group
4668 :call hlset([#{name: 'Search', cleared: v:true}])
4669 " clear the 'term' attributes for a highlight group
4670 :call hlset([#{name: 'Title', term: {}}])
4671 " create the MyHlg group linking it to DiffAdd
4672 :call hlset([#{name: 'MyHlg', linksto: 'DiffAdd'}])
4673 " remove the MyHlg group link
4674 :call hlset([#{name: 'MyHlg', linksto: 'NONE'}])
4675 " clear the attributes and a link
4676 :call hlset([#{name: 'MyHlg', cleared: v:true,
4677 \ linksto: 'NONE'}])
4678<
4679 Can also be used as a |method|: >
4680 GetAttrList()->hlset()
4681<
4682 *hlID()*
4683hlID({name}) The result is a Number, which is the ID of the highlight group
4684 with name {name}. When the highlight group doesn't exist,
4685 zero is returned.
4686 This can be used to retrieve information about the highlight
4687 group. For example, to get the background color of the
4688 "Comment" group: >
4689 :echo synIDattr(synIDtrans(hlID("Comment")), "bg")
4690< *highlightID()*
4691 Obsolete name: highlightID().
4692
4693 Can also be used as a |method|: >
4694 GetName()->hlID()
4695
4696hostname() *hostname()*
4697 The result is a String, which is the name of the machine on
4698 which Vim is currently running. Machine names greater than
4699 256 characters long are truncated.
4700
4701iconv({string}, {from}, {to}) *iconv()*
4702 The result is a String, which is the text {string} converted
4703 from encoding {from} to encoding {to}.
4704 When the conversion completely fails an empty string is
4705 returned. When some characters could not be converted they
4706 are replaced with "?".
4707 The encoding names are whatever the iconv() library function
4708 can accept, see ":!man 3 iconv".
4709 Most conversions require Vim to be compiled with the |+iconv|
4710 feature. Otherwise only UTF-8 to latin1 conversion and back
4711 can be done.
4712 This can be used to display messages with special characters,
4713 no matter what 'encoding' is set to. Write the message in
4714 UTF-8 and use: >
4715 echo iconv(utf8_str, "utf-8", &enc)
4716< Note that Vim uses UTF-8 for all Unicode encodings, conversion
4717 from/to UCS-2 is automatically changed to use UTF-8. You
4718 cannot use UCS-2 in a string anyway, because of the NUL bytes.
4719
4720 Can also be used as a |method|: >
4721 GetText()->iconv('latin1', 'utf-8')
4722<
4723 *indent()*
4724indent({lnum}) The result is a Number, which is indent of line {lnum} in the
4725 current buffer. The indent is counted in spaces, the value
4726 of 'tabstop' is relevant. {lnum} is used just like in
4727 |getline()|.
4728 When {lnum} is invalid -1 is returned. In |Vim9| script an
4729 error is given.
4730
4731 Can also be used as a |method|: >
4732 GetLnum()->indent()
4733
4734index({object}, {expr} [, {start} [, {ic}]]) *index()*
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01004735 Find {expr} in {object} and return its index. See
Yegappan Lakshmanan3fbf6cd2022-08-13 21:35:13 +01004736 |indexof()| for using a lambda to select the item.
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01004737
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004738 If {object} is a |List| return the lowest index where the item
4739 has a value equal to {expr}. There is no automatic
4740 conversion, so the String "4" is different from the Number 4.
4741 And the number 4 is different from the Float 4.0. The value
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01004742 of 'ignorecase' is not used here, case matters as indicated by
4743 the {ic} argument.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004744
4745 If {object} is |Blob| return the lowest index where the byte
4746 value is equal to {expr}.
4747
4748 If {start} is given then start looking at the item with index
4749 {start} (may be negative for an item relative to the end).
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01004750
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004751 When {ic} is given and it is |TRUE|, ignore case. Otherwise
4752 case must match.
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01004753
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004754 -1 is returned when {expr} is not found in {object}.
4755 Example: >
4756 :let idx = index(words, "the")
4757 :if index(numbers, 123) >= 0
4758
4759< Can also be used as a |method|: >
4760 GetObject()->index(what)
4761
Yegappan Lakshmanan3fbf6cd2022-08-13 21:35:13 +01004762indexof({object}, {expr} [, {opts}]) *indexof()*
4763 Returns the index of an item in {object} where {expr} is
4764 v:true. {object} must be a |List| or a |Blob|.
4765
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01004766 If {object} is a |List|, evaluate {expr} for each item in the
Yegappan Lakshmanan3fbf6cd2022-08-13 21:35:13 +01004767 List until the expression is v:true and return the index of
4768 this item.
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01004769
4770 If {object} is a |Blob| evaluate {expr} for each byte in the
Yegappan Lakshmanan3fbf6cd2022-08-13 21:35:13 +01004771 Blob until the expression is v:true and return the index of
4772 this byte.
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01004773
4774 {expr} must be a |string| or |Funcref|.
4775
4776 If {expr} is a |string|: If {object} is a |List|, inside
4777 {expr} |v:key| has the index of the current List item and
4778 |v:val| has the value of the item. If {object} is a |Blob|,
4779 inside {expr} |v:key| has the index of the current byte and
4780 |v:val| has the byte value.
4781
4782 If {expr} is a |Funcref| it must take two arguments:
4783 1. the key or the index of the current item.
4784 2. the value of the current item.
4785 The function must return |TRUE| if the item is found and the
4786 search should stop.
4787
Yegappan Lakshmanan3fbf6cd2022-08-13 21:35:13 +01004788 The optional argument {opts} is a Dict and supports the
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01004789 following items:
Yegappan Lakshmanan3fbf6cd2022-08-13 21:35:13 +01004790 startidx start evaluating {expr} at the item with this
4791 index; may be negative for an item relative to
4792 the end
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01004793 Returns -1 when {expr} evaluates to v:false for all the items.
4794 Example: >
Yegappan Lakshmanan3fbf6cd2022-08-13 21:35:13 +01004795 :let l = [#{n: 10}, #{n: 20}, #{n: 30}]
4796 :echo indexof(l, "v:val.n == 20")
4797 :echo indexof(l, {i, v -> v.n == 30})
4798 :echo indexof(l, "v:val.n == 20", #{startidx: 1})
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01004799
4800< Can also be used as a |method|: >
4801 mylist->indexof(expr)
4802
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004803input({prompt} [, {text} [, {completion}]]) *input()*
4804 The result is a String, which is whatever the user typed on
4805 the command-line. The {prompt} argument is either a prompt
4806 string, or a blank string (for no prompt). A '\n' can be used
4807 in the prompt to start a new line.
4808 The highlighting set with |:echohl| is used for the prompt.
4809 The input is entered just like a command-line, with the same
4810 editing commands and mappings. There is a separate history
4811 for lines typed for input().
4812 Example: >
4813 :if input("Coffee or beer? ") == "beer"
4814 : echo "Cheers!"
4815 :endif
4816<
4817 If the optional {text} argument is present and not empty, this
4818 is used for the default reply, as if the user typed this.
4819 Example: >
4820 :let color = input("Color? ", "white")
4821
4822< The optional {completion} argument specifies the type of
4823 completion supported for the input. Without it completion is
4824 not performed. The supported completion types are the same as
4825 that can be supplied to a user-defined command using the
4826 "-complete=" argument. Refer to |:command-completion| for
4827 more information. Example: >
4828 let fname = input("File: ", "", "file")
4829<
4830 NOTE: This function must not be used in a startup file, for
4831 the versions that only run in GUI mode (e.g., the Win32 GUI).
4832 Note: When input() is called from within a mapping it will
4833 consume remaining characters from that mapping, because a
4834 mapping is handled like the characters were typed.
4835 Use |inputsave()| before input() and |inputrestore()|
4836 after input() to avoid that. Another solution is to avoid
4837 that further characters follow in the mapping, e.g., by using
4838 |:execute| or |:normal|.
4839
4840 Example with a mapping: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00004841 :nmap \x :call GetFoo()<CR>:exe "/" .. Foo<CR>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004842 :function GetFoo()
4843 : call inputsave()
4844 : let g:Foo = input("enter search pattern: ")
4845 : call inputrestore()
4846 :endfunction
4847
4848< Can also be used as a |method|: >
4849 GetPrompt()->input()
4850
4851inputdialog({prompt} [, {text} [, {cancelreturn}]]) *inputdialog()*
4852 Like |input()|, but when the GUI is running and text dialogs
4853 are supported, a dialog window pops up to input the text.
4854 Example: >
4855 :let n = inputdialog("value for shiftwidth", shiftwidth())
4856 :if n != ""
4857 : let &sw = n
4858 :endif
4859< When the dialog is cancelled {cancelreturn} is returned. When
4860 omitted an empty string is returned.
4861 Hitting <Enter> works like pressing the OK button. Hitting
4862 <Esc> works like pressing the Cancel button.
4863 NOTE: Command-line completion is not supported.
4864
4865 Can also be used as a |method|: >
4866 GetPrompt()->inputdialog()
4867
4868inputlist({textlist}) *inputlist()*
4869 {textlist} must be a |List| of strings. This |List| is
4870 displayed, one string per line. The user will be prompted to
4871 enter a number, which is returned.
4872 The user can also select an item by clicking on it with the
4873 mouse, if the mouse is enabled in the command line ('mouse' is
4874 "a" or includes "c"). For the first string 0 is returned.
4875 When clicking above the first item a negative number is
4876 returned. When clicking on the prompt one more than the
4877 length of {textlist} is returned.
4878 Make sure {textlist} has less than 'lines' entries, otherwise
4879 it won't work. It's a good idea to put the entry number at
4880 the start of the string. And put a prompt in the first item.
4881 Example: >
4882 let color = inputlist(['Select color:', '1. red',
4883 \ '2. green', '3. blue'])
4884
4885< Can also be used as a |method|: >
4886 GetChoices()->inputlist()
4887
4888inputrestore() *inputrestore()*
4889 Restore typeahead that was saved with a previous |inputsave()|.
4890 Should be called the same number of times inputsave() is
4891 called. Calling it more often is harmless though.
4892 Returns TRUE when there is nothing to restore, FALSE otherwise.
4893
4894inputsave() *inputsave()*
4895 Preserve typeahead (also from mappings) and clear it, so that
4896 a following prompt gets input from the user. Should be
4897 followed by a matching inputrestore() after the prompt. Can
4898 be used several times, in which case there must be just as
4899 many inputrestore() calls.
4900 Returns TRUE when out of memory, FALSE otherwise.
4901
4902inputsecret({prompt} [, {text}]) *inputsecret()*
4903 This function acts much like the |input()| function with but
4904 two exceptions:
4905 a) the user's response will be displayed as a sequence of
4906 asterisks ("*") thereby keeping the entry secret, and
4907 b) the user's response will not be recorded on the input
4908 |history| stack.
4909 The result is a String, which is whatever the user actually
4910 typed on the command-line in response to the issued prompt.
4911 NOTE: Command-line completion is not supported.
4912
4913 Can also be used as a |method|: >
4914 GetPrompt()->inputsecret()
4915
4916insert({object}, {item} [, {idx}]) *insert()*
4917 When {object} is a |List| or a |Blob| insert {item} at the start
4918 of it.
4919
4920 If {idx} is specified insert {item} before the item with index
4921 {idx}. If {idx} is zero it goes before the first item, just
4922 like omitting {idx}. A negative {idx} is also possible, see
4923 |list-index|. -1 inserts just before the last item.
4924
4925 Returns the resulting |List| or |Blob|. Examples: >
4926 :let mylist = insert([2, 3, 5], 1)
4927 :call insert(mylist, 4, -1)
4928 :call insert(mylist, 6, len(mylist))
4929< The last example can be done simpler with |add()|.
4930 Note that when {item} is a |List| it is inserted as a single
4931 item. Use |extend()| to concatenate |Lists|.
4932
4933 Can also be used as a |method|: >
4934 mylist->insert(item)
4935
4936interrupt() *interrupt()*
4937 Interrupt script execution. It works more or less like the
4938 user typing CTRL-C, most commands won't execute and control
4939 returns to the user. This is useful to abort execution
4940 from lower down, e.g. in an autocommand. Example: >
4941 :function s:check_typoname(file)
4942 : if fnamemodify(a:file, ':t') == '['
4943 : echomsg 'Maybe typo'
4944 : call interrupt()
4945 : endif
4946 :endfunction
4947 :au BufWritePre * call s:check_typoname(expand('<amatch>'))
4948
4949invert({expr}) *invert()*
4950 Bitwise invert. The argument is converted to a number. A
4951 List, Dict or Float argument causes an error. Example: >
4952 :let bits = invert(bits)
4953< Can also be used as a |method|: >
4954 :let bits = bits->invert()
4955
Bram Moolenaar8a3b8052022-06-26 12:21:15 +01004956isabsolutepath({path}) *isabsolutepath()*
LemonBoydca1d402022-04-28 15:26:33 +01004957 The result is a Number, which is |TRUE| when {path} is an
4958 absolute path.
Bram Moolenaar8a3b8052022-06-26 12:21:15 +01004959 On Unix, a path is considered absolute when it starts with '/'.
LemonBoydca1d402022-04-28 15:26:33 +01004960 On MS-Windows, it is considered absolute when it starts with an
4961 optional drive prefix and is followed by a '\' or '/'. UNC paths
4962 are always absolute.
4963 Example: >
4964 echo isabsolutepath('/usr/share/') " 1
4965 echo isabsolutepath('./foobar') " 0
4966 echo isabsolutepath('C:\Windows') " 1
4967 echo isabsolutepath('foobar') " 0
4968 echo isabsolutepath('\\remote\file') " 1
Bram Moolenaar8a3b8052022-06-26 12:21:15 +01004969<
LemonBoydca1d402022-04-28 15:26:33 +01004970 Can also be used as a |method|: >
4971 GetName()->isabsolutepath()
4972
4973
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004974isdirectory({directory}) *isdirectory()*
4975 The result is a Number, which is |TRUE| when a directory
4976 with the name {directory} exists. If {directory} doesn't
4977 exist, or isn't a directory, the result is |FALSE|. {directory}
4978 is any expression, which is used as a String.
4979
4980 Can also be used as a |method|: >
4981 GetName()->isdirectory()
4982
4983isinf({expr}) *isinf()*
4984 Return 1 if {expr} is a positive infinity, or -1 a negative
4985 infinity, otherwise 0. >
4986 :echo isinf(1.0 / 0.0)
4987< 1 >
4988 :echo isinf(-1.0 / 0.0)
4989< -1
4990
4991 Can also be used as a |method|: >
4992 Compute()->isinf()
4993<
4994 {only available when compiled with the |+float| feature}
4995
4996islocked({expr}) *islocked()* *E786*
4997 The result is a Number, which is |TRUE| when {expr} is the
4998 name of a locked variable.
4999 The string argument {expr} must be the name of a variable,
5000 |List| item or |Dictionary| entry, not the variable itself!
5001 Example: >
5002 :let alist = [0, ['a', 'b'], 2, 3]
5003 :lockvar 1 alist
5004 :echo islocked('alist') " 1
5005 :echo islocked('alist[1]') " 0
5006
Bram Moolenaar9da17d72022-02-09 21:50:44 +00005007< When {expr} is a variable that does not exist -1 is returned.
5008 If {expr} uses a range, list or dict index that is out of
5009 range or does not exist you get an error message. Use
5010 |exists()| to check for existence.
5011 In Vim9 script it does not work for local function variables.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005012
5013 Can also be used as a |method|: >
5014 GetName()->islocked()
5015
5016isnan({expr}) *isnan()*
5017 Return |TRUE| if {expr} is a float with value NaN. >
5018 echo isnan(0.0 / 0.0)
5019< 1
5020
5021 Can also be used as a |method|: >
5022 Compute()->isnan()
5023<
5024 {only available when compiled with the |+float| feature}
5025
5026items({dict}) *items()*
5027 Return a |List| with all the key-value pairs of {dict}. Each
5028 |List| item is a list with two items: the key of a {dict}
5029 entry and the value of this entry. The |List| is in arbitrary
5030 order. Also see |keys()| and |values()|.
5031 Example: >
5032 for [key, value] in items(mydict)
Bram Moolenaarc51cf032022-02-26 12:25:45 +00005033 echo key .. ': ' .. value
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005034 endfor
5035
5036< Can also be used as a |method|: >
5037 mydict->items()
5038
5039job_ functions are documented here: |job-functions-details|
5040
5041
5042join({list} [, {sep}]) *join()*
5043 Join the items in {list} together into one String.
5044 When {sep} is specified it is put in between the items. If
5045 {sep} is omitted a single space is used.
5046 Note that {sep} is not added at the end. You might want to
5047 add it there too: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00005048 let lines = join(mylist, "\n") .. "\n"
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005049< String items are used as-is. |Lists| and |Dictionaries| are
5050 converted into a string like with |string()|.
5051 The opposite function is |split()|.
5052
5053 Can also be used as a |method|: >
5054 mylist->join()
5055
5056js_decode({string}) *js_decode()*
5057 This is similar to |json_decode()| with these differences:
5058 - Object key names do not have to be in quotes.
5059 - Strings can be in single quotes.
5060 - Empty items in an array (between two commas) are allowed and
5061 result in v:none items.
5062
5063 Can also be used as a |method|: >
5064 ReadObject()->js_decode()
5065
5066js_encode({expr}) *js_encode()*
5067 This is similar to |json_encode()| with these differences:
5068 - Object key names are not in quotes.
5069 - v:none items in an array result in an empty item between
5070 commas.
5071 For example, the Vim object:
5072 [1,v:none,{"one":1},v:none] ~
5073 Will be encoded as:
5074 [1,,{one:1},,] ~
5075 While json_encode() would produce:
5076 [1,null,{"one":1},null] ~
5077 This encoding is valid for JavaScript. It is more efficient
5078 than JSON, especially when using an array with optional items.
5079
5080 Can also be used as a |method|: >
5081 GetObject()->js_encode()
5082
Bram Moolenaar2f0936c2022-01-08 21:51:59 +00005083json_decode({string}) *json_decode()* *E491*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005084 This parses a JSON formatted string and returns the equivalent
5085 in Vim values. See |json_encode()| for the relation between
5086 JSON and Vim values.
5087 The decoding is permissive:
5088 - A trailing comma in an array and object is ignored, e.g.
5089 "[1, 2, ]" is the same as "[1, 2]".
5090 - Integer keys are accepted in objects, e.g. {1:2} is the
5091 same as {"1":2}.
5092 - More floating point numbers are recognized, e.g. "1." for
5093 "1.0", or "001.2" for "1.2". Special floating point values
5094 "Infinity", "-Infinity" and "NaN" (capitalization ignored)
5095 are accepted.
5096 - Leading zeroes in integer numbers are ignored, e.g. "012"
5097 for "12" or "-012" for "-12".
5098 - Capitalization is ignored in literal names null, true or
5099 false, e.g. "NULL" for "null", "True" for "true".
5100 - Control characters U+0000 through U+001F which are not
5101 escaped in strings are accepted, e.g. " " (tab
5102 character in string) for "\t".
5103 - An empty JSON expression or made of only spaces is accepted
5104 and results in v:none.
5105 - Backslash in an invalid 2-character sequence escape is
5106 ignored, e.g. "\a" is decoded as "a".
5107 - A correct surrogate pair in JSON strings should normally be
5108 a 12 character sequence such as "\uD834\uDD1E", but
5109 json_decode() silently accepts truncated surrogate pairs
5110 such as "\uD834" or "\uD834\u"
5111 *E938*
5112 A duplicate key in an object, valid in rfc7159, is not
5113 accepted by json_decode() as the result must be a valid Vim
5114 type, e.g. this fails: {"a":"b", "a":"c"}
5115
5116 Can also be used as a |method|: >
5117 ReadObject()->json_decode()
5118
5119json_encode({expr}) *json_encode()*
5120 Encode {expr} as JSON and return this as a string.
5121 The encoding is specified in:
5122 https://tools.ietf.org/html/rfc7159.html
Bram Moolenaara2baa732022-02-04 16:09:54 +00005123 Vim values are converted as follows: *E1161*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005124 |Number| decimal number
5125 |Float| floating point number
5126 Float nan "NaN"
5127 Float inf "Infinity"
5128 Float -inf "-Infinity"
5129 |String| in double quotes (possibly null)
5130 |Funcref| not possible, error
5131 |List| as an array (possibly null); when
5132 used recursively: []
5133 |Dict| as an object (possibly null); when
5134 used recursively: {}
5135 |Blob| as an array of the individual bytes
5136 v:false "false"
5137 v:true "true"
5138 v:none "null"
5139 v:null "null"
5140 Note that NaN and Infinity are passed on as values. This is
5141 missing in the JSON standard, but several implementations do
5142 allow it. If not then you will get an error.
Bram Moolenaarcbaff5e2022-04-08 17:45:08 +01005143 If a string contains an illegal character then the replacement
5144 character 0xfffd is used.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005145
5146 Can also be used as a |method|: >
5147 GetObject()->json_encode()
5148
5149keys({dict}) *keys()*
5150 Return a |List| with all the keys of {dict}. The |List| is in
5151 arbitrary order. Also see |items()| and |values()|.
5152
5153 Can also be used as a |method|: >
5154 mydict->keys()
5155
5156< *len()* *E701*
5157len({expr}) The result is a Number, which is the length of the argument.
5158 When {expr} is a String or a Number the length in bytes is
5159 used, as with |strlen()|.
5160 When {expr} is a |List| the number of items in the |List| is
5161 returned.
5162 When {expr} is a |Blob| the number of bytes is returned.
5163 When {expr} is a |Dictionary| the number of entries in the
5164 |Dictionary| is returned.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01005165 Otherwise an error is given and returns zero.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005166
5167 Can also be used as a |method|: >
5168 mylist->len()
5169
5170< *libcall()* *E364* *E368*
5171libcall({libname}, {funcname}, {argument})
5172 Call function {funcname} in the run-time library {libname}
5173 with single argument {argument}.
5174 This is useful to call functions in a library that you
5175 especially made to be used with Vim. Since only one argument
5176 is possible, calling standard library functions is rather
5177 limited.
5178 The result is the String returned by the function. If the
5179 function returns NULL, this will appear as an empty string ""
5180 to Vim.
5181 If the function returns a number, use libcallnr()!
5182 If {argument} is a number, it is passed to the function as an
5183 int; if {argument} is a string, it is passed as a
5184 null-terminated string.
5185 This function will fail in |restricted-mode|.
5186
5187 libcall() allows you to write your own 'plug-in' extensions to
5188 Vim without having to recompile the program. It is NOT a
5189 means to call system functions! If you try to do so Vim will
5190 very probably crash.
5191
5192 For Win32, the functions you write must be placed in a DLL
5193 and use the normal C calling convention (NOT Pascal which is
5194 used in Windows System DLLs). The function must take exactly
5195 one parameter, either a character pointer or a long integer,
5196 and must return a character pointer or NULL. The character
5197 pointer returned must point to memory that will remain valid
5198 after the function has returned (e.g. in static data in the
5199 DLL). If it points to allocated memory, that memory will
5200 leak away. Using a static buffer in the function should work,
5201 it's then freed when the DLL is unloaded.
5202
5203 WARNING: If the function returns a non-valid pointer, Vim may
5204 crash! This also happens if the function returns a number,
5205 because Vim thinks it's a pointer.
5206 For Win32 systems, {libname} should be the filename of the DLL
5207 without the ".DLL" suffix. A full path is only required if
5208 the DLL is not in the usual places.
5209 For Unix: When compiling your own plugins, remember that the
5210 object code must be compiled as position-independent ('PIC').
5211 {only in Win32 and some Unix versions, when the |+libcall|
5212 feature is present}
5213 Examples: >
5214 :echo libcall("libc.so", "getenv", "HOME")
5215
5216< Can also be used as a |method|, the base is passed as the
5217 third argument: >
5218 GetValue()->libcall("libc.so", "getenv")
5219<
5220 *libcallnr()*
5221libcallnr({libname}, {funcname}, {argument})
5222 Just like |libcall()|, but used for a function that returns an
5223 int instead of a string.
5224 {only in Win32 on some Unix versions, when the |+libcall|
5225 feature is present}
5226 Examples: >
5227 :echo libcallnr("/usr/lib/libc.so", "getpid", "")
5228 :call libcallnr("libc.so", "printf", "Hello World!\n")
5229 :call libcallnr("libc.so", "sleep", 10)
5230<
5231 Can also be used as a |method|, the base is passed as the
5232 third argument: >
5233 GetValue()->libcallnr("libc.so", "printf")
5234<
5235
5236line({expr} [, {winid}]) *line()*
5237 The result is a Number, which is the line number of the file
5238 position given with {expr}. The {expr} argument is a string.
Bram Moolenaara2baa732022-02-04 16:09:54 +00005239 The accepted positions are: *E1209*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005240 . the cursor position
5241 $ the last line in the current buffer
5242 'x position of mark x (if the mark is not set, 0 is
5243 returned)
5244 w0 first line visible in current window (one if the
5245 display isn't updated, e.g. in silent Ex mode)
5246 w$ last line visible in current window (this is one
5247 less than "w0" if no lines are visible)
5248 v In Visual mode: the start of the Visual area (the
5249 cursor is the end). When not in Visual mode
5250 returns the cursor position. Differs from |'<| in
5251 that it's updated right away.
5252 Note that a mark in another file can be used. The line number
5253 then applies to another buffer.
5254 To get the column number use |col()|. To get both use
5255 |getpos()|.
5256 With the optional {winid} argument the values are obtained for
5257 that window instead of the current window.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01005258 Returns 0 for invalid values of {expr} and {winid}.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005259 Examples: >
5260 line(".") line number of the cursor
5261 line(".", winid) idem, in window "winid"
5262 line("'t") line number of mark t
Bram Moolenaarc51cf032022-02-26 12:25:45 +00005263 line("'" .. marker) line number of mark marker
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005264<
5265 To jump to the last known position when opening a file see
5266 |last-position-jump|.
5267
5268 Can also be used as a |method|: >
5269 GetValue()->line()
5270
5271line2byte({lnum}) *line2byte()*
5272 Return the byte count from the start of the buffer for line
5273 {lnum}. This includes the end-of-line character, depending on
5274 the 'fileformat' option for the current buffer. The first
5275 line returns 1. 'encoding' matters, 'fileencoding' is ignored.
5276 This can also be used to get the byte count for the line just
5277 below the last line: >
5278 line2byte(line("$") + 1)
5279< This is the buffer size plus one. If 'fileencoding' is empty
5280 it is the file size plus one. {lnum} is used like with
5281 |getline()|. When {lnum} is invalid, or the |+byte_offset|
5282 feature has been disabled at compile time, -1 is returned.
5283 Also see |byte2line()|, |go| and |:goto|.
5284
5285 Can also be used as a |method|: >
5286 GetLnum()->line2byte()
5287
5288lispindent({lnum}) *lispindent()*
5289 Get the amount of indent for line {lnum} according the lisp
5290 indenting rules, as with 'lisp'.
5291 The indent is counted in spaces, the value of 'tabstop' is
5292 relevant. {lnum} is used just like in |getline()|.
Bram Moolenaar8e145b82022-05-21 20:17:31 +01005293 When {lnum} is invalid -1 is returned. In |Vim9| script an
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005294 error is given.
5295
5296 Can also be used as a |method|: >
5297 GetLnum()->lispindent()
5298
5299list2blob({list}) *list2blob()*
5300 Return a Blob concatenating all the number values in {list}.
5301 Examples: >
5302 list2blob([1, 2, 3, 4]) returns 0z01020304
5303 list2blob([]) returns 0z
5304< Returns an empty Blob on error. If one of the numbers is
5305 negative or more than 255 error *E1239* is given.
5306
5307 |blob2list()| does the opposite.
5308
5309 Can also be used as a |method|: >
5310 GetList()->list2blob()
5311
5312list2str({list} [, {utf8}]) *list2str()*
5313 Convert each number in {list} to a character string can
5314 concatenate them all. Examples: >
5315 list2str([32]) returns " "
5316 list2str([65, 66, 67]) returns "ABC"
5317< The same can be done (slowly) with: >
5318 join(map(list, {nr, val -> nr2char(val)}), '')
5319< |str2list()| does the opposite.
5320
5321 When {utf8} is omitted or zero, the current 'encoding' is used.
5322 When {utf8} is TRUE, always return UTF-8 characters.
5323 With UTF-8 composing characters work as expected: >
5324 list2str([97, 769]) returns "á"
5325<
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01005326 Returns an empty string on error.
5327
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005328 Can also be used as a |method|: >
5329 GetList()->list2str()
5330
5331listener_add({callback} [, {buf}]) *listener_add()*
5332 Add a callback function that will be invoked when changes have
5333 been made to buffer {buf}.
5334 {buf} refers to a buffer name or number. For the accepted
5335 values, see |bufname()|. When {buf} is omitted the current
5336 buffer is used.
5337 Returns a unique ID that can be passed to |listener_remove()|.
5338
5339 The {callback} is invoked with five arguments:
Bram Moolenaar944697a2022-02-20 19:48:20 +00005340 bufnr the buffer that was changed
5341 start first changed line number
5342 end first line number below the change
5343 added number of lines added, negative if lines were
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005344 deleted
Bram Moolenaar944697a2022-02-20 19:48:20 +00005345 changes a List of items with details about the changes
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005346
5347 Example: >
5348 func Listener(bufnr, start, end, added, changes)
5349 echo 'lines ' .. a:start .. ' until ' .. a:end .. ' changed'
5350 endfunc
5351 call listener_add('Listener', bufnr)
5352
Bram Moolenaar944697a2022-02-20 19:48:20 +00005353< The List cannot be changed. Each item in "changes" is a
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005354 dictionary with these entries:
5355 lnum the first line number of the change
5356 end the first line below the change
5357 added number of lines added; negative if lines were
5358 deleted
5359 col first column in "lnum" that was affected by
5360 the change; one if unknown or the whole line
5361 was affected; this is a byte index, first
5362 character has a value of one.
5363 When lines are inserted the values are:
5364 lnum line above which the new line is added
5365 end equal to "lnum"
5366 added number of lines inserted
5367 col 1
5368 When lines are deleted the values are:
5369 lnum the first deleted line
5370 end the line below the first deleted line, before
5371 the deletion was done
5372 added negative, number of lines deleted
5373 col 1
5374 When lines are changed:
5375 lnum the first changed line
5376 end the line below the last changed line
5377 added 0
5378 col first column with a change or 1
5379
5380 The entries are in the order the changes were made, thus the
5381 most recent change is at the end. The line numbers are valid
5382 when the callback is invoked, but later changes may make them
5383 invalid, thus keeping a copy for later might not work.
5384
5385 The {callback} is invoked just before the screen is updated,
5386 when |listener_flush()| is called or when a change is being
5387 made that changes the line count in a way it causes a line
5388 number in the list of changes to become invalid.
5389
5390 The {callback} is invoked with the text locked, see
5391 |textlock|. If you do need to make changes to the buffer, use
5392 a timer to do this later |timer_start()|.
5393
5394 The {callback} is not invoked when the buffer is first loaded.
5395 Use the |BufReadPost| autocmd event to handle the initial text
5396 of a buffer.
5397 The {callback} is also not invoked when the buffer is
5398 unloaded, use the |BufUnload| autocmd event for that.
5399
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01005400 Returns zero if {callback} or {buf} is invalid.
5401
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005402 Can also be used as a |method|, the base is passed as the
5403 second argument: >
5404 GetBuffer()->listener_add(callback)
5405
5406listener_flush([{buf}]) *listener_flush()*
5407 Invoke listener callbacks for buffer {buf}. If there are no
5408 pending changes then no callbacks are invoked.
5409
5410 {buf} refers to a buffer name or number. For the accepted
5411 values, see |bufname()|. When {buf} is omitted the current
5412 buffer is used.
5413
5414 Can also be used as a |method|: >
5415 GetBuffer()->listener_flush()
5416
5417listener_remove({id}) *listener_remove()*
5418 Remove a listener previously added with listener_add().
5419 Returns FALSE when {id} could not be found, TRUE when {id} was
5420 removed.
5421
5422 Can also be used as a |method|: >
5423 GetListenerId()->listener_remove()
5424
5425localtime() *localtime()*
5426 Return the current time, measured as seconds since 1st Jan
5427 1970. See also |strftime()|, |strptime()| and |getftime()|.
5428
5429
5430log({expr}) *log()*
5431 Return the natural logarithm (base e) of {expr} as a |Float|.
5432 {expr} must evaluate to a |Float| or a |Number| in the range
5433 (0, inf].
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01005434 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005435 Examples: >
5436 :echo log(10)
5437< 2.302585 >
5438 :echo log(exp(5))
5439< 5.0
5440
5441 Can also be used as a |method|: >
5442 Compute()->log()
5443<
5444 {only available when compiled with the |+float| feature}
5445
5446
5447log10({expr}) *log10()*
5448 Return the logarithm of Float {expr} to base 10 as a |Float|.
5449 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01005450 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005451 Examples: >
5452 :echo log10(1000)
5453< 3.0 >
5454 :echo log10(0.01)
5455< -2.0
5456
5457 Can also be used as a |method|: >
5458 Compute()->log10()
5459<
5460 {only available when compiled with the |+float| feature}
5461
5462luaeval({expr} [, {expr}]) *luaeval()*
5463 Evaluate Lua expression {expr} and return its result converted
5464 to Vim data structures. Second {expr} may hold additional
5465 argument accessible as _A inside first {expr}.
5466 Strings are returned as they are.
5467 Boolean objects are converted to numbers.
5468 Numbers are converted to |Float| values if vim was compiled
5469 with |+float| and to numbers otherwise.
5470 Dictionaries and lists obtained by vim.eval() are returned
5471 as-is.
5472 Other objects are returned as zero without any errors.
5473 See |lua-luaeval| for more details.
5474 Note that in a `:def` function local variables are not visible
5475 to {expr}.
5476
5477 Can also be used as a |method|: >
5478 GetExpr()->luaeval()
5479
5480< {only available when compiled with the |+lua| feature}
5481
5482map({expr1}, {expr2}) *map()*
5483 {expr1} must be a |List|, |String|, |Blob| or |Dictionary|.
Bram Moolenaar944697a2022-02-20 19:48:20 +00005484 When {expr1} is a |List| or |Dictionary|, replace each
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005485 item in {expr1} with the result of evaluating {expr2}.
5486 For a |Blob| each byte is replaced.
5487 For a |String|, each character, including composing
5488 characters, is replaced.
5489 If the item type changes you may want to use |mapnew()| to
5490 create a new List or Dictionary. This is required when using
5491 Vim9 script.
5492
5493 {expr2} must be a |String| or |Funcref|.
5494
5495 If {expr2} is a |String|, inside {expr2} |v:val| has the value
5496 of the current item. For a |Dictionary| |v:key| has the key
5497 of the current item and for a |List| |v:key| has the index of
5498 the current item. For a |Blob| |v:key| has the index of the
5499 current byte. For a |String| |v:key| has the index of the
5500 current character.
5501 Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00005502 :call map(mylist, '"> " .. v:val .. " <"')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005503< This puts "> " before and " <" after each item in "mylist".
5504
5505 Note that {expr2} is the result of an expression and is then
5506 used as an expression again. Often it is good to use a
5507 |literal-string| to avoid having to double backslashes. You
5508 still have to double ' quotes
5509
5510 If {expr2} is a |Funcref| it is called with two arguments:
5511 1. The key or the index of the current item.
5512 2. the value of the current item.
5513 The function must return the new value of the item. Example
5514 that changes each value by "key-value": >
5515 func KeyValue(key, val)
Bram Moolenaarc51cf032022-02-26 12:25:45 +00005516 return a:key .. '-' .. a:val
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005517 endfunc
5518 call map(myDict, function('KeyValue'))
5519< It is shorter when using a |lambda|: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00005520 call map(myDict, {key, val -> key .. '-' .. val})
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005521< If you do not use "val" you can leave it out: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00005522 call map(myDict, {key -> 'item: ' .. key})
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005523< If you do not use "key" you can use a short name: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00005524 call map(myDict, {_, val -> 'item: ' .. val})
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005525<
5526 The operation is done in-place for a |List| and |Dictionary|.
5527 If you want it to remain unmodified make a copy first: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00005528 :let tlist = map(copy(mylist), ' v:val .. "\t"')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005529
5530< Returns {expr1}, the |List| or |Dictionary| that was filtered,
5531 or a new |Blob| or |String|.
5532 When an error is encountered while evaluating {expr2} no
5533 further items in {expr1} are processed.
5534 When {expr2} is a Funcref errors inside a function are ignored,
5535 unless it was defined with the "abort" flag.
5536
5537 Can also be used as a |method|: >
5538 mylist->map(expr2)
5539
5540
5541maparg({name} [, {mode} [, {abbr} [, {dict}]]]) *maparg()*
5542 When {dict} is omitted or zero: Return the rhs of mapping
5543 {name} in mode {mode}. The returned String has special
5544 characters translated like in the output of the ":map" command
Ernie Rael09661202022-04-25 14:40:44 +01005545 listing. When {dict} is TRUE a dictionary is returned, see
5546 below. To get a list of all mappings see |maplist()|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005547
5548 When there is no mapping for {name}, an empty String is
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01005549 returned if {dict} is FALSE, otherwise returns an empty Dict.
5550 When the mapping for {name} is empty, then "<Nop>" is
5551 returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005552
5553 The {name} can have special key names, like in the ":map"
5554 command.
5555
5556 {mode} can be one of these strings:
5557 "n" Normal
5558 "v" Visual (including Select)
5559 "o" Operator-pending
5560 "i" Insert
5561 "c" Cmd-line
5562 "s" Select
5563 "x" Visual
5564 "l" langmap |language-mapping|
5565 "t" Terminal-Job
5566 "" Normal, Visual and Operator-pending
5567 When {mode} is omitted, the modes for "" are used.
5568
5569 When {abbr} is there and it is |TRUE| use abbreviations
5570 instead of mappings.
5571
5572 When {dict} is there and it is |TRUE| return a dictionary
5573 containing all the information of the mapping with the
Ernie Rael659c2402022-04-24 18:40:28 +01005574 following items: *mapping-dict*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005575 "lhs" The {lhs} of the mapping as it would be typed
5576 "lhsraw" The {lhs} of the mapping as raw bytes
5577 "lhsrawalt" The {lhs} of the mapping as raw bytes, alternate
5578 form, only present when it differs from "lhsraw"
5579 "rhs" The {rhs} of the mapping as typed.
5580 "silent" 1 for a |:map-silent| mapping, else 0.
5581 "noremap" 1 if the {rhs} of the mapping is not remappable.
5582 "script" 1 if mapping was defined with <script>.
5583 "expr" 1 for an expression mapping (|:map-<expr>|).
5584 "buffer" 1 for a buffer local mapping (|:map-local|).
5585 "mode" Modes for which the mapping is defined. In
5586 addition to the modes mentioned above, these
5587 characters will be used:
5588 " " Normal, Visual and Operator-pending
5589 "!" Insert and Commandline mode
5590 (|mapmode-ic|)
5591 "sid" The script local ID, used for <sid> mappings
5592 (|<SID>|).
Bram Moolenaara9528b32022-01-18 20:51:35 +00005593 "scriptversion" The version of the script. 999999 for
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01005594 |Vim9| script.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005595 "lnum" The line number in "sid", zero if unknown.
5596 "nowait" Do not wait for other, longer mappings.
5597 (|:map-<nowait>|).
Bram Moolenaar921bde82022-05-09 19:50:35 +01005598 "abbr" True if this is an abbreviation |abbreviations|.
Ernie Raeld8f5f762022-05-10 17:50:39 +01005599 "mode_bits" Vim's internal binary representation of "mode".
5600 |mapset()| ignores this; only "mode" is used.
5601 See |maplist()| for usage examples. The values
5602 are from src/vim.h and may change in the future.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005603
5604 The dictionary can be used to restore a mapping with
5605 |mapset()|.
5606
5607 The mappings local to the current buffer are checked first,
5608 then the global mappings.
5609 This function can be used to map a key even when it's already
5610 mapped, and have it do the original mapping too. Sketch: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00005611 exe 'nnoremap <Tab> ==' .. maparg('<Tab>', 'n')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005612
5613< Can also be used as a |method|: >
5614 GetKey()->maparg('n')
5615
5616mapcheck({name} [, {mode} [, {abbr}]]) *mapcheck()*
5617 Check if there is a mapping that matches with {name} in mode
5618 {mode}. See |maparg()| for {mode} and special names in
5619 {name}.
5620 When {abbr} is there and it is |TRUE| use abbreviations
5621 instead of mappings.
5622 A match happens with a mapping that starts with {name} and
5623 with a mapping which is equal to the start of {name}.
5624
5625 matches mapping "a" "ab" "abc" ~
5626 mapcheck("a") yes yes yes
5627 mapcheck("abc") yes yes yes
5628 mapcheck("ax") yes no no
5629 mapcheck("b") no no no
5630
5631 The difference with maparg() is that mapcheck() finds a
5632 mapping that matches with {name}, while maparg() only finds a
5633 mapping for {name} exactly.
5634 When there is no mapping that starts with {name}, an empty
5635 String is returned. If there is one, the RHS of that mapping
5636 is returned. If there are several mappings that start with
5637 {name}, the RHS of one of them is returned. This will be
5638 "<Nop>" if the RHS is empty.
5639 The mappings local to the current buffer are checked first,
5640 then the global mappings.
5641 This function can be used to check if a mapping can be added
5642 without being ambiguous. Example: >
5643 :if mapcheck("_vv") == ""
5644 : map _vv :set guifont=7x13<CR>
5645 :endif
5646< This avoids adding the "_vv" mapping when there already is a
5647 mapping for "_v" or for "_vvv".
5648
5649 Can also be used as a |method|: >
5650 GetKey()->mapcheck('n')
5651
5652
Ernie Rael09661202022-04-25 14:40:44 +01005653maplist([{abbr}]) *maplist()*
5654 Returns a |List| of all mappings. Each List item is a |Dict|,
5655 the same as what is returned by |maparg()|, see
5656 |mapping-dict|. When {abbr} is there and it is |TRUE| use
5657 abbreviations instead of mappings.
5658
5659 Example to show all mappings with 'MultiMatch' in rhs: >
5660 vim9script
5661 echo maplist()->filter(
5662 (_, m) => match(m.rhs, 'MultiMatch') >= 0)
Ernie Raeld8f5f762022-05-10 17:50:39 +01005663< It can be tricky to find mappings for particular |:map-modes|.
5664 |mapping-dict|'s "mode_bits" can simplify this. For example,
5665 the mode_bits for Normal, Insert or Command-line modes are
5666 0x19. To find all the mappings available in those modes you
5667 can do: >
5668 vim9script
5669 var saved_maps = []
5670 for m in maplist()
5671 if and(m.mode_bits, 0x19) != 0
5672 saved_maps->add(m)
5673 endif
5674 endfor
5675 echo saved_maps->mapnew((_, m) => m.lhs)
5676< The values of the mode_bits are defined in Vim's src/vim.h
5677 file and they can be discovered at runtime using
5678 |:map-commands| and "maplist()". Example: >
5679 vim9script
5680 omap xyzzy <Nop>
5681 var op_bit = maplist()->filter(
5682 (_, m) => m.lhs == 'xyzzy')[0].mode_bits
5683 ounmap xyzzy
5684 echo printf("Operator-pending mode bit: 0x%x", op_bit)
Ernie Rael09661202022-04-25 14:40:44 +01005685
5686
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005687mapnew({expr1}, {expr2}) *mapnew()*
5688 Like |map()| but instead of replacing items in {expr1} a new
5689 List or Dictionary is created and returned. {expr1} remains
5690 unchanged. Items can still be changed by {expr2}, if you
5691 don't want that use |deepcopy()| first.
5692
5693
5694mapset({mode}, {abbr}, {dict}) *mapset()*
Ernie Rael51d04d12022-05-04 15:40:22 +01005695mapset({dict})
5696 Restore a mapping from a dictionary, possibly returned by
5697 |maparg()| or |maplist()|. A buffer mapping, when dict.buffer
5698 is true, is set on the current buffer; it is up to the caller
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01005699 to ensure that the intended buffer is the current buffer. This
Ernie Rael51d04d12022-05-04 15:40:22 +01005700 feature allows copying mappings from one buffer to another.
5701 The dict.mode value may restore a single mapping that covers
5702 more than one mode, like with mode values of '!', ' ', 'nox',
5703 or 'v'. *E1276*
5704
5705 In the first form, {mode} and {abbr} should be the same as
5706 for the call to |maparg()|. *E460*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005707 {mode} is used to define the mode in which the mapping is set,
5708 not the "mode" entry in {dict}.
5709 Example for saving and restoring a mapping: >
5710 let save_map = maparg('K', 'n', 0, 1)
5711 nnoremap K somethingelse
5712 ...
5713 call mapset('n', 0, save_map)
5714< Note that if you are going to replace a map in several modes,
Ernie Rael51d04d12022-05-04 15:40:22 +01005715 e.g. with `:map!`, you need to save/restore the mapping for
5716 all of them, when they might differ.
5717
5718 In the second form, with {dict} as the only argument, mode
5719 and abbr are taken from the dict.
5720 Example: >
5721 vim9script
5722 var save_maps = maplist()->filter(
5723 (_, m) => m.lhs == 'K')
5724 nnoremap K somethingelse
5725 cnoremap K somethingelse2
5726 # ...
5727 unmap K
5728 for d in save_maps
5729 mapset(d)
5730 endfor
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005731
5732
5733match({expr}, {pat} [, {start} [, {count}]]) *match()*
5734 When {expr} is a |List| then this returns the index of the
5735 first item where {pat} matches. Each item is used as a
5736 String, |Lists| and |Dictionaries| are used as echoed.
5737
5738 Otherwise, {expr} is used as a String. The result is a
5739 Number, which gives the index (byte offset) in {expr} where
5740 {pat} matches.
5741
5742 A match at the first character or |List| item returns zero.
5743 If there is no match -1 is returned.
5744
5745 For getting submatches see |matchlist()|.
5746 Example: >
5747 :echo match("testing", "ing") " results in 4
5748 :echo match([1, 'x'], '\a') " results in 1
5749< See |string-match| for how {pat} is used.
5750 *strpbrk()*
5751 Vim doesn't have a strpbrk() function. But you can do: >
5752 :let sepidx = match(line, '[.,;: \t]')
5753< *strcasestr()*
5754 Vim doesn't have a strcasestr() function. But you can add
5755 "\c" to the pattern to ignore case: >
5756 :let idx = match(haystack, '\cneedle')
5757<
5758 If {start} is given, the search starts from byte index
5759 {start} in a String or item {start} in a |List|.
5760 The result, however, is still the index counted from the
5761 first character/item. Example: >
5762 :echo match("testing", "ing", 2)
5763< result is again "4". >
5764 :echo match("testing", "ing", 4)
5765< result is again "4". >
5766 :echo match("testing", "t", 2)
5767< result is "3".
5768 For a String, if {start} > 0 then it is like the string starts
5769 {start} bytes later, thus "^" will match at {start}. Except
5770 when {count} is given, then it's like matches before the
5771 {start} byte are ignored (this is a bit complicated to keep it
5772 backwards compatible).
5773 For a String, if {start} < 0, it will be set to 0. For a list
5774 the index is counted from the end.
5775 If {start} is out of range ({start} > strlen({expr}) for a
5776 String or {start} > len({expr}) for a |List|) -1 is returned.
5777
5778 When {count} is given use the {count}'th match. When a match
5779 is found in a String the search for the next one starts one
5780 character further. Thus this example results in 1: >
5781 echo match("testing", "..", 0, 2)
5782< In a |List| the search continues in the next item.
5783 Note that when {count} is added the way {start} works changes,
5784 see above.
5785
5786 See |pattern| for the patterns that are accepted.
5787 The 'ignorecase' option is used to set the ignore-caseness of
5788 the pattern. 'smartcase' is NOT used. The matching is always
5789 done like 'magic' is set and 'cpoptions' is empty.
5790 Note that a match at the start is preferred, thus when the
5791 pattern is using "*" (any number of matches) it tends to find
5792 zero matches at the start instead of a number of matches
5793 further down in the text.
5794
5795 Can also be used as a |method|: >
5796 GetText()->match('word')
5797 GetList()->match('word')
5798<
Bram Moolenaar2f0936c2022-01-08 21:51:59 +00005799 *matchadd()* *E290* *E798* *E799* *E801* *E957*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005800matchadd({group}, {pattern} [, {priority} [, {id} [, {dict}]]])
5801 Defines a pattern to be highlighted in the current window (a
5802 "match"). It will be highlighted with {group}. Returns an
5803 identification number (ID), which can be used to delete the
5804 match using |matchdelete()|. The ID is bound to the window.
5805 Matching is case sensitive and magic, unless case sensitivity
5806 or magicness are explicitly overridden in {pattern}. The
5807 'magic', 'smartcase' and 'ignorecase' options are not used.
5808 The "Conceal" value is special, it causes the match to be
5809 concealed.
5810
5811 The optional {priority} argument assigns a priority to the
5812 match. A match with a high priority will have its
5813 highlighting overrule that of a match with a lower priority.
5814 A priority is specified as an integer (negative numbers are no
5815 exception). If the {priority} argument is not specified, the
5816 default priority is 10. The priority of 'hlsearch' is zero,
5817 hence all matches with a priority greater than zero will
5818 overrule it. Syntax highlighting (see 'syntax') is a separate
5819 mechanism, and regardless of the chosen priority a match will
5820 always overrule syntax highlighting.
5821
5822 The optional {id} argument allows the request for a specific
5823 match ID. If a specified ID is already taken, an error
5824 message will appear and the match will not be added. An ID
5825 is specified as a positive integer (zero excluded). IDs 1, 2
5826 and 3 are reserved for |:match|, |:2match| and |:3match|,
Bram Moolenaar2ecbe532022-07-29 21:36:21 +01005827 respectively. 3 is reserved for use by the |matchparen|
5828 plugin.
Bram Moolenaarb529cfb2022-07-25 15:42:07 +01005829 If the {id} argument is not specified or -1, |matchadd()|
5830 automatically chooses a free ID.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005831
5832 The optional {dict} argument allows for further custom
5833 values. Currently this is used to specify a match specific
5834 conceal character that will be shown for |hl-Conceal|
5835 highlighted matches. The dict can have the following members:
5836
5837 conceal Special character to show instead of the
5838 match (only for |hl-Conceal| highlighted
5839 matches, see |:syn-cchar|)
5840 window Instead of the current window use the
5841 window with this number or window ID.
5842
5843 The number of matches is not limited, as it is the case with
5844 the |:match| commands.
5845
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01005846 Returns -1 on error.
5847
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005848 Example: >
5849 :highlight MyGroup ctermbg=green guibg=green
5850 :let m = matchadd("MyGroup", "TODO")
5851< Deletion of the pattern: >
5852 :call matchdelete(m)
5853
5854< A list of matches defined by |matchadd()| and |:match| are
5855 available from |getmatches()|. All matches can be deleted in
5856 one operation by |clearmatches()|.
5857
5858 Can also be used as a |method|: >
5859 GetGroup()->matchadd('TODO')
5860<
5861 *matchaddpos()*
5862matchaddpos({group}, {pos} [, {priority} [, {id} [, {dict}]]])
5863 Same as |matchadd()|, but requires a list of positions {pos}
5864 instead of a pattern. This command is faster than |matchadd()|
5865 because it does not require to handle regular expressions and
5866 sets buffer line boundaries to redraw screen. It is supposed
5867 to be used when fast match additions and deletions are
5868 required, for example to highlight matching parentheses.
5869
5870 {pos} is a list of positions. Each position can be one of
5871 these:
5872 - A number. This whole line will be highlighted. The first
5873 line has number 1.
5874 - A list with one number, e.g., [23]. The whole line with this
5875 number will be highlighted.
5876 - A list with two numbers, e.g., [23, 11]. The first number is
5877 the line number, the second one is the column number (first
5878 column is 1, the value must correspond to the byte index as
5879 |col()| would return). The character at this position will
5880 be highlighted.
5881 - A list with three numbers, e.g., [23, 11, 3]. As above, but
5882 the third number gives the length of the highlight in bytes.
5883
5884 The maximum number of positions in {pos} is 8.
5885
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01005886 Returns -1 on error.
5887
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005888 Example: >
5889 :highlight MyGroup ctermbg=green guibg=green
5890 :let m = matchaddpos("MyGroup", [[23, 24], 34])
5891< Deletion of the pattern: >
5892 :call matchdelete(m)
5893
5894< Matches added by |matchaddpos()| are returned by
5895 |getmatches()|.
5896
5897 Can also be used as a |method|: >
5898 GetGroup()->matchaddpos([23, 11])
5899
5900matcharg({nr}) *matcharg()*
5901 Selects the {nr} match item, as set with a |:match|,
5902 |:2match| or |:3match| command.
5903 Return a |List| with two elements:
5904 The name of the highlight group used
5905 The pattern used.
5906 When {nr} is not 1, 2 or 3 returns an empty |List|.
5907 When there is no match item set returns ['', ''].
5908 This is useful to save and restore a |:match|.
5909 Highlighting matches using the |:match| commands are limited
5910 to three matches. |matchadd()| does not have this limitation.
5911
5912 Can also be used as a |method|: >
5913 GetMatch()->matcharg()
5914
5915matchdelete({id} [, {win}) *matchdelete()* *E802* *E803*
5916 Deletes a match with ID {id} previously defined by |matchadd()|
5917 or one of the |:match| commands. Returns 0 if successful,
5918 otherwise -1. See example for |matchadd()|. All matches can
5919 be deleted in one operation by |clearmatches()|.
5920 If {win} is specified, use the window with this number or
5921 window ID instead of the current window.
5922
5923 Can also be used as a |method|: >
5924 GetMatch()->matchdelete()
5925
5926matchend({expr}, {pat} [, {start} [, {count}]]) *matchend()*
5927 Same as |match()|, but return the index of first character
5928 after the match. Example: >
5929 :echo matchend("testing", "ing")
5930< results in "7".
5931 *strspn()* *strcspn()*
5932 Vim doesn't have a strspn() or strcspn() function, but you can
5933 do it with matchend(): >
5934 :let span = matchend(line, '[a-zA-Z]')
5935 :let span = matchend(line, '[^a-zA-Z]')
5936< Except that -1 is returned when there are no matches.
5937
5938 The {start}, if given, has the same meaning as for |match()|. >
5939 :echo matchend("testing", "ing", 2)
5940< results in "7". >
5941 :echo matchend("testing", "ing", 5)
5942< result is "-1".
5943 When {expr} is a |List| the result is equal to |match()|.
5944
5945 Can also be used as a |method|: >
5946 GetText()->matchend('word')
5947
5948
5949matchfuzzy({list}, {str} [, {dict}]) *matchfuzzy()*
5950 If {list} is a list of strings, then returns a |List| with all
5951 the strings in {list} that fuzzy match {str}. The strings in
5952 the returned list are sorted based on the matching score.
5953
5954 The optional {dict} argument always supports the following
5955 items:
zeertzjq9af2bc02022-05-11 14:15:37 +01005956 matchseq When this item is present return only matches
5957 that contain the characters in {str} in the
5958 given sequence.
Kazuyuki Miyagi47f1a552022-06-17 18:30:03 +01005959 limit Maximum number of matches in {list} to be
5960 returned. Zero means no limit.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005961
5962 If {list} is a list of dictionaries, then the optional {dict}
5963 argument supports the following additional items:
Yasuhiro Matsumoto9029a6e2022-04-16 12:35:35 +01005964 key Key of the item which is fuzzy matched against
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005965 {str}. The value of this item should be a
5966 string.
5967 text_cb |Funcref| that will be called for every item
5968 in {list} to get the text for fuzzy matching.
5969 This should accept a dictionary item as the
5970 argument and return the text for that item to
5971 use for fuzzy matching.
5972
5973 {str} is treated as a literal string and regular expression
5974 matching is NOT supported. The maximum supported {str} length
5975 is 256.
5976
5977 When {str} has multiple words each separated by white space,
5978 then the list of strings that have all the words is returned.
5979
5980 If there are no matching strings or there is an error, then an
5981 empty list is returned. If length of {str} is greater than
5982 256, then returns an empty list.
5983
Yasuhiro Matsumoto9029a6e2022-04-16 12:35:35 +01005984 When {limit} is given, matchfuzzy() will find up to this
5985 number of matches in {list} and return them in sorted order.
5986
Bram Moolenaar1588bc82022-03-08 21:35:07 +00005987 Refer to |fuzzy-matching| for more information about fuzzy
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005988 matching strings.
5989
5990 Example: >
5991 :echo matchfuzzy(["clay", "crow"], "cay")
5992< results in ["clay"]. >
5993 :echo getbufinfo()->map({_, v -> v.name})->matchfuzzy("ndl")
5994< results in a list of buffer names fuzzy matching "ndl". >
5995 :echo getbufinfo()->matchfuzzy("ndl", {'key' : 'name'})
5996< results in a list of buffer information dicts with buffer
5997 names fuzzy matching "ndl". >
5998 :echo getbufinfo()->matchfuzzy("spl",
5999 \ {'text_cb' : {v -> v.name}})
6000< results in a list of buffer information dicts with buffer
6001 names fuzzy matching "spl". >
6002 :echo v:oldfiles->matchfuzzy("test")
6003< results in a list of file names fuzzy matching "test". >
6004 :let l = readfile("buffer.c")->matchfuzzy("str")
6005< results in a list of lines in "buffer.c" fuzzy matching "str". >
6006 :echo ['one two', 'two one']->matchfuzzy('two one')
6007< results in ['two one', 'one two']. >
6008 :echo ['one two', 'two one']->matchfuzzy('two one',
6009 \ {'matchseq': 1})
6010< results in ['two one'].
6011
6012matchfuzzypos({list}, {str} [, {dict}]) *matchfuzzypos()*
6013 Same as |matchfuzzy()|, but returns the list of matched
6014 strings, the list of character positions where characters
6015 in {str} matches and a list of matching scores. You can
6016 use |byteidx()| to convert a character position to a byte
6017 position.
6018
6019 If {str} matches multiple times in a string, then only the
6020 positions for the best match is returned.
6021
6022 If there are no matching strings or there is an error, then a
6023 list with three empty list items is returned.
6024
6025 Example: >
6026 :echo matchfuzzypos(['testing'], 'tsg')
6027< results in [['testing'], [[0, 2, 6]], [99]] >
6028 :echo matchfuzzypos(['clay', 'lacy'], 'la')
6029< results in [['lacy', 'clay'], [[0, 1], [1, 2]], [153, 133]] >
6030 :echo [{'text': 'hello', 'id' : 10}]->matchfuzzypos('ll', {'key' : 'text'})
6031< results in [[{'id': 10, 'text': 'hello'}], [[2, 3]], [127]]
6032
6033matchlist({expr}, {pat} [, {start} [, {count}]]) *matchlist()*
6034 Same as |match()|, but return a |List|. The first item in the
6035 list is the matched string, same as what matchstr() would
6036 return. Following items are submatches, like "\1", "\2", etc.
6037 in |:substitute|. When an optional submatch didn't match an
6038 empty string is used. Example: >
6039 echo matchlist('acd', '\(a\)\?\(b\)\?\(c\)\?\(.*\)')
6040< Results in: ['acd', 'a', '', 'c', 'd', '', '', '', '', '']
6041 When there is no match an empty list is returned.
6042
6043 You can pass in a List, but that is not very useful.
6044
6045 Can also be used as a |method|: >
6046 GetText()->matchlist('word')
6047
6048matchstr({expr}, {pat} [, {start} [, {count}]]) *matchstr()*
6049 Same as |match()|, but return the matched string. Example: >
6050 :echo matchstr("testing", "ing")
6051< results in "ing".
6052 When there is no match "" is returned.
6053 The {start}, if given, has the same meaning as for |match()|. >
6054 :echo matchstr("testing", "ing", 2)
6055< results in "ing". >
6056 :echo matchstr("testing", "ing", 5)
6057< result is "".
6058 When {expr} is a |List| then the matching item is returned.
6059 The type isn't changed, it's not necessarily a String.
6060
6061 Can also be used as a |method|: >
6062 GetText()->matchstr('word')
6063
6064matchstrpos({expr}, {pat} [, {start} [, {count}]]) *matchstrpos()*
6065 Same as |matchstr()|, but return the matched string, the start
6066 position and the end position of the match. Example: >
6067 :echo matchstrpos("testing", "ing")
6068< results in ["ing", 4, 7].
6069 When there is no match ["", -1, -1] is returned.
6070 The {start}, if given, has the same meaning as for |match()|. >
6071 :echo matchstrpos("testing", "ing", 2)
6072< results in ["ing", 4, 7]. >
6073 :echo matchstrpos("testing", "ing", 5)
6074< result is ["", -1, -1].
6075 When {expr} is a |List| then the matching item, the index
6076 of first item where {pat} matches, the start position and the
6077 end position of the match are returned. >
6078 :echo matchstrpos([1, '__x'], '\a')
6079< result is ["x", 1, 2, 3].
6080 The type isn't changed, it's not necessarily a String.
6081
6082 Can also be used as a |method|: >
6083 GetText()->matchstrpos('word')
6084<
6085
6086 *max()*
6087max({expr}) Return the maximum value of all items in {expr}. Example: >
6088 echo max([apples, pears, oranges])
6089
6090< {expr} can be a |List| or a |Dictionary|. For a Dictionary,
6091 it returns the maximum of all values in the Dictionary.
6092 If {expr} is neither a List nor a Dictionary, or one of the
6093 items in {expr} cannot be used as a Number this results in
6094 an error. An empty |List| or |Dictionary| results in zero.
6095
6096 Can also be used as a |method|: >
6097 mylist->max()
6098
6099
6100menu_info({name} [, {mode}]) *menu_info()*
6101 Return information about the specified menu {name} in
6102 mode {mode}. The menu name should be specified without the
6103 shortcut character ('&'). If {name} is "", then the top-level
6104 menu names are returned.
6105
6106 {mode} can be one of these strings:
6107 "n" Normal
6108 "v" Visual (including Select)
6109 "o" Operator-pending
6110 "i" Insert
6111 "c" Cmd-line
6112 "s" Select
6113 "x" Visual
6114 "t" Terminal-Job
6115 "" Normal, Visual and Operator-pending
6116 "!" Insert and Cmd-line
6117 When {mode} is omitted, the modes for "" are used.
6118
6119 Returns a |Dictionary| containing the following items:
6120 accel menu item accelerator text |menu-text|
6121 display display name (name without '&')
6122 enabled v:true if this menu item is enabled
6123 Refer to |:menu-enable|
6124 icon name of the icon file (for toolbar)
6125 |toolbar-icon|
6126 iconidx index of a built-in icon
6127 modes modes for which the menu is defined. In
6128 addition to the modes mentioned above, these
6129 characters will be used:
6130 " " Normal, Visual and Operator-pending
6131 name menu item name.
6132 noremenu v:true if the {rhs} of the menu item is not
6133 remappable else v:false.
6134 priority menu order priority |menu-priority|
6135 rhs right-hand-side of the menu item. The returned
6136 string has special characters translated like
6137 in the output of the ":menu" command listing.
6138 When the {rhs} of a menu item is empty, then
6139 "<Nop>" is returned.
6140 script v:true if script-local remapping of {rhs} is
6141 allowed else v:false. See |:menu-script|.
6142 shortcut shortcut key (character after '&' in
6143 the menu name) |menu-shortcut|
6144 silent v:true if the menu item is created
6145 with <silent> argument |:menu-silent|
6146 submenus |List| containing the names of
6147 all the submenus. Present only if the menu
6148 item has submenus.
6149
6150 Returns an empty dictionary if the menu item is not found.
6151
6152 Examples: >
6153 :echo menu_info('Edit.Cut')
6154 :echo menu_info('File.Save', 'n')
6155
6156 " Display the entire menu hierarchy in a buffer
6157 func ShowMenu(name, pfx)
6158 let m = menu_info(a:name)
6159 call append(line('$'), a:pfx .. m.display)
6160 for child in m->get('submenus', [])
6161 call ShowMenu(a:name .. '.' .. escape(child, '.'),
6162 \ a:pfx .. ' ')
6163 endfor
6164 endfunc
6165 new
6166 for topmenu in menu_info('').submenus
6167 call ShowMenu(topmenu, '')
6168 endfor
6169<
6170 Can also be used as a |method|: >
6171 GetMenuName()->menu_info('v')
6172
6173
6174< *min()*
6175min({expr}) Return the minimum value of all items in {expr}. Example: >
6176 echo min([apples, pears, oranges])
6177
6178< {expr} can be a |List| or a |Dictionary|. For a Dictionary,
6179 it returns the minimum of all values in the Dictionary.
6180 If {expr} is neither a List nor a Dictionary, or one of the
6181 items in {expr} cannot be used as a Number this results in
6182 an error. An empty |List| or |Dictionary| results in zero.
6183
6184 Can also be used as a |method|: >
6185 mylist->min()
6186
6187< *mkdir()* *E739*
6188mkdir({name} [, {path} [, {prot}]])
6189 Create directory {name}.
6190
6191 If {path} is "p" then intermediate directories are created as
6192 necessary. Otherwise it must be "".
6193
6194 If {prot} is given it is used to set the protection bits of
6195 the new directory. The default is 0o755 (rwxr-xr-x: r/w for
6196 the user, readable for others). Use 0o700 to make it
6197 unreadable for others. This is only used for the last part of
6198 {name}. Thus if you create /tmp/foo/bar then /tmp/foo will be
6199 created with 0o755.
6200 Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00006201 :call mkdir($HOME .. "/tmp/foo/bar", "p", 0o700)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006202
6203< This function is not available in the |sandbox|.
6204
6205 There is no error if the directory already exists and the "p"
6206 flag is passed (since patch 8.0.1708). However, without the
6207 "p" option the call will fail.
6208
6209 The function result is a Number, which is TRUE if the call was
6210 successful or FALSE if the directory creation failed or partly
6211 failed.
6212
6213 Not available on all systems. To check use: >
6214 :if exists("*mkdir")
6215
6216< Can also be used as a |method|: >
6217 GetName()->mkdir()
6218<
6219 *mode()*
6220mode([expr]) Return a string that indicates the current mode.
6221 If [expr] is supplied and it evaluates to a non-zero Number or
6222 a non-empty String (|non-zero-arg|), then the full mode is
6223 returned, otherwise only the first letter is returned.
6224 Also see |state()|.
6225
6226 n Normal
6227 no Operator-pending
6228 nov Operator-pending (forced characterwise |o_v|)
6229 noV Operator-pending (forced linewise |o_V|)
6230 noCTRL-V Operator-pending (forced blockwise |o_CTRL-V|);
6231 CTRL-V is one character
6232 niI Normal using |i_CTRL-O| in |Insert-mode|
6233 niR Normal using |i_CTRL-O| in |Replace-mode|
6234 niV Normal using |i_CTRL-O| in |Virtual-Replace-mode|
6235 nt Terminal-Normal (insert goes to Terminal-Job mode)
6236 v Visual by character
6237 vs Visual by character using |v_CTRL-O| in Select mode
6238 V Visual by line
6239 Vs Visual by line using |v_CTRL-O| in Select mode
6240 CTRL-V Visual blockwise
6241 CTRL-Vs Visual blockwise using |v_CTRL-O| in Select mode
6242 s Select by character
6243 S Select by line
6244 CTRL-S Select blockwise
6245 i Insert
6246 ic Insert mode completion |compl-generic|
6247 ix Insert mode |i_CTRL-X| completion
6248 R Replace |R|
6249 Rc Replace mode completion |compl-generic|
6250 Rx Replace mode |i_CTRL-X| completion
6251 Rv Virtual Replace |gR|
6252 Rvc Virtual Replace mode completion |compl-generic|
6253 Rvx Virtual Replace mode |i_CTRL-X| completion
6254 c Command-line editing
6255 cv Vim Ex mode |gQ|
6256 ce Normal Ex mode |Q|
6257 r Hit-enter prompt
6258 rm The -- more -- prompt
6259 r? A |:confirm| query of some sort
6260 ! Shell or external command is executing
6261 t Terminal-Job mode: keys go to the job
6262
6263 This is useful in the 'statusline' option or when used
6264 with |remote_expr()| In most other places it always returns
6265 "c" or "n".
6266 Note that in the future more modes and more specific modes may
6267 be added. It's better not to compare the whole string but only
6268 the leading character(s).
6269 Also see |visualmode()|.
6270
6271 Can also be used as a |method|: >
6272 DoFull()->mode()
6273
6274mzeval({expr}) *mzeval()*
6275 Evaluate MzScheme expression {expr} and return its result
6276 converted to Vim data structures.
6277 Numbers and strings are returned as they are.
6278 Pairs (including lists and improper lists) and vectors are
6279 returned as Vim |Lists|.
6280 Hash tables are represented as Vim |Dictionary| type with keys
6281 converted to strings.
6282 All other types are converted to string with display function.
6283 Examples: >
6284 :mz (define l (list 1 2 3))
6285 :mz (define h (make-hash)) (hash-set! h "list" l)
6286 :echo mzeval("l")
6287 :echo mzeval("h")
6288<
6289 Note that in a `:def` function local variables are not visible
6290 to {expr}.
6291
6292 Can also be used as a |method|: >
6293 GetExpr()->mzeval()
6294<
6295 {only available when compiled with the |+mzscheme| feature}
6296
6297nextnonblank({lnum}) *nextnonblank()*
6298 Return the line number of the first line at or below {lnum}
6299 that is not blank. Example: >
6300 if getline(nextnonblank(1)) =~ "Java"
6301< When {lnum} is invalid or there is no non-blank line at or
6302 below it, zero is returned.
6303 {lnum} is used like with |getline()|.
6304 See also |prevnonblank()|.
6305
6306 Can also be used as a |method|: >
6307 GetLnum()->nextnonblank()
6308
6309nr2char({expr} [, {utf8}]) *nr2char()*
6310 Return a string with a single character, which has the number
6311 value {expr}. Examples: >
6312 nr2char(64) returns "@"
6313 nr2char(32) returns " "
6314< When {utf8} is omitted or zero, the current 'encoding' is used.
6315 Example for "utf-8": >
6316 nr2char(300) returns I with bow character
6317< When {utf8} is TRUE, always return UTF-8 characters.
6318 Note that a NUL character in the file is specified with
6319 nr2char(10), because NULs are represented with newline
6320 characters. nr2char(0) is a real NUL and terminates the
6321 string, thus results in an empty string.
6322 To turn a list of character numbers into a string: >
6323 let list = [65, 66, 67]
6324 let str = join(map(list, {_, val -> nr2char(val)}), '')
6325< Result: "ABC"
6326
6327 Can also be used as a |method|: >
6328 GetNumber()->nr2char()
6329
6330or({expr}, {expr}) *or()*
6331 Bitwise OR on the two arguments. The arguments are converted
6332 to a number. A List, Dict or Float argument causes an error.
Bram Moolenaar5a6ec102022-05-27 21:58:00 +01006333 Also see `and()` and `xor()`.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006334 Example: >
6335 :let bits = or(bits, 0x80)
6336< Can also be used as a |method|: >
6337 :let bits = bits->or(0x80)
6338
Bram Moolenaar5a6ec102022-05-27 21:58:00 +01006339< Rationale: The reason this is a function and not using the "|"
6340 character like many languages, is that Vi has always used "|"
6341 to separate commands. In many places it would not be clear if
6342 "|" is an operator or a command separator.
6343
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006344
6345pathshorten({path} [, {len}]) *pathshorten()*
6346 Shorten directory names in the path {path} and return the
6347 result. The tail, the file name, is kept as-is. The other
6348 components in the path are reduced to {len} letters in length.
6349 If {len} is omitted or smaller than 1 then 1 is used (single
6350 letters). Leading '~' and '.' characters are kept. Examples: >
6351 :echo pathshorten('~/.vim/autoload/myfile.vim')
6352< ~/.v/a/myfile.vim ~
6353>
6354 :echo pathshorten('~/.vim/autoload/myfile.vim', 2)
6355< ~/.vi/au/myfile.vim ~
6356 It doesn't matter if the path exists or not.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01006357 Returns an empty string on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006358
6359 Can also be used as a |method|: >
6360 GetDirectories()->pathshorten()
6361
6362perleval({expr}) *perleval()*
6363 Evaluate Perl expression {expr} in scalar context and return
6364 its result converted to Vim data structures. If value can't be
6365 converted, it is returned as a string Perl representation.
6366 Note: If you want an array or hash, {expr} must return a
6367 reference to it.
6368 Example: >
6369 :echo perleval('[1 .. 4]')
6370< [1, 2, 3, 4]
6371
6372 Note that in a `:def` function local variables are not visible
6373 to {expr}.
6374
6375 Can also be used as a |method|: >
6376 GetExpr()->perleval()
6377
6378< {only available when compiled with the |+perl| feature}
6379
6380
6381popup_ functions are documented here: |popup-functions|
6382
6383
6384pow({x}, {y}) *pow()*
6385 Return the power of {x} to the exponent {y} as a |Float|.
6386 {x} and {y} must evaluate to a |Float| or a |Number|.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01006387 Returns 0.0 if {x} or {y} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006388 Examples: >
6389 :echo pow(3, 3)
6390< 27.0 >
6391 :echo pow(2, 16)
6392< 65536.0 >
6393 :echo pow(32, 0.20)
6394< 2.0
6395
6396 Can also be used as a |method|: >
6397 Compute()->pow(3)
6398<
6399 {only available when compiled with the |+float| feature}
6400
6401prevnonblank({lnum}) *prevnonblank()*
6402 Return the line number of the first line at or above {lnum}
6403 that is not blank. Example: >
6404 let ind = indent(prevnonblank(v:lnum - 1))
6405< When {lnum} is invalid or there is no non-blank line at or
6406 above it, zero is returned.
6407 {lnum} is used like with |getline()|.
6408 Also see |nextnonblank()|.
6409
6410 Can also be used as a |method|: >
6411 GetLnum()->prevnonblank()
6412
6413printf({fmt}, {expr1} ...) *printf()*
6414 Return a String with {fmt}, where "%" items are replaced by
6415 the formatted form of their respective arguments. Example: >
6416 printf("%4d: E%d %.30s", lnum, errno, msg)
6417< May result in:
6418 " 99: E42 asdfasdfasdfasdfasdfasdfasdfas" ~
6419
6420 When used as a |method| the base is passed as the second
6421 argument: >
6422 Compute()->printf("result: %d")
Bram Moolenaarcbaff5e2022-04-08 17:45:08 +01006423<
6424 You can use `call()` to pass the items as a list.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006425
Bram Moolenaarcbaff5e2022-04-08 17:45:08 +01006426 Often used items are:
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006427 %s string
6428 %6S string right-aligned in 6 display cells
6429 %6s string right-aligned in 6 bytes
6430 %.9s string truncated to 9 bytes
6431 %c single byte
6432 %d decimal number
6433 %5d decimal number padded with spaces to 5 characters
6434 %x hex number
6435 %04x hex number padded with zeros to at least 4 characters
6436 %X hex number using upper case letters
6437 %o octal number
6438 %08b binary number padded with zeros to at least 8 chars
6439 %f floating point number as 12.23, inf, -inf or nan
6440 %F floating point number as 12.23, INF, -INF or NAN
6441 %e floating point number as 1.23e3, inf, -inf or nan
6442 %E floating point number as 1.23E3, INF, -INF or NAN
6443 %g floating point number, as %f or %e depending on value
6444 %G floating point number, as %F or %E depending on value
6445 %% the % character itself
6446
6447 Conversion specifications start with '%' and end with the
6448 conversion type. All other characters are copied unchanged to
6449 the result.
6450
6451 The "%" starts a conversion specification. The following
6452 arguments appear in sequence:
6453
6454 % [flags] [field-width] [.precision] type
6455
6456 flags
6457 Zero or more of the following flags:
6458
6459 # The value should be converted to an "alternate
6460 form". For c, d, and s conversions, this option
6461 has no effect. For o conversions, the precision
6462 of the number is increased to force the first
6463 character of the output string to a zero (except
6464 if a zero value is printed with an explicit
6465 precision of zero).
6466 For b and B conversions, a non-zero result has
6467 the string "0b" (or "0B" for B conversions)
6468 prepended to it.
6469 For x and X conversions, a non-zero result has
6470 the string "0x" (or "0X" for X conversions)
6471 prepended to it.
6472
6473 0 (zero) Zero padding. For all conversions the converted
6474 value is padded on the left with zeros rather
6475 than blanks. If a precision is given with a
6476 numeric conversion (d, b, B, o, x, and X), the 0
6477 flag is ignored.
6478
6479 - A negative field width flag; the converted value
6480 is to be left adjusted on the field boundary.
6481 The converted value is padded on the right with
6482 blanks, rather than on the left with blanks or
6483 zeros. A - overrides a 0 if both are given.
6484
6485 ' ' (space) A blank should be left before a positive
6486 number produced by a signed conversion (d).
6487
6488 + A sign must always be placed before a number
6489 produced by a signed conversion. A + overrides
6490 a space if both are used.
6491
6492 field-width
6493 An optional decimal digit string specifying a minimum
6494 field width. If the converted value has fewer bytes
6495 than the field width, it will be padded with spaces on
6496 the left (or right, if the left-adjustment flag has
6497 been given) to fill out the field width. For the S
6498 conversion the count is in cells.
6499
6500 .precision
6501 An optional precision, in the form of a period '.'
6502 followed by an optional digit string. If the digit
6503 string is omitted, the precision is taken as zero.
6504 This gives the minimum number of digits to appear for
6505 d, o, x, and X conversions, the maximum number of
6506 bytes to be printed from a string for s conversions,
6507 or the maximum number of cells to be printed from a
6508 string for S conversions.
6509 For floating point it is the number of digits after
6510 the decimal point.
6511
6512 type
6513 A character that specifies the type of conversion to
6514 be applied, see below.
6515
6516 A field width or precision, or both, may be indicated by an
6517 asterisk '*' instead of a digit string. In this case, a
6518 Number argument supplies the field width or precision. A
6519 negative field width is treated as a left adjustment flag
6520 followed by a positive field width; a negative precision is
6521 treated as though it were missing. Example: >
6522 :echo printf("%d: %.*s", nr, width, line)
6523< This limits the length of the text used from "line" to
6524 "width" bytes.
6525
6526 The conversion specifiers and their meanings are:
6527
6528 *printf-d* *printf-b* *printf-B* *printf-o*
6529 *printf-x* *printf-X*
6530 dbBoxX The Number argument is converted to signed decimal
6531 (d), unsigned binary (b and B), unsigned octal (o), or
6532 unsigned hexadecimal (x and X) notation. The letters
6533 "abcdef" are used for x conversions; the letters
6534 "ABCDEF" are used for X conversions.
6535 The precision, if any, gives the minimum number of
6536 digits that must appear; if the converted value
6537 requires fewer digits, it is padded on the left with
6538 zeros.
6539 In no case does a non-existent or small field width
6540 cause truncation of a numeric field; if the result of
6541 a conversion is wider than the field width, the field
6542 is expanded to contain the conversion result.
6543 The 'h' modifier indicates the argument is 16 bits.
6544 The 'l' modifier indicates the argument is 32 bits.
6545 The 'L' modifier indicates the argument is 64 bits.
6546 Generally, these modifiers are not useful. They are
6547 ignored when type is known from the argument.
6548
6549 i alias for d
6550 D alias for ld
6551 U alias for lu
6552 O alias for lo
6553
6554 *printf-c*
6555 c The Number argument is converted to a byte, and the
6556 resulting character is written.
6557
6558 *printf-s*
6559 s The text of the String argument is used. If a
6560 precision is specified, no more bytes than the number
6561 specified are used.
6562 If the argument is not a String type, it is
6563 automatically converted to text with the same format
6564 as ":echo".
6565 *printf-S*
6566 S The text of the String argument is used. If a
6567 precision is specified, no more display cells than the
6568 number specified are used.
6569
6570 *printf-f* *E807*
6571 f F The Float argument is converted into a string of the
6572 form 123.456. The precision specifies the number of
6573 digits after the decimal point. When the precision is
6574 zero the decimal point is omitted. When the precision
6575 is not specified 6 is used. A really big number
6576 (out of range or dividing by zero) results in "inf"
6577 or "-inf" with %f (INF or -INF with %F).
6578 "0.0 / 0.0" results in "nan" with %f (NAN with %F).
6579 Example: >
6580 echo printf("%.2f", 12.115)
6581< 12.12
6582 Note that roundoff depends on the system libraries.
6583 Use |round()| when in doubt.
6584
6585 *printf-e* *printf-E*
6586 e E The Float argument is converted into a string of the
6587 form 1.234e+03 or 1.234E+03 when using 'E'. The
6588 precision specifies the number of digits after the
6589 decimal point, like with 'f'.
6590
6591 *printf-g* *printf-G*
6592 g G The Float argument is converted like with 'f' if the
6593 value is between 0.001 (inclusive) and 10000000.0
6594 (exclusive). Otherwise 'e' is used for 'g' and 'E'
6595 for 'G'. When no precision is specified superfluous
6596 zeroes and '+' signs are removed, except for the zero
6597 immediately after the decimal point. Thus 10000000.0
6598 results in 1.0e7.
6599
6600 *printf-%*
6601 % A '%' is written. No argument is converted. The
6602 complete conversion specification is "%%".
6603
6604 When a Number argument is expected a String argument is also
6605 accepted and automatically converted.
6606 When a Float or String argument is expected a Number argument
6607 is also accepted and automatically converted.
6608 Any other argument type results in an error message.
6609
6610 *E766* *E767*
6611 The number of {exprN} arguments must exactly match the number
6612 of "%" items. If there are not sufficient or too many
6613 arguments an error is given. Up to 18 arguments can be used.
6614
6615
6616prompt_getprompt({buf}) *prompt_getprompt()*
6617 Returns the effective prompt text for buffer {buf}. {buf} can
6618 be a buffer name or number. See |prompt-buffer|.
6619
6620 If the buffer doesn't exist or isn't a prompt buffer, an empty
6621 string is returned.
6622
6623 Can also be used as a |method|: >
6624 GetBuffer()->prompt_getprompt()
6625
6626< {only available when compiled with the |+channel| feature}
6627
6628
6629prompt_setcallback({buf}, {expr}) *prompt_setcallback()*
6630 Set prompt callback for buffer {buf} to {expr}. When {expr}
6631 is an empty string the callback is removed. This has only
6632 effect if {buf} has 'buftype' set to "prompt".
6633
6634 The callback is invoked when pressing Enter. The current
6635 buffer will always be the prompt buffer. A new line for a
6636 prompt is added before invoking the callback, thus the prompt
6637 for which the callback was invoked will be in the last but one
6638 line.
6639 If the callback wants to add text to the buffer, it must
6640 insert it above the last line, since that is where the current
6641 prompt is. This can also be done asynchronously.
6642 The callback is invoked with one argument, which is the text
6643 that was entered at the prompt. This can be an empty string
6644 if the user only typed Enter.
6645 Example: >
6646 call prompt_setcallback(bufnr(), function('s:TextEntered'))
6647 func s:TextEntered(text)
6648 if a:text == 'exit' || a:text == 'quit'
6649 stopinsert
6650 close
6651 else
Bram Moolenaarc51cf032022-02-26 12:25:45 +00006652 call append(line('$') - 1, 'Entered: "' .. a:text .. '"')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006653 " Reset 'modified' to allow the buffer to be closed.
6654 set nomodified
6655 endif
6656 endfunc
6657
6658< Can also be used as a |method|: >
6659 GetBuffer()->prompt_setcallback(callback)
6660
6661< {only available when compiled with the |+channel| feature}
6662
6663prompt_setinterrupt({buf}, {expr}) *prompt_setinterrupt()*
6664 Set a callback for buffer {buf} to {expr}. When {expr} is an
6665 empty string the callback is removed. This has only effect if
6666 {buf} has 'buftype' set to "prompt".
6667
6668 This callback will be invoked when pressing CTRL-C in Insert
6669 mode. Without setting a callback Vim will exit Insert mode,
6670 as in any buffer.
6671
6672 Can also be used as a |method|: >
6673 GetBuffer()->prompt_setinterrupt(callback)
6674
6675< {only available when compiled with the |+channel| feature}
6676
6677prompt_setprompt({buf}, {text}) *prompt_setprompt()*
6678 Set prompt for buffer {buf} to {text}. You most likely want
6679 {text} to end in a space.
6680 The result is only visible if {buf} has 'buftype' set to
6681 "prompt". Example: >
6682 call prompt_setprompt(bufnr(), 'command: ')
6683<
6684 Can also be used as a |method|: >
6685 GetBuffer()->prompt_setprompt('command: ')
6686
6687< {only available when compiled with the |+channel| feature}
6688
6689prop_ functions are documented here: |text-prop-functions|
6690
6691pum_getpos() *pum_getpos()*
6692 If the popup menu (see |ins-completion-menu|) is not visible,
6693 returns an empty |Dictionary|, otherwise, returns a
6694 |Dictionary| with the following keys:
6695 height nr of items visible
6696 width screen cells
6697 row top screen row (0 first row)
6698 col leftmost screen column (0 first col)
6699 size total nr of items
6700 scrollbar |TRUE| if scrollbar is visible
6701
6702 The values are the same as in |v:event| during
6703 |CompleteChanged|.
6704
6705pumvisible() *pumvisible()*
6706 Returns non-zero when the popup menu is visible, zero
6707 otherwise. See |ins-completion-menu|.
6708 This can be used to avoid some things that would remove the
6709 popup menu.
6710
6711py3eval({expr}) *py3eval()*
6712 Evaluate Python expression {expr} and return its result
6713 converted to Vim data structures.
6714 Numbers and strings are returned as they are (strings are
6715 copied though, Unicode strings are additionally converted to
6716 'encoding').
6717 Lists are represented as Vim |List| type.
6718 Dictionaries are represented as Vim |Dictionary| type with
6719 keys converted to strings.
6720 Note that in a `:def` function local variables are not visible
6721 to {expr}.
6722
6723 Can also be used as a |method|: >
6724 GetExpr()->py3eval()
6725
6726< {only available when compiled with the |+python3| feature}
6727
6728 *E858* *E859*
6729pyeval({expr}) *pyeval()*
6730 Evaluate Python expression {expr} and return its result
6731 converted to Vim data structures.
6732 Numbers and strings are returned as they are (strings are
6733 copied though).
6734 Lists are represented as Vim |List| type.
6735 Dictionaries are represented as Vim |Dictionary| type,
6736 non-string keys result in error.
6737 Note that in a `:def` function local variables are not visible
6738 to {expr}.
6739
6740 Can also be used as a |method|: >
6741 GetExpr()->pyeval()
6742
6743< {only available when compiled with the |+python| feature}
6744
6745pyxeval({expr}) *pyxeval()*
6746 Evaluate Python expression {expr} and return its result
6747 converted to Vim data structures.
6748 Uses Python 2 or 3, see |python_x| and 'pyxversion'.
6749 See also: |pyeval()|, |py3eval()|
6750
6751 Can also be used as a |method|: >
6752 GetExpr()->pyxeval()
6753
6754< {only available when compiled with the |+python| or the
6755 |+python3| feature}
6756
6757rand([{expr}]) *rand()* *random*
6758 Return a pseudo-random Number generated with an xoshiro128**
6759 algorithm using seed {expr}. The returned number is 32 bits,
6760 also on 64 bits systems, for consistency.
6761 {expr} can be initialized by |srand()| and will be updated by
6762 rand(). If {expr} is omitted, an internal seed value is used
6763 and updated.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01006764 Returns -1 if {expr} is invalid.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006765
6766 Examples: >
6767 :echo rand()
6768 :let seed = srand()
6769 :echo rand(seed)
6770 :echo rand(seed) % 16 " random number 0 - 15
6771<
6772
6773 *E726* *E727*
6774range({expr} [, {max} [, {stride}]]) *range()*
6775 Returns a |List| with Numbers:
6776 - If only {expr} is specified: [0, 1, ..., {expr} - 1]
6777 - If {max} is specified: [{expr}, {expr} + 1, ..., {max}]
6778 - If {stride} is specified: [{expr}, {expr} + {stride}, ...,
6779 {max}] (increasing {expr} with {stride} each time, not
6780 producing a value past {max}).
6781 When the maximum is one before the start the result is an
6782 empty list. When the maximum is more than one before the
6783 start this is an error.
6784 Examples: >
6785 range(4) " [0, 1, 2, 3]
6786 range(2, 4) " [2, 3, 4]
6787 range(2, 9, 3) " [2, 5, 8]
6788 range(2, -2, -1) " [2, 1, 0, -1, -2]
6789 range(0) " []
6790 range(2, 0) " error!
6791<
6792 Can also be used as a |method|: >
6793 GetExpr()->range()
6794<
6795
6796readblob({fname}) *readblob()*
6797 Read file {fname} in binary mode and return a |Blob|.
6798 When the file can't be opened an error message is given and
6799 the result is an empty |Blob|.
6800 Also see |readfile()| and |writefile()|.
6801
6802
6803readdir({directory} [, {expr} [, {dict}]]) *readdir()*
6804 Return a list with file and directory names in {directory}.
6805 You can also use |glob()| if you don't need to do complicated
6806 things, such as limiting the number of matches.
6807 The list will be sorted (case sensitive), see the {dict}
6808 argument below for changing the sort order.
6809
6810 When {expr} is omitted all entries are included.
6811 When {expr} is given, it is evaluated to check what to do:
6812 If {expr} results in -1 then no further entries will
6813 be handled.
6814 If {expr} results in 0 then this entry will not be
6815 added to the list.
6816 If {expr} results in 1 then this entry will be added
6817 to the list.
6818 The entries "." and ".." are always excluded.
6819 Each time {expr} is evaluated |v:val| is set to the entry name.
6820 When {expr} is a function the name is passed as the argument.
6821 For example, to get a list of files ending in ".txt": >
6822 readdir(dirname, {n -> n =~ '.txt$'})
6823< To skip hidden and backup files: >
6824 readdir(dirname, {n -> n !~ '^\.\|\~$'})
Bram Moolenaar6f4754b2022-01-23 12:07:04 +00006825< *E857*
6826 The optional {dict} argument allows for further custom
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006827 values. Currently this is used to specify if and how sorting
6828 should be performed. The dict can have the following members:
6829
6830 sort How to sort the result returned from the system.
6831 Valid values are:
6832 "none" do not sort (fastest method)
6833 "case" sort case sensitive (byte value of
6834 each character, technically, using
6835 strcmp()) (default)
6836 "icase" sort case insensitive (technically
6837 using strcasecmp())
6838 "collate" sort using the collation order
6839 of the "POSIX" or "C" |locale|
6840 (technically using strcoll())
6841 Other values are silently ignored.
6842
6843 For example, to get a list of all files in the current
6844 directory without sorting the individual entries: >
6845 readdir('.', '1', #{sort: 'none'})
6846< If you want to get a directory tree: >
6847 function! s:tree(dir)
6848 return {a:dir : map(readdir(a:dir),
6849 \ {_, x -> isdirectory(x) ?
Bram Moolenaarc51cf032022-02-26 12:25:45 +00006850 \ {x : s:tree(a:dir .. '/' .. x)} : x})}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006851 endfunction
6852 echo s:tree(".")
6853<
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01006854 Returns an empty List on error.
6855
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006856 Can also be used as a |method|: >
6857 GetDirName()->readdir()
6858<
6859readdirex({directory} [, {expr} [, {dict}]]) *readdirex()*
6860 Extended version of |readdir()|.
6861 Return a list of Dictionaries with file and directory
6862 information in {directory}.
6863 This is useful if you want to get the attributes of file and
6864 directory at the same time as getting a list of a directory.
6865 This is much faster than calling |readdir()| then calling
6866 |getfperm()|, |getfsize()|, |getftime()| and |getftype()| for
6867 each file and directory especially on MS-Windows.
6868 The list will by default be sorted by name (case sensitive),
6869 the sorting can be changed by using the optional {dict}
6870 argument, see |readdir()|.
6871
6872 The Dictionary for file and directory information has the
6873 following items:
6874 group Group name of the entry. (Only on Unix)
6875 name Name of the entry.
6876 perm Permissions of the entry. See |getfperm()|.
6877 size Size of the entry. See |getfsize()|.
6878 time Timestamp of the entry. See |getftime()|.
6879 type Type of the entry.
6880 On Unix, almost same as |getftype()| except:
6881 Symlink to a dir "linkd"
6882 Other symlink "link"
6883 On MS-Windows:
6884 Normal file "file"
6885 Directory "dir"
6886 Junction "junction"
6887 Symlink to a dir "linkd"
6888 Other symlink "link"
6889 Other reparse point "reparse"
6890 user User name of the entry's owner. (Only on Unix)
6891 On Unix, if the entry is a symlink, the Dictionary includes
6892 the information of the target (except the "type" item).
6893 On MS-Windows, it includes the information of the symlink
6894 itself because of performance reasons.
6895
6896 When {expr} is omitted all entries are included.
6897 When {expr} is given, it is evaluated to check what to do:
6898 If {expr} results in -1 then no further entries will
6899 be handled.
6900 If {expr} results in 0 then this entry will not be
6901 added to the list.
6902 If {expr} results in 1 then this entry will be added
6903 to the list.
6904 The entries "." and ".." are always excluded.
6905 Each time {expr} is evaluated |v:val| is set to a |Dictionary|
6906 of the entry.
6907 When {expr} is a function the entry is passed as the argument.
6908 For example, to get a list of files ending in ".txt": >
6909 readdirex(dirname, {e -> e.name =~ '.txt$'})
6910<
6911 For example, to get a list of all files in the current
6912 directory without sorting the individual entries: >
6913 readdirex(dirname, '1', #{sort: 'none'})
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006914<
6915 Can also be used as a |method|: >
6916 GetDirName()->readdirex()
6917<
6918
6919 *readfile()*
6920readfile({fname} [, {type} [, {max}]])
6921 Read file {fname} and return a |List|, each line of the file
6922 as an item. Lines are broken at NL characters. Macintosh
6923 files separated with CR will result in a single long line
6924 (unless a NL appears somewhere).
6925 All NUL characters are replaced with a NL character.
6926 When {type} contains "b" binary mode is used:
6927 - When the last line ends in a NL an extra empty list item is
6928 added.
6929 - No CR characters are removed.
6930 Otherwise:
6931 - CR characters that appear before a NL are removed.
6932 - Whether the last line ends in a NL or not does not matter.
6933 - When 'encoding' is Unicode any UTF-8 byte order mark is
6934 removed from the text.
6935 When {max} is given this specifies the maximum number of lines
6936 to be read. Useful if you only want to check the first ten
6937 lines of a file: >
6938 :for line in readfile(fname, '', 10)
6939 : if line =~ 'Date' | echo line | endif
6940 :endfor
6941< When {max} is negative -{max} lines from the end of the file
6942 are returned, or as many as there are.
6943 When {max} is zero the result is an empty list.
6944 Note that without {max} the whole file is read into memory.
6945 Also note that there is no recognition of encoding. Read a
6946 file into a buffer if you need to.
6947 Deprecated (use |readblob()| instead): When {type} contains
6948 "B" a |Blob| is returned with the binary data of the file
6949 unmodified.
6950 When the file can't be opened an error message is given and
6951 the result is an empty list.
6952 Also see |writefile()|.
6953
6954 Can also be used as a |method|: >
6955 GetFileName()->readfile()
6956
6957reduce({object}, {func} [, {initial}]) *reduce()* *E998*
6958 {func} is called for every item in {object}, which can be a
6959 |String|, |List| or a |Blob|. {func} is called with two
6960 arguments: the result so far and current item. After
Bram Moolenaarf10911e2022-01-29 22:20:48 +00006961 processing all items the result is returned. *E1132*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006962
6963 {initial} is the initial result. When omitted, the first item
6964 in {object} is used and {func} is first called for the second
6965 item. If {initial} is not given and {object} is empty no
6966 result can be computed, an E998 error is given.
6967
6968 Examples: >
6969 echo reduce([1, 3, 5], { acc, val -> acc + val })
6970 echo reduce(['x', 'y'], { acc, val -> acc .. val }, 'a')
6971 echo reduce(0z1122, { acc, val -> 2 * acc + val })
6972 echo reduce('xyz', { acc, val -> acc .. ',' .. val })
6973<
6974 Can also be used as a |method|: >
6975 echo mylist->reduce({ acc, val -> acc + val }, 0)
6976
6977
6978reg_executing() *reg_executing()*
6979 Returns the single letter name of the register being executed.
6980 Returns an empty string when no register is being executed.
6981 See |@|.
6982
6983reg_recording() *reg_recording()*
6984 Returns the single letter name of the register being recorded.
6985 Returns an empty string when not recording. See |q|.
6986
6987reltime([{start} [, {end}]]) *reltime()*
6988 Return an item that represents a time value. The item is a
6989 list with items that depend on the system. In Vim 9 script
6990 list<any> can be used.
6991 The item can be passed to |reltimestr()| to convert it to a
6992 string or |reltimefloat()| to convert to a Float.
6993
Bram Moolenaar016188f2022-06-06 20:52:59 +01006994 Without an argument reltime() returns the current time (the
Bram Moolenaareb490412022-06-28 13:44:46 +01006995 representation is system-dependent, it can not be used as the
Bram Moolenaar016188f2022-06-06 20:52:59 +01006996 wall-clock time, see |localtime()| for that).
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006997 With one argument is returns the time passed since the time
6998 specified in the argument.
6999 With two arguments it returns the time passed between {start}
7000 and {end}.
7001
7002 The {start} and {end} arguments must be values returned by
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01007003 reltime(). If there is an error an empty List is returned in
7004 legacy script, in Vim9 script an error is given.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007005
7006 Can also be used as a |method|: >
7007 GetStart()->reltime()
7008<
7009 {only available when compiled with the |+reltime| feature}
7010
7011reltimefloat({time}) *reltimefloat()*
7012 Return a Float that represents the time value of {time}.
7013 Example: >
7014 let start = reltime()
7015 call MyFunction()
7016 let seconds = reltimefloat(reltime(start))
7017< See the note of reltimestr() about overhead.
7018 Also see |profiling|.
7019 If there is an error 0.0 is returned in legacy script, in Vim9
7020 script an error is given.
7021
7022 Can also be used as a |method|: >
7023 reltime(start)->reltimefloat()
7024
7025< {only available when compiled with the |+reltime| feature}
7026
7027reltimestr({time}) *reltimestr()*
7028 Return a String that represents the time value of {time}.
7029 This is the number of seconds, a dot and the number of
7030 microseconds. Example: >
7031 let start = reltime()
7032 call MyFunction()
7033 echo reltimestr(reltime(start))
7034< Note that overhead for the commands will be added to the time.
7035 The accuracy depends on the system.
7036 Leading spaces are used to make the string align nicely. You
7037 can use split() to remove it. >
7038 echo split(reltimestr(reltime(start)))[0]
7039< Also see |profiling|.
7040 If there is an error an empty string is returned in legacy
7041 script, in Vim9 script an error is given.
7042
7043 Can also be used as a |method|: >
7044 reltime(start)->reltimestr()
7045
7046< {only available when compiled with the |+reltime| feature}
7047
7048 *remote_expr()* *E449*
7049remote_expr({server}, {string} [, {idvar} [, {timeout}]])
Bram Moolenaar944697a2022-02-20 19:48:20 +00007050 Send the {string} to {server}. The {server} argument is a
7051 string, also see |{server}|.
7052
7053 The string is sent as an expression and the result is returned
7054 after evaluation. The result must be a String or a |List|. A
7055 |List| is turned into a String by joining the items with a
7056 line break in between (not at the end), like with join(expr,
7057 "\n").
7058
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007059 If {idvar} is present and not empty, it is taken as the name
7060 of a variable and a {serverid} for later use with
7061 |remote_read()| is stored there.
Bram Moolenaar944697a2022-02-20 19:48:20 +00007062
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007063 If {timeout} is given the read times out after this many
7064 seconds. Otherwise a timeout of 600 seconds is used.
Bram Moolenaar944697a2022-02-20 19:48:20 +00007065
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007066 See also |clientserver| |RemoteReply|.
7067 This function is not available in the |sandbox|.
7068 {only available when compiled with the |+clientserver| feature}
7069 Note: Any errors will cause a local error message to be issued
7070 and the result will be the empty string.
7071
7072 Variables will be evaluated in the global namespace,
7073 independent of a function currently being active. Except
7074 when in debug mode, then local function variables and
7075 arguments can be evaluated.
7076
7077 Examples: >
7078 :echo remote_expr("gvim", "2+2")
7079 :echo remote_expr("gvim1", "b:current_syntax")
7080<
7081 Can also be used as a |method|: >
7082 ServerName()->remote_expr(expr)
7083
7084remote_foreground({server}) *remote_foreground()*
7085 Move the Vim server with the name {server} to the foreground.
Bram Moolenaar944697a2022-02-20 19:48:20 +00007086 The {server} argument is a string, also see |{server}|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007087 This works like: >
7088 remote_expr({server}, "foreground()")
7089< Except that on Win32 systems the client does the work, to work
7090 around the problem that the OS doesn't always allow the server
7091 to bring itself to the foreground.
7092 Note: This does not restore the window if it was minimized,
7093 like foreground() does.
7094 This function is not available in the |sandbox|.
7095
7096 Can also be used as a |method|: >
7097 ServerName()->remote_foreground()
7098
Bram Moolenaarcbaff5e2022-04-08 17:45:08 +01007099< {only in the Win32, Motif and GTK GUI versions and the
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007100 Win32 console version}
7101
7102
7103remote_peek({serverid} [, {retvar}]) *remote_peek()*
7104 Returns a positive number if there are available strings
7105 from {serverid}. Copies any reply string into the variable
7106 {retvar} if specified. {retvar} must be a string with the
7107 name of a variable.
7108 Returns zero if none are available.
7109 Returns -1 if something is wrong.
7110 See also |clientserver|.
7111 This function is not available in the |sandbox|.
7112 {only available when compiled with the |+clientserver| feature}
7113 Examples: >
7114 :let repl = ""
Bram Moolenaarc51cf032022-02-26 12:25:45 +00007115 :echo "PEEK: " .. remote_peek(id, "repl") .. ": " .. repl
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007116
7117< Can also be used as a |method|: >
7118 ServerId()->remote_peek()
7119
7120remote_read({serverid}, [{timeout}]) *remote_read()*
7121 Return the oldest available reply from {serverid} and consume
7122 it. Unless a {timeout} in seconds is given, it blocks until a
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01007123 reply is available. Returns an empty string, if a reply is
7124 not available or on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007125 See also |clientserver|.
7126 This function is not available in the |sandbox|.
7127 {only available when compiled with the |+clientserver| feature}
7128 Example: >
7129 :echo remote_read(id)
7130
7131< Can also be used as a |method|: >
7132 ServerId()->remote_read()
7133<
7134 *remote_send()* *E241*
7135remote_send({server}, {string} [, {idvar}])
Bram Moolenaar944697a2022-02-20 19:48:20 +00007136 Send the {string} to {server}. The {server} argument is a
7137 string, also see |{server}|.
7138
7139 The string is sent as input keys and the function returns
7140 immediately. At the Vim server the keys are not mapped
7141 |:map|.
7142
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007143 If {idvar} is present, it is taken as the name of a variable
7144 and a {serverid} for later use with remote_read() is stored
7145 there.
Bram Moolenaar944697a2022-02-20 19:48:20 +00007146
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007147 See also |clientserver| |RemoteReply|.
7148 This function is not available in the |sandbox|.
7149 {only available when compiled with the |+clientserver| feature}
7150
7151 Note: Any errors will be reported in the server and may mess
7152 up the display.
7153 Examples: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00007154 :echo remote_send("gvim", ":DropAndReply " .. file, "serverid") ..
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007155 \ remote_read(serverid)
7156
7157 :autocmd NONE RemoteReply *
7158 \ echo remote_read(expand("<amatch>"))
Bram Moolenaarc51cf032022-02-26 12:25:45 +00007159 :echo remote_send("gvim", ":sleep 10 | echo " ..
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007160 \ 'server2client(expand("<client>"), "HELLO")<CR>')
7161<
7162 Can also be used as a |method|: >
7163 ServerName()->remote_send(keys)
7164<
7165 *remote_startserver()* *E941* *E942*
7166remote_startserver({name})
7167 Become the server {name}. This fails if already running as a
7168 server, when |v:servername| is not empty.
7169
7170 Can also be used as a |method|: >
7171 ServerName()->remote_startserver()
7172
7173< {only available when compiled with the |+clientserver| feature}
7174
7175remove({list}, {idx} [, {end}]) *remove()*
7176 Without {end}: Remove the item at {idx} from |List| {list} and
7177 return the item.
7178 With {end}: Remove items from {idx} to {end} (inclusive) and
7179 return a |List| with these items. When {idx} points to the same
7180 item as {end} a list with one item is returned. When {end}
7181 points to an item before {idx} this is an error.
7182 See |list-index| for possible values of {idx} and {end}.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01007183 Returns zero on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007184 Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00007185 :echo "last item: " .. remove(mylist, -1)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007186 :call remove(mylist, 0, 9)
7187<
7188 Use |delete()| to remove a file.
7189
7190 Can also be used as a |method|: >
7191 mylist->remove(idx)
7192
7193remove({blob}, {idx} [, {end}])
7194 Without {end}: Remove the byte at {idx} from |Blob| {blob} and
7195 return the byte.
7196 With {end}: Remove bytes from {idx} to {end} (inclusive) and
7197 return a |Blob| with these bytes. When {idx} points to the same
7198 byte as {end} a |Blob| with one byte is returned. When {end}
7199 points to a byte before {idx} this is an error.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01007200 Returns zero on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007201 Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00007202 :echo "last byte: " .. remove(myblob, -1)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007203 :call remove(mylist, 0, 9)
7204
7205remove({dict}, {key})
7206 Remove the entry from {dict} with key {key} and return it.
7207 Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00007208 :echo "removed " .. remove(dict, "one")
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007209< If there is no {key} in {dict} this is an error.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01007210 Returns zero on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007211
7212rename({from}, {to}) *rename()*
7213 Rename the file by the name {from} to the name {to}. This
7214 should also work to move files across file systems. The
7215 result is a Number, which is 0 if the file was renamed
7216 successfully, and non-zero when the renaming failed.
7217 NOTE: If {to} exists it is overwritten without warning.
7218 This function is not available in the |sandbox|.
7219
7220 Can also be used as a |method|: >
7221 GetOldName()->rename(newname)
7222
7223repeat({expr}, {count}) *repeat()*
7224 Repeat {expr} {count} times and return the concatenated
7225 result. Example: >
7226 :let separator = repeat('-', 80)
7227< When {count} is zero or negative the result is empty.
7228 When {expr} is a |List| the result is {expr} concatenated
7229 {count} times. Example: >
7230 :let longlist = repeat(['a', 'b'], 3)
7231< Results in ['a', 'b', 'a', 'b', 'a', 'b'].
7232
7233 Can also be used as a |method|: >
7234 mylist->repeat(count)
7235
7236resolve({filename}) *resolve()* *E655*
7237 On MS-Windows, when {filename} is a shortcut (a .lnk file),
7238 returns the path the shortcut points to in a simplified form.
7239 When {filename} is a symbolic link or junction point, return
7240 the full path to the target. If the target of junction is
7241 removed, return {filename}.
7242 On Unix, repeat resolving symbolic links in all path
7243 components of {filename} and return the simplified result.
7244 To cope with link cycles, resolving of symbolic links is
7245 stopped after 100 iterations.
7246 On other systems, return the simplified {filename}.
7247 The simplification step is done as by |simplify()|.
7248 resolve() keeps a leading path component specifying the
7249 current directory (provided the result is still a relative
7250 path name) and also keeps a trailing path separator.
7251
7252 Can also be used as a |method|: >
7253 GetName()->resolve()
7254
7255reverse({object}) *reverse()*
7256 Reverse the order of items in {object} in-place.
7257 {object} can be a |List| or a |Blob|.
7258 Returns {object}.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01007259 Returns zero if {object} is not a List or a Blob.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007260 If you want an object to remain unmodified make a copy first: >
7261 :let revlist = reverse(copy(mylist))
7262< Can also be used as a |method|: >
7263 mylist->reverse()
7264
7265round({expr}) *round()*
7266 Round off {expr} to the nearest integral value and return it
7267 as a |Float|. If {expr} lies halfway between two integral
7268 values, then use the larger one (away from zero).
7269 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01007270 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007271 Examples: >
7272 echo round(0.456)
7273< 0.0 >
7274 echo round(4.5)
7275< 5.0 >
7276 echo round(-4.5)
7277< -5.0
7278
7279 Can also be used as a |method|: >
7280 Compute()->round()
7281<
7282 {only available when compiled with the |+float| feature}
7283
7284rubyeval({expr}) *rubyeval()*
7285 Evaluate Ruby expression {expr} and return its result
7286 converted to Vim data structures.
7287 Numbers, floats and strings are returned as they are (strings
7288 are copied though).
7289 Arrays are represented as Vim |List| type.
7290 Hashes are represented as Vim |Dictionary| type.
7291 Other objects are represented as strings resulted from their
7292 "Object#to_s" method.
7293 Note that in a `:def` function local variables are not visible
7294 to {expr}.
7295
7296 Can also be used as a |method|: >
7297 GetRubyExpr()->rubyeval()
7298
7299< {only available when compiled with the |+ruby| feature}
7300
7301screenattr({row}, {col}) *screenattr()*
7302 Like |screenchar()|, but return the attribute. This is a rather
7303 arbitrary number that can only be used to compare to the
7304 attribute at other positions.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01007305 Returns -1 when row or col is out of range.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007306
7307 Can also be used as a |method|: >
7308 GetRow()->screenattr(col)
7309
7310screenchar({row}, {col}) *screenchar()*
7311 The result is a Number, which is the character at position
7312 [row, col] on the screen. This works for every possible
7313 screen position, also status lines, window separators and the
7314 command line. The top left position is row one, column one
7315 The character excludes composing characters. For double-byte
7316 encodings it may only be the first byte.
7317 This is mainly to be used for testing.
7318 Returns -1 when row or col is out of range.
7319
7320 Can also be used as a |method|: >
7321 GetRow()->screenchar(col)
7322
7323screenchars({row}, {col}) *screenchars()*
7324 The result is a |List| of Numbers. The first number is the same
7325 as what |screenchar()| returns. Further numbers are
7326 composing characters on top of the base character.
7327 This is mainly to be used for testing.
7328 Returns an empty List when row or col is out of range.
7329
7330 Can also be used as a |method|: >
7331 GetRow()->screenchars(col)
7332
7333screencol() *screencol()*
7334 The result is a Number, which is the current screen column of
7335 the cursor. The leftmost column has number 1.
7336 This function is mainly used for testing.
7337
7338 Note: Always returns the current screen column, thus if used
7339 in a command (e.g. ":echo screencol()") it will return the
7340 column inside the command line, which is 1 when the command is
7341 executed. To get the cursor position in the file use one of
7342 the following mappings: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00007343 nnoremap <expr> GG ":echom " .. screencol() .. "\n"
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007344 nnoremap <silent> GG :echom screencol()<CR>
7345 nnoremap GG <Cmd>echom screencol()<CR>
7346<
7347screenpos({winid}, {lnum}, {col}) *screenpos()*
7348 The result is a Dict with the screen position of the text
7349 character in window {winid} at buffer line {lnum} and column
7350 {col}. {col} is a one-based byte index.
7351 The Dict has these members:
7352 row screen row
7353 col first screen column
7354 endcol last screen column
7355 curscol cursor screen column
7356 If the specified position is not visible, all values are zero.
7357 The "endcol" value differs from "col" when the character
7358 occupies more than one screen cell. E.g. for a Tab "col" can
7359 be 1 and "endcol" can be 8.
7360 The "curscol" value is where the cursor would be placed. For
7361 a Tab it would be the same as "endcol", while for a double
7362 width character it would be the same as "col".
7363 The |conceal| feature is ignored here, the column numbers are
7364 as if 'conceallevel' is zero. You can set the cursor to the
7365 right position and use |screencol()| to get the value with
7366 |conceal| taken into account.
Bram Moolenaar944697a2022-02-20 19:48:20 +00007367 If the position is in a closed fold the screen position of the
7368 first character is returned, {col} is not used.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01007369 Returns an empty Dict if {winid} is invalid.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007370
7371 Can also be used as a |method|: >
7372 GetWinid()->screenpos(lnum, col)
7373
7374screenrow() *screenrow()*
7375 The result is a Number, which is the current screen row of the
7376 cursor. The top line has number one.
7377 This function is mainly used for testing.
7378 Alternatively you can use |winline()|.
7379
7380 Note: Same restrictions as with |screencol()|.
7381
7382screenstring({row}, {col}) *screenstring()*
7383 The result is a String that contains the base character and
7384 any composing characters at position [row, col] on the screen.
7385 This is like |screenchars()| but returning a String with the
7386 characters.
7387 This is mainly to be used for testing.
7388 Returns an empty String when row or col is out of range.
7389
7390 Can also be used as a |method|: >
7391 GetRow()->screenstring(col)
7392<
7393 *search()*
7394search({pattern} [, {flags} [, {stopline} [, {timeout} [, {skip}]]]])
7395 Search for regexp pattern {pattern}. The search starts at the
7396 cursor position (you can use |cursor()| to set it).
7397
7398 When a match has been found its line number is returned.
7399 If there is no match a 0 is returned and the cursor doesn't
7400 move. No error message is given.
7401
7402 {flags} is a String, which can contain these character flags:
7403 'b' search Backward instead of forward
7404 'c' accept a match at the Cursor position
7405 'e' move to the End of the match
7406 'n' do Not move the cursor
7407 'p' return number of matching sub-Pattern (see below)
7408 's' Set the ' mark at the previous location of the cursor
7409 'w' Wrap around the end of the file
7410 'W' don't Wrap around the end of the file
7411 'z' start searching at the cursor column instead of zero
7412 If neither 'w' or 'W' is given, the 'wrapscan' option applies.
7413
7414 If the 's' flag is supplied, the ' mark is set, only if the
7415 cursor is moved. The 's' flag cannot be combined with the 'n'
7416 flag.
7417
7418 'ignorecase', 'smartcase' and 'magic' are used.
7419
7420 When the 'z' flag is not given, forward searching always
7421 starts in column zero and then matches before the cursor are
7422 skipped. When the 'c' flag is present in 'cpo' the next
7423 search starts after the match. Without the 'c' flag the next
7424 search starts one column further. This matters for
7425 overlapping matches.
7426 When searching backwards and the 'z' flag is given then the
7427 search starts in column zero, thus no match in the current
7428 line will be found (unless wrapping around the end of the
7429 file).
7430
7431 When the {stopline} argument is given then the search stops
7432 after searching this line. This is useful to restrict the
7433 search to a range of lines. Examples: >
7434 let match = search('(', 'b', line("w0"))
7435 let end = search('END', '', line("w$"))
7436< When {stopline} is used and it is not zero this also implies
7437 that the search does not wrap around the end of the file.
7438 A zero value is equal to not giving the argument.
Bram Moolenaar2ecbe532022-07-29 21:36:21 +01007439 *E1285* *E1286* *E1287* *E1288* *E1289*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007440 When the {timeout} argument is given the search stops when
7441 more than this many milliseconds have passed. Thus when
7442 {timeout} is 500 the search stops after half a second.
7443 The value must not be negative. A zero value is like not
7444 giving the argument.
7445 {only available when compiled with the |+reltime| feature}
7446
7447 If the {skip} expression is given it is evaluated with the
7448 cursor positioned on the start of a match. If it evaluates to
7449 non-zero this match is skipped. This can be used, for
7450 example, to skip a match in a comment or a string.
7451 {skip} can be a string, which is evaluated as an expression, a
7452 function reference or a lambda.
7453 When {skip} is omitted or empty, every match is accepted.
7454 When evaluating {skip} causes an error the search is aborted
7455 and -1 returned.
7456 *search()-sub-match*
7457 With the 'p' flag the returned value is one more than the
7458 first sub-match in \(\). One if none of them matched but the
7459 whole pattern did match.
7460 To get the column number too use |searchpos()|.
7461
7462 The cursor will be positioned at the match, unless the 'n'
7463 flag is used.
7464
7465 Example (goes over all files in the argument list): >
7466 :let n = 1
7467 :while n <= argc() " loop over all files in arglist
Bram Moolenaarc51cf032022-02-26 12:25:45 +00007468 : exe "argument " .. n
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007469 : " start at the last char in the file and wrap for the
7470 : " first search to find match at start of file
7471 : normal G$
7472 : let flags = "w"
7473 : while search("foo", flags) > 0
7474 : s/foo/bar/g
7475 : let flags = "W"
7476 : endwhile
7477 : update " write the file if modified
7478 : let n = n + 1
7479 :endwhile
7480<
7481 Example for using some flags: >
7482 :echo search('\<if\|\(else\)\|\(endif\)', 'ncpe')
7483< This will search for the keywords "if", "else", and "endif"
7484 under or after the cursor. Because of the 'p' flag, it
7485 returns 1, 2, or 3 depending on which keyword is found, or 0
7486 if the search fails. With the cursor on the first word of the
7487 line:
7488 if (foo == 0) | let foo = foo + 1 | endif ~
7489 the function returns 1. Without the 'c' flag, the function
7490 finds the "endif" and returns 3. The same thing happens
7491 without the 'e' flag if the cursor is on the "f" of "if".
7492 The 'n' flag tells the function not to move the cursor.
7493
7494 Can also be used as a |method|: >
7495 GetPattern()->search()
7496
7497searchcount([{options}]) *searchcount()*
7498 Get or update the last search count, like what is displayed
7499 without the "S" flag in 'shortmess'. This works even if
7500 'shortmess' does contain the "S" flag.
7501
7502 This returns a |Dictionary|. The dictionary is empty if the
7503 previous pattern was not set and "pattern" was not specified.
7504
7505 key type meaning ~
7506 current |Number| current position of match;
7507 0 if the cursor position is
7508 before the first match
7509 exact_match |Boolean| 1 if "current" is matched on
7510 "pos", otherwise 0
7511 total |Number| total count of matches found
7512 incomplete |Number| 0: search was fully completed
7513 1: recomputing was timed out
7514 2: max count exceeded
7515
7516 For {options} see further down.
7517
7518 To get the last search count when |n| or |N| was pressed, call
7519 this function with `recompute: 0` . This sometimes returns
7520 wrong information because |n| and |N|'s maximum count is 99.
7521 If it exceeded 99 the result must be max count + 1 (100). If
7522 you want to get correct information, specify `recompute: 1`: >
7523
7524 " result == maxcount + 1 (100) when many matches
7525 let result = searchcount(#{recompute: 0})
7526
7527 " Below returns correct result (recompute defaults
7528 " to 1)
7529 let result = searchcount()
7530<
Bram Moolenaarb529cfb2022-07-25 15:42:07 +01007531 The function is useful to add the count to 'statusline': >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007532 function! LastSearchCount() abort
7533 let result = searchcount(#{recompute: 0})
7534 if empty(result)
7535 return ''
7536 endif
7537 if result.incomplete ==# 1 " timed out
7538 return printf(' /%s [?/??]', @/)
7539 elseif result.incomplete ==# 2 " max count exceeded
7540 if result.total > result.maxcount &&
7541 \ result.current > result.maxcount
7542 return printf(' /%s [>%d/>%d]', @/,
7543 \ result.current, result.total)
7544 elseif result.total > result.maxcount
7545 return printf(' /%s [%d/>%d]', @/,
7546 \ result.current, result.total)
7547 endif
7548 endif
7549 return printf(' /%s [%d/%d]', @/,
7550 \ result.current, result.total)
7551 endfunction
Bram Moolenaarc51cf032022-02-26 12:25:45 +00007552 let &statusline ..= '%{LastSearchCount()}'
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007553
7554 " Or if you want to show the count only when
7555 " 'hlsearch' was on
Bram Moolenaarc51cf032022-02-26 12:25:45 +00007556 " let &statusline ..=
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007557 " \ '%{v:hlsearch ? LastSearchCount() : ""}'
7558<
7559 You can also update the search count, which can be useful in a
7560 |CursorMoved| or |CursorMovedI| autocommand: >
7561
7562 autocmd CursorMoved,CursorMovedI *
7563 \ let s:searchcount_timer = timer_start(
7564 \ 200, function('s:update_searchcount'))
7565 function! s:update_searchcount(timer) abort
7566 if a:timer ==# s:searchcount_timer
7567 call searchcount(#{
7568 \ recompute: 1, maxcount: 0, timeout: 100})
7569 redrawstatus
7570 endif
7571 endfunction
7572<
7573 This can also be used to count matched texts with specified
7574 pattern in the current buffer using "pattern": >
7575
7576 " Count '\<foo\>' in this buffer
7577 " (Note that it also updates search count)
7578 let result = searchcount(#{pattern: '\<foo\>'})
7579
7580 " To restore old search count by old pattern,
7581 " search again
7582 call searchcount()
7583<
7584 {options} must be a |Dictionary|. It can contain:
7585 key type meaning ~
7586 recompute |Boolean| if |TRUE|, recompute the count
7587 like |n| or |N| was executed.
7588 otherwise returns the last
7589 computed result (when |n| or
7590 |N| was used when "S" is not
7591 in 'shortmess', or this
7592 function was called).
7593 (default: |TRUE|)
7594 pattern |String| recompute if this was given
7595 and different with |@/|.
7596 this works as same as the
7597 below command is executed
7598 before calling this function >
7599 let @/ = pattern
7600< (default: |@/|)
7601 timeout |Number| 0 or negative number is no
7602 timeout. timeout milliseconds
7603 for recomputing the result
7604 (default: 0)
7605 maxcount |Number| 0 or negative number is no
7606 limit. max count of matched
7607 text while recomputing the
7608 result. if search exceeded
7609 total count, "total" value
7610 becomes `maxcount + 1`
7611 (default: 99)
7612 pos |List| `[lnum, col, off]` value
7613 when recomputing the result.
7614 this changes "current" result
7615 value. see |cursor()|,
7616 |getpos()|
7617 (default: cursor's position)
7618
7619 Can also be used as a |method|: >
7620 GetSearchOpts()->searchcount()
7621<
7622searchdecl({name} [, {global} [, {thisblock}]]) *searchdecl()*
7623 Search for the declaration of {name}.
7624
7625 With a non-zero {global} argument it works like |gD|, find
7626 first match in the file. Otherwise it works like |gd|, find
7627 first match in the function.
7628
7629 With a non-zero {thisblock} argument matches in a {} block
7630 that ends before the cursor position are ignored. Avoids
7631 finding variable declarations only valid in another scope.
7632
7633 Moves the cursor to the found match.
7634 Returns zero for success, non-zero for failure.
7635 Example: >
7636 if searchdecl('myvar') == 0
7637 echo getline('.')
7638 endif
7639<
7640 Can also be used as a |method|: >
7641 GetName()->searchdecl()
7642<
7643 *searchpair()*
7644searchpair({start}, {middle}, {end} [, {flags} [, {skip}
7645 [, {stopline} [, {timeout}]]]])
7646 Search for the match of a nested start-end pair. This can be
7647 used to find the "endif" that matches an "if", while other
7648 if/endif pairs in between are ignored.
7649 The search starts at the cursor. The default is to search
7650 forward, include 'b' in {flags} to search backward.
7651 If a match is found, the cursor is positioned at it and the
7652 line number is returned. If no match is found 0 or -1 is
7653 returned and the cursor doesn't move. No error message is
7654 given.
7655
7656 {start}, {middle} and {end} are patterns, see |pattern|. They
7657 must not contain \( \) pairs. Use of \%( \) is allowed. When
7658 {middle} is not empty, it is found when searching from either
7659 direction, but only when not in a nested start-end pair. A
7660 typical use is: >
7661 searchpair('\<if\>', '\<else\>', '\<endif\>')
7662< By leaving {middle} empty the "else" is skipped.
7663
7664 {flags} 'b', 'c', 'n', 's', 'w' and 'W' are used like with
7665 |search()|. Additionally:
7666 'r' Repeat until no more matches found; will find the
7667 outer pair. Implies the 'W' flag.
7668 'm' Return number of matches instead of line number with
7669 the match; will be > 1 when 'r' is used.
7670 Note: it's nearly always a good idea to use the 'W' flag, to
7671 avoid wrapping around the end of the file.
7672
7673 When a match for {start}, {middle} or {end} is found, the
7674 {skip} expression is evaluated with the cursor positioned on
7675 the start of the match. It should return non-zero if this
7676 match is to be skipped. E.g., because it is inside a comment
7677 or a string.
7678 When {skip} is omitted or empty, every match is accepted.
7679 When evaluating {skip} causes an error the search is aborted
7680 and -1 returned.
7681 {skip} can be a string, a lambda, a funcref or a partial.
7682 Anything else makes the function fail.
7683 In a `:def` function when the {skip} argument is a string
7684 constant it is compiled into instructions.
7685
7686 For {stopline} and {timeout} see |search()|.
7687
7688 The value of 'ignorecase' is used. 'magic' is ignored, the
7689 patterns are used like it's on.
7690
7691 The search starts exactly at the cursor. A match with
7692 {start}, {middle} or {end} at the next character, in the
7693 direction of searching, is the first one found. Example: >
7694 if 1
7695 if 2
7696 endif 2
7697 endif 1
7698< When starting at the "if 2", with the cursor on the "i", and
7699 searching forwards, the "endif 2" is found. When starting on
7700 the character just before the "if 2", the "endif 1" will be
7701 found. That's because the "if 2" will be found first, and
7702 then this is considered to be a nested if/endif from "if 2" to
7703 "endif 2".
7704 When searching backwards and {end} is more than one character,
7705 it may be useful to put "\zs" at the end of the pattern, so
7706 that when the cursor is inside a match with the end it finds
7707 the matching start.
7708
7709 Example, to find the "endif" command in a Vim script: >
7710
7711 :echo searchpair('\<if\>', '\<el\%[seif]\>', '\<en\%[dif]\>', 'W',
7712 \ 'getline(".") =~ "^\\s*\""')
7713
7714< The cursor must be at or after the "if" for which a match is
7715 to be found. Note that single-quote strings are used to avoid
7716 having to double the backslashes. The skip expression only
7717 catches comments at the start of a line, not after a command.
7718 Also, a word "en" or "if" halfway a line is considered a
7719 match.
7720 Another example, to search for the matching "{" of a "}": >
7721
7722 :echo searchpair('{', '', '}', 'bW')
7723
7724< This works when the cursor is at or before the "}" for which a
7725 match is to be found. To reject matches that syntax
7726 highlighting recognized as strings: >
7727
7728 :echo searchpair('{', '', '}', 'bW',
7729 \ 'synIDattr(synID(line("."), col("."), 0), "name") =~? "string"')
7730<
7731 *searchpairpos()*
7732searchpairpos({start}, {middle}, {end} [, {flags} [, {skip}
7733 [, {stopline} [, {timeout}]]]])
7734 Same as |searchpair()|, but returns a |List| with the line and
7735 column position of the match. The first element of the |List|
7736 is the line number and the second element is the byte index of
7737 the column position of the match. If no match is found,
7738 returns [0, 0]. >
7739
7740 :let [lnum,col] = searchpairpos('{', '', '}', 'n')
7741<
7742 See |match-parens| for a bigger and more useful example.
7743
7744 *searchpos()*
7745searchpos({pattern} [, {flags} [, {stopline} [, {timeout} [, {skip}]]]])
7746 Same as |search()|, but returns a |List| with the line and
7747 column position of the match. The first element of the |List|
7748 is the line number and the second element is the byte index of
7749 the column position of the match. If no match is found,
7750 returns [0, 0].
7751 Example: >
7752 :let [lnum, col] = searchpos('mypattern', 'n')
7753
7754< When the 'p' flag is given then there is an extra item with
7755 the sub-pattern match number |search()-sub-match|. Example: >
7756 :let [lnum, col, submatch] = searchpos('\(\l\)\|\(\u\)', 'np')
7757< In this example "submatch" is 2 when a lowercase letter is
7758 found |/\l|, 3 when an uppercase letter is found |/\u|.
7759
7760 Can also be used as a |method|: >
7761 GetPattern()->searchpos()
7762
7763server2client({clientid}, {string}) *server2client()*
7764 Send a reply string to {clientid}. The most recent {clientid}
7765 that sent a string can be retrieved with expand("<client>").
7766 {only available when compiled with the |+clientserver| feature}
7767 Returns zero for success, -1 for failure.
7768 Note:
7769 This id has to be stored before the next command can be
7770 received. I.e. before returning from the received command and
7771 before calling any commands that waits for input.
7772 See also |clientserver|.
7773 Example: >
7774 :echo server2client(expand("<client>"), "HELLO")
7775
7776< Can also be used as a |method|: >
7777 GetClientId()->server2client(string)
7778<
7779serverlist() *serverlist()*
7780 Return a list of available server names, one per line.
7781 When there are no servers or the information is not available
7782 an empty string is returned. See also |clientserver|.
7783 {only available when compiled with the |+clientserver| feature}
7784 Example: >
7785 :echo serverlist()
7786<
7787setbufline({buf}, {lnum}, {text}) *setbufline()*
7788 Set line {lnum} to {text} in buffer {buf}. This works like
7789 |setline()| for the specified buffer.
7790
7791 This function works only for loaded buffers. First call
7792 |bufload()| if needed.
7793
7794 To insert lines use |appendbufline()|.
7795 Any text properties in {lnum} are cleared.
7796
7797 {text} can be a string to set one line, or a list of strings
7798 to set multiple lines. If the list extends below the last
7799 line then those lines are added.
7800
7801 For the use of {buf}, see |bufname()| above.
7802
7803 {lnum} is used like with |setline()|.
7804 Use "$" to refer to the last line in buffer {buf}.
7805 When {lnum} is just below the last line the {text} will be
7806 added below the last line.
7807
7808 When {buf} is not a valid buffer, the buffer is not loaded or
7809 {lnum} is not valid then 1 is returned. In |Vim9| script an
7810 error is given.
7811 On success 0 is returned.
7812
7813 Can also be used as a |method|, the base is passed as the
7814 third argument: >
7815 GetText()->setbufline(buf, lnum)
7816
7817setbufvar({buf}, {varname}, {val}) *setbufvar()*
7818 Set option or local variable {varname} in buffer {buf} to
7819 {val}.
7820 This also works for a global or local window option, but it
7821 doesn't work for a global or local window variable.
7822 For a local window option the global value is unchanged.
7823 For the use of {buf}, see |bufname()| above.
7824 The {varname} argument is a string.
7825 Note that the variable name without "b:" must be used.
7826 Examples: >
7827 :call setbufvar(1, "&mod", 1)
7828 :call setbufvar("todo", "myvar", "foobar")
7829< This function is not available in the |sandbox|.
7830
7831 Can also be used as a |method|, the base is passed as the
7832 third argument: >
7833 GetValue()->setbufvar(buf, varname)
7834
7835
7836setcellwidths({list}) *setcellwidths()*
7837 Specify overrides for cell widths of character ranges. This
7838 tells Vim how wide characters are, counted in screen cells.
7839 This overrides 'ambiwidth'. Example: >
7840 setcellwidths([[0xad, 0xad, 1],
7841 \ [0x2194, 0x2199, 2]])
7842
Bram Moolenaarf10911e2022-01-29 22:20:48 +00007843< *E1109* *E1110* *E1111* *E1112* *E1113* *E1114*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007844 The {list} argument is a list of lists with each three
7845 numbers. These three numbers are [low, high, width]. "low"
7846 and "high" can be the same, in which case this refers to one
7847 character. Otherwise it is the range of characters from "low"
7848 to "high" (inclusive). "width" is either 1 or 2, indicating
7849 the character width in screen cells.
7850 An error is given if the argument is invalid, also when a
7851 range overlaps with another.
7852 Only characters with value 0x100 and higher can be used.
7853
7854 If the new value causes 'fillchars' or 'listchars' to become
7855 invalid it is rejected and an error is given.
7856
7857 To clear the overrides pass an empty list: >
7858 setcellwidths([]);
7859< You can use the script $VIMRUNTIME/tools/emoji_list.vim to see
7860 the effect for known emoji characters.
7861
7862setcharpos({expr}, {list}) *setcharpos()*
7863 Same as |setpos()| but uses the specified column number as the
7864 character index instead of the byte index in the line.
7865
7866 Example:
7867 With the text "여보세요" in line 8: >
7868 call setcharpos('.', [0, 8, 4, 0])
7869< positions the cursor on the fourth character '요'. >
7870 call setpos('.', [0, 8, 4, 0])
7871< positions the cursor on the second character '보'.
7872
7873 Can also be used as a |method|: >
7874 GetPosition()->setcharpos('.')
7875
7876setcharsearch({dict}) *setcharsearch()*
7877 Set the current character search information to {dict},
7878 which contains one or more of the following entries:
7879
7880 char character which will be used for a subsequent
7881 |,| or |;| command; an empty string clears the
7882 character search
7883 forward direction of character search; 1 for forward,
7884 0 for backward
7885 until type of character search; 1 for a |t| or |T|
7886 character search, 0 for an |f| or |F|
7887 character search
7888
7889 This can be useful to save/restore a user's character search
7890 from a script: >
7891 :let prevsearch = getcharsearch()
7892 :" Perform a command which clobbers user's search
7893 :call setcharsearch(prevsearch)
7894< Also see |getcharsearch()|.
7895
7896 Can also be used as a |method|: >
7897 SavedSearch()->setcharsearch()
7898
7899setcmdpos({pos}) *setcmdpos()*
7900 Set the cursor position in the command line to byte position
7901 {pos}. The first position is 1.
7902 Use |getcmdpos()| to obtain the current position.
7903 Only works while editing the command line, thus you must use
7904 |c_CTRL-\_e|, |c_CTRL-R_=| or |c_CTRL-R_CTRL-R| with '='. For
7905 |c_CTRL-\_e| and |c_CTRL-R_CTRL-R| with '=' the position is
7906 set after the command line is set to the expression. For
7907 |c_CTRL-R_=| it is set after evaluating the expression but
7908 before inserting the resulting text.
7909 When the number is too big the cursor is put at the end of the
7910 line. A number smaller than one has undefined results.
7911 Returns FALSE when successful, TRUE when not editing the
7912 command line.
7913
7914 Can also be used as a |method|: >
7915 GetPos()->setcmdpos()
7916
7917setcursorcharpos({lnum}, {col} [, {off}]) *setcursorcharpos()*
7918setcursorcharpos({list})
7919 Same as |cursor()| but uses the specified column number as the
7920 character index instead of the byte index in the line.
7921
7922 Example:
7923 With the text "여보세요" in line 4: >
7924 call setcursorcharpos(4, 3)
7925< positions the cursor on the third character '세'. >
7926 call cursor(4, 3)
7927< positions the cursor on the first character '여'.
7928
7929 Can also be used as a |method|: >
7930 GetCursorPos()->setcursorcharpos()
7931
7932
7933setenv({name}, {val}) *setenv()*
7934 Set environment variable {name} to {val}. Example: >
7935 call setenv('HOME', '/home/myhome')
7936
7937< When {val} is |v:null| the environment variable is deleted.
7938 See also |expr-env|.
7939
7940 Can also be used as a |method|, the base is passed as the
7941 second argument: >
7942 GetPath()->setenv('PATH')
7943
7944setfperm({fname}, {mode}) *setfperm()* *chmod*
7945 Set the file permissions for {fname} to {mode}.
7946 {mode} must be a string with 9 characters. It is of the form
7947 "rwxrwxrwx", where each group of "rwx" flags represent, in
7948 turn, the permissions of the owner of the file, the group the
7949 file belongs to, and other users. A '-' character means the
7950 permission is off, any other character means on. Multi-byte
7951 characters are not supported.
7952
7953 For example "rw-r-----" means read-write for the user,
7954 readable by the group, not accessible by others. "xx-x-----"
7955 would do the same thing.
7956
7957 Returns non-zero for success, zero for failure.
7958
7959 Can also be used as a |method|: >
7960 GetFilename()->setfperm(mode)
7961<
7962 To read permissions see |getfperm()|.
7963
7964
7965setline({lnum}, {text}) *setline()*
7966 Set line {lnum} of the current buffer to {text}. To insert
7967 lines use |append()|. To set lines in another buffer use
7968 |setbufline()|. Any text properties in {lnum} are cleared.
7969
7970 {lnum} is used like with |getline()|.
7971 When {lnum} is just below the last line the {text} will be
7972 added below the last line.
7973 {text} can be any type or a List of any type, each item is
7974 converted to a String.
7975
7976 If this succeeds, FALSE is returned. If this fails (most likely
7977 because {lnum} is invalid) TRUE is returned.
7978 In |Vim9| script an error is given if {lnum} is invalid.
7979
7980 Example: >
7981 :call setline(5, strftime("%c"))
7982
7983< When {text} is a |List| then line {lnum} and following lines
7984 will be set to the items in the list. Example: >
7985 :call setline(5, ['aaa', 'bbb', 'ccc'])
7986< This is equivalent to: >
7987 :for [n, l] in [[5, 'aaa'], [6, 'bbb'], [7, 'ccc']]
7988 : call setline(n, l)
7989 :endfor
7990
7991< Note: The '[ and '] marks are not set.
7992
7993 Can also be used as a |method|, the base is passed as the
7994 second argument: >
7995 GetText()->setline(lnum)
7996
7997setloclist({nr}, {list} [, {action} [, {what}]]) *setloclist()*
7998 Create or replace or add to the location list for window {nr}.
7999 {nr} can be the window number or the |window-ID|.
8000 When {nr} is zero the current window is used.
8001
8002 For a location list window, the displayed location list is
8003 modified. For an invalid window number {nr}, -1 is returned.
8004 Otherwise, same as |setqflist()|.
8005 Also see |location-list|.
8006
8007 For {action} see |setqflist-action|.
8008
8009 If the optional {what} dictionary argument is supplied, then
8010 only the items listed in {what} are set. Refer to |setqflist()|
8011 for the list of supported keys in {what}.
8012
8013 Can also be used as a |method|, the base is passed as the
8014 second argument: >
8015 GetLoclist()->setloclist(winnr)
8016
8017setmatches({list} [, {win}]) *setmatches()*
8018 Restores a list of matches saved by |getmatches()| for the
8019 current window. Returns 0 if successful, otherwise -1. All
8020 current matches are cleared before the list is restored. See
8021 example for |getmatches()|.
8022 If {win} is specified, use the window with this number or
8023 window ID instead of the current window.
8024
8025 Can also be used as a |method|: >
8026 GetMatches()->setmatches()
8027<
8028 *setpos()*
8029setpos({expr}, {list})
8030 Set the position for String {expr}. Possible values:
8031 . the cursor
8032 'x mark x
8033
8034 {list} must be a |List| with four or five numbers:
8035 [bufnum, lnum, col, off]
8036 [bufnum, lnum, col, off, curswant]
8037
8038 "bufnum" is the buffer number. Zero can be used for the
8039 current buffer. When setting an uppercase mark "bufnum" is
8040 used for the mark position. For other marks it specifies the
8041 buffer to set the mark in. You can use the |bufnr()| function
8042 to turn a file name into a buffer number.
8043 For setting the cursor and the ' mark "bufnum" is ignored,
8044 since these are associated with a window, not a buffer.
8045 Does not change the jumplist.
8046
8047 "lnum" and "col" are the position in the buffer. The first
8048 column is 1. Use a zero "lnum" to delete a mark. If "col" is
8049 smaller than 1 then 1 is used. To use the character count
8050 instead of the byte count, use |setcharpos()|.
8051
8052 The "off" number is only used when 'virtualedit' is set. Then
8053 it is the offset in screen columns from the start of the
8054 character. E.g., a position within a <Tab> or after the last
8055 character.
8056
8057 The "curswant" number is only used when setting the cursor
8058 position. It sets the preferred column for when moving the
8059 cursor vertically. When the "curswant" number is missing the
8060 preferred column is not set. When it is present and setting a
8061 mark position it is not used.
8062
8063 Note that for '< and '> changing the line number may result in
8064 the marks to be effectively be swapped, so that '< is always
8065 before '>.
8066
8067 Returns 0 when the position could be set, -1 otherwise.
8068 An error message is given if {expr} is invalid.
8069
8070 Also see |setcharpos()|, |getpos()| and |getcurpos()|.
8071
8072 This does not restore the preferred column for moving
8073 vertically; if you set the cursor position with this, |j| and
8074 |k| motions will jump to previous columns! Use |cursor()| to
8075 also set the preferred column. Also see the "curswant" key in
8076 |winrestview()|.
8077
8078 Can also be used as a |method|: >
8079 GetPosition()->setpos('.')
8080
8081setqflist({list} [, {action} [, {what}]]) *setqflist()*
8082 Create or replace or add to the quickfix list.
8083
8084 If the optional {what} dictionary argument is supplied, then
8085 only the items listed in {what} are set. The first {list}
8086 argument is ignored. See below for the supported items in
8087 {what}.
8088 *setqflist-what*
8089 When {what} is not present, the items in {list} are used. Each
8090 item must be a dictionary. Non-dictionary items in {list} are
8091 ignored. Each dictionary item can contain the following
8092 entries:
8093
8094 bufnr buffer number; must be the number of a valid
8095 buffer
8096 filename name of a file; only used when "bufnr" is not
8097 present or it is invalid.
8098 module name of a module; if given it will be used in
8099 quickfix error window instead of the filename.
8100 lnum line number in the file
Bram Moolenaara2baa732022-02-04 16:09:54 +00008101 end_lnum end of lines, if the item spans multiple lines
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008102 pattern search pattern used to locate the error
8103 col column number
8104 vcol when non-zero: "col" is visual column
8105 when zero: "col" is byte index
Bram Moolenaara2baa732022-02-04 16:09:54 +00008106 end_col end column, if the item spans multiple columns
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008107 nr error number
8108 text description of the error
8109 type single-character error type, 'E', 'W', etc.
8110 valid recognized error message
8111
8112 The "col", "vcol", "nr", "type" and "text" entries are
8113 optional. Either "lnum" or "pattern" entry can be used to
8114 locate a matching error line.
8115 If the "filename" and "bufnr" entries are not present or
8116 neither the "lnum" or "pattern" entries are present, then the
8117 item will not be handled as an error line.
8118 If both "pattern" and "lnum" are present then "pattern" will
8119 be used.
8120 If the "valid" entry is not supplied, then the valid flag is
8121 set when "bufnr" is a valid buffer or "filename" exists.
8122 If you supply an empty {list}, the quickfix list will be
8123 cleared.
8124 Note that the list is not exactly the same as what
8125 |getqflist()| returns.
8126
8127 {action} values: *setqflist-action* *E927*
8128 'a' The items from {list} are added to the existing
8129 quickfix list. If there is no existing list, then a
8130 new list is created.
8131
8132 'r' The items from the current quickfix list are replaced
8133 with the items from {list}. This can also be used to
8134 clear the list: >
8135 :call setqflist([], 'r')
8136<
8137 'f' All the quickfix lists in the quickfix stack are
8138 freed.
8139
8140 If {action} is not present or is set to ' ', then a new list
8141 is created. The new quickfix list is added after the current
8142 quickfix list in the stack and all the following lists are
8143 freed. To add a new quickfix list at the end of the stack,
8144 set "nr" in {what} to "$".
8145
8146 The following items can be specified in dictionary {what}:
8147 context quickfix list context. See |quickfix-context|
8148 efm errorformat to use when parsing text from
8149 "lines". If this is not present, then the
8150 'errorformat' option value is used.
8151 See |quickfix-parse|
8152 id quickfix list identifier |quickfix-ID|
8153 idx index of the current entry in the quickfix
8154 list specified by 'id' or 'nr'. If set to '$',
8155 then the last entry in the list is set as the
8156 current entry. See |quickfix-index|
8157 items list of quickfix entries. Same as the {list}
8158 argument.
8159 lines use 'errorformat' to parse a list of lines and
8160 add the resulting entries to the quickfix list
8161 {nr} or {id}. Only a |List| value is supported.
8162 See |quickfix-parse|
8163 nr list number in the quickfix stack; zero
8164 means the current quickfix list and "$" means
8165 the last quickfix list.
8166 quickfixtextfunc
8167 function to get the text to display in the
8168 quickfix window. The value can be the name of
8169 a function or a funcref or a lambda. Refer to
8170 |quickfix-window-function| for an explanation
8171 of how to write the function and an example.
8172 title quickfix list title text. See |quickfix-title|
8173 Unsupported keys in {what} are ignored.
8174 If the "nr" item is not present, then the current quickfix list
8175 is modified. When creating a new quickfix list, "nr" can be
8176 set to a value one greater than the quickfix stack size.
8177 When modifying a quickfix list, to guarantee that the correct
8178 list is modified, "id" should be used instead of "nr" to
8179 specify the list.
8180
8181 Examples (See also |setqflist-examples|): >
8182 :call setqflist([], 'r', {'title': 'My search'})
8183 :call setqflist([], 'r', {'nr': 2, 'title': 'Errors'})
8184 :call setqflist([], 'a', {'id':qfid, 'lines':["F1:10:L10"]})
8185<
8186 Returns zero for success, -1 for failure.
8187
8188 This function can be used to create a quickfix list
8189 independent of the 'errorformat' setting. Use a command like
8190 `:cc 1` to jump to the first position.
8191
8192 Can also be used as a |method|, the base is passed as the
8193 second argument: >
8194 GetErrorlist()->setqflist()
8195<
8196 *setreg()*
8197setreg({regname}, {value} [, {options}])
8198 Set the register {regname} to {value}.
8199 If {regname} is "" or "@", the unnamed register '"' is used.
8200 The {regname} argument is a string. In |Vim9-script|
8201 {regname} must be one character.
8202
8203 {value} may be any value returned by |getreg()| or
8204 |getreginfo()|, including a |List| or |Dict|.
8205 If {options} contains "a" or {regname} is upper case,
8206 then the value is appended.
8207
8208 {options} can also contain a register type specification:
8209 "c" or "v" |characterwise| mode
8210 "l" or "V" |linewise| mode
8211 "b" or "<CTRL-V>" |blockwise-visual| mode
8212 If a number immediately follows "b" or "<CTRL-V>" then this is
8213 used as the width of the selection - if it is not specified
8214 then the width of the block is set to the number of characters
8215 in the longest line (counting a <Tab> as 1 character).
8216
8217 If {options} contains no register settings, then the default
8218 is to use character mode unless {value} ends in a <NL> for
8219 string {value} and linewise mode for list {value}. Blockwise
8220 mode is never selected automatically.
8221 Returns zero for success, non-zero for failure.
8222
8223 *E883*
8224 Note: you may not use |List| containing more than one item to
8225 set search and expression registers. Lists containing no
8226 items act like empty strings.
8227
8228 Examples: >
8229 :call setreg(v:register, @*)
8230 :call setreg('*', @%, 'ac')
8231 :call setreg('a', "1\n2\n3", 'b5')
8232 :call setreg('"', { 'points_to': 'a'})
8233
8234< This example shows using the functions to save and restore a
8235 register: >
8236 :let var_a = getreginfo()
8237 :call setreg('a', var_a)
8238< or: >
8239 :let var_a = getreg('a', 1, 1)
8240 :let var_amode = getregtype('a')
8241 ....
8242 :call setreg('a', var_a, var_amode)
8243< Note: you may not reliably restore register value
8244 without using the third argument to |getreg()| as without it
8245 newlines are represented as newlines AND Nul bytes are
8246 represented as newlines as well, see |NL-used-for-Nul|.
8247
8248 You can also change the type of a register by appending
8249 nothing: >
8250 :call setreg('a', '', 'al')
8251
8252< Can also be used as a |method|, the base is passed as the
8253 second argument: >
8254 GetText()->setreg('a')
8255
8256settabvar({tabnr}, {varname}, {val}) *settabvar()*
8257 Set tab-local variable {varname} to {val} in tab page {tabnr}.
8258 |t:var|
8259 The {varname} argument is a string.
8260 Note that autocommands are blocked, side effects may not be
8261 triggered, e.g. when setting 'filetype'.
8262 Note that the variable name without "t:" must be used.
8263 Tabs are numbered starting with one.
8264 This function is not available in the |sandbox|.
8265
8266 Can also be used as a |method|, the base is passed as the
8267 third argument: >
8268 GetValue()->settabvar(tab, name)
8269
8270settabwinvar({tabnr}, {winnr}, {varname}, {val}) *settabwinvar()*
8271 Set option or local variable {varname} in window {winnr} to
8272 {val}.
8273 Tabs are numbered starting with one. For the current tabpage
8274 use |setwinvar()|.
8275 {winnr} can be the window number or the |window-ID|.
8276 When {winnr} is zero the current window is used.
8277 Note that autocommands are blocked, side effects may not be
8278 triggered, e.g. when setting 'filetype' or 'syntax'.
8279 This also works for a global or local buffer option, but it
8280 doesn't work for a global or local buffer variable.
8281 For a local buffer option the global value is unchanged.
8282 Note that the variable name without "w:" must be used.
8283 Examples: >
8284 :call settabwinvar(1, 1, "&list", 0)
8285 :call settabwinvar(3, 2, "myvar", "foobar")
8286< This function is not available in the |sandbox|.
8287
8288 Can also be used as a |method|, the base is passed as the
8289 fourth argument: >
8290 GetValue()->settabwinvar(tab, winnr, name)
8291
8292settagstack({nr}, {dict} [, {action}]) *settagstack()*
8293 Modify the tag stack of the window {nr} using {dict}.
8294 {nr} can be the window number or the |window-ID|.
8295
8296 For a list of supported items in {dict}, refer to
8297 |gettagstack()|. "curidx" takes effect before changing the tag
8298 stack.
8299 *E962*
8300 How the tag stack is modified depends on the {action}
8301 argument:
8302 - If {action} is not present or is set to 'r', then the tag
8303 stack is replaced.
8304 - If {action} is set to 'a', then new entries from {dict} are
8305 pushed (added) onto the tag stack.
8306 - If {action} is set to 't', then all the entries from the
8307 current entry in the tag stack or "curidx" in {dict} are
8308 removed and then new entries are pushed to the stack.
8309
8310 The current index is set to one after the length of the tag
8311 stack after the modification.
8312
8313 Returns zero for success, -1 for failure.
8314
8315 Examples (for more examples see |tagstack-examples|):
8316 Empty the tag stack of window 3: >
8317 call settagstack(3, {'items' : []})
8318
8319< Save and restore the tag stack: >
8320 let stack = gettagstack(1003)
8321 " do something else
8322 call settagstack(1003, stack)
8323 unlet stack
8324<
8325 Can also be used as a |method|, the base is passed as the
8326 second argument: >
8327 GetStack()->settagstack(winnr)
8328
8329setwinvar({winnr}, {varname}, {val}) *setwinvar()*
8330 Like |settabwinvar()| for the current tab page.
8331 Examples: >
8332 :call setwinvar(1, "&list", 0)
8333 :call setwinvar(2, "myvar", "foobar")
8334
8335< Can also be used as a |method|, the base is passed as the
8336 third argument: >
8337 GetValue()->setwinvar(winnr, name)
8338
8339sha256({string}) *sha256()*
8340 Returns a String with 64 hex characters, which is the SHA256
8341 checksum of {string}.
8342
8343 Can also be used as a |method|: >
8344 GetText()->sha256()
8345
8346< {only available when compiled with the |+cryptv| feature}
8347
8348shellescape({string} [, {special}]) *shellescape()*
8349 Escape {string} for use as a shell command argument.
8350 When the 'shell' contains powershell (MS-Windows) or pwsh
Bram Moolenaar944697a2022-02-20 19:48:20 +00008351 (MS-Windows, Linux, and macOS) then it will enclose {string}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008352 in single quotes and will double up all internal single
8353 quotes.
8354 On MS-Windows, when 'shellslash' is not set, it will enclose
8355 {string} in double quotes and double all double quotes within
8356 {string}.
8357 Otherwise it will enclose {string} in single quotes and
8358 replace all "'" with "'\''".
8359
8360 When the {special} argument is present and it's a non-zero
8361 Number or a non-empty String (|non-zero-arg|), then special
8362 items such as "!", "%", "#" and "<cword>" will be preceded by
8363 a backslash. This backslash will be removed again by the |:!|
8364 command.
8365
8366 The "!" character will be escaped (again with a |non-zero-arg|
8367 {special}) when 'shell' contains "csh" in the tail. That is
8368 because for csh and tcsh "!" is used for history replacement
8369 even when inside single quotes.
8370
8371 With a |non-zero-arg| {special} the <NL> character is also
8372 escaped. When 'shell' containing "csh" in the tail it's
8373 escaped a second time.
8374
8375 The "\" character will be escaped when 'shell' contains "fish"
8376 in the tail. That is because for fish "\" is used as an escape
8377 character inside single quotes.
8378
8379 Example of use with a |:!| command: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00008380 :exe '!dir ' .. shellescape(expand('<cfile>'), 1)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008381< This results in a directory listing for the file under the
8382 cursor. Example of use with |system()|: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00008383 :call system("chmod +w -- " .. shellescape(expand("%")))
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008384< See also |::S|.
8385
8386 Can also be used as a |method|: >
8387 GetCommand()->shellescape()
8388
8389shiftwidth([{col}]) *shiftwidth()*
8390 Returns the effective value of 'shiftwidth'. This is the
8391 'shiftwidth' value unless it is zero, in which case it is the
8392 'tabstop' value. This function was introduced with patch
8393 7.3.694 in 2012, everybody should have it by now (however it
8394 did not allow for the optional {col} argument until 8.1.542).
8395
8396 When there is one argument {col} this is used as column number
8397 for which to return the 'shiftwidth' value. This matters for the
8398 'vartabstop' feature. If the 'vartabstop' setting is enabled and
8399 no {col} argument is given, column 1 will be assumed.
8400
8401 Can also be used as a |method|: >
8402 GetColumn()->shiftwidth()
8403
8404sign_ functions are documented here: |sign-functions-details|
8405
8406
8407simplify({filename}) *simplify()*
8408 Simplify the file name as much as possible without changing
8409 the meaning. Shortcuts (on MS-Windows) or symbolic links (on
8410 Unix) are not resolved. If the first path component in
8411 {filename} designates the current directory, this will be
8412 valid for the result as well. A trailing path separator is
8413 not removed either. On Unix "//path" is unchanged, but
8414 "///path" is simplified to "/path" (this follows the Posix
8415 standard).
8416 Example: >
8417 simplify("./dir/.././/file/") == "./file/"
8418< Note: The combination "dir/.." is only removed if "dir" is
8419 a searchable directory or does not exist. On Unix, it is also
8420 removed when "dir" is a symbolic link within the same
8421 directory. In order to resolve all the involved symbolic
8422 links before simplifying the path name, use |resolve()|.
8423
8424 Can also be used as a |method|: >
8425 GetName()->simplify()
8426
8427sin({expr}) *sin()*
8428 Return the sine of {expr}, measured in radians, as a |Float|.
8429 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01008430 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008431 Examples: >
8432 :echo sin(100)
8433< -0.506366 >
8434 :echo sin(-4.01)
8435< 0.763301
8436
8437 Can also be used as a |method|: >
8438 Compute()->sin()
8439<
8440 {only available when compiled with the |+float| feature}
8441
8442
8443sinh({expr}) *sinh()*
8444 Return the hyperbolic sine of {expr} as a |Float| in the range
8445 [-inf, inf].
8446 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01008447 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008448 Examples: >
8449 :echo sinh(0.5)
8450< 0.521095 >
8451 :echo sinh(-0.9)
8452< -1.026517
8453
8454 Can also be used as a |method|: >
8455 Compute()->sinh()
8456<
8457 {only available when compiled with the |+float| feature}
8458
8459
8460slice({expr}, {start} [, {end}]) *slice()*
8461 Similar to using a |slice| "expr[start : end]", but "end" is
8462 used exclusive. And for a string the indexes are used as
8463 character indexes instead of byte indexes, like in
8464 |vim9script|. Also, composing characters are not counted.
8465 When {end} is omitted the slice continues to the last item.
8466 When {end} is -1 the last item is omitted.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01008467 Returns an empty value if {start} or {end} are invalid.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008468
8469 Can also be used as a |method|: >
8470 GetList()->slice(offset)
8471
8472
Bram Moolenaar2007dd42022-02-23 13:17:47 +00008473sort({list} [, {how} [, {dict}]]) *sort()* *E702*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008474 Sort the items in {list} in-place. Returns {list}.
8475
8476 If you want a list to remain unmodified make a copy first: >
8477 :let sortedlist = sort(copy(mylist))
8478
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01008479< When {how} is omitted or is a string, then sort() uses the
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008480 string representation of each item to sort on. Numbers sort
8481 after Strings, |Lists| after Numbers. For sorting text in the
8482 current buffer use |:sort|.
8483
Bram Moolenaar2007dd42022-02-23 13:17:47 +00008484 When {how} is given and it is 'i' then case is ignored.
8485 In legacy script, for backwards compatibility, the value one
8486 can be used to ignore case. Zero means to not ignore case.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008487
Bram Moolenaar2007dd42022-02-23 13:17:47 +00008488 When {how} is given and it is 'l' then the current collation
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008489 locale is used for ordering. Implementation details: strcoll()
8490 is used to compare strings. See |:language| check or set the
8491 collation locale. |v:collate| can also be used to check the
8492 current locale. Sorting using the locale typically ignores
8493 case. Example: >
8494 " ö is sorted similarly to o with English locale.
8495 :language collate en_US.UTF8
8496 :echo sort(['n', 'o', 'O', 'ö', 'p', 'z'], 'l')
8497< ['n', 'o', 'O', 'ö', 'p', 'z'] ~
8498>
8499 " ö is sorted after z with Swedish locale.
8500 :language collate sv_SE.UTF8
8501 :echo sort(['n', 'o', 'O', 'ö', 'p', 'z'], 'l')
8502< ['n', 'o', 'O', 'p', 'z', 'ö'] ~
8503 This does not work properly on Mac.
8504
Bram Moolenaar2007dd42022-02-23 13:17:47 +00008505 When {how} is given and it is 'n' then all items will be
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008506 sorted numerical (Implementation detail: this uses the
8507 strtod() function to parse numbers, Strings, Lists, Dicts and
8508 Funcrefs will be considered as being 0).
8509
Bram Moolenaar2007dd42022-02-23 13:17:47 +00008510 When {how} is given and it is 'N' then all items will be
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008511 sorted numerical. This is like 'n' but a string containing
8512 digits will be used as the number they represent.
8513
Bram Moolenaar2007dd42022-02-23 13:17:47 +00008514 When {how} is given and it is 'f' then all items will be
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008515 sorted numerical. All values must be a Number or a Float.
8516
Bram Moolenaar2007dd42022-02-23 13:17:47 +00008517 When {how} is a |Funcref| or a function name, this function
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008518 is called to compare items. The function is invoked with two
8519 items as argument and must return zero if they are equal, 1 or
8520 bigger if the first one sorts after the second one, -1 or
8521 smaller if the first one sorts before the second one.
8522
8523 {dict} is for functions with the "dict" attribute. It will be
8524 used to set the local variable "self". |Dictionary-function|
8525
8526 The sort is stable, items which compare equal (as number or as
8527 string) will keep their relative position. E.g., when sorting
8528 on numbers, text strings will sort next to each other, in the
8529 same order as they were originally.
8530
8531 Can also be used as a |method|: >
8532 mylist->sort()
8533
8534< Also see |uniq()|.
8535
8536 Example: >
8537 func MyCompare(i1, i2)
8538 return a:i1 == a:i2 ? 0 : a:i1 > a:i2 ? 1 : -1
8539 endfunc
8540 eval mylist->sort("MyCompare")
8541< A shorter compare version for this specific simple case, which
8542 ignores overflow: >
8543 func MyCompare(i1, i2)
8544 return a:i1 - a:i2
8545 endfunc
8546< For a simple expression you can use a lambda: >
8547 eval mylist->sort({i1, i2 -> i1 - i2})
8548<
8549sound_clear() *sound_clear()*
8550 Stop playing all sounds.
8551
8552 On some Linux systems you may need the libcanberra-pulse
8553 package, otherwise sound may not stop.
8554
8555 {only available when compiled with the |+sound| feature}
8556
8557 *sound_playevent()*
8558sound_playevent({name} [, {callback}])
8559 Play a sound identified by {name}. Which event names are
8560 supported depends on the system. Often the XDG sound names
8561 are used. On Ubuntu they may be found in
8562 /usr/share/sounds/freedesktop/stereo. Example: >
8563 call sound_playevent('bell')
8564< On MS-Windows, {name} can be SystemAsterisk, SystemDefault,
8565 SystemExclamation, SystemExit, SystemHand, SystemQuestion,
8566 SystemStart, SystemWelcome, etc.
8567
8568 When {callback} is specified it is invoked when the sound is
8569 finished. The first argument is the sound ID, the second
8570 argument is the status:
8571 0 sound was played to the end
8572 1 sound was interrupted
8573 2 error occurred after sound started
8574 Example: >
8575 func Callback(id, status)
8576 echomsg "sound " .. a:id .. " finished with " .. a:status
8577 endfunc
8578 call sound_playevent('bell', 'Callback')
8579
8580< MS-Windows: {callback} doesn't work for this function.
8581
8582 Returns the sound ID, which can be passed to `sound_stop()`.
8583 Returns zero if the sound could not be played.
8584
8585 Can also be used as a |method|: >
8586 GetSoundName()->sound_playevent()
8587
8588< {only available when compiled with the |+sound| feature}
8589
8590 *sound_playfile()*
8591sound_playfile({path} [, {callback}])
8592 Like `sound_playevent()` but play sound file {path}. {path}
8593 must be a full path. On Ubuntu you may find files to play
8594 with this command: >
8595 :!find /usr/share/sounds -type f | grep -v index.theme
8596
8597< Can also be used as a |method|: >
8598 GetSoundPath()->sound_playfile()
8599
Bram Moolenaar1588bc82022-03-08 21:35:07 +00008600< {only available when compiled with the |+sound| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008601
8602
8603sound_stop({id}) *sound_stop()*
8604 Stop playing sound {id}. {id} must be previously returned by
8605 `sound_playevent()` or `sound_playfile()`.
8606
8607 On some Linux systems you may need the libcanberra-pulse
8608 package, otherwise sound may not stop.
8609
8610 On MS-Windows, this does not work for event sound started by
8611 `sound_playevent()`. To stop event sounds, use `sound_clear()`.
8612
8613 Can also be used as a |method|: >
8614 soundid->sound_stop()
8615
8616< {only available when compiled with the |+sound| feature}
8617
8618 *soundfold()*
8619soundfold({word})
8620 Return the sound-folded equivalent of {word}. Uses the first
8621 language in 'spelllang' for the current window that supports
8622 soundfolding. 'spell' must be set. When no sound folding is
8623 possible the {word} is returned unmodified.
8624 This can be used for making spelling suggestions. Note that
8625 the method can be quite slow.
8626
8627 Can also be used as a |method|: >
8628 GetWord()->soundfold()
8629<
8630 *spellbadword()*
8631spellbadword([{sentence}])
8632 Without argument: The result is the badly spelled word under
8633 or after the cursor. The cursor is moved to the start of the
8634 bad word. When no bad word is found in the cursor line the
8635 result is an empty string and the cursor doesn't move.
8636
8637 With argument: The result is the first word in {sentence} that
8638 is badly spelled. If there are no spelling mistakes the
8639 result is an empty string.
8640
8641 The return value is a list with two items:
8642 - The badly spelled word or an empty string.
8643 - The type of the spelling error:
8644 "bad" spelling mistake
8645 "rare" rare word
8646 "local" word only valid in another region
8647 "caps" word should start with Capital
8648 Example: >
8649 echo spellbadword("the quik brown fox")
8650< ['quik', 'bad'] ~
8651
8652 The spelling information for the current window and the value
8653 of 'spelllang' are used.
8654
8655 Can also be used as a |method|: >
8656 GetText()->spellbadword()
8657<
8658 *spellsuggest()*
8659spellsuggest({word} [, {max} [, {capital}]])
8660 Return a |List| with spelling suggestions to replace {word}.
8661 When {max} is given up to this number of suggestions are
8662 returned. Otherwise up to 25 suggestions are returned.
8663
8664 When the {capital} argument is given and it's non-zero only
8665 suggestions with a leading capital will be given. Use this
8666 after a match with 'spellcapcheck'.
8667
8668 {word} can be a badly spelled word followed by other text.
8669 This allows for joining two words that were split. The
8670 suggestions also include the following text, thus you can
8671 replace a line.
8672
8673 {word} may also be a good word. Similar words will then be
8674 returned. {word} itself is not included in the suggestions,
8675 although it may appear capitalized.
8676
8677 The spelling information for the current window is used. The
8678 values of 'spelllang' and 'spellsuggest' are used.
8679
8680 Can also be used as a |method|: >
8681 GetWord()->spellsuggest()
8682
8683split({string} [, {pattern} [, {keepempty}]]) *split()*
8684 Make a |List| out of {string}. When {pattern} is omitted or
8685 empty each white-separated sequence of characters becomes an
8686 item.
8687 Otherwise the string is split where {pattern} matches,
8688 removing the matched characters. 'ignorecase' is not used
8689 here, add \c to ignore case. |/\c|
8690 When the first or last item is empty it is omitted, unless the
8691 {keepempty} argument is given and it's non-zero.
8692 Other empty items are kept when {pattern} matches at least one
8693 character or when {keepempty} is non-zero.
8694 Example: >
8695 :let words = split(getline('.'), '\W\+')
8696< To split a string in individual characters: >
8697 :for c in split(mystring, '\zs')
8698< If you want to keep the separator you can also use '\zs' at
8699 the end of the pattern: >
8700 :echo split('abc:def:ghi', ':\zs')
8701< ['abc:', 'def:', 'ghi'] ~
8702 Splitting a table where the first element can be empty: >
8703 :let items = split(line, ':', 1)
8704< The opposite function is |join()|.
8705
8706 Can also be used as a |method|: >
8707 GetString()->split()
8708
8709sqrt({expr}) *sqrt()*
8710 Return the non-negative square root of Float {expr} as a
8711 |Float|.
8712 {expr} must evaluate to a |Float| or a |Number|. When {expr}
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01008713 is negative the result is NaN (Not a Number). Returns 0.0 if
8714 {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008715 Examples: >
8716 :echo sqrt(100)
8717< 10.0 >
8718 :echo sqrt(-4.01)
8719< nan
8720 "nan" may be different, it depends on system libraries.
8721
8722 Can also be used as a |method|: >
8723 Compute()->sqrt()
8724<
8725 {only available when compiled with the |+float| feature}
8726
8727
8728srand([{expr}]) *srand()*
8729 Initialize seed used by |rand()|:
8730 - If {expr} is not given, seed values are initialized by
8731 reading from /dev/urandom, if possible, or using time(NULL)
8732 a.k.a. epoch time otherwise; this only has second accuracy.
8733 - If {expr} is given it must be a Number. It is used to
8734 initialize the seed values. This is useful for testing or
8735 when a predictable sequence is intended.
8736
8737 Examples: >
8738 :let seed = srand()
8739 :let seed = srand(userinput)
8740 :echo rand(seed)
8741
8742state([{what}]) *state()*
8743 Return a string which contains characters indicating the
8744 current state. Mostly useful in callbacks that want to do
8745 work that may not always be safe. Roughly this works like:
8746 - callback uses state() to check if work is safe to do.
8747 Yes: then do it right away.
8748 No: add to work queue and add a |SafeState| and/or
8749 |SafeStateAgain| autocommand (|SafeState| triggers at
8750 toplevel, |SafeStateAgain| triggers after handling
8751 messages and callbacks).
8752 - When SafeState or SafeStateAgain is triggered and executes
8753 your autocommand, check with `state()` if the work can be
8754 done now, and if yes remove it from the queue and execute.
8755 Remove the autocommand if the queue is now empty.
8756 Also see |mode()|.
8757
8758 When {what} is given only characters in this string will be
8759 added. E.g, this checks if the screen has scrolled: >
8760 if state('s') == ''
8761 " screen has not scrolled
8762<
8763 These characters indicate the state, generally indicating that
8764 something is busy:
8765 m halfway a mapping, :normal command, feedkeys() or
8766 stuffed command
8767 o operator pending, e.g. after |d|
8768 a Insert mode autocomplete active
8769 x executing an autocommand
8770 w blocked on waiting, e.g. ch_evalexpr(), ch_read() and
8771 ch_readraw() when reading json
8772 S not triggering SafeState or SafeStateAgain, e.g. after
8773 |f| or a count
8774 c callback invoked, including timer (repeats for
8775 recursiveness up to "ccc")
8776 s screen has scrolled for messages
8777
8778str2float({string} [, {quoted}]) *str2float()*
8779 Convert String {string} to a Float. This mostly works the
8780 same as when using a floating point number in an expression,
8781 see |floating-point-format|. But it's a bit more permissive.
8782 E.g., "1e40" is accepted, while in an expression you need to
8783 write "1.0e40". The hexadecimal form "0x123" is also
8784 accepted, but not others, like binary or octal.
8785 When {quoted} is present and non-zero then embedded single
8786 quotes before the dot are ignored, thus "1'000.0" is a
8787 thousand.
8788 Text after the number is silently ignored.
8789 The decimal point is always '.', no matter what the locale is
8790 set to. A comma ends the number: "12,345.67" is converted to
8791 12.0. You can strip out thousands separators with
8792 |substitute()|: >
8793 let f = str2float(substitute(text, ',', '', 'g'))
8794<
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01008795 Returns 0.0 if the conversion fails.
8796
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008797 Can also be used as a |method|: >
8798 let f = text->substitute(',', '', 'g')->str2float()
8799<
8800 {only available when compiled with the |+float| feature}
8801
8802str2list({string} [, {utf8}]) *str2list()*
8803 Return a list containing the number values which represent
8804 each character in String {string}. Examples: >
8805 str2list(" ") returns [32]
8806 str2list("ABC") returns [65, 66, 67]
8807< |list2str()| does the opposite.
8808
8809 When {utf8} is omitted or zero, the current 'encoding' is used.
8810 When {utf8} is TRUE, always treat the String as UTF-8
8811 characters. With UTF-8 composing characters are handled
8812 properly: >
8813 str2list("á") returns [97, 769]
8814
8815< Can also be used as a |method|: >
8816 GetString()->str2list()
8817
8818
8819str2nr({string} [, {base} [, {quoted}]]) *str2nr()*
8820 Convert string {string} to a number.
8821 {base} is the conversion base, it can be 2, 8, 10 or 16.
8822 When {quoted} is present and non-zero then embedded single
8823 quotes are ignored, thus "1'000'000" is a million.
8824
8825 When {base} is omitted base 10 is used. This also means that
8826 a leading zero doesn't cause octal conversion to be used, as
8827 with the default String to Number conversion. Example: >
8828 let nr = str2nr('0123')
8829<
8830 When {base} is 16 a leading "0x" or "0X" is ignored. With a
8831 different base the result will be zero. Similarly, when
8832 {base} is 8 a leading "0", "0o" or "0O" is ignored, and when
8833 {base} is 2 a leading "0b" or "0B" is ignored.
8834 Text after the number is silently ignored.
8835
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01008836 Returns 0 if {string} is empty or on error.
8837
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008838 Can also be used as a |method|: >
8839 GetText()->str2nr()
8840
8841
8842strcharlen({string}) *strcharlen()*
8843 The result is a Number, which is the number of characters
8844 in String {string}. Composing characters are ignored.
8845 |strchars()| can count the number of characters, counting
8846 composing characters separately.
8847
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01008848 Returns 0 if {string} is empty or on error.
8849
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008850 Also see |strlen()|, |strdisplaywidth()| and |strwidth()|.
8851
8852 Can also be used as a |method|: >
8853 GetText()->strcharlen()
8854
8855
8856strcharpart({src}, {start} [, {len} [, {skipcc}]]) *strcharpart()*
8857 Like |strpart()| but using character index and length instead
8858 of byte index and length.
8859 When {skipcc} is omitted or zero, composing characters are
8860 counted separately.
8861 When {skipcc} set to 1, Composing characters are ignored,
8862 similar to |slice()|.
8863 When a character index is used where a character does not
8864 exist it is omitted and counted as one character. For
8865 example: >
8866 strcharpart('abc', -1, 2)
8867< results in 'a'.
8868
Bram Moolenaard592deb2022-06-17 15:42:40 +01008869 Returns an empty string on error.
8870
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008871 Can also be used as a |method|: >
8872 GetText()->strcharpart(5)
8873
8874
8875strchars({string} [, {skipcc}]) *strchars()*
8876 The result is a Number, which is the number of characters
8877 in String {string}.
8878 When {skipcc} is omitted or zero, composing characters are
8879 counted separately.
8880 When {skipcc} set to 1, Composing characters are ignored.
8881 |strcharlen()| always does this.
8882
Bram Moolenaard592deb2022-06-17 15:42:40 +01008883 Returns zero on error.
8884
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008885 Also see |strlen()|, |strdisplaywidth()| and |strwidth()|.
8886
8887 {skipcc} is only available after 7.4.755. For backward
8888 compatibility, you can define a wrapper function: >
8889 if has("patch-7.4.755")
8890 function s:strchars(str, skipcc)
8891 return strchars(a:str, a:skipcc)
8892 endfunction
8893 else
8894 function s:strchars(str, skipcc)
8895 if a:skipcc
8896 return strlen(substitute(a:str, ".", "x", "g"))
8897 else
8898 return strchars(a:str)
8899 endif
8900 endfunction
8901 endif
8902<
8903 Can also be used as a |method|: >
8904 GetText()->strchars()
8905
8906strdisplaywidth({string} [, {col}]) *strdisplaywidth()*
8907 The result is a Number, which is the number of display cells
8908 String {string} occupies on the screen when it starts at {col}
8909 (first column is zero). When {col} is omitted zero is used.
8910 Otherwise it is the screen column where to start. This
8911 matters for Tab characters.
8912 The option settings of the current window are used. This
8913 matters for anything that's displayed differently, such as
8914 'tabstop' and 'display'.
8915 When {string} contains characters with East Asian Width Class
8916 Ambiguous, this function's return value depends on 'ambiwidth'.
Bram Moolenaard592deb2022-06-17 15:42:40 +01008917 Returns zero on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008918 Also see |strlen()|, |strwidth()| and |strchars()|.
8919
8920 Can also be used as a |method|: >
8921 GetText()->strdisplaywidth()
8922
8923strftime({format} [, {time}]) *strftime()*
8924 The result is a String, which is a formatted date and time, as
8925 specified by the {format} string. The given {time} is used,
8926 or the current time if no time is given. The accepted
8927 {format} depends on your system, thus this is not portable!
8928 See the manual page of the C function strftime() for the
8929 format. The maximum length of the result is 80 characters.
8930 See also |localtime()|, |getftime()| and |strptime()|.
8931 The language can be changed with the |:language| command.
8932 Examples: >
8933 :echo strftime("%c") Sun Apr 27 11:49:23 1997
8934 :echo strftime("%Y %b %d %X") 1997 Apr 27 11:53:25
8935 :echo strftime("%y%m%d %T") 970427 11:53:55
8936 :echo strftime("%H:%M") 11:55
8937 :echo strftime("%c", getftime("file.c"))
8938 Show mod time of file.c.
8939< Not available on all systems. To check use: >
8940 :if exists("*strftime")
8941
8942< Can also be used as a |method|: >
8943 GetFormat()->strftime()
8944
8945strgetchar({str}, {index}) *strgetchar()*
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01008946 Get a Number corresponding to the character at {index} in
8947 {str}. This uses a zero-based character index, not a byte
8948 index. Composing characters are considered separate
8949 characters here. Use |nr2char()| to convert the Number to a
8950 String.
Bram Moolenaard592deb2022-06-17 15:42:40 +01008951 Returns -1 if {index} is invalid.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008952 Also see |strcharpart()| and |strchars()|.
8953
8954 Can also be used as a |method|: >
8955 GetText()->strgetchar(5)
8956
8957stridx({haystack}, {needle} [, {start}]) *stridx()*
8958 The result is a Number, which gives the byte index in
8959 {haystack} of the first occurrence of the String {needle}.
8960 If {start} is specified, the search starts at index {start}.
8961 This can be used to find a second match: >
8962 :let colon1 = stridx(line, ":")
8963 :let colon2 = stridx(line, ":", colon1 + 1)
8964< The search is done case-sensitive.
8965 For pattern searches use |match()|.
8966 -1 is returned if the {needle} does not occur in {haystack}.
8967 See also |strridx()|.
8968 Examples: >
8969 :echo stridx("An Example", "Example") 3
8970 :echo stridx("Starting point", "Start") 0
8971 :echo stridx("Starting point", "start") -1
8972< *strstr()* *strchr()*
8973 stridx() works similar to the C function strstr(). When used
8974 with a single character it works similar to strchr().
8975
8976 Can also be used as a |method|: >
8977 GetHaystack()->stridx(needle)
8978<
8979 *string()*
8980string({expr}) Return {expr} converted to a String. If {expr} is a Number,
8981 Float, String, Blob or a composition of them, then the result
8982 can be parsed back with |eval()|.
8983 {expr} type result ~
8984 String 'string' (single quotes are doubled)
8985 Number 123
8986 Float 123.123456 or 1.123456e8
8987 Funcref function('name')
8988 Blob 0z00112233.44556677.8899
8989 List [item, item]
8990 Dictionary {key: value, key: value}
8991
8992 When a |List| or |Dictionary| has a recursive reference it is
8993 replaced by "[...]" or "{...}". Using eval() on the result
8994 will then fail.
8995
8996 Can also be used as a |method|: >
8997 mylist->string()
8998
8999< Also see |strtrans()|.
9000
9001
9002strlen({string}) *strlen()*
9003 The result is a Number, which is the length of the String
9004 {string} in bytes.
9005 If the argument is a Number it is first converted to a String.
Bram Moolenaard592deb2022-06-17 15:42:40 +01009006 For other types an error is given and zero is returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009007 If you want to count the number of multibyte characters use
9008 |strchars()|.
9009 Also see |len()|, |strdisplaywidth()| and |strwidth()|.
9010
9011 Can also be used as a |method|: >
9012 GetString()->strlen()
9013
9014strpart({src}, {start} [, {len} [, {chars}]]) *strpart()*
9015 The result is a String, which is part of {src}, starting from
9016 byte {start}, with the byte length {len}.
9017 When {chars} is present and TRUE then {len} is the number of
9018 characters positions (composing characters are not counted
9019 separately, thus "1" means one base character and any
9020 following composing characters).
9021 To count {start} as characters instead of bytes use
9022 |strcharpart()|.
9023
9024 When bytes are selected which do not exist, this doesn't
9025 result in an error, the bytes are simply omitted.
9026 If {len} is missing, the copy continues from {start} till the
9027 end of the {src}. >
9028 strpart("abcdefg", 3, 2) == "de"
9029 strpart("abcdefg", -2, 4) == "ab"
9030 strpart("abcdefg", 5, 4) == "fg"
9031 strpart("abcdefg", 3) == "defg"
9032
9033< Note: To get the first character, {start} must be 0. For
9034 example, to get the character under the cursor: >
9035 strpart(getline("."), col(".") - 1, 1, v:true)
9036<
Bram Moolenaard592deb2022-06-17 15:42:40 +01009037 Returns an empty string on error.
9038
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009039 Can also be used as a |method|: >
9040 GetText()->strpart(5)
9041
9042strptime({format}, {timestring}) *strptime()*
9043 The result is a Number, which is a unix timestamp representing
9044 the date and time in {timestring}, which is expected to match
9045 the format specified in {format}.
9046
9047 The accepted {format} depends on your system, thus this is not
9048 portable! See the manual page of the C function strptime()
9049 for the format. Especially avoid "%c". The value of $TZ also
9050 matters.
9051
9052 If the {timestring} cannot be parsed with {format} zero is
9053 returned. If you do not know the format of {timestring} you
9054 can try different {format} values until you get a non-zero
9055 result.
9056
9057 See also |strftime()|.
9058 Examples: >
9059 :echo strptime("%Y %b %d %X", "1997 Apr 27 11:49:23")
9060< 862156163 >
9061 :echo strftime("%c", strptime("%y%m%d %T", "970427 11:53:55"))
9062< Sun Apr 27 11:53:55 1997 >
9063 :echo strftime("%c", strptime("%Y%m%d%H%M%S", "19970427115355") + 3600)
9064< Sun Apr 27 12:53:55 1997
9065
9066 Can also be used as a |method|: >
9067 GetFormat()->strptime(timestring)
9068<
9069 Not available on all systems. To check use: >
9070 :if exists("*strptime")
9071
9072strridx({haystack}, {needle} [, {start}]) *strridx()*
9073 The result is a Number, which gives the byte index in
9074 {haystack} of the last occurrence of the String {needle}.
9075 When {start} is specified, matches beyond this index are
9076 ignored. This can be used to find a match before a previous
9077 match: >
9078 :let lastcomma = strridx(line, ",")
9079 :let comma2 = strridx(line, ",", lastcomma - 1)
9080< The search is done case-sensitive.
9081 For pattern searches use |match()|.
9082 -1 is returned if the {needle} does not occur in {haystack}.
9083 If the {needle} is empty the length of {haystack} is returned.
9084 See also |stridx()|. Examples: >
9085 :echo strridx("an angry armadillo", "an") 3
9086< *strrchr()*
9087 When used with a single character it works similar to the C
9088 function strrchr().
9089
9090 Can also be used as a |method|: >
9091 GetHaystack()->strridx(needle)
9092
9093strtrans({string}) *strtrans()*
9094 The result is a String, which is {string} with all unprintable
9095 characters translated into printable characters |'isprint'|.
9096 Like they are shown in a window. Example: >
9097 echo strtrans(@a)
9098< This displays a newline in register a as "^@" instead of
9099 starting a new line.
9100
Bram Moolenaard592deb2022-06-17 15:42:40 +01009101 Returns an empty string on error.
9102
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009103 Can also be used as a |method|: >
9104 GetString()->strtrans()
9105
9106strwidth({string}) *strwidth()*
9107 The result is a Number, which is the number of display cells
9108 String {string} occupies. A Tab character is counted as one
9109 cell, alternatively use |strdisplaywidth()|.
9110 When {string} contains characters with East Asian Width Class
9111 Ambiguous, this function's return value depends on 'ambiwidth'.
Bram Moolenaard592deb2022-06-17 15:42:40 +01009112 Returns zero on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009113 Also see |strlen()|, |strdisplaywidth()| and |strchars()|.
9114
9115 Can also be used as a |method|: >
9116 GetString()->strwidth()
9117
9118submatch({nr} [, {list}]) *submatch()* *E935*
9119 Only for an expression in a |:substitute| command or
9120 substitute() function.
9121 Returns the {nr}'th submatch of the matched text. When {nr}
9122 is 0 the whole matched text is returned.
9123 Note that a NL in the string can stand for a line break of a
9124 multi-line match or a NUL character in the text.
9125 Also see |sub-replace-expression|.
9126
9127 If {list} is present and non-zero then submatch() returns
9128 a list of strings, similar to |getline()| with two arguments.
9129 NL characters in the text represent NUL characters in the
9130 text.
9131 Only returns more than one item for |:substitute|, inside
9132 |substitute()| this list will always contain one or zero
9133 items, since there are no real line breaks.
9134
9135 When substitute() is used recursively only the submatches in
9136 the current (deepest) call can be obtained.
9137
Bram Moolenaard592deb2022-06-17 15:42:40 +01009138 Returns an empty string or list on error.
9139
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009140 Examples: >
9141 :s/\d\+/\=submatch(0) + 1/
9142 :echo substitute(text, '\d\+', '\=submatch(0) + 1', '')
9143< This finds the first number in the line and adds one to it.
9144 A line break is included as a newline character.
9145
9146 Can also be used as a |method|: >
9147 GetNr()->submatch()
9148
9149substitute({string}, {pat}, {sub}, {flags}) *substitute()*
9150 The result is a String, which is a copy of {string}, in which
9151 the first match of {pat} is replaced with {sub}.
9152 When {flags} is "g", all matches of {pat} in {string} are
9153 replaced. Otherwise {flags} should be "".
9154
9155 This works like the ":substitute" command (without any flags).
9156 But the matching with {pat} is always done like the 'magic'
9157 option is set and 'cpoptions' is empty (to make scripts
9158 portable). 'ignorecase' is still relevant, use |/\c| or |/\C|
9159 if you want to ignore or match case and ignore 'ignorecase'.
9160 'smartcase' is not used. See |string-match| for how {pat} is
9161 used.
9162
9163 A "~" in {sub} is not replaced with the previous {sub}.
9164 Note that some codes in {sub} have a special meaning
9165 |sub-replace-special|. For example, to replace something with
9166 "\n" (two characters), use "\\\\n" or '\\n'.
9167
9168 When {pat} does not match in {string}, {string} is returned
9169 unmodified.
9170
9171 Example: >
9172 :let &path = substitute(&path, ",\\=[^,]*$", "", "")
9173< This removes the last component of the 'path' option. >
9174 :echo substitute("testing", ".*", "\\U\\0", "")
9175< results in "TESTING".
9176
9177 When {sub} starts with "\=", the remainder is interpreted as
9178 an expression. See |sub-replace-expression|. Example: >
9179 :echo substitute(s, '%\(\x\x\)',
Bram Moolenaarc51cf032022-02-26 12:25:45 +00009180 \ '\=nr2char("0x" .. submatch(1))', 'g')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009181
9182< When {sub} is a Funcref that function is called, with one
9183 optional argument. Example: >
9184 :echo substitute(s, '%\(\x\x\)', SubNr, 'g')
9185< The optional argument is a list which contains the whole
9186 matched string and up to nine submatches, like what
9187 |submatch()| returns. Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00009188 :echo substitute(s, '%\(\x\x\)', {m -> '0x' .. m[1]}, 'g')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009189
Bram Moolenaard592deb2022-06-17 15:42:40 +01009190< Returns an empty string on error.
9191
9192 Can also be used as a |method|: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009193 GetString()->substitute(pat, sub, flags)
9194
9195swapinfo({fname}) *swapinfo()*
9196 The result is a dictionary, which holds information about the
9197 swapfile {fname}. The available fields are:
9198 version Vim version
9199 user user name
9200 host host name
9201 fname original file name
9202 pid PID of the Vim process that created the swap
9203 file
9204 mtime last modification time in seconds
9205 inode Optional: INODE number of the file
9206 dirty 1 if file was modified, 0 if not
9207 Note that "user" and "host" are truncated to at most 39 bytes.
9208 In case of failure an "error" item is added with the reason:
9209 Cannot open file: file not found or in accessible
9210 Cannot read file: cannot read first block
9211 Not a swap file: does not contain correct block ID
9212 Magic number mismatch: Info in first block is invalid
9213
9214 Can also be used as a |method|: >
9215 GetFilename()->swapinfo()
9216
9217swapname({buf}) *swapname()*
9218 The result is the swap file path of the buffer {expr}.
9219 For the use of {buf}, see |bufname()| above.
9220 If buffer {buf} is the current buffer, the result is equal to
9221 |:swapname| (unless there is no swap file).
9222 If buffer {buf} has no swap file, returns an empty string.
9223
9224 Can also be used as a |method|: >
9225 GetBufname()->swapname()
9226
9227synID({lnum}, {col}, {trans}) *synID()*
9228 The result is a Number, which is the syntax ID at the position
9229 {lnum} and {col} in the current window.
9230 The syntax ID can be used with |synIDattr()| and
9231 |synIDtrans()| to obtain syntax information about text.
9232
9233 {col} is 1 for the leftmost column, {lnum} is 1 for the first
9234 line. 'synmaxcol' applies, in a longer line zero is returned.
9235 Note that when the position is after the last character,
9236 that's where the cursor can be in Insert mode, synID() returns
9237 zero. {lnum} is used like with |getline()|.
9238
9239 When {trans} is |TRUE|, transparent items are reduced to the
9240 item that they reveal. This is useful when wanting to know
9241 the effective color. When {trans} is |FALSE|, the transparent
9242 item is returned. This is useful when wanting to know which
9243 syntax item is effective (e.g. inside parens).
9244 Warning: This function can be very slow. Best speed is
9245 obtained by going through the file in forward direction.
9246
Bram Moolenaard592deb2022-06-17 15:42:40 +01009247 Returns zero on error.
9248
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009249 Example (echoes the name of the syntax item under the cursor): >
9250 :echo synIDattr(synID(line("."), col("."), 1), "name")
9251<
9252
9253synIDattr({synID}, {what} [, {mode}]) *synIDattr()*
9254 The result is a String, which is the {what} attribute of
9255 syntax ID {synID}. This can be used to obtain information
9256 about a syntax item.
9257 {mode} can be "gui", "cterm" or "term", to get the attributes
9258 for that mode. When {mode} is omitted, or an invalid value is
9259 used, the attributes for the currently active highlighting are
9260 used (GUI, cterm or term).
9261 Use synIDtrans() to follow linked highlight groups.
9262 {what} result
9263 "name" the name of the syntax item
9264 "fg" foreground color (GUI: color name used to set
9265 the color, cterm: color number as a string,
9266 term: empty string)
9267 "bg" background color (as with "fg")
9268 "font" font name (only available in the GUI)
9269 |highlight-font|
9270 "sp" special color for the GUI (as with "fg")
9271 |highlight-guisp|
9272 "ul" underline color for cterm: number as a string
9273 "fg#" like "fg", but for the GUI and the GUI is
9274 running the name in "#RRGGBB" form
9275 "bg#" like "fg#" for "bg"
9276 "sp#" like "fg#" for "sp"
9277 "bold" "1" if bold
9278 "italic" "1" if italic
9279 "reverse" "1" if reverse
9280 "inverse" "1" if inverse (= reverse)
9281 "standout" "1" if standout
9282 "underline" "1" if underlined
9283 "undercurl" "1" if undercurled
9284 "strike" "1" if strikethrough
Bram Moolenaarde786322022-07-30 14:56:17 +01009285 "nocombine" "1" if nocombine
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009286
Bram Moolenaard592deb2022-06-17 15:42:40 +01009287 Returns an empty string on error.
9288
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009289 Example (echoes the color of the syntax item under the
9290 cursor): >
9291 :echo synIDattr(synIDtrans(synID(line("."), col("."), 1)), "fg")
9292<
9293 Can also be used as a |method|: >
9294 :echo synID(line("."), col("."), 1)->synIDtrans()->synIDattr("fg")
9295
9296
9297synIDtrans({synID}) *synIDtrans()*
9298 The result is a Number, which is the translated syntax ID of
9299 {synID}. This is the syntax group ID of what is being used to
9300 highlight the character. Highlight links given with
9301 ":highlight link" are followed.
9302
Bram Moolenaard592deb2022-06-17 15:42:40 +01009303 Returns zero on error.
9304
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009305 Can also be used as a |method|: >
9306 :echo synID(line("."), col("."), 1)->synIDtrans()->synIDattr("fg")
9307
9308synconcealed({lnum}, {col}) *synconcealed()*
9309 The result is a |List| with currently three items:
9310 1. The first item in the list is 0 if the character at the
9311 position {lnum} and {col} is not part of a concealable
9312 region, 1 if it is. {lnum} is used like with |getline()|.
9313 2. The second item in the list is a string. If the first item
9314 is 1, the second item contains the text which will be
9315 displayed in place of the concealed text, depending on the
9316 current setting of 'conceallevel' and 'listchars'.
9317 3. The third and final item in the list is a number
9318 representing the specific syntax region matched in the
9319 line. When the character is not concealed the value is
9320 zero. This allows detection of the beginning of a new
9321 concealable region if there are two consecutive regions
9322 with the same replacement character. For an example, if
9323 the text is "123456" and both "23" and "45" are concealed
9324 and replaced by the character "X", then:
9325 call returns ~
9326 synconcealed(lnum, 1) [0, '', 0]
9327 synconcealed(lnum, 2) [1, 'X', 1]
9328 synconcealed(lnum, 3) [1, 'X', 1]
9329 synconcealed(lnum, 4) [1, 'X', 2]
9330 synconcealed(lnum, 5) [1, 'X', 2]
9331 synconcealed(lnum, 6) [0, '', 0]
9332
9333
9334synstack({lnum}, {col}) *synstack()*
9335 Return a |List|, which is the stack of syntax items at the
9336 position {lnum} and {col} in the current window. {lnum} is
9337 used like with |getline()|. Each item in the List is an ID
9338 like what |synID()| returns.
9339 The first item in the List is the outer region, following are
9340 items contained in that one. The last one is what |synID()|
9341 returns, unless not the whole item is highlighted or it is a
9342 transparent item.
9343 This function is useful for debugging a syntax file.
9344 Example that shows the syntax stack under the cursor: >
9345 for id in synstack(line("."), col("."))
9346 echo synIDattr(id, "name")
9347 endfor
9348< When the position specified with {lnum} and {col} is invalid
Bram Moolenaard592deb2022-06-17 15:42:40 +01009349 an empty List is returned. The position just after the last
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009350 character in a line and the first column in an empty line are
9351 valid positions.
9352
9353system({expr} [, {input}]) *system()* *E677*
9354 Get the output of the shell command {expr} as a |String|. See
9355 |systemlist()| to get the output as a |List|.
9356
9357 When {input} is given and is a |String| this string is written
9358 to a file and passed as stdin to the command. The string is
9359 written as-is, you need to take care of using the correct line
9360 separators yourself.
9361 If {input} is given and is a |List| it is written to the file
9362 in a way |writefile()| does with {binary} set to "b" (i.e.
9363 with a newline between each list item with newlines inside
9364 list items converted to NULs).
9365 When {input} is given and is a number that is a valid id for
9366 an existing buffer then the content of the buffer is written
9367 to the file line by line, each line terminated by a NL and
9368 NULs characters where the text has a NL.
9369
9370 Pipes are not used, the 'shelltemp' option is not used.
9371
9372 When prepended by |:silent| the terminal will not be set to
9373 cooked mode. This is meant to be used for commands that do
9374 not need the user to type. It avoids stray characters showing
9375 up on the screen which require |CTRL-L| to remove. >
9376 :silent let f = system('ls *.vim')
9377<
9378 Note: Use |shellescape()| or |::S| with |expand()| or
9379 |fnamemodify()| to escape special characters in a command
9380 argument. Newlines in {expr} may cause the command to fail.
9381 The characters in 'shellquote' and 'shellxquote' may also
9382 cause trouble.
9383 This is not to be used for interactive commands.
9384
9385 The result is a String. Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00009386 :let files = system('ls ' .. shellescape(expand('%:h')))
9387 :let files = system('ls ' .. expand('%:h:S'))
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009388
9389< To make the result more system-independent, the shell output
9390 is filtered to replace <CR> with <NL> for Macintosh, and
9391 <CR><NL> with <NL> for DOS-like systems.
9392 To avoid the string being truncated at a NUL, all NUL
9393 characters are replaced with SOH (0x01).
9394
9395 The command executed is constructed using several options:
9396 'shell' 'shellcmdflag' 'shellxquote' {expr} 'shellredir' {tmp} 'shellxquote'
9397 ({tmp} is an automatically generated file name).
9398 For Unix, braces are put around {expr} to allow for
9399 concatenated commands.
9400
9401 The command will be executed in "cooked" mode, so that a
9402 CTRL-C will interrupt the command (on Unix at least).
9403
9404 The resulting error code can be found in |v:shell_error|.
9405 This function will fail in |restricted-mode|.
9406
9407 Note that any wrong value in the options mentioned above may
9408 make the function fail. It has also been reported to fail
9409 when using a security agent application.
9410 Unlike ":!cmd" there is no automatic check for changed files.
9411 Use |:checktime| to force a check.
9412
9413 Can also be used as a |method|: >
9414 :echo GetCmd()->system()
9415
9416
9417systemlist({expr} [, {input}]) *systemlist()*
9418 Same as |system()|, but returns a |List| with lines (parts of
9419 output separated by NL) with NULs transformed into NLs. Output
9420 is the same as |readfile()| will output with {binary} argument
9421 set to "b", except that there is no extra empty item when the
9422 result ends in a NL.
9423 Note that on MS-Windows you may get trailing CR characters.
9424
9425 To see the difference between "echo hello" and "echo -n hello"
9426 use |system()| and |split()|: >
9427 echo system('echo hello')->split('\n', 1)
9428<
9429 Returns an empty string on error.
9430
9431 Can also be used as a |method|: >
9432 :echo GetCmd()->systemlist()
9433
9434
9435tabpagebuflist([{arg}]) *tabpagebuflist()*
9436 The result is a |List|, where each item is the number of the
9437 buffer associated with each window in the current tab page.
9438 {arg} specifies the number of the tab page to be used. When
9439 omitted the current tab page is used.
9440 When {arg} is invalid the number zero is returned.
9441 To get a list of all buffers in all tabs use this: >
9442 let buflist = []
9443 for i in range(tabpagenr('$'))
9444 call extend(buflist, tabpagebuflist(i + 1))
9445 endfor
9446< Note that a buffer may appear in more than one window.
9447
9448 Can also be used as a |method|: >
9449 GetTabpage()->tabpagebuflist()
9450
9451tabpagenr([{arg}]) *tabpagenr()*
9452 The result is a Number, which is the number of the current
9453 tab page. The first tab page has number 1.
9454
9455 The optional argument {arg} supports the following values:
9456 $ the number of the last tab page (the tab page
9457 count).
9458 # the number of the last accessed tab page
9459 (where |g<Tab>| goes to). if there is no
9460 previous tab page 0 is returned.
9461 The number can be used with the |:tab| command.
9462
Bram Moolenaard592deb2022-06-17 15:42:40 +01009463 Returns zero on error.
9464
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009465
9466tabpagewinnr({tabarg} [, {arg}]) *tabpagewinnr()*
9467 Like |winnr()| but for tab page {tabarg}.
9468 {tabarg} specifies the number of tab page to be used.
9469 {arg} is used like with |winnr()|:
9470 - When omitted the current window number is returned. This is
9471 the window which will be used when going to this tab page.
9472 - When "$" the number of windows is returned.
9473 - When "#" the previous window nr is returned.
9474 Useful examples: >
9475 tabpagewinnr(1) " current window of tab page 1
9476 tabpagewinnr(4, '$') " number of windows in tab page 4
9477< When {tabarg} is invalid zero is returned.
9478
9479 Can also be used as a |method|: >
9480 GetTabpage()->tabpagewinnr()
9481<
9482 *tagfiles()*
9483tagfiles() Returns a |List| with the file names used to search for tags
9484 for the current buffer. This is the 'tags' option expanded.
9485
9486
9487taglist({expr} [, {filename}]) *taglist()*
9488 Returns a |List| of tags matching the regular expression {expr}.
9489
9490 If {filename} is passed it is used to prioritize the results
9491 in the same way that |:tselect| does. See |tag-priority|.
9492 {filename} should be the full path of the file.
9493
9494 Each list item is a dictionary with at least the following
9495 entries:
9496 name Name of the tag.
9497 filename Name of the file where the tag is
9498 defined. It is either relative to the
9499 current directory or a full path.
9500 cmd Ex command used to locate the tag in
9501 the file.
9502 kind Type of the tag. The value for this
9503 entry depends on the language specific
9504 kind values. Only available when
9505 using a tags file generated by
Bram Moolenaar47c532e2022-03-19 15:18:53 +00009506 Universal/Exuberant ctags or hdrtag.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009507 static A file specific tag. Refer to
9508 |static-tag| for more information.
9509 More entries may be present, depending on the content of the
9510 tags file: access, implementation, inherits and signature.
9511 Refer to the ctags documentation for information about these
9512 fields. For C code the fields "struct", "class" and "enum"
9513 may appear, they give the name of the entity the tag is
9514 contained in.
9515
9516 The ex-command "cmd" can be either an ex search pattern, a
9517 line number or a line number followed by a byte number.
9518
9519 If there are no matching tags, then an empty list is returned.
9520
9521 To get an exact tag match, the anchors '^' and '$' should be
9522 used in {expr}. This also make the function work faster.
9523 Refer to |tag-regexp| for more information about the tag
9524 search regular expression pattern.
9525
9526 Refer to |'tags'| for information about how the tags file is
9527 located by Vim. Refer to |tags-file-format| for the format of
9528 the tags file generated by the different ctags tools.
9529
9530 Can also be used as a |method|: >
9531 GetTagpattern()->taglist()
9532
9533tan({expr}) *tan()*
9534 Return the tangent of {expr}, measured in radians, as a |Float|
9535 in the range [-inf, inf].
9536 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaard592deb2022-06-17 15:42:40 +01009537 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009538 Examples: >
9539 :echo tan(10)
9540< 0.648361 >
9541 :echo tan(-4.01)
9542< -1.181502
9543
9544 Can also be used as a |method|: >
9545 Compute()->tan()
9546<
9547 {only available when compiled with the |+float| feature}
9548
9549
9550tanh({expr}) *tanh()*
9551 Return the hyperbolic tangent of {expr} as a |Float| in the
9552 range [-1, 1].
9553 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaard592deb2022-06-17 15:42:40 +01009554 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009555 Examples: >
9556 :echo tanh(0.5)
9557< 0.462117 >
9558 :echo tanh(-1)
9559< -0.761594
9560
9561 Can also be used as a |method|: >
9562 Compute()->tanh()
9563<
9564 {only available when compiled with the |+float| feature}
9565
9566
9567tempname() *tempname()* *temp-file-name*
9568 The result is a String, which is the name of a file that
9569 doesn't exist. It can be used for a temporary file. The name
9570 is different for at least 26 consecutive calls. Example: >
9571 :let tmpfile = tempname()
Bram Moolenaarc51cf032022-02-26 12:25:45 +00009572 :exe "redir > " .. tmpfile
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009573< For Unix, the file will be in a private directory |tempfile|.
9574 For MS-Windows forward slashes are used when the 'shellslash'
9575 option is set, or when 'shellcmdflag' starts with '-' and
9576 'shell' does not contain powershell or pwsh.
9577
9578
9579term_ functions are documented here: |terminal-function-details|
9580
9581
9582terminalprops() *terminalprops()*
9583 Returns a |Dictionary| with properties of the terminal that Vim
9584 detected from the response to |t_RV| request. See
9585 |v:termresponse| for the response itself. If |v:termresponse|
9586 is empty most values here will be 'u' for unknown.
9587 cursor_style whether sending |t_RS| works **
9588 cursor_blink_mode whether sending |t_RC| works **
9589 underline_rgb whether |t_8u| works **
9590 mouse mouse type supported
9591
9592 ** value 'u' for unknown, 'y' for yes, 'n' for no
9593
9594 If the |+termresponse| feature is missing then the result is
9595 an empty dictionary.
9596
9597 If "cursor_style" is 'y' then |t_RS| will be sent to request the
9598 current cursor style.
9599 If "cursor_blink_mode" is 'y' then |t_RC| will be sent to
9600 request the cursor blink status.
9601 "cursor_style" and "cursor_blink_mode" are also set if |t_u7|
9602 is not empty, Vim will detect the working of sending |t_RS|
9603 and |t_RC| on startup.
9604
9605 When "underline_rgb" is not 'y', then |t_8u| will be made empty.
9606 This avoids sending it to xterm, which would clear the colors.
9607
9608 For "mouse" the value 'u' is unknown
9609
9610 Also see:
9611 - 'ambiwidth' - detected by using |t_u7|.
9612 - |v:termstyleresp| and |v:termblinkresp| for the response to
9613 |t_RS| and |t_RC|.
9614
9615
9616test_ functions are documented here: |test-functions-details|
9617
9618
9619 *timer_info()*
9620timer_info([{id}])
9621 Return a list with information about timers.
9622 When {id} is given only information about this timer is
9623 returned. When timer {id} does not exist an empty list is
9624 returned.
9625 When {id} is omitted information about all timers is returned.
9626
9627 For each timer the information is stored in a |Dictionary| with
9628 these items:
9629 "id" the timer ID
9630 "time" time the timer was started with
9631 "remaining" time until the timer fires
9632 "repeat" number of times the timer will still fire;
9633 -1 means forever
9634 "callback" the callback
9635 "paused" 1 if the timer is paused, 0 otherwise
9636
9637 Can also be used as a |method|: >
9638 GetTimer()->timer_info()
9639
9640< {only available when compiled with the |+timers| feature}
9641
9642timer_pause({timer}, {paused}) *timer_pause()*
9643 Pause or unpause a timer. A paused timer does not invoke its
9644 callback when its time expires. Unpausing a timer may cause
9645 the callback to be invoked almost immediately if enough time
9646 has passed.
9647
9648 Pausing a timer is useful to avoid the callback to be called
9649 for a short time.
9650
9651 If {paused} evaluates to a non-zero Number or a non-empty
9652 String, then the timer is paused, otherwise it is unpaused.
9653 See |non-zero-arg|.
9654
9655 Can also be used as a |method|: >
9656 GetTimer()->timer_pause(1)
9657
9658< {only available when compiled with the |+timers| feature}
9659
9660 *timer_start()* *timer* *timers*
9661timer_start({time}, {callback} [, {options}])
9662 Create a timer and return the timer ID.
9663
9664 {time} is the waiting time in milliseconds. This is the
9665 minimum time before invoking the callback. When the system is
9666 busy or Vim is not waiting for input the time will be longer.
9667
9668 {callback} is the function to call. It can be the name of a
9669 function or a |Funcref|. It is called with one argument, which
9670 is the timer ID. The callback is only invoked when Vim is
9671 waiting for input.
9672 If you want to show a message look at |popup_notification()|
9673 to avoid interfering with what the user is doing.
9674
9675 {options} is a dictionary. Supported entries:
9676 "repeat" Number of times to repeat calling the
9677 callback. -1 means forever. When not present
9678 the callback will be called once.
9679 If the timer causes an error three times in a
9680 row the repeat is cancelled. This avoids that
9681 Vim becomes unusable because of all the error
9682 messages.
9683
Bram Moolenaard592deb2022-06-17 15:42:40 +01009684 Returns -1 on error.
9685
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009686 Example: >
9687 func MyHandler(timer)
9688 echo 'Handler called'
9689 endfunc
9690 let timer = timer_start(500, 'MyHandler',
9691 \ {'repeat': 3})
9692< This will invoke MyHandler() three times at 500 msec
9693 intervals.
9694
9695 Can also be used as a |method|: >
9696 GetMsec()->timer_start(callback)
9697
9698< Not available in the |sandbox|.
9699 {only available when compiled with the |+timers| feature}
9700
9701timer_stop({timer}) *timer_stop()*
9702 Stop a timer. The timer callback will no longer be invoked.
9703 {timer} is an ID returned by timer_start(), thus it must be a
9704 Number. If {timer} does not exist there is no error.
9705
9706 Can also be used as a |method|: >
9707 GetTimer()->timer_stop()
9708
9709< {only available when compiled with the |+timers| feature}
9710
9711timer_stopall() *timer_stopall()*
9712 Stop all timers. The timer callbacks will no longer be
9713 invoked. Useful if a timer is misbehaving. If there are no
9714 timers there is no error.
9715
9716 {only available when compiled with the |+timers| feature}
9717
9718tolower({expr}) *tolower()*
9719 The result is a copy of the String given, with all uppercase
9720 characters turned into lowercase (just like applying |gu| to
Bram Moolenaard592deb2022-06-17 15:42:40 +01009721 the string). Returns an empty string on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009722
9723 Can also be used as a |method|: >
9724 GetText()->tolower()
9725
9726toupper({expr}) *toupper()*
9727 The result is a copy of the String given, with all lowercase
9728 characters turned into uppercase (just like applying |gU| to
Bram Moolenaard592deb2022-06-17 15:42:40 +01009729 the string). Returns an empty string on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009730
9731 Can also be used as a |method|: >
9732 GetText()->toupper()
9733
9734tr({src}, {fromstr}, {tostr}) *tr()*
9735 The result is a copy of the {src} string with all characters
9736 which appear in {fromstr} replaced by the character in that
9737 position in the {tostr} string. Thus the first character in
9738 {fromstr} is translated into the first character in {tostr}
9739 and so on. Exactly like the unix "tr" command.
9740 This code also deals with multibyte characters properly.
9741
Bram Moolenaard592deb2022-06-17 15:42:40 +01009742 Returns an empty string on error.
9743
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009744 Examples: >
9745 echo tr("hello there", "ht", "HT")
9746< returns "Hello THere" >
9747 echo tr("<blob>", "<>", "{}")
9748< returns "{blob}"
9749
9750 Can also be used as a |method|: >
9751 GetText()->tr(from, to)
9752
9753trim({text} [, {mask} [, {dir}]]) *trim()*
9754 Return {text} as a String where any character in {mask} is
9755 removed from the beginning and/or end of {text}.
9756
9757 If {mask} is not given, {mask} is all characters up to 0x20,
9758 which includes Tab, space, NL and CR, plus the non-breaking
9759 space character 0xa0.
9760
9761 The optional {dir} argument specifies where to remove the
9762 characters:
9763 0 remove from the beginning and end of {text}
9764 1 remove only at the beginning of {text}
9765 2 remove only at the end of {text}
9766 When omitted both ends are trimmed.
9767
9768 This function deals with multibyte characters properly.
Bram Moolenaard592deb2022-06-17 15:42:40 +01009769 Returns an empty string on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009770
9771 Examples: >
9772 echo trim(" some text ")
9773< returns "some text" >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00009774 echo trim(" \r\t\t\r RESERVE \t\n\x0B\xA0") .. "_TAIL"
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009775< returns "RESERVE_TAIL" >
9776 echo trim("rm<Xrm<>X>rrm", "rm<>")
9777< returns "Xrm<>X" (characters in the middle are not removed) >
9778 echo trim(" vim ", " ", 2)
9779< returns " vim"
9780
9781 Can also be used as a |method|: >
9782 GetText()->trim()
9783
9784trunc({expr}) *trunc()*
9785 Return the largest integral value with magnitude less than or
9786 equal to {expr} as a |Float| (truncate towards zero).
9787 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaard592deb2022-06-17 15:42:40 +01009788 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009789 Examples: >
9790 echo trunc(1.456)
9791< 1.0 >
9792 echo trunc(-5.456)
9793< -5.0 >
9794 echo trunc(4.0)
9795< 4.0
9796
9797 Can also be used as a |method|: >
9798 Compute()->trunc()
9799<
9800 {only available when compiled with the |+float| feature}
9801
9802 *type()*
9803type({expr}) The result is a Number representing the type of {expr}.
9804 Instead of using the number directly, it is better to use the
9805 v:t_ variable that has the value:
9806 Number: 0 |v:t_number|
9807 String: 1 |v:t_string|
9808 Funcref: 2 |v:t_func|
9809 List: 3 |v:t_list|
9810 Dictionary: 4 |v:t_dict|
9811 Float: 5 |v:t_float|
9812 Boolean: 6 |v:t_bool| (v:false and v:true)
9813 None: 7 |v:t_none| (v:null and v:none)
9814 Job: 8 |v:t_job|
9815 Channel: 9 |v:t_channel|
9816 Blob: 10 |v:t_blob|
9817 For backward compatibility, this method can be used: >
9818 :if type(myvar) == type(0)
9819 :if type(myvar) == type("")
9820 :if type(myvar) == type(function("tr"))
9821 :if type(myvar) == type([])
9822 :if type(myvar) == type({})
9823 :if type(myvar) == type(0.0)
9824 :if type(myvar) == type(v:false)
9825 :if type(myvar) == type(v:none)
9826< To check if the v:t_ variables exist use this: >
9827 :if exists('v:t_number')
9828
9829< Can also be used as a |method|: >
9830 mylist->type()
9831
9832
9833typename({expr}) *typename()*
9834 Return a string representation of the type of {expr}.
9835 Example: >
9836 echo typename([1, 2, 3])
9837 list<number>
9838
9839
9840undofile({name}) *undofile()*
9841 Return the name of the undo file that would be used for a file
9842 with name {name} when writing. This uses the 'undodir'
9843 option, finding directories that exist. It does not check if
9844 the undo file exists.
9845 {name} is always expanded to the full path, since that is what
9846 is used internally.
9847 If {name} is empty undofile() returns an empty string, since a
9848 buffer without a file name will not write an undo file.
9849 Useful in combination with |:wundo| and |:rundo|.
9850 When compiled without the |+persistent_undo| option this always
9851 returns an empty string.
9852
9853 Can also be used as a |method|: >
9854 GetFilename()->undofile()
9855
9856undotree() *undotree()*
9857 Return the current state of the undo tree in a dictionary with
9858 the following items:
9859 "seq_last" The highest undo sequence number used.
9860 "seq_cur" The sequence number of the current position in
9861 the undo tree. This differs from "seq_last"
9862 when some changes were undone.
9863 "time_cur" Time last used for |:earlier| and related
9864 commands. Use |strftime()| to convert to
9865 something readable.
9866 "save_last" Number of the last file write. Zero when no
9867 write yet.
9868 "save_cur" Number of the current position in the undo
9869 tree.
9870 "synced" Non-zero when the last undo block was synced.
9871 This happens when waiting from input from the
9872 user. See |undo-blocks|.
9873 "entries" A list of dictionaries with information about
9874 undo blocks.
9875
9876 The first item in the "entries" list is the oldest undo item.
9877 Each List item is a |Dictionary| with these items:
9878 "seq" Undo sequence number. Same as what appears in
9879 |:undolist|.
9880 "time" Timestamp when the change happened. Use
9881 |strftime()| to convert to something readable.
9882 "newhead" Only appears in the item that is the last one
9883 that was added. This marks the last change
9884 and where further changes will be added.
9885 "curhead" Only appears in the item that is the last one
9886 that was undone. This marks the current
9887 position in the undo tree, the block that will
9888 be used by a redo command. When nothing was
9889 undone after the last change this item will
9890 not appear anywhere.
9891 "save" Only appears on the last block before a file
9892 write. The number is the write count. The
9893 first write has number 1, the last one the
9894 "save_last" mentioned above.
9895 "alt" Alternate entry. This is again a List of undo
9896 blocks. Each item may again have an "alt"
9897 item.
9898
9899uniq({list} [, {func} [, {dict}]]) *uniq()* *E882*
9900 Remove second and succeeding copies of repeated adjacent
9901 {list} items in-place. Returns {list}. If you want a list
9902 to remain unmodified make a copy first: >
9903 :let newlist = uniq(copy(mylist))
9904< The default compare function uses the string representation of
9905 each item. For the use of {func} and {dict} see |sort()|.
9906
Bram Moolenaard592deb2022-06-17 15:42:40 +01009907 Returns zero if {list} is not a |List|.
9908
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009909 Can also be used as a |method|: >
9910 mylist->uniq()
9911
9912values({dict}) *values()*
9913 Return a |List| with all the values of {dict}. The |List| is
9914 in arbitrary order. Also see |items()| and |keys()|.
Bram Moolenaard592deb2022-06-17 15:42:40 +01009915 Returns zero if {dict} is not a |Dict|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009916
9917 Can also be used as a |method|: >
9918 mydict->values()
9919
LemonBoy0f7a3e12022-05-26 12:10:37 +01009920virtcol({expr} [, {list}]) *virtcol()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009921 The result is a Number, which is the screen column of the file
9922 position given with {expr}. That is, the last screen position
9923 occupied by the character at that position, when the screen
9924 would be of unlimited width. When there is a <Tab> at the
9925 position, the returned Number will be the column at the end of
9926 the <Tab>. For example, for a <Tab> in column 1, with 'ts'
9927 set to 8, it returns 8. |conceal| is ignored.
9928 For the byte position use |col()|.
LemonBoy0f7a3e12022-05-26 12:10:37 +01009929
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009930 For the use of {expr} see |col()|.
LemonBoy0f7a3e12022-05-26 12:10:37 +01009931
9932 When 'virtualedit' is used {expr} can be [lnum, col, off],
9933 where "off" is the offset in screen columns from the start of
9934 the character. E.g., a position within a <Tab> or after the
9935 last character. When "off" is omitted zero is used. When
9936 Virtual editing is active in the current mode, a position
9937 beyond the end of the line can be returned. Also see
9938 |'virtualedit'|
9939
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009940 The accepted positions are:
9941 . the cursor position
9942 $ the end of the cursor line (the result is the
9943 number of displayed characters in the cursor line
9944 plus one)
9945 'x position of mark x (if the mark is not set, 0 is
9946 returned)
9947 v In Visual mode: the start of the Visual area (the
9948 cursor is the end). When not in Visual mode
9949 returns the cursor position. Differs from |'<| in
9950 that it's updated right away.
LemonBoy0f7a3e12022-05-26 12:10:37 +01009951
9952 If {list} is present and non-zero then virtcol() returns a List
9953 with the first and last screen position occupied by the
9954 character.
9955
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009956 Note that only marks in the current file can be used.
9957 Examples: >
LemonBoy0f7a3e12022-05-26 12:10:37 +01009958 " With text "foo^Lbar" and cursor on the "^L":
9959
9960 virtcol(".") " returns 5
9961 virtcol(".", 1) " returns [4, 5]
9962 virtcol("$") " returns 9
9963
9964 " With text " there", with 't at 'h':
9965
9966 virtcol("'t") " returns 6
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009967< The first column is 1. 0 is returned for an error.
9968 A more advanced example that echoes the maximum length of
9969 all lines: >
9970 echo max(map(range(1, line('$')), "virtcol([v:val, '$'])"))
9971
9972< Can also be used as a |method|: >
9973 GetPos()->virtcol()
9974
Bram Moolenaar5a6ec102022-05-27 21:58:00 +01009975virtcol2col({winid}, {lnum}, {col}) *virtcol2col()*
9976 The result is a Number, which is the byte index of the
9977 character in window {winid} at buffer line {lnum} and virtual
9978 column {col}.
9979
9980 If {col} is greater than the last virtual column in line
9981 {lnum}, then the byte index of the character at the last
9982 virtual column is returned.
9983
9984 The {winid} argument can be the window number or the
9985 |window-ID|. If this is zero, then the current window is used.
9986
9987 Returns -1 if the window {winid} doesn't exist or the buffer
9988 line {lnum} or virtual column {col} is invalid.
9989
9990 See also |screenpos()|, |virtcol()| and |col()|.
9991
9992 Can also be used as a |method|: >
9993 GetWinid()->virtcol2col(lnum, col)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009994
9995visualmode([{expr}]) *visualmode()*
9996 The result is a String, which describes the last Visual mode
9997 used in the current buffer. Initially it returns an empty
9998 string, but once Visual mode has been used, it returns "v",
9999 "V", or "<CTRL-V>" (a single CTRL-V character) for
10000 character-wise, line-wise, or block-wise Visual mode
10001 respectively.
10002 Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +000010003 :exe "normal " .. visualmode()
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010004< This enters the same Visual mode as before. It is also useful
10005 in scripts if you wish to act differently depending on the
10006 Visual mode that was used.
10007 If Visual mode is active, use |mode()| to get the Visual mode
10008 (e.g., in a |:vmap|).
10009 If {expr} is supplied and it evaluates to a non-zero Number or
10010 a non-empty String, then the Visual mode will be cleared and
10011 the old value is returned. See |non-zero-arg|.
10012
10013wildmenumode() *wildmenumode()*
10014 Returns |TRUE| when the wildmenu is active and |FALSE|
10015 otherwise. See 'wildmenu' and 'wildmode'.
10016 This can be used in mappings to handle the 'wildcharm' option
10017 gracefully. (Makes only sense with |mapmode-c| mappings).
10018
10019 For example to make <c-j> work like <down> in wildmode, use: >
10020 :cnoremap <expr> <C-j> wildmenumode() ? "\<Down>\<Tab>" : "\<c-j>"
10021<
10022 (Note, this needs the 'wildcharm' option set appropriately).
10023
10024win_execute({id}, {command} [, {silent}]) *win_execute()*
10025 Like `execute()` but in the context of window {id}.
10026 The window will temporarily be made the current window,
10027 without triggering autocommands or changing directory. When
10028 executing {command} autocommands will be triggered, this may
10029 have unexpected side effects. Use |:noautocmd| if needed.
10030 Example: >
10031 call win_execute(winid, 'set syntax=python')
10032< Doing the same with `setwinvar()` would not trigger
10033 autocommands and not actually show syntax highlighting.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010034 *E994*
10035 Not all commands are allowed in popup windows.
10036 When window {id} does not exist then no error is given and
10037 an empty string is returned.
10038
10039 Can also be used as a |method|, the base is passed as the
10040 second argument: >
10041 GetCommand()->win_execute(winid)
10042
10043win_findbuf({bufnr}) *win_findbuf()*
10044 Returns a |List| with |window-ID|s for windows that contain
10045 buffer {bufnr}. When there is none the list is empty.
10046
10047 Can also be used as a |method|: >
10048 GetBufnr()->win_findbuf()
10049
10050win_getid([{win} [, {tab}]]) *win_getid()*
10051 Get the |window-ID| for the specified window.
10052 When {win} is missing use the current window.
10053 With {win} this is the window number. The top window has
10054 number 1.
10055 Without {tab} use the current tab, otherwise the tab with
10056 number {tab}. The first tab has number one.
10057 Return zero if the window cannot be found.
10058
10059 Can also be used as a |method|: >
10060 GetWinnr()->win_getid()
10061
10062
10063win_gettype([{nr}]) *win_gettype()*
10064 Return the type of the window:
10065 "autocmd" autocommand window. Temporary window
10066 used to execute autocommands.
10067 "command" command-line window |cmdwin|
10068 (empty) normal window
10069 "loclist" |location-list-window|
10070 "popup" popup window |popup|
10071 "preview" preview window |preview-window|
10072 "quickfix" |quickfix-window|
10073 "unknown" window {nr} not found
10074
10075 When {nr} is omitted return the type of the current window.
10076 When {nr} is given return the type of this window by number or
10077 |window-ID|.
10078
10079 Also see the 'buftype' option. When running a terminal in a
10080 popup window then 'buftype' is "terminal" and win_gettype()
10081 returns "popup".
10082
10083 Can also be used as a |method|: >
10084 GetWinid()->win_gettype()
10085<
10086win_gotoid({expr}) *win_gotoid()*
10087 Go to window with ID {expr}. This may also change the current
10088 tabpage.
10089 Return TRUE if successful, FALSE if the window cannot be found.
10090
10091 Can also be used as a |method|: >
10092 GetWinid()->win_gotoid()
10093
10094win_id2tabwin({expr}) *win_id2tabwin()*
10095 Return a list with the tab number and window number of window
10096 with ID {expr}: [tabnr, winnr].
10097 Return [0, 0] if the window cannot be found.
10098
10099 Can also be used as a |method|: >
10100 GetWinid()->win_id2tabwin()
10101
10102win_id2win({expr}) *win_id2win()*
10103 Return the window number of window with ID {expr}.
10104 Return 0 if the window cannot be found in the current tabpage.
10105
10106 Can also be used as a |method|: >
10107 GetWinid()->win_id2win()
10108
Daniel Steinbergee630312022-01-10 13:36:34 +000010109win_move_separator({nr}, {offset}) *win_move_separator()*
10110 Move window {nr}'s vertical separator (i.e., the right border)
10111 by {offset} columns, as if being dragged by the mouse. {nr}
10112 can be a window number or |window-ID|. A positive {offset}
10113 moves right and a negative {offset} moves left. Moving a
10114 window's vertical separator will change the width of the
10115 window and the width of other windows adjacent to the vertical
10116 separator. The magnitude of movement may be smaller than
10117 specified (e.g., as a consequence of maintaining
10118 'winminwidth'). Returns TRUE if the window can be found and
10119 FALSE otherwise.
Bram Moolenaard592deb2022-06-17 15:42:40 +010010120 This will fail for the rightmost window and a full-width
10121 window, since it has no separator on the right.
Daniel Steinbergee630312022-01-10 13:36:34 +000010122
10123 Can also be used as a |method|: >
10124 GetWinnr()->win_move_separator(offset)
10125
10126win_move_statusline({nr}, {offset}) *win_move_statusline()*
10127 Move window {nr}'s status line (i.e., the bottom border) by
10128 {offset} rows, as if being dragged by the mouse. {nr} can be a
10129 window number or |window-ID|. A positive {offset} moves down
10130 and a negative {offset} moves up. Moving a window's status
10131 line will change the height of the window and the height of
10132 other windows adjacent to the status line. The magnitude of
10133 movement may be smaller than specified (e.g., as a consequence
10134 of maintaining 'winminheight'). Returns TRUE if the window can
10135 be found and FALSE otherwise.
10136
10137 Can also be used as a |method|: >
10138 GetWinnr()->win_move_statusline(offset)
10139
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010140win_screenpos({nr}) *win_screenpos()*
10141 Return the screen position of window {nr} as a list with two
10142 numbers: [row, col]. The first window always has position
10143 [1, 1], unless there is a tabline, then it is [2, 1].
10144 {nr} can be the window number or the |window-ID|. Use zero
10145 for the current window.
10146 Returns [0, 0] if the window cannot be found in the current
10147 tabpage.
10148
10149 Can also be used as a |method|: >
10150 GetWinid()->win_screenpos()
10151<
10152win_splitmove({nr}, {target} [, {options}]) *win_splitmove()*
10153 Move the window {nr} to a new split of the window {target}.
10154 This is similar to moving to {target}, creating a new window
10155 using |:split| but having the same contents as window {nr}, and
10156 then closing {nr}.
10157
10158 Both {nr} and {target} can be window numbers or |window-ID|s.
10159 Both must be in the current tab page.
10160
10161 Returns zero for success, non-zero for failure.
10162
10163 {options} is a |Dictionary| with the following optional entries:
10164 "vertical" When TRUE, the split is created vertically,
10165 like with |:vsplit|.
10166 "rightbelow" When TRUE, the split is made below or to the
10167 right (if vertical). When FALSE, it is done
10168 above or to the left (if vertical). When not
10169 present, the values of 'splitbelow' and
10170 'splitright' are used.
10171
10172 Can also be used as a |method|: >
10173 GetWinid()->win_splitmove(target)
10174<
10175
10176 *winbufnr()*
10177winbufnr({nr}) The result is a Number, which is the number of the buffer
10178 associated with window {nr}. {nr} can be the window number or
10179 the |window-ID|.
10180 When {nr} is zero, the number of the buffer in the current
10181 window is returned.
10182 When window {nr} doesn't exist, -1 is returned.
10183 Example: >
10184 :echo "The file in the current window is " . bufname(winbufnr(0))
10185<
10186 Can also be used as a |method|: >
10187 FindWindow()->winbufnr()->bufname()
10188<
10189 *wincol()*
10190wincol() The result is a Number, which is the virtual column of the
10191 cursor in the window. This is counting screen cells from the
10192 left side of the window. The leftmost column is one.
10193
10194 *windowsversion()*
10195windowsversion()
10196 The result is a String. For MS-Windows it indicates the OS
10197 version. E.g, Windows 10 is "10.0", Windows 8 is "6.2",
10198 Windows XP is "5.1". For non-MS-Windows systems the result is
10199 an empty string.
10200
10201winheight({nr}) *winheight()*
10202 The result is a Number, which is the height of window {nr}.
10203 {nr} can be the window number or the |window-ID|.
10204 When {nr} is zero, the height of the current window is
10205 returned. When window {nr} doesn't exist, -1 is returned.
10206 An existing window always has a height of zero or more.
10207 This excludes any window toolbar line.
10208 Examples: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +000010209 :echo "The current window has " .. winheight(0) .. " lines."
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010210
10211< Can also be used as a |method|: >
10212 GetWinid()->winheight()
10213<
10214winlayout([{tabnr}]) *winlayout()*
10215 The result is a nested List containing the layout of windows
10216 in a tabpage.
10217
10218 Without {tabnr} use the current tabpage, otherwise the tabpage
10219 with number {tabnr}. If the tabpage {tabnr} is not found,
10220 returns an empty list.
10221
10222 For a leaf window, it returns:
10223 ['leaf', {winid}]
10224 For horizontally split windows, which form a column, it
10225 returns:
10226 ['col', [{nested list of windows}]]
10227 For vertically split windows, which form a row, it returns:
10228 ['row', [{nested list of windows}]]
10229
10230 Example: >
10231 " Only one window in the tab page
10232 :echo winlayout()
10233 ['leaf', 1000]
10234 " Two horizontally split windows
10235 :echo winlayout()
10236 ['col', [['leaf', 1000], ['leaf', 1001]]]
10237 " The second tab page, with three horizontally split
10238 " windows, with two vertically split windows in the
10239 " middle window
10240 :echo winlayout(2)
10241 ['col', [['leaf', 1002], ['row', [['leaf', 1003],
10242 ['leaf', 1001]]], ['leaf', 1000]]]
10243<
10244 Can also be used as a |method|: >
10245 GetTabnr()->winlayout()
10246<
10247 *winline()*
10248winline() The result is a Number, which is the screen line of the cursor
10249 in the window. This is counting screen lines from the top of
10250 the window. The first line is one.
10251 If the cursor was moved the view on the file will be updated
10252 first, this may cause a scroll.
10253
10254 *winnr()*
10255winnr([{arg}]) The result is a Number, which is the number of the current
10256 window. The top window has number 1.
10257 Returns zero for a popup window.
10258
10259 The optional argument {arg} supports the following values:
10260 $ the number of the last window (the window
10261 count).
10262 # the number of the last accessed window (where
10263 |CTRL-W_p| goes to). If there is no previous
10264 window or it is in another tab page 0 is
10265 returned.
10266 {N}j the number of the Nth window below the
10267 current window (where |CTRL-W_j| goes to).
10268 {N}k the number of the Nth window above the current
10269 window (where |CTRL-W_k| goes to).
10270 {N}h the number of the Nth window left of the
10271 current window (where |CTRL-W_h| goes to).
10272 {N}l the number of the Nth window right of the
10273 current window (where |CTRL-W_l| goes to).
10274 The number can be used with |CTRL-W_w| and ":wincmd w"
10275 |:wincmd|.
Bram Moolenaar016188f2022-06-06 20:52:59 +010010276 When {arg} is invalid an error is given and zero is returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010277 Also see |tabpagewinnr()| and |win_getid()|.
10278 Examples: >
10279 let window_count = winnr('$')
10280 let prev_window = winnr('#')
10281 let wnum = winnr('3k')
10282
10283< Can also be used as a |method|: >
10284 GetWinval()->winnr()
10285<
10286 *winrestcmd()*
10287winrestcmd() Returns a sequence of |:resize| commands that should restore
10288 the current window sizes. Only works properly when no windows
10289 are opened or closed and the current window and tab page is
10290 unchanged.
10291 Example: >
10292 :let cmd = winrestcmd()
10293 :call MessWithWindowSizes()
10294 :exe cmd
10295<
10296 *winrestview()*
10297winrestview({dict})
10298 Uses the |Dictionary| returned by |winsaveview()| to restore
10299 the view of the current window.
10300 Note: The {dict} does not have to contain all values, that are
10301 returned by |winsaveview()|. If values are missing, those
10302 settings won't be restored. So you can use: >
10303 :call winrestview({'curswant': 4})
10304<
10305 This will only set the curswant value (the column the cursor
10306 wants to move on vertical movements) of the cursor to column 5
10307 (yes, that is 5), while all other settings will remain the
10308 same. This is useful, if you set the cursor position manually.
10309
10310 If you have changed the values the result is unpredictable.
10311 If the window size changed the result won't be the same.
10312
10313 Can also be used as a |method|: >
10314 GetView()->winrestview()
10315<
10316 *winsaveview()*
10317winsaveview() Returns a |Dictionary| that contains information to restore
10318 the view of the current window. Use |winrestview()| to
10319 restore the view.
10320 This is useful if you have a mapping that jumps around in the
10321 buffer and you want to go back to the original view.
10322 This does not save fold information. Use the 'foldenable'
10323 option to temporarily switch off folding, so that folds are
10324 not opened when moving around. This may have side effects.
10325 The return value includes:
10326 lnum cursor line number
10327 col cursor column (Note: the first column
naohiro ono56200ee2022-01-01 14:59:44 +000010328 zero, as opposed to what |getcurpos()|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010329 returns)
10330 coladd cursor column offset for 'virtualedit'
naohiro ono56200ee2022-01-01 14:59:44 +000010331 curswant column for vertical movement (Note:
10332 the first column is zero, as opposed
10333 to what |getcurpos()| returns). After
10334 |$| command it will be a very large
10335 number equal to |v:maxcol|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010336 topline first line in the window
10337 topfill filler lines, only in diff mode
10338 leftcol first column displayed; only used when
10339 'wrap' is off
10340 skipcol columns skipped
10341 Note that no option values are saved.
10342
10343
10344winwidth({nr}) *winwidth()*
10345 The result is a Number, which is the width of window {nr}.
10346 {nr} can be the window number or the |window-ID|.
10347 When {nr} is zero, the width of the current window is
10348 returned. When window {nr} doesn't exist, -1 is returned.
10349 An existing window always has a width of zero or more.
10350 Examples: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +000010351 :echo "The current window has " .. winwidth(0) .. " columns."
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010352 :if winwidth(0) <= 50
10353 : 50 wincmd |
10354 :endif
10355< For getting the terminal or screen size, see the 'columns'
10356 option.
10357
10358 Can also be used as a |method|: >
10359 GetWinid()->winwidth()
10360
10361
10362wordcount() *wordcount()*
10363 The result is a dictionary of byte/chars/word statistics for
10364 the current buffer. This is the same info as provided by
10365 |g_CTRL-G|
10366 The return value includes:
10367 bytes Number of bytes in the buffer
10368 chars Number of chars in the buffer
10369 words Number of words in the buffer
10370 cursor_bytes Number of bytes before cursor position
10371 (not in Visual mode)
10372 cursor_chars Number of chars before cursor position
10373 (not in Visual mode)
10374 cursor_words Number of words before cursor position
10375 (not in Visual mode)
10376 visual_bytes Number of bytes visually selected
10377 (only in Visual mode)
10378 visual_chars Number of chars visually selected
10379 (only in Visual mode)
10380 visual_words Number of words visually selected
10381 (only in Visual mode)
10382
10383
10384 *writefile()*
10385writefile({object}, {fname} [, {flags}])
10386 When {object} is a |List| write it to file {fname}. Each list
10387 item is separated with a NL. Each list item must be a String
10388 or Number.
10389 When {flags} contains "b" then binary mode is used: There will
10390 not be a NL after the last list item. An empty item at the
10391 end does cause the last line in the file to end in a NL.
10392
10393 When {object} is a |Blob| write the bytes to file {fname}
10394 unmodified.
10395
10396 When {flags} contains "a" then append mode is used, lines are
10397 appended to the file: >
10398 :call writefile(["foo"], "event.log", "a")
10399 :call writefile(["bar"], "event.log", "a")
10400<
10401 When {flags} contains "s" then fsync() is called after writing
10402 the file. This flushes the file to disk, if possible. This
10403 takes more time but avoids losing the file if the system
10404 crashes.
10405 When {flags} does not contain "S" or "s" then fsync() is
10406 called if the 'fsync' option is set.
10407 When {flags} contains "S" then fsync() is not called, even
10408 when 'fsync' is set.
10409
10410 All NL characters are replaced with a NUL character.
10411 Inserting CR characters needs to be done before passing {list}
10412 to writefile().
10413 An existing file is overwritten, if possible.
10414 When the write fails -1 is returned, otherwise 0. There is an
10415 error message if the file can't be created or when writing
10416 fails.
10417 Also see |readfile()|.
10418 To copy a file byte for byte: >
10419 :let fl = readfile("foo", "b")
10420 :call writefile(fl, "foocopy", "b")
10421
10422< Can also be used as a |method|: >
10423 GetText()->writefile("thefile")
10424
10425
10426xor({expr}, {expr}) *xor()*
10427 Bitwise XOR on the two arguments. The arguments are converted
10428 to a number. A List, Dict or Float argument causes an error.
Bram Moolenaar5a6ec102022-05-27 21:58:00 +010010429 Also see `and()` and `or()`.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010430 Example: >
10431 :let bits = xor(bits, 0x80)
10432<
10433 Can also be used as a |method|: >
10434 :let bits = bits->xor(0x80)
10435<
10436
10437==============================================================================
104383. Feature list *feature-list*
10439
10440There are three types of features:
104411. Features that are only supported when they have been enabled when Vim
10442 was compiled |+feature-list|. Example: >
10443 :if has("cindent")
10444< *gui_running*
104452. Features that are only supported when certain conditions have been met.
10446 Example: >
10447 :if has("gui_running")
10448< *has-patch*
104493. Beyond a certain version or at a certain version and including a specific
10450 patch. The "patch-7.4.248" feature means that the Vim version is 7.5 or
10451 later, or it is version 7.4 and patch 248 was included. Example: >
10452 :if has("patch-7.4.248")
10453< Note that it's possible for patch 248 to be omitted even though 249 is
10454 included. Only happens when cherry-picking patches.
10455 Note that this form only works for patch 7.4.237 and later, before that
10456 you need to check for the patch and the v:version. Example (checking
10457 version 6.2.148 or later): >
10458 :if v:version > 602 || (v:version == 602 && has("patch148"))
10459
10460Hint: To find out if Vim supports backslashes in a file name (MS-Windows),
10461use: `if exists('+shellslash')`
10462
10463
10464acl Compiled with |ACL| support.
10465all_builtin_terms Compiled with all builtin terminals enabled.
10466amiga Amiga version of Vim.
10467arabic Compiled with Arabic support |Arabic|.
10468arp Compiled with ARP support (Amiga).
10469autocmd Compiled with autocommand support. (always true)
10470autochdir Compiled with support for 'autochdir'
10471autoservername Automatically enable |clientserver|
10472balloon_eval Compiled with |balloon-eval| support.
10473balloon_multiline GUI supports multiline balloons.
10474beos BeOS version of Vim.
10475browse Compiled with |:browse| support, and browse() will
10476 work.
10477browsefilter Compiled with support for |browsefilter|.
10478bsd Compiled on an OS in the BSD family (excluding macOS).
10479builtin_terms Compiled with some builtin terminals.
10480byte_offset Compiled with support for 'o' in 'statusline'
10481channel Compiled with support for |channel| and |job|
Bram Moolenaare1dc76f2022-06-25 18:01:32 +010010482cindent Compiled with 'cindent' support. (always true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010483clientserver Compiled with remote invocation support |clientserver|.
10484clipboard Compiled with 'clipboard' support.
10485clipboard_working Compiled with 'clipboard' support and it can be used.
10486cmdline_compl Compiled with |cmdline-completion| support.
10487cmdline_hist Compiled with |cmdline-history| support.
10488cmdline_info Compiled with 'showcmd' and 'ruler' support.
10489comments Compiled with |'comments'| support.
10490compatible Compiled to be very Vi compatible.
10491conpty Platform where |ConPTY| can be used.
10492cryptv Compiled with encryption support |encryption|.
10493cscope Compiled with |cscope| support.
10494cursorbind Compiled with |'cursorbind'| (always true)
10495debug Compiled with "DEBUG" defined.
10496dialog_con Compiled with console dialog support.
10497dialog_gui Compiled with GUI dialog support.
10498diff Compiled with |vimdiff| and 'diff' support.
10499digraphs Compiled with support for digraphs.
10500directx Compiled with support for DirectX and 'renderoptions'.
10501dnd Compiled with support for the "~ register |quote_~|.
10502drop_file Compiled with |drop_file| support.
10503ebcdic Compiled on a machine with ebcdic character set.
10504emacs_tags Compiled with support for Emacs tags.
10505eval Compiled with expression evaluation support. Always
10506 true, of course!
10507ex_extra |+ex_extra| (always true)
10508extra_search Compiled with support for |'incsearch'| and
10509 |'hlsearch'|
10510farsi Support for Farsi was removed |farsi|.
10511file_in_path Compiled with support for |gf| and |<cfile>|
10512filterpipe When 'shelltemp' is off pipes are used for shell
10513 read/write/filter commands
10514find_in_path Compiled with support for include file searches
10515 |+find_in_path|.
10516float Compiled with support for |Float|.
10517fname_case Case in file names matters (for Amiga and MS-Windows
10518 this is not present).
10519folding Compiled with |folding| support.
10520footer Compiled with GUI footer support. |gui-footer|
10521fork Compiled to use fork()/exec() instead of system().
10522gettext Compiled with message translation |multi-lang|
10523gui Compiled with GUI enabled.
Bram Moolenaarcbaff5e2022-04-08 17:45:08 +010010524gui_athena Compiled with Athena GUI (always false).
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010525gui_gnome Compiled with Gnome support (gui_gtk is also defined).
10526gui_gtk Compiled with GTK+ GUI (any version).
10527gui_gtk2 Compiled with GTK+ 2 GUI (gui_gtk is also defined).
10528gui_gtk3 Compiled with GTK+ 3 GUI (gui_gtk is also defined).
10529gui_haiku Compiled with Haiku GUI.
10530gui_mac Compiled with Macintosh GUI.
10531gui_motif Compiled with Motif GUI.
10532gui_photon Compiled with Photon GUI.
10533gui_running Vim is running in the GUI, or it will start soon.
10534gui_win32 Compiled with MS-Windows Win32 GUI.
10535gui_win32s idem, and Win32s system being used (Windows 3.1)
10536haiku Haiku version of Vim.
10537hangul_input Compiled with Hangul input support. |hangul|
10538hpux HP-UX version of Vim.
10539iconv Can use iconv() for conversion.
10540insert_expand Compiled with support for CTRL-X expansion commands in
10541 Insert mode. (always true)
10542job Compiled with support for |channel| and |job|
10543ipv6 Compiled with support for IPv6 networking in |channel|.
Bram Moolenaare1dc76f2022-06-25 18:01:32 +010010544jumplist Compiled with |jumplist| support. (always true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010545keymap Compiled with 'keymap' support.
10546lambda Compiled with |lambda| support.
10547langmap Compiled with 'langmap' support.
10548libcall Compiled with |libcall()| support.
10549linebreak Compiled with 'linebreak', 'breakat', 'showbreak' and
10550 'breakindent' support.
10551linux Linux version of Vim.
10552lispindent Compiled with support for lisp indenting.
Bram Moolenaare1dc76f2022-06-25 18:01:32 +010010553 (always true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010554listcmds Compiled with commands for the buffer list |:files|
10555 and the argument list |arglist|.
10556localmap Compiled with local mappings and abbr. |:map-local|
10557lua Compiled with Lua interface |Lua|.
10558mac Any Macintosh version of Vim cf. osx
10559macunix Synonym for osxdarwin
10560menu Compiled with support for |:menu|.
10561mksession Compiled with support for |:mksession|.
10562modify_fname Compiled with file name modifiers. |filename-modifiers|
10563 (always true)
10564mouse Compiled with support for mouse.
10565mouse_dec Compiled with support for Dec terminal mouse.
10566mouse_gpm Compiled with support for gpm (Linux console mouse)
10567mouse_gpm_enabled GPM mouse is working
10568mouse_netterm Compiled with support for netterm mouse.
10569mouse_pterm Compiled with support for qnx pterm mouse.
10570mouse_sysmouse Compiled with support for sysmouse (*BSD console mouse)
10571mouse_sgr Compiled with support for sgr mouse.
10572mouse_urxvt Compiled with support for urxvt mouse.
10573mouse_xterm Compiled with support for xterm mouse.
10574mouseshape Compiled with support for 'mouseshape'.
10575multi_byte Compiled with support for 'encoding' (always true)
10576multi_byte_encoding 'encoding' is set to a multibyte encoding.
10577multi_byte_ime Compiled with support for IME input method.
10578multi_lang Compiled with support for multiple languages.
10579mzscheme Compiled with MzScheme interface |mzscheme|.
10580nanotime Compiled with sub-second time stamp checks.
10581netbeans_enabled Compiled with support for |netbeans| and connected.
10582netbeans_intg Compiled with support for |netbeans|.
Bram Moolenaare1dc76f2022-06-25 18:01:32 +010010583num64 Compiled with 64-bit |Number| support. (always true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010584ole Compiled with OLE automation support for Win32.
10585osx Compiled for macOS cf. mac
10586osxdarwin Compiled for macOS, with |mac-darwin-feature|
10587packages Compiled with |packages| support.
10588path_extra Compiled with up/downwards search in 'path' and 'tags'
10589perl Compiled with Perl interface.
10590persistent_undo Compiled with support for persistent undo history.
10591postscript Compiled with PostScript file printing.
10592printer Compiled with |:hardcopy| support.
10593profile Compiled with |:profile| support.
10594python Python 2.x interface available. |has-python|
10595python_compiled Compiled with Python 2.x interface. |has-python|
10596python_dynamic Python 2.x interface is dynamically loaded. |has-python|
10597python3 Python 3.x interface available. |has-python|
10598python3_compiled Compiled with Python 3.x interface. |has-python|
10599python3_dynamic Python 3.x interface is dynamically loaded. |has-python|
10600pythonx Python 2.x and/or 3.x interface available. |python_x|
10601qnx QNX version of Vim.
10602quickfix Compiled with |quickfix| support.
10603reltime Compiled with |reltime()| support.
10604rightleft Compiled with 'rightleft' support.
10605ruby Compiled with Ruby interface |ruby|.
10606scrollbind Compiled with 'scrollbind' support. (always true)
10607showcmd Compiled with 'showcmd' support.
10608signs Compiled with |:sign| support.
Bram Moolenaare1dc76f2022-06-25 18:01:32 +010010609smartindent Compiled with 'smartindent' support. (always true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010610sodium Compiled with libsodium for better crypt support
10611sound Compiled with sound support, e.g. `sound_playevent()`
10612spell Compiled with spell checking support |spell|.
10613startuptime Compiled with |--startuptime| support.
10614statusline Compiled with support for 'statusline', 'rulerformat'
10615 and special formats of 'titlestring' and 'iconstring'.
10616sun SunOS version of Vim.
10617sun_workshop Support for Sun |workshop| has been removed.
10618syntax Compiled with syntax highlighting support |syntax|.
10619syntax_items There are active syntax highlighting items for the
10620 current buffer.
10621system Compiled to use system() instead of fork()/exec().
10622tag_binary Compiled with binary searching in tags files
Bram Moolenaare1dc76f2022-06-25 18:01:32 +010010623 |tag-binary-search|. (always true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010624tag_old_static Support for old static tags was removed, see
10625 |tag-old-static|.
10626tcl Compiled with Tcl interface.
10627termguicolors Compiled with true color in terminal support.
10628terminal Compiled with |terminal| support.
10629terminfo Compiled with terminfo instead of termcap.
10630termresponse Compiled with support for |t_RV| and |v:termresponse|.
10631textobjects Compiled with support for |text-objects|.
10632textprop Compiled with support for |text-properties|.
10633tgetent Compiled with tgetent support, able to use a termcap
10634 or terminfo file.
10635timers Compiled with |timer_start()| support.
10636title Compiled with window title support |'title'|.
Bram Moolenaare1dc76f2022-06-25 18:01:32 +010010637 (always true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010638toolbar Compiled with support for |gui-toolbar|.
10639ttyin input is a terminal (tty)
10640ttyout output is a terminal (tty)
10641unix Unix version of Vim. *+unix*
10642unnamedplus Compiled with support for "unnamedplus" in 'clipboard'
10643user_commands User-defined commands. (always true)
10644vartabs Compiled with variable tabstop support |'vartabstop'|.
10645vcon Win32: Virtual console support is working, can use
10646 'termguicolors'. Also see |+vtp|.
10647vertsplit Compiled with vertically split windows |:vsplit|.
10648 (always true)
10649vim_starting True while initial source'ing takes place. |startup|
10650 *vim_starting*
Bram Moolenaara6feb162022-01-02 12:06:33 +000010651vim9script Compiled with |Vim9| script support
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010652viminfo Compiled with viminfo support.
10653vimscript-1 Compiled Vim script version 1 support
10654vimscript-2 Compiled Vim script version 2 support
10655vimscript-3 Compiled Vim script version 3 support
Bram Moolenaar8a3b8052022-06-26 12:21:15 +010010656vimscript-4 Compiled Vim script version 4 support
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010657virtualedit Compiled with 'virtualedit' option. (always true)
10658visual Compiled with Visual mode. (always true)
10659visualextra Compiled with extra Visual mode commands. (always
10660 true) |blockwise-operators|.
10661vms VMS version of Vim.
10662vreplace Compiled with |gR| and |gr| commands. (always true)
10663vtp Compiled for vcon support |+vtp| (check vcon to find
10664 out if it works in the current console).
10665wildignore Compiled with 'wildignore' option.
10666wildmenu Compiled with 'wildmenu' option.
10667win16 old version for MS-Windows 3.1 (always false)
10668win32 Win32 version of Vim (MS-Windows 95 and later, 32 or
10669 64 bits)
10670win32unix Win32 version of Vim, using Unix files (Cygwin)
10671win64 Win64 version of Vim (MS-Windows 64 bit).
10672win95 Win32 version for MS-Windows 95/98/ME (always false)
10673winaltkeys Compiled with 'winaltkeys' option.
10674windows Compiled with support for more than one window.
10675 (always true)
10676writebackup Compiled with 'writebackup' default on.
10677xfontset Compiled with X fontset support |xfontset|.
10678xim Compiled with X input method support |xim|.
10679xpm Compiled with pixmap support.
10680xpm_w32 Compiled with pixmap support for Win32. (Only for
10681 backward compatibility. Use "xpm" instead.)
10682xsmp Compiled with X session management support.
10683xsmp_interact Compiled with interactive X session management support.
10684xterm_clipboard Compiled with support for xterm clipboard.
10685xterm_save Compiled with support for saving and restoring the
10686 xterm screen.
10687x11 Compiled with X11 support.
10688
10689
10690==============================================================================
106914. Matching a pattern in a String *string-match*
10692
10693This is common between several functions. A regexp pattern as explained at
10694|pattern| is normally used to find a match in the buffer lines. When a
10695pattern is used to find a match in a String, almost everything works in the
10696same way. The difference is that a String is handled like it is one line.
10697When it contains a "\n" character, this is not seen as a line break for the
10698pattern. It can be matched with a "\n" in the pattern, or with ".". Example:
10699>
10700 :let a = "aaaa\nxxxx"
10701 :echo matchstr(a, "..\n..")
10702 aa
10703 xx
10704 :echo matchstr(a, "a.x")
10705 a
10706 x
10707
10708Don't forget that "^" will only match at the first character of the String and
10709"$" at the last character of the string. They don't match after or before a
10710"\n".
10711
10712 vim:tw=78:ts=8:noet:ft=help:norl: