blob: b14851ca8918b59a18d4453fec93e7f9903359d9 [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
157empty({expr}) Number |TRUE| if {expr} is empty
158environ() Dict return environment variables
159escape({string}, {chars}) String escape {chars} in {string} with '\'
160eval({string}) any evaluate {string} into its value
161eventhandler() Number |TRUE| if inside an event handler
162executable({expr}) Number 1 if executable {expr} exists
163execute({command}) String execute {command} and get the output
164exepath({expr}) String full path of the command {expr}
165exists({expr}) Number |TRUE| if {expr} exists
166exists_compiled({expr}) Number |TRUE| if {expr} exists at compile time
167exp({expr}) Float exponential of {expr}
168expand({expr} [, {nosuf} [, {list}]])
169 any expand special keywords in {expr}
Yegappan Lakshmanan2b74b682022-04-03 21:30:32 +0100170expandcmd({string} [, {options}])
171 String expand {string} like with `:edit`
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000172extend({expr1}, {expr2} [, {expr3}])
173 List/Dict insert items of {expr2} into {expr1}
174extendnew({expr1}, {expr2} [, {expr3}])
175 List/Dict like |extend()| but creates a new
176 List or Dictionary
177feedkeys({string} [, {mode}]) Number add key sequence to typeahead buffer
178filereadable({file}) Number |TRUE| if {file} is a readable file
179filewritable({file}) Number |TRUE| if {file} is a writable file
180filter({expr1}, {expr2}) List/Dict/Blob/String
181 remove items from {expr1} where
182 {expr2} is 0
183finddir({name} [, {path} [, {count}]])
184 String find directory {name} in {path}
185findfile({name} [, {path} [, {count}]])
186 String find file {name} in {path}
187flatten({list} [, {maxdepth}]) List flatten {list} up to {maxdepth} levels
188flattennew({list} [, {maxdepth}])
189 List flatten a copy of {list}
190float2nr({expr}) Number convert Float {expr} to a Number
191floor({expr}) Float round {expr} down
192fmod({expr1}, {expr2}) Float remainder of {expr1} / {expr2}
193fnameescape({fname}) String escape special characters in {fname}
194fnamemodify({fname}, {mods}) String modify file name
195foldclosed({lnum}) Number first line of fold at {lnum} if closed
196foldclosedend({lnum}) Number last line of fold at {lnum} if closed
197foldlevel({lnum}) Number fold level at {lnum}
198foldtext() String line displayed for closed fold
199foldtextresult({lnum}) String text for closed fold at {lnum}
200foreground() Number bring the Vim window to the foreground
Bram Moolenaaraa534142022-09-15 21:46:02 +0100201fullcommand({name} [, {vim9}]) String get full command from {name}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000202funcref({name} [, {arglist}] [, {dict}])
203 Funcref reference to function {name}
204function({name} [, {arglist}] [, {dict}])
205 Funcref named reference to function {name}
206garbagecollect([{atexit}]) none free memory, breaking cyclic references
207get({list}, {idx} [, {def}]) any get item {idx} from {list} or {def}
208get({dict}, {key} [, {def}]) any get item {key} from {dict} or {def}
209get({func}, {what}) any get property of funcref/partial {func}
210getbufinfo([{buf}]) List information about buffers
211getbufline({buf}, {lnum} [, {end}])
212 List lines {lnum} to {end} of buffer {buf}
Bram Moolenaarce30ccc2022-11-21 19:57:04 +0000213getbufoneline({buf}, {lnum}) String line {lnum} of buffer {buf}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000214getbufvar({buf}, {varname} [, {def}])
215 any variable {varname} in buffer {buf}
Kota Kato66bb9ae2023-01-17 18:31:56 +0000216getcellwidths() List get character cell width overrides
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000217getchangelist([{buf}]) List list of change list items
218getchar([expr]) Number or String
219 get one character from the user
220getcharmod() Number modifiers for the last typed character
221getcharpos({expr}) List position of cursor, mark, etc.
222getcharsearch() Dict last character search
223getcharstr([expr]) String get one character from the user
Shougo Matsushita79d599b2022-05-07 12:48:29 +0100224getcmdcompltype() String return the type of the current
225 command-line completion
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000226getcmdline() String return the current command-line
227getcmdpos() Number return cursor position in command-line
Shougo Matsushita79d599b2022-05-07 12:48:29 +0100228getcmdscreenpos() Number return cursor screen position in
229 command-line
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000230getcmdtype() String return current command-line type
231getcmdwintype() String return current command-line window type
232getcompletion({pat}, {type} [, {filtered}])
233 List list of cmdline completion matches
234getcurpos([{winnr}]) List position of the cursor
235getcursorcharpos([{winnr}]) List character position of the cursor
236getcwd([{winnr} [, {tabnr}]]) String get the current working directory
237getenv({name}) String return environment variable
238getfontname([{name}]) String name of font being used
239getfperm({fname}) String file permissions of file {fname}
240getfsize({fname}) Number size in bytes of file {fname}
241getftime({fname}) Number last modification time of file
242getftype({fname}) String description of type of file {fname}
243getimstatus() Number |TRUE| if the IME status is active
244getjumplist([{winnr} [, {tabnr}]])
245 List list of jump list items
246getline({lnum}) String line {lnum} of current buffer
247getline({lnum}, {end}) List lines {lnum} to {end} of current buffer
248getloclist({nr}) List list of location list items
249getloclist({nr}, {what}) Dict get specific location list properties
250getmarklist([{buf}]) List list of global/local marks
251getmatches([{win}]) List list of current matches
252getmousepos() Dict last known mouse position
Bram Moolenaar24dc19c2022-11-14 19:49:15 +0000253getmouseshape() String current mouse shape name
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000254getpid() Number process ID of Vim
255getpos({expr}) List position of cursor, mark, etc.
256getqflist() List list of quickfix items
257getqflist({what}) Dict get specific quickfix list properties
258getreg([{regname} [, 1 [, {list}]]])
259 String or List contents of a register
260getreginfo([{regname}]) Dict information about a register
261getregtype([{regname}]) String type of a register
Yegappan Lakshmanan520f6ef2022-08-25 17:40:40 +0100262getscriptinfo([{opts}]) List list of sourced scripts
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000263gettabinfo([{expr}]) List list of tab pages
264gettabvar({nr}, {varname} [, {def}])
265 any variable {varname} in tab {nr} or {def}
266gettabwinvar({tabnr}, {winnr}, {name} [, {def}])
267 any {name} in {winnr} in tab page {tabnr}
268gettagstack([{nr}]) Dict get the tag stack of window {nr}
269gettext({text}) String lookup translation of {text}
270getwininfo([{winid}]) List list of info about each window
Bram Moolenaar938ae282023-02-20 20:44:55 +0000271getwinpos([{timeout}]) List X and Y coord in pixels of Vim window
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000272getwinposx() Number X coord in pixels of the Vim window
273getwinposy() Number Y coord in pixels of the Vim window
274getwinvar({nr}, {varname} [, {def}])
275 any variable {varname} in window {nr}
276glob({expr} [, {nosuf} [, {list} [, {alllinks}]]])
277 any expand file wildcards in {expr}
278glob2regpat({expr}) String convert a glob pat into a search pat
279globpath({path}, {expr} [, {nosuf} [, {list} [, {alllinks}]]])
280 String do glob({expr}) for all dirs in {path}
281has({feature} [, {check}]) Number |TRUE| if feature {feature} supported
282has_key({dict}, {key}) Number |TRUE| if {dict} has entry {key}
283haslocaldir([{winnr} [, {tabnr}]])
284 Number |TRUE| if the window executed |:lcd|
285 or |:tcd|
286hasmapto({what} [, {mode} [, {abbr}]])
287 Number |TRUE| if mapping to {what} exists
288histadd({history}, {item}) Number add an item to a history
289histdel({history} [, {item}]) Number remove an item from a history
290histget({history} [, {index}]) String get the item {index} from a history
291histnr({history}) Number highest index of a history
292hlID({name}) Number syntax ID of highlight group {name}
293hlexists({name}) Number |TRUE| if highlight group {name} exists
294hlget([{name} [, {resolve}]]) List get highlight group attributes
295hlset({list}) Number set highlight group attributes
296hostname() String name of the machine Vim is running on
297iconv({expr}, {from}, {to}) String convert encoding of {expr}
298indent({lnum}) Number indent of line {lnum}
299index({object}, {expr} [, {start} [, {ic}]])
300 Number index in {object} where {expr} appears
Yegappan Lakshmananb2186552022-08-13 13:09:20 +0100301indexof({object}, {expr} [, {opts}]])
302 Number index in {object} where {expr} is true
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000303input({prompt} [, {text} [, {completion}]])
304 String get input from the user
Bram Moolenaarb529cfb2022-07-25 15:42:07 +0100305inputdialog({prompt} [, {text} [, {cancelreturn}]])
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000306 String like input() but in a GUI dialog
307inputlist({textlist}) Number let the user pick from a choice list
308inputrestore() Number restore typeahead
309inputsave() Number save and clear typeahead
310inputsecret({prompt} [, {text}]) String like input() but hiding the text
311insert({object}, {item} [, {idx}]) List insert {item} in {object} [before {idx}]
312interrupt() none interrupt script execution
313invert({expr}) Number bitwise invert
LemonBoydca1d402022-04-28 15:26:33 +0100314isabsolutepath({path}) Number |TRUE| if {path} is an absolute path
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000315isdirectory({directory}) Number |TRUE| if {directory} is a directory
316isinf({expr}) Number determine if {expr} is infinity value
317 (positive or negative)
318islocked({expr}) Number |TRUE| if {expr} is locked
319isnan({expr}) Number |TRUE| if {expr} is NaN
320items({dict}) List key-value pairs in {dict}
321job_getchannel({job}) Channel get the channel handle for {job}
322job_info([{job}]) Dict get information about {job}
323job_setoptions({job}, {options}) none set options for {job}
324job_start({command} [, {options}])
325 Job start a job
326job_status({job}) String get the status of {job}
327job_stop({job} [, {how}]) Number stop {job}
328join({list} [, {sep}]) String join {list} items into one String
329js_decode({string}) any decode JS style JSON
330js_encode({expr}) String encode JS style JSON
331json_decode({string}) any decode JSON
332json_encode({expr}) String encode JSON
333keys({dict}) List keys in {dict}
zeertzjqcdc83932022-09-12 13:38:41 +0100334keytrans({string}) String translate internal keycodes to a form
335 that can be used by |:map|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000336len({expr}) Number the length of {expr}
337libcall({lib}, {func}, {arg}) String call {func} in library {lib} with {arg}
338libcallnr({lib}, {func}, {arg}) Number idem, but return a Number
339line({expr} [, {winid}]) Number line nr of cursor, last line or mark
340line2byte({lnum}) Number byte count of line {lnum}
341lispindent({lnum}) Number Lisp indent for line {lnum}
342list2blob({list}) Blob turn {list} of numbers into a Blob
343list2str({list} [, {utf8}]) String turn {list} of numbers into a String
344listener_add({callback} [, {buf}])
345 Number add a callback to listen to changes
346listener_flush([{buf}]) none invoke listener callbacks
347listener_remove({id}) none remove a listener callback
348localtime() Number current time
349log({expr}) Float natural logarithm (base e) of {expr}
350log10({expr}) Float logarithm of Float {expr} to base 10
351luaeval({expr} [, {expr}]) any evaluate |Lua| expression
352map({expr1}, {expr2}) List/Dict/Blob/String
353 change each item in {expr1} to {expr2}
354maparg({name} [, {mode} [, {abbr} [, {dict}]]])
355 String or Dict
356 rhs of mapping {name} in mode {mode}
357mapcheck({name} [, {mode} [, {abbr}]])
358 String check for mappings matching {name}
Ernie Rael09661202022-04-25 14:40:44 +0100359maplist([{abbr}]) List list of all mappings, a dict for each
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000360mapnew({expr1}, {expr2}) List/Dict/Blob/String
361 like |map()| but creates a new List or
362 Dictionary
363mapset({mode}, {abbr}, {dict}) none restore mapping from |maparg()| result
364match({expr}, {pat} [, {start} [, {count}]])
365 Number position where {pat} matches in {expr}
366matchadd({group}, {pattern} [, {priority} [, {id} [, {dict}]]])
367 Number highlight {pattern} with {group}
368matchaddpos({group}, {pos} [, {priority} [, {id} [, {dict}]]])
369 Number highlight positions with {group}
370matcharg({nr}) List arguments of |:match|
371matchdelete({id} [, {win}]) Number delete match identified by {id}
372matchend({expr}, {pat} [, {start} [, {count}]])
373 Number position where {pat} ends in {expr}
374matchfuzzy({list}, {str} [, {dict}])
375 List fuzzy match {str} in {list}
376matchfuzzypos({list}, {str} [, {dict}])
377 List fuzzy match {str} in {list}
378matchlist({expr}, {pat} [, {start} [, {count}]])
379 List match and submatches of {pat} in {expr}
380matchstr({expr}, {pat} [, {start} [, {count}]])
381 String {count}'th match of {pat} in {expr}
382matchstrpos({expr}, {pat} [, {start} [, {count}]])
383 List {count}'th match of {pat} in {expr}
384max({expr}) Number maximum value of items in {expr}
385menu_info({name} [, {mode}]) Dict get menu item information
386min({expr}) Number minimum value of items in {expr}
Bram Moolenaar938ae282023-02-20 20:44:55 +0000387mkdir({name} [, {flags} [, {prot}]])
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000388 Number create directory {name}
389mode([expr]) String current editing mode
390mzeval({expr}) any evaluate |MzScheme| expression
391nextnonblank({lnum}) Number line nr of non-blank line >= {lnum}
392nr2char({expr} [, {utf8}]) String single char with ASCII/UTF-8 value {expr}
393or({expr}, {expr}) Number bitwise OR
394pathshorten({expr} [, {len}]) String shorten directory names in a path
395perleval({expr}) any evaluate |Perl| expression
396popup_atcursor({what}, {options}) Number create popup window near the cursor
397popup_beval({what}, {options}) Number create popup window for 'ballooneval'
398popup_clear() none close all popup windows
399popup_close({id} [, {result}]) none close popup window {id}
400popup_create({what}, {options}) Number create a popup window
401popup_dialog({what}, {options}) Number create a popup window used as a dialog
402popup_filter_menu({id}, {key}) Number filter for a menu popup window
403popup_filter_yesno({id}, {key}) Number filter for a dialog popup window
Bram Moolenaarbdc09a12022-10-07 14:31:45 +0100404popup_findecho() Number get window ID of popup for `:echowin`
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000405popup_findinfo() Number get window ID of info popup window
406popup_findpreview() Number get window ID of preview popup window
407popup_getoptions({id}) Dict get options of popup window {id}
408popup_getpos({id}) Dict get position of popup window {id}
409popup_hide({id}) none hide popup menu {id}
410popup_list() List get a list of window IDs of all popups
411popup_locate({row}, {col}) Number get window ID of popup at position
412popup_menu({what}, {options}) Number create a popup window used as a menu
413popup_move({id}, {options}) none set position of popup window {id}
414popup_notification({what}, {options})
415 Number create a notification popup window
416popup_setoptions({id}, {options})
417 none set options for popup window {id}
418popup_settext({id}, {text}) none set the text of popup window {id}
419popup_show({id}) none unhide popup window {id}
420pow({x}, {y}) Float {x} to the power of {y}
421prevnonblank({lnum}) Number line nr of non-blank line <= {lnum}
422printf({fmt}, {expr1}...) String format text
423prompt_getprompt({buf}) String get prompt text
424prompt_setcallback({buf}, {expr}) none set prompt callback function
425prompt_setinterrupt({buf}, {text}) none set prompt interrupt function
426prompt_setprompt({buf}, {text}) none set prompt text
427prop_add({lnum}, {col}, {props}) none add one text property
428prop_add_list({props}, [[{lnum}, {col}, {end-lnum}, {end-col}], ...])
429 none add multiple text properties
430prop_clear({lnum} [, {lnum-end} [, {props}]])
431 none remove all text properties
432prop_find({props} [, {direction}])
433 Dict search for a text property
434prop_list({lnum} [, {props}]) List text properties in {lnum}
435prop_remove({props} [, {lnum} [, {lnum-end}]])
436 Number remove a text property
437prop_type_add({name}, {props}) none define a new property type
438prop_type_change({name}, {props})
439 none change an existing property type
440prop_type_delete({name} [, {props}])
441 none delete a property type
442prop_type_get({name} [, {props}])
443 Dict get property type values
444prop_type_list([{props}]) List get list of property types
445pum_getpos() Dict position and size of pum if visible
446pumvisible() Number whether popup menu is visible
447py3eval({expr}) any evaluate |python3| expression
448pyeval({expr}) any evaluate |Python| expression
449pyxeval({expr}) any evaluate |python_x| expression
450rand([{expr}]) Number get pseudo-random number
451range({expr} [, {max} [, {stride}]])
452 List items from {expr} to {max}
K.Takata11df3ae2022-10-19 14:02:40 +0100453readblob({fname} [, {offset} [, {size}]])
454 Blob read a |Blob| from {fname}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000455readdir({dir} [, {expr} [, {dict}]])
456 List file names in {dir} selected by {expr}
457readdirex({dir} [, {expr} [, {dict}]])
458 List file info in {dir} selected by {expr}
459readfile({fname} [, {type} [, {max}]])
460 List get list of lines from file {fname}
461reduce({object}, {func} [, {initial}])
462 any reduce {object} using {func}
463reg_executing() String get the executing register name
464reg_recording() String get the recording register name
465reltime([{start} [, {end}]]) List get time value
466reltimefloat({time}) Float turn the time value into a Float
467reltimestr({time}) String turn time value into a String
468remote_expr({server}, {string} [, {idvar} [, {timeout}]])
469 String send expression
470remote_foreground({server}) Number bring Vim server to the foreground
471remote_peek({serverid} [, {retvar}])
472 Number check for reply string
473remote_read({serverid} [, {timeout}])
474 String read reply string
475remote_send({server}, {string} [, {idvar}])
476 String send key sequence
477remote_startserver({name}) none become server {name}
478remove({list}, {idx} [, {end}]) any/List
479 remove items {idx}-{end} from {list}
480remove({blob}, {idx} [, {end}]) Number/Blob
481 remove bytes {idx}-{end} from {blob}
482remove({dict}, {key}) any remove entry {key} from {dict}
483rename({from}, {to}) Number rename (move) file from {from} to {to}
Bakudankun375141e2022-09-09 18:46:47 +0100484repeat({expr}, {count}) List/Blob/String
485 repeat {expr} {count} times
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000486resolve({filename}) String get filename a shortcut points to
Yegappan Lakshmanan03ff1c22023-05-06 14:08:21 +0100487reverse({obj}) List/Blob/String
488 reverse {obj}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000489round({expr}) Float round off {expr}
490rubyeval({expr}) any evaluate |Ruby| expression
491screenattr({row}, {col}) Number attribute at screen position
492screenchar({row}, {col}) Number character at screen position
493screenchars({row}, {col}) List List of characters at screen position
494screencol() Number current cursor column
495screenpos({winid}, {lnum}, {col}) Dict screen row and col of a text character
496screenrow() Number current cursor row
497screenstring({row}, {col}) String characters at screen position
498search({pattern} [, {flags} [, {stopline} [, {timeout} [, {skip}]]]])
499 Number search for {pattern}
500searchcount([{options}]) Dict get or update search stats
501searchdecl({name} [, {global} [, {thisblock}]])
502 Number search for variable declaration
503searchpair({start}, {middle}, {end} [, {flags} [, {skip} [...]]])
504 Number search for other end of start/end pair
505searchpairpos({start}, {middle}, {end} [, {flags} [, {skip} [...]]])
506 List search for other end of start/end pair
507searchpos({pattern} [, {flags} [, {stopline} [, {timeout} [, {skip}]]]])
508 List search for {pattern}
509server2client({clientid}, {string})
510 Number send reply string
511serverlist() String get a list of available servers
512setbufline({expr}, {lnum}, {text})
513 Number set line {lnum} to {text} in buffer
514 {expr}
515setbufvar({buf}, {varname}, {val})
516 none set {varname} in buffer {buf} to {val}
517setcellwidths({list}) none set character cell width overrides
518setcharpos({expr}, {list}) Number set the {expr} position to {list}
519setcharsearch({dict}) Dict set character search from {dict}
Shougo Matsushita07ea5f12022-08-27 12:22:25 +0100520setcmdline({str} [, {pos}]) Number set command-line
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000521setcmdpos({pos}) Number set cursor position in command-line
522setcursorcharpos({list}) Number move cursor to position in {list}
523setenv({name}, {val}) none set environment variable
524setfperm({fname}, {mode}) Number set {fname} file permissions to {mode}
525setline({lnum}, {line}) Number set line {lnum} to {line}
526setloclist({nr}, {list} [, {action}])
527 Number modify location list using {list}
528setloclist({nr}, {list}, {action}, {what})
529 Number modify specific location list props
530setmatches({list} [, {win}]) Number restore a list of matches
531setpos({expr}, {list}) Number set the {expr} position to {list}
532setqflist({list} [, {action}]) Number modify quickfix list using {list}
533setqflist({list}, {action}, {what})
534 Number modify specific quickfix list props
535setreg({n}, {v} [, {opt}]) Number set register to value and type
536settabvar({nr}, {varname}, {val}) none set {varname} in tab page {nr} to {val}
537settabwinvar({tabnr}, {winnr}, {varname}, {val})
538 none set {varname} in window {winnr} in tab
539 page {tabnr} to {val}
540settagstack({nr}, {dict} [, {action}])
541 Number modify tag stack using {dict}
542setwinvar({nr}, {varname}, {val}) none set {varname} in window {nr} to {val}
543sha256({string}) String SHA256 checksum of {string}
544shellescape({string} [, {special}])
545 String escape {string} for use as shell
546 command argument
547shiftwidth([{col}]) Number effective value of 'shiftwidth'
548sign_define({name} [, {dict}]) Number define or update a sign
549sign_define({list}) List define or update a list of signs
550sign_getdefined([{name}]) List get a list of defined signs
551sign_getplaced([{buf} [, {dict}]])
552 List get a list of placed signs
553sign_jump({id}, {group}, {buf})
554 Number jump to a sign
555sign_place({id}, {group}, {name}, {buf} [, {dict}])
556 Number place a sign
557sign_placelist({list}) List place a list of signs
558sign_undefine([{name}]) Number undefine a sign
559sign_undefine({list}) List undefine a list of signs
560sign_unplace({group} [, {dict}])
561 Number unplace a sign
562sign_unplacelist({list}) List unplace a list of signs
563simplify({filename}) String simplify filename as much as possible
564sin({expr}) Float sine of {expr}
565sinh({expr}) Float hyperbolic sine of {expr}
566slice({expr}, {start} [, {end}]) String, List or Blob
567 slice of a String, List or Blob
Bram Moolenaar2007dd42022-02-23 13:17:47 +0000568sort({list} [, {how} [, {dict}]])
569 List sort {list}, compare with {how}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000570sound_clear() none stop playing all sounds
571sound_playevent({name} [, {callback}])
572 Number play an event sound
573sound_playfile({path} [, {callback}])
574 Number play sound file {path}
575sound_stop({id}) none stop playing sound {id}
576soundfold({word}) String sound-fold {word}
577spellbadword() String badly spelled word at cursor
578spellsuggest({word} [, {max} [, {capital}]])
579 List spelling suggestions
580split({expr} [, {pat} [, {keepempty}]])
581 List make |List| from {pat} separated {expr}
582sqrt({expr}) Float square root of {expr}
583srand([{expr}]) List get seed for |rand()|
584state([{what}]) String current state of Vim
585str2float({expr} [, {quoted}]) Float convert String to Float
586str2list({expr} [, {utf8}]) List convert each character of {expr} to
587 ASCII/UTF-8 value
588str2nr({expr} [, {base} [, {quoted}]])
589 Number convert String to Number
590strcharlen({expr}) Number character length of the String {expr}
591strcharpart({str}, {start} [, {len} [, {skipcc}]])
592 String {len} characters of {str} at
593 character {start}
594strchars({expr} [, {skipcc}]) Number character count of the String {expr}
595strdisplaywidth({expr} [, {col}]) Number display length of the String {expr}
596strftime({format} [, {time}]) String format time with a specified format
597strgetchar({str}, {index}) Number get char {index} from {str}
598stridx({haystack}, {needle} [, {start}])
599 Number index of {needle} in {haystack}
600string({expr}) String String representation of {expr} value
601strlen({expr}) Number length of the String {expr}
602strpart({str}, {start} [, {len} [, {chars}]])
603 String {len} bytes/chars of {str} at
604 byte {start}
605strptime({format}, {timestring})
606 Number Convert {timestring} to unix timestamp
607strridx({haystack}, {needle} [, {start}])
608 Number last index of {needle} in {haystack}
609strtrans({expr}) String translate string to make it printable
Christian Brabandt67672ef2023-04-24 21:09:54 +0100610strutf16len({string} [, {countcc}])
611 Number number of UTF-16 code units in {string}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000612strwidth({expr}) Number display cell length of the String {expr}
613submatch({nr} [, {list}]) String or List
614 specific match in ":s" or substitute()
615substitute({expr}, {pat}, {sub}, {flags})
616 String all {pat} in {expr} replaced with {sub}
Bram Moolenaarc216a7a2022-12-05 13:50:55 +0000617swapfilelist() List swap files found in 'directory'
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000618swapinfo({fname}) Dict information about swap file {fname}
619swapname({buf}) String swap file of buffer {buf}
620synID({lnum}, {col}, {trans}) Number syntax ID at {lnum} and {col}
621synIDattr({synID}, {what} [, {mode}])
622 String attribute {what} of syntax ID {synID}
623synIDtrans({synID}) Number translated syntax ID of {synID}
624synconcealed({lnum}, {col}) List info about concealing
625synstack({lnum}, {col}) List stack of syntax IDs at {lnum} and {col}
626system({expr} [, {input}]) String output of shell command/filter {expr}
627systemlist({expr} [, {input}]) List output of shell command/filter {expr}
628tabpagebuflist([{arg}]) List list of buffer numbers in tab page
629tabpagenr([{arg}]) Number number of current or last tab page
630tabpagewinnr({tabarg} [, {arg}]) Number number of current window in tab page
631tagfiles() List tags files used
632taglist({expr} [, {filename}]) List list of tags matching {expr}
633tan({expr}) Float tangent of {expr}
634tanh({expr}) Float hyperbolic tangent of {expr}
635tempname() String name for a temporary file
636term_dumpdiff({filename}, {filename} [, {options}])
637 Number display difference between two dumps
638term_dumpload({filename} [, {options}])
639 Number displaying a screen dump
640term_dumpwrite({buf}, {filename} [, {options}])
641 none dump terminal window contents
642term_getaltscreen({buf}) Number get the alternate screen flag
643term_getansicolors({buf}) List get ANSI palette in GUI color mode
644term_getattr({attr}, {what}) Number get the value of attribute {what}
645term_getcursor({buf}) List get the cursor position of a terminal
646term_getjob({buf}) Job get the job associated with a terminal
647term_getline({buf}, {row}) String get a line of text from a terminal
648term_getscrolled({buf}) Number get the scroll count of a terminal
649term_getsize({buf}) List get the size of a terminal
650term_getstatus({buf}) String get the status of a terminal
651term_gettitle({buf}) String get the title of a terminal
652term_gettty({buf}, [{input}]) String get the tty name of a terminal
653term_list() List get the list of terminal buffers
654term_scrape({buf}, {row}) List get row of a terminal screen
655term_sendkeys({buf}, {keys}) none send keystrokes to a terminal
656term_setansicolors({buf}, {colors})
657 none set ANSI palette in GUI color mode
658term_setapi({buf}, {expr}) none set |terminal-api| function name prefix
659term_setkill({buf}, {how}) none set signal to stop job in terminal
660term_setrestore({buf}, {command}) none set command to restore terminal
661term_setsize({buf}, {rows}, {cols})
662 none set the size of a terminal
663term_start({cmd} [, {options}]) Number open a terminal window and run a job
664term_wait({buf} [, {time}]) Number wait for screen to be updated
665terminalprops() Dict properties of the terminal
666test_alloc_fail({id}, {countdown}, {repeat})
667 none make memory allocation fail
668test_autochdir() none enable 'autochdir' during startup
669test_feedinput({string}) none add key sequence to input buffer
670test_garbagecollect_now() none free memory right now for testing
671test_garbagecollect_soon() none free memory soon for testing
672test_getvalue({string}) any get value of an internal variable
Yegappan Lakshmanan06011e12022-01-30 12:37:29 +0000673test_gui_event({event}, {args}) bool generate a GUI event for testing
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000674test_ignore_error({expr}) none ignore a specific error
Christopher Plewright20b795e2022-12-20 20:01:58 +0000675test_mswin_event({event}, {args})
676 bool generate MS-Windows event for testing
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000677test_null_blob() Blob null value for testing
678test_null_channel() Channel null value for testing
679test_null_dict() Dict null value for testing
680test_null_function() Funcref null value for testing
681test_null_job() Job null value for testing
682test_null_list() List null value for testing
683test_null_partial() Funcref null value for testing
684test_null_string() String null value for testing
685test_option_not_set({name}) none reset flag indicating option was set
686test_override({expr}, {val}) none test with Vim internal overrides
687test_refcount({expr}) Number get the reference count of {expr}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000688test_setmouse({row}, {col}) none set the mouse position for testing
689test_settime({expr}) none set current time for testing
690test_srand_seed([seed]) none set seed for testing srand()
691test_unknown() any unknown value for testing
692test_void() any void value for testing
693timer_info([{id}]) List information about timers
694timer_pause({id}, {pause}) none pause or unpause a timer
695timer_start({time}, {callback} [, {options}])
696 Number create a timer
697timer_stop({timer}) none stop a timer
698timer_stopall() none stop all timers
699tolower({expr}) String the String {expr} switched to lowercase
700toupper({expr}) String the String {expr} switched to uppercase
701tr({src}, {fromstr}, {tostr}) String translate chars of {src} in {fromstr}
702 to chars in {tostr}
703trim({text} [, {mask} [, {dir}]])
704 String trim characters in {mask} from {text}
705trunc({expr}) Float truncate Float {expr}
706type({expr}) Number type of value {expr}
707typename({expr}) String representation of the type of {expr}
708undofile({name}) String undo file name for {name}
709undotree() List undo file tree
710uniq({list} [, {func} [, {dict}]])
711 List remove adjacent duplicates from a list
Christian Brabandt67672ef2023-04-24 21:09:54 +0100712utf16idx({string}, {idx} [, {countcc} [, {charidx}]])
713 Number UTF-16 index of byte {idx} in {string}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000714values({dict}) List values in {dict}
LemonBoy0f7a3e12022-05-26 12:10:37 +0100715virtcol({expr} [, {list}]) Number or List
716 screen column of cursor or mark
Bram Moolenaar5a6ec102022-05-27 21:58:00 +0100717virtcol2col({winid}, {lnum}, {col})
718 Number byte index of a character on screen
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000719visualmode([expr]) String last visual mode used
720wildmenumode() Number whether 'wildmenu' mode is active
721win_execute({id}, {command} [, {silent}])
722 String execute {command} in window {id}
723win_findbuf({bufnr}) List find windows containing {bufnr}
724win_getid([{win} [, {tab}]]) Number get window ID for {win} in {tab}
725win_gettype([{nr}]) String type of window {nr}
726win_gotoid({expr}) Number go to window with ID {expr}
727win_id2tabwin({expr}) List get tab and window nr from window ID
728win_id2win({expr}) Number get window nr from window ID
Daniel Steinbergee630312022-01-10 13:36:34 +0000729win_move_separator({nr}) Number move window vertical separator
730win_move_statusline({nr}) Number move window status line
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000731win_screenpos({nr}) List get screen position of window {nr}
732win_splitmove({nr}, {target} [, {options}])
733 Number move window {nr} to split of {target}
734winbufnr({nr}) Number buffer number of window {nr}
735wincol() Number window column of the cursor
736windowsversion() String MS-Windows OS version
737winheight({nr}) Number height of window {nr}
738winlayout([{tabnr}]) List layout of windows in tab {tabnr}
739winline() Number window line of the cursor
740winnr([{expr}]) Number number of current window
741winrestcmd() String returns command to restore window sizes
742winrestview({dict}) none restore view of current window
743winsaveview() Dict save view of current window
744winwidth({nr}) Number width of window {nr}
745wordcount() Dict get byte/char/word statistics
746writefile({object}, {fname} [, {flags}])
747 Number write |Blob| or |List| of lines to file
748xor({expr}, {expr}) Number bitwise XOR
749
750==============================================================================
7512. Details *builtin-function-details*
752
753Not all functions are here, some have been moved to a help file covering the
754specific functionality.
755
756abs({expr}) *abs()*
757 Return the absolute value of {expr}. When {expr} evaluates to
758 a |Float| abs() returns a |Float|. When {expr} can be
759 converted to a |Number| abs() returns a |Number|. Otherwise
760 abs() gives an error message and returns -1.
761 Examples: >
762 echo abs(1.456)
763< 1.456 >
764 echo abs(-5.456)
765< 5.456 >
766 echo abs(-4)
767< 4
768
769 Can also be used as a |method|: >
770 Compute()->abs()
771
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000772
773acos({expr}) *acos()*
774 Return the arc cosine of {expr} measured in radians, as a
775 |Float| in the range of [0, pi].
776 {expr} must evaluate to a |Float| or a |Number| in the range
Bram Moolenaar016188f2022-06-06 20:52:59 +0100777 [-1, 1]. Otherwise acos() returns "nan".
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000778 Examples: >
779 :echo acos(0)
780< 1.570796 >
781 :echo acos(-0.5)
782< 2.094395
783
784 Can also be used as a |method|: >
785 Compute()->acos()
786
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000787
788add({object}, {expr}) *add()*
789 Append the item {expr} to |List| or |Blob| {object}. Returns
790 the resulting |List| or |Blob|. Examples: >
791 :let alist = add([1, 2, 3], item)
792 :call add(mylist, "woodstock")
793< Note that when {expr} is a |List| it is appended as a single
794 item. Use |extend()| to concatenate |Lists|.
795 When {object} is a |Blob| then {expr} must be a number.
796 Use |insert()| to add an item at another position.
Bram Moolenaar016188f2022-06-06 20:52:59 +0100797 Returns 1 if {object} is not a |List| or a |Blob|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000798
799 Can also be used as a |method|: >
800 mylist->add(val1)->add(val2)
801
802
803and({expr}, {expr}) *and()*
804 Bitwise AND on the two arguments. The arguments are converted
805 to a number. A List, Dict or Float argument causes an error.
LemonBoy0f7a3e12022-05-26 12:10:37 +0100806 Also see `or()` and `xor()`.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000807 Example: >
808 :let flag = and(bits, 0x80)
809< Can also be used as a |method|: >
810 :let flag = bits->and(0x80)
811
812
813append({lnum}, {text}) *append()*
814 When {text} is a |List|: Append each item of the |List| as a
815 text line below line {lnum} in the current buffer.
816 Otherwise append {text} as one text line below line {lnum} in
817 the current buffer.
818 Any type of item is accepted and converted to a String.
819 {lnum} can be zero to insert a line before the first one.
820 {lnum} is used like with |getline()|.
821 Returns 1 for failure ({lnum} out of range or out of memory),
Bram Moolenaarcd9c8d42022-11-05 23:46:43 +0000822 0 for success. When {text} is an empty list zero is returned,
823 no matter the value of {lnum}.
824 In |Vim9| script an invalid argument or negative number
825 results in an error. Example: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000826 :let failed = append(line('$'), "# THE END")
827 :let failed = append(0, ["Chapter 1", "the beginning"])
828
829< Can also be used as a |method| after a List, the base is
830 passed as the second argument: >
831 mylist->append(lnum)
832
833
834appendbufline({buf}, {lnum}, {text}) *appendbufline()*
835 Like |append()| but append the text in buffer {buf}.
836
837 This function works only for loaded buffers. First call
838 |bufload()| if needed.
839
840 For the use of {buf}, see |bufname()|.
841
Bram Moolenaar8b6256f2021-12-28 11:24:49 +0000842 {lnum} is the line number to append below. Note that using
843 |line()| would use the current buffer, not the one appending
844 to. Use "$" to append at the end of the buffer. Other string
845 values are not supported.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000846
847 On success 0 is returned, on failure 1 is returned.
848 In |Vim9| script an error is given for an invalid {lnum}.
849
850 If {buf} is not a valid buffer or {lnum} is not valid, an
851 error message is given. Example: >
852 :let failed = appendbufline(13, 0, "# THE START")
Bram Moolenaarcd9c8d42022-11-05 23:46:43 +0000853< However, when {text} is an empty list then no error is given
854 for an invalid {lnum}, since {lnum} isn't actually used.
855
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000856 Can also be used as a |method| after a List, the base is
857 passed as the second argument: >
858 mylist->appendbufline(buf, lnum)
859
860
861argc([{winid}]) *argc()*
862 The result is the number of files in the argument list. See
863 |arglist|.
864 If {winid} is not supplied, the argument list of the current
865 window is used.
866 If {winid} is -1, the global argument list is used.
867 Otherwise {winid} specifies the window of which the argument
868 list is used: either the window number or the window ID.
869 Returns -1 if the {winid} argument is invalid.
870
871 *argidx()*
872argidx() The result is the current index in the argument list. 0 is
873 the first file. argc() - 1 is the last one. See |arglist|.
874
875 *arglistid()*
876arglistid([{winnr} [, {tabnr}]])
877 Return the argument list ID. This is a number which
878 identifies the argument list being used. Zero is used for the
879 global argument list. See |arglist|.
880 Returns -1 if the arguments are invalid.
881
882 Without arguments use the current window.
883 With {winnr} only use this window in the current tab page.
884 With {winnr} and {tabnr} use the window in the specified tab
885 page.
886 {winnr} can be the window number or the |window-ID|.
887
888 *argv()*
889argv([{nr} [, {winid}]])
890 The result is the {nr}th file in the argument list. See
891 |arglist|. "argv(0)" is the first one. Example: >
892 :let i = 0
893 :while i < argc()
894 : let f = escape(fnameescape(argv(i)), '.')
Bram Moolenaarc51cf032022-02-26 12:25:45 +0000895 : exe 'amenu Arg.' .. f .. ' :e ' .. f .. '<CR>'
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000896 : let i = i + 1
897 :endwhile
898< Without the {nr} argument, or when {nr} is -1, a |List| with
899 the whole |arglist| is returned.
900
901 The {winid} argument specifies the window ID, see |argc()|.
902 For the Vim command line arguments see |v:argv|.
903
Bram Moolenaar016188f2022-06-06 20:52:59 +0100904 Returns an empty string if {nr}th argument is not present in
905 the argument list. Returns an empty List if the {winid}
906 argument is invalid.
907
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000908asin({expr}) *asin()*
909 Return the arc sine of {expr} measured in radians, as a |Float|
910 in the range of [-pi/2, pi/2].
911 {expr} must evaluate to a |Float| or a |Number| in the range
912 [-1, 1].
Bram Moolenaar016188f2022-06-06 20:52:59 +0100913 Returns "nan" if {expr} is outside the range [-1, 1]. Returns
914 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000915 Examples: >
916 :echo asin(0.8)
917< 0.927295 >
918 :echo asin(-0.5)
919< -0.523599
920
921 Can also be used as a |method|: >
922 Compute()->asin()
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000923
924
925assert_ functions are documented here: |assert-functions-details|
926
927
928
929atan({expr}) *atan()*
930 Return the principal value of the arc tangent of {expr}, in
931 the range [-pi/2, +pi/2] radians, as a |Float|.
932 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar016188f2022-06-06 20:52:59 +0100933 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000934 Examples: >
935 :echo atan(100)
936< 1.560797 >
937 :echo atan(-4.01)
938< -1.326405
939
940 Can also be used as a |method|: >
941 Compute()->atan()
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000942
943
944atan2({expr1}, {expr2}) *atan2()*
945 Return the arc tangent of {expr1} / {expr2}, measured in
946 radians, as a |Float| in the range [-pi, pi].
947 {expr1} and {expr2} must evaluate to a |Float| or a |Number|.
Bram Moolenaar016188f2022-06-06 20:52:59 +0100948 Returns 0.0 if {expr1} or {expr2} is not a |Float| or a
949 |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000950 Examples: >
951 :echo atan2(-1, 1)
952< -0.785398 >
953 :echo atan2(1, -1)
954< 2.356194
955
956 Can also be used as a |method|: >
957 Compute()->atan2(1)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000958
Yegappan Lakshmanan1755a912022-05-19 10:31:47 +0100959
960autocmd_add({acmds}) *autocmd_add()*
961 Adds a List of autocmds and autocmd groups.
962
963 The {acmds} argument is a List where each item is a Dict with
964 the following optional items:
965 bufnr buffer number to add a buffer-local autocmd.
966 If this item is specified, then the "pattern"
967 item is ignored.
968 cmd Ex command to execute for this autocmd event
969 event autocmd event name. Refer to |autocmd-events|.
Yegappan Lakshmanane0ff3a72022-05-27 18:05:33 +0100970 This can be either a String with a single
971 event name or a List of event names.
Yegappan Lakshmanan1755a912022-05-19 10:31:47 +0100972 group autocmd group name. Refer to |autocmd-groups|.
973 If this group doesn't exist then it is
974 created. If not specified or empty, then the
975 default group is used.
Yegappan Lakshmanan971f6822022-05-24 11:40:11 +0100976 nested boolean flag, set to v:true to add a nested
977 autocmd. Refer to |autocmd-nested|.
LemonBoy0f7a3e12022-05-26 12:10:37 +0100978 once boolean flag, set to v:true to add an autocmd
Yegappan Lakshmanan971f6822022-05-24 11:40:11 +0100979 which executes only once. Refer to
980 |autocmd-once|.
Yegappan Lakshmanan1755a912022-05-19 10:31:47 +0100981 pattern autocmd pattern string. Refer to
982 |autocmd-patterns|. If "bufnr" item is
Yegappan Lakshmanane0ff3a72022-05-27 18:05:33 +0100983 present, then this item is ignored. This can
984 be a String with a single pattern or a List of
985 patterns.
Yegappan Lakshmanan971f6822022-05-24 11:40:11 +0100986 replace boolean flag, set to v:true to remove all the
987 commands associated with the specified autocmd
988 event and group and add the {cmd}. This is
989 useful to avoid adding the same command
LemonBoy0f7a3e12022-05-26 12:10:37 +0100990 multiple times for an autocmd event in a group.
Yegappan Lakshmanan1755a912022-05-19 10:31:47 +0100991
992 Returns v:true on success and v:false on failure.
993 Examples: >
994 " Create a buffer-local autocmd for buffer 5
995 let acmd = {}
996 let acmd.group = 'MyGroup'
997 let acmd.event = 'BufEnter'
998 let acmd.bufnr = 5
999 let acmd.cmd = 'call BufEnterFunc()'
1000 call autocmd_add([acmd])
Bram Moolenaarcd9c8d42022-11-05 23:46:43 +00001001<
Yegappan Lakshmanan1755a912022-05-19 10:31:47 +01001002 Can also be used as a |method|: >
1003 GetAutocmdList()->autocmd_add()
1004<
1005autocmd_delete({acmds}) *autocmd_delete()*
1006 Deletes a List of autocmds and autocmd groups.
1007
1008 The {acmds} argument is a List where each item is a Dict with
1009 the following optional items:
1010 bufnr buffer number to delete a buffer-local autocmd.
1011 If this item is specified, then the "pattern"
1012 item is ignored.
1013 cmd Ex command for this autocmd event
1014 event autocmd event name. Refer to |autocmd-events|.
1015 If '*' then all the autocmd events in this
1016 group are deleted.
1017 group autocmd group name. Refer to |autocmd-groups|.
1018 If not specified or empty, then the default
1019 group is used.
1020 nested set to v:true for a nested autocmd.
1021 Refer to |autocmd-nested|.
1022 once set to v:true for an autocmd which executes
1023 only once. Refer to |autocmd-once|.
1024 pattern autocmd pattern string. Refer to
1025 |autocmd-patterns|. If "bufnr" item is
1026 present, then this item is ignored.
1027
1028 If only {group} is specified in a {acmds} entry and {event},
1029 {pattern} and {cmd} are not specified, then that autocmd group
1030 is deleted.
1031
Bram Moolenaar016188f2022-06-06 20:52:59 +01001032 Returns |v:true| on success and |v:false| on failure.
Yegappan Lakshmanan1755a912022-05-19 10:31:47 +01001033 Examples: >
1034 " :autocmd! BufLeave *.vim
1035 let acmd = #{event: 'BufLeave', pattern: '*.vim'}
1036 call autocmd_delete([acmd]})
1037 " :autocmd! MyGroup1 BufLeave
1038 let acmd = #{group: 'MyGroup1', event: 'BufLeave'}
1039 call autocmd_delete([acmd])
1040 " :autocmd! MyGroup2 BufEnter *.c
1041 let acmd = #{group: 'MyGroup2', event: 'BufEnter',
1042 \ pattern: '*.c'}
1043 " :autocmd! MyGroup2 * *.c
1044 let acmd = #{group: 'MyGroup2', event: '*',
1045 \ pattern: '*.c'}
1046 call autocmd_delete([acmd])
1047 " :autocmd! MyGroup3
1048 let acmd = #{group: 'MyGroup3'}
1049 call autocmd_delete([acmd])
1050<
1051 Can also be used as a |method|: >
1052 GetAutocmdList()->autocmd_delete()
1053
1054autocmd_get([{opts}]) *autocmd_get()*
1055 Returns a |List| of autocmds. If {opts} is not supplied, then
1056 returns the autocmds for all the events in all the groups.
1057
1058 The optional {opts} Dict argument supports the following
1059 items:
1060 group Autocmd group name. If specified, returns only
1061 the autocmds defined in this group. If the
1062 specified group doesn't exist, results in an
1063 error message. If set to an empty string,
1064 then the default autocmd group is used.
1065 event Autocmd event name. If specified, returns only
1066 the autocmds defined for this event. If set
1067 to "*", then returns autocmds for all the
1068 events. If the specified event doesn't exist,
1069 results in an error message.
1070 pattern Autocmd pattern. If specified, returns only
1071 the autocmds defined for this pattern.
1072 A combination of the above three times can be supplied in
1073 {opts}.
1074
1075 Each Dict in the returned List contains the following items:
1076 bufnr For buffer-local autocmds, buffer number where
1077 the autocmd is defined.
1078 cmd Command executed for this autocmd.
1079 event Autocmd event name.
1080 group Autocmd group name.
Yegappan Lakshmanan971f6822022-05-24 11:40:11 +01001081 nested Boolean flag, set to v:true for a nested
1082 autocmd. See |autocmd-nested|.
1083 once Boolean flag, set to v:true, if the autocmd
1084 will be executed only once. See |autocmd-once|.
Yegappan Lakshmanan1755a912022-05-19 10:31:47 +01001085 pattern Autocmd pattern. For a buffer-local
1086 autocmd, this will be of the form "<buffer=n>".
1087 If there are multiple commands for an autocmd event in a
1088 group, then separate items are returned for each command.
1089
Bram Moolenaar016188f2022-06-06 20:52:59 +01001090 Returns an empty List if an autocmd with the specified group
1091 or event or pattern is not found.
1092
Yegappan Lakshmanan1755a912022-05-19 10:31:47 +01001093 Examples: >
1094 " :autocmd MyGroup
1095 echo autocmd_get(#{group: 'Mygroup'})
1096 " :autocmd G BufUnload
1097 echo autocmd_get(#{group: 'G', event: 'BufUnload'})
1098 " :autocmd G * *.ts
1099 let acmd = #{group: 'G', event: '*', pattern: '*.ts'}
1100 echo autocmd_get(acmd)
1101 " :autocmd Syntax
1102 echo autocmd_get(#{event: 'Syntax'})
1103 " :autocmd G BufEnter *.ts
1104 let acmd = #{group: 'G', event: 'BufEnter',
1105 \ pattern: '*.ts'}
1106 echo autocmd_get(acmd)
1107<
1108 Can also be used as a |method|: >
1109 Getopts()->autocmd_get()
1110<
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001111balloon_gettext() *balloon_gettext()*
1112 Return the current text in the balloon. Only for the string,
Bram Moolenaar016188f2022-06-06 20:52:59 +01001113 not used for the List. Returns an empty string if balloon
1114 is not present.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001115
1116balloon_show({expr}) *balloon_show()*
1117 Show {expr} inside the balloon. For the GUI {expr} is used as
1118 a string. For a terminal {expr} can be a list, which contains
1119 the lines of the balloon. If {expr} is not a list it will be
1120 split with |balloon_split()|.
1121 If {expr} is an empty string any existing balloon is removed.
1122
1123 Example: >
1124 func GetBalloonContent()
1125 " ... initiate getting the content
1126 return ''
1127 endfunc
1128 set balloonexpr=GetBalloonContent()
1129
1130 func BalloonCallback(result)
1131 call balloon_show(a:result)
1132 endfunc
1133< Can also be used as a |method|: >
1134 GetText()->balloon_show()
1135<
1136 The intended use is that fetching the content of the balloon
1137 is initiated from 'balloonexpr'. It will invoke an
1138 asynchronous method, in which a callback invokes
1139 balloon_show(). The 'balloonexpr' itself can return an
Bram Moolenaar069a7d52022-06-27 22:16:08 +01001140 empty string or a placeholder, e.g. "loading...".
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001141
Bram Moolenaar069a7d52022-06-27 22:16:08 +01001142 When showing a balloon is not possible then nothing happens,
1143 no error message is given.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001144 {only available when compiled with the |+balloon_eval| or
1145 |+balloon_eval_term| feature}
1146
1147balloon_split({msg}) *balloon_split()*
1148 Split String {msg} into lines to be displayed in a balloon.
1149 The splits are made for the current window size and optimize
1150 to show debugger output.
Bram Moolenaar016188f2022-06-06 20:52:59 +01001151 Returns a |List| with the split lines. Returns an empty List
1152 on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001153 Can also be used as a |method|: >
1154 GetText()->balloon_split()->balloon_show()
1155
1156< {only available when compiled with the |+balloon_eval_term|
1157 feature}
1158
1159blob2list({blob}) *blob2list()*
1160 Return a List containing the number value of each byte in Blob
1161 {blob}. Examples: >
1162 blob2list(0z0102.0304) returns [1, 2, 3, 4]
1163 blob2list(0z) returns []
1164< Returns an empty List on error. |list2blob()| does the
1165 opposite.
1166
1167 Can also be used as a |method|: >
1168 GetBlob()->blob2list()
Bram Moolenaarb529cfb2022-07-25 15:42:07 +01001169<
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001170 *browse()*
1171browse({save}, {title}, {initdir}, {default})
1172 Put up a file requester. This only works when "has("browse")"
1173 returns |TRUE| (only in some GUI versions).
1174 The input fields are:
1175 {save} when |TRUE|, select file to write
1176 {title} title for the requester
1177 {initdir} directory to start browsing in
1178 {default} default file name
1179 An empty string is returned when the "Cancel" button is hit,
1180 something went wrong, or browsing is not possible.
1181
1182 *browsedir()*
1183browsedir({title}, {initdir})
1184 Put up a directory requester. This only works when
1185 "has("browse")" returns |TRUE| (only in some GUI versions).
1186 On systems where a directory browser is not supported a file
1187 browser is used. In that case: select a file in the directory
1188 to be used.
1189 The input fields are:
1190 {title} title for the requester
1191 {initdir} directory to start browsing in
1192 When the "Cancel" button is hit, something went wrong, or
1193 browsing is not possible, an empty string is returned.
1194
1195bufadd({name}) *bufadd()*
Bram Moolenaar2eddbac2022-08-25 12:45:21 +01001196 Add a buffer to the buffer list with name {name} (must be a
1197 String).
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001198 If a buffer for file {name} already exists, return that buffer
1199 number. Otherwise return the buffer number of the newly
1200 created buffer. When {name} is an empty string then a new
1201 buffer is always created.
1202 The buffer will not have 'buflisted' set and not be loaded
1203 yet. To add some text to the buffer use this: >
1204 let bufnr = bufadd('someName')
1205 call bufload(bufnr)
1206 call setbufline(bufnr, 1, ['some', 'text'])
Bram Moolenaar016188f2022-06-06 20:52:59 +01001207< Returns 0 on error.
1208 Can also be used as a |method|: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001209 let bufnr = 'somename'->bufadd()
1210
1211bufexists({buf}) *bufexists()*
1212 The result is a Number, which is |TRUE| if a buffer called
1213 {buf} exists.
1214 If the {buf} argument is a number, buffer numbers are used.
1215 Number zero is the alternate buffer for the current window.
1216
1217 If the {buf} argument is a string it must match a buffer name
1218 exactly. The name can be:
1219 - Relative to the current directory.
1220 - A full path.
1221 - The name of a buffer with 'buftype' set to "nofile".
1222 - A URL name.
1223 Unlisted buffers will be found.
1224 Note that help files are listed by their short name in the
1225 output of |:buffers|, but bufexists() requires using their
1226 long name to be able to find them.
1227 bufexists() may report a buffer exists, but to use the name
1228 with a |:buffer| command you may need to use |expand()|. Esp
1229 for MS-Windows 8.3 names in the form "c:\DOCUME~1"
1230 Use "bufexists(0)" to test for the existence of an alternate
1231 file name.
1232
1233 Can also be used as a |method|: >
1234 let exists = 'somename'->bufexists()
1235<
1236 Obsolete name: buffer_exists(). *buffer_exists()*
1237
1238buflisted({buf}) *buflisted()*
1239 The result is a Number, which is |TRUE| if a buffer called
1240 {buf} exists and is listed (has the 'buflisted' option set).
1241 The {buf} argument is used like with |bufexists()|.
1242
1243 Can also be used as a |method|: >
1244 let listed = 'somename'->buflisted()
1245
1246bufload({buf}) *bufload()*
1247 Ensure the buffer {buf} is loaded. When the buffer name
1248 refers to an existing file then the file is read. Otherwise
1249 the buffer will be empty. If the buffer was already loaded
Bram Moolenaar2eddbac2022-08-25 12:45:21 +01001250 then there is no change. If the buffer is not related to a
1251 file the no file is read (e.g., when 'buftype' is "nofile").
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001252 If there is an existing swap file for the file of the buffer,
1253 there will be no dialog, the buffer will be loaded anyway.
1254 The {buf} argument is used like with |bufexists()|.
1255
1256 Can also be used as a |method|: >
1257 eval 'somename'->bufload()
1258
1259bufloaded({buf}) *bufloaded()*
1260 The result is a Number, which is |TRUE| if a buffer called
1261 {buf} exists and is loaded (shown in a window or hidden).
1262 The {buf} argument is used like with |bufexists()|.
1263
1264 Can also be used as a |method|: >
1265 let loaded = 'somename'->bufloaded()
1266
1267bufname([{buf}]) *bufname()*
1268 The result is the name of a buffer. Mostly as it is displayed
1269 by the `:ls` command, but not using special names such as
1270 "[No Name]".
1271 If {buf} is omitted the current buffer is used.
1272 If {buf} is a Number, that buffer number's name is given.
1273 Number zero is the alternate buffer for the current window.
1274 If {buf} is a String, it is used as a |file-pattern| to match
1275 with the buffer names. This is always done like 'magic' is
1276 set and 'cpoptions' is empty. When there is more than one
1277 match an empty string is returned.
1278 "" or "%" can be used for the current buffer, "#" for the
1279 alternate buffer.
1280 A full match is preferred, otherwise a match at the start, end
1281 or middle of the buffer name is accepted. If you only want a
1282 full match then put "^" at the start and "$" at the end of the
1283 pattern.
1284 Listed buffers are found first. If there is a single match
1285 with a listed buffer, that one is returned. Next unlisted
1286 buffers are searched for.
1287 If the {buf} is a String, but you want to use it as a buffer
1288 number, force it to be a Number by adding zero to it: >
1289 :echo bufname("3" + 0)
1290< Can also be used as a |method|: >
1291 echo bufnr->bufname()
1292
1293< If the buffer doesn't exist, or doesn't have a name, an empty
1294 string is returned. >
1295 bufname("#") alternate buffer name
1296 bufname(3) name of buffer 3
1297 bufname("%") name of current buffer
1298 bufname("file2") name of buffer where "file2" matches.
1299< *buffer_name()*
1300 Obsolete name: buffer_name().
1301
1302 *bufnr()*
1303bufnr([{buf} [, {create}]])
1304 The result is the number of a buffer, as it is displayed by
1305 the `:ls` command. For the use of {buf}, see |bufname()|
1306 above.
1307
1308 If the buffer doesn't exist, -1 is returned. Or, if the
1309 {create} argument is present and TRUE, a new, unlisted,
1310 buffer is created and its number is returned. Example: >
1311 let newbuf = bufnr('Scratch001', 1)
1312< Using an empty name uses the current buffer. To create a new
1313 buffer with an empty name use |bufadd()|.
1314
1315 bufnr("$") is the last buffer: >
1316 :let last_buffer = bufnr("$")
1317< The result is a Number, which is the highest buffer number
1318 of existing buffers. Note that not all buffers with a smaller
1319 number necessarily exist, because ":bwipeout" may have removed
1320 them. Use bufexists() to test for the existence of a buffer.
1321
1322 Can also be used as a |method|: >
1323 echo bufref->bufnr()
1324<
1325 Obsolete name: buffer_number(). *buffer_number()*
1326 *last_buffer_nr()*
1327 Obsolete name for bufnr("$"): last_buffer_nr().
1328
1329bufwinid({buf}) *bufwinid()*
1330 The result is a Number, which is the |window-ID| of the first
1331 window associated with buffer {buf}. For the use of {buf},
1332 see |bufname()| above. If buffer {buf} doesn't exist or
1333 there is no such window, -1 is returned. Example: >
1334
Bram Moolenaarc51cf032022-02-26 12:25:45 +00001335 echo "A window containing buffer 1 is " .. (bufwinid(1))
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001336<
Bram Moolenaar76db9e02022-11-09 21:21:04 +00001337 Only deals with the current tab page. See |win_findbuf()| for
1338 finding more.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001339
1340 Can also be used as a |method|: >
1341 FindBuffer()->bufwinid()
1342
1343bufwinnr({buf}) *bufwinnr()*
1344 Like |bufwinid()| but return the window number instead of the
1345 |window-ID|.
1346 If buffer {buf} doesn't exist or there is no such window, -1
1347 is returned. Example: >
1348
Bram Moolenaarc51cf032022-02-26 12:25:45 +00001349 echo "A window containing buffer 1 is " .. (bufwinnr(1))
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001350
1351< The number can be used with |CTRL-W_w| and ":wincmd w"
1352 |:wincmd|.
1353
1354 Can also be used as a |method|: >
1355 FindBuffer()->bufwinnr()
1356
1357byte2line({byte}) *byte2line()*
1358 Return the line number that contains the character at byte
1359 count {byte} in the current buffer. This includes the
1360 end-of-line character, depending on the 'fileformat' option
1361 for the current buffer. The first character has byte count
1362 one.
1363 Also see |line2byte()|, |go| and |:goto|.
1364
Bram Moolenaar016188f2022-06-06 20:52:59 +01001365 Returns -1 if the {byte} value is invalid.
1366
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001367 Can also be used as a |method|: >
1368 GetOffset()->byte2line()
1369
1370< {not available when compiled without the |+byte_offset|
1371 feature}
1372
Christian Brabandt67672ef2023-04-24 21:09:54 +01001373byteidx({expr}, {nr} [, {utf16}]) *byteidx()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001374 Return byte index of the {nr}'th character in the String
1375 {expr}. Use zero for the first character, it then returns
1376 zero.
1377 If there are no multibyte characters the returned value is
1378 equal to {nr}.
1379 Composing characters are not counted separately, their byte
1380 length is added to the preceding base character. See
1381 |byteidxcomp()| below for counting composing characters
1382 separately.
Christian Brabandt67672ef2023-04-24 21:09:54 +01001383 When {utf16} is present and TRUE, {nr} is used as the UTF-16
1384 index in the String {expr} instead of as the character index.
1385 The UTF-16 index is the index in the string when it is encoded
1386 with 16-bit words. If the specified UTF-16 index is in the
1387 middle of a character (e.g. in a 4-byte character), then the
1388 byte index of the first byte in the character is returned.
1389 Refer to |string-offset-encoding| for more information.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001390 Example : >
1391 echo matchstr(str, ".", byteidx(str, 3))
1392< will display the fourth character. Another way to do the
1393 same: >
1394 let s = strpart(str, byteidx(str, 3))
1395 echo strpart(s, 0, byteidx(s, 1))
1396< Also see |strgetchar()| and |strcharpart()|.
1397
1398 If there are less than {nr} characters -1 is returned.
1399 If there are exactly {nr} characters the length of the string
1400 in bytes is returned.
Christian Brabandt67672ef2023-04-24 21:09:54 +01001401 See |charidx()| and |utf16idx()| for getting the character and
1402 UTF-16 index respectively from the byte index.
1403 Examples: >
1404 echo byteidx('a😊😊', 2) returns 5
1405 echo byteidx('a😊😊', 2, 1) returns 1
1406 echo byteidx('a😊😊', 3, 1) returns 5
1407<
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001408 Can also be used as a |method|: >
1409 GetName()->byteidx(idx)
1410
Christian Brabandt67672ef2023-04-24 21:09:54 +01001411byteidxcomp({expr}, {nr} [, {utf16}]) *byteidxcomp()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001412 Like byteidx(), except that a composing character is counted
1413 as a separate character. Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00001414 let s = 'e' .. nr2char(0x301)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001415 echo byteidx(s, 1)
1416 echo byteidxcomp(s, 1)
1417 echo byteidxcomp(s, 2)
1418< The first and third echo result in 3 ('e' plus composing
1419 character is 3 bytes), the second echo results in 1 ('e' is
1420 one byte).
1421 Only works differently from byteidx() when 'encoding' is set
1422 to a Unicode encoding.
1423
1424 Can also be used as a |method|: >
1425 GetName()->byteidxcomp(idx)
1426
1427call({func}, {arglist} [, {dict}]) *call()* *E699*
1428 Call function {func} with the items in |List| {arglist} as
1429 arguments.
1430 {func} can either be a |Funcref| or the name of a function.
1431 a:firstline and a:lastline are set to the cursor line.
1432 Returns the return value of the called function.
1433 {dict} is for functions with the "dict" attribute. It will be
1434 used to set the local variable "self". |Dictionary-function|
1435
1436 Can also be used as a |method|: >
1437 GetFunc()->call([arg, arg], dict)
1438
1439ceil({expr}) *ceil()*
1440 Return the smallest integral value greater than or equal to
1441 {expr} as a |Float| (round up).
1442 {expr} must evaluate to a |Float| or a |Number|.
1443 Examples: >
1444 echo ceil(1.456)
1445< 2.0 >
1446 echo ceil(-5.456)
1447< -5.0 >
1448 echo ceil(4.0)
1449< 4.0
1450
Bram Moolenaar016188f2022-06-06 20:52:59 +01001451 Returns 0.0 if {expr} is not a |Float| or a |Number|.
1452
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001453 Can also be used as a |method|: >
1454 Compute()->ceil()
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001455
1456
1457ch_ functions are documented here: |channel-functions-details|
1458
1459
1460changenr() *changenr()*
1461 Return the number of the most recent change. This is the same
1462 number as what is displayed with |:undolist| and can be used
1463 with the |:undo| command.
1464 When a change was made it is the number of that change. After
1465 redo it is the number of the redone change. After undo it is
1466 one less than the number of the undone change.
Bram Moolenaar016188f2022-06-06 20:52:59 +01001467 Returns 0 if the undo list is empty.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001468
1469char2nr({string} [, {utf8}]) *char2nr()*
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01001470 Return Number value of the first char in {string}.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001471 Examples: >
1472 char2nr(" ") returns 32
1473 char2nr("ABC") returns 65
1474< When {utf8} is omitted or zero, the current 'encoding' is used.
1475 Example for "utf-8": >
1476 char2nr("á") returns 225
1477 char2nr("á"[0]) returns 195
1478< When {utf8} is TRUE, always treat as UTF-8 characters.
1479 A combining character is a separate character.
1480 |nr2char()| does the opposite.
1481 To turn a string into a list of character numbers: >
1482 let str = "ABC"
1483 let list = map(split(str, '\zs'), {_, val -> char2nr(val)})
1484< Result: [65, 66, 67]
1485
Bram Moolenaar016188f2022-06-06 20:52:59 +01001486 Returns 0 if {string} is not a |String|.
1487
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001488 Can also be used as a |method|: >
1489 GetChar()->char2nr()
1490
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001491charclass({string}) *charclass()*
1492 Return the character class of the first character in {string}.
1493 The character class is one of:
1494 0 blank
1495 1 punctuation
1496 2 word character
1497 3 emoji
1498 other specific Unicode class
1499 The class is used in patterns and word motions.
Bram Moolenaar016188f2022-06-06 20:52:59 +01001500 Returns 0 if {string} is not a |String|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001501
1502
Yegappan Lakshmanan4c8d2f02022-11-12 16:07:47 +00001503charcol({expr} [, {winid}]) *charcol()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001504 Same as |col()| but returns the character index of the column
1505 position given with {expr} instead of the byte position.
1506
1507 Example:
1508 With the cursor on '세' in line 5 with text "여보세요": >
1509 charcol('.') returns 3
1510 col('.') returns 7
1511
1512< Can also be used as a |method|: >
1513 GetPos()->col()
1514<
1515 *charidx()*
Christian Brabandt67672ef2023-04-24 21:09:54 +01001516charidx({string}, {idx} [, {countcc} [, {utf16}]])
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001517 Return the character index of the byte at {idx} in {string}.
1518 The index of the first character is zero.
1519 If there are no multibyte characters the returned value is
1520 equal to {idx}.
Christian Brabandt67672ef2023-04-24 21:09:54 +01001521
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001522 When {countcc} is omitted or |FALSE|, then composing characters
Christian Brabandt67672ef2023-04-24 21:09:54 +01001523 are not counted separately, their byte length is added to the
1524 preceding base character.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001525 When {countcc} is |TRUE|, then composing characters are
1526 counted as separate characters.
Christian Brabandt67672ef2023-04-24 21:09:54 +01001527
1528 When {utf16} is present and TRUE, {idx} is used as the UTF-16
1529 index in the String {expr} instead of as the byte index.
1530
Yegappan Lakshmanan577922b2023-06-08 17:09:45 +01001531 Returns -1 if the arguments are invalid or if there are less
1532 than {idx} bytes. If there are exactly {idx} bytes the length
1533 of the string in characters is returned.
1534
1535 An error is given and -1 is returned if the first argument is
1536 not a string, the second argument is not a number or when the
1537 third argument is present and is not zero or one.
Christian Brabandt67672ef2023-04-24 21:09:54 +01001538
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001539 See |byteidx()| and |byteidxcomp()| for getting the byte index
Christian Brabandt67672ef2023-04-24 21:09:54 +01001540 from the character index and |utf16idx()| for getting the
1541 UTF-16 index from the character index.
1542 Refer to |string-offset-encoding| for more information.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001543 Examples: >
1544 echo charidx('áb́ć', 3) returns 1
1545 echo charidx('áb́ć', 6, 1) returns 4
1546 echo charidx('áb́ć', 16) returns -1
Christian Brabandt67672ef2023-04-24 21:09:54 +01001547 echo charidx('a😊😊', 4, 0, 1) returns 2
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001548<
1549 Can also be used as a |method|: >
1550 GetName()->charidx(idx)
1551
1552chdir({dir}) *chdir()*
1553 Change the current working directory to {dir}. The scope of
1554 the directory change depends on the directory of the current
1555 window:
1556 - If the current window has a window-local directory
1557 (|:lcd|), then changes the window local directory.
1558 - Otherwise, if the current tabpage has a local
1559 directory (|:tcd|) then changes the tabpage local
1560 directory.
1561 - Otherwise, changes the global directory.
1562 {dir} must be a String.
1563 If successful, returns the previous working directory. Pass
1564 this to another chdir() to restore the directory.
1565 On failure, returns an empty string.
1566
1567 Example: >
1568 let save_dir = chdir(newdir)
1569 if save_dir != ""
1570 " ... do some work
1571 call chdir(save_dir)
1572 endif
1573
1574< Can also be used as a |method|: >
1575 GetDir()->chdir()
1576<
1577cindent({lnum}) *cindent()*
1578 Get the amount of indent for line {lnum} according the C
1579 indenting rules, as with 'cindent'.
1580 The indent is counted in spaces, the value of 'tabstop' is
1581 relevant. {lnum} is used just like in |getline()|.
Bram Moolenaar8e145b82022-05-21 20:17:31 +01001582 When {lnum} is invalid -1 is returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001583 See |C-indenting|.
1584
1585 Can also be used as a |method|: >
1586 GetLnum()->cindent()
1587
1588clearmatches([{win}]) *clearmatches()*
1589 Clears all matches previously defined for the current window
1590 by |matchadd()| and the |:match| commands.
1591 If {win} is specified, use the window with this number or
1592 window ID instead of the current window.
1593
1594 Can also be used as a |method|: >
1595 GetWin()->clearmatches()
1596<
Bram Moolenaar10e8ff92023-06-10 21:40:39 +01001597col({expr} [, {winid}]) *col()*
Yegappan Lakshmanan4c8d2f02022-11-12 16:07:47 +00001598 The result is a Number, which is the byte index of the column
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001599 position given with {expr}. The accepted positions are:
1600 . the cursor position
1601 $ the end of the cursor line (the result is the
1602 number of bytes in the cursor line plus one)
1603 'x position of mark x (if the mark is not set, 0 is
1604 returned)
1605 v In Visual mode: the start of the Visual area (the
1606 cursor is the end). When not in Visual mode
1607 returns the cursor position. Differs from |'<| in
1608 that it's updated right away.
1609 Additionally {expr} can be [lnum, col]: a |List| with the line
1610 and column number. Most useful when the column is "$", to get
1611 the last column of a specific line. When "lnum" or "col" is
1612 out of range then col() returns zero.
Yegappan Lakshmanan4c8d2f02022-11-12 16:07:47 +00001613 With the optional {winid} argument the values are obtained for
1614 that window instead of the current window.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001615 To get the line number use |line()|. To get both use
1616 |getpos()|.
1617 For the screen column position use |virtcol()|. For the
1618 character position use |charcol()|.
1619 Note that only marks in the current file can be used.
1620 Examples: >
1621 col(".") column of cursor
1622 col("$") length of cursor line plus one
1623 col("'t") column of mark t
Bram Moolenaarc51cf032022-02-26 12:25:45 +00001624 col("'" .. markname) column of mark markname
Yegappan Lakshmanan4c8d2f02022-11-12 16:07:47 +00001625< The first column is 1. Returns 0 if {expr} is invalid or when
1626 the window with ID {winid} is not found.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001627 For an uppercase mark the column may actually be in another
1628 buffer.
1629 For the cursor position, when 'virtualedit' is active, the
1630 column is one higher if the cursor is after the end of the
Bram Moolenaar6ebe4f92022-10-28 20:47:54 +01001631 line. Also, when using a <Cmd> mapping the cursor isn't
1632 moved, this can be used to obtain the column in Insert mode: >
Bram Moolenaar76db9e02022-11-09 21:21:04 +00001633 :imap <F2> <Cmd>echowin col(".")<CR>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001634
1635< Can also be used as a |method|: >
1636 GetPos()->col()
1637<
1638
1639complete({startcol}, {matches}) *complete()* *E785*
1640 Set the matches for Insert mode completion.
1641 Can only be used in Insert mode. You need to use a mapping
1642 with CTRL-R = (see |i_CTRL-R|). It does not work after CTRL-O
1643 or with an expression mapping.
1644 {startcol} is the byte offset in the line where the completed
1645 text start. The text up to the cursor is the original text
1646 that will be replaced by the matches. Use col('.') for an
1647 empty string. "col('.') - 1" will replace one character by a
1648 match.
1649 {matches} must be a |List|. Each |List| item is one match.
1650 See |complete-items| for the kind of items that are possible.
1651 "longest" in 'completeopt' is ignored.
1652 Note that the after calling this function you need to avoid
1653 inserting anything that would cause completion to stop.
1654 The match can be selected with CTRL-N and CTRL-P as usual with
1655 Insert mode completion. The popup menu will appear if
1656 specified, see |ins-completion-menu|.
1657 Example: >
1658 inoremap <F5> <C-R>=ListMonths()<CR>
1659
Bram Moolenaar10e8ff92023-06-10 21:40:39 +01001660 func ListMonths()
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001661 call complete(col('.'), ['January', 'February', 'March',
1662 \ 'April', 'May', 'June', 'July', 'August', 'September',
1663 \ 'October', 'November', 'December'])
1664 return ''
1665 endfunc
1666< This isn't very useful, but it shows how it works. Note that
1667 an empty string is returned to avoid a zero being inserted.
1668
1669 Can also be used as a |method|, the base is passed as the
1670 second argument: >
1671 GetMatches()->complete(col('.'))
1672
1673complete_add({expr}) *complete_add()*
1674 Add {expr} to the list of matches. Only to be used by the
1675 function specified with the 'completefunc' option.
1676 Returns 0 for failure (empty string or out of memory),
1677 1 when the match was added, 2 when the match was already in
1678 the list.
1679 See |complete-functions| for an explanation of {expr}. It is
1680 the same as one item in the list that 'omnifunc' would return.
1681
1682 Can also be used as a |method|: >
1683 GetMoreMatches()->complete_add()
1684
1685complete_check() *complete_check()*
1686 Check for a key typed while looking for completion matches.
1687 This is to be used when looking for matches takes some time.
1688 Returns |TRUE| when searching for matches is to be aborted,
1689 zero otherwise.
1690 Only to be used by the function specified with the
1691 'completefunc' option.
1692
1693
1694complete_info([{what}]) *complete_info()*
1695 Returns a |Dictionary| with information about Insert mode
1696 completion. See |ins-completion|.
1697 The items are:
1698 mode Current completion mode name string.
1699 See |complete_info_mode| for the values.
1700 pum_visible |TRUE| if popup menu is visible.
1701 See |pumvisible()|.
1702 items List of completion matches. Each item is a
1703 dictionary containing the entries "word",
1704 "abbr", "menu", "kind", "info" and "user_data".
1705 See |complete-items|.
1706 selected Selected item index. First index is zero.
1707 Index is -1 if no item is selected (showing
1708 typed text only, or the last completion after
1709 no item is selected when using the <Up> or
1710 <Down> keys)
Bram Moolenaar0daafaa2022-09-04 17:45:43 +01001711 inserted Inserted string. [NOT IMPLEMENTED YET]
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001712
1713 *complete_info_mode*
1714 mode values are:
1715 "" Not in completion mode
1716 "keyword" Keyword completion |i_CTRL-X_CTRL-N|
1717 "ctrl_x" Just pressed CTRL-X |i_CTRL-X|
1718 "scroll" Scrolling with |i_CTRL-X_CTRL-E| or
1719 |i_CTRL-X_CTRL-Y|
1720 "whole_line" Whole lines |i_CTRL-X_CTRL-L|
1721 "files" File names |i_CTRL-X_CTRL-F|
1722 "tags" Tags |i_CTRL-X_CTRL-]|
1723 "path_defines" Definition completion |i_CTRL-X_CTRL-D|
1724 "path_patterns" Include completion |i_CTRL-X_CTRL-I|
1725 "dictionary" Dictionary |i_CTRL-X_CTRL-K|
1726 "thesaurus" Thesaurus |i_CTRL-X_CTRL-T|
1727 "cmdline" Vim Command line |i_CTRL-X_CTRL-V|
1728 "function" User defined completion |i_CTRL-X_CTRL-U|
1729 "omni" Omni completion |i_CTRL-X_CTRL-O|
1730 "spell" Spelling suggestions |i_CTRL-X_s|
1731 "eval" |complete()| completion
1732 "unknown" Other internal modes
1733
1734 If the optional {what} list argument is supplied, then only
1735 the items listed in {what} are returned. Unsupported items in
1736 {what} are silently ignored.
1737
1738 To get the position and size of the popup menu, see
1739 |pum_getpos()|. It's also available in |v:event| during the
1740 |CompleteChanged| event.
1741
Bram Moolenaar016188f2022-06-06 20:52:59 +01001742 Returns an empty |Dictionary| on error.
1743
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001744 Examples: >
1745 " Get all items
1746 call complete_info()
1747 " Get only 'mode'
1748 call complete_info(['mode'])
1749 " Get only 'mode' and 'pum_visible'
1750 call complete_info(['mode', 'pum_visible'])
1751
1752< Can also be used as a |method|: >
1753 GetItems()->complete_info()
1754<
1755 *confirm()*
1756confirm({msg} [, {choices} [, {default} [, {type}]]])
1757 confirm() offers the user a dialog, from which a choice can be
1758 made. It returns the number of the choice. For the first
1759 choice this is 1.
1760 Note: confirm() is only supported when compiled with dialog
1761 support, see |+dialog_con| and |+dialog_gui|.
1762
1763 {msg} is displayed in a |dialog| with {choices} as the
1764 alternatives. When {choices} is missing or empty, "&OK" is
1765 used (and translated).
1766 {msg} is a String, use '\n' to include a newline. Only on
1767 some systems the string is wrapped when it doesn't fit.
1768
1769 {choices} is a String, with the individual choices separated
1770 by '\n', e.g. >
1771 confirm("Save changes?", "&Yes\n&No\n&Cancel")
1772< The letter after the '&' is the shortcut key for that choice.
1773 Thus you can type 'c' to select "Cancel". The shortcut does
1774 not need to be the first letter: >
1775 confirm("file has been modified", "&Save\nSave &All")
1776< For the console, the first letter of each choice is used as
1777 the default shortcut key. Case is ignored.
1778
1779 The optional {default} argument is the number of the choice
1780 that is made if the user hits <CR>. Use 1 to make the first
1781 choice the default one. Use 0 to not set a default. If
1782 {default} is omitted, 1 is used.
1783
1784 The optional {type} String argument gives the type of dialog.
1785 This is only used for the icon of the GTK, Mac, Motif and
1786 Win32 GUI. It can be one of these values: "Error",
1787 "Question", "Info", "Warning" or "Generic". Only the first
1788 character is relevant. When {type} is omitted, "Generic" is
1789 used.
1790
1791 If the user aborts the dialog by pressing <Esc>, CTRL-C,
1792 or another valid interrupt key, confirm() returns 0.
1793
1794 An example: >
Bram Moolenaar46eea442022-03-30 10:51:39 +01001795 let choice = confirm("What do you want?",
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01001796 \ "&Apples\n&Oranges\n&Bananas", 2)
Bram Moolenaar46eea442022-03-30 10:51:39 +01001797 if choice == 0
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01001798 echo "make up your mind!"
Bram Moolenaar46eea442022-03-30 10:51:39 +01001799 elseif choice == 3
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01001800 echo "tasteful"
Bram Moolenaar46eea442022-03-30 10:51:39 +01001801 else
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01001802 echo "I prefer bananas myself."
Bram Moolenaar46eea442022-03-30 10:51:39 +01001803 endif
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001804< In a GUI dialog, buttons are used. The layout of the buttons
1805 depends on the 'v' flag in 'guioptions'. If it is included,
1806 the buttons are always put vertically. Otherwise, confirm()
1807 tries to put the buttons in one horizontal line. If they
1808 don't fit, a vertical layout is used anyway. For some systems
1809 the horizontal layout is always used.
1810
1811 Can also be used as a |method|in: >
1812 BuildMessage()->confirm("&Yes\n&No")
1813<
1814 *copy()*
1815copy({expr}) Make a copy of {expr}. For Numbers and Strings this isn't
1816 different from using {expr} directly.
1817 When {expr} is a |List| a shallow copy is created. This means
1818 that the original |List| can be changed without changing the
1819 copy, and vice versa. But the items are identical, thus
1820 changing an item changes the contents of both |Lists|.
1821 A |Dictionary| is copied in a similar way as a |List|.
1822 Also see |deepcopy()|.
1823 Can also be used as a |method|: >
1824 mylist->copy()
1825
1826cos({expr}) *cos()*
1827 Return the cosine of {expr}, measured in radians, as a |Float|.
1828 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar016188f2022-06-06 20:52:59 +01001829 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001830 Examples: >
1831 :echo cos(100)
1832< 0.862319 >
1833 :echo cos(-4.01)
1834< -0.646043
1835
1836 Can also be used as a |method|: >
1837 Compute()->cos()
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001838
1839
1840cosh({expr}) *cosh()*
1841 Return the hyperbolic cosine of {expr} as a |Float| in the range
1842 [1, inf].
1843 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar016188f2022-06-06 20:52:59 +01001844 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001845 Examples: >
1846 :echo cosh(0.5)
1847< 1.127626 >
1848 :echo cosh(-0.5)
1849< -1.127626
1850
1851 Can also be used as a |method|: >
1852 Compute()->cosh()
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001853
1854
1855count({comp}, {expr} [, {ic} [, {start}]]) *count()*
1856 Return the number of times an item with value {expr} appears
1857 in |String|, |List| or |Dictionary| {comp}.
1858
1859 If {start} is given then start with the item with this index.
1860 {start} can only be used with a |List|.
1861
1862 When {ic} is given and it's |TRUE| then case is ignored.
1863
1864 When {comp} is a string then the number of not overlapping
1865 occurrences of {expr} is returned. Zero is returned when
1866 {expr} is an empty string.
1867
1868 Can also be used as a |method|: >
1869 mylist->count(val)
1870<
1871 *cscope_connection()*
1872cscope_connection([{num} , {dbpath} [, {prepend}]])
1873 Checks for the existence of a |cscope| connection. If no
1874 parameters are specified, then the function returns:
1875 0, if cscope was not available (not compiled in), or
1876 if there are no cscope connections;
1877 1, if there is at least one cscope connection.
1878
1879 If parameters are specified, then the value of {num}
1880 determines how existence of a cscope connection is checked:
1881
1882 {num} Description of existence check
1883 ----- ------------------------------
1884 0 Same as no parameters (e.g., "cscope_connection()").
1885 1 Ignore {prepend}, and use partial string matches for
1886 {dbpath}.
1887 2 Ignore {prepend}, and use exact string matches for
1888 {dbpath}.
1889 3 Use {prepend}, use partial string matches for both
1890 {dbpath} and {prepend}.
1891 4 Use {prepend}, use exact string matches for both
1892 {dbpath} and {prepend}.
1893
1894 Note: All string comparisons are case sensitive!
1895
1896 Examples. Suppose we had the following (from ":cs show"): >
1897
1898 # pid database name prepend path
1899 0 27664 cscope.out /usr/local
1900<
1901 Invocation Return Val ~
1902 ---------- ---------- >
1903 cscope_connection() 1
1904 cscope_connection(1, "out") 1
1905 cscope_connection(2, "out") 0
1906 cscope_connection(3, "out") 0
1907 cscope_connection(3, "out", "local") 1
1908 cscope_connection(4, "out") 0
1909 cscope_connection(4, "out", "local") 0
1910 cscope_connection(4, "cscope.out", "/usr/local") 1
1911<
1912cursor({lnum}, {col} [, {off}]) *cursor()*
1913cursor({list})
1914 Positions the cursor at the column (byte count) {col} in the
1915 line {lnum}. The first column is one.
1916
1917 When there is one argument {list} this is used as a |List|
1918 with two, three or four item:
1919 [{lnum}, {col}]
1920 [{lnum}, {col}, {off}]
1921 [{lnum}, {col}, {off}, {curswant}]
1922 This is like the return value of |getpos()| or |getcurpos()|,
1923 but without the first item.
1924
Bram Moolenaar10e8ff92023-06-10 21:40:39 +01001925 To position the cursor using {col} as the character count, use
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001926 |setcursorcharpos()|.
1927
1928 Does not change the jumplist.
Bram Moolenaar7c6cd442022-10-11 21:54:04 +01001929 {lnum} is used like with |getline()|, except that if {lnum} is
1930 zero, the cursor will stay in the current line.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001931 If {lnum} is greater than the number of lines in the buffer,
1932 the cursor will be positioned at the last line in the buffer.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001933 If {col} is greater than the number of bytes in the line,
1934 the cursor will be positioned at the last character in the
1935 line.
1936 If {col} is zero, the cursor will stay in the current column.
1937 If {curswant} is given it is used to set the preferred column
1938 for vertical movement. Otherwise {col} is used.
1939
1940 When 'virtualedit' is used {off} specifies the offset in
1941 screen columns from the start of the character. E.g., a
1942 position within a <Tab> or after the last character.
1943 Returns 0 when the position could be set, -1 otherwise.
1944
1945 Can also be used as a |method|: >
1946 GetCursorPos()->cursor()
1947
1948debugbreak({pid}) *debugbreak()*
1949 Specifically used to interrupt a program being debugged. It
1950 will cause process {pid} to get a SIGTRAP. Behavior for other
1951 processes is undefined. See |terminal-debugger|.
1952 {only available on MS-Windows}
1953
Bram Moolenaar016188f2022-06-06 20:52:59 +01001954 Returns |TRUE| if successfully interrupted the program.
1955 Otherwise returns |FALSE|.
1956
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001957 Can also be used as a |method|: >
1958 GetPid()->debugbreak()
1959
1960deepcopy({expr} [, {noref}]) *deepcopy()* *E698*
1961 Make a copy of {expr}. For Numbers and Strings this isn't
1962 different from using {expr} directly.
1963 When {expr} is a |List| a full copy is created. This means
1964 that the original |List| can be changed without changing the
1965 copy, and vice versa. When an item is a |List| or
1966 |Dictionary|, a copy for it is made, recursively. Thus
1967 changing an item in the copy does not change the contents of
1968 the original |List|.
1969 A |Dictionary| is copied in a similar way as a |List|.
1970
1971 When {noref} is omitted or zero a contained |List| or
1972 |Dictionary| is only copied once. All references point to
1973 this single copy. With {noref} set to 1 every occurrence of a
1974 |List| or |Dictionary| results in a new copy. This also means
1975 that a cyclic reference causes deepcopy() to fail.
1976 *E724*
1977 Nesting is possible up to 100 levels. When there is an item
1978 that refers back to a higher level making a deep copy with
1979 {noref} set to 1 will fail.
1980 Also see |copy()|.
1981
1982 Can also be used as a |method|: >
1983 GetObject()->deepcopy()
1984
1985delete({fname} [, {flags}]) *delete()*
1986 Without {flags} or with {flags} empty: Deletes the file by the
Bram Moolenaarcbaff5e2022-04-08 17:45:08 +01001987 name {fname}.
1988
1989 This also works when {fname} is a symbolic link. The symbolic
1990 link itself is deleted, not what it points to.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001991
1992 When {flags} is "d": Deletes the directory by the name
1993 {fname}. This fails when directory {fname} is not empty.
1994
1995 When {flags} is "rf": Deletes the directory by the name
1996 {fname} and everything in it, recursively. BE CAREFUL!
1997 Note: on MS-Windows it is not possible to delete a directory
1998 that is being used.
1999
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002000 The result is a Number, which is 0/false if the delete
2001 operation was successful and -1/true when the deletion failed
2002 or partly failed.
2003
2004 Use |remove()| to delete an item from a |List|.
2005 To delete a line from the buffer use |:delete| or
2006 |deletebufline()|.
2007
2008 Can also be used as a |method|: >
2009 GetName()->delete()
2010
2011deletebufline({buf}, {first} [, {last}]) *deletebufline()*
2012 Delete lines {first} to {last} (inclusive) from buffer {buf}.
2013 If {last} is omitted then delete line {first} only.
2014 On success 0 is returned, on failure 1 is returned.
2015
2016 This function works only for loaded buffers. First call
2017 |bufload()| if needed.
2018
2019 For the use of {buf}, see |bufname()| above.
2020
2021 {first} and {last} are used like with |getline()|. Note that
2022 when using |line()| this refers to the current buffer. Use "$"
2023 to refer to the last line in buffer {buf}.
2024
2025 Can also be used as a |method|: >
2026 GetBuffer()->deletebufline(1)
2027<
2028 *did_filetype()*
2029did_filetype() Returns |TRUE| when autocommands are being executed and the
2030 FileType event has been triggered at least once. Can be used
2031 to avoid triggering the FileType event again in the scripts
2032 that detect the file type. |FileType|
2033 Returns |FALSE| when `:setf FALLBACK` was used.
2034 When editing another file, the counter is reset, thus this
2035 really checks if the FileType event has been triggered for the
2036 current buffer. This allows an autocommand that starts
2037 editing another buffer to set 'filetype' and load a syntax
2038 file.
2039
2040diff_filler({lnum}) *diff_filler()*
2041 Returns the number of filler lines above line {lnum}.
2042 These are the lines that were inserted at this point in
2043 another diff'ed window. These filler lines are shown in the
2044 display but don't exist in the buffer.
2045 {lnum} is used like with |getline()|. Thus "." is the current
2046 line, "'m" mark m, etc.
2047 Returns 0 if the current window is not in diff mode.
2048
2049 Can also be used as a |method|: >
2050 GetLnum()->diff_filler()
2051
2052diff_hlID({lnum}, {col}) *diff_hlID()*
2053 Returns the highlight ID for diff mode at line {lnum} column
2054 {col} (byte index). When the current line does not have a
2055 diff change zero is returned.
2056 {lnum} is used like with |getline()|. Thus "." is the current
2057 line, "'m" mark m, etc.
2058 {col} is 1 for the leftmost column, {lnum} is 1 for the first
2059 line.
2060 The highlight ID can be used with |synIDattr()| to obtain
2061 syntax information about the highlighting.
2062
2063 Can also be used as a |method|: >
2064 GetLnum()->diff_hlID(col)
2065<
2066
2067digraph_get({chars}) *digraph_get()* *E1214*
2068 Return the digraph of {chars}. This should be a string with
2069 exactly two characters. If {chars} are not just two
2070 characters, or the digraph of {chars} does not exist, an error
2071 is given and an empty string is returned.
2072
2073 The character will be converted from Unicode to 'encoding'
2074 when needed. This does require the conversion to be
2075 available, it might fail.
2076
2077 Also see |digraph_getlist()|.
2078
2079 Examples: >
2080 " Get a built-in digraph
2081 :echo digraph_get('00') " Returns '∞'
2082
2083 " Get a user-defined digraph
2084 :call digraph_set('aa', 'あ')
2085 :echo digraph_get('aa') " Returns 'あ'
2086<
2087 Can also be used as a |method|: >
2088 GetChars()->digraph_get()
2089<
2090 This function works only when compiled with the |+digraphs|
2091 feature. If this feature is disabled, this function will
2092 display an error message.
2093
2094
2095digraph_getlist([{listall}]) *digraph_getlist()*
2096 Return a list of digraphs. If the {listall} argument is given
2097 and it is TRUE, return all digraphs, including the default
2098 digraphs. Otherwise, return only user-defined digraphs.
2099
2100 The characters will be converted from Unicode to 'encoding'
2101 when needed. This does require the conservation to be
2102 available, it might fail.
2103
2104 Also see |digraph_get()|.
2105
2106 Examples: >
2107 " Get user-defined digraphs
2108 :echo digraph_getlist()
2109
2110 " Get all the digraphs, including default digraphs
2111 :echo digraph_getlist(1)
2112<
2113 Can also be used as a |method|: >
2114 GetNumber()->digraph_getlist()
2115<
2116 This function works only when compiled with the |+digraphs|
2117 feature. If this feature is disabled, this function will
2118 display an error message.
2119
2120
Bram Moolenaara2baa732022-02-04 16:09:54 +00002121digraph_set({chars}, {digraph}) *digraph_set()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002122 Add digraph {chars} to the list. {chars} must be a string
2123 with two characters. {digraph} is a string with one UTF-8
Bram Moolenaara2baa732022-02-04 16:09:54 +00002124 encoded character. *E1215*
2125 Be careful, composing characters are NOT ignored. This
2126 function is similar to |:digraphs| command, but useful to add
2127 digraphs start with a white space.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002128
2129 The function result is v:true if |digraph| is registered. If
2130 this fails an error message is given and v:false is returned.
2131
2132 If you want to define multiple digraphs at once, you can use
2133 |digraph_setlist()|.
2134
2135 Example: >
2136 call digraph_set(' ', 'あ')
2137<
2138 Can be used as a |method|: >
2139 GetString()->digraph_set('あ')
2140<
2141 This function works only when compiled with the |+digraphs|
2142 feature. If this feature is disabled, this function will
2143 display an error message.
2144
2145
2146digraph_setlist({digraphlist}) *digraph_setlist()*
2147 Similar to |digraph_set()| but this function can add multiple
2148 digraphs at once. {digraphlist} is a list composed of lists,
2149 where each list contains two strings with {chars} and
Bram Moolenaara2baa732022-02-04 16:09:54 +00002150 {digraph} as in |digraph_set()|. *E1216*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002151 Example: >
2152 call digraph_setlist([['aa', 'あ'], ['ii', 'い']])
2153<
2154 It is similar to the following: >
2155 for [chars, digraph] in [['aa', 'あ'], ['ii', 'い']]
2156 call digraph_set(chars, digraph)
2157 endfor
2158< Except that the function returns after the first error,
2159 following digraphs will not be added.
2160
2161 Can be used as a |method|: >
2162 GetList()->digraph_setlist()
2163<
2164 This function works only when compiled with the |+digraphs|
2165 feature. If this feature is disabled, this function will
2166 display an error message.
2167
2168
2169echoraw({string}) *echoraw()*
2170 Output {string} as-is, including unprintable characters.
2171 This can be used to output a terminal code. For example, to
2172 disable modifyOtherKeys: >
2173 call echoraw(&t_TE)
2174< and to enable it again: >
2175 call echoraw(&t_TI)
2176< Use with care, you can mess up the terminal this way.
2177
2178
2179empty({expr}) *empty()*
2180 Return the Number 1 if {expr} is empty, zero otherwise.
2181 - A |List| or |Dictionary| is empty when it does not have any
2182 items.
2183 - A |String| is empty when its length is zero.
2184 - A |Number| and |Float| are empty when their value is zero.
2185 - |v:false|, |v:none| and |v:null| are empty, |v:true| is not.
2186 - A |Job| is empty when it failed to start.
2187 - A |Channel| is empty when it is closed.
2188 - A |Blob| is empty when its length is zero.
2189
2190 For a long |List| this is much faster than comparing the
2191 length with zero.
2192
2193 Can also be used as a |method|: >
2194 mylist->empty()
2195
2196environ() *environ()*
2197 Return all of environment variables as dictionary. You can
2198 check if an environment variable exists like this: >
2199 :echo has_key(environ(), 'HOME')
2200< Note that the variable name may be CamelCase; to ignore case
2201 use this: >
2202 :echo index(keys(environ()), 'HOME', 0, 1) != -1
2203
2204escape({string}, {chars}) *escape()*
2205 Escape the characters in {chars} that occur in {string} with a
2206 backslash. Example: >
2207 :echo escape('c:\program files\vim', ' \')
2208< results in: >
2209 c:\\program\ files\\vim
2210< Also see |shellescape()| and |fnameescape()|.
2211
2212 Can also be used as a |method|: >
2213 GetText()->escape(' \')
2214<
2215 *eval()*
2216eval({string}) Evaluate {string} and return the result. Especially useful to
2217 turn the result of |string()| back into the original value.
2218 This works for Numbers, Floats, Strings, Blobs and composites
2219 of them. Also works for |Funcref|s that refer to existing
2220 functions.
2221
2222 Can also be used as a |method|: >
2223 argv->join()->eval()
2224
2225eventhandler() *eventhandler()*
2226 Returns 1 when inside an event handler. That is that Vim got
2227 interrupted while waiting for the user to type a character,
2228 e.g., when dropping a file on Vim. This means interactive
2229 commands cannot be used. Otherwise zero is returned.
2230
2231executable({expr}) *executable()*
2232 This function checks if an executable with the name {expr}
2233 exists. {expr} must be the name of the program without any
2234 arguments.
2235 executable() uses the value of $PATH and/or the normal
2236 searchpath for programs. *PATHEXT*
2237 On MS-Windows the ".exe", ".bat", etc. can optionally be
2238 included. Then the extensions in $PATHEXT are tried. Thus if
2239 "foo.exe" does not exist, "foo.exe.bat" can be found. If
2240 $PATHEXT is not set then ".com;.exe;.bat;.cmd" is used. A dot
2241 by itself can be used in $PATHEXT to try using the name
2242 without an extension. When 'shell' looks like a Unix shell,
2243 then the name is also tried without adding an extension.
2244 On MS-Windows it only checks if the file exists and is not a
2245 directory, not if it's really executable.
2246 On MS-Windows an executable in the same directory as Vim is
Yasuhiro Matsumoto05cf63e2022-05-03 11:02:28 +01002247 normally found. Since this directory is added to $PATH it
2248 should also work to execute it |win32-PATH|. This can be
2249 disabled by setting the $NoDefaultCurrentDirectoryInExePath
2250 environment variable. *NoDefaultCurrentDirectoryInExePath*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002251 The result is a Number:
2252 1 exists
2253 0 does not exist
2254 -1 not implemented on this system
2255 |exepath()| can be used to get the full path of an executable.
2256
2257 Can also be used as a |method|: >
2258 GetCommand()->executable()
2259
2260execute({command} [, {silent}]) *execute()*
2261 Execute an Ex command or commands and return the output as a
2262 string.
2263 {command} can be a string or a List. In case of a List the
2264 lines are executed one by one.
Bram Moolenaarb7398fe2023-05-14 18:50:25 +01002265 This is more or less equivalent to: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002266 redir => var
2267 {command}
2268 redir END
Bram Moolenaar71badf92023-04-22 22:40:14 +01002269< Except that line continuation in {command} is not recognized.
2270
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002271 The optional {silent} argument can have these values:
2272 "" no `:silent` used
2273 "silent" `:silent` used
2274 "silent!" `:silent!` used
2275 The default is "silent". Note that with "silent!", unlike
2276 `:redir`, error messages are dropped. When using an external
2277 command the screen may be messed up, use `system()` instead.
2278 *E930*
2279 It is not possible to use `:redir` anywhere in {command}.
2280
Bram Moolenaarb7398fe2023-05-14 18:50:25 +01002281 To get a list of lines use `split()` on the result: >
Bram Moolenaar75ab5902022-04-18 15:36:40 +01002282 execute('args')->split("\n")
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002283
2284< To execute a command in another window than the current one
2285 use `win_execute()`.
2286
2287 When used recursively the output of the recursive call is not
2288 included in the output of the higher level call.
2289
2290 Can also be used as a |method|: >
2291 GetCommand()->execute()
2292
2293exepath({expr}) *exepath()*
2294 If {expr} is an executable and is either an absolute path, a
2295 relative path or found in $PATH, return the full path.
2296 Note that the current directory is used when {expr} starts
2297 with "./", which may be a problem for Vim: >
2298 echo exepath(v:progpath)
2299< If {expr} cannot be found in $PATH or is not executable then
2300 an empty string is returned.
2301
2302 Can also be used as a |method|: >
2303 GetCommand()->exepath()
2304<
2305 *exists()*
2306exists({expr}) The result is a Number, which is |TRUE| if {expr} is defined,
2307 zero otherwise.
2308
2309 Note: In a compiled |:def| function the evaluation is done at
2310 runtime. Use `exists_compiled()` to evaluate the expression
2311 at compile time.
2312
2313 For checking for a supported feature use |has()|.
2314 For checking if a file exists use |filereadable()|.
2315
2316 The {expr} argument is a string, which contains one of these:
Bram Moolenaarf10911e2022-01-29 22:20:48 +00002317 varname internal variable (see
2318 dict.key |internal-variables|). Also works
2319 list[i] for |curly-braces-names|, |Dictionary|
2320 import.Func entries, |List| items, imported
Bram Moolenaar944697a2022-02-20 19:48:20 +00002321 items, etc.
Bram Moolenaarf10911e2022-01-29 22:20:48 +00002322 Does not work for local variables in a
2323 compiled `:def` function.
Bram Moolenaar944697a2022-02-20 19:48:20 +00002324 Also works for a function in |Vim9|
2325 script, since it can be used as a
2326 function reference.
Bram Moolenaarf10911e2022-01-29 22:20:48 +00002327 Beware that evaluating an index may
2328 cause an error message for an invalid
2329 expression. E.g.: >
2330 :let l = [1, 2, 3]
2331 :echo exists("l[5]")
2332< 0 >
2333 :echo exists("l[xx]")
2334< E121: Undefined variable: xx
2335 0
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002336 &option-name Vim option (only checks if it exists,
2337 not if it really works)
2338 +option-name Vim option that works.
2339 $ENVNAME environment variable (could also be
2340 done by comparing with an empty
2341 string)
2342 *funcname built-in function (see |functions|)
2343 or user defined function (see
2344 |user-functions|) that is implemented.
2345 Also works for a variable that is a
2346 Funcref.
2347 ?funcname built-in function that could be
2348 implemented; to be used to check if
2349 "funcname" is valid
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002350 :cmdname Ex command: built-in command, user
2351 command or command modifier |:command|.
2352 Returns:
2353 1 for match with start of a command
2354 2 full match with a command
2355 3 matches several user commands
2356 To check for a supported command
2357 always check the return value to be 2.
2358 :2match The |:2match| command.
Bram Moolenaarb529cfb2022-07-25 15:42:07 +01002359 :3match The |:3match| command (but you
2360 probably should not use it, it is
2361 reserved for internal usage)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002362 #event autocommand defined for this event
2363 #event#pattern autocommand defined for this event and
2364 pattern (the pattern is taken
2365 literally and compared to the
2366 autocommand patterns character by
2367 character)
2368 #group autocommand group exists
2369 #group#event autocommand defined for this group and
2370 event.
2371 #group#event#pattern
2372 autocommand defined for this group,
2373 event and pattern.
2374 ##event autocommand for this event is
2375 supported.
2376
2377 Examples: >
2378 exists("&shortname")
2379 exists("$HOSTNAME")
2380 exists("*strftime")
Bram Moolenaar944697a2022-02-20 19:48:20 +00002381 exists("*s:MyFunc") " only for legacy script
2382 exists("*MyFunc")
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002383 exists("bufcount")
2384 exists(":Make")
2385 exists("#CursorHold")
2386 exists("#BufReadPre#*.gz")
2387 exists("#filetypeindent")
2388 exists("#filetypeindent#FileType")
2389 exists("#filetypeindent#FileType#*")
2390 exists("##ColorScheme")
2391< There must be no space between the symbol (&/$/*/#) and the
2392 name.
2393 There must be no extra characters after the name, although in
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01002394 a few cases this is ignored. That may become stricter in the
2395 future, thus don't count on it!
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002396 Working example: >
2397 exists(":make")
2398< NOT working example: >
2399 exists(":make install")
2400
2401< Note that the argument must be a string, not the name of the
2402 variable itself. For example: >
2403 exists(bufcount)
2404< This doesn't check for existence of the "bufcount" variable,
2405 but gets the value of "bufcount", and checks if that exists.
2406
2407 Can also be used as a |method|: >
2408 Varname()->exists()
2409<
2410
2411exists_compiled({expr}) *exists_compiled()*
2412 Like `exists()` but evaluated at compile time. This is useful
2413 to skip a block where a function is used that would otherwise
2414 give an error: >
2415 if exists_compiled('*ThatFunction')
2416 ThatFunction('works')
2417 endif
2418< If `exists()` were used then a compilation error would be
2419 given if ThatFunction() is not defined.
2420
2421 {expr} must be a literal string. *E1232*
2422 Can only be used in a |:def| function. *E1233*
2423 This does not work to check for arguments or local variables.
2424
2425
2426exp({expr}) *exp()*
2427 Return the exponential of {expr} as a |Float| in the range
2428 [0, inf].
2429 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar016188f2022-06-06 20:52:59 +01002430 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002431 Examples: >
2432 :echo exp(2)
2433< 7.389056 >
2434 :echo exp(-1)
2435< 0.367879
2436
2437 Can also be used as a |method|: >
2438 Compute()->exp()
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002439
2440
2441expand({string} [, {nosuf} [, {list}]]) *expand()*
2442 Expand wildcards and the following special keywords in
2443 {string}. 'wildignorecase' applies.
2444
2445 If {list} is given and it is |TRUE|, a List will be returned.
2446 Otherwise the result is a String and when there are several
2447 matches, they are separated by <NL> characters. [Note: in
2448 version 5.0 a space was used, which caused problems when a
2449 file name contains a space]
2450
2451 If the expansion fails, the result is an empty string. A name
2452 for a non-existing file is not included, unless {string} does
2453 not start with '%', '#' or '<', see below.
2454
2455 When {string} starts with '%', '#' or '<', the expansion is
2456 done like for the |cmdline-special| variables with their
2457 associated modifiers. Here is a short overview:
2458
2459 % current file name
2460 # alternate file name
2461 #n alternate file name n
2462 <cfile> file name under the cursor
2463 <afile> autocmd file name
2464 <abuf> autocmd buffer number (as a String!)
2465 <amatch> autocmd matched name
2466 <cexpr> C expression under the cursor
2467 <sfile> sourced script file or function name
2468 <slnum> sourced script line number or function
2469 line number
2470 <sflnum> script file line number, also when in
2471 a function
2472 <SID> "<SNR>123_" where "123" is the
2473 current script ID |<SID>|
Bram Moolenaar75ab5902022-04-18 15:36:40 +01002474 <script> sourced script file, or script file
2475 where the current function was defined
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002476 <stack> call stack
2477 <cword> word under the cursor
2478 <cWORD> WORD under the cursor
2479 <client> the {clientid} of the last received
2480 message |server2client()|
2481 Modifiers:
2482 :p expand to full path
2483 :h head (last path component removed)
2484 :t tail (last path component only)
2485 :r root (one extension removed)
2486 :e extension only
2487
2488 Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00002489 :let &tags = expand("%:p:h") .. "/tags"
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002490< Note that when expanding a string that starts with '%', '#' or
2491 '<', any following text is ignored. This does NOT work: >
2492 :let doesntwork = expand("%:h.bak")
2493< Use this: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00002494 :let doeswork = expand("%:h") .. ".bak"
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002495< Also note that expanding "<cfile>" and others only returns the
2496 referenced file name without further expansion. If "<cfile>"
2497 is "~/.cshrc", you need to do another expand() to have the
2498 "~/" expanded into the path of the home directory: >
2499 :echo expand(expand("<cfile>"))
2500<
2501 There cannot be white space between the variables and the
2502 following modifier. The |fnamemodify()| function can be used
2503 to modify normal file names.
2504
2505 When using '%' or '#', and the current or alternate file name
2506 is not defined, an empty string is used. Using "%:p" in a
2507 buffer with no name, results in the current directory, with a
2508 '/' added.
Bram Moolenaar57544522022-04-12 12:54:11 +01002509 When 'verbose' is set then expanding '%', '#' and <> items
2510 will result in an error message if the argument cannot be
2511 expanded.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002512
2513 When {string} does not start with '%', '#' or '<', it is
2514 expanded like a file name is expanded on the command line.
2515 'suffixes' and 'wildignore' are used, unless the optional
2516 {nosuf} argument is given and it is |TRUE|.
2517 Names for non-existing files are included. The "**" item can
2518 be used to search in a directory tree. For example, to find
2519 all "README" files in the current directory and below: >
2520 :echo expand("**/README")
2521<
2522 expand() can also be used to expand variables and environment
2523 variables that are only known in a shell. But this can be
2524 slow, because a shell may be used to do the expansion. See
2525 |expr-env-expand|.
2526 The expanded variable is still handled like a list of file
2527 names. When an environment variable cannot be expanded, it is
2528 left unchanged. Thus ":echo expand('$FOOBAR')" results in
2529 "$FOOBAR".
2530
2531 See |glob()| for finding existing files. See |system()| for
2532 getting the raw output of an external command.
2533
2534 Can also be used as a |method|: >
2535 Getpattern()->expand()
2536
Yegappan Lakshmanan2b74b682022-04-03 21:30:32 +01002537expandcmd({string} [, {options}]) *expandcmd()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002538 Expand special items in String {string} like what is done for
2539 an Ex command such as `:edit`. This expands special keywords,
2540 like with |expand()|, and environment variables, anywhere in
2541 {string}. "~user" and "~/path" are only expanded at the
2542 start.
Yegappan Lakshmanan2b74b682022-04-03 21:30:32 +01002543
2544 The following items are supported in the {options} Dict
2545 argument:
2546 errmsg If set to TRUE, error messages are displayed
2547 if an error is encountered during expansion.
2548 By default, error messages are not displayed.
2549
Yegappan Lakshmanan5018a832022-04-02 21:12:21 +01002550 Returns the expanded string. If an error is encountered
2551 during expansion, the unmodified {string} is returned.
Yegappan Lakshmanan2b74b682022-04-03 21:30:32 +01002552
Yegappan Lakshmanan5018a832022-04-02 21:12:21 +01002553 Example: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002554 :echo expandcmd('make %<.o')
Yegappan Lakshmanan2b74b682022-04-03 21:30:32 +01002555 make /path/runtime/doc/builtin.o
2556 :echo expandcmd('make %<.o', {'errmsg': v:true})
2557<
Yegappan Lakshmanan5018a832022-04-02 21:12:21 +01002558 Can also be used as a |method|: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002559 GetCommand()->expandcmd()
2560<
2561extend({expr1}, {expr2} [, {expr3}]) *extend()*
2562 {expr1} and {expr2} must be both |Lists| or both
2563 |Dictionaries|.
2564
2565 If they are |Lists|: Append {expr2} to {expr1}.
2566 If {expr3} is given insert the items of {expr2} before the
2567 item with index {expr3} in {expr1}. When {expr3} is zero
2568 insert before the first item. When {expr3} is equal to
2569 len({expr1}) then {expr2} is appended.
2570 Examples: >
2571 :echo sort(extend(mylist, [7, 5]))
2572 :call extend(mylist, [2, 3], 1)
2573< When {expr1} is the same List as {expr2} then the number of
2574 items copied is equal to the original length of the List.
2575 E.g., when {expr3} is 1 you get N new copies of the first item
2576 (where N is the original length of the List).
2577 Use |add()| to concatenate one item to a list. To concatenate
2578 two lists into a new list use the + operator: >
2579 :let newlist = [1, 2, 3] + [4, 5]
2580<
2581 If they are |Dictionaries|:
2582 Add all entries from {expr2} to {expr1}.
2583 If a key exists in both {expr1} and {expr2} then {expr3} is
2584 used to decide what to do:
2585 {expr3} = "keep": keep the value of {expr1}
2586 {expr3} = "force": use the value of {expr2}
2587 {expr3} = "error": give an error message *E737*
2588 When {expr3} is omitted then "force" is assumed.
2589
2590 {expr1} is changed when {expr2} is not empty. If necessary
2591 make a copy of {expr1} first.
2592 {expr2} remains unchanged.
2593 When {expr1} is locked and {expr2} is not empty the operation
2594 fails.
Bram Moolenaar016188f2022-06-06 20:52:59 +01002595 Returns {expr1}. Returns 0 on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002596
2597 Can also be used as a |method|: >
2598 mylist->extend(otherlist)
2599
2600
2601extendnew({expr1}, {expr2} [, {expr3}]) *extendnew()*
2602 Like |extend()| but instead of adding items to {expr1} a new
2603 List or Dictionary is created and returned. {expr1} remains
Bram Moolenaardd60c362023-02-27 15:49:53 +00002604 unchanged.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002605
2606
2607feedkeys({string} [, {mode}]) *feedkeys()*
2608 Characters in {string} are queued for processing as if they
2609 come from a mapping or were typed by the user.
2610
2611 By default the string is added to the end of the typeahead
2612 buffer, thus if a mapping is still being executed the
2613 characters come after them. Use the 'i' flag to insert before
2614 other characters, they will be executed next, before any
2615 characters from a mapping.
2616
2617 The function does not wait for processing of keys contained in
2618 {string}.
2619
2620 To include special keys into {string}, use double-quotes
2621 and "\..." notation |expr-quote|. For example,
2622 feedkeys("\<CR>") simulates pressing of the <Enter> key. But
2623 feedkeys('\<CR>') pushes 5 characters.
2624 A special code that might be useful is <Ignore>, it exits the
2625 wait for a character without doing anything. *<Ignore>*
2626
2627 {mode} is a String, which can contain these character flags:
2628 'm' Remap keys. This is default. If {mode} is absent,
2629 keys are remapped.
2630 'n' Do not remap keys.
2631 't' Handle keys as if typed; otherwise they are handled as
2632 if coming from a mapping. This matters for undo,
2633 opening folds, etc.
2634 'L' Lowlevel input. Only works for Unix or when using the
2635 GUI. Keys are used as if they were coming from the
2636 terminal. Other flags are not used. *E980*
2637 When a CTRL-C interrupts and 't' is included it sets
2638 the internal "got_int" flag.
2639 'i' Insert the string instead of appending (see above).
2640 'x' Execute commands until typeahead is empty. This is
2641 similar to using ":normal!". You can call feedkeys()
2642 several times without 'x' and then one time with 'x'
2643 (possibly with an empty {string}) to execute all the
2644 typeahead. Note that when Vim ends in Insert mode it
2645 will behave as if <Esc> is typed, to avoid getting
2646 stuck, waiting for a character to be typed before the
2647 script continues.
2648 Note that if you manage to call feedkeys() while
2649 executing commands, thus calling it recursively, then
2650 all typeahead will be consumed by the last call.
Bram Moolenaara9725222022-01-16 13:30:33 +00002651 'c' Remove any script context when executing, so that
2652 legacy script syntax applies, "s:var" does not work,
Bram Moolenaard899e512022-05-07 21:54:03 +01002653 etc. Note that if the string being fed sets a script
Bram Moolenaarce001a32022-04-27 15:25:03 +01002654 context this still applies.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002655 '!' When used with 'x' will not end Insert mode. Can be
2656 used in a test when a timer is set to exit Insert mode
2657 a little later. Useful for testing CursorHoldI.
2658
2659 Return value is always 0.
2660
2661 Can also be used as a |method|: >
2662 GetInput()->feedkeys()
2663
2664filereadable({file}) *filereadable()*
2665 The result is a Number, which is |TRUE| when a file with the
2666 name {file} exists, and can be read. If {file} doesn't exist,
2667 or is a directory, the result is |FALSE|. {file} is any
2668 expression, which is used as a String.
2669 If you don't care about the file being readable you can use
2670 |glob()|.
2671 {file} is used as-is, you may want to expand wildcards first: >
2672 echo filereadable('~/.vimrc')
2673 0
2674 echo filereadable(expand('~/.vimrc'))
2675 1
2676
2677< Can also be used as a |method|: >
2678 GetName()->filereadable()
2679< *file_readable()*
2680 Obsolete name: file_readable().
2681
2682
2683filewritable({file}) *filewritable()*
2684 The result is a Number, which is 1 when a file with the
2685 name {file} exists, and can be written. If {file} doesn't
2686 exist, or is not writable, the result is 0. If {file} is a
2687 directory, and we can write to it, the result is 2.
2688
2689 Can also be used as a |method|: >
2690 GetName()->filewritable()
2691
2692
2693filter({expr1}, {expr2}) *filter()*
2694 {expr1} must be a |List|, |String|, |Blob| or |Dictionary|.
2695 For each item in {expr1} evaluate {expr2} and when the result
2696 is zero or false remove the item from the |List| or
2697 |Dictionary|. Similarly for each byte in a |Blob| and each
Bram Moolenaar2f0936c2022-01-08 21:51:59 +00002698 character in a |String|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002699
2700 {expr2} must be a |string| or |Funcref|.
2701
2702 If {expr2} is a |string|, inside {expr2} |v:val| has the value
2703 of the current item. For a |Dictionary| |v:key| has the key
2704 of the current item and for a |List| |v:key| has the index of
2705 the current item. For a |Blob| |v:key| has the index of the
2706 current byte. For a |String| |v:key| has the index of the
2707 current character.
2708 Examples: >
2709 call filter(mylist, 'v:val !~ "OLD"')
2710< Removes the items where "OLD" appears. >
2711 call filter(mydict, 'v:key >= 8')
2712< Removes the items with a key below 8. >
2713 call filter(var, 0)
2714< Removes all the items, thus clears the |List| or |Dictionary|.
2715
2716 Note that {expr2} is the result of expression and is then
2717 used as an expression again. Often it is good to use a
2718 |literal-string| to avoid having to double backslashes.
2719
2720 If {expr2} is a |Funcref| it must take two arguments:
2721 1. the key or the index of the current item.
2722 2. the value of the current item.
2723 The function must return |TRUE| if the item should be kept.
2724 Example that keeps the odd items of a list: >
2725 func Odd(idx, val)
2726 return a:idx % 2 == 1
2727 endfunc
2728 call filter(mylist, function('Odd'))
Bram Moolenaar2f0936c2022-01-08 21:51:59 +00002729< It is shorter when using a |lambda|. In |Vim9| syntax: >
2730 call filter(myList, (idx, val) => idx * val <= 42)
2731< In legacy script syntax: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002732 call filter(myList, {idx, val -> idx * val <= 42})
2733< If you do not use "val" you can leave it out: >
2734 call filter(myList, {idx -> idx % 2 == 1})
2735<
2736 In |Vim9| script the result must be true, false, zero or one.
2737 Other values will result in a type error.
2738
2739 For a |List| and a |Dictionary| the operation is done
2740 in-place. If you want it to remain unmodified make a copy
2741 first: >
2742 :let l = filter(copy(mylist), 'v:val =~ "KEEP"')
2743
2744< Returns {expr1}, the |List| or |Dictionary| that was filtered,
naohiro ono56200ee2022-01-01 14:59:44 +00002745 or a new |Blob| or |String|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002746 When an error is encountered while evaluating {expr2} no
2747 further items in {expr1} are processed.
2748 When {expr2} is a Funcref errors inside a function are ignored,
2749 unless it was defined with the "abort" flag.
2750
2751 Can also be used as a |method|: >
2752 mylist->filter(expr2)
2753
2754finddir({name} [, {path} [, {count}]]) *finddir()*
2755 Find directory {name} in {path}. Supports both downwards and
2756 upwards recursive directory searches. See |file-searching|
2757 for the syntax of {path}.
2758
2759 Returns the path of the first found match. When the found
2760 directory is below the current directory a relative path is
2761 returned. Otherwise a full path is returned.
2762 If {path} is omitted or empty then 'path' is used.
2763
2764 If the optional {count} is given, find {count}'s occurrence of
2765 {name} in {path} instead of the first one.
2766 When {count} is negative return all the matches in a |List|.
2767
Bram Moolenaar016188f2022-06-06 20:52:59 +01002768 Returns an empty string if the directory is not found.
2769
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002770 This is quite similar to the ex-command `:find`.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002771
2772 Can also be used as a |method|: >
2773 GetName()->finddir()
2774
2775findfile({name} [, {path} [, {count}]]) *findfile()*
2776 Just like |finddir()|, but find a file instead of a directory.
2777 Uses 'suffixesadd'.
2778 Example: >
2779 :echo findfile("tags.vim", ".;")
2780< Searches from the directory of the current file upwards until
2781 it finds the file "tags.vim".
2782
2783 Can also be used as a |method|: >
2784 GetName()->findfile()
2785
2786flatten({list} [, {maxdepth}]) *flatten()*
2787 Flatten {list} up to {maxdepth} levels. Without {maxdepth}
2788 the result is a |List| without nesting, as if {maxdepth} is
2789 a very large number.
2790 The {list} is changed in place, use |flattennew()| if you do
2791 not want that.
2792 In Vim9 script flatten() cannot be used, you must always use
Bram Moolenaara2baa732022-02-04 16:09:54 +00002793 |flattennew()|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002794 *E900*
2795 {maxdepth} means how deep in nested lists changes are made.
2796 {list} is not modified when {maxdepth} is 0.
2797 {maxdepth} must be positive number.
2798
2799 If there is an error the number zero is returned.
2800
2801 Example: >
2802 :echo flatten([1, [2, [3, 4]], 5])
2803< [1, 2, 3, 4, 5] >
2804 :echo flatten([1, [2, [3, 4]], 5], 1)
2805< [1, 2, [3, 4], 5]
2806
2807 Can also be used as a |method|: >
2808 mylist->flatten()
2809<
2810flattennew({list} [, {maxdepth}]) *flattennew()*
2811 Like |flatten()| but first make a copy of {list}.
2812
2813
2814float2nr({expr}) *float2nr()*
2815 Convert {expr} to a Number by omitting the part after the
2816 decimal point.
Bram Moolenaar76db9e02022-11-09 21:21:04 +00002817 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar016188f2022-06-06 20:52:59 +01002818 Returns 0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002819 When the value of {expr} is out of range for a |Number| the
2820 result is truncated to 0x7fffffff or -0x7fffffff (or when
2821 64-bit Number support is enabled, 0x7fffffffffffffff or
2822 -0x7fffffffffffffff). NaN results in -0x80000000 (or when
2823 64-bit Number support is enabled, -0x8000000000000000).
2824 Examples: >
2825 echo float2nr(3.95)
2826< 3 >
2827 echo float2nr(-23.45)
2828< -23 >
2829 echo float2nr(1.0e100)
2830< 2147483647 (or 9223372036854775807) >
2831 echo float2nr(-1.0e150)
2832< -2147483647 (or -9223372036854775807) >
2833 echo float2nr(1.0e-100)
2834< 0
2835
2836 Can also be used as a |method|: >
2837 Compute()->float2nr()
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002838
2839
2840floor({expr}) *floor()*
2841 Return the largest integral value less than or equal to
2842 {expr} as a |Float| (round down).
2843 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar016188f2022-06-06 20:52:59 +01002844 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002845 Examples: >
2846 echo floor(1.856)
2847< 1.0 >
2848 echo floor(-5.456)
2849< -6.0 >
2850 echo floor(4.0)
2851< 4.0
2852
2853 Can also be used as a |method|: >
2854 Compute()->floor()
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002855
2856
2857fmod({expr1}, {expr2}) *fmod()*
2858 Return the remainder of {expr1} / {expr2}, even if the
2859 division is not representable. Returns {expr1} - i * {expr2}
2860 for some integer i such that if {expr2} is non-zero, the
2861 result has the same sign as {expr1} and magnitude less than
2862 the magnitude of {expr2}. If {expr2} is zero, the value
2863 returned is zero. The value returned is a |Float|.
2864 {expr1} and {expr2} must evaluate to a |Float| or a |Number|.
Bram Moolenaar016188f2022-06-06 20:52:59 +01002865 Returns 0.0 if {expr1} or {expr2} is not a |Float| or a
2866 |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002867 Examples: >
2868 :echo fmod(12.33, 1.22)
2869< 0.13 >
2870 :echo fmod(-12.33, 1.22)
2871< -0.13
2872
2873 Can also be used as a |method|: >
2874 Compute()->fmod(1.22)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002875
2876
2877fnameescape({string}) *fnameescape()*
2878 Escape {string} for use as file name command argument. All
2879 characters that have a special meaning, such as '%' and '|'
2880 are escaped with a backslash.
2881 For most systems the characters escaped are
2882 " \t\n*?[{`$\\%#'\"|!<". For systems where a backslash
2883 appears in a filename, it depends on the value of 'isfname'.
2884 A leading '+' and '>' is also escaped (special after |:edit|
2885 and |:write|). And a "-" by itself (special after |:cd|).
Bram Moolenaar016188f2022-06-06 20:52:59 +01002886 Returns an empty string on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002887 Example: >
2888 :let fname = '+some str%nge|name'
Bram Moolenaarc51cf032022-02-26 12:25:45 +00002889 :exe "edit " .. fnameescape(fname)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002890< results in executing: >
2891 edit \+some\ str\%nge\|name
2892<
2893 Can also be used as a |method|: >
2894 GetName()->fnameescape()
2895
2896fnamemodify({fname}, {mods}) *fnamemodify()*
2897 Modify file name {fname} according to {mods}. {mods} is a
2898 string of characters like it is used for file names on the
2899 command line. See |filename-modifiers|.
2900 Example: >
2901 :echo fnamemodify("main.c", ":p:h")
2902< results in: >
Bram Moolenaard799daa2022-06-20 11:17:32 +01002903 /home/user/vim/vim/src
Bram Moolenaar016188f2022-06-06 20:52:59 +01002904< If {mods} is empty or an unsupported modifier is used then
2905 {fname} is returned.
Bram Moolenaar5ed11532022-07-06 13:18:11 +01002906 When {fname} is empty then with {mods} ":h" returns ".", so
2907 that `:cd` can be used with it. This is different from
2908 expand('%:h') without a buffer name, which returns an empty
2909 string.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002910 Note: Environment variables don't work in {fname}, use
2911 |expand()| first then.
2912
2913 Can also be used as a |method|: >
2914 GetName()->fnamemodify(':p:h')
2915
2916foldclosed({lnum}) *foldclosed()*
2917 The result is a Number. If the line {lnum} is in a closed
2918 fold, the result is the number of the first line in that fold.
2919 If the line {lnum} is not in a closed fold, -1 is returned.
2920 {lnum} is used like with |getline()|. Thus "." is the current
2921 line, "'m" mark m, etc.
2922
2923 Can also be used as a |method|: >
2924 GetLnum()->foldclosed()
2925
2926foldclosedend({lnum}) *foldclosedend()*
2927 The result is a Number. If the line {lnum} is in a closed
2928 fold, the result is the number of the last line in that fold.
2929 If the line {lnum} is not in a closed fold, -1 is returned.
2930 {lnum} is used like with |getline()|. Thus "." is the current
2931 line, "'m" mark m, etc.
2932
2933 Can also be used as a |method|: >
2934 GetLnum()->foldclosedend()
2935
2936foldlevel({lnum}) *foldlevel()*
2937 The result is a Number, which is the foldlevel of line {lnum}
2938 in the current buffer. For nested folds the deepest level is
2939 returned. If there is no fold at line {lnum}, zero is
2940 returned. It doesn't matter if the folds are open or closed.
2941 When used while updating folds (from 'foldexpr') -1 is
2942 returned for lines where folds are still to be updated and the
2943 foldlevel is unknown. As a special case the level of the
2944 previous line is usually available.
2945 {lnum} is used like with |getline()|. Thus "." is the current
2946 line, "'m" mark m, etc.
2947
2948 Can also be used as a |method|: >
2949 GetLnum()->foldlevel()
2950<
2951 *foldtext()*
2952foldtext() Returns a String, to be displayed for a closed fold. This is
2953 the default function used for the 'foldtext' option and should
2954 only be called from evaluating 'foldtext'. It uses the
2955 |v:foldstart|, |v:foldend| and |v:folddashes| variables.
2956 The returned string looks like this: >
2957 +-- 45 lines: abcdef
2958< The number of leading dashes depends on the foldlevel. The
2959 "45" is the number of lines in the fold. "abcdef" is the text
2960 in the first non-blank line of the fold. Leading white space,
2961 "//" or "/*" and the text from the 'foldmarker' and
2962 'commentstring' options is removed.
2963 When used to draw the actual foldtext, the rest of the line
2964 will be filled with the fold char from the 'fillchars'
2965 setting.
Bram Moolenaar016188f2022-06-06 20:52:59 +01002966 Returns an empty string when there is no fold.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002967 {not available when compiled without the |+folding| feature}
2968
2969foldtextresult({lnum}) *foldtextresult()*
2970 Returns the text that is displayed for the closed fold at line
2971 {lnum}. Evaluates 'foldtext' in the appropriate context.
2972 When there is no closed fold at {lnum} an empty string is
2973 returned.
2974 {lnum} is used like with |getline()|. Thus "." is the current
2975 line, "'m" mark m, etc.
2976 Useful when exporting folded text, e.g., to HTML.
2977 {not available when compiled without the |+folding| feature}
2978
2979
2980 Can also be used as a |method|: >
2981 GetLnum()->foldtextresult()
2982<
2983 *foreground()*
2984foreground() Move the Vim window to the foreground. Useful when sent from
2985 a client to a Vim server. |remote_send()|
2986 On Win32 systems this might not work, the OS does not always
2987 allow a window to bring itself to the foreground. Use
2988 |remote_foreground()| instead.
Bram Moolenaarcbaff5e2022-04-08 17:45:08 +01002989 {only in the Win32, Motif and GTK GUI versions and the
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002990 Win32 console version}
2991
Bram Moolenaaraa534142022-09-15 21:46:02 +01002992fullcommand({name} [, {vim9}]) *fullcommand()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002993 Get the full command name from a short abbreviated command
2994 name; see |20.2| for details on command abbreviations.
2995
2996 The string argument {name} may start with a `:` and can
2997 include a [range], these are skipped and not returned.
Bram Moolenaaraa534142022-09-15 21:46:02 +01002998 Returns an empty string if a command doesn't exist, if it's
2999 ambiguous (for user-defined commands) or cannot be shortened
3000 this way. |vim9-no-shorten|
3001
3002 Without the {vim9} argument uses the current script version.
3003 If {vim9} is present and FALSE then legacy script rules are
3004 used. When {vim9} is present and TRUE then Vim9 rules are
3005 used, e.g. "en" is not a short form of "endif".
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003006
3007 For example `fullcommand('s')`, `fullcommand('sub')`,
3008 `fullcommand(':%substitute')` all return "substitute".
3009
3010 Can also be used as a |method|: >
3011 GetName()->fullcommand()
3012<
3013 *funcref()*
3014funcref({name} [, {arglist}] [, {dict}])
3015 Just like |function()|, but the returned Funcref will lookup
3016 the function by reference, not by name. This matters when the
3017 function {name} is redefined later.
3018
3019 Unlike |function()|, {name} must be an existing user function.
Bram Moolenaar2f0936c2022-01-08 21:51:59 +00003020 It only works for an autoloaded function if it has already
3021 been loaded (to avoid mistakenly loading the autoload script
3022 when only intending to use the function name, use |function()|
3023 instead). {name} cannot be a builtin function.
Bram Moolenaar016188f2022-06-06 20:52:59 +01003024 Returns 0 on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003025
3026 Can also be used as a |method|: >
3027 GetFuncname()->funcref([arg])
3028<
Dominique Pellee764d1b2023-03-12 21:20:59 +00003029 *function()* *partial* *E700* *E923*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003030function({name} [, {arglist}] [, {dict}])
3031 Return a |Funcref| variable that refers to function {name}.
3032 {name} can be the name of a user defined function or an
3033 internal function.
3034
3035 {name} can also be a Funcref or a partial. When it is a
3036 partial the dict stored in it will be used and the {dict}
3037 argument is not allowed. E.g.: >
3038 let FuncWithArg = function(dict.Func, [arg])
3039 let Broken = function(dict.Func, [arg], dict)
3040<
3041 When using the Funcref the function will be found by {name},
3042 also when it was redefined later. Use |funcref()| to keep the
3043 same function.
3044
3045 When {arglist} or {dict} is present this creates a partial.
3046 That means the argument list and/or the dictionary is stored in
3047 the Funcref and will be used when the Funcref is called.
3048
3049 The arguments are passed to the function in front of other
3050 arguments, but after any argument from |method|. Example: >
3051 func Callback(arg1, arg2, name)
3052 ...
3053 let Partial = function('Callback', ['one', 'two'])
3054 ...
3055 call Partial('name')
3056< Invokes the function as with: >
3057 call Callback('one', 'two', 'name')
3058
3059< With a |method|: >
3060 func Callback(one, two, three)
3061 ...
3062 let Partial = function('Callback', ['two'])
3063 ...
3064 eval 'one'->Partial('three')
3065< Invokes the function as with: >
3066 call Callback('one', 'two', 'three')
3067
3068< The function() call can be nested to add more arguments to the
3069 Funcref. The extra arguments are appended to the list of
3070 arguments. Example: >
3071 func Callback(arg1, arg2, name)
Bram Moolenaar0daafaa2022-09-04 17:45:43 +01003072 "...
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003073 let Func = function('Callback', ['one'])
3074 let Func2 = function(Func, ['two'])
Bram Moolenaar0daafaa2022-09-04 17:45:43 +01003075 "...
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003076 call Func2('name')
3077< Invokes the function as with: >
3078 call Callback('one', 'two', 'name')
3079
3080< The Dictionary is only useful when calling a "dict" function.
3081 In that case the {dict} is passed in as "self". Example: >
3082 function Callback() dict
Bram Moolenaarc51cf032022-02-26 12:25:45 +00003083 echo "called for " .. self.name
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003084 endfunction
Bram Moolenaar0daafaa2022-09-04 17:45:43 +01003085 "...
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003086 let context = {"name": "example"}
3087 let Func = function('Callback', context)
Bram Moolenaar0daafaa2022-09-04 17:45:43 +01003088 "...
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003089 call Func() " will echo: called for example
3090< The use of function() is not needed when there are no extra
Bram Moolenaar0daafaa2022-09-04 17:45:43 +01003091 arguments, these two are equivalent, if Callback() is defined
3092 as context.Callback(): >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003093 let Func = function('Callback', context)
3094 let Func = context.Callback
3095
3096< The argument list and the Dictionary can be combined: >
3097 function Callback(arg1, count) dict
Bram Moolenaar0daafaa2022-09-04 17:45:43 +01003098 "...
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003099 let context = {"name": "example"}
3100 let Func = function('Callback', ['one'], context)
Bram Moolenaar0daafaa2022-09-04 17:45:43 +01003101 "...
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003102 call Func(500)
3103< Invokes the function as with: >
3104 call context.Callback('one', 500)
3105<
Bram Moolenaar016188f2022-06-06 20:52:59 +01003106 Returns 0 on error.
3107
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003108 Can also be used as a |method|: >
3109 GetFuncname()->function([arg])
3110
3111
3112garbagecollect([{atexit}]) *garbagecollect()*
3113 Cleanup unused |Lists|, |Dictionaries|, |Channels| and |Jobs|
3114 that have circular references.
3115
3116 There is hardly ever a need to invoke this function, as it is
3117 automatically done when Vim runs out of memory or is waiting
3118 for the user to press a key after 'updatetime'. Items without
3119 circular references are always freed when they become unused.
3120 This is useful if you have deleted a very big |List| and/or
3121 |Dictionary| with circular references in a script that runs
3122 for a long time.
3123
3124 When the optional {atexit} argument is one, garbage
3125 collection will also be done when exiting Vim, if it wasn't
3126 done before. This is useful when checking for memory leaks.
3127
3128 The garbage collection is not done immediately but only when
3129 it's safe to perform. This is when waiting for the user to
3130 type a character. To force garbage collection immediately use
3131 |test_garbagecollect_now()|.
3132
3133get({list}, {idx} [, {default}]) *get()*
3134 Get item {idx} from |List| {list}. When this item is not
3135 available return {default}. Return zero when {default} is
3136 omitted.
3137 Preferably used as a |method|: >
3138 mylist->get(idx)
3139get({blob}, {idx} [, {default}])
3140 Get byte {idx} from |Blob| {blob}. When this byte is not
3141 available return {default}. Return -1 when {default} is
3142 omitted.
3143 Preferably used as a |method|: >
3144 myblob->get(idx)
3145get({dict}, {key} [, {default}])
3146 Get item with key {key} from |Dictionary| {dict}. When this
3147 item is not available return {default}. Return zero when
3148 {default} is omitted. Useful example: >
3149 let val = get(g:, 'var_name', 'default')
3150< This gets the value of g:var_name if it exists, and uses
3151 'default' when it does not exist.
3152 Preferably used as a |method|: >
3153 mydict->get(key)
3154get({func}, {what})
Bram Moolenaar6f4754b2022-01-23 12:07:04 +00003155 Get item {what} from Funcref {func}. Possible values for
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003156 {what} are:
3157 "name" The function name
3158 "func" The function
3159 "dict" The dictionary
3160 "args" The list with arguments
Bram Moolenaar016188f2022-06-06 20:52:59 +01003161 Returns zero on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003162 Preferably used as a |method|: >
3163 myfunc->get(what)
3164<
3165 *getbufinfo()*
3166getbufinfo([{buf}])
3167getbufinfo([{dict}])
3168 Get information about buffers as a List of Dictionaries.
3169
3170 Without an argument information about all the buffers is
3171 returned.
3172
3173 When the argument is a |Dictionary| only the buffers matching
3174 the specified criteria are returned. The following keys can
3175 be specified in {dict}:
3176 buflisted include only listed buffers.
3177 bufloaded include only loaded buffers.
3178 bufmodified include only modified buffers.
3179
3180 Otherwise, {buf} specifies a particular buffer to return
3181 information for. For the use of {buf}, see |bufname()|
3182 above. If the buffer is found the returned List has one item.
3183 Otherwise the result is an empty list.
3184
3185 Each returned List item is a dictionary with the following
3186 entries:
3187 bufnr Buffer number.
3188 changed TRUE if the buffer is modified.
3189 changedtick Number of changes made to the buffer.
3190 hidden TRUE if the buffer is hidden.
3191 lastused Timestamp in seconds, like
3192 |localtime()|, when the buffer was
3193 last used.
3194 {only with the |+viminfo| feature}
3195 listed TRUE if the buffer is listed.
3196 lnum Line number used for the buffer when
3197 opened in the current window.
3198 Only valid if the buffer has been
3199 displayed in the window in the past.
3200 If you want the line number of the
3201 last known cursor position in a given
3202 window, use |line()|: >
3203 :echo line('.', {winid})
3204<
3205 linecount Number of lines in the buffer (only
3206 valid when loaded)
3207 loaded TRUE if the buffer is loaded.
3208 name Full path to the file in the buffer.
3209 signs List of signs placed in the buffer.
3210 Each list item is a dictionary with
3211 the following fields:
3212 id sign identifier
3213 lnum line number
3214 name sign name
3215 variables A reference to the dictionary with
3216 buffer-local variables.
3217 windows List of |window-ID|s that display this
3218 buffer
3219 popups List of popup |window-ID|s that
3220 display this buffer
3221
3222 Examples: >
3223 for buf in getbufinfo()
3224 echo buf.name
3225 endfor
3226 for buf in getbufinfo({'buflisted':1})
3227 if buf.changed
3228 ....
3229 endif
3230 endfor
3231<
3232 To get buffer-local options use: >
3233 getbufvar({bufnr}, '&option_name')
3234<
3235 Can also be used as a |method|: >
3236 GetBufnr()->getbufinfo()
3237<
3238
3239 *getbufline()*
3240getbufline({buf}, {lnum} [, {end}])
3241 Return a |List| with the lines starting from {lnum} to {end}
3242 (inclusive) in the buffer {buf}. If {end} is omitted, a
Bram Moolenaarce30ccc2022-11-21 19:57:04 +00003243 |List| with only the line {lnum} is returned. See
3244 `getbufoneline()` for only getting the line.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003245
3246 For the use of {buf}, see |bufname()| above.
3247
3248 For {lnum} and {end} "$" can be used for the last line of the
3249 buffer. Otherwise a number must be used.
3250
3251 When {lnum} is smaller than 1 or bigger than the number of
3252 lines in the buffer, an empty |List| is returned.
3253
3254 When {end} is greater than the number of lines in the buffer,
3255 it is treated as {end} is set to the number of lines in the
3256 buffer. When {end} is before {lnum} an empty |List| is
3257 returned.
3258
3259 This function works only for loaded buffers. For unloaded and
3260 non-existing buffers, an empty |List| is returned.
3261
3262 Example: >
3263 :let lines = getbufline(bufnr("myfile"), 1, "$")
3264
3265< Can also be used as a |method|: >
3266 GetBufnr()->getbufline(lnum)
Bram Moolenaarce30ccc2022-11-21 19:57:04 +00003267<
3268 *getbufoneline()*
3269getbufoneline({buf}, {lnum})
3270 Just like `getbufline()` but only get one line and return it
3271 as a string.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003272
3273getbufvar({buf}, {varname} [, {def}]) *getbufvar()*
3274 The result is the value of option or local buffer variable
3275 {varname} in buffer {buf}. Note that the name without "b:"
3276 must be used.
3277 The {varname} argument is a string.
3278 When {varname} is empty returns a |Dictionary| with all the
3279 buffer-local variables.
3280 When {varname} is equal to "&" returns a |Dictionary| with all
3281 the buffer-local options.
3282 Otherwise, when {varname} starts with "&" returns the value of
3283 a buffer-local option.
3284 This also works for a global or buffer-local option, but it
3285 doesn't work for a global variable, window-local variable or
3286 window-local option.
3287 For the use of {buf}, see |bufname()| above.
3288 When the buffer or variable doesn't exist {def} or an empty
3289 string is returned, there is no error message.
3290 Examples: >
3291 :let bufmodified = getbufvar(1, "&mod")
Bram Moolenaarc51cf032022-02-26 12:25:45 +00003292 :echo "todo myvar = " .. getbufvar("todo", "myvar")
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003293
3294< Can also be used as a |method|: >
3295 GetBufnr()->getbufvar(varname)
3296<
Kota Kato66bb9ae2023-01-17 18:31:56 +00003297getcellwidths() *getcellwidths()*
3298 Returns a |List| of cell widths of character ranges overridden
3299 by |setcellwidths()|. The format is equal to the argument of
3300 |setcellwidths()|. If no character ranges have their cell
3301 widths overridden, an empty List is returned.
3302
3303
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003304getchangelist([{buf}]) *getchangelist()*
3305 Returns the |changelist| for the buffer {buf}. For the use
3306 of {buf}, see |bufname()| above. If buffer {buf} doesn't
3307 exist, an empty list is returned.
3308
3309 The returned list contains two entries: a list with the change
3310 locations and the current position in the list. Each
3311 entry in the change list is a dictionary with the following
3312 entries:
3313 col column number
3314 coladd column offset for 'virtualedit'
3315 lnum line number
3316 If buffer {buf} is the current buffer, then the current
3317 position refers to the position in the list. For other
3318 buffers, it is set to the length of the list.
3319
3320 Can also be used as a |method|: >
3321 GetBufnr()->getchangelist()
3322
3323getchar([expr]) *getchar()*
3324 Get a single character from the user or input stream.
3325 If [expr] is omitted, wait until a character is available.
3326 If [expr] is 0, only get a character when one is available.
3327 Return zero otherwise.
3328 If [expr] is 1, only check if a character is available, it is
3329 not consumed. Return zero if no character available.
3330 If you prefer always getting a string use |getcharstr()|.
3331
3332 Without [expr] and when [expr] is 0 a whole character or
3333 special key is returned. If it is a single character, the
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01003334 result is a Number. Use |nr2char()| to convert it to a String.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003335 Otherwise a String is returned with the encoded character.
3336 For a special key it's a String with a sequence of bytes
3337 starting with 0x80 (decimal: 128). This is the same value as
3338 the String "\<Key>", e.g., "\<Left>". The returned value is
3339 also a String when a modifier (shift, control, alt) was used
3340 that is not included in the character.
3341
3342 When [expr] is 0 and Esc is typed, there will be a short delay
3343 while Vim waits to see if this is the start of an escape
3344 sequence.
3345
3346 When [expr] is 1 only the first byte is returned. For a
3347 one-byte character it is the character itself as a number.
3348 Use nr2char() to convert it to a String.
3349
3350 Use getcharmod() to obtain any additional modifiers.
3351
3352 When the user clicks a mouse button, the mouse event will be
3353 returned. The position can then be found in |v:mouse_col|,
3354 |v:mouse_lnum|, |v:mouse_winid| and |v:mouse_win|.
3355 |getmousepos()| can also be used. Mouse move events will be
3356 ignored.
3357 This example positions the mouse as it would normally happen: >
3358 let c = getchar()
3359 if c == "\<LeftMouse>" && v:mouse_win > 0
Bram Moolenaarc51cf032022-02-26 12:25:45 +00003360 exe v:mouse_win .. "wincmd w"
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003361 exe v:mouse_lnum
Bram Moolenaarc51cf032022-02-26 12:25:45 +00003362 exe "normal " .. v:mouse_col .. "|"
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003363 endif
3364<
3365 When using bracketed paste only the first character is
3366 returned, the rest of the pasted text is dropped.
3367 |xterm-bracketed-paste|.
3368
3369 There is no prompt, you will somehow have to make clear to the
3370 user that a character has to be typed. The screen is not
3371 redrawn, e.g. when resizing the window. When using a popup
3372 window it should work better with a |popup-filter|.
3373
3374 There is no mapping for the character.
3375 Key codes are replaced, thus when the user presses the <Del>
3376 key you get the code for the <Del> key, not the raw character
3377 sequence. Examples: >
3378 getchar() == "\<Del>"
3379 getchar() == "\<S-Left>"
3380< This example redefines "f" to ignore case: >
3381 :nmap f :call FindChar()<CR>
3382 :function FindChar()
3383 : let c = nr2char(getchar())
3384 : while col('.') < col('$') - 1
3385 : normal l
3386 : if getline('.')[col('.') - 1] ==? c
3387 : break
3388 : endif
3389 : endwhile
3390 :endfunction
3391<
3392 You may also receive synthetic characters, such as
3393 |<CursorHold>|. Often you will want to ignore this and get
3394 another character: >
3395 :function GetKey()
3396 : let c = getchar()
3397 : while c == "\<CursorHold>"
3398 : let c = getchar()
3399 : endwhile
3400 : return c
3401 :endfunction
3402
3403getcharmod() *getcharmod()*
3404 The result is a Number which is the state of the modifiers for
3405 the last obtained character with getchar() or in another way.
3406 These values are added together:
3407 2 shift
3408 4 control
3409 8 alt (meta)
3410 16 meta (when it's different from ALT)
3411 32 mouse double click
3412 64 mouse triple click
3413 96 mouse quadruple click (== 32 + 64)
3414 128 command (Macintosh only)
3415 Only the modifiers that have not been included in the
3416 character itself are obtained. Thus Shift-a results in "A"
Bram Moolenaar016188f2022-06-06 20:52:59 +01003417 without a modifier. Returns 0 if no modifiers are used.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003418
3419 *getcharpos()*
3420getcharpos({expr})
3421 Get the position for String {expr}. Same as |getpos()| but the
3422 column number in the returned List is a character index
3423 instead of a byte index.
naohiro ono56200ee2022-01-01 14:59:44 +00003424 If |getpos()| returns a very large column number, equal to
3425 |v:maxcol|, then getcharpos() will return the character index
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003426 of the last character.
3427
3428 Example:
3429 With the cursor on '세' in line 5 with text "여보세요": >
3430 getcharpos('.') returns [0, 5, 3, 0]
3431 getpos('.') returns [0, 5, 7, 0]
3432<
3433 Can also be used as a |method|: >
3434 GetMark()->getcharpos()
3435
3436getcharsearch() *getcharsearch()*
3437 Return the current character search information as a {dict}
3438 with the following entries:
3439
3440 char character previously used for a character
3441 search (|t|, |f|, |T|, or |F|); empty string
3442 if no character search has been performed
3443 forward direction of character search; 1 for forward,
3444 0 for backward
3445 until type of character search; 1 for a |t| or |T|
3446 character search, 0 for an |f| or |F|
3447 character search
3448
3449 This can be useful to always have |;| and |,| search
3450 forward/backward regardless of the direction of the previous
3451 character search: >
3452 :nnoremap <expr> ; getcharsearch().forward ? ';' : ','
3453 :nnoremap <expr> , getcharsearch().forward ? ',' : ';'
3454< Also see |setcharsearch()|.
3455
3456
3457getcharstr([expr]) *getcharstr()*
3458 Get a single character from the user or input stream as a
3459 string.
3460 If [expr] is omitted, wait until a character is available.
3461 If [expr] is 0 or false, only get a character when one is
3462 available. Return an empty string otherwise.
3463 If [expr] is 1 or true, only check if a character is
3464 available, it is not consumed. Return an empty string
3465 if no character is available.
3466 Otherwise this works like |getchar()|, except that a number
3467 result is converted to a string.
3468
Shougo Matsushita79d599b2022-05-07 12:48:29 +01003469getcmdcompltype() *getcmdcompltype()*
3470 Return the type of the current command-line completion.
3471 Only works when the command line is being edited, thus
3472 requires use of |c_CTRL-\_e| or |c_CTRL-R_=|.
Bram Moolenaar921bde82022-05-09 19:50:35 +01003473 See |:command-completion| for the return string.
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01003474 Also see |getcmdtype()|, |setcmdpos()|, |getcmdline()| and
3475 |setcmdline()|.
Shougo Matsushita79d599b2022-05-07 12:48:29 +01003476 Returns an empty string when completion is not defined.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003477
3478getcmdline() *getcmdline()*
3479 Return the current command-line. Only works when the command
3480 line is being edited, thus requires use of |c_CTRL-\_e| or
3481 |c_CTRL-R_=|.
3482 Example: >
3483 :cmap <F7> <C-\>eescape(getcmdline(), ' \')<CR>
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01003484< Also see |getcmdtype()|, |getcmdpos()|, |setcmdpos()| and
3485 |setcmdline()|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003486 Returns an empty string when entering a password or using
3487 |inputsecret()|.
3488
3489getcmdpos() *getcmdpos()*
3490 Return the position of the cursor in the command line as a
3491 byte count. The first column is 1.
3492 Only works when editing the command line, thus requires use of
3493 |c_CTRL-\_e| or |c_CTRL-R_=| or an expression mapping.
3494 Returns 0 otherwise.
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01003495 Also see |getcmdtype()|, |setcmdpos()|, |getcmdline()| and
3496 |setcmdline()|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003497
Shougo Matsushita79d599b2022-05-07 12:48:29 +01003498getcmdscreenpos() *getcmdscreenpos()*
3499 Return the screen position of the cursor in the command line
3500 as a byte count. The first column is 1.
3501 Instead of |getcmdpos()|, it adds the prompt position.
3502 Only works when editing the command line, thus requires use of
3503 |c_CTRL-\_e| or |c_CTRL-R_=| or an expression mapping.
3504 Returns 0 otherwise.
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01003505 Also see |getcmdpos()|, |setcmdpos()|, |getcmdline()| and
3506 |setcmdline()|.
Shougo Matsushita79d599b2022-05-07 12:48:29 +01003507
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003508getcmdtype() *getcmdtype()*
3509 Return the current command-line type. Possible return values
3510 are:
3511 : normal Ex command
3512 > debug mode command |debug-mode|
3513 / forward search command
3514 ? backward search command
3515 @ |input()| command
3516 - |:insert| or |:append| command
3517 = |i_CTRL-R_=|
3518 Only works when editing the command line, thus requires use of
3519 |c_CTRL-\_e| or |c_CTRL-R_=| or an expression mapping.
3520 Returns an empty string otherwise.
3521 Also see |getcmdpos()|, |setcmdpos()| and |getcmdline()|.
3522
3523getcmdwintype() *getcmdwintype()*
3524 Return the current |command-line-window| type. Possible return
3525 values are the same as |getcmdtype()|. Returns an empty string
3526 when not in the command-line window.
3527
3528getcompletion({pat}, {type} [, {filtered}]) *getcompletion()*
3529 Return a list of command-line completion matches. The String
3530 {type} argument specifies what for. The following completion
3531 types are supported:
3532
3533 arglist file names in argument list
3534 augroup autocmd groups
3535 buffer buffer names
Bram Moolenaar6e2e2cc2022-03-14 19:24:46 +00003536 behave |:behave| suboptions
3537 breakpoint |:breakadd| and |:breakdel| suboptions
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003538 color color schemes
3539 command Ex command
3540 cmdline |cmdline-completion| result
3541 compiler compilers
3542 cscope |:cscope| suboptions
3543 diff_buffer |:diffget| and |:diffput| completion
3544 dir directory names
3545 environment environment variable names
3546 event autocommand events
3547 expression Vim expression
3548 file file and directory names
3549 file_in_path file and directory names in |'path'|
3550 filetype filetype names |'filetype'|
3551 function function name
3552 help help subjects
3553 highlight highlight groups
Bram Moolenaar6e2e2cc2022-03-14 19:24:46 +00003554 history |:history| suboptions
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003555 locale locale names (as output of locale -a)
3556 mapclear buffer argument
3557 mapping mapping name
3558 menu menus
3559 messages |:messages| suboptions
3560 option options
3561 packadd optional package |pack-add| names
zeertzjq5c8771b2023-01-24 12:34:03 +00003562 runtime |:runtime| completion
Yegappan Lakshmanan454ce672022-03-24 11:22:13 +00003563 scriptnames sourced script names |:scriptnames|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003564 shellcmd Shell command
3565 sign |:sign| suboptions
3566 syntax syntax file names |'syntax'|
3567 syntime |:syntime| suboptions
3568 tag tags
3569 tag_listfiles tags, file names
3570 user user names
3571 var user variables
3572
3573 If {pat} is an empty string, then all the matches are
3574 returned. Otherwise only items matching {pat} are returned.
3575 See |wildcards| for the use of special characters in {pat}.
3576
3577 If the optional {filtered} flag is set to 1, then 'wildignore'
3578 is applied to filter the results. Otherwise all the matches
3579 are returned. The 'wildignorecase' option always applies.
3580
Yegappan Lakshmanane7dd0fa2022-03-22 16:06:31 +00003581 If the 'wildoptions' option contains 'fuzzy', then fuzzy
3582 matching is used to get the completion matches. Otherwise
Yegappan Lakshmanan454ce672022-03-24 11:22:13 +00003583 regular expression matching is used. Thus this function
3584 follows the user preference, what happens on the command line.
3585 If you do not want this you can make 'wildoptions' empty
3586 before calling getcompletion() and restore it afterwards.
Yegappan Lakshmanane7dd0fa2022-03-22 16:06:31 +00003587
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003588 If {type} is "cmdline", then the |cmdline-completion| result is
3589 returned. For example, to complete the possible values after
3590 a ":call" command: >
3591 echo getcompletion('call ', 'cmdline')
3592<
3593 If there are no matches, an empty list is returned. An
3594 invalid value for {type} produces an error.
3595
3596 Can also be used as a |method|: >
3597 GetPattern()->getcompletion('color')
3598<
3599 *getcurpos()*
3600getcurpos([{winid}])
3601 Get the position of the cursor. This is like getpos('.'), but
3602 includes an extra "curswant" item in the list:
3603 [0, lnum, col, off, curswant] ~
3604 The "curswant" number is the preferred column when moving the
naohiro ono56200ee2022-01-01 14:59:44 +00003605 cursor vertically. After |$| command it will be a very large
3606 number equal to |v:maxcol|. Also see |getcursorcharpos()| and
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003607 |getpos()|.
3608 The first "bufnum" item is always zero. The byte position of
3609 the cursor is returned in 'col'. To get the character
3610 position, use |getcursorcharpos()|.
3611
3612 The optional {winid} argument can specify the window. It can
3613 be the window number or the |window-ID|. The last known
3614 cursor position is returned, this may be invalid for the
3615 current value of the buffer if it is not the current window.
3616 If {winid} is invalid a list with zeroes is returned.
3617
3618 This can be used to save and restore the cursor position: >
3619 let save_cursor = getcurpos()
3620 MoveTheCursorAround
3621 call setpos('.', save_cursor)
3622< Note that this only works within the window. See
3623 |winrestview()| for restoring more state.
3624
3625 Can also be used as a |method|: >
3626 GetWinid()->getcurpos()
3627<
3628 *getcursorcharpos()*
3629getcursorcharpos([{winid}])
3630 Same as |getcurpos()| but the column number in the returned
3631 List is a character index instead of a byte index.
3632
3633 Example:
3634 With the cursor on '보' in line 3 with text "여보세요": >
3635 getcursorcharpos() returns [0, 3, 2, 0, 3]
3636 getcurpos() returns [0, 3, 4, 0, 3]
3637<
3638 Can also be used as a |method|: >
3639 GetWinid()->getcursorcharpos()
3640
3641< *getcwd()*
3642getcwd([{winnr} [, {tabnr}]])
3643 The result is a String, which is the name of the current
3644 working directory. 'autochdir' is ignored.
3645
3646 With {winnr} return the local current directory of this window
3647 in the current tab page. {winnr} can be the window number or
3648 the |window-ID|.
3649 If {winnr} is -1 return the name of the global working
3650 directory. See also |haslocaldir()|.
3651
3652 With {winnr} and {tabnr} return the local current directory of
3653 the window in the specified tab page. If {winnr} is -1 return
3654 the working directory of the tabpage.
3655 If {winnr} is zero use the current window, if {tabnr} is zero
3656 use the current tabpage.
3657 Without any arguments, return the actual working directory of
3658 the current window.
3659 Return an empty string if the arguments are invalid.
3660
3661 Examples: >
3662 " Get the working directory of the current window
3663 :echo getcwd()
3664 :echo getcwd(0)
3665 :echo getcwd(0, 0)
3666 " Get the working directory of window 3 in tabpage 2
3667 :echo getcwd(3, 2)
3668 " Get the global working directory
3669 :echo getcwd(-1)
3670 " Get the working directory of tabpage 3
3671 :echo getcwd(-1, 3)
3672 " Get the working directory of current tabpage
3673 :echo getcwd(-1, 0)
3674
3675< Can also be used as a |method|: >
3676 GetWinnr()->getcwd()
3677
3678getenv({name}) *getenv()*
3679 Return the value of environment variable {name}. The {name}
3680 argument is a string, without a leading '$'. Example: >
3681 myHome = getenv('HOME')
3682
3683< When the variable does not exist |v:null| is returned. That
3684 is different from a variable set to an empty string, although
3685 some systems interpret the empty value as the variable being
3686 deleted. See also |expr-env|.
3687
3688 Can also be used as a |method|: >
3689 GetVarname()->getenv()
3690
3691getfontname([{name}]) *getfontname()*
3692 Without an argument returns the name of the normal font being
3693 used. Like what is used for the Normal highlight group
3694 |hl-Normal|.
3695 With an argument a check is done whether String {name} is a
3696 valid font name. If not then an empty string is returned.
3697 Otherwise the actual font name is returned, or {name} if the
3698 GUI does not support obtaining the real name.
3699 Only works when the GUI is running, thus not in your vimrc or
3700 gvimrc file. Use the |GUIEnter| autocommand to use this
3701 function just after the GUI has started.
3702 Note that the GTK GUI accepts any font name, thus checking for
3703 a valid name does not work.
3704
3705getfperm({fname}) *getfperm()*
3706 The result is a String, which is the read, write, and execute
3707 permissions of the given file {fname}.
3708 If {fname} does not exist or its directory cannot be read, an
3709 empty string is returned.
3710 The result is of the form "rwxrwxrwx", where each group of
3711 "rwx" flags represent, in turn, the permissions of the owner
3712 of the file, the group the file belongs to, and other users.
3713 If a user does not have a given permission the flag for this
3714 is replaced with the string "-". Examples: >
3715 :echo getfperm("/etc/passwd")
3716 :echo getfperm(expand("~/.vimrc"))
3717< This will hopefully (from a security point of view) display
3718 the string "rw-r--r--" or even "rw-------".
3719
3720 Can also be used as a |method|: >
3721 GetFilename()->getfperm()
3722<
3723 For setting permissions use |setfperm()|.
3724
3725getfsize({fname}) *getfsize()*
3726 The result is a Number, which is the size in bytes of the
3727 given file {fname}.
3728 If {fname} is a directory, 0 is returned.
3729 If the file {fname} can't be found, -1 is returned.
3730 If the size of {fname} is too big to fit in a Number then -2
3731 is returned.
3732
3733 Can also be used as a |method|: >
3734 GetFilename()->getfsize()
3735
3736getftime({fname}) *getftime()*
3737 The result is a Number, which is the last modification time of
3738 the given file {fname}. The value is measured as seconds
3739 since 1st Jan 1970, and may be passed to strftime(). See also
3740 |localtime()| and |strftime()|.
3741 If the file {fname} can't be found -1 is returned.
3742
3743 Can also be used as a |method|: >
3744 GetFilename()->getftime()
3745
3746getftype({fname}) *getftype()*
3747 The result is a String, which is a description of the kind of
3748 file of the given file {fname}.
3749 If {fname} does not exist an empty string is returned.
3750 Here is a table over different kinds of files and their
3751 results:
3752 Normal file "file"
3753 Directory "dir"
3754 Symbolic link "link"
3755 Block device "bdev"
3756 Character device "cdev"
3757 Socket "socket"
3758 FIFO "fifo"
3759 All other "other"
3760 Example: >
3761 getftype("/home")
3762< Note that a type such as "link" will only be returned on
3763 systems that support it. On some systems only "dir" and
3764 "file" are returned. On MS-Windows a symbolic link to a
3765 directory returns "dir" instead of "link".
3766
3767 Can also be used as a |method|: >
3768 GetFilename()->getftype()
3769
3770getimstatus() *getimstatus()*
3771 The result is a Number, which is |TRUE| when the IME status is
Bram Moolenaar016188f2022-06-06 20:52:59 +01003772 active and |FALSE| otherwise.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003773 See 'imstatusfunc'.
3774
3775getjumplist([{winnr} [, {tabnr}]]) *getjumplist()*
3776 Returns the |jumplist| for the specified window.
3777
3778 Without arguments use the current window.
3779 With {winnr} only use this window in the current tab page.
3780 {winnr} can also be a |window-ID|.
3781 With {winnr} and {tabnr} use the window in the specified tab
Bram Moolenaar016188f2022-06-06 20:52:59 +01003782 page. If {winnr} or {tabnr} is invalid, an empty list is
3783 returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003784
3785 The returned list contains two entries: a list with the jump
3786 locations and the last used jump position number in the list.
3787 Each entry in the jump location list is a dictionary with
3788 the following entries:
3789 bufnr buffer number
3790 col column number
3791 coladd column offset for 'virtualedit'
3792 filename filename if available
3793 lnum line number
3794
3795 Can also be used as a |method|: >
3796 GetWinnr()->getjumplist()
3797
3798< *getline()*
3799getline({lnum} [, {end}])
3800 Without {end} the result is a String, which is line {lnum}
3801 from the current buffer. Example: >
3802 getline(1)
3803< When {lnum} is a String that doesn't start with a
3804 digit, |line()| is called to translate the String into a Number.
3805 To get the line under the cursor: >
3806 getline(".")
3807< When {lnum} is a number smaller than 1 or bigger than the
3808 number of lines in the buffer, an empty string is returned.
3809
3810 When {end} is given the result is a |List| where each item is
3811 a line from the current buffer in the range {lnum} to {end},
3812 including line {end}.
3813 {end} is used in the same way as {lnum}.
3814 Non-existing lines are silently omitted.
3815 When {end} is before {lnum} an empty |List| is returned.
3816 Example: >
3817 :let start = line('.')
3818 :let end = search("^$") - 1
3819 :let lines = getline(start, end)
3820
3821< Can also be used as a |method|: >
3822 ComputeLnum()->getline()
3823
Bram Moolenaarce30ccc2022-11-21 19:57:04 +00003824< To get lines from another buffer see |getbufline()| and
3825 |getbufoneline()|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003826
3827getloclist({nr} [, {what}]) *getloclist()*
3828 Returns a |List| with all the entries in the location list for
3829 window {nr}. {nr} can be the window number or the |window-ID|.
3830 When {nr} is zero the current window is used.
3831
3832 For a location list window, the displayed location list is
3833 returned. For an invalid window number {nr}, an empty list is
3834 returned. Otherwise, same as |getqflist()|.
3835
3836 If the optional {what} dictionary argument is supplied, then
3837 returns the items listed in {what} as a dictionary. Refer to
3838 |getqflist()| for the supported items in {what}.
3839
3840 In addition to the items supported by |getqflist()| in {what},
3841 the following item is supported by |getloclist()|:
3842
3843 filewinid id of the window used to display files
3844 from the location list. This field is
3845 applicable only when called from a
3846 location list window. See
3847 |location-list-file-window| for more
3848 details.
3849
3850 Returns a |Dictionary| with default values if there is no
3851 location list for the window {nr}.
3852 Returns an empty Dictionary if window {nr} does not exist.
3853
3854 Examples (See also |getqflist-examples|): >
3855 :echo getloclist(3, {'all': 0})
3856 :echo getloclist(5, {'filewinid': 0})
3857
3858
3859getmarklist([{buf}]) *getmarklist()*
3860 Without the {buf} argument returns a |List| with information
3861 about all the global marks. |mark|
3862
3863 If the optional {buf} argument is specified, returns the
3864 local marks defined in buffer {buf}. For the use of {buf},
Bram Moolenaar016188f2022-06-06 20:52:59 +01003865 see |bufname()|. If {buf} is invalid, an empty list is
3866 returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003867
3868 Each item in the returned List is a |Dict| with the following:
3869 mark name of the mark prefixed by "'"
3870 pos a |List| with the position of the mark:
3871 [bufnum, lnum, col, off]
3872 Refer to |getpos()| for more information.
3873 file file name
3874
3875 Refer to |getpos()| for getting information about a specific
3876 mark.
3877
3878 Can also be used as a |method|: >
3879 GetBufnr()->getmarklist()
3880
3881getmatches([{win}]) *getmatches()*
3882 Returns a |List| with all matches previously defined for the
3883 current window by |matchadd()| and the |:match| commands.
3884 |getmatches()| is useful in combination with |setmatches()|,
3885 as |setmatches()| can restore a list of matches saved by
3886 |getmatches()|.
3887 If {win} is specified, use the window with this number or
Bram Moolenaar016188f2022-06-06 20:52:59 +01003888 window ID instead of the current window. If {win} is invalid,
3889 an empty list is returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003890 Example: >
3891 :echo getmatches()
3892< [{'group': 'MyGroup1', 'pattern': 'TODO',
3893 'priority': 10, 'id': 1}, {'group': 'MyGroup2',
3894 'pattern': 'FIXME', 'priority': 10, 'id': 2}] >
3895 :let m = getmatches()
3896 :call clearmatches()
3897 :echo getmatches()
3898< [] >
3899 :call setmatches(m)
3900 :echo getmatches()
3901< [{'group': 'MyGroup1', 'pattern': 'TODO',
3902 'priority': 10, 'id': 1}, {'group': 'MyGroup2',
3903 'pattern': 'FIXME', 'priority': 10, 'id': 2}] >
3904 :unlet m
3905<
3906getmousepos() *getmousepos()*
3907 Returns a |Dictionary| with the last known position of the
3908 mouse. This can be used in a mapping for a mouse click or in
3909 a filter of a popup window. The items are:
3910 screenrow screen row
3911 screencol screen column
3912 winid Window ID of the click
3913 winrow row inside "winid"
3914 wincol column inside "winid"
3915 line text line inside "winid"
3916 column text column inside "winid"
3917 All numbers are 1-based.
3918
3919 If not over a window, e.g. when in the command line, then only
3920 "screenrow" and "screencol" are valid, the others are zero.
3921
3922 When on the status line below a window or the vertical
3923 separator right of a window, the "line" and "column" values
3924 are zero.
3925
3926 When the position is after the text then "column" is the
3927 length of the text in bytes plus one.
3928
3929 If the mouse is over a popup window then that window is used.
3930
3931 When using |getchar()| the Vim variables |v:mouse_lnum|,
3932 |v:mouse_col| and |v:mouse_winid| also provide these values.
3933
Bram Moolenaar24dc19c2022-11-14 19:49:15 +00003934getmouseshape() *getmouseshape()*
3935 Returns the name of the currently showing mouse pointer.
3936 When the |+mouseshape| feature is not supported or the shape
3937 is unknown an empty string is returned.
3938 This function is mainly intended for testing.
3939
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003940 *getpid()*
3941getpid() Return a Number which is the process ID of the Vim process.
3942 On Unix and MS-Windows this is a unique number, until Vim
3943 exits.
3944
3945 *getpos()*
3946getpos({expr}) Get the position for String {expr}. For possible values of
3947 {expr} see |line()|. For getting the cursor position see
3948 |getcurpos()|.
3949 The result is a |List| with four numbers:
3950 [bufnum, lnum, col, off]
3951 "bufnum" is zero, unless a mark like '0 or 'A is used, then it
3952 is the buffer number of the mark.
3953 "lnum" and "col" are the position in the buffer. The first
3954 column is 1.
3955 The "off" number is zero, unless 'virtualedit' is used. Then
3956 it is the offset in screen columns from the start of the
3957 character. E.g., a position within a <Tab> or after the last
3958 character.
3959 Note that for '< and '> Visual mode matters: when it is "V"
3960 (visual line mode) the column of '< is zero and the column of
naohiro ono56200ee2022-01-01 14:59:44 +00003961 '> is a large number equal to |v:maxcol|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003962 The column number in the returned List is the byte position
3963 within the line. To get the character position in the line,
3964 use |getcharpos()|.
naohiro ono56200ee2022-01-01 14:59:44 +00003965 A very large column number equal to |v:maxcol| can be returned,
3966 in which case it means "after the end of the line".
Bram Moolenaar016188f2022-06-06 20:52:59 +01003967 If {expr} is invalid, returns a list with all zeros.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003968 This can be used to save and restore the position of a mark: >
3969 let save_a_mark = getpos("'a")
3970 ...
3971 call setpos("'a", save_a_mark)
3972< Also see |getcharpos()|, |getcurpos()| and |setpos()|.
3973
3974 Can also be used as a |method|: >
3975 GetMark()->getpos()
3976
3977getqflist([{what}]) *getqflist()*
3978 Returns a |List| with all the current quickfix errors. Each
3979 list item is a dictionary with these entries:
3980 bufnr number of buffer that has the file name, use
3981 bufname() to get the name
3982 module module name
3983 lnum line number in the buffer (first line is 1)
3984 end_lnum
3985 end of line number if the item is multiline
3986 col column number (first column is 1)
3987 end_col end of column number if the item has range
3988 vcol |TRUE|: "col" is visual column
3989 |FALSE|: "col" is byte index
3990 nr error number
3991 pattern search pattern used to locate the error
3992 text description of the error
3993 type type of the error, 'E', '1', etc.
3994 valid |TRUE|: recognized error message
3995
3996 When there is no error list or it's empty, an empty list is
3997 returned. Quickfix list entries with a non-existing buffer
3998 number are returned with "bufnr" set to zero (Note: some
3999 functions accept buffer number zero for the alternate buffer,
4000 you may need to explicitly check for zero).
4001
4002 Useful application: Find pattern matches in multiple files and
4003 do something with them: >
4004 :vimgrep /theword/jg *.c
4005 :for d in getqflist()
4006 : echo bufname(d.bufnr) ':' d.lnum '=' d.text
4007 :endfor
4008<
4009 If the optional {what} dictionary argument is supplied, then
4010 returns only the items listed in {what} as a dictionary. The
4011 following string items are supported in {what}:
4012 changedtick get the total number of changes made
4013 to the list |quickfix-changedtick|
4014 context get the |quickfix-context|
4015 efm errorformat to use when parsing "lines". If
4016 not present, then the 'errorformat' option
4017 value is used.
4018 id get information for the quickfix list with
4019 |quickfix-ID|; zero means the id for the
4020 current list or the list specified by "nr"
4021 idx get information for the quickfix entry at this
4022 index in the list specified by 'id' or 'nr'.
4023 If set to zero, then uses the current entry.
4024 See |quickfix-index|
4025 items quickfix list entries
4026 lines parse a list of lines using 'efm' and return
4027 the resulting entries. Only a |List| type is
4028 accepted. The current quickfix list is not
4029 modified. See |quickfix-parse|.
4030 nr get information for this quickfix list; zero
4031 means the current quickfix list and "$" means
4032 the last quickfix list
4033 qfbufnr number of the buffer displayed in the quickfix
4034 window. Returns 0 if the quickfix buffer is
4035 not present. See |quickfix-buffer|.
4036 size number of entries in the quickfix list
4037 title get the list title |quickfix-title|
4038 winid get the quickfix |window-ID|
4039 all all of the above quickfix properties
4040 Non-string items in {what} are ignored. To get the value of a
4041 particular item, set it to zero.
4042 If "nr" is not present then the current quickfix list is used.
4043 If both "nr" and a non-zero "id" are specified, then the list
4044 specified by "id" is used.
4045 To get the number of lists in the quickfix stack, set "nr" to
4046 "$" in {what}. The "nr" value in the returned dictionary
4047 contains the quickfix stack size.
4048 When "lines" is specified, all the other items except "efm"
4049 are ignored. The returned dictionary contains the entry
4050 "items" with the list of entries.
4051
4052 The returned dictionary contains the following entries:
4053 changedtick total number of changes made to the
4054 list |quickfix-changedtick|
4055 context quickfix list context. See |quickfix-context|
4056 If not present, set to "".
4057 id quickfix list ID |quickfix-ID|. If not
4058 present, set to 0.
4059 idx index of the quickfix entry in the list. If not
4060 present, set to 0.
4061 items quickfix list entries. If not present, set to
4062 an empty list.
4063 nr quickfix list number. If not present, set to 0
4064 qfbufnr number of the buffer displayed in the quickfix
4065 window. If not present, set to 0.
4066 size number of entries in the quickfix list. If not
4067 present, set to 0.
4068 title quickfix list title text. If not present, set
4069 to "".
4070 winid quickfix |window-ID|. If not present, set to 0
4071
4072 Examples (See also |getqflist-examples|): >
4073 :echo getqflist({'all': 1})
4074 :echo getqflist({'nr': 2, 'title': 1})
4075 :echo getqflist({'lines' : ["F1:10:L10"]})
4076<
4077getreg([{regname} [, 1 [, {list}]]]) *getreg()*
4078 The result is a String, which is the contents of register
4079 {regname}. Example: >
4080 :let cliptext = getreg('*')
4081< When register {regname} was not set the result is an empty
4082 string.
Bram Moolenaara2baa732022-02-04 16:09:54 +00004083 The {regname} argument must be a string. *E1162*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004084
4085 getreg('=') returns the last evaluated value of the expression
4086 register. (For use in maps.)
4087 getreg('=', 1) returns the expression itself, so that it can
4088 be restored with |setreg()|. For other registers the extra
4089 argument is ignored, thus you can always give it.
4090
4091 If {list} is present and |TRUE|, the result type is changed
4092 to |List|. Each list item is one text line. Use it if you care
4093 about zero bytes possibly present inside register: without
4094 third argument both NLs and zero bytes are represented as NLs
4095 (see |NL-used-for-Nul|).
4096 When the register was not set an empty list is returned.
4097
4098 If {regname} is "", the unnamed register '"' is used.
4099 If {regname} is not specified, |v:register| is used.
4100 In |Vim9-script| {regname} must be one character.
4101
4102 Can also be used as a |method|: >
4103 GetRegname()->getreg()
4104
4105getreginfo([{regname}]) *getreginfo()*
4106 Returns detailed information about register {regname} as a
4107 Dictionary with the following entries:
4108 regcontents List of lines contained in register
4109 {regname}, like
4110 |getreg|({regname}, 1, 1).
4111 regtype the type of register {regname}, as in
4112 |getregtype()|.
4113 isunnamed Boolean flag, v:true if this register
4114 is currently pointed to by the unnamed
4115 register.
4116 points_to for the unnamed register, gives the
4117 single letter name of the register
4118 currently pointed to (see |quotequote|).
4119 For example, after deleting a line
4120 with `dd`, this field will be "1",
4121 which is the register that got the
4122 deleted text.
4123
4124 The {regname} argument is a string. If {regname} is invalid
4125 or not set, an empty Dictionary will be returned.
4126 If {regname} is "" or "@", the unnamed register '"' is used.
4127 If {regname} is not specified, |v:register| is used.
4128 The returned Dictionary can be passed to |setreg()|.
4129 In |Vim9-script| {regname} must be one character.
4130
4131 Can also be used as a |method|: >
4132 GetRegname()->getreginfo()
4133
4134getregtype([{regname}]) *getregtype()*
4135 The result is a String, which is type of register {regname}.
4136 The value will be one of:
4137 "v" for |characterwise| text
4138 "V" for |linewise| text
4139 "<CTRL-V>{width}" for |blockwise-visual| text
4140 "" for an empty or unknown register
4141 <CTRL-V> is one character with value 0x16.
4142 The {regname} argument is a string. If {regname} is "", the
4143 unnamed register '"' is used. If {regname} is not specified,
4144 |v:register| is used.
4145 In |Vim9-script| {regname} must be one character.
4146
4147 Can also be used as a |method|: >
4148 GetRegname()->getregtype()
4149
Bram Moolenaar71badf92023-04-22 22:40:14 +01004150getscriptinfo([{opts}]) *getscriptinfo()*
Yegappan Lakshmananf768c3d2022-08-22 13:15:13 +01004151 Returns a |List| with information about all the sourced Vim
Bram Moolenaar753885b2022-08-24 16:30:36 +01004152 scripts in the order they were sourced, like what
4153 `:scriptnames` shows.
Yegappan Lakshmananf768c3d2022-08-22 13:15:13 +01004154
Yegappan Lakshmanan2f892d82022-08-28 18:52:10 +01004155 The optional Dict argument {opts} supports the following
4156 optional items:
4157 name Script name match pattern. If specified,
4158 and "sid" is not specified, information about
Bram Moolenaar71badf92023-04-22 22:40:14 +01004159 scripts with a name that match the pattern
Yegappan Lakshmanan2f892d82022-08-28 18:52:10 +01004160 "name" are returned.
4161 sid Script ID |<SID>|. If specified, only
4162 information about the script with ID "sid" is
4163 returned and "name" is ignored.
4164
Yegappan Lakshmananf768c3d2022-08-22 13:15:13 +01004165 Each item in the returned List is a |Dict| with the following
4166 items:
Yegappan Lakshmanan2f892d82022-08-28 18:52:10 +01004167 autoload Set to TRUE for a script that was used with
Bram Moolenaar753885b2022-08-24 16:30:36 +01004168 `import autoload` but was not actually sourced
4169 yet (see |import-autoload|).
Yegappan Lakshmanan2f892d82022-08-28 18:52:10 +01004170 functions List of script-local function names defined in
4171 the script. Present only when a particular
4172 script is specified using the "sid" item in
4173 {opts}.
4174 name Vim script file name.
4175 sid Script ID |<SID>|.
4176 sourced Script ID of the actually sourced script that
Bram Moolenaarfd999452022-08-24 18:30:14 +01004177 this script name links to, if any, otherwise
4178 zero
Yegappan Lakshmanan2f892d82022-08-28 18:52:10 +01004179 variables A dictionary with the script-local variables.
Bram Moolenaarf1dcd142022-12-31 15:30:45 +00004180 Present only when a particular script is
Yegappan Lakshmanan2f892d82022-08-28 18:52:10 +01004181 specified using the "sid" item in {opts}.
4182 Note that this is a copy, the value of
4183 script-local variables cannot be changed using
4184 this dictionary.
4185 version Vimscript version (|scriptversion|)
Yegappan Lakshmanan520f6ef2022-08-25 17:40:40 +01004186
Yegappan Lakshmanan2f892d82022-08-28 18:52:10 +01004187 Examples: >
4188 :echo getscriptinfo({'name': 'myscript'})
4189 :echo getscriptinfo({'sid': 15}).variables
4190<
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004191gettabinfo([{tabnr}]) *gettabinfo()*
4192 If {tabnr} is not specified, then information about all the
4193 tab pages is returned as a |List|. Each List item is a
4194 |Dictionary|. Otherwise, {tabnr} specifies the tab page
4195 number and information about that one is returned. If the tab
4196 page does not exist an empty List is returned.
4197
4198 Each List item is a |Dictionary| with the following entries:
4199 tabnr tab page number.
4200 variables a reference to the dictionary with
4201 tabpage-local variables
4202 windows List of |window-ID|s in the tab page.
4203
4204 Can also be used as a |method|: >
4205 GetTabnr()->gettabinfo()
4206
4207gettabvar({tabnr}, {varname} [, {def}]) *gettabvar()*
4208 Get the value of a tab-local variable {varname} in tab page
4209 {tabnr}. |t:var|
4210 Tabs are numbered starting with one.
4211 The {varname} argument is a string. When {varname} is empty a
4212 dictionary with all tab-local variables is returned.
4213 Note that the name without "t:" must be used.
4214 When the tab or variable doesn't exist {def} or an empty
4215 string is returned, there is no error message.
4216
4217 Can also be used as a |method|: >
4218 GetTabnr()->gettabvar(varname)
4219
4220gettabwinvar({tabnr}, {winnr}, {varname} [, {def}]) *gettabwinvar()*
4221 Get the value of window-local variable {varname} in window
4222 {winnr} in tab page {tabnr}.
4223 The {varname} argument is a string. When {varname} is empty a
4224 dictionary with all window-local variables is returned.
4225 When {varname} is equal to "&" get the values of all
4226 window-local options in a |Dictionary|.
4227 Otherwise, when {varname} starts with "&" get the value of a
4228 window-local option.
4229 Note that {varname} must be the name without "w:".
4230 Tabs are numbered starting with one. For the current tabpage
4231 use |getwinvar()|.
4232 {winnr} can be the window number or the |window-ID|.
4233 When {winnr} is zero the current window is used.
4234 This also works for a global option, buffer-local option and
4235 window-local option, but it doesn't work for a global variable
4236 or buffer-local variable.
4237 When the tab, window or variable doesn't exist {def} or an
4238 empty string is returned, there is no error message.
4239 Examples: >
4240 :let list_is_on = gettabwinvar(1, 2, '&list')
Bram Moolenaarc51cf032022-02-26 12:25:45 +00004241 :echo "myvar = " .. gettabwinvar(3, 1, 'myvar')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004242<
4243 To obtain all window-local variables use: >
4244 gettabwinvar({tabnr}, {winnr}, '&')
4245
4246< Can also be used as a |method|: >
4247 GetTabnr()->gettabwinvar(winnr, varname)
4248
4249gettagstack([{winnr}]) *gettagstack()*
4250 The result is a Dict, which is the tag stack of window {winnr}.
4251 {winnr} can be the window number or the |window-ID|.
4252 When {winnr} is not specified, the current window is used.
4253 When window {winnr} doesn't exist, an empty Dict is returned.
4254
4255 The returned dictionary contains the following entries:
4256 curidx Current index in the stack. When at
4257 top of the stack, set to (length + 1).
4258 Index of bottom of the stack is 1.
4259 items List of items in the stack. Each item
4260 is a dictionary containing the
4261 entries described below.
4262 length Number of entries in the stack.
4263
4264 Each item in the stack is a dictionary with the following
4265 entries:
4266 bufnr buffer number of the current jump
4267 from cursor position before the tag jump.
4268 See |getpos()| for the format of the
4269 returned list.
4270 matchnr current matching tag number. Used when
4271 multiple matching tags are found for a
4272 name.
4273 tagname name of the tag
4274
4275 See |tagstack| for more information about the tag stack.
4276
4277 Can also be used as a |method|: >
4278 GetWinnr()->gettagstack()
4279
4280
4281gettext({text}) *gettext()*
4282 Translate String {text} if possible.
4283 This is mainly for use in the distributed Vim scripts. When
4284 generating message translations the {text} is extracted by
4285 xgettext, the translator can add the translated message in the
4286 .po file and Vim will lookup the translation when gettext() is
4287 called.
4288 For {text} double quoted strings are preferred, because
4289 xgettext does not understand escaping in single quoted
4290 strings.
4291
4292
4293getwininfo([{winid}]) *getwininfo()*
4294 Returns information about windows as a |List| with Dictionaries.
4295
4296 If {winid} is given Information about the window with that ID
4297 is returned, as a |List| with one item. If the window does not
4298 exist the result is an empty list.
4299
4300 Without {winid} information about all the windows in all the
4301 tab pages is returned.
4302
4303 Each List item is a |Dictionary| with the following entries:
4304 botline last complete displayed buffer line
4305 bufnr number of buffer in the window
4306 height window height (excluding winbar)
4307 loclist 1 if showing a location list
4308 {only with the +quickfix feature}
4309 quickfix 1 if quickfix or location list window
4310 {only with the +quickfix feature}
4311 terminal 1 if a terminal window
4312 {only with the +terminal feature}
4313 tabnr tab page number
4314 topline first displayed buffer line
4315 variables a reference to the dictionary with
4316 window-local variables
4317 width window width
4318 winbar 1 if the window has a toolbar, 0
4319 otherwise
4320 wincol leftmost screen column of the window;
4321 "col" from |win_screenpos()|
4322 textoff number of columns occupied by any
4323 'foldcolumn', 'signcolumn' and line
4324 number in front of the text
4325 winid |window-ID|
4326 winnr window number
4327 winrow topmost screen line of the window;
4328 "row" from |win_screenpos()|
4329
4330 Can also be used as a |method|: >
4331 GetWinnr()->getwininfo()
4332
4333getwinpos([{timeout}]) *getwinpos()*
4334 The result is a |List| with two numbers, the result of
4335 |getwinposx()| and |getwinposy()| combined:
4336 [x-pos, y-pos]
4337 {timeout} can be used to specify how long to wait in msec for
4338 a response from the terminal. When omitted 100 msec is used.
4339 Use a longer time for a remote terminal.
4340 When using a value less than 10 and no response is received
4341 within that time, a previously reported position is returned,
4342 if available. This can be used to poll for the position and
4343 do some work in the meantime: >
4344 while 1
4345 let res = getwinpos(1)
4346 if res[0] >= 0
4347 break
4348 endif
4349 " Do some work here
4350 endwhile
4351<
4352
4353 Can also be used as a |method|: >
4354 GetTimeout()->getwinpos()
4355<
4356 *getwinposx()*
4357getwinposx() The result is a Number, which is the X coordinate in pixels of
4358 the left hand side of the GUI Vim window. Also works for an
4359 xterm (uses a timeout of 100 msec).
4360 The result will be -1 if the information is not available.
4361 The value can be used with `:winpos`.
4362
4363 *getwinposy()*
4364getwinposy() The result is a Number, which is the Y coordinate in pixels of
4365 the top of the GUI Vim window. Also works for an xterm (uses
4366 a timeout of 100 msec).
4367 The result will be -1 if the information is not available.
4368 The value can be used with `:winpos`.
4369
4370getwinvar({winnr}, {varname} [, {def}]) *getwinvar()*
4371 Like |gettabwinvar()| for the current tabpage.
4372 Examples: >
4373 :let list_is_on = getwinvar(2, '&list')
Bram Moolenaarc51cf032022-02-26 12:25:45 +00004374 :echo "myvar = " .. getwinvar(1, 'myvar')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004375
4376< Can also be used as a |method|: >
4377 GetWinnr()->getwinvar(varname)
4378<
4379glob({expr} [, {nosuf} [, {list} [, {alllinks}]]]) *glob()*
4380 Expand the file wildcards in {expr}. See |wildcards| for the
4381 use of special characters.
4382
4383 Unless the optional {nosuf} argument is given and is |TRUE|,
4384 the 'suffixes' and 'wildignore' options apply: Names matching
4385 one of the patterns in 'wildignore' will be skipped and
4386 'suffixes' affect the ordering of matches.
4387 'wildignorecase' always applies.
4388
4389 When {list} is present and it is |TRUE| the result is a |List|
4390 with all matching files. The advantage of using a List is,
4391 you also get filenames containing newlines correctly.
4392 Otherwise the result is a String and when there are several
4393 matches, they are separated by <NL> characters.
4394
4395 If the expansion fails, the result is an empty String or List.
4396
4397 You can also use |readdir()| if you need to do complicated
4398 things, such as limiting the number of matches.
4399
4400 A name for a non-existing file is not included. A symbolic
4401 link is only included if it points to an existing file.
4402 However, when the {alllinks} argument is present and it is
4403 |TRUE| then all symbolic links are included.
4404
4405 For most systems backticks can be used to get files names from
4406 any external command. Example: >
4407 :let tagfiles = glob("`find . -name tags -print`")
4408 :let &tags = substitute(tagfiles, "\n", ",", "g")
4409< The result of the program inside the backticks should be one
4410 item per line. Spaces inside an item are allowed.
4411
4412 See |expand()| for expanding special Vim variables. See
4413 |system()| for getting the raw output of an external command.
4414
4415 Can also be used as a |method|: >
4416 GetExpr()->glob()
4417
4418glob2regpat({string}) *glob2regpat()*
4419 Convert a file pattern, as used by glob(), into a search
4420 pattern. The result can be used to match with a string that
4421 is a file name. E.g. >
4422 if filename =~ glob2regpat('Make*.mak')
4423< This is equivalent to: >
4424 if filename =~ '^Make.*\.mak$'
4425< When {string} is an empty string the result is "^$", match an
4426 empty string.
4427 Note that the result depends on the system. On MS-Windows
4428 a backslash usually means a path separator.
4429
4430 Can also be used as a |method|: >
4431 GetExpr()->glob2regpat()
4432< *globpath()*
4433globpath({path}, {expr} [, {nosuf} [, {list} [, {alllinks}]]])
4434 Perform glob() for String {expr} on all directories in {path}
4435 and concatenate the results. Example: >
4436 :echo globpath(&rtp, "syntax/c.vim")
4437<
4438 {path} is a comma-separated list of directory names. Each
4439 directory name is prepended to {expr} and expanded like with
4440 |glob()|. A path separator is inserted when needed.
4441 To add a comma inside a directory name escape it with a
4442 backslash. Note that on MS-Windows a directory may have a
4443 trailing backslash, remove it if you put a comma after it.
4444 If the expansion fails for one of the directories, there is no
4445 error message.
4446
4447 Unless the optional {nosuf} argument is given and is |TRUE|,
4448 the 'suffixes' and 'wildignore' options apply: Names matching
4449 one of the patterns in 'wildignore' will be skipped and
4450 'suffixes' affect the ordering of matches.
4451
4452 When {list} is present and it is |TRUE| the result is a |List|
4453 with all matching files. The advantage of using a List is, you
4454 also get filenames containing newlines correctly. Otherwise
4455 the result is a String and when there are several matches,
4456 they are separated by <NL> characters. Example: >
4457 :echo globpath(&rtp, "syntax/c.vim", 0, 1)
4458<
4459 {alllinks} is used as with |glob()|.
4460
4461 The "**" item can be used to search in a directory tree.
4462 For example, to find all "README.txt" files in the directories
4463 in 'runtimepath' and below: >
4464 :echo globpath(&rtp, "**/README.txt")
4465< Upwards search and limiting the depth of "**" is not
4466 supported, thus using 'path' will not always work properly.
4467
4468 Can also be used as a |method|, the base is passed as the
4469 second argument: >
4470 GetExpr()->globpath(&rtp)
4471<
4472 *has()*
4473has({feature} [, {check}])
4474 When {check} is omitted or is zero: The result is a Number,
4475 which is 1 if the feature {feature} is supported, zero
4476 otherwise. The {feature} argument is a string, case is
4477 ignored. See |feature-list| below.
4478
4479 When {check} is present and not zero: The result is a Number,
4480 which is 1 if the feature {feature} could ever be supported,
4481 zero otherwise. This is useful to check for a typo in
4482 {feature} and to detect dead code. Keep in mind that an older
4483 Vim version will not know about a feature added later and
4484 features that have been abandoned will not be known by the
4485 current Vim version.
4486
4487 Also see |exists()| and |exists_compiled()|.
4488
4489 Note that to skip code that has a syntax error when the
4490 feature is not available, Vim may skip the rest of the line
4491 and miss a following `endif`. Therefore put the `endif` on a
4492 separate line: >
4493 if has('feature')
4494 let x = this->breaks->without->the->feature
4495 endif
4496< If the `endif` would be moved to the second line as "| endif" it
4497 would not be found.
4498
4499
4500has_key({dict}, {key}) *has_key()*
4501 The result is a Number, which is TRUE if |Dictionary| {dict}
Bram Moolenaare8008642022-08-19 17:15:35 +01004502 has an entry with key {key}. FALSE otherwise.
4503 The {key} argument is a string. In |Vim9| script a number is
4504 also accepted (and converted to a string) but no other types.
4505 In legacy script the usual automatic conversion to string is
4506 done.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004507
4508 Can also be used as a |method|: >
4509 mydict->has_key(key)
4510
4511haslocaldir([{winnr} [, {tabnr}]]) *haslocaldir()*
4512 The result is a Number:
4513 1 when the window has set a local directory via |:lcd|
4514 2 when the tab-page has set a local directory via |:tcd|
4515 0 otherwise.
4516
4517 Without arguments use the current window.
4518 With {winnr} use this window in the current tab page.
4519 With {winnr} and {tabnr} use the window in the specified tab
4520 page.
4521 {winnr} can be the window number or the |window-ID|.
4522 If {winnr} is -1 it is ignored and only the tabpage is used.
4523 Return 0 if the arguments are invalid.
4524 Examples: >
4525 if haslocaldir() == 1
4526 " window local directory case
4527 elseif haslocaldir() == 2
4528 " tab-local directory case
4529 else
4530 " global directory case
4531 endif
4532
4533 " current window
4534 :echo haslocaldir()
4535 :echo haslocaldir(0)
4536 :echo haslocaldir(0, 0)
4537 " window n in current tab page
4538 :echo haslocaldir(n)
4539 :echo haslocaldir(n, 0)
4540 " window n in tab page m
4541 :echo haslocaldir(n, m)
4542 " tab page m
4543 :echo haslocaldir(-1, m)
4544<
4545 Can also be used as a |method|: >
4546 GetWinnr()->haslocaldir()
4547
4548hasmapto({what} [, {mode} [, {abbr}]]) *hasmapto()*
4549 The result is a Number, which is TRUE if there is a mapping
4550 that contains {what} in somewhere in the rhs (what it is
4551 mapped to) and this mapping exists in one of the modes
4552 indicated by {mode}.
4553 The arguments {what} and {mode} are strings.
4554 When {abbr} is there and it is |TRUE| use abbreviations
4555 instead of mappings. Don't forget to specify Insert and/or
4556 Command-line mode.
4557 Both the global mappings and the mappings local to the current
4558 buffer are checked for a match.
4559 If no matching mapping is found FALSE is returned.
4560 The following characters are recognized in {mode}:
4561 n Normal mode
4562 v Visual and Select mode
4563 x Visual mode
4564 s Select mode
4565 o Operator-pending mode
4566 i Insert mode
4567 l Language-Argument ("r", "f", "t", etc.)
4568 c Command-line mode
4569 When {mode} is omitted, "nvo" is used.
4570
4571 This function is useful to check if a mapping already exists
4572 to a function in a Vim script. Example: >
4573 :if !hasmapto('\ABCdoit')
4574 : map <Leader>d \ABCdoit
4575 :endif
4576< This installs the mapping to "\ABCdoit" only if there isn't
4577 already a mapping to "\ABCdoit".
4578
4579 Can also be used as a |method|: >
4580 GetRHS()->hasmapto()
4581
4582histadd({history}, {item}) *histadd()*
4583 Add the String {item} to the history {history} which can be
4584 one of: *hist-names*
4585 "cmd" or ":" command line history
4586 "search" or "/" search pattern history
4587 "expr" or "=" typed expression history
4588 "input" or "@" input line history
4589 "debug" or ">" debug command history
4590 empty the current or last used history
4591 The {history} string does not need to be the whole name, one
4592 character is sufficient.
4593 If {item} does already exist in the history, it will be
4594 shifted to become the newest entry.
4595 The result is a Number: TRUE if the operation was successful,
4596 otherwise FALSE is returned.
4597
4598 Example: >
4599 :call histadd("input", strftime("%Y %b %d"))
4600 :let date=input("Enter date: ")
4601< This function is not available in the |sandbox|.
4602
4603 Can also be used as a |method|, the base is passed as the
4604 second argument: >
4605 GetHistory()->histadd('search')
4606
4607histdel({history} [, {item}]) *histdel()*
4608 Clear {history}, i.e. delete all its entries. See |hist-names|
4609 for the possible values of {history}.
4610
4611 If the parameter {item} evaluates to a String, it is used as a
4612 regular expression. All entries matching that expression will
4613 be removed from the history (if there are any).
4614 Upper/lowercase must match, unless "\c" is used |/\c|.
4615 If {item} evaluates to a Number, it will be interpreted as
4616 an index, see |:history-indexing|. The respective entry will
4617 be removed if it exists.
4618
4619 The result is TRUE for a successful operation, otherwise FALSE
4620 is returned.
4621
4622 Examples:
4623 Clear expression register history: >
4624 :call histdel("expr")
4625<
4626 Remove all entries starting with "*" from the search history: >
4627 :call histdel("/", '^\*')
4628<
4629 The following three are equivalent: >
4630 :call histdel("search", histnr("search"))
4631 :call histdel("search", -1)
Bram Moolenaarc51cf032022-02-26 12:25:45 +00004632 :call histdel("search", '^' .. histget("search", -1) .. '$')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004633<
4634 To delete the last search pattern and use the last-but-one for
4635 the "n" command and 'hlsearch': >
4636 :call histdel("search", -1)
4637 :let @/ = histget("search", -1)
4638<
4639 Can also be used as a |method|: >
4640 GetHistory()->histdel()
4641
4642histget({history} [, {index}]) *histget()*
4643 The result is a String, the entry with Number {index} from
4644 {history}. See |hist-names| for the possible values of
4645 {history}, and |:history-indexing| for {index}. If there is
4646 no such entry, an empty String is returned. When {index} is
4647 omitted, the most recent item from the history is used.
4648
4649 Examples:
4650 Redo the second last search from history. >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00004651 :execute '/' .. histget("search", -2)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004652
4653< Define an Ex command ":H {num}" that supports re-execution of
4654 the {num}th entry from the output of |:history|. >
4655 :command -nargs=1 H execute histget("cmd", 0+<args>)
4656<
4657 Can also be used as a |method|: >
4658 GetHistory()->histget()
4659
4660histnr({history}) *histnr()*
4661 The result is the Number of the current entry in {history}.
4662 See |hist-names| for the possible values of {history}.
4663 If an error occurred, -1 is returned.
4664
4665 Example: >
4666 :let inp_index = histnr("expr")
4667
4668< Can also be used as a |method|: >
4669 GetHistory()->histnr()
4670<
4671hlexists({name}) *hlexists()*
4672 The result is a Number, which is TRUE if a highlight group
4673 called {name} exists. This is when the group has been
4674 defined in some way. Not necessarily when highlighting has
4675 been defined for it, it may also have been used for a syntax
4676 item.
4677 *highlight_exists()*
4678 Obsolete name: highlight_exists().
4679
4680 Can also be used as a |method|: >
4681 GetName()->hlexists()
4682<
4683hlget([{name} [, {resolve}]]) *hlget()*
4684 Returns a List of all the highlight group attributes. If the
4685 optional {name} is specified, then returns a List with only
4686 the attributes of the specified highlight group. Returns an
4687 empty List if the highlight group {name} is not present.
4688
4689 If the optional {resolve} argument is set to v:true and the
4690 highlight group {name} is linked to another group, then the
4691 link is resolved recursively and the attributes of the
4692 resolved highlight group are returned.
4693
4694 Each entry in the returned List is a Dictionary with the
4695 following items:
4696 cleared boolean flag, set to v:true if the highlight
4697 group attributes are cleared or not yet
4698 specified. See |highlight-clear|.
4699 cterm cterm attributes. See |highlight-cterm|.
4700 ctermbg cterm background color.
4701 See |highlight-ctermbg|.
4702 ctermfg cterm foreground color.
4703 See |highlight-ctermfg|.
4704 ctermul cterm underline color. See |highlight-ctermul|.
4705 default boolean flag, set to v:true if the highlight
4706 group link is a default link. See
4707 |highlight-default|.
4708 font highlight group font. See |highlight-font|.
4709 gui gui attributes. See |highlight-gui|.
4710 guibg gui background color. See |highlight-guibg|.
4711 guifg gui foreground color. See |highlight-guifg|.
4712 guisp gui special color. See |highlight-guisp|.
4713 id highlight group ID.
4714 linksto linked highlight group name.
4715 See |:highlight-link|.
4716 name highlight group name. See |group-name|.
4717 start start terminal keycode. See |highlight-start|.
4718 stop stop terminal keycode. See |highlight-stop|.
4719 term term attributes. See |highlight-term|.
4720
4721 The 'term', 'cterm' and 'gui' items in the above Dictionary
4722 have a dictionary value with the following optional boolean
4723 items: 'bold', 'standout', 'underline', 'undercurl', 'italic',
4724 'reverse', 'inverse' and 'strikethrough'.
4725
4726 Example(s): >
4727 :echo hlget()
4728 :echo hlget('ModeMsg')
4729 :echo hlget('Number', v:true)
4730<
4731 Can also be used as a |method|: >
4732 GetName()->hlget()
4733<
4734hlset({list}) *hlset()*
4735 Creates or modifies the attributes of a List of highlight
4736 groups. Each item in {list} is a dictionary containing the
4737 attributes of a highlight group. See |hlget()| for the list of
4738 supported items in this dictionary.
4739
4740 In addition to the items described in |hlget()|, the following
4741 additional items are supported in the dictionary:
4742
4743 force boolean flag to force the creation of
4744 a link for an existing highlight group
4745 with attributes.
4746
4747 The highlight group is identified using the 'name' item and
4748 the 'id' item (if supplied) is ignored. If a highlight group
4749 with a specified name doesn't exist, then it is created.
4750 Otherwise the attributes of an existing highlight group are
4751 modified.
4752
4753 If an empty dictionary value is used for the 'term' or 'cterm'
4754 or 'gui' entries, then the corresponding attributes are
4755 cleared. If the 'cleared' item is set to v:true, then all the
4756 attributes of the highlight group are cleared.
4757
4758 The 'linksto' item can be used to link a highlight group to
4759 another highlight group. See |:highlight-link|.
4760
4761 Returns zero for success, -1 for failure.
4762
4763 Example(s): >
4764 " add bold attribute to the Visual highlight group
4765 :call hlset([#{name: 'Visual',
4766 \ term: #{reverse: 1 , bold: 1}}])
4767 :call hlset([#{name: 'Type', guifg: 'DarkGreen'}])
4768 :let l = hlget()
4769 :call hlset(l)
4770 " clear the Search highlight group
4771 :call hlset([#{name: 'Search', cleared: v:true}])
4772 " clear the 'term' attributes for a highlight group
4773 :call hlset([#{name: 'Title', term: {}}])
4774 " create the MyHlg group linking it to DiffAdd
4775 :call hlset([#{name: 'MyHlg', linksto: 'DiffAdd'}])
4776 " remove the MyHlg group link
4777 :call hlset([#{name: 'MyHlg', linksto: 'NONE'}])
4778 " clear the attributes and a link
4779 :call hlset([#{name: 'MyHlg', cleared: v:true,
4780 \ linksto: 'NONE'}])
4781<
4782 Can also be used as a |method|: >
4783 GetAttrList()->hlset()
4784<
4785 *hlID()*
4786hlID({name}) The result is a Number, which is the ID of the highlight group
4787 with name {name}. When the highlight group doesn't exist,
4788 zero is returned.
4789 This can be used to retrieve information about the highlight
4790 group. For example, to get the background color of the
4791 "Comment" group: >
4792 :echo synIDattr(synIDtrans(hlID("Comment")), "bg")
4793< *highlightID()*
4794 Obsolete name: highlightID().
4795
4796 Can also be used as a |method|: >
4797 GetName()->hlID()
4798
4799hostname() *hostname()*
4800 The result is a String, which is the name of the machine on
4801 which Vim is currently running. Machine names greater than
4802 256 characters long are truncated.
4803
4804iconv({string}, {from}, {to}) *iconv()*
4805 The result is a String, which is the text {string} converted
4806 from encoding {from} to encoding {to}.
4807 When the conversion completely fails an empty string is
4808 returned. When some characters could not be converted they
4809 are replaced with "?".
4810 The encoding names are whatever the iconv() library function
4811 can accept, see ":!man 3 iconv".
4812 Most conversions require Vim to be compiled with the |+iconv|
4813 feature. Otherwise only UTF-8 to latin1 conversion and back
4814 can be done.
4815 This can be used to display messages with special characters,
4816 no matter what 'encoding' is set to. Write the message in
4817 UTF-8 and use: >
4818 echo iconv(utf8_str, "utf-8", &enc)
4819< Note that Vim uses UTF-8 for all Unicode encodings, conversion
4820 from/to UCS-2 is automatically changed to use UTF-8. You
4821 cannot use UCS-2 in a string anyway, because of the NUL bytes.
4822
4823 Can also be used as a |method|: >
4824 GetText()->iconv('latin1', 'utf-8')
4825<
4826 *indent()*
4827indent({lnum}) The result is a Number, which is indent of line {lnum} in the
4828 current buffer. The indent is counted in spaces, the value
4829 of 'tabstop' is relevant. {lnum} is used just like in
4830 |getline()|.
4831 When {lnum} is invalid -1 is returned. In |Vim9| script an
4832 error is given.
4833
4834 Can also be used as a |method|: >
4835 GetLnum()->indent()
4836
4837index({object}, {expr} [, {start} [, {ic}]]) *index()*
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01004838 Find {expr} in {object} and return its index. See
Yegappan Lakshmanan3fbf6cd2022-08-13 21:35:13 +01004839 |indexof()| for using a lambda to select the item.
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01004840
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004841 If {object} is a |List| return the lowest index where the item
4842 has a value equal to {expr}. There is no automatic
4843 conversion, so the String "4" is different from the Number 4.
4844 And the number 4 is different from the Float 4.0. The value
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01004845 of 'ignorecase' is not used here, case matters as indicated by
4846 the {ic} argument.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004847
4848 If {object} is |Blob| return the lowest index where the byte
4849 value is equal to {expr}.
4850
4851 If {start} is given then start looking at the item with index
4852 {start} (may be negative for an item relative to the end).
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01004853
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004854 When {ic} is given and it is |TRUE|, ignore case. Otherwise
4855 case must match.
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01004856
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004857 -1 is returned when {expr} is not found in {object}.
4858 Example: >
4859 :let idx = index(words, "the")
4860 :if index(numbers, 123) >= 0
4861
4862< Can also be used as a |method|: >
4863 GetObject()->index(what)
4864
Yegappan Lakshmanan3fbf6cd2022-08-13 21:35:13 +01004865indexof({object}, {expr} [, {opts}]) *indexof()*
4866 Returns the index of an item in {object} where {expr} is
4867 v:true. {object} must be a |List| or a |Blob|.
4868
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01004869 If {object} is a |List|, evaluate {expr} for each item in the
Yegappan Lakshmanan3fbf6cd2022-08-13 21:35:13 +01004870 List until the expression is v:true and return the index of
4871 this item.
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01004872
4873 If {object} is a |Blob| evaluate {expr} for each byte in the
Yegappan Lakshmanan3fbf6cd2022-08-13 21:35:13 +01004874 Blob until the expression is v:true and return the index of
4875 this byte.
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01004876
4877 {expr} must be a |string| or |Funcref|.
4878
4879 If {expr} is a |string|: If {object} is a |List|, inside
4880 {expr} |v:key| has the index of the current List item and
4881 |v:val| has the value of the item. If {object} is a |Blob|,
4882 inside {expr} |v:key| has the index of the current byte and
4883 |v:val| has the byte value.
4884
4885 If {expr} is a |Funcref| it must take two arguments:
4886 1. the key or the index of the current item.
4887 2. the value of the current item.
4888 The function must return |TRUE| if the item is found and the
4889 search should stop.
4890
Yegappan Lakshmanan3fbf6cd2022-08-13 21:35:13 +01004891 The optional argument {opts} is a Dict and supports the
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01004892 following items:
Yegappan Lakshmanan3fbf6cd2022-08-13 21:35:13 +01004893 startidx start evaluating {expr} at the item with this
4894 index; may be negative for an item relative to
4895 the end
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01004896 Returns -1 when {expr} evaluates to v:false for all the items.
4897 Example: >
Yegappan Lakshmanan3fbf6cd2022-08-13 21:35:13 +01004898 :let l = [#{n: 10}, #{n: 20}, #{n: 30}]
4899 :echo indexof(l, "v:val.n == 20")
4900 :echo indexof(l, {i, v -> v.n == 30})
4901 :echo indexof(l, "v:val.n == 20", #{startidx: 1})
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01004902
4903< Can also be used as a |method|: >
4904 mylist->indexof(expr)
4905
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004906input({prompt} [, {text} [, {completion}]]) *input()*
4907 The result is a String, which is whatever the user typed on
4908 the command-line. The {prompt} argument is either a prompt
4909 string, or a blank string (for no prompt). A '\n' can be used
4910 in the prompt to start a new line.
4911 The highlighting set with |:echohl| is used for the prompt.
4912 The input is entered just like a command-line, with the same
4913 editing commands and mappings. There is a separate history
4914 for lines typed for input().
4915 Example: >
4916 :if input("Coffee or beer? ") == "beer"
4917 : echo "Cheers!"
4918 :endif
4919<
4920 If the optional {text} argument is present and not empty, this
4921 is used for the default reply, as if the user typed this.
4922 Example: >
4923 :let color = input("Color? ", "white")
4924
4925< The optional {completion} argument specifies the type of
4926 completion supported for the input. Without it completion is
4927 not performed. The supported completion types are the same as
4928 that can be supplied to a user-defined command using the
4929 "-complete=" argument. Refer to |:command-completion| for
4930 more information. Example: >
4931 let fname = input("File: ", "", "file")
4932<
4933 NOTE: This function must not be used in a startup file, for
4934 the versions that only run in GUI mode (e.g., the Win32 GUI).
4935 Note: When input() is called from within a mapping it will
4936 consume remaining characters from that mapping, because a
4937 mapping is handled like the characters were typed.
4938 Use |inputsave()| before input() and |inputrestore()|
4939 after input() to avoid that. Another solution is to avoid
4940 that further characters follow in the mapping, e.g., by using
4941 |:execute| or |:normal|.
4942
4943 Example with a mapping: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00004944 :nmap \x :call GetFoo()<CR>:exe "/" .. Foo<CR>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004945 :function GetFoo()
4946 : call inputsave()
4947 : let g:Foo = input("enter search pattern: ")
4948 : call inputrestore()
4949 :endfunction
4950
4951< Can also be used as a |method|: >
4952 GetPrompt()->input()
4953
4954inputdialog({prompt} [, {text} [, {cancelreturn}]]) *inputdialog()*
4955 Like |input()|, but when the GUI is running and text dialogs
4956 are supported, a dialog window pops up to input the text.
4957 Example: >
4958 :let n = inputdialog("value for shiftwidth", shiftwidth())
4959 :if n != ""
4960 : let &sw = n
4961 :endif
4962< When the dialog is cancelled {cancelreturn} is returned. When
4963 omitted an empty string is returned.
4964 Hitting <Enter> works like pressing the OK button. Hitting
4965 <Esc> works like pressing the Cancel button.
4966 NOTE: Command-line completion is not supported.
4967
4968 Can also be used as a |method|: >
4969 GetPrompt()->inputdialog()
4970
4971inputlist({textlist}) *inputlist()*
4972 {textlist} must be a |List| of strings. This |List| is
4973 displayed, one string per line. The user will be prompted to
4974 enter a number, which is returned.
4975 The user can also select an item by clicking on it with the
4976 mouse, if the mouse is enabled in the command line ('mouse' is
4977 "a" or includes "c"). For the first string 0 is returned.
4978 When clicking above the first item a negative number is
4979 returned. When clicking on the prompt one more than the
4980 length of {textlist} is returned.
4981 Make sure {textlist} has less than 'lines' entries, otherwise
4982 it won't work. It's a good idea to put the entry number at
4983 the start of the string. And put a prompt in the first item.
4984 Example: >
4985 let color = inputlist(['Select color:', '1. red',
4986 \ '2. green', '3. blue'])
4987
4988< Can also be used as a |method|: >
4989 GetChoices()->inputlist()
4990
4991inputrestore() *inputrestore()*
4992 Restore typeahead that was saved with a previous |inputsave()|.
4993 Should be called the same number of times inputsave() is
4994 called. Calling it more often is harmless though.
4995 Returns TRUE when there is nothing to restore, FALSE otherwise.
4996
4997inputsave() *inputsave()*
4998 Preserve typeahead (also from mappings) and clear it, so that
4999 a following prompt gets input from the user. Should be
5000 followed by a matching inputrestore() after the prompt. Can
5001 be used several times, in which case there must be just as
5002 many inputrestore() calls.
5003 Returns TRUE when out of memory, FALSE otherwise.
5004
5005inputsecret({prompt} [, {text}]) *inputsecret()*
5006 This function acts much like the |input()| function with but
5007 two exceptions:
5008 a) the user's response will be displayed as a sequence of
5009 asterisks ("*") thereby keeping the entry secret, and
5010 b) the user's response will not be recorded on the input
5011 |history| stack.
5012 The result is a String, which is whatever the user actually
5013 typed on the command-line in response to the issued prompt.
5014 NOTE: Command-line completion is not supported.
5015
5016 Can also be used as a |method|: >
5017 GetPrompt()->inputsecret()
5018
5019insert({object}, {item} [, {idx}]) *insert()*
5020 When {object} is a |List| or a |Blob| insert {item} at the start
5021 of it.
5022
5023 If {idx} is specified insert {item} before the item with index
5024 {idx}. If {idx} is zero it goes before the first item, just
5025 like omitting {idx}. A negative {idx} is also possible, see
5026 |list-index|. -1 inserts just before the last item.
5027
5028 Returns the resulting |List| or |Blob|. Examples: >
5029 :let mylist = insert([2, 3, 5], 1)
5030 :call insert(mylist, 4, -1)
5031 :call insert(mylist, 6, len(mylist))
5032< The last example can be done simpler with |add()|.
5033 Note that when {item} is a |List| it is inserted as a single
5034 item. Use |extend()| to concatenate |Lists|.
5035
5036 Can also be used as a |method|: >
5037 mylist->insert(item)
5038
5039interrupt() *interrupt()*
5040 Interrupt script execution. It works more or less like the
5041 user typing CTRL-C, most commands won't execute and control
5042 returns to the user. This is useful to abort execution
5043 from lower down, e.g. in an autocommand. Example: >
5044 :function s:check_typoname(file)
5045 : if fnamemodify(a:file, ':t') == '['
5046 : echomsg 'Maybe typo'
5047 : call interrupt()
5048 : endif
5049 :endfunction
5050 :au BufWritePre * call s:check_typoname(expand('<amatch>'))
5051
5052invert({expr}) *invert()*
5053 Bitwise invert. The argument is converted to a number. A
5054 List, Dict or Float argument causes an error. Example: >
5055 :let bits = invert(bits)
5056< Can also be used as a |method|: >
5057 :let bits = bits->invert()
5058
Bram Moolenaar8a3b8052022-06-26 12:21:15 +01005059isabsolutepath({path}) *isabsolutepath()*
LemonBoydca1d402022-04-28 15:26:33 +01005060 The result is a Number, which is |TRUE| when {path} is an
5061 absolute path.
Bram Moolenaar8a3b8052022-06-26 12:21:15 +01005062 On Unix, a path is considered absolute when it starts with '/'.
LemonBoydca1d402022-04-28 15:26:33 +01005063 On MS-Windows, it is considered absolute when it starts with an
5064 optional drive prefix and is followed by a '\' or '/'. UNC paths
5065 are always absolute.
5066 Example: >
5067 echo isabsolutepath('/usr/share/') " 1
5068 echo isabsolutepath('./foobar') " 0
5069 echo isabsolutepath('C:\Windows') " 1
5070 echo isabsolutepath('foobar') " 0
5071 echo isabsolutepath('\\remote\file') " 1
Bram Moolenaar8a3b8052022-06-26 12:21:15 +01005072<
LemonBoydca1d402022-04-28 15:26:33 +01005073 Can also be used as a |method|: >
5074 GetName()->isabsolutepath()
5075
5076
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005077isdirectory({directory}) *isdirectory()*
5078 The result is a Number, which is |TRUE| when a directory
5079 with the name {directory} exists. If {directory} doesn't
5080 exist, or isn't a directory, the result is |FALSE|. {directory}
5081 is any expression, which is used as a String.
5082
5083 Can also be used as a |method|: >
5084 GetName()->isdirectory()
5085
5086isinf({expr}) *isinf()*
5087 Return 1 if {expr} is a positive infinity, or -1 a negative
5088 infinity, otherwise 0. >
5089 :echo isinf(1.0 / 0.0)
5090< 1 >
5091 :echo isinf(-1.0 / 0.0)
5092< -1
5093
5094 Can also be used as a |method|: >
5095 Compute()->isinf()
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005096
5097islocked({expr}) *islocked()* *E786*
5098 The result is a Number, which is |TRUE| when {expr} is the
5099 name of a locked variable.
5100 The string argument {expr} must be the name of a variable,
5101 |List| item or |Dictionary| entry, not the variable itself!
5102 Example: >
5103 :let alist = [0, ['a', 'b'], 2, 3]
5104 :lockvar 1 alist
5105 :echo islocked('alist') " 1
5106 :echo islocked('alist[1]') " 0
5107
Bram Moolenaar9da17d72022-02-09 21:50:44 +00005108< When {expr} is a variable that does not exist -1 is returned.
5109 If {expr} uses a range, list or dict index that is out of
5110 range or does not exist you get an error message. Use
5111 |exists()| to check for existence.
5112 In Vim9 script it does not work for local function variables.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005113
5114 Can also be used as a |method|: >
5115 GetName()->islocked()
5116
5117isnan({expr}) *isnan()*
5118 Return |TRUE| if {expr} is a float with value NaN. >
5119 echo isnan(0.0 / 0.0)
5120< 1
5121
5122 Can also be used as a |method|: >
5123 Compute()->isnan()
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005124
5125items({dict}) *items()*
5126 Return a |List| with all the key-value pairs of {dict}. Each
5127 |List| item is a list with two items: the key of a {dict}
5128 entry and the value of this entry. The |List| is in arbitrary
5129 order. Also see |keys()| and |values()|.
5130 Example: >
5131 for [key, value] in items(mydict)
Bram Moolenaarc51cf032022-02-26 12:25:45 +00005132 echo key .. ': ' .. value
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005133 endfor
5134
5135< Can also be used as a |method|: >
5136 mydict->items()
5137
5138job_ functions are documented here: |job-functions-details|
5139
5140
5141join({list} [, {sep}]) *join()*
5142 Join the items in {list} together into one String.
5143 When {sep} is specified it is put in between the items. If
5144 {sep} is omitted a single space is used.
5145 Note that {sep} is not added at the end. You might want to
5146 add it there too: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00005147 let lines = join(mylist, "\n") .. "\n"
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005148< String items are used as-is. |Lists| and |Dictionaries| are
5149 converted into a string like with |string()|.
5150 The opposite function is |split()|.
5151
5152 Can also be used as a |method|: >
5153 mylist->join()
5154
5155js_decode({string}) *js_decode()*
5156 This is similar to |json_decode()| with these differences:
5157 - Object key names do not have to be in quotes.
5158 - Strings can be in single quotes.
5159 - Empty items in an array (between two commas) are allowed and
5160 result in v:none items.
5161
5162 Can also be used as a |method|: >
5163 ReadObject()->js_decode()
5164
5165js_encode({expr}) *js_encode()*
5166 This is similar to |json_encode()| with these differences:
5167 - Object key names are not in quotes.
5168 - v:none items in an array result in an empty item between
5169 commas.
5170 For example, the Vim object:
5171 [1,v:none,{"one":1},v:none] ~
5172 Will be encoded as:
5173 [1,,{one:1},,] ~
5174 While json_encode() would produce:
5175 [1,null,{"one":1},null] ~
5176 This encoding is valid for JavaScript. It is more efficient
5177 than JSON, especially when using an array with optional items.
5178
5179 Can also be used as a |method|: >
5180 GetObject()->js_encode()
5181
Bram Moolenaar2f0936c2022-01-08 21:51:59 +00005182json_decode({string}) *json_decode()* *E491*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005183 This parses a JSON formatted string and returns the equivalent
5184 in Vim values. See |json_encode()| for the relation between
5185 JSON and Vim values.
5186 The decoding is permissive:
5187 - A trailing comma in an array and object is ignored, e.g.
5188 "[1, 2, ]" is the same as "[1, 2]".
5189 - Integer keys are accepted in objects, e.g. {1:2} is the
5190 same as {"1":2}.
5191 - More floating point numbers are recognized, e.g. "1." for
5192 "1.0", or "001.2" for "1.2". Special floating point values
5193 "Infinity", "-Infinity" and "NaN" (capitalization ignored)
5194 are accepted.
5195 - Leading zeroes in integer numbers are ignored, e.g. "012"
5196 for "12" or "-012" for "-12".
5197 - Capitalization is ignored in literal names null, true or
5198 false, e.g. "NULL" for "null", "True" for "true".
5199 - Control characters U+0000 through U+001F which are not
5200 escaped in strings are accepted, e.g. " " (tab
5201 character in string) for "\t".
5202 - An empty JSON expression or made of only spaces is accepted
5203 and results in v:none.
5204 - Backslash in an invalid 2-character sequence escape is
5205 ignored, e.g. "\a" is decoded as "a".
5206 - A correct surrogate pair in JSON strings should normally be
5207 a 12 character sequence such as "\uD834\uDD1E", but
5208 json_decode() silently accepts truncated surrogate pairs
5209 such as "\uD834" or "\uD834\u"
5210 *E938*
5211 A duplicate key in an object, valid in rfc7159, is not
5212 accepted by json_decode() as the result must be a valid Vim
5213 type, e.g. this fails: {"a":"b", "a":"c"}
5214
5215 Can also be used as a |method|: >
5216 ReadObject()->json_decode()
5217
5218json_encode({expr}) *json_encode()*
5219 Encode {expr} as JSON and return this as a string.
5220 The encoding is specified in:
5221 https://tools.ietf.org/html/rfc7159.html
Bram Moolenaara2baa732022-02-04 16:09:54 +00005222 Vim values are converted as follows: *E1161*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005223 |Number| decimal number
5224 |Float| floating point number
5225 Float nan "NaN"
5226 Float inf "Infinity"
5227 Float -inf "-Infinity"
5228 |String| in double quotes (possibly null)
5229 |Funcref| not possible, error
5230 |List| as an array (possibly null); when
5231 used recursively: []
5232 |Dict| as an object (possibly null); when
5233 used recursively: {}
5234 |Blob| as an array of the individual bytes
5235 v:false "false"
5236 v:true "true"
5237 v:none "null"
5238 v:null "null"
5239 Note that NaN and Infinity are passed on as values. This is
5240 missing in the JSON standard, but several implementations do
5241 allow it. If not then you will get an error.
Bram Moolenaarcbaff5e2022-04-08 17:45:08 +01005242 If a string contains an illegal character then the replacement
5243 character 0xfffd is used.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005244
5245 Can also be used as a |method|: >
5246 GetObject()->json_encode()
5247
5248keys({dict}) *keys()*
5249 Return a |List| with all the keys of {dict}. The |List| is in
5250 arbitrary order. Also see |items()| and |values()|.
5251
5252 Can also be used as a |method|: >
5253 mydict->keys()
5254
zeertzjqcdc83932022-09-12 13:38:41 +01005255keytrans({string}) *keytrans()*
5256 Turn the internal byte representation of keys into a form that
5257 can be used for |:map|. E.g. >
5258 :let xx = "\<C-Home>"
5259 :echo keytrans(xx)
5260< <C-Home>
5261
5262 Can also be used as a |method|: >
5263 "\<C-Home>"->keytrans()
5264
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005265< *len()* *E701*
5266len({expr}) The result is a Number, which is the length of the argument.
5267 When {expr} is a String or a Number the length in bytes is
5268 used, as with |strlen()|.
5269 When {expr} is a |List| the number of items in the |List| is
5270 returned.
5271 When {expr} is a |Blob| the number of bytes is returned.
5272 When {expr} is a |Dictionary| the number of entries in the
5273 |Dictionary| is returned.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01005274 Otherwise an error is given and returns zero.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005275
5276 Can also be used as a |method|: >
5277 mylist->len()
5278
5279< *libcall()* *E364* *E368*
5280libcall({libname}, {funcname}, {argument})
5281 Call function {funcname} in the run-time library {libname}
5282 with single argument {argument}.
5283 This is useful to call functions in a library that you
5284 especially made to be used with Vim. Since only one argument
5285 is possible, calling standard library functions is rather
5286 limited.
5287 The result is the String returned by the function. If the
5288 function returns NULL, this will appear as an empty string ""
5289 to Vim.
5290 If the function returns a number, use libcallnr()!
5291 If {argument} is a number, it is passed to the function as an
5292 int; if {argument} is a string, it is passed as a
5293 null-terminated string.
5294 This function will fail in |restricted-mode|.
5295
5296 libcall() allows you to write your own 'plug-in' extensions to
5297 Vim without having to recompile the program. It is NOT a
5298 means to call system functions! If you try to do so Vim will
5299 very probably crash.
5300
5301 For Win32, the functions you write must be placed in a DLL
5302 and use the normal C calling convention (NOT Pascal which is
5303 used in Windows System DLLs). The function must take exactly
5304 one parameter, either a character pointer or a long integer,
5305 and must return a character pointer or NULL. The character
5306 pointer returned must point to memory that will remain valid
5307 after the function has returned (e.g. in static data in the
5308 DLL). If it points to allocated memory, that memory will
5309 leak away. Using a static buffer in the function should work,
5310 it's then freed when the DLL is unloaded.
5311
5312 WARNING: If the function returns a non-valid pointer, Vim may
5313 crash! This also happens if the function returns a number,
5314 because Vim thinks it's a pointer.
5315 For Win32 systems, {libname} should be the filename of the DLL
5316 without the ".DLL" suffix. A full path is only required if
5317 the DLL is not in the usual places.
5318 For Unix: When compiling your own plugins, remember that the
5319 object code must be compiled as position-independent ('PIC').
5320 {only in Win32 and some Unix versions, when the |+libcall|
5321 feature is present}
5322 Examples: >
5323 :echo libcall("libc.so", "getenv", "HOME")
5324
5325< Can also be used as a |method|, the base is passed as the
5326 third argument: >
5327 GetValue()->libcall("libc.so", "getenv")
5328<
5329 *libcallnr()*
5330libcallnr({libname}, {funcname}, {argument})
5331 Just like |libcall()|, but used for a function that returns an
5332 int instead of a string.
5333 {only in Win32 on some Unix versions, when the |+libcall|
5334 feature is present}
5335 Examples: >
5336 :echo libcallnr("/usr/lib/libc.so", "getpid", "")
5337 :call libcallnr("libc.so", "printf", "Hello World!\n")
5338 :call libcallnr("libc.so", "sleep", 10)
5339<
5340 Can also be used as a |method|, the base is passed as the
5341 third argument: >
5342 GetValue()->libcallnr("libc.so", "printf")
5343<
5344
5345line({expr} [, {winid}]) *line()*
5346 The result is a Number, which is the line number of the file
5347 position given with {expr}. The {expr} argument is a string.
Bram Moolenaara2baa732022-02-04 16:09:54 +00005348 The accepted positions are: *E1209*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005349 . the cursor position
5350 $ the last line in the current buffer
5351 'x position of mark x (if the mark is not set, 0 is
5352 returned)
5353 w0 first line visible in current window (one if the
5354 display isn't updated, e.g. in silent Ex mode)
5355 w$ last line visible in current window (this is one
5356 less than "w0" if no lines are visible)
5357 v In Visual mode: the start of the Visual area (the
5358 cursor is the end). When not in Visual mode
5359 returns the cursor position. Differs from |'<| in
5360 that it's updated right away.
5361 Note that a mark in another file can be used. The line number
5362 then applies to another buffer.
5363 To get the column number use |col()|. To get both use
5364 |getpos()|.
5365 With the optional {winid} argument the values are obtained for
5366 that window instead of the current window.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01005367 Returns 0 for invalid values of {expr} and {winid}.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005368 Examples: >
5369 line(".") line number of the cursor
5370 line(".", winid) idem, in window "winid"
5371 line("'t") line number of mark t
Bram Moolenaarc51cf032022-02-26 12:25:45 +00005372 line("'" .. marker) line number of mark marker
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005373<
5374 To jump to the last known position when opening a file see
5375 |last-position-jump|.
5376
5377 Can also be used as a |method|: >
5378 GetValue()->line()
5379
5380line2byte({lnum}) *line2byte()*
5381 Return the byte count from the start of the buffer for line
5382 {lnum}. This includes the end-of-line character, depending on
5383 the 'fileformat' option for the current buffer. The first
5384 line returns 1. 'encoding' matters, 'fileencoding' is ignored.
5385 This can also be used to get the byte count for the line just
5386 below the last line: >
5387 line2byte(line("$") + 1)
5388< This is the buffer size plus one. If 'fileencoding' is empty
5389 it is the file size plus one. {lnum} is used like with
5390 |getline()|. When {lnum} is invalid, or the |+byte_offset|
5391 feature has been disabled at compile time, -1 is returned.
5392 Also see |byte2line()|, |go| and |:goto|.
5393
5394 Can also be used as a |method|: >
5395 GetLnum()->line2byte()
5396
5397lispindent({lnum}) *lispindent()*
5398 Get the amount of indent for line {lnum} according the lisp
5399 indenting rules, as with 'lisp'.
5400 The indent is counted in spaces, the value of 'tabstop' is
5401 relevant. {lnum} is used just like in |getline()|.
Bram Moolenaar8e145b82022-05-21 20:17:31 +01005402 When {lnum} is invalid -1 is returned. In |Vim9| script an
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005403 error is given.
5404
5405 Can also be used as a |method|: >
5406 GetLnum()->lispindent()
5407
5408list2blob({list}) *list2blob()*
5409 Return a Blob concatenating all the number values in {list}.
5410 Examples: >
5411 list2blob([1, 2, 3, 4]) returns 0z01020304
5412 list2blob([]) returns 0z
5413< Returns an empty Blob on error. If one of the numbers is
5414 negative or more than 255 error *E1239* is given.
5415
5416 |blob2list()| does the opposite.
5417
5418 Can also be used as a |method|: >
5419 GetList()->list2blob()
5420
5421list2str({list} [, {utf8}]) *list2str()*
5422 Convert each number in {list} to a character string can
5423 concatenate them all. Examples: >
5424 list2str([32]) returns " "
5425 list2str([65, 66, 67]) returns "ABC"
5426< The same can be done (slowly) with: >
5427 join(map(list, {nr, val -> nr2char(val)}), '')
5428< |str2list()| does the opposite.
5429
5430 When {utf8} is omitted or zero, the current 'encoding' is used.
5431 When {utf8} is TRUE, always return UTF-8 characters.
5432 With UTF-8 composing characters work as expected: >
5433 list2str([97, 769]) returns "á"
5434<
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01005435 Returns an empty string on error.
5436
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005437 Can also be used as a |method|: >
5438 GetList()->list2str()
5439
5440listener_add({callback} [, {buf}]) *listener_add()*
5441 Add a callback function that will be invoked when changes have
5442 been made to buffer {buf}.
5443 {buf} refers to a buffer name or number. For the accepted
5444 values, see |bufname()|. When {buf} is omitted the current
5445 buffer is used.
5446 Returns a unique ID that can be passed to |listener_remove()|.
5447
5448 The {callback} is invoked with five arguments:
Bram Moolenaar944697a2022-02-20 19:48:20 +00005449 bufnr the buffer that was changed
5450 start first changed line number
5451 end first line number below the change
5452 added number of lines added, negative if lines were
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005453 deleted
Bram Moolenaar944697a2022-02-20 19:48:20 +00005454 changes a List of items with details about the changes
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005455
5456 Example: >
5457 func Listener(bufnr, start, end, added, changes)
5458 echo 'lines ' .. a:start .. ' until ' .. a:end .. ' changed'
5459 endfunc
5460 call listener_add('Listener', bufnr)
5461
Bram Moolenaar944697a2022-02-20 19:48:20 +00005462< The List cannot be changed. Each item in "changes" is a
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005463 dictionary with these entries:
5464 lnum the first line number of the change
5465 end the first line below the change
5466 added number of lines added; negative if lines were
5467 deleted
5468 col first column in "lnum" that was affected by
5469 the change; one if unknown or the whole line
5470 was affected; this is a byte index, first
5471 character has a value of one.
Bram Moolenaar3c053a12022-10-16 13:11:12 +01005472 When lines are inserted (not when a line is split, e.g. by
5473 typing CR in Insert mode) the values are:
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005474 lnum line above which the new line is added
5475 end equal to "lnum"
5476 added number of lines inserted
5477 col 1
5478 When lines are deleted the values are:
5479 lnum the first deleted line
5480 end the line below the first deleted line, before
5481 the deletion was done
5482 added negative, number of lines deleted
5483 col 1
5484 When lines are changed:
5485 lnum the first changed line
5486 end the line below the last changed line
5487 added 0
5488 col first column with a change or 1
5489
5490 The entries are in the order the changes were made, thus the
5491 most recent change is at the end. The line numbers are valid
5492 when the callback is invoked, but later changes may make them
5493 invalid, thus keeping a copy for later might not work.
5494
5495 The {callback} is invoked just before the screen is updated,
5496 when |listener_flush()| is called or when a change is being
5497 made that changes the line count in a way it causes a line
5498 number in the list of changes to become invalid.
5499
5500 The {callback} is invoked with the text locked, see
5501 |textlock|. If you do need to make changes to the buffer, use
5502 a timer to do this later |timer_start()|.
5503
5504 The {callback} is not invoked when the buffer is first loaded.
5505 Use the |BufReadPost| autocmd event to handle the initial text
5506 of a buffer.
5507 The {callback} is also not invoked when the buffer is
5508 unloaded, use the |BufUnload| autocmd event for that.
5509
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01005510 Returns zero if {callback} or {buf} is invalid.
5511
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005512 Can also be used as a |method|, the base is passed as the
5513 second argument: >
5514 GetBuffer()->listener_add(callback)
5515
5516listener_flush([{buf}]) *listener_flush()*
5517 Invoke listener callbacks for buffer {buf}. If there are no
5518 pending changes then no callbacks are invoked.
5519
5520 {buf} refers to a buffer name or number. For the accepted
5521 values, see |bufname()|. When {buf} is omitted the current
5522 buffer is used.
5523
5524 Can also be used as a |method|: >
5525 GetBuffer()->listener_flush()
5526
5527listener_remove({id}) *listener_remove()*
5528 Remove a listener previously added with listener_add().
5529 Returns FALSE when {id} could not be found, TRUE when {id} was
5530 removed.
5531
5532 Can also be used as a |method|: >
5533 GetListenerId()->listener_remove()
5534
5535localtime() *localtime()*
5536 Return the current time, measured as seconds since 1st Jan
5537 1970. See also |strftime()|, |strptime()| and |getftime()|.
5538
5539
5540log({expr}) *log()*
5541 Return the natural logarithm (base e) of {expr} as a |Float|.
5542 {expr} must evaluate to a |Float| or a |Number| in the range
5543 (0, inf].
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01005544 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005545 Examples: >
5546 :echo log(10)
5547< 2.302585 >
5548 :echo log(exp(5))
5549< 5.0
5550
5551 Can also be used as a |method|: >
5552 Compute()->log()
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005553
5554
5555log10({expr}) *log10()*
5556 Return the logarithm of Float {expr} to base 10 as a |Float|.
5557 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01005558 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005559 Examples: >
5560 :echo log10(1000)
5561< 3.0 >
5562 :echo log10(0.01)
5563< -2.0
5564
5565 Can also be used as a |method|: >
5566 Compute()->log10()
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005567
5568luaeval({expr} [, {expr}]) *luaeval()*
5569 Evaluate Lua expression {expr} and return its result converted
5570 to Vim data structures. Second {expr} may hold additional
5571 argument accessible as _A inside first {expr}.
5572 Strings are returned as they are.
5573 Boolean objects are converted to numbers.
Bram Moolenaar73e28dc2022-09-17 21:08:33 +01005574 Numbers are converted to |Float| values.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005575 Dictionaries and lists obtained by vim.eval() are returned
5576 as-is.
5577 Other objects are returned as zero without any errors.
5578 See |lua-luaeval| for more details.
5579 Note that in a `:def` function local variables are not visible
5580 to {expr}.
5581
5582 Can also be used as a |method|: >
5583 GetExpr()->luaeval()
5584
5585< {only available when compiled with the |+lua| feature}
5586
5587map({expr1}, {expr2}) *map()*
5588 {expr1} must be a |List|, |String|, |Blob| or |Dictionary|.
Bram Moolenaar944697a2022-02-20 19:48:20 +00005589 When {expr1} is a |List| or |Dictionary|, replace each
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005590 item in {expr1} with the result of evaluating {expr2}.
5591 For a |Blob| each byte is replaced.
5592 For a |String|, each character, including composing
5593 characters, is replaced.
5594 If the item type changes you may want to use |mapnew()| to
5595 create a new List or Dictionary. This is required when using
5596 Vim9 script.
5597
5598 {expr2} must be a |String| or |Funcref|.
5599
5600 If {expr2} is a |String|, inside {expr2} |v:val| has the value
5601 of the current item. For a |Dictionary| |v:key| has the key
5602 of the current item and for a |List| |v:key| has the index of
5603 the current item. For a |Blob| |v:key| has the index of the
5604 current byte. For a |String| |v:key| has the index of the
5605 current character.
5606 Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00005607 :call map(mylist, '"> " .. v:val .. " <"')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005608< This puts "> " before and " <" after each item in "mylist".
5609
5610 Note that {expr2} is the result of an expression and is then
5611 used as an expression again. Often it is good to use a
5612 |literal-string| to avoid having to double backslashes. You
5613 still have to double ' quotes
5614
5615 If {expr2} is a |Funcref| it is called with two arguments:
5616 1. The key or the index of the current item.
5617 2. the value of the current item.
Bram Moolenaarb59ae592022-11-23 23:46:31 +00005618 With a legacy script lambda you don't get an error if it only
5619 accepts one argument, but with a Vim9 lambda you get "E1106:
5620 One argument too many", the number of arguments must match.
5621
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005622 The function must return the new value of the item. Example
5623 that changes each value by "key-value": >
5624 func KeyValue(key, val)
Bram Moolenaarc51cf032022-02-26 12:25:45 +00005625 return a:key .. '-' .. a:val
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005626 endfunc
5627 call map(myDict, function('KeyValue'))
5628< It is shorter when using a |lambda|: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00005629 call map(myDict, {key, val -> key .. '-' .. val})
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005630< If you do not use "val" you can leave it out: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00005631 call map(myDict, {key -> 'item: ' .. key})
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005632< If you do not use "key" you can use a short name: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00005633 call map(myDict, {_, val -> 'item: ' .. val})
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005634<
5635 The operation is done in-place for a |List| and |Dictionary|.
5636 If you want it to remain unmodified make a copy first: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00005637 :let tlist = map(copy(mylist), ' v:val .. "\t"')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005638
5639< Returns {expr1}, the |List| or |Dictionary| that was filtered,
5640 or a new |Blob| or |String|.
5641 When an error is encountered while evaluating {expr2} no
5642 further items in {expr1} are processed.
5643 When {expr2} is a Funcref errors inside a function are ignored,
5644 unless it was defined with the "abort" flag.
5645
5646 Can also be used as a |method|: >
5647 mylist->map(expr2)
5648
5649
5650maparg({name} [, {mode} [, {abbr} [, {dict}]]]) *maparg()*
5651 When {dict} is omitted or zero: Return the rhs of mapping
5652 {name} in mode {mode}. The returned String has special
5653 characters translated like in the output of the ":map" command
Ernie Rael09661202022-04-25 14:40:44 +01005654 listing. When {dict} is TRUE a dictionary is returned, see
5655 below. To get a list of all mappings see |maplist()|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005656
5657 When there is no mapping for {name}, an empty String is
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01005658 returned if {dict} is FALSE, otherwise returns an empty Dict.
5659 When the mapping for {name} is empty, then "<Nop>" is
5660 returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005661
5662 The {name} can have special key names, like in the ":map"
5663 command.
5664
5665 {mode} can be one of these strings:
5666 "n" Normal
5667 "v" Visual (including Select)
5668 "o" Operator-pending
5669 "i" Insert
5670 "c" Cmd-line
5671 "s" Select
5672 "x" Visual
5673 "l" langmap |language-mapping|
5674 "t" Terminal-Job
5675 "" Normal, Visual and Operator-pending
5676 When {mode} is omitted, the modes for "" are used.
5677
5678 When {abbr} is there and it is |TRUE| use abbreviations
5679 instead of mappings.
5680
5681 When {dict} is there and it is |TRUE| return a dictionary
5682 containing all the information of the mapping with the
Ernie Rael659c2402022-04-24 18:40:28 +01005683 following items: *mapping-dict*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005684 "lhs" The {lhs} of the mapping as it would be typed
5685 "lhsraw" The {lhs} of the mapping as raw bytes
5686 "lhsrawalt" The {lhs} of the mapping as raw bytes, alternate
5687 form, only present when it differs from "lhsraw"
5688 "rhs" The {rhs} of the mapping as typed.
5689 "silent" 1 for a |:map-silent| mapping, else 0.
5690 "noremap" 1 if the {rhs} of the mapping is not remappable.
5691 "script" 1 if mapping was defined with <script>.
5692 "expr" 1 for an expression mapping (|:map-<expr>|).
5693 "buffer" 1 for a buffer local mapping (|:map-local|).
5694 "mode" Modes for which the mapping is defined. In
5695 addition to the modes mentioned above, these
5696 characters will be used:
5697 " " Normal, Visual and Operator-pending
5698 "!" Insert and Commandline mode
5699 (|mapmode-ic|)
5700 "sid" The script local ID, used for <sid> mappings
Bram Moolenaar71badf92023-04-22 22:40:14 +01005701 (|<SID>|). Negative for special contexts.
Bram Moolenaara9528b32022-01-18 20:51:35 +00005702 "scriptversion" The version of the script. 999999 for
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01005703 |Vim9| script.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005704 "lnum" The line number in "sid", zero if unknown.
5705 "nowait" Do not wait for other, longer mappings.
5706 (|:map-<nowait>|).
Bram Moolenaar921bde82022-05-09 19:50:35 +01005707 "abbr" True if this is an abbreviation |abbreviations|.
Ernie Raeld8f5f762022-05-10 17:50:39 +01005708 "mode_bits" Vim's internal binary representation of "mode".
5709 |mapset()| ignores this; only "mode" is used.
5710 See |maplist()| for usage examples. The values
5711 are from src/vim.h and may change in the future.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005712
5713 The dictionary can be used to restore a mapping with
5714 |mapset()|.
5715
5716 The mappings local to the current buffer are checked first,
5717 then the global mappings.
5718 This function can be used to map a key even when it's already
5719 mapped, and have it do the original mapping too. Sketch: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00005720 exe 'nnoremap <Tab> ==' .. maparg('<Tab>', 'n')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005721
5722< Can also be used as a |method|: >
5723 GetKey()->maparg('n')
5724
5725mapcheck({name} [, {mode} [, {abbr}]]) *mapcheck()*
5726 Check if there is a mapping that matches with {name} in mode
5727 {mode}. See |maparg()| for {mode} and special names in
5728 {name}.
5729 When {abbr} is there and it is |TRUE| use abbreviations
5730 instead of mappings.
5731 A match happens with a mapping that starts with {name} and
5732 with a mapping which is equal to the start of {name}.
5733
5734 matches mapping "a" "ab" "abc" ~
5735 mapcheck("a") yes yes yes
5736 mapcheck("abc") yes yes yes
5737 mapcheck("ax") yes no no
5738 mapcheck("b") no no no
5739
5740 The difference with maparg() is that mapcheck() finds a
5741 mapping that matches with {name}, while maparg() only finds a
5742 mapping for {name} exactly.
5743 When there is no mapping that starts with {name}, an empty
5744 String is returned. If there is one, the RHS of that mapping
5745 is returned. If there are several mappings that start with
5746 {name}, the RHS of one of them is returned. This will be
5747 "<Nop>" if the RHS is empty.
5748 The mappings local to the current buffer are checked first,
5749 then the global mappings.
5750 This function can be used to check if a mapping can be added
5751 without being ambiguous. Example: >
5752 :if mapcheck("_vv") == ""
5753 : map _vv :set guifont=7x13<CR>
5754 :endif
5755< This avoids adding the "_vv" mapping when there already is a
5756 mapping for "_v" or for "_vvv".
5757
5758 Can also be used as a |method|: >
5759 GetKey()->mapcheck('n')
5760
5761
Ernie Rael09661202022-04-25 14:40:44 +01005762maplist([{abbr}]) *maplist()*
5763 Returns a |List| of all mappings. Each List item is a |Dict|,
5764 the same as what is returned by |maparg()|, see
5765 |mapping-dict|. When {abbr} is there and it is |TRUE| use
5766 abbreviations instead of mappings.
5767
5768 Example to show all mappings with 'MultiMatch' in rhs: >
5769 vim9script
5770 echo maplist()->filter(
5771 (_, m) => match(m.rhs, 'MultiMatch') >= 0)
Ernie Raeld8f5f762022-05-10 17:50:39 +01005772< It can be tricky to find mappings for particular |:map-modes|.
5773 |mapping-dict|'s "mode_bits" can simplify this. For example,
5774 the mode_bits for Normal, Insert or Command-line modes are
5775 0x19. To find all the mappings available in those modes you
5776 can do: >
5777 vim9script
5778 var saved_maps = []
5779 for m in maplist()
5780 if and(m.mode_bits, 0x19) != 0
5781 saved_maps->add(m)
5782 endif
5783 endfor
5784 echo saved_maps->mapnew((_, m) => m.lhs)
5785< The values of the mode_bits are defined in Vim's src/vim.h
5786 file and they can be discovered at runtime using
5787 |:map-commands| and "maplist()". Example: >
5788 vim9script
5789 omap xyzzy <Nop>
5790 var op_bit = maplist()->filter(
5791 (_, m) => m.lhs == 'xyzzy')[0].mode_bits
5792 ounmap xyzzy
5793 echo printf("Operator-pending mode bit: 0x%x", op_bit)
Ernie Rael09661202022-04-25 14:40:44 +01005794
5795
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005796mapnew({expr1}, {expr2}) *mapnew()*
5797 Like |map()| but instead of replacing items in {expr1} a new
5798 List or Dictionary is created and returned. {expr1} remains
5799 unchanged. Items can still be changed by {expr2}, if you
5800 don't want that use |deepcopy()| first.
5801
5802
5803mapset({mode}, {abbr}, {dict}) *mapset()*
Ernie Rael51d04d12022-05-04 15:40:22 +01005804mapset({dict})
5805 Restore a mapping from a dictionary, possibly returned by
5806 |maparg()| or |maplist()|. A buffer mapping, when dict.buffer
5807 is true, is set on the current buffer; it is up to the caller
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01005808 to ensure that the intended buffer is the current buffer. This
Ernie Rael51d04d12022-05-04 15:40:22 +01005809 feature allows copying mappings from one buffer to another.
5810 The dict.mode value may restore a single mapping that covers
5811 more than one mode, like with mode values of '!', ' ', 'nox',
5812 or 'v'. *E1276*
5813
5814 In the first form, {mode} and {abbr} should be the same as
5815 for the call to |maparg()|. *E460*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005816 {mode} is used to define the mode in which the mapping is set,
5817 not the "mode" entry in {dict}.
5818 Example for saving and restoring a mapping: >
5819 let save_map = maparg('K', 'n', 0, 1)
5820 nnoremap K somethingelse
5821 ...
5822 call mapset('n', 0, save_map)
5823< Note that if you are going to replace a map in several modes,
Ernie Rael51d04d12022-05-04 15:40:22 +01005824 e.g. with `:map!`, you need to save/restore the mapping for
5825 all of them, when they might differ.
5826
5827 In the second form, with {dict} as the only argument, mode
5828 and abbr are taken from the dict.
5829 Example: >
5830 vim9script
5831 var save_maps = maplist()->filter(
5832 (_, m) => m.lhs == 'K')
5833 nnoremap K somethingelse
5834 cnoremap K somethingelse2
5835 # ...
5836 unmap K
5837 for d in save_maps
5838 mapset(d)
5839 endfor
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005840
5841
5842match({expr}, {pat} [, {start} [, {count}]]) *match()*
5843 When {expr} is a |List| then this returns the index of the
5844 first item where {pat} matches. Each item is used as a
5845 String, |Lists| and |Dictionaries| are used as echoed.
5846
5847 Otherwise, {expr} is used as a String. The result is a
5848 Number, which gives the index (byte offset) in {expr} where
5849 {pat} matches.
5850
5851 A match at the first character or |List| item returns zero.
5852 If there is no match -1 is returned.
5853
5854 For getting submatches see |matchlist()|.
5855 Example: >
5856 :echo match("testing", "ing") " results in 4
5857 :echo match([1, 'x'], '\a') " results in 1
5858< See |string-match| for how {pat} is used.
5859 *strpbrk()*
5860 Vim doesn't have a strpbrk() function. But you can do: >
5861 :let sepidx = match(line, '[.,;: \t]')
5862< *strcasestr()*
5863 Vim doesn't have a strcasestr() function. But you can add
5864 "\c" to the pattern to ignore case: >
5865 :let idx = match(haystack, '\cneedle')
5866<
5867 If {start} is given, the search starts from byte index
5868 {start} in a String or item {start} in a |List|.
5869 The result, however, is still the index counted from the
5870 first character/item. Example: >
5871 :echo match("testing", "ing", 2)
5872< result is again "4". >
5873 :echo match("testing", "ing", 4)
5874< result is again "4". >
5875 :echo match("testing", "t", 2)
5876< result is "3".
5877 For a String, if {start} > 0 then it is like the string starts
5878 {start} bytes later, thus "^" will match at {start}. Except
5879 when {count} is given, then it's like matches before the
5880 {start} byte are ignored (this is a bit complicated to keep it
5881 backwards compatible).
5882 For a String, if {start} < 0, it will be set to 0. For a list
5883 the index is counted from the end.
5884 If {start} is out of range ({start} > strlen({expr}) for a
5885 String or {start} > len({expr}) for a |List|) -1 is returned.
5886
5887 When {count} is given use the {count}'th match. When a match
5888 is found in a String the search for the next one starts one
5889 character further. Thus this example results in 1: >
5890 echo match("testing", "..", 0, 2)
5891< In a |List| the search continues in the next item.
5892 Note that when {count} is added the way {start} works changes,
5893 see above.
5894
5895 See |pattern| for the patterns that are accepted.
5896 The 'ignorecase' option is used to set the ignore-caseness of
5897 the pattern. 'smartcase' is NOT used. The matching is always
5898 done like 'magic' is set and 'cpoptions' is empty.
5899 Note that a match at the start is preferred, thus when the
5900 pattern is using "*" (any number of matches) it tends to find
5901 zero matches at the start instead of a number of matches
5902 further down in the text.
5903
5904 Can also be used as a |method|: >
5905 GetText()->match('word')
5906 GetList()->match('word')
5907<
Bram Moolenaar2f0936c2022-01-08 21:51:59 +00005908 *matchadd()* *E290* *E798* *E799* *E801* *E957*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005909matchadd({group}, {pattern} [, {priority} [, {id} [, {dict}]]])
5910 Defines a pattern to be highlighted in the current window (a
5911 "match"). It will be highlighted with {group}. Returns an
5912 identification number (ID), which can be used to delete the
5913 match using |matchdelete()|. The ID is bound to the window.
5914 Matching is case sensitive and magic, unless case sensitivity
5915 or magicness are explicitly overridden in {pattern}. The
5916 'magic', 'smartcase' and 'ignorecase' options are not used.
5917 The "Conceal" value is special, it causes the match to be
5918 concealed.
5919
5920 The optional {priority} argument assigns a priority to the
5921 match. A match with a high priority will have its
5922 highlighting overrule that of a match with a lower priority.
5923 A priority is specified as an integer (negative numbers are no
5924 exception). If the {priority} argument is not specified, the
5925 default priority is 10. The priority of 'hlsearch' is zero,
5926 hence all matches with a priority greater than zero will
5927 overrule it. Syntax highlighting (see 'syntax') is a separate
5928 mechanism, and regardless of the chosen priority a match will
5929 always overrule syntax highlighting.
5930
5931 The optional {id} argument allows the request for a specific
5932 match ID. If a specified ID is already taken, an error
5933 message will appear and the match will not be added. An ID
5934 is specified as a positive integer (zero excluded). IDs 1, 2
5935 and 3 are reserved for |:match|, |:2match| and |:3match|,
Bram Moolenaar2ecbe532022-07-29 21:36:21 +01005936 respectively. 3 is reserved for use by the |matchparen|
5937 plugin.
Bram Moolenaarb529cfb2022-07-25 15:42:07 +01005938 If the {id} argument is not specified or -1, |matchadd()|
Bram Moolenaar9f573a82022-09-29 13:50:08 +01005939 automatically chooses a free ID, which is at least 1000.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005940
5941 The optional {dict} argument allows for further custom
5942 values. Currently this is used to specify a match specific
5943 conceal character that will be shown for |hl-Conceal|
5944 highlighted matches. The dict can have the following members:
5945
5946 conceal Special character to show instead of the
5947 match (only for |hl-Conceal| highlighted
5948 matches, see |:syn-cchar|)
5949 window Instead of the current window use the
5950 window with this number or window ID.
5951
5952 The number of matches is not limited, as it is the case with
5953 the |:match| commands.
5954
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01005955 Returns -1 on error.
5956
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005957 Example: >
5958 :highlight MyGroup ctermbg=green guibg=green
5959 :let m = matchadd("MyGroup", "TODO")
5960< Deletion of the pattern: >
5961 :call matchdelete(m)
5962
5963< A list of matches defined by |matchadd()| and |:match| are
5964 available from |getmatches()|. All matches can be deleted in
5965 one operation by |clearmatches()|.
5966
5967 Can also be used as a |method|: >
5968 GetGroup()->matchadd('TODO')
5969<
5970 *matchaddpos()*
5971matchaddpos({group}, {pos} [, {priority} [, {id} [, {dict}]]])
5972 Same as |matchadd()|, but requires a list of positions {pos}
5973 instead of a pattern. This command is faster than |matchadd()|
5974 because it does not require to handle regular expressions and
5975 sets buffer line boundaries to redraw screen. It is supposed
5976 to be used when fast match additions and deletions are
5977 required, for example to highlight matching parentheses.
5978
5979 {pos} is a list of positions. Each position can be one of
5980 these:
5981 - A number. This whole line will be highlighted. The first
5982 line has number 1.
5983 - A list with one number, e.g., [23]. The whole line with this
5984 number will be highlighted.
5985 - A list with two numbers, e.g., [23, 11]. The first number is
5986 the line number, the second one is the column number (first
5987 column is 1, the value must correspond to the byte index as
5988 |col()| would return). The character at this position will
5989 be highlighted.
5990 - A list with three numbers, e.g., [23, 11, 3]. As above, but
5991 the third number gives the length of the highlight in bytes.
5992
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01005993 Returns -1 on error.
5994
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005995 Example: >
5996 :highlight MyGroup ctermbg=green guibg=green
5997 :let m = matchaddpos("MyGroup", [[23, 24], 34])
5998< Deletion of the pattern: >
5999 :call matchdelete(m)
6000
6001< Matches added by |matchaddpos()| are returned by
6002 |getmatches()|.
6003
6004 Can also be used as a |method|: >
6005 GetGroup()->matchaddpos([23, 11])
6006
6007matcharg({nr}) *matcharg()*
6008 Selects the {nr} match item, as set with a |:match|,
6009 |:2match| or |:3match| command.
6010 Return a |List| with two elements:
6011 The name of the highlight group used
6012 The pattern used.
6013 When {nr} is not 1, 2 or 3 returns an empty |List|.
6014 When there is no match item set returns ['', ''].
6015 This is useful to save and restore a |:match|.
6016 Highlighting matches using the |:match| commands are limited
6017 to three matches. |matchadd()| does not have this limitation.
6018
6019 Can also be used as a |method|: >
6020 GetMatch()->matcharg()
6021
6022matchdelete({id} [, {win}) *matchdelete()* *E802* *E803*
6023 Deletes a match with ID {id} previously defined by |matchadd()|
6024 or one of the |:match| commands. Returns 0 if successful,
6025 otherwise -1. See example for |matchadd()|. All matches can
6026 be deleted in one operation by |clearmatches()|.
6027 If {win} is specified, use the window with this number or
6028 window ID instead of the current window.
6029
6030 Can also be used as a |method|: >
6031 GetMatch()->matchdelete()
6032
6033matchend({expr}, {pat} [, {start} [, {count}]]) *matchend()*
6034 Same as |match()|, but return the index of first character
6035 after the match. Example: >
6036 :echo matchend("testing", "ing")
6037< results in "7".
6038 *strspn()* *strcspn()*
6039 Vim doesn't have a strspn() or strcspn() function, but you can
6040 do it with matchend(): >
6041 :let span = matchend(line, '[a-zA-Z]')
6042 :let span = matchend(line, '[^a-zA-Z]')
6043< Except that -1 is returned when there are no matches.
6044
6045 The {start}, if given, has the same meaning as for |match()|. >
6046 :echo matchend("testing", "ing", 2)
6047< results in "7". >
6048 :echo matchend("testing", "ing", 5)
6049< result is "-1".
6050 When {expr} is a |List| the result is equal to |match()|.
6051
6052 Can also be used as a |method|: >
6053 GetText()->matchend('word')
6054
6055
6056matchfuzzy({list}, {str} [, {dict}]) *matchfuzzy()*
6057 If {list} is a list of strings, then returns a |List| with all
6058 the strings in {list} that fuzzy match {str}. The strings in
6059 the returned list are sorted based on the matching score.
6060
6061 The optional {dict} argument always supports the following
6062 items:
zeertzjq9af2bc02022-05-11 14:15:37 +01006063 matchseq When this item is present return only matches
6064 that contain the characters in {str} in the
6065 given sequence.
Kazuyuki Miyagi47f1a552022-06-17 18:30:03 +01006066 limit Maximum number of matches in {list} to be
6067 returned. Zero means no limit.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006068
6069 If {list} is a list of dictionaries, then the optional {dict}
6070 argument supports the following additional items:
Yasuhiro Matsumoto9029a6e2022-04-16 12:35:35 +01006071 key Key of the item which is fuzzy matched against
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006072 {str}. The value of this item should be a
6073 string.
6074 text_cb |Funcref| that will be called for every item
6075 in {list} to get the text for fuzzy matching.
6076 This should accept a dictionary item as the
6077 argument and return the text for that item to
6078 use for fuzzy matching.
6079
6080 {str} is treated as a literal string and regular expression
6081 matching is NOT supported. The maximum supported {str} length
6082 is 256.
6083
6084 When {str} has multiple words each separated by white space,
6085 then the list of strings that have all the words is returned.
6086
6087 If there are no matching strings or there is an error, then an
6088 empty list is returned. If length of {str} is greater than
6089 256, then returns an empty list.
6090
Yasuhiro Matsumoto9029a6e2022-04-16 12:35:35 +01006091 When {limit} is given, matchfuzzy() will find up to this
6092 number of matches in {list} and return them in sorted order.
6093
Bram Moolenaar1588bc82022-03-08 21:35:07 +00006094 Refer to |fuzzy-matching| for more information about fuzzy
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006095 matching strings.
6096
6097 Example: >
6098 :echo matchfuzzy(["clay", "crow"], "cay")
6099< results in ["clay"]. >
6100 :echo getbufinfo()->map({_, v -> v.name})->matchfuzzy("ndl")
6101< results in a list of buffer names fuzzy matching "ndl". >
6102 :echo getbufinfo()->matchfuzzy("ndl", {'key' : 'name'})
6103< results in a list of buffer information dicts with buffer
6104 names fuzzy matching "ndl". >
6105 :echo getbufinfo()->matchfuzzy("spl",
6106 \ {'text_cb' : {v -> v.name}})
6107< results in a list of buffer information dicts with buffer
6108 names fuzzy matching "spl". >
6109 :echo v:oldfiles->matchfuzzy("test")
6110< results in a list of file names fuzzy matching "test". >
6111 :let l = readfile("buffer.c")->matchfuzzy("str")
6112< results in a list of lines in "buffer.c" fuzzy matching "str". >
6113 :echo ['one two', 'two one']->matchfuzzy('two one')
6114< results in ['two one', 'one two']. >
6115 :echo ['one two', 'two one']->matchfuzzy('two one',
6116 \ {'matchseq': 1})
6117< results in ['two one'].
6118
6119matchfuzzypos({list}, {str} [, {dict}]) *matchfuzzypos()*
6120 Same as |matchfuzzy()|, but returns the list of matched
6121 strings, the list of character positions where characters
6122 in {str} matches and a list of matching scores. You can
6123 use |byteidx()| to convert a character position to a byte
6124 position.
6125
6126 If {str} matches multiple times in a string, then only the
6127 positions for the best match is returned.
6128
6129 If there are no matching strings or there is an error, then a
6130 list with three empty list items is returned.
6131
6132 Example: >
6133 :echo matchfuzzypos(['testing'], 'tsg')
6134< results in [['testing'], [[0, 2, 6]], [99]] >
6135 :echo matchfuzzypos(['clay', 'lacy'], 'la')
6136< results in [['lacy', 'clay'], [[0, 1], [1, 2]], [153, 133]] >
6137 :echo [{'text': 'hello', 'id' : 10}]->matchfuzzypos('ll', {'key' : 'text'})
6138< results in [[{'id': 10, 'text': 'hello'}], [[2, 3]], [127]]
6139
6140matchlist({expr}, {pat} [, {start} [, {count}]]) *matchlist()*
6141 Same as |match()|, but return a |List|. The first item in the
6142 list is the matched string, same as what matchstr() would
6143 return. Following items are submatches, like "\1", "\2", etc.
6144 in |:substitute|. When an optional submatch didn't match an
6145 empty string is used. Example: >
6146 echo matchlist('acd', '\(a\)\?\(b\)\?\(c\)\?\(.*\)')
6147< Results in: ['acd', 'a', '', 'c', 'd', '', '', '', '', '']
6148 When there is no match an empty list is returned.
6149
6150 You can pass in a List, but that is not very useful.
6151
6152 Can also be used as a |method|: >
6153 GetText()->matchlist('word')
6154
6155matchstr({expr}, {pat} [, {start} [, {count}]]) *matchstr()*
6156 Same as |match()|, but return the matched string. Example: >
6157 :echo matchstr("testing", "ing")
6158< results in "ing".
6159 When there is no match "" is returned.
6160 The {start}, if given, has the same meaning as for |match()|. >
6161 :echo matchstr("testing", "ing", 2)
6162< results in "ing". >
6163 :echo matchstr("testing", "ing", 5)
6164< result is "".
6165 When {expr} is a |List| then the matching item is returned.
6166 The type isn't changed, it's not necessarily a String.
6167
6168 Can also be used as a |method|: >
6169 GetText()->matchstr('word')
6170
6171matchstrpos({expr}, {pat} [, {start} [, {count}]]) *matchstrpos()*
6172 Same as |matchstr()|, but return the matched string, the start
6173 position and the end position of the match. Example: >
6174 :echo matchstrpos("testing", "ing")
6175< results in ["ing", 4, 7].
6176 When there is no match ["", -1, -1] is returned.
6177 The {start}, if given, has the same meaning as for |match()|. >
6178 :echo matchstrpos("testing", "ing", 2)
6179< results in ["ing", 4, 7]. >
6180 :echo matchstrpos("testing", "ing", 5)
6181< result is ["", -1, -1].
6182 When {expr} is a |List| then the matching item, the index
6183 of first item where {pat} matches, the start position and the
6184 end position of the match are returned. >
6185 :echo matchstrpos([1, '__x'], '\a')
6186< result is ["x", 1, 2, 3].
6187 The type isn't changed, it's not necessarily a String.
6188
6189 Can also be used as a |method|: >
6190 GetText()->matchstrpos('word')
6191<
6192
6193 *max()*
6194max({expr}) Return the maximum value of all items in {expr}. Example: >
6195 echo max([apples, pears, oranges])
6196
6197< {expr} can be a |List| or a |Dictionary|. For a Dictionary,
6198 it returns the maximum of all values in the Dictionary.
6199 If {expr} is neither a List nor a Dictionary, or one of the
6200 items in {expr} cannot be used as a Number this results in
6201 an error. An empty |List| or |Dictionary| results in zero.
6202
6203 Can also be used as a |method|: >
6204 mylist->max()
6205
6206
6207menu_info({name} [, {mode}]) *menu_info()*
6208 Return information about the specified menu {name} in
6209 mode {mode}. The menu name should be specified without the
6210 shortcut character ('&'). If {name} is "", then the top-level
6211 menu names are returned.
6212
6213 {mode} can be one of these strings:
6214 "n" Normal
6215 "v" Visual (including Select)
6216 "o" Operator-pending
6217 "i" Insert
6218 "c" Cmd-line
6219 "s" Select
6220 "x" Visual
6221 "t" Terminal-Job
6222 "" Normal, Visual and Operator-pending
6223 "!" Insert and Cmd-line
6224 When {mode} is omitted, the modes for "" are used.
6225
6226 Returns a |Dictionary| containing the following items:
6227 accel menu item accelerator text |menu-text|
6228 display display name (name without '&')
6229 enabled v:true if this menu item is enabled
6230 Refer to |:menu-enable|
6231 icon name of the icon file (for toolbar)
6232 |toolbar-icon|
6233 iconidx index of a built-in icon
6234 modes modes for which the menu is defined. In
6235 addition to the modes mentioned above, these
6236 characters will be used:
6237 " " Normal, Visual and Operator-pending
6238 name menu item name.
6239 noremenu v:true if the {rhs} of the menu item is not
6240 remappable else v:false.
6241 priority menu order priority |menu-priority|
6242 rhs right-hand-side of the menu item. The returned
6243 string has special characters translated like
6244 in the output of the ":menu" command listing.
6245 When the {rhs} of a menu item is empty, then
6246 "<Nop>" is returned.
6247 script v:true if script-local remapping of {rhs} is
6248 allowed else v:false. See |:menu-script|.
6249 shortcut shortcut key (character after '&' in
6250 the menu name) |menu-shortcut|
6251 silent v:true if the menu item is created
6252 with <silent> argument |:menu-silent|
6253 submenus |List| containing the names of
6254 all the submenus. Present only if the menu
6255 item has submenus.
6256
6257 Returns an empty dictionary if the menu item is not found.
6258
6259 Examples: >
6260 :echo menu_info('Edit.Cut')
6261 :echo menu_info('File.Save', 'n')
6262
6263 " Display the entire menu hierarchy in a buffer
6264 func ShowMenu(name, pfx)
6265 let m = menu_info(a:name)
6266 call append(line('$'), a:pfx .. m.display)
6267 for child in m->get('submenus', [])
6268 call ShowMenu(a:name .. '.' .. escape(child, '.'),
6269 \ a:pfx .. ' ')
6270 endfor
6271 endfunc
6272 new
6273 for topmenu in menu_info('').submenus
6274 call ShowMenu(topmenu, '')
6275 endfor
6276<
6277 Can also be used as a |method|: >
6278 GetMenuName()->menu_info('v')
6279
6280
6281< *min()*
6282min({expr}) Return the minimum value of all items in {expr}. Example: >
6283 echo min([apples, pears, oranges])
6284
6285< {expr} can be a |List| or a |Dictionary|. For a Dictionary,
6286 it returns the minimum of all values in the Dictionary.
6287 If {expr} is neither a List nor a Dictionary, or one of the
6288 items in {expr} cannot be used as a Number this results in
6289 an error. An empty |List| or |Dictionary| results in zero.
6290
6291 Can also be used as a |method|: >
6292 mylist->min()
6293
6294< *mkdir()* *E739*
Bram Moolenaar938ae282023-02-20 20:44:55 +00006295mkdir({name} [, {flags} [, {prot}]])
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006296 Create directory {name}.
6297
Bram Moolenaar938ae282023-02-20 20:44:55 +00006298 When {flags} is present it must be a string. An empty string
6299 has no effect.
Bram Moolenaar6f14da12022-09-07 21:30:44 +01006300
Bram Moolenaar938ae282023-02-20 20:44:55 +00006301 If {flags} contains "p" then intermediate directories are
6302 created as necessary.
6303
6304 If {flags} contains "D" then {name} is deleted at the end of
Bram Moolenaar6f14da12022-09-07 21:30:44 +01006305 the current function, as with: >
6306 defer delete({name}, 'd')
6307<
Bram Moolenaar938ae282023-02-20 20:44:55 +00006308 If {flags} contains "R" then {name} is deleted recursively at
Bram Moolenaar6f14da12022-09-07 21:30:44 +01006309 the end of the current function, as with: >
6310 defer delete({name}, 'rf')
6311< Note that when {name} has more than one part and "p" is used
6312 some directories may already exist. Only the first one that
6313 is created and what it contains is scheduled to be deleted.
6314 E.g. when using: >
6315 call mkdir('subdir/tmp/autoload', 'pR')
6316< and "subdir" already exists then "subdir/tmp" will be
6317 scheduled for deletion, like with: >
6318 defer delete('subdir/tmp', 'rf')
6319< Note that if scheduling the defer fails the directory is not
6320 deleted. This should only happen when out of memory.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006321
6322 If {prot} is given it is used to set the protection bits of
6323 the new directory. The default is 0o755 (rwxr-xr-x: r/w for
6324 the user, readable for others). Use 0o700 to make it
6325 unreadable for others. This is only used for the last part of
6326 {name}. Thus if you create /tmp/foo/bar then /tmp/foo will be
6327 created with 0o755.
6328 Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00006329 :call mkdir($HOME .. "/tmp/foo/bar", "p", 0o700)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006330
6331< This function is not available in the |sandbox|.
6332
6333 There is no error if the directory already exists and the "p"
6334 flag is passed (since patch 8.0.1708). However, without the
6335 "p" option the call will fail.
6336
6337 The function result is a Number, which is TRUE if the call was
6338 successful or FALSE if the directory creation failed or partly
6339 failed.
6340
6341 Not available on all systems. To check use: >
6342 :if exists("*mkdir")
6343
6344< Can also be used as a |method|: >
6345 GetName()->mkdir()
6346<
6347 *mode()*
6348mode([expr]) Return a string that indicates the current mode.
6349 If [expr] is supplied and it evaluates to a non-zero Number or
6350 a non-empty String (|non-zero-arg|), then the full mode is
6351 returned, otherwise only the first letter is returned.
6352 Also see |state()|.
6353
6354 n Normal
6355 no Operator-pending
6356 nov Operator-pending (forced characterwise |o_v|)
6357 noV Operator-pending (forced linewise |o_V|)
6358 noCTRL-V Operator-pending (forced blockwise |o_CTRL-V|);
6359 CTRL-V is one character
6360 niI Normal using |i_CTRL-O| in |Insert-mode|
6361 niR Normal using |i_CTRL-O| in |Replace-mode|
6362 niV Normal using |i_CTRL-O| in |Virtual-Replace-mode|
6363 nt Terminal-Normal (insert goes to Terminal-Job mode)
6364 v Visual by character
6365 vs Visual by character using |v_CTRL-O| in Select mode
6366 V Visual by line
6367 Vs Visual by line using |v_CTRL-O| in Select mode
6368 CTRL-V Visual blockwise
6369 CTRL-Vs Visual blockwise using |v_CTRL-O| in Select mode
6370 s Select by character
6371 S Select by line
6372 CTRL-S Select blockwise
6373 i Insert
6374 ic Insert mode completion |compl-generic|
6375 ix Insert mode |i_CTRL-X| completion
6376 R Replace |R|
6377 Rc Replace mode completion |compl-generic|
6378 Rx Replace mode |i_CTRL-X| completion
6379 Rv Virtual Replace |gR|
6380 Rvc Virtual Replace mode completion |compl-generic|
6381 Rvx Virtual Replace mode |i_CTRL-X| completion
6382 c Command-line editing
6383 cv Vim Ex mode |gQ|
6384 ce Normal Ex mode |Q|
6385 r Hit-enter prompt
6386 rm The -- more -- prompt
6387 r? A |:confirm| query of some sort
6388 ! Shell or external command is executing
6389 t Terminal-Job mode: keys go to the job
6390
6391 This is useful in the 'statusline' option or when used
6392 with |remote_expr()| In most other places it always returns
6393 "c" or "n".
6394 Note that in the future more modes and more specific modes may
6395 be added. It's better not to compare the whole string but only
6396 the leading character(s).
6397 Also see |visualmode()|.
6398
6399 Can also be used as a |method|: >
6400 DoFull()->mode()
6401
6402mzeval({expr}) *mzeval()*
6403 Evaluate MzScheme expression {expr} and return its result
6404 converted to Vim data structures.
6405 Numbers and strings are returned as they are.
6406 Pairs (including lists and improper lists) and vectors are
6407 returned as Vim |Lists|.
6408 Hash tables are represented as Vim |Dictionary| type with keys
6409 converted to strings.
6410 All other types are converted to string with display function.
6411 Examples: >
6412 :mz (define l (list 1 2 3))
6413 :mz (define h (make-hash)) (hash-set! h "list" l)
6414 :echo mzeval("l")
6415 :echo mzeval("h")
6416<
6417 Note that in a `:def` function local variables are not visible
6418 to {expr}.
6419
6420 Can also be used as a |method|: >
6421 GetExpr()->mzeval()
6422<
6423 {only available when compiled with the |+mzscheme| feature}
6424
6425nextnonblank({lnum}) *nextnonblank()*
6426 Return the line number of the first line at or below {lnum}
6427 that is not blank. Example: >
6428 if getline(nextnonblank(1)) =~ "Java"
6429< When {lnum} is invalid or there is no non-blank line at or
6430 below it, zero is returned.
6431 {lnum} is used like with |getline()|.
6432 See also |prevnonblank()|.
6433
6434 Can also be used as a |method|: >
6435 GetLnum()->nextnonblank()
6436
6437nr2char({expr} [, {utf8}]) *nr2char()*
6438 Return a string with a single character, which has the number
6439 value {expr}. Examples: >
6440 nr2char(64) returns "@"
6441 nr2char(32) returns " "
6442< When {utf8} is omitted or zero, the current 'encoding' is used.
6443 Example for "utf-8": >
6444 nr2char(300) returns I with bow character
6445< When {utf8} is TRUE, always return UTF-8 characters.
6446 Note that a NUL character in the file is specified with
6447 nr2char(10), because NULs are represented with newline
6448 characters. nr2char(0) is a real NUL and terminates the
6449 string, thus results in an empty string.
6450 To turn a list of character numbers into a string: >
6451 let list = [65, 66, 67]
6452 let str = join(map(list, {_, val -> nr2char(val)}), '')
6453< Result: "ABC"
6454
6455 Can also be used as a |method|: >
6456 GetNumber()->nr2char()
6457
6458or({expr}, {expr}) *or()*
6459 Bitwise OR on the two arguments. The arguments are converted
6460 to a number. A List, Dict or Float argument causes an error.
Bram Moolenaar5a6ec102022-05-27 21:58:00 +01006461 Also see `and()` and `xor()`.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006462 Example: >
6463 :let bits = or(bits, 0x80)
6464< Can also be used as a |method|: >
6465 :let bits = bits->or(0x80)
6466
Bram Moolenaar5a6ec102022-05-27 21:58:00 +01006467< Rationale: The reason this is a function and not using the "|"
6468 character like many languages, is that Vi has always used "|"
6469 to separate commands. In many places it would not be clear if
6470 "|" is an operator or a command separator.
6471
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006472
6473pathshorten({path} [, {len}]) *pathshorten()*
6474 Shorten directory names in the path {path} and return the
6475 result. The tail, the file name, is kept as-is. The other
6476 components in the path are reduced to {len} letters in length.
6477 If {len} is omitted or smaller than 1 then 1 is used (single
6478 letters). Leading '~' and '.' characters are kept. Examples: >
6479 :echo pathshorten('~/.vim/autoload/myfile.vim')
6480< ~/.v/a/myfile.vim ~
6481>
6482 :echo pathshorten('~/.vim/autoload/myfile.vim', 2)
6483< ~/.vi/au/myfile.vim ~
6484 It doesn't matter if the path exists or not.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01006485 Returns an empty string on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006486
6487 Can also be used as a |method|: >
6488 GetDirectories()->pathshorten()
6489
6490perleval({expr}) *perleval()*
6491 Evaluate Perl expression {expr} in scalar context and return
6492 its result converted to Vim data structures. If value can't be
6493 converted, it is returned as a string Perl representation.
6494 Note: If you want an array or hash, {expr} must return a
6495 reference to it.
6496 Example: >
6497 :echo perleval('[1 .. 4]')
6498< [1, 2, 3, 4]
6499
6500 Note that in a `:def` function local variables are not visible
6501 to {expr}.
6502
6503 Can also be used as a |method|: >
6504 GetExpr()->perleval()
6505
6506< {only available when compiled with the |+perl| feature}
6507
6508
6509popup_ functions are documented here: |popup-functions|
6510
6511
6512pow({x}, {y}) *pow()*
6513 Return the power of {x} to the exponent {y} as a |Float|.
6514 {x} and {y} must evaluate to a |Float| or a |Number|.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01006515 Returns 0.0 if {x} or {y} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006516 Examples: >
6517 :echo pow(3, 3)
6518< 27.0 >
6519 :echo pow(2, 16)
6520< 65536.0 >
6521 :echo pow(32, 0.20)
6522< 2.0
6523
6524 Can also be used as a |method|: >
6525 Compute()->pow(3)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006526
6527prevnonblank({lnum}) *prevnonblank()*
6528 Return the line number of the first line at or above {lnum}
6529 that is not blank. Example: >
6530 let ind = indent(prevnonblank(v:lnum - 1))
6531< When {lnum} is invalid or there is no non-blank line at or
6532 above it, zero is returned.
6533 {lnum} is used like with |getline()|.
6534 Also see |nextnonblank()|.
6535
6536 Can also be used as a |method|: >
6537 GetLnum()->prevnonblank()
6538
6539printf({fmt}, {expr1} ...) *printf()*
6540 Return a String with {fmt}, where "%" items are replaced by
6541 the formatted form of their respective arguments. Example: >
6542 printf("%4d: E%d %.30s", lnum, errno, msg)
6543< May result in:
6544 " 99: E42 asdfasdfasdfasdfasdfasdfasdfas" ~
6545
6546 When used as a |method| the base is passed as the second
6547 argument: >
6548 Compute()->printf("result: %d")
Bram Moolenaarcbaff5e2022-04-08 17:45:08 +01006549<
6550 You can use `call()` to pass the items as a list.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006551
Bram Moolenaarcbaff5e2022-04-08 17:45:08 +01006552 Often used items are:
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006553 %s string
6554 %6S string right-aligned in 6 display cells
6555 %6s string right-aligned in 6 bytes
6556 %.9s string truncated to 9 bytes
6557 %c single byte
6558 %d decimal number
6559 %5d decimal number padded with spaces to 5 characters
6560 %x hex number
6561 %04x hex number padded with zeros to at least 4 characters
6562 %X hex number using upper case letters
6563 %o octal number
6564 %08b binary number padded with zeros to at least 8 chars
6565 %f floating point number as 12.23, inf, -inf or nan
6566 %F floating point number as 12.23, INF, -INF or NAN
6567 %e floating point number as 1.23e3, inf, -inf or nan
6568 %E floating point number as 1.23E3, INF, -INF or NAN
6569 %g floating point number, as %f or %e depending on value
6570 %G floating point number, as %F or %E depending on value
6571 %% the % character itself
6572
6573 Conversion specifications start with '%' and end with the
6574 conversion type. All other characters are copied unchanged to
6575 the result.
6576
6577 The "%" starts a conversion specification. The following
6578 arguments appear in sequence:
6579
6580 % [flags] [field-width] [.precision] type
6581
6582 flags
6583 Zero or more of the following flags:
6584
6585 # The value should be converted to an "alternate
6586 form". For c, d, and s conversions, this option
6587 has no effect. For o conversions, the precision
6588 of the number is increased to force the first
6589 character of the output string to a zero (except
6590 if a zero value is printed with an explicit
6591 precision of zero).
6592 For b and B conversions, a non-zero result has
6593 the string "0b" (or "0B" for B conversions)
6594 prepended to it.
6595 For x and X conversions, a non-zero result has
6596 the string "0x" (or "0X" for X conversions)
6597 prepended to it.
6598
6599 0 (zero) Zero padding. For all conversions the converted
6600 value is padded on the left with zeros rather
6601 than blanks. If a precision is given with a
6602 numeric conversion (d, b, B, o, x, and X), the 0
6603 flag is ignored.
6604
6605 - A negative field width flag; the converted value
6606 is to be left adjusted on the field boundary.
6607 The converted value is padded on the right with
6608 blanks, rather than on the left with blanks or
6609 zeros. A - overrides a 0 if both are given.
6610
6611 ' ' (space) A blank should be left before a positive
6612 number produced by a signed conversion (d).
6613
6614 + A sign must always be placed before a number
6615 produced by a signed conversion. A + overrides
6616 a space if both are used.
6617
6618 field-width
6619 An optional decimal digit string specifying a minimum
6620 field width. If the converted value has fewer bytes
6621 than the field width, it will be padded with spaces on
6622 the left (or right, if the left-adjustment flag has
6623 been given) to fill out the field width. For the S
6624 conversion the count is in cells.
6625
6626 .precision
6627 An optional precision, in the form of a period '.'
6628 followed by an optional digit string. If the digit
6629 string is omitted, the precision is taken as zero.
6630 This gives the minimum number of digits to appear for
6631 d, o, x, and X conversions, the maximum number of
6632 bytes to be printed from a string for s conversions,
6633 or the maximum number of cells to be printed from a
6634 string for S conversions.
6635 For floating point it is the number of digits after
6636 the decimal point.
6637
6638 type
6639 A character that specifies the type of conversion to
6640 be applied, see below.
6641
6642 A field width or precision, or both, may be indicated by an
6643 asterisk '*' instead of a digit string. In this case, a
6644 Number argument supplies the field width or precision. A
6645 negative field width is treated as a left adjustment flag
6646 followed by a positive field width; a negative precision is
6647 treated as though it were missing. Example: >
6648 :echo printf("%d: %.*s", nr, width, line)
6649< This limits the length of the text used from "line" to
6650 "width" bytes.
6651
6652 The conversion specifiers and their meanings are:
6653
6654 *printf-d* *printf-b* *printf-B* *printf-o*
6655 *printf-x* *printf-X*
6656 dbBoxX The Number argument is converted to signed decimal
6657 (d), unsigned binary (b and B), unsigned octal (o), or
6658 unsigned hexadecimal (x and X) notation. The letters
6659 "abcdef" are used for x conversions; the letters
6660 "ABCDEF" are used for X conversions.
6661 The precision, if any, gives the minimum number of
6662 digits that must appear; if the converted value
6663 requires fewer digits, it is padded on the left with
6664 zeros.
6665 In no case does a non-existent or small field width
6666 cause truncation of a numeric field; if the result of
6667 a conversion is wider than the field width, the field
6668 is expanded to contain the conversion result.
6669 The 'h' modifier indicates the argument is 16 bits.
6670 The 'l' modifier indicates the argument is 32 bits.
6671 The 'L' modifier indicates the argument is 64 bits.
6672 Generally, these modifiers are not useful. They are
6673 ignored when type is known from the argument.
6674
6675 i alias for d
6676 D alias for ld
6677 U alias for lu
6678 O alias for lo
6679
6680 *printf-c*
6681 c The Number argument is converted to a byte, and the
6682 resulting character is written.
6683
6684 *printf-s*
6685 s The text of the String argument is used. If a
6686 precision is specified, no more bytes than the number
6687 specified are used.
6688 If the argument is not a String type, it is
6689 automatically converted to text with the same format
6690 as ":echo".
6691 *printf-S*
6692 S The text of the String argument is used. If a
6693 precision is specified, no more display cells than the
6694 number specified are used.
6695
6696 *printf-f* *E807*
6697 f F The Float argument is converted into a string of the
6698 form 123.456. The precision specifies the number of
6699 digits after the decimal point. When the precision is
6700 zero the decimal point is omitted. When the precision
6701 is not specified 6 is used. A really big number
6702 (out of range or dividing by zero) results in "inf"
6703 or "-inf" with %f (INF or -INF with %F).
6704 "0.0 / 0.0" results in "nan" with %f (NAN with %F).
6705 Example: >
6706 echo printf("%.2f", 12.115)
6707< 12.12
6708 Note that roundoff depends on the system libraries.
6709 Use |round()| when in doubt.
6710
6711 *printf-e* *printf-E*
6712 e E The Float argument is converted into a string of the
6713 form 1.234e+03 or 1.234E+03 when using 'E'. The
6714 precision specifies the number of digits after the
6715 decimal point, like with 'f'.
6716
6717 *printf-g* *printf-G*
6718 g G The Float argument is converted like with 'f' if the
6719 value is between 0.001 (inclusive) and 10000000.0
6720 (exclusive). Otherwise 'e' is used for 'g' and 'E'
6721 for 'G'. When no precision is specified superfluous
6722 zeroes and '+' signs are removed, except for the zero
6723 immediately after the decimal point. Thus 10000000.0
6724 results in 1.0e7.
6725
6726 *printf-%*
6727 % A '%' is written. No argument is converted. The
6728 complete conversion specification is "%%".
6729
6730 When a Number argument is expected a String argument is also
6731 accepted and automatically converted.
6732 When a Float or String argument is expected a Number argument
6733 is also accepted and automatically converted.
6734 Any other argument type results in an error message.
6735
6736 *E766* *E767*
6737 The number of {exprN} arguments must exactly match the number
6738 of "%" items. If there are not sufficient or too many
6739 arguments an error is given. Up to 18 arguments can be used.
6740
6741
6742prompt_getprompt({buf}) *prompt_getprompt()*
6743 Returns the effective prompt text for buffer {buf}. {buf} can
6744 be a buffer name or number. See |prompt-buffer|.
6745
6746 If the buffer doesn't exist or isn't a prompt buffer, an empty
6747 string is returned.
6748
6749 Can also be used as a |method|: >
6750 GetBuffer()->prompt_getprompt()
6751
6752< {only available when compiled with the |+channel| feature}
6753
6754
6755prompt_setcallback({buf}, {expr}) *prompt_setcallback()*
6756 Set prompt callback for buffer {buf} to {expr}. When {expr}
6757 is an empty string the callback is removed. This has only
6758 effect if {buf} has 'buftype' set to "prompt".
6759
6760 The callback is invoked when pressing Enter. The current
6761 buffer will always be the prompt buffer. A new line for a
6762 prompt is added before invoking the callback, thus the prompt
6763 for which the callback was invoked will be in the last but one
6764 line.
6765 If the callback wants to add text to the buffer, it must
6766 insert it above the last line, since that is where the current
6767 prompt is. This can also be done asynchronously.
6768 The callback is invoked with one argument, which is the text
6769 that was entered at the prompt. This can be an empty string
6770 if the user only typed Enter.
6771 Example: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006772 func s:TextEntered(text)
6773 if a:text == 'exit' || a:text == 'quit'
6774 stopinsert
Bram Moolenaarb7398fe2023-05-14 18:50:25 +01006775 " Reset 'modified' to allow the buffer to be closed.
6776 " We assume there is nothing useful to be saved.
6777 set nomodified
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006778 close
6779 else
Bram Moolenaarb7398fe2023-05-14 18:50:25 +01006780 " Do something useful with "a:text". In this example
6781 " we just repeat it.
Bram Moolenaarc51cf032022-02-26 12:25:45 +00006782 call append(line('$') - 1, 'Entered: "' .. a:text .. '"')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006783 endif
6784 endfunc
Bram Moolenaarb7398fe2023-05-14 18:50:25 +01006785 call prompt_setcallback(bufnr(), function('s:TextEntered'))
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006786
6787< Can also be used as a |method|: >
6788 GetBuffer()->prompt_setcallback(callback)
6789
6790< {only available when compiled with the |+channel| feature}
6791
6792prompt_setinterrupt({buf}, {expr}) *prompt_setinterrupt()*
6793 Set a callback for buffer {buf} to {expr}. When {expr} is an
6794 empty string the callback is removed. This has only effect if
6795 {buf} has 'buftype' set to "prompt".
6796
6797 This callback will be invoked when pressing CTRL-C in Insert
6798 mode. Without setting a callback Vim will exit Insert mode,
6799 as in any buffer.
6800
6801 Can also be used as a |method|: >
6802 GetBuffer()->prompt_setinterrupt(callback)
6803
6804< {only available when compiled with the |+channel| feature}
6805
6806prompt_setprompt({buf}, {text}) *prompt_setprompt()*
6807 Set prompt for buffer {buf} to {text}. You most likely want
6808 {text} to end in a space.
6809 The result is only visible if {buf} has 'buftype' set to
6810 "prompt". Example: >
6811 call prompt_setprompt(bufnr(), 'command: ')
6812<
6813 Can also be used as a |method|: >
6814 GetBuffer()->prompt_setprompt('command: ')
6815
6816< {only available when compiled with the |+channel| feature}
6817
6818prop_ functions are documented here: |text-prop-functions|
6819
6820pum_getpos() *pum_getpos()*
6821 If the popup menu (see |ins-completion-menu|) is not visible,
6822 returns an empty |Dictionary|, otherwise, returns a
6823 |Dictionary| with the following keys:
6824 height nr of items visible
6825 width screen cells
6826 row top screen row (0 first row)
6827 col leftmost screen column (0 first col)
6828 size total nr of items
6829 scrollbar |TRUE| if scrollbar is visible
6830
6831 The values are the same as in |v:event| during
6832 |CompleteChanged|.
6833
6834pumvisible() *pumvisible()*
6835 Returns non-zero when the popup menu is visible, zero
6836 otherwise. See |ins-completion-menu|.
6837 This can be used to avoid some things that would remove the
6838 popup menu.
6839
6840py3eval({expr}) *py3eval()*
6841 Evaluate Python expression {expr} and return its result
6842 converted to Vim data structures.
6843 Numbers and strings are returned as they are (strings are
6844 copied though, Unicode strings are additionally converted to
6845 'encoding').
6846 Lists are represented as Vim |List| type.
6847 Dictionaries are represented as Vim |Dictionary| type with
6848 keys converted to strings.
6849 Note that in a `:def` function local variables are not visible
6850 to {expr}.
6851
6852 Can also be used as a |method|: >
6853 GetExpr()->py3eval()
6854
6855< {only available when compiled with the |+python3| feature}
6856
6857 *E858* *E859*
6858pyeval({expr}) *pyeval()*
6859 Evaluate Python expression {expr} and return its result
6860 converted to Vim data structures.
6861 Numbers and strings are returned as they are (strings are
6862 copied though).
6863 Lists are represented as Vim |List| type.
6864 Dictionaries are represented as Vim |Dictionary| type,
6865 non-string keys result in error.
6866 Note that in a `:def` function local variables are not visible
6867 to {expr}.
6868
6869 Can also be used as a |method|: >
6870 GetExpr()->pyeval()
6871
6872< {only available when compiled with the |+python| feature}
6873
6874pyxeval({expr}) *pyxeval()*
6875 Evaluate Python expression {expr} and return its result
6876 converted to Vim data structures.
6877 Uses Python 2 or 3, see |python_x| and 'pyxversion'.
6878 See also: |pyeval()|, |py3eval()|
6879
6880 Can also be used as a |method|: >
6881 GetExpr()->pyxeval()
6882
6883< {only available when compiled with the |+python| or the
6884 |+python3| feature}
6885
6886rand([{expr}]) *rand()* *random*
6887 Return a pseudo-random Number generated with an xoshiro128**
6888 algorithm using seed {expr}. The returned number is 32 bits,
6889 also on 64 bits systems, for consistency.
6890 {expr} can be initialized by |srand()| and will be updated by
6891 rand(). If {expr} is omitted, an internal seed value is used
6892 and updated.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01006893 Returns -1 if {expr} is invalid.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006894
6895 Examples: >
6896 :echo rand()
6897 :let seed = srand()
6898 :echo rand(seed)
6899 :echo rand(seed) % 16 " random number 0 - 15
6900<
6901
6902 *E726* *E727*
6903range({expr} [, {max} [, {stride}]]) *range()*
6904 Returns a |List| with Numbers:
6905 - If only {expr} is specified: [0, 1, ..., {expr} - 1]
6906 - If {max} is specified: [{expr}, {expr} + 1, ..., {max}]
6907 - If {stride} is specified: [{expr}, {expr} + {stride}, ...,
6908 {max}] (increasing {expr} with {stride} each time, not
6909 producing a value past {max}).
6910 When the maximum is one before the start the result is an
6911 empty list. When the maximum is more than one before the
6912 start this is an error.
6913 Examples: >
6914 range(4) " [0, 1, 2, 3]
6915 range(2, 4) " [2, 3, 4]
6916 range(2, 9, 3) " [2, 5, 8]
6917 range(2, -2, -1) " [2, 1, 0, -1, -2]
6918 range(0) " []
6919 range(2, 0) " error!
6920<
6921 Can also be used as a |method|: >
6922 GetExpr()->range()
6923<
6924
K.Takata11df3ae2022-10-19 14:02:40 +01006925readblob({fname} [, {offset} [, {size}]]) *readblob()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006926 Read file {fname} in binary mode and return a |Blob|.
K.Takata11df3ae2022-10-19 14:02:40 +01006927 If {offset} is specified, read the file from the specified
6928 offset. If it is a negative value, it is used as an offset
6929 from the end of the file. E.g., to read the last 12 bytes: >
6930 readblob('file.bin', -12)
6931< If {size} is specified, only the specified size will be read.
6932 E.g. to read the first 100 bytes of a file: >
6933 readblob('file.bin', 0, 100)
6934< If {size} is -1 or omitted, the whole data starting from
6935 {offset} will be read.
K.Takata43625762022-10-20 13:28:51 +01006936 This can be also used to read the data from a character device
6937 on Unix when {size} is explicitly set. Only if the device
6938 supports seeking {offset} can be used. Otherwise it should be
6939 zero. E.g. to read 10 bytes from a serial console: >
6940 readblob('/dev/ttyS0', 0, 10)
6941< When the file can't be opened an error message is given and
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006942 the result is an empty |Blob|.
Bram Moolenaar5b2a3d72022-10-21 11:25:30 +01006943 When the offset is beyond the end of the file the result is an
6944 empty blob.
6945 When trying to read more bytes than are available the result
6946 is truncated.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006947 Also see |readfile()| and |writefile()|.
6948
6949
6950readdir({directory} [, {expr} [, {dict}]]) *readdir()*
6951 Return a list with file and directory names in {directory}.
6952 You can also use |glob()| if you don't need to do complicated
6953 things, such as limiting the number of matches.
6954 The list will be sorted (case sensitive), see the {dict}
6955 argument below for changing the sort order.
6956
6957 When {expr} is omitted all entries are included.
6958 When {expr} is given, it is evaluated to check what to do:
6959 If {expr} results in -1 then no further entries will
6960 be handled.
6961 If {expr} results in 0 then this entry will not be
6962 added to the list.
6963 If {expr} results in 1 then this entry will be added
6964 to the list.
6965 The entries "." and ".." are always excluded.
6966 Each time {expr} is evaluated |v:val| is set to the entry name.
6967 When {expr} is a function the name is passed as the argument.
6968 For example, to get a list of files ending in ".txt": >
6969 readdir(dirname, {n -> n =~ '.txt$'})
6970< To skip hidden and backup files: >
6971 readdir(dirname, {n -> n !~ '^\.\|\~$'})
Bram Moolenaar6f4754b2022-01-23 12:07:04 +00006972< *E857*
6973 The optional {dict} argument allows for further custom
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006974 values. Currently this is used to specify if and how sorting
6975 should be performed. The dict can have the following members:
6976
6977 sort How to sort the result returned from the system.
6978 Valid values are:
6979 "none" do not sort (fastest method)
6980 "case" sort case sensitive (byte value of
6981 each character, technically, using
6982 strcmp()) (default)
6983 "icase" sort case insensitive (technically
6984 using strcasecmp())
6985 "collate" sort using the collation order
6986 of the "POSIX" or "C" |locale|
6987 (technically using strcoll())
6988 Other values are silently ignored.
6989
6990 For example, to get a list of all files in the current
6991 directory without sorting the individual entries: >
6992 readdir('.', '1', #{sort: 'none'})
6993< If you want to get a directory tree: >
6994 function! s:tree(dir)
6995 return {a:dir : map(readdir(a:dir),
6996 \ {_, x -> isdirectory(x) ?
Bram Moolenaarc51cf032022-02-26 12:25:45 +00006997 \ {x : s:tree(a:dir .. '/' .. x)} : x})}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006998 endfunction
6999 echo s:tree(".")
7000<
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01007001 Returns an empty List on error.
7002
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007003 Can also be used as a |method|: >
7004 GetDirName()->readdir()
7005<
7006readdirex({directory} [, {expr} [, {dict}]]) *readdirex()*
7007 Extended version of |readdir()|.
7008 Return a list of Dictionaries with file and directory
7009 information in {directory}.
7010 This is useful if you want to get the attributes of file and
7011 directory at the same time as getting a list of a directory.
7012 This is much faster than calling |readdir()| then calling
7013 |getfperm()|, |getfsize()|, |getftime()| and |getftype()| for
7014 each file and directory especially on MS-Windows.
7015 The list will by default be sorted by name (case sensitive),
7016 the sorting can be changed by using the optional {dict}
7017 argument, see |readdir()|.
7018
7019 The Dictionary for file and directory information has the
7020 following items:
7021 group Group name of the entry. (Only on Unix)
7022 name Name of the entry.
7023 perm Permissions of the entry. See |getfperm()|.
7024 size Size of the entry. See |getfsize()|.
7025 time Timestamp of the entry. See |getftime()|.
7026 type Type of the entry.
7027 On Unix, almost same as |getftype()| except:
7028 Symlink to a dir "linkd"
7029 Other symlink "link"
7030 On MS-Windows:
7031 Normal file "file"
7032 Directory "dir"
7033 Junction "junction"
7034 Symlink to a dir "linkd"
7035 Other symlink "link"
7036 Other reparse point "reparse"
7037 user User name of the entry's owner. (Only on Unix)
7038 On Unix, if the entry is a symlink, the Dictionary includes
7039 the information of the target (except the "type" item).
7040 On MS-Windows, it includes the information of the symlink
7041 itself because of performance reasons.
7042
7043 When {expr} is omitted all entries are included.
7044 When {expr} is given, it is evaluated to check what to do:
7045 If {expr} results in -1 then no further entries will
7046 be handled.
7047 If {expr} results in 0 then this entry will not be
7048 added to the list.
7049 If {expr} results in 1 then this entry will be added
7050 to the list.
7051 The entries "." and ".." are always excluded.
7052 Each time {expr} is evaluated |v:val| is set to a |Dictionary|
7053 of the entry.
7054 When {expr} is a function the entry is passed as the argument.
7055 For example, to get a list of files ending in ".txt": >
7056 readdirex(dirname, {e -> e.name =~ '.txt$'})
7057<
7058 For example, to get a list of all files in the current
7059 directory without sorting the individual entries: >
7060 readdirex(dirname, '1', #{sort: 'none'})
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007061<
7062 Can also be used as a |method|: >
7063 GetDirName()->readdirex()
7064<
7065
7066 *readfile()*
7067readfile({fname} [, {type} [, {max}]])
7068 Read file {fname} and return a |List|, each line of the file
7069 as an item. Lines are broken at NL characters. Macintosh
7070 files separated with CR will result in a single long line
7071 (unless a NL appears somewhere).
7072 All NUL characters are replaced with a NL character.
7073 When {type} contains "b" binary mode is used:
7074 - When the last line ends in a NL an extra empty list item is
7075 added.
7076 - No CR characters are removed.
7077 Otherwise:
7078 - CR characters that appear before a NL are removed.
7079 - Whether the last line ends in a NL or not does not matter.
7080 - When 'encoding' is Unicode any UTF-8 byte order mark is
7081 removed from the text.
7082 When {max} is given this specifies the maximum number of lines
7083 to be read. Useful if you only want to check the first ten
7084 lines of a file: >
7085 :for line in readfile(fname, '', 10)
7086 : if line =~ 'Date' | echo line | endif
7087 :endfor
7088< When {max} is negative -{max} lines from the end of the file
7089 are returned, or as many as there are.
7090 When {max} is zero the result is an empty list.
7091 Note that without {max} the whole file is read into memory.
7092 Also note that there is no recognition of encoding. Read a
7093 file into a buffer if you need to.
7094 Deprecated (use |readblob()| instead): When {type} contains
7095 "B" a |Blob| is returned with the binary data of the file
7096 unmodified.
7097 When the file can't be opened an error message is given and
7098 the result is an empty list.
7099 Also see |writefile()|.
7100
7101 Can also be used as a |method|: >
7102 GetFileName()->readfile()
7103
7104reduce({object}, {func} [, {initial}]) *reduce()* *E998*
7105 {func} is called for every item in {object}, which can be a
7106 |String|, |List| or a |Blob|. {func} is called with two
7107 arguments: the result so far and current item. After
Bram Moolenaarf10911e2022-01-29 22:20:48 +00007108 processing all items the result is returned. *E1132*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007109
7110 {initial} is the initial result. When omitted, the first item
7111 in {object} is used and {func} is first called for the second
7112 item. If {initial} is not given and {object} is empty no
7113 result can be computed, an E998 error is given.
7114
7115 Examples: >
7116 echo reduce([1, 3, 5], { acc, val -> acc + val })
7117 echo reduce(['x', 'y'], { acc, val -> acc .. val }, 'a')
7118 echo reduce(0z1122, { acc, val -> 2 * acc + val })
7119 echo reduce('xyz', { acc, val -> acc .. ',' .. val })
7120<
7121 Can also be used as a |method|: >
7122 echo mylist->reduce({ acc, val -> acc + val }, 0)
7123
7124
7125reg_executing() *reg_executing()*
7126 Returns the single letter name of the register being executed.
7127 Returns an empty string when no register is being executed.
7128 See |@|.
7129
7130reg_recording() *reg_recording()*
7131 Returns the single letter name of the register being recorded.
7132 Returns an empty string when not recording. See |q|.
7133
Bram Moolenaarf269eab2022-10-03 18:04:35 +01007134reltime()
7135reltime({start})
7136reltime({start}, {end}) *reltime()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007137 Return an item that represents a time value. The item is a
7138 list with items that depend on the system. In Vim 9 script
Bram Moolenaar71badf92023-04-22 22:40:14 +01007139 the type list<any> can be used.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007140 The item can be passed to |reltimestr()| to convert it to a
Bram Moolenaarf269eab2022-10-03 18:04:35 +01007141 string or |reltimefloat()| to convert to a Float. For
7142 example, to see the time spent in function Work(): >
7143 var startTime = reltime()
7144 Work()
7145 echo startTime->reltime()->reltimestr()
7146<
Bram Moolenaar016188f2022-06-06 20:52:59 +01007147 Without an argument reltime() returns the current time (the
Bram Moolenaareb490412022-06-28 13:44:46 +01007148 representation is system-dependent, it can not be used as the
Bram Moolenaar016188f2022-06-06 20:52:59 +01007149 wall-clock time, see |localtime()| for that).
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007150 With one argument is returns the time passed since the time
7151 specified in the argument.
7152 With two arguments it returns the time passed between {start}
7153 and {end}.
7154
7155 The {start} and {end} arguments must be values returned by
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01007156 reltime(). If there is an error an empty List is returned in
7157 legacy script, in Vim9 script an error is given.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007158
7159 Can also be used as a |method|: >
7160 GetStart()->reltime()
7161<
7162 {only available when compiled with the |+reltime| feature}
7163
7164reltimefloat({time}) *reltimefloat()*
7165 Return a Float that represents the time value of {time}.
7166 Example: >
7167 let start = reltime()
7168 call MyFunction()
7169 let seconds = reltimefloat(reltime(start))
7170< See the note of reltimestr() about overhead.
7171 Also see |profiling|.
7172 If there is an error 0.0 is returned in legacy script, in Vim9
7173 script an error is given.
7174
7175 Can also be used as a |method|: >
7176 reltime(start)->reltimefloat()
7177
7178< {only available when compiled with the |+reltime| feature}
7179
7180reltimestr({time}) *reltimestr()*
7181 Return a String that represents the time value of {time}.
7182 This is the number of seconds, a dot and the number of
7183 microseconds. Example: >
7184 let start = reltime()
7185 call MyFunction()
7186 echo reltimestr(reltime(start))
7187< Note that overhead for the commands will be added to the time.
Ernie Rael076de792023-03-16 21:43:15 +00007188 The accuracy depends on the system. Use reltimefloat() for the
7189 greatest accuracy which is nanoseconds on some systems.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007190 Leading spaces are used to make the string align nicely. You
7191 can use split() to remove it. >
7192 echo split(reltimestr(reltime(start)))[0]
7193< Also see |profiling|.
7194 If there is an error an empty string is returned in legacy
7195 script, in Vim9 script an error is given.
7196
7197 Can also be used as a |method|: >
7198 reltime(start)->reltimestr()
7199
7200< {only available when compiled with the |+reltime| feature}
7201
7202 *remote_expr()* *E449*
7203remote_expr({server}, {string} [, {idvar} [, {timeout}]])
Bram Moolenaar944697a2022-02-20 19:48:20 +00007204 Send the {string} to {server}. The {server} argument is a
7205 string, also see |{server}|.
7206
7207 The string is sent as an expression and the result is returned
7208 after evaluation. The result must be a String or a |List|. A
7209 |List| is turned into a String by joining the items with a
7210 line break in between (not at the end), like with join(expr,
7211 "\n").
7212
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007213 If {idvar} is present and not empty, it is taken as the name
7214 of a variable and a {serverid} for later use with
7215 |remote_read()| is stored there.
Bram Moolenaar944697a2022-02-20 19:48:20 +00007216
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007217 If {timeout} is given the read times out after this many
7218 seconds. Otherwise a timeout of 600 seconds is used.
Bram Moolenaar944697a2022-02-20 19:48:20 +00007219
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007220 See also |clientserver| |RemoteReply|.
7221 This function is not available in the |sandbox|.
7222 {only available when compiled with the |+clientserver| feature}
7223 Note: Any errors will cause a local error message to be issued
7224 and the result will be the empty string.
7225
7226 Variables will be evaluated in the global namespace,
7227 independent of a function currently being active. Except
7228 when in debug mode, then local function variables and
7229 arguments can be evaluated.
7230
7231 Examples: >
7232 :echo remote_expr("gvim", "2+2")
7233 :echo remote_expr("gvim1", "b:current_syntax")
7234<
7235 Can also be used as a |method|: >
7236 ServerName()->remote_expr(expr)
7237
7238remote_foreground({server}) *remote_foreground()*
7239 Move the Vim server with the name {server} to the foreground.
Bram Moolenaar944697a2022-02-20 19:48:20 +00007240 The {server} argument is a string, also see |{server}|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007241 This works like: >
7242 remote_expr({server}, "foreground()")
7243< Except that on Win32 systems the client does the work, to work
7244 around the problem that the OS doesn't always allow the server
7245 to bring itself to the foreground.
7246 Note: This does not restore the window if it was minimized,
7247 like foreground() does.
7248 This function is not available in the |sandbox|.
7249
7250 Can also be used as a |method|: >
7251 ServerName()->remote_foreground()
7252
Bram Moolenaarcbaff5e2022-04-08 17:45:08 +01007253< {only in the Win32, Motif and GTK GUI versions and the
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007254 Win32 console version}
7255
7256
7257remote_peek({serverid} [, {retvar}]) *remote_peek()*
7258 Returns a positive number if there are available strings
7259 from {serverid}. Copies any reply string into the variable
7260 {retvar} if specified. {retvar} must be a string with the
7261 name of a variable.
7262 Returns zero if none are available.
7263 Returns -1 if something is wrong.
7264 See also |clientserver|.
7265 This function is not available in the |sandbox|.
7266 {only available when compiled with the |+clientserver| feature}
7267 Examples: >
Bram Moolenaarf269eab2022-10-03 18:04:35 +01007268 :let repl = ""
7269 :echo "PEEK: " .. remote_peek(id, "repl") .. ": " .. repl
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007270
7271< Can also be used as a |method|: >
7272 ServerId()->remote_peek()
7273
7274remote_read({serverid}, [{timeout}]) *remote_read()*
7275 Return the oldest available reply from {serverid} and consume
7276 it. Unless a {timeout} in seconds is given, it blocks until a
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01007277 reply is available. Returns an empty string, if a reply is
7278 not available or on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007279 See also |clientserver|.
7280 This function is not available in the |sandbox|.
7281 {only available when compiled with the |+clientserver| feature}
7282 Example: >
7283 :echo remote_read(id)
7284
7285< Can also be used as a |method|: >
7286 ServerId()->remote_read()
7287<
7288 *remote_send()* *E241*
7289remote_send({server}, {string} [, {idvar}])
Bram Moolenaar944697a2022-02-20 19:48:20 +00007290 Send the {string} to {server}. The {server} argument is a
7291 string, also see |{server}|.
7292
7293 The string is sent as input keys and the function returns
7294 immediately. At the Vim server the keys are not mapped
7295 |:map|.
7296
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007297 If {idvar} is present, it is taken as the name of a variable
7298 and a {serverid} for later use with remote_read() is stored
7299 there.
Bram Moolenaar944697a2022-02-20 19:48:20 +00007300
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007301 See also |clientserver| |RemoteReply|.
7302 This function is not available in the |sandbox|.
7303 {only available when compiled with the |+clientserver| feature}
7304
7305 Note: Any errors will be reported in the server and may mess
7306 up the display.
7307 Examples: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00007308 :echo remote_send("gvim", ":DropAndReply " .. file, "serverid") ..
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007309 \ remote_read(serverid)
7310
7311 :autocmd NONE RemoteReply *
7312 \ echo remote_read(expand("<amatch>"))
Bram Moolenaarc51cf032022-02-26 12:25:45 +00007313 :echo remote_send("gvim", ":sleep 10 | echo " ..
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007314 \ 'server2client(expand("<client>"), "HELLO")<CR>')
7315<
7316 Can also be used as a |method|: >
7317 ServerName()->remote_send(keys)
7318<
7319 *remote_startserver()* *E941* *E942*
7320remote_startserver({name})
h-east17b69512023-05-01 22:36:56 +01007321 Become the server {name}. {name} must be a non-empty string.
7322 This fails if already running as a server, when |v:servername|
7323 is not empty.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007324
7325 Can also be used as a |method|: >
7326 ServerName()->remote_startserver()
7327
7328< {only available when compiled with the |+clientserver| feature}
7329
Bram Moolenaarf269eab2022-10-03 18:04:35 +01007330remove({list}, {idx})
7331remove({list}, {idx}, {end}) *remove()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007332 Without {end}: Remove the item at {idx} from |List| {list} and
7333 return the item.
7334 With {end}: Remove items from {idx} to {end} (inclusive) and
7335 return a |List| with these items. When {idx} points to the same
7336 item as {end} a list with one item is returned. When {end}
7337 points to an item before {idx} this is an error.
7338 See |list-index| for possible values of {idx} and {end}.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01007339 Returns zero on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007340 Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00007341 :echo "last item: " .. remove(mylist, -1)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007342 :call remove(mylist, 0, 9)
7343<
7344 Use |delete()| to remove a file.
7345
7346 Can also be used as a |method|: >
7347 mylist->remove(idx)
7348
Bram Moolenaarf269eab2022-10-03 18:04:35 +01007349remove({blob}, {idx})
7350remove({blob}, {idx}, {end})
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007351 Without {end}: Remove the byte at {idx} from |Blob| {blob} and
7352 return the byte.
7353 With {end}: Remove bytes from {idx} to {end} (inclusive) and
7354 return a |Blob| with these bytes. When {idx} points to the same
7355 byte as {end} a |Blob| with one byte is returned. When {end}
7356 points to a byte before {idx} this is an error.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01007357 Returns zero on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007358 Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00007359 :echo "last byte: " .. remove(myblob, -1)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007360 :call remove(mylist, 0, 9)
7361
7362remove({dict}, {key})
7363 Remove the entry from {dict} with key {key} and return it.
7364 Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00007365 :echo "removed " .. remove(dict, "one")
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007366< If there is no {key} in {dict} this is an error.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01007367 Returns zero on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007368
7369rename({from}, {to}) *rename()*
7370 Rename the file by the name {from} to the name {to}. This
7371 should also work to move files across file systems. The
7372 result is a Number, which is 0 if the file was renamed
7373 successfully, and non-zero when the renaming failed.
7374 NOTE: If {to} exists it is overwritten without warning.
7375 This function is not available in the |sandbox|.
7376
7377 Can also be used as a |method|: >
7378 GetOldName()->rename(newname)
7379
7380repeat({expr}, {count}) *repeat()*
7381 Repeat {expr} {count} times and return the concatenated
7382 result. Example: >
7383 :let separator = repeat('-', 80)
7384< When {count} is zero or negative the result is empty.
Bakudankun375141e2022-09-09 18:46:47 +01007385 When {expr} is a |List| or a |Blob| the result is {expr}
7386 concatenated {count} times. Example: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007387 :let longlist = repeat(['a', 'b'], 3)
7388< Results in ['a', 'b', 'a', 'b', 'a', 'b'].
7389
7390 Can also be used as a |method|: >
7391 mylist->repeat(count)
7392
7393resolve({filename}) *resolve()* *E655*
7394 On MS-Windows, when {filename} is a shortcut (a .lnk file),
7395 returns the path the shortcut points to in a simplified form.
7396 When {filename} is a symbolic link or junction point, return
7397 the full path to the target. If the target of junction is
7398 removed, return {filename}.
7399 On Unix, repeat resolving symbolic links in all path
7400 components of {filename} and return the simplified result.
7401 To cope with link cycles, resolving of symbolic links is
7402 stopped after 100 iterations.
7403 On other systems, return the simplified {filename}.
7404 The simplification step is done as by |simplify()|.
7405 resolve() keeps a leading path component specifying the
7406 current directory (provided the result is still a relative
7407 path name) and also keeps a trailing path separator.
7408
7409 Can also be used as a |method|: >
7410 GetName()->resolve()
7411
7412reverse({object}) *reverse()*
Yegappan Lakshmanan03ff1c22023-05-06 14:08:21 +01007413 Reverse the order of items in {object}. {object} can be a
7414 |List|, a |Blob| or a |String|. For a List and a Blob the
7415 items are reversed in-place and {object} is returned.
7416 For a String a new String is returned.
7417 Returns zero if {object} is not a List, Blob or a String.
7418 If you want a List or Blob to remain unmodified make a copy
7419 first: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007420 :let revlist = reverse(copy(mylist))
7421< Can also be used as a |method|: >
7422 mylist->reverse()
7423
7424round({expr}) *round()*
7425 Round off {expr} to the nearest integral value and return it
7426 as a |Float|. If {expr} lies halfway between two integral
7427 values, then use the larger one (away from zero).
7428 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01007429 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007430 Examples: >
7431 echo round(0.456)
7432< 0.0 >
7433 echo round(4.5)
7434< 5.0 >
7435 echo round(-4.5)
7436< -5.0
7437
7438 Can also be used as a |method|: >
7439 Compute()->round()
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007440
7441rubyeval({expr}) *rubyeval()*
7442 Evaluate Ruby expression {expr} and return its result
7443 converted to Vim data structures.
7444 Numbers, floats and strings are returned as they are (strings
7445 are copied though).
7446 Arrays are represented as Vim |List| type.
7447 Hashes are represented as Vim |Dictionary| type.
7448 Other objects are represented as strings resulted from their
7449 "Object#to_s" method.
7450 Note that in a `:def` function local variables are not visible
7451 to {expr}.
7452
7453 Can also be used as a |method|: >
7454 GetRubyExpr()->rubyeval()
7455
7456< {only available when compiled with the |+ruby| feature}
7457
7458screenattr({row}, {col}) *screenattr()*
7459 Like |screenchar()|, but return the attribute. This is a rather
7460 arbitrary number that can only be used to compare to the
7461 attribute at other positions.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01007462 Returns -1 when row or col is out of range.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007463
7464 Can also be used as a |method|: >
7465 GetRow()->screenattr(col)
7466
7467screenchar({row}, {col}) *screenchar()*
7468 The result is a Number, which is the character at position
7469 [row, col] on the screen. This works for every possible
7470 screen position, also status lines, window separators and the
7471 command line. The top left position is row one, column one
7472 The character excludes composing characters. For double-byte
7473 encodings it may only be the first byte.
7474 This is mainly to be used for testing.
7475 Returns -1 when row or col is out of range.
7476
7477 Can also be used as a |method|: >
7478 GetRow()->screenchar(col)
7479
7480screenchars({row}, {col}) *screenchars()*
7481 The result is a |List| of Numbers. The first number is the same
7482 as what |screenchar()| returns. Further numbers are
7483 composing characters on top of the base character.
7484 This is mainly to be used for testing.
7485 Returns an empty List when row or col is out of range.
7486
7487 Can also be used as a |method|: >
7488 GetRow()->screenchars(col)
7489
7490screencol() *screencol()*
7491 The result is a Number, which is the current screen column of
7492 the cursor. The leftmost column has number 1.
7493 This function is mainly used for testing.
7494
7495 Note: Always returns the current screen column, thus if used
7496 in a command (e.g. ":echo screencol()") it will return the
7497 column inside the command line, which is 1 when the command is
7498 executed. To get the cursor position in the file use one of
7499 the following mappings: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00007500 nnoremap <expr> GG ":echom " .. screencol() .. "\n"
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007501 nnoremap <silent> GG :echom screencol()<CR>
7502 nnoremap GG <Cmd>echom screencol()<CR>
7503<
7504screenpos({winid}, {lnum}, {col}) *screenpos()*
7505 The result is a Dict with the screen position of the text
7506 character in window {winid} at buffer line {lnum} and column
7507 {col}. {col} is a one-based byte index.
7508 The Dict has these members:
7509 row screen row
7510 col first screen column
7511 endcol last screen column
7512 curscol cursor screen column
7513 If the specified position is not visible, all values are zero.
7514 The "endcol" value differs from "col" when the character
7515 occupies more than one screen cell. E.g. for a Tab "col" can
7516 be 1 and "endcol" can be 8.
7517 The "curscol" value is where the cursor would be placed. For
7518 a Tab it would be the same as "endcol", while for a double
7519 width character it would be the same as "col".
7520 The |conceal| feature is ignored here, the column numbers are
7521 as if 'conceallevel' is zero. You can set the cursor to the
7522 right position and use |screencol()| to get the value with
7523 |conceal| taken into account.
Bram Moolenaar944697a2022-02-20 19:48:20 +00007524 If the position is in a closed fold the screen position of the
7525 first character is returned, {col} is not used.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01007526 Returns an empty Dict if {winid} is invalid.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007527
7528 Can also be used as a |method|: >
7529 GetWinid()->screenpos(lnum, col)
7530
7531screenrow() *screenrow()*
7532 The result is a Number, which is the current screen row of the
7533 cursor. The top line has number one.
7534 This function is mainly used for testing.
7535 Alternatively you can use |winline()|.
7536
7537 Note: Same restrictions as with |screencol()|.
7538
7539screenstring({row}, {col}) *screenstring()*
7540 The result is a String that contains the base character and
7541 any composing characters at position [row, col] on the screen.
7542 This is like |screenchars()| but returning a String with the
7543 characters.
7544 This is mainly to be used for testing.
7545 Returns an empty String when row or col is out of range.
7546
7547 Can also be used as a |method|: >
7548 GetRow()->screenstring(col)
7549<
7550 *search()*
7551search({pattern} [, {flags} [, {stopline} [, {timeout} [, {skip}]]]])
7552 Search for regexp pattern {pattern}. The search starts at the
7553 cursor position (you can use |cursor()| to set it).
7554
7555 When a match has been found its line number is returned.
7556 If there is no match a 0 is returned and the cursor doesn't
7557 move. No error message is given.
7558
7559 {flags} is a String, which can contain these character flags:
7560 'b' search Backward instead of forward
7561 'c' accept a match at the Cursor position
7562 'e' move to the End of the match
7563 'n' do Not move the cursor
7564 'p' return number of matching sub-Pattern (see below)
7565 's' Set the ' mark at the previous location of the cursor
7566 'w' Wrap around the end of the file
7567 'W' don't Wrap around the end of the file
7568 'z' start searching at the cursor column instead of zero
7569 If neither 'w' or 'W' is given, the 'wrapscan' option applies.
7570
7571 If the 's' flag is supplied, the ' mark is set, only if the
7572 cursor is moved. The 's' flag cannot be combined with the 'n'
7573 flag.
7574
7575 'ignorecase', 'smartcase' and 'magic' are used.
7576
7577 When the 'z' flag is not given, forward searching always
7578 starts in column zero and then matches before the cursor are
7579 skipped. When the 'c' flag is present in 'cpo' the next
7580 search starts after the match. Without the 'c' flag the next
Bram Moolenaarfd999452022-08-24 18:30:14 +01007581 search starts one column after the start of the match. This
7582 matters for overlapping matches. See |cpo-c|. You can also
7583 insert "\ze" to change where the match ends, see |/\ze|.
7584
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007585 When searching backwards and the 'z' flag is given then the
7586 search starts in column zero, thus no match in the current
7587 line will be found (unless wrapping around the end of the
7588 file).
7589
7590 When the {stopline} argument is given then the search stops
7591 after searching this line. This is useful to restrict the
7592 search to a range of lines. Examples: >
7593 let match = search('(', 'b', line("w0"))
7594 let end = search('END', '', line("w$"))
7595< When {stopline} is used and it is not zero this also implies
7596 that the search does not wrap around the end of the file.
7597 A zero value is equal to not giving the argument.
Bram Moolenaar2ecbe532022-07-29 21:36:21 +01007598 *E1285* *E1286* *E1287* *E1288* *E1289*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007599 When the {timeout} argument is given the search stops when
7600 more than this many milliseconds have passed. Thus when
7601 {timeout} is 500 the search stops after half a second.
7602 The value must not be negative. A zero value is like not
7603 giving the argument.
7604 {only available when compiled with the |+reltime| feature}
7605
7606 If the {skip} expression is given it is evaluated with the
7607 cursor positioned on the start of a match. If it evaluates to
7608 non-zero this match is skipped. This can be used, for
7609 example, to skip a match in a comment or a string.
7610 {skip} can be a string, which is evaluated as an expression, a
7611 function reference or a lambda.
7612 When {skip} is omitted or empty, every match is accepted.
7613 When evaluating {skip} causes an error the search is aborted
7614 and -1 returned.
7615 *search()-sub-match*
7616 With the 'p' flag the returned value is one more than the
7617 first sub-match in \(\). One if none of them matched but the
7618 whole pattern did match.
7619 To get the column number too use |searchpos()|.
7620
7621 The cursor will be positioned at the match, unless the 'n'
7622 flag is used.
7623
7624 Example (goes over all files in the argument list): >
7625 :let n = 1
7626 :while n <= argc() " loop over all files in arglist
Bram Moolenaarc51cf032022-02-26 12:25:45 +00007627 : exe "argument " .. n
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007628 : " start at the last char in the file and wrap for the
7629 : " first search to find match at start of file
7630 : normal G$
7631 : let flags = "w"
7632 : while search("foo", flags) > 0
7633 : s/foo/bar/g
7634 : let flags = "W"
7635 : endwhile
7636 : update " write the file if modified
7637 : let n = n + 1
7638 :endwhile
7639<
7640 Example for using some flags: >
7641 :echo search('\<if\|\(else\)\|\(endif\)', 'ncpe')
7642< This will search for the keywords "if", "else", and "endif"
7643 under or after the cursor. Because of the 'p' flag, it
7644 returns 1, 2, or 3 depending on which keyword is found, or 0
7645 if the search fails. With the cursor on the first word of the
7646 line:
7647 if (foo == 0) | let foo = foo + 1 | endif ~
7648 the function returns 1. Without the 'c' flag, the function
7649 finds the "endif" and returns 3. The same thing happens
7650 without the 'e' flag if the cursor is on the "f" of "if".
7651 The 'n' flag tells the function not to move the cursor.
7652
7653 Can also be used as a |method|: >
7654 GetPattern()->search()
7655
7656searchcount([{options}]) *searchcount()*
7657 Get or update the last search count, like what is displayed
7658 without the "S" flag in 'shortmess'. This works even if
7659 'shortmess' does contain the "S" flag.
7660
7661 This returns a |Dictionary|. The dictionary is empty if the
7662 previous pattern was not set and "pattern" was not specified.
7663
7664 key type meaning ~
7665 current |Number| current position of match;
7666 0 if the cursor position is
7667 before the first match
7668 exact_match |Boolean| 1 if "current" is matched on
7669 "pos", otherwise 0
7670 total |Number| total count of matches found
7671 incomplete |Number| 0: search was fully completed
7672 1: recomputing was timed out
7673 2: max count exceeded
7674
7675 For {options} see further down.
7676
7677 To get the last search count when |n| or |N| was pressed, call
7678 this function with `recompute: 0` . This sometimes returns
7679 wrong information because |n| and |N|'s maximum count is 99.
7680 If it exceeded 99 the result must be max count + 1 (100). If
7681 you want to get correct information, specify `recompute: 1`: >
7682
7683 " result == maxcount + 1 (100) when many matches
7684 let result = searchcount(#{recompute: 0})
7685
7686 " Below returns correct result (recompute defaults
7687 " to 1)
7688 let result = searchcount()
7689<
Bram Moolenaarb529cfb2022-07-25 15:42:07 +01007690 The function is useful to add the count to 'statusline': >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007691 function! LastSearchCount() abort
7692 let result = searchcount(#{recompute: 0})
7693 if empty(result)
7694 return ''
7695 endif
7696 if result.incomplete ==# 1 " timed out
7697 return printf(' /%s [?/??]', @/)
7698 elseif result.incomplete ==# 2 " max count exceeded
7699 if result.total > result.maxcount &&
7700 \ result.current > result.maxcount
7701 return printf(' /%s [>%d/>%d]', @/,
7702 \ result.current, result.total)
7703 elseif result.total > result.maxcount
7704 return printf(' /%s [%d/>%d]', @/,
7705 \ result.current, result.total)
7706 endif
7707 endif
7708 return printf(' /%s [%d/%d]', @/,
7709 \ result.current, result.total)
7710 endfunction
Bram Moolenaarc51cf032022-02-26 12:25:45 +00007711 let &statusline ..= '%{LastSearchCount()}'
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007712
7713 " Or if you want to show the count only when
7714 " 'hlsearch' was on
Bram Moolenaarc51cf032022-02-26 12:25:45 +00007715 " let &statusline ..=
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007716 " \ '%{v:hlsearch ? LastSearchCount() : ""}'
7717<
7718 You can also update the search count, which can be useful in a
7719 |CursorMoved| or |CursorMovedI| autocommand: >
7720
7721 autocmd CursorMoved,CursorMovedI *
7722 \ let s:searchcount_timer = timer_start(
7723 \ 200, function('s:update_searchcount'))
7724 function! s:update_searchcount(timer) abort
7725 if a:timer ==# s:searchcount_timer
7726 call searchcount(#{
7727 \ recompute: 1, maxcount: 0, timeout: 100})
7728 redrawstatus
7729 endif
7730 endfunction
7731<
7732 This can also be used to count matched texts with specified
7733 pattern in the current buffer using "pattern": >
7734
7735 " Count '\<foo\>' in this buffer
7736 " (Note that it also updates search count)
7737 let result = searchcount(#{pattern: '\<foo\>'})
7738
7739 " To restore old search count by old pattern,
7740 " search again
7741 call searchcount()
7742<
7743 {options} must be a |Dictionary|. It can contain:
7744 key type meaning ~
7745 recompute |Boolean| if |TRUE|, recompute the count
7746 like |n| or |N| was executed.
7747 otherwise returns the last
7748 computed result (when |n| or
7749 |N| was used when "S" is not
7750 in 'shortmess', or this
7751 function was called).
7752 (default: |TRUE|)
7753 pattern |String| recompute if this was given
7754 and different with |@/|.
7755 this works as same as the
7756 below command is executed
7757 before calling this function >
7758 let @/ = pattern
7759< (default: |@/|)
7760 timeout |Number| 0 or negative number is no
7761 timeout. timeout milliseconds
7762 for recomputing the result
7763 (default: 0)
7764 maxcount |Number| 0 or negative number is no
7765 limit. max count of matched
7766 text while recomputing the
7767 result. if search exceeded
7768 total count, "total" value
7769 becomes `maxcount + 1`
7770 (default: 99)
7771 pos |List| `[lnum, col, off]` value
7772 when recomputing the result.
7773 this changes "current" result
7774 value. see |cursor()|,
7775 |getpos()|
7776 (default: cursor's position)
7777
7778 Can also be used as a |method|: >
7779 GetSearchOpts()->searchcount()
7780<
7781searchdecl({name} [, {global} [, {thisblock}]]) *searchdecl()*
7782 Search for the declaration of {name}.
7783
7784 With a non-zero {global} argument it works like |gD|, find
7785 first match in the file. Otherwise it works like |gd|, find
7786 first match in the function.
7787
7788 With a non-zero {thisblock} argument matches in a {} block
7789 that ends before the cursor position are ignored. Avoids
7790 finding variable declarations only valid in another scope.
7791
7792 Moves the cursor to the found match.
7793 Returns zero for success, non-zero for failure.
7794 Example: >
7795 if searchdecl('myvar') == 0
7796 echo getline('.')
7797 endif
7798<
7799 Can also be used as a |method|: >
7800 GetName()->searchdecl()
7801<
7802 *searchpair()*
7803searchpair({start}, {middle}, {end} [, {flags} [, {skip}
7804 [, {stopline} [, {timeout}]]]])
7805 Search for the match of a nested start-end pair. This can be
7806 used to find the "endif" that matches an "if", while other
7807 if/endif pairs in between are ignored.
7808 The search starts at the cursor. The default is to search
7809 forward, include 'b' in {flags} to search backward.
7810 If a match is found, the cursor is positioned at it and the
7811 line number is returned. If no match is found 0 or -1 is
7812 returned and the cursor doesn't move. No error message is
7813 given.
7814
7815 {start}, {middle} and {end} are patterns, see |pattern|. They
7816 must not contain \( \) pairs. Use of \%( \) is allowed. When
7817 {middle} is not empty, it is found when searching from either
7818 direction, but only when not in a nested start-end pair. A
7819 typical use is: >
7820 searchpair('\<if\>', '\<else\>', '\<endif\>')
7821< By leaving {middle} empty the "else" is skipped.
7822
7823 {flags} 'b', 'c', 'n', 's', 'w' and 'W' are used like with
7824 |search()|. Additionally:
7825 'r' Repeat until no more matches found; will find the
7826 outer pair. Implies the 'W' flag.
7827 'm' Return number of matches instead of line number with
7828 the match; will be > 1 when 'r' is used.
7829 Note: it's nearly always a good idea to use the 'W' flag, to
7830 avoid wrapping around the end of the file.
7831
7832 When a match for {start}, {middle} or {end} is found, the
7833 {skip} expression is evaluated with the cursor positioned on
7834 the start of the match. It should return non-zero if this
7835 match is to be skipped. E.g., because it is inside a comment
7836 or a string.
7837 When {skip} is omitted or empty, every match is accepted.
7838 When evaluating {skip} causes an error the search is aborted
7839 and -1 returned.
7840 {skip} can be a string, a lambda, a funcref or a partial.
7841 Anything else makes the function fail.
7842 In a `:def` function when the {skip} argument is a string
7843 constant it is compiled into instructions.
7844
7845 For {stopline} and {timeout} see |search()|.
7846
7847 The value of 'ignorecase' is used. 'magic' is ignored, the
7848 patterns are used like it's on.
7849
7850 The search starts exactly at the cursor. A match with
7851 {start}, {middle} or {end} at the next character, in the
7852 direction of searching, is the first one found. Example: >
7853 if 1
7854 if 2
7855 endif 2
7856 endif 1
7857< When starting at the "if 2", with the cursor on the "i", and
7858 searching forwards, the "endif 2" is found. When starting on
7859 the character just before the "if 2", the "endif 1" will be
7860 found. That's because the "if 2" will be found first, and
7861 then this is considered to be a nested if/endif from "if 2" to
7862 "endif 2".
7863 When searching backwards and {end} is more than one character,
7864 it may be useful to put "\zs" at the end of the pattern, so
7865 that when the cursor is inside a match with the end it finds
7866 the matching start.
7867
7868 Example, to find the "endif" command in a Vim script: >
7869
7870 :echo searchpair('\<if\>', '\<el\%[seif]\>', '\<en\%[dif]\>', 'W',
7871 \ 'getline(".") =~ "^\\s*\""')
7872
7873< The cursor must be at or after the "if" for which a match is
7874 to be found. Note that single-quote strings are used to avoid
7875 having to double the backslashes. The skip expression only
7876 catches comments at the start of a line, not after a command.
7877 Also, a word "en" or "if" halfway a line is considered a
7878 match.
7879 Another example, to search for the matching "{" of a "}": >
7880
7881 :echo searchpair('{', '', '}', 'bW')
7882
7883< This works when the cursor is at or before the "}" for which a
7884 match is to be found. To reject matches that syntax
7885 highlighting recognized as strings: >
7886
7887 :echo searchpair('{', '', '}', 'bW',
7888 \ 'synIDattr(synID(line("."), col("."), 0), "name") =~? "string"')
7889<
7890 *searchpairpos()*
7891searchpairpos({start}, {middle}, {end} [, {flags} [, {skip}
7892 [, {stopline} [, {timeout}]]]])
7893 Same as |searchpair()|, but returns a |List| with the line and
7894 column position of the match. The first element of the |List|
7895 is the line number and the second element is the byte index of
7896 the column position of the match. If no match is found,
7897 returns [0, 0]. >
7898
7899 :let [lnum,col] = searchpairpos('{', '', '}', 'n')
7900<
7901 See |match-parens| for a bigger and more useful example.
7902
7903 *searchpos()*
7904searchpos({pattern} [, {flags} [, {stopline} [, {timeout} [, {skip}]]]])
7905 Same as |search()|, but returns a |List| with the line and
7906 column position of the match. The first element of the |List|
7907 is the line number and the second element is the byte index of
7908 the column position of the match. If no match is found,
7909 returns [0, 0].
7910 Example: >
7911 :let [lnum, col] = searchpos('mypattern', 'n')
7912
7913< When the 'p' flag is given then there is an extra item with
7914 the sub-pattern match number |search()-sub-match|. Example: >
7915 :let [lnum, col, submatch] = searchpos('\(\l\)\|\(\u\)', 'np')
7916< In this example "submatch" is 2 when a lowercase letter is
7917 found |/\l|, 3 when an uppercase letter is found |/\u|.
7918
7919 Can also be used as a |method|: >
7920 GetPattern()->searchpos()
7921
7922server2client({clientid}, {string}) *server2client()*
7923 Send a reply string to {clientid}. The most recent {clientid}
7924 that sent a string can be retrieved with expand("<client>").
7925 {only available when compiled with the |+clientserver| feature}
7926 Returns zero for success, -1 for failure.
7927 Note:
7928 This id has to be stored before the next command can be
7929 received. I.e. before returning from the received command and
7930 before calling any commands that waits for input.
7931 See also |clientserver|.
7932 Example: >
7933 :echo server2client(expand("<client>"), "HELLO")
7934
7935< Can also be used as a |method|: >
7936 GetClientId()->server2client(string)
7937<
7938serverlist() *serverlist()*
7939 Return a list of available server names, one per line.
7940 When there are no servers or the information is not available
7941 an empty string is returned. See also |clientserver|.
7942 {only available when compiled with the |+clientserver| feature}
7943 Example: >
7944 :echo serverlist()
7945<
7946setbufline({buf}, {lnum}, {text}) *setbufline()*
7947 Set line {lnum} to {text} in buffer {buf}. This works like
7948 |setline()| for the specified buffer.
7949
7950 This function works only for loaded buffers. First call
7951 |bufload()| if needed.
7952
7953 To insert lines use |appendbufline()|.
7954 Any text properties in {lnum} are cleared.
7955
Bram Moolenaarcd9c8d42022-11-05 23:46:43 +00007956 {text} can be a string to set one line, or a List of strings
7957 to set multiple lines. If the List extends below the last
7958 line then those lines are added. If the List is empty then
7959 nothing is changed and zero is returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007960
7961 For the use of {buf}, see |bufname()| above.
7962
7963 {lnum} is used like with |setline()|.
7964 Use "$" to refer to the last line in buffer {buf}.
7965 When {lnum} is just below the last line the {text} will be
7966 added below the last line.
7967
7968 When {buf} is not a valid buffer, the buffer is not loaded or
7969 {lnum} is not valid then 1 is returned. In |Vim9| script an
7970 error is given.
7971 On success 0 is returned.
7972
7973 Can also be used as a |method|, the base is passed as the
7974 third argument: >
7975 GetText()->setbufline(buf, lnum)
7976
7977setbufvar({buf}, {varname}, {val}) *setbufvar()*
7978 Set option or local variable {varname} in buffer {buf} to
7979 {val}.
7980 This also works for a global or local window option, but it
7981 doesn't work for a global or local window variable.
7982 For a local window option the global value is unchanged.
7983 For the use of {buf}, see |bufname()| above.
7984 The {varname} argument is a string.
7985 Note that the variable name without "b:" must be used.
7986 Examples: >
7987 :call setbufvar(1, "&mod", 1)
7988 :call setbufvar("todo", "myvar", "foobar")
7989< This function is not available in the |sandbox|.
7990
7991 Can also be used as a |method|, the base is passed as the
7992 third argument: >
7993 GetValue()->setbufvar(buf, varname)
7994
7995
7996setcellwidths({list}) *setcellwidths()*
7997 Specify overrides for cell widths of character ranges. This
Bram Moolenaarb59ae592022-11-23 23:46:31 +00007998 tells Vim how wide characters are when displayed in the
7999 terminal, counted in screen cells. The values override
8000 'ambiwidth'. Example: >
8001 call setcellwidths([
Bram Moolenaar938ae282023-02-20 20:44:55 +00008002 \ [0x111, 0x111, 1],
Bram Moolenaarb59ae592022-11-23 23:46:31 +00008003 \ [0x2194, 0x2199, 2],
8004 \ ])
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008005
Bram Moolenaarb59ae592022-11-23 23:46:31 +00008006< The {list} argument is a List of Lists with each three
8007 numbers: [{low}, {high}, {width}]. *E1109* *E1110*
8008 {low} and {high} can be the same, in which case this refers to
8009 one character. Otherwise it is the range of characters from
8010 {low} to {high} (inclusive). *E1111* *E1114*
K.Takata71933232023-01-20 16:00:55 +00008011 Only characters with value 0x80 and higher can be used.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008012
Bram Moolenaarb59ae592022-11-23 23:46:31 +00008013 {width} must be either 1 or 2, indicating the character width
8014 in screen cells. *E1112*
8015 An error is given if the argument is invalid, also when a
Bram Moolenaar938ae282023-02-20 20:44:55 +00008016 range overlaps with another. *E1113*
Bram Moolenaarb59ae592022-11-23 23:46:31 +00008017
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008018 If the new value causes 'fillchars' or 'listchars' to become
8019 invalid it is rejected and an error is given.
8020
Bram Moolenaarb59ae592022-11-23 23:46:31 +00008021 To clear the overrides pass an empty {list}: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008022 setcellwidths([]);
Bram Moolenaarb59ae592022-11-23 23:46:31 +00008023
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008024< You can use the script $VIMRUNTIME/tools/emoji_list.vim to see
Bram Moolenaarb59ae592022-11-23 23:46:31 +00008025 the effect for known emoji characters. Move the cursor
8026 through the text to check if the cell widths of your terminal
8027 match with what Vim knows about each emoji. If it doesn't
8028 look right you need to adjust the {list} argument.
8029
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008030
8031setcharpos({expr}, {list}) *setcharpos()*
8032 Same as |setpos()| but uses the specified column number as the
8033 character index instead of the byte index in the line.
8034
8035 Example:
8036 With the text "여보세요" in line 8: >
8037 call setcharpos('.', [0, 8, 4, 0])
8038< positions the cursor on the fourth character '요'. >
8039 call setpos('.', [0, 8, 4, 0])
8040< positions the cursor on the second character '보'.
8041
8042 Can also be used as a |method|: >
8043 GetPosition()->setcharpos('.')
8044
8045setcharsearch({dict}) *setcharsearch()*
8046 Set the current character search information to {dict},
8047 which contains one or more of the following entries:
8048
8049 char character which will be used for a subsequent
8050 |,| or |;| command; an empty string clears the
8051 character search
8052 forward direction of character search; 1 for forward,
8053 0 for backward
8054 until type of character search; 1 for a |t| or |T|
8055 character search, 0 for an |f| or |F|
8056 character search
8057
8058 This can be useful to save/restore a user's character search
8059 from a script: >
8060 :let prevsearch = getcharsearch()
8061 :" Perform a command which clobbers user's search
8062 :call setcharsearch(prevsearch)
8063< Also see |getcharsearch()|.
8064
8065 Can also be used as a |method|: >
8066 SavedSearch()->setcharsearch()
8067
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01008068setcmdline({str} [, {pos}]) *setcmdline()*
8069 Set the command line to {str} and set the cursor position to
8070 {pos}.
8071 If {pos} is omitted, the cursor is positioned after the text.
8072 Returns 0 when successful, 1 when not editing the command
8073 line.
8074
8075 Can also be used as a |method|: >
8076 GetText()->setcmdline()
8077
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008078setcmdpos({pos}) *setcmdpos()*
8079 Set the cursor position in the command line to byte position
8080 {pos}. The first position is 1.
8081 Use |getcmdpos()| to obtain the current position.
8082 Only works while editing the command line, thus you must use
8083 |c_CTRL-\_e|, |c_CTRL-R_=| or |c_CTRL-R_CTRL-R| with '='. For
8084 |c_CTRL-\_e| and |c_CTRL-R_CTRL-R| with '=' the position is
8085 set after the command line is set to the expression. For
8086 |c_CTRL-R_=| it is set after evaluating the expression but
8087 before inserting the resulting text.
8088 When the number is too big the cursor is put at the end of the
8089 line. A number smaller than one has undefined results.
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01008090 Returns 0 when successful, 1 when not editing the command
8091 line.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008092
8093 Can also be used as a |method|: >
8094 GetPos()->setcmdpos()
8095
8096setcursorcharpos({lnum}, {col} [, {off}]) *setcursorcharpos()*
8097setcursorcharpos({list})
8098 Same as |cursor()| but uses the specified column number as the
8099 character index instead of the byte index in the line.
8100
8101 Example:
8102 With the text "여보세요" in line 4: >
8103 call setcursorcharpos(4, 3)
8104< positions the cursor on the third character '세'. >
8105 call cursor(4, 3)
8106< positions the cursor on the first character '여'.
8107
8108 Can also be used as a |method|: >
8109 GetCursorPos()->setcursorcharpos()
8110
8111
8112setenv({name}, {val}) *setenv()*
8113 Set environment variable {name} to {val}. Example: >
8114 call setenv('HOME', '/home/myhome')
8115
8116< When {val} is |v:null| the environment variable is deleted.
8117 See also |expr-env|.
8118
8119 Can also be used as a |method|, the base is passed as the
8120 second argument: >
8121 GetPath()->setenv('PATH')
8122
8123setfperm({fname}, {mode}) *setfperm()* *chmod*
8124 Set the file permissions for {fname} to {mode}.
8125 {mode} must be a string with 9 characters. It is of the form
8126 "rwxrwxrwx", where each group of "rwx" flags represent, in
8127 turn, the permissions of the owner of the file, the group the
8128 file belongs to, and other users. A '-' character means the
8129 permission is off, any other character means on. Multi-byte
8130 characters are not supported.
8131
8132 For example "rw-r-----" means read-write for the user,
8133 readable by the group, not accessible by others. "xx-x-----"
8134 would do the same thing.
8135
8136 Returns non-zero for success, zero for failure.
8137
8138 Can also be used as a |method|: >
8139 GetFilename()->setfperm(mode)
8140<
8141 To read permissions see |getfperm()|.
8142
8143
8144setline({lnum}, {text}) *setline()*
8145 Set line {lnum} of the current buffer to {text}. To insert
8146 lines use |append()|. To set lines in another buffer use
8147 |setbufline()|. Any text properties in {lnum} are cleared.
8148
8149 {lnum} is used like with |getline()|.
8150 When {lnum} is just below the last line the {text} will be
8151 added below the last line.
8152 {text} can be any type or a List of any type, each item is
Bram Moolenaarcd9c8d42022-11-05 23:46:43 +00008153 converted to a String. When {text} is an empty List then
8154 nothing is changed and FALSE is returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008155
8156 If this succeeds, FALSE is returned. If this fails (most likely
8157 because {lnum} is invalid) TRUE is returned.
8158 In |Vim9| script an error is given if {lnum} is invalid.
8159
8160 Example: >
8161 :call setline(5, strftime("%c"))
8162
8163< When {text} is a |List| then line {lnum} and following lines
8164 will be set to the items in the list. Example: >
8165 :call setline(5, ['aaa', 'bbb', 'ccc'])
8166< This is equivalent to: >
8167 :for [n, l] in [[5, 'aaa'], [6, 'bbb'], [7, 'ccc']]
8168 : call setline(n, l)
8169 :endfor
8170
8171< Note: The '[ and '] marks are not set.
8172
8173 Can also be used as a |method|, the base is passed as the
8174 second argument: >
8175 GetText()->setline(lnum)
8176
8177setloclist({nr}, {list} [, {action} [, {what}]]) *setloclist()*
8178 Create or replace or add to the location list for window {nr}.
8179 {nr} can be the window number or the |window-ID|.
8180 When {nr} is zero the current window is used.
8181
8182 For a location list window, the displayed location list is
8183 modified. For an invalid window number {nr}, -1 is returned.
8184 Otherwise, same as |setqflist()|.
8185 Also see |location-list|.
8186
8187 For {action} see |setqflist-action|.
8188
8189 If the optional {what} dictionary argument is supplied, then
8190 only the items listed in {what} are set. Refer to |setqflist()|
8191 for the list of supported keys in {what}.
8192
8193 Can also be used as a |method|, the base is passed as the
8194 second argument: >
8195 GetLoclist()->setloclist(winnr)
8196
8197setmatches({list} [, {win}]) *setmatches()*
8198 Restores a list of matches saved by |getmatches()| for the
8199 current window. Returns 0 if successful, otherwise -1. All
8200 current matches are cleared before the list is restored. See
8201 example for |getmatches()|.
8202 If {win} is specified, use the window with this number or
8203 window ID instead of the current window.
8204
8205 Can also be used as a |method|: >
8206 GetMatches()->setmatches()
8207<
8208 *setpos()*
8209setpos({expr}, {list})
8210 Set the position for String {expr}. Possible values:
8211 . the cursor
8212 'x mark x
8213
8214 {list} must be a |List| with four or five numbers:
8215 [bufnum, lnum, col, off]
8216 [bufnum, lnum, col, off, curswant]
8217
8218 "bufnum" is the buffer number. Zero can be used for the
8219 current buffer. When setting an uppercase mark "bufnum" is
8220 used for the mark position. For other marks it specifies the
8221 buffer to set the mark in. You can use the |bufnr()| function
8222 to turn a file name into a buffer number.
8223 For setting the cursor and the ' mark "bufnum" is ignored,
8224 since these are associated with a window, not a buffer.
8225 Does not change the jumplist.
8226
8227 "lnum" and "col" are the position in the buffer. The first
8228 column is 1. Use a zero "lnum" to delete a mark. If "col" is
8229 smaller than 1 then 1 is used. To use the character count
8230 instead of the byte count, use |setcharpos()|.
8231
8232 The "off" number is only used when 'virtualedit' is set. Then
8233 it is the offset in screen columns from the start of the
8234 character. E.g., a position within a <Tab> or after the last
8235 character.
8236
8237 The "curswant" number is only used when setting the cursor
8238 position. It sets the preferred column for when moving the
8239 cursor vertically. When the "curswant" number is missing the
8240 preferred column is not set. When it is present and setting a
8241 mark position it is not used.
8242
8243 Note that for '< and '> changing the line number may result in
8244 the marks to be effectively be swapped, so that '< is always
8245 before '>.
8246
8247 Returns 0 when the position could be set, -1 otherwise.
8248 An error message is given if {expr} is invalid.
8249
8250 Also see |setcharpos()|, |getpos()| and |getcurpos()|.
8251
8252 This does not restore the preferred column for moving
8253 vertically; if you set the cursor position with this, |j| and
8254 |k| motions will jump to previous columns! Use |cursor()| to
8255 also set the preferred column. Also see the "curswant" key in
8256 |winrestview()|.
8257
8258 Can also be used as a |method|: >
8259 GetPosition()->setpos('.')
8260
8261setqflist({list} [, {action} [, {what}]]) *setqflist()*
8262 Create or replace or add to the quickfix list.
8263
8264 If the optional {what} dictionary argument is supplied, then
8265 only the items listed in {what} are set. The first {list}
8266 argument is ignored. See below for the supported items in
8267 {what}.
8268 *setqflist-what*
8269 When {what} is not present, the items in {list} are used. Each
8270 item must be a dictionary. Non-dictionary items in {list} are
8271 ignored. Each dictionary item can contain the following
8272 entries:
8273
8274 bufnr buffer number; must be the number of a valid
8275 buffer
8276 filename name of a file; only used when "bufnr" is not
8277 present or it is invalid.
8278 module name of a module; if given it will be used in
8279 quickfix error window instead of the filename.
8280 lnum line number in the file
Bram Moolenaara2baa732022-02-04 16:09:54 +00008281 end_lnum end of lines, if the item spans multiple lines
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008282 pattern search pattern used to locate the error
8283 col column number
8284 vcol when non-zero: "col" is visual column
8285 when zero: "col" is byte index
Bram Moolenaara2baa732022-02-04 16:09:54 +00008286 end_col end column, if the item spans multiple columns
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008287 nr error number
8288 text description of the error
8289 type single-character error type, 'E', 'W', etc.
8290 valid recognized error message
8291
8292 The "col", "vcol", "nr", "type" and "text" entries are
8293 optional. Either "lnum" or "pattern" entry can be used to
8294 locate a matching error line.
8295 If the "filename" and "bufnr" entries are not present or
8296 neither the "lnum" or "pattern" entries are present, then the
8297 item will not be handled as an error line.
8298 If both "pattern" and "lnum" are present then "pattern" will
8299 be used.
8300 If the "valid" entry is not supplied, then the valid flag is
8301 set when "bufnr" is a valid buffer or "filename" exists.
8302 If you supply an empty {list}, the quickfix list will be
8303 cleared.
8304 Note that the list is not exactly the same as what
8305 |getqflist()| returns.
8306
8307 {action} values: *setqflist-action* *E927*
8308 'a' The items from {list} are added to the existing
8309 quickfix list. If there is no existing list, then a
8310 new list is created.
8311
8312 'r' The items from the current quickfix list are replaced
8313 with the items from {list}. This can also be used to
8314 clear the list: >
8315 :call setqflist([], 'r')
8316<
8317 'f' All the quickfix lists in the quickfix stack are
8318 freed.
8319
8320 If {action} is not present or is set to ' ', then a new list
8321 is created. The new quickfix list is added after the current
8322 quickfix list in the stack and all the following lists are
8323 freed. To add a new quickfix list at the end of the stack,
8324 set "nr" in {what} to "$".
8325
8326 The following items can be specified in dictionary {what}:
8327 context quickfix list context. See |quickfix-context|
8328 efm errorformat to use when parsing text from
8329 "lines". If this is not present, then the
8330 'errorformat' option value is used.
8331 See |quickfix-parse|
8332 id quickfix list identifier |quickfix-ID|
8333 idx index of the current entry in the quickfix
8334 list specified by 'id' or 'nr'. If set to '$',
8335 then the last entry in the list is set as the
8336 current entry. See |quickfix-index|
8337 items list of quickfix entries. Same as the {list}
8338 argument.
8339 lines use 'errorformat' to parse a list of lines and
8340 add the resulting entries to the quickfix list
8341 {nr} or {id}. Only a |List| value is supported.
8342 See |quickfix-parse|
8343 nr list number in the quickfix stack; zero
8344 means the current quickfix list and "$" means
8345 the last quickfix list.
8346 quickfixtextfunc
8347 function to get the text to display in the
8348 quickfix window. The value can be the name of
8349 a function or a funcref or a lambda. Refer to
8350 |quickfix-window-function| for an explanation
8351 of how to write the function and an example.
8352 title quickfix list title text. See |quickfix-title|
8353 Unsupported keys in {what} are ignored.
8354 If the "nr" item is not present, then the current quickfix list
8355 is modified. When creating a new quickfix list, "nr" can be
8356 set to a value one greater than the quickfix stack size.
8357 When modifying a quickfix list, to guarantee that the correct
8358 list is modified, "id" should be used instead of "nr" to
8359 specify the list.
8360
8361 Examples (See also |setqflist-examples|): >
8362 :call setqflist([], 'r', {'title': 'My search'})
8363 :call setqflist([], 'r', {'nr': 2, 'title': 'Errors'})
8364 :call setqflist([], 'a', {'id':qfid, 'lines':["F1:10:L10"]})
8365<
8366 Returns zero for success, -1 for failure.
8367
8368 This function can be used to create a quickfix list
8369 independent of the 'errorformat' setting. Use a command like
8370 `:cc 1` to jump to the first position.
8371
8372 Can also be used as a |method|, the base is passed as the
8373 second argument: >
8374 GetErrorlist()->setqflist()
8375<
8376 *setreg()*
8377setreg({regname}, {value} [, {options}])
8378 Set the register {regname} to {value}.
8379 If {regname} is "" or "@", the unnamed register '"' is used.
8380 The {regname} argument is a string. In |Vim9-script|
8381 {regname} must be one character.
8382
8383 {value} may be any value returned by |getreg()| or
8384 |getreginfo()|, including a |List| or |Dict|.
8385 If {options} contains "a" or {regname} is upper case,
8386 then the value is appended.
8387
8388 {options} can also contain a register type specification:
8389 "c" or "v" |characterwise| mode
8390 "l" or "V" |linewise| mode
8391 "b" or "<CTRL-V>" |blockwise-visual| mode
8392 If a number immediately follows "b" or "<CTRL-V>" then this is
8393 used as the width of the selection - if it is not specified
8394 then the width of the block is set to the number of characters
8395 in the longest line (counting a <Tab> as 1 character).
8396
8397 If {options} contains no register settings, then the default
8398 is to use character mode unless {value} ends in a <NL> for
8399 string {value} and linewise mode for list {value}. Blockwise
8400 mode is never selected automatically.
8401 Returns zero for success, non-zero for failure.
8402
8403 *E883*
8404 Note: you may not use |List| containing more than one item to
8405 set search and expression registers. Lists containing no
8406 items act like empty strings.
8407
8408 Examples: >
8409 :call setreg(v:register, @*)
8410 :call setreg('*', @%, 'ac')
8411 :call setreg('a', "1\n2\n3", 'b5')
8412 :call setreg('"', { 'points_to': 'a'})
8413
8414< This example shows using the functions to save and restore a
8415 register: >
8416 :let var_a = getreginfo()
8417 :call setreg('a', var_a)
8418< or: >
8419 :let var_a = getreg('a', 1, 1)
8420 :let var_amode = getregtype('a')
8421 ....
8422 :call setreg('a', var_a, var_amode)
8423< Note: you may not reliably restore register value
8424 without using the third argument to |getreg()| as without it
8425 newlines are represented as newlines AND Nul bytes are
8426 represented as newlines as well, see |NL-used-for-Nul|.
8427
8428 You can also change the type of a register by appending
8429 nothing: >
8430 :call setreg('a', '', 'al')
8431
8432< Can also be used as a |method|, the base is passed as the
8433 second argument: >
8434 GetText()->setreg('a')
8435
8436settabvar({tabnr}, {varname}, {val}) *settabvar()*
8437 Set tab-local variable {varname} to {val} in tab page {tabnr}.
8438 |t:var|
8439 The {varname} argument is a string.
8440 Note that autocommands are blocked, side effects may not be
8441 triggered, e.g. when setting 'filetype'.
8442 Note that the variable name without "t:" must be used.
8443 Tabs are numbered starting with one.
8444 This function is not available in the |sandbox|.
8445
8446 Can also be used as a |method|, the base is passed as the
8447 third argument: >
8448 GetValue()->settabvar(tab, name)
8449
8450settabwinvar({tabnr}, {winnr}, {varname}, {val}) *settabwinvar()*
8451 Set option or local variable {varname} in window {winnr} to
8452 {val}.
8453 Tabs are numbered starting with one. For the current tabpage
8454 use |setwinvar()|.
8455 {winnr} can be the window number or the |window-ID|.
8456 When {winnr} is zero the current window is used.
8457 Note that autocommands are blocked, side effects may not be
8458 triggered, e.g. when setting 'filetype' or 'syntax'.
8459 This also works for a global or local buffer option, but it
8460 doesn't work for a global or local buffer variable.
8461 For a local buffer option the global value is unchanged.
8462 Note that the variable name without "w:" must be used.
8463 Examples: >
8464 :call settabwinvar(1, 1, "&list", 0)
8465 :call settabwinvar(3, 2, "myvar", "foobar")
8466< This function is not available in the |sandbox|.
8467
8468 Can also be used as a |method|, the base is passed as the
8469 fourth argument: >
8470 GetValue()->settabwinvar(tab, winnr, name)
8471
8472settagstack({nr}, {dict} [, {action}]) *settagstack()*
8473 Modify the tag stack of the window {nr} using {dict}.
8474 {nr} can be the window number or the |window-ID|.
8475
8476 For a list of supported items in {dict}, refer to
8477 |gettagstack()|. "curidx" takes effect before changing the tag
8478 stack.
8479 *E962*
8480 How the tag stack is modified depends on the {action}
8481 argument:
8482 - If {action} is not present or is set to 'r', then the tag
8483 stack is replaced.
8484 - If {action} is set to 'a', then new entries from {dict} are
8485 pushed (added) onto the tag stack.
8486 - If {action} is set to 't', then all the entries from the
8487 current entry in the tag stack or "curidx" in {dict} are
8488 removed and then new entries are pushed to the stack.
8489
8490 The current index is set to one after the length of the tag
8491 stack after the modification.
8492
8493 Returns zero for success, -1 for failure.
8494
8495 Examples (for more examples see |tagstack-examples|):
8496 Empty the tag stack of window 3: >
8497 call settagstack(3, {'items' : []})
8498
8499< Save and restore the tag stack: >
8500 let stack = gettagstack(1003)
8501 " do something else
8502 call settagstack(1003, stack)
8503 unlet stack
8504<
8505 Can also be used as a |method|, the base is passed as the
8506 second argument: >
8507 GetStack()->settagstack(winnr)
8508
8509setwinvar({winnr}, {varname}, {val}) *setwinvar()*
8510 Like |settabwinvar()| for the current tab page.
8511 Examples: >
8512 :call setwinvar(1, "&list", 0)
8513 :call setwinvar(2, "myvar", "foobar")
8514
8515< Can also be used as a |method|, the base is passed as the
8516 third argument: >
8517 GetValue()->setwinvar(winnr, name)
8518
8519sha256({string}) *sha256()*
8520 Returns a String with 64 hex characters, which is the SHA256
8521 checksum of {string}.
8522
8523 Can also be used as a |method|: >
8524 GetText()->sha256()
8525
8526< {only available when compiled with the |+cryptv| feature}
8527
8528shellescape({string} [, {special}]) *shellescape()*
8529 Escape {string} for use as a shell command argument.
8530 When the 'shell' contains powershell (MS-Windows) or pwsh
Bram Moolenaar944697a2022-02-20 19:48:20 +00008531 (MS-Windows, Linux, and macOS) then it will enclose {string}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008532 in single quotes and will double up all internal single
8533 quotes.
8534 On MS-Windows, when 'shellslash' is not set, it will enclose
8535 {string} in double quotes and double all double quotes within
8536 {string}.
8537 Otherwise it will enclose {string} in single quotes and
8538 replace all "'" with "'\''".
8539
8540 When the {special} argument is present and it's a non-zero
8541 Number or a non-empty String (|non-zero-arg|), then special
8542 items such as "!", "%", "#" and "<cword>" will be preceded by
8543 a backslash. This backslash will be removed again by the |:!|
8544 command.
8545
8546 The "!" character will be escaped (again with a |non-zero-arg|
8547 {special}) when 'shell' contains "csh" in the tail. That is
8548 because for csh and tcsh "!" is used for history replacement
8549 even when inside single quotes.
8550
8551 With a |non-zero-arg| {special} the <NL> character is also
8552 escaped. When 'shell' containing "csh" in the tail it's
8553 escaped a second time.
8554
8555 The "\" character will be escaped when 'shell' contains "fish"
8556 in the tail. That is because for fish "\" is used as an escape
8557 character inside single quotes.
8558
8559 Example of use with a |:!| command: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00008560 :exe '!dir ' .. shellescape(expand('<cfile>'), 1)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008561< This results in a directory listing for the file under the
8562 cursor. Example of use with |system()|: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00008563 :call system("chmod +w -- " .. shellescape(expand("%")))
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008564< See also |::S|.
8565
8566 Can also be used as a |method|: >
8567 GetCommand()->shellescape()
8568
8569shiftwidth([{col}]) *shiftwidth()*
8570 Returns the effective value of 'shiftwidth'. This is the
8571 'shiftwidth' value unless it is zero, in which case it is the
8572 'tabstop' value. This function was introduced with patch
8573 7.3.694 in 2012, everybody should have it by now (however it
8574 did not allow for the optional {col} argument until 8.1.542).
8575
8576 When there is one argument {col} this is used as column number
8577 for which to return the 'shiftwidth' value. This matters for the
8578 'vartabstop' feature. If the 'vartabstop' setting is enabled and
8579 no {col} argument is given, column 1 will be assumed.
8580
8581 Can also be used as a |method|: >
8582 GetColumn()->shiftwidth()
8583
8584sign_ functions are documented here: |sign-functions-details|
8585
8586
8587simplify({filename}) *simplify()*
8588 Simplify the file name as much as possible without changing
8589 the meaning. Shortcuts (on MS-Windows) or symbolic links (on
8590 Unix) are not resolved. If the first path component in
8591 {filename} designates the current directory, this will be
8592 valid for the result as well. A trailing path separator is
8593 not removed either. On Unix "//path" is unchanged, but
8594 "///path" is simplified to "/path" (this follows the Posix
8595 standard).
8596 Example: >
8597 simplify("./dir/.././/file/") == "./file/"
8598< Note: The combination "dir/.." is only removed if "dir" is
8599 a searchable directory or does not exist. On Unix, it is also
8600 removed when "dir" is a symbolic link within the same
8601 directory. In order to resolve all the involved symbolic
8602 links before simplifying the path name, use |resolve()|.
8603
8604 Can also be used as a |method|: >
8605 GetName()->simplify()
8606
8607sin({expr}) *sin()*
8608 Return the sine of {expr}, measured in radians, as a |Float|.
8609 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01008610 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008611 Examples: >
8612 :echo sin(100)
8613< -0.506366 >
8614 :echo sin(-4.01)
8615< 0.763301
8616
8617 Can also be used as a |method|: >
8618 Compute()->sin()
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008619
8620
8621sinh({expr}) *sinh()*
8622 Return the hyperbolic sine of {expr} as a |Float| in the range
8623 [-inf, inf].
8624 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01008625 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008626 Examples: >
8627 :echo sinh(0.5)
8628< 0.521095 >
8629 :echo sinh(-0.9)
8630< -1.026517
8631
8632 Can also be used as a |method|: >
8633 Compute()->sinh()
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008634
8635
8636slice({expr}, {start} [, {end}]) *slice()*
8637 Similar to using a |slice| "expr[start : end]", but "end" is
8638 used exclusive. And for a string the indexes are used as
8639 character indexes instead of byte indexes, like in
8640 |vim9script|. Also, composing characters are not counted.
8641 When {end} is omitted the slice continues to the last item.
8642 When {end} is -1 the last item is omitted.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01008643 Returns an empty value if {start} or {end} are invalid.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008644
8645 Can also be used as a |method|: >
8646 GetList()->slice(offset)
8647
8648
Bram Moolenaar2007dd42022-02-23 13:17:47 +00008649sort({list} [, {how} [, {dict}]]) *sort()* *E702*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008650 Sort the items in {list} in-place. Returns {list}.
8651
8652 If you want a list to remain unmodified make a copy first: >
8653 :let sortedlist = sort(copy(mylist))
8654
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01008655< When {how} is omitted or is a string, then sort() uses the
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008656 string representation of each item to sort on. Numbers sort
8657 after Strings, |Lists| after Numbers. For sorting text in the
8658 current buffer use |:sort|.
8659
Bram Moolenaar2007dd42022-02-23 13:17:47 +00008660 When {how} is given and it is 'i' then case is ignored.
8661 In legacy script, for backwards compatibility, the value one
8662 can be used to ignore case. Zero means to not ignore case.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008663
Bram Moolenaar2007dd42022-02-23 13:17:47 +00008664 When {how} is given and it is 'l' then the current collation
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008665 locale is used for ordering. Implementation details: strcoll()
8666 is used to compare strings. See |:language| check or set the
8667 collation locale. |v:collate| can also be used to check the
8668 current locale. Sorting using the locale typically ignores
8669 case. Example: >
8670 " ö is sorted similarly to o with English locale.
8671 :language collate en_US.UTF8
8672 :echo sort(['n', 'o', 'O', 'ö', 'p', 'z'], 'l')
8673< ['n', 'o', 'O', 'ö', 'p', 'z'] ~
8674>
8675 " ö is sorted after z with Swedish locale.
8676 :language collate sv_SE.UTF8
8677 :echo sort(['n', 'o', 'O', 'ö', 'p', 'z'], 'l')
8678< ['n', 'o', 'O', 'p', 'z', 'ö'] ~
8679 This does not work properly on Mac.
8680
Bram Moolenaar2007dd42022-02-23 13:17:47 +00008681 When {how} is given and it is 'n' then all items will be
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008682 sorted numerical (Implementation detail: this uses the
Bram Moolenaarbe19d782023-03-09 22:06:49 +00008683 strtod() function to parse numbers. Strings, Lists, Dicts and
8684 Funcrefs will be considered as being 0). Note that this won't
8685 sort a list of strings with numbers!
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008686
Bram Moolenaar2007dd42022-02-23 13:17:47 +00008687 When {how} is given and it is 'N' then all items will be
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008688 sorted numerical. This is like 'n' but a string containing
8689 digits will be used as the number they represent.
8690
Bram Moolenaar2007dd42022-02-23 13:17:47 +00008691 When {how} is given and it is 'f' then all items will be
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008692 sorted numerical. All values must be a Number or a Float.
8693
Bram Moolenaar2007dd42022-02-23 13:17:47 +00008694 When {how} is a |Funcref| or a function name, this function
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008695 is called to compare items. The function is invoked with two
8696 items as argument and must return zero if they are equal, 1 or
8697 bigger if the first one sorts after the second one, -1 or
8698 smaller if the first one sorts before the second one.
8699
8700 {dict} is for functions with the "dict" attribute. It will be
8701 used to set the local variable "self". |Dictionary-function|
8702
8703 The sort is stable, items which compare equal (as number or as
8704 string) will keep their relative position. E.g., when sorting
8705 on numbers, text strings will sort next to each other, in the
8706 same order as they were originally.
8707
8708 Can also be used as a |method|: >
8709 mylist->sort()
8710
8711< Also see |uniq()|.
8712
8713 Example: >
8714 func MyCompare(i1, i2)
8715 return a:i1 == a:i2 ? 0 : a:i1 > a:i2 ? 1 : -1
8716 endfunc
8717 eval mylist->sort("MyCompare")
8718< A shorter compare version for this specific simple case, which
8719 ignores overflow: >
8720 func MyCompare(i1, i2)
8721 return a:i1 - a:i2
8722 endfunc
8723< For a simple expression you can use a lambda: >
8724 eval mylist->sort({i1, i2 -> i1 - i2})
8725<
8726sound_clear() *sound_clear()*
8727 Stop playing all sounds.
8728
8729 On some Linux systems you may need the libcanberra-pulse
8730 package, otherwise sound may not stop.
8731
8732 {only available when compiled with the |+sound| feature}
8733
8734 *sound_playevent()*
8735sound_playevent({name} [, {callback}])
8736 Play a sound identified by {name}. Which event names are
8737 supported depends on the system. Often the XDG sound names
8738 are used. On Ubuntu they may be found in
8739 /usr/share/sounds/freedesktop/stereo. Example: >
8740 call sound_playevent('bell')
8741< On MS-Windows, {name} can be SystemAsterisk, SystemDefault,
8742 SystemExclamation, SystemExit, SystemHand, SystemQuestion,
8743 SystemStart, SystemWelcome, etc.
Yee Cheng Chin4314e4f2022-10-08 13:50:05 +01008744 On macOS, {name} refers to files located in
8745 /System/Library/Sounds (e.g. "Tink"). It will also work for
8746 custom installed sounds in folders like ~/Library/Sounds.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008747
8748 When {callback} is specified it is invoked when the sound is
8749 finished. The first argument is the sound ID, the second
8750 argument is the status:
8751 0 sound was played to the end
8752 1 sound was interrupted
8753 2 error occurred after sound started
8754 Example: >
8755 func Callback(id, status)
8756 echomsg "sound " .. a:id .. " finished with " .. a:status
8757 endfunc
8758 call sound_playevent('bell', 'Callback')
8759
8760< MS-Windows: {callback} doesn't work for this function.
8761
8762 Returns the sound ID, which can be passed to `sound_stop()`.
8763 Returns zero if the sound could not be played.
8764
8765 Can also be used as a |method|: >
8766 GetSoundName()->sound_playevent()
8767
8768< {only available when compiled with the |+sound| feature}
8769
8770 *sound_playfile()*
8771sound_playfile({path} [, {callback}])
8772 Like `sound_playevent()` but play sound file {path}. {path}
8773 must be a full path. On Ubuntu you may find files to play
8774 with this command: >
8775 :!find /usr/share/sounds -type f | grep -v index.theme
8776
8777< Can also be used as a |method|: >
8778 GetSoundPath()->sound_playfile()
8779
Bram Moolenaar1588bc82022-03-08 21:35:07 +00008780< {only available when compiled with the |+sound| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008781
8782
8783sound_stop({id}) *sound_stop()*
8784 Stop playing sound {id}. {id} must be previously returned by
8785 `sound_playevent()` or `sound_playfile()`.
8786
8787 On some Linux systems you may need the libcanberra-pulse
8788 package, otherwise sound may not stop.
8789
8790 On MS-Windows, this does not work for event sound started by
8791 `sound_playevent()`. To stop event sounds, use `sound_clear()`.
8792
8793 Can also be used as a |method|: >
8794 soundid->sound_stop()
8795
8796< {only available when compiled with the |+sound| feature}
8797
8798 *soundfold()*
8799soundfold({word})
8800 Return the sound-folded equivalent of {word}. Uses the first
8801 language in 'spelllang' for the current window that supports
8802 soundfolding. 'spell' must be set. When no sound folding is
8803 possible the {word} is returned unmodified.
8804 This can be used for making spelling suggestions. Note that
8805 the method can be quite slow.
8806
8807 Can also be used as a |method|: >
8808 GetWord()->soundfold()
8809<
8810 *spellbadword()*
8811spellbadword([{sentence}])
8812 Without argument: The result is the badly spelled word under
8813 or after the cursor. The cursor is moved to the start of the
8814 bad word. When no bad word is found in the cursor line the
8815 result is an empty string and the cursor doesn't move.
8816
8817 With argument: The result is the first word in {sentence} that
8818 is badly spelled. If there are no spelling mistakes the
8819 result is an empty string.
8820
8821 The return value is a list with two items:
8822 - The badly spelled word or an empty string.
8823 - The type of the spelling error:
8824 "bad" spelling mistake
8825 "rare" rare word
8826 "local" word only valid in another region
8827 "caps" word should start with Capital
8828 Example: >
8829 echo spellbadword("the quik brown fox")
8830< ['quik', 'bad'] ~
8831
8832 The spelling information for the current window and the value
8833 of 'spelllang' are used.
8834
8835 Can also be used as a |method|: >
8836 GetText()->spellbadword()
8837<
8838 *spellsuggest()*
8839spellsuggest({word} [, {max} [, {capital}]])
8840 Return a |List| with spelling suggestions to replace {word}.
8841 When {max} is given up to this number of suggestions are
8842 returned. Otherwise up to 25 suggestions are returned.
8843
8844 When the {capital} argument is given and it's non-zero only
8845 suggestions with a leading capital will be given. Use this
8846 after a match with 'spellcapcheck'.
8847
8848 {word} can be a badly spelled word followed by other text.
8849 This allows for joining two words that were split. The
8850 suggestions also include the following text, thus you can
8851 replace a line.
8852
8853 {word} may also be a good word. Similar words will then be
8854 returned. {word} itself is not included in the suggestions,
8855 although it may appear capitalized.
8856
8857 The spelling information for the current window is used. The
8858 values of 'spelllang' and 'spellsuggest' are used.
8859
8860 Can also be used as a |method|: >
8861 GetWord()->spellsuggest()
8862
8863split({string} [, {pattern} [, {keepempty}]]) *split()*
8864 Make a |List| out of {string}. When {pattern} is omitted or
8865 empty each white-separated sequence of characters becomes an
8866 item.
8867 Otherwise the string is split where {pattern} matches,
8868 removing the matched characters. 'ignorecase' is not used
8869 here, add \c to ignore case. |/\c|
8870 When the first or last item is empty it is omitted, unless the
8871 {keepempty} argument is given and it's non-zero.
8872 Other empty items are kept when {pattern} matches at least one
8873 character or when {keepempty} is non-zero.
8874 Example: >
8875 :let words = split(getline('.'), '\W\+')
8876< To split a string in individual characters: >
8877 :for c in split(mystring, '\zs')
8878< If you want to keep the separator you can also use '\zs' at
8879 the end of the pattern: >
8880 :echo split('abc:def:ghi', ':\zs')
8881< ['abc:', 'def:', 'ghi'] ~
8882 Splitting a table where the first element can be empty: >
8883 :let items = split(line, ':', 1)
8884< The opposite function is |join()|.
8885
8886 Can also be used as a |method|: >
8887 GetString()->split()
8888
8889sqrt({expr}) *sqrt()*
8890 Return the non-negative square root of Float {expr} as a
8891 |Float|.
8892 {expr} must evaluate to a |Float| or a |Number|. When {expr}
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01008893 is negative the result is NaN (Not a Number). Returns 0.0 if
8894 {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008895 Examples: >
8896 :echo sqrt(100)
8897< 10.0 >
8898 :echo sqrt(-4.01)
8899< nan
8900 "nan" may be different, it depends on system libraries.
8901
8902 Can also be used as a |method|: >
8903 Compute()->sqrt()
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008904
8905
8906srand([{expr}]) *srand()*
8907 Initialize seed used by |rand()|:
8908 - If {expr} is not given, seed values are initialized by
8909 reading from /dev/urandom, if possible, or using time(NULL)
8910 a.k.a. epoch time otherwise; this only has second accuracy.
8911 - If {expr} is given it must be a Number. It is used to
8912 initialize the seed values. This is useful for testing or
8913 when a predictable sequence is intended.
8914
8915 Examples: >
8916 :let seed = srand()
8917 :let seed = srand(userinput)
8918 :echo rand(seed)
8919
8920state([{what}]) *state()*
8921 Return a string which contains characters indicating the
8922 current state. Mostly useful in callbacks that want to do
8923 work that may not always be safe. Roughly this works like:
8924 - callback uses state() to check if work is safe to do.
8925 Yes: then do it right away.
8926 No: add to work queue and add a |SafeState| and/or
8927 |SafeStateAgain| autocommand (|SafeState| triggers at
8928 toplevel, |SafeStateAgain| triggers after handling
8929 messages and callbacks).
8930 - When SafeState or SafeStateAgain is triggered and executes
8931 your autocommand, check with `state()` if the work can be
8932 done now, and if yes remove it from the queue and execute.
8933 Remove the autocommand if the queue is now empty.
8934 Also see |mode()|.
8935
8936 When {what} is given only characters in this string will be
8937 added. E.g, this checks if the screen has scrolled: >
8938 if state('s') == ''
8939 " screen has not scrolled
8940<
8941 These characters indicate the state, generally indicating that
8942 something is busy:
8943 m halfway a mapping, :normal command, feedkeys() or
8944 stuffed command
8945 o operator pending, e.g. after |d|
8946 a Insert mode autocomplete active
8947 x executing an autocommand
8948 w blocked on waiting, e.g. ch_evalexpr(), ch_read() and
8949 ch_readraw() when reading json
8950 S not triggering SafeState or SafeStateAgain, e.g. after
8951 |f| or a count
8952 c callback invoked, including timer (repeats for
8953 recursiveness up to "ccc")
8954 s screen has scrolled for messages
8955
8956str2float({string} [, {quoted}]) *str2float()*
8957 Convert String {string} to a Float. This mostly works the
8958 same as when using a floating point number in an expression,
8959 see |floating-point-format|. But it's a bit more permissive.
8960 E.g., "1e40" is accepted, while in an expression you need to
8961 write "1.0e40". The hexadecimal form "0x123" is also
8962 accepted, but not others, like binary or octal.
8963 When {quoted} is present and non-zero then embedded single
8964 quotes before the dot are ignored, thus "1'000.0" is a
8965 thousand.
8966 Text after the number is silently ignored.
8967 The decimal point is always '.', no matter what the locale is
8968 set to. A comma ends the number: "12,345.67" is converted to
8969 12.0. You can strip out thousands separators with
8970 |substitute()|: >
8971 let f = str2float(substitute(text, ',', '', 'g'))
8972<
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01008973 Returns 0.0 if the conversion fails.
8974
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008975 Can also be used as a |method|: >
8976 let f = text->substitute(',', '', 'g')->str2float()
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008977
8978str2list({string} [, {utf8}]) *str2list()*
8979 Return a list containing the number values which represent
8980 each character in String {string}. Examples: >
8981 str2list(" ") returns [32]
8982 str2list("ABC") returns [65, 66, 67]
8983< |list2str()| does the opposite.
8984
8985 When {utf8} is omitted or zero, the current 'encoding' is used.
8986 When {utf8} is TRUE, always treat the String as UTF-8
8987 characters. With UTF-8 composing characters are handled
8988 properly: >
8989 str2list("á") returns [97, 769]
8990
8991< Can also be used as a |method|: >
8992 GetString()->str2list()
8993
8994
8995str2nr({string} [, {base} [, {quoted}]]) *str2nr()*
8996 Convert string {string} to a number.
8997 {base} is the conversion base, it can be 2, 8, 10 or 16.
8998 When {quoted} is present and non-zero then embedded single
8999 quotes are ignored, thus "1'000'000" is a million.
9000
9001 When {base} is omitted base 10 is used. This also means that
9002 a leading zero doesn't cause octal conversion to be used, as
9003 with the default String to Number conversion. Example: >
9004 let nr = str2nr('0123')
9005<
9006 When {base} is 16 a leading "0x" or "0X" is ignored. With a
9007 different base the result will be zero. Similarly, when
9008 {base} is 8 a leading "0", "0o" or "0O" is ignored, and when
9009 {base} is 2 a leading "0b" or "0B" is ignored.
9010 Text after the number is silently ignored.
9011
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01009012 Returns 0 if {string} is empty or on error.
9013
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009014 Can also be used as a |method|: >
9015 GetText()->str2nr()
9016
9017
9018strcharlen({string}) *strcharlen()*
9019 The result is a Number, which is the number of characters
9020 in String {string}. Composing characters are ignored.
9021 |strchars()| can count the number of characters, counting
9022 composing characters separately.
9023
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01009024 Returns 0 if {string} is empty or on error.
9025
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009026 Also see |strlen()|, |strdisplaywidth()| and |strwidth()|.
9027
9028 Can also be used as a |method|: >
9029 GetText()->strcharlen()
9030
9031
9032strcharpart({src}, {start} [, {len} [, {skipcc}]]) *strcharpart()*
9033 Like |strpart()| but using character index and length instead
9034 of byte index and length.
9035 When {skipcc} is omitted or zero, composing characters are
9036 counted separately.
9037 When {skipcc} set to 1, Composing characters are ignored,
9038 similar to |slice()|.
9039 When a character index is used where a character does not
9040 exist it is omitted and counted as one character. For
9041 example: >
9042 strcharpart('abc', -1, 2)
9043< results in 'a'.
9044
Bram Moolenaard592deb2022-06-17 15:42:40 +01009045 Returns an empty string on error.
9046
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009047 Can also be used as a |method|: >
9048 GetText()->strcharpart(5)
9049
9050
9051strchars({string} [, {skipcc}]) *strchars()*
9052 The result is a Number, which is the number of characters
9053 in String {string}.
9054 When {skipcc} is omitted or zero, composing characters are
9055 counted separately.
9056 When {skipcc} set to 1, Composing characters are ignored.
9057 |strcharlen()| always does this.
9058
Bram Moolenaard592deb2022-06-17 15:42:40 +01009059 Returns zero on error.
9060
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009061 Also see |strlen()|, |strdisplaywidth()| and |strwidth()|.
9062
9063 {skipcc} is only available after 7.4.755. For backward
9064 compatibility, you can define a wrapper function: >
9065 if has("patch-7.4.755")
9066 function s:strchars(str, skipcc)
9067 return strchars(a:str, a:skipcc)
9068 endfunction
9069 else
9070 function s:strchars(str, skipcc)
9071 if a:skipcc
9072 return strlen(substitute(a:str, ".", "x", "g"))
9073 else
9074 return strchars(a:str)
9075 endif
9076 endfunction
9077 endif
9078<
9079 Can also be used as a |method|: >
9080 GetText()->strchars()
9081
9082strdisplaywidth({string} [, {col}]) *strdisplaywidth()*
9083 The result is a Number, which is the number of display cells
9084 String {string} occupies on the screen when it starts at {col}
9085 (first column is zero). When {col} is omitted zero is used.
9086 Otherwise it is the screen column where to start. This
9087 matters for Tab characters.
9088 The option settings of the current window are used. This
9089 matters for anything that's displayed differently, such as
9090 'tabstop' and 'display'.
9091 When {string} contains characters with East Asian Width Class
9092 Ambiguous, this function's return value depends on 'ambiwidth'.
Bram Moolenaard592deb2022-06-17 15:42:40 +01009093 Returns zero on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009094 Also see |strlen()|, |strwidth()| and |strchars()|.
9095
9096 Can also be used as a |method|: >
9097 GetText()->strdisplaywidth()
9098
9099strftime({format} [, {time}]) *strftime()*
9100 The result is a String, which is a formatted date and time, as
9101 specified by the {format} string. The given {time} is used,
9102 or the current time if no time is given. The accepted
9103 {format} depends on your system, thus this is not portable!
9104 See the manual page of the C function strftime() for the
9105 format. The maximum length of the result is 80 characters.
9106 See also |localtime()|, |getftime()| and |strptime()|.
9107 The language can be changed with the |:language| command.
9108 Examples: >
9109 :echo strftime("%c") Sun Apr 27 11:49:23 1997
9110 :echo strftime("%Y %b %d %X") 1997 Apr 27 11:53:25
9111 :echo strftime("%y%m%d %T") 970427 11:53:55
9112 :echo strftime("%H:%M") 11:55
9113 :echo strftime("%c", getftime("file.c"))
9114 Show mod time of file.c.
9115< Not available on all systems. To check use: >
9116 :if exists("*strftime")
9117
9118< Can also be used as a |method|: >
9119 GetFormat()->strftime()
9120
9121strgetchar({str}, {index}) *strgetchar()*
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01009122 Get a Number corresponding to the character at {index} in
9123 {str}. This uses a zero-based character index, not a byte
9124 index. Composing characters are considered separate
9125 characters here. Use |nr2char()| to convert the Number to a
9126 String.
Bram Moolenaard592deb2022-06-17 15:42:40 +01009127 Returns -1 if {index} is invalid.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009128 Also see |strcharpart()| and |strchars()|.
9129
9130 Can also be used as a |method|: >
9131 GetText()->strgetchar(5)
9132
9133stridx({haystack}, {needle} [, {start}]) *stridx()*
9134 The result is a Number, which gives the byte index in
9135 {haystack} of the first occurrence of the String {needle}.
9136 If {start} is specified, the search starts at index {start}.
9137 This can be used to find a second match: >
9138 :let colon1 = stridx(line, ":")
9139 :let colon2 = stridx(line, ":", colon1 + 1)
9140< The search is done case-sensitive.
9141 For pattern searches use |match()|.
9142 -1 is returned if the {needle} does not occur in {haystack}.
9143 See also |strridx()|.
9144 Examples: >
9145 :echo stridx("An Example", "Example") 3
9146 :echo stridx("Starting point", "Start") 0
9147 :echo stridx("Starting point", "start") -1
9148< *strstr()* *strchr()*
9149 stridx() works similar to the C function strstr(). When used
9150 with a single character it works similar to strchr().
9151
9152 Can also be used as a |method|: >
9153 GetHaystack()->stridx(needle)
9154<
9155 *string()*
9156string({expr}) Return {expr} converted to a String. If {expr} is a Number,
9157 Float, String, Blob or a composition of them, then the result
9158 can be parsed back with |eval()|.
9159 {expr} type result ~
9160 String 'string' (single quotes are doubled)
9161 Number 123
9162 Float 123.123456 or 1.123456e8
9163 Funcref function('name')
9164 Blob 0z00112233.44556677.8899
9165 List [item, item]
9166 Dictionary {key: value, key: value}
Bram Moolenaarf1dcd142022-12-31 15:30:45 +00009167 Class class SomeName
9168 Object object of SomeName {lnum: 1, col: 3}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009169
9170 When a |List| or |Dictionary| has a recursive reference it is
9171 replaced by "[...]" or "{...}". Using eval() on the result
9172 will then fail.
9173
9174 Can also be used as a |method|: >
9175 mylist->string()
9176
9177< Also see |strtrans()|.
9178
9179
9180strlen({string}) *strlen()*
9181 The result is a Number, which is the length of the String
9182 {string} in bytes.
9183 If the argument is a Number it is first converted to a String.
Bram Moolenaard592deb2022-06-17 15:42:40 +01009184 For other types an error is given and zero is returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009185 If you want to count the number of multibyte characters use
9186 |strchars()|.
9187 Also see |len()|, |strdisplaywidth()| and |strwidth()|.
9188
9189 Can also be used as a |method|: >
9190 GetString()->strlen()
9191
9192strpart({src}, {start} [, {len} [, {chars}]]) *strpart()*
9193 The result is a String, which is part of {src}, starting from
9194 byte {start}, with the byte length {len}.
9195 When {chars} is present and TRUE then {len} is the number of
9196 characters positions (composing characters are not counted
9197 separately, thus "1" means one base character and any
9198 following composing characters).
9199 To count {start} as characters instead of bytes use
9200 |strcharpart()|.
9201
9202 When bytes are selected which do not exist, this doesn't
9203 result in an error, the bytes are simply omitted.
9204 If {len} is missing, the copy continues from {start} till the
9205 end of the {src}. >
9206 strpart("abcdefg", 3, 2) == "de"
9207 strpart("abcdefg", -2, 4) == "ab"
9208 strpart("abcdefg", 5, 4) == "fg"
9209 strpart("abcdefg", 3) == "defg"
9210
9211< Note: To get the first character, {start} must be 0. For
9212 example, to get the character under the cursor: >
9213 strpart(getline("."), col(".") - 1, 1, v:true)
9214<
Bram Moolenaard592deb2022-06-17 15:42:40 +01009215 Returns an empty string on error.
9216
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009217 Can also be used as a |method|: >
9218 GetText()->strpart(5)
9219
9220strptime({format}, {timestring}) *strptime()*
9221 The result is a Number, which is a unix timestamp representing
9222 the date and time in {timestring}, which is expected to match
9223 the format specified in {format}.
9224
9225 The accepted {format} depends on your system, thus this is not
9226 portable! See the manual page of the C function strptime()
9227 for the format. Especially avoid "%c". The value of $TZ also
9228 matters.
9229
9230 If the {timestring} cannot be parsed with {format} zero is
9231 returned. If you do not know the format of {timestring} you
9232 can try different {format} values until you get a non-zero
9233 result.
9234
9235 See also |strftime()|.
9236 Examples: >
9237 :echo strptime("%Y %b %d %X", "1997 Apr 27 11:49:23")
9238< 862156163 >
9239 :echo strftime("%c", strptime("%y%m%d %T", "970427 11:53:55"))
9240< Sun Apr 27 11:53:55 1997 >
9241 :echo strftime("%c", strptime("%Y%m%d%H%M%S", "19970427115355") + 3600)
9242< Sun Apr 27 12:53:55 1997
9243
9244 Can also be used as a |method|: >
9245 GetFormat()->strptime(timestring)
9246<
9247 Not available on all systems. To check use: >
9248 :if exists("*strptime")
9249
9250strridx({haystack}, {needle} [, {start}]) *strridx()*
9251 The result is a Number, which gives the byte index in
9252 {haystack} of the last occurrence of the String {needle}.
9253 When {start} is specified, matches beyond this index are
9254 ignored. This can be used to find a match before a previous
9255 match: >
9256 :let lastcomma = strridx(line, ",")
9257 :let comma2 = strridx(line, ",", lastcomma - 1)
9258< The search is done case-sensitive.
9259 For pattern searches use |match()|.
9260 -1 is returned if the {needle} does not occur in {haystack}.
9261 If the {needle} is empty the length of {haystack} is returned.
9262 See also |stridx()|. Examples: >
9263 :echo strridx("an angry armadillo", "an") 3
9264< *strrchr()*
9265 When used with a single character it works similar to the C
9266 function strrchr().
9267
9268 Can also be used as a |method|: >
9269 GetHaystack()->strridx(needle)
9270
9271strtrans({string}) *strtrans()*
9272 The result is a String, which is {string} with all unprintable
9273 characters translated into printable characters |'isprint'|.
9274 Like they are shown in a window. Example: >
9275 echo strtrans(@a)
9276< This displays a newline in register a as "^@" instead of
9277 starting a new line.
9278
Bram Moolenaard592deb2022-06-17 15:42:40 +01009279 Returns an empty string on error.
9280
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009281 Can also be used as a |method|: >
9282 GetString()->strtrans()
9283
Christian Brabandt67672ef2023-04-24 21:09:54 +01009284strutf16len({string} [, {countcc}]) *strutf16len()*
9285 The result is a Number, which is the number of UTF-16 code
9286 units in String {string} (after converting it to UTF-16).
9287
9288 When {countcc} is TRUE, composing characters are counted
9289 separately.
9290 When {countcc} is omitted or FALSE, composing characters are
9291 ignored.
9292
9293 Returns zero on error.
9294
9295 Also see |strlen()| and |strcharlen()|.
9296 Examples: >
9297 echo strutf16len('a') returns 1
9298 echo strutf16len('©') returns 1
9299 echo strutf16len('😊') returns 2
9300 echo strutf16len('ą́') returns 1
9301 echo strutf16len('ą́', v:true) returns 3
9302
9303 Can also be used as a |method|: >
9304 GetText()->strutf16len()
9305<
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009306strwidth({string}) *strwidth()*
9307 The result is a Number, which is the number of display cells
9308 String {string} occupies. A Tab character is counted as one
9309 cell, alternatively use |strdisplaywidth()|.
9310 When {string} contains characters with East Asian Width Class
9311 Ambiguous, this function's return value depends on 'ambiwidth'.
Bram Moolenaard592deb2022-06-17 15:42:40 +01009312 Returns zero on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009313 Also see |strlen()|, |strdisplaywidth()| and |strchars()|.
9314
9315 Can also be used as a |method|: >
9316 GetString()->strwidth()
9317
9318submatch({nr} [, {list}]) *submatch()* *E935*
9319 Only for an expression in a |:substitute| command or
9320 substitute() function.
9321 Returns the {nr}'th submatch of the matched text. When {nr}
9322 is 0 the whole matched text is returned.
9323 Note that a NL in the string can stand for a line break of a
9324 multi-line match or a NUL character in the text.
9325 Also see |sub-replace-expression|.
9326
9327 If {list} is present and non-zero then submatch() returns
9328 a list of strings, similar to |getline()| with two arguments.
9329 NL characters in the text represent NUL characters in the
9330 text.
9331 Only returns more than one item for |:substitute|, inside
9332 |substitute()| this list will always contain one or zero
9333 items, since there are no real line breaks.
9334
9335 When substitute() is used recursively only the submatches in
9336 the current (deepest) call can be obtained.
9337
Bram Moolenaard592deb2022-06-17 15:42:40 +01009338 Returns an empty string or list on error.
9339
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009340 Examples: >
9341 :s/\d\+/\=submatch(0) + 1/
9342 :echo substitute(text, '\d\+', '\=submatch(0) + 1', '')
9343< This finds the first number in the line and adds one to it.
9344 A line break is included as a newline character.
9345
9346 Can also be used as a |method|: >
9347 GetNr()->submatch()
9348
9349substitute({string}, {pat}, {sub}, {flags}) *substitute()*
9350 The result is a String, which is a copy of {string}, in which
9351 the first match of {pat} is replaced with {sub}.
9352 When {flags} is "g", all matches of {pat} in {string} are
9353 replaced. Otherwise {flags} should be "".
9354
9355 This works like the ":substitute" command (without any flags).
9356 But the matching with {pat} is always done like the 'magic'
9357 option is set and 'cpoptions' is empty (to make scripts
9358 portable). 'ignorecase' is still relevant, use |/\c| or |/\C|
9359 if you want to ignore or match case and ignore 'ignorecase'.
9360 'smartcase' is not used. See |string-match| for how {pat} is
9361 used.
9362
9363 A "~" in {sub} is not replaced with the previous {sub}.
9364 Note that some codes in {sub} have a special meaning
9365 |sub-replace-special|. For example, to replace something with
9366 "\n" (two characters), use "\\\\n" or '\\n'.
9367
9368 When {pat} does not match in {string}, {string} is returned
9369 unmodified.
9370
9371 Example: >
9372 :let &path = substitute(&path, ",\\=[^,]*$", "", "")
9373< This removes the last component of the 'path' option. >
9374 :echo substitute("testing", ".*", "\\U\\0", "")
9375< results in "TESTING".
9376
9377 When {sub} starts with "\=", the remainder is interpreted as
9378 an expression. See |sub-replace-expression|. Example: >
9379 :echo substitute(s, '%\(\x\x\)',
Bram Moolenaarc51cf032022-02-26 12:25:45 +00009380 \ '\=nr2char("0x" .. submatch(1))', 'g')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009381
9382< When {sub} is a Funcref that function is called, with one
9383 optional argument. Example: >
9384 :echo substitute(s, '%\(\x\x\)', SubNr, 'g')
9385< The optional argument is a list which contains the whole
9386 matched string and up to nine submatches, like what
9387 |submatch()| returns. Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00009388 :echo substitute(s, '%\(\x\x\)', {m -> '0x' .. m[1]}, 'g')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009389
Bram Moolenaard592deb2022-06-17 15:42:40 +01009390< Returns an empty string on error.
9391
9392 Can also be used as a |method|: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009393 GetString()->substitute(pat, sub, flags)
9394
Bram Moolenaarc216a7a2022-12-05 13:50:55 +00009395swapfilelist() *swapfilelist()*
9396 Returns a list of swap file names, like what "vim -r" shows.
9397 See the |-r| command argument. The 'directory' option is used
9398 for the directories to inspect. If you only want to get a
9399 list of swap files in the current directory then temporarily
9400 set 'directory' to a dot: >
9401 let save_dir = &directory
9402 let &directory = '.'
9403 let swapfiles = swapfilelist()
9404 let &directory = save_dir
9405
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009406swapinfo({fname}) *swapinfo()*
9407 The result is a dictionary, which holds information about the
9408 swapfile {fname}. The available fields are:
9409 version Vim version
9410 user user name
9411 host host name
9412 fname original file name
9413 pid PID of the Vim process that created the swap
9414 file
9415 mtime last modification time in seconds
9416 inode Optional: INODE number of the file
9417 dirty 1 if file was modified, 0 if not
9418 Note that "user" and "host" are truncated to at most 39 bytes.
9419 In case of failure an "error" item is added with the reason:
9420 Cannot open file: file not found or in accessible
9421 Cannot read file: cannot read first block
9422 Not a swap file: does not contain correct block ID
9423 Magic number mismatch: Info in first block is invalid
9424
9425 Can also be used as a |method|: >
9426 GetFilename()->swapinfo()
9427
9428swapname({buf}) *swapname()*
9429 The result is the swap file path of the buffer {expr}.
9430 For the use of {buf}, see |bufname()| above.
9431 If buffer {buf} is the current buffer, the result is equal to
9432 |:swapname| (unless there is no swap file).
9433 If buffer {buf} has no swap file, returns an empty string.
9434
9435 Can also be used as a |method|: >
9436 GetBufname()->swapname()
9437
9438synID({lnum}, {col}, {trans}) *synID()*
9439 The result is a Number, which is the syntax ID at the position
9440 {lnum} and {col} in the current window.
9441 The syntax ID can be used with |synIDattr()| and
9442 |synIDtrans()| to obtain syntax information about text.
9443
9444 {col} is 1 for the leftmost column, {lnum} is 1 for the first
9445 line. 'synmaxcol' applies, in a longer line zero is returned.
9446 Note that when the position is after the last character,
9447 that's where the cursor can be in Insert mode, synID() returns
9448 zero. {lnum} is used like with |getline()|.
9449
9450 When {trans} is |TRUE|, transparent items are reduced to the
9451 item that they reveal. This is useful when wanting to know
9452 the effective color. When {trans} is |FALSE|, the transparent
9453 item is returned. This is useful when wanting to know which
9454 syntax item is effective (e.g. inside parens).
9455 Warning: This function can be very slow. Best speed is
9456 obtained by going through the file in forward direction.
9457
Bram Moolenaard592deb2022-06-17 15:42:40 +01009458 Returns zero on error.
9459
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009460 Example (echoes the name of the syntax item under the cursor): >
9461 :echo synIDattr(synID(line("."), col("."), 1), "name")
9462<
9463
9464synIDattr({synID}, {what} [, {mode}]) *synIDattr()*
9465 The result is a String, which is the {what} attribute of
9466 syntax ID {synID}. This can be used to obtain information
9467 about a syntax item.
9468 {mode} can be "gui", "cterm" or "term", to get the attributes
9469 for that mode. When {mode} is omitted, or an invalid value is
9470 used, the attributes for the currently active highlighting are
9471 used (GUI, cterm or term).
9472 Use synIDtrans() to follow linked highlight groups.
9473 {what} result
9474 "name" the name of the syntax item
9475 "fg" foreground color (GUI: color name used to set
9476 the color, cterm: color number as a string,
9477 term: empty string)
9478 "bg" background color (as with "fg")
9479 "font" font name (only available in the GUI)
9480 |highlight-font|
9481 "sp" special color for the GUI (as with "fg")
9482 |highlight-guisp|
9483 "ul" underline color for cterm: number as a string
9484 "fg#" like "fg", but for the GUI and the GUI is
9485 running the name in "#RRGGBB" form
9486 "bg#" like "fg#" for "bg"
9487 "sp#" like "fg#" for "sp"
9488 "bold" "1" if bold
9489 "italic" "1" if italic
9490 "reverse" "1" if reverse
9491 "inverse" "1" if inverse (= reverse)
9492 "standout" "1" if standout
9493 "underline" "1" if underlined
9494 "undercurl" "1" if undercurled
9495 "strike" "1" if strikethrough
Bram Moolenaarde786322022-07-30 14:56:17 +01009496 "nocombine" "1" if nocombine
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009497
Bram Moolenaard592deb2022-06-17 15:42:40 +01009498 Returns an empty string on error.
9499
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009500 Example (echoes the color of the syntax item under the
9501 cursor): >
9502 :echo synIDattr(synIDtrans(synID(line("."), col("."), 1)), "fg")
9503<
9504 Can also be used as a |method|: >
9505 :echo synID(line("."), col("."), 1)->synIDtrans()->synIDattr("fg")
9506
9507
9508synIDtrans({synID}) *synIDtrans()*
9509 The result is a Number, which is the translated syntax ID of
9510 {synID}. This is the syntax group ID of what is being used to
9511 highlight the character. Highlight links given with
9512 ":highlight link" are followed.
9513
Bram Moolenaard592deb2022-06-17 15:42:40 +01009514 Returns zero on error.
9515
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009516 Can also be used as a |method|: >
9517 :echo synID(line("."), col("."), 1)->synIDtrans()->synIDattr("fg")
9518
9519synconcealed({lnum}, {col}) *synconcealed()*
9520 The result is a |List| with currently three items:
9521 1. The first item in the list is 0 if the character at the
9522 position {lnum} and {col} is not part of a concealable
9523 region, 1 if it is. {lnum} is used like with |getline()|.
9524 2. The second item in the list is a string. If the first item
9525 is 1, the second item contains the text which will be
9526 displayed in place of the concealed text, depending on the
9527 current setting of 'conceallevel' and 'listchars'.
9528 3. The third and final item in the list is a number
9529 representing the specific syntax region matched in the
9530 line. When the character is not concealed the value is
9531 zero. This allows detection of the beginning of a new
9532 concealable region if there are two consecutive regions
9533 with the same replacement character. For an example, if
9534 the text is "123456" and both "23" and "45" are concealed
9535 and replaced by the character "X", then:
9536 call returns ~
9537 synconcealed(lnum, 1) [0, '', 0]
9538 synconcealed(lnum, 2) [1, 'X', 1]
9539 synconcealed(lnum, 3) [1, 'X', 1]
9540 synconcealed(lnum, 4) [1, 'X', 2]
9541 synconcealed(lnum, 5) [1, 'X', 2]
9542 synconcealed(lnum, 6) [0, '', 0]
9543
9544
9545synstack({lnum}, {col}) *synstack()*
9546 Return a |List|, which is the stack of syntax items at the
9547 position {lnum} and {col} in the current window. {lnum} is
9548 used like with |getline()|. Each item in the List is an ID
9549 like what |synID()| returns.
9550 The first item in the List is the outer region, following are
9551 items contained in that one. The last one is what |synID()|
9552 returns, unless not the whole item is highlighted or it is a
9553 transparent item.
9554 This function is useful for debugging a syntax file.
9555 Example that shows the syntax stack under the cursor: >
9556 for id in synstack(line("."), col("."))
9557 echo synIDattr(id, "name")
9558 endfor
9559< When the position specified with {lnum} and {col} is invalid
Bram Moolenaard592deb2022-06-17 15:42:40 +01009560 an empty List is returned. The position just after the last
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009561 character in a line and the first column in an empty line are
9562 valid positions.
9563
9564system({expr} [, {input}]) *system()* *E677*
9565 Get the output of the shell command {expr} as a |String|. See
9566 |systemlist()| to get the output as a |List|.
9567
9568 When {input} is given and is a |String| this string is written
9569 to a file and passed as stdin to the command. The string is
9570 written as-is, you need to take care of using the correct line
9571 separators yourself.
9572 If {input} is given and is a |List| it is written to the file
9573 in a way |writefile()| does with {binary} set to "b" (i.e.
9574 with a newline between each list item with newlines inside
9575 list items converted to NULs).
9576 When {input} is given and is a number that is a valid id for
9577 an existing buffer then the content of the buffer is written
9578 to the file line by line, each line terminated by a NL and
9579 NULs characters where the text has a NL.
9580
9581 Pipes are not used, the 'shelltemp' option is not used.
9582
9583 When prepended by |:silent| the terminal will not be set to
9584 cooked mode. This is meant to be used for commands that do
9585 not need the user to type. It avoids stray characters showing
9586 up on the screen which require |CTRL-L| to remove. >
9587 :silent let f = system('ls *.vim')
9588<
9589 Note: Use |shellescape()| or |::S| with |expand()| or
9590 |fnamemodify()| to escape special characters in a command
9591 argument. Newlines in {expr} may cause the command to fail.
9592 The characters in 'shellquote' and 'shellxquote' may also
9593 cause trouble.
9594 This is not to be used for interactive commands.
9595
9596 The result is a String. Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00009597 :let files = system('ls ' .. shellescape(expand('%:h')))
9598 :let files = system('ls ' .. expand('%:h:S'))
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009599
9600< To make the result more system-independent, the shell output
9601 is filtered to replace <CR> with <NL> for Macintosh, and
9602 <CR><NL> with <NL> for DOS-like systems.
9603 To avoid the string being truncated at a NUL, all NUL
9604 characters are replaced with SOH (0x01).
9605
9606 The command executed is constructed using several options:
9607 'shell' 'shellcmdflag' 'shellxquote' {expr} 'shellredir' {tmp} 'shellxquote'
9608 ({tmp} is an automatically generated file name).
9609 For Unix, braces are put around {expr} to allow for
9610 concatenated commands.
9611
9612 The command will be executed in "cooked" mode, so that a
9613 CTRL-C will interrupt the command (on Unix at least).
9614
9615 The resulting error code can be found in |v:shell_error|.
9616 This function will fail in |restricted-mode|.
9617
9618 Note that any wrong value in the options mentioned above may
9619 make the function fail. It has also been reported to fail
9620 when using a security agent application.
9621 Unlike ":!cmd" there is no automatic check for changed files.
9622 Use |:checktime| to force a check.
9623
9624 Can also be used as a |method|: >
9625 :echo GetCmd()->system()
9626
9627
9628systemlist({expr} [, {input}]) *systemlist()*
9629 Same as |system()|, but returns a |List| with lines (parts of
9630 output separated by NL) with NULs transformed into NLs. Output
9631 is the same as |readfile()| will output with {binary} argument
9632 set to "b", except that there is no extra empty item when the
9633 result ends in a NL.
9634 Note that on MS-Windows you may get trailing CR characters.
9635
9636 To see the difference between "echo hello" and "echo -n hello"
9637 use |system()| and |split()|: >
9638 echo system('echo hello')->split('\n', 1)
9639<
9640 Returns an empty string on error.
9641
9642 Can also be used as a |method|: >
9643 :echo GetCmd()->systemlist()
9644
9645
9646tabpagebuflist([{arg}]) *tabpagebuflist()*
9647 The result is a |List|, where each item is the number of the
9648 buffer associated with each window in the current tab page.
9649 {arg} specifies the number of the tab page to be used. When
9650 omitted the current tab page is used.
9651 When {arg} is invalid the number zero is returned.
9652 To get a list of all buffers in all tabs use this: >
9653 let buflist = []
9654 for i in range(tabpagenr('$'))
9655 call extend(buflist, tabpagebuflist(i + 1))
9656 endfor
9657< Note that a buffer may appear in more than one window.
9658
9659 Can also be used as a |method|: >
9660 GetTabpage()->tabpagebuflist()
9661
9662tabpagenr([{arg}]) *tabpagenr()*
9663 The result is a Number, which is the number of the current
9664 tab page. The first tab page has number 1.
9665
9666 The optional argument {arg} supports the following values:
9667 $ the number of the last tab page (the tab page
9668 count).
9669 # the number of the last accessed tab page
9670 (where |g<Tab>| goes to). if there is no
9671 previous tab page 0 is returned.
9672 The number can be used with the |:tab| command.
9673
Bram Moolenaard592deb2022-06-17 15:42:40 +01009674 Returns zero on error.
9675
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009676
9677tabpagewinnr({tabarg} [, {arg}]) *tabpagewinnr()*
9678 Like |winnr()| but for tab page {tabarg}.
9679 {tabarg} specifies the number of tab page to be used.
9680 {arg} is used like with |winnr()|:
9681 - When omitted the current window number is returned. This is
9682 the window which will be used when going to this tab page.
9683 - When "$" the number of windows is returned.
9684 - When "#" the previous window nr is returned.
9685 Useful examples: >
9686 tabpagewinnr(1) " current window of tab page 1
9687 tabpagewinnr(4, '$') " number of windows in tab page 4
9688< When {tabarg} is invalid zero is returned.
9689
9690 Can also be used as a |method|: >
9691 GetTabpage()->tabpagewinnr()
9692<
9693 *tagfiles()*
9694tagfiles() Returns a |List| with the file names used to search for tags
9695 for the current buffer. This is the 'tags' option expanded.
9696
9697
9698taglist({expr} [, {filename}]) *taglist()*
9699 Returns a |List| of tags matching the regular expression {expr}.
9700
9701 If {filename} is passed it is used to prioritize the results
9702 in the same way that |:tselect| does. See |tag-priority|.
9703 {filename} should be the full path of the file.
9704
9705 Each list item is a dictionary with at least the following
9706 entries:
9707 name Name of the tag.
9708 filename Name of the file where the tag is
9709 defined. It is either relative to the
9710 current directory or a full path.
9711 cmd Ex command used to locate the tag in
9712 the file.
9713 kind Type of the tag. The value for this
9714 entry depends on the language specific
9715 kind values. Only available when
9716 using a tags file generated by
Bram Moolenaar47c532e2022-03-19 15:18:53 +00009717 Universal/Exuberant ctags or hdrtag.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009718 static A file specific tag. Refer to
9719 |static-tag| for more information.
9720 More entries may be present, depending on the content of the
9721 tags file: access, implementation, inherits and signature.
9722 Refer to the ctags documentation for information about these
9723 fields. For C code the fields "struct", "class" and "enum"
9724 may appear, they give the name of the entity the tag is
9725 contained in.
9726
9727 The ex-command "cmd" can be either an ex search pattern, a
9728 line number or a line number followed by a byte number.
9729
9730 If there are no matching tags, then an empty list is returned.
9731
9732 To get an exact tag match, the anchors '^' and '$' should be
9733 used in {expr}. This also make the function work faster.
9734 Refer to |tag-regexp| for more information about the tag
9735 search regular expression pattern.
9736
9737 Refer to |'tags'| for information about how the tags file is
9738 located by Vim. Refer to |tags-file-format| for the format of
9739 the tags file generated by the different ctags tools.
9740
9741 Can also be used as a |method|: >
9742 GetTagpattern()->taglist()
9743
9744tan({expr}) *tan()*
9745 Return the tangent of {expr}, measured in radians, as a |Float|
9746 in the range [-inf, inf].
9747 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaard592deb2022-06-17 15:42:40 +01009748 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009749 Examples: >
9750 :echo tan(10)
9751< 0.648361 >
9752 :echo tan(-4.01)
9753< -1.181502
9754
9755 Can also be used as a |method|: >
9756 Compute()->tan()
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009757
9758
9759tanh({expr}) *tanh()*
9760 Return the hyperbolic tangent of {expr} as a |Float| in the
9761 range [-1, 1].
9762 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaard592deb2022-06-17 15:42:40 +01009763 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009764 Examples: >
9765 :echo tanh(0.5)
9766< 0.462117 >
9767 :echo tanh(-1)
9768< -0.761594
9769
9770 Can also be used as a |method|: >
9771 Compute()->tanh()
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009772
9773
9774tempname() *tempname()* *temp-file-name*
9775 The result is a String, which is the name of a file that
9776 doesn't exist. It can be used for a temporary file. The name
9777 is different for at least 26 consecutive calls. Example: >
9778 :let tmpfile = tempname()
Bram Moolenaarc51cf032022-02-26 12:25:45 +00009779 :exe "redir > " .. tmpfile
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009780< For Unix, the file will be in a private directory |tempfile|.
9781 For MS-Windows forward slashes are used when the 'shellslash'
9782 option is set, or when 'shellcmdflag' starts with '-' and
9783 'shell' does not contain powershell or pwsh.
9784
9785
9786term_ functions are documented here: |terminal-function-details|
9787
9788
9789terminalprops() *terminalprops()*
9790 Returns a |Dictionary| with properties of the terminal that Vim
9791 detected from the response to |t_RV| request. See
9792 |v:termresponse| for the response itself. If |v:termresponse|
9793 is empty most values here will be 'u' for unknown.
9794 cursor_style whether sending |t_RS| works **
9795 cursor_blink_mode whether sending |t_RC| works **
9796 underline_rgb whether |t_8u| works **
9797 mouse mouse type supported
Bram Moolenaar4bc85f22022-10-21 14:17:24 +01009798 kitty whether Kitty terminal was detected
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009799
9800 ** value 'u' for unknown, 'y' for yes, 'n' for no
9801
9802 If the |+termresponse| feature is missing then the result is
9803 an empty dictionary.
9804
9805 If "cursor_style" is 'y' then |t_RS| will be sent to request the
9806 current cursor style.
9807 If "cursor_blink_mode" is 'y' then |t_RC| will be sent to
9808 request the cursor blink status.
9809 "cursor_style" and "cursor_blink_mode" are also set if |t_u7|
9810 is not empty, Vim will detect the working of sending |t_RS|
9811 and |t_RC| on startup.
9812
9813 When "underline_rgb" is not 'y', then |t_8u| will be made empty.
9814 This avoids sending it to xterm, which would clear the colors.
9815
9816 For "mouse" the value 'u' is unknown
9817
9818 Also see:
9819 - 'ambiwidth' - detected by using |t_u7|.
9820 - |v:termstyleresp| and |v:termblinkresp| for the response to
9821 |t_RS| and |t_RC|.
9822
9823
9824test_ functions are documented here: |test-functions-details|
9825
9826
9827 *timer_info()*
9828timer_info([{id}])
9829 Return a list with information about timers.
9830 When {id} is given only information about this timer is
9831 returned. When timer {id} does not exist an empty list is
9832 returned.
9833 When {id} is omitted information about all timers is returned.
9834
9835 For each timer the information is stored in a |Dictionary| with
9836 these items:
9837 "id" the timer ID
9838 "time" time the timer was started with
9839 "remaining" time until the timer fires
9840 "repeat" number of times the timer will still fire;
9841 -1 means forever
9842 "callback" the callback
9843 "paused" 1 if the timer is paused, 0 otherwise
9844
9845 Can also be used as a |method|: >
9846 GetTimer()->timer_info()
9847
9848< {only available when compiled with the |+timers| feature}
9849
9850timer_pause({timer}, {paused}) *timer_pause()*
9851 Pause or unpause a timer. A paused timer does not invoke its
9852 callback when its time expires. Unpausing a timer may cause
9853 the callback to be invoked almost immediately if enough time
9854 has passed.
9855
9856 Pausing a timer is useful to avoid the callback to be called
9857 for a short time.
9858
9859 If {paused} evaluates to a non-zero Number or a non-empty
9860 String, then the timer is paused, otherwise it is unpaused.
9861 See |non-zero-arg|.
9862
9863 Can also be used as a |method|: >
9864 GetTimer()->timer_pause(1)
9865
9866< {only available when compiled with the |+timers| feature}
9867
9868 *timer_start()* *timer* *timers*
9869timer_start({time}, {callback} [, {options}])
9870 Create a timer and return the timer ID.
9871
9872 {time} is the waiting time in milliseconds. This is the
9873 minimum time before invoking the callback. When the system is
9874 busy or Vim is not waiting for input the time will be longer.
Bram Moolenaardd60c362023-02-27 15:49:53 +00009875 Zero can be used to execute the callback when Vim is back in
9876 the main loop.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009877
9878 {callback} is the function to call. It can be the name of a
9879 function or a |Funcref|. It is called with one argument, which
9880 is the timer ID. The callback is only invoked when Vim is
9881 waiting for input.
9882 If you want to show a message look at |popup_notification()|
9883 to avoid interfering with what the user is doing.
9884
9885 {options} is a dictionary. Supported entries:
9886 "repeat" Number of times to repeat calling the
9887 callback. -1 means forever. When not present
9888 the callback will be called once.
9889 If the timer causes an error three times in a
9890 row the repeat is cancelled. This avoids that
9891 Vim becomes unusable because of all the error
9892 messages.
9893
Bram Moolenaard592deb2022-06-17 15:42:40 +01009894 Returns -1 on error.
9895
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009896 Example: >
9897 func MyHandler(timer)
9898 echo 'Handler called'
9899 endfunc
9900 let timer = timer_start(500, 'MyHandler',
9901 \ {'repeat': 3})
9902< This will invoke MyHandler() three times at 500 msec
9903 intervals.
9904
9905 Can also be used as a |method|: >
9906 GetMsec()->timer_start(callback)
9907
9908< Not available in the |sandbox|.
9909 {only available when compiled with the |+timers| feature}
9910
9911timer_stop({timer}) *timer_stop()*
9912 Stop a timer. The timer callback will no longer be invoked.
9913 {timer} is an ID returned by timer_start(), thus it must be a
9914 Number. If {timer} does not exist there is no error.
9915
9916 Can also be used as a |method|: >
9917 GetTimer()->timer_stop()
9918
9919< {only available when compiled with the |+timers| feature}
9920
9921timer_stopall() *timer_stopall()*
9922 Stop all timers. The timer callbacks will no longer be
9923 invoked. Useful if a timer is misbehaving. If there are no
9924 timers there is no error.
9925
9926 {only available when compiled with the |+timers| feature}
9927
9928tolower({expr}) *tolower()*
9929 The result is a copy of the String given, with all uppercase
9930 characters turned into lowercase (just like applying |gu| to
Bram Moolenaard592deb2022-06-17 15:42:40 +01009931 the string). Returns an empty string on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009932
9933 Can also be used as a |method|: >
9934 GetText()->tolower()
9935
9936toupper({expr}) *toupper()*
9937 The result is a copy of the String given, with all lowercase
9938 characters turned into uppercase (just like applying |gU| to
Bram Moolenaard592deb2022-06-17 15:42:40 +01009939 the string). Returns an empty string on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009940
9941 Can also be used as a |method|: >
9942 GetText()->toupper()
9943
9944tr({src}, {fromstr}, {tostr}) *tr()*
9945 The result is a copy of the {src} string with all characters
9946 which appear in {fromstr} replaced by the character in that
9947 position in the {tostr} string. Thus the first character in
9948 {fromstr} is translated into the first character in {tostr}
9949 and so on. Exactly like the unix "tr" command.
9950 This code also deals with multibyte characters properly.
9951
Bram Moolenaard592deb2022-06-17 15:42:40 +01009952 Returns an empty string on error.
9953
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009954 Examples: >
9955 echo tr("hello there", "ht", "HT")
9956< returns "Hello THere" >
9957 echo tr("<blob>", "<>", "{}")
9958< returns "{blob}"
9959
9960 Can also be used as a |method|: >
9961 GetText()->tr(from, to)
9962
9963trim({text} [, {mask} [, {dir}]]) *trim()*
9964 Return {text} as a String where any character in {mask} is
9965 removed from the beginning and/or end of {text}.
9966
9967 If {mask} is not given, {mask} is all characters up to 0x20,
9968 which includes Tab, space, NL and CR, plus the non-breaking
9969 space character 0xa0.
9970
9971 The optional {dir} argument specifies where to remove the
9972 characters:
9973 0 remove from the beginning and end of {text}
9974 1 remove only at the beginning of {text}
9975 2 remove only at the end of {text}
9976 When omitted both ends are trimmed.
9977
9978 This function deals with multibyte characters properly.
Bram Moolenaard592deb2022-06-17 15:42:40 +01009979 Returns an empty string on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009980
9981 Examples: >
9982 echo trim(" some text ")
9983< returns "some text" >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00009984 echo trim(" \r\t\t\r RESERVE \t\n\x0B\xA0") .. "_TAIL"
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009985< returns "RESERVE_TAIL" >
9986 echo trim("rm<Xrm<>X>rrm", "rm<>")
9987< returns "Xrm<>X" (characters in the middle are not removed) >
9988 echo trim(" vim ", " ", 2)
9989< returns " vim"
9990
9991 Can also be used as a |method|: >
9992 GetText()->trim()
9993
9994trunc({expr}) *trunc()*
9995 Return the largest integral value with magnitude less than or
9996 equal to {expr} as a |Float| (truncate towards zero).
9997 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaard592deb2022-06-17 15:42:40 +01009998 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009999 Examples: >
10000 echo trunc(1.456)
10001< 1.0 >
10002 echo trunc(-5.456)
10003< -5.0 >
10004 echo trunc(4.0)
10005< 4.0
10006
10007 Can also be used as a |method|: >
10008 Compute()->trunc()
10009<
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010010 *type()*
10011type({expr}) The result is a Number representing the type of {expr}.
10012 Instead of using the number directly, it is better to use the
10013 v:t_ variable that has the value:
10014 Number: 0 |v:t_number|
10015 String: 1 |v:t_string|
10016 Funcref: 2 |v:t_func|
10017 List: 3 |v:t_list|
10018 Dictionary: 4 |v:t_dict|
10019 Float: 5 |v:t_float|
10020 Boolean: 6 |v:t_bool| (v:false and v:true)
10021 None: 7 |v:t_none| (v:null and v:none)
10022 Job: 8 |v:t_job|
10023 Channel: 9 |v:t_channel|
10024 Blob: 10 |v:t_blob|
Bram Moolenaarc0c2c262023-01-12 21:08:53 +000010025 Class 12 |v:t_class|
10026 Object 13 |v:t_object|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010027 For backward compatibility, this method can be used: >
10028 :if type(myvar) == type(0)
10029 :if type(myvar) == type("")
10030 :if type(myvar) == type(function("tr"))
10031 :if type(myvar) == type([])
10032 :if type(myvar) == type({})
10033 :if type(myvar) == type(0.0)
10034 :if type(myvar) == type(v:false)
10035 :if type(myvar) == type(v:none)
10036< To check if the v:t_ variables exist use this: >
10037 :if exists('v:t_number')
10038
10039< Can also be used as a |method|: >
10040 mylist->type()
10041
10042
10043typename({expr}) *typename()*
10044 Return a string representation of the type of {expr}.
10045 Example: >
10046 echo typename([1, 2, 3])
Kota Kato66bb9ae2023-01-17 18:31:56 +000010047< list<number> ~
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010048
10049
10050undofile({name}) *undofile()*
10051 Return the name of the undo file that would be used for a file
10052 with name {name} when writing. This uses the 'undodir'
10053 option, finding directories that exist. It does not check if
10054 the undo file exists.
10055 {name} is always expanded to the full path, since that is what
10056 is used internally.
10057 If {name} is empty undofile() returns an empty string, since a
10058 buffer without a file name will not write an undo file.
10059 Useful in combination with |:wundo| and |:rundo|.
10060 When compiled without the |+persistent_undo| option this always
10061 returns an empty string.
10062
10063 Can also be used as a |method|: >
10064 GetFilename()->undofile()
10065
10066undotree() *undotree()*
10067 Return the current state of the undo tree in a dictionary with
10068 the following items:
10069 "seq_last" The highest undo sequence number used.
10070 "seq_cur" The sequence number of the current position in
10071 the undo tree. This differs from "seq_last"
10072 when some changes were undone.
10073 "time_cur" Time last used for |:earlier| and related
10074 commands. Use |strftime()| to convert to
10075 something readable.
10076 "save_last" Number of the last file write. Zero when no
10077 write yet.
10078 "save_cur" Number of the current position in the undo
10079 tree.
10080 "synced" Non-zero when the last undo block was synced.
10081 This happens when waiting from input from the
10082 user. See |undo-blocks|.
10083 "entries" A list of dictionaries with information about
10084 undo blocks.
10085
10086 The first item in the "entries" list is the oldest undo item.
10087 Each List item is a |Dictionary| with these items:
10088 "seq" Undo sequence number. Same as what appears in
10089 |:undolist|.
10090 "time" Timestamp when the change happened. Use
10091 |strftime()| to convert to something readable.
10092 "newhead" Only appears in the item that is the last one
10093 that was added. This marks the last change
10094 and where further changes will be added.
10095 "curhead" Only appears in the item that is the last one
10096 that was undone. This marks the current
10097 position in the undo tree, the block that will
10098 be used by a redo command. When nothing was
10099 undone after the last change this item will
10100 not appear anywhere.
10101 "save" Only appears on the last block before a file
10102 write. The number is the write count. The
10103 first write has number 1, the last one the
10104 "save_last" mentioned above.
10105 "alt" Alternate entry. This is again a List of undo
10106 blocks. Each item may again have an "alt"
10107 item.
10108
10109uniq({list} [, {func} [, {dict}]]) *uniq()* *E882*
10110 Remove second and succeeding copies of repeated adjacent
10111 {list} items in-place. Returns {list}. If you want a list
10112 to remain unmodified make a copy first: >
10113 :let newlist = uniq(copy(mylist))
10114< The default compare function uses the string representation of
10115 each item. For the use of {func} and {dict} see |sort()|.
10116
Bram Moolenaard592deb2022-06-17 15:42:40 +010010117 Returns zero if {list} is not a |List|.
10118
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010119 Can also be used as a |method|: >
10120 mylist->uniq()
Christian Brabandt67672ef2023-04-24 21:09:54 +010010121<
10122 *utf16idx()*
10123utf16idx({string}, {idx} [, {countcc} [, {charidx}]])
Yegappan Lakshmanan577922b2023-06-08 17:09:45 +010010124 Same as |charidx()| but returns the UTF-16 code unit index of
10125 the byte at {idx} in {string} (after converting it to UTF-16).
Christian Brabandt67672ef2023-04-24 21:09:54 +010010126
10127 When {charidx} is present and TRUE, {idx} is used as the
10128 character index in the String {string} instead of as the byte
10129 index.
10130 An {idx} in the middle of a UTF-8 sequence is rounded upwards
10131 to the end of that sequence.
10132
Yegappan Lakshmanan577922b2023-06-08 17:09:45 +010010133 Returns -1 if the arguments are invalid or if there are less
10134 than {idx} bytes in {string}. If there are exactly {idx} bytes
10135 the length of the string in UTF-16 code units is returned.
10136
Christian Brabandt67672ef2023-04-24 21:09:54 +010010137 See |byteidx()| and |byteidxcomp()| for getting the byte index
10138 from the UTF-16 index and |charidx()| for getting the
10139 character index from the UTF-16 index.
10140 Refer to |string-offset-encoding| for more information.
10141 Examples: >
10142 echo utf16idx('a😊😊', 3) returns 2
10143 echo utf16idx('a😊😊', 7) returns 4
10144 echo utf16idx('a😊😊', 1, 0, 1) returns 2
10145 echo utf16idx('a😊😊', 2, 0, 1) returns 4
10146 echo utf16idx('aą́c', 6) returns 2
10147 echo utf16idx('aą́c', 6, 1) returns 4
10148 echo utf16idx('a😊😊', 9) returns -1
10149<
10150 Can also be used as a |method|: >
10151 GetName()->utf16idx(idx)
10152
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010153
10154values({dict}) *values()*
10155 Return a |List| with all the values of {dict}. The |List| is
10156 in arbitrary order. Also see |items()| and |keys()|.
Bram Moolenaard592deb2022-06-17 15:42:40 +010010157 Returns zero if {dict} is not a |Dict|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010158
10159 Can also be used as a |method|: >
10160 mydict->values()
10161
LemonBoy0f7a3e12022-05-26 12:10:37 +010010162virtcol({expr} [, {list}]) *virtcol()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010163 The result is a Number, which is the screen column of the file
10164 position given with {expr}. That is, the last screen position
10165 occupied by the character at that position, when the screen
10166 would be of unlimited width. When there is a <Tab> at the
10167 position, the returned Number will be the column at the end of
10168 the <Tab>. For example, for a <Tab> in column 1, with 'ts'
10169 set to 8, it returns 8. |conceal| is ignored.
10170 For the byte position use |col()|.
LemonBoy0f7a3e12022-05-26 12:10:37 +010010171
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010172 For the use of {expr} see |col()|.
LemonBoy0f7a3e12022-05-26 12:10:37 +010010173
10174 When 'virtualedit' is used {expr} can be [lnum, col, off],
10175 where "off" is the offset in screen columns from the start of
10176 the character. E.g., a position within a <Tab> or after the
10177 last character. When "off" is omitted zero is used. When
10178 Virtual editing is active in the current mode, a position
10179 beyond the end of the line can be returned. Also see
10180 |'virtualedit'|
10181
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010182 The accepted positions are:
10183 . the cursor position
10184 $ the end of the cursor line (the result is the
10185 number of displayed characters in the cursor line
10186 plus one)
10187 'x position of mark x (if the mark is not set, 0 is
10188 returned)
10189 v In Visual mode: the start of the Visual area (the
10190 cursor is the end). When not in Visual mode
10191 returns the cursor position. Differs from |'<| in
10192 that it's updated right away.
LemonBoy0f7a3e12022-05-26 12:10:37 +010010193
10194 If {list} is present and non-zero then virtcol() returns a List
10195 with the first and last screen position occupied by the
10196 character.
10197
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010198 Note that only marks in the current file can be used.
10199 Examples: >
LemonBoy0f7a3e12022-05-26 12:10:37 +010010200 " With text "foo^Lbar" and cursor on the "^L":
10201
10202 virtcol(".") " returns 5
10203 virtcol(".", 1) " returns [4, 5]
10204 virtcol("$") " returns 9
10205
10206 " With text " there", with 't at 'h':
10207
10208 virtcol("'t") " returns 6
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010209< The first column is 1. 0 is returned for an error.
10210 A more advanced example that echoes the maximum length of
10211 all lines: >
10212 echo max(map(range(1, line('$')), "virtcol([v:val, '$'])"))
10213
10214< Can also be used as a |method|: >
10215 GetPos()->virtcol()
10216
Bram Moolenaar5a6ec102022-05-27 21:58:00 +010010217virtcol2col({winid}, {lnum}, {col}) *virtcol2col()*
10218 The result is a Number, which is the byte index of the
10219 character in window {winid} at buffer line {lnum} and virtual
10220 column {col}.
10221
10222 If {col} is greater than the last virtual column in line
10223 {lnum}, then the byte index of the character at the last
10224 virtual column is returned.
10225
10226 The {winid} argument can be the window number or the
10227 |window-ID|. If this is zero, then the current window is used.
10228
10229 Returns -1 if the window {winid} doesn't exist or the buffer
10230 line {lnum} or virtual column {col} is invalid.
10231
10232 See also |screenpos()|, |virtcol()| and |col()|.
10233
10234 Can also be used as a |method|: >
10235 GetWinid()->virtcol2col(lnum, col)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010236
10237visualmode([{expr}]) *visualmode()*
10238 The result is a String, which describes the last Visual mode
10239 used in the current buffer. Initially it returns an empty
10240 string, but once Visual mode has been used, it returns "v",
10241 "V", or "<CTRL-V>" (a single CTRL-V character) for
10242 character-wise, line-wise, or block-wise Visual mode
10243 respectively.
10244 Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +000010245 :exe "normal " .. visualmode()
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010246< This enters the same Visual mode as before. It is also useful
10247 in scripts if you wish to act differently depending on the
10248 Visual mode that was used.
10249 If Visual mode is active, use |mode()| to get the Visual mode
10250 (e.g., in a |:vmap|).
10251 If {expr} is supplied and it evaluates to a non-zero Number or
10252 a non-empty String, then the Visual mode will be cleared and
10253 the old value is returned. See |non-zero-arg|.
10254
10255wildmenumode() *wildmenumode()*
10256 Returns |TRUE| when the wildmenu is active and |FALSE|
10257 otherwise. See 'wildmenu' and 'wildmode'.
10258 This can be used in mappings to handle the 'wildcharm' option
10259 gracefully. (Makes only sense with |mapmode-c| mappings).
10260
10261 For example to make <c-j> work like <down> in wildmode, use: >
10262 :cnoremap <expr> <C-j> wildmenumode() ? "\<Down>\<Tab>" : "\<c-j>"
10263<
10264 (Note, this needs the 'wildcharm' option set appropriately).
10265
10266win_execute({id}, {command} [, {silent}]) *win_execute()*
10267 Like `execute()` but in the context of window {id}.
10268 The window will temporarily be made the current window,
10269 without triggering autocommands or changing directory. When
10270 executing {command} autocommands will be triggered, this may
Bram Moolenaarb7398fe2023-05-14 18:50:25 +010010271 have unexpected side effects. Use `:noautocmd` if needed.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010272 Example: >
10273 call win_execute(winid, 'set syntax=python')
10274< Doing the same with `setwinvar()` would not trigger
10275 autocommands and not actually show syntax highlighting.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010276 *E994*
10277 Not all commands are allowed in popup windows.
10278 When window {id} does not exist then no error is given and
10279 an empty string is returned.
10280
10281 Can also be used as a |method|, the base is passed as the
10282 second argument: >
10283 GetCommand()->win_execute(winid)
10284
10285win_findbuf({bufnr}) *win_findbuf()*
10286 Returns a |List| with |window-ID|s for windows that contain
10287 buffer {bufnr}. When there is none the list is empty.
10288
10289 Can also be used as a |method|: >
10290 GetBufnr()->win_findbuf()
10291
10292win_getid([{win} [, {tab}]]) *win_getid()*
10293 Get the |window-ID| for the specified window.
10294 When {win} is missing use the current window.
10295 With {win} this is the window number. The top window has
10296 number 1.
10297 Without {tab} use the current tab, otherwise the tab with
10298 number {tab}. The first tab has number one.
10299 Return zero if the window cannot be found.
10300
10301 Can also be used as a |method|: >
10302 GetWinnr()->win_getid()
10303
10304
10305win_gettype([{nr}]) *win_gettype()*
10306 Return the type of the window:
10307 "autocmd" autocommand window. Temporary window
10308 used to execute autocommands.
10309 "command" command-line window |cmdwin|
10310 (empty) normal window
10311 "loclist" |location-list-window|
10312 "popup" popup window |popup|
10313 "preview" preview window |preview-window|
10314 "quickfix" |quickfix-window|
10315 "unknown" window {nr} not found
10316
10317 When {nr} is omitted return the type of the current window.
10318 When {nr} is given return the type of this window by number or
10319 |window-ID|.
10320
10321 Also see the 'buftype' option. When running a terminal in a
10322 popup window then 'buftype' is "terminal" and win_gettype()
10323 returns "popup".
10324
10325 Can also be used as a |method|: >
10326 GetWinid()->win_gettype()
10327<
10328win_gotoid({expr}) *win_gotoid()*
10329 Go to window with ID {expr}. This may also change the current
10330 tabpage.
10331 Return TRUE if successful, FALSE if the window cannot be found.
10332
10333 Can also be used as a |method|: >
10334 GetWinid()->win_gotoid()
10335
10336win_id2tabwin({expr}) *win_id2tabwin()*
10337 Return a list with the tab number and window number of window
10338 with ID {expr}: [tabnr, winnr].
10339 Return [0, 0] if the window cannot be found.
10340
10341 Can also be used as a |method|: >
10342 GetWinid()->win_id2tabwin()
10343
10344win_id2win({expr}) *win_id2win()*
10345 Return the window number of window with ID {expr}.
10346 Return 0 if the window cannot be found in the current tabpage.
10347
10348 Can also be used as a |method|: >
10349 GetWinid()->win_id2win()
10350
Daniel Steinbergee630312022-01-10 13:36:34 +000010351win_move_separator({nr}, {offset}) *win_move_separator()*
10352 Move window {nr}'s vertical separator (i.e., the right border)
10353 by {offset} columns, as if being dragged by the mouse. {nr}
10354 can be a window number or |window-ID|. A positive {offset}
10355 moves right and a negative {offset} moves left. Moving a
10356 window's vertical separator will change the width of the
10357 window and the width of other windows adjacent to the vertical
10358 separator. The magnitude of movement may be smaller than
10359 specified (e.g., as a consequence of maintaining
10360 'winminwidth'). Returns TRUE if the window can be found and
10361 FALSE otherwise.
Bram Moolenaard592deb2022-06-17 15:42:40 +010010362 This will fail for the rightmost window and a full-width
10363 window, since it has no separator on the right.
Bram Moolenaar76db9e02022-11-09 21:21:04 +000010364 Only works for the current tab page. *E1308*
Daniel Steinbergee630312022-01-10 13:36:34 +000010365
10366 Can also be used as a |method|: >
10367 GetWinnr()->win_move_separator(offset)
10368
10369win_move_statusline({nr}, {offset}) *win_move_statusline()*
10370 Move window {nr}'s status line (i.e., the bottom border) by
10371 {offset} rows, as if being dragged by the mouse. {nr} can be a
10372 window number or |window-ID|. A positive {offset} moves down
10373 and a negative {offset} moves up. Moving a window's status
10374 line will change the height of the window and the height of
10375 other windows adjacent to the status line. The magnitude of
10376 movement may be smaller than specified (e.g., as a consequence
10377 of maintaining 'winminheight'). Returns TRUE if the window can
10378 be found and FALSE otherwise.
Bram Moolenaar76db9e02022-11-09 21:21:04 +000010379 Only works for the current tab page.
Daniel Steinbergee630312022-01-10 13:36:34 +000010380
10381 Can also be used as a |method|: >
10382 GetWinnr()->win_move_statusline(offset)
10383
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010384win_screenpos({nr}) *win_screenpos()*
10385 Return the screen position of window {nr} as a list with two
10386 numbers: [row, col]. The first window always has position
10387 [1, 1], unless there is a tabline, then it is [2, 1].
10388 {nr} can be the window number or the |window-ID|. Use zero
10389 for the current window.
10390 Returns [0, 0] if the window cannot be found in the current
10391 tabpage.
10392
10393 Can also be used as a |method|: >
10394 GetWinid()->win_screenpos()
10395<
10396win_splitmove({nr}, {target} [, {options}]) *win_splitmove()*
10397 Move the window {nr} to a new split of the window {target}.
10398 This is similar to moving to {target}, creating a new window
10399 using |:split| but having the same contents as window {nr}, and
10400 then closing {nr}.
10401
10402 Both {nr} and {target} can be window numbers or |window-ID|s.
10403 Both must be in the current tab page.
10404
10405 Returns zero for success, non-zero for failure.
10406
10407 {options} is a |Dictionary| with the following optional entries:
10408 "vertical" When TRUE, the split is created vertically,
10409 like with |:vsplit|.
10410 "rightbelow" When TRUE, the split is made below or to the
10411 right (if vertical). When FALSE, it is done
10412 above or to the left (if vertical). When not
10413 present, the values of 'splitbelow' and
10414 'splitright' are used.
10415
10416 Can also be used as a |method|: >
10417 GetWinid()->win_splitmove(target)
10418<
10419
10420 *winbufnr()*
10421winbufnr({nr}) The result is a Number, which is the number of the buffer
10422 associated with window {nr}. {nr} can be the window number or
10423 the |window-ID|.
10424 When {nr} is zero, the number of the buffer in the current
10425 window is returned.
10426 When window {nr} doesn't exist, -1 is returned.
10427 Example: >
10428 :echo "The file in the current window is " . bufname(winbufnr(0))
10429<
10430 Can also be used as a |method|: >
10431 FindWindow()->winbufnr()->bufname()
10432<
10433 *wincol()*
10434wincol() The result is a Number, which is the virtual column of the
10435 cursor in the window. This is counting screen cells from the
10436 left side of the window. The leftmost column is one.
10437
10438 *windowsversion()*
10439windowsversion()
10440 The result is a String. For MS-Windows it indicates the OS
10441 version. E.g, Windows 10 is "10.0", Windows 8 is "6.2",
10442 Windows XP is "5.1". For non-MS-Windows systems the result is
10443 an empty string.
10444
10445winheight({nr}) *winheight()*
10446 The result is a Number, which is the height of window {nr}.
10447 {nr} can be the window number or the |window-ID|.
10448 When {nr} is zero, the height of the current window is
10449 returned. When window {nr} doesn't exist, -1 is returned.
10450 An existing window always has a height of zero or more.
10451 This excludes any window toolbar line.
10452 Examples: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +000010453 :echo "The current window has " .. winheight(0) .. " lines."
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010454
10455< Can also be used as a |method|: >
10456 GetWinid()->winheight()
10457<
10458winlayout([{tabnr}]) *winlayout()*
10459 The result is a nested List containing the layout of windows
10460 in a tabpage.
10461
10462 Without {tabnr} use the current tabpage, otherwise the tabpage
10463 with number {tabnr}. If the tabpage {tabnr} is not found,
10464 returns an empty list.
10465
10466 For a leaf window, it returns:
10467 ['leaf', {winid}]
10468 For horizontally split windows, which form a column, it
10469 returns:
10470 ['col', [{nested list of windows}]]
10471 For vertically split windows, which form a row, it returns:
10472 ['row', [{nested list of windows}]]
10473
10474 Example: >
10475 " Only one window in the tab page
10476 :echo winlayout()
10477 ['leaf', 1000]
10478 " Two horizontally split windows
10479 :echo winlayout()
10480 ['col', [['leaf', 1000], ['leaf', 1001]]]
10481 " The second tab page, with three horizontally split
10482 " windows, with two vertically split windows in the
10483 " middle window
10484 :echo winlayout(2)
10485 ['col', [['leaf', 1002], ['row', [['leaf', 1003],
10486 ['leaf', 1001]]], ['leaf', 1000]]]
10487<
10488 Can also be used as a |method|: >
10489 GetTabnr()->winlayout()
10490<
10491 *winline()*
10492winline() The result is a Number, which is the screen line of the cursor
10493 in the window. This is counting screen lines from the top of
10494 the window. The first line is one.
10495 If the cursor was moved the view on the file will be updated
10496 first, this may cause a scroll.
10497
10498 *winnr()*
10499winnr([{arg}]) The result is a Number, which is the number of the current
10500 window. The top window has number 1.
10501 Returns zero for a popup window.
10502
10503 The optional argument {arg} supports the following values:
10504 $ the number of the last window (the window
10505 count).
10506 # the number of the last accessed window (where
10507 |CTRL-W_p| goes to). If there is no previous
10508 window or it is in another tab page 0 is
10509 returned.
10510 {N}j the number of the Nth window below the
10511 current window (where |CTRL-W_j| goes to).
10512 {N}k the number of the Nth window above the current
10513 window (where |CTRL-W_k| goes to).
10514 {N}h the number of the Nth window left of the
10515 current window (where |CTRL-W_h| goes to).
10516 {N}l the number of the Nth window right of the
10517 current window (where |CTRL-W_l| goes to).
10518 The number can be used with |CTRL-W_w| and ":wincmd w"
10519 |:wincmd|.
Bram Moolenaar016188f2022-06-06 20:52:59 +010010520 When {arg} is invalid an error is given and zero is returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010521 Also see |tabpagewinnr()| and |win_getid()|.
10522 Examples: >
10523 let window_count = winnr('$')
10524 let prev_window = winnr('#')
10525 let wnum = winnr('3k')
10526
10527< Can also be used as a |method|: >
10528 GetWinval()->winnr()
10529<
10530 *winrestcmd()*
10531winrestcmd() Returns a sequence of |:resize| commands that should restore
10532 the current window sizes. Only works properly when no windows
10533 are opened or closed and the current window and tab page is
10534 unchanged.
10535 Example: >
10536 :let cmd = winrestcmd()
10537 :call MessWithWindowSizes()
10538 :exe cmd
10539<
10540 *winrestview()*
10541winrestview({dict})
10542 Uses the |Dictionary| returned by |winsaveview()| to restore
10543 the view of the current window.
10544 Note: The {dict} does not have to contain all values, that are
10545 returned by |winsaveview()|. If values are missing, those
10546 settings won't be restored. So you can use: >
10547 :call winrestview({'curswant': 4})
10548<
10549 This will only set the curswant value (the column the cursor
10550 wants to move on vertical movements) of the cursor to column 5
10551 (yes, that is 5), while all other settings will remain the
10552 same. This is useful, if you set the cursor position manually.
10553
10554 If you have changed the values the result is unpredictable.
10555 If the window size changed the result won't be the same.
10556
10557 Can also be used as a |method|: >
10558 GetView()->winrestview()
10559<
10560 *winsaveview()*
10561winsaveview() Returns a |Dictionary| that contains information to restore
10562 the view of the current window. Use |winrestview()| to
10563 restore the view.
10564 This is useful if you have a mapping that jumps around in the
10565 buffer and you want to go back to the original view.
10566 This does not save fold information. Use the 'foldenable'
10567 option to temporarily switch off folding, so that folds are
10568 not opened when moving around. This may have side effects.
10569 The return value includes:
10570 lnum cursor line number
10571 col cursor column (Note: the first column
naohiro ono56200ee2022-01-01 14:59:44 +000010572 zero, as opposed to what |getcurpos()|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010573 returns)
10574 coladd cursor column offset for 'virtualedit'
naohiro ono56200ee2022-01-01 14:59:44 +000010575 curswant column for vertical movement (Note:
10576 the first column is zero, as opposed
10577 to what |getcurpos()| returns). After
10578 |$| command it will be a very large
10579 number equal to |v:maxcol|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010580 topline first line in the window
10581 topfill filler lines, only in diff mode
10582 leftcol first column displayed; only used when
10583 'wrap' is off
10584 skipcol columns skipped
10585 Note that no option values are saved.
10586
10587
10588winwidth({nr}) *winwidth()*
10589 The result is a Number, which is the width of window {nr}.
10590 {nr} can be the window number or the |window-ID|.
10591 When {nr} is zero, the width of the current window is
10592 returned. When window {nr} doesn't exist, -1 is returned.
10593 An existing window always has a width of zero or more.
10594 Examples: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +000010595 :echo "The current window has " .. winwidth(0) .. " columns."
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010596 :if winwidth(0) <= 50
10597 : 50 wincmd |
10598 :endif
10599< For getting the terminal or screen size, see the 'columns'
10600 option.
10601
10602 Can also be used as a |method|: >
10603 GetWinid()->winwidth()
10604
10605
10606wordcount() *wordcount()*
10607 The result is a dictionary of byte/chars/word statistics for
10608 the current buffer. This is the same info as provided by
10609 |g_CTRL-G|
10610 The return value includes:
10611 bytes Number of bytes in the buffer
10612 chars Number of chars in the buffer
10613 words Number of words in the buffer
10614 cursor_bytes Number of bytes before cursor position
10615 (not in Visual mode)
10616 cursor_chars Number of chars before cursor position
10617 (not in Visual mode)
10618 cursor_words Number of words before cursor position
10619 (not in Visual mode)
10620 visual_bytes Number of bytes visually selected
10621 (only in Visual mode)
10622 visual_chars Number of chars visually selected
10623 (only in Visual mode)
10624 visual_words Number of words visually selected
10625 (only in Visual mode)
10626
10627
10628 *writefile()*
10629writefile({object}, {fname} [, {flags}])
10630 When {object} is a |List| write it to file {fname}. Each list
10631 item is separated with a NL. Each list item must be a String
10632 or Number.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010633 All NL characters are replaced with a NUL character.
10634 Inserting CR characters needs to be done before passing {list}
10635 to writefile().
Bram Moolenaar806a2732022-09-04 15:40:36 +010010636
10637 When {object} is a |Blob| write the bytes to file {fname}
10638 unmodified, also when binary mode is not specified.
10639
10640 {flags} must be a String. These characters are recognized:
10641
10642 'b' Binary mode is used: There will not be a NL after the
10643 last list item. An empty item at the end does cause the
10644 last line in the file to end in a NL.
10645
10646 'a' Append mode is used, lines are appended to the file: >
10647 :call writefile(["foo"], "event.log", "a")
10648 :call writefile(["bar"], "event.log", "a")
10649<
10650 'D' Delete the file when the current function ends. This
10651 works like: >
Bram Moolenaar938ae282023-02-20 20:44:55 +000010652 :defer delete({fname})
Bram Moolenaar806a2732022-09-04 15:40:36 +010010653< Fails when not in a function. Also see |:defer|.
10654
10655 's' fsync() is called after writing the file. This flushes
10656 the file to disk, if possible. This takes more time but
10657 avoids losing the file if the system crashes.
10658
10659 'S' fsync() is not called, even when 'fsync' is set.
10660
10661 When {flags} does not contain "S" or "s" then fsync() is
10662 called if the 'fsync' option is set.
10663
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010664 An existing file is overwritten, if possible.
Bram Moolenaar806a2732022-09-04 15:40:36 +010010665
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010666 When the write fails -1 is returned, otherwise 0. There is an
10667 error message if the file can't be created or when writing
10668 fails.
Bram Moolenaar806a2732022-09-04 15:40:36 +010010669
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010670 Also see |readfile()|.
10671 To copy a file byte for byte: >
10672 :let fl = readfile("foo", "b")
10673 :call writefile(fl, "foocopy", "b")
10674
10675< Can also be used as a |method|: >
10676 GetText()->writefile("thefile")
10677
10678
10679xor({expr}, {expr}) *xor()*
10680 Bitwise XOR on the two arguments. The arguments are converted
10681 to a number. A List, Dict or Float argument causes an error.
Bram Moolenaar5a6ec102022-05-27 21:58:00 +010010682 Also see `and()` and `or()`.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010683 Example: >
10684 :let bits = xor(bits, 0x80)
10685<
10686 Can also be used as a |method|: >
10687 :let bits = bits->xor(0x80)
10688<
10689
10690==============================================================================
106913. Feature list *feature-list*
10692
10693There are three types of features:
106941. Features that are only supported when they have been enabled when Vim
10695 was compiled |+feature-list|. Example: >
10696 :if has("cindent")
10697< *gui_running*
106982. Features that are only supported when certain conditions have been met.
10699 Example: >
10700 :if has("gui_running")
10701< *has-patch*
107023. Beyond a certain version or at a certain version and including a specific
10703 patch. The "patch-7.4.248" feature means that the Vim version is 7.5 or
10704 later, or it is version 7.4 and patch 248 was included. Example: >
10705 :if has("patch-7.4.248")
10706< Note that it's possible for patch 248 to be omitted even though 249 is
10707 included. Only happens when cherry-picking patches.
10708 Note that this form only works for patch 7.4.237 and later, before that
10709 you need to check for the patch and the v:version. Example (checking
10710 version 6.2.148 or later): >
10711 :if v:version > 602 || (v:version == 602 && has("patch148"))
10712
10713Hint: To find out if Vim supports backslashes in a file name (MS-Windows),
10714use: `if exists('+shellslash')`
10715
10716
10717acl Compiled with |ACL| support.
Bram Moolenaar2ee347f2022-08-26 17:53:44 +010010718all_builtin_terms Compiled with all builtin terminals enabled. (always
10719 true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010720amiga Amiga version of Vim.
10721arabic Compiled with Arabic support |Arabic|.
10722arp Compiled with ARP support (Amiga).
10723autocmd Compiled with autocommand support. (always true)
10724autochdir Compiled with support for 'autochdir'
10725autoservername Automatically enable |clientserver|
10726balloon_eval Compiled with |balloon-eval| support.
10727balloon_multiline GUI supports multiline balloons.
10728beos BeOS version of Vim.
10729browse Compiled with |:browse| support, and browse() will
10730 work.
10731browsefilter Compiled with support for |browsefilter|.
10732bsd Compiled on an OS in the BSD family (excluding macOS).
Bram Moolenaar2ee347f2022-08-26 17:53:44 +010010733builtin_terms Compiled with some builtin terminals. (always true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010734byte_offset Compiled with support for 'o' in 'statusline'
10735channel Compiled with support for |channel| and |job|
Bram Moolenaare1dc76f2022-06-25 18:01:32 +010010736cindent Compiled with 'cindent' support. (always true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010737clientserver Compiled with remote invocation support |clientserver|.
10738clipboard Compiled with 'clipboard' support.
10739clipboard_working Compiled with 'clipboard' support and it can be used.
10740cmdline_compl Compiled with |cmdline-completion| support.
10741cmdline_hist Compiled with |cmdline-history| support.
10742cmdline_info Compiled with 'showcmd' and 'ruler' support.
10743comments Compiled with |'comments'| support.
10744compatible Compiled to be very Vi compatible.
10745conpty Platform where |ConPTY| can be used.
10746cryptv Compiled with encryption support |encryption|.
10747cscope Compiled with |cscope| support.
10748cursorbind Compiled with |'cursorbind'| (always true)
10749debug Compiled with "DEBUG" defined.
10750dialog_con Compiled with console dialog support.
10751dialog_gui Compiled with GUI dialog support.
10752diff Compiled with |vimdiff| and 'diff' support.
10753digraphs Compiled with support for digraphs.
10754directx Compiled with support for DirectX and 'renderoptions'.
10755dnd Compiled with support for the "~ register |quote_~|.
10756drop_file Compiled with |drop_file| support.
10757ebcdic Compiled on a machine with ebcdic character set.
10758emacs_tags Compiled with support for Emacs tags.
10759eval Compiled with expression evaluation support. Always
10760 true, of course!
10761ex_extra |+ex_extra| (always true)
10762extra_search Compiled with support for |'incsearch'| and
10763 |'hlsearch'|
10764farsi Support for Farsi was removed |farsi|.
Bram Moolenaarf80f40a2022-08-25 16:02:23 +010010765file_in_path Compiled with support for |gf| and |<cfile>| (always
10766 true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010767filterpipe When 'shelltemp' is off pipes are used for shell
10768 read/write/filter commands
10769find_in_path Compiled with support for include file searches
10770 |+find_in_path|.
10771float Compiled with support for |Float|.
10772fname_case Case in file names matters (for Amiga and MS-Windows
10773 this is not present).
10774folding Compiled with |folding| support.
10775footer Compiled with GUI footer support. |gui-footer|
10776fork Compiled to use fork()/exec() instead of system().
10777gettext Compiled with message translation |multi-lang|
10778gui Compiled with GUI enabled.
Bram Moolenaarcbaff5e2022-04-08 17:45:08 +010010779gui_athena Compiled with Athena GUI (always false).
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010780gui_gnome Compiled with Gnome support (gui_gtk is also defined).
10781gui_gtk Compiled with GTK+ GUI (any version).
10782gui_gtk2 Compiled with GTK+ 2 GUI (gui_gtk is also defined).
10783gui_gtk3 Compiled with GTK+ 3 GUI (gui_gtk is also defined).
10784gui_haiku Compiled with Haiku GUI.
10785gui_mac Compiled with Macintosh GUI.
10786gui_motif Compiled with Motif GUI.
10787gui_photon Compiled with Photon GUI.
10788gui_running Vim is running in the GUI, or it will start soon.
10789gui_win32 Compiled with MS-Windows Win32 GUI.
10790gui_win32s idem, and Win32s system being used (Windows 3.1)
10791haiku Haiku version of Vim.
10792hangul_input Compiled with Hangul input support. |hangul|
10793hpux HP-UX version of Vim.
10794iconv Can use iconv() for conversion.
10795insert_expand Compiled with support for CTRL-X expansion commands in
10796 Insert mode. (always true)
10797job Compiled with support for |channel| and |job|
10798ipv6 Compiled with support for IPv6 networking in |channel|.
Bram Moolenaare1dc76f2022-06-25 18:01:32 +010010799jumplist Compiled with |jumplist| support. (always true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010800keymap Compiled with 'keymap' support.
10801lambda Compiled with |lambda| support.
10802langmap Compiled with 'langmap' support.
10803libcall Compiled with |libcall()| support.
10804linebreak Compiled with 'linebreak', 'breakat', 'showbreak' and
10805 'breakindent' support.
10806linux Linux version of Vim.
10807lispindent Compiled with support for lisp indenting.
Bram Moolenaare1dc76f2022-06-25 18:01:32 +010010808 (always true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010809listcmds Compiled with commands for the buffer list |:files|
10810 and the argument list |arglist|.
10811localmap Compiled with local mappings and abbr. |:map-local|
10812lua Compiled with Lua interface |Lua|.
10813mac Any Macintosh version of Vim cf. osx
10814macunix Synonym for osxdarwin
10815menu Compiled with support for |:menu|.
10816mksession Compiled with support for |:mksession|.
10817modify_fname Compiled with file name modifiers. |filename-modifiers|
10818 (always true)
10819mouse Compiled with support for mouse.
10820mouse_dec Compiled with support for Dec terminal mouse.
10821mouse_gpm Compiled with support for gpm (Linux console mouse)
10822mouse_gpm_enabled GPM mouse is working
10823mouse_netterm Compiled with support for netterm mouse.
10824mouse_pterm Compiled with support for qnx pterm mouse.
10825mouse_sysmouse Compiled with support for sysmouse (*BSD console mouse)
10826mouse_sgr Compiled with support for sgr mouse.
10827mouse_urxvt Compiled with support for urxvt mouse.
10828mouse_xterm Compiled with support for xterm mouse.
10829mouseshape Compiled with support for 'mouseshape'.
10830multi_byte Compiled with support for 'encoding' (always true)
10831multi_byte_encoding 'encoding' is set to a multibyte encoding.
10832multi_byte_ime Compiled with support for IME input method.
10833multi_lang Compiled with support for multiple languages.
10834mzscheme Compiled with MzScheme interface |mzscheme|.
10835nanotime Compiled with sub-second time stamp checks.
10836netbeans_enabled Compiled with support for |netbeans| and connected.
10837netbeans_intg Compiled with support for |netbeans|.
Bram Moolenaare1dc76f2022-06-25 18:01:32 +010010838num64 Compiled with 64-bit |Number| support. (always true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010839ole Compiled with OLE automation support for Win32.
10840osx Compiled for macOS cf. mac
10841osxdarwin Compiled for macOS, with |mac-darwin-feature|
10842packages Compiled with |packages| support.
10843path_extra Compiled with up/downwards search in 'path' and 'tags'
10844perl Compiled with Perl interface.
10845persistent_undo Compiled with support for persistent undo history.
10846postscript Compiled with PostScript file printing.
10847printer Compiled with |:hardcopy| support.
10848profile Compiled with |:profile| support.
Bram Moolenaar71badf92023-04-22 22:40:14 +010010849prof_nsec Profile results are in nanoseconds.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010850python Python 2.x interface available. |has-python|
10851python_compiled Compiled with Python 2.x interface. |has-python|
10852python_dynamic Python 2.x interface is dynamically loaded. |has-python|
10853python3 Python 3.x interface available. |has-python|
10854python3_compiled Compiled with Python 3.x interface. |has-python|
10855python3_dynamic Python 3.x interface is dynamically loaded. |has-python|
10856pythonx Python 2.x and/or 3.x interface available. |python_x|
10857qnx QNX version of Vim.
10858quickfix Compiled with |quickfix| support.
10859reltime Compiled with |reltime()| support.
10860rightleft Compiled with 'rightleft' support.
10861ruby Compiled with Ruby interface |ruby|.
10862scrollbind Compiled with 'scrollbind' support. (always true)
10863showcmd Compiled with 'showcmd' support.
10864signs Compiled with |:sign| support.
Bram Moolenaare1dc76f2022-06-25 18:01:32 +010010865smartindent Compiled with 'smartindent' support. (always true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010866sodium Compiled with libsodium for better crypt support
10867sound Compiled with sound support, e.g. `sound_playevent()`
10868spell Compiled with spell checking support |spell|.
10869startuptime Compiled with |--startuptime| support.
10870statusline Compiled with support for 'statusline', 'rulerformat'
10871 and special formats of 'titlestring' and 'iconstring'.
10872sun SunOS version of Vim.
10873sun_workshop Support for Sun |workshop| has been removed.
10874syntax Compiled with syntax highlighting support |syntax|.
10875syntax_items There are active syntax highlighting items for the
10876 current buffer.
10877system Compiled to use system() instead of fork()/exec().
10878tag_binary Compiled with binary searching in tags files
Bram Moolenaare1dc76f2022-06-25 18:01:32 +010010879 |tag-binary-search|. (always true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010880tag_old_static Support for old static tags was removed, see
10881 |tag-old-static|.
10882tcl Compiled with Tcl interface.
10883termguicolors Compiled with true color in terminal support.
10884terminal Compiled with |terminal| support.
10885terminfo Compiled with terminfo instead of termcap.
10886termresponse Compiled with support for |t_RV| and |v:termresponse|.
10887textobjects Compiled with support for |text-objects|.
10888textprop Compiled with support for |text-properties|.
10889tgetent Compiled with tgetent support, able to use a termcap
10890 or terminfo file.
10891timers Compiled with |timer_start()| support.
10892title Compiled with window title support |'title'|.
Bram Moolenaare1dc76f2022-06-25 18:01:32 +010010893 (always true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010894toolbar Compiled with support for |gui-toolbar|.
10895ttyin input is a terminal (tty)
10896ttyout output is a terminal (tty)
10897unix Unix version of Vim. *+unix*
10898unnamedplus Compiled with support for "unnamedplus" in 'clipboard'
10899user_commands User-defined commands. (always true)
10900vartabs Compiled with variable tabstop support |'vartabstop'|.
10901vcon Win32: Virtual console support is working, can use
10902 'termguicolors'. Also see |+vtp|.
10903vertsplit Compiled with vertically split windows |:vsplit|.
10904 (always true)
10905vim_starting True while initial source'ing takes place. |startup|
10906 *vim_starting*
Bram Moolenaara6feb162022-01-02 12:06:33 +000010907vim9script Compiled with |Vim9| script support
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010908viminfo Compiled with viminfo support.
10909vimscript-1 Compiled Vim script version 1 support
10910vimscript-2 Compiled Vim script version 2 support
10911vimscript-3 Compiled Vim script version 3 support
Bram Moolenaar8a3b8052022-06-26 12:21:15 +010010912vimscript-4 Compiled Vim script version 4 support
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010913virtualedit Compiled with 'virtualedit' option. (always true)
10914visual Compiled with Visual mode. (always true)
10915visualextra Compiled with extra Visual mode commands. (always
10916 true) |blockwise-operators|.
10917vms VMS version of Vim.
10918vreplace Compiled with |gR| and |gr| commands. (always true)
10919vtp Compiled for vcon support |+vtp| (check vcon to find
10920 out if it works in the current console).
10921wildignore Compiled with 'wildignore' option.
10922wildmenu Compiled with 'wildmenu' option.
10923win16 old version for MS-Windows 3.1 (always false)
10924win32 Win32 version of Vim (MS-Windows 95 and later, 32 or
10925 64 bits)
10926win32unix Win32 version of Vim, using Unix files (Cygwin)
10927win64 Win64 version of Vim (MS-Windows 64 bit).
10928win95 Win32 version for MS-Windows 95/98/ME (always false)
10929winaltkeys Compiled with 'winaltkeys' option.
10930windows Compiled with support for more than one window.
10931 (always true)
10932writebackup Compiled with 'writebackup' default on.
10933xfontset Compiled with X fontset support |xfontset|.
10934xim Compiled with X input method support |xim|.
10935xpm Compiled with pixmap support.
10936xpm_w32 Compiled with pixmap support for Win32. (Only for
10937 backward compatibility. Use "xpm" instead.)
10938xsmp Compiled with X session management support.
10939xsmp_interact Compiled with interactive X session management support.
10940xterm_clipboard Compiled with support for xterm clipboard.
10941xterm_save Compiled with support for saving and restoring the
10942 xterm screen.
10943x11 Compiled with X11 support.
10944
10945
10946==============================================================================
109474. Matching a pattern in a String *string-match*
10948
10949This is common between several functions. A regexp pattern as explained at
10950|pattern| is normally used to find a match in the buffer lines. When a
10951pattern is used to find a match in a String, almost everything works in the
10952same way. The difference is that a String is handled like it is one line.
10953When it contains a "\n" character, this is not seen as a line break for the
10954pattern. It can be matched with a "\n" in the pattern, or with ".". Example:
10955>
10956 :let a = "aaaa\nxxxx"
10957 :echo matchstr(a, "..\n..")
10958 aa
10959 xx
10960 :echo matchstr(a, "a.x")
10961 a
10962 x
10963
10964Don't forget that "^" will only match at the first character of the String and
10965"$" at the last character of the string. They don't match after or before a
10966"\n".
10967
10968 vim:tw=78:ts=8:noet:ft=help:norl: