blob: 7fb1a435c3a0723d656dbc3b5d62d3e8fc5e05da [file] [log] [blame]
Bram Moolenaar10e8ff92023-06-10 21:40:39 +01001*builtin.txt* For Vim version 9.0. Last change: 2023 Jun 08
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002
3
4 VIM REFERENCE MANUAL by Bram Moolenaar
5
6
7Builtin functions *builtin-functions*
8
Bram Moolenaarf269eab2022-10-03 18:04:35 +01009Note: Expression evaluation can be disabled at compile time, the builtin
10functions are not available then. See |+eval| and |no-eval-feature|.
11
12For functions grouped by what they are used for see |function-list|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000013
141. Overview |builtin-function-list|
152. Details |builtin-function-details|
163. Feature list |feature-list|
174. Matching a pattern in a String |string-match|
18
19==============================================================================
201. Overview *builtin-function-list*
21
22Use CTRL-] on the function name to jump to the full explanation.
23
24USAGE RESULT DESCRIPTION ~
25
26abs({expr}) Float or Number absolute value of {expr}
27acos({expr}) Float arc cosine of {expr}
28add({object}, {item}) List/Blob append {item} to {object}
29and({expr}, {expr}) Number bitwise AND
30append({lnum}, {text}) Number append {text} below line {lnum}
31appendbufline({expr}, {lnum}, {text})
32 Number append {text} below line {lnum}
33 in buffer {expr}
34argc([{winid}]) Number number of files in the argument list
35argidx() Number current index in the argument list
36arglistid([{winnr} [, {tabnr}]]) Number argument list id
37argv({nr} [, {winid}]) String {nr} entry of the argument list
38argv([-1, {winid}]) List the argument list
39asin({expr}) Float arc sine of {expr}
40assert_beeps({cmd}) Number assert {cmd} causes a beep
41assert_equal({exp}, {act} [, {msg}])
42 Number assert {exp} is equal to {act}
43assert_equalfile({fname-one}, {fname-two} [, {msg}])
44 Number assert file contents are equal
45assert_exception({error} [, {msg}])
46 Number assert {error} is in v:exception
47assert_fails({cmd} [, {error} [, {msg} [, {lnum} [, {context}]]]])
48 Number assert {cmd} fails
49assert_false({actual} [, {msg}])
50 Number assert {actual} is false
51assert_inrange({lower}, {upper}, {actual} [, {msg}])
52 Number assert {actual} is inside the range
53assert_match({pat}, {text} [, {msg}])
54 Number assert {pat} matches {text}
55assert_nobeep({cmd}) Number assert {cmd} does not cause a beep
56assert_notequal({exp}, {act} [, {msg}])
57 Number assert {exp} is not equal {act}
58assert_notmatch({pat}, {text} [, {msg}])
59 Number assert {pat} not matches {text}
60assert_report({msg}) Number report a test failure
61assert_true({actual} [, {msg}]) Number assert {actual} is true
62atan({expr}) Float arc tangent of {expr}
63atan2({expr1}, {expr2}) Float arc tangent of {expr1} / {expr2}
Yegappan Lakshmanan1755a912022-05-19 10:31:47 +010064autocmd_add({acmds}) Bool add a list of autocmds and groups
65autocmd_delete({acmds}) Bool delete a list of autocmds and groups
66autocmd_get([{opts}]) List return a list of autocmds
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000067balloon_gettext() String current text in the balloon
68balloon_show({expr}) none show {expr} inside the balloon
69balloon_split({msg}) List split {msg} as used for a balloon
70blob2list({blob}) List convert {blob} into a list of numbers
71browse({save}, {title}, {initdir}, {default})
72 String put up a file requester
73browsedir({title}, {initdir}) String put up a directory requester
74bufadd({name}) Number add a buffer to the buffer list
75bufexists({buf}) Number |TRUE| if buffer {buf} exists
76buflisted({buf}) Number |TRUE| if buffer {buf} is listed
77bufload({buf}) Number load buffer {buf} if not loaded yet
78bufloaded({buf}) Number |TRUE| if buffer {buf} is loaded
79bufname([{buf}]) String Name of the buffer {buf}
80bufnr([{buf} [, {create}]]) Number Number of the buffer {buf}
81bufwinid({buf}) Number window ID of buffer {buf}
82bufwinnr({buf}) Number window number of buffer {buf}
83byte2line({byte}) Number line number at byte count {byte}
Christian Brabandt67672ef2023-04-24 21:09:54 +010084byteidx({expr}, {nr} [, {utf16}])
85 Number byte index of {nr}'th char in {expr}
86byteidxcomp({expr}, {nr} [, {utf16}])
87 Number byte index of {nr}'th char in {expr}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000088call({func}, {arglist} [, {dict}])
89 any call {func} with arguments {arglist}
90ceil({expr}) Float round {expr} up
91ch_canread({handle}) Number check if there is something to read
92ch_close({handle}) none close {handle}
93ch_close_in({handle}) none close in part of {handle}
94ch_evalexpr({handle}, {expr} [, {options}])
95 any evaluate {expr} on JSON {handle}
96ch_evalraw({handle}, {string} [, {options}])
97 any evaluate {string} on raw {handle}
98ch_getbufnr({handle}, {what}) Number get buffer number for {handle}/{what}
99ch_getjob({channel}) Job get the Job of {channel}
100ch_info({handle}) String info about channel {handle}
101ch_log({msg} [, {handle}]) none write {msg} in the channel log file
102ch_logfile({fname} [, {mode}]) none start logging channel activity
103ch_open({address} [, {options}])
104 Channel open a channel to {address}
105ch_read({handle} [, {options}]) String read from {handle}
106ch_readblob({handle} [, {options}])
107 Blob read Blob from {handle}
108ch_readraw({handle} [, {options}])
109 String read raw from {handle}
110ch_sendexpr({handle}, {expr} [, {options}])
111 any send {expr} over JSON {handle}
112ch_sendraw({handle}, {expr} [, {options}])
113 any send {expr} over raw {handle}
114ch_setoptions({handle}, {options})
115 none set options for {handle}
116ch_status({handle} [, {options}])
117 String status of channel {handle}
118changenr() Number current change number
119char2nr({expr} [, {utf8}]) Number ASCII/UTF-8 value of first char in {expr}
120charclass({string}) Number character class of {string}
Yegappan Lakshmanan4c8d2f02022-11-12 16:07:47 +0000121charcol({expr} [, {winid}]) Number column number of cursor or mark
Christian Brabandt67672ef2023-04-24 21:09:54 +0100122charidx({string}, {idx} [, {countcc} [, {utf16}]])
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000123 Number char index of byte {idx} in {string}
124chdir({dir}) String change current working directory
125cindent({lnum}) Number C indent for line {lnum}
126clearmatches([{win}]) none clear all matches
Yegappan Lakshmanan4c8d2f02022-11-12 16:07:47 +0000127col({expr} [, {winid}]) Number column byte index of cursor or mark
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000128complete({startcol}, {matches}) none set Insert mode completion
129complete_add({expr}) Number add completion match
130complete_check() Number check for key typed during completion
131complete_info([{what}]) Dict get current completion information
132confirm({msg} [, {choices} [, {default} [, {type}]]])
133 Number number of choice picked by user
134copy({expr}) any make a shallow copy of {expr}
135cos({expr}) Float cosine of {expr}
136cosh({expr}) Float hyperbolic cosine of {expr}
137count({comp}, {expr} [, {ic} [, {start}]])
138 Number count how many {expr} are in {comp}
139cscope_connection([{num}, {dbpath} [, {prepend}]])
140 Number checks existence of cscope connection
141cursor({lnum}, {col} [, {off}])
142 Number move cursor to {lnum}, {col}, {off}
143cursor({list}) Number move cursor to position in {list}
144debugbreak({pid}) Number interrupt process being debugged
145deepcopy({expr} [, {noref}]) any make a full copy of {expr}
146delete({fname} [, {flags}]) Number delete the file or directory {fname}
147deletebufline({buf}, {first} [, {last}])
148 Number delete lines from buffer {buf}
149did_filetype() Number |TRUE| if FileType autocmd event used
150diff_filler({lnum}) Number diff filler lines about {lnum}
151diff_hlID({lnum}, {col}) Number diff highlighting at {lnum}/{col}
152digraph_get({chars}) String get the |digraph| of {chars}
153digraph_getlist([{listall}]) List get all |digraph|s
154digraph_set({chars}, {digraph}) Boolean register |digraph|
155digraph_setlist({digraphlist}) Boolean register multiple |digraph|s
156echoraw({expr}) none output {expr} as-is
Bram Moolenaar80adaa82023-07-07 18:57:40 +0100157err_teapot() Number produce error 418
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000158empty({expr}) Number |TRUE| if {expr} is empty
159environ() Dict return environment variables
160escape({string}, {chars}) String escape {chars} in {string} with '\'
161eval({string}) any evaluate {string} into its value
162eventhandler() Number |TRUE| if inside an event handler
163executable({expr}) Number 1 if executable {expr} exists
164execute({command}) String execute {command} and get the output
165exepath({expr}) String full path of the command {expr}
166exists({expr}) Number |TRUE| if {expr} exists
167exists_compiled({expr}) Number |TRUE| if {expr} exists at compile time
168exp({expr}) Float exponential of {expr}
169expand({expr} [, {nosuf} [, {list}]])
170 any expand special keywords in {expr}
Yegappan Lakshmanan2b74b682022-04-03 21:30:32 +0100171expandcmd({string} [, {options}])
172 String expand {string} like with `:edit`
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000173extend({expr1}, {expr2} [, {expr3}])
174 List/Dict insert items of {expr2} into {expr1}
175extendnew({expr1}, {expr2} [, {expr3}])
176 List/Dict like |extend()| but creates a new
177 List or Dictionary
178feedkeys({string} [, {mode}]) Number add key sequence to typeahead buffer
179filereadable({file}) Number |TRUE| if {file} is a readable file
180filewritable({file}) Number |TRUE| if {file} is a writable file
181filter({expr1}, {expr2}) List/Dict/Blob/String
182 remove items from {expr1} where
183 {expr2} is 0
184finddir({name} [, {path} [, {count}]])
185 String find directory {name} in {path}
186findfile({name} [, {path} [, {count}]])
187 String find file {name} in {path}
188flatten({list} [, {maxdepth}]) List flatten {list} up to {maxdepth} levels
189flattennew({list} [, {maxdepth}])
190 List flatten a copy of {list}
191float2nr({expr}) Number convert Float {expr} to a Number
192floor({expr}) Float round {expr} down
193fmod({expr1}, {expr2}) Float remainder of {expr1} / {expr2}
194fnameescape({fname}) String escape special characters in {fname}
195fnamemodify({fname}, {mods}) String modify file name
196foldclosed({lnum}) Number first line of fold at {lnum} if closed
197foldclosedend({lnum}) Number last line of fold at {lnum} if closed
198foldlevel({lnum}) Number fold level at {lnum}
199foldtext() String line displayed for closed fold
200foldtextresult({lnum}) String text for closed fold at {lnum}
201foreground() Number bring the Vim window to the foreground
Bram Moolenaaraa534142022-09-15 21:46:02 +0100202fullcommand({name} [, {vim9}]) String get full command from {name}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000203funcref({name} [, {arglist}] [, {dict}])
204 Funcref reference to function {name}
205function({name} [, {arglist}] [, {dict}])
206 Funcref named reference to function {name}
207garbagecollect([{atexit}]) none free memory, breaking cyclic references
208get({list}, {idx} [, {def}]) any get item {idx} from {list} or {def}
209get({dict}, {key} [, {def}]) any get item {key} from {dict} or {def}
210get({func}, {what}) any get property of funcref/partial {func}
211getbufinfo([{buf}]) List information about buffers
212getbufline({buf}, {lnum} [, {end}])
213 List lines {lnum} to {end} of buffer {buf}
Bram Moolenaarce30ccc2022-11-21 19:57:04 +0000214getbufoneline({buf}, {lnum}) String line {lnum} of buffer {buf}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000215getbufvar({buf}, {varname} [, {def}])
216 any variable {varname} in buffer {buf}
Kota Kato66bb9ae2023-01-17 18:31:56 +0000217getcellwidths() List get character cell width overrides
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000218getchangelist([{buf}]) List list of change list items
219getchar([expr]) Number or String
220 get one character from the user
221getcharmod() Number modifiers for the last typed character
222getcharpos({expr}) List position of cursor, mark, etc.
223getcharsearch() Dict last character search
224getcharstr([expr]) String get one character from the user
Shougo Matsushita79d599b2022-05-07 12:48:29 +0100225getcmdcompltype() String return the type of the current
226 command-line completion
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000227getcmdline() String return the current command-line
228getcmdpos() Number return cursor position in command-line
Shougo Matsushita79d599b2022-05-07 12:48:29 +0100229getcmdscreenpos() Number return cursor screen position in
230 command-line
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000231getcmdtype() String return current command-line type
232getcmdwintype() String return current command-line window type
233getcompletion({pat}, {type} [, {filtered}])
234 List list of cmdline completion matches
235getcurpos([{winnr}]) List position of the cursor
236getcursorcharpos([{winnr}]) List character position of the cursor
237getcwd([{winnr} [, {tabnr}]]) String get the current working directory
238getenv({name}) String return environment variable
239getfontname([{name}]) String name of font being used
240getfperm({fname}) String file permissions of file {fname}
241getfsize({fname}) Number size in bytes of file {fname}
242getftime({fname}) Number last modification time of file
243getftype({fname}) String description of type of file {fname}
244getimstatus() Number |TRUE| if the IME status is active
245getjumplist([{winnr} [, {tabnr}]])
246 List list of jump list items
247getline({lnum}) String line {lnum} of current buffer
248getline({lnum}, {end}) List lines {lnum} to {end} of current buffer
249getloclist({nr}) List list of location list items
250getloclist({nr}, {what}) Dict get specific location list properties
251getmarklist([{buf}]) List list of global/local marks
252getmatches([{win}]) List list of current matches
253getmousepos() Dict last known mouse position
Bram Moolenaar24dc19c2022-11-14 19:49:15 +0000254getmouseshape() String current mouse shape name
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000255getpid() Number process ID of Vim
256getpos({expr}) List position of cursor, mark, etc.
257getqflist() List list of quickfix items
258getqflist({what}) Dict get specific quickfix list properties
259getreg([{regname} [, 1 [, {list}]]])
260 String or List contents of a register
261getreginfo([{regname}]) Dict information about a register
262getregtype([{regname}]) String type of a register
Yegappan Lakshmanan520f6ef2022-08-25 17:40:40 +0100263getscriptinfo([{opts}]) List list of sourced scripts
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000264gettabinfo([{expr}]) List list of tab pages
265gettabvar({nr}, {varname} [, {def}])
266 any variable {varname} in tab {nr} or {def}
267gettabwinvar({tabnr}, {winnr}, {name} [, {def}])
268 any {name} in {winnr} in tab page {tabnr}
269gettagstack([{nr}]) Dict get the tag stack of window {nr}
270gettext({text}) String lookup translation of {text}
271getwininfo([{winid}]) List list of info about each window
Bram Moolenaar938ae282023-02-20 20:44:55 +0000272getwinpos([{timeout}]) List X and Y coord in pixels of Vim window
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000273getwinposx() Number X coord in pixels of the Vim window
274getwinposy() Number Y coord in pixels of the Vim window
275getwinvar({nr}, {varname} [, {def}])
276 any variable {varname} in window {nr}
277glob({expr} [, {nosuf} [, {list} [, {alllinks}]]])
278 any expand file wildcards in {expr}
279glob2regpat({expr}) String convert a glob pat into a search pat
280globpath({path}, {expr} [, {nosuf} [, {list} [, {alllinks}]]])
281 String do glob({expr}) for all dirs in {path}
282has({feature} [, {check}]) Number |TRUE| if feature {feature} supported
283has_key({dict}, {key}) Number |TRUE| if {dict} has entry {key}
284haslocaldir([{winnr} [, {tabnr}]])
285 Number |TRUE| if the window executed |:lcd|
286 or |:tcd|
287hasmapto({what} [, {mode} [, {abbr}]])
288 Number |TRUE| if mapping to {what} exists
289histadd({history}, {item}) Number add an item to a history
290histdel({history} [, {item}]) Number remove an item from a history
291histget({history} [, {index}]) String get the item {index} from a history
292histnr({history}) Number highest index of a history
293hlID({name}) Number syntax ID of highlight group {name}
294hlexists({name}) Number |TRUE| if highlight group {name} exists
295hlget([{name} [, {resolve}]]) List get highlight group attributes
296hlset({list}) Number set highlight group attributes
297hostname() String name of the machine Vim is running on
298iconv({expr}, {from}, {to}) String convert encoding of {expr}
299indent({lnum}) Number indent of line {lnum}
300index({object}, {expr} [, {start} [, {ic}]])
301 Number index in {object} where {expr} appears
Yegappan Lakshmananb2186552022-08-13 13:09:20 +0100302indexof({object}, {expr} [, {opts}]])
303 Number index in {object} where {expr} is true
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000304input({prompt} [, {text} [, {completion}]])
305 String get input from the user
Bram Moolenaarb529cfb2022-07-25 15:42:07 +0100306inputdialog({prompt} [, {text} [, {cancelreturn}]])
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000307 String like input() but in a GUI dialog
308inputlist({textlist}) Number let the user pick from a choice list
309inputrestore() Number restore typeahead
310inputsave() Number save and clear typeahead
311inputsecret({prompt} [, {text}]) String like input() but hiding the text
312insert({object}, {item} [, {idx}]) List insert {item} in {object} [before {idx}]
313interrupt() none interrupt script execution
314invert({expr}) Number bitwise invert
LemonBoydca1d402022-04-28 15:26:33 +0100315isabsolutepath({path}) Number |TRUE| if {path} is an absolute path
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000316isdirectory({directory}) Number |TRUE| if {directory} is a directory
317isinf({expr}) Number determine if {expr} is infinity value
318 (positive or negative)
319islocked({expr}) Number |TRUE| if {expr} is locked
320isnan({expr}) Number |TRUE| if {expr} is NaN
321items({dict}) List key-value pairs in {dict}
322job_getchannel({job}) Channel get the channel handle for {job}
323job_info([{job}]) Dict get information about {job}
324job_setoptions({job}, {options}) none set options for {job}
325job_start({command} [, {options}])
326 Job start a job
327job_status({job}) String get the status of {job}
328job_stop({job} [, {how}]) Number stop {job}
329join({list} [, {sep}]) String join {list} items into one String
330js_decode({string}) any decode JS style JSON
331js_encode({expr}) String encode JS style JSON
332json_decode({string}) any decode JSON
333json_encode({expr}) String encode JSON
334keys({dict}) List keys in {dict}
zeertzjqcdc83932022-09-12 13:38:41 +0100335keytrans({string}) String translate internal keycodes to a form
336 that can be used by |:map|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000337len({expr}) Number the length of {expr}
338libcall({lib}, {func}, {arg}) String call {func} in library {lib} with {arg}
339libcallnr({lib}, {func}, {arg}) Number idem, but return a Number
340line({expr} [, {winid}]) Number line nr of cursor, last line or mark
341line2byte({lnum}) Number byte count of line {lnum}
342lispindent({lnum}) Number Lisp indent for line {lnum}
343list2blob({list}) Blob turn {list} of numbers into a Blob
344list2str({list} [, {utf8}]) String turn {list} of numbers into a String
345listener_add({callback} [, {buf}])
346 Number add a callback to listen to changes
347listener_flush([{buf}]) none invoke listener callbacks
348listener_remove({id}) none remove a listener callback
349localtime() Number current time
350log({expr}) Float natural logarithm (base e) of {expr}
351log10({expr}) Float logarithm of Float {expr} to base 10
352luaeval({expr} [, {expr}]) any evaluate |Lua| expression
353map({expr1}, {expr2}) List/Dict/Blob/String
354 change each item in {expr1} to {expr2}
355maparg({name} [, {mode} [, {abbr} [, {dict}]]])
356 String or Dict
357 rhs of mapping {name} in mode {mode}
358mapcheck({name} [, {mode} [, {abbr}]])
359 String check for mappings matching {name}
Ernie Rael09661202022-04-25 14:40:44 +0100360maplist([{abbr}]) List list of all mappings, a dict for each
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000361mapnew({expr1}, {expr2}) List/Dict/Blob/String
362 like |map()| but creates a new List or
363 Dictionary
364mapset({mode}, {abbr}, {dict}) none restore mapping from |maparg()| result
365match({expr}, {pat} [, {start} [, {count}]])
366 Number position where {pat} matches in {expr}
367matchadd({group}, {pattern} [, {priority} [, {id} [, {dict}]]])
368 Number highlight {pattern} with {group}
369matchaddpos({group}, {pos} [, {priority} [, {id} [, {dict}]]])
370 Number highlight positions with {group}
371matcharg({nr}) List arguments of |:match|
372matchdelete({id} [, {win}]) Number delete match identified by {id}
373matchend({expr}, {pat} [, {start} [, {count}]])
374 Number position where {pat} ends in {expr}
375matchfuzzy({list}, {str} [, {dict}])
376 List fuzzy match {str} in {list}
377matchfuzzypos({list}, {str} [, {dict}])
378 List fuzzy match {str} in {list}
379matchlist({expr}, {pat} [, {start} [, {count}]])
380 List match and submatches of {pat} in {expr}
381matchstr({expr}, {pat} [, {start} [, {count}]])
382 String {count}'th match of {pat} in {expr}
383matchstrpos({expr}, {pat} [, {start} [, {count}]])
384 List {count}'th match of {pat} in {expr}
385max({expr}) Number maximum value of items in {expr}
386menu_info({name} [, {mode}]) Dict get menu item information
387min({expr}) Number minimum value of items in {expr}
Bram Moolenaar938ae282023-02-20 20:44:55 +0000388mkdir({name} [, {flags} [, {prot}]])
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000389 Number create directory {name}
390mode([expr]) String current editing mode
391mzeval({expr}) any evaluate |MzScheme| expression
392nextnonblank({lnum}) Number line nr of non-blank line >= {lnum}
393nr2char({expr} [, {utf8}]) String single char with ASCII/UTF-8 value {expr}
394or({expr}, {expr}) Number bitwise OR
395pathshorten({expr} [, {len}]) String shorten directory names in a path
396perleval({expr}) any evaluate |Perl| expression
397popup_atcursor({what}, {options}) Number create popup window near the cursor
398popup_beval({what}, {options}) Number create popup window for 'ballooneval'
399popup_clear() none close all popup windows
400popup_close({id} [, {result}]) none close popup window {id}
401popup_create({what}, {options}) Number create a popup window
402popup_dialog({what}, {options}) Number create a popup window used as a dialog
403popup_filter_menu({id}, {key}) Number filter for a menu popup window
404popup_filter_yesno({id}, {key}) Number filter for a dialog popup window
Bram Moolenaarbdc09a12022-10-07 14:31:45 +0100405popup_findecho() Number get window ID of popup for `:echowin`
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000406popup_findinfo() Number get window ID of info popup window
407popup_findpreview() Number get window ID of preview popup window
408popup_getoptions({id}) Dict get options of popup window {id}
409popup_getpos({id}) Dict get position of popup window {id}
410popup_hide({id}) none hide popup menu {id}
411popup_list() List get a list of window IDs of all popups
412popup_locate({row}, {col}) Number get window ID of popup at position
413popup_menu({what}, {options}) Number create a popup window used as a menu
414popup_move({id}, {options}) none set position of popup window {id}
415popup_notification({what}, {options})
416 Number create a notification popup window
417popup_setoptions({id}, {options})
418 none set options for popup window {id}
419popup_settext({id}, {text}) none set the text of popup window {id}
420popup_show({id}) none unhide popup window {id}
421pow({x}, {y}) Float {x} to the power of {y}
422prevnonblank({lnum}) Number line nr of non-blank line <= {lnum}
423printf({fmt}, {expr1}...) String format text
424prompt_getprompt({buf}) String get prompt text
425prompt_setcallback({buf}, {expr}) none set prompt callback function
426prompt_setinterrupt({buf}, {text}) none set prompt interrupt function
427prompt_setprompt({buf}, {text}) none set prompt text
428prop_add({lnum}, {col}, {props}) none add one text property
429prop_add_list({props}, [[{lnum}, {col}, {end-lnum}, {end-col}], ...])
430 none add multiple text properties
431prop_clear({lnum} [, {lnum-end} [, {props}]])
432 none remove all text properties
433prop_find({props} [, {direction}])
434 Dict search for a text property
435prop_list({lnum} [, {props}]) List text properties in {lnum}
436prop_remove({props} [, {lnum} [, {lnum-end}]])
437 Number remove a text property
438prop_type_add({name}, {props}) none define a new property type
439prop_type_change({name}, {props})
440 none change an existing property type
441prop_type_delete({name} [, {props}])
442 none delete a property type
443prop_type_get({name} [, {props}])
444 Dict get property type values
445prop_type_list([{props}]) List get list of property types
446pum_getpos() Dict position and size of pum if visible
447pumvisible() Number whether popup menu is visible
448py3eval({expr}) any evaluate |python3| expression
449pyeval({expr}) any evaluate |Python| expression
450pyxeval({expr}) any evaluate |python_x| expression
451rand([{expr}]) Number get pseudo-random number
452range({expr} [, {max} [, {stride}]])
453 List items from {expr} to {max}
K.Takata11df3ae2022-10-19 14:02:40 +0100454readblob({fname} [, {offset} [, {size}]])
455 Blob read a |Blob| from {fname}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000456readdir({dir} [, {expr} [, {dict}]])
457 List file names in {dir} selected by {expr}
458readdirex({dir} [, {expr} [, {dict}]])
459 List file info in {dir} selected by {expr}
460readfile({fname} [, {type} [, {max}]])
461 List get list of lines from file {fname}
462reduce({object}, {func} [, {initial}])
463 any reduce {object} using {func}
464reg_executing() String get the executing register name
465reg_recording() String get the recording register name
466reltime([{start} [, {end}]]) List get time value
467reltimefloat({time}) Float turn the time value into a Float
468reltimestr({time}) String turn time value into a String
469remote_expr({server}, {string} [, {idvar} [, {timeout}]])
470 String send expression
471remote_foreground({server}) Number bring Vim server to the foreground
472remote_peek({serverid} [, {retvar}])
473 Number check for reply string
474remote_read({serverid} [, {timeout}])
475 String read reply string
476remote_send({server}, {string} [, {idvar}])
477 String send key sequence
478remote_startserver({name}) none become server {name}
479remove({list}, {idx} [, {end}]) any/List
480 remove items {idx}-{end} from {list}
481remove({blob}, {idx} [, {end}]) Number/Blob
482 remove bytes {idx}-{end} from {blob}
483remove({dict}, {key}) any remove entry {key} from {dict}
484rename({from}, {to}) Number rename (move) file from {from} to {to}
Bakudankun375141e2022-09-09 18:46:47 +0100485repeat({expr}, {count}) List/Blob/String
486 repeat {expr} {count} times
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000487resolve({filename}) String get filename a shortcut points to
Yegappan Lakshmanan03ff1c22023-05-06 14:08:21 +0100488reverse({obj}) List/Blob/String
489 reverse {obj}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000490round({expr}) Float round off {expr}
491rubyeval({expr}) any evaluate |Ruby| expression
492screenattr({row}, {col}) Number attribute at screen position
493screenchar({row}, {col}) Number character at screen position
494screenchars({row}, {col}) List List of characters at screen position
495screencol() Number current cursor column
496screenpos({winid}, {lnum}, {col}) Dict screen row and col of a text character
497screenrow() Number current cursor row
498screenstring({row}, {col}) String characters at screen position
499search({pattern} [, {flags} [, {stopline} [, {timeout} [, {skip}]]]])
500 Number search for {pattern}
501searchcount([{options}]) Dict get or update search stats
502searchdecl({name} [, {global} [, {thisblock}]])
503 Number search for variable declaration
504searchpair({start}, {middle}, {end} [, {flags} [, {skip} [...]]])
505 Number search for other end of start/end pair
506searchpairpos({start}, {middle}, {end} [, {flags} [, {skip} [...]]])
507 List search for other end of start/end pair
508searchpos({pattern} [, {flags} [, {stopline} [, {timeout} [, {skip}]]]])
509 List search for {pattern}
510server2client({clientid}, {string})
511 Number send reply string
512serverlist() String get a list of available servers
513setbufline({expr}, {lnum}, {text})
514 Number set line {lnum} to {text} in buffer
515 {expr}
516setbufvar({buf}, {varname}, {val})
517 none set {varname} in buffer {buf} to {val}
518setcellwidths({list}) none set character cell width overrides
519setcharpos({expr}, {list}) Number set the {expr} position to {list}
520setcharsearch({dict}) Dict set character search from {dict}
Shougo Matsushita07ea5f12022-08-27 12:22:25 +0100521setcmdline({str} [, {pos}]) Number set command-line
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000522setcmdpos({pos}) Number set cursor position in command-line
523setcursorcharpos({list}) Number move cursor to position in {list}
524setenv({name}, {val}) none set environment variable
525setfperm({fname}, {mode}) Number set {fname} file permissions to {mode}
526setline({lnum}, {line}) Number set line {lnum} to {line}
527setloclist({nr}, {list} [, {action}])
528 Number modify location list using {list}
529setloclist({nr}, {list}, {action}, {what})
530 Number modify specific location list props
531setmatches({list} [, {win}]) Number restore a list of matches
532setpos({expr}, {list}) Number set the {expr} position to {list}
533setqflist({list} [, {action}]) Number modify quickfix list using {list}
534setqflist({list}, {action}, {what})
535 Number modify specific quickfix list props
536setreg({n}, {v} [, {opt}]) Number set register to value and type
537settabvar({nr}, {varname}, {val}) none set {varname} in tab page {nr} to {val}
538settabwinvar({tabnr}, {winnr}, {varname}, {val})
539 none set {varname} in window {winnr} in tab
540 page {tabnr} to {val}
541settagstack({nr}, {dict} [, {action}])
542 Number modify tag stack using {dict}
543setwinvar({nr}, {varname}, {val}) none set {varname} in window {nr} to {val}
544sha256({string}) String SHA256 checksum of {string}
545shellescape({string} [, {special}])
546 String escape {string} for use as shell
547 command argument
548shiftwidth([{col}]) Number effective value of 'shiftwidth'
549sign_define({name} [, {dict}]) Number define or update a sign
550sign_define({list}) List define or update a list of signs
551sign_getdefined([{name}]) List get a list of defined signs
552sign_getplaced([{buf} [, {dict}]])
553 List get a list of placed signs
554sign_jump({id}, {group}, {buf})
555 Number jump to a sign
556sign_place({id}, {group}, {name}, {buf} [, {dict}])
557 Number place a sign
558sign_placelist({list}) List place a list of signs
559sign_undefine([{name}]) Number undefine a sign
560sign_undefine({list}) List undefine a list of signs
561sign_unplace({group} [, {dict}])
562 Number unplace a sign
563sign_unplacelist({list}) List unplace a list of signs
564simplify({filename}) String simplify filename as much as possible
565sin({expr}) Float sine of {expr}
566sinh({expr}) Float hyperbolic sine of {expr}
567slice({expr}, {start} [, {end}]) String, List or Blob
568 slice of a String, List or Blob
Bram Moolenaar2007dd42022-02-23 13:17:47 +0000569sort({list} [, {how} [, {dict}]])
570 List sort {list}, compare with {how}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000571sound_clear() none stop playing all sounds
572sound_playevent({name} [, {callback}])
573 Number play an event sound
574sound_playfile({path} [, {callback}])
575 Number play sound file {path}
576sound_stop({id}) none stop playing sound {id}
577soundfold({word}) String sound-fold {word}
578spellbadword() String badly spelled word at cursor
579spellsuggest({word} [, {max} [, {capital}]])
580 List spelling suggestions
581split({expr} [, {pat} [, {keepempty}]])
582 List make |List| from {pat} separated {expr}
583sqrt({expr}) Float square root of {expr}
584srand([{expr}]) List get seed for |rand()|
585state([{what}]) String current state of Vim
586str2float({expr} [, {quoted}]) Float convert String to Float
587str2list({expr} [, {utf8}]) List convert each character of {expr} to
588 ASCII/UTF-8 value
589str2nr({expr} [, {base} [, {quoted}]])
590 Number convert String to Number
591strcharlen({expr}) Number character length of the String {expr}
592strcharpart({str}, {start} [, {len} [, {skipcc}]])
593 String {len} characters of {str} at
594 character {start}
595strchars({expr} [, {skipcc}]) Number character count of the String {expr}
596strdisplaywidth({expr} [, {col}]) Number display length of the String {expr}
597strftime({format} [, {time}]) String format time with a specified format
598strgetchar({str}, {index}) Number get char {index} from {str}
599stridx({haystack}, {needle} [, {start}])
600 Number index of {needle} in {haystack}
601string({expr}) String String representation of {expr} value
602strlen({expr}) Number length of the String {expr}
603strpart({str}, {start} [, {len} [, {chars}]])
604 String {len} bytes/chars of {str} at
605 byte {start}
606strptime({format}, {timestring})
607 Number Convert {timestring} to unix timestamp
608strridx({haystack}, {needle} [, {start}])
609 Number last index of {needle} in {haystack}
610strtrans({expr}) String translate string to make it printable
Christian Brabandt67672ef2023-04-24 21:09:54 +0100611strutf16len({string} [, {countcc}])
612 Number number of UTF-16 code units in {string}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000613strwidth({expr}) Number display cell length of the String {expr}
614submatch({nr} [, {list}]) String or List
615 specific match in ":s" or substitute()
616substitute({expr}, {pat}, {sub}, {flags})
617 String all {pat} in {expr} replaced with {sub}
Bram Moolenaarc216a7a2022-12-05 13:50:55 +0000618swapfilelist() List swap files found in 'directory'
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000619swapinfo({fname}) Dict information about swap file {fname}
620swapname({buf}) String swap file of buffer {buf}
621synID({lnum}, {col}, {trans}) Number syntax ID at {lnum} and {col}
622synIDattr({synID}, {what} [, {mode}])
623 String attribute {what} of syntax ID {synID}
624synIDtrans({synID}) Number translated syntax ID of {synID}
625synconcealed({lnum}, {col}) List info about concealing
626synstack({lnum}, {col}) List stack of syntax IDs at {lnum} and {col}
627system({expr} [, {input}]) String output of shell command/filter {expr}
628systemlist({expr} [, {input}]) List output of shell command/filter {expr}
629tabpagebuflist([{arg}]) List list of buffer numbers in tab page
630tabpagenr([{arg}]) Number number of current or last tab page
631tabpagewinnr({tabarg} [, {arg}]) Number number of current window in tab page
632tagfiles() List tags files used
633taglist({expr} [, {filename}]) List list of tags matching {expr}
634tan({expr}) Float tangent of {expr}
635tanh({expr}) Float hyperbolic tangent of {expr}
636tempname() String name for a temporary file
637term_dumpdiff({filename}, {filename} [, {options}])
638 Number display difference between two dumps
639term_dumpload({filename} [, {options}])
640 Number displaying a screen dump
641term_dumpwrite({buf}, {filename} [, {options}])
642 none dump terminal window contents
643term_getaltscreen({buf}) Number get the alternate screen flag
644term_getansicolors({buf}) List get ANSI palette in GUI color mode
645term_getattr({attr}, {what}) Number get the value of attribute {what}
646term_getcursor({buf}) List get the cursor position of a terminal
647term_getjob({buf}) Job get the job associated with a terminal
648term_getline({buf}, {row}) String get a line of text from a terminal
649term_getscrolled({buf}) Number get the scroll count of a terminal
650term_getsize({buf}) List get the size of a terminal
651term_getstatus({buf}) String get the status of a terminal
652term_gettitle({buf}) String get the title of a terminal
653term_gettty({buf}, [{input}]) String get the tty name of a terminal
654term_list() List get the list of terminal buffers
655term_scrape({buf}, {row}) List get row of a terminal screen
656term_sendkeys({buf}, {keys}) none send keystrokes to a terminal
657term_setansicolors({buf}, {colors})
658 none set ANSI palette in GUI color mode
659term_setapi({buf}, {expr}) none set |terminal-api| function name prefix
660term_setkill({buf}, {how}) none set signal to stop job in terminal
661term_setrestore({buf}, {command}) none set command to restore terminal
662term_setsize({buf}, {rows}, {cols})
663 none set the size of a terminal
664term_start({cmd} [, {options}]) Number open a terminal window and run a job
665term_wait({buf} [, {time}]) Number wait for screen to be updated
666terminalprops() Dict properties of the terminal
667test_alloc_fail({id}, {countdown}, {repeat})
668 none make memory allocation fail
669test_autochdir() none enable 'autochdir' during startup
670test_feedinput({string}) none add key sequence to input buffer
671test_garbagecollect_now() none free memory right now for testing
672test_garbagecollect_soon() none free memory soon for testing
673test_getvalue({string}) any get value of an internal variable
Yegappan Lakshmanan06011e12022-01-30 12:37:29 +0000674test_gui_event({event}, {args}) bool generate a GUI event for testing
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000675test_ignore_error({expr}) none ignore a specific error
Christopher Plewright20b795e2022-12-20 20:01:58 +0000676test_mswin_event({event}, {args})
677 bool generate MS-Windows event for testing
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000678test_null_blob() Blob null value for testing
679test_null_channel() Channel null value for testing
680test_null_dict() Dict null value for testing
681test_null_function() Funcref null value for testing
682test_null_job() Job null value for testing
683test_null_list() List null value for testing
684test_null_partial() Funcref null value for testing
685test_null_string() String null value for testing
686test_option_not_set({name}) none reset flag indicating option was set
687test_override({expr}, {val}) none test with Vim internal overrides
688test_refcount({expr}) Number get the reference count of {expr}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000689test_setmouse({row}, {col}) none set the mouse position for testing
690test_settime({expr}) none set current time for testing
691test_srand_seed([seed]) none set seed for testing srand()
692test_unknown() any unknown value for testing
693test_void() any void value for testing
694timer_info([{id}]) List information about timers
695timer_pause({id}, {pause}) none pause or unpause a timer
696timer_start({time}, {callback} [, {options}])
697 Number create a timer
698timer_stop({timer}) none stop a timer
699timer_stopall() none stop all timers
700tolower({expr}) String the String {expr} switched to lowercase
701toupper({expr}) String the String {expr} switched to uppercase
702tr({src}, {fromstr}, {tostr}) String translate chars of {src} in {fromstr}
703 to chars in {tostr}
704trim({text} [, {mask} [, {dir}]])
705 String trim characters in {mask} from {text}
706trunc({expr}) Float truncate Float {expr}
707type({expr}) Number type of value {expr}
708typename({expr}) String representation of the type of {expr}
709undofile({name}) String undo file name for {name}
710undotree() List undo file tree
711uniq({list} [, {func} [, {dict}]])
712 List remove adjacent duplicates from a list
Christian Brabandt67672ef2023-04-24 21:09:54 +0100713utf16idx({string}, {idx} [, {countcc} [, {charidx}]])
714 Number UTF-16 index of byte {idx} in {string}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000715values({dict}) List values in {dict}
LemonBoy0f7a3e12022-05-26 12:10:37 +0100716virtcol({expr} [, {list}]) Number or List
717 screen column of cursor or mark
Bram Moolenaar5a6ec102022-05-27 21:58:00 +0100718virtcol2col({winid}, {lnum}, {col})
719 Number byte index of a character on screen
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000720visualmode([expr]) String last visual mode used
721wildmenumode() Number whether 'wildmenu' mode is active
722win_execute({id}, {command} [, {silent}])
723 String execute {command} in window {id}
724win_findbuf({bufnr}) List find windows containing {bufnr}
725win_getid([{win} [, {tab}]]) Number get window ID for {win} in {tab}
726win_gettype([{nr}]) String type of window {nr}
727win_gotoid({expr}) Number go to window with ID {expr}
728win_id2tabwin({expr}) List get tab and window nr from window ID
729win_id2win({expr}) Number get window nr from window ID
Daniel Steinbergee630312022-01-10 13:36:34 +0000730win_move_separator({nr}) Number move window vertical separator
731win_move_statusline({nr}) Number move window status line
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000732win_screenpos({nr}) List get screen position of window {nr}
733win_splitmove({nr}, {target} [, {options}])
734 Number move window {nr} to split of {target}
735winbufnr({nr}) Number buffer number of window {nr}
736wincol() Number window column of the cursor
737windowsversion() String MS-Windows OS version
738winheight({nr}) Number height of window {nr}
739winlayout([{tabnr}]) List layout of windows in tab {tabnr}
740winline() Number window line of the cursor
741winnr([{expr}]) Number number of current window
742winrestcmd() String returns command to restore window sizes
743winrestview({dict}) none restore view of current window
744winsaveview() Dict save view of current window
745winwidth({nr}) Number width of window {nr}
746wordcount() Dict get byte/char/word statistics
747writefile({object}, {fname} [, {flags}])
748 Number write |Blob| or |List| of lines to file
749xor({expr}, {expr}) Number bitwise XOR
750
751==============================================================================
7522. Details *builtin-function-details*
753
754Not all functions are here, some have been moved to a help file covering the
755specific functionality.
756
757abs({expr}) *abs()*
758 Return the absolute value of {expr}. When {expr} evaluates to
759 a |Float| abs() returns a |Float|. When {expr} can be
760 converted to a |Number| abs() returns a |Number|. Otherwise
761 abs() gives an error message and returns -1.
762 Examples: >
763 echo abs(1.456)
764< 1.456 >
765 echo abs(-5.456)
766< 5.456 >
767 echo abs(-4)
768< 4
769
770 Can also be used as a |method|: >
771 Compute()->abs()
772
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000773
774acos({expr}) *acos()*
775 Return the arc cosine of {expr} measured in radians, as a
776 |Float| in the range of [0, pi].
777 {expr} must evaluate to a |Float| or a |Number| in the range
Bram Moolenaar016188f2022-06-06 20:52:59 +0100778 [-1, 1]. Otherwise acos() returns "nan".
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000779 Examples: >
780 :echo acos(0)
781< 1.570796 >
782 :echo acos(-0.5)
783< 2.094395
784
785 Can also be used as a |method|: >
786 Compute()->acos()
787
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000788
789add({object}, {expr}) *add()*
790 Append the item {expr} to |List| or |Blob| {object}. Returns
791 the resulting |List| or |Blob|. Examples: >
792 :let alist = add([1, 2, 3], item)
793 :call add(mylist, "woodstock")
794< Note that when {expr} is a |List| it is appended as a single
795 item. Use |extend()| to concatenate |Lists|.
796 When {object} is a |Blob| then {expr} must be a number.
797 Use |insert()| to add an item at another position.
Bram Moolenaar016188f2022-06-06 20:52:59 +0100798 Returns 1 if {object} is not a |List| or a |Blob|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000799
800 Can also be used as a |method|: >
801 mylist->add(val1)->add(val2)
802
803
804and({expr}, {expr}) *and()*
805 Bitwise AND on the two arguments. The arguments are converted
806 to a number. A List, Dict or Float argument causes an error.
LemonBoy0f7a3e12022-05-26 12:10:37 +0100807 Also see `or()` and `xor()`.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000808 Example: >
809 :let flag = and(bits, 0x80)
810< Can also be used as a |method|: >
811 :let flag = bits->and(0x80)
812
813
814append({lnum}, {text}) *append()*
815 When {text} is a |List|: Append each item of the |List| as a
816 text line below line {lnum} in the current buffer.
817 Otherwise append {text} as one text line below line {lnum} in
818 the current buffer.
819 Any type of item is accepted and converted to a String.
820 {lnum} can be zero to insert a line before the first one.
821 {lnum} is used like with |getline()|.
822 Returns 1 for failure ({lnum} out of range or out of memory),
Bram Moolenaarcd9c8d42022-11-05 23:46:43 +0000823 0 for success. When {text} is an empty list zero is returned,
824 no matter the value of {lnum}.
825 In |Vim9| script an invalid argument or negative number
826 results in an error. Example: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000827 :let failed = append(line('$'), "# THE END")
828 :let failed = append(0, ["Chapter 1", "the beginning"])
829
830< Can also be used as a |method| after a List, the base is
831 passed as the second argument: >
832 mylist->append(lnum)
833
834
835appendbufline({buf}, {lnum}, {text}) *appendbufline()*
836 Like |append()| but append the text in buffer {buf}.
837
838 This function works only for loaded buffers. First call
839 |bufload()| if needed.
840
841 For the use of {buf}, see |bufname()|.
842
Bram Moolenaar8b6256f2021-12-28 11:24:49 +0000843 {lnum} is the line number to append below. Note that using
844 |line()| would use the current buffer, not the one appending
845 to. Use "$" to append at the end of the buffer. Other string
846 values are not supported.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000847
848 On success 0 is returned, on failure 1 is returned.
849 In |Vim9| script an error is given for an invalid {lnum}.
850
851 If {buf} is not a valid buffer or {lnum} is not valid, an
852 error message is given. Example: >
853 :let failed = appendbufline(13, 0, "# THE START")
Bram Moolenaarcd9c8d42022-11-05 23:46:43 +0000854< However, when {text} is an empty list then no error is given
855 for an invalid {lnum}, since {lnum} isn't actually used.
856
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000857 Can also be used as a |method| after a List, the base is
858 passed as the second argument: >
859 mylist->appendbufline(buf, lnum)
860
861
862argc([{winid}]) *argc()*
863 The result is the number of files in the argument list. See
864 |arglist|.
865 If {winid} is not supplied, the argument list of the current
866 window is used.
867 If {winid} is -1, the global argument list is used.
868 Otherwise {winid} specifies the window of which the argument
869 list is used: either the window number or the window ID.
870 Returns -1 if the {winid} argument is invalid.
871
872 *argidx()*
873argidx() The result is the current index in the argument list. 0 is
874 the first file. argc() - 1 is the last one. See |arglist|.
875
876 *arglistid()*
877arglistid([{winnr} [, {tabnr}]])
878 Return the argument list ID. This is a number which
879 identifies the argument list being used. Zero is used for the
880 global argument list. See |arglist|.
881 Returns -1 if the arguments are invalid.
882
883 Without arguments use the current window.
884 With {winnr} only use this window in the current tab page.
885 With {winnr} and {tabnr} use the window in the specified tab
886 page.
887 {winnr} can be the window number or the |window-ID|.
888
889 *argv()*
890argv([{nr} [, {winid}]])
891 The result is the {nr}th file in the argument list. See
892 |arglist|. "argv(0)" is the first one. Example: >
893 :let i = 0
894 :while i < argc()
895 : let f = escape(fnameescape(argv(i)), '.')
Bram Moolenaarc51cf032022-02-26 12:25:45 +0000896 : exe 'amenu Arg.' .. f .. ' :e ' .. f .. '<CR>'
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000897 : let i = i + 1
898 :endwhile
899< Without the {nr} argument, or when {nr} is -1, a |List| with
900 the whole |arglist| is returned.
901
902 The {winid} argument specifies the window ID, see |argc()|.
903 For the Vim command line arguments see |v:argv|.
904
Bram Moolenaar016188f2022-06-06 20:52:59 +0100905 Returns an empty string if {nr}th argument is not present in
906 the argument list. Returns an empty List if the {winid}
907 argument is invalid.
908
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000909asin({expr}) *asin()*
910 Return the arc sine of {expr} measured in radians, as a |Float|
911 in the range of [-pi/2, pi/2].
912 {expr} must evaluate to a |Float| or a |Number| in the range
913 [-1, 1].
Bram Moolenaar016188f2022-06-06 20:52:59 +0100914 Returns "nan" if {expr} is outside the range [-1, 1]. Returns
915 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000916 Examples: >
917 :echo asin(0.8)
918< 0.927295 >
919 :echo asin(-0.5)
920< -0.523599
921
922 Can also be used as a |method|: >
923 Compute()->asin()
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000924
925
926assert_ functions are documented here: |assert-functions-details|
927
928
929
930atan({expr}) *atan()*
931 Return the principal value of the arc tangent of {expr}, in
932 the range [-pi/2, +pi/2] radians, as a |Float|.
933 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar016188f2022-06-06 20:52:59 +0100934 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000935 Examples: >
936 :echo atan(100)
937< 1.560797 >
938 :echo atan(-4.01)
939< -1.326405
940
941 Can also be used as a |method|: >
942 Compute()->atan()
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000943
944
945atan2({expr1}, {expr2}) *atan2()*
946 Return the arc tangent of {expr1} / {expr2}, measured in
947 radians, as a |Float| in the range [-pi, pi].
948 {expr1} and {expr2} must evaluate to a |Float| or a |Number|.
Bram Moolenaar016188f2022-06-06 20:52:59 +0100949 Returns 0.0 if {expr1} or {expr2} is not a |Float| or a
950 |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000951 Examples: >
952 :echo atan2(-1, 1)
953< -0.785398 >
954 :echo atan2(1, -1)
955< 2.356194
956
957 Can also be used as a |method|: >
958 Compute()->atan2(1)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000959
Yegappan Lakshmanan1755a912022-05-19 10:31:47 +0100960
961autocmd_add({acmds}) *autocmd_add()*
962 Adds a List of autocmds and autocmd groups.
963
964 The {acmds} argument is a List where each item is a Dict with
965 the following optional items:
966 bufnr buffer number to add a buffer-local autocmd.
967 If this item is specified, then the "pattern"
968 item is ignored.
969 cmd Ex command to execute for this autocmd event
970 event autocmd event name. Refer to |autocmd-events|.
Yegappan Lakshmanane0ff3a72022-05-27 18:05:33 +0100971 This can be either a String with a single
972 event name or a List of event names.
Yegappan Lakshmanan1755a912022-05-19 10:31:47 +0100973 group autocmd group name. Refer to |autocmd-groups|.
974 If this group doesn't exist then it is
975 created. If not specified or empty, then the
976 default group is used.
Yegappan Lakshmanan971f6822022-05-24 11:40:11 +0100977 nested boolean flag, set to v:true to add a nested
978 autocmd. Refer to |autocmd-nested|.
LemonBoy0f7a3e12022-05-26 12:10:37 +0100979 once boolean flag, set to v:true to add an autocmd
Yegappan Lakshmanan971f6822022-05-24 11:40:11 +0100980 which executes only once. Refer to
981 |autocmd-once|.
Yegappan Lakshmanan1755a912022-05-19 10:31:47 +0100982 pattern autocmd pattern string. Refer to
983 |autocmd-patterns|. If "bufnr" item is
Yegappan Lakshmanane0ff3a72022-05-27 18:05:33 +0100984 present, then this item is ignored. This can
985 be a String with a single pattern or a List of
986 patterns.
Yegappan Lakshmanan971f6822022-05-24 11:40:11 +0100987 replace boolean flag, set to v:true to remove all the
988 commands associated with the specified autocmd
989 event and group and add the {cmd}. This is
990 useful to avoid adding the same command
LemonBoy0f7a3e12022-05-26 12:10:37 +0100991 multiple times for an autocmd event in a group.
Yegappan Lakshmanan1755a912022-05-19 10:31:47 +0100992
993 Returns v:true on success and v:false on failure.
994 Examples: >
995 " Create a buffer-local autocmd for buffer 5
996 let acmd = {}
997 let acmd.group = 'MyGroup'
998 let acmd.event = 'BufEnter'
999 let acmd.bufnr = 5
1000 let acmd.cmd = 'call BufEnterFunc()'
1001 call autocmd_add([acmd])
Bram Moolenaarcd9c8d42022-11-05 23:46:43 +00001002<
Yegappan Lakshmanan1755a912022-05-19 10:31:47 +01001003 Can also be used as a |method|: >
1004 GetAutocmdList()->autocmd_add()
1005<
1006autocmd_delete({acmds}) *autocmd_delete()*
1007 Deletes a List of autocmds and autocmd groups.
1008
1009 The {acmds} argument is a List where each item is a Dict with
1010 the following optional items:
1011 bufnr buffer number to delete a buffer-local autocmd.
1012 If this item is specified, then the "pattern"
1013 item is ignored.
1014 cmd Ex command for this autocmd event
1015 event autocmd event name. Refer to |autocmd-events|.
1016 If '*' then all the autocmd events in this
1017 group are deleted.
1018 group autocmd group name. Refer to |autocmd-groups|.
1019 If not specified or empty, then the default
1020 group is used.
1021 nested set to v:true for a nested autocmd.
1022 Refer to |autocmd-nested|.
1023 once set to v:true for an autocmd which executes
1024 only once. Refer to |autocmd-once|.
1025 pattern autocmd pattern string. Refer to
1026 |autocmd-patterns|. If "bufnr" item is
1027 present, then this item is ignored.
1028
1029 If only {group} is specified in a {acmds} entry and {event},
1030 {pattern} and {cmd} are not specified, then that autocmd group
1031 is deleted.
1032
Bram Moolenaar016188f2022-06-06 20:52:59 +01001033 Returns |v:true| on success and |v:false| on failure.
Yegappan Lakshmanan1755a912022-05-19 10:31:47 +01001034 Examples: >
1035 " :autocmd! BufLeave *.vim
1036 let acmd = #{event: 'BufLeave', pattern: '*.vim'}
1037 call autocmd_delete([acmd]})
1038 " :autocmd! MyGroup1 BufLeave
1039 let acmd = #{group: 'MyGroup1', event: 'BufLeave'}
1040 call autocmd_delete([acmd])
1041 " :autocmd! MyGroup2 BufEnter *.c
1042 let acmd = #{group: 'MyGroup2', event: 'BufEnter',
1043 \ pattern: '*.c'}
1044 " :autocmd! MyGroup2 * *.c
1045 let acmd = #{group: 'MyGroup2', event: '*',
1046 \ pattern: '*.c'}
1047 call autocmd_delete([acmd])
1048 " :autocmd! MyGroup3
1049 let acmd = #{group: 'MyGroup3'}
1050 call autocmd_delete([acmd])
1051<
1052 Can also be used as a |method|: >
1053 GetAutocmdList()->autocmd_delete()
1054
1055autocmd_get([{opts}]) *autocmd_get()*
1056 Returns a |List| of autocmds. If {opts} is not supplied, then
1057 returns the autocmds for all the events in all the groups.
1058
1059 The optional {opts} Dict argument supports the following
1060 items:
1061 group Autocmd group name. If specified, returns only
1062 the autocmds defined in this group. If the
1063 specified group doesn't exist, results in an
1064 error message. If set to an empty string,
1065 then the default autocmd group is used.
1066 event Autocmd event name. If specified, returns only
1067 the autocmds defined for this event. If set
1068 to "*", then returns autocmds for all the
1069 events. If the specified event doesn't exist,
1070 results in an error message.
1071 pattern Autocmd pattern. If specified, returns only
1072 the autocmds defined for this pattern.
1073 A combination of the above three times can be supplied in
1074 {opts}.
1075
1076 Each Dict in the returned List contains the following items:
1077 bufnr For buffer-local autocmds, buffer number where
1078 the autocmd is defined.
1079 cmd Command executed for this autocmd.
1080 event Autocmd event name.
1081 group Autocmd group name.
Yegappan Lakshmanan971f6822022-05-24 11:40:11 +01001082 nested Boolean flag, set to v:true for a nested
1083 autocmd. See |autocmd-nested|.
1084 once Boolean flag, set to v:true, if the autocmd
1085 will be executed only once. See |autocmd-once|.
Yegappan Lakshmanan1755a912022-05-19 10:31:47 +01001086 pattern Autocmd pattern. For a buffer-local
1087 autocmd, this will be of the form "<buffer=n>".
1088 If there are multiple commands for an autocmd event in a
1089 group, then separate items are returned for each command.
1090
Bram Moolenaar016188f2022-06-06 20:52:59 +01001091 Returns an empty List if an autocmd with the specified group
1092 or event or pattern is not found.
1093
Yegappan Lakshmanan1755a912022-05-19 10:31:47 +01001094 Examples: >
1095 " :autocmd MyGroup
1096 echo autocmd_get(#{group: 'Mygroup'})
1097 " :autocmd G BufUnload
1098 echo autocmd_get(#{group: 'G', event: 'BufUnload'})
1099 " :autocmd G * *.ts
1100 let acmd = #{group: 'G', event: '*', pattern: '*.ts'}
1101 echo autocmd_get(acmd)
1102 " :autocmd Syntax
1103 echo autocmd_get(#{event: 'Syntax'})
1104 " :autocmd G BufEnter *.ts
1105 let acmd = #{group: 'G', event: 'BufEnter',
1106 \ pattern: '*.ts'}
1107 echo autocmd_get(acmd)
1108<
1109 Can also be used as a |method|: >
1110 Getopts()->autocmd_get()
1111<
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001112balloon_gettext() *balloon_gettext()*
1113 Return the current text in the balloon. Only for the string,
Bram Moolenaar016188f2022-06-06 20:52:59 +01001114 not used for the List. Returns an empty string if balloon
1115 is not present.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001116
1117balloon_show({expr}) *balloon_show()*
1118 Show {expr} inside the balloon. For the GUI {expr} is used as
1119 a string. For a terminal {expr} can be a list, which contains
1120 the lines of the balloon. If {expr} is not a list it will be
1121 split with |balloon_split()|.
1122 If {expr} is an empty string any existing balloon is removed.
1123
1124 Example: >
1125 func GetBalloonContent()
1126 " ... initiate getting the content
1127 return ''
1128 endfunc
1129 set balloonexpr=GetBalloonContent()
1130
1131 func BalloonCallback(result)
1132 call balloon_show(a:result)
1133 endfunc
1134< Can also be used as a |method|: >
1135 GetText()->balloon_show()
1136<
1137 The intended use is that fetching the content of the balloon
1138 is initiated from 'balloonexpr'. It will invoke an
1139 asynchronous method, in which a callback invokes
1140 balloon_show(). The 'balloonexpr' itself can return an
Bram Moolenaar069a7d52022-06-27 22:16:08 +01001141 empty string or a placeholder, e.g. "loading...".
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001142
Bram Moolenaar069a7d52022-06-27 22:16:08 +01001143 When showing a balloon is not possible then nothing happens,
1144 no error message is given.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001145 {only available when compiled with the |+balloon_eval| or
1146 |+balloon_eval_term| feature}
1147
1148balloon_split({msg}) *balloon_split()*
1149 Split String {msg} into lines to be displayed in a balloon.
1150 The splits are made for the current window size and optimize
1151 to show debugger output.
Bram Moolenaar016188f2022-06-06 20:52:59 +01001152 Returns a |List| with the split lines. Returns an empty List
1153 on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001154 Can also be used as a |method|: >
1155 GetText()->balloon_split()->balloon_show()
1156
1157< {only available when compiled with the |+balloon_eval_term|
1158 feature}
1159
1160blob2list({blob}) *blob2list()*
1161 Return a List containing the number value of each byte in Blob
1162 {blob}. Examples: >
1163 blob2list(0z0102.0304) returns [1, 2, 3, 4]
1164 blob2list(0z) returns []
1165< Returns an empty List on error. |list2blob()| does the
1166 opposite.
1167
1168 Can also be used as a |method|: >
1169 GetBlob()->blob2list()
Bram Moolenaarb529cfb2022-07-25 15:42:07 +01001170<
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001171 *browse()*
1172browse({save}, {title}, {initdir}, {default})
1173 Put up a file requester. This only works when "has("browse")"
1174 returns |TRUE| (only in some GUI versions).
1175 The input fields are:
1176 {save} when |TRUE|, select file to write
1177 {title} title for the requester
1178 {initdir} directory to start browsing in
1179 {default} default file name
1180 An empty string is returned when the "Cancel" button is hit,
1181 something went wrong, or browsing is not possible.
1182
1183 *browsedir()*
1184browsedir({title}, {initdir})
1185 Put up a directory requester. This only works when
1186 "has("browse")" returns |TRUE| (only in some GUI versions).
1187 On systems where a directory browser is not supported a file
1188 browser is used. In that case: select a file in the directory
1189 to be used.
1190 The input fields are:
1191 {title} title for the requester
1192 {initdir} directory to start browsing in
1193 When the "Cancel" button is hit, something went wrong, or
1194 browsing is not possible, an empty string is returned.
1195
1196bufadd({name}) *bufadd()*
Bram Moolenaar2eddbac2022-08-25 12:45:21 +01001197 Add a buffer to the buffer list with name {name} (must be a
1198 String).
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001199 If a buffer for file {name} already exists, return that buffer
1200 number. Otherwise return the buffer number of the newly
1201 created buffer. When {name} is an empty string then a new
1202 buffer is always created.
1203 The buffer will not have 'buflisted' set and not be loaded
1204 yet. To add some text to the buffer use this: >
1205 let bufnr = bufadd('someName')
1206 call bufload(bufnr)
1207 call setbufline(bufnr, 1, ['some', 'text'])
Bram Moolenaar016188f2022-06-06 20:52:59 +01001208< Returns 0 on error.
1209 Can also be used as a |method|: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001210 let bufnr = 'somename'->bufadd()
1211
1212bufexists({buf}) *bufexists()*
1213 The result is a Number, which is |TRUE| if a buffer called
1214 {buf} exists.
1215 If the {buf} argument is a number, buffer numbers are used.
1216 Number zero is the alternate buffer for the current window.
1217
1218 If the {buf} argument is a string it must match a buffer name
1219 exactly. The name can be:
1220 - Relative to the current directory.
1221 - A full path.
1222 - The name of a buffer with 'buftype' set to "nofile".
1223 - A URL name.
1224 Unlisted buffers will be found.
1225 Note that help files are listed by their short name in the
1226 output of |:buffers|, but bufexists() requires using their
1227 long name to be able to find them.
1228 bufexists() may report a buffer exists, but to use the name
1229 with a |:buffer| command you may need to use |expand()|. Esp
1230 for MS-Windows 8.3 names in the form "c:\DOCUME~1"
1231 Use "bufexists(0)" to test for the existence of an alternate
1232 file name.
1233
1234 Can also be used as a |method|: >
1235 let exists = 'somename'->bufexists()
1236<
1237 Obsolete name: buffer_exists(). *buffer_exists()*
1238
1239buflisted({buf}) *buflisted()*
1240 The result is a Number, which is |TRUE| if a buffer called
1241 {buf} exists and is listed (has the 'buflisted' option set).
1242 The {buf} argument is used like with |bufexists()|.
1243
1244 Can also be used as a |method|: >
1245 let listed = 'somename'->buflisted()
1246
1247bufload({buf}) *bufload()*
1248 Ensure the buffer {buf} is loaded. When the buffer name
1249 refers to an existing file then the file is read. Otherwise
1250 the buffer will be empty. If the buffer was already loaded
Bram Moolenaar2eddbac2022-08-25 12:45:21 +01001251 then there is no change. If the buffer is not related to a
1252 file the no file is read (e.g., when 'buftype' is "nofile").
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001253 If there is an existing swap file for the file of the buffer,
1254 there will be no dialog, the buffer will be loaded anyway.
1255 The {buf} argument is used like with |bufexists()|.
1256
1257 Can also be used as a |method|: >
1258 eval 'somename'->bufload()
1259
1260bufloaded({buf}) *bufloaded()*
1261 The result is a Number, which is |TRUE| if a buffer called
1262 {buf} exists and is loaded (shown in a window or hidden).
1263 The {buf} argument is used like with |bufexists()|.
1264
1265 Can also be used as a |method|: >
1266 let loaded = 'somename'->bufloaded()
1267
1268bufname([{buf}]) *bufname()*
1269 The result is the name of a buffer. Mostly as it is displayed
1270 by the `:ls` command, but not using special names such as
1271 "[No Name]".
1272 If {buf} is omitted the current buffer is used.
1273 If {buf} is a Number, that buffer number's name is given.
1274 Number zero is the alternate buffer for the current window.
1275 If {buf} is a String, it is used as a |file-pattern| to match
1276 with the buffer names. This is always done like 'magic' is
1277 set and 'cpoptions' is empty. When there is more than one
1278 match an empty string is returned.
1279 "" or "%" can be used for the current buffer, "#" for the
1280 alternate buffer.
1281 A full match is preferred, otherwise a match at the start, end
1282 or middle of the buffer name is accepted. If you only want a
1283 full match then put "^" at the start and "$" at the end of the
1284 pattern.
1285 Listed buffers are found first. If there is a single match
1286 with a listed buffer, that one is returned. Next unlisted
1287 buffers are searched for.
1288 If the {buf} is a String, but you want to use it as a buffer
1289 number, force it to be a Number by adding zero to it: >
1290 :echo bufname("3" + 0)
1291< Can also be used as a |method|: >
1292 echo bufnr->bufname()
1293
1294< If the buffer doesn't exist, or doesn't have a name, an empty
1295 string is returned. >
1296 bufname("#") alternate buffer name
1297 bufname(3) name of buffer 3
1298 bufname("%") name of current buffer
1299 bufname("file2") name of buffer where "file2" matches.
1300< *buffer_name()*
1301 Obsolete name: buffer_name().
1302
1303 *bufnr()*
1304bufnr([{buf} [, {create}]])
1305 The result is the number of a buffer, as it is displayed by
1306 the `:ls` command. For the use of {buf}, see |bufname()|
1307 above.
1308
1309 If the buffer doesn't exist, -1 is returned. Or, if the
1310 {create} argument is present and TRUE, a new, unlisted,
1311 buffer is created and its number is returned. Example: >
1312 let newbuf = bufnr('Scratch001', 1)
1313< Using an empty name uses the current buffer. To create a new
1314 buffer with an empty name use |bufadd()|.
1315
1316 bufnr("$") is the last buffer: >
1317 :let last_buffer = bufnr("$")
1318< The result is a Number, which is the highest buffer number
1319 of existing buffers. Note that not all buffers with a smaller
1320 number necessarily exist, because ":bwipeout" may have removed
1321 them. Use bufexists() to test for the existence of a buffer.
1322
1323 Can also be used as a |method|: >
1324 echo bufref->bufnr()
1325<
1326 Obsolete name: buffer_number(). *buffer_number()*
1327 *last_buffer_nr()*
1328 Obsolete name for bufnr("$"): last_buffer_nr().
1329
1330bufwinid({buf}) *bufwinid()*
1331 The result is a Number, which is the |window-ID| of the first
1332 window associated with buffer {buf}. For the use of {buf},
1333 see |bufname()| above. If buffer {buf} doesn't exist or
1334 there is no such window, -1 is returned. Example: >
1335
Bram Moolenaarc51cf032022-02-26 12:25:45 +00001336 echo "A window containing buffer 1 is " .. (bufwinid(1))
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001337<
Bram Moolenaar76db9e02022-11-09 21:21:04 +00001338 Only deals with the current tab page. See |win_findbuf()| for
1339 finding more.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001340
1341 Can also be used as a |method|: >
1342 FindBuffer()->bufwinid()
1343
1344bufwinnr({buf}) *bufwinnr()*
1345 Like |bufwinid()| but return the window number instead of the
1346 |window-ID|.
1347 If buffer {buf} doesn't exist or there is no such window, -1
1348 is returned. Example: >
1349
Bram Moolenaarc51cf032022-02-26 12:25:45 +00001350 echo "A window containing buffer 1 is " .. (bufwinnr(1))
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001351
1352< The number can be used with |CTRL-W_w| and ":wincmd w"
1353 |:wincmd|.
1354
1355 Can also be used as a |method|: >
1356 FindBuffer()->bufwinnr()
1357
1358byte2line({byte}) *byte2line()*
1359 Return the line number that contains the character at byte
1360 count {byte} in the current buffer. This includes the
1361 end-of-line character, depending on the 'fileformat' option
1362 for the current buffer. The first character has byte count
1363 one.
1364 Also see |line2byte()|, |go| and |:goto|.
1365
Bram Moolenaar016188f2022-06-06 20:52:59 +01001366 Returns -1 if the {byte} value is invalid.
1367
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001368 Can also be used as a |method|: >
1369 GetOffset()->byte2line()
1370
1371< {not available when compiled without the |+byte_offset|
1372 feature}
1373
Christian Brabandt67672ef2023-04-24 21:09:54 +01001374byteidx({expr}, {nr} [, {utf16}]) *byteidx()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001375 Return byte index of the {nr}'th character in the String
1376 {expr}. Use zero for the first character, it then returns
1377 zero.
1378 If there are no multibyte characters the returned value is
1379 equal to {nr}.
1380 Composing characters are not counted separately, their byte
1381 length is added to the preceding base character. See
1382 |byteidxcomp()| below for counting composing characters
1383 separately.
Christian Brabandt67672ef2023-04-24 21:09:54 +01001384 When {utf16} is present and TRUE, {nr} is used as the UTF-16
1385 index in the String {expr} instead of as the character index.
1386 The UTF-16 index is the index in the string when it is encoded
1387 with 16-bit words. If the specified UTF-16 index is in the
1388 middle of a character (e.g. in a 4-byte character), then the
1389 byte index of the first byte in the character is returned.
1390 Refer to |string-offset-encoding| for more information.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001391 Example : >
1392 echo matchstr(str, ".", byteidx(str, 3))
1393< will display the fourth character. Another way to do the
1394 same: >
1395 let s = strpart(str, byteidx(str, 3))
1396 echo strpart(s, 0, byteidx(s, 1))
1397< Also see |strgetchar()| and |strcharpart()|.
1398
1399 If there are less than {nr} characters -1 is returned.
1400 If there are exactly {nr} characters the length of the string
1401 in bytes is returned.
Christian Brabandt67672ef2023-04-24 21:09:54 +01001402 See |charidx()| and |utf16idx()| for getting the character and
1403 UTF-16 index respectively from the byte index.
1404 Examples: >
1405 echo byteidx('a😊😊', 2) returns 5
1406 echo byteidx('a😊😊', 2, 1) returns 1
1407 echo byteidx('a😊😊', 3, 1) returns 5
1408<
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001409 Can also be used as a |method|: >
1410 GetName()->byteidx(idx)
1411
Christian Brabandt67672ef2023-04-24 21:09:54 +01001412byteidxcomp({expr}, {nr} [, {utf16}]) *byteidxcomp()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001413 Like byteidx(), except that a composing character is counted
1414 as a separate character. Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00001415 let s = 'e' .. nr2char(0x301)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001416 echo byteidx(s, 1)
1417 echo byteidxcomp(s, 1)
1418 echo byteidxcomp(s, 2)
1419< The first and third echo result in 3 ('e' plus composing
1420 character is 3 bytes), the second echo results in 1 ('e' is
1421 one byte).
1422 Only works differently from byteidx() when 'encoding' is set
1423 to a Unicode encoding.
1424
1425 Can also be used as a |method|: >
1426 GetName()->byteidxcomp(idx)
1427
1428call({func}, {arglist} [, {dict}]) *call()* *E699*
1429 Call function {func} with the items in |List| {arglist} as
1430 arguments.
1431 {func} can either be a |Funcref| or the name of a function.
1432 a:firstline and a:lastline are set to the cursor line.
1433 Returns the return value of the called function.
1434 {dict} is for functions with the "dict" attribute. It will be
1435 used to set the local variable "self". |Dictionary-function|
1436
1437 Can also be used as a |method|: >
1438 GetFunc()->call([arg, arg], dict)
1439
1440ceil({expr}) *ceil()*
1441 Return the smallest integral value greater than or equal to
1442 {expr} as a |Float| (round up).
1443 {expr} must evaluate to a |Float| or a |Number|.
1444 Examples: >
1445 echo ceil(1.456)
1446< 2.0 >
1447 echo ceil(-5.456)
1448< -5.0 >
1449 echo ceil(4.0)
1450< 4.0
1451
Bram Moolenaar016188f2022-06-06 20:52:59 +01001452 Returns 0.0 if {expr} is not a |Float| or a |Number|.
1453
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001454 Can also be used as a |method|: >
1455 Compute()->ceil()
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001456
1457
1458ch_ functions are documented here: |channel-functions-details|
1459
1460
1461changenr() *changenr()*
1462 Return the number of the most recent change. This is the same
1463 number as what is displayed with |:undolist| and can be used
1464 with the |:undo| command.
1465 When a change was made it is the number of that change. After
1466 redo it is the number of the redone change. After undo it is
1467 one less than the number of the undone change.
Bram Moolenaar016188f2022-06-06 20:52:59 +01001468 Returns 0 if the undo list is empty.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001469
1470char2nr({string} [, {utf8}]) *char2nr()*
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01001471 Return Number value of the first char in {string}.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001472 Examples: >
1473 char2nr(" ") returns 32
1474 char2nr("ABC") returns 65
1475< When {utf8} is omitted or zero, the current 'encoding' is used.
1476 Example for "utf-8": >
1477 char2nr("á") returns 225
1478 char2nr("á"[0]) returns 195
1479< When {utf8} is TRUE, always treat as UTF-8 characters.
1480 A combining character is a separate character.
1481 |nr2char()| does the opposite.
1482 To turn a string into a list of character numbers: >
1483 let str = "ABC"
1484 let list = map(split(str, '\zs'), {_, val -> char2nr(val)})
1485< Result: [65, 66, 67]
1486
Bram Moolenaar016188f2022-06-06 20:52:59 +01001487 Returns 0 if {string} is not a |String|.
1488
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001489 Can also be used as a |method|: >
1490 GetChar()->char2nr()
1491
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001492charclass({string}) *charclass()*
1493 Return the character class of the first character in {string}.
1494 The character class is one of:
1495 0 blank
1496 1 punctuation
1497 2 word character
1498 3 emoji
1499 other specific Unicode class
1500 The class is used in patterns and word motions.
Bram Moolenaar016188f2022-06-06 20:52:59 +01001501 Returns 0 if {string} is not a |String|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001502
1503
Yegappan Lakshmanan4c8d2f02022-11-12 16:07:47 +00001504charcol({expr} [, {winid}]) *charcol()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001505 Same as |col()| but returns the character index of the column
1506 position given with {expr} instead of the byte position.
1507
1508 Example:
1509 With the cursor on '세' in line 5 with text "여보세요": >
1510 charcol('.') returns 3
1511 col('.') returns 7
1512
1513< Can also be used as a |method|: >
1514 GetPos()->col()
1515<
1516 *charidx()*
Christian Brabandt67672ef2023-04-24 21:09:54 +01001517charidx({string}, {idx} [, {countcc} [, {utf16}]])
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001518 Return the character index of the byte at {idx} in {string}.
1519 The index of the first character is zero.
1520 If there are no multibyte characters the returned value is
1521 equal to {idx}.
Christian Brabandt67672ef2023-04-24 21:09:54 +01001522
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001523 When {countcc} is omitted or |FALSE|, then composing characters
Christian Brabandt67672ef2023-04-24 21:09:54 +01001524 are not counted separately, their byte length is added to the
1525 preceding base character.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001526 When {countcc} is |TRUE|, then composing characters are
1527 counted as separate characters.
Christian Brabandt67672ef2023-04-24 21:09:54 +01001528
1529 When {utf16} is present and TRUE, {idx} is used as the UTF-16
1530 index in the String {expr} instead of as the byte index.
1531
Yegappan Lakshmanan577922b2023-06-08 17:09:45 +01001532 Returns -1 if the arguments are invalid or if there are less
1533 than {idx} bytes. If there are exactly {idx} bytes the length
1534 of the string in characters is returned.
1535
1536 An error is given and -1 is returned if the first argument is
1537 not a string, the second argument is not a number or when the
1538 third argument is present and is not zero or one.
Christian Brabandt67672ef2023-04-24 21:09:54 +01001539
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001540 See |byteidx()| and |byteidxcomp()| for getting the byte index
Christian Brabandt67672ef2023-04-24 21:09:54 +01001541 from the character index and |utf16idx()| for getting the
1542 UTF-16 index from the character index.
1543 Refer to |string-offset-encoding| for more information.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001544 Examples: >
1545 echo charidx('áb́ć', 3) returns 1
1546 echo charidx('áb́ć', 6, 1) returns 4
1547 echo charidx('áb́ć', 16) returns -1
Christian Brabandt67672ef2023-04-24 21:09:54 +01001548 echo charidx('a😊😊', 4, 0, 1) returns 2
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001549<
1550 Can also be used as a |method|: >
1551 GetName()->charidx(idx)
1552
1553chdir({dir}) *chdir()*
1554 Change the current working directory to {dir}. The scope of
1555 the directory change depends on the directory of the current
1556 window:
1557 - If the current window has a window-local directory
1558 (|:lcd|), then changes the window local directory.
1559 - Otherwise, if the current tabpage has a local
1560 directory (|:tcd|) then changes the tabpage local
1561 directory.
1562 - Otherwise, changes the global directory.
1563 {dir} must be a String.
1564 If successful, returns the previous working directory. Pass
1565 this to another chdir() to restore the directory.
1566 On failure, returns an empty string.
1567
1568 Example: >
1569 let save_dir = chdir(newdir)
1570 if save_dir != ""
1571 " ... do some work
1572 call chdir(save_dir)
1573 endif
1574
1575< Can also be used as a |method|: >
1576 GetDir()->chdir()
1577<
1578cindent({lnum}) *cindent()*
1579 Get the amount of indent for line {lnum} according the C
1580 indenting rules, as with 'cindent'.
1581 The indent is counted in spaces, the value of 'tabstop' is
1582 relevant. {lnum} is used just like in |getline()|.
Bram Moolenaar8e145b82022-05-21 20:17:31 +01001583 When {lnum} is invalid -1 is returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001584 See |C-indenting|.
1585
1586 Can also be used as a |method|: >
1587 GetLnum()->cindent()
1588
1589clearmatches([{win}]) *clearmatches()*
1590 Clears all matches previously defined for the current window
1591 by |matchadd()| and the |:match| commands.
1592 If {win} is specified, use the window with this number or
1593 window ID instead of the current window.
1594
1595 Can also be used as a |method|: >
1596 GetWin()->clearmatches()
1597<
Bram Moolenaar10e8ff92023-06-10 21:40:39 +01001598col({expr} [, {winid}]) *col()*
Yegappan Lakshmanan4c8d2f02022-11-12 16:07:47 +00001599 The result is a Number, which is the byte index of the column
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001600 position given with {expr}. The accepted positions are:
1601 . the cursor position
1602 $ the end of the cursor line (the result is the
1603 number of bytes in the cursor line plus one)
1604 'x position of mark x (if the mark is not set, 0 is
1605 returned)
1606 v In Visual mode: the start of the Visual area (the
1607 cursor is the end). When not in Visual mode
1608 returns the cursor position. Differs from |'<| in
1609 that it's updated right away.
1610 Additionally {expr} can be [lnum, col]: a |List| with the line
1611 and column number. Most useful when the column is "$", to get
1612 the last column of a specific line. When "lnum" or "col" is
1613 out of range then col() returns zero.
Yegappan Lakshmanan4c8d2f02022-11-12 16:07:47 +00001614 With the optional {winid} argument the values are obtained for
1615 that window instead of the current window.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001616 To get the line number use |line()|. To get both use
1617 |getpos()|.
1618 For the screen column position use |virtcol()|. For the
1619 character position use |charcol()|.
1620 Note that only marks in the current file can be used.
1621 Examples: >
1622 col(".") column of cursor
1623 col("$") length of cursor line plus one
1624 col("'t") column of mark t
Bram Moolenaarc51cf032022-02-26 12:25:45 +00001625 col("'" .. markname) column of mark markname
Yegappan Lakshmanan4c8d2f02022-11-12 16:07:47 +00001626< The first column is 1. Returns 0 if {expr} is invalid or when
1627 the window with ID {winid} is not found.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001628 For an uppercase mark the column may actually be in another
1629 buffer.
1630 For the cursor position, when 'virtualedit' is active, the
1631 column is one higher if the cursor is after the end of the
Bram Moolenaar6ebe4f92022-10-28 20:47:54 +01001632 line. Also, when using a <Cmd> mapping the cursor isn't
1633 moved, this can be used to obtain the column in Insert mode: >
Bram Moolenaar76db9e02022-11-09 21:21:04 +00001634 :imap <F2> <Cmd>echowin col(".")<CR>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001635
1636< Can also be used as a |method|: >
1637 GetPos()->col()
1638<
1639
1640complete({startcol}, {matches}) *complete()* *E785*
1641 Set the matches for Insert mode completion.
1642 Can only be used in Insert mode. You need to use a mapping
1643 with CTRL-R = (see |i_CTRL-R|). It does not work after CTRL-O
1644 or with an expression mapping.
1645 {startcol} is the byte offset in the line where the completed
1646 text start. The text up to the cursor is the original text
1647 that will be replaced by the matches. Use col('.') for an
1648 empty string. "col('.') - 1" will replace one character by a
1649 match.
1650 {matches} must be a |List|. Each |List| item is one match.
1651 See |complete-items| for the kind of items that are possible.
1652 "longest" in 'completeopt' is ignored.
1653 Note that the after calling this function you need to avoid
1654 inserting anything that would cause completion to stop.
1655 The match can be selected with CTRL-N and CTRL-P as usual with
1656 Insert mode completion. The popup menu will appear if
1657 specified, see |ins-completion-menu|.
1658 Example: >
1659 inoremap <F5> <C-R>=ListMonths()<CR>
1660
Bram Moolenaar10e8ff92023-06-10 21:40:39 +01001661 func ListMonths()
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001662 call complete(col('.'), ['January', 'February', 'March',
1663 \ 'April', 'May', 'June', 'July', 'August', 'September',
1664 \ 'October', 'November', 'December'])
1665 return ''
1666 endfunc
1667< This isn't very useful, but it shows how it works. Note that
1668 an empty string is returned to avoid a zero being inserted.
1669
1670 Can also be used as a |method|, the base is passed as the
1671 second argument: >
1672 GetMatches()->complete(col('.'))
1673
1674complete_add({expr}) *complete_add()*
1675 Add {expr} to the list of matches. Only to be used by the
1676 function specified with the 'completefunc' option.
1677 Returns 0 for failure (empty string or out of memory),
1678 1 when the match was added, 2 when the match was already in
1679 the list.
1680 See |complete-functions| for an explanation of {expr}. It is
1681 the same as one item in the list that 'omnifunc' would return.
1682
1683 Can also be used as a |method|: >
1684 GetMoreMatches()->complete_add()
1685
1686complete_check() *complete_check()*
1687 Check for a key typed while looking for completion matches.
1688 This is to be used when looking for matches takes some time.
1689 Returns |TRUE| when searching for matches is to be aborted,
1690 zero otherwise.
1691 Only to be used by the function specified with the
1692 'completefunc' option.
1693
1694
1695complete_info([{what}]) *complete_info()*
1696 Returns a |Dictionary| with information about Insert mode
1697 completion. See |ins-completion|.
1698 The items are:
1699 mode Current completion mode name string.
1700 See |complete_info_mode| for the values.
1701 pum_visible |TRUE| if popup menu is visible.
1702 See |pumvisible()|.
1703 items List of completion matches. Each item is a
1704 dictionary containing the entries "word",
1705 "abbr", "menu", "kind", "info" and "user_data".
1706 See |complete-items|.
1707 selected Selected item index. First index is zero.
1708 Index is -1 if no item is selected (showing
1709 typed text only, or the last completion after
1710 no item is selected when using the <Up> or
1711 <Down> keys)
Bram Moolenaar0daafaa2022-09-04 17:45:43 +01001712 inserted Inserted string. [NOT IMPLEMENTED YET]
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001713
1714 *complete_info_mode*
1715 mode values are:
1716 "" Not in completion mode
1717 "keyword" Keyword completion |i_CTRL-X_CTRL-N|
1718 "ctrl_x" Just pressed CTRL-X |i_CTRL-X|
1719 "scroll" Scrolling with |i_CTRL-X_CTRL-E| or
1720 |i_CTRL-X_CTRL-Y|
1721 "whole_line" Whole lines |i_CTRL-X_CTRL-L|
1722 "files" File names |i_CTRL-X_CTRL-F|
1723 "tags" Tags |i_CTRL-X_CTRL-]|
1724 "path_defines" Definition completion |i_CTRL-X_CTRL-D|
1725 "path_patterns" Include completion |i_CTRL-X_CTRL-I|
1726 "dictionary" Dictionary |i_CTRL-X_CTRL-K|
1727 "thesaurus" Thesaurus |i_CTRL-X_CTRL-T|
1728 "cmdline" Vim Command line |i_CTRL-X_CTRL-V|
1729 "function" User defined completion |i_CTRL-X_CTRL-U|
1730 "omni" Omni completion |i_CTRL-X_CTRL-O|
1731 "spell" Spelling suggestions |i_CTRL-X_s|
1732 "eval" |complete()| completion
1733 "unknown" Other internal modes
1734
1735 If the optional {what} list argument is supplied, then only
1736 the items listed in {what} are returned. Unsupported items in
1737 {what} are silently ignored.
1738
1739 To get the position and size of the popup menu, see
1740 |pum_getpos()|. It's also available in |v:event| during the
1741 |CompleteChanged| event.
1742
Bram Moolenaar016188f2022-06-06 20:52:59 +01001743 Returns an empty |Dictionary| on error.
1744
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001745 Examples: >
1746 " Get all items
1747 call complete_info()
1748 " Get only 'mode'
1749 call complete_info(['mode'])
1750 " Get only 'mode' and 'pum_visible'
1751 call complete_info(['mode', 'pum_visible'])
1752
1753< Can also be used as a |method|: >
1754 GetItems()->complete_info()
1755<
1756 *confirm()*
1757confirm({msg} [, {choices} [, {default} [, {type}]]])
1758 confirm() offers the user a dialog, from which a choice can be
1759 made. It returns the number of the choice. For the first
1760 choice this is 1.
1761 Note: confirm() is only supported when compiled with dialog
1762 support, see |+dialog_con| and |+dialog_gui|.
1763
1764 {msg} is displayed in a |dialog| with {choices} as the
1765 alternatives. When {choices} is missing or empty, "&OK" is
1766 used (and translated).
1767 {msg} is a String, use '\n' to include a newline. Only on
1768 some systems the string is wrapped when it doesn't fit.
1769
1770 {choices} is a String, with the individual choices separated
1771 by '\n', e.g. >
1772 confirm("Save changes?", "&Yes\n&No\n&Cancel")
1773< The letter after the '&' is the shortcut key for that choice.
1774 Thus you can type 'c' to select "Cancel". The shortcut does
1775 not need to be the first letter: >
1776 confirm("file has been modified", "&Save\nSave &All")
1777< For the console, the first letter of each choice is used as
1778 the default shortcut key. Case is ignored.
1779
1780 The optional {default} argument is the number of the choice
1781 that is made if the user hits <CR>. Use 1 to make the first
1782 choice the default one. Use 0 to not set a default. If
1783 {default} is omitted, 1 is used.
1784
1785 The optional {type} String argument gives the type of dialog.
1786 This is only used for the icon of the GTK, Mac, Motif and
1787 Win32 GUI. It can be one of these values: "Error",
1788 "Question", "Info", "Warning" or "Generic". Only the first
1789 character is relevant. When {type} is omitted, "Generic" is
1790 used.
1791
1792 If the user aborts the dialog by pressing <Esc>, CTRL-C,
1793 or another valid interrupt key, confirm() returns 0.
1794
1795 An example: >
Bram Moolenaar46eea442022-03-30 10:51:39 +01001796 let choice = confirm("What do you want?",
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01001797 \ "&Apples\n&Oranges\n&Bananas", 2)
Bram Moolenaar46eea442022-03-30 10:51:39 +01001798 if choice == 0
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01001799 echo "make up your mind!"
Bram Moolenaar46eea442022-03-30 10:51:39 +01001800 elseif choice == 3
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01001801 echo "tasteful"
Bram Moolenaar46eea442022-03-30 10:51:39 +01001802 else
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01001803 echo "I prefer bananas myself."
Bram Moolenaar46eea442022-03-30 10:51:39 +01001804 endif
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001805< In a GUI dialog, buttons are used. The layout of the buttons
1806 depends on the 'v' flag in 'guioptions'. If it is included,
1807 the buttons are always put vertically. Otherwise, confirm()
1808 tries to put the buttons in one horizontal line. If they
1809 don't fit, a vertical layout is used anyway. For some systems
1810 the horizontal layout is always used.
1811
1812 Can also be used as a |method|in: >
1813 BuildMessage()->confirm("&Yes\n&No")
1814<
1815 *copy()*
1816copy({expr}) Make a copy of {expr}. For Numbers and Strings this isn't
1817 different from using {expr} directly.
1818 When {expr} is a |List| a shallow copy is created. This means
1819 that the original |List| can be changed without changing the
1820 copy, and vice versa. But the items are identical, thus
1821 changing an item changes the contents of both |Lists|.
1822 A |Dictionary| is copied in a similar way as a |List|.
1823 Also see |deepcopy()|.
1824 Can also be used as a |method|: >
1825 mylist->copy()
1826
1827cos({expr}) *cos()*
1828 Return the cosine of {expr}, measured in radians, as a |Float|.
1829 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar016188f2022-06-06 20:52:59 +01001830 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001831 Examples: >
1832 :echo cos(100)
1833< 0.862319 >
1834 :echo cos(-4.01)
1835< -0.646043
1836
1837 Can also be used as a |method|: >
1838 Compute()->cos()
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001839
1840
1841cosh({expr}) *cosh()*
1842 Return the hyperbolic cosine of {expr} as a |Float| in the range
1843 [1, inf].
1844 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar016188f2022-06-06 20:52:59 +01001845 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001846 Examples: >
1847 :echo cosh(0.5)
1848< 1.127626 >
1849 :echo cosh(-0.5)
1850< -1.127626
1851
1852 Can also be used as a |method|: >
1853 Compute()->cosh()
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001854
1855
1856count({comp}, {expr} [, {ic} [, {start}]]) *count()*
1857 Return the number of times an item with value {expr} appears
1858 in |String|, |List| or |Dictionary| {comp}.
1859
1860 If {start} is given then start with the item with this index.
1861 {start} can only be used with a |List|.
1862
1863 When {ic} is given and it's |TRUE| then case is ignored.
1864
1865 When {comp} is a string then the number of not overlapping
1866 occurrences of {expr} is returned. Zero is returned when
1867 {expr} is an empty string.
1868
1869 Can also be used as a |method|: >
1870 mylist->count(val)
1871<
1872 *cscope_connection()*
1873cscope_connection([{num} , {dbpath} [, {prepend}]])
1874 Checks for the existence of a |cscope| connection. If no
1875 parameters are specified, then the function returns:
1876 0, if cscope was not available (not compiled in), or
1877 if there are no cscope connections;
1878 1, if there is at least one cscope connection.
1879
1880 If parameters are specified, then the value of {num}
1881 determines how existence of a cscope connection is checked:
1882
1883 {num} Description of existence check
1884 ----- ------------------------------
1885 0 Same as no parameters (e.g., "cscope_connection()").
1886 1 Ignore {prepend}, and use partial string matches for
1887 {dbpath}.
1888 2 Ignore {prepend}, and use exact string matches for
1889 {dbpath}.
1890 3 Use {prepend}, use partial string matches for both
1891 {dbpath} and {prepend}.
1892 4 Use {prepend}, use exact string matches for both
1893 {dbpath} and {prepend}.
1894
1895 Note: All string comparisons are case sensitive!
1896
1897 Examples. Suppose we had the following (from ":cs show"): >
1898
1899 # pid database name prepend path
1900 0 27664 cscope.out /usr/local
1901<
1902 Invocation Return Val ~
1903 ---------- ---------- >
1904 cscope_connection() 1
1905 cscope_connection(1, "out") 1
1906 cscope_connection(2, "out") 0
1907 cscope_connection(3, "out") 0
1908 cscope_connection(3, "out", "local") 1
1909 cscope_connection(4, "out") 0
1910 cscope_connection(4, "out", "local") 0
1911 cscope_connection(4, "cscope.out", "/usr/local") 1
1912<
1913cursor({lnum}, {col} [, {off}]) *cursor()*
1914cursor({list})
1915 Positions the cursor at the column (byte count) {col} in the
1916 line {lnum}. The first column is one.
1917
1918 When there is one argument {list} this is used as a |List|
1919 with two, three or four item:
1920 [{lnum}, {col}]
1921 [{lnum}, {col}, {off}]
1922 [{lnum}, {col}, {off}, {curswant}]
1923 This is like the return value of |getpos()| or |getcurpos()|,
1924 but without the first item.
1925
Bram Moolenaar10e8ff92023-06-10 21:40:39 +01001926 To position the cursor using {col} as the character count, use
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001927 |setcursorcharpos()|.
1928
1929 Does not change the jumplist.
Bram Moolenaar7c6cd442022-10-11 21:54:04 +01001930 {lnum} is used like with |getline()|, except that if {lnum} is
1931 zero, the cursor will stay in the current line.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001932 If {lnum} is greater than the number of lines in the buffer,
1933 the cursor will be positioned at the last line in the buffer.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001934 If {col} is greater than the number of bytes in the line,
1935 the cursor will be positioned at the last character in the
1936 line.
1937 If {col} is zero, the cursor will stay in the current column.
1938 If {curswant} is given it is used to set the preferred column
1939 for vertical movement. Otherwise {col} is used.
1940
1941 When 'virtualedit' is used {off} specifies the offset in
1942 screen columns from the start of the character. E.g., a
1943 position within a <Tab> or after the last character.
1944 Returns 0 when the position could be set, -1 otherwise.
1945
1946 Can also be used as a |method|: >
1947 GetCursorPos()->cursor()
1948
1949debugbreak({pid}) *debugbreak()*
1950 Specifically used to interrupt a program being debugged. It
1951 will cause process {pid} to get a SIGTRAP. Behavior for other
1952 processes is undefined. See |terminal-debugger|.
1953 {only available on MS-Windows}
1954
Bram Moolenaar016188f2022-06-06 20:52:59 +01001955 Returns |TRUE| if successfully interrupted the program.
1956 Otherwise returns |FALSE|.
1957
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001958 Can also be used as a |method|: >
1959 GetPid()->debugbreak()
1960
1961deepcopy({expr} [, {noref}]) *deepcopy()* *E698*
1962 Make a copy of {expr}. For Numbers and Strings this isn't
1963 different from using {expr} directly.
1964 When {expr} is a |List| a full copy is created. This means
1965 that the original |List| can be changed without changing the
1966 copy, and vice versa. When an item is a |List| or
1967 |Dictionary|, a copy for it is made, recursively. Thus
1968 changing an item in the copy does not change the contents of
1969 the original |List|.
1970 A |Dictionary| is copied in a similar way as a |List|.
1971
1972 When {noref} is omitted or zero a contained |List| or
1973 |Dictionary| is only copied once. All references point to
1974 this single copy. With {noref} set to 1 every occurrence of a
1975 |List| or |Dictionary| results in a new copy. This also means
1976 that a cyclic reference causes deepcopy() to fail.
1977 *E724*
1978 Nesting is possible up to 100 levels. When there is an item
1979 that refers back to a higher level making a deep copy with
1980 {noref} set to 1 will fail.
1981 Also see |copy()|.
1982
1983 Can also be used as a |method|: >
1984 GetObject()->deepcopy()
1985
1986delete({fname} [, {flags}]) *delete()*
1987 Without {flags} or with {flags} empty: Deletes the file by the
Bram Moolenaarcbaff5e2022-04-08 17:45:08 +01001988 name {fname}.
1989
1990 This also works when {fname} is a symbolic link. The symbolic
1991 link itself is deleted, not what it points to.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001992
1993 When {flags} is "d": Deletes the directory by the name
1994 {fname}. This fails when directory {fname} is not empty.
1995
1996 When {flags} is "rf": Deletes the directory by the name
1997 {fname} and everything in it, recursively. BE CAREFUL!
1998 Note: on MS-Windows it is not possible to delete a directory
1999 that is being used.
2000
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002001 The result is a Number, which is 0/false if the delete
2002 operation was successful and -1/true when the deletion failed
2003 or partly failed.
2004
2005 Use |remove()| to delete an item from a |List|.
2006 To delete a line from the buffer use |:delete| or
2007 |deletebufline()|.
2008
2009 Can also be used as a |method|: >
2010 GetName()->delete()
2011
2012deletebufline({buf}, {first} [, {last}]) *deletebufline()*
2013 Delete lines {first} to {last} (inclusive) from buffer {buf}.
2014 If {last} is omitted then delete line {first} only.
2015 On success 0 is returned, on failure 1 is returned.
2016
2017 This function works only for loaded buffers. First call
2018 |bufload()| if needed.
2019
2020 For the use of {buf}, see |bufname()| above.
2021
2022 {first} and {last} are used like with |getline()|. Note that
2023 when using |line()| this refers to the current buffer. Use "$"
2024 to refer to the last line in buffer {buf}.
2025
2026 Can also be used as a |method|: >
2027 GetBuffer()->deletebufline(1)
2028<
2029 *did_filetype()*
2030did_filetype() Returns |TRUE| when autocommands are being executed and the
2031 FileType event has been triggered at least once. Can be used
2032 to avoid triggering the FileType event again in the scripts
2033 that detect the file type. |FileType|
2034 Returns |FALSE| when `:setf FALLBACK` was used.
2035 When editing another file, the counter is reset, thus this
2036 really checks if the FileType event has been triggered for the
2037 current buffer. This allows an autocommand that starts
2038 editing another buffer to set 'filetype' and load a syntax
2039 file.
2040
2041diff_filler({lnum}) *diff_filler()*
2042 Returns the number of filler lines above line {lnum}.
2043 These are the lines that were inserted at this point in
2044 another diff'ed window. These filler lines are shown in the
2045 display but don't exist in the buffer.
2046 {lnum} is used like with |getline()|. Thus "." is the current
2047 line, "'m" mark m, etc.
2048 Returns 0 if the current window is not in diff mode.
2049
2050 Can also be used as a |method|: >
2051 GetLnum()->diff_filler()
2052
2053diff_hlID({lnum}, {col}) *diff_hlID()*
2054 Returns the highlight ID for diff mode at line {lnum} column
2055 {col} (byte index). When the current line does not have a
2056 diff change zero is returned.
2057 {lnum} is used like with |getline()|. Thus "." is the current
2058 line, "'m" mark m, etc.
2059 {col} is 1 for the leftmost column, {lnum} is 1 for the first
2060 line.
2061 The highlight ID can be used with |synIDattr()| to obtain
2062 syntax information about the highlighting.
2063
2064 Can also be used as a |method|: >
2065 GetLnum()->diff_hlID(col)
2066<
2067
2068digraph_get({chars}) *digraph_get()* *E1214*
2069 Return the digraph of {chars}. This should be a string with
2070 exactly two characters. If {chars} are not just two
2071 characters, or the digraph of {chars} does not exist, an error
2072 is given and an empty string is returned.
2073
2074 The character will be converted from Unicode to 'encoding'
2075 when needed. This does require the conversion to be
2076 available, it might fail.
2077
2078 Also see |digraph_getlist()|.
2079
2080 Examples: >
2081 " Get a built-in digraph
2082 :echo digraph_get('00') " Returns '∞'
2083
2084 " Get a user-defined digraph
2085 :call digraph_set('aa', 'あ')
2086 :echo digraph_get('aa') " Returns 'あ'
2087<
2088 Can also be used as a |method|: >
2089 GetChars()->digraph_get()
2090<
2091 This function works only when compiled with the |+digraphs|
2092 feature. If this feature is disabled, this function will
2093 display an error message.
2094
2095
2096digraph_getlist([{listall}]) *digraph_getlist()*
2097 Return a list of digraphs. If the {listall} argument is given
2098 and it is TRUE, return all digraphs, including the default
2099 digraphs. Otherwise, return only user-defined digraphs.
2100
2101 The characters will be converted from Unicode to 'encoding'
2102 when needed. This does require the conservation to be
2103 available, it might fail.
2104
2105 Also see |digraph_get()|.
2106
2107 Examples: >
2108 " Get user-defined digraphs
2109 :echo digraph_getlist()
2110
2111 " Get all the digraphs, including default digraphs
2112 :echo digraph_getlist(1)
2113<
2114 Can also be used as a |method|: >
2115 GetNumber()->digraph_getlist()
2116<
2117 This function works only when compiled with the |+digraphs|
2118 feature. If this feature is disabled, this function will
2119 display an error message.
2120
2121
Bram Moolenaara2baa732022-02-04 16:09:54 +00002122digraph_set({chars}, {digraph}) *digraph_set()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002123 Add digraph {chars} to the list. {chars} must be a string
2124 with two characters. {digraph} is a string with one UTF-8
Bram Moolenaara2baa732022-02-04 16:09:54 +00002125 encoded character. *E1215*
2126 Be careful, composing characters are NOT ignored. This
2127 function is similar to |:digraphs| command, but useful to add
2128 digraphs start with a white space.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002129
2130 The function result is v:true if |digraph| is registered. If
2131 this fails an error message is given and v:false is returned.
2132
2133 If you want to define multiple digraphs at once, you can use
2134 |digraph_setlist()|.
2135
2136 Example: >
2137 call digraph_set(' ', 'あ')
2138<
2139 Can be used as a |method|: >
2140 GetString()->digraph_set('あ')
2141<
2142 This function works only when compiled with the |+digraphs|
2143 feature. If this feature is disabled, this function will
2144 display an error message.
2145
2146
2147digraph_setlist({digraphlist}) *digraph_setlist()*
2148 Similar to |digraph_set()| but this function can add multiple
2149 digraphs at once. {digraphlist} is a list composed of lists,
2150 where each list contains two strings with {chars} and
Bram Moolenaara2baa732022-02-04 16:09:54 +00002151 {digraph} as in |digraph_set()|. *E1216*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002152 Example: >
2153 call digraph_setlist([['aa', 'あ'], ['ii', 'い']])
2154<
2155 It is similar to the following: >
2156 for [chars, digraph] in [['aa', 'あ'], ['ii', 'い']]
2157 call digraph_set(chars, digraph)
2158 endfor
2159< Except that the function returns after the first error,
2160 following digraphs will not be added.
2161
2162 Can be used as a |method|: >
2163 GetList()->digraph_setlist()
2164<
2165 This function works only when compiled with the |+digraphs|
2166 feature. If this feature is disabled, this function will
2167 display an error message.
2168
2169
2170echoraw({string}) *echoraw()*
2171 Output {string} as-is, including unprintable characters.
2172 This can be used to output a terminal code. For example, to
2173 disable modifyOtherKeys: >
2174 call echoraw(&t_TE)
2175< and to enable it again: >
2176 call echoraw(&t_TI)
2177< Use with care, you can mess up the terminal this way.
2178
2179
Bram Moolenaar80adaa82023-07-07 18:57:40 +01002180err_teapot([{expr}]) *err_teapot()*
2181 Produce an error with number 418, needed for implementation of
2182 RFC 2325.
2183 If {expr} is present and it is TRUE error 503 is given,
2184 indicating that coffee is temporarily not available.
2185 If {expr} is present it must be a String.
2186
2187
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002188empty({expr}) *empty()*
2189 Return the Number 1 if {expr} is empty, zero otherwise.
2190 - A |List| or |Dictionary| is empty when it does not have any
2191 items.
2192 - A |String| is empty when its length is zero.
2193 - A |Number| and |Float| are empty when their value is zero.
2194 - |v:false|, |v:none| and |v:null| are empty, |v:true| is not.
2195 - A |Job| is empty when it failed to start.
2196 - A |Channel| is empty when it is closed.
2197 - A |Blob| is empty when its length is zero.
2198
2199 For a long |List| this is much faster than comparing the
2200 length with zero.
2201
2202 Can also be used as a |method|: >
2203 mylist->empty()
2204
2205environ() *environ()*
2206 Return all of environment variables as dictionary. You can
2207 check if an environment variable exists like this: >
2208 :echo has_key(environ(), 'HOME')
2209< Note that the variable name may be CamelCase; to ignore case
2210 use this: >
2211 :echo index(keys(environ()), 'HOME', 0, 1) != -1
2212
2213escape({string}, {chars}) *escape()*
2214 Escape the characters in {chars} that occur in {string} with a
2215 backslash. Example: >
2216 :echo escape('c:\program files\vim', ' \')
2217< results in: >
2218 c:\\program\ files\\vim
2219< Also see |shellescape()| and |fnameescape()|.
2220
2221 Can also be used as a |method|: >
2222 GetText()->escape(' \')
2223<
2224 *eval()*
2225eval({string}) Evaluate {string} and return the result. Especially useful to
2226 turn the result of |string()| back into the original value.
2227 This works for Numbers, Floats, Strings, Blobs and composites
2228 of them. Also works for |Funcref|s that refer to existing
2229 functions.
2230
2231 Can also be used as a |method|: >
2232 argv->join()->eval()
2233
2234eventhandler() *eventhandler()*
2235 Returns 1 when inside an event handler. That is that Vim got
2236 interrupted while waiting for the user to type a character,
2237 e.g., when dropping a file on Vim. This means interactive
2238 commands cannot be used. Otherwise zero is returned.
2239
2240executable({expr}) *executable()*
2241 This function checks if an executable with the name {expr}
2242 exists. {expr} must be the name of the program without any
2243 arguments.
2244 executable() uses the value of $PATH and/or the normal
2245 searchpath for programs. *PATHEXT*
2246 On MS-Windows the ".exe", ".bat", etc. can optionally be
2247 included. Then the extensions in $PATHEXT are tried. Thus if
2248 "foo.exe" does not exist, "foo.exe.bat" can be found. If
2249 $PATHEXT is not set then ".com;.exe;.bat;.cmd" is used. A dot
2250 by itself can be used in $PATHEXT to try using the name
2251 without an extension. When 'shell' looks like a Unix shell,
2252 then the name is also tried without adding an extension.
2253 On MS-Windows it only checks if the file exists and is not a
2254 directory, not if it's really executable.
2255 On MS-Windows an executable in the same directory as Vim is
Yasuhiro Matsumoto05cf63e2022-05-03 11:02:28 +01002256 normally found. Since this directory is added to $PATH it
2257 should also work to execute it |win32-PATH|. This can be
2258 disabled by setting the $NoDefaultCurrentDirectoryInExePath
2259 environment variable. *NoDefaultCurrentDirectoryInExePath*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002260 The result is a Number:
2261 1 exists
2262 0 does not exist
2263 -1 not implemented on this system
2264 |exepath()| can be used to get the full path of an executable.
2265
2266 Can also be used as a |method|: >
2267 GetCommand()->executable()
2268
2269execute({command} [, {silent}]) *execute()*
2270 Execute an Ex command or commands and return the output as a
2271 string.
2272 {command} can be a string or a List. In case of a List the
2273 lines are executed one by one.
Bram Moolenaarb7398fe2023-05-14 18:50:25 +01002274 This is more or less equivalent to: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002275 redir => var
2276 {command}
2277 redir END
Bram Moolenaar71badf92023-04-22 22:40:14 +01002278< Except that line continuation in {command} is not recognized.
2279
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002280 The optional {silent} argument can have these values:
2281 "" no `:silent` used
2282 "silent" `:silent` used
2283 "silent!" `:silent!` used
2284 The default is "silent". Note that with "silent!", unlike
2285 `:redir`, error messages are dropped. When using an external
2286 command the screen may be messed up, use `system()` instead.
2287 *E930*
2288 It is not possible to use `:redir` anywhere in {command}.
2289
Bram Moolenaarb7398fe2023-05-14 18:50:25 +01002290 To get a list of lines use `split()` on the result: >
Bram Moolenaar75ab5902022-04-18 15:36:40 +01002291 execute('args')->split("\n")
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002292
2293< To execute a command in another window than the current one
2294 use `win_execute()`.
2295
2296 When used recursively the output of the recursive call is not
2297 included in the output of the higher level call.
2298
2299 Can also be used as a |method|: >
2300 GetCommand()->execute()
2301
2302exepath({expr}) *exepath()*
2303 If {expr} is an executable and is either an absolute path, a
2304 relative path or found in $PATH, return the full path.
2305 Note that the current directory is used when {expr} starts
2306 with "./", which may be a problem for Vim: >
2307 echo exepath(v:progpath)
2308< If {expr} cannot be found in $PATH or is not executable then
2309 an empty string is returned.
2310
2311 Can also be used as a |method|: >
2312 GetCommand()->exepath()
2313<
2314 *exists()*
2315exists({expr}) The result is a Number, which is |TRUE| if {expr} is defined,
2316 zero otherwise.
2317
2318 Note: In a compiled |:def| function the evaluation is done at
2319 runtime. Use `exists_compiled()` to evaluate the expression
2320 at compile time.
2321
2322 For checking for a supported feature use |has()|.
2323 For checking if a file exists use |filereadable()|.
2324
2325 The {expr} argument is a string, which contains one of these:
Bram Moolenaarf10911e2022-01-29 22:20:48 +00002326 varname internal variable (see
2327 dict.key |internal-variables|). Also works
2328 list[i] for |curly-braces-names|, |Dictionary|
2329 import.Func entries, |List| items, imported
Bram Moolenaar944697a2022-02-20 19:48:20 +00002330 items, etc.
Bram Moolenaarf10911e2022-01-29 22:20:48 +00002331 Does not work for local variables in a
2332 compiled `:def` function.
Bram Moolenaar944697a2022-02-20 19:48:20 +00002333 Also works for a function in |Vim9|
2334 script, since it can be used as a
2335 function reference.
Bram Moolenaarf10911e2022-01-29 22:20:48 +00002336 Beware that evaluating an index may
2337 cause an error message for an invalid
2338 expression. E.g.: >
2339 :let l = [1, 2, 3]
2340 :echo exists("l[5]")
2341< 0 >
2342 :echo exists("l[xx]")
2343< E121: Undefined variable: xx
2344 0
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002345 &option-name Vim option (only checks if it exists,
2346 not if it really works)
2347 +option-name Vim option that works.
2348 $ENVNAME environment variable (could also be
2349 done by comparing with an empty
2350 string)
2351 *funcname built-in function (see |functions|)
2352 or user defined function (see
2353 |user-functions|) that is implemented.
2354 Also works for a variable that is a
2355 Funcref.
2356 ?funcname built-in function that could be
2357 implemented; to be used to check if
2358 "funcname" is valid
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002359 :cmdname Ex command: built-in command, user
2360 command or command modifier |:command|.
2361 Returns:
2362 1 for match with start of a command
2363 2 full match with a command
2364 3 matches several user commands
2365 To check for a supported command
2366 always check the return value to be 2.
2367 :2match The |:2match| command.
Bram Moolenaarb529cfb2022-07-25 15:42:07 +01002368 :3match The |:3match| command (but you
2369 probably should not use it, it is
2370 reserved for internal usage)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002371 #event autocommand defined for this event
2372 #event#pattern autocommand defined for this event and
2373 pattern (the pattern is taken
2374 literally and compared to the
2375 autocommand patterns character by
2376 character)
2377 #group autocommand group exists
2378 #group#event autocommand defined for this group and
2379 event.
2380 #group#event#pattern
2381 autocommand defined for this group,
2382 event and pattern.
2383 ##event autocommand for this event is
2384 supported.
2385
2386 Examples: >
2387 exists("&shortname")
2388 exists("$HOSTNAME")
2389 exists("*strftime")
Bram Moolenaar944697a2022-02-20 19:48:20 +00002390 exists("*s:MyFunc") " only for legacy script
2391 exists("*MyFunc")
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002392 exists("bufcount")
2393 exists(":Make")
2394 exists("#CursorHold")
2395 exists("#BufReadPre#*.gz")
2396 exists("#filetypeindent")
2397 exists("#filetypeindent#FileType")
2398 exists("#filetypeindent#FileType#*")
2399 exists("##ColorScheme")
2400< There must be no space between the symbol (&/$/*/#) and the
2401 name.
2402 There must be no extra characters after the name, although in
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01002403 a few cases this is ignored. That may become stricter in the
2404 future, thus don't count on it!
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002405 Working example: >
2406 exists(":make")
2407< NOT working example: >
2408 exists(":make install")
2409
2410< Note that the argument must be a string, not the name of the
2411 variable itself. For example: >
2412 exists(bufcount)
2413< This doesn't check for existence of the "bufcount" variable,
2414 but gets the value of "bufcount", and checks if that exists.
2415
2416 Can also be used as a |method|: >
2417 Varname()->exists()
2418<
2419
2420exists_compiled({expr}) *exists_compiled()*
2421 Like `exists()` but evaluated at compile time. This is useful
2422 to skip a block where a function is used that would otherwise
2423 give an error: >
2424 if exists_compiled('*ThatFunction')
2425 ThatFunction('works')
2426 endif
2427< If `exists()` were used then a compilation error would be
2428 given if ThatFunction() is not defined.
2429
2430 {expr} must be a literal string. *E1232*
2431 Can only be used in a |:def| function. *E1233*
2432 This does not work to check for arguments or local variables.
2433
2434
2435exp({expr}) *exp()*
2436 Return the exponential of {expr} as a |Float| in the range
2437 [0, inf].
2438 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar016188f2022-06-06 20:52:59 +01002439 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002440 Examples: >
2441 :echo exp(2)
2442< 7.389056 >
2443 :echo exp(-1)
2444< 0.367879
2445
2446 Can also be used as a |method|: >
2447 Compute()->exp()
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002448
2449
2450expand({string} [, {nosuf} [, {list}]]) *expand()*
2451 Expand wildcards and the following special keywords in
2452 {string}. 'wildignorecase' applies.
2453
2454 If {list} is given and it is |TRUE|, a List will be returned.
2455 Otherwise the result is a String and when there are several
2456 matches, they are separated by <NL> characters. [Note: in
2457 version 5.0 a space was used, which caused problems when a
2458 file name contains a space]
2459
2460 If the expansion fails, the result is an empty string. A name
2461 for a non-existing file is not included, unless {string} does
2462 not start with '%', '#' or '<', see below.
2463
2464 When {string} starts with '%', '#' or '<', the expansion is
2465 done like for the |cmdline-special| variables with their
2466 associated modifiers. Here is a short overview:
2467
2468 % current file name
2469 # alternate file name
2470 #n alternate file name n
2471 <cfile> file name under the cursor
2472 <afile> autocmd file name
2473 <abuf> autocmd buffer number (as a String!)
2474 <amatch> autocmd matched name
2475 <cexpr> C expression under the cursor
2476 <sfile> sourced script file or function name
2477 <slnum> sourced script line number or function
2478 line number
2479 <sflnum> script file line number, also when in
2480 a function
2481 <SID> "<SNR>123_" where "123" is the
2482 current script ID |<SID>|
Bram Moolenaar75ab5902022-04-18 15:36:40 +01002483 <script> sourced script file, or script file
2484 where the current function was defined
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002485 <stack> call stack
2486 <cword> word under the cursor
2487 <cWORD> WORD under the cursor
2488 <client> the {clientid} of the last received
2489 message |server2client()|
2490 Modifiers:
2491 :p expand to full path
2492 :h head (last path component removed)
2493 :t tail (last path component only)
2494 :r root (one extension removed)
2495 :e extension only
2496
2497 Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00002498 :let &tags = expand("%:p:h") .. "/tags"
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002499< Note that when expanding a string that starts with '%', '#' or
2500 '<', any following text is ignored. This does NOT work: >
2501 :let doesntwork = expand("%:h.bak")
2502< Use this: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00002503 :let doeswork = expand("%:h") .. ".bak"
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002504< Also note that expanding "<cfile>" and others only returns the
2505 referenced file name without further expansion. If "<cfile>"
2506 is "~/.cshrc", you need to do another expand() to have the
2507 "~/" expanded into the path of the home directory: >
2508 :echo expand(expand("<cfile>"))
2509<
2510 There cannot be white space between the variables and the
2511 following modifier. The |fnamemodify()| function can be used
2512 to modify normal file names.
2513
2514 When using '%' or '#', and the current or alternate file name
2515 is not defined, an empty string is used. Using "%:p" in a
2516 buffer with no name, results in the current directory, with a
2517 '/' added.
Bram Moolenaar57544522022-04-12 12:54:11 +01002518 When 'verbose' is set then expanding '%', '#' and <> items
2519 will result in an error message if the argument cannot be
2520 expanded.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002521
2522 When {string} does not start with '%', '#' or '<', it is
2523 expanded like a file name is expanded on the command line.
2524 'suffixes' and 'wildignore' are used, unless the optional
2525 {nosuf} argument is given and it is |TRUE|.
2526 Names for non-existing files are included. The "**" item can
2527 be used to search in a directory tree. For example, to find
2528 all "README" files in the current directory and below: >
2529 :echo expand("**/README")
2530<
2531 expand() can also be used to expand variables and environment
2532 variables that are only known in a shell. But this can be
2533 slow, because a shell may be used to do the expansion. See
2534 |expr-env-expand|.
2535 The expanded variable is still handled like a list of file
2536 names. When an environment variable cannot be expanded, it is
2537 left unchanged. Thus ":echo expand('$FOOBAR')" results in
2538 "$FOOBAR".
2539
2540 See |glob()| for finding existing files. See |system()| for
2541 getting the raw output of an external command.
2542
2543 Can also be used as a |method|: >
2544 Getpattern()->expand()
2545
Yegappan Lakshmanan2b74b682022-04-03 21:30:32 +01002546expandcmd({string} [, {options}]) *expandcmd()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002547 Expand special items in String {string} like what is done for
2548 an Ex command such as `:edit`. This expands special keywords,
2549 like with |expand()|, and environment variables, anywhere in
2550 {string}. "~user" and "~/path" are only expanded at the
2551 start.
Yegappan Lakshmanan2b74b682022-04-03 21:30:32 +01002552
2553 The following items are supported in the {options} Dict
2554 argument:
2555 errmsg If set to TRUE, error messages are displayed
2556 if an error is encountered during expansion.
2557 By default, error messages are not displayed.
2558
Yegappan Lakshmanan5018a832022-04-02 21:12:21 +01002559 Returns the expanded string. If an error is encountered
2560 during expansion, the unmodified {string} is returned.
Yegappan Lakshmanan2b74b682022-04-03 21:30:32 +01002561
Yegappan Lakshmanan5018a832022-04-02 21:12:21 +01002562 Example: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002563 :echo expandcmd('make %<.o')
Yegappan Lakshmanan2b74b682022-04-03 21:30:32 +01002564 make /path/runtime/doc/builtin.o
2565 :echo expandcmd('make %<.o', {'errmsg': v:true})
2566<
Yegappan Lakshmanan5018a832022-04-02 21:12:21 +01002567 Can also be used as a |method|: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002568 GetCommand()->expandcmd()
2569<
2570extend({expr1}, {expr2} [, {expr3}]) *extend()*
2571 {expr1} and {expr2} must be both |Lists| or both
2572 |Dictionaries|.
2573
2574 If they are |Lists|: Append {expr2} to {expr1}.
2575 If {expr3} is given insert the items of {expr2} before the
2576 item with index {expr3} in {expr1}. When {expr3} is zero
2577 insert before the first item. When {expr3} is equal to
2578 len({expr1}) then {expr2} is appended.
2579 Examples: >
2580 :echo sort(extend(mylist, [7, 5]))
2581 :call extend(mylist, [2, 3], 1)
2582< When {expr1} is the same List as {expr2} then the number of
2583 items copied is equal to the original length of the List.
2584 E.g., when {expr3} is 1 you get N new copies of the first item
2585 (where N is the original length of the List).
2586 Use |add()| to concatenate one item to a list. To concatenate
2587 two lists into a new list use the + operator: >
2588 :let newlist = [1, 2, 3] + [4, 5]
2589<
2590 If they are |Dictionaries|:
2591 Add all entries from {expr2} to {expr1}.
2592 If a key exists in both {expr1} and {expr2} then {expr3} is
2593 used to decide what to do:
2594 {expr3} = "keep": keep the value of {expr1}
2595 {expr3} = "force": use the value of {expr2}
2596 {expr3} = "error": give an error message *E737*
2597 When {expr3} is omitted then "force" is assumed.
2598
2599 {expr1} is changed when {expr2} is not empty. If necessary
2600 make a copy of {expr1} first.
2601 {expr2} remains unchanged.
2602 When {expr1} is locked and {expr2} is not empty the operation
2603 fails.
Bram Moolenaar016188f2022-06-06 20:52:59 +01002604 Returns {expr1}. Returns 0 on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002605
2606 Can also be used as a |method|: >
2607 mylist->extend(otherlist)
2608
2609
2610extendnew({expr1}, {expr2} [, {expr3}]) *extendnew()*
2611 Like |extend()| but instead of adding items to {expr1} a new
2612 List or Dictionary is created and returned. {expr1} remains
Bram Moolenaardd60c362023-02-27 15:49:53 +00002613 unchanged.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002614
2615
2616feedkeys({string} [, {mode}]) *feedkeys()*
2617 Characters in {string} are queued for processing as if they
2618 come from a mapping or were typed by the user.
2619
2620 By default the string is added to the end of the typeahead
2621 buffer, thus if a mapping is still being executed the
2622 characters come after them. Use the 'i' flag to insert before
2623 other characters, they will be executed next, before any
2624 characters from a mapping.
2625
2626 The function does not wait for processing of keys contained in
2627 {string}.
2628
2629 To include special keys into {string}, use double-quotes
2630 and "\..." notation |expr-quote|. For example,
2631 feedkeys("\<CR>") simulates pressing of the <Enter> key. But
2632 feedkeys('\<CR>') pushes 5 characters.
2633 A special code that might be useful is <Ignore>, it exits the
2634 wait for a character without doing anything. *<Ignore>*
2635
2636 {mode} is a String, which can contain these character flags:
2637 'm' Remap keys. This is default. If {mode} is absent,
2638 keys are remapped.
2639 'n' Do not remap keys.
2640 't' Handle keys as if typed; otherwise they are handled as
2641 if coming from a mapping. This matters for undo,
2642 opening folds, etc.
2643 'L' Lowlevel input. Only works for Unix or when using the
2644 GUI. Keys are used as if they were coming from the
2645 terminal. Other flags are not used. *E980*
2646 When a CTRL-C interrupts and 't' is included it sets
2647 the internal "got_int" flag.
2648 'i' Insert the string instead of appending (see above).
2649 'x' Execute commands until typeahead is empty. This is
2650 similar to using ":normal!". You can call feedkeys()
2651 several times without 'x' and then one time with 'x'
2652 (possibly with an empty {string}) to execute all the
2653 typeahead. Note that when Vim ends in Insert mode it
2654 will behave as if <Esc> is typed, to avoid getting
2655 stuck, waiting for a character to be typed before the
2656 script continues.
2657 Note that if you manage to call feedkeys() while
2658 executing commands, thus calling it recursively, then
2659 all typeahead will be consumed by the last call.
Bram Moolenaara9725222022-01-16 13:30:33 +00002660 'c' Remove any script context when executing, so that
2661 legacy script syntax applies, "s:var" does not work,
Bram Moolenaard899e512022-05-07 21:54:03 +01002662 etc. Note that if the string being fed sets a script
Bram Moolenaarce001a32022-04-27 15:25:03 +01002663 context this still applies.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002664 '!' When used with 'x' will not end Insert mode. Can be
2665 used in a test when a timer is set to exit Insert mode
2666 a little later. Useful for testing CursorHoldI.
2667
2668 Return value is always 0.
2669
2670 Can also be used as a |method|: >
2671 GetInput()->feedkeys()
2672
2673filereadable({file}) *filereadable()*
2674 The result is a Number, which is |TRUE| when a file with the
2675 name {file} exists, and can be read. If {file} doesn't exist,
2676 or is a directory, the result is |FALSE|. {file} is any
2677 expression, which is used as a String.
2678 If you don't care about the file being readable you can use
2679 |glob()|.
2680 {file} is used as-is, you may want to expand wildcards first: >
2681 echo filereadable('~/.vimrc')
2682 0
2683 echo filereadable(expand('~/.vimrc'))
2684 1
2685
2686< Can also be used as a |method|: >
2687 GetName()->filereadable()
2688< *file_readable()*
2689 Obsolete name: file_readable().
2690
2691
2692filewritable({file}) *filewritable()*
2693 The result is a Number, which is 1 when a file with the
2694 name {file} exists, and can be written. If {file} doesn't
2695 exist, or is not writable, the result is 0. If {file} is a
2696 directory, and we can write to it, the result is 2.
2697
2698 Can also be used as a |method|: >
2699 GetName()->filewritable()
2700
2701
2702filter({expr1}, {expr2}) *filter()*
2703 {expr1} must be a |List|, |String|, |Blob| or |Dictionary|.
2704 For each item in {expr1} evaluate {expr2} and when the result
2705 is zero or false remove the item from the |List| or
2706 |Dictionary|. Similarly for each byte in a |Blob| and each
Bram Moolenaar2f0936c2022-01-08 21:51:59 +00002707 character in a |String|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002708
2709 {expr2} must be a |string| or |Funcref|.
2710
2711 If {expr2} is a |string|, inside {expr2} |v:val| has the value
2712 of the current item. For a |Dictionary| |v:key| has the key
2713 of the current item and for a |List| |v:key| has the index of
2714 the current item. For a |Blob| |v:key| has the index of the
2715 current byte. For a |String| |v:key| has the index of the
2716 current character.
2717 Examples: >
2718 call filter(mylist, 'v:val !~ "OLD"')
2719< Removes the items where "OLD" appears. >
2720 call filter(mydict, 'v:key >= 8')
2721< Removes the items with a key below 8. >
2722 call filter(var, 0)
2723< Removes all the items, thus clears the |List| or |Dictionary|.
2724
2725 Note that {expr2} is the result of expression and is then
2726 used as an expression again. Often it is good to use a
2727 |literal-string| to avoid having to double backslashes.
2728
2729 If {expr2} is a |Funcref| it must take two arguments:
2730 1. the key or the index of the current item.
2731 2. the value of the current item.
2732 The function must return |TRUE| if the item should be kept.
2733 Example that keeps the odd items of a list: >
2734 func Odd(idx, val)
2735 return a:idx % 2 == 1
2736 endfunc
2737 call filter(mylist, function('Odd'))
Bram Moolenaar2f0936c2022-01-08 21:51:59 +00002738< It is shorter when using a |lambda|. In |Vim9| syntax: >
2739 call filter(myList, (idx, val) => idx * val <= 42)
2740< In legacy script syntax: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002741 call filter(myList, {idx, val -> idx * val <= 42})
2742< If you do not use "val" you can leave it out: >
2743 call filter(myList, {idx -> idx % 2 == 1})
2744<
2745 In |Vim9| script the result must be true, false, zero or one.
2746 Other values will result in a type error.
2747
2748 For a |List| and a |Dictionary| the operation is done
2749 in-place. If you want it to remain unmodified make a copy
2750 first: >
2751 :let l = filter(copy(mylist), 'v:val =~ "KEEP"')
2752
2753< Returns {expr1}, the |List| or |Dictionary| that was filtered,
naohiro ono56200ee2022-01-01 14:59:44 +00002754 or a new |Blob| or |String|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002755 When an error is encountered while evaluating {expr2} no
2756 further items in {expr1} are processed.
2757 When {expr2} is a Funcref errors inside a function are ignored,
2758 unless it was defined with the "abort" flag.
2759
2760 Can also be used as a |method|: >
2761 mylist->filter(expr2)
2762
2763finddir({name} [, {path} [, {count}]]) *finddir()*
2764 Find directory {name} in {path}. Supports both downwards and
2765 upwards recursive directory searches. See |file-searching|
2766 for the syntax of {path}.
2767
2768 Returns the path of the first found match. When the found
2769 directory is below the current directory a relative path is
2770 returned. Otherwise a full path is returned.
2771 If {path} is omitted or empty then 'path' is used.
2772
2773 If the optional {count} is given, find {count}'s occurrence of
2774 {name} in {path} instead of the first one.
2775 When {count} is negative return all the matches in a |List|.
2776
Bram Moolenaar016188f2022-06-06 20:52:59 +01002777 Returns an empty string if the directory is not found.
2778
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002779 This is quite similar to the ex-command `:find`.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002780
2781 Can also be used as a |method|: >
2782 GetName()->finddir()
2783
2784findfile({name} [, {path} [, {count}]]) *findfile()*
2785 Just like |finddir()|, but find a file instead of a directory.
2786 Uses 'suffixesadd'.
2787 Example: >
2788 :echo findfile("tags.vim", ".;")
2789< Searches from the directory of the current file upwards until
2790 it finds the file "tags.vim".
2791
2792 Can also be used as a |method|: >
2793 GetName()->findfile()
2794
2795flatten({list} [, {maxdepth}]) *flatten()*
2796 Flatten {list} up to {maxdepth} levels. Without {maxdepth}
2797 the result is a |List| without nesting, as if {maxdepth} is
2798 a very large number.
2799 The {list} is changed in place, use |flattennew()| if you do
2800 not want that.
2801 In Vim9 script flatten() cannot be used, you must always use
Bram Moolenaara2baa732022-02-04 16:09:54 +00002802 |flattennew()|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002803 *E900*
2804 {maxdepth} means how deep in nested lists changes are made.
2805 {list} is not modified when {maxdepth} is 0.
2806 {maxdepth} must be positive number.
2807
2808 If there is an error the number zero is returned.
2809
2810 Example: >
2811 :echo flatten([1, [2, [3, 4]], 5])
2812< [1, 2, 3, 4, 5] >
2813 :echo flatten([1, [2, [3, 4]], 5], 1)
2814< [1, 2, [3, 4], 5]
2815
2816 Can also be used as a |method|: >
2817 mylist->flatten()
2818<
2819flattennew({list} [, {maxdepth}]) *flattennew()*
2820 Like |flatten()| but first make a copy of {list}.
2821
2822
2823float2nr({expr}) *float2nr()*
2824 Convert {expr} to a Number by omitting the part after the
2825 decimal point.
Bram Moolenaar76db9e02022-11-09 21:21:04 +00002826 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar016188f2022-06-06 20:52:59 +01002827 Returns 0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002828 When the value of {expr} is out of range for a |Number| the
2829 result is truncated to 0x7fffffff or -0x7fffffff (or when
2830 64-bit Number support is enabled, 0x7fffffffffffffff or
2831 -0x7fffffffffffffff). NaN results in -0x80000000 (or when
2832 64-bit Number support is enabled, -0x8000000000000000).
2833 Examples: >
2834 echo float2nr(3.95)
2835< 3 >
2836 echo float2nr(-23.45)
2837< -23 >
2838 echo float2nr(1.0e100)
2839< 2147483647 (or 9223372036854775807) >
2840 echo float2nr(-1.0e150)
2841< -2147483647 (or -9223372036854775807) >
2842 echo float2nr(1.0e-100)
2843< 0
2844
2845 Can also be used as a |method|: >
2846 Compute()->float2nr()
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002847
2848
2849floor({expr}) *floor()*
2850 Return the largest integral value less than or equal to
2851 {expr} as a |Float| (round down).
2852 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar016188f2022-06-06 20:52:59 +01002853 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002854 Examples: >
2855 echo floor(1.856)
2856< 1.0 >
2857 echo floor(-5.456)
2858< -6.0 >
2859 echo floor(4.0)
2860< 4.0
2861
2862 Can also be used as a |method|: >
2863 Compute()->floor()
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002864
2865
2866fmod({expr1}, {expr2}) *fmod()*
2867 Return the remainder of {expr1} / {expr2}, even if the
2868 division is not representable. Returns {expr1} - i * {expr2}
2869 for some integer i such that if {expr2} is non-zero, the
2870 result has the same sign as {expr1} and magnitude less than
2871 the magnitude of {expr2}. If {expr2} is zero, the value
2872 returned is zero. The value returned is a |Float|.
2873 {expr1} and {expr2} must evaluate to a |Float| or a |Number|.
Bram Moolenaar016188f2022-06-06 20:52:59 +01002874 Returns 0.0 if {expr1} or {expr2} is not a |Float| or a
2875 |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002876 Examples: >
2877 :echo fmod(12.33, 1.22)
2878< 0.13 >
2879 :echo fmod(-12.33, 1.22)
2880< -0.13
2881
2882 Can also be used as a |method|: >
2883 Compute()->fmod(1.22)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002884
2885
2886fnameescape({string}) *fnameescape()*
2887 Escape {string} for use as file name command argument. All
2888 characters that have a special meaning, such as '%' and '|'
2889 are escaped with a backslash.
2890 For most systems the characters escaped are
2891 " \t\n*?[{`$\\%#'\"|!<". For systems where a backslash
2892 appears in a filename, it depends on the value of 'isfname'.
2893 A leading '+' and '>' is also escaped (special after |:edit|
2894 and |:write|). And a "-" by itself (special after |:cd|).
Bram Moolenaar016188f2022-06-06 20:52:59 +01002895 Returns an empty string on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002896 Example: >
2897 :let fname = '+some str%nge|name'
Bram Moolenaarc51cf032022-02-26 12:25:45 +00002898 :exe "edit " .. fnameescape(fname)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002899< results in executing: >
2900 edit \+some\ str\%nge\|name
2901<
2902 Can also be used as a |method|: >
2903 GetName()->fnameescape()
2904
2905fnamemodify({fname}, {mods}) *fnamemodify()*
2906 Modify file name {fname} according to {mods}. {mods} is a
2907 string of characters like it is used for file names on the
2908 command line. See |filename-modifiers|.
2909 Example: >
2910 :echo fnamemodify("main.c", ":p:h")
2911< results in: >
Bram Moolenaard799daa2022-06-20 11:17:32 +01002912 /home/user/vim/vim/src
Bram Moolenaar016188f2022-06-06 20:52:59 +01002913< If {mods} is empty or an unsupported modifier is used then
2914 {fname} is returned.
Bram Moolenaar5ed11532022-07-06 13:18:11 +01002915 When {fname} is empty then with {mods} ":h" returns ".", so
2916 that `:cd` can be used with it. This is different from
2917 expand('%:h') without a buffer name, which returns an empty
2918 string.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002919 Note: Environment variables don't work in {fname}, use
2920 |expand()| first then.
2921
2922 Can also be used as a |method|: >
2923 GetName()->fnamemodify(':p:h')
2924
2925foldclosed({lnum}) *foldclosed()*
2926 The result is a Number. If the line {lnum} is in a closed
2927 fold, the result is the number of the first line in that fold.
2928 If the line {lnum} is not in a closed fold, -1 is returned.
2929 {lnum} is used like with |getline()|. Thus "." is the current
2930 line, "'m" mark m, etc.
2931
2932 Can also be used as a |method|: >
2933 GetLnum()->foldclosed()
2934
2935foldclosedend({lnum}) *foldclosedend()*
2936 The result is a Number. If the line {lnum} is in a closed
2937 fold, the result is the number of the last line in that fold.
2938 If the line {lnum} is not in a closed fold, -1 is returned.
2939 {lnum} is used like with |getline()|. Thus "." is the current
2940 line, "'m" mark m, etc.
2941
2942 Can also be used as a |method|: >
2943 GetLnum()->foldclosedend()
2944
2945foldlevel({lnum}) *foldlevel()*
2946 The result is a Number, which is the foldlevel of line {lnum}
2947 in the current buffer. For nested folds the deepest level is
2948 returned. If there is no fold at line {lnum}, zero is
2949 returned. It doesn't matter if the folds are open or closed.
2950 When used while updating folds (from 'foldexpr') -1 is
2951 returned for lines where folds are still to be updated and the
2952 foldlevel is unknown. As a special case the level of the
2953 previous line is usually available.
2954 {lnum} is used like with |getline()|. Thus "." is the current
2955 line, "'m" mark m, etc.
2956
2957 Can also be used as a |method|: >
2958 GetLnum()->foldlevel()
2959<
2960 *foldtext()*
2961foldtext() Returns a String, to be displayed for a closed fold. This is
2962 the default function used for the 'foldtext' option and should
2963 only be called from evaluating 'foldtext'. It uses the
2964 |v:foldstart|, |v:foldend| and |v:folddashes| variables.
2965 The returned string looks like this: >
2966 +-- 45 lines: abcdef
2967< The number of leading dashes depends on the foldlevel. The
2968 "45" is the number of lines in the fold. "abcdef" is the text
2969 in the first non-blank line of the fold. Leading white space,
2970 "//" or "/*" and the text from the 'foldmarker' and
2971 'commentstring' options is removed.
2972 When used to draw the actual foldtext, the rest of the line
2973 will be filled with the fold char from the 'fillchars'
2974 setting.
Bram Moolenaar016188f2022-06-06 20:52:59 +01002975 Returns an empty string when there is no fold.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002976 {not available when compiled without the |+folding| feature}
2977
2978foldtextresult({lnum}) *foldtextresult()*
2979 Returns the text that is displayed for the closed fold at line
2980 {lnum}. Evaluates 'foldtext' in the appropriate context.
2981 When there is no closed fold at {lnum} an empty string is
2982 returned.
2983 {lnum} is used like with |getline()|. Thus "." is the current
2984 line, "'m" mark m, etc.
2985 Useful when exporting folded text, e.g., to HTML.
2986 {not available when compiled without the |+folding| feature}
2987
2988
2989 Can also be used as a |method|: >
2990 GetLnum()->foldtextresult()
2991<
2992 *foreground()*
2993foreground() Move the Vim window to the foreground. Useful when sent from
2994 a client to a Vim server. |remote_send()|
2995 On Win32 systems this might not work, the OS does not always
2996 allow a window to bring itself to the foreground. Use
2997 |remote_foreground()| instead.
Bram Moolenaarcbaff5e2022-04-08 17:45:08 +01002998 {only in the Win32, Motif and GTK GUI versions and the
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002999 Win32 console version}
3000
Bram Moolenaaraa534142022-09-15 21:46:02 +01003001fullcommand({name} [, {vim9}]) *fullcommand()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003002 Get the full command name from a short abbreviated command
3003 name; see |20.2| for details on command abbreviations.
3004
3005 The string argument {name} may start with a `:` and can
3006 include a [range], these are skipped and not returned.
Bram Moolenaaraa534142022-09-15 21:46:02 +01003007 Returns an empty string if a command doesn't exist, if it's
3008 ambiguous (for user-defined commands) or cannot be shortened
3009 this way. |vim9-no-shorten|
3010
3011 Without the {vim9} argument uses the current script version.
3012 If {vim9} is present and FALSE then legacy script rules are
3013 used. When {vim9} is present and TRUE then Vim9 rules are
3014 used, e.g. "en" is not a short form of "endif".
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003015
3016 For example `fullcommand('s')`, `fullcommand('sub')`,
3017 `fullcommand(':%substitute')` all return "substitute".
3018
3019 Can also be used as a |method|: >
3020 GetName()->fullcommand()
3021<
3022 *funcref()*
3023funcref({name} [, {arglist}] [, {dict}])
3024 Just like |function()|, but the returned Funcref will lookup
3025 the function by reference, not by name. This matters when the
3026 function {name} is redefined later.
3027
3028 Unlike |function()|, {name} must be an existing user function.
Bram Moolenaar2f0936c2022-01-08 21:51:59 +00003029 It only works for an autoloaded function if it has already
3030 been loaded (to avoid mistakenly loading the autoload script
3031 when only intending to use the function name, use |function()|
3032 instead). {name} cannot be a builtin function.
Bram Moolenaar016188f2022-06-06 20:52:59 +01003033 Returns 0 on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003034
3035 Can also be used as a |method|: >
3036 GetFuncname()->funcref([arg])
3037<
Dominique Pellee764d1b2023-03-12 21:20:59 +00003038 *function()* *partial* *E700* *E923*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003039function({name} [, {arglist}] [, {dict}])
3040 Return a |Funcref| variable that refers to function {name}.
3041 {name} can be the name of a user defined function or an
3042 internal function.
3043
3044 {name} can also be a Funcref or a partial. When it is a
3045 partial the dict stored in it will be used and the {dict}
3046 argument is not allowed. E.g.: >
3047 let FuncWithArg = function(dict.Func, [arg])
3048 let Broken = function(dict.Func, [arg], dict)
3049<
3050 When using the Funcref the function will be found by {name},
3051 also when it was redefined later. Use |funcref()| to keep the
3052 same function.
3053
3054 When {arglist} or {dict} is present this creates a partial.
3055 That means the argument list and/or the dictionary is stored in
3056 the Funcref and will be used when the Funcref is called.
3057
3058 The arguments are passed to the function in front of other
3059 arguments, but after any argument from |method|. Example: >
3060 func Callback(arg1, arg2, name)
3061 ...
3062 let Partial = function('Callback', ['one', 'two'])
3063 ...
3064 call Partial('name')
3065< Invokes the function as with: >
3066 call Callback('one', 'two', 'name')
3067
3068< With a |method|: >
3069 func Callback(one, two, three)
3070 ...
3071 let Partial = function('Callback', ['two'])
3072 ...
3073 eval 'one'->Partial('three')
3074< Invokes the function as with: >
3075 call Callback('one', 'two', 'three')
3076
3077< The function() call can be nested to add more arguments to the
3078 Funcref. The extra arguments are appended to the list of
3079 arguments. Example: >
3080 func Callback(arg1, arg2, name)
Bram Moolenaar0daafaa2022-09-04 17:45:43 +01003081 "...
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003082 let Func = function('Callback', ['one'])
3083 let Func2 = function(Func, ['two'])
Bram Moolenaar0daafaa2022-09-04 17:45:43 +01003084 "...
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003085 call Func2('name')
3086< Invokes the function as with: >
3087 call Callback('one', 'two', 'name')
3088
3089< The Dictionary is only useful when calling a "dict" function.
3090 In that case the {dict} is passed in as "self". Example: >
3091 function Callback() dict
Bram Moolenaarc51cf032022-02-26 12:25:45 +00003092 echo "called for " .. self.name
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003093 endfunction
Bram Moolenaar0daafaa2022-09-04 17:45:43 +01003094 "...
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003095 let context = {"name": "example"}
3096 let Func = function('Callback', context)
Bram Moolenaar0daafaa2022-09-04 17:45:43 +01003097 "...
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003098 call Func() " will echo: called for example
3099< The use of function() is not needed when there are no extra
Bram Moolenaar0daafaa2022-09-04 17:45:43 +01003100 arguments, these two are equivalent, if Callback() is defined
3101 as context.Callback(): >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003102 let Func = function('Callback', context)
3103 let Func = context.Callback
3104
3105< The argument list and the Dictionary can be combined: >
3106 function Callback(arg1, count) dict
Bram Moolenaar0daafaa2022-09-04 17:45:43 +01003107 "...
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003108 let context = {"name": "example"}
3109 let Func = function('Callback', ['one'], context)
Bram Moolenaar0daafaa2022-09-04 17:45:43 +01003110 "...
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003111 call Func(500)
3112< Invokes the function as with: >
3113 call context.Callback('one', 500)
3114<
Bram Moolenaar016188f2022-06-06 20:52:59 +01003115 Returns 0 on error.
3116
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003117 Can also be used as a |method|: >
3118 GetFuncname()->function([arg])
3119
3120
3121garbagecollect([{atexit}]) *garbagecollect()*
3122 Cleanup unused |Lists|, |Dictionaries|, |Channels| and |Jobs|
3123 that have circular references.
3124
3125 There is hardly ever a need to invoke this function, as it is
3126 automatically done when Vim runs out of memory or is waiting
3127 for the user to press a key after 'updatetime'. Items without
3128 circular references are always freed when they become unused.
3129 This is useful if you have deleted a very big |List| and/or
3130 |Dictionary| with circular references in a script that runs
3131 for a long time.
3132
3133 When the optional {atexit} argument is one, garbage
3134 collection will also be done when exiting Vim, if it wasn't
3135 done before. This is useful when checking for memory leaks.
3136
3137 The garbage collection is not done immediately but only when
3138 it's safe to perform. This is when waiting for the user to
3139 type a character. To force garbage collection immediately use
3140 |test_garbagecollect_now()|.
3141
3142get({list}, {idx} [, {default}]) *get()*
3143 Get item {idx} from |List| {list}. When this item is not
3144 available return {default}. Return zero when {default} is
3145 omitted.
3146 Preferably used as a |method|: >
3147 mylist->get(idx)
3148get({blob}, {idx} [, {default}])
3149 Get byte {idx} from |Blob| {blob}. When this byte is not
3150 available return {default}. Return -1 when {default} is
3151 omitted.
3152 Preferably used as a |method|: >
3153 myblob->get(idx)
3154get({dict}, {key} [, {default}])
3155 Get item with key {key} from |Dictionary| {dict}. When this
3156 item is not available return {default}. Return zero when
3157 {default} is omitted. Useful example: >
3158 let val = get(g:, 'var_name', 'default')
3159< This gets the value of g:var_name if it exists, and uses
3160 'default' when it does not exist.
3161 Preferably used as a |method|: >
3162 mydict->get(key)
3163get({func}, {what})
Bram Moolenaar6f4754b2022-01-23 12:07:04 +00003164 Get item {what} from Funcref {func}. Possible values for
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003165 {what} are:
3166 "name" The function name
3167 "func" The function
3168 "dict" The dictionary
3169 "args" The list with arguments
Bram Moolenaar016188f2022-06-06 20:52:59 +01003170 Returns zero on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003171 Preferably used as a |method|: >
3172 myfunc->get(what)
3173<
3174 *getbufinfo()*
3175getbufinfo([{buf}])
3176getbufinfo([{dict}])
3177 Get information about buffers as a List of Dictionaries.
3178
3179 Without an argument information about all the buffers is
3180 returned.
3181
3182 When the argument is a |Dictionary| only the buffers matching
3183 the specified criteria are returned. The following keys can
3184 be specified in {dict}:
3185 buflisted include only listed buffers.
3186 bufloaded include only loaded buffers.
3187 bufmodified include only modified buffers.
3188
3189 Otherwise, {buf} specifies a particular buffer to return
3190 information for. For the use of {buf}, see |bufname()|
3191 above. If the buffer is found the returned List has one item.
3192 Otherwise the result is an empty list.
3193
3194 Each returned List item is a dictionary with the following
3195 entries:
3196 bufnr Buffer number.
3197 changed TRUE if the buffer is modified.
3198 changedtick Number of changes made to the buffer.
3199 hidden TRUE if the buffer is hidden.
3200 lastused Timestamp in seconds, like
3201 |localtime()|, when the buffer was
3202 last used.
3203 {only with the |+viminfo| feature}
3204 listed TRUE if the buffer is listed.
3205 lnum Line number used for the buffer when
3206 opened in the current window.
3207 Only valid if the buffer has been
3208 displayed in the window in the past.
3209 If you want the line number of the
3210 last known cursor position in a given
3211 window, use |line()|: >
3212 :echo line('.', {winid})
3213<
3214 linecount Number of lines in the buffer (only
3215 valid when loaded)
3216 loaded TRUE if the buffer is loaded.
3217 name Full path to the file in the buffer.
3218 signs List of signs placed in the buffer.
3219 Each list item is a dictionary with
3220 the following fields:
3221 id sign identifier
3222 lnum line number
3223 name sign name
3224 variables A reference to the dictionary with
3225 buffer-local variables.
3226 windows List of |window-ID|s that display this
3227 buffer
3228 popups List of popup |window-ID|s that
3229 display this buffer
3230
3231 Examples: >
3232 for buf in getbufinfo()
3233 echo buf.name
3234 endfor
3235 for buf in getbufinfo({'buflisted':1})
3236 if buf.changed
3237 ....
3238 endif
3239 endfor
3240<
3241 To get buffer-local options use: >
3242 getbufvar({bufnr}, '&option_name')
3243<
3244 Can also be used as a |method|: >
3245 GetBufnr()->getbufinfo()
3246<
3247
3248 *getbufline()*
3249getbufline({buf}, {lnum} [, {end}])
3250 Return a |List| with the lines starting from {lnum} to {end}
3251 (inclusive) in the buffer {buf}. If {end} is omitted, a
Bram Moolenaarce30ccc2022-11-21 19:57:04 +00003252 |List| with only the line {lnum} is returned. See
3253 `getbufoneline()` for only getting the line.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003254
3255 For the use of {buf}, see |bufname()| above.
3256
3257 For {lnum} and {end} "$" can be used for the last line of the
3258 buffer. Otherwise a number must be used.
3259
3260 When {lnum} is smaller than 1 or bigger than the number of
3261 lines in the buffer, an empty |List| is returned.
3262
3263 When {end} is greater than the number of lines in the buffer,
3264 it is treated as {end} is set to the number of lines in the
3265 buffer. When {end} is before {lnum} an empty |List| is
3266 returned.
3267
3268 This function works only for loaded buffers. For unloaded and
3269 non-existing buffers, an empty |List| is returned.
3270
3271 Example: >
3272 :let lines = getbufline(bufnr("myfile"), 1, "$")
3273
3274< Can also be used as a |method|: >
3275 GetBufnr()->getbufline(lnum)
Bram Moolenaarce30ccc2022-11-21 19:57:04 +00003276<
3277 *getbufoneline()*
3278getbufoneline({buf}, {lnum})
3279 Just like `getbufline()` but only get one line and return it
3280 as a string.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003281
3282getbufvar({buf}, {varname} [, {def}]) *getbufvar()*
3283 The result is the value of option or local buffer variable
3284 {varname} in buffer {buf}. Note that the name without "b:"
3285 must be used.
3286 The {varname} argument is a string.
3287 When {varname} is empty returns a |Dictionary| with all the
3288 buffer-local variables.
3289 When {varname} is equal to "&" returns a |Dictionary| with all
3290 the buffer-local options.
3291 Otherwise, when {varname} starts with "&" returns the value of
3292 a buffer-local option.
3293 This also works for a global or buffer-local option, but it
3294 doesn't work for a global variable, window-local variable or
3295 window-local option.
3296 For the use of {buf}, see |bufname()| above.
3297 When the buffer or variable doesn't exist {def} or an empty
3298 string is returned, there is no error message.
3299 Examples: >
3300 :let bufmodified = getbufvar(1, "&mod")
Bram Moolenaarc51cf032022-02-26 12:25:45 +00003301 :echo "todo myvar = " .. getbufvar("todo", "myvar")
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003302
3303< Can also be used as a |method|: >
3304 GetBufnr()->getbufvar(varname)
3305<
Kota Kato66bb9ae2023-01-17 18:31:56 +00003306getcellwidths() *getcellwidths()*
3307 Returns a |List| of cell widths of character ranges overridden
3308 by |setcellwidths()|. The format is equal to the argument of
3309 |setcellwidths()|. If no character ranges have their cell
3310 widths overridden, an empty List is returned.
3311
3312
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003313getchangelist([{buf}]) *getchangelist()*
3314 Returns the |changelist| for the buffer {buf}. For the use
3315 of {buf}, see |bufname()| above. If buffer {buf} doesn't
3316 exist, an empty list is returned.
3317
3318 The returned list contains two entries: a list with the change
3319 locations and the current position in the list. Each
3320 entry in the change list is a dictionary with the following
3321 entries:
3322 col column number
3323 coladd column offset for 'virtualedit'
3324 lnum line number
3325 If buffer {buf} is the current buffer, then the current
3326 position refers to the position in the list. For other
3327 buffers, it is set to the length of the list.
3328
3329 Can also be used as a |method|: >
3330 GetBufnr()->getchangelist()
3331
3332getchar([expr]) *getchar()*
3333 Get a single character from the user or input stream.
3334 If [expr] is omitted, wait until a character is available.
3335 If [expr] is 0, only get a character when one is available.
3336 Return zero otherwise.
3337 If [expr] is 1, only check if a character is available, it is
3338 not consumed. Return zero if no character available.
3339 If you prefer always getting a string use |getcharstr()|.
3340
3341 Without [expr] and when [expr] is 0 a whole character or
3342 special key is returned. If it is a single character, the
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01003343 result is a Number. Use |nr2char()| to convert it to a String.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003344 Otherwise a String is returned with the encoded character.
3345 For a special key it's a String with a sequence of bytes
3346 starting with 0x80 (decimal: 128). This is the same value as
3347 the String "\<Key>", e.g., "\<Left>". The returned value is
3348 also a String when a modifier (shift, control, alt) was used
3349 that is not included in the character.
3350
3351 When [expr] is 0 and Esc is typed, there will be a short delay
3352 while Vim waits to see if this is the start of an escape
3353 sequence.
3354
3355 When [expr] is 1 only the first byte is returned. For a
3356 one-byte character it is the character itself as a number.
3357 Use nr2char() to convert it to a String.
3358
3359 Use getcharmod() to obtain any additional modifiers.
3360
3361 When the user clicks a mouse button, the mouse event will be
3362 returned. The position can then be found in |v:mouse_col|,
3363 |v:mouse_lnum|, |v:mouse_winid| and |v:mouse_win|.
3364 |getmousepos()| can also be used. Mouse move events will be
3365 ignored.
3366 This example positions the mouse as it would normally happen: >
3367 let c = getchar()
3368 if c == "\<LeftMouse>" && v:mouse_win > 0
Bram Moolenaarc51cf032022-02-26 12:25:45 +00003369 exe v:mouse_win .. "wincmd w"
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003370 exe v:mouse_lnum
Bram Moolenaarc51cf032022-02-26 12:25:45 +00003371 exe "normal " .. v:mouse_col .. "|"
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003372 endif
3373<
3374 When using bracketed paste only the first character is
3375 returned, the rest of the pasted text is dropped.
3376 |xterm-bracketed-paste|.
3377
3378 There is no prompt, you will somehow have to make clear to the
3379 user that a character has to be typed. The screen is not
3380 redrawn, e.g. when resizing the window. When using a popup
3381 window it should work better with a |popup-filter|.
3382
3383 There is no mapping for the character.
3384 Key codes are replaced, thus when the user presses the <Del>
3385 key you get the code for the <Del> key, not the raw character
3386 sequence. Examples: >
3387 getchar() == "\<Del>"
3388 getchar() == "\<S-Left>"
3389< This example redefines "f" to ignore case: >
3390 :nmap f :call FindChar()<CR>
3391 :function FindChar()
3392 : let c = nr2char(getchar())
3393 : while col('.') < col('$') - 1
3394 : normal l
3395 : if getline('.')[col('.') - 1] ==? c
3396 : break
3397 : endif
3398 : endwhile
3399 :endfunction
3400<
3401 You may also receive synthetic characters, such as
3402 |<CursorHold>|. Often you will want to ignore this and get
3403 another character: >
3404 :function GetKey()
3405 : let c = getchar()
3406 : while c == "\<CursorHold>"
3407 : let c = getchar()
3408 : endwhile
3409 : return c
3410 :endfunction
3411
3412getcharmod() *getcharmod()*
3413 The result is a Number which is the state of the modifiers for
3414 the last obtained character with getchar() or in another way.
3415 These values are added together:
3416 2 shift
3417 4 control
3418 8 alt (meta)
3419 16 meta (when it's different from ALT)
3420 32 mouse double click
3421 64 mouse triple click
3422 96 mouse quadruple click (== 32 + 64)
3423 128 command (Macintosh only)
3424 Only the modifiers that have not been included in the
3425 character itself are obtained. Thus Shift-a results in "A"
Bram Moolenaar016188f2022-06-06 20:52:59 +01003426 without a modifier. Returns 0 if no modifiers are used.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003427
3428 *getcharpos()*
3429getcharpos({expr})
3430 Get the position for String {expr}. Same as |getpos()| but the
3431 column number in the returned List is a character index
3432 instead of a byte index.
naohiro ono56200ee2022-01-01 14:59:44 +00003433 If |getpos()| returns a very large column number, equal to
3434 |v:maxcol|, then getcharpos() will return the character index
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003435 of the last character.
3436
3437 Example:
3438 With the cursor on '세' in line 5 with text "여보세요": >
3439 getcharpos('.') returns [0, 5, 3, 0]
3440 getpos('.') returns [0, 5, 7, 0]
3441<
3442 Can also be used as a |method|: >
3443 GetMark()->getcharpos()
3444
3445getcharsearch() *getcharsearch()*
3446 Return the current character search information as a {dict}
3447 with the following entries:
3448
3449 char character previously used for a character
3450 search (|t|, |f|, |T|, or |F|); empty string
3451 if no character search has been performed
3452 forward direction of character search; 1 for forward,
3453 0 for backward
3454 until type of character search; 1 for a |t| or |T|
3455 character search, 0 for an |f| or |F|
3456 character search
3457
3458 This can be useful to always have |;| and |,| search
3459 forward/backward regardless of the direction of the previous
3460 character search: >
3461 :nnoremap <expr> ; getcharsearch().forward ? ';' : ','
3462 :nnoremap <expr> , getcharsearch().forward ? ',' : ';'
3463< Also see |setcharsearch()|.
3464
3465
3466getcharstr([expr]) *getcharstr()*
3467 Get a single character from the user or input stream as a
3468 string.
3469 If [expr] is omitted, wait until a character is available.
3470 If [expr] is 0 or false, only get a character when one is
3471 available. Return an empty string otherwise.
3472 If [expr] is 1 or true, only check if a character is
3473 available, it is not consumed. Return an empty string
3474 if no character is available.
3475 Otherwise this works like |getchar()|, except that a number
3476 result is converted to a string.
3477
Shougo Matsushita79d599b2022-05-07 12:48:29 +01003478getcmdcompltype() *getcmdcompltype()*
3479 Return the type of the current command-line completion.
3480 Only works when the command line is being edited, thus
3481 requires use of |c_CTRL-\_e| or |c_CTRL-R_=|.
Bram Moolenaar921bde82022-05-09 19:50:35 +01003482 See |:command-completion| for the return string.
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01003483 Also see |getcmdtype()|, |setcmdpos()|, |getcmdline()| and
3484 |setcmdline()|.
Shougo Matsushita79d599b2022-05-07 12:48:29 +01003485 Returns an empty string when completion is not defined.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003486
3487getcmdline() *getcmdline()*
3488 Return the current command-line. Only works when the command
3489 line is being edited, thus requires use of |c_CTRL-\_e| or
3490 |c_CTRL-R_=|.
3491 Example: >
3492 :cmap <F7> <C-\>eescape(getcmdline(), ' \')<CR>
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01003493< Also see |getcmdtype()|, |getcmdpos()|, |setcmdpos()| and
3494 |setcmdline()|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003495 Returns an empty string when entering a password or using
3496 |inputsecret()|.
3497
3498getcmdpos() *getcmdpos()*
3499 Return the position of the cursor in the command line as a
3500 byte count. The first column is 1.
3501 Only works when editing the command line, thus requires use of
3502 |c_CTRL-\_e| or |c_CTRL-R_=| or an expression mapping.
3503 Returns 0 otherwise.
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01003504 Also see |getcmdtype()|, |setcmdpos()|, |getcmdline()| and
3505 |setcmdline()|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003506
Shougo Matsushita79d599b2022-05-07 12:48:29 +01003507getcmdscreenpos() *getcmdscreenpos()*
3508 Return the screen position of the cursor in the command line
3509 as a byte count. The first column is 1.
3510 Instead of |getcmdpos()|, it adds the prompt position.
3511 Only works when editing the command line, thus requires use of
3512 |c_CTRL-\_e| or |c_CTRL-R_=| or an expression mapping.
3513 Returns 0 otherwise.
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01003514 Also see |getcmdpos()|, |setcmdpos()|, |getcmdline()| and
3515 |setcmdline()|.
Shougo Matsushita79d599b2022-05-07 12:48:29 +01003516
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003517getcmdtype() *getcmdtype()*
3518 Return the current command-line type. Possible return values
3519 are:
3520 : normal Ex command
3521 > debug mode command |debug-mode|
3522 / forward search command
3523 ? backward search command
3524 @ |input()| command
3525 - |:insert| or |:append| command
3526 = |i_CTRL-R_=|
3527 Only works when editing the command line, thus requires use of
3528 |c_CTRL-\_e| or |c_CTRL-R_=| or an expression mapping.
3529 Returns an empty string otherwise.
3530 Also see |getcmdpos()|, |setcmdpos()| and |getcmdline()|.
3531
3532getcmdwintype() *getcmdwintype()*
3533 Return the current |command-line-window| type. Possible return
3534 values are the same as |getcmdtype()|. Returns an empty string
3535 when not in the command-line window.
3536
3537getcompletion({pat}, {type} [, {filtered}]) *getcompletion()*
3538 Return a list of command-line completion matches. The String
3539 {type} argument specifies what for. The following completion
3540 types are supported:
3541
3542 arglist file names in argument list
3543 augroup autocmd groups
3544 buffer buffer names
Bram Moolenaar6e2e2cc2022-03-14 19:24:46 +00003545 behave |:behave| suboptions
3546 breakpoint |:breakadd| and |:breakdel| suboptions
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003547 color color schemes
3548 command Ex command
3549 cmdline |cmdline-completion| result
3550 compiler compilers
3551 cscope |:cscope| suboptions
3552 diff_buffer |:diffget| and |:diffput| completion
3553 dir directory names
3554 environment environment variable names
3555 event autocommand events
3556 expression Vim expression
3557 file file and directory names
3558 file_in_path file and directory names in |'path'|
3559 filetype filetype names |'filetype'|
3560 function function name
3561 help help subjects
3562 highlight highlight groups
Bram Moolenaar6e2e2cc2022-03-14 19:24:46 +00003563 history |:history| suboptions
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003564 locale locale names (as output of locale -a)
3565 mapclear buffer argument
3566 mapping mapping name
3567 menu menus
3568 messages |:messages| suboptions
3569 option options
3570 packadd optional package |pack-add| names
zeertzjq5c8771b2023-01-24 12:34:03 +00003571 runtime |:runtime| completion
Yegappan Lakshmanan454ce672022-03-24 11:22:13 +00003572 scriptnames sourced script names |:scriptnames|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003573 shellcmd Shell command
3574 sign |:sign| suboptions
3575 syntax syntax file names |'syntax'|
3576 syntime |:syntime| suboptions
3577 tag tags
3578 tag_listfiles tags, file names
3579 user user names
3580 var user variables
3581
3582 If {pat} is an empty string, then all the matches are
3583 returned. Otherwise only items matching {pat} are returned.
3584 See |wildcards| for the use of special characters in {pat}.
3585
3586 If the optional {filtered} flag is set to 1, then 'wildignore'
3587 is applied to filter the results. Otherwise all the matches
3588 are returned. The 'wildignorecase' option always applies.
3589
Yegappan Lakshmanane7dd0fa2022-03-22 16:06:31 +00003590 If the 'wildoptions' option contains 'fuzzy', then fuzzy
3591 matching is used to get the completion matches. Otherwise
Yegappan Lakshmanan454ce672022-03-24 11:22:13 +00003592 regular expression matching is used. Thus this function
3593 follows the user preference, what happens on the command line.
3594 If you do not want this you can make 'wildoptions' empty
3595 before calling getcompletion() and restore it afterwards.
Yegappan Lakshmanane7dd0fa2022-03-22 16:06:31 +00003596
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003597 If {type} is "cmdline", then the |cmdline-completion| result is
3598 returned. For example, to complete the possible values after
3599 a ":call" command: >
3600 echo getcompletion('call ', 'cmdline')
3601<
3602 If there are no matches, an empty list is returned. An
3603 invalid value for {type} produces an error.
3604
3605 Can also be used as a |method|: >
3606 GetPattern()->getcompletion('color')
3607<
3608 *getcurpos()*
3609getcurpos([{winid}])
3610 Get the position of the cursor. This is like getpos('.'), but
3611 includes an extra "curswant" item in the list:
3612 [0, lnum, col, off, curswant] ~
3613 The "curswant" number is the preferred column when moving the
naohiro ono56200ee2022-01-01 14:59:44 +00003614 cursor vertically. After |$| command it will be a very large
3615 number equal to |v:maxcol|. Also see |getcursorcharpos()| and
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003616 |getpos()|.
3617 The first "bufnum" item is always zero. The byte position of
3618 the cursor is returned in 'col'. To get the character
3619 position, use |getcursorcharpos()|.
3620
3621 The optional {winid} argument can specify the window. It can
3622 be the window number or the |window-ID|. The last known
3623 cursor position is returned, this may be invalid for the
3624 current value of the buffer if it is not the current window.
3625 If {winid} is invalid a list with zeroes is returned.
3626
3627 This can be used to save and restore the cursor position: >
3628 let save_cursor = getcurpos()
3629 MoveTheCursorAround
3630 call setpos('.', save_cursor)
3631< Note that this only works within the window. See
3632 |winrestview()| for restoring more state.
3633
3634 Can also be used as a |method|: >
3635 GetWinid()->getcurpos()
3636<
3637 *getcursorcharpos()*
3638getcursorcharpos([{winid}])
3639 Same as |getcurpos()| but the column number in the returned
3640 List is a character index instead of a byte index.
3641
3642 Example:
3643 With the cursor on '보' in line 3 with text "여보세요": >
3644 getcursorcharpos() returns [0, 3, 2, 0, 3]
3645 getcurpos() returns [0, 3, 4, 0, 3]
3646<
3647 Can also be used as a |method|: >
3648 GetWinid()->getcursorcharpos()
3649
3650< *getcwd()*
3651getcwd([{winnr} [, {tabnr}]])
3652 The result is a String, which is the name of the current
3653 working directory. 'autochdir' is ignored.
3654
3655 With {winnr} return the local current directory of this window
3656 in the current tab page. {winnr} can be the window number or
3657 the |window-ID|.
3658 If {winnr} is -1 return the name of the global working
3659 directory. See also |haslocaldir()|.
3660
3661 With {winnr} and {tabnr} return the local current directory of
3662 the window in the specified tab page. If {winnr} is -1 return
3663 the working directory of the tabpage.
3664 If {winnr} is zero use the current window, if {tabnr} is zero
3665 use the current tabpage.
3666 Without any arguments, return the actual working directory of
3667 the current window.
3668 Return an empty string if the arguments are invalid.
3669
3670 Examples: >
3671 " Get the working directory of the current window
3672 :echo getcwd()
3673 :echo getcwd(0)
3674 :echo getcwd(0, 0)
3675 " Get the working directory of window 3 in tabpage 2
3676 :echo getcwd(3, 2)
3677 " Get the global working directory
3678 :echo getcwd(-1)
3679 " Get the working directory of tabpage 3
3680 :echo getcwd(-1, 3)
3681 " Get the working directory of current tabpage
3682 :echo getcwd(-1, 0)
3683
3684< Can also be used as a |method|: >
3685 GetWinnr()->getcwd()
3686
3687getenv({name}) *getenv()*
3688 Return the value of environment variable {name}. The {name}
3689 argument is a string, without a leading '$'. Example: >
3690 myHome = getenv('HOME')
3691
3692< When the variable does not exist |v:null| is returned. That
3693 is different from a variable set to an empty string, although
3694 some systems interpret the empty value as the variable being
3695 deleted. See also |expr-env|.
3696
3697 Can also be used as a |method|: >
3698 GetVarname()->getenv()
3699
3700getfontname([{name}]) *getfontname()*
3701 Without an argument returns the name of the normal font being
3702 used. Like what is used for the Normal highlight group
3703 |hl-Normal|.
3704 With an argument a check is done whether String {name} is a
3705 valid font name. If not then an empty string is returned.
3706 Otherwise the actual font name is returned, or {name} if the
3707 GUI does not support obtaining the real name.
3708 Only works when the GUI is running, thus not in your vimrc or
3709 gvimrc file. Use the |GUIEnter| autocommand to use this
3710 function just after the GUI has started.
3711 Note that the GTK GUI accepts any font name, thus checking for
3712 a valid name does not work.
3713
3714getfperm({fname}) *getfperm()*
3715 The result is a String, which is the read, write, and execute
3716 permissions of the given file {fname}.
3717 If {fname} does not exist or its directory cannot be read, an
3718 empty string is returned.
3719 The result is of the form "rwxrwxrwx", where each group of
3720 "rwx" flags represent, in turn, the permissions of the owner
3721 of the file, the group the file belongs to, and other users.
3722 If a user does not have a given permission the flag for this
3723 is replaced with the string "-". Examples: >
3724 :echo getfperm("/etc/passwd")
3725 :echo getfperm(expand("~/.vimrc"))
3726< This will hopefully (from a security point of view) display
3727 the string "rw-r--r--" or even "rw-------".
3728
3729 Can also be used as a |method|: >
3730 GetFilename()->getfperm()
3731<
3732 For setting permissions use |setfperm()|.
3733
3734getfsize({fname}) *getfsize()*
3735 The result is a Number, which is the size in bytes of the
3736 given file {fname}.
3737 If {fname} is a directory, 0 is returned.
3738 If the file {fname} can't be found, -1 is returned.
3739 If the size of {fname} is too big to fit in a Number then -2
3740 is returned.
3741
3742 Can also be used as a |method|: >
3743 GetFilename()->getfsize()
3744
3745getftime({fname}) *getftime()*
3746 The result is a Number, which is the last modification time of
3747 the given file {fname}. The value is measured as seconds
3748 since 1st Jan 1970, and may be passed to strftime(). See also
3749 |localtime()| and |strftime()|.
3750 If the file {fname} can't be found -1 is returned.
3751
3752 Can also be used as a |method|: >
3753 GetFilename()->getftime()
3754
3755getftype({fname}) *getftype()*
3756 The result is a String, which is a description of the kind of
3757 file of the given file {fname}.
3758 If {fname} does not exist an empty string is returned.
3759 Here is a table over different kinds of files and their
3760 results:
3761 Normal file "file"
3762 Directory "dir"
3763 Symbolic link "link"
3764 Block device "bdev"
3765 Character device "cdev"
3766 Socket "socket"
3767 FIFO "fifo"
3768 All other "other"
3769 Example: >
3770 getftype("/home")
3771< Note that a type such as "link" will only be returned on
3772 systems that support it. On some systems only "dir" and
3773 "file" are returned. On MS-Windows a symbolic link to a
3774 directory returns "dir" instead of "link".
3775
3776 Can also be used as a |method|: >
3777 GetFilename()->getftype()
3778
3779getimstatus() *getimstatus()*
3780 The result is a Number, which is |TRUE| when the IME status is
Bram Moolenaar016188f2022-06-06 20:52:59 +01003781 active and |FALSE| otherwise.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003782 See 'imstatusfunc'.
3783
3784getjumplist([{winnr} [, {tabnr}]]) *getjumplist()*
3785 Returns the |jumplist| for the specified window.
3786
3787 Without arguments use the current window.
3788 With {winnr} only use this window in the current tab page.
3789 {winnr} can also be a |window-ID|.
3790 With {winnr} and {tabnr} use the window in the specified tab
Bram Moolenaar016188f2022-06-06 20:52:59 +01003791 page. If {winnr} or {tabnr} is invalid, an empty list is
3792 returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003793
3794 The returned list contains two entries: a list with the jump
3795 locations and the last used jump position number in the list.
3796 Each entry in the jump location list is a dictionary with
3797 the following entries:
3798 bufnr buffer number
3799 col column number
3800 coladd column offset for 'virtualedit'
3801 filename filename if available
3802 lnum line number
3803
3804 Can also be used as a |method|: >
3805 GetWinnr()->getjumplist()
3806
3807< *getline()*
3808getline({lnum} [, {end}])
3809 Without {end} the result is a String, which is line {lnum}
3810 from the current buffer. Example: >
3811 getline(1)
3812< When {lnum} is a String that doesn't start with a
3813 digit, |line()| is called to translate the String into a Number.
3814 To get the line under the cursor: >
3815 getline(".")
3816< When {lnum} is a number smaller than 1 or bigger than the
3817 number of lines in the buffer, an empty string is returned.
3818
3819 When {end} is given the result is a |List| where each item is
3820 a line from the current buffer in the range {lnum} to {end},
3821 including line {end}.
3822 {end} is used in the same way as {lnum}.
3823 Non-existing lines are silently omitted.
3824 When {end} is before {lnum} an empty |List| is returned.
3825 Example: >
3826 :let start = line('.')
3827 :let end = search("^$") - 1
3828 :let lines = getline(start, end)
3829
3830< Can also be used as a |method|: >
3831 ComputeLnum()->getline()
3832
Bram Moolenaarce30ccc2022-11-21 19:57:04 +00003833< To get lines from another buffer see |getbufline()| and
3834 |getbufoneline()|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003835
3836getloclist({nr} [, {what}]) *getloclist()*
3837 Returns a |List| with all the entries in the location list for
3838 window {nr}. {nr} can be the window number or the |window-ID|.
3839 When {nr} is zero the current window is used.
3840
3841 For a location list window, the displayed location list is
3842 returned. For an invalid window number {nr}, an empty list is
3843 returned. Otherwise, same as |getqflist()|.
3844
3845 If the optional {what} dictionary argument is supplied, then
3846 returns the items listed in {what} as a dictionary. Refer to
3847 |getqflist()| for the supported items in {what}.
3848
3849 In addition to the items supported by |getqflist()| in {what},
3850 the following item is supported by |getloclist()|:
3851
3852 filewinid id of the window used to display files
3853 from the location list. This field is
3854 applicable only when called from a
3855 location list window. See
3856 |location-list-file-window| for more
3857 details.
3858
3859 Returns a |Dictionary| with default values if there is no
3860 location list for the window {nr}.
3861 Returns an empty Dictionary if window {nr} does not exist.
3862
3863 Examples (See also |getqflist-examples|): >
3864 :echo getloclist(3, {'all': 0})
3865 :echo getloclist(5, {'filewinid': 0})
3866
3867
3868getmarklist([{buf}]) *getmarklist()*
3869 Without the {buf} argument returns a |List| with information
3870 about all the global marks. |mark|
3871
3872 If the optional {buf} argument is specified, returns the
3873 local marks defined in buffer {buf}. For the use of {buf},
Bram Moolenaar016188f2022-06-06 20:52:59 +01003874 see |bufname()|. If {buf} is invalid, an empty list is
3875 returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003876
3877 Each item in the returned List is a |Dict| with the following:
3878 mark name of the mark prefixed by "'"
3879 pos a |List| with the position of the mark:
3880 [bufnum, lnum, col, off]
3881 Refer to |getpos()| for more information.
3882 file file name
3883
3884 Refer to |getpos()| for getting information about a specific
3885 mark.
3886
3887 Can also be used as a |method|: >
3888 GetBufnr()->getmarklist()
3889
3890getmatches([{win}]) *getmatches()*
3891 Returns a |List| with all matches previously defined for the
3892 current window by |matchadd()| and the |:match| commands.
3893 |getmatches()| is useful in combination with |setmatches()|,
3894 as |setmatches()| can restore a list of matches saved by
3895 |getmatches()|.
3896 If {win} is specified, use the window with this number or
Bram Moolenaar016188f2022-06-06 20:52:59 +01003897 window ID instead of the current window. If {win} is invalid,
3898 an empty list is returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003899 Example: >
3900 :echo getmatches()
3901< [{'group': 'MyGroup1', 'pattern': 'TODO',
3902 'priority': 10, 'id': 1}, {'group': 'MyGroup2',
3903 'pattern': 'FIXME', 'priority': 10, 'id': 2}] >
3904 :let m = getmatches()
3905 :call clearmatches()
3906 :echo getmatches()
3907< [] >
3908 :call setmatches(m)
3909 :echo getmatches()
3910< [{'group': 'MyGroup1', 'pattern': 'TODO',
3911 'priority': 10, 'id': 1}, {'group': 'MyGroup2',
3912 'pattern': 'FIXME', 'priority': 10, 'id': 2}] >
3913 :unlet m
3914<
3915getmousepos() *getmousepos()*
3916 Returns a |Dictionary| with the last known position of the
3917 mouse. This can be used in a mapping for a mouse click or in
3918 a filter of a popup window. The items are:
3919 screenrow screen row
3920 screencol screen column
3921 winid Window ID of the click
3922 winrow row inside "winid"
3923 wincol column inside "winid"
3924 line text line inside "winid"
3925 column text column inside "winid"
3926 All numbers are 1-based.
3927
3928 If not over a window, e.g. when in the command line, then only
3929 "screenrow" and "screencol" are valid, the others are zero.
3930
3931 When on the status line below a window or the vertical
3932 separator right of a window, the "line" and "column" values
3933 are zero.
3934
3935 When the position is after the text then "column" is the
3936 length of the text in bytes plus one.
3937
3938 If the mouse is over a popup window then that window is used.
3939
3940 When using |getchar()| the Vim variables |v:mouse_lnum|,
3941 |v:mouse_col| and |v:mouse_winid| also provide these values.
3942
Bram Moolenaar24dc19c2022-11-14 19:49:15 +00003943getmouseshape() *getmouseshape()*
3944 Returns the name of the currently showing mouse pointer.
3945 When the |+mouseshape| feature is not supported or the shape
3946 is unknown an empty string is returned.
3947 This function is mainly intended for testing.
3948
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003949 *getpid()*
3950getpid() Return a Number which is the process ID of the Vim process.
3951 On Unix and MS-Windows this is a unique number, until Vim
3952 exits.
3953
3954 *getpos()*
3955getpos({expr}) Get the position for String {expr}. For possible values of
3956 {expr} see |line()|. For getting the cursor position see
3957 |getcurpos()|.
3958 The result is a |List| with four numbers:
3959 [bufnum, lnum, col, off]
3960 "bufnum" is zero, unless a mark like '0 or 'A is used, then it
3961 is the buffer number of the mark.
3962 "lnum" and "col" are the position in the buffer. The first
3963 column is 1.
3964 The "off" number is zero, unless 'virtualedit' is used. Then
3965 it is the offset in screen columns from the start of the
3966 character. E.g., a position within a <Tab> or after the last
3967 character.
3968 Note that for '< and '> Visual mode matters: when it is "V"
3969 (visual line mode) the column of '< is zero and the column of
naohiro ono56200ee2022-01-01 14:59:44 +00003970 '> is a large number equal to |v:maxcol|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003971 The column number in the returned List is the byte position
3972 within the line. To get the character position in the line,
3973 use |getcharpos()|.
naohiro ono56200ee2022-01-01 14:59:44 +00003974 A very large column number equal to |v:maxcol| can be returned,
3975 in which case it means "after the end of the line".
Bram Moolenaar016188f2022-06-06 20:52:59 +01003976 If {expr} is invalid, returns a list with all zeros.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003977 This can be used to save and restore the position of a mark: >
3978 let save_a_mark = getpos("'a")
3979 ...
3980 call setpos("'a", save_a_mark)
3981< Also see |getcharpos()|, |getcurpos()| and |setpos()|.
3982
3983 Can also be used as a |method|: >
3984 GetMark()->getpos()
3985
3986getqflist([{what}]) *getqflist()*
3987 Returns a |List| with all the current quickfix errors. Each
3988 list item is a dictionary with these entries:
3989 bufnr number of buffer that has the file name, use
3990 bufname() to get the name
3991 module module name
3992 lnum line number in the buffer (first line is 1)
3993 end_lnum
3994 end of line number if the item is multiline
3995 col column number (first column is 1)
3996 end_col end of column number if the item has range
3997 vcol |TRUE|: "col" is visual column
3998 |FALSE|: "col" is byte index
3999 nr error number
4000 pattern search pattern used to locate the error
4001 text description of the error
4002 type type of the error, 'E', '1', etc.
4003 valid |TRUE|: recognized error message
4004
4005 When there is no error list or it's empty, an empty list is
4006 returned. Quickfix list entries with a non-existing buffer
4007 number are returned with "bufnr" set to zero (Note: some
4008 functions accept buffer number zero for the alternate buffer,
4009 you may need to explicitly check for zero).
4010
4011 Useful application: Find pattern matches in multiple files and
4012 do something with them: >
4013 :vimgrep /theword/jg *.c
4014 :for d in getqflist()
4015 : echo bufname(d.bufnr) ':' d.lnum '=' d.text
4016 :endfor
4017<
4018 If the optional {what} dictionary argument is supplied, then
4019 returns only the items listed in {what} as a dictionary. The
4020 following string items are supported in {what}:
4021 changedtick get the total number of changes made
4022 to the list |quickfix-changedtick|
4023 context get the |quickfix-context|
4024 efm errorformat to use when parsing "lines". If
4025 not present, then the 'errorformat' option
4026 value is used.
4027 id get information for the quickfix list with
4028 |quickfix-ID|; zero means the id for the
4029 current list or the list specified by "nr"
4030 idx get information for the quickfix entry at this
4031 index in the list specified by 'id' or 'nr'.
4032 If set to zero, then uses the current entry.
4033 See |quickfix-index|
4034 items quickfix list entries
4035 lines parse a list of lines using 'efm' and return
4036 the resulting entries. Only a |List| type is
4037 accepted. The current quickfix list is not
4038 modified. See |quickfix-parse|.
4039 nr get information for this quickfix list; zero
4040 means the current quickfix list and "$" means
4041 the last quickfix list
4042 qfbufnr number of the buffer displayed in the quickfix
4043 window. Returns 0 if the quickfix buffer is
4044 not present. See |quickfix-buffer|.
4045 size number of entries in the quickfix list
4046 title get the list title |quickfix-title|
4047 winid get the quickfix |window-ID|
4048 all all of the above quickfix properties
4049 Non-string items in {what} are ignored. To get the value of a
4050 particular item, set it to zero.
4051 If "nr" is not present then the current quickfix list is used.
4052 If both "nr" and a non-zero "id" are specified, then the list
4053 specified by "id" is used.
4054 To get the number of lists in the quickfix stack, set "nr" to
4055 "$" in {what}. The "nr" value in the returned dictionary
4056 contains the quickfix stack size.
4057 When "lines" is specified, all the other items except "efm"
4058 are ignored. The returned dictionary contains the entry
4059 "items" with the list of entries.
4060
4061 The returned dictionary contains the following entries:
4062 changedtick total number of changes made to the
4063 list |quickfix-changedtick|
4064 context quickfix list context. See |quickfix-context|
4065 If not present, set to "".
4066 id quickfix list ID |quickfix-ID|. If not
4067 present, set to 0.
4068 idx index of the quickfix entry in the list. If not
4069 present, set to 0.
4070 items quickfix list entries. If not present, set to
4071 an empty list.
4072 nr quickfix list number. If not present, set to 0
4073 qfbufnr number of the buffer displayed in the quickfix
4074 window. If not present, set to 0.
4075 size number of entries in the quickfix list. If not
4076 present, set to 0.
4077 title quickfix list title text. If not present, set
4078 to "".
4079 winid quickfix |window-ID|. If not present, set to 0
4080
4081 Examples (See also |getqflist-examples|): >
4082 :echo getqflist({'all': 1})
4083 :echo getqflist({'nr': 2, 'title': 1})
4084 :echo getqflist({'lines' : ["F1:10:L10"]})
4085<
4086getreg([{regname} [, 1 [, {list}]]]) *getreg()*
4087 The result is a String, which is the contents of register
4088 {regname}. Example: >
4089 :let cliptext = getreg('*')
4090< When register {regname} was not set the result is an empty
4091 string.
Bram Moolenaara2baa732022-02-04 16:09:54 +00004092 The {regname} argument must be a string. *E1162*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004093
4094 getreg('=') returns the last evaluated value of the expression
4095 register. (For use in maps.)
4096 getreg('=', 1) returns the expression itself, so that it can
4097 be restored with |setreg()|. For other registers the extra
4098 argument is ignored, thus you can always give it.
4099
4100 If {list} is present and |TRUE|, the result type is changed
4101 to |List|. Each list item is one text line. Use it if you care
4102 about zero bytes possibly present inside register: without
4103 third argument both NLs and zero bytes are represented as NLs
4104 (see |NL-used-for-Nul|).
4105 When the register was not set an empty list is returned.
4106
4107 If {regname} is "", the unnamed register '"' is used.
4108 If {regname} is not specified, |v:register| is used.
4109 In |Vim9-script| {regname} must be one character.
4110
4111 Can also be used as a |method|: >
4112 GetRegname()->getreg()
4113
4114getreginfo([{regname}]) *getreginfo()*
4115 Returns detailed information about register {regname} as a
4116 Dictionary with the following entries:
4117 regcontents List of lines contained in register
4118 {regname}, like
4119 |getreg|({regname}, 1, 1).
4120 regtype the type of register {regname}, as in
4121 |getregtype()|.
4122 isunnamed Boolean flag, v:true if this register
4123 is currently pointed to by the unnamed
4124 register.
4125 points_to for the unnamed register, gives the
4126 single letter name of the register
4127 currently pointed to (see |quotequote|).
4128 For example, after deleting a line
4129 with `dd`, this field will be "1",
4130 which is the register that got the
4131 deleted text.
4132
4133 The {regname} argument is a string. If {regname} is invalid
4134 or not set, an empty Dictionary will be returned.
4135 If {regname} is "" or "@", the unnamed register '"' is used.
4136 If {regname} is not specified, |v:register| is used.
4137 The returned Dictionary can be passed to |setreg()|.
4138 In |Vim9-script| {regname} must be one character.
4139
4140 Can also be used as a |method|: >
4141 GetRegname()->getreginfo()
4142
4143getregtype([{regname}]) *getregtype()*
4144 The result is a String, which is type of register {regname}.
4145 The value will be one of:
4146 "v" for |characterwise| text
4147 "V" for |linewise| text
4148 "<CTRL-V>{width}" for |blockwise-visual| text
4149 "" for an empty or unknown register
4150 <CTRL-V> is one character with value 0x16.
4151 The {regname} argument is a string. If {regname} is "", the
4152 unnamed register '"' is used. If {regname} is not specified,
4153 |v:register| is used.
4154 In |Vim9-script| {regname} must be one character.
4155
4156 Can also be used as a |method|: >
4157 GetRegname()->getregtype()
4158
Bram Moolenaar71badf92023-04-22 22:40:14 +01004159getscriptinfo([{opts}]) *getscriptinfo()*
Yegappan Lakshmananf768c3d2022-08-22 13:15:13 +01004160 Returns a |List| with information about all the sourced Vim
Bram Moolenaar753885b2022-08-24 16:30:36 +01004161 scripts in the order they were sourced, like what
4162 `:scriptnames` shows.
Yegappan Lakshmananf768c3d2022-08-22 13:15:13 +01004163
Yegappan Lakshmanan2f892d82022-08-28 18:52:10 +01004164 The optional Dict argument {opts} supports the following
4165 optional items:
4166 name Script name match pattern. If specified,
4167 and "sid" is not specified, information about
Bram Moolenaar71badf92023-04-22 22:40:14 +01004168 scripts with a name that match the pattern
Yegappan Lakshmanan2f892d82022-08-28 18:52:10 +01004169 "name" are returned.
4170 sid Script ID |<SID>|. If specified, only
4171 information about the script with ID "sid" is
4172 returned and "name" is ignored.
4173
Yegappan Lakshmananf768c3d2022-08-22 13:15:13 +01004174 Each item in the returned List is a |Dict| with the following
4175 items:
Yegappan Lakshmanan2f892d82022-08-28 18:52:10 +01004176 autoload Set to TRUE for a script that was used with
Bram Moolenaar753885b2022-08-24 16:30:36 +01004177 `import autoload` but was not actually sourced
4178 yet (see |import-autoload|).
Yegappan Lakshmanan2f892d82022-08-28 18:52:10 +01004179 functions List of script-local function names defined in
4180 the script. Present only when a particular
4181 script is specified using the "sid" item in
4182 {opts}.
4183 name Vim script file name.
4184 sid Script ID |<SID>|.
4185 sourced Script ID of the actually sourced script that
Bram Moolenaarfd999452022-08-24 18:30:14 +01004186 this script name links to, if any, otherwise
4187 zero
Yegappan Lakshmanan2f892d82022-08-28 18:52:10 +01004188 variables A dictionary with the script-local variables.
Bram Moolenaarf1dcd142022-12-31 15:30:45 +00004189 Present only when a particular script is
Yegappan Lakshmanan2f892d82022-08-28 18:52:10 +01004190 specified using the "sid" item in {opts}.
4191 Note that this is a copy, the value of
4192 script-local variables cannot be changed using
4193 this dictionary.
4194 version Vimscript version (|scriptversion|)
Yegappan Lakshmanan520f6ef2022-08-25 17:40:40 +01004195
Yegappan Lakshmanan2f892d82022-08-28 18:52:10 +01004196 Examples: >
4197 :echo getscriptinfo({'name': 'myscript'})
4198 :echo getscriptinfo({'sid': 15}).variables
4199<
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004200gettabinfo([{tabnr}]) *gettabinfo()*
4201 If {tabnr} is not specified, then information about all the
4202 tab pages is returned as a |List|. Each List item is a
4203 |Dictionary|. Otherwise, {tabnr} specifies the tab page
4204 number and information about that one is returned. If the tab
4205 page does not exist an empty List is returned.
4206
4207 Each List item is a |Dictionary| with the following entries:
4208 tabnr tab page number.
4209 variables a reference to the dictionary with
4210 tabpage-local variables
4211 windows List of |window-ID|s in the tab page.
4212
4213 Can also be used as a |method|: >
4214 GetTabnr()->gettabinfo()
4215
4216gettabvar({tabnr}, {varname} [, {def}]) *gettabvar()*
4217 Get the value of a tab-local variable {varname} in tab page
4218 {tabnr}. |t:var|
4219 Tabs are numbered starting with one.
4220 The {varname} argument is a string. When {varname} is empty a
4221 dictionary with all tab-local variables is returned.
4222 Note that the name without "t:" must be used.
4223 When the tab or variable doesn't exist {def} or an empty
4224 string is returned, there is no error message.
4225
4226 Can also be used as a |method|: >
4227 GetTabnr()->gettabvar(varname)
4228
4229gettabwinvar({tabnr}, {winnr}, {varname} [, {def}]) *gettabwinvar()*
4230 Get the value of window-local variable {varname} in window
4231 {winnr} in tab page {tabnr}.
4232 The {varname} argument is a string. When {varname} is empty a
4233 dictionary with all window-local variables is returned.
4234 When {varname} is equal to "&" get the values of all
4235 window-local options in a |Dictionary|.
4236 Otherwise, when {varname} starts with "&" get the value of a
4237 window-local option.
4238 Note that {varname} must be the name without "w:".
4239 Tabs are numbered starting with one. For the current tabpage
4240 use |getwinvar()|.
4241 {winnr} can be the window number or the |window-ID|.
4242 When {winnr} is zero the current window is used.
4243 This also works for a global option, buffer-local option and
4244 window-local option, but it doesn't work for a global variable
4245 or buffer-local variable.
4246 When the tab, window or variable doesn't exist {def} or an
4247 empty string is returned, there is no error message.
4248 Examples: >
4249 :let list_is_on = gettabwinvar(1, 2, '&list')
Bram Moolenaarc51cf032022-02-26 12:25:45 +00004250 :echo "myvar = " .. gettabwinvar(3, 1, 'myvar')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004251<
4252 To obtain all window-local variables use: >
4253 gettabwinvar({tabnr}, {winnr}, '&')
4254
4255< Can also be used as a |method|: >
4256 GetTabnr()->gettabwinvar(winnr, varname)
4257
4258gettagstack([{winnr}]) *gettagstack()*
4259 The result is a Dict, which is the tag stack of window {winnr}.
4260 {winnr} can be the window number or the |window-ID|.
4261 When {winnr} is not specified, the current window is used.
4262 When window {winnr} doesn't exist, an empty Dict is returned.
4263
4264 The returned dictionary contains the following entries:
4265 curidx Current index in the stack. When at
4266 top of the stack, set to (length + 1).
4267 Index of bottom of the stack is 1.
4268 items List of items in the stack. Each item
4269 is a dictionary containing the
4270 entries described below.
4271 length Number of entries in the stack.
4272
4273 Each item in the stack is a dictionary with the following
4274 entries:
4275 bufnr buffer number of the current jump
4276 from cursor position before the tag jump.
4277 See |getpos()| for the format of the
4278 returned list.
4279 matchnr current matching tag number. Used when
4280 multiple matching tags are found for a
4281 name.
4282 tagname name of the tag
4283
4284 See |tagstack| for more information about the tag stack.
4285
4286 Can also be used as a |method|: >
4287 GetWinnr()->gettagstack()
4288
4289
4290gettext({text}) *gettext()*
4291 Translate String {text} if possible.
4292 This is mainly for use in the distributed Vim scripts. When
4293 generating message translations the {text} is extracted by
4294 xgettext, the translator can add the translated message in the
4295 .po file and Vim will lookup the translation when gettext() is
4296 called.
4297 For {text} double quoted strings are preferred, because
4298 xgettext does not understand escaping in single quoted
4299 strings.
4300
4301
4302getwininfo([{winid}]) *getwininfo()*
4303 Returns information about windows as a |List| with Dictionaries.
4304
4305 If {winid} is given Information about the window with that ID
4306 is returned, as a |List| with one item. If the window does not
4307 exist the result is an empty list.
4308
4309 Without {winid} information about all the windows in all the
4310 tab pages is returned.
4311
4312 Each List item is a |Dictionary| with the following entries:
4313 botline last complete displayed buffer line
4314 bufnr number of buffer in the window
4315 height window height (excluding winbar)
4316 loclist 1 if showing a location list
4317 {only with the +quickfix feature}
4318 quickfix 1 if quickfix or location list window
4319 {only with the +quickfix feature}
4320 terminal 1 if a terminal window
4321 {only with the +terminal feature}
4322 tabnr tab page number
4323 topline first displayed buffer line
4324 variables a reference to the dictionary with
4325 window-local variables
4326 width window width
4327 winbar 1 if the window has a toolbar, 0
4328 otherwise
4329 wincol leftmost screen column of the window;
4330 "col" from |win_screenpos()|
4331 textoff number of columns occupied by any
4332 'foldcolumn', 'signcolumn' and line
4333 number in front of the text
4334 winid |window-ID|
4335 winnr window number
4336 winrow topmost screen line of the window;
4337 "row" from |win_screenpos()|
4338
4339 Can also be used as a |method|: >
4340 GetWinnr()->getwininfo()
4341
4342getwinpos([{timeout}]) *getwinpos()*
4343 The result is a |List| with two numbers, the result of
4344 |getwinposx()| and |getwinposy()| combined:
4345 [x-pos, y-pos]
4346 {timeout} can be used to specify how long to wait in msec for
4347 a response from the terminal. When omitted 100 msec is used.
4348 Use a longer time for a remote terminal.
4349 When using a value less than 10 and no response is received
4350 within that time, a previously reported position is returned,
4351 if available. This can be used to poll for the position and
4352 do some work in the meantime: >
4353 while 1
4354 let res = getwinpos(1)
4355 if res[0] >= 0
4356 break
4357 endif
4358 " Do some work here
4359 endwhile
4360<
4361
4362 Can also be used as a |method|: >
4363 GetTimeout()->getwinpos()
4364<
4365 *getwinposx()*
4366getwinposx() The result is a Number, which is the X coordinate in pixels of
4367 the left hand side of the GUI Vim window. Also works for an
4368 xterm (uses a timeout of 100 msec).
4369 The result will be -1 if the information is not available.
4370 The value can be used with `:winpos`.
4371
4372 *getwinposy()*
4373getwinposy() The result is a Number, which is the Y coordinate in pixels of
4374 the top of the GUI Vim window. Also works for an xterm (uses
4375 a timeout of 100 msec).
4376 The result will be -1 if the information is not available.
4377 The value can be used with `:winpos`.
4378
4379getwinvar({winnr}, {varname} [, {def}]) *getwinvar()*
4380 Like |gettabwinvar()| for the current tabpage.
4381 Examples: >
4382 :let list_is_on = getwinvar(2, '&list')
Bram Moolenaarc51cf032022-02-26 12:25:45 +00004383 :echo "myvar = " .. getwinvar(1, 'myvar')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004384
4385< Can also be used as a |method|: >
4386 GetWinnr()->getwinvar(varname)
4387<
4388glob({expr} [, {nosuf} [, {list} [, {alllinks}]]]) *glob()*
4389 Expand the file wildcards in {expr}. See |wildcards| for the
4390 use of special characters.
4391
4392 Unless the optional {nosuf} argument is given and is |TRUE|,
4393 the 'suffixes' and 'wildignore' options apply: Names matching
4394 one of the patterns in 'wildignore' will be skipped and
4395 'suffixes' affect the ordering of matches.
4396 'wildignorecase' always applies.
4397
4398 When {list} is present and it is |TRUE| the result is a |List|
4399 with all matching files. The advantage of using a List is,
4400 you also get filenames containing newlines correctly.
4401 Otherwise the result is a String and when there are several
4402 matches, they are separated by <NL> characters.
4403
4404 If the expansion fails, the result is an empty String or List.
4405
4406 You can also use |readdir()| if you need to do complicated
4407 things, such as limiting the number of matches.
4408
4409 A name for a non-existing file is not included. A symbolic
4410 link is only included if it points to an existing file.
4411 However, when the {alllinks} argument is present and it is
4412 |TRUE| then all symbolic links are included.
4413
4414 For most systems backticks can be used to get files names from
4415 any external command. Example: >
4416 :let tagfiles = glob("`find . -name tags -print`")
4417 :let &tags = substitute(tagfiles, "\n", ",", "g")
4418< The result of the program inside the backticks should be one
4419 item per line. Spaces inside an item are allowed.
4420
4421 See |expand()| for expanding special Vim variables. See
4422 |system()| for getting the raw output of an external command.
4423
4424 Can also be used as a |method|: >
4425 GetExpr()->glob()
4426
4427glob2regpat({string}) *glob2regpat()*
4428 Convert a file pattern, as used by glob(), into a search
4429 pattern. The result can be used to match with a string that
4430 is a file name. E.g. >
4431 if filename =~ glob2regpat('Make*.mak')
4432< This is equivalent to: >
4433 if filename =~ '^Make.*\.mak$'
4434< When {string} is an empty string the result is "^$", match an
4435 empty string.
4436 Note that the result depends on the system. On MS-Windows
4437 a backslash usually means a path separator.
4438
4439 Can also be used as a |method|: >
4440 GetExpr()->glob2regpat()
4441< *globpath()*
4442globpath({path}, {expr} [, {nosuf} [, {list} [, {alllinks}]]])
4443 Perform glob() for String {expr} on all directories in {path}
4444 and concatenate the results. Example: >
4445 :echo globpath(&rtp, "syntax/c.vim")
4446<
4447 {path} is a comma-separated list of directory names. Each
4448 directory name is prepended to {expr} and expanded like with
4449 |glob()|. A path separator is inserted when needed.
4450 To add a comma inside a directory name escape it with a
4451 backslash. Note that on MS-Windows a directory may have a
4452 trailing backslash, remove it if you put a comma after it.
4453 If the expansion fails for one of the directories, there is no
4454 error message.
4455
4456 Unless the optional {nosuf} argument is given and is |TRUE|,
4457 the 'suffixes' and 'wildignore' options apply: Names matching
4458 one of the patterns in 'wildignore' will be skipped and
4459 'suffixes' affect the ordering of matches.
4460
4461 When {list} is present and it is |TRUE| the result is a |List|
4462 with all matching files. The advantage of using a List is, you
4463 also get filenames containing newlines correctly. Otherwise
4464 the result is a String and when there are several matches,
4465 they are separated by <NL> characters. Example: >
4466 :echo globpath(&rtp, "syntax/c.vim", 0, 1)
4467<
4468 {alllinks} is used as with |glob()|.
4469
4470 The "**" item can be used to search in a directory tree.
4471 For example, to find all "README.txt" files in the directories
4472 in 'runtimepath' and below: >
4473 :echo globpath(&rtp, "**/README.txt")
4474< Upwards search and limiting the depth of "**" is not
4475 supported, thus using 'path' will not always work properly.
4476
4477 Can also be used as a |method|, the base is passed as the
4478 second argument: >
4479 GetExpr()->globpath(&rtp)
4480<
4481 *has()*
4482has({feature} [, {check}])
4483 When {check} is omitted or is zero: The result is a Number,
4484 which is 1 if the feature {feature} is supported, zero
4485 otherwise. The {feature} argument is a string, case is
4486 ignored. See |feature-list| below.
4487
4488 When {check} is present and not zero: The result is a Number,
4489 which is 1 if the feature {feature} could ever be supported,
4490 zero otherwise. This is useful to check for a typo in
4491 {feature} and to detect dead code. Keep in mind that an older
4492 Vim version will not know about a feature added later and
4493 features that have been abandoned will not be known by the
4494 current Vim version.
4495
4496 Also see |exists()| and |exists_compiled()|.
4497
4498 Note that to skip code that has a syntax error when the
4499 feature is not available, Vim may skip the rest of the line
4500 and miss a following `endif`. Therefore put the `endif` on a
4501 separate line: >
4502 if has('feature')
4503 let x = this->breaks->without->the->feature
4504 endif
4505< If the `endif` would be moved to the second line as "| endif" it
4506 would not be found.
4507
4508
4509has_key({dict}, {key}) *has_key()*
4510 The result is a Number, which is TRUE if |Dictionary| {dict}
Bram Moolenaare8008642022-08-19 17:15:35 +01004511 has an entry with key {key}. FALSE otherwise.
4512 The {key} argument is a string. In |Vim9| script a number is
4513 also accepted (and converted to a string) but no other types.
4514 In legacy script the usual automatic conversion to string is
4515 done.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004516
4517 Can also be used as a |method|: >
4518 mydict->has_key(key)
4519
4520haslocaldir([{winnr} [, {tabnr}]]) *haslocaldir()*
4521 The result is a Number:
4522 1 when the window has set a local directory via |:lcd|
4523 2 when the tab-page has set a local directory via |:tcd|
4524 0 otherwise.
4525
4526 Without arguments use the current window.
4527 With {winnr} use this window in the current tab page.
4528 With {winnr} and {tabnr} use the window in the specified tab
4529 page.
4530 {winnr} can be the window number or the |window-ID|.
4531 If {winnr} is -1 it is ignored and only the tabpage is used.
4532 Return 0 if the arguments are invalid.
4533 Examples: >
4534 if haslocaldir() == 1
4535 " window local directory case
4536 elseif haslocaldir() == 2
4537 " tab-local directory case
4538 else
4539 " global directory case
4540 endif
4541
4542 " current window
4543 :echo haslocaldir()
4544 :echo haslocaldir(0)
4545 :echo haslocaldir(0, 0)
4546 " window n in current tab page
4547 :echo haslocaldir(n)
4548 :echo haslocaldir(n, 0)
4549 " window n in tab page m
4550 :echo haslocaldir(n, m)
4551 " tab page m
4552 :echo haslocaldir(-1, m)
4553<
4554 Can also be used as a |method|: >
4555 GetWinnr()->haslocaldir()
4556
4557hasmapto({what} [, {mode} [, {abbr}]]) *hasmapto()*
4558 The result is a Number, which is TRUE if there is a mapping
4559 that contains {what} in somewhere in the rhs (what it is
4560 mapped to) and this mapping exists in one of the modes
4561 indicated by {mode}.
4562 The arguments {what} and {mode} are strings.
4563 When {abbr} is there and it is |TRUE| use abbreviations
4564 instead of mappings. Don't forget to specify Insert and/or
4565 Command-line mode.
4566 Both the global mappings and the mappings local to the current
4567 buffer are checked for a match.
4568 If no matching mapping is found FALSE is returned.
4569 The following characters are recognized in {mode}:
4570 n Normal mode
4571 v Visual and Select mode
4572 x Visual mode
4573 s Select mode
4574 o Operator-pending mode
4575 i Insert mode
4576 l Language-Argument ("r", "f", "t", etc.)
4577 c Command-line mode
4578 When {mode} is omitted, "nvo" is used.
4579
4580 This function is useful to check if a mapping already exists
4581 to a function in a Vim script. Example: >
4582 :if !hasmapto('\ABCdoit')
4583 : map <Leader>d \ABCdoit
4584 :endif
4585< This installs the mapping to "\ABCdoit" only if there isn't
4586 already a mapping to "\ABCdoit".
4587
4588 Can also be used as a |method|: >
4589 GetRHS()->hasmapto()
4590
4591histadd({history}, {item}) *histadd()*
4592 Add the String {item} to the history {history} which can be
4593 one of: *hist-names*
4594 "cmd" or ":" command line history
4595 "search" or "/" search pattern history
4596 "expr" or "=" typed expression history
4597 "input" or "@" input line history
4598 "debug" or ">" debug command history
4599 empty the current or last used history
4600 The {history} string does not need to be the whole name, one
4601 character is sufficient.
4602 If {item} does already exist in the history, it will be
4603 shifted to become the newest entry.
4604 The result is a Number: TRUE if the operation was successful,
4605 otherwise FALSE is returned.
4606
4607 Example: >
4608 :call histadd("input", strftime("%Y %b %d"))
4609 :let date=input("Enter date: ")
4610< This function is not available in the |sandbox|.
4611
4612 Can also be used as a |method|, the base is passed as the
4613 second argument: >
4614 GetHistory()->histadd('search')
4615
4616histdel({history} [, {item}]) *histdel()*
4617 Clear {history}, i.e. delete all its entries. See |hist-names|
4618 for the possible values of {history}.
4619
4620 If the parameter {item} evaluates to a String, it is used as a
4621 regular expression. All entries matching that expression will
4622 be removed from the history (if there are any).
4623 Upper/lowercase must match, unless "\c" is used |/\c|.
4624 If {item} evaluates to a Number, it will be interpreted as
4625 an index, see |:history-indexing|. The respective entry will
4626 be removed if it exists.
4627
4628 The result is TRUE for a successful operation, otherwise FALSE
4629 is returned.
4630
4631 Examples:
4632 Clear expression register history: >
4633 :call histdel("expr")
4634<
4635 Remove all entries starting with "*" from the search history: >
4636 :call histdel("/", '^\*')
4637<
4638 The following three are equivalent: >
4639 :call histdel("search", histnr("search"))
4640 :call histdel("search", -1)
Bram Moolenaarc51cf032022-02-26 12:25:45 +00004641 :call histdel("search", '^' .. histget("search", -1) .. '$')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004642<
4643 To delete the last search pattern and use the last-but-one for
4644 the "n" command and 'hlsearch': >
4645 :call histdel("search", -1)
4646 :let @/ = histget("search", -1)
4647<
4648 Can also be used as a |method|: >
4649 GetHistory()->histdel()
4650
4651histget({history} [, {index}]) *histget()*
4652 The result is a String, the entry with Number {index} from
4653 {history}. See |hist-names| for the possible values of
4654 {history}, and |:history-indexing| for {index}. If there is
4655 no such entry, an empty String is returned. When {index} is
4656 omitted, the most recent item from the history is used.
4657
4658 Examples:
4659 Redo the second last search from history. >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00004660 :execute '/' .. histget("search", -2)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004661
4662< Define an Ex command ":H {num}" that supports re-execution of
4663 the {num}th entry from the output of |:history|. >
4664 :command -nargs=1 H execute histget("cmd", 0+<args>)
4665<
4666 Can also be used as a |method|: >
4667 GetHistory()->histget()
4668
4669histnr({history}) *histnr()*
4670 The result is the Number of the current entry in {history}.
4671 See |hist-names| for the possible values of {history}.
4672 If an error occurred, -1 is returned.
4673
4674 Example: >
4675 :let inp_index = histnr("expr")
4676
4677< Can also be used as a |method|: >
4678 GetHistory()->histnr()
4679<
4680hlexists({name}) *hlexists()*
4681 The result is a Number, which is TRUE if a highlight group
4682 called {name} exists. This is when the group has been
4683 defined in some way. Not necessarily when highlighting has
4684 been defined for it, it may also have been used for a syntax
4685 item.
4686 *highlight_exists()*
4687 Obsolete name: highlight_exists().
4688
4689 Can also be used as a |method|: >
4690 GetName()->hlexists()
4691<
4692hlget([{name} [, {resolve}]]) *hlget()*
4693 Returns a List of all the highlight group attributes. If the
4694 optional {name} is specified, then returns a List with only
4695 the attributes of the specified highlight group. Returns an
4696 empty List if the highlight group {name} is not present.
4697
4698 If the optional {resolve} argument is set to v:true and the
4699 highlight group {name} is linked to another group, then the
4700 link is resolved recursively and the attributes of the
4701 resolved highlight group are returned.
4702
4703 Each entry in the returned List is a Dictionary with the
4704 following items:
4705 cleared boolean flag, set to v:true if the highlight
4706 group attributes are cleared or not yet
4707 specified. See |highlight-clear|.
4708 cterm cterm attributes. See |highlight-cterm|.
4709 ctermbg cterm background color.
4710 See |highlight-ctermbg|.
4711 ctermfg cterm foreground color.
4712 See |highlight-ctermfg|.
4713 ctermul cterm underline color. See |highlight-ctermul|.
4714 default boolean flag, set to v:true if the highlight
4715 group link is a default link. See
4716 |highlight-default|.
4717 font highlight group font. See |highlight-font|.
4718 gui gui attributes. See |highlight-gui|.
4719 guibg gui background color. See |highlight-guibg|.
4720 guifg gui foreground color. See |highlight-guifg|.
4721 guisp gui special color. See |highlight-guisp|.
4722 id highlight group ID.
4723 linksto linked highlight group name.
4724 See |:highlight-link|.
4725 name highlight group name. See |group-name|.
4726 start start terminal keycode. See |highlight-start|.
4727 stop stop terminal keycode. See |highlight-stop|.
4728 term term attributes. See |highlight-term|.
4729
4730 The 'term', 'cterm' and 'gui' items in the above Dictionary
4731 have a dictionary value with the following optional boolean
4732 items: 'bold', 'standout', 'underline', 'undercurl', 'italic',
4733 'reverse', 'inverse' and 'strikethrough'.
4734
4735 Example(s): >
4736 :echo hlget()
4737 :echo hlget('ModeMsg')
4738 :echo hlget('Number', v:true)
4739<
4740 Can also be used as a |method|: >
4741 GetName()->hlget()
4742<
4743hlset({list}) *hlset()*
4744 Creates or modifies the attributes of a List of highlight
4745 groups. Each item in {list} is a dictionary containing the
4746 attributes of a highlight group. See |hlget()| for the list of
4747 supported items in this dictionary.
4748
4749 In addition to the items described in |hlget()|, the following
4750 additional items are supported in the dictionary:
4751
4752 force boolean flag to force the creation of
4753 a link for an existing highlight group
4754 with attributes.
4755
4756 The highlight group is identified using the 'name' item and
4757 the 'id' item (if supplied) is ignored. If a highlight group
4758 with a specified name doesn't exist, then it is created.
4759 Otherwise the attributes of an existing highlight group are
4760 modified.
4761
4762 If an empty dictionary value is used for the 'term' or 'cterm'
4763 or 'gui' entries, then the corresponding attributes are
4764 cleared. If the 'cleared' item is set to v:true, then all the
4765 attributes of the highlight group are cleared.
4766
4767 The 'linksto' item can be used to link a highlight group to
4768 another highlight group. See |:highlight-link|.
4769
4770 Returns zero for success, -1 for failure.
4771
4772 Example(s): >
4773 " add bold attribute to the Visual highlight group
4774 :call hlset([#{name: 'Visual',
4775 \ term: #{reverse: 1 , bold: 1}}])
4776 :call hlset([#{name: 'Type', guifg: 'DarkGreen'}])
4777 :let l = hlget()
4778 :call hlset(l)
4779 " clear the Search highlight group
4780 :call hlset([#{name: 'Search', cleared: v:true}])
4781 " clear the 'term' attributes for a highlight group
4782 :call hlset([#{name: 'Title', term: {}}])
4783 " create the MyHlg group linking it to DiffAdd
4784 :call hlset([#{name: 'MyHlg', linksto: 'DiffAdd'}])
4785 " remove the MyHlg group link
4786 :call hlset([#{name: 'MyHlg', linksto: 'NONE'}])
4787 " clear the attributes and a link
4788 :call hlset([#{name: 'MyHlg', cleared: v:true,
4789 \ linksto: 'NONE'}])
4790<
4791 Can also be used as a |method|: >
4792 GetAttrList()->hlset()
4793<
4794 *hlID()*
4795hlID({name}) The result is a Number, which is the ID of the highlight group
4796 with name {name}. When the highlight group doesn't exist,
4797 zero is returned.
4798 This can be used to retrieve information about the highlight
4799 group. For example, to get the background color of the
4800 "Comment" group: >
4801 :echo synIDattr(synIDtrans(hlID("Comment")), "bg")
4802< *highlightID()*
4803 Obsolete name: highlightID().
4804
4805 Can also be used as a |method|: >
4806 GetName()->hlID()
4807
4808hostname() *hostname()*
4809 The result is a String, which is the name of the machine on
4810 which Vim is currently running. Machine names greater than
4811 256 characters long are truncated.
4812
4813iconv({string}, {from}, {to}) *iconv()*
4814 The result is a String, which is the text {string} converted
4815 from encoding {from} to encoding {to}.
4816 When the conversion completely fails an empty string is
4817 returned. When some characters could not be converted they
4818 are replaced with "?".
4819 The encoding names are whatever the iconv() library function
4820 can accept, see ":!man 3 iconv".
4821 Most conversions require Vim to be compiled with the |+iconv|
4822 feature. Otherwise only UTF-8 to latin1 conversion and back
4823 can be done.
4824 This can be used to display messages with special characters,
4825 no matter what 'encoding' is set to. Write the message in
4826 UTF-8 and use: >
4827 echo iconv(utf8_str, "utf-8", &enc)
4828< Note that Vim uses UTF-8 for all Unicode encodings, conversion
4829 from/to UCS-2 is automatically changed to use UTF-8. You
4830 cannot use UCS-2 in a string anyway, because of the NUL bytes.
4831
4832 Can also be used as a |method|: >
4833 GetText()->iconv('latin1', 'utf-8')
4834<
4835 *indent()*
4836indent({lnum}) The result is a Number, which is indent of line {lnum} in the
4837 current buffer. The indent is counted in spaces, the value
4838 of 'tabstop' is relevant. {lnum} is used just like in
4839 |getline()|.
4840 When {lnum} is invalid -1 is returned. In |Vim9| script an
4841 error is given.
4842
4843 Can also be used as a |method|: >
4844 GetLnum()->indent()
4845
4846index({object}, {expr} [, {start} [, {ic}]]) *index()*
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01004847 Find {expr} in {object} and return its index. See
Yegappan Lakshmanan3fbf6cd2022-08-13 21:35:13 +01004848 |indexof()| for using a lambda to select the item.
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01004849
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004850 If {object} is a |List| return the lowest index where the item
4851 has a value equal to {expr}. There is no automatic
4852 conversion, so the String "4" is different from the Number 4.
4853 And the number 4 is different from the Float 4.0. The value
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01004854 of 'ignorecase' is not used here, case matters as indicated by
4855 the {ic} argument.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004856
4857 If {object} is |Blob| return the lowest index where the byte
4858 value is equal to {expr}.
4859
4860 If {start} is given then start looking at the item with index
4861 {start} (may be negative for an item relative to the end).
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01004862
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004863 When {ic} is given and it is |TRUE|, ignore case. Otherwise
4864 case must match.
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01004865
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004866 -1 is returned when {expr} is not found in {object}.
4867 Example: >
4868 :let idx = index(words, "the")
4869 :if index(numbers, 123) >= 0
4870
4871< Can also be used as a |method|: >
4872 GetObject()->index(what)
4873
Yegappan Lakshmanan3fbf6cd2022-08-13 21:35:13 +01004874indexof({object}, {expr} [, {opts}]) *indexof()*
4875 Returns the index of an item in {object} where {expr} is
4876 v:true. {object} must be a |List| or a |Blob|.
4877
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01004878 If {object} is a |List|, evaluate {expr} for each item in the
Yegappan Lakshmanan3fbf6cd2022-08-13 21:35:13 +01004879 List until the expression is v:true and return the index of
4880 this item.
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01004881
4882 If {object} is a |Blob| evaluate {expr} for each byte in the
Yegappan Lakshmanan3fbf6cd2022-08-13 21:35:13 +01004883 Blob until the expression is v:true and return the index of
4884 this byte.
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01004885
4886 {expr} must be a |string| or |Funcref|.
4887
4888 If {expr} is a |string|: If {object} is a |List|, inside
4889 {expr} |v:key| has the index of the current List item and
4890 |v:val| has the value of the item. If {object} is a |Blob|,
4891 inside {expr} |v:key| has the index of the current byte and
4892 |v:val| has the byte value.
4893
4894 If {expr} is a |Funcref| it must take two arguments:
4895 1. the key or the index of the current item.
4896 2. the value of the current item.
4897 The function must return |TRUE| if the item is found and the
4898 search should stop.
4899
Yegappan Lakshmanan3fbf6cd2022-08-13 21:35:13 +01004900 The optional argument {opts} is a Dict and supports the
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01004901 following items:
Yegappan Lakshmanan3fbf6cd2022-08-13 21:35:13 +01004902 startidx start evaluating {expr} at the item with this
4903 index; may be negative for an item relative to
4904 the end
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01004905 Returns -1 when {expr} evaluates to v:false for all the items.
4906 Example: >
Yegappan Lakshmanan3fbf6cd2022-08-13 21:35:13 +01004907 :let l = [#{n: 10}, #{n: 20}, #{n: 30}]
4908 :echo indexof(l, "v:val.n == 20")
4909 :echo indexof(l, {i, v -> v.n == 30})
4910 :echo indexof(l, "v:val.n == 20", #{startidx: 1})
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01004911
4912< Can also be used as a |method|: >
4913 mylist->indexof(expr)
4914
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004915input({prompt} [, {text} [, {completion}]]) *input()*
4916 The result is a String, which is whatever the user typed on
4917 the command-line. The {prompt} argument is either a prompt
4918 string, or a blank string (for no prompt). A '\n' can be used
4919 in the prompt to start a new line.
4920 The highlighting set with |:echohl| is used for the prompt.
4921 The input is entered just like a command-line, with the same
4922 editing commands and mappings. There is a separate history
4923 for lines typed for input().
4924 Example: >
4925 :if input("Coffee or beer? ") == "beer"
4926 : echo "Cheers!"
4927 :endif
4928<
4929 If the optional {text} argument is present and not empty, this
4930 is used for the default reply, as if the user typed this.
4931 Example: >
4932 :let color = input("Color? ", "white")
4933
4934< The optional {completion} argument specifies the type of
4935 completion supported for the input. Without it completion is
4936 not performed. The supported completion types are the same as
4937 that can be supplied to a user-defined command using the
4938 "-complete=" argument. Refer to |:command-completion| for
4939 more information. Example: >
4940 let fname = input("File: ", "", "file")
4941<
4942 NOTE: This function must not be used in a startup file, for
4943 the versions that only run in GUI mode (e.g., the Win32 GUI).
4944 Note: When input() is called from within a mapping it will
4945 consume remaining characters from that mapping, because a
4946 mapping is handled like the characters were typed.
4947 Use |inputsave()| before input() and |inputrestore()|
4948 after input() to avoid that. Another solution is to avoid
4949 that further characters follow in the mapping, e.g., by using
4950 |:execute| or |:normal|.
4951
4952 Example with a mapping: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00004953 :nmap \x :call GetFoo()<CR>:exe "/" .. Foo<CR>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004954 :function GetFoo()
4955 : call inputsave()
4956 : let g:Foo = input("enter search pattern: ")
4957 : call inputrestore()
4958 :endfunction
4959
4960< Can also be used as a |method|: >
4961 GetPrompt()->input()
4962
4963inputdialog({prompt} [, {text} [, {cancelreturn}]]) *inputdialog()*
4964 Like |input()|, but when the GUI is running and text dialogs
4965 are supported, a dialog window pops up to input the text.
4966 Example: >
4967 :let n = inputdialog("value for shiftwidth", shiftwidth())
4968 :if n != ""
4969 : let &sw = n
4970 :endif
4971< When the dialog is cancelled {cancelreturn} is returned. When
4972 omitted an empty string is returned.
4973 Hitting <Enter> works like pressing the OK button. Hitting
4974 <Esc> works like pressing the Cancel button.
4975 NOTE: Command-line completion is not supported.
4976
4977 Can also be used as a |method|: >
4978 GetPrompt()->inputdialog()
4979
4980inputlist({textlist}) *inputlist()*
4981 {textlist} must be a |List| of strings. This |List| is
4982 displayed, one string per line. The user will be prompted to
4983 enter a number, which is returned.
4984 The user can also select an item by clicking on it with the
4985 mouse, if the mouse is enabled in the command line ('mouse' is
4986 "a" or includes "c"). For the first string 0 is returned.
4987 When clicking above the first item a negative number is
4988 returned. When clicking on the prompt one more than the
4989 length of {textlist} is returned.
4990 Make sure {textlist} has less than 'lines' entries, otherwise
4991 it won't work. It's a good idea to put the entry number at
4992 the start of the string. And put a prompt in the first item.
4993 Example: >
4994 let color = inputlist(['Select color:', '1. red',
4995 \ '2. green', '3. blue'])
4996
4997< Can also be used as a |method|: >
4998 GetChoices()->inputlist()
4999
5000inputrestore() *inputrestore()*
5001 Restore typeahead that was saved with a previous |inputsave()|.
5002 Should be called the same number of times inputsave() is
5003 called. Calling it more often is harmless though.
5004 Returns TRUE when there is nothing to restore, FALSE otherwise.
5005
5006inputsave() *inputsave()*
5007 Preserve typeahead (also from mappings) and clear it, so that
5008 a following prompt gets input from the user. Should be
5009 followed by a matching inputrestore() after the prompt. Can
5010 be used several times, in which case there must be just as
5011 many inputrestore() calls.
5012 Returns TRUE when out of memory, FALSE otherwise.
5013
5014inputsecret({prompt} [, {text}]) *inputsecret()*
5015 This function acts much like the |input()| function with but
5016 two exceptions:
5017 a) the user's response will be displayed as a sequence of
5018 asterisks ("*") thereby keeping the entry secret, and
5019 b) the user's response will not be recorded on the input
5020 |history| stack.
5021 The result is a String, which is whatever the user actually
5022 typed on the command-line in response to the issued prompt.
5023 NOTE: Command-line completion is not supported.
5024
5025 Can also be used as a |method|: >
5026 GetPrompt()->inputsecret()
5027
5028insert({object}, {item} [, {idx}]) *insert()*
5029 When {object} is a |List| or a |Blob| insert {item} at the start
5030 of it.
5031
5032 If {idx} is specified insert {item} before the item with index
5033 {idx}. If {idx} is zero it goes before the first item, just
5034 like omitting {idx}. A negative {idx} is also possible, see
5035 |list-index|. -1 inserts just before the last item.
5036
5037 Returns the resulting |List| or |Blob|. Examples: >
5038 :let mylist = insert([2, 3, 5], 1)
5039 :call insert(mylist, 4, -1)
5040 :call insert(mylist, 6, len(mylist))
5041< The last example can be done simpler with |add()|.
5042 Note that when {item} is a |List| it is inserted as a single
5043 item. Use |extend()| to concatenate |Lists|.
5044
5045 Can also be used as a |method|: >
5046 mylist->insert(item)
5047
5048interrupt() *interrupt()*
5049 Interrupt script execution. It works more or less like the
5050 user typing CTRL-C, most commands won't execute and control
5051 returns to the user. This is useful to abort execution
5052 from lower down, e.g. in an autocommand. Example: >
5053 :function s:check_typoname(file)
5054 : if fnamemodify(a:file, ':t') == '['
5055 : echomsg 'Maybe typo'
5056 : call interrupt()
5057 : endif
5058 :endfunction
5059 :au BufWritePre * call s:check_typoname(expand('<amatch>'))
5060
5061invert({expr}) *invert()*
5062 Bitwise invert. The argument is converted to a number. A
5063 List, Dict or Float argument causes an error. Example: >
5064 :let bits = invert(bits)
5065< Can also be used as a |method|: >
5066 :let bits = bits->invert()
5067
Bram Moolenaar8a3b8052022-06-26 12:21:15 +01005068isabsolutepath({path}) *isabsolutepath()*
LemonBoydca1d402022-04-28 15:26:33 +01005069 The result is a Number, which is |TRUE| when {path} is an
5070 absolute path.
Bram Moolenaar8a3b8052022-06-26 12:21:15 +01005071 On Unix, a path is considered absolute when it starts with '/'.
LemonBoydca1d402022-04-28 15:26:33 +01005072 On MS-Windows, it is considered absolute when it starts with an
5073 optional drive prefix and is followed by a '\' or '/'. UNC paths
5074 are always absolute.
5075 Example: >
5076 echo isabsolutepath('/usr/share/') " 1
5077 echo isabsolutepath('./foobar') " 0
5078 echo isabsolutepath('C:\Windows') " 1
5079 echo isabsolutepath('foobar') " 0
5080 echo isabsolutepath('\\remote\file') " 1
Bram Moolenaar8a3b8052022-06-26 12:21:15 +01005081<
LemonBoydca1d402022-04-28 15:26:33 +01005082 Can also be used as a |method|: >
5083 GetName()->isabsolutepath()
5084
5085
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005086isdirectory({directory}) *isdirectory()*
5087 The result is a Number, which is |TRUE| when a directory
5088 with the name {directory} exists. If {directory} doesn't
5089 exist, or isn't a directory, the result is |FALSE|. {directory}
5090 is any expression, which is used as a String.
5091
5092 Can also be used as a |method|: >
5093 GetName()->isdirectory()
5094
5095isinf({expr}) *isinf()*
5096 Return 1 if {expr} is a positive infinity, or -1 a negative
5097 infinity, otherwise 0. >
5098 :echo isinf(1.0 / 0.0)
5099< 1 >
5100 :echo isinf(-1.0 / 0.0)
5101< -1
5102
5103 Can also be used as a |method|: >
5104 Compute()->isinf()
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005105
5106islocked({expr}) *islocked()* *E786*
5107 The result is a Number, which is |TRUE| when {expr} is the
5108 name of a locked variable.
5109 The string argument {expr} must be the name of a variable,
5110 |List| item or |Dictionary| entry, not the variable itself!
5111 Example: >
5112 :let alist = [0, ['a', 'b'], 2, 3]
5113 :lockvar 1 alist
5114 :echo islocked('alist') " 1
5115 :echo islocked('alist[1]') " 0
5116
Bram Moolenaar9da17d72022-02-09 21:50:44 +00005117< When {expr} is a variable that does not exist -1 is returned.
5118 If {expr} uses a range, list or dict index that is out of
5119 range or does not exist you get an error message. Use
5120 |exists()| to check for existence.
5121 In Vim9 script it does not work for local function variables.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005122
5123 Can also be used as a |method|: >
5124 GetName()->islocked()
5125
5126isnan({expr}) *isnan()*
5127 Return |TRUE| if {expr} is a float with value NaN. >
5128 echo isnan(0.0 / 0.0)
5129< 1
5130
5131 Can also be used as a |method|: >
5132 Compute()->isnan()
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005133
5134items({dict}) *items()*
5135 Return a |List| with all the key-value pairs of {dict}. Each
5136 |List| item is a list with two items: the key of a {dict}
5137 entry and the value of this entry. The |List| is in arbitrary
5138 order. Also see |keys()| and |values()|.
5139 Example: >
5140 for [key, value] in items(mydict)
Bram Moolenaarc51cf032022-02-26 12:25:45 +00005141 echo key .. ': ' .. value
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005142 endfor
5143
5144< Can also be used as a |method|: >
5145 mydict->items()
5146
5147job_ functions are documented here: |job-functions-details|
5148
5149
5150join({list} [, {sep}]) *join()*
5151 Join the items in {list} together into one String.
5152 When {sep} is specified it is put in between the items. If
5153 {sep} is omitted a single space is used.
5154 Note that {sep} is not added at the end. You might want to
5155 add it there too: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00005156 let lines = join(mylist, "\n") .. "\n"
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005157< String items are used as-is. |Lists| and |Dictionaries| are
5158 converted into a string like with |string()|.
5159 The opposite function is |split()|.
5160
5161 Can also be used as a |method|: >
5162 mylist->join()
5163
5164js_decode({string}) *js_decode()*
5165 This is similar to |json_decode()| with these differences:
5166 - Object key names do not have to be in quotes.
5167 - Strings can be in single quotes.
5168 - Empty items in an array (between two commas) are allowed and
5169 result in v:none items.
5170
5171 Can also be used as a |method|: >
5172 ReadObject()->js_decode()
5173
5174js_encode({expr}) *js_encode()*
5175 This is similar to |json_encode()| with these differences:
5176 - Object key names are not in quotes.
5177 - v:none items in an array result in an empty item between
5178 commas.
5179 For example, the Vim object:
5180 [1,v:none,{"one":1},v:none] ~
5181 Will be encoded as:
5182 [1,,{one:1},,] ~
5183 While json_encode() would produce:
5184 [1,null,{"one":1},null] ~
5185 This encoding is valid for JavaScript. It is more efficient
5186 than JSON, especially when using an array with optional items.
5187
5188 Can also be used as a |method|: >
5189 GetObject()->js_encode()
5190
Bram Moolenaar2f0936c2022-01-08 21:51:59 +00005191json_decode({string}) *json_decode()* *E491*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005192 This parses a JSON formatted string and returns the equivalent
5193 in Vim values. See |json_encode()| for the relation between
5194 JSON and Vim values.
5195 The decoding is permissive:
5196 - A trailing comma in an array and object is ignored, e.g.
5197 "[1, 2, ]" is the same as "[1, 2]".
5198 - Integer keys are accepted in objects, e.g. {1:2} is the
5199 same as {"1":2}.
5200 - More floating point numbers are recognized, e.g. "1." for
5201 "1.0", or "001.2" for "1.2". Special floating point values
5202 "Infinity", "-Infinity" and "NaN" (capitalization ignored)
5203 are accepted.
5204 - Leading zeroes in integer numbers are ignored, e.g. "012"
5205 for "12" or "-012" for "-12".
5206 - Capitalization is ignored in literal names null, true or
5207 false, e.g. "NULL" for "null", "True" for "true".
5208 - Control characters U+0000 through U+001F which are not
5209 escaped in strings are accepted, e.g. " " (tab
5210 character in string) for "\t".
5211 - An empty JSON expression or made of only spaces is accepted
5212 and results in v:none.
5213 - Backslash in an invalid 2-character sequence escape is
5214 ignored, e.g. "\a" is decoded as "a".
5215 - A correct surrogate pair in JSON strings should normally be
5216 a 12 character sequence such as "\uD834\uDD1E", but
5217 json_decode() silently accepts truncated surrogate pairs
5218 such as "\uD834" or "\uD834\u"
5219 *E938*
5220 A duplicate key in an object, valid in rfc7159, is not
5221 accepted by json_decode() as the result must be a valid Vim
5222 type, e.g. this fails: {"a":"b", "a":"c"}
5223
5224 Can also be used as a |method|: >
5225 ReadObject()->json_decode()
5226
5227json_encode({expr}) *json_encode()*
5228 Encode {expr} as JSON and return this as a string.
5229 The encoding is specified in:
5230 https://tools.ietf.org/html/rfc7159.html
Bram Moolenaara2baa732022-02-04 16:09:54 +00005231 Vim values are converted as follows: *E1161*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005232 |Number| decimal number
5233 |Float| floating point number
5234 Float nan "NaN"
5235 Float inf "Infinity"
5236 Float -inf "-Infinity"
5237 |String| in double quotes (possibly null)
5238 |Funcref| not possible, error
5239 |List| as an array (possibly null); when
5240 used recursively: []
5241 |Dict| as an object (possibly null); when
5242 used recursively: {}
5243 |Blob| as an array of the individual bytes
5244 v:false "false"
5245 v:true "true"
5246 v:none "null"
5247 v:null "null"
5248 Note that NaN and Infinity are passed on as values. This is
5249 missing in the JSON standard, but several implementations do
5250 allow it. If not then you will get an error.
Bram Moolenaarcbaff5e2022-04-08 17:45:08 +01005251 If a string contains an illegal character then the replacement
5252 character 0xfffd is used.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005253
5254 Can also be used as a |method|: >
5255 GetObject()->json_encode()
5256
5257keys({dict}) *keys()*
5258 Return a |List| with all the keys of {dict}. The |List| is in
5259 arbitrary order. Also see |items()| and |values()|.
5260
5261 Can also be used as a |method|: >
5262 mydict->keys()
5263
zeertzjqcdc83932022-09-12 13:38:41 +01005264keytrans({string}) *keytrans()*
5265 Turn the internal byte representation of keys into a form that
5266 can be used for |:map|. E.g. >
5267 :let xx = "\<C-Home>"
5268 :echo keytrans(xx)
5269< <C-Home>
5270
5271 Can also be used as a |method|: >
5272 "\<C-Home>"->keytrans()
5273
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005274< *len()* *E701*
5275len({expr}) The result is a Number, which is the length of the argument.
5276 When {expr} is a String or a Number the length in bytes is
5277 used, as with |strlen()|.
5278 When {expr} is a |List| the number of items in the |List| is
5279 returned.
5280 When {expr} is a |Blob| the number of bytes is returned.
5281 When {expr} is a |Dictionary| the number of entries in the
5282 |Dictionary| is returned.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01005283 Otherwise an error is given and returns zero.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005284
5285 Can also be used as a |method|: >
5286 mylist->len()
5287
5288< *libcall()* *E364* *E368*
5289libcall({libname}, {funcname}, {argument})
5290 Call function {funcname} in the run-time library {libname}
5291 with single argument {argument}.
5292 This is useful to call functions in a library that you
5293 especially made to be used with Vim. Since only one argument
5294 is possible, calling standard library functions is rather
5295 limited.
5296 The result is the String returned by the function. If the
5297 function returns NULL, this will appear as an empty string ""
5298 to Vim.
5299 If the function returns a number, use libcallnr()!
5300 If {argument} is a number, it is passed to the function as an
5301 int; if {argument} is a string, it is passed as a
5302 null-terminated string.
5303 This function will fail in |restricted-mode|.
5304
5305 libcall() allows you to write your own 'plug-in' extensions to
5306 Vim without having to recompile the program. It is NOT a
5307 means to call system functions! If you try to do so Vim will
5308 very probably crash.
5309
5310 For Win32, the functions you write must be placed in a DLL
5311 and use the normal C calling convention (NOT Pascal which is
5312 used in Windows System DLLs). The function must take exactly
5313 one parameter, either a character pointer or a long integer,
5314 and must return a character pointer or NULL. The character
5315 pointer returned must point to memory that will remain valid
5316 after the function has returned (e.g. in static data in the
5317 DLL). If it points to allocated memory, that memory will
5318 leak away. Using a static buffer in the function should work,
5319 it's then freed when the DLL is unloaded.
5320
5321 WARNING: If the function returns a non-valid pointer, Vim may
5322 crash! This also happens if the function returns a number,
5323 because Vim thinks it's a pointer.
5324 For Win32 systems, {libname} should be the filename of the DLL
5325 without the ".DLL" suffix. A full path is only required if
5326 the DLL is not in the usual places.
5327 For Unix: When compiling your own plugins, remember that the
5328 object code must be compiled as position-independent ('PIC').
5329 {only in Win32 and some Unix versions, when the |+libcall|
5330 feature is present}
5331 Examples: >
5332 :echo libcall("libc.so", "getenv", "HOME")
5333
5334< Can also be used as a |method|, the base is passed as the
5335 third argument: >
5336 GetValue()->libcall("libc.so", "getenv")
5337<
5338 *libcallnr()*
5339libcallnr({libname}, {funcname}, {argument})
5340 Just like |libcall()|, but used for a function that returns an
5341 int instead of a string.
5342 {only in Win32 on some Unix versions, when the |+libcall|
5343 feature is present}
5344 Examples: >
5345 :echo libcallnr("/usr/lib/libc.so", "getpid", "")
5346 :call libcallnr("libc.so", "printf", "Hello World!\n")
5347 :call libcallnr("libc.so", "sleep", 10)
5348<
5349 Can also be used as a |method|, the base is passed as the
5350 third argument: >
5351 GetValue()->libcallnr("libc.so", "printf")
5352<
5353
5354line({expr} [, {winid}]) *line()*
5355 The result is a Number, which is the line number of the file
5356 position given with {expr}. The {expr} argument is a string.
Bram Moolenaara2baa732022-02-04 16:09:54 +00005357 The accepted positions are: *E1209*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005358 . the cursor position
5359 $ the last line in the current buffer
5360 'x position of mark x (if the mark is not set, 0 is
5361 returned)
5362 w0 first line visible in current window (one if the
5363 display isn't updated, e.g. in silent Ex mode)
5364 w$ last line visible in current window (this is one
5365 less than "w0" if no lines are visible)
5366 v In Visual mode: the start of the Visual area (the
5367 cursor is the end). When not in Visual mode
5368 returns the cursor position. Differs from |'<| in
5369 that it's updated right away.
5370 Note that a mark in another file can be used. The line number
5371 then applies to another buffer.
5372 To get the column number use |col()|. To get both use
5373 |getpos()|.
5374 With the optional {winid} argument the values are obtained for
5375 that window instead of the current window.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01005376 Returns 0 for invalid values of {expr} and {winid}.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005377 Examples: >
5378 line(".") line number of the cursor
5379 line(".", winid) idem, in window "winid"
5380 line("'t") line number of mark t
Bram Moolenaarc51cf032022-02-26 12:25:45 +00005381 line("'" .. marker) line number of mark marker
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005382<
5383 To jump to the last known position when opening a file see
5384 |last-position-jump|.
5385
5386 Can also be used as a |method|: >
5387 GetValue()->line()
5388
5389line2byte({lnum}) *line2byte()*
5390 Return the byte count from the start of the buffer for line
5391 {lnum}. This includes the end-of-line character, depending on
5392 the 'fileformat' option for the current buffer. The first
5393 line returns 1. 'encoding' matters, 'fileencoding' is ignored.
5394 This can also be used to get the byte count for the line just
5395 below the last line: >
5396 line2byte(line("$") + 1)
5397< This is the buffer size plus one. If 'fileencoding' is empty
5398 it is the file size plus one. {lnum} is used like with
5399 |getline()|. When {lnum} is invalid, or the |+byte_offset|
5400 feature has been disabled at compile time, -1 is returned.
5401 Also see |byte2line()|, |go| and |:goto|.
5402
5403 Can also be used as a |method|: >
5404 GetLnum()->line2byte()
5405
5406lispindent({lnum}) *lispindent()*
5407 Get the amount of indent for line {lnum} according the lisp
5408 indenting rules, as with 'lisp'.
5409 The indent is counted in spaces, the value of 'tabstop' is
5410 relevant. {lnum} is used just like in |getline()|.
Bram Moolenaar8e145b82022-05-21 20:17:31 +01005411 When {lnum} is invalid -1 is returned. In |Vim9| script an
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005412 error is given.
5413
5414 Can also be used as a |method|: >
5415 GetLnum()->lispindent()
5416
5417list2blob({list}) *list2blob()*
5418 Return a Blob concatenating all the number values in {list}.
5419 Examples: >
5420 list2blob([1, 2, 3, 4]) returns 0z01020304
5421 list2blob([]) returns 0z
5422< Returns an empty Blob on error. If one of the numbers is
5423 negative or more than 255 error *E1239* is given.
5424
5425 |blob2list()| does the opposite.
5426
5427 Can also be used as a |method|: >
5428 GetList()->list2blob()
5429
5430list2str({list} [, {utf8}]) *list2str()*
5431 Convert each number in {list} to a character string can
5432 concatenate them all. Examples: >
5433 list2str([32]) returns " "
5434 list2str([65, 66, 67]) returns "ABC"
5435< The same can be done (slowly) with: >
5436 join(map(list, {nr, val -> nr2char(val)}), '')
5437< |str2list()| does the opposite.
5438
5439 When {utf8} is omitted or zero, the current 'encoding' is used.
5440 When {utf8} is TRUE, always return UTF-8 characters.
5441 With UTF-8 composing characters work as expected: >
5442 list2str([97, 769]) returns "á"
5443<
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01005444 Returns an empty string on error.
5445
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005446 Can also be used as a |method|: >
5447 GetList()->list2str()
5448
5449listener_add({callback} [, {buf}]) *listener_add()*
5450 Add a callback function that will be invoked when changes have
5451 been made to buffer {buf}.
5452 {buf} refers to a buffer name or number. For the accepted
5453 values, see |bufname()|. When {buf} is omitted the current
5454 buffer is used.
5455 Returns a unique ID that can be passed to |listener_remove()|.
5456
5457 The {callback} is invoked with five arguments:
Bram Moolenaar944697a2022-02-20 19:48:20 +00005458 bufnr the buffer that was changed
5459 start first changed line number
5460 end first line number below the change
5461 added number of lines added, negative if lines were
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005462 deleted
Bram Moolenaar944697a2022-02-20 19:48:20 +00005463 changes a List of items with details about the changes
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005464
5465 Example: >
5466 func Listener(bufnr, start, end, added, changes)
5467 echo 'lines ' .. a:start .. ' until ' .. a:end .. ' changed'
5468 endfunc
5469 call listener_add('Listener', bufnr)
5470
Bram Moolenaar944697a2022-02-20 19:48:20 +00005471< The List cannot be changed. Each item in "changes" is a
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005472 dictionary with these entries:
5473 lnum the first line number of the change
5474 end the first line below the change
5475 added number of lines added; negative if lines were
5476 deleted
5477 col first column in "lnum" that was affected by
5478 the change; one if unknown or the whole line
5479 was affected; this is a byte index, first
5480 character has a value of one.
Bram Moolenaar3c053a12022-10-16 13:11:12 +01005481 When lines are inserted (not when a line is split, e.g. by
5482 typing CR in Insert mode) the values are:
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005483 lnum line above which the new line is added
5484 end equal to "lnum"
5485 added number of lines inserted
5486 col 1
5487 When lines are deleted the values are:
5488 lnum the first deleted line
5489 end the line below the first deleted line, before
5490 the deletion was done
5491 added negative, number of lines deleted
5492 col 1
5493 When lines are changed:
5494 lnum the first changed line
5495 end the line below the last changed line
5496 added 0
5497 col first column with a change or 1
5498
5499 The entries are in the order the changes were made, thus the
5500 most recent change is at the end. The line numbers are valid
5501 when the callback is invoked, but later changes may make them
5502 invalid, thus keeping a copy for later might not work.
5503
5504 The {callback} is invoked just before the screen is updated,
5505 when |listener_flush()| is called or when a change is being
5506 made that changes the line count in a way it causes a line
5507 number in the list of changes to become invalid.
5508
5509 The {callback} is invoked with the text locked, see
5510 |textlock|. If you do need to make changes to the buffer, use
5511 a timer to do this later |timer_start()|.
5512
5513 The {callback} is not invoked when the buffer is first loaded.
5514 Use the |BufReadPost| autocmd event to handle the initial text
5515 of a buffer.
5516 The {callback} is also not invoked when the buffer is
5517 unloaded, use the |BufUnload| autocmd event for that.
5518
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01005519 Returns zero if {callback} or {buf} is invalid.
5520
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005521 Can also be used as a |method|, the base is passed as the
5522 second argument: >
5523 GetBuffer()->listener_add(callback)
5524
5525listener_flush([{buf}]) *listener_flush()*
5526 Invoke listener callbacks for buffer {buf}. If there are no
5527 pending changes then no callbacks are invoked.
5528
5529 {buf} refers to a buffer name or number. For the accepted
5530 values, see |bufname()|. When {buf} is omitted the current
5531 buffer is used.
5532
5533 Can also be used as a |method|: >
5534 GetBuffer()->listener_flush()
5535
5536listener_remove({id}) *listener_remove()*
5537 Remove a listener previously added with listener_add().
5538 Returns FALSE when {id} could not be found, TRUE when {id} was
5539 removed.
5540
5541 Can also be used as a |method|: >
5542 GetListenerId()->listener_remove()
5543
5544localtime() *localtime()*
5545 Return the current time, measured as seconds since 1st Jan
5546 1970. See also |strftime()|, |strptime()| and |getftime()|.
5547
5548
5549log({expr}) *log()*
5550 Return the natural logarithm (base e) of {expr} as a |Float|.
5551 {expr} must evaluate to a |Float| or a |Number| in the range
5552 (0, inf].
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01005553 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005554 Examples: >
5555 :echo log(10)
5556< 2.302585 >
5557 :echo log(exp(5))
5558< 5.0
5559
5560 Can also be used as a |method|: >
5561 Compute()->log()
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005562
5563
5564log10({expr}) *log10()*
5565 Return the logarithm of Float {expr} to base 10 as a |Float|.
5566 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01005567 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005568 Examples: >
5569 :echo log10(1000)
5570< 3.0 >
5571 :echo log10(0.01)
5572< -2.0
5573
5574 Can also be used as a |method|: >
5575 Compute()->log10()
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005576
5577luaeval({expr} [, {expr}]) *luaeval()*
5578 Evaluate Lua expression {expr} and return its result converted
5579 to Vim data structures. Second {expr} may hold additional
5580 argument accessible as _A inside first {expr}.
5581 Strings are returned as they are.
5582 Boolean objects are converted to numbers.
Bram Moolenaar73e28dc2022-09-17 21:08:33 +01005583 Numbers are converted to |Float| values.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005584 Dictionaries and lists obtained by vim.eval() are returned
5585 as-is.
5586 Other objects are returned as zero without any errors.
5587 See |lua-luaeval| for more details.
5588 Note that in a `:def` function local variables are not visible
5589 to {expr}.
5590
5591 Can also be used as a |method|: >
5592 GetExpr()->luaeval()
5593
5594< {only available when compiled with the |+lua| feature}
5595
5596map({expr1}, {expr2}) *map()*
5597 {expr1} must be a |List|, |String|, |Blob| or |Dictionary|.
Bram Moolenaar944697a2022-02-20 19:48:20 +00005598 When {expr1} is a |List| or |Dictionary|, replace each
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005599 item in {expr1} with the result of evaluating {expr2}.
5600 For a |Blob| each byte is replaced.
5601 For a |String|, each character, including composing
5602 characters, is replaced.
5603 If the item type changes you may want to use |mapnew()| to
5604 create a new List or Dictionary. This is required when using
5605 Vim9 script.
5606
5607 {expr2} must be a |String| or |Funcref|.
5608
5609 If {expr2} is a |String|, inside {expr2} |v:val| has the value
5610 of the current item. For a |Dictionary| |v:key| has the key
5611 of the current item and for a |List| |v:key| has the index of
5612 the current item. For a |Blob| |v:key| has the index of the
5613 current byte. For a |String| |v:key| has the index of the
5614 current character.
5615 Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00005616 :call map(mylist, '"> " .. v:val .. " <"')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005617< This puts "> " before and " <" after each item in "mylist".
5618
5619 Note that {expr2} is the result of an expression and is then
5620 used as an expression again. Often it is good to use a
5621 |literal-string| to avoid having to double backslashes. You
5622 still have to double ' quotes
5623
5624 If {expr2} is a |Funcref| it is called with two arguments:
5625 1. The key or the index of the current item.
5626 2. the value of the current item.
Bram Moolenaarb59ae592022-11-23 23:46:31 +00005627 With a legacy script lambda you don't get an error if it only
5628 accepts one argument, but with a Vim9 lambda you get "E1106:
5629 One argument too many", the number of arguments must match.
5630
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005631 The function must return the new value of the item. Example
5632 that changes each value by "key-value": >
5633 func KeyValue(key, val)
Bram Moolenaarc51cf032022-02-26 12:25:45 +00005634 return a:key .. '-' .. a:val
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005635 endfunc
5636 call map(myDict, function('KeyValue'))
5637< It is shorter when using a |lambda|: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00005638 call map(myDict, {key, val -> key .. '-' .. val})
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005639< If you do not use "val" you can leave it out: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00005640 call map(myDict, {key -> 'item: ' .. key})
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005641< If you do not use "key" you can use a short name: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00005642 call map(myDict, {_, val -> 'item: ' .. val})
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005643<
5644 The operation is done in-place for a |List| and |Dictionary|.
5645 If you want it to remain unmodified make a copy first: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00005646 :let tlist = map(copy(mylist), ' v:val .. "\t"')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005647
5648< Returns {expr1}, the |List| or |Dictionary| that was filtered,
5649 or a new |Blob| or |String|.
5650 When an error is encountered while evaluating {expr2} no
5651 further items in {expr1} are processed.
5652 When {expr2} is a Funcref errors inside a function are ignored,
5653 unless it was defined with the "abort" flag.
5654
5655 Can also be used as a |method|: >
5656 mylist->map(expr2)
5657
5658
5659maparg({name} [, {mode} [, {abbr} [, {dict}]]]) *maparg()*
5660 When {dict} is omitted or zero: Return the rhs of mapping
5661 {name} in mode {mode}. The returned String has special
5662 characters translated like in the output of the ":map" command
Ernie Rael09661202022-04-25 14:40:44 +01005663 listing. When {dict} is TRUE a dictionary is returned, see
5664 below. To get a list of all mappings see |maplist()|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005665
5666 When there is no mapping for {name}, an empty String is
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01005667 returned if {dict} is FALSE, otherwise returns an empty Dict.
5668 When the mapping for {name} is empty, then "<Nop>" is
5669 returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005670
5671 The {name} can have special key names, like in the ":map"
5672 command.
5673
5674 {mode} can be one of these strings:
5675 "n" Normal
5676 "v" Visual (including Select)
5677 "o" Operator-pending
5678 "i" Insert
5679 "c" Cmd-line
5680 "s" Select
5681 "x" Visual
5682 "l" langmap |language-mapping|
5683 "t" Terminal-Job
5684 "" Normal, Visual and Operator-pending
5685 When {mode} is omitted, the modes for "" are used.
5686
5687 When {abbr} is there and it is |TRUE| use abbreviations
5688 instead of mappings.
5689
5690 When {dict} is there and it is |TRUE| return a dictionary
5691 containing all the information of the mapping with the
Ernie Rael659c2402022-04-24 18:40:28 +01005692 following items: *mapping-dict*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005693 "lhs" The {lhs} of the mapping as it would be typed
5694 "lhsraw" The {lhs} of the mapping as raw bytes
5695 "lhsrawalt" The {lhs} of the mapping as raw bytes, alternate
5696 form, only present when it differs from "lhsraw"
5697 "rhs" The {rhs} of the mapping as typed.
5698 "silent" 1 for a |:map-silent| mapping, else 0.
5699 "noremap" 1 if the {rhs} of the mapping is not remappable.
5700 "script" 1 if mapping was defined with <script>.
5701 "expr" 1 for an expression mapping (|:map-<expr>|).
5702 "buffer" 1 for a buffer local mapping (|:map-local|).
5703 "mode" Modes for which the mapping is defined. In
5704 addition to the modes mentioned above, these
5705 characters will be used:
5706 " " Normal, Visual and Operator-pending
5707 "!" Insert and Commandline mode
5708 (|mapmode-ic|)
5709 "sid" The script local ID, used for <sid> mappings
Bram Moolenaar71badf92023-04-22 22:40:14 +01005710 (|<SID>|). Negative for special contexts.
Bram Moolenaara9528b32022-01-18 20:51:35 +00005711 "scriptversion" The version of the script. 999999 for
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01005712 |Vim9| script.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005713 "lnum" The line number in "sid", zero if unknown.
5714 "nowait" Do not wait for other, longer mappings.
5715 (|:map-<nowait>|).
Bram Moolenaar921bde82022-05-09 19:50:35 +01005716 "abbr" True if this is an abbreviation |abbreviations|.
Ernie Raeld8f5f762022-05-10 17:50:39 +01005717 "mode_bits" Vim's internal binary representation of "mode".
5718 |mapset()| ignores this; only "mode" is used.
5719 See |maplist()| for usage examples. The values
5720 are from src/vim.h and may change in the future.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005721
5722 The dictionary can be used to restore a mapping with
5723 |mapset()|.
5724
5725 The mappings local to the current buffer are checked first,
5726 then the global mappings.
5727 This function can be used to map a key even when it's already
5728 mapped, and have it do the original mapping too. Sketch: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00005729 exe 'nnoremap <Tab> ==' .. maparg('<Tab>', 'n')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005730
5731< Can also be used as a |method|: >
5732 GetKey()->maparg('n')
5733
5734mapcheck({name} [, {mode} [, {abbr}]]) *mapcheck()*
5735 Check if there is a mapping that matches with {name} in mode
5736 {mode}. See |maparg()| for {mode} and special names in
5737 {name}.
5738 When {abbr} is there and it is |TRUE| use abbreviations
5739 instead of mappings.
5740 A match happens with a mapping that starts with {name} and
5741 with a mapping which is equal to the start of {name}.
5742
5743 matches mapping "a" "ab" "abc" ~
5744 mapcheck("a") yes yes yes
5745 mapcheck("abc") yes yes yes
5746 mapcheck("ax") yes no no
5747 mapcheck("b") no no no
5748
5749 The difference with maparg() is that mapcheck() finds a
5750 mapping that matches with {name}, while maparg() only finds a
5751 mapping for {name} exactly.
5752 When there is no mapping that starts with {name}, an empty
5753 String is returned. If there is one, the RHS of that mapping
5754 is returned. If there are several mappings that start with
5755 {name}, the RHS of one of them is returned. This will be
5756 "<Nop>" if the RHS is empty.
5757 The mappings local to the current buffer are checked first,
5758 then the global mappings.
5759 This function can be used to check if a mapping can be added
5760 without being ambiguous. Example: >
5761 :if mapcheck("_vv") == ""
5762 : map _vv :set guifont=7x13<CR>
5763 :endif
5764< This avoids adding the "_vv" mapping when there already is a
5765 mapping for "_v" or for "_vvv".
5766
5767 Can also be used as a |method|: >
5768 GetKey()->mapcheck('n')
5769
5770
Ernie Rael09661202022-04-25 14:40:44 +01005771maplist([{abbr}]) *maplist()*
5772 Returns a |List| of all mappings. Each List item is a |Dict|,
5773 the same as what is returned by |maparg()|, see
5774 |mapping-dict|. When {abbr} is there and it is |TRUE| use
5775 abbreviations instead of mappings.
5776
5777 Example to show all mappings with 'MultiMatch' in rhs: >
5778 vim9script
5779 echo maplist()->filter(
5780 (_, m) => match(m.rhs, 'MultiMatch') >= 0)
Ernie Raeld8f5f762022-05-10 17:50:39 +01005781< It can be tricky to find mappings for particular |:map-modes|.
5782 |mapping-dict|'s "mode_bits" can simplify this. For example,
5783 the mode_bits for Normal, Insert or Command-line modes are
5784 0x19. To find all the mappings available in those modes you
5785 can do: >
5786 vim9script
5787 var saved_maps = []
5788 for m in maplist()
5789 if and(m.mode_bits, 0x19) != 0
5790 saved_maps->add(m)
5791 endif
5792 endfor
5793 echo saved_maps->mapnew((_, m) => m.lhs)
5794< The values of the mode_bits are defined in Vim's src/vim.h
5795 file and they can be discovered at runtime using
5796 |:map-commands| and "maplist()". Example: >
5797 vim9script
5798 omap xyzzy <Nop>
5799 var op_bit = maplist()->filter(
5800 (_, m) => m.lhs == 'xyzzy')[0].mode_bits
5801 ounmap xyzzy
5802 echo printf("Operator-pending mode bit: 0x%x", op_bit)
Ernie Rael09661202022-04-25 14:40:44 +01005803
5804
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005805mapnew({expr1}, {expr2}) *mapnew()*
5806 Like |map()| but instead of replacing items in {expr1} a new
5807 List or Dictionary is created and returned. {expr1} remains
5808 unchanged. Items can still be changed by {expr2}, if you
5809 don't want that use |deepcopy()| first.
5810
5811
5812mapset({mode}, {abbr}, {dict}) *mapset()*
Ernie Rael51d04d12022-05-04 15:40:22 +01005813mapset({dict})
5814 Restore a mapping from a dictionary, possibly returned by
5815 |maparg()| or |maplist()|. A buffer mapping, when dict.buffer
5816 is true, is set on the current buffer; it is up to the caller
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01005817 to ensure that the intended buffer is the current buffer. This
Ernie Rael51d04d12022-05-04 15:40:22 +01005818 feature allows copying mappings from one buffer to another.
5819 The dict.mode value may restore a single mapping that covers
5820 more than one mode, like with mode values of '!', ' ', 'nox',
5821 or 'v'. *E1276*
5822
5823 In the first form, {mode} and {abbr} should be the same as
5824 for the call to |maparg()|. *E460*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005825 {mode} is used to define the mode in which the mapping is set,
5826 not the "mode" entry in {dict}.
5827 Example for saving and restoring a mapping: >
5828 let save_map = maparg('K', 'n', 0, 1)
5829 nnoremap K somethingelse
5830 ...
5831 call mapset('n', 0, save_map)
5832< Note that if you are going to replace a map in several modes,
Ernie Rael51d04d12022-05-04 15:40:22 +01005833 e.g. with `:map!`, you need to save/restore the mapping for
5834 all of them, when they might differ.
5835
5836 In the second form, with {dict} as the only argument, mode
5837 and abbr are taken from the dict.
5838 Example: >
5839 vim9script
5840 var save_maps = maplist()->filter(
5841 (_, m) => m.lhs == 'K')
5842 nnoremap K somethingelse
5843 cnoremap K somethingelse2
5844 # ...
5845 unmap K
5846 for d in save_maps
5847 mapset(d)
5848 endfor
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005849
5850
5851match({expr}, {pat} [, {start} [, {count}]]) *match()*
5852 When {expr} is a |List| then this returns the index of the
5853 first item where {pat} matches. Each item is used as a
5854 String, |Lists| and |Dictionaries| are used as echoed.
5855
5856 Otherwise, {expr} is used as a String. The result is a
5857 Number, which gives the index (byte offset) in {expr} where
5858 {pat} matches.
5859
5860 A match at the first character or |List| item returns zero.
5861 If there is no match -1 is returned.
5862
5863 For getting submatches see |matchlist()|.
5864 Example: >
5865 :echo match("testing", "ing") " results in 4
5866 :echo match([1, 'x'], '\a') " results in 1
5867< See |string-match| for how {pat} is used.
5868 *strpbrk()*
5869 Vim doesn't have a strpbrk() function. But you can do: >
5870 :let sepidx = match(line, '[.,;: \t]')
5871< *strcasestr()*
5872 Vim doesn't have a strcasestr() function. But you can add
5873 "\c" to the pattern to ignore case: >
5874 :let idx = match(haystack, '\cneedle')
5875<
5876 If {start} is given, the search starts from byte index
5877 {start} in a String or item {start} in a |List|.
5878 The result, however, is still the index counted from the
5879 first character/item. Example: >
5880 :echo match("testing", "ing", 2)
5881< result is again "4". >
5882 :echo match("testing", "ing", 4)
5883< result is again "4". >
5884 :echo match("testing", "t", 2)
5885< result is "3".
5886 For a String, if {start} > 0 then it is like the string starts
5887 {start} bytes later, thus "^" will match at {start}. Except
5888 when {count} is given, then it's like matches before the
5889 {start} byte are ignored (this is a bit complicated to keep it
5890 backwards compatible).
5891 For a String, if {start} < 0, it will be set to 0. For a list
5892 the index is counted from the end.
5893 If {start} is out of range ({start} > strlen({expr}) for a
5894 String or {start} > len({expr}) for a |List|) -1 is returned.
5895
5896 When {count} is given use the {count}'th match. When a match
5897 is found in a String the search for the next one starts one
5898 character further. Thus this example results in 1: >
5899 echo match("testing", "..", 0, 2)
5900< In a |List| the search continues in the next item.
5901 Note that when {count} is added the way {start} works changes,
5902 see above.
5903
5904 See |pattern| for the patterns that are accepted.
5905 The 'ignorecase' option is used to set the ignore-caseness of
5906 the pattern. 'smartcase' is NOT used. The matching is always
5907 done like 'magic' is set and 'cpoptions' is empty.
5908 Note that a match at the start is preferred, thus when the
5909 pattern is using "*" (any number of matches) it tends to find
5910 zero matches at the start instead of a number of matches
5911 further down in the text.
5912
5913 Can also be used as a |method|: >
5914 GetText()->match('word')
5915 GetList()->match('word')
5916<
Bram Moolenaar2f0936c2022-01-08 21:51:59 +00005917 *matchadd()* *E290* *E798* *E799* *E801* *E957*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005918matchadd({group}, {pattern} [, {priority} [, {id} [, {dict}]]])
5919 Defines a pattern to be highlighted in the current window (a
5920 "match"). It will be highlighted with {group}. Returns an
5921 identification number (ID), which can be used to delete the
5922 match using |matchdelete()|. The ID is bound to the window.
5923 Matching is case sensitive and magic, unless case sensitivity
5924 or magicness are explicitly overridden in {pattern}. The
5925 'magic', 'smartcase' and 'ignorecase' options are not used.
5926 The "Conceal" value is special, it causes the match to be
5927 concealed.
5928
5929 The optional {priority} argument assigns a priority to the
5930 match. A match with a high priority will have its
5931 highlighting overrule that of a match with a lower priority.
5932 A priority is specified as an integer (negative numbers are no
5933 exception). If the {priority} argument is not specified, the
5934 default priority is 10. The priority of 'hlsearch' is zero,
5935 hence all matches with a priority greater than zero will
5936 overrule it. Syntax highlighting (see 'syntax') is a separate
5937 mechanism, and regardless of the chosen priority a match will
5938 always overrule syntax highlighting.
5939
5940 The optional {id} argument allows the request for a specific
5941 match ID. If a specified ID is already taken, an error
5942 message will appear and the match will not be added. An ID
5943 is specified as a positive integer (zero excluded). IDs 1, 2
5944 and 3 are reserved for |:match|, |:2match| and |:3match|,
Bram Moolenaar2ecbe532022-07-29 21:36:21 +01005945 respectively. 3 is reserved for use by the |matchparen|
5946 plugin.
Bram Moolenaarb529cfb2022-07-25 15:42:07 +01005947 If the {id} argument is not specified or -1, |matchadd()|
Bram Moolenaar9f573a82022-09-29 13:50:08 +01005948 automatically chooses a free ID, which is at least 1000.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005949
5950 The optional {dict} argument allows for further custom
5951 values. Currently this is used to specify a match specific
5952 conceal character that will be shown for |hl-Conceal|
5953 highlighted matches. The dict can have the following members:
5954
5955 conceal Special character to show instead of the
5956 match (only for |hl-Conceal| highlighted
5957 matches, see |:syn-cchar|)
5958 window Instead of the current window use the
5959 window with this number or window ID.
5960
5961 The number of matches is not limited, as it is the case with
5962 the |:match| commands.
5963
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01005964 Returns -1 on error.
5965
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005966 Example: >
5967 :highlight MyGroup ctermbg=green guibg=green
5968 :let m = matchadd("MyGroup", "TODO")
5969< Deletion of the pattern: >
5970 :call matchdelete(m)
5971
5972< A list of matches defined by |matchadd()| and |:match| are
5973 available from |getmatches()|. All matches can be deleted in
5974 one operation by |clearmatches()|.
5975
5976 Can also be used as a |method|: >
5977 GetGroup()->matchadd('TODO')
5978<
5979 *matchaddpos()*
5980matchaddpos({group}, {pos} [, {priority} [, {id} [, {dict}]]])
5981 Same as |matchadd()|, but requires a list of positions {pos}
5982 instead of a pattern. This command is faster than |matchadd()|
5983 because it does not require to handle regular expressions and
5984 sets buffer line boundaries to redraw screen. It is supposed
5985 to be used when fast match additions and deletions are
5986 required, for example to highlight matching parentheses.
5987
5988 {pos} is a list of positions. Each position can be one of
5989 these:
5990 - A number. This whole line will be highlighted. The first
5991 line has number 1.
5992 - A list with one number, e.g., [23]. The whole line with this
5993 number will be highlighted.
5994 - A list with two numbers, e.g., [23, 11]. The first number is
5995 the line number, the second one is the column number (first
5996 column is 1, the value must correspond to the byte index as
5997 |col()| would return). The character at this position will
5998 be highlighted.
5999 - A list with three numbers, e.g., [23, 11, 3]. As above, but
6000 the third number gives the length of the highlight in bytes.
6001
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01006002 Returns -1 on error.
6003
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006004 Example: >
6005 :highlight MyGroup ctermbg=green guibg=green
6006 :let m = matchaddpos("MyGroup", [[23, 24], 34])
6007< Deletion of the pattern: >
6008 :call matchdelete(m)
6009
6010< Matches added by |matchaddpos()| are returned by
6011 |getmatches()|.
6012
6013 Can also be used as a |method|: >
6014 GetGroup()->matchaddpos([23, 11])
6015
6016matcharg({nr}) *matcharg()*
6017 Selects the {nr} match item, as set with a |:match|,
6018 |:2match| or |:3match| command.
6019 Return a |List| with two elements:
6020 The name of the highlight group used
6021 The pattern used.
6022 When {nr} is not 1, 2 or 3 returns an empty |List|.
6023 When there is no match item set returns ['', ''].
6024 This is useful to save and restore a |:match|.
6025 Highlighting matches using the |:match| commands are limited
6026 to three matches. |matchadd()| does not have this limitation.
6027
6028 Can also be used as a |method|: >
6029 GetMatch()->matcharg()
6030
6031matchdelete({id} [, {win}) *matchdelete()* *E802* *E803*
6032 Deletes a match with ID {id} previously defined by |matchadd()|
6033 or one of the |:match| commands. Returns 0 if successful,
6034 otherwise -1. See example for |matchadd()|. All matches can
6035 be deleted in one operation by |clearmatches()|.
6036 If {win} is specified, use the window with this number or
6037 window ID instead of the current window.
6038
6039 Can also be used as a |method|: >
6040 GetMatch()->matchdelete()
6041
6042matchend({expr}, {pat} [, {start} [, {count}]]) *matchend()*
6043 Same as |match()|, but return the index of first character
6044 after the match. Example: >
6045 :echo matchend("testing", "ing")
6046< results in "7".
6047 *strspn()* *strcspn()*
6048 Vim doesn't have a strspn() or strcspn() function, but you can
6049 do it with matchend(): >
6050 :let span = matchend(line, '[a-zA-Z]')
6051 :let span = matchend(line, '[^a-zA-Z]')
6052< Except that -1 is returned when there are no matches.
6053
6054 The {start}, if given, has the same meaning as for |match()|. >
6055 :echo matchend("testing", "ing", 2)
6056< results in "7". >
6057 :echo matchend("testing", "ing", 5)
6058< result is "-1".
6059 When {expr} is a |List| the result is equal to |match()|.
6060
6061 Can also be used as a |method|: >
6062 GetText()->matchend('word')
6063
6064
6065matchfuzzy({list}, {str} [, {dict}]) *matchfuzzy()*
6066 If {list} is a list of strings, then returns a |List| with all
6067 the strings in {list} that fuzzy match {str}. The strings in
6068 the returned list are sorted based on the matching score.
6069
6070 The optional {dict} argument always supports the following
6071 items:
zeertzjq9af2bc02022-05-11 14:15:37 +01006072 matchseq When this item is present return only matches
6073 that contain the characters in {str} in the
6074 given sequence.
Kazuyuki Miyagi47f1a552022-06-17 18:30:03 +01006075 limit Maximum number of matches in {list} to be
6076 returned. Zero means no limit.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006077
6078 If {list} is a list of dictionaries, then the optional {dict}
6079 argument supports the following additional items:
Yasuhiro Matsumoto9029a6e2022-04-16 12:35:35 +01006080 key Key of the item which is fuzzy matched against
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006081 {str}. The value of this item should be a
6082 string.
6083 text_cb |Funcref| that will be called for every item
6084 in {list} to get the text for fuzzy matching.
6085 This should accept a dictionary item as the
6086 argument and return the text for that item to
6087 use for fuzzy matching.
6088
6089 {str} is treated as a literal string and regular expression
6090 matching is NOT supported. The maximum supported {str} length
6091 is 256.
6092
6093 When {str} has multiple words each separated by white space,
6094 then the list of strings that have all the words is returned.
6095
6096 If there are no matching strings or there is an error, then an
6097 empty list is returned. If length of {str} is greater than
6098 256, then returns an empty list.
6099
Yasuhiro Matsumoto9029a6e2022-04-16 12:35:35 +01006100 When {limit} is given, matchfuzzy() will find up to this
6101 number of matches in {list} and return them in sorted order.
6102
Bram Moolenaar1588bc82022-03-08 21:35:07 +00006103 Refer to |fuzzy-matching| for more information about fuzzy
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006104 matching strings.
6105
6106 Example: >
6107 :echo matchfuzzy(["clay", "crow"], "cay")
6108< results in ["clay"]. >
6109 :echo getbufinfo()->map({_, v -> v.name})->matchfuzzy("ndl")
6110< results in a list of buffer names fuzzy matching "ndl". >
6111 :echo getbufinfo()->matchfuzzy("ndl", {'key' : 'name'})
6112< results in a list of buffer information dicts with buffer
6113 names fuzzy matching "ndl". >
6114 :echo getbufinfo()->matchfuzzy("spl",
6115 \ {'text_cb' : {v -> v.name}})
6116< results in a list of buffer information dicts with buffer
6117 names fuzzy matching "spl". >
6118 :echo v:oldfiles->matchfuzzy("test")
6119< results in a list of file names fuzzy matching "test". >
6120 :let l = readfile("buffer.c")->matchfuzzy("str")
6121< results in a list of lines in "buffer.c" fuzzy matching "str". >
6122 :echo ['one two', 'two one']->matchfuzzy('two one')
6123< results in ['two one', 'one two']. >
6124 :echo ['one two', 'two one']->matchfuzzy('two one',
6125 \ {'matchseq': 1})
6126< results in ['two one'].
6127
6128matchfuzzypos({list}, {str} [, {dict}]) *matchfuzzypos()*
6129 Same as |matchfuzzy()|, but returns the list of matched
6130 strings, the list of character positions where characters
6131 in {str} matches and a list of matching scores. You can
6132 use |byteidx()| to convert a character position to a byte
6133 position.
6134
6135 If {str} matches multiple times in a string, then only the
6136 positions for the best match is returned.
6137
6138 If there are no matching strings or there is an error, then a
6139 list with three empty list items is returned.
6140
6141 Example: >
6142 :echo matchfuzzypos(['testing'], 'tsg')
6143< results in [['testing'], [[0, 2, 6]], [99]] >
6144 :echo matchfuzzypos(['clay', 'lacy'], 'la')
6145< results in [['lacy', 'clay'], [[0, 1], [1, 2]], [153, 133]] >
6146 :echo [{'text': 'hello', 'id' : 10}]->matchfuzzypos('ll', {'key' : 'text'})
6147< results in [[{'id': 10, 'text': 'hello'}], [[2, 3]], [127]]
6148
6149matchlist({expr}, {pat} [, {start} [, {count}]]) *matchlist()*
6150 Same as |match()|, but return a |List|. The first item in the
6151 list is the matched string, same as what matchstr() would
6152 return. Following items are submatches, like "\1", "\2", etc.
6153 in |:substitute|. When an optional submatch didn't match an
6154 empty string is used. Example: >
6155 echo matchlist('acd', '\(a\)\?\(b\)\?\(c\)\?\(.*\)')
6156< Results in: ['acd', 'a', '', 'c', 'd', '', '', '', '', '']
6157 When there is no match an empty list is returned.
6158
6159 You can pass in a List, but that is not very useful.
6160
6161 Can also be used as a |method|: >
6162 GetText()->matchlist('word')
6163
6164matchstr({expr}, {pat} [, {start} [, {count}]]) *matchstr()*
6165 Same as |match()|, but return the matched string. Example: >
6166 :echo matchstr("testing", "ing")
6167< results in "ing".
6168 When there is no match "" is returned.
6169 The {start}, if given, has the same meaning as for |match()|. >
6170 :echo matchstr("testing", "ing", 2)
6171< results in "ing". >
6172 :echo matchstr("testing", "ing", 5)
6173< result is "".
6174 When {expr} is a |List| then the matching item is returned.
6175 The type isn't changed, it's not necessarily a String.
6176
6177 Can also be used as a |method|: >
6178 GetText()->matchstr('word')
6179
6180matchstrpos({expr}, {pat} [, {start} [, {count}]]) *matchstrpos()*
6181 Same as |matchstr()|, but return the matched string, the start
6182 position and the end position of the match. Example: >
6183 :echo matchstrpos("testing", "ing")
6184< results in ["ing", 4, 7].
6185 When there is no match ["", -1, -1] is returned.
6186 The {start}, if given, has the same meaning as for |match()|. >
6187 :echo matchstrpos("testing", "ing", 2)
6188< results in ["ing", 4, 7]. >
6189 :echo matchstrpos("testing", "ing", 5)
6190< result is ["", -1, -1].
6191 When {expr} is a |List| then the matching item, the index
6192 of first item where {pat} matches, the start position and the
6193 end position of the match are returned. >
6194 :echo matchstrpos([1, '__x'], '\a')
6195< result is ["x", 1, 2, 3].
6196 The type isn't changed, it's not necessarily a String.
6197
6198 Can also be used as a |method|: >
6199 GetText()->matchstrpos('word')
6200<
6201
6202 *max()*
6203max({expr}) Return the maximum value of all items in {expr}. Example: >
6204 echo max([apples, pears, oranges])
6205
6206< {expr} can be a |List| or a |Dictionary|. For a Dictionary,
6207 it returns the maximum of all values in the Dictionary.
6208 If {expr} is neither a List nor a Dictionary, or one of the
6209 items in {expr} cannot be used as a Number this results in
6210 an error. An empty |List| or |Dictionary| results in zero.
6211
6212 Can also be used as a |method|: >
6213 mylist->max()
6214
6215
6216menu_info({name} [, {mode}]) *menu_info()*
6217 Return information about the specified menu {name} in
6218 mode {mode}. The menu name should be specified without the
6219 shortcut character ('&'). If {name} is "", then the top-level
6220 menu names are returned.
6221
6222 {mode} can be one of these strings:
6223 "n" Normal
6224 "v" Visual (including Select)
6225 "o" Operator-pending
6226 "i" Insert
6227 "c" Cmd-line
6228 "s" Select
6229 "x" Visual
6230 "t" Terminal-Job
6231 "" Normal, Visual and Operator-pending
6232 "!" Insert and Cmd-line
6233 When {mode} is omitted, the modes for "" are used.
6234
6235 Returns a |Dictionary| containing the following items:
6236 accel menu item accelerator text |menu-text|
6237 display display name (name without '&')
6238 enabled v:true if this menu item is enabled
6239 Refer to |:menu-enable|
6240 icon name of the icon file (for toolbar)
6241 |toolbar-icon|
6242 iconidx index of a built-in icon
6243 modes modes for which the menu is defined. In
6244 addition to the modes mentioned above, these
6245 characters will be used:
6246 " " Normal, Visual and Operator-pending
6247 name menu item name.
6248 noremenu v:true if the {rhs} of the menu item is not
6249 remappable else v:false.
6250 priority menu order priority |menu-priority|
6251 rhs right-hand-side of the menu item. The returned
6252 string has special characters translated like
6253 in the output of the ":menu" command listing.
6254 When the {rhs} of a menu item is empty, then
6255 "<Nop>" is returned.
6256 script v:true if script-local remapping of {rhs} is
6257 allowed else v:false. See |:menu-script|.
6258 shortcut shortcut key (character after '&' in
6259 the menu name) |menu-shortcut|
6260 silent v:true if the menu item is created
6261 with <silent> argument |:menu-silent|
6262 submenus |List| containing the names of
6263 all the submenus. Present only if the menu
6264 item has submenus.
6265
6266 Returns an empty dictionary if the menu item is not found.
6267
6268 Examples: >
6269 :echo menu_info('Edit.Cut')
6270 :echo menu_info('File.Save', 'n')
6271
6272 " Display the entire menu hierarchy in a buffer
6273 func ShowMenu(name, pfx)
6274 let m = menu_info(a:name)
6275 call append(line('$'), a:pfx .. m.display)
6276 for child in m->get('submenus', [])
6277 call ShowMenu(a:name .. '.' .. escape(child, '.'),
6278 \ a:pfx .. ' ')
6279 endfor
6280 endfunc
6281 new
6282 for topmenu in menu_info('').submenus
6283 call ShowMenu(topmenu, '')
6284 endfor
6285<
6286 Can also be used as a |method|: >
6287 GetMenuName()->menu_info('v')
6288
6289
6290< *min()*
6291min({expr}) Return the minimum value of all items in {expr}. Example: >
6292 echo min([apples, pears, oranges])
6293
6294< {expr} can be a |List| or a |Dictionary|. For a Dictionary,
6295 it returns the minimum of all values in the Dictionary.
6296 If {expr} is neither a List nor a Dictionary, or one of the
6297 items in {expr} cannot be used as a Number this results in
6298 an error. An empty |List| or |Dictionary| results in zero.
6299
6300 Can also be used as a |method|: >
6301 mylist->min()
6302
6303< *mkdir()* *E739*
Bram Moolenaar938ae282023-02-20 20:44:55 +00006304mkdir({name} [, {flags} [, {prot}]])
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006305 Create directory {name}.
6306
Bram Moolenaar938ae282023-02-20 20:44:55 +00006307 When {flags} is present it must be a string. An empty string
6308 has no effect.
Bram Moolenaar6f14da12022-09-07 21:30:44 +01006309
Bram Moolenaar938ae282023-02-20 20:44:55 +00006310 If {flags} contains "p" then intermediate directories are
6311 created as necessary.
6312
6313 If {flags} contains "D" then {name} is deleted at the end of
Bram Moolenaar6f14da12022-09-07 21:30:44 +01006314 the current function, as with: >
6315 defer delete({name}, 'd')
6316<
Bram Moolenaar938ae282023-02-20 20:44:55 +00006317 If {flags} contains "R" then {name} is deleted recursively at
Bram Moolenaar6f14da12022-09-07 21:30:44 +01006318 the end of the current function, as with: >
6319 defer delete({name}, 'rf')
6320< Note that when {name} has more than one part and "p" is used
6321 some directories may already exist. Only the first one that
6322 is created and what it contains is scheduled to be deleted.
6323 E.g. when using: >
6324 call mkdir('subdir/tmp/autoload', 'pR')
6325< and "subdir" already exists then "subdir/tmp" will be
6326 scheduled for deletion, like with: >
6327 defer delete('subdir/tmp', 'rf')
6328< Note that if scheduling the defer fails the directory is not
6329 deleted. This should only happen when out of memory.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006330
6331 If {prot} is given it is used to set the protection bits of
6332 the new directory. The default is 0o755 (rwxr-xr-x: r/w for
6333 the user, readable for others). Use 0o700 to make it
6334 unreadable for others. This is only used for the last part of
6335 {name}. Thus if you create /tmp/foo/bar then /tmp/foo will be
6336 created with 0o755.
6337 Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00006338 :call mkdir($HOME .. "/tmp/foo/bar", "p", 0o700)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006339
6340< This function is not available in the |sandbox|.
6341
6342 There is no error if the directory already exists and the "p"
6343 flag is passed (since patch 8.0.1708). However, without the
6344 "p" option the call will fail.
6345
6346 The function result is a Number, which is TRUE if the call was
6347 successful or FALSE if the directory creation failed or partly
6348 failed.
6349
6350 Not available on all systems. To check use: >
6351 :if exists("*mkdir")
6352
6353< Can also be used as a |method|: >
6354 GetName()->mkdir()
6355<
6356 *mode()*
6357mode([expr]) Return a string that indicates the current mode.
6358 If [expr] is supplied and it evaluates to a non-zero Number or
6359 a non-empty String (|non-zero-arg|), then the full mode is
6360 returned, otherwise only the first letter is returned.
6361 Also see |state()|.
6362
6363 n Normal
6364 no Operator-pending
6365 nov Operator-pending (forced characterwise |o_v|)
6366 noV Operator-pending (forced linewise |o_V|)
6367 noCTRL-V Operator-pending (forced blockwise |o_CTRL-V|);
6368 CTRL-V is one character
6369 niI Normal using |i_CTRL-O| in |Insert-mode|
6370 niR Normal using |i_CTRL-O| in |Replace-mode|
6371 niV Normal using |i_CTRL-O| in |Virtual-Replace-mode|
6372 nt Terminal-Normal (insert goes to Terminal-Job mode)
6373 v Visual by character
6374 vs Visual by character using |v_CTRL-O| in Select mode
6375 V Visual by line
6376 Vs Visual by line using |v_CTRL-O| in Select mode
6377 CTRL-V Visual blockwise
6378 CTRL-Vs Visual blockwise using |v_CTRL-O| in Select mode
6379 s Select by character
6380 S Select by line
6381 CTRL-S Select blockwise
6382 i Insert
6383 ic Insert mode completion |compl-generic|
6384 ix Insert mode |i_CTRL-X| completion
6385 R Replace |R|
6386 Rc Replace mode completion |compl-generic|
6387 Rx Replace mode |i_CTRL-X| completion
6388 Rv Virtual Replace |gR|
6389 Rvc Virtual Replace mode completion |compl-generic|
6390 Rvx Virtual Replace mode |i_CTRL-X| completion
6391 c Command-line editing
6392 cv Vim Ex mode |gQ|
6393 ce Normal Ex mode |Q|
6394 r Hit-enter prompt
6395 rm The -- more -- prompt
6396 r? A |:confirm| query of some sort
6397 ! Shell or external command is executing
6398 t Terminal-Job mode: keys go to the job
6399
6400 This is useful in the 'statusline' option or when used
6401 with |remote_expr()| In most other places it always returns
6402 "c" or "n".
6403 Note that in the future more modes and more specific modes may
6404 be added. It's better not to compare the whole string but only
6405 the leading character(s).
6406 Also see |visualmode()|.
6407
6408 Can also be used as a |method|: >
6409 DoFull()->mode()
6410
6411mzeval({expr}) *mzeval()*
6412 Evaluate MzScheme expression {expr} and return its result
6413 converted to Vim data structures.
6414 Numbers and strings are returned as they are.
6415 Pairs (including lists and improper lists) and vectors are
6416 returned as Vim |Lists|.
6417 Hash tables are represented as Vim |Dictionary| type with keys
6418 converted to strings.
6419 All other types are converted to string with display function.
6420 Examples: >
6421 :mz (define l (list 1 2 3))
6422 :mz (define h (make-hash)) (hash-set! h "list" l)
6423 :echo mzeval("l")
6424 :echo mzeval("h")
6425<
6426 Note that in a `:def` function local variables are not visible
6427 to {expr}.
6428
6429 Can also be used as a |method|: >
6430 GetExpr()->mzeval()
6431<
6432 {only available when compiled with the |+mzscheme| feature}
6433
6434nextnonblank({lnum}) *nextnonblank()*
6435 Return the line number of the first line at or below {lnum}
6436 that is not blank. Example: >
6437 if getline(nextnonblank(1)) =~ "Java"
6438< When {lnum} is invalid or there is no non-blank line at or
6439 below it, zero is returned.
6440 {lnum} is used like with |getline()|.
6441 See also |prevnonblank()|.
6442
6443 Can also be used as a |method|: >
6444 GetLnum()->nextnonblank()
6445
6446nr2char({expr} [, {utf8}]) *nr2char()*
6447 Return a string with a single character, which has the number
6448 value {expr}. Examples: >
6449 nr2char(64) returns "@"
6450 nr2char(32) returns " "
6451< When {utf8} is omitted or zero, the current 'encoding' is used.
6452 Example for "utf-8": >
6453 nr2char(300) returns I with bow character
6454< When {utf8} is TRUE, always return UTF-8 characters.
6455 Note that a NUL character in the file is specified with
6456 nr2char(10), because NULs are represented with newline
6457 characters. nr2char(0) is a real NUL and terminates the
6458 string, thus results in an empty string.
6459 To turn a list of character numbers into a string: >
6460 let list = [65, 66, 67]
6461 let str = join(map(list, {_, val -> nr2char(val)}), '')
6462< Result: "ABC"
6463
6464 Can also be used as a |method|: >
6465 GetNumber()->nr2char()
6466
6467or({expr}, {expr}) *or()*
6468 Bitwise OR on the two arguments. The arguments are converted
6469 to a number. A List, Dict or Float argument causes an error.
Bram Moolenaar5a6ec102022-05-27 21:58:00 +01006470 Also see `and()` and `xor()`.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006471 Example: >
6472 :let bits = or(bits, 0x80)
6473< Can also be used as a |method|: >
6474 :let bits = bits->or(0x80)
6475
Bram Moolenaar5a6ec102022-05-27 21:58:00 +01006476< Rationale: The reason this is a function and not using the "|"
6477 character like many languages, is that Vi has always used "|"
6478 to separate commands. In many places it would not be clear if
6479 "|" is an operator or a command separator.
6480
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006481
6482pathshorten({path} [, {len}]) *pathshorten()*
6483 Shorten directory names in the path {path} and return the
6484 result. The tail, the file name, is kept as-is. The other
6485 components in the path are reduced to {len} letters in length.
6486 If {len} is omitted or smaller than 1 then 1 is used (single
6487 letters). Leading '~' and '.' characters are kept. Examples: >
6488 :echo pathshorten('~/.vim/autoload/myfile.vim')
6489< ~/.v/a/myfile.vim ~
6490>
6491 :echo pathshorten('~/.vim/autoload/myfile.vim', 2)
6492< ~/.vi/au/myfile.vim ~
6493 It doesn't matter if the path exists or not.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01006494 Returns an empty string on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006495
6496 Can also be used as a |method|: >
6497 GetDirectories()->pathshorten()
6498
6499perleval({expr}) *perleval()*
6500 Evaluate Perl expression {expr} in scalar context and return
6501 its result converted to Vim data structures. If value can't be
6502 converted, it is returned as a string Perl representation.
6503 Note: If you want an array or hash, {expr} must return a
6504 reference to it.
6505 Example: >
6506 :echo perleval('[1 .. 4]')
6507< [1, 2, 3, 4]
6508
6509 Note that in a `:def` function local variables are not visible
6510 to {expr}.
6511
6512 Can also be used as a |method|: >
6513 GetExpr()->perleval()
6514
6515< {only available when compiled with the |+perl| feature}
6516
6517
6518popup_ functions are documented here: |popup-functions|
6519
6520
6521pow({x}, {y}) *pow()*
6522 Return the power of {x} to the exponent {y} as a |Float|.
6523 {x} and {y} must evaluate to a |Float| or a |Number|.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01006524 Returns 0.0 if {x} or {y} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006525 Examples: >
6526 :echo pow(3, 3)
6527< 27.0 >
6528 :echo pow(2, 16)
6529< 65536.0 >
6530 :echo pow(32, 0.20)
6531< 2.0
6532
6533 Can also be used as a |method|: >
6534 Compute()->pow(3)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006535
6536prevnonblank({lnum}) *prevnonblank()*
6537 Return the line number of the first line at or above {lnum}
6538 that is not blank. Example: >
6539 let ind = indent(prevnonblank(v:lnum - 1))
6540< When {lnum} is invalid or there is no non-blank line at or
6541 above it, zero is returned.
6542 {lnum} is used like with |getline()|.
6543 Also see |nextnonblank()|.
6544
6545 Can also be used as a |method|: >
6546 GetLnum()->prevnonblank()
6547
6548printf({fmt}, {expr1} ...) *printf()*
6549 Return a String with {fmt}, where "%" items are replaced by
6550 the formatted form of their respective arguments. Example: >
6551 printf("%4d: E%d %.30s", lnum, errno, msg)
6552< May result in:
6553 " 99: E42 asdfasdfasdfasdfasdfasdfasdfas" ~
6554
6555 When used as a |method| the base is passed as the second
6556 argument: >
6557 Compute()->printf("result: %d")
Bram Moolenaarcbaff5e2022-04-08 17:45:08 +01006558<
6559 You can use `call()` to pass the items as a list.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006560
Bram Moolenaarcbaff5e2022-04-08 17:45:08 +01006561 Often used items are:
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006562 %s string
6563 %6S string right-aligned in 6 display cells
6564 %6s string right-aligned in 6 bytes
6565 %.9s string truncated to 9 bytes
6566 %c single byte
6567 %d decimal number
6568 %5d decimal number padded with spaces to 5 characters
6569 %x hex number
6570 %04x hex number padded with zeros to at least 4 characters
6571 %X hex number using upper case letters
6572 %o octal number
6573 %08b binary number padded with zeros to at least 8 chars
6574 %f floating point number as 12.23, inf, -inf or nan
6575 %F floating point number as 12.23, INF, -INF or NAN
6576 %e floating point number as 1.23e3, inf, -inf or nan
6577 %E floating point number as 1.23E3, INF, -INF or NAN
6578 %g floating point number, as %f or %e depending on value
6579 %G floating point number, as %F or %E depending on value
6580 %% the % character itself
6581
6582 Conversion specifications start with '%' and end with the
6583 conversion type. All other characters are copied unchanged to
6584 the result.
6585
6586 The "%" starts a conversion specification. The following
6587 arguments appear in sequence:
6588
6589 % [flags] [field-width] [.precision] type
6590
6591 flags
6592 Zero or more of the following flags:
6593
6594 # The value should be converted to an "alternate
6595 form". For c, d, and s conversions, this option
6596 has no effect. For o conversions, the precision
6597 of the number is increased to force the first
6598 character of the output string to a zero (except
6599 if a zero value is printed with an explicit
6600 precision of zero).
6601 For b and B conversions, a non-zero result has
6602 the string "0b" (or "0B" for B conversions)
6603 prepended to it.
6604 For x and X conversions, a non-zero result has
6605 the string "0x" (or "0X" for X conversions)
6606 prepended to it.
6607
6608 0 (zero) Zero padding. For all conversions the converted
6609 value is padded on the left with zeros rather
6610 than blanks. If a precision is given with a
6611 numeric conversion (d, b, B, o, x, and X), the 0
6612 flag is ignored.
6613
6614 - A negative field width flag; the converted value
6615 is to be left adjusted on the field boundary.
6616 The converted value is padded on the right with
6617 blanks, rather than on the left with blanks or
6618 zeros. A - overrides a 0 if both are given.
6619
6620 ' ' (space) A blank should be left before a positive
6621 number produced by a signed conversion (d).
6622
6623 + A sign must always be placed before a number
6624 produced by a signed conversion. A + overrides
6625 a space if both are used.
6626
6627 field-width
6628 An optional decimal digit string specifying a minimum
6629 field width. If the converted value has fewer bytes
6630 than the field width, it will be padded with spaces on
6631 the left (or right, if the left-adjustment flag has
6632 been given) to fill out the field width. For the S
6633 conversion the count is in cells.
6634
6635 .precision
6636 An optional precision, in the form of a period '.'
6637 followed by an optional digit string. If the digit
6638 string is omitted, the precision is taken as zero.
6639 This gives the minimum number of digits to appear for
6640 d, o, x, and X conversions, the maximum number of
6641 bytes to be printed from a string for s conversions,
6642 or the maximum number of cells to be printed from a
6643 string for S conversions.
6644 For floating point it is the number of digits after
6645 the decimal point.
6646
6647 type
6648 A character that specifies the type of conversion to
6649 be applied, see below.
6650
6651 A field width or precision, or both, may be indicated by an
6652 asterisk '*' instead of a digit string. In this case, a
6653 Number argument supplies the field width or precision. A
6654 negative field width is treated as a left adjustment flag
6655 followed by a positive field width; a negative precision is
6656 treated as though it were missing. Example: >
6657 :echo printf("%d: %.*s", nr, width, line)
6658< This limits the length of the text used from "line" to
6659 "width" bytes.
6660
6661 The conversion specifiers and their meanings are:
6662
6663 *printf-d* *printf-b* *printf-B* *printf-o*
6664 *printf-x* *printf-X*
6665 dbBoxX The Number argument is converted to signed decimal
6666 (d), unsigned binary (b and B), unsigned octal (o), or
6667 unsigned hexadecimal (x and X) notation. The letters
6668 "abcdef" are used for x conversions; the letters
6669 "ABCDEF" are used for X conversions.
6670 The precision, if any, gives the minimum number of
6671 digits that must appear; if the converted value
6672 requires fewer digits, it is padded on the left with
6673 zeros.
6674 In no case does a non-existent or small field width
6675 cause truncation of a numeric field; if the result of
6676 a conversion is wider than the field width, the field
6677 is expanded to contain the conversion result.
6678 The 'h' modifier indicates the argument is 16 bits.
6679 The 'l' modifier indicates the argument is 32 bits.
6680 The 'L' modifier indicates the argument is 64 bits.
6681 Generally, these modifiers are not useful. They are
6682 ignored when type is known from the argument.
6683
6684 i alias for d
6685 D alias for ld
6686 U alias for lu
6687 O alias for lo
6688
6689 *printf-c*
6690 c The Number argument is converted to a byte, and the
6691 resulting character is written.
6692
6693 *printf-s*
6694 s The text of the String argument is used. If a
6695 precision is specified, no more bytes than the number
6696 specified are used.
6697 If the argument is not a String type, it is
6698 automatically converted to text with the same format
6699 as ":echo".
6700 *printf-S*
6701 S The text of the String argument is used. If a
6702 precision is specified, no more display cells than the
6703 number specified are used.
6704
6705 *printf-f* *E807*
6706 f F The Float argument is converted into a string of the
6707 form 123.456. The precision specifies the number of
6708 digits after the decimal point. When the precision is
6709 zero the decimal point is omitted. When the precision
6710 is not specified 6 is used. A really big number
6711 (out of range or dividing by zero) results in "inf"
6712 or "-inf" with %f (INF or -INF with %F).
6713 "0.0 / 0.0" results in "nan" with %f (NAN with %F).
6714 Example: >
6715 echo printf("%.2f", 12.115)
6716< 12.12
6717 Note that roundoff depends on the system libraries.
6718 Use |round()| when in doubt.
6719
6720 *printf-e* *printf-E*
6721 e E The Float argument is converted into a string of the
6722 form 1.234e+03 or 1.234E+03 when using 'E'. The
6723 precision specifies the number of digits after the
6724 decimal point, like with 'f'.
6725
6726 *printf-g* *printf-G*
6727 g G The Float argument is converted like with 'f' if the
6728 value is between 0.001 (inclusive) and 10000000.0
6729 (exclusive). Otherwise 'e' is used for 'g' and 'E'
6730 for 'G'. When no precision is specified superfluous
6731 zeroes and '+' signs are removed, except for the zero
6732 immediately after the decimal point. Thus 10000000.0
6733 results in 1.0e7.
6734
6735 *printf-%*
6736 % A '%' is written. No argument is converted. The
6737 complete conversion specification is "%%".
6738
6739 When a Number argument is expected a String argument is also
6740 accepted and automatically converted.
6741 When a Float or String argument is expected a Number argument
6742 is also accepted and automatically converted.
6743 Any other argument type results in an error message.
6744
6745 *E766* *E767*
6746 The number of {exprN} arguments must exactly match the number
6747 of "%" items. If there are not sufficient or too many
6748 arguments an error is given. Up to 18 arguments can be used.
6749
6750
6751prompt_getprompt({buf}) *prompt_getprompt()*
6752 Returns the effective prompt text for buffer {buf}. {buf} can
6753 be a buffer name or number. See |prompt-buffer|.
6754
6755 If the buffer doesn't exist or isn't a prompt buffer, an empty
6756 string is returned.
6757
6758 Can also be used as a |method|: >
6759 GetBuffer()->prompt_getprompt()
6760
6761< {only available when compiled with the |+channel| feature}
6762
6763
6764prompt_setcallback({buf}, {expr}) *prompt_setcallback()*
6765 Set prompt callback for buffer {buf} to {expr}. When {expr}
6766 is an empty string the callback is removed. This has only
6767 effect if {buf} has 'buftype' set to "prompt".
6768
6769 The callback is invoked when pressing Enter. The current
6770 buffer will always be the prompt buffer. A new line for a
6771 prompt is added before invoking the callback, thus the prompt
6772 for which the callback was invoked will be in the last but one
6773 line.
6774 If the callback wants to add text to the buffer, it must
6775 insert it above the last line, since that is where the current
6776 prompt is. This can also be done asynchronously.
6777 The callback is invoked with one argument, which is the text
6778 that was entered at the prompt. This can be an empty string
6779 if the user only typed Enter.
6780 Example: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006781 func s:TextEntered(text)
6782 if a:text == 'exit' || a:text == 'quit'
6783 stopinsert
Bram Moolenaarb7398fe2023-05-14 18:50:25 +01006784 " Reset 'modified' to allow the buffer to be closed.
6785 " We assume there is nothing useful to be saved.
6786 set nomodified
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006787 close
6788 else
Bram Moolenaarb7398fe2023-05-14 18:50:25 +01006789 " Do something useful with "a:text". In this example
6790 " we just repeat it.
Bram Moolenaarc51cf032022-02-26 12:25:45 +00006791 call append(line('$') - 1, 'Entered: "' .. a:text .. '"')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006792 endif
6793 endfunc
Bram Moolenaarb7398fe2023-05-14 18:50:25 +01006794 call prompt_setcallback(bufnr(), function('s:TextEntered'))
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006795
6796< Can also be used as a |method|: >
6797 GetBuffer()->prompt_setcallback(callback)
6798
6799< {only available when compiled with the |+channel| feature}
6800
6801prompt_setinterrupt({buf}, {expr}) *prompt_setinterrupt()*
6802 Set a callback for buffer {buf} to {expr}. When {expr} is an
6803 empty string the callback is removed. This has only effect if
6804 {buf} has 'buftype' set to "prompt".
6805
6806 This callback will be invoked when pressing CTRL-C in Insert
6807 mode. Without setting a callback Vim will exit Insert mode,
6808 as in any buffer.
6809
6810 Can also be used as a |method|: >
6811 GetBuffer()->prompt_setinterrupt(callback)
6812
6813< {only available when compiled with the |+channel| feature}
6814
6815prompt_setprompt({buf}, {text}) *prompt_setprompt()*
6816 Set prompt for buffer {buf} to {text}. You most likely want
6817 {text} to end in a space.
6818 The result is only visible if {buf} has 'buftype' set to
6819 "prompt". Example: >
6820 call prompt_setprompt(bufnr(), 'command: ')
6821<
6822 Can also be used as a |method|: >
6823 GetBuffer()->prompt_setprompt('command: ')
6824
6825< {only available when compiled with the |+channel| feature}
6826
6827prop_ functions are documented here: |text-prop-functions|
6828
6829pum_getpos() *pum_getpos()*
6830 If the popup menu (see |ins-completion-menu|) is not visible,
6831 returns an empty |Dictionary|, otherwise, returns a
6832 |Dictionary| with the following keys:
6833 height nr of items visible
6834 width screen cells
6835 row top screen row (0 first row)
6836 col leftmost screen column (0 first col)
6837 size total nr of items
6838 scrollbar |TRUE| if scrollbar is visible
6839
6840 The values are the same as in |v:event| during
6841 |CompleteChanged|.
6842
6843pumvisible() *pumvisible()*
6844 Returns non-zero when the popup menu is visible, zero
6845 otherwise. See |ins-completion-menu|.
6846 This can be used to avoid some things that would remove the
6847 popup menu.
6848
6849py3eval({expr}) *py3eval()*
6850 Evaluate Python expression {expr} and return its result
6851 converted to Vim data structures.
6852 Numbers and strings are returned as they are (strings are
6853 copied though, Unicode strings are additionally converted to
6854 'encoding').
6855 Lists are represented as Vim |List| type.
6856 Dictionaries are represented as Vim |Dictionary| type with
6857 keys converted to strings.
6858 Note that in a `:def` function local variables are not visible
6859 to {expr}.
6860
6861 Can also be used as a |method|: >
6862 GetExpr()->py3eval()
6863
6864< {only available when compiled with the |+python3| feature}
6865
6866 *E858* *E859*
6867pyeval({expr}) *pyeval()*
6868 Evaluate Python expression {expr} and return its result
6869 converted to Vim data structures.
6870 Numbers and strings are returned as they are (strings are
6871 copied though).
6872 Lists are represented as Vim |List| type.
6873 Dictionaries are represented as Vim |Dictionary| type,
6874 non-string keys result in error.
6875 Note that in a `:def` function local variables are not visible
6876 to {expr}.
6877
6878 Can also be used as a |method|: >
6879 GetExpr()->pyeval()
6880
6881< {only available when compiled with the |+python| feature}
6882
6883pyxeval({expr}) *pyxeval()*
6884 Evaluate Python expression {expr} and return its result
6885 converted to Vim data structures.
6886 Uses Python 2 or 3, see |python_x| and 'pyxversion'.
6887 See also: |pyeval()|, |py3eval()|
6888
6889 Can also be used as a |method|: >
6890 GetExpr()->pyxeval()
6891
6892< {only available when compiled with the |+python| or the
6893 |+python3| feature}
6894
6895rand([{expr}]) *rand()* *random*
6896 Return a pseudo-random Number generated with an xoshiro128**
6897 algorithm using seed {expr}. The returned number is 32 bits,
6898 also on 64 bits systems, for consistency.
6899 {expr} can be initialized by |srand()| and will be updated by
6900 rand(). If {expr} is omitted, an internal seed value is used
6901 and updated.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01006902 Returns -1 if {expr} is invalid.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006903
6904 Examples: >
6905 :echo rand()
6906 :let seed = srand()
6907 :echo rand(seed)
6908 :echo rand(seed) % 16 " random number 0 - 15
6909<
6910
6911 *E726* *E727*
6912range({expr} [, {max} [, {stride}]]) *range()*
6913 Returns a |List| with Numbers:
6914 - If only {expr} is specified: [0, 1, ..., {expr} - 1]
6915 - If {max} is specified: [{expr}, {expr} + 1, ..., {max}]
6916 - If {stride} is specified: [{expr}, {expr} + {stride}, ...,
6917 {max}] (increasing {expr} with {stride} each time, not
6918 producing a value past {max}).
6919 When the maximum is one before the start the result is an
6920 empty list. When the maximum is more than one before the
6921 start this is an error.
6922 Examples: >
6923 range(4) " [0, 1, 2, 3]
6924 range(2, 4) " [2, 3, 4]
6925 range(2, 9, 3) " [2, 5, 8]
6926 range(2, -2, -1) " [2, 1, 0, -1, -2]
6927 range(0) " []
6928 range(2, 0) " error!
6929<
6930 Can also be used as a |method|: >
6931 GetExpr()->range()
6932<
6933
K.Takata11df3ae2022-10-19 14:02:40 +01006934readblob({fname} [, {offset} [, {size}]]) *readblob()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006935 Read file {fname} in binary mode and return a |Blob|.
K.Takata11df3ae2022-10-19 14:02:40 +01006936 If {offset} is specified, read the file from the specified
6937 offset. If it is a negative value, it is used as an offset
6938 from the end of the file. E.g., to read the last 12 bytes: >
6939 readblob('file.bin', -12)
6940< If {size} is specified, only the specified size will be read.
6941 E.g. to read the first 100 bytes of a file: >
6942 readblob('file.bin', 0, 100)
6943< If {size} is -1 or omitted, the whole data starting from
6944 {offset} will be read.
K.Takata43625762022-10-20 13:28:51 +01006945 This can be also used to read the data from a character device
6946 on Unix when {size} is explicitly set. Only if the device
6947 supports seeking {offset} can be used. Otherwise it should be
6948 zero. E.g. to read 10 bytes from a serial console: >
6949 readblob('/dev/ttyS0', 0, 10)
6950< When the file can't be opened an error message is given and
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006951 the result is an empty |Blob|.
Bram Moolenaar5b2a3d72022-10-21 11:25:30 +01006952 When the offset is beyond the end of the file the result is an
6953 empty blob.
6954 When trying to read more bytes than are available the result
6955 is truncated.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006956 Also see |readfile()| and |writefile()|.
6957
6958
6959readdir({directory} [, {expr} [, {dict}]]) *readdir()*
6960 Return a list with file and directory names in {directory}.
6961 You can also use |glob()| if you don't need to do complicated
6962 things, such as limiting the number of matches.
6963 The list will be sorted (case sensitive), see the {dict}
6964 argument below for changing the sort order.
6965
6966 When {expr} is omitted all entries are included.
6967 When {expr} is given, it is evaluated to check what to do:
6968 If {expr} results in -1 then no further entries will
6969 be handled.
6970 If {expr} results in 0 then this entry will not be
6971 added to the list.
6972 If {expr} results in 1 then this entry will be added
6973 to the list.
6974 The entries "." and ".." are always excluded.
6975 Each time {expr} is evaluated |v:val| is set to the entry name.
6976 When {expr} is a function the name is passed as the argument.
6977 For example, to get a list of files ending in ".txt": >
6978 readdir(dirname, {n -> n =~ '.txt$'})
6979< To skip hidden and backup files: >
6980 readdir(dirname, {n -> n !~ '^\.\|\~$'})
Bram Moolenaar6f4754b2022-01-23 12:07:04 +00006981< *E857*
6982 The optional {dict} argument allows for further custom
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006983 values. Currently this is used to specify if and how sorting
6984 should be performed. The dict can have the following members:
6985
6986 sort How to sort the result returned from the system.
6987 Valid values are:
6988 "none" do not sort (fastest method)
6989 "case" sort case sensitive (byte value of
6990 each character, technically, using
6991 strcmp()) (default)
6992 "icase" sort case insensitive (technically
6993 using strcasecmp())
6994 "collate" sort using the collation order
6995 of the "POSIX" or "C" |locale|
6996 (technically using strcoll())
6997 Other values are silently ignored.
6998
6999 For example, to get a list of all files in the current
7000 directory without sorting the individual entries: >
7001 readdir('.', '1', #{sort: 'none'})
7002< If you want to get a directory tree: >
7003 function! s:tree(dir)
7004 return {a:dir : map(readdir(a:dir),
7005 \ {_, x -> isdirectory(x) ?
Bram Moolenaarc51cf032022-02-26 12:25:45 +00007006 \ {x : s:tree(a:dir .. '/' .. x)} : x})}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007007 endfunction
7008 echo s:tree(".")
7009<
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01007010 Returns an empty List on error.
7011
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007012 Can also be used as a |method|: >
7013 GetDirName()->readdir()
7014<
7015readdirex({directory} [, {expr} [, {dict}]]) *readdirex()*
7016 Extended version of |readdir()|.
7017 Return a list of Dictionaries with file and directory
7018 information in {directory}.
7019 This is useful if you want to get the attributes of file and
7020 directory at the same time as getting a list of a directory.
7021 This is much faster than calling |readdir()| then calling
7022 |getfperm()|, |getfsize()|, |getftime()| and |getftype()| for
7023 each file and directory especially on MS-Windows.
7024 The list will by default be sorted by name (case sensitive),
7025 the sorting can be changed by using the optional {dict}
7026 argument, see |readdir()|.
7027
7028 The Dictionary for file and directory information has the
7029 following items:
7030 group Group name of the entry. (Only on Unix)
7031 name Name of the entry.
7032 perm Permissions of the entry. See |getfperm()|.
7033 size Size of the entry. See |getfsize()|.
7034 time Timestamp of the entry. See |getftime()|.
7035 type Type of the entry.
7036 On Unix, almost same as |getftype()| except:
7037 Symlink to a dir "linkd"
7038 Other symlink "link"
7039 On MS-Windows:
7040 Normal file "file"
7041 Directory "dir"
7042 Junction "junction"
7043 Symlink to a dir "linkd"
7044 Other symlink "link"
7045 Other reparse point "reparse"
7046 user User name of the entry's owner. (Only on Unix)
7047 On Unix, if the entry is a symlink, the Dictionary includes
7048 the information of the target (except the "type" item).
7049 On MS-Windows, it includes the information of the symlink
7050 itself because of performance reasons.
7051
7052 When {expr} is omitted all entries are included.
7053 When {expr} is given, it is evaluated to check what to do:
7054 If {expr} results in -1 then no further entries will
7055 be handled.
7056 If {expr} results in 0 then this entry will not be
7057 added to the list.
7058 If {expr} results in 1 then this entry will be added
7059 to the list.
7060 The entries "." and ".." are always excluded.
7061 Each time {expr} is evaluated |v:val| is set to a |Dictionary|
7062 of the entry.
7063 When {expr} is a function the entry is passed as the argument.
7064 For example, to get a list of files ending in ".txt": >
7065 readdirex(dirname, {e -> e.name =~ '.txt$'})
7066<
7067 For example, to get a list of all files in the current
7068 directory without sorting the individual entries: >
7069 readdirex(dirname, '1', #{sort: 'none'})
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007070<
7071 Can also be used as a |method|: >
7072 GetDirName()->readdirex()
7073<
7074
7075 *readfile()*
7076readfile({fname} [, {type} [, {max}]])
7077 Read file {fname} and return a |List|, each line of the file
7078 as an item. Lines are broken at NL characters. Macintosh
7079 files separated with CR will result in a single long line
7080 (unless a NL appears somewhere).
7081 All NUL characters are replaced with a NL character.
7082 When {type} contains "b" binary mode is used:
7083 - When the last line ends in a NL an extra empty list item is
7084 added.
7085 - No CR characters are removed.
7086 Otherwise:
7087 - CR characters that appear before a NL are removed.
7088 - Whether the last line ends in a NL or not does not matter.
7089 - When 'encoding' is Unicode any UTF-8 byte order mark is
7090 removed from the text.
7091 When {max} is given this specifies the maximum number of lines
7092 to be read. Useful if you only want to check the first ten
7093 lines of a file: >
7094 :for line in readfile(fname, '', 10)
7095 : if line =~ 'Date' | echo line | endif
7096 :endfor
7097< When {max} is negative -{max} lines from the end of the file
7098 are returned, or as many as there are.
7099 When {max} is zero the result is an empty list.
7100 Note that without {max} the whole file is read into memory.
7101 Also note that there is no recognition of encoding. Read a
7102 file into a buffer if you need to.
7103 Deprecated (use |readblob()| instead): When {type} contains
7104 "B" a |Blob| is returned with the binary data of the file
7105 unmodified.
7106 When the file can't be opened an error message is given and
7107 the result is an empty list.
7108 Also see |writefile()|.
7109
7110 Can also be used as a |method|: >
7111 GetFileName()->readfile()
7112
7113reduce({object}, {func} [, {initial}]) *reduce()* *E998*
7114 {func} is called for every item in {object}, which can be a
7115 |String|, |List| or a |Blob|. {func} is called with two
7116 arguments: the result so far and current item. After
Bram Moolenaarf10911e2022-01-29 22:20:48 +00007117 processing all items the result is returned. *E1132*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007118
7119 {initial} is the initial result. When omitted, the first item
7120 in {object} is used and {func} is first called for the second
7121 item. If {initial} is not given and {object} is empty no
7122 result can be computed, an E998 error is given.
7123
7124 Examples: >
7125 echo reduce([1, 3, 5], { acc, val -> acc + val })
7126 echo reduce(['x', 'y'], { acc, val -> acc .. val }, 'a')
7127 echo reduce(0z1122, { acc, val -> 2 * acc + val })
7128 echo reduce('xyz', { acc, val -> acc .. ',' .. val })
7129<
7130 Can also be used as a |method|: >
7131 echo mylist->reduce({ acc, val -> acc + val }, 0)
7132
7133
7134reg_executing() *reg_executing()*
7135 Returns the single letter name of the register being executed.
7136 Returns an empty string when no register is being executed.
7137 See |@|.
7138
7139reg_recording() *reg_recording()*
7140 Returns the single letter name of the register being recorded.
7141 Returns an empty string when not recording. See |q|.
7142
Bram Moolenaarf269eab2022-10-03 18:04:35 +01007143reltime()
7144reltime({start})
7145reltime({start}, {end}) *reltime()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007146 Return an item that represents a time value. The item is a
7147 list with items that depend on the system. In Vim 9 script
Bram Moolenaar71badf92023-04-22 22:40:14 +01007148 the type list<any> can be used.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007149 The item can be passed to |reltimestr()| to convert it to a
Bram Moolenaarf269eab2022-10-03 18:04:35 +01007150 string or |reltimefloat()| to convert to a Float. For
7151 example, to see the time spent in function Work(): >
7152 var startTime = reltime()
7153 Work()
7154 echo startTime->reltime()->reltimestr()
7155<
Bram Moolenaar016188f2022-06-06 20:52:59 +01007156 Without an argument reltime() returns the current time (the
Bram Moolenaareb490412022-06-28 13:44:46 +01007157 representation is system-dependent, it can not be used as the
Bram Moolenaar016188f2022-06-06 20:52:59 +01007158 wall-clock time, see |localtime()| for that).
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007159 With one argument is returns the time passed since the time
7160 specified in the argument.
7161 With two arguments it returns the time passed between {start}
7162 and {end}.
7163
7164 The {start} and {end} arguments must be values returned by
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01007165 reltime(). If there is an error an empty List is returned in
7166 legacy script, in Vim9 script an error is given.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007167
7168 Can also be used as a |method|: >
7169 GetStart()->reltime()
7170<
7171 {only available when compiled with the |+reltime| feature}
7172
7173reltimefloat({time}) *reltimefloat()*
7174 Return a Float that represents the time value of {time}.
7175 Example: >
7176 let start = reltime()
7177 call MyFunction()
7178 let seconds = reltimefloat(reltime(start))
7179< See the note of reltimestr() about overhead.
7180 Also see |profiling|.
7181 If there is an error 0.0 is returned in legacy script, in Vim9
7182 script an error is given.
7183
7184 Can also be used as a |method|: >
7185 reltime(start)->reltimefloat()
7186
7187< {only available when compiled with the |+reltime| feature}
7188
7189reltimestr({time}) *reltimestr()*
7190 Return a String that represents the time value of {time}.
7191 This is the number of seconds, a dot and the number of
7192 microseconds. Example: >
7193 let start = reltime()
7194 call MyFunction()
7195 echo reltimestr(reltime(start))
7196< Note that overhead for the commands will be added to the time.
Ernie Rael076de792023-03-16 21:43:15 +00007197 The accuracy depends on the system. Use reltimefloat() for the
7198 greatest accuracy which is nanoseconds on some systems.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007199 Leading spaces are used to make the string align nicely. You
7200 can use split() to remove it. >
7201 echo split(reltimestr(reltime(start)))[0]
7202< Also see |profiling|.
7203 If there is an error an empty string is returned in legacy
7204 script, in Vim9 script an error is given.
7205
7206 Can also be used as a |method|: >
7207 reltime(start)->reltimestr()
7208
7209< {only available when compiled with the |+reltime| feature}
7210
7211 *remote_expr()* *E449*
7212remote_expr({server}, {string} [, {idvar} [, {timeout}]])
Bram Moolenaar944697a2022-02-20 19:48:20 +00007213 Send the {string} to {server}. The {server} argument is a
7214 string, also see |{server}|.
7215
7216 The string is sent as an expression and the result is returned
7217 after evaluation. The result must be a String or a |List|. A
7218 |List| is turned into a String by joining the items with a
7219 line break in between (not at the end), like with join(expr,
7220 "\n").
7221
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007222 If {idvar} is present and not empty, it is taken as the name
7223 of a variable and a {serverid} for later use with
7224 |remote_read()| is stored there.
Bram Moolenaar944697a2022-02-20 19:48:20 +00007225
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007226 If {timeout} is given the read times out after this many
7227 seconds. Otherwise a timeout of 600 seconds is used.
Bram Moolenaar944697a2022-02-20 19:48:20 +00007228
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007229 See also |clientserver| |RemoteReply|.
7230 This function is not available in the |sandbox|.
7231 {only available when compiled with the |+clientserver| feature}
7232 Note: Any errors will cause a local error message to be issued
7233 and the result will be the empty string.
7234
7235 Variables will be evaluated in the global namespace,
7236 independent of a function currently being active. Except
7237 when in debug mode, then local function variables and
7238 arguments can be evaluated.
7239
7240 Examples: >
7241 :echo remote_expr("gvim", "2+2")
7242 :echo remote_expr("gvim1", "b:current_syntax")
7243<
7244 Can also be used as a |method|: >
7245 ServerName()->remote_expr(expr)
7246
7247remote_foreground({server}) *remote_foreground()*
7248 Move the Vim server with the name {server} to the foreground.
Bram Moolenaar944697a2022-02-20 19:48:20 +00007249 The {server} argument is a string, also see |{server}|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007250 This works like: >
7251 remote_expr({server}, "foreground()")
7252< Except that on Win32 systems the client does the work, to work
7253 around the problem that the OS doesn't always allow the server
7254 to bring itself to the foreground.
7255 Note: This does not restore the window if it was minimized,
7256 like foreground() does.
7257 This function is not available in the |sandbox|.
7258
7259 Can also be used as a |method|: >
7260 ServerName()->remote_foreground()
7261
Bram Moolenaarcbaff5e2022-04-08 17:45:08 +01007262< {only in the Win32, Motif and GTK GUI versions and the
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007263 Win32 console version}
7264
7265
7266remote_peek({serverid} [, {retvar}]) *remote_peek()*
7267 Returns a positive number if there are available strings
7268 from {serverid}. Copies any reply string into the variable
7269 {retvar} if specified. {retvar} must be a string with the
7270 name of a variable.
7271 Returns zero if none are available.
7272 Returns -1 if something is wrong.
7273 See also |clientserver|.
7274 This function is not available in the |sandbox|.
7275 {only available when compiled with the |+clientserver| feature}
7276 Examples: >
Bram Moolenaarf269eab2022-10-03 18:04:35 +01007277 :let repl = ""
7278 :echo "PEEK: " .. remote_peek(id, "repl") .. ": " .. repl
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007279
7280< Can also be used as a |method|: >
7281 ServerId()->remote_peek()
7282
7283remote_read({serverid}, [{timeout}]) *remote_read()*
7284 Return the oldest available reply from {serverid} and consume
7285 it. Unless a {timeout} in seconds is given, it blocks until a
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01007286 reply is available. Returns an empty string, if a reply is
7287 not available or on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007288 See also |clientserver|.
7289 This function is not available in the |sandbox|.
7290 {only available when compiled with the |+clientserver| feature}
7291 Example: >
7292 :echo remote_read(id)
7293
7294< Can also be used as a |method|: >
7295 ServerId()->remote_read()
7296<
7297 *remote_send()* *E241*
7298remote_send({server}, {string} [, {idvar}])
Bram Moolenaar944697a2022-02-20 19:48:20 +00007299 Send the {string} to {server}. The {server} argument is a
7300 string, also see |{server}|.
7301
7302 The string is sent as input keys and the function returns
7303 immediately. At the Vim server the keys are not mapped
7304 |:map|.
7305
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007306 If {idvar} is present, it is taken as the name of a variable
7307 and a {serverid} for later use with remote_read() is stored
7308 there.
Bram Moolenaar944697a2022-02-20 19:48:20 +00007309
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007310 See also |clientserver| |RemoteReply|.
7311 This function is not available in the |sandbox|.
7312 {only available when compiled with the |+clientserver| feature}
7313
7314 Note: Any errors will be reported in the server and may mess
7315 up the display.
7316 Examples: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00007317 :echo remote_send("gvim", ":DropAndReply " .. file, "serverid") ..
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007318 \ remote_read(serverid)
7319
7320 :autocmd NONE RemoteReply *
7321 \ echo remote_read(expand("<amatch>"))
Bram Moolenaarc51cf032022-02-26 12:25:45 +00007322 :echo remote_send("gvim", ":sleep 10 | echo " ..
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007323 \ 'server2client(expand("<client>"), "HELLO")<CR>')
7324<
7325 Can also be used as a |method|: >
7326 ServerName()->remote_send(keys)
7327<
7328 *remote_startserver()* *E941* *E942*
7329remote_startserver({name})
h-east17b69512023-05-01 22:36:56 +01007330 Become the server {name}. {name} must be a non-empty string.
7331 This fails if already running as a server, when |v:servername|
7332 is not empty.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007333
7334 Can also be used as a |method|: >
7335 ServerName()->remote_startserver()
7336
7337< {only available when compiled with the |+clientserver| feature}
7338
Bram Moolenaarf269eab2022-10-03 18:04:35 +01007339remove({list}, {idx})
7340remove({list}, {idx}, {end}) *remove()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007341 Without {end}: Remove the item at {idx} from |List| {list} and
7342 return the item.
7343 With {end}: Remove items from {idx} to {end} (inclusive) and
7344 return a |List| with these items. When {idx} points to the same
7345 item as {end} a list with one item is returned. When {end}
7346 points to an item before {idx} this is an error.
7347 See |list-index| for possible values of {idx} and {end}.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01007348 Returns zero on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007349 Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00007350 :echo "last item: " .. remove(mylist, -1)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007351 :call remove(mylist, 0, 9)
7352<
7353 Use |delete()| to remove a file.
7354
7355 Can also be used as a |method|: >
7356 mylist->remove(idx)
7357
Bram Moolenaarf269eab2022-10-03 18:04:35 +01007358remove({blob}, {idx})
7359remove({blob}, {idx}, {end})
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007360 Without {end}: Remove the byte at {idx} from |Blob| {blob} and
7361 return the byte.
7362 With {end}: Remove bytes from {idx} to {end} (inclusive) and
7363 return a |Blob| with these bytes. When {idx} points to the same
7364 byte as {end} a |Blob| with one byte is returned. When {end}
7365 points to a byte before {idx} this is an error.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01007366 Returns zero on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007367 Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00007368 :echo "last byte: " .. remove(myblob, -1)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007369 :call remove(mylist, 0, 9)
7370
7371remove({dict}, {key})
7372 Remove the entry from {dict} with key {key} and return it.
7373 Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00007374 :echo "removed " .. remove(dict, "one")
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007375< If there is no {key} in {dict} this is an error.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01007376 Returns zero on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007377
7378rename({from}, {to}) *rename()*
7379 Rename the file by the name {from} to the name {to}. This
7380 should also work to move files across file systems. The
7381 result is a Number, which is 0 if the file was renamed
7382 successfully, and non-zero when the renaming failed.
7383 NOTE: If {to} exists it is overwritten without warning.
7384 This function is not available in the |sandbox|.
7385
7386 Can also be used as a |method|: >
7387 GetOldName()->rename(newname)
7388
7389repeat({expr}, {count}) *repeat()*
7390 Repeat {expr} {count} times and return the concatenated
7391 result. Example: >
7392 :let separator = repeat('-', 80)
7393< When {count} is zero or negative the result is empty.
Bakudankun375141e2022-09-09 18:46:47 +01007394 When {expr} is a |List| or a |Blob| the result is {expr}
7395 concatenated {count} times. Example: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007396 :let longlist = repeat(['a', 'b'], 3)
7397< Results in ['a', 'b', 'a', 'b', 'a', 'b'].
7398
7399 Can also be used as a |method|: >
7400 mylist->repeat(count)
7401
7402resolve({filename}) *resolve()* *E655*
7403 On MS-Windows, when {filename} is a shortcut (a .lnk file),
7404 returns the path the shortcut points to in a simplified form.
7405 When {filename} is a symbolic link or junction point, return
7406 the full path to the target. If the target of junction is
7407 removed, return {filename}.
7408 On Unix, repeat resolving symbolic links in all path
7409 components of {filename} and return the simplified result.
7410 To cope with link cycles, resolving of symbolic links is
7411 stopped after 100 iterations.
7412 On other systems, return the simplified {filename}.
7413 The simplification step is done as by |simplify()|.
7414 resolve() keeps a leading path component specifying the
7415 current directory (provided the result is still a relative
7416 path name) and also keeps a trailing path separator.
7417
7418 Can also be used as a |method|: >
7419 GetName()->resolve()
7420
7421reverse({object}) *reverse()*
Yegappan Lakshmanan03ff1c22023-05-06 14:08:21 +01007422 Reverse the order of items in {object}. {object} can be a
7423 |List|, a |Blob| or a |String|. For a List and a Blob the
7424 items are reversed in-place and {object} is returned.
7425 For a String a new String is returned.
7426 Returns zero if {object} is not a List, Blob or a String.
7427 If you want a List or Blob to remain unmodified make a copy
7428 first: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007429 :let revlist = reverse(copy(mylist))
7430< Can also be used as a |method|: >
7431 mylist->reverse()
7432
7433round({expr}) *round()*
7434 Round off {expr} to the nearest integral value and return it
7435 as a |Float|. If {expr} lies halfway between two integral
7436 values, then use the larger one (away from zero).
7437 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01007438 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007439 Examples: >
7440 echo round(0.456)
7441< 0.0 >
7442 echo round(4.5)
7443< 5.0 >
7444 echo round(-4.5)
7445< -5.0
7446
7447 Can also be used as a |method|: >
7448 Compute()->round()
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007449
7450rubyeval({expr}) *rubyeval()*
7451 Evaluate Ruby expression {expr} and return its result
7452 converted to Vim data structures.
7453 Numbers, floats and strings are returned as they are (strings
7454 are copied though).
7455 Arrays are represented as Vim |List| type.
7456 Hashes are represented as Vim |Dictionary| type.
7457 Other objects are represented as strings resulted from their
7458 "Object#to_s" method.
7459 Note that in a `:def` function local variables are not visible
7460 to {expr}.
7461
7462 Can also be used as a |method|: >
7463 GetRubyExpr()->rubyeval()
7464
7465< {only available when compiled with the |+ruby| feature}
7466
7467screenattr({row}, {col}) *screenattr()*
7468 Like |screenchar()|, but return the attribute. This is a rather
7469 arbitrary number that can only be used to compare to the
7470 attribute at other positions.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01007471 Returns -1 when row or col is out of range.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007472
7473 Can also be used as a |method|: >
7474 GetRow()->screenattr(col)
7475
7476screenchar({row}, {col}) *screenchar()*
7477 The result is a Number, which is the character at position
7478 [row, col] on the screen. This works for every possible
7479 screen position, also status lines, window separators and the
7480 command line. The top left position is row one, column one
7481 The character excludes composing characters. For double-byte
7482 encodings it may only be the first byte.
7483 This is mainly to be used for testing.
7484 Returns -1 when row or col is out of range.
7485
7486 Can also be used as a |method|: >
7487 GetRow()->screenchar(col)
7488
7489screenchars({row}, {col}) *screenchars()*
7490 The result is a |List| of Numbers. The first number is the same
7491 as what |screenchar()| returns. Further numbers are
7492 composing characters on top of the base character.
7493 This is mainly to be used for testing.
7494 Returns an empty List when row or col is out of range.
7495
7496 Can also be used as a |method|: >
7497 GetRow()->screenchars(col)
7498
7499screencol() *screencol()*
7500 The result is a Number, which is the current screen column of
7501 the cursor. The leftmost column has number 1.
7502 This function is mainly used for testing.
7503
7504 Note: Always returns the current screen column, thus if used
7505 in a command (e.g. ":echo screencol()") it will return the
7506 column inside the command line, which is 1 when the command is
7507 executed. To get the cursor position in the file use one of
7508 the following mappings: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00007509 nnoremap <expr> GG ":echom " .. screencol() .. "\n"
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007510 nnoremap <silent> GG :echom screencol()<CR>
7511 nnoremap GG <Cmd>echom screencol()<CR>
7512<
7513screenpos({winid}, {lnum}, {col}) *screenpos()*
7514 The result is a Dict with the screen position of the text
7515 character in window {winid} at buffer line {lnum} and column
7516 {col}. {col} is a one-based byte index.
7517 The Dict has these members:
7518 row screen row
7519 col first screen column
7520 endcol last screen column
7521 curscol cursor screen column
7522 If the specified position is not visible, all values are zero.
7523 The "endcol" value differs from "col" when the character
7524 occupies more than one screen cell. E.g. for a Tab "col" can
7525 be 1 and "endcol" can be 8.
7526 The "curscol" value is where the cursor would be placed. For
7527 a Tab it would be the same as "endcol", while for a double
7528 width character it would be the same as "col".
7529 The |conceal| feature is ignored here, the column numbers are
7530 as if 'conceallevel' is zero. You can set the cursor to the
7531 right position and use |screencol()| to get the value with
7532 |conceal| taken into account.
Bram Moolenaar944697a2022-02-20 19:48:20 +00007533 If the position is in a closed fold the screen position of the
7534 first character is returned, {col} is not used.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01007535 Returns an empty Dict if {winid} is invalid.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007536
7537 Can also be used as a |method|: >
7538 GetWinid()->screenpos(lnum, col)
7539
7540screenrow() *screenrow()*
7541 The result is a Number, which is the current screen row of the
7542 cursor. The top line has number one.
7543 This function is mainly used for testing.
7544 Alternatively you can use |winline()|.
7545
7546 Note: Same restrictions as with |screencol()|.
7547
7548screenstring({row}, {col}) *screenstring()*
7549 The result is a String that contains the base character and
7550 any composing characters at position [row, col] on the screen.
7551 This is like |screenchars()| but returning a String with the
7552 characters.
7553 This is mainly to be used for testing.
7554 Returns an empty String when row or col is out of range.
7555
7556 Can also be used as a |method|: >
7557 GetRow()->screenstring(col)
7558<
7559 *search()*
7560search({pattern} [, {flags} [, {stopline} [, {timeout} [, {skip}]]]])
7561 Search for regexp pattern {pattern}. The search starts at the
7562 cursor position (you can use |cursor()| to set it).
7563
7564 When a match has been found its line number is returned.
7565 If there is no match a 0 is returned and the cursor doesn't
7566 move. No error message is given.
7567
7568 {flags} is a String, which can contain these character flags:
7569 'b' search Backward instead of forward
7570 'c' accept a match at the Cursor position
7571 'e' move to the End of the match
7572 'n' do Not move the cursor
7573 'p' return number of matching sub-Pattern (see below)
7574 's' Set the ' mark at the previous location of the cursor
7575 'w' Wrap around the end of the file
7576 'W' don't Wrap around the end of the file
7577 'z' start searching at the cursor column instead of zero
7578 If neither 'w' or 'W' is given, the 'wrapscan' option applies.
7579
7580 If the 's' flag is supplied, the ' mark is set, only if the
7581 cursor is moved. The 's' flag cannot be combined with the 'n'
7582 flag.
7583
7584 'ignorecase', 'smartcase' and 'magic' are used.
7585
7586 When the 'z' flag is not given, forward searching always
7587 starts in column zero and then matches before the cursor are
7588 skipped. When the 'c' flag is present in 'cpo' the next
7589 search starts after the match. Without the 'c' flag the next
Bram Moolenaarfd999452022-08-24 18:30:14 +01007590 search starts one column after the start of the match. This
7591 matters for overlapping matches. See |cpo-c|. You can also
7592 insert "\ze" to change where the match ends, see |/\ze|.
7593
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007594 When searching backwards and the 'z' flag is given then the
7595 search starts in column zero, thus no match in the current
7596 line will be found (unless wrapping around the end of the
7597 file).
7598
7599 When the {stopline} argument is given then the search stops
7600 after searching this line. This is useful to restrict the
7601 search to a range of lines. Examples: >
7602 let match = search('(', 'b', line("w0"))
7603 let end = search('END', '', line("w$"))
7604< When {stopline} is used and it is not zero this also implies
7605 that the search does not wrap around the end of the file.
7606 A zero value is equal to not giving the argument.
Bram Moolenaar2ecbe532022-07-29 21:36:21 +01007607 *E1285* *E1286* *E1287* *E1288* *E1289*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007608 When the {timeout} argument is given the search stops when
7609 more than this many milliseconds have passed. Thus when
7610 {timeout} is 500 the search stops after half a second.
7611 The value must not be negative. A zero value is like not
7612 giving the argument.
7613 {only available when compiled with the |+reltime| feature}
7614
7615 If the {skip} expression is given it is evaluated with the
7616 cursor positioned on the start of a match. If it evaluates to
7617 non-zero this match is skipped. This can be used, for
7618 example, to skip a match in a comment or a string.
7619 {skip} can be a string, which is evaluated as an expression, a
7620 function reference or a lambda.
7621 When {skip} is omitted or empty, every match is accepted.
7622 When evaluating {skip} causes an error the search is aborted
7623 and -1 returned.
7624 *search()-sub-match*
7625 With the 'p' flag the returned value is one more than the
7626 first sub-match in \(\). One if none of them matched but the
7627 whole pattern did match.
7628 To get the column number too use |searchpos()|.
7629
7630 The cursor will be positioned at the match, unless the 'n'
7631 flag is used.
7632
7633 Example (goes over all files in the argument list): >
7634 :let n = 1
7635 :while n <= argc() " loop over all files in arglist
Bram Moolenaarc51cf032022-02-26 12:25:45 +00007636 : exe "argument " .. n
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007637 : " start at the last char in the file and wrap for the
7638 : " first search to find match at start of file
7639 : normal G$
7640 : let flags = "w"
7641 : while search("foo", flags) > 0
7642 : s/foo/bar/g
7643 : let flags = "W"
7644 : endwhile
7645 : update " write the file if modified
7646 : let n = n + 1
7647 :endwhile
7648<
7649 Example for using some flags: >
7650 :echo search('\<if\|\(else\)\|\(endif\)', 'ncpe')
7651< This will search for the keywords "if", "else", and "endif"
7652 under or after the cursor. Because of the 'p' flag, it
7653 returns 1, 2, or 3 depending on which keyword is found, or 0
7654 if the search fails. With the cursor on the first word of the
7655 line:
7656 if (foo == 0) | let foo = foo + 1 | endif ~
7657 the function returns 1. Without the 'c' flag, the function
7658 finds the "endif" and returns 3. The same thing happens
7659 without the 'e' flag if the cursor is on the "f" of "if".
7660 The 'n' flag tells the function not to move the cursor.
7661
7662 Can also be used as a |method|: >
7663 GetPattern()->search()
7664
7665searchcount([{options}]) *searchcount()*
7666 Get or update the last search count, like what is displayed
7667 without the "S" flag in 'shortmess'. This works even if
7668 'shortmess' does contain the "S" flag.
7669
7670 This returns a |Dictionary|. The dictionary is empty if the
7671 previous pattern was not set and "pattern" was not specified.
7672
7673 key type meaning ~
7674 current |Number| current position of match;
7675 0 if the cursor position is
7676 before the first match
7677 exact_match |Boolean| 1 if "current" is matched on
7678 "pos", otherwise 0
7679 total |Number| total count of matches found
7680 incomplete |Number| 0: search was fully completed
7681 1: recomputing was timed out
7682 2: max count exceeded
7683
7684 For {options} see further down.
7685
7686 To get the last search count when |n| or |N| was pressed, call
7687 this function with `recompute: 0` . This sometimes returns
7688 wrong information because |n| and |N|'s maximum count is 99.
7689 If it exceeded 99 the result must be max count + 1 (100). If
7690 you want to get correct information, specify `recompute: 1`: >
7691
7692 " result == maxcount + 1 (100) when many matches
7693 let result = searchcount(#{recompute: 0})
7694
7695 " Below returns correct result (recompute defaults
7696 " to 1)
7697 let result = searchcount()
7698<
Bram Moolenaarb529cfb2022-07-25 15:42:07 +01007699 The function is useful to add the count to 'statusline': >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007700 function! LastSearchCount() abort
7701 let result = searchcount(#{recompute: 0})
7702 if empty(result)
7703 return ''
7704 endif
7705 if result.incomplete ==# 1 " timed out
7706 return printf(' /%s [?/??]', @/)
7707 elseif result.incomplete ==# 2 " max count exceeded
7708 if result.total > result.maxcount &&
7709 \ result.current > result.maxcount
7710 return printf(' /%s [>%d/>%d]', @/,
7711 \ result.current, result.total)
7712 elseif result.total > result.maxcount
7713 return printf(' /%s [%d/>%d]', @/,
7714 \ result.current, result.total)
7715 endif
7716 endif
7717 return printf(' /%s [%d/%d]', @/,
7718 \ result.current, result.total)
7719 endfunction
Bram Moolenaarc51cf032022-02-26 12:25:45 +00007720 let &statusline ..= '%{LastSearchCount()}'
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007721
7722 " Or if you want to show the count only when
7723 " 'hlsearch' was on
Bram Moolenaarc51cf032022-02-26 12:25:45 +00007724 " let &statusline ..=
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007725 " \ '%{v:hlsearch ? LastSearchCount() : ""}'
7726<
7727 You can also update the search count, which can be useful in a
7728 |CursorMoved| or |CursorMovedI| autocommand: >
7729
7730 autocmd CursorMoved,CursorMovedI *
7731 \ let s:searchcount_timer = timer_start(
7732 \ 200, function('s:update_searchcount'))
7733 function! s:update_searchcount(timer) abort
7734 if a:timer ==# s:searchcount_timer
7735 call searchcount(#{
7736 \ recompute: 1, maxcount: 0, timeout: 100})
7737 redrawstatus
7738 endif
7739 endfunction
7740<
7741 This can also be used to count matched texts with specified
7742 pattern in the current buffer using "pattern": >
7743
7744 " Count '\<foo\>' in this buffer
7745 " (Note that it also updates search count)
7746 let result = searchcount(#{pattern: '\<foo\>'})
7747
7748 " To restore old search count by old pattern,
7749 " search again
7750 call searchcount()
7751<
7752 {options} must be a |Dictionary|. It can contain:
7753 key type meaning ~
7754 recompute |Boolean| if |TRUE|, recompute the count
7755 like |n| or |N| was executed.
7756 otherwise returns the last
7757 computed result (when |n| or
7758 |N| was used when "S" is not
7759 in 'shortmess', or this
7760 function was called).
7761 (default: |TRUE|)
7762 pattern |String| recompute if this was given
7763 and different with |@/|.
7764 this works as same as the
7765 below command is executed
7766 before calling this function >
7767 let @/ = pattern
7768< (default: |@/|)
7769 timeout |Number| 0 or negative number is no
7770 timeout. timeout milliseconds
7771 for recomputing the result
7772 (default: 0)
7773 maxcount |Number| 0 or negative number is no
7774 limit. max count of matched
7775 text while recomputing the
7776 result. if search exceeded
7777 total count, "total" value
7778 becomes `maxcount + 1`
7779 (default: 99)
7780 pos |List| `[lnum, col, off]` value
7781 when recomputing the result.
7782 this changes "current" result
7783 value. see |cursor()|,
7784 |getpos()|
7785 (default: cursor's position)
7786
7787 Can also be used as a |method|: >
7788 GetSearchOpts()->searchcount()
7789<
7790searchdecl({name} [, {global} [, {thisblock}]]) *searchdecl()*
7791 Search for the declaration of {name}.
7792
7793 With a non-zero {global} argument it works like |gD|, find
7794 first match in the file. Otherwise it works like |gd|, find
7795 first match in the function.
7796
7797 With a non-zero {thisblock} argument matches in a {} block
7798 that ends before the cursor position are ignored. Avoids
7799 finding variable declarations only valid in another scope.
7800
7801 Moves the cursor to the found match.
7802 Returns zero for success, non-zero for failure.
7803 Example: >
7804 if searchdecl('myvar') == 0
7805 echo getline('.')
7806 endif
7807<
7808 Can also be used as a |method|: >
7809 GetName()->searchdecl()
7810<
7811 *searchpair()*
7812searchpair({start}, {middle}, {end} [, {flags} [, {skip}
7813 [, {stopline} [, {timeout}]]]])
7814 Search for the match of a nested start-end pair. This can be
7815 used to find the "endif" that matches an "if", while other
7816 if/endif pairs in between are ignored.
7817 The search starts at the cursor. The default is to search
7818 forward, include 'b' in {flags} to search backward.
7819 If a match is found, the cursor is positioned at it and the
7820 line number is returned. If no match is found 0 or -1 is
7821 returned and the cursor doesn't move. No error message is
7822 given.
7823
7824 {start}, {middle} and {end} are patterns, see |pattern|. They
7825 must not contain \( \) pairs. Use of \%( \) is allowed. When
7826 {middle} is not empty, it is found when searching from either
7827 direction, but only when not in a nested start-end pair. A
7828 typical use is: >
7829 searchpair('\<if\>', '\<else\>', '\<endif\>')
7830< By leaving {middle} empty the "else" is skipped.
7831
7832 {flags} 'b', 'c', 'n', 's', 'w' and 'W' are used like with
7833 |search()|. Additionally:
7834 'r' Repeat until no more matches found; will find the
7835 outer pair. Implies the 'W' flag.
7836 'm' Return number of matches instead of line number with
7837 the match; will be > 1 when 'r' is used.
7838 Note: it's nearly always a good idea to use the 'W' flag, to
7839 avoid wrapping around the end of the file.
7840
7841 When a match for {start}, {middle} or {end} is found, the
7842 {skip} expression is evaluated with the cursor positioned on
7843 the start of the match. It should return non-zero if this
7844 match is to be skipped. E.g., because it is inside a comment
7845 or a string.
7846 When {skip} is omitted or empty, every match is accepted.
7847 When evaluating {skip} causes an error the search is aborted
7848 and -1 returned.
7849 {skip} can be a string, a lambda, a funcref or a partial.
7850 Anything else makes the function fail.
7851 In a `:def` function when the {skip} argument is a string
7852 constant it is compiled into instructions.
7853
7854 For {stopline} and {timeout} see |search()|.
7855
7856 The value of 'ignorecase' is used. 'magic' is ignored, the
7857 patterns are used like it's on.
7858
7859 The search starts exactly at the cursor. A match with
7860 {start}, {middle} or {end} at the next character, in the
7861 direction of searching, is the first one found. Example: >
7862 if 1
7863 if 2
7864 endif 2
7865 endif 1
7866< When starting at the "if 2", with the cursor on the "i", and
7867 searching forwards, the "endif 2" is found. When starting on
7868 the character just before the "if 2", the "endif 1" will be
7869 found. That's because the "if 2" will be found first, and
7870 then this is considered to be a nested if/endif from "if 2" to
7871 "endif 2".
7872 When searching backwards and {end} is more than one character,
7873 it may be useful to put "\zs" at the end of the pattern, so
7874 that when the cursor is inside a match with the end it finds
7875 the matching start.
7876
7877 Example, to find the "endif" command in a Vim script: >
7878
7879 :echo searchpair('\<if\>', '\<el\%[seif]\>', '\<en\%[dif]\>', 'W',
7880 \ 'getline(".") =~ "^\\s*\""')
7881
7882< The cursor must be at or after the "if" for which a match is
7883 to be found. Note that single-quote strings are used to avoid
7884 having to double the backslashes. The skip expression only
7885 catches comments at the start of a line, not after a command.
7886 Also, a word "en" or "if" halfway a line is considered a
7887 match.
7888 Another example, to search for the matching "{" of a "}": >
7889
7890 :echo searchpair('{', '', '}', 'bW')
7891
7892< This works when the cursor is at or before the "}" for which a
7893 match is to be found. To reject matches that syntax
7894 highlighting recognized as strings: >
7895
7896 :echo searchpair('{', '', '}', 'bW',
7897 \ 'synIDattr(synID(line("."), col("."), 0), "name") =~? "string"')
7898<
7899 *searchpairpos()*
7900searchpairpos({start}, {middle}, {end} [, {flags} [, {skip}
7901 [, {stopline} [, {timeout}]]]])
7902 Same as |searchpair()|, but returns a |List| with the line and
7903 column position of the match. The first element of the |List|
7904 is the line number and the second element is the byte index of
7905 the column position of the match. If no match is found,
7906 returns [0, 0]. >
7907
7908 :let [lnum,col] = searchpairpos('{', '', '}', 'n')
7909<
7910 See |match-parens| for a bigger and more useful example.
7911
7912 *searchpos()*
7913searchpos({pattern} [, {flags} [, {stopline} [, {timeout} [, {skip}]]]])
7914 Same as |search()|, but returns a |List| with the line and
7915 column position of the match. The first element of the |List|
7916 is the line number and the second element is the byte index of
7917 the column position of the match. If no match is found,
7918 returns [0, 0].
7919 Example: >
7920 :let [lnum, col] = searchpos('mypattern', 'n')
7921
7922< When the 'p' flag is given then there is an extra item with
7923 the sub-pattern match number |search()-sub-match|. Example: >
7924 :let [lnum, col, submatch] = searchpos('\(\l\)\|\(\u\)', 'np')
7925< In this example "submatch" is 2 when a lowercase letter is
7926 found |/\l|, 3 when an uppercase letter is found |/\u|.
7927
7928 Can also be used as a |method|: >
7929 GetPattern()->searchpos()
7930
7931server2client({clientid}, {string}) *server2client()*
7932 Send a reply string to {clientid}. The most recent {clientid}
7933 that sent a string can be retrieved with expand("<client>").
7934 {only available when compiled with the |+clientserver| feature}
7935 Returns zero for success, -1 for failure.
7936 Note:
7937 This id has to be stored before the next command can be
7938 received. I.e. before returning from the received command and
7939 before calling any commands that waits for input.
7940 See also |clientserver|.
7941 Example: >
7942 :echo server2client(expand("<client>"), "HELLO")
7943
7944< Can also be used as a |method|: >
7945 GetClientId()->server2client(string)
7946<
7947serverlist() *serverlist()*
7948 Return a list of available server names, one per line.
7949 When there are no servers or the information is not available
7950 an empty string is returned. See also |clientserver|.
7951 {only available when compiled with the |+clientserver| feature}
7952 Example: >
7953 :echo serverlist()
7954<
7955setbufline({buf}, {lnum}, {text}) *setbufline()*
7956 Set line {lnum} to {text} in buffer {buf}. This works like
7957 |setline()| for the specified buffer.
7958
7959 This function works only for loaded buffers. First call
7960 |bufload()| if needed.
7961
7962 To insert lines use |appendbufline()|.
7963 Any text properties in {lnum} are cleared.
7964
Bram Moolenaarcd9c8d42022-11-05 23:46:43 +00007965 {text} can be a string to set one line, or a List of strings
7966 to set multiple lines. If the List extends below the last
7967 line then those lines are added. If the List is empty then
7968 nothing is changed and zero is returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007969
7970 For the use of {buf}, see |bufname()| above.
7971
7972 {lnum} is used like with |setline()|.
7973 Use "$" to refer to the last line in buffer {buf}.
7974 When {lnum} is just below the last line the {text} will be
7975 added below the last line.
7976
7977 When {buf} is not a valid buffer, the buffer is not loaded or
7978 {lnum} is not valid then 1 is returned. In |Vim9| script an
7979 error is given.
7980 On success 0 is returned.
7981
7982 Can also be used as a |method|, the base is passed as the
7983 third argument: >
7984 GetText()->setbufline(buf, lnum)
7985
7986setbufvar({buf}, {varname}, {val}) *setbufvar()*
7987 Set option or local variable {varname} in buffer {buf} to
7988 {val}.
7989 This also works for a global or local window option, but it
7990 doesn't work for a global or local window variable.
7991 For a local window option the global value is unchanged.
7992 For the use of {buf}, see |bufname()| above.
7993 The {varname} argument is a string.
7994 Note that the variable name without "b:" must be used.
7995 Examples: >
7996 :call setbufvar(1, "&mod", 1)
7997 :call setbufvar("todo", "myvar", "foobar")
7998< This function is not available in the |sandbox|.
7999
8000 Can also be used as a |method|, the base is passed as the
8001 third argument: >
8002 GetValue()->setbufvar(buf, varname)
8003
8004
8005setcellwidths({list}) *setcellwidths()*
8006 Specify overrides for cell widths of character ranges. This
Bram Moolenaarb59ae592022-11-23 23:46:31 +00008007 tells Vim how wide characters are when displayed in the
8008 terminal, counted in screen cells. The values override
8009 'ambiwidth'. Example: >
8010 call setcellwidths([
Bram Moolenaar938ae282023-02-20 20:44:55 +00008011 \ [0x111, 0x111, 1],
Bram Moolenaarb59ae592022-11-23 23:46:31 +00008012 \ [0x2194, 0x2199, 2],
8013 \ ])
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008014
Bram Moolenaarb59ae592022-11-23 23:46:31 +00008015< The {list} argument is a List of Lists with each three
8016 numbers: [{low}, {high}, {width}]. *E1109* *E1110*
8017 {low} and {high} can be the same, in which case this refers to
8018 one character. Otherwise it is the range of characters from
8019 {low} to {high} (inclusive). *E1111* *E1114*
K.Takata71933232023-01-20 16:00:55 +00008020 Only characters with value 0x80 and higher can be used.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008021
Bram Moolenaarb59ae592022-11-23 23:46:31 +00008022 {width} must be either 1 or 2, indicating the character width
8023 in screen cells. *E1112*
8024 An error is given if the argument is invalid, also when a
Bram Moolenaar938ae282023-02-20 20:44:55 +00008025 range overlaps with another. *E1113*
Bram Moolenaarb59ae592022-11-23 23:46:31 +00008026
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008027 If the new value causes 'fillchars' or 'listchars' to become
8028 invalid it is rejected and an error is given.
8029
Bram Moolenaarb59ae592022-11-23 23:46:31 +00008030 To clear the overrides pass an empty {list}: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008031 setcellwidths([]);
Bram Moolenaarb59ae592022-11-23 23:46:31 +00008032
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008033< You can use the script $VIMRUNTIME/tools/emoji_list.vim to see
Bram Moolenaarb59ae592022-11-23 23:46:31 +00008034 the effect for known emoji characters. Move the cursor
8035 through the text to check if the cell widths of your terminal
8036 match with what Vim knows about each emoji. If it doesn't
8037 look right you need to adjust the {list} argument.
8038
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008039
8040setcharpos({expr}, {list}) *setcharpos()*
8041 Same as |setpos()| but uses the specified column number as the
8042 character index instead of the byte index in the line.
8043
8044 Example:
8045 With the text "여보세요" in line 8: >
8046 call setcharpos('.', [0, 8, 4, 0])
8047< positions the cursor on the fourth character '요'. >
8048 call setpos('.', [0, 8, 4, 0])
8049< positions the cursor on the second character '보'.
8050
8051 Can also be used as a |method|: >
8052 GetPosition()->setcharpos('.')
8053
8054setcharsearch({dict}) *setcharsearch()*
8055 Set the current character search information to {dict},
8056 which contains one or more of the following entries:
8057
8058 char character which will be used for a subsequent
8059 |,| or |;| command; an empty string clears the
8060 character search
8061 forward direction of character search; 1 for forward,
8062 0 for backward
8063 until type of character search; 1 for a |t| or |T|
8064 character search, 0 for an |f| or |F|
8065 character search
8066
8067 This can be useful to save/restore a user's character search
8068 from a script: >
8069 :let prevsearch = getcharsearch()
8070 :" Perform a command which clobbers user's search
8071 :call setcharsearch(prevsearch)
8072< Also see |getcharsearch()|.
8073
8074 Can also be used as a |method|: >
8075 SavedSearch()->setcharsearch()
8076
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01008077setcmdline({str} [, {pos}]) *setcmdline()*
8078 Set the command line to {str} and set the cursor position to
8079 {pos}.
8080 If {pos} is omitted, the cursor is positioned after the text.
8081 Returns 0 when successful, 1 when not editing the command
8082 line.
8083
8084 Can also be used as a |method|: >
8085 GetText()->setcmdline()
8086
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008087setcmdpos({pos}) *setcmdpos()*
8088 Set the cursor position in the command line to byte position
8089 {pos}. The first position is 1.
8090 Use |getcmdpos()| to obtain the current position.
8091 Only works while editing the command line, thus you must use
8092 |c_CTRL-\_e|, |c_CTRL-R_=| or |c_CTRL-R_CTRL-R| with '='. For
8093 |c_CTRL-\_e| and |c_CTRL-R_CTRL-R| with '=' the position is
8094 set after the command line is set to the expression. For
8095 |c_CTRL-R_=| it is set after evaluating the expression but
8096 before inserting the resulting text.
8097 When the number is too big the cursor is put at the end of the
8098 line. A number smaller than one has undefined results.
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01008099 Returns 0 when successful, 1 when not editing the command
8100 line.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008101
8102 Can also be used as a |method|: >
8103 GetPos()->setcmdpos()
8104
8105setcursorcharpos({lnum}, {col} [, {off}]) *setcursorcharpos()*
8106setcursorcharpos({list})
8107 Same as |cursor()| but uses the specified column number as the
8108 character index instead of the byte index in the line.
8109
8110 Example:
8111 With the text "여보세요" in line 4: >
8112 call setcursorcharpos(4, 3)
8113< positions the cursor on the third character '세'. >
8114 call cursor(4, 3)
8115< positions the cursor on the first character '여'.
8116
8117 Can also be used as a |method|: >
8118 GetCursorPos()->setcursorcharpos()
8119
8120
8121setenv({name}, {val}) *setenv()*
8122 Set environment variable {name} to {val}. Example: >
8123 call setenv('HOME', '/home/myhome')
8124
8125< When {val} is |v:null| the environment variable is deleted.
8126 See also |expr-env|.
8127
8128 Can also be used as a |method|, the base is passed as the
8129 second argument: >
8130 GetPath()->setenv('PATH')
8131
8132setfperm({fname}, {mode}) *setfperm()* *chmod*
8133 Set the file permissions for {fname} to {mode}.
8134 {mode} must be a string with 9 characters. It is of the form
8135 "rwxrwxrwx", where each group of "rwx" flags represent, in
8136 turn, the permissions of the owner of the file, the group the
8137 file belongs to, and other users. A '-' character means the
8138 permission is off, any other character means on. Multi-byte
8139 characters are not supported.
8140
8141 For example "rw-r-----" means read-write for the user,
8142 readable by the group, not accessible by others. "xx-x-----"
8143 would do the same thing.
8144
8145 Returns non-zero for success, zero for failure.
8146
8147 Can also be used as a |method|: >
8148 GetFilename()->setfperm(mode)
8149<
8150 To read permissions see |getfperm()|.
8151
8152
8153setline({lnum}, {text}) *setline()*
8154 Set line {lnum} of the current buffer to {text}. To insert
8155 lines use |append()|. To set lines in another buffer use
8156 |setbufline()|. Any text properties in {lnum} are cleared.
8157
8158 {lnum} is used like with |getline()|.
8159 When {lnum} is just below the last line the {text} will be
8160 added below the last line.
8161 {text} can be any type or a List of any type, each item is
Bram Moolenaarcd9c8d42022-11-05 23:46:43 +00008162 converted to a String. When {text} is an empty List then
8163 nothing is changed and FALSE is returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008164
8165 If this succeeds, FALSE is returned. If this fails (most likely
8166 because {lnum} is invalid) TRUE is returned.
8167 In |Vim9| script an error is given if {lnum} is invalid.
8168
8169 Example: >
8170 :call setline(5, strftime("%c"))
8171
8172< When {text} is a |List| then line {lnum} and following lines
8173 will be set to the items in the list. Example: >
8174 :call setline(5, ['aaa', 'bbb', 'ccc'])
8175< This is equivalent to: >
8176 :for [n, l] in [[5, 'aaa'], [6, 'bbb'], [7, 'ccc']]
8177 : call setline(n, l)
8178 :endfor
8179
8180< Note: The '[ and '] marks are not set.
8181
8182 Can also be used as a |method|, the base is passed as the
8183 second argument: >
8184 GetText()->setline(lnum)
8185
8186setloclist({nr}, {list} [, {action} [, {what}]]) *setloclist()*
8187 Create or replace or add to the location list for window {nr}.
8188 {nr} can be the window number or the |window-ID|.
8189 When {nr} is zero the current window is used.
8190
8191 For a location list window, the displayed location list is
8192 modified. For an invalid window number {nr}, -1 is returned.
8193 Otherwise, same as |setqflist()|.
8194 Also see |location-list|.
8195
8196 For {action} see |setqflist-action|.
8197
8198 If the optional {what} dictionary argument is supplied, then
8199 only the items listed in {what} are set. Refer to |setqflist()|
8200 for the list of supported keys in {what}.
8201
8202 Can also be used as a |method|, the base is passed as the
8203 second argument: >
8204 GetLoclist()->setloclist(winnr)
8205
8206setmatches({list} [, {win}]) *setmatches()*
8207 Restores a list of matches saved by |getmatches()| for the
8208 current window. Returns 0 if successful, otherwise -1. All
8209 current matches are cleared before the list is restored. See
8210 example for |getmatches()|.
8211 If {win} is specified, use the window with this number or
8212 window ID instead of the current window.
8213
8214 Can also be used as a |method|: >
8215 GetMatches()->setmatches()
8216<
8217 *setpos()*
8218setpos({expr}, {list})
8219 Set the position for String {expr}. Possible values:
8220 . the cursor
8221 'x mark x
8222
8223 {list} must be a |List| with four or five numbers:
8224 [bufnum, lnum, col, off]
8225 [bufnum, lnum, col, off, curswant]
8226
8227 "bufnum" is the buffer number. Zero can be used for the
8228 current buffer. When setting an uppercase mark "bufnum" is
8229 used for the mark position. For other marks it specifies the
8230 buffer to set the mark in. You can use the |bufnr()| function
8231 to turn a file name into a buffer number.
8232 For setting the cursor and the ' mark "bufnum" is ignored,
8233 since these are associated with a window, not a buffer.
8234 Does not change the jumplist.
8235
8236 "lnum" and "col" are the position in the buffer. The first
8237 column is 1. Use a zero "lnum" to delete a mark. If "col" is
8238 smaller than 1 then 1 is used. To use the character count
8239 instead of the byte count, use |setcharpos()|.
8240
8241 The "off" number is only used when 'virtualedit' is set. Then
8242 it is the offset in screen columns from the start of the
8243 character. E.g., a position within a <Tab> or after the last
8244 character.
8245
8246 The "curswant" number is only used when setting the cursor
8247 position. It sets the preferred column for when moving the
8248 cursor vertically. When the "curswant" number is missing the
8249 preferred column is not set. When it is present and setting a
8250 mark position it is not used.
8251
8252 Note that for '< and '> changing the line number may result in
8253 the marks to be effectively be swapped, so that '< is always
8254 before '>.
8255
8256 Returns 0 when the position could be set, -1 otherwise.
8257 An error message is given if {expr} is invalid.
8258
8259 Also see |setcharpos()|, |getpos()| and |getcurpos()|.
8260
8261 This does not restore the preferred column for moving
8262 vertically; if you set the cursor position with this, |j| and
8263 |k| motions will jump to previous columns! Use |cursor()| to
8264 also set the preferred column. Also see the "curswant" key in
8265 |winrestview()|.
8266
8267 Can also be used as a |method|: >
8268 GetPosition()->setpos('.')
8269
8270setqflist({list} [, {action} [, {what}]]) *setqflist()*
8271 Create or replace or add to the quickfix list.
8272
8273 If the optional {what} dictionary argument is supplied, then
8274 only the items listed in {what} are set. The first {list}
8275 argument is ignored. See below for the supported items in
8276 {what}.
8277 *setqflist-what*
8278 When {what} is not present, the items in {list} are used. Each
8279 item must be a dictionary. Non-dictionary items in {list} are
8280 ignored. Each dictionary item can contain the following
8281 entries:
8282
8283 bufnr buffer number; must be the number of a valid
8284 buffer
8285 filename name of a file; only used when "bufnr" is not
8286 present or it is invalid.
8287 module name of a module; if given it will be used in
8288 quickfix error window instead of the filename.
8289 lnum line number in the file
Bram Moolenaara2baa732022-02-04 16:09:54 +00008290 end_lnum end of lines, if the item spans multiple lines
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008291 pattern search pattern used to locate the error
8292 col column number
8293 vcol when non-zero: "col" is visual column
8294 when zero: "col" is byte index
Bram Moolenaara2baa732022-02-04 16:09:54 +00008295 end_col end column, if the item spans multiple columns
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008296 nr error number
8297 text description of the error
8298 type single-character error type, 'E', 'W', etc.
8299 valid recognized error message
8300
8301 The "col", "vcol", "nr", "type" and "text" entries are
8302 optional. Either "lnum" or "pattern" entry can be used to
8303 locate a matching error line.
8304 If the "filename" and "bufnr" entries are not present or
8305 neither the "lnum" or "pattern" entries are present, then the
8306 item will not be handled as an error line.
8307 If both "pattern" and "lnum" are present then "pattern" will
8308 be used.
8309 If the "valid" entry is not supplied, then the valid flag is
8310 set when "bufnr" is a valid buffer or "filename" exists.
8311 If you supply an empty {list}, the quickfix list will be
8312 cleared.
8313 Note that the list is not exactly the same as what
8314 |getqflist()| returns.
8315
8316 {action} values: *setqflist-action* *E927*
8317 'a' The items from {list} are added to the existing
8318 quickfix list. If there is no existing list, then a
8319 new list is created.
8320
8321 'r' The items from the current quickfix list are replaced
8322 with the items from {list}. This can also be used to
8323 clear the list: >
8324 :call setqflist([], 'r')
8325<
8326 'f' All the quickfix lists in the quickfix stack are
8327 freed.
8328
8329 If {action} is not present or is set to ' ', then a new list
8330 is created. The new quickfix list is added after the current
8331 quickfix list in the stack and all the following lists are
8332 freed. To add a new quickfix list at the end of the stack,
8333 set "nr" in {what} to "$".
8334
8335 The following items can be specified in dictionary {what}:
8336 context quickfix list context. See |quickfix-context|
8337 efm errorformat to use when parsing text from
8338 "lines". If this is not present, then the
8339 'errorformat' option value is used.
8340 See |quickfix-parse|
8341 id quickfix list identifier |quickfix-ID|
8342 idx index of the current entry in the quickfix
8343 list specified by 'id' or 'nr'. If set to '$',
8344 then the last entry in the list is set as the
8345 current entry. See |quickfix-index|
8346 items list of quickfix entries. Same as the {list}
8347 argument.
8348 lines use 'errorformat' to parse a list of lines and
8349 add the resulting entries to the quickfix list
8350 {nr} or {id}. Only a |List| value is supported.
8351 See |quickfix-parse|
8352 nr list number in the quickfix stack; zero
8353 means the current quickfix list and "$" means
8354 the last quickfix list.
8355 quickfixtextfunc
8356 function to get the text to display in the
8357 quickfix window. The value can be the name of
8358 a function or a funcref or a lambda. Refer to
8359 |quickfix-window-function| for an explanation
8360 of how to write the function and an example.
8361 title quickfix list title text. See |quickfix-title|
8362 Unsupported keys in {what} are ignored.
8363 If the "nr" item is not present, then the current quickfix list
8364 is modified. When creating a new quickfix list, "nr" can be
8365 set to a value one greater than the quickfix stack size.
8366 When modifying a quickfix list, to guarantee that the correct
8367 list is modified, "id" should be used instead of "nr" to
8368 specify the list.
8369
8370 Examples (See also |setqflist-examples|): >
8371 :call setqflist([], 'r', {'title': 'My search'})
8372 :call setqflist([], 'r', {'nr': 2, 'title': 'Errors'})
8373 :call setqflist([], 'a', {'id':qfid, 'lines':["F1:10:L10"]})
8374<
8375 Returns zero for success, -1 for failure.
8376
8377 This function can be used to create a quickfix list
8378 independent of the 'errorformat' setting. Use a command like
8379 `:cc 1` to jump to the first position.
8380
8381 Can also be used as a |method|, the base is passed as the
8382 second argument: >
8383 GetErrorlist()->setqflist()
8384<
8385 *setreg()*
8386setreg({regname}, {value} [, {options}])
8387 Set the register {regname} to {value}.
8388 If {regname} is "" or "@", the unnamed register '"' is used.
8389 The {regname} argument is a string. In |Vim9-script|
8390 {regname} must be one character.
8391
8392 {value} may be any value returned by |getreg()| or
8393 |getreginfo()|, including a |List| or |Dict|.
8394 If {options} contains "a" or {regname} is upper case,
8395 then the value is appended.
8396
8397 {options} can also contain a register type specification:
8398 "c" or "v" |characterwise| mode
8399 "l" or "V" |linewise| mode
8400 "b" or "<CTRL-V>" |blockwise-visual| mode
8401 If a number immediately follows "b" or "<CTRL-V>" then this is
8402 used as the width of the selection - if it is not specified
8403 then the width of the block is set to the number of characters
8404 in the longest line (counting a <Tab> as 1 character).
8405
8406 If {options} contains no register settings, then the default
8407 is to use character mode unless {value} ends in a <NL> for
8408 string {value} and linewise mode for list {value}. Blockwise
8409 mode is never selected automatically.
8410 Returns zero for success, non-zero for failure.
8411
8412 *E883*
8413 Note: you may not use |List| containing more than one item to
8414 set search and expression registers. Lists containing no
8415 items act like empty strings.
8416
8417 Examples: >
8418 :call setreg(v:register, @*)
8419 :call setreg('*', @%, 'ac')
8420 :call setreg('a', "1\n2\n3", 'b5')
8421 :call setreg('"', { 'points_to': 'a'})
8422
8423< This example shows using the functions to save and restore a
8424 register: >
8425 :let var_a = getreginfo()
8426 :call setreg('a', var_a)
8427< or: >
8428 :let var_a = getreg('a', 1, 1)
8429 :let var_amode = getregtype('a')
8430 ....
8431 :call setreg('a', var_a, var_amode)
8432< Note: you may not reliably restore register value
8433 without using the third argument to |getreg()| as without it
8434 newlines are represented as newlines AND Nul bytes are
8435 represented as newlines as well, see |NL-used-for-Nul|.
8436
8437 You can also change the type of a register by appending
8438 nothing: >
8439 :call setreg('a', '', 'al')
8440
8441< Can also be used as a |method|, the base is passed as the
8442 second argument: >
8443 GetText()->setreg('a')
8444
8445settabvar({tabnr}, {varname}, {val}) *settabvar()*
8446 Set tab-local variable {varname} to {val} in tab page {tabnr}.
8447 |t:var|
8448 The {varname} argument is a string.
8449 Note that autocommands are blocked, side effects may not be
8450 triggered, e.g. when setting 'filetype'.
8451 Note that the variable name without "t:" must be used.
8452 Tabs are numbered starting with one.
8453 This function is not available in the |sandbox|.
8454
8455 Can also be used as a |method|, the base is passed as the
8456 third argument: >
8457 GetValue()->settabvar(tab, name)
8458
8459settabwinvar({tabnr}, {winnr}, {varname}, {val}) *settabwinvar()*
8460 Set option or local variable {varname} in window {winnr} to
8461 {val}.
8462 Tabs are numbered starting with one. For the current tabpage
8463 use |setwinvar()|.
8464 {winnr} can be the window number or the |window-ID|.
8465 When {winnr} is zero the current window is used.
8466 Note that autocommands are blocked, side effects may not be
8467 triggered, e.g. when setting 'filetype' or 'syntax'.
8468 This also works for a global or local buffer option, but it
8469 doesn't work for a global or local buffer variable.
8470 For a local buffer option the global value is unchanged.
8471 Note that the variable name without "w:" must be used.
8472 Examples: >
8473 :call settabwinvar(1, 1, "&list", 0)
8474 :call settabwinvar(3, 2, "myvar", "foobar")
8475< This function is not available in the |sandbox|.
8476
8477 Can also be used as a |method|, the base is passed as the
8478 fourth argument: >
8479 GetValue()->settabwinvar(tab, winnr, name)
8480
8481settagstack({nr}, {dict} [, {action}]) *settagstack()*
8482 Modify the tag stack of the window {nr} using {dict}.
8483 {nr} can be the window number or the |window-ID|.
8484
8485 For a list of supported items in {dict}, refer to
8486 |gettagstack()|. "curidx" takes effect before changing the tag
8487 stack.
8488 *E962*
8489 How the tag stack is modified depends on the {action}
8490 argument:
8491 - If {action} is not present or is set to 'r', then the tag
8492 stack is replaced.
8493 - If {action} is set to 'a', then new entries from {dict} are
8494 pushed (added) onto the tag stack.
8495 - If {action} is set to 't', then all the entries from the
8496 current entry in the tag stack or "curidx" in {dict} are
8497 removed and then new entries are pushed to the stack.
8498
8499 The current index is set to one after the length of the tag
8500 stack after the modification.
8501
8502 Returns zero for success, -1 for failure.
8503
8504 Examples (for more examples see |tagstack-examples|):
8505 Empty the tag stack of window 3: >
8506 call settagstack(3, {'items' : []})
8507
8508< Save and restore the tag stack: >
8509 let stack = gettagstack(1003)
8510 " do something else
8511 call settagstack(1003, stack)
8512 unlet stack
8513<
8514 Can also be used as a |method|, the base is passed as the
8515 second argument: >
8516 GetStack()->settagstack(winnr)
8517
8518setwinvar({winnr}, {varname}, {val}) *setwinvar()*
8519 Like |settabwinvar()| for the current tab page.
8520 Examples: >
8521 :call setwinvar(1, "&list", 0)
8522 :call setwinvar(2, "myvar", "foobar")
8523
8524< Can also be used as a |method|, the base is passed as the
8525 third argument: >
8526 GetValue()->setwinvar(winnr, name)
8527
8528sha256({string}) *sha256()*
8529 Returns a String with 64 hex characters, which is the SHA256
8530 checksum of {string}.
8531
8532 Can also be used as a |method|: >
8533 GetText()->sha256()
8534
8535< {only available when compiled with the |+cryptv| feature}
8536
8537shellescape({string} [, {special}]) *shellescape()*
8538 Escape {string} for use as a shell command argument.
8539 When the 'shell' contains powershell (MS-Windows) or pwsh
Bram Moolenaar944697a2022-02-20 19:48:20 +00008540 (MS-Windows, Linux, and macOS) then it will enclose {string}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008541 in single quotes and will double up all internal single
8542 quotes.
8543 On MS-Windows, when 'shellslash' is not set, it will enclose
8544 {string} in double quotes and double all double quotes within
8545 {string}.
8546 Otherwise it will enclose {string} in single quotes and
8547 replace all "'" with "'\''".
8548
8549 When the {special} argument is present and it's a non-zero
8550 Number or a non-empty String (|non-zero-arg|), then special
8551 items such as "!", "%", "#" and "<cword>" will be preceded by
8552 a backslash. This backslash will be removed again by the |:!|
8553 command.
8554
8555 The "!" character will be escaped (again with a |non-zero-arg|
8556 {special}) when 'shell' contains "csh" in the tail. That is
8557 because for csh and tcsh "!" is used for history replacement
8558 even when inside single quotes.
8559
8560 With a |non-zero-arg| {special} the <NL> character is also
8561 escaped. When 'shell' containing "csh" in the tail it's
8562 escaped a second time.
8563
8564 The "\" character will be escaped when 'shell' contains "fish"
8565 in the tail. That is because for fish "\" is used as an escape
8566 character inside single quotes.
8567
8568 Example of use with a |:!| command: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00008569 :exe '!dir ' .. shellescape(expand('<cfile>'), 1)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008570< This results in a directory listing for the file under the
8571 cursor. Example of use with |system()|: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00008572 :call system("chmod +w -- " .. shellescape(expand("%")))
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008573< See also |::S|.
8574
8575 Can also be used as a |method|: >
8576 GetCommand()->shellescape()
8577
8578shiftwidth([{col}]) *shiftwidth()*
8579 Returns the effective value of 'shiftwidth'. This is the
8580 'shiftwidth' value unless it is zero, in which case it is the
8581 'tabstop' value. This function was introduced with patch
8582 7.3.694 in 2012, everybody should have it by now (however it
8583 did not allow for the optional {col} argument until 8.1.542).
8584
8585 When there is one argument {col} this is used as column number
8586 for which to return the 'shiftwidth' value. This matters for the
8587 'vartabstop' feature. If the 'vartabstop' setting is enabled and
8588 no {col} argument is given, column 1 will be assumed.
8589
8590 Can also be used as a |method|: >
8591 GetColumn()->shiftwidth()
8592
8593sign_ functions are documented here: |sign-functions-details|
8594
8595
8596simplify({filename}) *simplify()*
8597 Simplify the file name as much as possible without changing
8598 the meaning. Shortcuts (on MS-Windows) or symbolic links (on
8599 Unix) are not resolved. If the first path component in
8600 {filename} designates the current directory, this will be
8601 valid for the result as well. A trailing path separator is
8602 not removed either. On Unix "//path" is unchanged, but
8603 "///path" is simplified to "/path" (this follows the Posix
8604 standard).
8605 Example: >
8606 simplify("./dir/.././/file/") == "./file/"
8607< Note: The combination "dir/.." is only removed if "dir" is
8608 a searchable directory or does not exist. On Unix, it is also
8609 removed when "dir" is a symbolic link within the same
8610 directory. In order to resolve all the involved symbolic
8611 links before simplifying the path name, use |resolve()|.
8612
8613 Can also be used as a |method|: >
8614 GetName()->simplify()
8615
8616sin({expr}) *sin()*
8617 Return the sine of {expr}, measured in radians, as a |Float|.
8618 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01008619 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008620 Examples: >
8621 :echo sin(100)
8622< -0.506366 >
8623 :echo sin(-4.01)
8624< 0.763301
8625
8626 Can also be used as a |method|: >
8627 Compute()->sin()
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008628
8629
8630sinh({expr}) *sinh()*
8631 Return the hyperbolic sine of {expr} as a |Float| in the range
8632 [-inf, inf].
8633 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01008634 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008635 Examples: >
8636 :echo sinh(0.5)
8637< 0.521095 >
8638 :echo sinh(-0.9)
8639< -1.026517
8640
8641 Can also be used as a |method|: >
8642 Compute()->sinh()
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008643
8644
8645slice({expr}, {start} [, {end}]) *slice()*
8646 Similar to using a |slice| "expr[start : end]", but "end" is
8647 used exclusive. And for a string the indexes are used as
8648 character indexes instead of byte indexes, like in
8649 |vim9script|. Also, composing characters are not counted.
8650 When {end} is omitted the slice continues to the last item.
8651 When {end} is -1 the last item is omitted.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01008652 Returns an empty value if {start} or {end} are invalid.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008653
8654 Can also be used as a |method|: >
8655 GetList()->slice(offset)
8656
8657
Bram Moolenaar2007dd42022-02-23 13:17:47 +00008658sort({list} [, {how} [, {dict}]]) *sort()* *E702*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008659 Sort the items in {list} in-place. Returns {list}.
8660
8661 If you want a list to remain unmodified make a copy first: >
8662 :let sortedlist = sort(copy(mylist))
8663
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01008664< When {how} is omitted or is a string, then sort() uses the
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008665 string representation of each item to sort on. Numbers sort
8666 after Strings, |Lists| after Numbers. For sorting text in the
8667 current buffer use |:sort|.
8668
Bram Moolenaar2007dd42022-02-23 13:17:47 +00008669 When {how} is given and it is 'i' then case is ignored.
8670 In legacy script, for backwards compatibility, the value one
8671 can be used to ignore case. Zero means to not ignore case.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008672
Bram Moolenaar2007dd42022-02-23 13:17:47 +00008673 When {how} is given and it is 'l' then the current collation
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008674 locale is used for ordering. Implementation details: strcoll()
8675 is used to compare strings. See |:language| check or set the
8676 collation locale. |v:collate| can also be used to check the
8677 current locale. Sorting using the locale typically ignores
8678 case. Example: >
8679 " ö is sorted similarly to o with English locale.
8680 :language collate en_US.UTF8
8681 :echo sort(['n', 'o', 'O', 'ö', 'p', 'z'], 'l')
8682< ['n', 'o', 'O', 'ö', 'p', 'z'] ~
8683>
8684 " ö is sorted after z with Swedish locale.
8685 :language collate sv_SE.UTF8
8686 :echo sort(['n', 'o', 'O', 'ö', 'p', 'z'], 'l')
8687< ['n', 'o', 'O', 'p', 'z', 'ö'] ~
8688 This does not work properly on Mac.
8689
Bram Moolenaar2007dd42022-02-23 13:17:47 +00008690 When {how} is given and it is 'n' then all items will be
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008691 sorted numerical (Implementation detail: this uses the
Bram Moolenaarbe19d782023-03-09 22:06:49 +00008692 strtod() function to parse numbers. Strings, Lists, Dicts and
8693 Funcrefs will be considered as being 0). Note that this won't
8694 sort a list of strings with numbers!
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008695
Bram Moolenaar2007dd42022-02-23 13:17:47 +00008696 When {how} is given and it is 'N' then all items will be
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008697 sorted numerical. This is like 'n' but a string containing
8698 digits will be used as the number they represent.
8699
Bram Moolenaar2007dd42022-02-23 13:17:47 +00008700 When {how} is given and it is 'f' then all items will be
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008701 sorted numerical. All values must be a Number or a Float.
8702
Bram Moolenaar2007dd42022-02-23 13:17:47 +00008703 When {how} is a |Funcref| or a function name, this function
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008704 is called to compare items. The function is invoked with two
8705 items as argument and must return zero if they are equal, 1 or
8706 bigger if the first one sorts after the second one, -1 or
8707 smaller if the first one sorts before the second one.
8708
8709 {dict} is for functions with the "dict" attribute. It will be
8710 used to set the local variable "self". |Dictionary-function|
8711
8712 The sort is stable, items which compare equal (as number or as
8713 string) will keep their relative position. E.g., when sorting
8714 on numbers, text strings will sort next to each other, in the
8715 same order as they were originally.
8716
8717 Can also be used as a |method|: >
8718 mylist->sort()
8719
8720< Also see |uniq()|.
8721
8722 Example: >
8723 func MyCompare(i1, i2)
8724 return a:i1 == a:i2 ? 0 : a:i1 > a:i2 ? 1 : -1
8725 endfunc
8726 eval mylist->sort("MyCompare")
8727< A shorter compare version for this specific simple case, which
8728 ignores overflow: >
8729 func MyCompare(i1, i2)
8730 return a:i1 - a:i2
8731 endfunc
8732< For a simple expression you can use a lambda: >
8733 eval mylist->sort({i1, i2 -> i1 - i2})
8734<
8735sound_clear() *sound_clear()*
8736 Stop playing all sounds.
8737
8738 On some Linux systems you may need the libcanberra-pulse
8739 package, otherwise sound may not stop.
8740
8741 {only available when compiled with the |+sound| feature}
8742
8743 *sound_playevent()*
8744sound_playevent({name} [, {callback}])
8745 Play a sound identified by {name}. Which event names are
8746 supported depends on the system. Often the XDG sound names
8747 are used. On Ubuntu they may be found in
8748 /usr/share/sounds/freedesktop/stereo. Example: >
8749 call sound_playevent('bell')
8750< On MS-Windows, {name} can be SystemAsterisk, SystemDefault,
8751 SystemExclamation, SystemExit, SystemHand, SystemQuestion,
8752 SystemStart, SystemWelcome, etc.
Yee Cheng Chin4314e4f2022-10-08 13:50:05 +01008753 On macOS, {name} refers to files located in
8754 /System/Library/Sounds (e.g. "Tink"). It will also work for
8755 custom installed sounds in folders like ~/Library/Sounds.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008756
8757 When {callback} is specified it is invoked when the sound is
8758 finished. The first argument is the sound ID, the second
8759 argument is the status:
8760 0 sound was played to the end
8761 1 sound was interrupted
8762 2 error occurred after sound started
8763 Example: >
8764 func Callback(id, status)
8765 echomsg "sound " .. a:id .. " finished with " .. a:status
8766 endfunc
8767 call sound_playevent('bell', 'Callback')
8768
8769< MS-Windows: {callback} doesn't work for this function.
8770
8771 Returns the sound ID, which can be passed to `sound_stop()`.
8772 Returns zero if the sound could not be played.
8773
8774 Can also be used as a |method|: >
8775 GetSoundName()->sound_playevent()
8776
8777< {only available when compiled with the |+sound| feature}
8778
8779 *sound_playfile()*
8780sound_playfile({path} [, {callback}])
8781 Like `sound_playevent()` but play sound file {path}. {path}
8782 must be a full path. On Ubuntu you may find files to play
8783 with this command: >
8784 :!find /usr/share/sounds -type f | grep -v index.theme
8785
8786< Can also be used as a |method|: >
8787 GetSoundPath()->sound_playfile()
8788
Bram Moolenaar1588bc82022-03-08 21:35:07 +00008789< {only available when compiled with the |+sound| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008790
8791
8792sound_stop({id}) *sound_stop()*
8793 Stop playing sound {id}. {id} must be previously returned by
8794 `sound_playevent()` or `sound_playfile()`.
8795
8796 On some Linux systems you may need the libcanberra-pulse
8797 package, otherwise sound may not stop.
8798
8799 On MS-Windows, this does not work for event sound started by
8800 `sound_playevent()`. To stop event sounds, use `sound_clear()`.
8801
8802 Can also be used as a |method|: >
8803 soundid->sound_stop()
8804
8805< {only available when compiled with the |+sound| feature}
8806
8807 *soundfold()*
8808soundfold({word})
8809 Return the sound-folded equivalent of {word}. Uses the first
8810 language in 'spelllang' for the current window that supports
8811 soundfolding. 'spell' must be set. When no sound folding is
8812 possible the {word} is returned unmodified.
8813 This can be used for making spelling suggestions. Note that
8814 the method can be quite slow.
8815
8816 Can also be used as a |method|: >
8817 GetWord()->soundfold()
8818<
8819 *spellbadword()*
8820spellbadword([{sentence}])
8821 Without argument: The result is the badly spelled word under
8822 or after the cursor. The cursor is moved to the start of the
8823 bad word. When no bad word is found in the cursor line the
8824 result is an empty string and the cursor doesn't move.
8825
8826 With argument: The result is the first word in {sentence} that
8827 is badly spelled. If there are no spelling mistakes the
8828 result is an empty string.
8829
8830 The return value is a list with two items:
8831 - The badly spelled word or an empty string.
8832 - The type of the spelling error:
8833 "bad" spelling mistake
8834 "rare" rare word
8835 "local" word only valid in another region
8836 "caps" word should start with Capital
8837 Example: >
8838 echo spellbadword("the quik brown fox")
8839< ['quik', 'bad'] ~
8840
8841 The spelling information for the current window and the value
8842 of 'spelllang' are used.
8843
8844 Can also be used as a |method|: >
8845 GetText()->spellbadword()
8846<
8847 *spellsuggest()*
8848spellsuggest({word} [, {max} [, {capital}]])
8849 Return a |List| with spelling suggestions to replace {word}.
8850 When {max} is given up to this number of suggestions are
8851 returned. Otherwise up to 25 suggestions are returned.
8852
8853 When the {capital} argument is given and it's non-zero only
8854 suggestions with a leading capital will be given. Use this
8855 after a match with 'spellcapcheck'.
8856
8857 {word} can be a badly spelled word followed by other text.
8858 This allows for joining two words that were split. The
8859 suggestions also include the following text, thus you can
8860 replace a line.
8861
8862 {word} may also be a good word. Similar words will then be
8863 returned. {word} itself is not included in the suggestions,
8864 although it may appear capitalized.
8865
8866 The spelling information for the current window is used. The
8867 values of 'spelllang' and 'spellsuggest' are used.
8868
8869 Can also be used as a |method|: >
8870 GetWord()->spellsuggest()
8871
8872split({string} [, {pattern} [, {keepempty}]]) *split()*
8873 Make a |List| out of {string}. When {pattern} is omitted or
8874 empty each white-separated sequence of characters becomes an
8875 item.
8876 Otherwise the string is split where {pattern} matches,
8877 removing the matched characters. 'ignorecase' is not used
8878 here, add \c to ignore case. |/\c|
8879 When the first or last item is empty it is omitted, unless the
8880 {keepempty} argument is given and it's non-zero.
8881 Other empty items are kept when {pattern} matches at least one
8882 character or when {keepempty} is non-zero.
8883 Example: >
8884 :let words = split(getline('.'), '\W\+')
8885< To split a string in individual characters: >
8886 :for c in split(mystring, '\zs')
8887< If you want to keep the separator you can also use '\zs' at
8888 the end of the pattern: >
8889 :echo split('abc:def:ghi', ':\zs')
8890< ['abc:', 'def:', 'ghi'] ~
8891 Splitting a table where the first element can be empty: >
8892 :let items = split(line, ':', 1)
8893< The opposite function is |join()|.
8894
8895 Can also be used as a |method|: >
8896 GetString()->split()
8897
8898sqrt({expr}) *sqrt()*
8899 Return the non-negative square root of Float {expr} as a
8900 |Float|.
8901 {expr} must evaluate to a |Float| or a |Number|. When {expr}
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01008902 is negative the result is NaN (Not a Number). Returns 0.0 if
8903 {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008904 Examples: >
8905 :echo sqrt(100)
8906< 10.0 >
8907 :echo sqrt(-4.01)
8908< nan
8909 "nan" may be different, it depends on system libraries.
8910
8911 Can also be used as a |method|: >
8912 Compute()->sqrt()
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008913
8914
8915srand([{expr}]) *srand()*
8916 Initialize seed used by |rand()|:
8917 - If {expr} is not given, seed values are initialized by
8918 reading from /dev/urandom, if possible, or using time(NULL)
8919 a.k.a. epoch time otherwise; this only has second accuracy.
8920 - If {expr} is given it must be a Number. It is used to
8921 initialize the seed values. This is useful for testing or
8922 when a predictable sequence is intended.
8923
8924 Examples: >
8925 :let seed = srand()
8926 :let seed = srand(userinput)
8927 :echo rand(seed)
8928
8929state([{what}]) *state()*
8930 Return a string which contains characters indicating the
8931 current state. Mostly useful in callbacks that want to do
8932 work that may not always be safe. Roughly this works like:
8933 - callback uses state() to check if work is safe to do.
8934 Yes: then do it right away.
8935 No: add to work queue and add a |SafeState| and/or
8936 |SafeStateAgain| autocommand (|SafeState| triggers at
8937 toplevel, |SafeStateAgain| triggers after handling
8938 messages and callbacks).
8939 - When SafeState or SafeStateAgain is triggered and executes
8940 your autocommand, check with `state()` if the work can be
8941 done now, and if yes remove it from the queue and execute.
8942 Remove the autocommand if the queue is now empty.
8943 Also see |mode()|.
8944
8945 When {what} is given only characters in this string will be
8946 added. E.g, this checks if the screen has scrolled: >
8947 if state('s') == ''
8948 " screen has not scrolled
8949<
8950 These characters indicate the state, generally indicating that
8951 something is busy:
8952 m halfway a mapping, :normal command, feedkeys() or
8953 stuffed command
8954 o operator pending, e.g. after |d|
8955 a Insert mode autocomplete active
8956 x executing an autocommand
8957 w blocked on waiting, e.g. ch_evalexpr(), ch_read() and
8958 ch_readraw() when reading json
8959 S not triggering SafeState or SafeStateAgain, e.g. after
8960 |f| or a count
8961 c callback invoked, including timer (repeats for
8962 recursiveness up to "ccc")
8963 s screen has scrolled for messages
8964
8965str2float({string} [, {quoted}]) *str2float()*
8966 Convert String {string} to a Float. This mostly works the
8967 same as when using a floating point number in an expression,
8968 see |floating-point-format|. But it's a bit more permissive.
8969 E.g., "1e40" is accepted, while in an expression you need to
8970 write "1.0e40". The hexadecimal form "0x123" is also
8971 accepted, but not others, like binary or octal.
8972 When {quoted} is present and non-zero then embedded single
8973 quotes before the dot are ignored, thus "1'000.0" is a
8974 thousand.
8975 Text after the number is silently ignored.
8976 The decimal point is always '.', no matter what the locale is
8977 set to. A comma ends the number: "12,345.67" is converted to
8978 12.0. You can strip out thousands separators with
8979 |substitute()|: >
8980 let f = str2float(substitute(text, ',', '', 'g'))
8981<
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01008982 Returns 0.0 if the conversion fails.
8983
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008984 Can also be used as a |method|: >
8985 let f = text->substitute(',', '', 'g')->str2float()
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008986
8987str2list({string} [, {utf8}]) *str2list()*
8988 Return a list containing the number values which represent
8989 each character in String {string}. Examples: >
8990 str2list(" ") returns [32]
8991 str2list("ABC") returns [65, 66, 67]
8992< |list2str()| does the opposite.
8993
8994 When {utf8} is omitted or zero, the current 'encoding' is used.
8995 When {utf8} is TRUE, always treat the String as UTF-8
8996 characters. With UTF-8 composing characters are handled
8997 properly: >
8998 str2list("á") returns [97, 769]
8999
9000< Can also be used as a |method|: >
9001 GetString()->str2list()
9002
9003
9004str2nr({string} [, {base} [, {quoted}]]) *str2nr()*
9005 Convert string {string} to a number.
9006 {base} is the conversion base, it can be 2, 8, 10 or 16.
9007 When {quoted} is present and non-zero then embedded single
9008 quotes are ignored, thus "1'000'000" is a million.
9009
9010 When {base} is omitted base 10 is used. This also means that
9011 a leading zero doesn't cause octal conversion to be used, as
9012 with the default String to Number conversion. Example: >
9013 let nr = str2nr('0123')
9014<
9015 When {base} is 16 a leading "0x" or "0X" is ignored. With a
9016 different base the result will be zero. Similarly, when
9017 {base} is 8 a leading "0", "0o" or "0O" is ignored, and when
9018 {base} is 2 a leading "0b" or "0B" is ignored.
9019 Text after the number is silently ignored.
9020
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01009021 Returns 0 if {string} is empty or on error.
9022
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009023 Can also be used as a |method|: >
9024 GetText()->str2nr()
9025
9026
9027strcharlen({string}) *strcharlen()*
9028 The result is a Number, which is the number of characters
9029 in String {string}. Composing characters are ignored.
9030 |strchars()| can count the number of characters, counting
9031 composing characters separately.
9032
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01009033 Returns 0 if {string} is empty or on error.
9034
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009035 Also see |strlen()|, |strdisplaywidth()| and |strwidth()|.
9036
9037 Can also be used as a |method|: >
9038 GetText()->strcharlen()
9039
9040
9041strcharpart({src}, {start} [, {len} [, {skipcc}]]) *strcharpart()*
9042 Like |strpart()| but using character index and length instead
9043 of byte index and length.
9044 When {skipcc} is omitted or zero, composing characters are
9045 counted separately.
9046 When {skipcc} set to 1, Composing characters are ignored,
9047 similar to |slice()|.
9048 When a character index is used where a character does not
9049 exist it is omitted and counted as one character. For
9050 example: >
9051 strcharpart('abc', -1, 2)
9052< results in 'a'.
9053
Bram Moolenaard592deb2022-06-17 15:42:40 +01009054 Returns an empty string on error.
9055
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009056 Can also be used as a |method|: >
9057 GetText()->strcharpart(5)
9058
9059
9060strchars({string} [, {skipcc}]) *strchars()*
9061 The result is a Number, which is the number of characters
9062 in String {string}.
9063 When {skipcc} is omitted or zero, composing characters are
9064 counted separately.
9065 When {skipcc} set to 1, Composing characters are ignored.
9066 |strcharlen()| always does this.
9067
Bram Moolenaard592deb2022-06-17 15:42:40 +01009068 Returns zero on error.
9069
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009070 Also see |strlen()|, |strdisplaywidth()| and |strwidth()|.
9071
9072 {skipcc} is only available after 7.4.755. For backward
9073 compatibility, you can define a wrapper function: >
9074 if has("patch-7.4.755")
9075 function s:strchars(str, skipcc)
9076 return strchars(a:str, a:skipcc)
9077 endfunction
9078 else
9079 function s:strchars(str, skipcc)
9080 if a:skipcc
9081 return strlen(substitute(a:str, ".", "x", "g"))
9082 else
9083 return strchars(a:str)
9084 endif
9085 endfunction
9086 endif
9087<
9088 Can also be used as a |method|: >
9089 GetText()->strchars()
9090
9091strdisplaywidth({string} [, {col}]) *strdisplaywidth()*
9092 The result is a Number, which is the number of display cells
9093 String {string} occupies on the screen when it starts at {col}
9094 (first column is zero). When {col} is omitted zero is used.
9095 Otherwise it is the screen column where to start. This
9096 matters for Tab characters.
9097 The option settings of the current window are used. This
9098 matters for anything that's displayed differently, such as
9099 'tabstop' and 'display'.
9100 When {string} contains characters with East Asian Width Class
9101 Ambiguous, this function's return value depends on 'ambiwidth'.
Bram Moolenaard592deb2022-06-17 15:42:40 +01009102 Returns zero on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009103 Also see |strlen()|, |strwidth()| and |strchars()|.
9104
9105 Can also be used as a |method|: >
9106 GetText()->strdisplaywidth()
9107
9108strftime({format} [, {time}]) *strftime()*
9109 The result is a String, which is a formatted date and time, as
9110 specified by the {format} string. The given {time} is used,
9111 or the current time if no time is given. The accepted
9112 {format} depends on your system, thus this is not portable!
9113 See the manual page of the C function strftime() for the
9114 format. The maximum length of the result is 80 characters.
9115 See also |localtime()|, |getftime()| and |strptime()|.
9116 The language can be changed with the |:language| command.
9117 Examples: >
9118 :echo strftime("%c") Sun Apr 27 11:49:23 1997
9119 :echo strftime("%Y %b %d %X") 1997 Apr 27 11:53:25
9120 :echo strftime("%y%m%d %T") 970427 11:53:55
9121 :echo strftime("%H:%M") 11:55
9122 :echo strftime("%c", getftime("file.c"))
9123 Show mod time of file.c.
9124< Not available on all systems. To check use: >
9125 :if exists("*strftime")
9126
9127< Can also be used as a |method|: >
9128 GetFormat()->strftime()
9129
9130strgetchar({str}, {index}) *strgetchar()*
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01009131 Get a Number corresponding to the character at {index} in
9132 {str}. This uses a zero-based character index, not a byte
9133 index. Composing characters are considered separate
9134 characters here. Use |nr2char()| to convert the Number to a
9135 String.
Bram Moolenaard592deb2022-06-17 15:42:40 +01009136 Returns -1 if {index} is invalid.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009137 Also see |strcharpart()| and |strchars()|.
9138
9139 Can also be used as a |method|: >
9140 GetText()->strgetchar(5)
9141
9142stridx({haystack}, {needle} [, {start}]) *stridx()*
9143 The result is a Number, which gives the byte index in
9144 {haystack} of the first occurrence of the String {needle}.
9145 If {start} is specified, the search starts at index {start}.
9146 This can be used to find a second match: >
9147 :let colon1 = stridx(line, ":")
9148 :let colon2 = stridx(line, ":", colon1 + 1)
9149< The search is done case-sensitive.
9150 For pattern searches use |match()|.
9151 -1 is returned if the {needle} does not occur in {haystack}.
9152 See also |strridx()|.
9153 Examples: >
9154 :echo stridx("An Example", "Example") 3
9155 :echo stridx("Starting point", "Start") 0
9156 :echo stridx("Starting point", "start") -1
9157< *strstr()* *strchr()*
9158 stridx() works similar to the C function strstr(). When used
9159 with a single character it works similar to strchr().
9160
9161 Can also be used as a |method|: >
9162 GetHaystack()->stridx(needle)
9163<
9164 *string()*
9165string({expr}) Return {expr} converted to a String. If {expr} is a Number,
9166 Float, String, Blob or a composition of them, then the result
9167 can be parsed back with |eval()|.
9168 {expr} type result ~
9169 String 'string' (single quotes are doubled)
9170 Number 123
9171 Float 123.123456 or 1.123456e8
9172 Funcref function('name')
9173 Blob 0z00112233.44556677.8899
9174 List [item, item]
9175 Dictionary {key: value, key: value}
Bram Moolenaarf1dcd142022-12-31 15:30:45 +00009176 Class class SomeName
9177 Object object of SomeName {lnum: 1, col: 3}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009178
9179 When a |List| or |Dictionary| has a recursive reference it is
9180 replaced by "[...]" or "{...}". Using eval() on the result
9181 will then fail.
9182
9183 Can also be used as a |method|: >
9184 mylist->string()
9185
9186< Also see |strtrans()|.
9187
9188
9189strlen({string}) *strlen()*
9190 The result is a Number, which is the length of the String
9191 {string} in bytes.
9192 If the argument is a Number it is first converted to a String.
Bram Moolenaard592deb2022-06-17 15:42:40 +01009193 For other types an error is given and zero is returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009194 If you want to count the number of multibyte characters use
9195 |strchars()|.
9196 Also see |len()|, |strdisplaywidth()| and |strwidth()|.
9197
9198 Can also be used as a |method|: >
9199 GetString()->strlen()
9200
9201strpart({src}, {start} [, {len} [, {chars}]]) *strpart()*
9202 The result is a String, which is part of {src}, starting from
9203 byte {start}, with the byte length {len}.
9204 When {chars} is present and TRUE then {len} is the number of
9205 characters positions (composing characters are not counted
9206 separately, thus "1" means one base character and any
9207 following composing characters).
9208 To count {start} as characters instead of bytes use
9209 |strcharpart()|.
9210
9211 When bytes are selected which do not exist, this doesn't
9212 result in an error, the bytes are simply omitted.
9213 If {len} is missing, the copy continues from {start} till the
9214 end of the {src}. >
9215 strpart("abcdefg", 3, 2) == "de"
9216 strpart("abcdefg", -2, 4) == "ab"
9217 strpart("abcdefg", 5, 4) == "fg"
9218 strpart("abcdefg", 3) == "defg"
9219
9220< Note: To get the first character, {start} must be 0. For
9221 example, to get the character under the cursor: >
9222 strpart(getline("."), col(".") - 1, 1, v:true)
9223<
Bram Moolenaard592deb2022-06-17 15:42:40 +01009224 Returns an empty string on error.
9225
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009226 Can also be used as a |method|: >
9227 GetText()->strpart(5)
9228
9229strptime({format}, {timestring}) *strptime()*
9230 The result is a Number, which is a unix timestamp representing
9231 the date and time in {timestring}, which is expected to match
9232 the format specified in {format}.
9233
9234 The accepted {format} depends on your system, thus this is not
9235 portable! See the manual page of the C function strptime()
9236 for the format. Especially avoid "%c". The value of $TZ also
9237 matters.
9238
9239 If the {timestring} cannot be parsed with {format} zero is
9240 returned. If you do not know the format of {timestring} you
9241 can try different {format} values until you get a non-zero
9242 result.
9243
9244 See also |strftime()|.
9245 Examples: >
9246 :echo strptime("%Y %b %d %X", "1997 Apr 27 11:49:23")
9247< 862156163 >
9248 :echo strftime("%c", strptime("%y%m%d %T", "970427 11:53:55"))
9249< Sun Apr 27 11:53:55 1997 >
9250 :echo strftime("%c", strptime("%Y%m%d%H%M%S", "19970427115355") + 3600)
9251< Sun Apr 27 12:53:55 1997
9252
9253 Can also be used as a |method|: >
9254 GetFormat()->strptime(timestring)
9255<
9256 Not available on all systems. To check use: >
9257 :if exists("*strptime")
9258
9259strridx({haystack}, {needle} [, {start}]) *strridx()*
9260 The result is a Number, which gives the byte index in
9261 {haystack} of the last occurrence of the String {needle}.
9262 When {start} is specified, matches beyond this index are
9263 ignored. This can be used to find a match before a previous
9264 match: >
9265 :let lastcomma = strridx(line, ",")
9266 :let comma2 = strridx(line, ",", lastcomma - 1)
9267< The search is done case-sensitive.
9268 For pattern searches use |match()|.
9269 -1 is returned if the {needle} does not occur in {haystack}.
9270 If the {needle} is empty the length of {haystack} is returned.
9271 See also |stridx()|. Examples: >
9272 :echo strridx("an angry armadillo", "an") 3
9273< *strrchr()*
9274 When used with a single character it works similar to the C
9275 function strrchr().
9276
9277 Can also be used as a |method|: >
9278 GetHaystack()->strridx(needle)
9279
9280strtrans({string}) *strtrans()*
9281 The result is a String, which is {string} with all unprintable
9282 characters translated into printable characters |'isprint'|.
9283 Like they are shown in a window. Example: >
9284 echo strtrans(@a)
9285< This displays a newline in register a as "^@" instead of
9286 starting a new line.
9287
Bram Moolenaard592deb2022-06-17 15:42:40 +01009288 Returns an empty string on error.
9289
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009290 Can also be used as a |method|: >
9291 GetString()->strtrans()
9292
Christian Brabandt67672ef2023-04-24 21:09:54 +01009293strutf16len({string} [, {countcc}]) *strutf16len()*
9294 The result is a Number, which is the number of UTF-16 code
9295 units in String {string} (after converting it to UTF-16).
9296
9297 When {countcc} is TRUE, composing characters are counted
9298 separately.
9299 When {countcc} is omitted or FALSE, composing characters are
9300 ignored.
9301
9302 Returns zero on error.
9303
9304 Also see |strlen()| and |strcharlen()|.
9305 Examples: >
9306 echo strutf16len('a') returns 1
9307 echo strutf16len('©') returns 1
9308 echo strutf16len('😊') returns 2
9309 echo strutf16len('ą́') returns 1
9310 echo strutf16len('ą́', v:true) returns 3
9311
9312 Can also be used as a |method|: >
9313 GetText()->strutf16len()
9314<
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009315strwidth({string}) *strwidth()*
9316 The result is a Number, which is the number of display cells
9317 String {string} occupies. A Tab character is counted as one
9318 cell, alternatively use |strdisplaywidth()|.
9319 When {string} contains characters with East Asian Width Class
9320 Ambiguous, this function's return value depends on 'ambiwidth'.
Bram Moolenaard592deb2022-06-17 15:42:40 +01009321 Returns zero on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009322 Also see |strlen()|, |strdisplaywidth()| and |strchars()|.
9323
9324 Can also be used as a |method|: >
9325 GetString()->strwidth()
9326
9327submatch({nr} [, {list}]) *submatch()* *E935*
9328 Only for an expression in a |:substitute| command or
9329 substitute() function.
9330 Returns the {nr}'th submatch of the matched text. When {nr}
9331 is 0 the whole matched text is returned.
9332 Note that a NL in the string can stand for a line break of a
9333 multi-line match or a NUL character in the text.
9334 Also see |sub-replace-expression|.
9335
9336 If {list} is present and non-zero then submatch() returns
9337 a list of strings, similar to |getline()| with two arguments.
9338 NL characters in the text represent NUL characters in the
9339 text.
9340 Only returns more than one item for |:substitute|, inside
9341 |substitute()| this list will always contain one or zero
9342 items, since there are no real line breaks.
9343
9344 When substitute() is used recursively only the submatches in
9345 the current (deepest) call can be obtained.
9346
Bram Moolenaard592deb2022-06-17 15:42:40 +01009347 Returns an empty string or list on error.
9348
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009349 Examples: >
9350 :s/\d\+/\=submatch(0) + 1/
9351 :echo substitute(text, '\d\+', '\=submatch(0) + 1', '')
9352< This finds the first number in the line and adds one to it.
9353 A line break is included as a newline character.
9354
9355 Can also be used as a |method|: >
9356 GetNr()->submatch()
9357
9358substitute({string}, {pat}, {sub}, {flags}) *substitute()*
9359 The result is a String, which is a copy of {string}, in which
9360 the first match of {pat} is replaced with {sub}.
9361 When {flags} is "g", all matches of {pat} in {string} are
9362 replaced. Otherwise {flags} should be "".
9363
9364 This works like the ":substitute" command (without any flags).
9365 But the matching with {pat} is always done like the 'magic'
9366 option is set and 'cpoptions' is empty (to make scripts
9367 portable). 'ignorecase' is still relevant, use |/\c| or |/\C|
9368 if you want to ignore or match case and ignore 'ignorecase'.
9369 'smartcase' is not used. See |string-match| for how {pat} is
9370 used.
9371
9372 A "~" in {sub} is not replaced with the previous {sub}.
9373 Note that some codes in {sub} have a special meaning
9374 |sub-replace-special|. For example, to replace something with
9375 "\n" (two characters), use "\\\\n" or '\\n'.
9376
9377 When {pat} does not match in {string}, {string} is returned
9378 unmodified.
9379
9380 Example: >
9381 :let &path = substitute(&path, ",\\=[^,]*$", "", "")
9382< This removes the last component of the 'path' option. >
9383 :echo substitute("testing", ".*", "\\U\\0", "")
9384< results in "TESTING".
9385
9386 When {sub} starts with "\=", the remainder is interpreted as
9387 an expression. See |sub-replace-expression|. Example: >
9388 :echo substitute(s, '%\(\x\x\)',
Bram Moolenaarc51cf032022-02-26 12:25:45 +00009389 \ '\=nr2char("0x" .. submatch(1))', 'g')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009390
9391< When {sub} is a Funcref that function is called, with one
9392 optional argument. Example: >
9393 :echo substitute(s, '%\(\x\x\)', SubNr, 'g')
9394< The optional argument is a list which contains the whole
9395 matched string and up to nine submatches, like what
9396 |submatch()| returns. Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00009397 :echo substitute(s, '%\(\x\x\)', {m -> '0x' .. m[1]}, 'g')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009398
Bram Moolenaard592deb2022-06-17 15:42:40 +01009399< Returns an empty string on error.
9400
9401 Can also be used as a |method|: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009402 GetString()->substitute(pat, sub, flags)
9403
Bram Moolenaarc216a7a2022-12-05 13:50:55 +00009404swapfilelist() *swapfilelist()*
9405 Returns a list of swap file names, like what "vim -r" shows.
9406 See the |-r| command argument. The 'directory' option is used
9407 for the directories to inspect. If you only want to get a
9408 list of swap files in the current directory then temporarily
9409 set 'directory' to a dot: >
9410 let save_dir = &directory
9411 let &directory = '.'
9412 let swapfiles = swapfilelist()
9413 let &directory = save_dir
9414
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009415swapinfo({fname}) *swapinfo()*
9416 The result is a dictionary, which holds information about the
9417 swapfile {fname}. The available fields are:
9418 version Vim version
9419 user user name
9420 host host name
9421 fname original file name
9422 pid PID of the Vim process that created the swap
9423 file
9424 mtime last modification time in seconds
9425 inode Optional: INODE number of the file
9426 dirty 1 if file was modified, 0 if not
9427 Note that "user" and "host" are truncated to at most 39 bytes.
9428 In case of failure an "error" item is added with the reason:
9429 Cannot open file: file not found or in accessible
9430 Cannot read file: cannot read first block
9431 Not a swap file: does not contain correct block ID
9432 Magic number mismatch: Info in first block is invalid
9433
9434 Can also be used as a |method|: >
9435 GetFilename()->swapinfo()
9436
9437swapname({buf}) *swapname()*
9438 The result is the swap file path of the buffer {expr}.
9439 For the use of {buf}, see |bufname()| above.
9440 If buffer {buf} is the current buffer, the result is equal to
9441 |:swapname| (unless there is no swap file).
9442 If buffer {buf} has no swap file, returns an empty string.
9443
9444 Can also be used as a |method|: >
9445 GetBufname()->swapname()
9446
9447synID({lnum}, {col}, {trans}) *synID()*
9448 The result is a Number, which is the syntax ID at the position
9449 {lnum} and {col} in the current window.
9450 The syntax ID can be used with |synIDattr()| and
9451 |synIDtrans()| to obtain syntax information about text.
9452
9453 {col} is 1 for the leftmost column, {lnum} is 1 for the first
9454 line. 'synmaxcol' applies, in a longer line zero is returned.
9455 Note that when the position is after the last character,
9456 that's where the cursor can be in Insert mode, synID() returns
9457 zero. {lnum} is used like with |getline()|.
9458
9459 When {trans} is |TRUE|, transparent items are reduced to the
9460 item that they reveal. This is useful when wanting to know
9461 the effective color. When {trans} is |FALSE|, the transparent
9462 item is returned. This is useful when wanting to know which
9463 syntax item is effective (e.g. inside parens).
9464 Warning: This function can be very slow. Best speed is
9465 obtained by going through the file in forward direction.
9466
Bram Moolenaard592deb2022-06-17 15:42:40 +01009467 Returns zero on error.
9468
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009469 Example (echoes the name of the syntax item under the cursor): >
9470 :echo synIDattr(synID(line("."), col("."), 1), "name")
9471<
9472
9473synIDattr({synID}, {what} [, {mode}]) *synIDattr()*
9474 The result is a String, which is the {what} attribute of
9475 syntax ID {synID}. This can be used to obtain information
9476 about a syntax item.
9477 {mode} can be "gui", "cterm" or "term", to get the attributes
9478 for that mode. When {mode} is omitted, or an invalid value is
9479 used, the attributes for the currently active highlighting are
9480 used (GUI, cterm or term).
9481 Use synIDtrans() to follow linked highlight groups.
9482 {what} result
9483 "name" the name of the syntax item
9484 "fg" foreground color (GUI: color name used to set
9485 the color, cterm: color number as a string,
9486 term: empty string)
9487 "bg" background color (as with "fg")
9488 "font" font name (only available in the GUI)
9489 |highlight-font|
9490 "sp" special color for the GUI (as with "fg")
9491 |highlight-guisp|
9492 "ul" underline color for cterm: number as a string
9493 "fg#" like "fg", but for the GUI and the GUI is
9494 running the name in "#RRGGBB" form
9495 "bg#" like "fg#" for "bg"
9496 "sp#" like "fg#" for "sp"
9497 "bold" "1" if bold
9498 "italic" "1" if italic
9499 "reverse" "1" if reverse
9500 "inverse" "1" if inverse (= reverse)
9501 "standout" "1" if standout
9502 "underline" "1" if underlined
9503 "undercurl" "1" if undercurled
9504 "strike" "1" if strikethrough
Bram Moolenaarde786322022-07-30 14:56:17 +01009505 "nocombine" "1" if nocombine
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009506
Bram Moolenaard592deb2022-06-17 15:42:40 +01009507 Returns an empty string on error.
9508
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009509 Example (echoes the color of the syntax item under the
9510 cursor): >
9511 :echo synIDattr(synIDtrans(synID(line("."), col("."), 1)), "fg")
9512<
9513 Can also be used as a |method|: >
9514 :echo synID(line("."), col("."), 1)->synIDtrans()->synIDattr("fg")
9515
9516
9517synIDtrans({synID}) *synIDtrans()*
9518 The result is a Number, which is the translated syntax ID of
9519 {synID}. This is the syntax group ID of what is being used to
9520 highlight the character. Highlight links given with
9521 ":highlight link" are followed.
9522
Bram Moolenaard592deb2022-06-17 15:42:40 +01009523 Returns zero on error.
9524
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009525 Can also be used as a |method|: >
9526 :echo synID(line("."), col("."), 1)->synIDtrans()->synIDattr("fg")
9527
9528synconcealed({lnum}, {col}) *synconcealed()*
9529 The result is a |List| with currently three items:
9530 1. The first item in the list is 0 if the character at the
9531 position {lnum} and {col} is not part of a concealable
9532 region, 1 if it is. {lnum} is used like with |getline()|.
9533 2. The second item in the list is a string. If the first item
9534 is 1, the second item contains the text which will be
9535 displayed in place of the concealed text, depending on the
9536 current setting of 'conceallevel' and 'listchars'.
9537 3. The third and final item in the list is a number
9538 representing the specific syntax region matched in the
9539 line. When the character is not concealed the value is
9540 zero. This allows detection of the beginning of a new
9541 concealable region if there are two consecutive regions
9542 with the same replacement character. For an example, if
9543 the text is "123456" and both "23" and "45" are concealed
9544 and replaced by the character "X", then:
9545 call returns ~
9546 synconcealed(lnum, 1) [0, '', 0]
9547 synconcealed(lnum, 2) [1, 'X', 1]
9548 synconcealed(lnum, 3) [1, 'X', 1]
9549 synconcealed(lnum, 4) [1, 'X', 2]
9550 synconcealed(lnum, 5) [1, 'X', 2]
9551 synconcealed(lnum, 6) [0, '', 0]
9552
9553
9554synstack({lnum}, {col}) *synstack()*
9555 Return a |List|, which is the stack of syntax items at the
9556 position {lnum} and {col} in the current window. {lnum} is
9557 used like with |getline()|. Each item in the List is an ID
9558 like what |synID()| returns.
9559 The first item in the List is the outer region, following are
9560 items contained in that one. The last one is what |synID()|
9561 returns, unless not the whole item is highlighted or it is a
9562 transparent item.
9563 This function is useful for debugging a syntax file.
9564 Example that shows the syntax stack under the cursor: >
9565 for id in synstack(line("."), col("."))
9566 echo synIDattr(id, "name")
9567 endfor
9568< When the position specified with {lnum} and {col} is invalid
Bram Moolenaard592deb2022-06-17 15:42:40 +01009569 an empty List is returned. The position just after the last
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009570 character in a line and the first column in an empty line are
9571 valid positions.
9572
9573system({expr} [, {input}]) *system()* *E677*
9574 Get the output of the shell command {expr} as a |String|. See
9575 |systemlist()| to get the output as a |List|.
9576
9577 When {input} is given and is a |String| this string is written
9578 to a file and passed as stdin to the command. The string is
9579 written as-is, you need to take care of using the correct line
9580 separators yourself.
9581 If {input} is given and is a |List| it is written to the file
9582 in a way |writefile()| does with {binary} set to "b" (i.e.
9583 with a newline between each list item with newlines inside
9584 list items converted to NULs).
9585 When {input} is given and is a number that is a valid id for
9586 an existing buffer then the content of the buffer is written
9587 to the file line by line, each line terminated by a NL and
9588 NULs characters where the text has a NL.
9589
9590 Pipes are not used, the 'shelltemp' option is not used.
9591
9592 When prepended by |:silent| the terminal will not be set to
9593 cooked mode. This is meant to be used for commands that do
9594 not need the user to type. It avoids stray characters showing
9595 up on the screen which require |CTRL-L| to remove. >
9596 :silent let f = system('ls *.vim')
9597<
9598 Note: Use |shellescape()| or |::S| with |expand()| or
9599 |fnamemodify()| to escape special characters in a command
9600 argument. Newlines in {expr} may cause the command to fail.
9601 The characters in 'shellquote' and 'shellxquote' may also
9602 cause trouble.
9603 This is not to be used for interactive commands.
9604
9605 The result is a String. Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00009606 :let files = system('ls ' .. shellescape(expand('%:h')))
9607 :let files = system('ls ' .. expand('%:h:S'))
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009608
9609< To make the result more system-independent, the shell output
9610 is filtered to replace <CR> with <NL> for Macintosh, and
9611 <CR><NL> with <NL> for DOS-like systems.
9612 To avoid the string being truncated at a NUL, all NUL
9613 characters are replaced with SOH (0x01).
9614
9615 The command executed is constructed using several options:
9616 'shell' 'shellcmdflag' 'shellxquote' {expr} 'shellredir' {tmp} 'shellxquote'
9617 ({tmp} is an automatically generated file name).
9618 For Unix, braces are put around {expr} to allow for
9619 concatenated commands.
9620
9621 The command will be executed in "cooked" mode, so that a
9622 CTRL-C will interrupt the command (on Unix at least).
9623
9624 The resulting error code can be found in |v:shell_error|.
9625 This function will fail in |restricted-mode|.
9626
9627 Note that any wrong value in the options mentioned above may
9628 make the function fail. It has also been reported to fail
9629 when using a security agent application.
9630 Unlike ":!cmd" there is no automatic check for changed files.
9631 Use |:checktime| to force a check.
9632
9633 Can also be used as a |method|: >
9634 :echo GetCmd()->system()
9635
9636
9637systemlist({expr} [, {input}]) *systemlist()*
9638 Same as |system()|, but returns a |List| with lines (parts of
9639 output separated by NL) with NULs transformed into NLs. Output
9640 is the same as |readfile()| will output with {binary} argument
9641 set to "b", except that there is no extra empty item when the
9642 result ends in a NL.
9643 Note that on MS-Windows you may get trailing CR characters.
9644
9645 To see the difference between "echo hello" and "echo -n hello"
9646 use |system()| and |split()|: >
9647 echo system('echo hello')->split('\n', 1)
9648<
9649 Returns an empty string on error.
9650
9651 Can also be used as a |method|: >
9652 :echo GetCmd()->systemlist()
9653
9654
9655tabpagebuflist([{arg}]) *tabpagebuflist()*
9656 The result is a |List|, where each item is the number of the
9657 buffer associated with each window in the current tab page.
9658 {arg} specifies the number of the tab page to be used. When
9659 omitted the current tab page is used.
9660 When {arg} is invalid the number zero is returned.
9661 To get a list of all buffers in all tabs use this: >
9662 let buflist = []
9663 for i in range(tabpagenr('$'))
9664 call extend(buflist, tabpagebuflist(i + 1))
9665 endfor
9666< Note that a buffer may appear in more than one window.
9667
9668 Can also be used as a |method|: >
9669 GetTabpage()->tabpagebuflist()
9670
9671tabpagenr([{arg}]) *tabpagenr()*
9672 The result is a Number, which is the number of the current
9673 tab page. The first tab page has number 1.
9674
9675 The optional argument {arg} supports the following values:
9676 $ the number of the last tab page (the tab page
9677 count).
9678 # the number of the last accessed tab page
9679 (where |g<Tab>| goes to). if there is no
9680 previous tab page 0 is returned.
9681 The number can be used with the |:tab| command.
9682
Bram Moolenaard592deb2022-06-17 15:42:40 +01009683 Returns zero on error.
9684
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009685
9686tabpagewinnr({tabarg} [, {arg}]) *tabpagewinnr()*
9687 Like |winnr()| but for tab page {tabarg}.
9688 {tabarg} specifies the number of tab page to be used.
9689 {arg} is used like with |winnr()|:
9690 - When omitted the current window number is returned. This is
9691 the window which will be used when going to this tab page.
9692 - When "$" the number of windows is returned.
9693 - When "#" the previous window nr is returned.
9694 Useful examples: >
9695 tabpagewinnr(1) " current window of tab page 1
9696 tabpagewinnr(4, '$') " number of windows in tab page 4
9697< When {tabarg} is invalid zero is returned.
9698
9699 Can also be used as a |method|: >
9700 GetTabpage()->tabpagewinnr()
9701<
9702 *tagfiles()*
9703tagfiles() Returns a |List| with the file names used to search for tags
9704 for the current buffer. This is the 'tags' option expanded.
9705
9706
9707taglist({expr} [, {filename}]) *taglist()*
9708 Returns a |List| of tags matching the regular expression {expr}.
9709
9710 If {filename} is passed it is used to prioritize the results
9711 in the same way that |:tselect| does. See |tag-priority|.
9712 {filename} should be the full path of the file.
9713
9714 Each list item is a dictionary with at least the following
9715 entries:
9716 name Name of the tag.
9717 filename Name of the file where the tag is
9718 defined. It is either relative to the
9719 current directory or a full path.
9720 cmd Ex command used to locate the tag in
9721 the file.
9722 kind Type of the tag. The value for this
9723 entry depends on the language specific
9724 kind values. Only available when
9725 using a tags file generated by
Bram Moolenaar47c532e2022-03-19 15:18:53 +00009726 Universal/Exuberant ctags or hdrtag.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009727 static A file specific tag. Refer to
9728 |static-tag| for more information.
9729 More entries may be present, depending on the content of the
9730 tags file: access, implementation, inherits and signature.
9731 Refer to the ctags documentation for information about these
9732 fields. For C code the fields "struct", "class" and "enum"
9733 may appear, they give the name of the entity the tag is
9734 contained in.
9735
9736 The ex-command "cmd" can be either an ex search pattern, a
9737 line number or a line number followed by a byte number.
9738
9739 If there are no matching tags, then an empty list is returned.
9740
9741 To get an exact tag match, the anchors '^' and '$' should be
9742 used in {expr}. This also make the function work faster.
9743 Refer to |tag-regexp| for more information about the tag
9744 search regular expression pattern.
9745
9746 Refer to |'tags'| for information about how the tags file is
9747 located by Vim. Refer to |tags-file-format| for the format of
9748 the tags file generated by the different ctags tools.
9749
9750 Can also be used as a |method|: >
9751 GetTagpattern()->taglist()
9752
9753tan({expr}) *tan()*
9754 Return the tangent of {expr}, measured in radians, as a |Float|
9755 in the range [-inf, inf].
9756 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaard592deb2022-06-17 15:42:40 +01009757 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009758 Examples: >
9759 :echo tan(10)
9760< 0.648361 >
9761 :echo tan(-4.01)
9762< -1.181502
9763
9764 Can also be used as a |method|: >
9765 Compute()->tan()
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009766
9767
9768tanh({expr}) *tanh()*
9769 Return the hyperbolic tangent of {expr} as a |Float| in the
9770 range [-1, 1].
9771 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaard592deb2022-06-17 15:42:40 +01009772 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009773 Examples: >
9774 :echo tanh(0.5)
9775< 0.462117 >
9776 :echo tanh(-1)
9777< -0.761594
9778
9779 Can also be used as a |method|: >
9780 Compute()->tanh()
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009781
9782
9783tempname() *tempname()* *temp-file-name*
9784 The result is a String, which is the name of a file that
9785 doesn't exist. It can be used for a temporary file. The name
9786 is different for at least 26 consecutive calls. Example: >
9787 :let tmpfile = tempname()
Bram Moolenaarc51cf032022-02-26 12:25:45 +00009788 :exe "redir > " .. tmpfile
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009789< For Unix, the file will be in a private directory |tempfile|.
9790 For MS-Windows forward slashes are used when the 'shellslash'
9791 option is set, or when 'shellcmdflag' starts with '-' and
9792 'shell' does not contain powershell or pwsh.
9793
9794
9795term_ functions are documented here: |terminal-function-details|
9796
9797
9798terminalprops() *terminalprops()*
9799 Returns a |Dictionary| with properties of the terminal that Vim
9800 detected from the response to |t_RV| request. See
9801 |v:termresponse| for the response itself. If |v:termresponse|
9802 is empty most values here will be 'u' for unknown.
9803 cursor_style whether sending |t_RS| works **
9804 cursor_blink_mode whether sending |t_RC| works **
9805 underline_rgb whether |t_8u| works **
9806 mouse mouse type supported
Bram Moolenaar4bc85f22022-10-21 14:17:24 +01009807 kitty whether Kitty terminal was detected
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009808
9809 ** value 'u' for unknown, 'y' for yes, 'n' for no
9810
9811 If the |+termresponse| feature is missing then the result is
9812 an empty dictionary.
9813
9814 If "cursor_style" is 'y' then |t_RS| will be sent to request the
9815 current cursor style.
9816 If "cursor_blink_mode" is 'y' then |t_RC| will be sent to
9817 request the cursor blink status.
9818 "cursor_style" and "cursor_blink_mode" are also set if |t_u7|
9819 is not empty, Vim will detect the working of sending |t_RS|
9820 and |t_RC| on startup.
9821
9822 When "underline_rgb" is not 'y', then |t_8u| will be made empty.
9823 This avoids sending it to xterm, which would clear the colors.
9824
9825 For "mouse" the value 'u' is unknown
9826
9827 Also see:
9828 - 'ambiwidth' - detected by using |t_u7|.
9829 - |v:termstyleresp| and |v:termblinkresp| for the response to
9830 |t_RS| and |t_RC|.
9831
9832
9833test_ functions are documented here: |test-functions-details|
9834
9835
9836 *timer_info()*
9837timer_info([{id}])
9838 Return a list with information about timers.
9839 When {id} is given only information about this timer is
9840 returned. When timer {id} does not exist an empty list is
9841 returned.
9842 When {id} is omitted information about all timers is returned.
9843
9844 For each timer the information is stored in a |Dictionary| with
9845 these items:
9846 "id" the timer ID
9847 "time" time the timer was started with
9848 "remaining" time until the timer fires
9849 "repeat" number of times the timer will still fire;
9850 -1 means forever
9851 "callback" the callback
9852 "paused" 1 if the timer is paused, 0 otherwise
9853
9854 Can also be used as a |method|: >
9855 GetTimer()->timer_info()
9856
9857< {only available when compiled with the |+timers| feature}
9858
9859timer_pause({timer}, {paused}) *timer_pause()*
9860 Pause or unpause a timer. A paused timer does not invoke its
9861 callback when its time expires. Unpausing a timer may cause
9862 the callback to be invoked almost immediately if enough time
9863 has passed.
9864
9865 Pausing a timer is useful to avoid the callback to be called
9866 for a short time.
9867
9868 If {paused} evaluates to a non-zero Number or a non-empty
9869 String, then the timer is paused, otherwise it is unpaused.
9870 See |non-zero-arg|.
9871
9872 Can also be used as a |method|: >
9873 GetTimer()->timer_pause(1)
9874
9875< {only available when compiled with the |+timers| feature}
9876
9877 *timer_start()* *timer* *timers*
9878timer_start({time}, {callback} [, {options}])
9879 Create a timer and return the timer ID.
9880
9881 {time} is the waiting time in milliseconds. This is the
9882 minimum time before invoking the callback. When the system is
9883 busy or Vim is not waiting for input the time will be longer.
Bram Moolenaardd60c362023-02-27 15:49:53 +00009884 Zero can be used to execute the callback when Vim is back in
9885 the main loop.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009886
9887 {callback} is the function to call. It can be the name of a
9888 function or a |Funcref|. It is called with one argument, which
9889 is the timer ID. The callback is only invoked when Vim is
9890 waiting for input.
9891 If you want to show a message look at |popup_notification()|
9892 to avoid interfering with what the user is doing.
9893
9894 {options} is a dictionary. Supported entries:
9895 "repeat" Number of times to repeat calling the
9896 callback. -1 means forever. When not present
9897 the callback will be called once.
9898 If the timer causes an error three times in a
9899 row the repeat is cancelled. This avoids that
9900 Vim becomes unusable because of all the error
9901 messages.
9902
Bram Moolenaard592deb2022-06-17 15:42:40 +01009903 Returns -1 on error.
9904
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009905 Example: >
9906 func MyHandler(timer)
9907 echo 'Handler called'
9908 endfunc
9909 let timer = timer_start(500, 'MyHandler',
9910 \ {'repeat': 3})
9911< This will invoke MyHandler() three times at 500 msec
9912 intervals.
9913
9914 Can also be used as a |method|: >
9915 GetMsec()->timer_start(callback)
9916
9917< Not available in the |sandbox|.
9918 {only available when compiled with the |+timers| feature}
9919
9920timer_stop({timer}) *timer_stop()*
9921 Stop a timer. The timer callback will no longer be invoked.
9922 {timer} is an ID returned by timer_start(), thus it must be a
9923 Number. If {timer} does not exist there is no error.
9924
9925 Can also be used as a |method|: >
9926 GetTimer()->timer_stop()
9927
9928< {only available when compiled with the |+timers| feature}
9929
9930timer_stopall() *timer_stopall()*
9931 Stop all timers. The timer callbacks will no longer be
9932 invoked. Useful if a timer is misbehaving. If there are no
9933 timers there is no error.
9934
9935 {only available when compiled with the |+timers| feature}
9936
9937tolower({expr}) *tolower()*
9938 The result is a copy of the String given, with all uppercase
9939 characters turned into lowercase (just like applying |gu| to
Bram Moolenaard592deb2022-06-17 15:42:40 +01009940 the string). Returns an empty string on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009941
9942 Can also be used as a |method|: >
9943 GetText()->tolower()
9944
9945toupper({expr}) *toupper()*
9946 The result is a copy of the String given, with all lowercase
9947 characters turned into uppercase (just like applying |gU| to
Bram Moolenaard592deb2022-06-17 15:42:40 +01009948 the string). Returns an empty string on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009949
9950 Can also be used as a |method|: >
9951 GetText()->toupper()
9952
9953tr({src}, {fromstr}, {tostr}) *tr()*
9954 The result is a copy of the {src} string with all characters
9955 which appear in {fromstr} replaced by the character in that
9956 position in the {tostr} string. Thus the first character in
9957 {fromstr} is translated into the first character in {tostr}
9958 and so on. Exactly like the unix "tr" command.
9959 This code also deals with multibyte characters properly.
9960
Bram Moolenaard592deb2022-06-17 15:42:40 +01009961 Returns an empty string on error.
9962
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009963 Examples: >
9964 echo tr("hello there", "ht", "HT")
9965< returns "Hello THere" >
9966 echo tr("<blob>", "<>", "{}")
9967< returns "{blob}"
9968
9969 Can also be used as a |method|: >
9970 GetText()->tr(from, to)
9971
9972trim({text} [, {mask} [, {dir}]]) *trim()*
9973 Return {text} as a String where any character in {mask} is
9974 removed from the beginning and/or end of {text}.
9975
9976 If {mask} is not given, {mask} is all characters up to 0x20,
9977 which includes Tab, space, NL and CR, plus the non-breaking
9978 space character 0xa0.
9979
9980 The optional {dir} argument specifies where to remove the
9981 characters:
9982 0 remove from the beginning and end of {text}
9983 1 remove only at the beginning of {text}
9984 2 remove only at the end of {text}
9985 When omitted both ends are trimmed.
9986
9987 This function deals with multibyte characters properly.
Bram Moolenaard592deb2022-06-17 15:42:40 +01009988 Returns an empty string on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009989
9990 Examples: >
9991 echo trim(" some text ")
9992< returns "some text" >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00009993 echo trim(" \r\t\t\r RESERVE \t\n\x0B\xA0") .. "_TAIL"
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009994< returns "RESERVE_TAIL" >
9995 echo trim("rm<Xrm<>X>rrm", "rm<>")
9996< returns "Xrm<>X" (characters in the middle are not removed) >
9997 echo trim(" vim ", " ", 2)
9998< returns " vim"
9999
10000 Can also be used as a |method|: >
10001 GetText()->trim()
10002
10003trunc({expr}) *trunc()*
10004 Return the largest integral value with magnitude less than or
10005 equal to {expr} as a |Float| (truncate towards zero).
10006 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaard592deb2022-06-17 15:42:40 +010010007 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010008 Examples: >
10009 echo trunc(1.456)
10010< 1.0 >
10011 echo trunc(-5.456)
10012< -5.0 >
10013 echo trunc(4.0)
10014< 4.0
10015
10016 Can also be used as a |method|: >
10017 Compute()->trunc()
10018<
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010019 *type()*
10020type({expr}) The result is a Number representing the type of {expr}.
10021 Instead of using the number directly, it is better to use the
10022 v:t_ variable that has the value:
10023 Number: 0 |v:t_number|
10024 String: 1 |v:t_string|
10025 Funcref: 2 |v:t_func|
10026 List: 3 |v:t_list|
10027 Dictionary: 4 |v:t_dict|
10028 Float: 5 |v:t_float|
10029 Boolean: 6 |v:t_bool| (v:false and v:true)
10030 None: 7 |v:t_none| (v:null and v:none)
10031 Job: 8 |v:t_job|
10032 Channel: 9 |v:t_channel|
10033 Blob: 10 |v:t_blob|
Bram Moolenaarc0c2c262023-01-12 21:08:53 +000010034 Class 12 |v:t_class|
10035 Object 13 |v:t_object|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010036 For backward compatibility, this method can be used: >
10037 :if type(myvar) == type(0)
10038 :if type(myvar) == type("")
10039 :if type(myvar) == type(function("tr"))
10040 :if type(myvar) == type([])
10041 :if type(myvar) == type({})
10042 :if type(myvar) == type(0.0)
10043 :if type(myvar) == type(v:false)
10044 :if type(myvar) == type(v:none)
10045< To check if the v:t_ variables exist use this: >
10046 :if exists('v:t_number')
10047
10048< Can also be used as a |method|: >
10049 mylist->type()
10050
10051
10052typename({expr}) *typename()*
10053 Return a string representation of the type of {expr}.
10054 Example: >
10055 echo typename([1, 2, 3])
Kota Kato66bb9ae2023-01-17 18:31:56 +000010056< list<number> ~
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010057
10058
10059undofile({name}) *undofile()*
10060 Return the name of the undo file that would be used for a file
10061 with name {name} when writing. This uses the 'undodir'
10062 option, finding directories that exist. It does not check if
10063 the undo file exists.
10064 {name} is always expanded to the full path, since that is what
10065 is used internally.
10066 If {name} is empty undofile() returns an empty string, since a
10067 buffer without a file name will not write an undo file.
10068 Useful in combination with |:wundo| and |:rundo|.
10069 When compiled without the |+persistent_undo| option this always
10070 returns an empty string.
10071
10072 Can also be used as a |method|: >
10073 GetFilename()->undofile()
10074
10075undotree() *undotree()*
10076 Return the current state of the undo tree in a dictionary with
10077 the following items:
10078 "seq_last" The highest undo sequence number used.
10079 "seq_cur" The sequence number of the current position in
10080 the undo tree. This differs from "seq_last"
10081 when some changes were undone.
10082 "time_cur" Time last used for |:earlier| and related
10083 commands. Use |strftime()| to convert to
10084 something readable.
10085 "save_last" Number of the last file write. Zero when no
10086 write yet.
10087 "save_cur" Number of the current position in the undo
10088 tree.
10089 "synced" Non-zero when the last undo block was synced.
10090 This happens when waiting from input from the
10091 user. See |undo-blocks|.
10092 "entries" A list of dictionaries with information about
10093 undo blocks.
10094
10095 The first item in the "entries" list is the oldest undo item.
10096 Each List item is a |Dictionary| with these items:
10097 "seq" Undo sequence number. Same as what appears in
10098 |:undolist|.
10099 "time" Timestamp when the change happened. Use
10100 |strftime()| to convert to something readable.
10101 "newhead" Only appears in the item that is the last one
10102 that was added. This marks the last change
10103 and where further changes will be added.
10104 "curhead" Only appears in the item that is the last one
10105 that was undone. This marks the current
10106 position in the undo tree, the block that will
10107 be used by a redo command. When nothing was
10108 undone after the last change this item will
10109 not appear anywhere.
10110 "save" Only appears on the last block before a file
10111 write. The number is the write count. The
10112 first write has number 1, the last one the
10113 "save_last" mentioned above.
10114 "alt" Alternate entry. This is again a List of undo
10115 blocks. Each item may again have an "alt"
10116 item.
10117
10118uniq({list} [, {func} [, {dict}]]) *uniq()* *E882*
10119 Remove second and succeeding copies of repeated adjacent
10120 {list} items in-place. Returns {list}. If you want a list
10121 to remain unmodified make a copy first: >
10122 :let newlist = uniq(copy(mylist))
10123< The default compare function uses the string representation of
10124 each item. For the use of {func} and {dict} see |sort()|.
10125
Bram Moolenaard592deb2022-06-17 15:42:40 +010010126 Returns zero if {list} is not a |List|.
10127
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010128 Can also be used as a |method|: >
10129 mylist->uniq()
Christian Brabandt67672ef2023-04-24 21:09:54 +010010130<
10131 *utf16idx()*
10132utf16idx({string}, {idx} [, {countcc} [, {charidx}]])
Yegappan Lakshmanan577922b2023-06-08 17:09:45 +010010133 Same as |charidx()| but returns the UTF-16 code unit index of
10134 the byte at {idx} in {string} (after converting it to UTF-16).
Christian Brabandt67672ef2023-04-24 21:09:54 +010010135
10136 When {charidx} is present and TRUE, {idx} is used as the
10137 character index in the String {string} instead of as the byte
10138 index.
Yegappan Lakshmanan95707032023-06-14 13:10:15 +010010139 An {idx} in the middle of a UTF-8 sequence is rounded
10140 downwards to the beginning of that sequence.
Christian Brabandt67672ef2023-04-24 21:09:54 +010010141
Yegappan Lakshmanan577922b2023-06-08 17:09:45 +010010142 Returns -1 if the arguments are invalid or if there are less
10143 than {idx} bytes in {string}. If there are exactly {idx} bytes
10144 the length of the string in UTF-16 code units is returned.
10145
Christian Brabandt67672ef2023-04-24 21:09:54 +010010146 See |byteidx()| and |byteidxcomp()| for getting the byte index
10147 from the UTF-16 index and |charidx()| for getting the
10148 character index from the UTF-16 index.
10149 Refer to |string-offset-encoding| for more information.
10150 Examples: >
10151 echo utf16idx('a😊😊', 3) returns 2
10152 echo utf16idx('a😊😊', 7) returns 4
10153 echo utf16idx('a😊😊', 1, 0, 1) returns 2
10154 echo utf16idx('a😊😊', 2, 0, 1) returns 4
10155 echo utf16idx('aą́c', 6) returns 2
10156 echo utf16idx('aą́c', 6, 1) returns 4
10157 echo utf16idx('a😊😊', 9) returns -1
10158<
10159 Can also be used as a |method|: >
10160 GetName()->utf16idx(idx)
10161
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010162
10163values({dict}) *values()*
10164 Return a |List| with all the values of {dict}. The |List| is
10165 in arbitrary order. Also see |items()| and |keys()|.
Bram Moolenaard592deb2022-06-17 15:42:40 +010010166 Returns zero if {dict} is not a |Dict|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010167
10168 Can also be used as a |method|: >
10169 mydict->values()
10170
LemonBoy0f7a3e12022-05-26 12:10:37 +010010171virtcol({expr} [, {list}]) *virtcol()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010172 The result is a Number, which is the screen column of the file
10173 position given with {expr}. That is, the last screen position
10174 occupied by the character at that position, when the screen
10175 would be of unlimited width. When there is a <Tab> at the
10176 position, the returned Number will be the column at the end of
10177 the <Tab>. For example, for a <Tab> in column 1, with 'ts'
10178 set to 8, it returns 8. |conceal| is ignored.
10179 For the byte position use |col()|.
LemonBoy0f7a3e12022-05-26 12:10:37 +010010180
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010181 For the use of {expr} see |col()|.
LemonBoy0f7a3e12022-05-26 12:10:37 +010010182
10183 When 'virtualedit' is used {expr} can be [lnum, col, off],
10184 where "off" is the offset in screen columns from the start of
10185 the character. E.g., a position within a <Tab> or after the
10186 last character. When "off" is omitted zero is used. When
10187 Virtual editing is active in the current mode, a position
10188 beyond the end of the line can be returned. Also see
10189 |'virtualedit'|
10190
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010191 The accepted positions are:
10192 . the cursor position
10193 $ the end of the cursor line (the result is the
10194 number of displayed characters in the cursor line
10195 plus one)
10196 'x position of mark x (if the mark is not set, 0 is
10197 returned)
10198 v In Visual mode: the start of the Visual area (the
10199 cursor is the end). When not in Visual mode
10200 returns the cursor position. Differs from |'<| in
10201 that it's updated right away.
LemonBoy0f7a3e12022-05-26 12:10:37 +010010202
10203 If {list} is present and non-zero then virtcol() returns a List
10204 with the first and last screen position occupied by the
10205 character.
10206
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010207 Note that only marks in the current file can be used.
10208 Examples: >
LemonBoy0f7a3e12022-05-26 12:10:37 +010010209 " With text "foo^Lbar" and cursor on the "^L":
10210
10211 virtcol(".") " returns 5
10212 virtcol(".", 1) " returns [4, 5]
10213 virtcol("$") " returns 9
10214
10215 " With text " there", with 't at 'h':
10216
10217 virtcol("'t") " returns 6
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010218< The first column is 1. 0 is returned for an error.
10219 A more advanced example that echoes the maximum length of
10220 all lines: >
10221 echo max(map(range(1, line('$')), "virtcol([v:val, '$'])"))
10222
10223< Can also be used as a |method|: >
10224 GetPos()->virtcol()
10225
Bram Moolenaar5a6ec102022-05-27 21:58:00 +010010226virtcol2col({winid}, {lnum}, {col}) *virtcol2col()*
10227 The result is a Number, which is the byte index of the
10228 character in window {winid} at buffer line {lnum} and virtual
10229 column {col}.
10230
10231 If {col} is greater than the last virtual column in line
10232 {lnum}, then the byte index of the character at the last
10233 virtual column is returned.
10234
10235 The {winid} argument can be the window number or the
10236 |window-ID|. If this is zero, then the current window is used.
10237
10238 Returns -1 if the window {winid} doesn't exist or the buffer
10239 line {lnum} or virtual column {col} is invalid.
10240
10241 See also |screenpos()|, |virtcol()| and |col()|.
10242
10243 Can also be used as a |method|: >
10244 GetWinid()->virtcol2col(lnum, col)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010245
10246visualmode([{expr}]) *visualmode()*
10247 The result is a String, which describes the last Visual mode
10248 used in the current buffer. Initially it returns an empty
10249 string, but once Visual mode has been used, it returns "v",
10250 "V", or "<CTRL-V>" (a single CTRL-V character) for
10251 character-wise, line-wise, or block-wise Visual mode
10252 respectively.
10253 Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +000010254 :exe "normal " .. visualmode()
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010255< This enters the same Visual mode as before. It is also useful
10256 in scripts if you wish to act differently depending on the
10257 Visual mode that was used.
10258 If Visual mode is active, use |mode()| to get the Visual mode
10259 (e.g., in a |:vmap|).
10260 If {expr} is supplied and it evaluates to a non-zero Number or
10261 a non-empty String, then the Visual mode will be cleared and
10262 the old value is returned. See |non-zero-arg|.
10263
10264wildmenumode() *wildmenumode()*
10265 Returns |TRUE| when the wildmenu is active and |FALSE|
10266 otherwise. See 'wildmenu' and 'wildmode'.
10267 This can be used in mappings to handle the 'wildcharm' option
10268 gracefully. (Makes only sense with |mapmode-c| mappings).
10269
10270 For example to make <c-j> work like <down> in wildmode, use: >
10271 :cnoremap <expr> <C-j> wildmenumode() ? "\<Down>\<Tab>" : "\<c-j>"
10272<
10273 (Note, this needs the 'wildcharm' option set appropriately).
10274
10275win_execute({id}, {command} [, {silent}]) *win_execute()*
10276 Like `execute()` but in the context of window {id}.
10277 The window will temporarily be made the current window,
10278 without triggering autocommands or changing directory. When
10279 executing {command} autocommands will be triggered, this may
Bram Moolenaarb7398fe2023-05-14 18:50:25 +010010280 have unexpected side effects. Use `:noautocmd` if needed.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010281 Example: >
10282 call win_execute(winid, 'set syntax=python')
10283< Doing the same with `setwinvar()` would not trigger
10284 autocommands and not actually show syntax highlighting.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010285 *E994*
10286 Not all commands are allowed in popup windows.
10287 When window {id} does not exist then no error is given and
10288 an empty string is returned.
10289
10290 Can also be used as a |method|, the base is passed as the
10291 second argument: >
10292 GetCommand()->win_execute(winid)
10293
10294win_findbuf({bufnr}) *win_findbuf()*
10295 Returns a |List| with |window-ID|s for windows that contain
10296 buffer {bufnr}. When there is none the list is empty.
10297
10298 Can also be used as a |method|: >
10299 GetBufnr()->win_findbuf()
10300
10301win_getid([{win} [, {tab}]]) *win_getid()*
10302 Get the |window-ID| for the specified window.
10303 When {win} is missing use the current window.
10304 With {win} this is the window number. The top window has
10305 number 1.
10306 Without {tab} use the current tab, otherwise the tab with
10307 number {tab}. The first tab has number one.
10308 Return zero if the window cannot be found.
10309
10310 Can also be used as a |method|: >
10311 GetWinnr()->win_getid()
10312
10313
10314win_gettype([{nr}]) *win_gettype()*
10315 Return the type of the window:
10316 "autocmd" autocommand window. Temporary window
10317 used to execute autocommands.
10318 "command" command-line window |cmdwin|
10319 (empty) normal window
10320 "loclist" |location-list-window|
10321 "popup" popup window |popup|
10322 "preview" preview window |preview-window|
10323 "quickfix" |quickfix-window|
10324 "unknown" window {nr} not found
10325
10326 When {nr} is omitted return the type of the current window.
10327 When {nr} is given return the type of this window by number or
10328 |window-ID|.
10329
10330 Also see the 'buftype' option. When running a terminal in a
10331 popup window then 'buftype' is "terminal" and win_gettype()
10332 returns "popup".
10333
10334 Can also be used as a |method|: >
10335 GetWinid()->win_gettype()
10336<
10337win_gotoid({expr}) *win_gotoid()*
10338 Go to window with ID {expr}. This may also change the current
10339 tabpage.
10340 Return TRUE if successful, FALSE if the window cannot be found.
10341
10342 Can also be used as a |method|: >
10343 GetWinid()->win_gotoid()
10344
10345win_id2tabwin({expr}) *win_id2tabwin()*
10346 Return a list with the tab number and window number of window
10347 with ID {expr}: [tabnr, winnr].
10348 Return [0, 0] if the window cannot be found.
10349
10350 Can also be used as a |method|: >
10351 GetWinid()->win_id2tabwin()
10352
10353win_id2win({expr}) *win_id2win()*
10354 Return the window number of window with ID {expr}.
10355 Return 0 if the window cannot be found in the current tabpage.
10356
10357 Can also be used as a |method|: >
10358 GetWinid()->win_id2win()
10359
Daniel Steinbergee630312022-01-10 13:36:34 +000010360win_move_separator({nr}, {offset}) *win_move_separator()*
10361 Move window {nr}'s vertical separator (i.e., the right border)
10362 by {offset} columns, as if being dragged by the mouse. {nr}
10363 can be a window number or |window-ID|. A positive {offset}
10364 moves right and a negative {offset} moves left. Moving a
10365 window's vertical separator will change the width of the
10366 window and the width of other windows adjacent to the vertical
10367 separator. The magnitude of movement may be smaller than
10368 specified (e.g., as a consequence of maintaining
10369 'winminwidth'). Returns TRUE if the window can be found and
10370 FALSE otherwise.
Bram Moolenaard592deb2022-06-17 15:42:40 +010010371 This will fail for the rightmost window and a full-width
10372 window, since it has no separator on the right.
Bram Moolenaar76db9e02022-11-09 21:21:04 +000010373 Only works for the current tab page. *E1308*
Daniel Steinbergee630312022-01-10 13:36:34 +000010374
10375 Can also be used as a |method|: >
10376 GetWinnr()->win_move_separator(offset)
10377
10378win_move_statusline({nr}, {offset}) *win_move_statusline()*
10379 Move window {nr}'s status line (i.e., the bottom border) by
10380 {offset} rows, as if being dragged by the mouse. {nr} can be a
10381 window number or |window-ID|. A positive {offset} moves down
10382 and a negative {offset} moves up. Moving a window's status
10383 line will change the height of the window and the height of
10384 other windows adjacent to the status line. The magnitude of
10385 movement may be smaller than specified (e.g., as a consequence
10386 of maintaining 'winminheight'). Returns TRUE if the window can
10387 be found and FALSE otherwise.
Bram Moolenaar76db9e02022-11-09 21:21:04 +000010388 Only works for the current tab page.
Daniel Steinbergee630312022-01-10 13:36:34 +000010389
10390 Can also be used as a |method|: >
10391 GetWinnr()->win_move_statusline(offset)
10392
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010393win_screenpos({nr}) *win_screenpos()*
10394 Return the screen position of window {nr} as a list with two
10395 numbers: [row, col]. The first window always has position
10396 [1, 1], unless there is a tabline, then it is [2, 1].
10397 {nr} can be the window number or the |window-ID|. Use zero
10398 for the current window.
10399 Returns [0, 0] if the window cannot be found in the current
10400 tabpage.
10401
10402 Can also be used as a |method|: >
10403 GetWinid()->win_screenpos()
10404<
10405win_splitmove({nr}, {target} [, {options}]) *win_splitmove()*
10406 Move the window {nr} to a new split of the window {target}.
10407 This is similar to moving to {target}, creating a new window
10408 using |:split| but having the same contents as window {nr}, and
10409 then closing {nr}.
10410
10411 Both {nr} and {target} can be window numbers or |window-ID|s.
10412 Both must be in the current tab page.
10413
10414 Returns zero for success, non-zero for failure.
10415
10416 {options} is a |Dictionary| with the following optional entries:
10417 "vertical" When TRUE, the split is created vertically,
10418 like with |:vsplit|.
10419 "rightbelow" When TRUE, the split is made below or to the
10420 right (if vertical). When FALSE, it is done
10421 above or to the left (if vertical). When not
10422 present, the values of 'splitbelow' and
10423 'splitright' are used.
10424
10425 Can also be used as a |method|: >
10426 GetWinid()->win_splitmove(target)
10427<
10428
10429 *winbufnr()*
10430winbufnr({nr}) The result is a Number, which is the number of the buffer
10431 associated with window {nr}. {nr} can be the window number or
10432 the |window-ID|.
10433 When {nr} is zero, the number of the buffer in the current
10434 window is returned.
10435 When window {nr} doesn't exist, -1 is returned.
10436 Example: >
10437 :echo "The file in the current window is " . bufname(winbufnr(0))
10438<
10439 Can also be used as a |method|: >
10440 FindWindow()->winbufnr()->bufname()
10441<
10442 *wincol()*
10443wincol() The result is a Number, which is the virtual column of the
10444 cursor in the window. This is counting screen cells from the
10445 left side of the window. The leftmost column is one.
10446
10447 *windowsversion()*
10448windowsversion()
10449 The result is a String. For MS-Windows it indicates the OS
10450 version. E.g, Windows 10 is "10.0", Windows 8 is "6.2",
10451 Windows XP is "5.1". For non-MS-Windows systems the result is
10452 an empty string.
10453
10454winheight({nr}) *winheight()*
10455 The result is a Number, which is the height of window {nr}.
10456 {nr} can be the window number or the |window-ID|.
10457 When {nr} is zero, the height of the current window is
10458 returned. When window {nr} doesn't exist, -1 is returned.
10459 An existing window always has a height of zero or more.
10460 This excludes any window toolbar line.
10461 Examples: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +000010462 :echo "The current window has " .. winheight(0) .. " lines."
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010463
10464< Can also be used as a |method|: >
10465 GetWinid()->winheight()
10466<
10467winlayout([{tabnr}]) *winlayout()*
10468 The result is a nested List containing the layout of windows
10469 in a tabpage.
10470
10471 Without {tabnr} use the current tabpage, otherwise the tabpage
10472 with number {tabnr}. If the tabpage {tabnr} is not found,
10473 returns an empty list.
10474
10475 For a leaf window, it returns:
10476 ['leaf', {winid}]
10477 For horizontally split windows, which form a column, it
10478 returns:
10479 ['col', [{nested list of windows}]]
10480 For vertically split windows, which form a row, it returns:
10481 ['row', [{nested list of windows}]]
10482
10483 Example: >
10484 " Only one window in the tab page
10485 :echo winlayout()
10486 ['leaf', 1000]
10487 " Two horizontally split windows
10488 :echo winlayout()
10489 ['col', [['leaf', 1000], ['leaf', 1001]]]
10490 " The second tab page, with three horizontally split
10491 " windows, with two vertically split windows in the
10492 " middle window
10493 :echo winlayout(2)
10494 ['col', [['leaf', 1002], ['row', [['leaf', 1003],
10495 ['leaf', 1001]]], ['leaf', 1000]]]
10496<
10497 Can also be used as a |method|: >
10498 GetTabnr()->winlayout()
10499<
10500 *winline()*
10501winline() The result is a Number, which is the screen line of the cursor
10502 in the window. This is counting screen lines from the top of
10503 the window. The first line is one.
10504 If the cursor was moved the view on the file will be updated
10505 first, this may cause a scroll.
10506
10507 *winnr()*
10508winnr([{arg}]) The result is a Number, which is the number of the current
10509 window. The top window has number 1.
10510 Returns zero for a popup window.
10511
10512 The optional argument {arg} supports the following values:
10513 $ the number of the last window (the window
10514 count).
10515 # the number of the last accessed window (where
10516 |CTRL-W_p| goes to). If there is no previous
10517 window or it is in another tab page 0 is
10518 returned.
10519 {N}j the number of the Nth window below the
10520 current window (where |CTRL-W_j| goes to).
10521 {N}k the number of the Nth window above the current
10522 window (where |CTRL-W_k| goes to).
10523 {N}h the number of the Nth window left of the
10524 current window (where |CTRL-W_h| goes to).
10525 {N}l the number of the Nth window right of the
10526 current window (where |CTRL-W_l| goes to).
10527 The number can be used with |CTRL-W_w| and ":wincmd w"
10528 |:wincmd|.
Bram Moolenaar016188f2022-06-06 20:52:59 +010010529 When {arg} is invalid an error is given and zero is returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010530 Also see |tabpagewinnr()| and |win_getid()|.
10531 Examples: >
10532 let window_count = winnr('$')
10533 let prev_window = winnr('#')
10534 let wnum = winnr('3k')
10535
10536< Can also be used as a |method|: >
10537 GetWinval()->winnr()
10538<
10539 *winrestcmd()*
10540winrestcmd() Returns a sequence of |:resize| commands that should restore
10541 the current window sizes. Only works properly when no windows
10542 are opened or closed and the current window and tab page is
10543 unchanged.
10544 Example: >
10545 :let cmd = winrestcmd()
10546 :call MessWithWindowSizes()
10547 :exe cmd
10548<
10549 *winrestview()*
10550winrestview({dict})
10551 Uses the |Dictionary| returned by |winsaveview()| to restore
10552 the view of the current window.
10553 Note: The {dict} does not have to contain all values, that are
10554 returned by |winsaveview()|. If values are missing, those
10555 settings won't be restored. So you can use: >
10556 :call winrestview({'curswant': 4})
10557<
10558 This will only set the curswant value (the column the cursor
10559 wants to move on vertical movements) of the cursor to column 5
10560 (yes, that is 5), while all other settings will remain the
10561 same. This is useful, if you set the cursor position manually.
10562
10563 If you have changed the values the result is unpredictable.
10564 If the window size changed the result won't be the same.
10565
10566 Can also be used as a |method|: >
10567 GetView()->winrestview()
10568<
10569 *winsaveview()*
10570winsaveview() Returns a |Dictionary| that contains information to restore
10571 the view of the current window. Use |winrestview()| to
10572 restore the view.
10573 This is useful if you have a mapping that jumps around in the
10574 buffer and you want to go back to the original view.
10575 This does not save fold information. Use the 'foldenable'
10576 option to temporarily switch off folding, so that folds are
10577 not opened when moving around. This may have side effects.
10578 The return value includes:
10579 lnum cursor line number
10580 col cursor column (Note: the first column
naohiro ono56200ee2022-01-01 14:59:44 +000010581 zero, as opposed to what |getcurpos()|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010582 returns)
10583 coladd cursor column offset for 'virtualedit'
naohiro ono56200ee2022-01-01 14:59:44 +000010584 curswant column for vertical movement (Note:
10585 the first column is zero, as opposed
10586 to what |getcurpos()| returns). After
10587 |$| command it will be a very large
10588 number equal to |v:maxcol|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010589 topline first line in the window
10590 topfill filler lines, only in diff mode
10591 leftcol first column displayed; only used when
10592 'wrap' is off
10593 skipcol columns skipped
10594 Note that no option values are saved.
10595
10596
10597winwidth({nr}) *winwidth()*
10598 The result is a Number, which is the width of window {nr}.
10599 {nr} can be the window number or the |window-ID|.
10600 When {nr} is zero, the width of the current window is
10601 returned. When window {nr} doesn't exist, -1 is returned.
10602 An existing window always has a width of zero or more.
10603 Examples: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +000010604 :echo "The current window has " .. winwidth(0) .. " columns."
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010605 :if winwidth(0) <= 50
10606 : 50 wincmd |
10607 :endif
10608< For getting the terminal or screen size, see the 'columns'
10609 option.
10610
10611 Can also be used as a |method|: >
10612 GetWinid()->winwidth()
10613
10614
10615wordcount() *wordcount()*
10616 The result is a dictionary of byte/chars/word statistics for
10617 the current buffer. This is the same info as provided by
10618 |g_CTRL-G|
10619 The return value includes:
10620 bytes Number of bytes in the buffer
10621 chars Number of chars in the buffer
10622 words Number of words in the buffer
10623 cursor_bytes Number of bytes before cursor position
10624 (not in Visual mode)
10625 cursor_chars Number of chars before cursor position
10626 (not in Visual mode)
10627 cursor_words Number of words before cursor position
10628 (not in Visual mode)
10629 visual_bytes Number of bytes visually selected
10630 (only in Visual mode)
10631 visual_chars Number of chars visually selected
10632 (only in Visual mode)
10633 visual_words Number of words visually selected
10634 (only in Visual mode)
10635
10636
10637 *writefile()*
10638writefile({object}, {fname} [, {flags}])
10639 When {object} is a |List| write it to file {fname}. Each list
10640 item is separated with a NL. Each list item must be a String
10641 or Number.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010642 All NL characters are replaced with a NUL character.
10643 Inserting CR characters needs to be done before passing {list}
10644 to writefile().
Bram Moolenaar806a2732022-09-04 15:40:36 +010010645
10646 When {object} is a |Blob| write the bytes to file {fname}
10647 unmodified, also when binary mode is not specified.
10648
10649 {flags} must be a String. These characters are recognized:
10650
10651 'b' Binary mode is used: There will not be a NL after the
10652 last list item. An empty item at the end does cause the
10653 last line in the file to end in a NL.
10654
10655 'a' Append mode is used, lines are appended to the file: >
10656 :call writefile(["foo"], "event.log", "a")
10657 :call writefile(["bar"], "event.log", "a")
10658<
10659 'D' Delete the file when the current function ends. This
10660 works like: >
Bram Moolenaar938ae282023-02-20 20:44:55 +000010661 :defer delete({fname})
Bram Moolenaar806a2732022-09-04 15:40:36 +010010662< Fails when not in a function. Also see |:defer|.
10663
10664 's' fsync() is called after writing the file. This flushes
10665 the file to disk, if possible. This takes more time but
10666 avoids losing the file if the system crashes.
10667
10668 'S' fsync() is not called, even when 'fsync' is set.
10669
10670 When {flags} does not contain "S" or "s" then fsync() is
10671 called if the 'fsync' option is set.
10672
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010673 An existing file is overwritten, if possible.
Bram Moolenaar806a2732022-09-04 15:40:36 +010010674
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010675 When the write fails -1 is returned, otherwise 0. There is an
10676 error message if the file can't be created or when writing
10677 fails.
Bram Moolenaar806a2732022-09-04 15:40:36 +010010678
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010679 Also see |readfile()|.
10680 To copy a file byte for byte: >
10681 :let fl = readfile("foo", "b")
10682 :call writefile(fl, "foocopy", "b")
10683
10684< Can also be used as a |method|: >
10685 GetText()->writefile("thefile")
10686
10687
10688xor({expr}, {expr}) *xor()*
10689 Bitwise XOR on the two arguments. The arguments are converted
10690 to a number. A List, Dict or Float argument causes an error.
Bram Moolenaar5a6ec102022-05-27 21:58:00 +010010691 Also see `and()` and `or()`.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010692 Example: >
10693 :let bits = xor(bits, 0x80)
10694<
10695 Can also be used as a |method|: >
10696 :let bits = bits->xor(0x80)
10697<
10698
10699==============================================================================
107003. Feature list *feature-list*
10701
10702There are three types of features:
107031. Features that are only supported when they have been enabled when Vim
10704 was compiled |+feature-list|. Example: >
10705 :if has("cindent")
10706< *gui_running*
107072. Features that are only supported when certain conditions have been met.
10708 Example: >
10709 :if has("gui_running")
10710< *has-patch*
107113. Beyond a certain version or at a certain version and including a specific
10712 patch. The "patch-7.4.248" feature means that the Vim version is 7.5 or
10713 later, or it is version 7.4 and patch 248 was included. Example: >
10714 :if has("patch-7.4.248")
10715< Note that it's possible for patch 248 to be omitted even though 249 is
10716 included. Only happens when cherry-picking patches.
10717 Note that this form only works for patch 7.4.237 and later, before that
10718 you need to check for the patch and the v:version. Example (checking
10719 version 6.2.148 or later): >
10720 :if v:version > 602 || (v:version == 602 && has("patch148"))
10721
10722Hint: To find out if Vim supports backslashes in a file name (MS-Windows),
10723use: `if exists('+shellslash')`
10724
10725
10726acl Compiled with |ACL| support.
Bram Moolenaar2ee347f2022-08-26 17:53:44 +010010727all_builtin_terms Compiled with all builtin terminals enabled. (always
10728 true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010729amiga Amiga version of Vim.
10730arabic Compiled with Arabic support |Arabic|.
10731arp Compiled with ARP support (Amiga).
10732autocmd Compiled with autocommand support. (always true)
10733autochdir Compiled with support for 'autochdir'
10734autoservername Automatically enable |clientserver|
10735balloon_eval Compiled with |balloon-eval| support.
10736balloon_multiline GUI supports multiline balloons.
10737beos BeOS version of Vim.
10738browse Compiled with |:browse| support, and browse() will
10739 work.
10740browsefilter Compiled with support for |browsefilter|.
10741bsd Compiled on an OS in the BSD family (excluding macOS).
Bram Moolenaar2ee347f2022-08-26 17:53:44 +010010742builtin_terms Compiled with some builtin terminals. (always true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010743byte_offset Compiled with support for 'o' in 'statusline'
10744channel Compiled with support for |channel| and |job|
Bram Moolenaare1dc76f2022-06-25 18:01:32 +010010745cindent Compiled with 'cindent' support. (always true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010746clientserver Compiled with remote invocation support |clientserver|.
10747clipboard Compiled with 'clipboard' support.
10748clipboard_working Compiled with 'clipboard' support and it can be used.
10749cmdline_compl Compiled with |cmdline-completion| support.
10750cmdline_hist Compiled with |cmdline-history| support.
10751cmdline_info Compiled with 'showcmd' and 'ruler' support.
10752comments Compiled with |'comments'| support.
10753compatible Compiled to be very Vi compatible.
10754conpty Platform where |ConPTY| can be used.
10755cryptv Compiled with encryption support |encryption|.
10756cscope Compiled with |cscope| support.
10757cursorbind Compiled with |'cursorbind'| (always true)
10758debug Compiled with "DEBUG" defined.
10759dialog_con Compiled with console dialog support.
10760dialog_gui Compiled with GUI dialog support.
10761diff Compiled with |vimdiff| and 'diff' support.
10762digraphs Compiled with support for digraphs.
10763directx Compiled with support for DirectX and 'renderoptions'.
10764dnd Compiled with support for the "~ register |quote_~|.
10765drop_file Compiled with |drop_file| support.
10766ebcdic Compiled on a machine with ebcdic character set.
10767emacs_tags Compiled with support for Emacs tags.
10768eval Compiled with expression evaluation support. Always
10769 true, of course!
10770ex_extra |+ex_extra| (always true)
10771extra_search Compiled with support for |'incsearch'| and
10772 |'hlsearch'|
10773farsi Support for Farsi was removed |farsi|.
Bram Moolenaarf80f40a2022-08-25 16:02:23 +010010774file_in_path Compiled with support for |gf| and |<cfile>| (always
10775 true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010776filterpipe When 'shelltemp' is off pipes are used for shell
10777 read/write/filter commands
10778find_in_path Compiled with support for include file searches
10779 |+find_in_path|.
10780float Compiled with support for |Float|.
10781fname_case Case in file names matters (for Amiga and MS-Windows
10782 this is not present).
10783folding Compiled with |folding| support.
10784footer Compiled with GUI footer support. |gui-footer|
10785fork Compiled to use fork()/exec() instead of system().
10786gettext Compiled with message translation |multi-lang|
10787gui Compiled with GUI enabled.
Bram Moolenaarcbaff5e2022-04-08 17:45:08 +010010788gui_athena Compiled with Athena GUI (always false).
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010789gui_gnome Compiled with Gnome support (gui_gtk is also defined).
10790gui_gtk Compiled with GTK+ GUI (any version).
10791gui_gtk2 Compiled with GTK+ 2 GUI (gui_gtk is also defined).
10792gui_gtk3 Compiled with GTK+ 3 GUI (gui_gtk is also defined).
10793gui_haiku Compiled with Haiku GUI.
10794gui_mac Compiled with Macintosh GUI.
10795gui_motif Compiled with Motif GUI.
10796gui_photon Compiled with Photon GUI.
10797gui_running Vim is running in the GUI, or it will start soon.
10798gui_win32 Compiled with MS-Windows Win32 GUI.
10799gui_win32s idem, and Win32s system being used (Windows 3.1)
10800haiku Haiku version of Vim.
10801hangul_input Compiled with Hangul input support. |hangul|
10802hpux HP-UX version of Vim.
10803iconv Can use iconv() for conversion.
10804insert_expand Compiled with support for CTRL-X expansion commands in
10805 Insert mode. (always true)
10806job Compiled with support for |channel| and |job|
10807ipv6 Compiled with support for IPv6 networking in |channel|.
Bram Moolenaare1dc76f2022-06-25 18:01:32 +010010808jumplist Compiled with |jumplist| support. (always true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010809keymap Compiled with 'keymap' support.
10810lambda Compiled with |lambda| support.
10811langmap Compiled with 'langmap' support.
10812libcall Compiled with |libcall()| support.
10813linebreak Compiled with 'linebreak', 'breakat', 'showbreak' and
10814 'breakindent' support.
10815linux Linux version of Vim.
10816lispindent Compiled with support for lisp indenting.
Bram Moolenaare1dc76f2022-06-25 18:01:32 +010010817 (always true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010818listcmds Compiled with commands for the buffer list |:files|
10819 and the argument list |arglist|.
10820localmap Compiled with local mappings and abbr. |:map-local|
10821lua Compiled with Lua interface |Lua|.
10822mac Any Macintosh version of Vim cf. osx
10823macunix Synonym for osxdarwin
10824menu Compiled with support for |:menu|.
10825mksession Compiled with support for |:mksession|.
10826modify_fname Compiled with file name modifiers. |filename-modifiers|
10827 (always true)
10828mouse Compiled with support for mouse.
10829mouse_dec Compiled with support for Dec terminal mouse.
10830mouse_gpm Compiled with support for gpm (Linux console mouse)
10831mouse_gpm_enabled GPM mouse is working
10832mouse_netterm Compiled with support for netterm mouse.
10833mouse_pterm Compiled with support for qnx pterm mouse.
10834mouse_sysmouse Compiled with support for sysmouse (*BSD console mouse)
10835mouse_sgr Compiled with support for sgr mouse.
10836mouse_urxvt Compiled with support for urxvt mouse.
10837mouse_xterm Compiled with support for xterm mouse.
10838mouseshape Compiled with support for 'mouseshape'.
10839multi_byte Compiled with support for 'encoding' (always true)
10840multi_byte_encoding 'encoding' is set to a multibyte encoding.
10841multi_byte_ime Compiled with support for IME input method.
10842multi_lang Compiled with support for multiple languages.
10843mzscheme Compiled with MzScheme interface |mzscheme|.
10844nanotime Compiled with sub-second time stamp checks.
10845netbeans_enabled Compiled with support for |netbeans| and connected.
10846netbeans_intg Compiled with support for |netbeans|.
Bram Moolenaare1dc76f2022-06-25 18:01:32 +010010847num64 Compiled with 64-bit |Number| support. (always true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010848ole Compiled with OLE automation support for Win32.
10849osx Compiled for macOS cf. mac
10850osxdarwin Compiled for macOS, with |mac-darwin-feature|
10851packages Compiled with |packages| support.
10852path_extra Compiled with up/downwards search in 'path' and 'tags'
10853perl Compiled with Perl interface.
10854persistent_undo Compiled with support for persistent undo history.
10855postscript Compiled with PostScript file printing.
10856printer Compiled with |:hardcopy| support.
10857profile Compiled with |:profile| support.
Bram Moolenaar71badf92023-04-22 22:40:14 +010010858prof_nsec Profile results are in nanoseconds.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010859python Python 2.x interface available. |has-python|
10860python_compiled Compiled with Python 2.x interface. |has-python|
10861python_dynamic Python 2.x interface is dynamically loaded. |has-python|
10862python3 Python 3.x interface available. |has-python|
10863python3_compiled Compiled with Python 3.x interface. |has-python|
10864python3_dynamic Python 3.x interface is dynamically loaded. |has-python|
10865pythonx Python 2.x and/or 3.x interface available. |python_x|
10866qnx QNX version of Vim.
10867quickfix Compiled with |quickfix| support.
10868reltime Compiled with |reltime()| support.
10869rightleft Compiled with 'rightleft' support.
10870ruby Compiled with Ruby interface |ruby|.
10871scrollbind Compiled with 'scrollbind' support. (always true)
10872showcmd Compiled with 'showcmd' support.
10873signs Compiled with |:sign| support.
Bram Moolenaare1dc76f2022-06-25 18:01:32 +010010874smartindent Compiled with 'smartindent' support. (always true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010875sodium Compiled with libsodium for better crypt support
10876sound Compiled with sound support, e.g. `sound_playevent()`
10877spell Compiled with spell checking support |spell|.
10878startuptime Compiled with |--startuptime| support.
10879statusline Compiled with support for 'statusline', 'rulerformat'
10880 and special formats of 'titlestring' and 'iconstring'.
10881sun SunOS version of Vim.
10882sun_workshop Support for Sun |workshop| has been removed.
10883syntax Compiled with syntax highlighting support |syntax|.
10884syntax_items There are active syntax highlighting items for the
10885 current buffer.
10886system Compiled to use system() instead of fork()/exec().
10887tag_binary Compiled with binary searching in tags files
Bram Moolenaare1dc76f2022-06-25 18:01:32 +010010888 |tag-binary-search|. (always true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010889tag_old_static Support for old static tags was removed, see
10890 |tag-old-static|.
10891tcl Compiled with Tcl interface.
10892termguicolors Compiled with true color in terminal support.
10893terminal Compiled with |terminal| support.
10894terminfo Compiled with terminfo instead of termcap.
10895termresponse Compiled with support for |t_RV| and |v:termresponse|.
10896textobjects Compiled with support for |text-objects|.
10897textprop Compiled with support for |text-properties|.
10898tgetent Compiled with tgetent support, able to use a termcap
10899 or terminfo file.
10900timers Compiled with |timer_start()| support.
10901title Compiled with window title support |'title'|.
Bram Moolenaare1dc76f2022-06-25 18:01:32 +010010902 (always true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010903toolbar Compiled with support for |gui-toolbar|.
10904ttyin input is a terminal (tty)
10905ttyout output is a terminal (tty)
10906unix Unix version of Vim. *+unix*
10907unnamedplus Compiled with support for "unnamedplus" in 'clipboard'
10908user_commands User-defined commands. (always true)
10909vartabs Compiled with variable tabstop support |'vartabstop'|.
10910vcon Win32: Virtual console support is working, can use
10911 'termguicolors'. Also see |+vtp|.
10912vertsplit Compiled with vertically split windows |:vsplit|.
10913 (always true)
10914vim_starting True while initial source'ing takes place. |startup|
10915 *vim_starting*
Bram Moolenaara6feb162022-01-02 12:06:33 +000010916vim9script Compiled with |Vim9| script support
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010917viminfo Compiled with viminfo support.
10918vimscript-1 Compiled Vim script version 1 support
10919vimscript-2 Compiled Vim script version 2 support
10920vimscript-3 Compiled Vim script version 3 support
Bram Moolenaar8a3b8052022-06-26 12:21:15 +010010921vimscript-4 Compiled Vim script version 4 support
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010922virtualedit Compiled with 'virtualedit' option. (always true)
10923visual Compiled with Visual mode. (always true)
10924visualextra Compiled with extra Visual mode commands. (always
10925 true) |blockwise-operators|.
10926vms VMS version of Vim.
10927vreplace Compiled with |gR| and |gr| commands. (always true)
10928vtp Compiled for vcon support |+vtp| (check vcon to find
10929 out if it works in the current console).
10930wildignore Compiled with 'wildignore' option.
10931wildmenu Compiled with 'wildmenu' option.
10932win16 old version for MS-Windows 3.1 (always false)
10933win32 Win32 version of Vim (MS-Windows 95 and later, 32 or
10934 64 bits)
10935win32unix Win32 version of Vim, using Unix files (Cygwin)
10936win64 Win64 version of Vim (MS-Windows 64 bit).
10937win95 Win32 version for MS-Windows 95/98/ME (always false)
10938winaltkeys Compiled with 'winaltkeys' option.
10939windows Compiled with support for more than one window.
10940 (always true)
10941writebackup Compiled with 'writebackup' default on.
10942xfontset Compiled with X fontset support |xfontset|.
10943xim Compiled with X input method support |xim|.
10944xpm Compiled with pixmap support.
10945xpm_w32 Compiled with pixmap support for Win32. (Only for
10946 backward compatibility. Use "xpm" instead.)
10947xsmp Compiled with X session management support.
10948xsmp_interact Compiled with interactive X session management support.
10949xterm_clipboard Compiled with support for xterm clipboard.
10950xterm_save Compiled with support for saving and restoring the
10951 xterm screen.
10952x11 Compiled with X11 support.
10953
10954
10955==============================================================================
109564. Matching a pattern in a String *string-match*
10957
10958This is common between several functions. A regexp pattern as explained at
10959|pattern| is normally used to find a match in the buffer lines. When a
10960pattern is used to find a match in a String, almost everything works in the
10961same way. The difference is that a String is handled like it is one line.
10962When it contains a "\n" character, this is not seen as a line break for the
10963pattern. It can be matched with a "\n" in the pattern, or with ".". Example:
10964>
10965 :let a = "aaaa\nxxxx"
10966 :echo matchstr(a, "..\n..")
10967 aa
10968 xx
10969 :echo matchstr(a, "a.x")
10970 a
10971 x
10972
10973Don't forget that "^" will only match at the first character of the String and
10974"$" at the last character of the string. They don't match after or before a
10975"\n".
10976
10977 vim:tw=78:ts=8:noet:ft=help:norl: