blob: beb7ac71843b03bb852c3fdc1c902dff7dc867d1 [file] [log] [blame]
Bram Moolenaar71badf92023-04-22 22:40:14 +01001*builtin.txt* For Vim version 9.0. Last change: 2023 Apr 19
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
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001531 Returns -1 if the arguments are invalid or if {idx} is greater
1532 than the index of the last byte in {string}. An error is
1533 given if the first argument is not a string, the second
1534 argument is not a number or when the third argument is present
1535 and is not zero or one.
Christian Brabandt67672ef2023-04-24 21:09:54 +01001536
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001537 See |byteidx()| and |byteidxcomp()| for getting the byte index
Christian Brabandt67672ef2023-04-24 21:09:54 +01001538 from the character index and |utf16idx()| for getting the
1539 UTF-16 index from the character index.
1540 Refer to |string-offset-encoding| for more information.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001541 Examples: >
1542 echo charidx('áb́ć', 3) returns 1
1543 echo charidx('áb́ć', 6, 1) returns 4
1544 echo charidx('áb́ć', 16) returns -1
Christian Brabandt67672ef2023-04-24 21:09:54 +01001545 echo charidx('a😊😊', 4, 0, 1) returns 2
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001546<
1547 Can also be used as a |method|: >
1548 GetName()->charidx(idx)
1549
1550chdir({dir}) *chdir()*
1551 Change the current working directory to {dir}. The scope of
1552 the directory change depends on the directory of the current
1553 window:
1554 - If the current window has a window-local directory
1555 (|:lcd|), then changes the window local directory.
1556 - Otherwise, if the current tabpage has a local
1557 directory (|:tcd|) then changes the tabpage local
1558 directory.
1559 - Otherwise, changes the global directory.
1560 {dir} must be a String.
1561 If successful, returns the previous working directory. Pass
1562 this to another chdir() to restore the directory.
1563 On failure, returns an empty string.
1564
1565 Example: >
1566 let save_dir = chdir(newdir)
1567 if save_dir != ""
1568 " ... do some work
1569 call chdir(save_dir)
1570 endif
1571
1572< Can also be used as a |method|: >
1573 GetDir()->chdir()
1574<
1575cindent({lnum}) *cindent()*
1576 Get the amount of indent for line {lnum} according the C
1577 indenting rules, as with 'cindent'.
1578 The indent is counted in spaces, the value of 'tabstop' is
1579 relevant. {lnum} is used just like in |getline()|.
Bram Moolenaar8e145b82022-05-21 20:17:31 +01001580 When {lnum} is invalid -1 is returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001581 See |C-indenting|.
1582
1583 Can also be used as a |method|: >
1584 GetLnum()->cindent()
1585
1586clearmatches([{win}]) *clearmatches()*
1587 Clears all matches previously defined for the current window
1588 by |matchadd()| and the |:match| commands.
1589 If {win} is specified, use the window with this number or
1590 window ID instead of the current window.
1591
1592 Can also be used as a |method|: >
1593 GetWin()->clearmatches()
1594<
Yegappan Lakshmanan4c8d2f02022-11-12 16:07:47 +00001595col({expr} [, {winid}) *col()*
1596 The result is a Number, which is the byte index of the column
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001597 position given with {expr}. The accepted positions are:
1598 . the cursor position
1599 $ the end of the cursor line (the result is the
1600 number of bytes in the cursor line plus one)
1601 'x position of mark x (if the mark is not set, 0 is
1602 returned)
1603 v In Visual mode: the start of the Visual area (the
1604 cursor is the end). When not in Visual mode
1605 returns the cursor position. Differs from |'<| in
1606 that it's updated right away.
1607 Additionally {expr} can be [lnum, col]: a |List| with the line
1608 and column number. Most useful when the column is "$", to get
1609 the last column of a specific line. When "lnum" or "col" is
1610 out of range then col() returns zero.
Yegappan Lakshmanan4c8d2f02022-11-12 16:07:47 +00001611 With the optional {winid} argument the values are obtained for
1612 that window instead of the current window.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001613 To get the line number use |line()|. To get both use
1614 |getpos()|.
1615 For the screen column position use |virtcol()|. For the
1616 character position use |charcol()|.
1617 Note that only marks in the current file can be used.
1618 Examples: >
1619 col(".") column of cursor
1620 col("$") length of cursor line plus one
1621 col("'t") column of mark t
Bram Moolenaarc51cf032022-02-26 12:25:45 +00001622 col("'" .. markname) column of mark markname
Yegappan Lakshmanan4c8d2f02022-11-12 16:07:47 +00001623< The first column is 1. Returns 0 if {expr} is invalid or when
1624 the window with ID {winid} is not found.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001625 For an uppercase mark the column may actually be in another
1626 buffer.
1627 For the cursor position, when 'virtualedit' is active, the
1628 column is one higher if the cursor is after the end of the
Bram Moolenaar6ebe4f92022-10-28 20:47:54 +01001629 line. Also, when using a <Cmd> mapping the cursor isn't
1630 moved, this can be used to obtain the column in Insert mode: >
Bram Moolenaar76db9e02022-11-09 21:21:04 +00001631 :imap <F2> <Cmd>echowin col(".")<CR>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001632
1633< Can also be used as a |method|: >
1634 GetPos()->col()
1635<
1636
1637complete({startcol}, {matches}) *complete()* *E785*
1638 Set the matches for Insert mode completion.
1639 Can only be used in Insert mode. You need to use a mapping
1640 with CTRL-R = (see |i_CTRL-R|). It does not work after CTRL-O
1641 or with an expression mapping.
1642 {startcol} is the byte offset in the line where the completed
1643 text start. The text up to the cursor is the original text
1644 that will be replaced by the matches. Use col('.') for an
1645 empty string. "col('.') - 1" will replace one character by a
1646 match.
1647 {matches} must be a |List|. Each |List| item is one match.
1648 See |complete-items| for the kind of items that are possible.
1649 "longest" in 'completeopt' is ignored.
1650 Note that the after calling this function you need to avoid
1651 inserting anything that would cause completion to stop.
1652 The match can be selected with CTRL-N and CTRL-P as usual with
1653 Insert mode completion. The popup menu will appear if
1654 specified, see |ins-completion-menu|.
1655 Example: >
1656 inoremap <F5> <C-R>=ListMonths()<CR>
1657
1658 func! ListMonths()
1659 call complete(col('.'), ['January', 'February', 'March',
1660 \ 'April', 'May', 'June', 'July', 'August', 'September',
1661 \ 'October', 'November', 'December'])
1662 return ''
1663 endfunc
1664< This isn't very useful, but it shows how it works. Note that
1665 an empty string is returned to avoid a zero being inserted.
1666
1667 Can also be used as a |method|, the base is passed as the
1668 second argument: >
1669 GetMatches()->complete(col('.'))
1670
1671complete_add({expr}) *complete_add()*
1672 Add {expr} to the list of matches. Only to be used by the
1673 function specified with the 'completefunc' option.
1674 Returns 0 for failure (empty string or out of memory),
1675 1 when the match was added, 2 when the match was already in
1676 the list.
1677 See |complete-functions| for an explanation of {expr}. It is
1678 the same as one item in the list that 'omnifunc' would return.
1679
1680 Can also be used as a |method|: >
1681 GetMoreMatches()->complete_add()
1682
1683complete_check() *complete_check()*
1684 Check for a key typed while looking for completion matches.
1685 This is to be used when looking for matches takes some time.
1686 Returns |TRUE| when searching for matches is to be aborted,
1687 zero otherwise.
1688 Only to be used by the function specified with the
1689 'completefunc' option.
1690
1691
1692complete_info([{what}]) *complete_info()*
1693 Returns a |Dictionary| with information about Insert mode
1694 completion. See |ins-completion|.
1695 The items are:
1696 mode Current completion mode name string.
1697 See |complete_info_mode| for the values.
1698 pum_visible |TRUE| if popup menu is visible.
1699 See |pumvisible()|.
1700 items List of completion matches. Each item is a
1701 dictionary containing the entries "word",
1702 "abbr", "menu", "kind", "info" and "user_data".
1703 See |complete-items|.
1704 selected Selected item index. First index is zero.
1705 Index is -1 if no item is selected (showing
1706 typed text only, or the last completion after
1707 no item is selected when using the <Up> or
1708 <Down> keys)
Bram Moolenaar0daafaa2022-09-04 17:45:43 +01001709 inserted Inserted string. [NOT IMPLEMENTED YET]
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001710
1711 *complete_info_mode*
1712 mode values are:
1713 "" Not in completion mode
1714 "keyword" Keyword completion |i_CTRL-X_CTRL-N|
1715 "ctrl_x" Just pressed CTRL-X |i_CTRL-X|
1716 "scroll" Scrolling with |i_CTRL-X_CTRL-E| or
1717 |i_CTRL-X_CTRL-Y|
1718 "whole_line" Whole lines |i_CTRL-X_CTRL-L|
1719 "files" File names |i_CTRL-X_CTRL-F|
1720 "tags" Tags |i_CTRL-X_CTRL-]|
1721 "path_defines" Definition completion |i_CTRL-X_CTRL-D|
1722 "path_patterns" Include completion |i_CTRL-X_CTRL-I|
1723 "dictionary" Dictionary |i_CTRL-X_CTRL-K|
1724 "thesaurus" Thesaurus |i_CTRL-X_CTRL-T|
1725 "cmdline" Vim Command line |i_CTRL-X_CTRL-V|
1726 "function" User defined completion |i_CTRL-X_CTRL-U|
1727 "omni" Omni completion |i_CTRL-X_CTRL-O|
1728 "spell" Spelling suggestions |i_CTRL-X_s|
1729 "eval" |complete()| completion
1730 "unknown" Other internal modes
1731
1732 If the optional {what} list argument is supplied, then only
1733 the items listed in {what} are returned. Unsupported items in
1734 {what} are silently ignored.
1735
1736 To get the position and size of the popup menu, see
1737 |pum_getpos()|. It's also available in |v:event| during the
1738 |CompleteChanged| event.
1739
Bram Moolenaar016188f2022-06-06 20:52:59 +01001740 Returns an empty |Dictionary| on error.
1741
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001742 Examples: >
1743 " Get all items
1744 call complete_info()
1745 " Get only 'mode'
1746 call complete_info(['mode'])
1747 " Get only 'mode' and 'pum_visible'
1748 call complete_info(['mode', 'pum_visible'])
1749
1750< Can also be used as a |method|: >
1751 GetItems()->complete_info()
1752<
1753 *confirm()*
1754confirm({msg} [, {choices} [, {default} [, {type}]]])
1755 confirm() offers the user a dialog, from which a choice can be
1756 made. It returns the number of the choice. For the first
1757 choice this is 1.
1758 Note: confirm() is only supported when compiled with dialog
1759 support, see |+dialog_con| and |+dialog_gui|.
1760
1761 {msg} is displayed in a |dialog| with {choices} as the
1762 alternatives. When {choices} is missing or empty, "&OK" is
1763 used (and translated).
1764 {msg} is a String, use '\n' to include a newline. Only on
1765 some systems the string is wrapped when it doesn't fit.
1766
1767 {choices} is a String, with the individual choices separated
1768 by '\n', e.g. >
1769 confirm("Save changes?", "&Yes\n&No\n&Cancel")
1770< The letter after the '&' is the shortcut key for that choice.
1771 Thus you can type 'c' to select "Cancel". The shortcut does
1772 not need to be the first letter: >
1773 confirm("file has been modified", "&Save\nSave &All")
1774< For the console, the first letter of each choice is used as
1775 the default shortcut key. Case is ignored.
1776
1777 The optional {default} argument is the number of the choice
1778 that is made if the user hits <CR>. Use 1 to make the first
1779 choice the default one. Use 0 to not set a default. If
1780 {default} is omitted, 1 is used.
1781
1782 The optional {type} String argument gives the type of dialog.
1783 This is only used for the icon of the GTK, Mac, Motif and
1784 Win32 GUI. It can be one of these values: "Error",
1785 "Question", "Info", "Warning" or "Generic". Only the first
1786 character is relevant. When {type} is omitted, "Generic" is
1787 used.
1788
1789 If the user aborts the dialog by pressing <Esc>, CTRL-C,
1790 or another valid interrupt key, confirm() returns 0.
1791
1792 An example: >
Bram Moolenaar46eea442022-03-30 10:51:39 +01001793 let choice = confirm("What do you want?",
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01001794 \ "&Apples\n&Oranges\n&Bananas", 2)
Bram Moolenaar46eea442022-03-30 10:51:39 +01001795 if choice == 0
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01001796 echo "make up your mind!"
Bram Moolenaar46eea442022-03-30 10:51:39 +01001797 elseif choice == 3
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01001798 echo "tasteful"
Bram Moolenaar46eea442022-03-30 10:51:39 +01001799 else
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01001800 echo "I prefer bananas myself."
Bram Moolenaar46eea442022-03-30 10:51:39 +01001801 endif
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001802< In a GUI dialog, buttons are used. The layout of the buttons
1803 depends on the 'v' flag in 'guioptions'. If it is included,
1804 the buttons are always put vertically. Otherwise, confirm()
1805 tries to put the buttons in one horizontal line. If they
1806 don't fit, a vertical layout is used anyway. For some systems
1807 the horizontal layout is always used.
1808
1809 Can also be used as a |method|in: >
1810 BuildMessage()->confirm("&Yes\n&No")
1811<
1812 *copy()*
1813copy({expr}) Make a copy of {expr}. For Numbers and Strings this isn't
1814 different from using {expr} directly.
1815 When {expr} is a |List| a shallow copy is created. This means
1816 that the original |List| can be changed without changing the
1817 copy, and vice versa. But the items are identical, thus
1818 changing an item changes the contents of both |Lists|.
1819 A |Dictionary| is copied in a similar way as a |List|.
1820 Also see |deepcopy()|.
1821 Can also be used as a |method|: >
1822 mylist->copy()
1823
1824cos({expr}) *cos()*
1825 Return the cosine of {expr}, measured in radians, as a |Float|.
1826 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar016188f2022-06-06 20:52:59 +01001827 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001828 Examples: >
1829 :echo cos(100)
1830< 0.862319 >
1831 :echo cos(-4.01)
1832< -0.646043
1833
1834 Can also be used as a |method|: >
1835 Compute()->cos()
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001836
1837
1838cosh({expr}) *cosh()*
1839 Return the hyperbolic cosine of {expr} as a |Float| in the range
1840 [1, inf].
1841 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar016188f2022-06-06 20:52:59 +01001842 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001843 Examples: >
1844 :echo cosh(0.5)
1845< 1.127626 >
1846 :echo cosh(-0.5)
1847< -1.127626
1848
1849 Can also be used as a |method|: >
1850 Compute()->cosh()
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001851
1852
1853count({comp}, {expr} [, {ic} [, {start}]]) *count()*
1854 Return the number of times an item with value {expr} appears
1855 in |String|, |List| or |Dictionary| {comp}.
1856
1857 If {start} is given then start with the item with this index.
1858 {start} can only be used with a |List|.
1859
1860 When {ic} is given and it's |TRUE| then case is ignored.
1861
1862 When {comp} is a string then the number of not overlapping
1863 occurrences of {expr} is returned. Zero is returned when
1864 {expr} is an empty string.
1865
1866 Can also be used as a |method|: >
1867 mylist->count(val)
1868<
1869 *cscope_connection()*
1870cscope_connection([{num} , {dbpath} [, {prepend}]])
1871 Checks for the existence of a |cscope| connection. If no
1872 parameters are specified, then the function returns:
1873 0, if cscope was not available (not compiled in), or
1874 if there are no cscope connections;
1875 1, if there is at least one cscope connection.
1876
1877 If parameters are specified, then the value of {num}
1878 determines how existence of a cscope connection is checked:
1879
1880 {num} Description of existence check
1881 ----- ------------------------------
1882 0 Same as no parameters (e.g., "cscope_connection()").
1883 1 Ignore {prepend}, and use partial string matches for
1884 {dbpath}.
1885 2 Ignore {prepend}, and use exact string matches for
1886 {dbpath}.
1887 3 Use {prepend}, use partial string matches for both
1888 {dbpath} and {prepend}.
1889 4 Use {prepend}, use exact string matches for both
1890 {dbpath} and {prepend}.
1891
1892 Note: All string comparisons are case sensitive!
1893
1894 Examples. Suppose we had the following (from ":cs show"): >
1895
1896 # pid database name prepend path
1897 0 27664 cscope.out /usr/local
1898<
1899 Invocation Return Val ~
1900 ---------- ---------- >
1901 cscope_connection() 1
1902 cscope_connection(1, "out") 1
1903 cscope_connection(2, "out") 0
1904 cscope_connection(3, "out") 0
1905 cscope_connection(3, "out", "local") 1
1906 cscope_connection(4, "out") 0
1907 cscope_connection(4, "out", "local") 0
1908 cscope_connection(4, "cscope.out", "/usr/local") 1
1909<
1910cursor({lnum}, {col} [, {off}]) *cursor()*
1911cursor({list})
1912 Positions the cursor at the column (byte count) {col} in the
1913 line {lnum}. The first column is one.
1914
1915 When there is one argument {list} this is used as a |List|
1916 with two, three or four item:
1917 [{lnum}, {col}]
1918 [{lnum}, {col}, {off}]
1919 [{lnum}, {col}, {off}, {curswant}]
1920 This is like the return value of |getpos()| or |getcurpos()|,
1921 but without the first item.
1922
1923 To position the cursor using the character count, use
1924 |setcursorcharpos()|.
1925
1926 Does not change the jumplist.
Bram Moolenaar7c6cd442022-10-11 21:54:04 +01001927 {lnum} is used like with |getline()|, except that if {lnum} is
1928 zero, the cursor will stay in the current line.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001929 If {lnum} is greater than the number of lines in the buffer,
1930 the cursor will be positioned at the last line in the buffer.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001931 If {col} is greater than the number of bytes in the line,
1932 the cursor will be positioned at the last character in the
1933 line.
1934 If {col} is zero, the cursor will stay in the current column.
1935 If {curswant} is given it is used to set the preferred column
1936 for vertical movement. Otherwise {col} is used.
1937
1938 When 'virtualedit' is used {off} specifies the offset in
1939 screen columns from the start of the character. E.g., a
1940 position within a <Tab> or after the last character.
1941 Returns 0 when the position could be set, -1 otherwise.
1942
1943 Can also be used as a |method|: >
1944 GetCursorPos()->cursor()
1945
1946debugbreak({pid}) *debugbreak()*
1947 Specifically used to interrupt a program being debugged. It
1948 will cause process {pid} to get a SIGTRAP. Behavior for other
1949 processes is undefined. See |terminal-debugger|.
1950 {only available on MS-Windows}
1951
Bram Moolenaar016188f2022-06-06 20:52:59 +01001952 Returns |TRUE| if successfully interrupted the program.
1953 Otherwise returns |FALSE|.
1954
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001955 Can also be used as a |method|: >
1956 GetPid()->debugbreak()
1957
1958deepcopy({expr} [, {noref}]) *deepcopy()* *E698*
1959 Make a copy of {expr}. For Numbers and Strings this isn't
1960 different from using {expr} directly.
1961 When {expr} is a |List| a full copy is created. This means
1962 that the original |List| can be changed without changing the
1963 copy, and vice versa. When an item is a |List| or
1964 |Dictionary|, a copy for it is made, recursively. Thus
1965 changing an item in the copy does not change the contents of
1966 the original |List|.
1967 A |Dictionary| is copied in a similar way as a |List|.
1968
1969 When {noref} is omitted or zero a contained |List| or
1970 |Dictionary| is only copied once. All references point to
1971 this single copy. With {noref} set to 1 every occurrence of a
1972 |List| or |Dictionary| results in a new copy. This also means
1973 that a cyclic reference causes deepcopy() to fail.
1974 *E724*
1975 Nesting is possible up to 100 levels. When there is an item
1976 that refers back to a higher level making a deep copy with
1977 {noref} set to 1 will fail.
1978 Also see |copy()|.
1979
1980 Can also be used as a |method|: >
1981 GetObject()->deepcopy()
1982
1983delete({fname} [, {flags}]) *delete()*
1984 Without {flags} or with {flags} empty: Deletes the file by the
Bram Moolenaarcbaff5e2022-04-08 17:45:08 +01001985 name {fname}.
1986
1987 This also works when {fname} is a symbolic link. The symbolic
1988 link itself is deleted, not what it points to.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001989
1990 When {flags} is "d": Deletes the directory by the name
1991 {fname}. This fails when directory {fname} is not empty.
1992
1993 When {flags} is "rf": Deletes the directory by the name
1994 {fname} and everything in it, recursively. BE CAREFUL!
1995 Note: on MS-Windows it is not possible to delete a directory
1996 that is being used.
1997
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001998 The result is a Number, which is 0/false if the delete
1999 operation was successful and -1/true when the deletion failed
2000 or partly failed.
2001
2002 Use |remove()| to delete an item from a |List|.
2003 To delete a line from the buffer use |:delete| or
2004 |deletebufline()|.
2005
2006 Can also be used as a |method|: >
2007 GetName()->delete()
2008
2009deletebufline({buf}, {first} [, {last}]) *deletebufline()*
2010 Delete lines {first} to {last} (inclusive) from buffer {buf}.
2011 If {last} is omitted then delete line {first} only.
2012 On success 0 is returned, on failure 1 is returned.
2013
2014 This function works only for loaded buffers. First call
2015 |bufload()| if needed.
2016
2017 For the use of {buf}, see |bufname()| above.
2018
2019 {first} and {last} are used like with |getline()|. Note that
2020 when using |line()| this refers to the current buffer. Use "$"
2021 to refer to the last line in buffer {buf}.
2022
2023 Can also be used as a |method|: >
2024 GetBuffer()->deletebufline(1)
2025<
2026 *did_filetype()*
2027did_filetype() Returns |TRUE| when autocommands are being executed and the
2028 FileType event has been triggered at least once. Can be used
2029 to avoid triggering the FileType event again in the scripts
2030 that detect the file type. |FileType|
2031 Returns |FALSE| when `:setf FALLBACK` was used.
2032 When editing another file, the counter is reset, thus this
2033 really checks if the FileType event has been triggered for the
2034 current buffer. This allows an autocommand that starts
2035 editing another buffer to set 'filetype' and load a syntax
2036 file.
2037
2038diff_filler({lnum}) *diff_filler()*
2039 Returns the number of filler lines above line {lnum}.
2040 These are the lines that were inserted at this point in
2041 another diff'ed window. These filler lines are shown in the
2042 display but don't exist in the buffer.
2043 {lnum} is used like with |getline()|. Thus "." is the current
2044 line, "'m" mark m, etc.
2045 Returns 0 if the current window is not in diff mode.
2046
2047 Can also be used as a |method|: >
2048 GetLnum()->diff_filler()
2049
2050diff_hlID({lnum}, {col}) *diff_hlID()*
2051 Returns the highlight ID for diff mode at line {lnum} column
2052 {col} (byte index). When the current line does not have a
2053 diff change zero is returned.
2054 {lnum} is used like with |getline()|. Thus "." is the current
2055 line, "'m" mark m, etc.
2056 {col} is 1 for the leftmost column, {lnum} is 1 for the first
2057 line.
2058 The highlight ID can be used with |synIDattr()| to obtain
2059 syntax information about the highlighting.
2060
2061 Can also be used as a |method|: >
2062 GetLnum()->diff_hlID(col)
2063<
2064
2065digraph_get({chars}) *digraph_get()* *E1214*
2066 Return the digraph of {chars}. This should be a string with
2067 exactly two characters. If {chars} are not just two
2068 characters, or the digraph of {chars} does not exist, an error
2069 is given and an empty string is returned.
2070
2071 The character will be converted from Unicode to 'encoding'
2072 when needed. This does require the conversion to be
2073 available, it might fail.
2074
2075 Also see |digraph_getlist()|.
2076
2077 Examples: >
2078 " Get a built-in digraph
2079 :echo digraph_get('00') " Returns '∞'
2080
2081 " Get a user-defined digraph
2082 :call digraph_set('aa', 'あ')
2083 :echo digraph_get('aa') " Returns 'あ'
2084<
2085 Can also be used as a |method|: >
2086 GetChars()->digraph_get()
2087<
2088 This function works only when compiled with the |+digraphs|
2089 feature. If this feature is disabled, this function will
2090 display an error message.
2091
2092
2093digraph_getlist([{listall}]) *digraph_getlist()*
2094 Return a list of digraphs. If the {listall} argument is given
2095 and it is TRUE, return all digraphs, including the default
2096 digraphs. Otherwise, return only user-defined digraphs.
2097
2098 The characters will be converted from Unicode to 'encoding'
2099 when needed. This does require the conservation to be
2100 available, it might fail.
2101
2102 Also see |digraph_get()|.
2103
2104 Examples: >
2105 " Get user-defined digraphs
2106 :echo digraph_getlist()
2107
2108 " Get all the digraphs, including default digraphs
2109 :echo digraph_getlist(1)
2110<
2111 Can also be used as a |method|: >
2112 GetNumber()->digraph_getlist()
2113<
2114 This function works only when compiled with the |+digraphs|
2115 feature. If this feature is disabled, this function will
2116 display an error message.
2117
2118
Bram Moolenaara2baa732022-02-04 16:09:54 +00002119digraph_set({chars}, {digraph}) *digraph_set()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002120 Add digraph {chars} to the list. {chars} must be a string
2121 with two characters. {digraph} is a string with one UTF-8
Bram Moolenaara2baa732022-02-04 16:09:54 +00002122 encoded character. *E1215*
2123 Be careful, composing characters are NOT ignored. This
2124 function is similar to |:digraphs| command, but useful to add
2125 digraphs start with a white space.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002126
2127 The function result is v:true if |digraph| is registered. If
2128 this fails an error message is given and v:false is returned.
2129
2130 If you want to define multiple digraphs at once, you can use
2131 |digraph_setlist()|.
2132
2133 Example: >
2134 call digraph_set(' ', 'あ')
2135<
2136 Can be used as a |method|: >
2137 GetString()->digraph_set('あ')
2138<
2139 This function works only when compiled with the |+digraphs|
2140 feature. If this feature is disabled, this function will
2141 display an error message.
2142
2143
2144digraph_setlist({digraphlist}) *digraph_setlist()*
2145 Similar to |digraph_set()| but this function can add multiple
2146 digraphs at once. {digraphlist} is a list composed of lists,
2147 where each list contains two strings with {chars} and
Bram Moolenaara2baa732022-02-04 16:09:54 +00002148 {digraph} as in |digraph_set()|. *E1216*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002149 Example: >
2150 call digraph_setlist([['aa', 'あ'], ['ii', 'い']])
2151<
2152 It is similar to the following: >
2153 for [chars, digraph] in [['aa', 'あ'], ['ii', 'い']]
2154 call digraph_set(chars, digraph)
2155 endfor
2156< Except that the function returns after the first error,
2157 following digraphs will not be added.
2158
2159 Can be used as a |method|: >
2160 GetList()->digraph_setlist()
2161<
2162 This function works only when compiled with the |+digraphs|
2163 feature. If this feature is disabled, this function will
2164 display an error message.
2165
2166
2167echoraw({string}) *echoraw()*
2168 Output {string} as-is, including unprintable characters.
2169 This can be used to output a terminal code. For example, to
2170 disable modifyOtherKeys: >
2171 call echoraw(&t_TE)
2172< and to enable it again: >
2173 call echoraw(&t_TI)
2174< Use with care, you can mess up the terminal this way.
2175
2176
2177empty({expr}) *empty()*
2178 Return the Number 1 if {expr} is empty, zero otherwise.
2179 - A |List| or |Dictionary| is empty when it does not have any
2180 items.
2181 - A |String| is empty when its length is zero.
2182 - A |Number| and |Float| are empty when their value is zero.
2183 - |v:false|, |v:none| and |v:null| are empty, |v:true| is not.
2184 - A |Job| is empty when it failed to start.
2185 - A |Channel| is empty when it is closed.
2186 - A |Blob| is empty when its length is zero.
2187
2188 For a long |List| this is much faster than comparing the
2189 length with zero.
2190
2191 Can also be used as a |method|: >
2192 mylist->empty()
2193
2194environ() *environ()*
2195 Return all of environment variables as dictionary. You can
2196 check if an environment variable exists like this: >
2197 :echo has_key(environ(), 'HOME')
2198< Note that the variable name may be CamelCase; to ignore case
2199 use this: >
2200 :echo index(keys(environ()), 'HOME', 0, 1) != -1
2201
2202escape({string}, {chars}) *escape()*
2203 Escape the characters in {chars} that occur in {string} with a
2204 backslash. Example: >
2205 :echo escape('c:\program files\vim', ' \')
2206< results in: >
2207 c:\\program\ files\\vim
2208< Also see |shellescape()| and |fnameescape()|.
2209
2210 Can also be used as a |method|: >
2211 GetText()->escape(' \')
2212<
2213 *eval()*
2214eval({string}) Evaluate {string} and return the result. Especially useful to
2215 turn the result of |string()| back into the original value.
2216 This works for Numbers, Floats, Strings, Blobs and composites
2217 of them. Also works for |Funcref|s that refer to existing
2218 functions.
2219
2220 Can also be used as a |method|: >
2221 argv->join()->eval()
2222
2223eventhandler() *eventhandler()*
2224 Returns 1 when inside an event handler. That is that Vim got
2225 interrupted while waiting for the user to type a character,
2226 e.g., when dropping a file on Vim. This means interactive
2227 commands cannot be used. Otherwise zero is returned.
2228
2229executable({expr}) *executable()*
2230 This function checks if an executable with the name {expr}
2231 exists. {expr} must be the name of the program without any
2232 arguments.
2233 executable() uses the value of $PATH and/or the normal
2234 searchpath for programs. *PATHEXT*
2235 On MS-Windows the ".exe", ".bat", etc. can optionally be
2236 included. Then the extensions in $PATHEXT are tried. Thus if
2237 "foo.exe" does not exist, "foo.exe.bat" can be found. If
2238 $PATHEXT is not set then ".com;.exe;.bat;.cmd" is used. A dot
2239 by itself can be used in $PATHEXT to try using the name
2240 without an extension. When 'shell' looks like a Unix shell,
2241 then the name is also tried without adding an extension.
2242 On MS-Windows it only checks if the file exists and is not a
2243 directory, not if it's really executable.
2244 On MS-Windows an executable in the same directory as Vim is
Yasuhiro Matsumoto05cf63e2022-05-03 11:02:28 +01002245 normally found. Since this directory is added to $PATH it
2246 should also work to execute it |win32-PATH|. This can be
2247 disabled by setting the $NoDefaultCurrentDirectoryInExePath
2248 environment variable. *NoDefaultCurrentDirectoryInExePath*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002249 The result is a Number:
2250 1 exists
2251 0 does not exist
2252 -1 not implemented on this system
2253 |exepath()| can be used to get the full path of an executable.
2254
2255 Can also be used as a |method|: >
2256 GetCommand()->executable()
2257
2258execute({command} [, {silent}]) *execute()*
2259 Execute an Ex command or commands and return the output as a
2260 string.
2261 {command} can be a string or a List. In case of a List the
2262 lines are executed one by one.
2263 This is equivalent to: >
2264 redir => var
2265 {command}
2266 redir END
Bram Moolenaar71badf92023-04-22 22:40:14 +01002267< Except that line continuation in {command} is not recognized.
2268
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002269 The optional {silent} argument can have these values:
2270 "" no `:silent` used
2271 "silent" `:silent` used
2272 "silent!" `:silent!` used
2273 The default is "silent". Note that with "silent!", unlike
2274 `:redir`, error messages are dropped. When using an external
2275 command the screen may be messed up, use `system()` instead.
2276 *E930*
2277 It is not possible to use `:redir` anywhere in {command}.
2278
2279 To get a list of lines use |split()| on the result: >
Bram Moolenaar75ab5902022-04-18 15:36:40 +01002280 execute('args')->split("\n")
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002281
2282< To execute a command in another window than the current one
2283 use `win_execute()`.
2284
2285 When used recursively the output of the recursive call is not
2286 included in the output of the higher level call.
2287
2288 Can also be used as a |method|: >
2289 GetCommand()->execute()
2290
2291exepath({expr}) *exepath()*
2292 If {expr} is an executable and is either an absolute path, a
2293 relative path or found in $PATH, return the full path.
2294 Note that the current directory is used when {expr} starts
2295 with "./", which may be a problem for Vim: >
2296 echo exepath(v:progpath)
2297< If {expr} cannot be found in $PATH or is not executable then
2298 an empty string is returned.
2299
2300 Can also be used as a |method|: >
2301 GetCommand()->exepath()
2302<
2303 *exists()*
2304exists({expr}) The result is a Number, which is |TRUE| if {expr} is defined,
2305 zero otherwise.
2306
2307 Note: In a compiled |:def| function the evaluation is done at
2308 runtime. Use `exists_compiled()` to evaluate the expression
2309 at compile time.
2310
2311 For checking for a supported feature use |has()|.
2312 For checking if a file exists use |filereadable()|.
2313
2314 The {expr} argument is a string, which contains one of these:
Bram Moolenaarf10911e2022-01-29 22:20:48 +00002315 varname internal variable (see
2316 dict.key |internal-variables|). Also works
2317 list[i] for |curly-braces-names|, |Dictionary|
2318 import.Func entries, |List| items, imported
Bram Moolenaar944697a2022-02-20 19:48:20 +00002319 items, etc.
Bram Moolenaarf10911e2022-01-29 22:20:48 +00002320 Does not work for local variables in a
2321 compiled `:def` function.
Bram Moolenaar944697a2022-02-20 19:48:20 +00002322 Also works for a function in |Vim9|
2323 script, since it can be used as a
2324 function reference.
Bram Moolenaarf10911e2022-01-29 22:20:48 +00002325 Beware that evaluating an index may
2326 cause an error message for an invalid
2327 expression. E.g.: >
2328 :let l = [1, 2, 3]
2329 :echo exists("l[5]")
2330< 0 >
2331 :echo exists("l[xx]")
2332< E121: Undefined variable: xx
2333 0
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002334 &option-name Vim option (only checks if it exists,
2335 not if it really works)
2336 +option-name Vim option that works.
2337 $ENVNAME environment variable (could also be
2338 done by comparing with an empty
2339 string)
2340 *funcname built-in function (see |functions|)
2341 or user defined function (see
2342 |user-functions|) that is implemented.
2343 Also works for a variable that is a
2344 Funcref.
2345 ?funcname built-in function that could be
2346 implemented; to be used to check if
2347 "funcname" is valid
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002348 :cmdname Ex command: built-in command, user
2349 command or command modifier |:command|.
2350 Returns:
2351 1 for match with start of a command
2352 2 full match with a command
2353 3 matches several user commands
2354 To check for a supported command
2355 always check the return value to be 2.
2356 :2match The |:2match| command.
Bram Moolenaarb529cfb2022-07-25 15:42:07 +01002357 :3match The |:3match| command (but you
2358 probably should not use it, it is
2359 reserved for internal usage)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002360 #event autocommand defined for this event
2361 #event#pattern autocommand defined for this event and
2362 pattern (the pattern is taken
2363 literally and compared to the
2364 autocommand patterns character by
2365 character)
2366 #group autocommand group exists
2367 #group#event autocommand defined for this group and
2368 event.
2369 #group#event#pattern
2370 autocommand defined for this group,
2371 event and pattern.
2372 ##event autocommand for this event is
2373 supported.
2374
2375 Examples: >
2376 exists("&shortname")
2377 exists("$HOSTNAME")
2378 exists("*strftime")
Bram Moolenaar944697a2022-02-20 19:48:20 +00002379 exists("*s:MyFunc") " only for legacy script
2380 exists("*MyFunc")
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002381 exists("bufcount")
2382 exists(":Make")
2383 exists("#CursorHold")
2384 exists("#BufReadPre#*.gz")
2385 exists("#filetypeindent")
2386 exists("#filetypeindent#FileType")
2387 exists("#filetypeindent#FileType#*")
2388 exists("##ColorScheme")
2389< There must be no space between the symbol (&/$/*/#) and the
2390 name.
2391 There must be no extra characters after the name, although in
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01002392 a few cases this is ignored. That may become stricter in the
2393 future, thus don't count on it!
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002394 Working example: >
2395 exists(":make")
2396< NOT working example: >
2397 exists(":make install")
2398
2399< Note that the argument must be a string, not the name of the
2400 variable itself. For example: >
2401 exists(bufcount)
2402< This doesn't check for existence of the "bufcount" variable,
2403 but gets the value of "bufcount", and checks if that exists.
2404
2405 Can also be used as a |method|: >
2406 Varname()->exists()
2407<
2408
2409exists_compiled({expr}) *exists_compiled()*
2410 Like `exists()` but evaluated at compile time. This is useful
2411 to skip a block where a function is used that would otherwise
2412 give an error: >
2413 if exists_compiled('*ThatFunction')
2414 ThatFunction('works')
2415 endif
2416< If `exists()` were used then a compilation error would be
2417 given if ThatFunction() is not defined.
2418
2419 {expr} must be a literal string. *E1232*
2420 Can only be used in a |:def| function. *E1233*
2421 This does not work to check for arguments or local variables.
2422
2423
2424exp({expr}) *exp()*
2425 Return the exponential of {expr} as a |Float| in the range
2426 [0, inf].
2427 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar016188f2022-06-06 20:52:59 +01002428 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002429 Examples: >
2430 :echo exp(2)
2431< 7.389056 >
2432 :echo exp(-1)
2433< 0.367879
2434
2435 Can also be used as a |method|: >
2436 Compute()->exp()
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002437
2438
2439expand({string} [, {nosuf} [, {list}]]) *expand()*
2440 Expand wildcards and the following special keywords in
2441 {string}. 'wildignorecase' applies.
2442
2443 If {list} is given and it is |TRUE|, a List will be returned.
2444 Otherwise the result is a String and when there are several
2445 matches, they are separated by <NL> characters. [Note: in
2446 version 5.0 a space was used, which caused problems when a
2447 file name contains a space]
2448
2449 If the expansion fails, the result is an empty string. A name
2450 for a non-existing file is not included, unless {string} does
2451 not start with '%', '#' or '<', see below.
2452
2453 When {string} starts with '%', '#' or '<', the expansion is
2454 done like for the |cmdline-special| variables with their
2455 associated modifiers. Here is a short overview:
2456
2457 % current file name
2458 # alternate file name
2459 #n alternate file name n
2460 <cfile> file name under the cursor
2461 <afile> autocmd file name
2462 <abuf> autocmd buffer number (as a String!)
2463 <amatch> autocmd matched name
2464 <cexpr> C expression under the cursor
2465 <sfile> sourced script file or function name
2466 <slnum> sourced script line number or function
2467 line number
2468 <sflnum> script file line number, also when in
2469 a function
2470 <SID> "<SNR>123_" where "123" is the
2471 current script ID |<SID>|
Bram Moolenaar75ab5902022-04-18 15:36:40 +01002472 <script> sourced script file, or script file
2473 where the current function was defined
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002474 <stack> call stack
2475 <cword> word under the cursor
2476 <cWORD> WORD under the cursor
2477 <client> the {clientid} of the last received
2478 message |server2client()|
2479 Modifiers:
2480 :p expand to full path
2481 :h head (last path component removed)
2482 :t tail (last path component only)
2483 :r root (one extension removed)
2484 :e extension only
2485
2486 Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00002487 :let &tags = expand("%:p:h") .. "/tags"
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002488< Note that when expanding a string that starts with '%', '#' or
2489 '<', any following text is ignored. This does NOT work: >
2490 :let doesntwork = expand("%:h.bak")
2491< Use this: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00002492 :let doeswork = expand("%:h") .. ".bak"
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002493< Also note that expanding "<cfile>" and others only returns the
2494 referenced file name without further expansion. If "<cfile>"
2495 is "~/.cshrc", you need to do another expand() to have the
2496 "~/" expanded into the path of the home directory: >
2497 :echo expand(expand("<cfile>"))
2498<
2499 There cannot be white space between the variables and the
2500 following modifier. The |fnamemodify()| function can be used
2501 to modify normal file names.
2502
2503 When using '%' or '#', and the current or alternate file name
2504 is not defined, an empty string is used. Using "%:p" in a
2505 buffer with no name, results in the current directory, with a
2506 '/' added.
Bram Moolenaar57544522022-04-12 12:54:11 +01002507 When 'verbose' is set then expanding '%', '#' and <> items
2508 will result in an error message if the argument cannot be
2509 expanded.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002510
2511 When {string} does not start with '%', '#' or '<', it is
2512 expanded like a file name is expanded on the command line.
2513 'suffixes' and 'wildignore' are used, unless the optional
2514 {nosuf} argument is given and it is |TRUE|.
2515 Names for non-existing files are included. The "**" item can
2516 be used to search in a directory tree. For example, to find
2517 all "README" files in the current directory and below: >
2518 :echo expand("**/README")
2519<
2520 expand() can also be used to expand variables and environment
2521 variables that are only known in a shell. But this can be
2522 slow, because a shell may be used to do the expansion. See
2523 |expr-env-expand|.
2524 The expanded variable is still handled like a list of file
2525 names. When an environment variable cannot be expanded, it is
2526 left unchanged. Thus ":echo expand('$FOOBAR')" results in
2527 "$FOOBAR".
2528
2529 See |glob()| for finding existing files. See |system()| for
2530 getting the raw output of an external command.
2531
2532 Can also be used as a |method|: >
2533 Getpattern()->expand()
2534
Yegappan Lakshmanan2b74b682022-04-03 21:30:32 +01002535expandcmd({string} [, {options}]) *expandcmd()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002536 Expand special items in String {string} like what is done for
2537 an Ex command such as `:edit`. This expands special keywords,
2538 like with |expand()|, and environment variables, anywhere in
2539 {string}. "~user" and "~/path" are only expanded at the
2540 start.
Yegappan Lakshmanan2b74b682022-04-03 21:30:32 +01002541
2542 The following items are supported in the {options} Dict
2543 argument:
2544 errmsg If set to TRUE, error messages are displayed
2545 if an error is encountered during expansion.
2546 By default, error messages are not displayed.
2547
Yegappan Lakshmanan5018a832022-04-02 21:12:21 +01002548 Returns the expanded string. If an error is encountered
2549 during expansion, the unmodified {string} is returned.
Yegappan Lakshmanan2b74b682022-04-03 21:30:32 +01002550
Yegappan Lakshmanan5018a832022-04-02 21:12:21 +01002551 Example: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002552 :echo expandcmd('make %<.o')
Yegappan Lakshmanan2b74b682022-04-03 21:30:32 +01002553 make /path/runtime/doc/builtin.o
2554 :echo expandcmd('make %<.o', {'errmsg': v:true})
2555<
Yegappan Lakshmanan5018a832022-04-02 21:12:21 +01002556 Can also be used as a |method|: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002557 GetCommand()->expandcmd()
2558<
2559extend({expr1}, {expr2} [, {expr3}]) *extend()*
2560 {expr1} and {expr2} must be both |Lists| or both
2561 |Dictionaries|.
2562
2563 If they are |Lists|: Append {expr2} to {expr1}.
2564 If {expr3} is given insert the items of {expr2} before the
2565 item with index {expr3} in {expr1}. When {expr3} is zero
2566 insert before the first item. When {expr3} is equal to
2567 len({expr1}) then {expr2} is appended.
2568 Examples: >
2569 :echo sort(extend(mylist, [7, 5]))
2570 :call extend(mylist, [2, 3], 1)
2571< When {expr1} is the same List as {expr2} then the number of
2572 items copied is equal to the original length of the List.
2573 E.g., when {expr3} is 1 you get N new copies of the first item
2574 (where N is the original length of the List).
2575 Use |add()| to concatenate one item to a list. To concatenate
2576 two lists into a new list use the + operator: >
2577 :let newlist = [1, 2, 3] + [4, 5]
2578<
2579 If they are |Dictionaries|:
2580 Add all entries from {expr2} to {expr1}.
2581 If a key exists in both {expr1} and {expr2} then {expr3} is
2582 used to decide what to do:
2583 {expr3} = "keep": keep the value of {expr1}
2584 {expr3} = "force": use the value of {expr2}
2585 {expr3} = "error": give an error message *E737*
2586 When {expr3} is omitted then "force" is assumed.
2587
2588 {expr1} is changed when {expr2} is not empty. If necessary
2589 make a copy of {expr1} first.
2590 {expr2} remains unchanged.
2591 When {expr1} is locked and {expr2} is not empty the operation
2592 fails.
Bram Moolenaar016188f2022-06-06 20:52:59 +01002593 Returns {expr1}. Returns 0 on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002594
2595 Can also be used as a |method|: >
2596 mylist->extend(otherlist)
2597
2598
2599extendnew({expr1}, {expr2} [, {expr3}]) *extendnew()*
2600 Like |extend()| but instead of adding items to {expr1} a new
2601 List or Dictionary is created and returned. {expr1} remains
Bram Moolenaardd60c362023-02-27 15:49:53 +00002602 unchanged.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002603
2604
2605feedkeys({string} [, {mode}]) *feedkeys()*
2606 Characters in {string} are queued for processing as if they
2607 come from a mapping or were typed by the user.
2608
2609 By default the string is added to the end of the typeahead
2610 buffer, thus if a mapping is still being executed the
2611 characters come after them. Use the 'i' flag to insert before
2612 other characters, they will be executed next, before any
2613 characters from a mapping.
2614
2615 The function does not wait for processing of keys contained in
2616 {string}.
2617
2618 To include special keys into {string}, use double-quotes
2619 and "\..." notation |expr-quote|. For example,
2620 feedkeys("\<CR>") simulates pressing of the <Enter> key. But
2621 feedkeys('\<CR>') pushes 5 characters.
2622 A special code that might be useful is <Ignore>, it exits the
2623 wait for a character without doing anything. *<Ignore>*
2624
2625 {mode} is a String, which can contain these character flags:
2626 'm' Remap keys. This is default. If {mode} is absent,
2627 keys are remapped.
2628 'n' Do not remap keys.
2629 't' Handle keys as if typed; otherwise they are handled as
2630 if coming from a mapping. This matters for undo,
2631 opening folds, etc.
2632 'L' Lowlevel input. Only works for Unix or when using the
2633 GUI. Keys are used as if they were coming from the
2634 terminal. Other flags are not used. *E980*
2635 When a CTRL-C interrupts and 't' is included it sets
2636 the internal "got_int" flag.
2637 'i' Insert the string instead of appending (see above).
2638 'x' Execute commands until typeahead is empty. This is
2639 similar to using ":normal!". You can call feedkeys()
2640 several times without 'x' and then one time with 'x'
2641 (possibly with an empty {string}) to execute all the
2642 typeahead. Note that when Vim ends in Insert mode it
2643 will behave as if <Esc> is typed, to avoid getting
2644 stuck, waiting for a character to be typed before the
2645 script continues.
2646 Note that if you manage to call feedkeys() while
2647 executing commands, thus calling it recursively, then
2648 all typeahead will be consumed by the last call.
Bram Moolenaara9725222022-01-16 13:30:33 +00002649 'c' Remove any script context when executing, so that
2650 legacy script syntax applies, "s:var" does not work,
Bram Moolenaard899e512022-05-07 21:54:03 +01002651 etc. Note that if the string being fed sets a script
Bram Moolenaarce001a32022-04-27 15:25:03 +01002652 context this still applies.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002653 '!' When used with 'x' will not end Insert mode. Can be
2654 used in a test when a timer is set to exit Insert mode
2655 a little later. Useful for testing CursorHoldI.
2656
2657 Return value is always 0.
2658
2659 Can also be used as a |method|: >
2660 GetInput()->feedkeys()
2661
2662filereadable({file}) *filereadable()*
2663 The result is a Number, which is |TRUE| when a file with the
2664 name {file} exists, and can be read. If {file} doesn't exist,
2665 or is a directory, the result is |FALSE|. {file} is any
2666 expression, which is used as a String.
2667 If you don't care about the file being readable you can use
2668 |glob()|.
2669 {file} is used as-is, you may want to expand wildcards first: >
2670 echo filereadable('~/.vimrc')
2671 0
2672 echo filereadable(expand('~/.vimrc'))
2673 1
2674
2675< Can also be used as a |method|: >
2676 GetName()->filereadable()
2677< *file_readable()*
2678 Obsolete name: file_readable().
2679
2680
2681filewritable({file}) *filewritable()*
2682 The result is a Number, which is 1 when a file with the
2683 name {file} exists, and can be written. If {file} doesn't
2684 exist, or is not writable, the result is 0. If {file} is a
2685 directory, and we can write to it, the result is 2.
2686
2687 Can also be used as a |method|: >
2688 GetName()->filewritable()
2689
2690
2691filter({expr1}, {expr2}) *filter()*
2692 {expr1} must be a |List|, |String|, |Blob| or |Dictionary|.
2693 For each item in {expr1} evaluate {expr2} and when the result
2694 is zero or false remove the item from the |List| or
2695 |Dictionary|. Similarly for each byte in a |Blob| and each
Bram Moolenaar2f0936c2022-01-08 21:51:59 +00002696 character in a |String|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002697
2698 {expr2} must be a |string| or |Funcref|.
2699
2700 If {expr2} is a |string|, inside {expr2} |v:val| has the value
2701 of the current item. For a |Dictionary| |v:key| has the key
2702 of the current item and for a |List| |v:key| has the index of
2703 the current item. For a |Blob| |v:key| has the index of the
2704 current byte. For a |String| |v:key| has the index of the
2705 current character.
2706 Examples: >
2707 call filter(mylist, 'v:val !~ "OLD"')
2708< Removes the items where "OLD" appears. >
2709 call filter(mydict, 'v:key >= 8')
2710< Removes the items with a key below 8. >
2711 call filter(var, 0)
2712< Removes all the items, thus clears the |List| or |Dictionary|.
2713
2714 Note that {expr2} is the result of expression and is then
2715 used as an expression again. Often it is good to use a
2716 |literal-string| to avoid having to double backslashes.
2717
2718 If {expr2} is a |Funcref| it must take two arguments:
2719 1. the key or the index of the current item.
2720 2. the value of the current item.
2721 The function must return |TRUE| if the item should be kept.
2722 Example that keeps the odd items of a list: >
2723 func Odd(idx, val)
2724 return a:idx % 2 == 1
2725 endfunc
2726 call filter(mylist, function('Odd'))
Bram Moolenaar2f0936c2022-01-08 21:51:59 +00002727< It is shorter when using a |lambda|. In |Vim9| syntax: >
2728 call filter(myList, (idx, val) => idx * val <= 42)
2729< In legacy script syntax: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002730 call filter(myList, {idx, val -> idx * val <= 42})
2731< If you do not use "val" you can leave it out: >
2732 call filter(myList, {idx -> idx % 2 == 1})
2733<
2734 In |Vim9| script the result must be true, false, zero or one.
2735 Other values will result in a type error.
2736
2737 For a |List| and a |Dictionary| the operation is done
2738 in-place. If you want it to remain unmodified make a copy
2739 first: >
2740 :let l = filter(copy(mylist), 'v:val =~ "KEEP"')
2741
2742< Returns {expr1}, the |List| or |Dictionary| that was filtered,
naohiro ono56200ee2022-01-01 14:59:44 +00002743 or a new |Blob| or |String|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002744 When an error is encountered while evaluating {expr2} no
2745 further items in {expr1} are processed.
2746 When {expr2} is a Funcref errors inside a function are ignored,
2747 unless it was defined with the "abort" flag.
2748
2749 Can also be used as a |method|: >
2750 mylist->filter(expr2)
2751
2752finddir({name} [, {path} [, {count}]]) *finddir()*
2753 Find directory {name} in {path}. Supports both downwards and
2754 upwards recursive directory searches. See |file-searching|
2755 for the syntax of {path}.
2756
2757 Returns the path of the first found match. When the found
2758 directory is below the current directory a relative path is
2759 returned. Otherwise a full path is returned.
2760 If {path} is omitted or empty then 'path' is used.
2761
2762 If the optional {count} is given, find {count}'s occurrence of
2763 {name} in {path} instead of the first one.
2764 When {count} is negative return all the matches in a |List|.
2765
Bram Moolenaar016188f2022-06-06 20:52:59 +01002766 Returns an empty string if the directory is not found.
2767
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002768 This is quite similar to the ex-command `:find`.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002769
2770 Can also be used as a |method|: >
2771 GetName()->finddir()
2772
2773findfile({name} [, {path} [, {count}]]) *findfile()*
2774 Just like |finddir()|, but find a file instead of a directory.
2775 Uses 'suffixesadd'.
2776 Example: >
2777 :echo findfile("tags.vim", ".;")
2778< Searches from the directory of the current file upwards until
2779 it finds the file "tags.vim".
2780
2781 Can also be used as a |method|: >
2782 GetName()->findfile()
2783
2784flatten({list} [, {maxdepth}]) *flatten()*
2785 Flatten {list} up to {maxdepth} levels. Without {maxdepth}
2786 the result is a |List| without nesting, as if {maxdepth} is
2787 a very large number.
2788 The {list} is changed in place, use |flattennew()| if you do
2789 not want that.
2790 In Vim9 script flatten() cannot be used, you must always use
Bram Moolenaara2baa732022-02-04 16:09:54 +00002791 |flattennew()|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002792 *E900*
2793 {maxdepth} means how deep in nested lists changes are made.
2794 {list} is not modified when {maxdepth} is 0.
2795 {maxdepth} must be positive number.
2796
2797 If there is an error the number zero is returned.
2798
2799 Example: >
2800 :echo flatten([1, [2, [3, 4]], 5])
2801< [1, 2, 3, 4, 5] >
2802 :echo flatten([1, [2, [3, 4]], 5], 1)
2803< [1, 2, [3, 4], 5]
2804
2805 Can also be used as a |method|: >
2806 mylist->flatten()
2807<
2808flattennew({list} [, {maxdepth}]) *flattennew()*
2809 Like |flatten()| but first make a copy of {list}.
2810
2811
2812float2nr({expr}) *float2nr()*
2813 Convert {expr} to a Number by omitting the part after the
2814 decimal point.
Bram Moolenaar76db9e02022-11-09 21:21:04 +00002815 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar016188f2022-06-06 20:52:59 +01002816 Returns 0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002817 When the value of {expr} is out of range for a |Number| the
2818 result is truncated to 0x7fffffff or -0x7fffffff (or when
2819 64-bit Number support is enabled, 0x7fffffffffffffff or
2820 -0x7fffffffffffffff). NaN results in -0x80000000 (or when
2821 64-bit Number support is enabled, -0x8000000000000000).
2822 Examples: >
2823 echo float2nr(3.95)
2824< 3 >
2825 echo float2nr(-23.45)
2826< -23 >
2827 echo float2nr(1.0e100)
2828< 2147483647 (or 9223372036854775807) >
2829 echo float2nr(-1.0e150)
2830< -2147483647 (or -9223372036854775807) >
2831 echo float2nr(1.0e-100)
2832< 0
2833
2834 Can also be used as a |method|: >
2835 Compute()->float2nr()
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002836
2837
2838floor({expr}) *floor()*
2839 Return the largest integral value less than or equal to
2840 {expr} as a |Float| (round down).
2841 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar016188f2022-06-06 20:52:59 +01002842 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002843 Examples: >
2844 echo floor(1.856)
2845< 1.0 >
2846 echo floor(-5.456)
2847< -6.0 >
2848 echo floor(4.0)
2849< 4.0
2850
2851 Can also be used as a |method|: >
2852 Compute()->floor()
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002853
2854
2855fmod({expr1}, {expr2}) *fmod()*
2856 Return the remainder of {expr1} / {expr2}, even if the
2857 division is not representable. Returns {expr1} - i * {expr2}
2858 for some integer i such that if {expr2} is non-zero, the
2859 result has the same sign as {expr1} and magnitude less than
2860 the magnitude of {expr2}. If {expr2} is zero, the value
2861 returned is zero. The value returned is a |Float|.
2862 {expr1} and {expr2} must evaluate to a |Float| or a |Number|.
Bram Moolenaar016188f2022-06-06 20:52:59 +01002863 Returns 0.0 if {expr1} or {expr2} is not a |Float| or a
2864 |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002865 Examples: >
2866 :echo fmod(12.33, 1.22)
2867< 0.13 >
2868 :echo fmod(-12.33, 1.22)
2869< -0.13
2870
2871 Can also be used as a |method|: >
2872 Compute()->fmod(1.22)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002873
2874
2875fnameescape({string}) *fnameescape()*
2876 Escape {string} for use as file name command argument. All
2877 characters that have a special meaning, such as '%' and '|'
2878 are escaped with a backslash.
2879 For most systems the characters escaped are
2880 " \t\n*?[{`$\\%#'\"|!<". For systems where a backslash
2881 appears in a filename, it depends on the value of 'isfname'.
2882 A leading '+' and '>' is also escaped (special after |:edit|
2883 and |:write|). And a "-" by itself (special after |:cd|).
Bram Moolenaar016188f2022-06-06 20:52:59 +01002884 Returns an empty string on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002885 Example: >
2886 :let fname = '+some str%nge|name'
Bram Moolenaarc51cf032022-02-26 12:25:45 +00002887 :exe "edit " .. fnameescape(fname)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002888< results in executing: >
2889 edit \+some\ str\%nge\|name
2890<
2891 Can also be used as a |method|: >
2892 GetName()->fnameescape()
2893
2894fnamemodify({fname}, {mods}) *fnamemodify()*
2895 Modify file name {fname} according to {mods}. {mods} is a
2896 string of characters like it is used for file names on the
2897 command line. See |filename-modifiers|.
2898 Example: >
2899 :echo fnamemodify("main.c", ":p:h")
2900< results in: >
Bram Moolenaard799daa2022-06-20 11:17:32 +01002901 /home/user/vim/vim/src
Bram Moolenaar016188f2022-06-06 20:52:59 +01002902< If {mods} is empty or an unsupported modifier is used then
2903 {fname} is returned.
Bram Moolenaar5ed11532022-07-06 13:18:11 +01002904 When {fname} is empty then with {mods} ":h" returns ".", so
2905 that `:cd` can be used with it. This is different from
2906 expand('%:h') without a buffer name, which returns an empty
2907 string.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002908 Note: Environment variables don't work in {fname}, use
2909 |expand()| first then.
2910
2911 Can also be used as a |method|: >
2912 GetName()->fnamemodify(':p:h')
2913
2914foldclosed({lnum}) *foldclosed()*
2915 The result is a Number. If the line {lnum} is in a closed
2916 fold, the result is the number of the first line in that fold.
2917 If the line {lnum} is not in a closed fold, -1 is returned.
2918 {lnum} is used like with |getline()|. Thus "." is the current
2919 line, "'m" mark m, etc.
2920
2921 Can also be used as a |method|: >
2922 GetLnum()->foldclosed()
2923
2924foldclosedend({lnum}) *foldclosedend()*
2925 The result is a Number. If the line {lnum} is in a closed
2926 fold, the result is the number of the last line in that fold.
2927 If the line {lnum} is not in a closed fold, -1 is returned.
2928 {lnum} is used like with |getline()|. Thus "." is the current
2929 line, "'m" mark m, etc.
2930
2931 Can also be used as a |method|: >
2932 GetLnum()->foldclosedend()
2933
2934foldlevel({lnum}) *foldlevel()*
2935 The result is a Number, which is the foldlevel of line {lnum}
2936 in the current buffer. For nested folds the deepest level is
2937 returned. If there is no fold at line {lnum}, zero is
2938 returned. It doesn't matter if the folds are open or closed.
2939 When used while updating folds (from 'foldexpr') -1 is
2940 returned for lines where folds are still to be updated and the
2941 foldlevel is unknown. As a special case the level of the
2942 previous line is usually available.
2943 {lnum} is used like with |getline()|. Thus "." is the current
2944 line, "'m" mark m, etc.
2945
2946 Can also be used as a |method|: >
2947 GetLnum()->foldlevel()
2948<
2949 *foldtext()*
2950foldtext() Returns a String, to be displayed for a closed fold. This is
2951 the default function used for the 'foldtext' option and should
2952 only be called from evaluating 'foldtext'. It uses the
2953 |v:foldstart|, |v:foldend| and |v:folddashes| variables.
2954 The returned string looks like this: >
2955 +-- 45 lines: abcdef
2956< The number of leading dashes depends on the foldlevel. The
2957 "45" is the number of lines in the fold. "abcdef" is the text
2958 in the first non-blank line of the fold. Leading white space,
2959 "//" or "/*" and the text from the 'foldmarker' and
2960 'commentstring' options is removed.
2961 When used to draw the actual foldtext, the rest of the line
2962 will be filled with the fold char from the 'fillchars'
2963 setting.
Bram Moolenaar016188f2022-06-06 20:52:59 +01002964 Returns an empty string when there is no fold.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002965 {not available when compiled without the |+folding| feature}
2966
2967foldtextresult({lnum}) *foldtextresult()*
2968 Returns the text that is displayed for the closed fold at line
2969 {lnum}. Evaluates 'foldtext' in the appropriate context.
2970 When there is no closed fold at {lnum} an empty string is
2971 returned.
2972 {lnum} is used like with |getline()|. Thus "." is the current
2973 line, "'m" mark m, etc.
2974 Useful when exporting folded text, e.g., to HTML.
2975 {not available when compiled without the |+folding| feature}
2976
2977
2978 Can also be used as a |method|: >
2979 GetLnum()->foldtextresult()
2980<
2981 *foreground()*
2982foreground() Move the Vim window to the foreground. Useful when sent from
2983 a client to a Vim server. |remote_send()|
2984 On Win32 systems this might not work, the OS does not always
2985 allow a window to bring itself to the foreground. Use
2986 |remote_foreground()| instead.
Bram Moolenaarcbaff5e2022-04-08 17:45:08 +01002987 {only in the Win32, Motif and GTK GUI versions and the
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002988 Win32 console version}
2989
Bram Moolenaaraa534142022-09-15 21:46:02 +01002990fullcommand({name} [, {vim9}]) *fullcommand()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002991 Get the full command name from a short abbreviated command
2992 name; see |20.2| for details on command abbreviations.
2993
2994 The string argument {name} may start with a `:` and can
2995 include a [range], these are skipped and not returned.
Bram Moolenaaraa534142022-09-15 21:46:02 +01002996 Returns an empty string if a command doesn't exist, if it's
2997 ambiguous (for user-defined commands) or cannot be shortened
2998 this way. |vim9-no-shorten|
2999
3000 Without the {vim9} argument uses the current script version.
3001 If {vim9} is present and FALSE then legacy script rules are
3002 used. When {vim9} is present and TRUE then Vim9 rules are
3003 used, e.g. "en" is not a short form of "endif".
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003004
3005 For example `fullcommand('s')`, `fullcommand('sub')`,
3006 `fullcommand(':%substitute')` all return "substitute".
3007
3008 Can also be used as a |method|: >
3009 GetName()->fullcommand()
3010<
3011 *funcref()*
3012funcref({name} [, {arglist}] [, {dict}])
3013 Just like |function()|, but the returned Funcref will lookup
3014 the function by reference, not by name. This matters when the
3015 function {name} is redefined later.
3016
3017 Unlike |function()|, {name} must be an existing user function.
Bram Moolenaar2f0936c2022-01-08 21:51:59 +00003018 It only works for an autoloaded function if it has already
3019 been loaded (to avoid mistakenly loading the autoload script
3020 when only intending to use the function name, use |function()|
3021 instead). {name} cannot be a builtin function.
Bram Moolenaar016188f2022-06-06 20:52:59 +01003022 Returns 0 on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003023
3024 Can also be used as a |method|: >
3025 GetFuncname()->funcref([arg])
3026<
Dominique Pellee764d1b2023-03-12 21:20:59 +00003027 *function()* *partial* *E700* *E923*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003028function({name} [, {arglist}] [, {dict}])
3029 Return a |Funcref| variable that refers to function {name}.
3030 {name} can be the name of a user defined function or an
3031 internal function.
3032
3033 {name} can also be a Funcref or a partial. When it is a
3034 partial the dict stored in it will be used and the {dict}
3035 argument is not allowed. E.g.: >
3036 let FuncWithArg = function(dict.Func, [arg])
3037 let Broken = function(dict.Func, [arg], dict)
3038<
3039 When using the Funcref the function will be found by {name},
3040 also when it was redefined later. Use |funcref()| to keep the
3041 same function.
3042
3043 When {arglist} or {dict} is present this creates a partial.
3044 That means the argument list and/or the dictionary is stored in
3045 the Funcref and will be used when the Funcref is called.
3046
3047 The arguments are passed to the function in front of other
3048 arguments, but after any argument from |method|. Example: >
3049 func Callback(arg1, arg2, name)
3050 ...
3051 let Partial = function('Callback', ['one', 'two'])
3052 ...
3053 call Partial('name')
3054< Invokes the function as with: >
3055 call Callback('one', 'two', 'name')
3056
3057< With a |method|: >
3058 func Callback(one, two, three)
3059 ...
3060 let Partial = function('Callback', ['two'])
3061 ...
3062 eval 'one'->Partial('three')
3063< Invokes the function as with: >
3064 call Callback('one', 'two', 'three')
3065
3066< The function() call can be nested to add more arguments to the
3067 Funcref. The extra arguments are appended to the list of
3068 arguments. Example: >
3069 func Callback(arg1, arg2, name)
Bram Moolenaar0daafaa2022-09-04 17:45:43 +01003070 "...
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003071 let Func = function('Callback', ['one'])
3072 let Func2 = function(Func, ['two'])
Bram Moolenaar0daafaa2022-09-04 17:45:43 +01003073 "...
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003074 call Func2('name')
3075< Invokes the function as with: >
3076 call Callback('one', 'two', 'name')
3077
3078< The Dictionary is only useful when calling a "dict" function.
3079 In that case the {dict} is passed in as "self". Example: >
3080 function Callback() dict
Bram Moolenaarc51cf032022-02-26 12:25:45 +00003081 echo "called for " .. self.name
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003082 endfunction
Bram Moolenaar0daafaa2022-09-04 17:45:43 +01003083 "...
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003084 let context = {"name": "example"}
3085 let Func = function('Callback', context)
Bram Moolenaar0daafaa2022-09-04 17:45:43 +01003086 "...
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003087 call Func() " will echo: called for example
3088< The use of function() is not needed when there are no extra
Bram Moolenaar0daafaa2022-09-04 17:45:43 +01003089 arguments, these two are equivalent, if Callback() is defined
3090 as context.Callback(): >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003091 let Func = function('Callback', context)
3092 let Func = context.Callback
3093
3094< The argument list and the Dictionary can be combined: >
3095 function Callback(arg1, count) dict
Bram Moolenaar0daafaa2022-09-04 17:45:43 +01003096 "...
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003097 let context = {"name": "example"}
3098 let Func = function('Callback', ['one'], context)
Bram Moolenaar0daafaa2022-09-04 17:45:43 +01003099 "...
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003100 call Func(500)
3101< Invokes the function as with: >
3102 call context.Callback('one', 500)
3103<
Bram Moolenaar016188f2022-06-06 20:52:59 +01003104 Returns 0 on error.
3105
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003106 Can also be used as a |method|: >
3107 GetFuncname()->function([arg])
3108
3109
3110garbagecollect([{atexit}]) *garbagecollect()*
3111 Cleanup unused |Lists|, |Dictionaries|, |Channels| and |Jobs|
3112 that have circular references.
3113
3114 There is hardly ever a need to invoke this function, as it is
3115 automatically done when Vim runs out of memory or is waiting
3116 for the user to press a key after 'updatetime'. Items without
3117 circular references are always freed when they become unused.
3118 This is useful if you have deleted a very big |List| and/or
3119 |Dictionary| with circular references in a script that runs
3120 for a long time.
3121
3122 When the optional {atexit} argument is one, garbage
3123 collection will also be done when exiting Vim, if it wasn't
3124 done before. This is useful when checking for memory leaks.
3125
3126 The garbage collection is not done immediately but only when
3127 it's safe to perform. This is when waiting for the user to
3128 type a character. To force garbage collection immediately use
3129 |test_garbagecollect_now()|.
3130
3131get({list}, {idx} [, {default}]) *get()*
3132 Get item {idx} from |List| {list}. When this item is not
3133 available return {default}. Return zero when {default} is
3134 omitted.
3135 Preferably used as a |method|: >
3136 mylist->get(idx)
3137get({blob}, {idx} [, {default}])
3138 Get byte {idx} from |Blob| {blob}. When this byte is not
3139 available return {default}. Return -1 when {default} is
3140 omitted.
3141 Preferably used as a |method|: >
3142 myblob->get(idx)
3143get({dict}, {key} [, {default}])
3144 Get item with key {key} from |Dictionary| {dict}. When this
3145 item is not available return {default}. Return zero when
3146 {default} is omitted. Useful example: >
3147 let val = get(g:, 'var_name', 'default')
3148< This gets the value of g:var_name if it exists, and uses
3149 'default' when it does not exist.
3150 Preferably used as a |method|: >
3151 mydict->get(key)
3152get({func}, {what})
Bram Moolenaar6f4754b2022-01-23 12:07:04 +00003153 Get item {what} from Funcref {func}. Possible values for
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003154 {what} are:
3155 "name" The function name
3156 "func" The function
3157 "dict" The dictionary
3158 "args" The list with arguments
Bram Moolenaar016188f2022-06-06 20:52:59 +01003159 Returns zero on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003160 Preferably used as a |method|: >
3161 myfunc->get(what)
3162<
3163 *getbufinfo()*
3164getbufinfo([{buf}])
3165getbufinfo([{dict}])
3166 Get information about buffers as a List of Dictionaries.
3167
3168 Without an argument information about all the buffers is
3169 returned.
3170
3171 When the argument is a |Dictionary| only the buffers matching
3172 the specified criteria are returned. The following keys can
3173 be specified in {dict}:
3174 buflisted include only listed buffers.
3175 bufloaded include only loaded buffers.
3176 bufmodified include only modified buffers.
3177
3178 Otherwise, {buf} specifies a particular buffer to return
3179 information for. For the use of {buf}, see |bufname()|
3180 above. If the buffer is found the returned List has one item.
3181 Otherwise the result is an empty list.
3182
3183 Each returned List item is a dictionary with the following
3184 entries:
3185 bufnr Buffer number.
3186 changed TRUE if the buffer is modified.
3187 changedtick Number of changes made to the buffer.
3188 hidden TRUE if the buffer is hidden.
3189 lastused Timestamp in seconds, like
3190 |localtime()|, when the buffer was
3191 last used.
3192 {only with the |+viminfo| feature}
3193 listed TRUE if the buffer is listed.
3194 lnum Line number used for the buffer when
3195 opened in the current window.
3196 Only valid if the buffer has been
3197 displayed in the window in the past.
3198 If you want the line number of the
3199 last known cursor position in a given
3200 window, use |line()|: >
3201 :echo line('.', {winid})
3202<
3203 linecount Number of lines in the buffer (only
3204 valid when loaded)
3205 loaded TRUE if the buffer is loaded.
3206 name Full path to the file in the buffer.
3207 signs List of signs placed in the buffer.
3208 Each list item is a dictionary with
3209 the following fields:
3210 id sign identifier
3211 lnum line number
3212 name sign name
3213 variables A reference to the dictionary with
3214 buffer-local variables.
3215 windows List of |window-ID|s that display this
3216 buffer
3217 popups List of popup |window-ID|s that
3218 display this buffer
3219
3220 Examples: >
3221 for buf in getbufinfo()
3222 echo buf.name
3223 endfor
3224 for buf in getbufinfo({'buflisted':1})
3225 if buf.changed
3226 ....
3227 endif
3228 endfor
3229<
3230 To get buffer-local options use: >
3231 getbufvar({bufnr}, '&option_name')
3232<
3233 Can also be used as a |method|: >
3234 GetBufnr()->getbufinfo()
3235<
3236
3237 *getbufline()*
3238getbufline({buf}, {lnum} [, {end}])
3239 Return a |List| with the lines starting from {lnum} to {end}
3240 (inclusive) in the buffer {buf}. If {end} is omitted, a
Bram Moolenaarce30ccc2022-11-21 19:57:04 +00003241 |List| with only the line {lnum} is returned. See
3242 `getbufoneline()` for only getting the line.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003243
3244 For the use of {buf}, see |bufname()| above.
3245
3246 For {lnum} and {end} "$" can be used for the last line of the
3247 buffer. Otherwise a number must be used.
3248
3249 When {lnum} is smaller than 1 or bigger than the number of
3250 lines in the buffer, an empty |List| is returned.
3251
3252 When {end} is greater than the number of lines in the buffer,
3253 it is treated as {end} is set to the number of lines in the
3254 buffer. When {end} is before {lnum} an empty |List| is
3255 returned.
3256
3257 This function works only for loaded buffers. For unloaded and
3258 non-existing buffers, an empty |List| is returned.
3259
3260 Example: >
3261 :let lines = getbufline(bufnr("myfile"), 1, "$")
3262
3263< Can also be used as a |method|: >
3264 GetBufnr()->getbufline(lnum)
Bram Moolenaarce30ccc2022-11-21 19:57:04 +00003265<
3266 *getbufoneline()*
3267getbufoneline({buf}, {lnum})
3268 Just like `getbufline()` but only get one line and return it
3269 as a string.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003270
3271getbufvar({buf}, {varname} [, {def}]) *getbufvar()*
3272 The result is the value of option or local buffer variable
3273 {varname} in buffer {buf}. Note that the name without "b:"
3274 must be used.
3275 The {varname} argument is a string.
3276 When {varname} is empty returns a |Dictionary| with all the
3277 buffer-local variables.
3278 When {varname} is equal to "&" returns a |Dictionary| with all
3279 the buffer-local options.
3280 Otherwise, when {varname} starts with "&" returns the value of
3281 a buffer-local option.
3282 This also works for a global or buffer-local option, but it
3283 doesn't work for a global variable, window-local variable or
3284 window-local option.
3285 For the use of {buf}, see |bufname()| above.
3286 When the buffer or variable doesn't exist {def} or an empty
3287 string is returned, there is no error message.
3288 Examples: >
3289 :let bufmodified = getbufvar(1, "&mod")
Bram Moolenaarc51cf032022-02-26 12:25:45 +00003290 :echo "todo myvar = " .. getbufvar("todo", "myvar")
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003291
3292< Can also be used as a |method|: >
3293 GetBufnr()->getbufvar(varname)
3294<
Kota Kato66bb9ae2023-01-17 18:31:56 +00003295getcellwidths() *getcellwidths()*
3296 Returns a |List| of cell widths of character ranges overridden
3297 by |setcellwidths()|. The format is equal to the argument of
3298 |setcellwidths()|. If no character ranges have their cell
3299 widths overridden, an empty List is returned.
3300
3301
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003302getchangelist([{buf}]) *getchangelist()*
3303 Returns the |changelist| for the buffer {buf}. For the use
3304 of {buf}, see |bufname()| above. If buffer {buf} doesn't
3305 exist, an empty list is returned.
3306
3307 The returned list contains two entries: a list with the change
3308 locations and the current position in the list. Each
3309 entry in the change list is a dictionary with the following
3310 entries:
3311 col column number
3312 coladd column offset for 'virtualedit'
3313 lnum line number
3314 If buffer {buf} is the current buffer, then the current
3315 position refers to the position in the list. For other
3316 buffers, it is set to the length of the list.
3317
3318 Can also be used as a |method|: >
3319 GetBufnr()->getchangelist()
3320
3321getchar([expr]) *getchar()*
3322 Get a single character from the user or input stream.
3323 If [expr] is omitted, wait until a character is available.
3324 If [expr] is 0, only get a character when one is available.
3325 Return zero otherwise.
3326 If [expr] is 1, only check if a character is available, it is
3327 not consumed. Return zero if no character available.
3328 If you prefer always getting a string use |getcharstr()|.
3329
3330 Without [expr] and when [expr] is 0 a whole character or
3331 special key is returned. If it is a single character, the
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01003332 result is a Number. Use |nr2char()| to convert it to a String.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003333 Otherwise a String is returned with the encoded character.
3334 For a special key it's a String with a sequence of bytes
3335 starting with 0x80 (decimal: 128). This is the same value as
3336 the String "\<Key>", e.g., "\<Left>". The returned value is
3337 also a String when a modifier (shift, control, alt) was used
3338 that is not included in the character.
3339
3340 When [expr] is 0 and Esc is typed, there will be a short delay
3341 while Vim waits to see if this is the start of an escape
3342 sequence.
3343
3344 When [expr] is 1 only the first byte is returned. For a
3345 one-byte character it is the character itself as a number.
3346 Use nr2char() to convert it to a String.
3347
3348 Use getcharmod() to obtain any additional modifiers.
3349
3350 When the user clicks a mouse button, the mouse event will be
3351 returned. The position can then be found in |v:mouse_col|,
3352 |v:mouse_lnum|, |v:mouse_winid| and |v:mouse_win|.
3353 |getmousepos()| can also be used. Mouse move events will be
3354 ignored.
3355 This example positions the mouse as it would normally happen: >
3356 let c = getchar()
3357 if c == "\<LeftMouse>" && v:mouse_win > 0
Bram Moolenaarc51cf032022-02-26 12:25:45 +00003358 exe v:mouse_win .. "wincmd w"
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003359 exe v:mouse_lnum
Bram Moolenaarc51cf032022-02-26 12:25:45 +00003360 exe "normal " .. v:mouse_col .. "|"
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003361 endif
3362<
3363 When using bracketed paste only the first character is
3364 returned, the rest of the pasted text is dropped.
3365 |xterm-bracketed-paste|.
3366
3367 There is no prompt, you will somehow have to make clear to the
3368 user that a character has to be typed. The screen is not
3369 redrawn, e.g. when resizing the window. When using a popup
3370 window it should work better with a |popup-filter|.
3371
3372 There is no mapping for the character.
3373 Key codes are replaced, thus when the user presses the <Del>
3374 key you get the code for the <Del> key, not the raw character
3375 sequence. Examples: >
3376 getchar() == "\<Del>"
3377 getchar() == "\<S-Left>"
3378< This example redefines "f" to ignore case: >
3379 :nmap f :call FindChar()<CR>
3380 :function FindChar()
3381 : let c = nr2char(getchar())
3382 : while col('.') < col('$') - 1
3383 : normal l
3384 : if getline('.')[col('.') - 1] ==? c
3385 : break
3386 : endif
3387 : endwhile
3388 :endfunction
3389<
3390 You may also receive synthetic characters, such as
3391 |<CursorHold>|. Often you will want to ignore this and get
3392 another character: >
3393 :function GetKey()
3394 : let c = getchar()
3395 : while c == "\<CursorHold>"
3396 : let c = getchar()
3397 : endwhile
3398 : return c
3399 :endfunction
3400
3401getcharmod() *getcharmod()*
3402 The result is a Number which is the state of the modifiers for
3403 the last obtained character with getchar() or in another way.
3404 These values are added together:
3405 2 shift
3406 4 control
3407 8 alt (meta)
3408 16 meta (when it's different from ALT)
3409 32 mouse double click
3410 64 mouse triple click
3411 96 mouse quadruple click (== 32 + 64)
3412 128 command (Macintosh only)
3413 Only the modifiers that have not been included in the
3414 character itself are obtained. Thus Shift-a results in "A"
Bram Moolenaar016188f2022-06-06 20:52:59 +01003415 without a modifier. Returns 0 if no modifiers are used.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003416
3417 *getcharpos()*
3418getcharpos({expr})
3419 Get the position for String {expr}. Same as |getpos()| but the
3420 column number in the returned List is a character index
3421 instead of a byte index.
naohiro ono56200ee2022-01-01 14:59:44 +00003422 If |getpos()| returns a very large column number, equal to
3423 |v:maxcol|, then getcharpos() will return the character index
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003424 of the last character.
3425
3426 Example:
3427 With the cursor on '세' in line 5 with text "여보세요": >
3428 getcharpos('.') returns [0, 5, 3, 0]
3429 getpos('.') returns [0, 5, 7, 0]
3430<
3431 Can also be used as a |method|: >
3432 GetMark()->getcharpos()
3433
3434getcharsearch() *getcharsearch()*
3435 Return the current character search information as a {dict}
3436 with the following entries:
3437
3438 char character previously used for a character
3439 search (|t|, |f|, |T|, or |F|); empty string
3440 if no character search has been performed
3441 forward direction of character search; 1 for forward,
3442 0 for backward
3443 until type of character search; 1 for a |t| or |T|
3444 character search, 0 for an |f| or |F|
3445 character search
3446
3447 This can be useful to always have |;| and |,| search
3448 forward/backward regardless of the direction of the previous
3449 character search: >
3450 :nnoremap <expr> ; getcharsearch().forward ? ';' : ','
3451 :nnoremap <expr> , getcharsearch().forward ? ',' : ';'
3452< Also see |setcharsearch()|.
3453
3454
3455getcharstr([expr]) *getcharstr()*
3456 Get a single character from the user or input stream as a
3457 string.
3458 If [expr] is omitted, wait until a character is available.
3459 If [expr] is 0 or false, only get a character when one is
3460 available. Return an empty string otherwise.
3461 If [expr] is 1 or true, only check if a character is
3462 available, it is not consumed. Return an empty string
3463 if no character is available.
3464 Otherwise this works like |getchar()|, except that a number
3465 result is converted to a string.
3466
Shougo Matsushita79d599b2022-05-07 12:48:29 +01003467getcmdcompltype() *getcmdcompltype()*
3468 Return the type of the current command-line completion.
3469 Only works when the command line is being edited, thus
3470 requires use of |c_CTRL-\_e| or |c_CTRL-R_=|.
Bram Moolenaar921bde82022-05-09 19:50:35 +01003471 See |:command-completion| for the return string.
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01003472 Also see |getcmdtype()|, |setcmdpos()|, |getcmdline()| and
3473 |setcmdline()|.
Shougo Matsushita79d599b2022-05-07 12:48:29 +01003474 Returns an empty string when completion is not defined.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003475
3476getcmdline() *getcmdline()*
3477 Return the current command-line. Only works when the command
3478 line is being edited, thus requires use of |c_CTRL-\_e| or
3479 |c_CTRL-R_=|.
3480 Example: >
3481 :cmap <F7> <C-\>eescape(getcmdline(), ' \')<CR>
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01003482< Also see |getcmdtype()|, |getcmdpos()|, |setcmdpos()| and
3483 |setcmdline()|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003484 Returns an empty string when entering a password or using
3485 |inputsecret()|.
3486
3487getcmdpos() *getcmdpos()*
3488 Return the position of the cursor in the command line as a
3489 byte count. The first column is 1.
3490 Only works when editing the command line, thus requires use of
3491 |c_CTRL-\_e| or |c_CTRL-R_=| or an expression mapping.
3492 Returns 0 otherwise.
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01003493 Also see |getcmdtype()|, |setcmdpos()|, |getcmdline()| and
3494 |setcmdline()|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003495
Shougo Matsushita79d599b2022-05-07 12:48:29 +01003496getcmdscreenpos() *getcmdscreenpos()*
3497 Return the screen position of the cursor in the command line
3498 as a byte count. The first column is 1.
3499 Instead of |getcmdpos()|, it adds the prompt position.
3500 Only works when editing the command line, thus requires use of
3501 |c_CTRL-\_e| or |c_CTRL-R_=| or an expression mapping.
3502 Returns 0 otherwise.
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01003503 Also see |getcmdpos()|, |setcmdpos()|, |getcmdline()| and
3504 |setcmdline()|.
Shougo Matsushita79d599b2022-05-07 12:48:29 +01003505
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003506getcmdtype() *getcmdtype()*
3507 Return the current command-line type. Possible return values
3508 are:
3509 : normal Ex command
3510 > debug mode command |debug-mode|
3511 / forward search command
3512 ? backward search command
3513 @ |input()| command
3514 - |:insert| or |:append| command
3515 = |i_CTRL-R_=|
3516 Only works when editing the command line, thus requires use of
3517 |c_CTRL-\_e| or |c_CTRL-R_=| or an expression mapping.
3518 Returns an empty string otherwise.
3519 Also see |getcmdpos()|, |setcmdpos()| and |getcmdline()|.
3520
3521getcmdwintype() *getcmdwintype()*
3522 Return the current |command-line-window| type. Possible return
3523 values are the same as |getcmdtype()|. Returns an empty string
3524 when not in the command-line window.
3525
3526getcompletion({pat}, {type} [, {filtered}]) *getcompletion()*
3527 Return a list of command-line completion matches. The String
3528 {type} argument specifies what for. The following completion
3529 types are supported:
3530
3531 arglist file names in argument list
3532 augroup autocmd groups
3533 buffer buffer names
Bram Moolenaar6e2e2cc2022-03-14 19:24:46 +00003534 behave |:behave| suboptions
3535 breakpoint |:breakadd| and |:breakdel| suboptions
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003536 color color schemes
3537 command Ex command
3538 cmdline |cmdline-completion| result
3539 compiler compilers
3540 cscope |:cscope| suboptions
3541 diff_buffer |:diffget| and |:diffput| completion
3542 dir directory names
3543 environment environment variable names
3544 event autocommand events
3545 expression Vim expression
3546 file file and directory names
3547 file_in_path file and directory names in |'path'|
3548 filetype filetype names |'filetype'|
3549 function function name
3550 help help subjects
3551 highlight highlight groups
Bram Moolenaar6e2e2cc2022-03-14 19:24:46 +00003552 history |:history| suboptions
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003553 locale locale names (as output of locale -a)
3554 mapclear buffer argument
3555 mapping mapping name
3556 menu menus
3557 messages |:messages| suboptions
3558 option options
3559 packadd optional package |pack-add| names
zeertzjq5c8771b2023-01-24 12:34:03 +00003560 runtime |:runtime| completion
Yegappan Lakshmanan454ce672022-03-24 11:22:13 +00003561 scriptnames sourced script names |:scriptnames|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003562 shellcmd Shell command
3563 sign |:sign| suboptions
3564 syntax syntax file names |'syntax'|
3565 syntime |:syntime| suboptions
3566 tag tags
3567 tag_listfiles tags, file names
3568 user user names
3569 var user variables
3570
3571 If {pat} is an empty string, then all the matches are
3572 returned. Otherwise only items matching {pat} are returned.
3573 See |wildcards| for the use of special characters in {pat}.
3574
3575 If the optional {filtered} flag is set to 1, then 'wildignore'
3576 is applied to filter the results. Otherwise all the matches
3577 are returned. The 'wildignorecase' option always applies.
3578
Yegappan Lakshmanane7dd0fa2022-03-22 16:06:31 +00003579 If the 'wildoptions' option contains 'fuzzy', then fuzzy
3580 matching is used to get the completion matches. Otherwise
Yegappan Lakshmanan454ce672022-03-24 11:22:13 +00003581 regular expression matching is used. Thus this function
3582 follows the user preference, what happens on the command line.
3583 If you do not want this you can make 'wildoptions' empty
3584 before calling getcompletion() and restore it afterwards.
Yegappan Lakshmanane7dd0fa2022-03-22 16:06:31 +00003585
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003586 If {type} is "cmdline", then the |cmdline-completion| result is
3587 returned. For example, to complete the possible values after
3588 a ":call" command: >
3589 echo getcompletion('call ', 'cmdline')
3590<
3591 If there are no matches, an empty list is returned. An
3592 invalid value for {type} produces an error.
3593
3594 Can also be used as a |method|: >
3595 GetPattern()->getcompletion('color')
3596<
3597 *getcurpos()*
3598getcurpos([{winid}])
3599 Get the position of the cursor. This is like getpos('.'), but
3600 includes an extra "curswant" item in the list:
3601 [0, lnum, col, off, curswant] ~
3602 The "curswant" number is the preferred column when moving the
naohiro ono56200ee2022-01-01 14:59:44 +00003603 cursor vertically. After |$| command it will be a very large
3604 number equal to |v:maxcol|. Also see |getcursorcharpos()| and
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003605 |getpos()|.
3606 The first "bufnum" item is always zero. The byte position of
3607 the cursor is returned in 'col'. To get the character
3608 position, use |getcursorcharpos()|.
3609
3610 The optional {winid} argument can specify the window. It can
3611 be the window number or the |window-ID|. The last known
3612 cursor position is returned, this may be invalid for the
3613 current value of the buffer if it is not the current window.
3614 If {winid} is invalid a list with zeroes is returned.
3615
3616 This can be used to save and restore the cursor position: >
3617 let save_cursor = getcurpos()
3618 MoveTheCursorAround
3619 call setpos('.', save_cursor)
3620< Note that this only works within the window. See
3621 |winrestview()| for restoring more state.
3622
3623 Can also be used as a |method|: >
3624 GetWinid()->getcurpos()
3625<
3626 *getcursorcharpos()*
3627getcursorcharpos([{winid}])
3628 Same as |getcurpos()| but the column number in the returned
3629 List is a character index instead of a byte index.
3630
3631 Example:
3632 With the cursor on '보' in line 3 with text "여보세요": >
3633 getcursorcharpos() returns [0, 3, 2, 0, 3]
3634 getcurpos() returns [0, 3, 4, 0, 3]
3635<
3636 Can also be used as a |method|: >
3637 GetWinid()->getcursorcharpos()
3638
3639< *getcwd()*
3640getcwd([{winnr} [, {tabnr}]])
3641 The result is a String, which is the name of the current
3642 working directory. 'autochdir' is ignored.
3643
3644 With {winnr} return the local current directory of this window
3645 in the current tab page. {winnr} can be the window number or
3646 the |window-ID|.
3647 If {winnr} is -1 return the name of the global working
3648 directory. See also |haslocaldir()|.
3649
3650 With {winnr} and {tabnr} return the local current directory of
3651 the window in the specified tab page. If {winnr} is -1 return
3652 the working directory of the tabpage.
3653 If {winnr} is zero use the current window, if {tabnr} is zero
3654 use the current tabpage.
3655 Without any arguments, return the actual working directory of
3656 the current window.
3657 Return an empty string if the arguments are invalid.
3658
3659 Examples: >
3660 " Get the working directory of the current window
3661 :echo getcwd()
3662 :echo getcwd(0)
3663 :echo getcwd(0, 0)
3664 " Get the working directory of window 3 in tabpage 2
3665 :echo getcwd(3, 2)
3666 " Get the global working directory
3667 :echo getcwd(-1)
3668 " Get the working directory of tabpage 3
3669 :echo getcwd(-1, 3)
3670 " Get the working directory of current tabpage
3671 :echo getcwd(-1, 0)
3672
3673< Can also be used as a |method|: >
3674 GetWinnr()->getcwd()
3675
3676getenv({name}) *getenv()*
3677 Return the value of environment variable {name}. The {name}
3678 argument is a string, without a leading '$'. Example: >
3679 myHome = getenv('HOME')
3680
3681< When the variable does not exist |v:null| is returned. That
3682 is different from a variable set to an empty string, although
3683 some systems interpret the empty value as the variable being
3684 deleted. See also |expr-env|.
3685
3686 Can also be used as a |method|: >
3687 GetVarname()->getenv()
3688
3689getfontname([{name}]) *getfontname()*
3690 Without an argument returns the name of the normal font being
3691 used. Like what is used for the Normal highlight group
3692 |hl-Normal|.
3693 With an argument a check is done whether String {name} is a
3694 valid font name. If not then an empty string is returned.
3695 Otherwise the actual font name is returned, or {name} if the
3696 GUI does not support obtaining the real name.
3697 Only works when the GUI is running, thus not in your vimrc or
3698 gvimrc file. Use the |GUIEnter| autocommand to use this
3699 function just after the GUI has started.
3700 Note that the GTK GUI accepts any font name, thus checking for
3701 a valid name does not work.
3702
3703getfperm({fname}) *getfperm()*
3704 The result is a String, which is the read, write, and execute
3705 permissions of the given file {fname}.
3706 If {fname} does not exist or its directory cannot be read, an
3707 empty string is returned.
3708 The result is of the form "rwxrwxrwx", where each group of
3709 "rwx" flags represent, in turn, the permissions of the owner
3710 of the file, the group the file belongs to, and other users.
3711 If a user does not have a given permission the flag for this
3712 is replaced with the string "-". Examples: >
3713 :echo getfperm("/etc/passwd")
3714 :echo getfperm(expand("~/.vimrc"))
3715< This will hopefully (from a security point of view) display
3716 the string "rw-r--r--" or even "rw-------".
3717
3718 Can also be used as a |method|: >
3719 GetFilename()->getfperm()
3720<
3721 For setting permissions use |setfperm()|.
3722
3723getfsize({fname}) *getfsize()*
3724 The result is a Number, which is the size in bytes of the
3725 given file {fname}.
3726 If {fname} is a directory, 0 is returned.
3727 If the file {fname} can't be found, -1 is returned.
3728 If the size of {fname} is too big to fit in a Number then -2
3729 is returned.
3730
3731 Can also be used as a |method|: >
3732 GetFilename()->getfsize()
3733
3734getftime({fname}) *getftime()*
3735 The result is a Number, which is the last modification time of
3736 the given file {fname}. The value is measured as seconds
3737 since 1st Jan 1970, and may be passed to strftime(). See also
3738 |localtime()| and |strftime()|.
3739 If the file {fname} can't be found -1 is returned.
3740
3741 Can also be used as a |method|: >
3742 GetFilename()->getftime()
3743
3744getftype({fname}) *getftype()*
3745 The result is a String, which is a description of the kind of
3746 file of the given file {fname}.
3747 If {fname} does not exist an empty string is returned.
3748 Here is a table over different kinds of files and their
3749 results:
3750 Normal file "file"
3751 Directory "dir"
3752 Symbolic link "link"
3753 Block device "bdev"
3754 Character device "cdev"
3755 Socket "socket"
3756 FIFO "fifo"
3757 All other "other"
3758 Example: >
3759 getftype("/home")
3760< Note that a type such as "link" will only be returned on
3761 systems that support it. On some systems only "dir" and
3762 "file" are returned. On MS-Windows a symbolic link to a
3763 directory returns "dir" instead of "link".
3764
3765 Can also be used as a |method|: >
3766 GetFilename()->getftype()
3767
3768getimstatus() *getimstatus()*
3769 The result is a Number, which is |TRUE| when the IME status is
Bram Moolenaar016188f2022-06-06 20:52:59 +01003770 active and |FALSE| otherwise.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003771 See 'imstatusfunc'.
3772
3773getjumplist([{winnr} [, {tabnr}]]) *getjumplist()*
3774 Returns the |jumplist| for the specified window.
3775
3776 Without arguments use the current window.
3777 With {winnr} only use this window in the current tab page.
3778 {winnr} can also be a |window-ID|.
3779 With {winnr} and {tabnr} use the window in the specified tab
Bram Moolenaar016188f2022-06-06 20:52:59 +01003780 page. If {winnr} or {tabnr} is invalid, an empty list is
3781 returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003782
3783 The returned list contains two entries: a list with the jump
3784 locations and the last used jump position number in the list.
3785 Each entry in the jump location list is a dictionary with
3786 the following entries:
3787 bufnr buffer number
3788 col column number
3789 coladd column offset for 'virtualedit'
3790 filename filename if available
3791 lnum line number
3792
3793 Can also be used as a |method|: >
3794 GetWinnr()->getjumplist()
3795
3796< *getline()*
3797getline({lnum} [, {end}])
3798 Without {end} the result is a String, which is line {lnum}
3799 from the current buffer. Example: >
3800 getline(1)
3801< When {lnum} is a String that doesn't start with a
3802 digit, |line()| is called to translate the String into a Number.
3803 To get the line under the cursor: >
3804 getline(".")
3805< When {lnum} is a number smaller than 1 or bigger than the
3806 number of lines in the buffer, an empty string is returned.
3807
3808 When {end} is given the result is a |List| where each item is
3809 a line from the current buffer in the range {lnum} to {end},
3810 including line {end}.
3811 {end} is used in the same way as {lnum}.
3812 Non-existing lines are silently omitted.
3813 When {end} is before {lnum} an empty |List| is returned.
3814 Example: >
3815 :let start = line('.')
3816 :let end = search("^$") - 1
3817 :let lines = getline(start, end)
3818
3819< Can also be used as a |method|: >
3820 ComputeLnum()->getline()
3821
Bram Moolenaarce30ccc2022-11-21 19:57:04 +00003822< To get lines from another buffer see |getbufline()| and
3823 |getbufoneline()|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003824
3825getloclist({nr} [, {what}]) *getloclist()*
3826 Returns a |List| with all the entries in the location list for
3827 window {nr}. {nr} can be the window number or the |window-ID|.
3828 When {nr} is zero the current window is used.
3829
3830 For a location list window, the displayed location list is
3831 returned. For an invalid window number {nr}, an empty list is
3832 returned. Otherwise, same as |getqflist()|.
3833
3834 If the optional {what} dictionary argument is supplied, then
3835 returns the items listed in {what} as a dictionary. Refer to
3836 |getqflist()| for the supported items in {what}.
3837
3838 In addition to the items supported by |getqflist()| in {what},
3839 the following item is supported by |getloclist()|:
3840
3841 filewinid id of the window used to display files
3842 from the location list. This field is
3843 applicable only when called from a
3844 location list window. See
3845 |location-list-file-window| for more
3846 details.
3847
3848 Returns a |Dictionary| with default values if there is no
3849 location list for the window {nr}.
3850 Returns an empty Dictionary if window {nr} does not exist.
3851
3852 Examples (See also |getqflist-examples|): >
3853 :echo getloclist(3, {'all': 0})
3854 :echo getloclist(5, {'filewinid': 0})
3855
3856
3857getmarklist([{buf}]) *getmarklist()*
3858 Without the {buf} argument returns a |List| with information
3859 about all the global marks. |mark|
3860
3861 If the optional {buf} argument is specified, returns the
3862 local marks defined in buffer {buf}. For the use of {buf},
Bram Moolenaar016188f2022-06-06 20:52:59 +01003863 see |bufname()|. If {buf} is invalid, an empty list is
3864 returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003865
3866 Each item in the returned List is a |Dict| with the following:
3867 mark name of the mark prefixed by "'"
3868 pos a |List| with the position of the mark:
3869 [bufnum, lnum, col, off]
3870 Refer to |getpos()| for more information.
3871 file file name
3872
3873 Refer to |getpos()| for getting information about a specific
3874 mark.
3875
3876 Can also be used as a |method|: >
3877 GetBufnr()->getmarklist()
3878
3879getmatches([{win}]) *getmatches()*
3880 Returns a |List| with all matches previously defined for the
3881 current window by |matchadd()| and the |:match| commands.
3882 |getmatches()| is useful in combination with |setmatches()|,
3883 as |setmatches()| can restore a list of matches saved by
3884 |getmatches()|.
3885 If {win} is specified, use the window with this number or
Bram Moolenaar016188f2022-06-06 20:52:59 +01003886 window ID instead of the current window. If {win} is invalid,
3887 an empty list is returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003888 Example: >
3889 :echo getmatches()
3890< [{'group': 'MyGroup1', 'pattern': 'TODO',
3891 'priority': 10, 'id': 1}, {'group': 'MyGroup2',
3892 'pattern': 'FIXME', 'priority': 10, 'id': 2}] >
3893 :let m = getmatches()
3894 :call clearmatches()
3895 :echo getmatches()
3896< [] >
3897 :call setmatches(m)
3898 :echo getmatches()
3899< [{'group': 'MyGroup1', 'pattern': 'TODO',
3900 'priority': 10, 'id': 1}, {'group': 'MyGroup2',
3901 'pattern': 'FIXME', 'priority': 10, 'id': 2}] >
3902 :unlet m
3903<
3904getmousepos() *getmousepos()*
3905 Returns a |Dictionary| with the last known position of the
3906 mouse. This can be used in a mapping for a mouse click or in
3907 a filter of a popup window. The items are:
3908 screenrow screen row
3909 screencol screen column
3910 winid Window ID of the click
3911 winrow row inside "winid"
3912 wincol column inside "winid"
3913 line text line inside "winid"
3914 column text column inside "winid"
3915 All numbers are 1-based.
3916
3917 If not over a window, e.g. when in the command line, then only
3918 "screenrow" and "screencol" are valid, the others are zero.
3919
3920 When on the status line below a window or the vertical
3921 separator right of a window, the "line" and "column" values
3922 are zero.
3923
3924 When the position is after the text then "column" is the
3925 length of the text in bytes plus one.
3926
3927 If the mouse is over a popup window then that window is used.
3928
3929 When using |getchar()| the Vim variables |v:mouse_lnum|,
3930 |v:mouse_col| and |v:mouse_winid| also provide these values.
3931
Bram Moolenaar24dc19c2022-11-14 19:49:15 +00003932getmouseshape() *getmouseshape()*
3933 Returns the name of the currently showing mouse pointer.
3934 When the |+mouseshape| feature is not supported or the shape
3935 is unknown an empty string is returned.
3936 This function is mainly intended for testing.
3937
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003938 *getpid()*
3939getpid() Return a Number which is the process ID of the Vim process.
3940 On Unix and MS-Windows this is a unique number, until Vim
3941 exits.
3942
3943 *getpos()*
3944getpos({expr}) Get the position for String {expr}. For possible values of
3945 {expr} see |line()|. For getting the cursor position see
3946 |getcurpos()|.
3947 The result is a |List| with four numbers:
3948 [bufnum, lnum, col, off]
3949 "bufnum" is zero, unless a mark like '0 or 'A is used, then it
3950 is the buffer number of the mark.
3951 "lnum" and "col" are the position in the buffer. The first
3952 column is 1.
3953 The "off" number is zero, unless 'virtualedit' is used. Then
3954 it is the offset in screen columns from the start of the
3955 character. E.g., a position within a <Tab> or after the last
3956 character.
3957 Note that for '< and '> Visual mode matters: when it is "V"
3958 (visual line mode) the column of '< is zero and the column of
naohiro ono56200ee2022-01-01 14:59:44 +00003959 '> is a large number equal to |v:maxcol|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003960 The column number in the returned List is the byte position
3961 within the line. To get the character position in the line,
3962 use |getcharpos()|.
naohiro ono56200ee2022-01-01 14:59:44 +00003963 A very large column number equal to |v:maxcol| can be returned,
3964 in which case it means "after the end of the line".
Bram Moolenaar016188f2022-06-06 20:52:59 +01003965 If {expr} is invalid, returns a list with all zeros.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003966 This can be used to save and restore the position of a mark: >
3967 let save_a_mark = getpos("'a")
3968 ...
3969 call setpos("'a", save_a_mark)
3970< Also see |getcharpos()|, |getcurpos()| and |setpos()|.
3971
3972 Can also be used as a |method|: >
3973 GetMark()->getpos()
3974
3975getqflist([{what}]) *getqflist()*
3976 Returns a |List| with all the current quickfix errors. Each
3977 list item is a dictionary with these entries:
3978 bufnr number of buffer that has the file name, use
3979 bufname() to get the name
3980 module module name
3981 lnum line number in the buffer (first line is 1)
3982 end_lnum
3983 end of line number if the item is multiline
3984 col column number (first column is 1)
3985 end_col end of column number if the item has range
3986 vcol |TRUE|: "col" is visual column
3987 |FALSE|: "col" is byte index
3988 nr error number
3989 pattern search pattern used to locate the error
3990 text description of the error
3991 type type of the error, 'E', '1', etc.
3992 valid |TRUE|: recognized error message
3993
3994 When there is no error list or it's empty, an empty list is
3995 returned. Quickfix list entries with a non-existing buffer
3996 number are returned with "bufnr" set to zero (Note: some
3997 functions accept buffer number zero for the alternate buffer,
3998 you may need to explicitly check for zero).
3999
4000 Useful application: Find pattern matches in multiple files and
4001 do something with them: >
4002 :vimgrep /theword/jg *.c
4003 :for d in getqflist()
4004 : echo bufname(d.bufnr) ':' d.lnum '=' d.text
4005 :endfor
4006<
4007 If the optional {what} dictionary argument is supplied, then
4008 returns only the items listed in {what} as a dictionary. The
4009 following string items are supported in {what}:
4010 changedtick get the total number of changes made
4011 to the list |quickfix-changedtick|
4012 context get the |quickfix-context|
4013 efm errorformat to use when parsing "lines". If
4014 not present, then the 'errorformat' option
4015 value is used.
4016 id get information for the quickfix list with
4017 |quickfix-ID|; zero means the id for the
4018 current list or the list specified by "nr"
4019 idx get information for the quickfix entry at this
4020 index in the list specified by 'id' or 'nr'.
4021 If set to zero, then uses the current entry.
4022 See |quickfix-index|
4023 items quickfix list entries
4024 lines parse a list of lines using 'efm' and return
4025 the resulting entries. Only a |List| type is
4026 accepted. The current quickfix list is not
4027 modified. See |quickfix-parse|.
4028 nr get information for this quickfix list; zero
4029 means the current quickfix list and "$" means
4030 the last quickfix list
4031 qfbufnr number of the buffer displayed in the quickfix
4032 window. Returns 0 if the quickfix buffer is
4033 not present. See |quickfix-buffer|.
4034 size number of entries in the quickfix list
4035 title get the list title |quickfix-title|
4036 winid get the quickfix |window-ID|
4037 all all of the above quickfix properties
4038 Non-string items in {what} are ignored. To get the value of a
4039 particular item, set it to zero.
4040 If "nr" is not present then the current quickfix list is used.
4041 If both "nr" and a non-zero "id" are specified, then the list
4042 specified by "id" is used.
4043 To get the number of lists in the quickfix stack, set "nr" to
4044 "$" in {what}. The "nr" value in the returned dictionary
4045 contains the quickfix stack size.
4046 When "lines" is specified, all the other items except "efm"
4047 are ignored. The returned dictionary contains the entry
4048 "items" with the list of entries.
4049
4050 The returned dictionary contains the following entries:
4051 changedtick total number of changes made to the
4052 list |quickfix-changedtick|
4053 context quickfix list context. See |quickfix-context|
4054 If not present, set to "".
4055 id quickfix list ID |quickfix-ID|. If not
4056 present, set to 0.
4057 idx index of the quickfix entry in the list. If not
4058 present, set to 0.
4059 items quickfix list entries. If not present, set to
4060 an empty list.
4061 nr quickfix list number. If not present, set to 0
4062 qfbufnr number of the buffer displayed in the quickfix
4063 window. If not present, set to 0.
4064 size number of entries in the quickfix list. If not
4065 present, set to 0.
4066 title quickfix list title text. If not present, set
4067 to "".
4068 winid quickfix |window-ID|. If not present, set to 0
4069
4070 Examples (See also |getqflist-examples|): >
4071 :echo getqflist({'all': 1})
4072 :echo getqflist({'nr': 2, 'title': 1})
4073 :echo getqflist({'lines' : ["F1:10:L10"]})
4074<
4075getreg([{regname} [, 1 [, {list}]]]) *getreg()*
4076 The result is a String, which is the contents of register
4077 {regname}. Example: >
4078 :let cliptext = getreg('*')
4079< When register {regname} was not set the result is an empty
4080 string.
Bram Moolenaara2baa732022-02-04 16:09:54 +00004081 The {regname} argument must be a string. *E1162*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004082
4083 getreg('=') returns the last evaluated value of the expression
4084 register. (For use in maps.)
4085 getreg('=', 1) returns the expression itself, so that it can
4086 be restored with |setreg()|. For other registers the extra
4087 argument is ignored, thus you can always give it.
4088
4089 If {list} is present and |TRUE|, the result type is changed
4090 to |List|. Each list item is one text line. Use it if you care
4091 about zero bytes possibly present inside register: without
4092 third argument both NLs and zero bytes are represented as NLs
4093 (see |NL-used-for-Nul|).
4094 When the register was not set an empty list is returned.
4095
4096 If {regname} is "", the unnamed register '"' is used.
4097 If {regname} is not specified, |v:register| is used.
4098 In |Vim9-script| {regname} must be one character.
4099
4100 Can also be used as a |method|: >
4101 GetRegname()->getreg()
4102
4103getreginfo([{regname}]) *getreginfo()*
4104 Returns detailed information about register {regname} as a
4105 Dictionary with the following entries:
4106 regcontents List of lines contained in register
4107 {regname}, like
4108 |getreg|({regname}, 1, 1).
4109 regtype the type of register {regname}, as in
4110 |getregtype()|.
4111 isunnamed Boolean flag, v:true if this register
4112 is currently pointed to by the unnamed
4113 register.
4114 points_to for the unnamed register, gives the
4115 single letter name of the register
4116 currently pointed to (see |quotequote|).
4117 For example, after deleting a line
4118 with `dd`, this field will be "1",
4119 which is the register that got the
4120 deleted text.
4121
4122 The {regname} argument is a string. If {regname} is invalid
4123 or not set, an empty Dictionary will be returned.
4124 If {regname} is "" or "@", the unnamed register '"' is used.
4125 If {regname} is not specified, |v:register| is used.
4126 The returned Dictionary can be passed to |setreg()|.
4127 In |Vim9-script| {regname} must be one character.
4128
4129 Can also be used as a |method|: >
4130 GetRegname()->getreginfo()
4131
4132getregtype([{regname}]) *getregtype()*
4133 The result is a String, which is type of register {regname}.
4134 The value will be one of:
4135 "v" for |characterwise| text
4136 "V" for |linewise| text
4137 "<CTRL-V>{width}" for |blockwise-visual| text
4138 "" for an empty or unknown register
4139 <CTRL-V> is one character with value 0x16.
4140 The {regname} argument is a string. If {regname} is "", the
4141 unnamed register '"' is used. If {regname} is not specified,
4142 |v:register| is used.
4143 In |Vim9-script| {regname} must be one character.
4144
4145 Can also be used as a |method|: >
4146 GetRegname()->getregtype()
4147
Bram Moolenaar71badf92023-04-22 22:40:14 +01004148getscriptinfo([{opts}]) *getscriptinfo()*
Yegappan Lakshmananf768c3d2022-08-22 13:15:13 +01004149 Returns a |List| with information about all the sourced Vim
Bram Moolenaar753885b2022-08-24 16:30:36 +01004150 scripts in the order they were sourced, like what
4151 `:scriptnames` shows.
Yegappan Lakshmananf768c3d2022-08-22 13:15:13 +01004152
Yegappan Lakshmanan2f892d82022-08-28 18:52:10 +01004153 The optional Dict argument {opts} supports the following
4154 optional items:
4155 name Script name match pattern. If specified,
4156 and "sid" is not specified, information about
Bram Moolenaar71badf92023-04-22 22:40:14 +01004157 scripts with a name that match the pattern
Yegappan Lakshmanan2f892d82022-08-28 18:52:10 +01004158 "name" are returned.
4159 sid Script ID |<SID>|. If specified, only
4160 information about the script with ID "sid" is
4161 returned and "name" is ignored.
4162
Yegappan Lakshmananf768c3d2022-08-22 13:15:13 +01004163 Each item in the returned List is a |Dict| with the following
4164 items:
Yegappan Lakshmanan2f892d82022-08-28 18:52:10 +01004165 autoload Set to TRUE for a script that was used with
Bram Moolenaar753885b2022-08-24 16:30:36 +01004166 `import autoload` but was not actually sourced
4167 yet (see |import-autoload|).
Yegappan Lakshmanan2f892d82022-08-28 18:52:10 +01004168 functions List of script-local function names defined in
4169 the script. Present only when a particular
4170 script is specified using the "sid" item in
4171 {opts}.
4172 name Vim script file name.
4173 sid Script ID |<SID>|.
4174 sourced Script ID of the actually sourced script that
Bram Moolenaarfd999452022-08-24 18:30:14 +01004175 this script name links to, if any, otherwise
4176 zero
Yegappan Lakshmanan2f892d82022-08-28 18:52:10 +01004177 variables A dictionary with the script-local variables.
Bram Moolenaarf1dcd142022-12-31 15:30:45 +00004178 Present only when a particular script is
Yegappan Lakshmanan2f892d82022-08-28 18:52:10 +01004179 specified using the "sid" item in {opts}.
4180 Note that this is a copy, the value of
4181 script-local variables cannot be changed using
4182 this dictionary.
4183 version Vimscript version (|scriptversion|)
Yegappan Lakshmanan520f6ef2022-08-25 17:40:40 +01004184
Yegappan Lakshmanan2f892d82022-08-28 18:52:10 +01004185 Examples: >
4186 :echo getscriptinfo({'name': 'myscript'})
4187 :echo getscriptinfo({'sid': 15}).variables
4188<
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004189gettabinfo([{tabnr}]) *gettabinfo()*
4190 If {tabnr} is not specified, then information about all the
4191 tab pages is returned as a |List|. Each List item is a
4192 |Dictionary|. Otherwise, {tabnr} specifies the tab page
4193 number and information about that one is returned. If the tab
4194 page does not exist an empty List is returned.
4195
4196 Each List item is a |Dictionary| with the following entries:
4197 tabnr tab page number.
4198 variables a reference to the dictionary with
4199 tabpage-local variables
4200 windows List of |window-ID|s in the tab page.
4201
4202 Can also be used as a |method|: >
4203 GetTabnr()->gettabinfo()
4204
4205gettabvar({tabnr}, {varname} [, {def}]) *gettabvar()*
4206 Get the value of a tab-local variable {varname} in tab page
4207 {tabnr}. |t:var|
4208 Tabs are numbered starting with one.
4209 The {varname} argument is a string. When {varname} is empty a
4210 dictionary with all tab-local variables is returned.
4211 Note that the name without "t:" must be used.
4212 When the tab or variable doesn't exist {def} or an empty
4213 string is returned, there is no error message.
4214
4215 Can also be used as a |method|: >
4216 GetTabnr()->gettabvar(varname)
4217
4218gettabwinvar({tabnr}, {winnr}, {varname} [, {def}]) *gettabwinvar()*
4219 Get the value of window-local variable {varname} in window
4220 {winnr} in tab page {tabnr}.
4221 The {varname} argument is a string. When {varname} is empty a
4222 dictionary with all window-local variables is returned.
4223 When {varname} is equal to "&" get the values of all
4224 window-local options in a |Dictionary|.
4225 Otherwise, when {varname} starts with "&" get the value of a
4226 window-local option.
4227 Note that {varname} must be the name without "w:".
4228 Tabs are numbered starting with one. For the current tabpage
4229 use |getwinvar()|.
4230 {winnr} can be the window number or the |window-ID|.
4231 When {winnr} is zero the current window is used.
4232 This also works for a global option, buffer-local option and
4233 window-local option, but it doesn't work for a global variable
4234 or buffer-local variable.
4235 When the tab, window or variable doesn't exist {def} or an
4236 empty string is returned, there is no error message.
4237 Examples: >
4238 :let list_is_on = gettabwinvar(1, 2, '&list')
Bram Moolenaarc51cf032022-02-26 12:25:45 +00004239 :echo "myvar = " .. gettabwinvar(3, 1, 'myvar')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004240<
4241 To obtain all window-local variables use: >
4242 gettabwinvar({tabnr}, {winnr}, '&')
4243
4244< Can also be used as a |method|: >
4245 GetTabnr()->gettabwinvar(winnr, varname)
4246
4247gettagstack([{winnr}]) *gettagstack()*
4248 The result is a Dict, which is the tag stack of window {winnr}.
4249 {winnr} can be the window number or the |window-ID|.
4250 When {winnr} is not specified, the current window is used.
4251 When window {winnr} doesn't exist, an empty Dict is returned.
4252
4253 The returned dictionary contains the following entries:
4254 curidx Current index in the stack. When at
4255 top of the stack, set to (length + 1).
4256 Index of bottom of the stack is 1.
4257 items List of items in the stack. Each item
4258 is a dictionary containing the
4259 entries described below.
4260 length Number of entries in the stack.
4261
4262 Each item in the stack is a dictionary with the following
4263 entries:
4264 bufnr buffer number of the current jump
4265 from cursor position before the tag jump.
4266 See |getpos()| for the format of the
4267 returned list.
4268 matchnr current matching tag number. Used when
4269 multiple matching tags are found for a
4270 name.
4271 tagname name of the tag
4272
4273 See |tagstack| for more information about the tag stack.
4274
4275 Can also be used as a |method|: >
4276 GetWinnr()->gettagstack()
4277
4278
4279gettext({text}) *gettext()*
4280 Translate String {text} if possible.
4281 This is mainly for use in the distributed Vim scripts. When
4282 generating message translations the {text} is extracted by
4283 xgettext, the translator can add the translated message in the
4284 .po file and Vim will lookup the translation when gettext() is
4285 called.
4286 For {text} double quoted strings are preferred, because
4287 xgettext does not understand escaping in single quoted
4288 strings.
4289
4290
4291getwininfo([{winid}]) *getwininfo()*
4292 Returns information about windows as a |List| with Dictionaries.
4293
4294 If {winid} is given Information about the window with that ID
4295 is returned, as a |List| with one item. If the window does not
4296 exist the result is an empty list.
4297
4298 Without {winid} information about all the windows in all the
4299 tab pages is returned.
4300
4301 Each List item is a |Dictionary| with the following entries:
4302 botline last complete displayed buffer line
4303 bufnr number of buffer in the window
4304 height window height (excluding winbar)
4305 loclist 1 if showing a location list
4306 {only with the +quickfix feature}
4307 quickfix 1 if quickfix or location list window
4308 {only with the +quickfix feature}
4309 terminal 1 if a terminal window
4310 {only with the +terminal feature}
4311 tabnr tab page number
4312 topline first displayed buffer line
4313 variables a reference to the dictionary with
4314 window-local variables
4315 width window width
4316 winbar 1 if the window has a toolbar, 0
4317 otherwise
4318 wincol leftmost screen column of the window;
4319 "col" from |win_screenpos()|
4320 textoff number of columns occupied by any
4321 'foldcolumn', 'signcolumn' and line
4322 number in front of the text
4323 winid |window-ID|
4324 winnr window number
4325 winrow topmost screen line of the window;
4326 "row" from |win_screenpos()|
4327
4328 Can also be used as a |method|: >
4329 GetWinnr()->getwininfo()
4330
4331getwinpos([{timeout}]) *getwinpos()*
4332 The result is a |List| with two numbers, the result of
4333 |getwinposx()| and |getwinposy()| combined:
4334 [x-pos, y-pos]
4335 {timeout} can be used to specify how long to wait in msec for
4336 a response from the terminal. When omitted 100 msec is used.
4337 Use a longer time for a remote terminal.
4338 When using a value less than 10 and no response is received
4339 within that time, a previously reported position is returned,
4340 if available. This can be used to poll for the position and
4341 do some work in the meantime: >
4342 while 1
4343 let res = getwinpos(1)
4344 if res[0] >= 0
4345 break
4346 endif
4347 " Do some work here
4348 endwhile
4349<
4350
4351 Can also be used as a |method|: >
4352 GetTimeout()->getwinpos()
4353<
4354 *getwinposx()*
4355getwinposx() The result is a Number, which is the X coordinate in pixels of
4356 the left hand side of the GUI Vim window. Also works for an
4357 xterm (uses a timeout of 100 msec).
4358 The result will be -1 if the information is not available.
4359 The value can be used with `:winpos`.
4360
4361 *getwinposy()*
4362getwinposy() The result is a Number, which is the Y coordinate in pixels of
4363 the top of the GUI Vim window. Also works for an xterm (uses
4364 a timeout of 100 msec).
4365 The result will be -1 if the information is not available.
4366 The value can be used with `:winpos`.
4367
4368getwinvar({winnr}, {varname} [, {def}]) *getwinvar()*
4369 Like |gettabwinvar()| for the current tabpage.
4370 Examples: >
4371 :let list_is_on = getwinvar(2, '&list')
Bram Moolenaarc51cf032022-02-26 12:25:45 +00004372 :echo "myvar = " .. getwinvar(1, 'myvar')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004373
4374< Can also be used as a |method|: >
4375 GetWinnr()->getwinvar(varname)
4376<
4377glob({expr} [, {nosuf} [, {list} [, {alllinks}]]]) *glob()*
4378 Expand the file wildcards in {expr}. See |wildcards| for the
4379 use of special characters.
4380
4381 Unless the optional {nosuf} argument is given and is |TRUE|,
4382 the 'suffixes' and 'wildignore' options apply: Names matching
4383 one of the patterns in 'wildignore' will be skipped and
4384 'suffixes' affect the ordering of matches.
4385 'wildignorecase' always applies.
4386
4387 When {list} is present and it is |TRUE| the result is a |List|
4388 with all matching files. The advantage of using a List is,
4389 you also get filenames containing newlines correctly.
4390 Otherwise the result is a String and when there are several
4391 matches, they are separated by <NL> characters.
4392
4393 If the expansion fails, the result is an empty String or List.
4394
4395 You can also use |readdir()| if you need to do complicated
4396 things, such as limiting the number of matches.
4397
4398 A name for a non-existing file is not included. A symbolic
4399 link is only included if it points to an existing file.
4400 However, when the {alllinks} argument is present and it is
4401 |TRUE| then all symbolic links are included.
4402
4403 For most systems backticks can be used to get files names from
4404 any external command. Example: >
4405 :let tagfiles = glob("`find . -name tags -print`")
4406 :let &tags = substitute(tagfiles, "\n", ",", "g")
4407< The result of the program inside the backticks should be one
4408 item per line. Spaces inside an item are allowed.
4409
4410 See |expand()| for expanding special Vim variables. See
4411 |system()| for getting the raw output of an external command.
4412
4413 Can also be used as a |method|: >
4414 GetExpr()->glob()
4415
4416glob2regpat({string}) *glob2regpat()*
4417 Convert a file pattern, as used by glob(), into a search
4418 pattern. The result can be used to match with a string that
4419 is a file name. E.g. >
4420 if filename =~ glob2regpat('Make*.mak')
4421< This is equivalent to: >
4422 if filename =~ '^Make.*\.mak$'
4423< When {string} is an empty string the result is "^$", match an
4424 empty string.
4425 Note that the result depends on the system. On MS-Windows
4426 a backslash usually means a path separator.
4427
4428 Can also be used as a |method|: >
4429 GetExpr()->glob2regpat()
4430< *globpath()*
4431globpath({path}, {expr} [, {nosuf} [, {list} [, {alllinks}]]])
4432 Perform glob() for String {expr} on all directories in {path}
4433 and concatenate the results. Example: >
4434 :echo globpath(&rtp, "syntax/c.vim")
4435<
4436 {path} is a comma-separated list of directory names. Each
4437 directory name is prepended to {expr} and expanded like with
4438 |glob()|. A path separator is inserted when needed.
4439 To add a comma inside a directory name escape it with a
4440 backslash. Note that on MS-Windows a directory may have a
4441 trailing backslash, remove it if you put a comma after it.
4442 If the expansion fails for one of the directories, there is no
4443 error message.
4444
4445 Unless the optional {nosuf} argument is given and is |TRUE|,
4446 the 'suffixes' and 'wildignore' options apply: Names matching
4447 one of the patterns in 'wildignore' will be skipped and
4448 'suffixes' affect the ordering of matches.
4449
4450 When {list} is present and it is |TRUE| the result is a |List|
4451 with all matching files. The advantage of using a List is, you
4452 also get filenames containing newlines correctly. Otherwise
4453 the result is a String and when there are several matches,
4454 they are separated by <NL> characters. Example: >
4455 :echo globpath(&rtp, "syntax/c.vim", 0, 1)
4456<
4457 {alllinks} is used as with |glob()|.
4458
4459 The "**" item can be used to search in a directory tree.
4460 For example, to find all "README.txt" files in the directories
4461 in 'runtimepath' and below: >
4462 :echo globpath(&rtp, "**/README.txt")
4463< Upwards search and limiting the depth of "**" is not
4464 supported, thus using 'path' will not always work properly.
4465
4466 Can also be used as a |method|, the base is passed as the
4467 second argument: >
4468 GetExpr()->globpath(&rtp)
4469<
4470 *has()*
4471has({feature} [, {check}])
4472 When {check} is omitted or is zero: The result is a Number,
4473 which is 1 if the feature {feature} is supported, zero
4474 otherwise. The {feature} argument is a string, case is
4475 ignored. See |feature-list| below.
4476
4477 When {check} is present and not zero: The result is a Number,
4478 which is 1 if the feature {feature} could ever be supported,
4479 zero otherwise. This is useful to check for a typo in
4480 {feature} and to detect dead code. Keep in mind that an older
4481 Vim version will not know about a feature added later and
4482 features that have been abandoned will not be known by the
4483 current Vim version.
4484
4485 Also see |exists()| and |exists_compiled()|.
4486
4487 Note that to skip code that has a syntax error when the
4488 feature is not available, Vim may skip the rest of the line
4489 and miss a following `endif`. Therefore put the `endif` on a
4490 separate line: >
4491 if has('feature')
4492 let x = this->breaks->without->the->feature
4493 endif
4494< If the `endif` would be moved to the second line as "| endif" it
4495 would not be found.
4496
4497
4498has_key({dict}, {key}) *has_key()*
4499 The result is a Number, which is TRUE if |Dictionary| {dict}
Bram Moolenaare8008642022-08-19 17:15:35 +01004500 has an entry with key {key}. FALSE otherwise.
4501 The {key} argument is a string. In |Vim9| script a number is
4502 also accepted (and converted to a string) but no other types.
4503 In legacy script the usual automatic conversion to string is
4504 done.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004505
4506 Can also be used as a |method|: >
4507 mydict->has_key(key)
4508
4509haslocaldir([{winnr} [, {tabnr}]]) *haslocaldir()*
4510 The result is a Number:
4511 1 when the window has set a local directory via |:lcd|
4512 2 when the tab-page has set a local directory via |:tcd|
4513 0 otherwise.
4514
4515 Without arguments use the current window.
4516 With {winnr} use this window in the current tab page.
4517 With {winnr} and {tabnr} use the window in the specified tab
4518 page.
4519 {winnr} can be the window number or the |window-ID|.
4520 If {winnr} is -1 it is ignored and only the tabpage is used.
4521 Return 0 if the arguments are invalid.
4522 Examples: >
4523 if haslocaldir() == 1
4524 " window local directory case
4525 elseif haslocaldir() == 2
4526 " tab-local directory case
4527 else
4528 " global directory case
4529 endif
4530
4531 " current window
4532 :echo haslocaldir()
4533 :echo haslocaldir(0)
4534 :echo haslocaldir(0, 0)
4535 " window n in current tab page
4536 :echo haslocaldir(n)
4537 :echo haslocaldir(n, 0)
4538 " window n in tab page m
4539 :echo haslocaldir(n, m)
4540 " tab page m
4541 :echo haslocaldir(-1, m)
4542<
4543 Can also be used as a |method|: >
4544 GetWinnr()->haslocaldir()
4545
4546hasmapto({what} [, {mode} [, {abbr}]]) *hasmapto()*
4547 The result is a Number, which is TRUE if there is a mapping
4548 that contains {what} in somewhere in the rhs (what it is
4549 mapped to) and this mapping exists in one of the modes
4550 indicated by {mode}.
4551 The arguments {what} and {mode} are strings.
4552 When {abbr} is there and it is |TRUE| use abbreviations
4553 instead of mappings. Don't forget to specify Insert and/or
4554 Command-line mode.
4555 Both the global mappings and the mappings local to the current
4556 buffer are checked for a match.
4557 If no matching mapping is found FALSE is returned.
4558 The following characters are recognized in {mode}:
4559 n Normal mode
4560 v Visual and Select mode
4561 x Visual mode
4562 s Select mode
4563 o Operator-pending mode
4564 i Insert mode
4565 l Language-Argument ("r", "f", "t", etc.)
4566 c Command-line mode
4567 When {mode} is omitted, "nvo" is used.
4568
4569 This function is useful to check if a mapping already exists
4570 to a function in a Vim script. Example: >
4571 :if !hasmapto('\ABCdoit')
4572 : map <Leader>d \ABCdoit
4573 :endif
4574< This installs the mapping to "\ABCdoit" only if there isn't
4575 already a mapping to "\ABCdoit".
4576
4577 Can also be used as a |method|: >
4578 GetRHS()->hasmapto()
4579
4580histadd({history}, {item}) *histadd()*
4581 Add the String {item} to the history {history} which can be
4582 one of: *hist-names*
4583 "cmd" or ":" command line history
4584 "search" or "/" search pattern history
4585 "expr" or "=" typed expression history
4586 "input" or "@" input line history
4587 "debug" or ">" debug command history
4588 empty the current or last used history
4589 The {history} string does not need to be the whole name, one
4590 character is sufficient.
4591 If {item} does already exist in the history, it will be
4592 shifted to become the newest entry.
4593 The result is a Number: TRUE if the operation was successful,
4594 otherwise FALSE is returned.
4595
4596 Example: >
4597 :call histadd("input", strftime("%Y %b %d"))
4598 :let date=input("Enter date: ")
4599< This function is not available in the |sandbox|.
4600
4601 Can also be used as a |method|, the base is passed as the
4602 second argument: >
4603 GetHistory()->histadd('search')
4604
4605histdel({history} [, {item}]) *histdel()*
4606 Clear {history}, i.e. delete all its entries. See |hist-names|
4607 for the possible values of {history}.
4608
4609 If the parameter {item} evaluates to a String, it is used as a
4610 regular expression. All entries matching that expression will
4611 be removed from the history (if there are any).
4612 Upper/lowercase must match, unless "\c" is used |/\c|.
4613 If {item} evaluates to a Number, it will be interpreted as
4614 an index, see |:history-indexing|. The respective entry will
4615 be removed if it exists.
4616
4617 The result is TRUE for a successful operation, otherwise FALSE
4618 is returned.
4619
4620 Examples:
4621 Clear expression register history: >
4622 :call histdel("expr")
4623<
4624 Remove all entries starting with "*" from the search history: >
4625 :call histdel("/", '^\*')
4626<
4627 The following three are equivalent: >
4628 :call histdel("search", histnr("search"))
4629 :call histdel("search", -1)
Bram Moolenaarc51cf032022-02-26 12:25:45 +00004630 :call histdel("search", '^' .. histget("search", -1) .. '$')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004631<
4632 To delete the last search pattern and use the last-but-one for
4633 the "n" command and 'hlsearch': >
4634 :call histdel("search", -1)
4635 :let @/ = histget("search", -1)
4636<
4637 Can also be used as a |method|: >
4638 GetHistory()->histdel()
4639
4640histget({history} [, {index}]) *histget()*
4641 The result is a String, the entry with Number {index} from
4642 {history}. See |hist-names| for the possible values of
4643 {history}, and |:history-indexing| for {index}. If there is
4644 no such entry, an empty String is returned. When {index} is
4645 omitted, the most recent item from the history is used.
4646
4647 Examples:
4648 Redo the second last search from history. >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00004649 :execute '/' .. histget("search", -2)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004650
4651< Define an Ex command ":H {num}" that supports re-execution of
4652 the {num}th entry from the output of |:history|. >
4653 :command -nargs=1 H execute histget("cmd", 0+<args>)
4654<
4655 Can also be used as a |method|: >
4656 GetHistory()->histget()
4657
4658histnr({history}) *histnr()*
4659 The result is the Number of the current entry in {history}.
4660 See |hist-names| for the possible values of {history}.
4661 If an error occurred, -1 is returned.
4662
4663 Example: >
4664 :let inp_index = histnr("expr")
4665
4666< Can also be used as a |method|: >
4667 GetHistory()->histnr()
4668<
4669hlexists({name}) *hlexists()*
4670 The result is a Number, which is TRUE if a highlight group
4671 called {name} exists. This is when the group has been
4672 defined in some way. Not necessarily when highlighting has
4673 been defined for it, it may also have been used for a syntax
4674 item.
4675 *highlight_exists()*
4676 Obsolete name: highlight_exists().
4677
4678 Can also be used as a |method|: >
4679 GetName()->hlexists()
4680<
4681hlget([{name} [, {resolve}]]) *hlget()*
4682 Returns a List of all the highlight group attributes. If the
4683 optional {name} is specified, then returns a List with only
4684 the attributes of the specified highlight group. Returns an
4685 empty List if the highlight group {name} is not present.
4686
4687 If the optional {resolve} argument is set to v:true and the
4688 highlight group {name} is linked to another group, then the
4689 link is resolved recursively and the attributes of the
4690 resolved highlight group are returned.
4691
4692 Each entry in the returned List is a Dictionary with the
4693 following items:
4694 cleared boolean flag, set to v:true if the highlight
4695 group attributes are cleared or not yet
4696 specified. See |highlight-clear|.
4697 cterm cterm attributes. See |highlight-cterm|.
4698 ctermbg cterm background color.
4699 See |highlight-ctermbg|.
4700 ctermfg cterm foreground color.
4701 See |highlight-ctermfg|.
4702 ctermul cterm underline color. See |highlight-ctermul|.
4703 default boolean flag, set to v:true if the highlight
4704 group link is a default link. See
4705 |highlight-default|.
4706 font highlight group font. See |highlight-font|.
4707 gui gui attributes. See |highlight-gui|.
4708 guibg gui background color. See |highlight-guibg|.
4709 guifg gui foreground color. See |highlight-guifg|.
4710 guisp gui special color. See |highlight-guisp|.
4711 id highlight group ID.
4712 linksto linked highlight group name.
4713 See |:highlight-link|.
4714 name highlight group name. See |group-name|.
4715 start start terminal keycode. See |highlight-start|.
4716 stop stop terminal keycode. See |highlight-stop|.
4717 term term attributes. See |highlight-term|.
4718
4719 The 'term', 'cterm' and 'gui' items in the above Dictionary
4720 have a dictionary value with the following optional boolean
4721 items: 'bold', 'standout', 'underline', 'undercurl', 'italic',
4722 'reverse', 'inverse' and 'strikethrough'.
4723
4724 Example(s): >
4725 :echo hlget()
4726 :echo hlget('ModeMsg')
4727 :echo hlget('Number', v:true)
4728<
4729 Can also be used as a |method|: >
4730 GetName()->hlget()
4731<
4732hlset({list}) *hlset()*
4733 Creates or modifies the attributes of a List of highlight
4734 groups. Each item in {list} is a dictionary containing the
4735 attributes of a highlight group. See |hlget()| for the list of
4736 supported items in this dictionary.
4737
4738 In addition to the items described in |hlget()|, the following
4739 additional items are supported in the dictionary:
4740
4741 force boolean flag to force the creation of
4742 a link for an existing highlight group
4743 with attributes.
4744
4745 The highlight group is identified using the 'name' item and
4746 the 'id' item (if supplied) is ignored. If a highlight group
4747 with a specified name doesn't exist, then it is created.
4748 Otherwise the attributes of an existing highlight group are
4749 modified.
4750
4751 If an empty dictionary value is used for the 'term' or 'cterm'
4752 or 'gui' entries, then the corresponding attributes are
4753 cleared. If the 'cleared' item is set to v:true, then all the
4754 attributes of the highlight group are cleared.
4755
4756 The 'linksto' item can be used to link a highlight group to
4757 another highlight group. See |:highlight-link|.
4758
4759 Returns zero for success, -1 for failure.
4760
4761 Example(s): >
4762 " add bold attribute to the Visual highlight group
4763 :call hlset([#{name: 'Visual',
4764 \ term: #{reverse: 1 , bold: 1}}])
4765 :call hlset([#{name: 'Type', guifg: 'DarkGreen'}])
4766 :let l = hlget()
4767 :call hlset(l)
4768 " clear the Search highlight group
4769 :call hlset([#{name: 'Search', cleared: v:true}])
4770 " clear the 'term' attributes for a highlight group
4771 :call hlset([#{name: 'Title', term: {}}])
4772 " create the MyHlg group linking it to DiffAdd
4773 :call hlset([#{name: 'MyHlg', linksto: 'DiffAdd'}])
4774 " remove the MyHlg group link
4775 :call hlset([#{name: 'MyHlg', linksto: 'NONE'}])
4776 " clear the attributes and a link
4777 :call hlset([#{name: 'MyHlg', cleared: v:true,
4778 \ linksto: 'NONE'}])
4779<
4780 Can also be used as a |method|: >
4781 GetAttrList()->hlset()
4782<
4783 *hlID()*
4784hlID({name}) The result is a Number, which is the ID of the highlight group
4785 with name {name}. When the highlight group doesn't exist,
4786 zero is returned.
4787 This can be used to retrieve information about the highlight
4788 group. For example, to get the background color of the
4789 "Comment" group: >
4790 :echo synIDattr(synIDtrans(hlID("Comment")), "bg")
4791< *highlightID()*
4792 Obsolete name: highlightID().
4793
4794 Can also be used as a |method|: >
4795 GetName()->hlID()
4796
4797hostname() *hostname()*
4798 The result is a String, which is the name of the machine on
4799 which Vim is currently running. Machine names greater than
4800 256 characters long are truncated.
4801
4802iconv({string}, {from}, {to}) *iconv()*
4803 The result is a String, which is the text {string} converted
4804 from encoding {from} to encoding {to}.
4805 When the conversion completely fails an empty string is
4806 returned. When some characters could not be converted they
4807 are replaced with "?".
4808 The encoding names are whatever the iconv() library function
4809 can accept, see ":!man 3 iconv".
4810 Most conversions require Vim to be compiled with the |+iconv|
4811 feature. Otherwise only UTF-8 to latin1 conversion and back
4812 can be done.
4813 This can be used to display messages with special characters,
4814 no matter what 'encoding' is set to. Write the message in
4815 UTF-8 and use: >
4816 echo iconv(utf8_str, "utf-8", &enc)
4817< Note that Vim uses UTF-8 for all Unicode encodings, conversion
4818 from/to UCS-2 is automatically changed to use UTF-8. You
4819 cannot use UCS-2 in a string anyway, because of the NUL bytes.
4820
4821 Can also be used as a |method|: >
4822 GetText()->iconv('latin1', 'utf-8')
4823<
4824 *indent()*
4825indent({lnum}) The result is a Number, which is indent of line {lnum} in the
4826 current buffer. The indent is counted in spaces, the value
4827 of 'tabstop' is relevant. {lnum} is used just like in
4828 |getline()|.
4829 When {lnum} is invalid -1 is returned. In |Vim9| script an
4830 error is given.
4831
4832 Can also be used as a |method|: >
4833 GetLnum()->indent()
4834
4835index({object}, {expr} [, {start} [, {ic}]]) *index()*
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01004836 Find {expr} in {object} and return its index. See
Yegappan Lakshmanan3fbf6cd2022-08-13 21:35:13 +01004837 |indexof()| for using a lambda to select the item.
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01004838
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004839 If {object} is a |List| return the lowest index where the item
4840 has a value equal to {expr}. There is no automatic
4841 conversion, so the String "4" is different from the Number 4.
4842 And the number 4 is different from the Float 4.0. The value
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01004843 of 'ignorecase' is not used here, case matters as indicated by
4844 the {ic} argument.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004845
4846 If {object} is |Blob| return the lowest index where the byte
4847 value is equal to {expr}.
4848
4849 If {start} is given then start looking at the item with index
4850 {start} (may be negative for an item relative to the end).
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01004851
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004852 When {ic} is given and it is |TRUE|, ignore case. Otherwise
4853 case must match.
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01004854
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004855 -1 is returned when {expr} is not found in {object}.
4856 Example: >
4857 :let idx = index(words, "the")
4858 :if index(numbers, 123) >= 0
4859
4860< Can also be used as a |method|: >
4861 GetObject()->index(what)
4862
Yegappan Lakshmanan3fbf6cd2022-08-13 21:35:13 +01004863indexof({object}, {expr} [, {opts}]) *indexof()*
4864 Returns the index of an item in {object} where {expr} is
4865 v:true. {object} must be a |List| or a |Blob|.
4866
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01004867 If {object} is a |List|, evaluate {expr} for each item in the
Yegappan Lakshmanan3fbf6cd2022-08-13 21:35:13 +01004868 List until the expression is v:true and return the index of
4869 this item.
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01004870
4871 If {object} is a |Blob| evaluate {expr} for each byte in the
Yegappan Lakshmanan3fbf6cd2022-08-13 21:35:13 +01004872 Blob until the expression is v:true and return the index of
4873 this byte.
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01004874
4875 {expr} must be a |string| or |Funcref|.
4876
4877 If {expr} is a |string|: If {object} is a |List|, inside
4878 {expr} |v:key| has the index of the current List item and
4879 |v:val| has the value of the item. If {object} is a |Blob|,
4880 inside {expr} |v:key| has the index of the current byte and
4881 |v:val| has the byte value.
4882
4883 If {expr} is a |Funcref| it must take two arguments:
4884 1. the key or the index of the current item.
4885 2. the value of the current item.
4886 The function must return |TRUE| if the item is found and the
4887 search should stop.
4888
Yegappan Lakshmanan3fbf6cd2022-08-13 21:35:13 +01004889 The optional argument {opts} is a Dict and supports the
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01004890 following items:
Yegappan Lakshmanan3fbf6cd2022-08-13 21:35:13 +01004891 startidx start evaluating {expr} at the item with this
4892 index; may be negative for an item relative to
4893 the end
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01004894 Returns -1 when {expr} evaluates to v:false for all the items.
4895 Example: >
Yegappan Lakshmanan3fbf6cd2022-08-13 21:35:13 +01004896 :let l = [#{n: 10}, #{n: 20}, #{n: 30}]
4897 :echo indexof(l, "v:val.n == 20")
4898 :echo indexof(l, {i, v -> v.n == 30})
4899 :echo indexof(l, "v:val.n == 20", #{startidx: 1})
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01004900
4901< Can also be used as a |method|: >
4902 mylist->indexof(expr)
4903
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004904input({prompt} [, {text} [, {completion}]]) *input()*
4905 The result is a String, which is whatever the user typed on
4906 the command-line. The {prompt} argument is either a prompt
4907 string, or a blank string (for no prompt). A '\n' can be used
4908 in the prompt to start a new line.
4909 The highlighting set with |:echohl| is used for the prompt.
4910 The input is entered just like a command-line, with the same
4911 editing commands and mappings. There is a separate history
4912 for lines typed for input().
4913 Example: >
4914 :if input("Coffee or beer? ") == "beer"
4915 : echo "Cheers!"
4916 :endif
4917<
4918 If the optional {text} argument is present and not empty, this
4919 is used for the default reply, as if the user typed this.
4920 Example: >
4921 :let color = input("Color? ", "white")
4922
4923< The optional {completion} argument specifies the type of
4924 completion supported for the input. Without it completion is
4925 not performed. The supported completion types are the same as
4926 that can be supplied to a user-defined command using the
4927 "-complete=" argument. Refer to |:command-completion| for
4928 more information. Example: >
4929 let fname = input("File: ", "", "file")
4930<
4931 NOTE: This function must not be used in a startup file, for
4932 the versions that only run in GUI mode (e.g., the Win32 GUI).
4933 Note: When input() is called from within a mapping it will
4934 consume remaining characters from that mapping, because a
4935 mapping is handled like the characters were typed.
4936 Use |inputsave()| before input() and |inputrestore()|
4937 after input() to avoid that. Another solution is to avoid
4938 that further characters follow in the mapping, e.g., by using
4939 |:execute| or |:normal|.
4940
4941 Example with a mapping: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00004942 :nmap \x :call GetFoo()<CR>:exe "/" .. Foo<CR>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004943 :function GetFoo()
4944 : call inputsave()
4945 : let g:Foo = input("enter search pattern: ")
4946 : call inputrestore()
4947 :endfunction
4948
4949< Can also be used as a |method|: >
4950 GetPrompt()->input()
4951
4952inputdialog({prompt} [, {text} [, {cancelreturn}]]) *inputdialog()*
4953 Like |input()|, but when the GUI is running and text dialogs
4954 are supported, a dialog window pops up to input the text.
4955 Example: >
4956 :let n = inputdialog("value for shiftwidth", shiftwidth())
4957 :if n != ""
4958 : let &sw = n
4959 :endif
4960< When the dialog is cancelled {cancelreturn} is returned. When
4961 omitted an empty string is returned.
4962 Hitting <Enter> works like pressing the OK button. Hitting
4963 <Esc> works like pressing the Cancel button.
4964 NOTE: Command-line completion is not supported.
4965
4966 Can also be used as a |method|: >
4967 GetPrompt()->inputdialog()
4968
4969inputlist({textlist}) *inputlist()*
4970 {textlist} must be a |List| of strings. This |List| is
4971 displayed, one string per line. The user will be prompted to
4972 enter a number, which is returned.
4973 The user can also select an item by clicking on it with the
4974 mouse, if the mouse is enabled in the command line ('mouse' is
4975 "a" or includes "c"). For the first string 0 is returned.
4976 When clicking above the first item a negative number is
4977 returned. When clicking on the prompt one more than the
4978 length of {textlist} is returned.
4979 Make sure {textlist} has less than 'lines' entries, otherwise
4980 it won't work. It's a good idea to put the entry number at
4981 the start of the string. And put a prompt in the first item.
4982 Example: >
4983 let color = inputlist(['Select color:', '1. red',
4984 \ '2. green', '3. blue'])
4985
4986< Can also be used as a |method|: >
4987 GetChoices()->inputlist()
4988
4989inputrestore() *inputrestore()*
4990 Restore typeahead that was saved with a previous |inputsave()|.
4991 Should be called the same number of times inputsave() is
4992 called. Calling it more often is harmless though.
4993 Returns TRUE when there is nothing to restore, FALSE otherwise.
4994
4995inputsave() *inputsave()*
4996 Preserve typeahead (also from mappings) and clear it, so that
4997 a following prompt gets input from the user. Should be
4998 followed by a matching inputrestore() after the prompt. Can
4999 be used several times, in which case there must be just as
5000 many inputrestore() calls.
5001 Returns TRUE when out of memory, FALSE otherwise.
5002
5003inputsecret({prompt} [, {text}]) *inputsecret()*
5004 This function acts much like the |input()| function with but
5005 two exceptions:
5006 a) the user's response will be displayed as a sequence of
5007 asterisks ("*") thereby keeping the entry secret, and
5008 b) the user's response will not be recorded on the input
5009 |history| stack.
5010 The result is a String, which is whatever the user actually
5011 typed on the command-line in response to the issued prompt.
5012 NOTE: Command-line completion is not supported.
5013
5014 Can also be used as a |method|: >
5015 GetPrompt()->inputsecret()
5016
5017insert({object}, {item} [, {idx}]) *insert()*
5018 When {object} is a |List| or a |Blob| insert {item} at the start
5019 of it.
5020
5021 If {idx} is specified insert {item} before the item with index
5022 {idx}. If {idx} is zero it goes before the first item, just
5023 like omitting {idx}. A negative {idx} is also possible, see
5024 |list-index|. -1 inserts just before the last item.
5025
5026 Returns the resulting |List| or |Blob|. Examples: >
5027 :let mylist = insert([2, 3, 5], 1)
5028 :call insert(mylist, 4, -1)
5029 :call insert(mylist, 6, len(mylist))
5030< The last example can be done simpler with |add()|.
5031 Note that when {item} is a |List| it is inserted as a single
5032 item. Use |extend()| to concatenate |Lists|.
5033
5034 Can also be used as a |method|: >
5035 mylist->insert(item)
5036
5037interrupt() *interrupt()*
5038 Interrupt script execution. It works more or less like the
5039 user typing CTRL-C, most commands won't execute and control
5040 returns to the user. This is useful to abort execution
5041 from lower down, e.g. in an autocommand. Example: >
5042 :function s:check_typoname(file)
5043 : if fnamemodify(a:file, ':t') == '['
5044 : echomsg 'Maybe typo'
5045 : call interrupt()
5046 : endif
5047 :endfunction
5048 :au BufWritePre * call s:check_typoname(expand('<amatch>'))
5049
5050invert({expr}) *invert()*
5051 Bitwise invert. The argument is converted to a number. A
5052 List, Dict or Float argument causes an error. Example: >
5053 :let bits = invert(bits)
5054< Can also be used as a |method|: >
5055 :let bits = bits->invert()
5056
Bram Moolenaar8a3b8052022-06-26 12:21:15 +01005057isabsolutepath({path}) *isabsolutepath()*
LemonBoydca1d402022-04-28 15:26:33 +01005058 The result is a Number, which is |TRUE| when {path} is an
5059 absolute path.
Bram Moolenaar8a3b8052022-06-26 12:21:15 +01005060 On Unix, a path is considered absolute when it starts with '/'.
LemonBoydca1d402022-04-28 15:26:33 +01005061 On MS-Windows, it is considered absolute when it starts with an
5062 optional drive prefix and is followed by a '\' or '/'. UNC paths
5063 are always absolute.
5064 Example: >
5065 echo isabsolutepath('/usr/share/') " 1
5066 echo isabsolutepath('./foobar') " 0
5067 echo isabsolutepath('C:\Windows') " 1
5068 echo isabsolutepath('foobar') " 0
5069 echo isabsolutepath('\\remote\file') " 1
Bram Moolenaar8a3b8052022-06-26 12:21:15 +01005070<
LemonBoydca1d402022-04-28 15:26:33 +01005071 Can also be used as a |method|: >
5072 GetName()->isabsolutepath()
5073
5074
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005075isdirectory({directory}) *isdirectory()*
5076 The result is a Number, which is |TRUE| when a directory
5077 with the name {directory} exists. If {directory} doesn't
5078 exist, or isn't a directory, the result is |FALSE|. {directory}
5079 is any expression, which is used as a String.
5080
5081 Can also be used as a |method|: >
5082 GetName()->isdirectory()
5083
5084isinf({expr}) *isinf()*
5085 Return 1 if {expr} is a positive infinity, or -1 a negative
5086 infinity, otherwise 0. >
5087 :echo isinf(1.0 / 0.0)
5088< 1 >
5089 :echo isinf(-1.0 / 0.0)
5090< -1
5091
5092 Can also be used as a |method|: >
5093 Compute()->isinf()
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005094
5095islocked({expr}) *islocked()* *E786*
5096 The result is a Number, which is |TRUE| when {expr} is the
5097 name of a locked variable.
5098 The string argument {expr} must be the name of a variable,
5099 |List| item or |Dictionary| entry, not the variable itself!
5100 Example: >
5101 :let alist = [0, ['a', 'b'], 2, 3]
5102 :lockvar 1 alist
5103 :echo islocked('alist') " 1
5104 :echo islocked('alist[1]') " 0
5105
Bram Moolenaar9da17d72022-02-09 21:50:44 +00005106< When {expr} is a variable that does not exist -1 is returned.
5107 If {expr} uses a range, list or dict index that is out of
5108 range or does not exist you get an error message. Use
5109 |exists()| to check for existence.
5110 In Vim9 script it does not work for local function variables.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005111
5112 Can also be used as a |method|: >
5113 GetName()->islocked()
5114
5115isnan({expr}) *isnan()*
5116 Return |TRUE| if {expr} is a float with value NaN. >
5117 echo isnan(0.0 / 0.0)
5118< 1
5119
5120 Can also be used as a |method|: >
5121 Compute()->isnan()
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005122
5123items({dict}) *items()*
5124 Return a |List| with all the key-value pairs of {dict}. Each
5125 |List| item is a list with two items: the key of a {dict}
5126 entry and the value of this entry. The |List| is in arbitrary
5127 order. Also see |keys()| and |values()|.
5128 Example: >
5129 for [key, value] in items(mydict)
Bram Moolenaarc51cf032022-02-26 12:25:45 +00005130 echo key .. ': ' .. value
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005131 endfor
5132
5133< Can also be used as a |method|: >
5134 mydict->items()
5135
5136job_ functions are documented here: |job-functions-details|
5137
5138
5139join({list} [, {sep}]) *join()*
5140 Join the items in {list} together into one String.
5141 When {sep} is specified it is put in between the items. If
5142 {sep} is omitted a single space is used.
5143 Note that {sep} is not added at the end. You might want to
5144 add it there too: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00005145 let lines = join(mylist, "\n") .. "\n"
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005146< String items are used as-is. |Lists| and |Dictionaries| are
5147 converted into a string like with |string()|.
5148 The opposite function is |split()|.
5149
5150 Can also be used as a |method|: >
5151 mylist->join()
5152
5153js_decode({string}) *js_decode()*
5154 This is similar to |json_decode()| with these differences:
5155 - Object key names do not have to be in quotes.
5156 - Strings can be in single quotes.
5157 - Empty items in an array (between two commas) are allowed and
5158 result in v:none items.
5159
5160 Can also be used as a |method|: >
5161 ReadObject()->js_decode()
5162
5163js_encode({expr}) *js_encode()*
5164 This is similar to |json_encode()| with these differences:
5165 - Object key names are not in quotes.
5166 - v:none items in an array result in an empty item between
5167 commas.
5168 For example, the Vim object:
5169 [1,v:none,{"one":1},v:none] ~
5170 Will be encoded as:
5171 [1,,{one:1},,] ~
5172 While json_encode() would produce:
5173 [1,null,{"one":1},null] ~
5174 This encoding is valid for JavaScript. It is more efficient
5175 than JSON, especially when using an array with optional items.
5176
5177 Can also be used as a |method|: >
5178 GetObject()->js_encode()
5179
Bram Moolenaar2f0936c2022-01-08 21:51:59 +00005180json_decode({string}) *json_decode()* *E491*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005181 This parses a JSON formatted string and returns the equivalent
5182 in Vim values. See |json_encode()| for the relation between
5183 JSON and Vim values.
5184 The decoding is permissive:
5185 - A trailing comma in an array and object is ignored, e.g.
5186 "[1, 2, ]" is the same as "[1, 2]".
5187 - Integer keys are accepted in objects, e.g. {1:2} is the
5188 same as {"1":2}.
5189 - More floating point numbers are recognized, e.g. "1." for
5190 "1.0", or "001.2" for "1.2". Special floating point values
5191 "Infinity", "-Infinity" and "NaN" (capitalization ignored)
5192 are accepted.
5193 - Leading zeroes in integer numbers are ignored, e.g. "012"
5194 for "12" or "-012" for "-12".
5195 - Capitalization is ignored in literal names null, true or
5196 false, e.g. "NULL" for "null", "True" for "true".
5197 - Control characters U+0000 through U+001F which are not
5198 escaped in strings are accepted, e.g. " " (tab
5199 character in string) for "\t".
5200 - An empty JSON expression or made of only spaces is accepted
5201 and results in v:none.
5202 - Backslash in an invalid 2-character sequence escape is
5203 ignored, e.g. "\a" is decoded as "a".
5204 - A correct surrogate pair in JSON strings should normally be
5205 a 12 character sequence such as "\uD834\uDD1E", but
5206 json_decode() silently accepts truncated surrogate pairs
5207 such as "\uD834" or "\uD834\u"
5208 *E938*
5209 A duplicate key in an object, valid in rfc7159, is not
5210 accepted by json_decode() as the result must be a valid Vim
5211 type, e.g. this fails: {"a":"b", "a":"c"}
5212
5213 Can also be used as a |method|: >
5214 ReadObject()->json_decode()
5215
5216json_encode({expr}) *json_encode()*
5217 Encode {expr} as JSON and return this as a string.
5218 The encoding is specified in:
5219 https://tools.ietf.org/html/rfc7159.html
Bram Moolenaara2baa732022-02-04 16:09:54 +00005220 Vim values are converted as follows: *E1161*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005221 |Number| decimal number
5222 |Float| floating point number
5223 Float nan "NaN"
5224 Float inf "Infinity"
5225 Float -inf "-Infinity"
5226 |String| in double quotes (possibly null)
5227 |Funcref| not possible, error
5228 |List| as an array (possibly null); when
5229 used recursively: []
5230 |Dict| as an object (possibly null); when
5231 used recursively: {}
5232 |Blob| as an array of the individual bytes
5233 v:false "false"
5234 v:true "true"
5235 v:none "null"
5236 v:null "null"
5237 Note that NaN and Infinity are passed on as values. This is
5238 missing in the JSON standard, but several implementations do
5239 allow it. If not then you will get an error.
Bram Moolenaarcbaff5e2022-04-08 17:45:08 +01005240 If a string contains an illegal character then the replacement
5241 character 0xfffd is used.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005242
5243 Can also be used as a |method|: >
5244 GetObject()->json_encode()
5245
5246keys({dict}) *keys()*
5247 Return a |List| with all the keys of {dict}. The |List| is in
5248 arbitrary order. Also see |items()| and |values()|.
5249
5250 Can also be used as a |method|: >
5251 mydict->keys()
5252
zeertzjqcdc83932022-09-12 13:38:41 +01005253keytrans({string}) *keytrans()*
5254 Turn the internal byte representation of keys into a form that
5255 can be used for |:map|. E.g. >
5256 :let xx = "\<C-Home>"
5257 :echo keytrans(xx)
5258< <C-Home>
5259
5260 Can also be used as a |method|: >
5261 "\<C-Home>"->keytrans()
5262
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005263< *len()* *E701*
5264len({expr}) The result is a Number, which is the length of the argument.
5265 When {expr} is a String or a Number the length in bytes is
5266 used, as with |strlen()|.
5267 When {expr} is a |List| the number of items in the |List| is
5268 returned.
5269 When {expr} is a |Blob| the number of bytes is returned.
5270 When {expr} is a |Dictionary| the number of entries in the
5271 |Dictionary| is returned.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01005272 Otherwise an error is given and returns zero.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005273
5274 Can also be used as a |method|: >
5275 mylist->len()
5276
5277< *libcall()* *E364* *E368*
5278libcall({libname}, {funcname}, {argument})
5279 Call function {funcname} in the run-time library {libname}
5280 with single argument {argument}.
5281 This is useful to call functions in a library that you
5282 especially made to be used with Vim. Since only one argument
5283 is possible, calling standard library functions is rather
5284 limited.
5285 The result is the String returned by the function. If the
5286 function returns NULL, this will appear as an empty string ""
5287 to Vim.
5288 If the function returns a number, use libcallnr()!
5289 If {argument} is a number, it is passed to the function as an
5290 int; if {argument} is a string, it is passed as a
5291 null-terminated string.
5292 This function will fail in |restricted-mode|.
5293
5294 libcall() allows you to write your own 'plug-in' extensions to
5295 Vim without having to recompile the program. It is NOT a
5296 means to call system functions! If you try to do so Vim will
5297 very probably crash.
5298
5299 For Win32, the functions you write must be placed in a DLL
5300 and use the normal C calling convention (NOT Pascal which is
5301 used in Windows System DLLs). The function must take exactly
5302 one parameter, either a character pointer or a long integer,
5303 and must return a character pointer or NULL. The character
5304 pointer returned must point to memory that will remain valid
5305 after the function has returned (e.g. in static data in the
5306 DLL). If it points to allocated memory, that memory will
5307 leak away. Using a static buffer in the function should work,
5308 it's then freed when the DLL is unloaded.
5309
5310 WARNING: If the function returns a non-valid pointer, Vim may
5311 crash! This also happens if the function returns a number,
5312 because Vim thinks it's a pointer.
5313 For Win32 systems, {libname} should be the filename of the DLL
5314 without the ".DLL" suffix. A full path is only required if
5315 the DLL is not in the usual places.
5316 For Unix: When compiling your own plugins, remember that the
5317 object code must be compiled as position-independent ('PIC').
5318 {only in Win32 and some Unix versions, when the |+libcall|
5319 feature is present}
5320 Examples: >
5321 :echo libcall("libc.so", "getenv", "HOME")
5322
5323< Can also be used as a |method|, the base is passed as the
5324 third argument: >
5325 GetValue()->libcall("libc.so", "getenv")
5326<
5327 *libcallnr()*
5328libcallnr({libname}, {funcname}, {argument})
5329 Just like |libcall()|, but used for a function that returns an
5330 int instead of a string.
5331 {only in Win32 on some Unix versions, when the |+libcall|
5332 feature is present}
5333 Examples: >
5334 :echo libcallnr("/usr/lib/libc.so", "getpid", "")
5335 :call libcallnr("libc.so", "printf", "Hello World!\n")
5336 :call libcallnr("libc.so", "sleep", 10)
5337<
5338 Can also be used as a |method|, the base is passed as the
5339 third argument: >
5340 GetValue()->libcallnr("libc.so", "printf")
5341<
5342
5343line({expr} [, {winid}]) *line()*
5344 The result is a Number, which is the line number of the file
5345 position given with {expr}. The {expr} argument is a string.
Bram Moolenaara2baa732022-02-04 16:09:54 +00005346 The accepted positions are: *E1209*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005347 . the cursor position
5348 $ the last line in the current buffer
5349 'x position of mark x (if the mark is not set, 0 is
5350 returned)
5351 w0 first line visible in current window (one if the
5352 display isn't updated, e.g. in silent Ex mode)
5353 w$ last line visible in current window (this is one
5354 less than "w0" if no lines are visible)
5355 v In Visual mode: the start of the Visual area (the
5356 cursor is the end). When not in Visual mode
5357 returns the cursor position. Differs from |'<| in
5358 that it's updated right away.
5359 Note that a mark in another file can be used. The line number
5360 then applies to another buffer.
5361 To get the column number use |col()|. To get both use
5362 |getpos()|.
5363 With the optional {winid} argument the values are obtained for
5364 that window instead of the current window.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01005365 Returns 0 for invalid values of {expr} and {winid}.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005366 Examples: >
5367 line(".") line number of the cursor
5368 line(".", winid) idem, in window "winid"
5369 line("'t") line number of mark t
Bram Moolenaarc51cf032022-02-26 12:25:45 +00005370 line("'" .. marker) line number of mark marker
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005371<
5372 To jump to the last known position when opening a file see
5373 |last-position-jump|.
5374
5375 Can also be used as a |method|: >
5376 GetValue()->line()
5377
5378line2byte({lnum}) *line2byte()*
5379 Return the byte count from the start of the buffer for line
5380 {lnum}. This includes the end-of-line character, depending on
5381 the 'fileformat' option for the current buffer. The first
5382 line returns 1. 'encoding' matters, 'fileencoding' is ignored.
5383 This can also be used to get the byte count for the line just
5384 below the last line: >
5385 line2byte(line("$") + 1)
5386< This is the buffer size plus one. If 'fileencoding' is empty
5387 it is the file size plus one. {lnum} is used like with
5388 |getline()|. When {lnum} is invalid, or the |+byte_offset|
5389 feature has been disabled at compile time, -1 is returned.
5390 Also see |byte2line()|, |go| and |:goto|.
5391
5392 Can also be used as a |method|: >
5393 GetLnum()->line2byte()
5394
5395lispindent({lnum}) *lispindent()*
5396 Get the amount of indent for line {lnum} according the lisp
5397 indenting rules, as with 'lisp'.
5398 The indent is counted in spaces, the value of 'tabstop' is
5399 relevant. {lnum} is used just like in |getline()|.
Bram Moolenaar8e145b82022-05-21 20:17:31 +01005400 When {lnum} is invalid -1 is returned. In |Vim9| script an
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005401 error is given.
5402
5403 Can also be used as a |method|: >
5404 GetLnum()->lispindent()
5405
5406list2blob({list}) *list2blob()*
5407 Return a Blob concatenating all the number values in {list}.
5408 Examples: >
5409 list2blob([1, 2, 3, 4]) returns 0z01020304
5410 list2blob([]) returns 0z
5411< Returns an empty Blob on error. If one of the numbers is
5412 negative or more than 255 error *E1239* is given.
5413
5414 |blob2list()| does the opposite.
5415
5416 Can also be used as a |method|: >
5417 GetList()->list2blob()
5418
5419list2str({list} [, {utf8}]) *list2str()*
5420 Convert each number in {list} to a character string can
5421 concatenate them all. Examples: >
5422 list2str([32]) returns " "
5423 list2str([65, 66, 67]) returns "ABC"
5424< The same can be done (slowly) with: >
5425 join(map(list, {nr, val -> nr2char(val)}), '')
5426< |str2list()| does the opposite.
5427
5428 When {utf8} is omitted or zero, the current 'encoding' is used.
5429 When {utf8} is TRUE, always return UTF-8 characters.
5430 With UTF-8 composing characters work as expected: >
5431 list2str([97, 769]) returns "á"
5432<
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01005433 Returns an empty string on error.
5434
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005435 Can also be used as a |method|: >
5436 GetList()->list2str()
5437
5438listener_add({callback} [, {buf}]) *listener_add()*
5439 Add a callback function that will be invoked when changes have
5440 been made to buffer {buf}.
5441 {buf} refers to a buffer name or number. For the accepted
5442 values, see |bufname()|. When {buf} is omitted the current
5443 buffer is used.
5444 Returns a unique ID that can be passed to |listener_remove()|.
5445
5446 The {callback} is invoked with five arguments:
Bram Moolenaar944697a2022-02-20 19:48:20 +00005447 bufnr the buffer that was changed
5448 start first changed line number
5449 end first line number below the change
5450 added number of lines added, negative if lines were
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005451 deleted
Bram Moolenaar944697a2022-02-20 19:48:20 +00005452 changes a List of items with details about the changes
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005453
5454 Example: >
5455 func Listener(bufnr, start, end, added, changes)
5456 echo 'lines ' .. a:start .. ' until ' .. a:end .. ' changed'
5457 endfunc
5458 call listener_add('Listener', bufnr)
5459
Bram Moolenaar944697a2022-02-20 19:48:20 +00005460< The List cannot be changed. Each item in "changes" is a
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005461 dictionary with these entries:
5462 lnum the first line number of the change
5463 end the first line below the change
5464 added number of lines added; negative if lines were
5465 deleted
5466 col first column in "lnum" that was affected by
5467 the change; one if unknown or the whole line
5468 was affected; this is a byte index, first
5469 character has a value of one.
Bram Moolenaar3c053a12022-10-16 13:11:12 +01005470 When lines are inserted (not when a line is split, e.g. by
5471 typing CR in Insert mode) the values are:
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005472 lnum line above which the new line is added
5473 end equal to "lnum"
5474 added number of lines inserted
5475 col 1
5476 When lines are deleted the values are:
5477 lnum the first deleted line
5478 end the line below the first deleted line, before
5479 the deletion was done
5480 added negative, number of lines deleted
5481 col 1
5482 When lines are changed:
5483 lnum the first changed line
5484 end the line below the last changed line
5485 added 0
5486 col first column with a change or 1
5487
5488 The entries are in the order the changes were made, thus the
5489 most recent change is at the end. The line numbers are valid
5490 when the callback is invoked, but later changes may make them
5491 invalid, thus keeping a copy for later might not work.
5492
5493 The {callback} is invoked just before the screen is updated,
5494 when |listener_flush()| is called or when a change is being
5495 made that changes the line count in a way it causes a line
5496 number in the list of changes to become invalid.
5497
5498 The {callback} is invoked with the text locked, see
5499 |textlock|. If you do need to make changes to the buffer, use
5500 a timer to do this later |timer_start()|.
5501
5502 The {callback} is not invoked when the buffer is first loaded.
5503 Use the |BufReadPost| autocmd event to handle the initial text
5504 of a buffer.
5505 The {callback} is also not invoked when the buffer is
5506 unloaded, use the |BufUnload| autocmd event for that.
5507
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01005508 Returns zero if {callback} or {buf} is invalid.
5509
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005510 Can also be used as a |method|, the base is passed as the
5511 second argument: >
5512 GetBuffer()->listener_add(callback)
5513
5514listener_flush([{buf}]) *listener_flush()*
5515 Invoke listener callbacks for buffer {buf}. If there are no
5516 pending changes then no callbacks are invoked.
5517
5518 {buf} refers to a buffer name or number. For the accepted
5519 values, see |bufname()|. When {buf} is omitted the current
5520 buffer is used.
5521
5522 Can also be used as a |method|: >
5523 GetBuffer()->listener_flush()
5524
5525listener_remove({id}) *listener_remove()*
5526 Remove a listener previously added with listener_add().
5527 Returns FALSE when {id} could not be found, TRUE when {id} was
5528 removed.
5529
5530 Can also be used as a |method|: >
5531 GetListenerId()->listener_remove()
5532
5533localtime() *localtime()*
5534 Return the current time, measured as seconds since 1st Jan
5535 1970. See also |strftime()|, |strptime()| and |getftime()|.
5536
5537
5538log({expr}) *log()*
5539 Return the natural logarithm (base e) of {expr} as a |Float|.
5540 {expr} must evaluate to a |Float| or a |Number| in the range
5541 (0, inf].
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01005542 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005543 Examples: >
5544 :echo log(10)
5545< 2.302585 >
5546 :echo log(exp(5))
5547< 5.0
5548
5549 Can also be used as a |method|: >
5550 Compute()->log()
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005551
5552
5553log10({expr}) *log10()*
5554 Return the logarithm of Float {expr} to base 10 as a |Float|.
5555 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01005556 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005557 Examples: >
5558 :echo log10(1000)
5559< 3.0 >
5560 :echo log10(0.01)
5561< -2.0
5562
5563 Can also be used as a |method|: >
5564 Compute()->log10()
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005565
5566luaeval({expr} [, {expr}]) *luaeval()*
5567 Evaluate Lua expression {expr} and return its result converted
5568 to Vim data structures. Second {expr} may hold additional
5569 argument accessible as _A inside first {expr}.
5570 Strings are returned as they are.
5571 Boolean objects are converted to numbers.
Bram Moolenaar73e28dc2022-09-17 21:08:33 +01005572 Numbers are converted to |Float| values.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005573 Dictionaries and lists obtained by vim.eval() are returned
5574 as-is.
5575 Other objects are returned as zero without any errors.
5576 See |lua-luaeval| for more details.
5577 Note that in a `:def` function local variables are not visible
5578 to {expr}.
5579
5580 Can also be used as a |method|: >
5581 GetExpr()->luaeval()
5582
5583< {only available when compiled with the |+lua| feature}
5584
5585map({expr1}, {expr2}) *map()*
5586 {expr1} must be a |List|, |String|, |Blob| or |Dictionary|.
Bram Moolenaar944697a2022-02-20 19:48:20 +00005587 When {expr1} is a |List| or |Dictionary|, replace each
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005588 item in {expr1} with the result of evaluating {expr2}.
5589 For a |Blob| each byte is replaced.
5590 For a |String|, each character, including composing
5591 characters, is replaced.
5592 If the item type changes you may want to use |mapnew()| to
5593 create a new List or Dictionary. This is required when using
5594 Vim9 script.
5595
5596 {expr2} must be a |String| or |Funcref|.
5597
5598 If {expr2} is a |String|, inside {expr2} |v:val| has the value
5599 of the current item. For a |Dictionary| |v:key| has the key
5600 of the current item and for a |List| |v:key| has the index of
5601 the current item. For a |Blob| |v:key| has the index of the
5602 current byte. For a |String| |v:key| has the index of the
5603 current character.
5604 Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00005605 :call map(mylist, '"> " .. v:val .. " <"')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005606< This puts "> " before and " <" after each item in "mylist".
5607
5608 Note that {expr2} is the result of an expression and is then
5609 used as an expression again. Often it is good to use a
5610 |literal-string| to avoid having to double backslashes. You
5611 still have to double ' quotes
5612
5613 If {expr2} is a |Funcref| it is called with two arguments:
5614 1. The key or the index of the current item.
5615 2. the value of the current item.
Bram Moolenaarb59ae592022-11-23 23:46:31 +00005616 With a legacy script lambda you don't get an error if it only
5617 accepts one argument, but with a Vim9 lambda you get "E1106:
5618 One argument too many", the number of arguments must match.
5619
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005620 The function must return the new value of the item. Example
5621 that changes each value by "key-value": >
5622 func KeyValue(key, val)
Bram Moolenaarc51cf032022-02-26 12:25:45 +00005623 return a:key .. '-' .. a:val
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005624 endfunc
5625 call map(myDict, function('KeyValue'))
5626< It is shorter when using a |lambda|: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00005627 call map(myDict, {key, val -> key .. '-' .. val})
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005628< If you do not use "val" you can leave it out: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00005629 call map(myDict, {key -> 'item: ' .. key})
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005630< If you do not use "key" you can use a short name: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00005631 call map(myDict, {_, val -> 'item: ' .. val})
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005632<
5633 The operation is done in-place for a |List| and |Dictionary|.
5634 If you want it to remain unmodified make a copy first: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00005635 :let tlist = map(copy(mylist), ' v:val .. "\t"')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005636
5637< Returns {expr1}, the |List| or |Dictionary| that was filtered,
5638 or a new |Blob| or |String|.
5639 When an error is encountered while evaluating {expr2} no
5640 further items in {expr1} are processed.
5641 When {expr2} is a Funcref errors inside a function are ignored,
5642 unless it was defined with the "abort" flag.
5643
5644 Can also be used as a |method|: >
5645 mylist->map(expr2)
5646
5647
5648maparg({name} [, {mode} [, {abbr} [, {dict}]]]) *maparg()*
5649 When {dict} is omitted or zero: Return the rhs of mapping
5650 {name} in mode {mode}. The returned String has special
5651 characters translated like in the output of the ":map" command
Ernie Rael09661202022-04-25 14:40:44 +01005652 listing. When {dict} is TRUE a dictionary is returned, see
5653 below. To get a list of all mappings see |maplist()|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005654
5655 When there is no mapping for {name}, an empty String is
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01005656 returned if {dict} is FALSE, otherwise returns an empty Dict.
5657 When the mapping for {name} is empty, then "<Nop>" is
5658 returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005659
5660 The {name} can have special key names, like in the ":map"
5661 command.
5662
5663 {mode} can be one of these strings:
5664 "n" Normal
5665 "v" Visual (including Select)
5666 "o" Operator-pending
5667 "i" Insert
5668 "c" Cmd-line
5669 "s" Select
5670 "x" Visual
5671 "l" langmap |language-mapping|
5672 "t" Terminal-Job
5673 "" Normal, Visual and Operator-pending
5674 When {mode} is omitted, the modes for "" are used.
5675
5676 When {abbr} is there and it is |TRUE| use abbreviations
5677 instead of mappings.
5678
5679 When {dict} is there and it is |TRUE| return a dictionary
5680 containing all the information of the mapping with the
Ernie Rael659c2402022-04-24 18:40:28 +01005681 following items: *mapping-dict*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005682 "lhs" The {lhs} of the mapping as it would be typed
5683 "lhsraw" The {lhs} of the mapping as raw bytes
5684 "lhsrawalt" The {lhs} of the mapping as raw bytes, alternate
5685 form, only present when it differs from "lhsraw"
5686 "rhs" The {rhs} of the mapping as typed.
5687 "silent" 1 for a |:map-silent| mapping, else 0.
5688 "noremap" 1 if the {rhs} of the mapping is not remappable.
5689 "script" 1 if mapping was defined with <script>.
5690 "expr" 1 for an expression mapping (|:map-<expr>|).
5691 "buffer" 1 for a buffer local mapping (|:map-local|).
5692 "mode" Modes for which the mapping is defined. In
5693 addition to the modes mentioned above, these
5694 characters will be used:
5695 " " Normal, Visual and Operator-pending
5696 "!" Insert and Commandline mode
5697 (|mapmode-ic|)
5698 "sid" The script local ID, used for <sid> mappings
Bram Moolenaar71badf92023-04-22 22:40:14 +01005699 (|<SID>|). Negative for special contexts.
Bram Moolenaara9528b32022-01-18 20:51:35 +00005700 "scriptversion" The version of the script. 999999 for
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01005701 |Vim9| script.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005702 "lnum" The line number in "sid", zero if unknown.
5703 "nowait" Do not wait for other, longer mappings.
5704 (|:map-<nowait>|).
Bram Moolenaar921bde82022-05-09 19:50:35 +01005705 "abbr" True if this is an abbreviation |abbreviations|.
Ernie Raeld8f5f762022-05-10 17:50:39 +01005706 "mode_bits" Vim's internal binary representation of "mode".
5707 |mapset()| ignores this; only "mode" is used.
5708 See |maplist()| for usage examples. The values
5709 are from src/vim.h and may change in the future.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005710
5711 The dictionary can be used to restore a mapping with
5712 |mapset()|.
5713
5714 The mappings local to the current buffer are checked first,
5715 then the global mappings.
5716 This function can be used to map a key even when it's already
5717 mapped, and have it do the original mapping too. Sketch: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00005718 exe 'nnoremap <Tab> ==' .. maparg('<Tab>', 'n')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005719
5720< Can also be used as a |method|: >
5721 GetKey()->maparg('n')
5722
5723mapcheck({name} [, {mode} [, {abbr}]]) *mapcheck()*
5724 Check if there is a mapping that matches with {name} in mode
5725 {mode}. See |maparg()| for {mode} and special names in
5726 {name}.
5727 When {abbr} is there and it is |TRUE| use abbreviations
5728 instead of mappings.
5729 A match happens with a mapping that starts with {name} and
5730 with a mapping which is equal to the start of {name}.
5731
5732 matches mapping "a" "ab" "abc" ~
5733 mapcheck("a") yes yes yes
5734 mapcheck("abc") yes yes yes
5735 mapcheck("ax") yes no no
5736 mapcheck("b") no no no
5737
5738 The difference with maparg() is that mapcheck() finds a
5739 mapping that matches with {name}, while maparg() only finds a
5740 mapping for {name} exactly.
5741 When there is no mapping that starts with {name}, an empty
5742 String is returned. If there is one, the RHS of that mapping
5743 is returned. If there are several mappings that start with
5744 {name}, the RHS of one of them is returned. This will be
5745 "<Nop>" if the RHS is empty.
5746 The mappings local to the current buffer are checked first,
5747 then the global mappings.
5748 This function can be used to check if a mapping can be added
5749 without being ambiguous. Example: >
5750 :if mapcheck("_vv") == ""
5751 : map _vv :set guifont=7x13<CR>
5752 :endif
5753< This avoids adding the "_vv" mapping when there already is a
5754 mapping for "_v" or for "_vvv".
5755
5756 Can also be used as a |method|: >
5757 GetKey()->mapcheck('n')
5758
5759
Ernie Rael09661202022-04-25 14:40:44 +01005760maplist([{abbr}]) *maplist()*
5761 Returns a |List| of all mappings. Each List item is a |Dict|,
5762 the same as what is returned by |maparg()|, see
5763 |mapping-dict|. When {abbr} is there and it is |TRUE| use
5764 abbreviations instead of mappings.
5765
5766 Example to show all mappings with 'MultiMatch' in rhs: >
5767 vim9script
5768 echo maplist()->filter(
5769 (_, m) => match(m.rhs, 'MultiMatch') >= 0)
Ernie Raeld8f5f762022-05-10 17:50:39 +01005770< It can be tricky to find mappings for particular |:map-modes|.
5771 |mapping-dict|'s "mode_bits" can simplify this. For example,
5772 the mode_bits for Normal, Insert or Command-line modes are
5773 0x19. To find all the mappings available in those modes you
5774 can do: >
5775 vim9script
5776 var saved_maps = []
5777 for m in maplist()
5778 if and(m.mode_bits, 0x19) != 0
5779 saved_maps->add(m)
5780 endif
5781 endfor
5782 echo saved_maps->mapnew((_, m) => m.lhs)
5783< The values of the mode_bits are defined in Vim's src/vim.h
5784 file and they can be discovered at runtime using
5785 |:map-commands| and "maplist()". Example: >
5786 vim9script
5787 omap xyzzy <Nop>
5788 var op_bit = maplist()->filter(
5789 (_, m) => m.lhs == 'xyzzy')[0].mode_bits
5790 ounmap xyzzy
5791 echo printf("Operator-pending mode bit: 0x%x", op_bit)
Ernie Rael09661202022-04-25 14:40:44 +01005792
5793
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005794mapnew({expr1}, {expr2}) *mapnew()*
5795 Like |map()| but instead of replacing items in {expr1} a new
5796 List or Dictionary is created and returned. {expr1} remains
5797 unchanged. Items can still be changed by {expr2}, if you
5798 don't want that use |deepcopy()| first.
5799
5800
5801mapset({mode}, {abbr}, {dict}) *mapset()*
Ernie Rael51d04d12022-05-04 15:40:22 +01005802mapset({dict})
5803 Restore a mapping from a dictionary, possibly returned by
5804 |maparg()| or |maplist()|. A buffer mapping, when dict.buffer
5805 is true, is set on the current buffer; it is up to the caller
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01005806 to ensure that the intended buffer is the current buffer. This
Ernie Rael51d04d12022-05-04 15:40:22 +01005807 feature allows copying mappings from one buffer to another.
5808 The dict.mode value may restore a single mapping that covers
5809 more than one mode, like with mode values of '!', ' ', 'nox',
5810 or 'v'. *E1276*
5811
5812 In the first form, {mode} and {abbr} should be the same as
5813 for the call to |maparg()|. *E460*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005814 {mode} is used to define the mode in which the mapping is set,
5815 not the "mode" entry in {dict}.
5816 Example for saving and restoring a mapping: >
5817 let save_map = maparg('K', 'n', 0, 1)
5818 nnoremap K somethingelse
5819 ...
5820 call mapset('n', 0, save_map)
5821< Note that if you are going to replace a map in several modes,
Ernie Rael51d04d12022-05-04 15:40:22 +01005822 e.g. with `:map!`, you need to save/restore the mapping for
5823 all of them, when they might differ.
5824
5825 In the second form, with {dict} as the only argument, mode
5826 and abbr are taken from the dict.
5827 Example: >
5828 vim9script
5829 var save_maps = maplist()->filter(
5830 (_, m) => m.lhs == 'K')
5831 nnoremap K somethingelse
5832 cnoremap K somethingelse2
5833 # ...
5834 unmap K
5835 for d in save_maps
5836 mapset(d)
5837 endfor
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005838
5839
5840match({expr}, {pat} [, {start} [, {count}]]) *match()*
5841 When {expr} is a |List| then this returns the index of the
5842 first item where {pat} matches. Each item is used as a
5843 String, |Lists| and |Dictionaries| are used as echoed.
5844
5845 Otherwise, {expr} is used as a String. The result is a
5846 Number, which gives the index (byte offset) in {expr} where
5847 {pat} matches.
5848
5849 A match at the first character or |List| item returns zero.
5850 If there is no match -1 is returned.
5851
5852 For getting submatches see |matchlist()|.
5853 Example: >
5854 :echo match("testing", "ing") " results in 4
5855 :echo match([1, 'x'], '\a') " results in 1
5856< See |string-match| for how {pat} is used.
5857 *strpbrk()*
5858 Vim doesn't have a strpbrk() function. But you can do: >
5859 :let sepidx = match(line, '[.,;: \t]')
5860< *strcasestr()*
5861 Vim doesn't have a strcasestr() function. But you can add
5862 "\c" to the pattern to ignore case: >
5863 :let idx = match(haystack, '\cneedle')
5864<
5865 If {start} is given, the search starts from byte index
5866 {start} in a String or item {start} in a |List|.
5867 The result, however, is still the index counted from the
5868 first character/item. Example: >
5869 :echo match("testing", "ing", 2)
5870< result is again "4". >
5871 :echo match("testing", "ing", 4)
5872< result is again "4". >
5873 :echo match("testing", "t", 2)
5874< result is "3".
5875 For a String, if {start} > 0 then it is like the string starts
5876 {start} bytes later, thus "^" will match at {start}. Except
5877 when {count} is given, then it's like matches before the
5878 {start} byte are ignored (this is a bit complicated to keep it
5879 backwards compatible).
5880 For a String, if {start} < 0, it will be set to 0. For a list
5881 the index is counted from the end.
5882 If {start} is out of range ({start} > strlen({expr}) for a
5883 String or {start} > len({expr}) for a |List|) -1 is returned.
5884
5885 When {count} is given use the {count}'th match. When a match
5886 is found in a String the search for the next one starts one
5887 character further. Thus this example results in 1: >
5888 echo match("testing", "..", 0, 2)
5889< In a |List| the search continues in the next item.
5890 Note that when {count} is added the way {start} works changes,
5891 see above.
5892
5893 See |pattern| for the patterns that are accepted.
5894 The 'ignorecase' option is used to set the ignore-caseness of
5895 the pattern. 'smartcase' is NOT used. The matching is always
5896 done like 'magic' is set and 'cpoptions' is empty.
5897 Note that a match at the start is preferred, thus when the
5898 pattern is using "*" (any number of matches) it tends to find
5899 zero matches at the start instead of a number of matches
5900 further down in the text.
5901
5902 Can also be used as a |method|: >
5903 GetText()->match('word')
5904 GetList()->match('word')
5905<
Bram Moolenaar2f0936c2022-01-08 21:51:59 +00005906 *matchadd()* *E290* *E798* *E799* *E801* *E957*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005907matchadd({group}, {pattern} [, {priority} [, {id} [, {dict}]]])
5908 Defines a pattern to be highlighted in the current window (a
5909 "match"). It will be highlighted with {group}. Returns an
5910 identification number (ID), which can be used to delete the
5911 match using |matchdelete()|. The ID is bound to the window.
5912 Matching is case sensitive and magic, unless case sensitivity
5913 or magicness are explicitly overridden in {pattern}. The
5914 'magic', 'smartcase' and 'ignorecase' options are not used.
5915 The "Conceal" value is special, it causes the match to be
5916 concealed.
5917
5918 The optional {priority} argument assigns a priority to the
5919 match. A match with a high priority will have its
5920 highlighting overrule that of a match with a lower priority.
5921 A priority is specified as an integer (negative numbers are no
5922 exception). If the {priority} argument is not specified, the
5923 default priority is 10. The priority of 'hlsearch' is zero,
5924 hence all matches with a priority greater than zero will
5925 overrule it. Syntax highlighting (see 'syntax') is a separate
5926 mechanism, and regardless of the chosen priority a match will
5927 always overrule syntax highlighting.
5928
5929 The optional {id} argument allows the request for a specific
5930 match ID. If a specified ID is already taken, an error
5931 message will appear and the match will not be added. An ID
5932 is specified as a positive integer (zero excluded). IDs 1, 2
5933 and 3 are reserved for |:match|, |:2match| and |:3match|,
Bram Moolenaar2ecbe532022-07-29 21:36:21 +01005934 respectively. 3 is reserved for use by the |matchparen|
5935 plugin.
Bram Moolenaarb529cfb2022-07-25 15:42:07 +01005936 If the {id} argument is not specified or -1, |matchadd()|
Bram Moolenaar9f573a82022-09-29 13:50:08 +01005937 automatically chooses a free ID, which is at least 1000.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005938
5939 The optional {dict} argument allows for further custom
5940 values. Currently this is used to specify a match specific
5941 conceal character that will be shown for |hl-Conceal|
5942 highlighted matches. The dict can have the following members:
5943
5944 conceal Special character to show instead of the
5945 match (only for |hl-Conceal| highlighted
5946 matches, see |:syn-cchar|)
5947 window Instead of the current window use the
5948 window with this number or window ID.
5949
5950 The number of matches is not limited, as it is the case with
5951 the |:match| commands.
5952
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01005953 Returns -1 on error.
5954
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005955 Example: >
5956 :highlight MyGroup ctermbg=green guibg=green
5957 :let m = matchadd("MyGroup", "TODO")
5958< Deletion of the pattern: >
5959 :call matchdelete(m)
5960
5961< A list of matches defined by |matchadd()| and |:match| are
5962 available from |getmatches()|. All matches can be deleted in
5963 one operation by |clearmatches()|.
5964
5965 Can also be used as a |method|: >
5966 GetGroup()->matchadd('TODO')
5967<
5968 *matchaddpos()*
5969matchaddpos({group}, {pos} [, {priority} [, {id} [, {dict}]]])
5970 Same as |matchadd()|, but requires a list of positions {pos}
5971 instead of a pattern. This command is faster than |matchadd()|
5972 because it does not require to handle regular expressions and
5973 sets buffer line boundaries to redraw screen. It is supposed
5974 to be used when fast match additions and deletions are
5975 required, for example to highlight matching parentheses.
5976
5977 {pos} is a list of positions. Each position can be one of
5978 these:
5979 - A number. This whole line will be highlighted. The first
5980 line has number 1.
5981 - A list with one number, e.g., [23]. The whole line with this
5982 number will be highlighted.
5983 - A list with two numbers, e.g., [23, 11]. The first number is
5984 the line number, the second one is the column number (first
5985 column is 1, the value must correspond to the byte index as
5986 |col()| would return). The character at this position will
5987 be highlighted.
5988 - A list with three numbers, e.g., [23, 11, 3]. As above, but
5989 the third number gives the length of the highlight in bytes.
5990
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01005991 Returns -1 on error.
5992
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005993 Example: >
5994 :highlight MyGroup ctermbg=green guibg=green
5995 :let m = matchaddpos("MyGroup", [[23, 24], 34])
5996< Deletion of the pattern: >
5997 :call matchdelete(m)
5998
5999< Matches added by |matchaddpos()| are returned by
6000 |getmatches()|.
6001
6002 Can also be used as a |method|: >
6003 GetGroup()->matchaddpos([23, 11])
6004
6005matcharg({nr}) *matcharg()*
6006 Selects the {nr} match item, as set with a |:match|,
6007 |:2match| or |:3match| command.
6008 Return a |List| with two elements:
6009 The name of the highlight group used
6010 The pattern used.
6011 When {nr} is not 1, 2 or 3 returns an empty |List|.
6012 When there is no match item set returns ['', ''].
6013 This is useful to save and restore a |:match|.
6014 Highlighting matches using the |:match| commands are limited
6015 to three matches. |matchadd()| does not have this limitation.
6016
6017 Can also be used as a |method|: >
6018 GetMatch()->matcharg()
6019
6020matchdelete({id} [, {win}) *matchdelete()* *E802* *E803*
6021 Deletes a match with ID {id} previously defined by |matchadd()|
6022 or one of the |:match| commands. Returns 0 if successful,
6023 otherwise -1. See example for |matchadd()|. All matches can
6024 be deleted in one operation by |clearmatches()|.
6025 If {win} is specified, use the window with this number or
6026 window ID instead of the current window.
6027
6028 Can also be used as a |method|: >
6029 GetMatch()->matchdelete()
6030
6031matchend({expr}, {pat} [, {start} [, {count}]]) *matchend()*
6032 Same as |match()|, but return the index of first character
6033 after the match. Example: >
6034 :echo matchend("testing", "ing")
6035< results in "7".
6036 *strspn()* *strcspn()*
6037 Vim doesn't have a strspn() or strcspn() function, but you can
6038 do it with matchend(): >
6039 :let span = matchend(line, '[a-zA-Z]')
6040 :let span = matchend(line, '[^a-zA-Z]')
6041< Except that -1 is returned when there are no matches.
6042
6043 The {start}, if given, has the same meaning as for |match()|. >
6044 :echo matchend("testing", "ing", 2)
6045< results in "7". >
6046 :echo matchend("testing", "ing", 5)
6047< result is "-1".
6048 When {expr} is a |List| the result is equal to |match()|.
6049
6050 Can also be used as a |method|: >
6051 GetText()->matchend('word')
6052
6053
6054matchfuzzy({list}, {str} [, {dict}]) *matchfuzzy()*
6055 If {list} is a list of strings, then returns a |List| with all
6056 the strings in {list} that fuzzy match {str}. The strings in
6057 the returned list are sorted based on the matching score.
6058
6059 The optional {dict} argument always supports the following
6060 items:
zeertzjq9af2bc02022-05-11 14:15:37 +01006061 matchseq When this item is present return only matches
6062 that contain the characters in {str} in the
6063 given sequence.
Kazuyuki Miyagi47f1a552022-06-17 18:30:03 +01006064 limit Maximum number of matches in {list} to be
6065 returned. Zero means no limit.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006066
6067 If {list} is a list of dictionaries, then the optional {dict}
6068 argument supports the following additional items:
Yasuhiro Matsumoto9029a6e2022-04-16 12:35:35 +01006069 key Key of the item which is fuzzy matched against
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006070 {str}. The value of this item should be a
6071 string.
6072 text_cb |Funcref| that will be called for every item
6073 in {list} to get the text for fuzzy matching.
6074 This should accept a dictionary item as the
6075 argument and return the text for that item to
6076 use for fuzzy matching.
6077
6078 {str} is treated as a literal string and regular expression
6079 matching is NOT supported. The maximum supported {str} length
6080 is 256.
6081
6082 When {str} has multiple words each separated by white space,
6083 then the list of strings that have all the words is returned.
6084
6085 If there are no matching strings or there is an error, then an
6086 empty list is returned. If length of {str} is greater than
6087 256, then returns an empty list.
6088
Yasuhiro Matsumoto9029a6e2022-04-16 12:35:35 +01006089 When {limit} is given, matchfuzzy() will find up to this
6090 number of matches in {list} and return them in sorted order.
6091
Bram Moolenaar1588bc82022-03-08 21:35:07 +00006092 Refer to |fuzzy-matching| for more information about fuzzy
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006093 matching strings.
6094
6095 Example: >
6096 :echo matchfuzzy(["clay", "crow"], "cay")
6097< results in ["clay"]. >
6098 :echo getbufinfo()->map({_, v -> v.name})->matchfuzzy("ndl")
6099< results in a list of buffer names fuzzy matching "ndl". >
6100 :echo getbufinfo()->matchfuzzy("ndl", {'key' : 'name'})
6101< results in a list of buffer information dicts with buffer
6102 names fuzzy matching "ndl". >
6103 :echo getbufinfo()->matchfuzzy("spl",
6104 \ {'text_cb' : {v -> v.name}})
6105< results in a list of buffer information dicts with buffer
6106 names fuzzy matching "spl". >
6107 :echo v:oldfiles->matchfuzzy("test")
6108< results in a list of file names fuzzy matching "test". >
6109 :let l = readfile("buffer.c")->matchfuzzy("str")
6110< results in a list of lines in "buffer.c" fuzzy matching "str". >
6111 :echo ['one two', 'two one']->matchfuzzy('two one')
6112< results in ['two one', 'one two']. >
6113 :echo ['one two', 'two one']->matchfuzzy('two one',
6114 \ {'matchseq': 1})
6115< results in ['two one'].
6116
6117matchfuzzypos({list}, {str} [, {dict}]) *matchfuzzypos()*
6118 Same as |matchfuzzy()|, but returns the list of matched
6119 strings, the list of character positions where characters
6120 in {str} matches and a list of matching scores. You can
6121 use |byteidx()| to convert a character position to a byte
6122 position.
6123
6124 If {str} matches multiple times in a string, then only the
6125 positions for the best match is returned.
6126
6127 If there are no matching strings or there is an error, then a
6128 list with three empty list items is returned.
6129
6130 Example: >
6131 :echo matchfuzzypos(['testing'], 'tsg')
6132< results in [['testing'], [[0, 2, 6]], [99]] >
6133 :echo matchfuzzypos(['clay', 'lacy'], 'la')
6134< results in [['lacy', 'clay'], [[0, 1], [1, 2]], [153, 133]] >
6135 :echo [{'text': 'hello', 'id' : 10}]->matchfuzzypos('ll', {'key' : 'text'})
6136< results in [[{'id': 10, 'text': 'hello'}], [[2, 3]], [127]]
6137
6138matchlist({expr}, {pat} [, {start} [, {count}]]) *matchlist()*
6139 Same as |match()|, but return a |List|. The first item in the
6140 list is the matched string, same as what matchstr() would
6141 return. Following items are submatches, like "\1", "\2", etc.
6142 in |:substitute|. When an optional submatch didn't match an
6143 empty string is used. Example: >
6144 echo matchlist('acd', '\(a\)\?\(b\)\?\(c\)\?\(.*\)')
6145< Results in: ['acd', 'a', '', 'c', 'd', '', '', '', '', '']
6146 When there is no match an empty list is returned.
6147
6148 You can pass in a List, but that is not very useful.
6149
6150 Can also be used as a |method|: >
6151 GetText()->matchlist('word')
6152
6153matchstr({expr}, {pat} [, {start} [, {count}]]) *matchstr()*
6154 Same as |match()|, but return the matched string. Example: >
6155 :echo matchstr("testing", "ing")
6156< results in "ing".
6157 When there is no match "" is returned.
6158 The {start}, if given, has the same meaning as for |match()|. >
6159 :echo matchstr("testing", "ing", 2)
6160< results in "ing". >
6161 :echo matchstr("testing", "ing", 5)
6162< result is "".
6163 When {expr} is a |List| then the matching item is returned.
6164 The type isn't changed, it's not necessarily a String.
6165
6166 Can also be used as a |method|: >
6167 GetText()->matchstr('word')
6168
6169matchstrpos({expr}, {pat} [, {start} [, {count}]]) *matchstrpos()*
6170 Same as |matchstr()|, but return the matched string, the start
6171 position and the end position of the match. Example: >
6172 :echo matchstrpos("testing", "ing")
6173< results in ["ing", 4, 7].
6174 When there is no match ["", -1, -1] is returned.
6175 The {start}, if given, has the same meaning as for |match()|. >
6176 :echo matchstrpos("testing", "ing", 2)
6177< results in ["ing", 4, 7]. >
6178 :echo matchstrpos("testing", "ing", 5)
6179< result is ["", -1, -1].
6180 When {expr} is a |List| then the matching item, the index
6181 of first item where {pat} matches, the start position and the
6182 end position of the match are returned. >
6183 :echo matchstrpos([1, '__x'], '\a')
6184< result is ["x", 1, 2, 3].
6185 The type isn't changed, it's not necessarily a String.
6186
6187 Can also be used as a |method|: >
6188 GetText()->matchstrpos('word')
6189<
6190
6191 *max()*
6192max({expr}) Return the maximum value of all items in {expr}. Example: >
6193 echo max([apples, pears, oranges])
6194
6195< {expr} can be a |List| or a |Dictionary|. For a Dictionary,
6196 it returns the maximum of all values in the Dictionary.
6197 If {expr} is neither a List nor a Dictionary, or one of the
6198 items in {expr} cannot be used as a Number this results in
6199 an error. An empty |List| or |Dictionary| results in zero.
6200
6201 Can also be used as a |method|: >
6202 mylist->max()
6203
6204
6205menu_info({name} [, {mode}]) *menu_info()*
6206 Return information about the specified menu {name} in
6207 mode {mode}. The menu name should be specified without the
6208 shortcut character ('&'). If {name} is "", then the top-level
6209 menu names are returned.
6210
6211 {mode} can be one of these strings:
6212 "n" Normal
6213 "v" Visual (including Select)
6214 "o" Operator-pending
6215 "i" Insert
6216 "c" Cmd-line
6217 "s" Select
6218 "x" Visual
6219 "t" Terminal-Job
6220 "" Normal, Visual and Operator-pending
6221 "!" Insert and Cmd-line
6222 When {mode} is omitted, the modes for "" are used.
6223
6224 Returns a |Dictionary| containing the following items:
6225 accel menu item accelerator text |menu-text|
6226 display display name (name without '&')
6227 enabled v:true if this menu item is enabled
6228 Refer to |:menu-enable|
6229 icon name of the icon file (for toolbar)
6230 |toolbar-icon|
6231 iconidx index of a built-in icon
6232 modes modes for which the menu is defined. In
6233 addition to the modes mentioned above, these
6234 characters will be used:
6235 " " Normal, Visual and Operator-pending
6236 name menu item name.
6237 noremenu v:true if the {rhs} of the menu item is not
6238 remappable else v:false.
6239 priority menu order priority |menu-priority|
6240 rhs right-hand-side of the menu item. The returned
6241 string has special characters translated like
6242 in the output of the ":menu" command listing.
6243 When the {rhs} of a menu item is empty, then
6244 "<Nop>" is returned.
6245 script v:true if script-local remapping of {rhs} is
6246 allowed else v:false. See |:menu-script|.
6247 shortcut shortcut key (character after '&' in
6248 the menu name) |menu-shortcut|
6249 silent v:true if the menu item is created
6250 with <silent> argument |:menu-silent|
6251 submenus |List| containing the names of
6252 all the submenus. Present only if the menu
6253 item has submenus.
6254
6255 Returns an empty dictionary if the menu item is not found.
6256
6257 Examples: >
6258 :echo menu_info('Edit.Cut')
6259 :echo menu_info('File.Save', 'n')
6260
6261 " Display the entire menu hierarchy in a buffer
6262 func ShowMenu(name, pfx)
6263 let m = menu_info(a:name)
6264 call append(line('$'), a:pfx .. m.display)
6265 for child in m->get('submenus', [])
6266 call ShowMenu(a:name .. '.' .. escape(child, '.'),
6267 \ a:pfx .. ' ')
6268 endfor
6269 endfunc
6270 new
6271 for topmenu in menu_info('').submenus
6272 call ShowMenu(topmenu, '')
6273 endfor
6274<
6275 Can also be used as a |method|: >
6276 GetMenuName()->menu_info('v')
6277
6278
6279< *min()*
6280min({expr}) Return the minimum value of all items in {expr}. Example: >
6281 echo min([apples, pears, oranges])
6282
6283< {expr} can be a |List| or a |Dictionary|. For a Dictionary,
6284 it returns the minimum of all values in the Dictionary.
6285 If {expr} is neither a List nor a Dictionary, or one of the
6286 items in {expr} cannot be used as a Number this results in
6287 an error. An empty |List| or |Dictionary| results in zero.
6288
6289 Can also be used as a |method|: >
6290 mylist->min()
6291
6292< *mkdir()* *E739*
Bram Moolenaar938ae282023-02-20 20:44:55 +00006293mkdir({name} [, {flags} [, {prot}]])
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006294 Create directory {name}.
6295
Bram Moolenaar938ae282023-02-20 20:44:55 +00006296 When {flags} is present it must be a string. An empty string
6297 has no effect.
Bram Moolenaar6f14da12022-09-07 21:30:44 +01006298
Bram Moolenaar938ae282023-02-20 20:44:55 +00006299 If {flags} contains "p" then intermediate directories are
6300 created as necessary.
6301
6302 If {flags} contains "D" then {name} is deleted at the end of
Bram Moolenaar6f14da12022-09-07 21:30:44 +01006303 the current function, as with: >
6304 defer delete({name}, 'd')
6305<
Bram Moolenaar938ae282023-02-20 20:44:55 +00006306 If {flags} contains "R" then {name} is deleted recursively at
Bram Moolenaar6f14da12022-09-07 21:30:44 +01006307 the end of the current function, as with: >
6308 defer delete({name}, 'rf')
6309< Note that when {name} has more than one part and "p" is used
6310 some directories may already exist. Only the first one that
6311 is created and what it contains is scheduled to be deleted.
6312 E.g. when using: >
6313 call mkdir('subdir/tmp/autoload', 'pR')
6314< and "subdir" already exists then "subdir/tmp" will be
6315 scheduled for deletion, like with: >
6316 defer delete('subdir/tmp', 'rf')
6317< Note that if scheduling the defer fails the directory is not
6318 deleted. This should only happen when out of memory.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006319
6320 If {prot} is given it is used to set the protection bits of
6321 the new directory. The default is 0o755 (rwxr-xr-x: r/w for
6322 the user, readable for others). Use 0o700 to make it
6323 unreadable for others. This is only used for the last part of
6324 {name}. Thus if you create /tmp/foo/bar then /tmp/foo will be
6325 created with 0o755.
6326 Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00006327 :call mkdir($HOME .. "/tmp/foo/bar", "p", 0o700)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006328
6329< This function is not available in the |sandbox|.
6330
6331 There is no error if the directory already exists and the "p"
6332 flag is passed (since patch 8.0.1708). However, without the
6333 "p" option the call will fail.
6334
6335 The function result is a Number, which is TRUE if the call was
6336 successful or FALSE if the directory creation failed or partly
6337 failed.
6338
6339 Not available on all systems. To check use: >
6340 :if exists("*mkdir")
6341
6342< Can also be used as a |method|: >
6343 GetName()->mkdir()
6344<
6345 *mode()*
6346mode([expr]) Return a string that indicates the current mode.
6347 If [expr] is supplied and it evaluates to a non-zero Number or
6348 a non-empty String (|non-zero-arg|), then the full mode is
6349 returned, otherwise only the first letter is returned.
6350 Also see |state()|.
6351
6352 n Normal
6353 no Operator-pending
6354 nov Operator-pending (forced characterwise |o_v|)
6355 noV Operator-pending (forced linewise |o_V|)
6356 noCTRL-V Operator-pending (forced blockwise |o_CTRL-V|);
6357 CTRL-V is one character
6358 niI Normal using |i_CTRL-O| in |Insert-mode|
6359 niR Normal using |i_CTRL-O| in |Replace-mode|
6360 niV Normal using |i_CTRL-O| in |Virtual-Replace-mode|
6361 nt Terminal-Normal (insert goes to Terminal-Job mode)
6362 v Visual by character
6363 vs Visual by character using |v_CTRL-O| in Select mode
6364 V Visual by line
6365 Vs Visual by line using |v_CTRL-O| in Select mode
6366 CTRL-V Visual blockwise
6367 CTRL-Vs Visual blockwise using |v_CTRL-O| in Select mode
6368 s Select by character
6369 S Select by line
6370 CTRL-S Select blockwise
6371 i Insert
6372 ic Insert mode completion |compl-generic|
6373 ix Insert mode |i_CTRL-X| completion
6374 R Replace |R|
6375 Rc Replace mode completion |compl-generic|
6376 Rx Replace mode |i_CTRL-X| completion
6377 Rv Virtual Replace |gR|
6378 Rvc Virtual Replace mode completion |compl-generic|
6379 Rvx Virtual Replace mode |i_CTRL-X| completion
6380 c Command-line editing
6381 cv Vim Ex mode |gQ|
6382 ce Normal Ex mode |Q|
6383 r Hit-enter prompt
6384 rm The -- more -- prompt
6385 r? A |:confirm| query of some sort
6386 ! Shell or external command is executing
6387 t Terminal-Job mode: keys go to the job
6388
6389 This is useful in the 'statusline' option or when used
6390 with |remote_expr()| In most other places it always returns
6391 "c" or "n".
6392 Note that in the future more modes and more specific modes may
6393 be added. It's better not to compare the whole string but only
6394 the leading character(s).
6395 Also see |visualmode()|.
6396
6397 Can also be used as a |method|: >
6398 DoFull()->mode()
6399
6400mzeval({expr}) *mzeval()*
6401 Evaluate MzScheme expression {expr} and return its result
6402 converted to Vim data structures.
6403 Numbers and strings are returned as they are.
6404 Pairs (including lists and improper lists) and vectors are
6405 returned as Vim |Lists|.
6406 Hash tables are represented as Vim |Dictionary| type with keys
6407 converted to strings.
6408 All other types are converted to string with display function.
6409 Examples: >
6410 :mz (define l (list 1 2 3))
6411 :mz (define h (make-hash)) (hash-set! h "list" l)
6412 :echo mzeval("l")
6413 :echo mzeval("h")
6414<
6415 Note that in a `:def` function local variables are not visible
6416 to {expr}.
6417
6418 Can also be used as a |method|: >
6419 GetExpr()->mzeval()
6420<
6421 {only available when compiled with the |+mzscheme| feature}
6422
6423nextnonblank({lnum}) *nextnonblank()*
6424 Return the line number of the first line at or below {lnum}
6425 that is not blank. Example: >
6426 if getline(nextnonblank(1)) =~ "Java"
6427< When {lnum} is invalid or there is no non-blank line at or
6428 below it, zero is returned.
6429 {lnum} is used like with |getline()|.
6430 See also |prevnonblank()|.
6431
6432 Can also be used as a |method|: >
6433 GetLnum()->nextnonblank()
6434
6435nr2char({expr} [, {utf8}]) *nr2char()*
6436 Return a string with a single character, which has the number
6437 value {expr}. Examples: >
6438 nr2char(64) returns "@"
6439 nr2char(32) returns " "
6440< When {utf8} is omitted or zero, the current 'encoding' is used.
6441 Example for "utf-8": >
6442 nr2char(300) returns I with bow character
6443< When {utf8} is TRUE, always return UTF-8 characters.
6444 Note that a NUL character in the file is specified with
6445 nr2char(10), because NULs are represented with newline
6446 characters. nr2char(0) is a real NUL and terminates the
6447 string, thus results in an empty string.
6448 To turn a list of character numbers into a string: >
6449 let list = [65, 66, 67]
6450 let str = join(map(list, {_, val -> nr2char(val)}), '')
6451< Result: "ABC"
6452
6453 Can also be used as a |method|: >
6454 GetNumber()->nr2char()
6455
6456or({expr}, {expr}) *or()*
6457 Bitwise OR on the two arguments. The arguments are converted
6458 to a number. A List, Dict or Float argument causes an error.
Bram Moolenaar5a6ec102022-05-27 21:58:00 +01006459 Also see `and()` and `xor()`.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006460 Example: >
6461 :let bits = or(bits, 0x80)
6462< Can also be used as a |method|: >
6463 :let bits = bits->or(0x80)
6464
Bram Moolenaar5a6ec102022-05-27 21:58:00 +01006465< Rationale: The reason this is a function and not using the "|"
6466 character like many languages, is that Vi has always used "|"
6467 to separate commands. In many places it would not be clear if
6468 "|" is an operator or a command separator.
6469
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006470
6471pathshorten({path} [, {len}]) *pathshorten()*
6472 Shorten directory names in the path {path} and return the
6473 result. The tail, the file name, is kept as-is. The other
6474 components in the path are reduced to {len} letters in length.
6475 If {len} is omitted or smaller than 1 then 1 is used (single
6476 letters). Leading '~' and '.' characters are kept. Examples: >
6477 :echo pathshorten('~/.vim/autoload/myfile.vim')
6478< ~/.v/a/myfile.vim ~
6479>
6480 :echo pathshorten('~/.vim/autoload/myfile.vim', 2)
6481< ~/.vi/au/myfile.vim ~
6482 It doesn't matter if the path exists or not.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01006483 Returns an empty string on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006484
6485 Can also be used as a |method|: >
6486 GetDirectories()->pathshorten()
6487
6488perleval({expr}) *perleval()*
6489 Evaluate Perl expression {expr} in scalar context and return
6490 its result converted to Vim data structures. If value can't be
6491 converted, it is returned as a string Perl representation.
6492 Note: If you want an array or hash, {expr} must return a
6493 reference to it.
6494 Example: >
6495 :echo perleval('[1 .. 4]')
6496< [1, 2, 3, 4]
6497
6498 Note that in a `:def` function local variables are not visible
6499 to {expr}.
6500
6501 Can also be used as a |method|: >
6502 GetExpr()->perleval()
6503
6504< {only available when compiled with the |+perl| feature}
6505
6506
6507popup_ functions are documented here: |popup-functions|
6508
6509
6510pow({x}, {y}) *pow()*
6511 Return the power of {x} to the exponent {y} as a |Float|.
6512 {x} and {y} must evaluate to a |Float| or a |Number|.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01006513 Returns 0.0 if {x} or {y} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006514 Examples: >
6515 :echo pow(3, 3)
6516< 27.0 >
6517 :echo pow(2, 16)
6518< 65536.0 >
6519 :echo pow(32, 0.20)
6520< 2.0
6521
6522 Can also be used as a |method|: >
6523 Compute()->pow(3)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006524
6525prevnonblank({lnum}) *prevnonblank()*
6526 Return the line number of the first line at or above {lnum}
6527 that is not blank. Example: >
6528 let ind = indent(prevnonblank(v:lnum - 1))
6529< When {lnum} is invalid or there is no non-blank line at or
6530 above it, zero is returned.
6531 {lnum} is used like with |getline()|.
6532 Also see |nextnonblank()|.
6533
6534 Can also be used as a |method|: >
6535 GetLnum()->prevnonblank()
6536
6537printf({fmt}, {expr1} ...) *printf()*
6538 Return a String with {fmt}, where "%" items are replaced by
6539 the formatted form of their respective arguments. Example: >
6540 printf("%4d: E%d %.30s", lnum, errno, msg)
6541< May result in:
6542 " 99: E42 asdfasdfasdfasdfasdfasdfasdfas" ~
6543
6544 When used as a |method| the base is passed as the second
6545 argument: >
6546 Compute()->printf("result: %d")
Bram Moolenaarcbaff5e2022-04-08 17:45:08 +01006547<
6548 You can use `call()` to pass the items as a list.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006549
Bram Moolenaarcbaff5e2022-04-08 17:45:08 +01006550 Often used items are:
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006551 %s string
6552 %6S string right-aligned in 6 display cells
6553 %6s string right-aligned in 6 bytes
6554 %.9s string truncated to 9 bytes
6555 %c single byte
6556 %d decimal number
6557 %5d decimal number padded with spaces to 5 characters
6558 %x hex number
6559 %04x hex number padded with zeros to at least 4 characters
6560 %X hex number using upper case letters
6561 %o octal number
6562 %08b binary number padded with zeros to at least 8 chars
6563 %f floating point number as 12.23, inf, -inf or nan
6564 %F floating point number as 12.23, INF, -INF or NAN
6565 %e floating point number as 1.23e3, inf, -inf or nan
6566 %E floating point number as 1.23E3, INF, -INF or NAN
6567 %g floating point number, as %f or %e depending on value
6568 %G floating point number, as %F or %E depending on value
6569 %% the % character itself
6570
6571 Conversion specifications start with '%' and end with the
6572 conversion type. All other characters are copied unchanged to
6573 the result.
6574
6575 The "%" starts a conversion specification. The following
6576 arguments appear in sequence:
6577
6578 % [flags] [field-width] [.precision] type
6579
6580 flags
6581 Zero or more of the following flags:
6582
6583 # The value should be converted to an "alternate
6584 form". For c, d, and s conversions, this option
6585 has no effect. For o conversions, the precision
6586 of the number is increased to force the first
6587 character of the output string to a zero (except
6588 if a zero value is printed with an explicit
6589 precision of zero).
6590 For b and B conversions, a non-zero result has
6591 the string "0b" (or "0B" for B conversions)
6592 prepended to it.
6593 For x and X conversions, a non-zero result has
6594 the string "0x" (or "0X" for X conversions)
6595 prepended to it.
6596
6597 0 (zero) Zero padding. For all conversions the converted
6598 value is padded on the left with zeros rather
6599 than blanks. If a precision is given with a
6600 numeric conversion (d, b, B, o, x, and X), the 0
6601 flag is ignored.
6602
6603 - A negative field width flag; the converted value
6604 is to be left adjusted on the field boundary.
6605 The converted value is padded on the right with
6606 blanks, rather than on the left with blanks or
6607 zeros. A - overrides a 0 if both are given.
6608
6609 ' ' (space) A blank should be left before a positive
6610 number produced by a signed conversion (d).
6611
6612 + A sign must always be placed before a number
6613 produced by a signed conversion. A + overrides
6614 a space if both are used.
6615
6616 field-width
6617 An optional decimal digit string specifying a minimum
6618 field width. If the converted value has fewer bytes
6619 than the field width, it will be padded with spaces on
6620 the left (or right, if the left-adjustment flag has
6621 been given) to fill out the field width. For the S
6622 conversion the count is in cells.
6623
6624 .precision
6625 An optional precision, in the form of a period '.'
6626 followed by an optional digit string. If the digit
6627 string is omitted, the precision is taken as zero.
6628 This gives the minimum number of digits to appear for
6629 d, o, x, and X conversions, the maximum number of
6630 bytes to be printed from a string for s conversions,
6631 or the maximum number of cells to be printed from a
6632 string for S conversions.
6633 For floating point it is the number of digits after
6634 the decimal point.
6635
6636 type
6637 A character that specifies the type of conversion to
6638 be applied, see below.
6639
6640 A field width or precision, or both, may be indicated by an
6641 asterisk '*' instead of a digit string. In this case, a
6642 Number argument supplies the field width or precision. A
6643 negative field width is treated as a left adjustment flag
6644 followed by a positive field width; a negative precision is
6645 treated as though it were missing. Example: >
6646 :echo printf("%d: %.*s", nr, width, line)
6647< This limits the length of the text used from "line" to
6648 "width" bytes.
6649
6650 The conversion specifiers and their meanings are:
6651
6652 *printf-d* *printf-b* *printf-B* *printf-o*
6653 *printf-x* *printf-X*
6654 dbBoxX The Number argument is converted to signed decimal
6655 (d), unsigned binary (b and B), unsigned octal (o), or
6656 unsigned hexadecimal (x and X) notation. The letters
6657 "abcdef" are used for x conversions; the letters
6658 "ABCDEF" are used for X conversions.
6659 The precision, if any, gives the minimum number of
6660 digits that must appear; if the converted value
6661 requires fewer digits, it is padded on the left with
6662 zeros.
6663 In no case does a non-existent or small field width
6664 cause truncation of a numeric field; if the result of
6665 a conversion is wider than the field width, the field
6666 is expanded to contain the conversion result.
6667 The 'h' modifier indicates the argument is 16 bits.
6668 The 'l' modifier indicates the argument is 32 bits.
6669 The 'L' modifier indicates the argument is 64 bits.
6670 Generally, these modifiers are not useful. They are
6671 ignored when type is known from the argument.
6672
6673 i alias for d
6674 D alias for ld
6675 U alias for lu
6676 O alias for lo
6677
6678 *printf-c*
6679 c The Number argument is converted to a byte, and the
6680 resulting character is written.
6681
6682 *printf-s*
6683 s The text of the String argument is used. If a
6684 precision is specified, no more bytes than the number
6685 specified are used.
6686 If the argument is not a String type, it is
6687 automatically converted to text with the same format
6688 as ":echo".
6689 *printf-S*
6690 S The text of the String argument is used. If a
6691 precision is specified, no more display cells than the
6692 number specified are used.
6693
6694 *printf-f* *E807*
6695 f F The Float argument is converted into a string of the
6696 form 123.456. The precision specifies the number of
6697 digits after the decimal point. When the precision is
6698 zero the decimal point is omitted. When the precision
6699 is not specified 6 is used. A really big number
6700 (out of range or dividing by zero) results in "inf"
6701 or "-inf" with %f (INF or -INF with %F).
6702 "0.0 / 0.0" results in "nan" with %f (NAN with %F).
6703 Example: >
6704 echo printf("%.2f", 12.115)
6705< 12.12
6706 Note that roundoff depends on the system libraries.
6707 Use |round()| when in doubt.
6708
6709 *printf-e* *printf-E*
6710 e E The Float argument is converted into a string of the
6711 form 1.234e+03 or 1.234E+03 when using 'E'. The
6712 precision specifies the number of digits after the
6713 decimal point, like with 'f'.
6714
6715 *printf-g* *printf-G*
6716 g G The Float argument is converted like with 'f' if the
6717 value is between 0.001 (inclusive) and 10000000.0
6718 (exclusive). Otherwise 'e' is used for 'g' and 'E'
6719 for 'G'. When no precision is specified superfluous
6720 zeroes and '+' signs are removed, except for the zero
6721 immediately after the decimal point. Thus 10000000.0
6722 results in 1.0e7.
6723
6724 *printf-%*
6725 % A '%' is written. No argument is converted. The
6726 complete conversion specification is "%%".
6727
6728 When a Number argument is expected a String argument is also
6729 accepted and automatically converted.
6730 When a Float or String argument is expected a Number argument
6731 is also accepted and automatically converted.
6732 Any other argument type results in an error message.
6733
6734 *E766* *E767*
6735 The number of {exprN} arguments must exactly match the number
6736 of "%" items. If there are not sufficient or too many
6737 arguments an error is given. Up to 18 arguments can be used.
6738
6739
6740prompt_getprompt({buf}) *prompt_getprompt()*
6741 Returns the effective prompt text for buffer {buf}. {buf} can
6742 be a buffer name or number. See |prompt-buffer|.
6743
6744 If the buffer doesn't exist or isn't a prompt buffer, an empty
6745 string is returned.
6746
6747 Can also be used as a |method|: >
6748 GetBuffer()->prompt_getprompt()
6749
6750< {only available when compiled with the |+channel| feature}
6751
6752
6753prompt_setcallback({buf}, {expr}) *prompt_setcallback()*
6754 Set prompt callback for buffer {buf} to {expr}. When {expr}
6755 is an empty string the callback is removed. This has only
6756 effect if {buf} has 'buftype' set to "prompt".
6757
6758 The callback is invoked when pressing Enter. The current
6759 buffer will always be the prompt buffer. A new line for a
6760 prompt is added before invoking the callback, thus the prompt
6761 for which the callback was invoked will be in the last but one
6762 line.
6763 If the callback wants to add text to the buffer, it must
6764 insert it above the last line, since that is where the current
6765 prompt is. This can also be done asynchronously.
6766 The callback is invoked with one argument, which is the text
6767 that was entered at the prompt. This can be an empty string
6768 if the user only typed Enter.
6769 Example: >
6770 call prompt_setcallback(bufnr(), function('s:TextEntered'))
6771 func s:TextEntered(text)
6772 if a:text == 'exit' || a:text == 'quit'
6773 stopinsert
6774 close
6775 else
Bram Moolenaarc51cf032022-02-26 12:25:45 +00006776 call append(line('$') - 1, 'Entered: "' .. a:text .. '"')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006777 " Reset 'modified' to allow the buffer to be closed.
6778 set nomodified
6779 endif
6780 endfunc
6781
6782< Can also be used as a |method|: >
6783 GetBuffer()->prompt_setcallback(callback)
6784
6785< {only available when compiled with the |+channel| feature}
6786
6787prompt_setinterrupt({buf}, {expr}) *prompt_setinterrupt()*
6788 Set a callback for buffer {buf} to {expr}. When {expr} is an
6789 empty string the callback is removed. This has only effect if
6790 {buf} has 'buftype' set to "prompt".
6791
6792 This callback will be invoked when pressing CTRL-C in Insert
6793 mode. Without setting a callback Vim will exit Insert mode,
6794 as in any buffer.
6795
6796 Can also be used as a |method|: >
6797 GetBuffer()->prompt_setinterrupt(callback)
6798
6799< {only available when compiled with the |+channel| feature}
6800
6801prompt_setprompt({buf}, {text}) *prompt_setprompt()*
6802 Set prompt for buffer {buf} to {text}. You most likely want
6803 {text} to end in a space.
6804 The result is only visible if {buf} has 'buftype' set to
6805 "prompt". Example: >
6806 call prompt_setprompt(bufnr(), 'command: ')
6807<
6808 Can also be used as a |method|: >
6809 GetBuffer()->prompt_setprompt('command: ')
6810
6811< {only available when compiled with the |+channel| feature}
6812
6813prop_ functions are documented here: |text-prop-functions|
6814
6815pum_getpos() *pum_getpos()*
6816 If the popup menu (see |ins-completion-menu|) is not visible,
6817 returns an empty |Dictionary|, otherwise, returns a
6818 |Dictionary| with the following keys:
6819 height nr of items visible
6820 width screen cells
6821 row top screen row (0 first row)
6822 col leftmost screen column (0 first col)
6823 size total nr of items
6824 scrollbar |TRUE| if scrollbar is visible
6825
6826 The values are the same as in |v:event| during
6827 |CompleteChanged|.
6828
6829pumvisible() *pumvisible()*
6830 Returns non-zero when the popup menu is visible, zero
6831 otherwise. See |ins-completion-menu|.
6832 This can be used to avoid some things that would remove the
6833 popup menu.
6834
6835py3eval({expr}) *py3eval()*
6836 Evaluate Python expression {expr} and return its result
6837 converted to Vim data structures.
6838 Numbers and strings are returned as they are (strings are
6839 copied though, Unicode strings are additionally converted to
6840 'encoding').
6841 Lists are represented as Vim |List| type.
6842 Dictionaries are represented as Vim |Dictionary| type with
6843 keys converted to strings.
6844 Note that in a `:def` function local variables are not visible
6845 to {expr}.
6846
6847 Can also be used as a |method|: >
6848 GetExpr()->py3eval()
6849
6850< {only available when compiled with the |+python3| feature}
6851
6852 *E858* *E859*
6853pyeval({expr}) *pyeval()*
6854 Evaluate Python expression {expr} and return its result
6855 converted to Vim data structures.
6856 Numbers and strings are returned as they are (strings are
6857 copied though).
6858 Lists are represented as Vim |List| type.
6859 Dictionaries are represented as Vim |Dictionary| type,
6860 non-string keys result in error.
6861 Note that in a `:def` function local variables are not visible
6862 to {expr}.
6863
6864 Can also be used as a |method|: >
6865 GetExpr()->pyeval()
6866
6867< {only available when compiled with the |+python| feature}
6868
6869pyxeval({expr}) *pyxeval()*
6870 Evaluate Python expression {expr} and return its result
6871 converted to Vim data structures.
6872 Uses Python 2 or 3, see |python_x| and 'pyxversion'.
6873 See also: |pyeval()|, |py3eval()|
6874
6875 Can also be used as a |method|: >
6876 GetExpr()->pyxeval()
6877
6878< {only available when compiled with the |+python| or the
6879 |+python3| feature}
6880
6881rand([{expr}]) *rand()* *random*
6882 Return a pseudo-random Number generated with an xoshiro128**
6883 algorithm using seed {expr}. The returned number is 32 bits,
6884 also on 64 bits systems, for consistency.
6885 {expr} can be initialized by |srand()| and will be updated by
6886 rand(). If {expr} is omitted, an internal seed value is used
6887 and updated.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01006888 Returns -1 if {expr} is invalid.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006889
6890 Examples: >
6891 :echo rand()
6892 :let seed = srand()
6893 :echo rand(seed)
6894 :echo rand(seed) % 16 " random number 0 - 15
6895<
6896
6897 *E726* *E727*
6898range({expr} [, {max} [, {stride}]]) *range()*
6899 Returns a |List| with Numbers:
6900 - If only {expr} is specified: [0, 1, ..., {expr} - 1]
6901 - If {max} is specified: [{expr}, {expr} + 1, ..., {max}]
6902 - If {stride} is specified: [{expr}, {expr} + {stride}, ...,
6903 {max}] (increasing {expr} with {stride} each time, not
6904 producing a value past {max}).
6905 When the maximum is one before the start the result is an
6906 empty list. When the maximum is more than one before the
6907 start this is an error.
6908 Examples: >
6909 range(4) " [0, 1, 2, 3]
6910 range(2, 4) " [2, 3, 4]
6911 range(2, 9, 3) " [2, 5, 8]
6912 range(2, -2, -1) " [2, 1, 0, -1, -2]
6913 range(0) " []
6914 range(2, 0) " error!
6915<
6916 Can also be used as a |method|: >
6917 GetExpr()->range()
6918<
6919
K.Takata11df3ae2022-10-19 14:02:40 +01006920readblob({fname} [, {offset} [, {size}]]) *readblob()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006921 Read file {fname} in binary mode and return a |Blob|.
K.Takata11df3ae2022-10-19 14:02:40 +01006922 If {offset} is specified, read the file from the specified
6923 offset. If it is a negative value, it is used as an offset
6924 from the end of the file. E.g., to read the last 12 bytes: >
6925 readblob('file.bin', -12)
6926< If {size} is specified, only the specified size will be read.
6927 E.g. to read the first 100 bytes of a file: >
6928 readblob('file.bin', 0, 100)
6929< If {size} is -1 or omitted, the whole data starting from
6930 {offset} will be read.
K.Takata43625762022-10-20 13:28:51 +01006931 This can be also used to read the data from a character device
6932 on Unix when {size} is explicitly set. Only if the device
6933 supports seeking {offset} can be used. Otherwise it should be
6934 zero. E.g. to read 10 bytes from a serial console: >
6935 readblob('/dev/ttyS0', 0, 10)
6936< When the file can't be opened an error message is given and
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006937 the result is an empty |Blob|.
Bram Moolenaar5b2a3d72022-10-21 11:25:30 +01006938 When the offset is beyond the end of the file the result is an
6939 empty blob.
6940 When trying to read more bytes than are available the result
6941 is truncated.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006942 Also see |readfile()| and |writefile()|.
6943
6944
6945readdir({directory} [, {expr} [, {dict}]]) *readdir()*
6946 Return a list with file and directory names in {directory}.
6947 You can also use |glob()| if you don't need to do complicated
6948 things, such as limiting the number of matches.
6949 The list will be sorted (case sensitive), see the {dict}
6950 argument below for changing the sort order.
6951
6952 When {expr} is omitted all entries are included.
6953 When {expr} is given, it is evaluated to check what to do:
6954 If {expr} results in -1 then no further entries will
6955 be handled.
6956 If {expr} results in 0 then this entry will not be
6957 added to the list.
6958 If {expr} results in 1 then this entry will be added
6959 to the list.
6960 The entries "." and ".." are always excluded.
6961 Each time {expr} is evaluated |v:val| is set to the entry name.
6962 When {expr} is a function the name is passed as the argument.
6963 For example, to get a list of files ending in ".txt": >
6964 readdir(dirname, {n -> n =~ '.txt$'})
6965< To skip hidden and backup files: >
6966 readdir(dirname, {n -> n !~ '^\.\|\~$'})
Bram Moolenaar6f4754b2022-01-23 12:07:04 +00006967< *E857*
6968 The optional {dict} argument allows for further custom
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006969 values. Currently this is used to specify if and how sorting
6970 should be performed. The dict can have the following members:
6971
6972 sort How to sort the result returned from the system.
6973 Valid values are:
6974 "none" do not sort (fastest method)
6975 "case" sort case sensitive (byte value of
6976 each character, technically, using
6977 strcmp()) (default)
6978 "icase" sort case insensitive (technically
6979 using strcasecmp())
6980 "collate" sort using the collation order
6981 of the "POSIX" or "C" |locale|
6982 (technically using strcoll())
6983 Other values are silently ignored.
6984
6985 For example, to get a list of all files in the current
6986 directory without sorting the individual entries: >
6987 readdir('.', '1', #{sort: 'none'})
6988< If you want to get a directory tree: >
6989 function! s:tree(dir)
6990 return {a:dir : map(readdir(a:dir),
6991 \ {_, x -> isdirectory(x) ?
Bram Moolenaarc51cf032022-02-26 12:25:45 +00006992 \ {x : s:tree(a:dir .. '/' .. x)} : x})}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006993 endfunction
6994 echo s:tree(".")
6995<
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01006996 Returns an empty List on error.
6997
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006998 Can also be used as a |method|: >
6999 GetDirName()->readdir()
7000<
7001readdirex({directory} [, {expr} [, {dict}]]) *readdirex()*
7002 Extended version of |readdir()|.
7003 Return a list of Dictionaries with file and directory
7004 information in {directory}.
7005 This is useful if you want to get the attributes of file and
7006 directory at the same time as getting a list of a directory.
7007 This is much faster than calling |readdir()| then calling
7008 |getfperm()|, |getfsize()|, |getftime()| and |getftype()| for
7009 each file and directory especially on MS-Windows.
7010 The list will by default be sorted by name (case sensitive),
7011 the sorting can be changed by using the optional {dict}
7012 argument, see |readdir()|.
7013
7014 The Dictionary for file and directory information has the
7015 following items:
7016 group Group name of the entry. (Only on Unix)
7017 name Name of the entry.
7018 perm Permissions of the entry. See |getfperm()|.
7019 size Size of the entry. See |getfsize()|.
7020 time Timestamp of the entry. See |getftime()|.
7021 type Type of the entry.
7022 On Unix, almost same as |getftype()| except:
7023 Symlink to a dir "linkd"
7024 Other symlink "link"
7025 On MS-Windows:
7026 Normal file "file"
7027 Directory "dir"
7028 Junction "junction"
7029 Symlink to a dir "linkd"
7030 Other symlink "link"
7031 Other reparse point "reparse"
7032 user User name of the entry's owner. (Only on Unix)
7033 On Unix, if the entry is a symlink, the Dictionary includes
7034 the information of the target (except the "type" item).
7035 On MS-Windows, it includes the information of the symlink
7036 itself because of performance reasons.
7037
7038 When {expr} is omitted all entries are included.
7039 When {expr} is given, it is evaluated to check what to do:
7040 If {expr} results in -1 then no further entries will
7041 be handled.
7042 If {expr} results in 0 then this entry will not be
7043 added to the list.
7044 If {expr} results in 1 then this entry will be added
7045 to the list.
7046 The entries "." and ".." are always excluded.
7047 Each time {expr} is evaluated |v:val| is set to a |Dictionary|
7048 of the entry.
7049 When {expr} is a function the entry is passed as the argument.
7050 For example, to get a list of files ending in ".txt": >
7051 readdirex(dirname, {e -> e.name =~ '.txt$'})
7052<
7053 For example, to get a list of all files in the current
7054 directory without sorting the individual entries: >
7055 readdirex(dirname, '1', #{sort: 'none'})
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007056<
7057 Can also be used as a |method|: >
7058 GetDirName()->readdirex()
7059<
7060
7061 *readfile()*
7062readfile({fname} [, {type} [, {max}]])
7063 Read file {fname} and return a |List|, each line of the file
7064 as an item. Lines are broken at NL characters. Macintosh
7065 files separated with CR will result in a single long line
7066 (unless a NL appears somewhere).
7067 All NUL characters are replaced with a NL character.
7068 When {type} contains "b" binary mode is used:
7069 - When the last line ends in a NL an extra empty list item is
7070 added.
7071 - No CR characters are removed.
7072 Otherwise:
7073 - CR characters that appear before a NL are removed.
7074 - Whether the last line ends in a NL or not does not matter.
7075 - When 'encoding' is Unicode any UTF-8 byte order mark is
7076 removed from the text.
7077 When {max} is given this specifies the maximum number of lines
7078 to be read. Useful if you only want to check the first ten
7079 lines of a file: >
7080 :for line in readfile(fname, '', 10)
7081 : if line =~ 'Date' | echo line | endif
7082 :endfor
7083< When {max} is negative -{max} lines from the end of the file
7084 are returned, or as many as there are.
7085 When {max} is zero the result is an empty list.
7086 Note that without {max} the whole file is read into memory.
7087 Also note that there is no recognition of encoding. Read a
7088 file into a buffer if you need to.
7089 Deprecated (use |readblob()| instead): When {type} contains
7090 "B" a |Blob| is returned with the binary data of the file
7091 unmodified.
7092 When the file can't be opened an error message is given and
7093 the result is an empty list.
7094 Also see |writefile()|.
7095
7096 Can also be used as a |method|: >
7097 GetFileName()->readfile()
7098
7099reduce({object}, {func} [, {initial}]) *reduce()* *E998*
7100 {func} is called for every item in {object}, which can be a
7101 |String|, |List| or a |Blob|. {func} is called with two
7102 arguments: the result so far and current item. After
Bram Moolenaarf10911e2022-01-29 22:20:48 +00007103 processing all items the result is returned. *E1132*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007104
7105 {initial} is the initial result. When omitted, the first item
7106 in {object} is used and {func} is first called for the second
7107 item. If {initial} is not given and {object} is empty no
7108 result can be computed, an E998 error is given.
7109
7110 Examples: >
7111 echo reduce([1, 3, 5], { acc, val -> acc + val })
7112 echo reduce(['x', 'y'], { acc, val -> acc .. val }, 'a')
7113 echo reduce(0z1122, { acc, val -> 2 * acc + val })
7114 echo reduce('xyz', { acc, val -> acc .. ',' .. val })
7115<
7116 Can also be used as a |method|: >
7117 echo mylist->reduce({ acc, val -> acc + val }, 0)
7118
7119
7120reg_executing() *reg_executing()*
7121 Returns the single letter name of the register being executed.
7122 Returns an empty string when no register is being executed.
7123 See |@|.
7124
7125reg_recording() *reg_recording()*
7126 Returns the single letter name of the register being recorded.
7127 Returns an empty string when not recording. See |q|.
7128
Bram Moolenaarf269eab2022-10-03 18:04:35 +01007129reltime()
7130reltime({start})
7131reltime({start}, {end}) *reltime()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007132 Return an item that represents a time value. The item is a
7133 list with items that depend on the system. In Vim 9 script
Bram Moolenaar71badf92023-04-22 22:40:14 +01007134 the type list<any> can be used.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007135 The item can be passed to |reltimestr()| to convert it to a
Bram Moolenaarf269eab2022-10-03 18:04:35 +01007136 string or |reltimefloat()| to convert to a Float. For
7137 example, to see the time spent in function Work(): >
7138 var startTime = reltime()
7139 Work()
7140 echo startTime->reltime()->reltimestr()
7141<
Bram Moolenaar016188f2022-06-06 20:52:59 +01007142 Without an argument reltime() returns the current time (the
Bram Moolenaareb490412022-06-28 13:44:46 +01007143 representation is system-dependent, it can not be used as the
Bram Moolenaar016188f2022-06-06 20:52:59 +01007144 wall-clock time, see |localtime()| for that).
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007145 With one argument is returns the time passed since the time
7146 specified in the argument.
7147 With two arguments it returns the time passed between {start}
7148 and {end}.
7149
7150 The {start} and {end} arguments must be values returned by
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01007151 reltime(). If there is an error an empty List is returned in
7152 legacy script, in Vim9 script an error is given.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007153
7154 Can also be used as a |method|: >
7155 GetStart()->reltime()
7156<
7157 {only available when compiled with the |+reltime| feature}
7158
7159reltimefloat({time}) *reltimefloat()*
7160 Return a Float that represents the time value of {time}.
7161 Example: >
7162 let start = reltime()
7163 call MyFunction()
7164 let seconds = reltimefloat(reltime(start))
7165< See the note of reltimestr() about overhead.
7166 Also see |profiling|.
7167 If there is an error 0.0 is returned in legacy script, in Vim9
7168 script an error is given.
7169
7170 Can also be used as a |method|: >
7171 reltime(start)->reltimefloat()
7172
7173< {only available when compiled with the |+reltime| feature}
7174
7175reltimestr({time}) *reltimestr()*
7176 Return a String that represents the time value of {time}.
7177 This is the number of seconds, a dot and the number of
7178 microseconds. Example: >
7179 let start = reltime()
7180 call MyFunction()
7181 echo reltimestr(reltime(start))
7182< Note that overhead for the commands will be added to the time.
Ernie Rael076de792023-03-16 21:43:15 +00007183 The accuracy depends on the system. Use reltimefloat() for the
7184 greatest accuracy which is nanoseconds on some systems.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007185 Leading spaces are used to make the string align nicely. You
7186 can use split() to remove it. >
7187 echo split(reltimestr(reltime(start)))[0]
7188< Also see |profiling|.
7189 If there is an error an empty string is returned in legacy
7190 script, in Vim9 script an error is given.
7191
7192 Can also be used as a |method|: >
7193 reltime(start)->reltimestr()
7194
7195< {only available when compiled with the |+reltime| feature}
7196
7197 *remote_expr()* *E449*
7198remote_expr({server}, {string} [, {idvar} [, {timeout}]])
Bram Moolenaar944697a2022-02-20 19:48:20 +00007199 Send the {string} to {server}. The {server} argument is a
7200 string, also see |{server}|.
7201
7202 The string is sent as an expression and the result is returned
7203 after evaluation. The result must be a String or a |List|. A
7204 |List| is turned into a String by joining the items with a
7205 line break in between (not at the end), like with join(expr,
7206 "\n").
7207
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007208 If {idvar} is present and not empty, it is taken as the name
7209 of a variable and a {serverid} for later use with
7210 |remote_read()| is stored there.
Bram Moolenaar944697a2022-02-20 19:48:20 +00007211
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007212 If {timeout} is given the read times out after this many
7213 seconds. Otherwise a timeout of 600 seconds is used.
Bram Moolenaar944697a2022-02-20 19:48:20 +00007214
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007215 See also |clientserver| |RemoteReply|.
7216 This function is not available in the |sandbox|.
7217 {only available when compiled with the |+clientserver| feature}
7218 Note: Any errors will cause a local error message to be issued
7219 and the result will be the empty string.
7220
7221 Variables will be evaluated in the global namespace,
7222 independent of a function currently being active. Except
7223 when in debug mode, then local function variables and
7224 arguments can be evaluated.
7225
7226 Examples: >
7227 :echo remote_expr("gvim", "2+2")
7228 :echo remote_expr("gvim1", "b:current_syntax")
7229<
7230 Can also be used as a |method|: >
7231 ServerName()->remote_expr(expr)
7232
7233remote_foreground({server}) *remote_foreground()*
7234 Move the Vim server with the name {server} to the foreground.
Bram Moolenaar944697a2022-02-20 19:48:20 +00007235 The {server} argument is a string, also see |{server}|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007236 This works like: >
7237 remote_expr({server}, "foreground()")
7238< Except that on Win32 systems the client does the work, to work
7239 around the problem that the OS doesn't always allow the server
7240 to bring itself to the foreground.
7241 Note: This does not restore the window if it was minimized,
7242 like foreground() does.
7243 This function is not available in the |sandbox|.
7244
7245 Can also be used as a |method|: >
7246 ServerName()->remote_foreground()
7247
Bram Moolenaarcbaff5e2022-04-08 17:45:08 +01007248< {only in the Win32, Motif and GTK GUI versions and the
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007249 Win32 console version}
7250
7251
7252remote_peek({serverid} [, {retvar}]) *remote_peek()*
7253 Returns a positive number if there are available strings
7254 from {serverid}. Copies any reply string into the variable
7255 {retvar} if specified. {retvar} must be a string with the
7256 name of a variable.
7257 Returns zero if none are available.
7258 Returns -1 if something is wrong.
7259 See also |clientserver|.
7260 This function is not available in the |sandbox|.
7261 {only available when compiled with the |+clientserver| feature}
7262 Examples: >
Bram Moolenaarf269eab2022-10-03 18:04:35 +01007263 :let repl = ""
7264 :echo "PEEK: " .. remote_peek(id, "repl") .. ": " .. repl
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007265
7266< Can also be used as a |method|: >
7267 ServerId()->remote_peek()
7268
7269remote_read({serverid}, [{timeout}]) *remote_read()*
7270 Return the oldest available reply from {serverid} and consume
7271 it. Unless a {timeout} in seconds is given, it blocks until a
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01007272 reply is available. Returns an empty string, if a reply is
7273 not available or on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007274 See also |clientserver|.
7275 This function is not available in the |sandbox|.
7276 {only available when compiled with the |+clientserver| feature}
7277 Example: >
7278 :echo remote_read(id)
7279
7280< Can also be used as a |method|: >
7281 ServerId()->remote_read()
7282<
7283 *remote_send()* *E241*
7284remote_send({server}, {string} [, {idvar}])
Bram Moolenaar944697a2022-02-20 19:48:20 +00007285 Send the {string} to {server}. The {server} argument is a
7286 string, also see |{server}|.
7287
7288 The string is sent as input keys and the function returns
7289 immediately. At the Vim server the keys are not mapped
7290 |:map|.
7291
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007292 If {idvar} is present, it is taken as the name of a variable
7293 and a {serverid} for later use with remote_read() is stored
7294 there.
Bram Moolenaar944697a2022-02-20 19:48:20 +00007295
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007296 See also |clientserver| |RemoteReply|.
7297 This function is not available in the |sandbox|.
7298 {only available when compiled with the |+clientserver| feature}
7299
7300 Note: Any errors will be reported in the server and may mess
7301 up the display.
7302 Examples: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00007303 :echo remote_send("gvim", ":DropAndReply " .. file, "serverid") ..
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007304 \ remote_read(serverid)
7305
7306 :autocmd NONE RemoteReply *
7307 \ echo remote_read(expand("<amatch>"))
Bram Moolenaarc51cf032022-02-26 12:25:45 +00007308 :echo remote_send("gvim", ":sleep 10 | echo " ..
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007309 \ 'server2client(expand("<client>"), "HELLO")<CR>')
7310<
7311 Can also be used as a |method|: >
7312 ServerName()->remote_send(keys)
7313<
7314 *remote_startserver()* *E941* *E942*
7315remote_startserver({name})
h-east17b69512023-05-01 22:36:56 +01007316 Become the server {name}. {name} must be a non-empty string.
7317 This fails if already running as a server, when |v:servername|
7318 is not empty.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007319
7320 Can also be used as a |method|: >
7321 ServerName()->remote_startserver()
7322
7323< {only available when compiled with the |+clientserver| feature}
7324
Bram Moolenaarf269eab2022-10-03 18:04:35 +01007325remove({list}, {idx})
7326remove({list}, {idx}, {end}) *remove()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007327 Without {end}: Remove the item at {idx} from |List| {list} and
7328 return the item.
7329 With {end}: Remove items from {idx} to {end} (inclusive) and
7330 return a |List| with these items. When {idx} points to the same
7331 item as {end} a list with one item is returned. When {end}
7332 points to an item before {idx} this is an error.
7333 See |list-index| for possible values of {idx} and {end}.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01007334 Returns zero on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007335 Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00007336 :echo "last item: " .. remove(mylist, -1)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007337 :call remove(mylist, 0, 9)
7338<
7339 Use |delete()| to remove a file.
7340
7341 Can also be used as a |method|: >
7342 mylist->remove(idx)
7343
Bram Moolenaarf269eab2022-10-03 18:04:35 +01007344remove({blob}, {idx})
7345remove({blob}, {idx}, {end})
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007346 Without {end}: Remove the byte at {idx} from |Blob| {blob} and
7347 return the byte.
7348 With {end}: Remove bytes from {idx} to {end} (inclusive) and
7349 return a |Blob| with these bytes. When {idx} points to the same
7350 byte as {end} a |Blob| with one byte is returned. When {end}
7351 points to a byte before {idx} this is an error.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01007352 Returns zero on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007353 Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00007354 :echo "last byte: " .. remove(myblob, -1)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007355 :call remove(mylist, 0, 9)
7356
7357remove({dict}, {key})
7358 Remove the entry from {dict} with key {key} and return it.
7359 Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00007360 :echo "removed " .. remove(dict, "one")
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007361< If there is no {key} in {dict} this is an error.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01007362 Returns zero on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007363
7364rename({from}, {to}) *rename()*
7365 Rename the file by the name {from} to the name {to}. This
7366 should also work to move files across file systems. The
7367 result is a Number, which is 0 if the file was renamed
7368 successfully, and non-zero when the renaming failed.
7369 NOTE: If {to} exists it is overwritten without warning.
7370 This function is not available in the |sandbox|.
7371
7372 Can also be used as a |method|: >
7373 GetOldName()->rename(newname)
7374
7375repeat({expr}, {count}) *repeat()*
7376 Repeat {expr} {count} times and return the concatenated
7377 result. Example: >
7378 :let separator = repeat('-', 80)
7379< When {count} is zero or negative the result is empty.
Bakudankun375141e2022-09-09 18:46:47 +01007380 When {expr} is a |List| or a |Blob| the result is {expr}
7381 concatenated {count} times. Example: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007382 :let longlist = repeat(['a', 'b'], 3)
7383< Results in ['a', 'b', 'a', 'b', 'a', 'b'].
7384
7385 Can also be used as a |method|: >
7386 mylist->repeat(count)
7387
7388resolve({filename}) *resolve()* *E655*
7389 On MS-Windows, when {filename} is a shortcut (a .lnk file),
7390 returns the path the shortcut points to in a simplified form.
7391 When {filename} is a symbolic link or junction point, return
7392 the full path to the target. If the target of junction is
7393 removed, return {filename}.
7394 On Unix, repeat resolving symbolic links in all path
7395 components of {filename} and return the simplified result.
7396 To cope with link cycles, resolving of symbolic links is
7397 stopped after 100 iterations.
7398 On other systems, return the simplified {filename}.
7399 The simplification step is done as by |simplify()|.
7400 resolve() keeps a leading path component specifying the
7401 current directory (provided the result is still a relative
7402 path name) and also keeps a trailing path separator.
7403
7404 Can also be used as a |method|: >
7405 GetName()->resolve()
7406
7407reverse({object}) *reverse()*
Yegappan Lakshmanan03ff1c22023-05-06 14:08:21 +01007408 Reverse the order of items in {object}. {object} can be a
7409 |List|, a |Blob| or a |String|. For a List and a Blob the
7410 items are reversed in-place and {object} is returned.
7411 For a String a new String is returned.
7412 Returns zero if {object} is not a List, Blob or a String.
7413 If you want a List or Blob to remain unmodified make a copy
7414 first: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007415 :let revlist = reverse(copy(mylist))
7416< Can also be used as a |method|: >
7417 mylist->reverse()
7418
7419round({expr}) *round()*
7420 Round off {expr} to the nearest integral value and return it
7421 as a |Float|. If {expr} lies halfway between two integral
7422 values, then use the larger one (away from zero).
7423 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01007424 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007425 Examples: >
7426 echo round(0.456)
7427< 0.0 >
7428 echo round(4.5)
7429< 5.0 >
7430 echo round(-4.5)
7431< -5.0
7432
7433 Can also be used as a |method|: >
7434 Compute()->round()
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007435
7436rubyeval({expr}) *rubyeval()*
7437 Evaluate Ruby expression {expr} and return its result
7438 converted to Vim data structures.
7439 Numbers, floats and strings are returned as they are (strings
7440 are copied though).
7441 Arrays are represented as Vim |List| type.
7442 Hashes are represented as Vim |Dictionary| type.
7443 Other objects are represented as strings resulted from their
7444 "Object#to_s" method.
7445 Note that in a `:def` function local variables are not visible
7446 to {expr}.
7447
7448 Can also be used as a |method|: >
7449 GetRubyExpr()->rubyeval()
7450
7451< {only available when compiled with the |+ruby| feature}
7452
7453screenattr({row}, {col}) *screenattr()*
7454 Like |screenchar()|, but return the attribute. This is a rather
7455 arbitrary number that can only be used to compare to the
7456 attribute at other positions.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01007457 Returns -1 when row or col is out of range.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007458
7459 Can also be used as a |method|: >
7460 GetRow()->screenattr(col)
7461
7462screenchar({row}, {col}) *screenchar()*
7463 The result is a Number, which is the character at position
7464 [row, col] on the screen. This works for every possible
7465 screen position, also status lines, window separators and the
7466 command line. The top left position is row one, column one
7467 The character excludes composing characters. For double-byte
7468 encodings it may only be the first byte.
7469 This is mainly to be used for testing.
7470 Returns -1 when row or col is out of range.
7471
7472 Can also be used as a |method|: >
7473 GetRow()->screenchar(col)
7474
7475screenchars({row}, {col}) *screenchars()*
7476 The result is a |List| of Numbers. The first number is the same
7477 as what |screenchar()| returns. Further numbers are
7478 composing characters on top of the base character.
7479 This is mainly to be used for testing.
7480 Returns an empty List when row or col is out of range.
7481
7482 Can also be used as a |method|: >
7483 GetRow()->screenchars(col)
7484
7485screencol() *screencol()*
7486 The result is a Number, which is the current screen column of
7487 the cursor. The leftmost column has number 1.
7488 This function is mainly used for testing.
7489
7490 Note: Always returns the current screen column, thus if used
7491 in a command (e.g. ":echo screencol()") it will return the
7492 column inside the command line, which is 1 when the command is
7493 executed. To get the cursor position in the file use one of
7494 the following mappings: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00007495 nnoremap <expr> GG ":echom " .. screencol() .. "\n"
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007496 nnoremap <silent> GG :echom screencol()<CR>
7497 nnoremap GG <Cmd>echom screencol()<CR>
7498<
7499screenpos({winid}, {lnum}, {col}) *screenpos()*
7500 The result is a Dict with the screen position of the text
7501 character in window {winid} at buffer line {lnum} and column
7502 {col}. {col} is a one-based byte index.
7503 The Dict has these members:
7504 row screen row
7505 col first screen column
7506 endcol last screen column
7507 curscol cursor screen column
7508 If the specified position is not visible, all values are zero.
7509 The "endcol" value differs from "col" when the character
7510 occupies more than one screen cell. E.g. for a Tab "col" can
7511 be 1 and "endcol" can be 8.
7512 The "curscol" value is where the cursor would be placed. For
7513 a Tab it would be the same as "endcol", while for a double
7514 width character it would be the same as "col".
7515 The |conceal| feature is ignored here, the column numbers are
7516 as if 'conceallevel' is zero. You can set the cursor to the
7517 right position and use |screencol()| to get the value with
7518 |conceal| taken into account.
Bram Moolenaar944697a2022-02-20 19:48:20 +00007519 If the position is in a closed fold the screen position of the
7520 first character is returned, {col} is not used.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01007521 Returns an empty Dict if {winid} is invalid.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007522
7523 Can also be used as a |method|: >
7524 GetWinid()->screenpos(lnum, col)
7525
7526screenrow() *screenrow()*
7527 The result is a Number, which is the current screen row of the
7528 cursor. The top line has number one.
7529 This function is mainly used for testing.
7530 Alternatively you can use |winline()|.
7531
7532 Note: Same restrictions as with |screencol()|.
7533
7534screenstring({row}, {col}) *screenstring()*
7535 The result is a String that contains the base character and
7536 any composing characters at position [row, col] on the screen.
7537 This is like |screenchars()| but returning a String with the
7538 characters.
7539 This is mainly to be used for testing.
7540 Returns an empty String when row or col is out of range.
7541
7542 Can also be used as a |method|: >
7543 GetRow()->screenstring(col)
7544<
7545 *search()*
7546search({pattern} [, {flags} [, {stopline} [, {timeout} [, {skip}]]]])
7547 Search for regexp pattern {pattern}. The search starts at the
7548 cursor position (you can use |cursor()| to set it).
7549
7550 When a match has been found its line number is returned.
7551 If there is no match a 0 is returned and the cursor doesn't
7552 move. No error message is given.
7553
7554 {flags} is a String, which can contain these character flags:
7555 'b' search Backward instead of forward
7556 'c' accept a match at the Cursor position
7557 'e' move to the End of the match
7558 'n' do Not move the cursor
7559 'p' return number of matching sub-Pattern (see below)
7560 's' Set the ' mark at the previous location of the cursor
7561 'w' Wrap around the end of the file
7562 'W' don't Wrap around the end of the file
7563 'z' start searching at the cursor column instead of zero
7564 If neither 'w' or 'W' is given, the 'wrapscan' option applies.
7565
7566 If the 's' flag is supplied, the ' mark is set, only if the
7567 cursor is moved. The 's' flag cannot be combined with the 'n'
7568 flag.
7569
7570 'ignorecase', 'smartcase' and 'magic' are used.
7571
7572 When the 'z' flag is not given, forward searching always
7573 starts in column zero and then matches before the cursor are
7574 skipped. When the 'c' flag is present in 'cpo' the next
7575 search starts after the match. Without the 'c' flag the next
Bram Moolenaarfd999452022-08-24 18:30:14 +01007576 search starts one column after the start of the match. This
7577 matters for overlapping matches. See |cpo-c|. You can also
7578 insert "\ze" to change where the match ends, see |/\ze|.
7579
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007580 When searching backwards and the 'z' flag is given then the
7581 search starts in column zero, thus no match in the current
7582 line will be found (unless wrapping around the end of the
7583 file).
7584
7585 When the {stopline} argument is given then the search stops
7586 after searching this line. This is useful to restrict the
7587 search to a range of lines. Examples: >
7588 let match = search('(', 'b', line("w0"))
7589 let end = search('END', '', line("w$"))
7590< When {stopline} is used and it is not zero this also implies
7591 that the search does not wrap around the end of the file.
7592 A zero value is equal to not giving the argument.
Bram Moolenaar2ecbe532022-07-29 21:36:21 +01007593 *E1285* *E1286* *E1287* *E1288* *E1289*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007594 When the {timeout} argument is given the search stops when
7595 more than this many milliseconds have passed. Thus when
7596 {timeout} is 500 the search stops after half a second.
7597 The value must not be negative. A zero value is like not
7598 giving the argument.
7599 {only available when compiled with the |+reltime| feature}
7600
7601 If the {skip} expression is given it is evaluated with the
7602 cursor positioned on the start of a match. If it evaluates to
7603 non-zero this match is skipped. This can be used, for
7604 example, to skip a match in a comment or a string.
7605 {skip} can be a string, which is evaluated as an expression, a
7606 function reference or a lambda.
7607 When {skip} is omitted or empty, every match is accepted.
7608 When evaluating {skip} causes an error the search is aborted
7609 and -1 returned.
7610 *search()-sub-match*
7611 With the 'p' flag the returned value is one more than the
7612 first sub-match in \(\). One if none of them matched but the
7613 whole pattern did match.
7614 To get the column number too use |searchpos()|.
7615
7616 The cursor will be positioned at the match, unless the 'n'
7617 flag is used.
7618
7619 Example (goes over all files in the argument list): >
7620 :let n = 1
7621 :while n <= argc() " loop over all files in arglist
Bram Moolenaarc51cf032022-02-26 12:25:45 +00007622 : exe "argument " .. n
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007623 : " start at the last char in the file and wrap for the
7624 : " first search to find match at start of file
7625 : normal G$
7626 : let flags = "w"
7627 : while search("foo", flags) > 0
7628 : s/foo/bar/g
7629 : let flags = "W"
7630 : endwhile
7631 : update " write the file if modified
7632 : let n = n + 1
7633 :endwhile
7634<
7635 Example for using some flags: >
7636 :echo search('\<if\|\(else\)\|\(endif\)', 'ncpe')
7637< This will search for the keywords "if", "else", and "endif"
7638 under or after the cursor. Because of the 'p' flag, it
7639 returns 1, 2, or 3 depending on which keyword is found, or 0
7640 if the search fails. With the cursor on the first word of the
7641 line:
7642 if (foo == 0) | let foo = foo + 1 | endif ~
7643 the function returns 1. Without the 'c' flag, the function
7644 finds the "endif" and returns 3. The same thing happens
7645 without the 'e' flag if the cursor is on the "f" of "if".
7646 The 'n' flag tells the function not to move the cursor.
7647
7648 Can also be used as a |method|: >
7649 GetPattern()->search()
7650
7651searchcount([{options}]) *searchcount()*
7652 Get or update the last search count, like what is displayed
7653 without the "S" flag in 'shortmess'. This works even if
7654 'shortmess' does contain the "S" flag.
7655
7656 This returns a |Dictionary|. The dictionary is empty if the
7657 previous pattern was not set and "pattern" was not specified.
7658
7659 key type meaning ~
7660 current |Number| current position of match;
7661 0 if the cursor position is
7662 before the first match
7663 exact_match |Boolean| 1 if "current" is matched on
7664 "pos", otherwise 0
7665 total |Number| total count of matches found
7666 incomplete |Number| 0: search was fully completed
7667 1: recomputing was timed out
7668 2: max count exceeded
7669
7670 For {options} see further down.
7671
7672 To get the last search count when |n| or |N| was pressed, call
7673 this function with `recompute: 0` . This sometimes returns
7674 wrong information because |n| and |N|'s maximum count is 99.
7675 If it exceeded 99 the result must be max count + 1 (100). If
7676 you want to get correct information, specify `recompute: 1`: >
7677
7678 " result == maxcount + 1 (100) when many matches
7679 let result = searchcount(#{recompute: 0})
7680
7681 " Below returns correct result (recompute defaults
7682 " to 1)
7683 let result = searchcount()
7684<
Bram Moolenaarb529cfb2022-07-25 15:42:07 +01007685 The function is useful to add the count to 'statusline': >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007686 function! LastSearchCount() abort
7687 let result = searchcount(#{recompute: 0})
7688 if empty(result)
7689 return ''
7690 endif
7691 if result.incomplete ==# 1 " timed out
7692 return printf(' /%s [?/??]', @/)
7693 elseif result.incomplete ==# 2 " max count exceeded
7694 if result.total > result.maxcount &&
7695 \ result.current > result.maxcount
7696 return printf(' /%s [>%d/>%d]', @/,
7697 \ result.current, result.total)
7698 elseif result.total > result.maxcount
7699 return printf(' /%s [%d/>%d]', @/,
7700 \ result.current, result.total)
7701 endif
7702 endif
7703 return printf(' /%s [%d/%d]', @/,
7704 \ result.current, result.total)
7705 endfunction
Bram Moolenaarc51cf032022-02-26 12:25:45 +00007706 let &statusline ..= '%{LastSearchCount()}'
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007707
7708 " Or if you want to show the count only when
7709 " 'hlsearch' was on
Bram Moolenaarc51cf032022-02-26 12:25:45 +00007710 " let &statusline ..=
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007711 " \ '%{v:hlsearch ? LastSearchCount() : ""}'
7712<
7713 You can also update the search count, which can be useful in a
7714 |CursorMoved| or |CursorMovedI| autocommand: >
7715
7716 autocmd CursorMoved,CursorMovedI *
7717 \ let s:searchcount_timer = timer_start(
7718 \ 200, function('s:update_searchcount'))
7719 function! s:update_searchcount(timer) abort
7720 if a:timer ==# s:searchcount_timer
7721 call searchcount(#{
7722 \ recompute: 1, maxcount: 0, timeout: 100})
7723 redrawstatus
7724 endif
7725 endfunction
7726<
7727 This can also be used to count matched texts with specified
7728 pattern in the current buffer using "pattern": >
7729
7730 " Count '\<foo\>' in this buffer
7731 " (Note that it also updates search count)
7732 let result = searchcount(#{pattern: '\<foo\>'})
7733
7734 " To restore old search count by old pattern,
7735 " search again
7736 call searchcount()
7737<
7738 {options} must be a |Dictionary|. It can contain:
7739 key type meaning ~
7740 recompute |Boolean| if |TRUE|, recompute the count
7741 like |n| or |N| was executed.
7742 otherwise returns the last
7743 computed result (when |n| or
7744 |N| was used when "S" is not
7745 in 'shortmess', or this
7746 function was called).
7747 (default: |TRUE|)
7748 pattern |String| recompute if this was given
7749 and different with |@/|.
7750 this works as same as the
7751 below command is executed
7752 before calling this function >
7753 let @/ = pattern
7754< (default: |@/|)
7755 timeout |Number| 0 or negative number is no
7756 timeout. timeout milliseconds
7757 for recomputing the result
7758 (default: 0)
7759 maxcount |Number| 0 or negative number is no
7760 limit. max count of matched
7761 text while recomputing the
7762 result. if search exceeded
7763 total count, "total" value
7764 becomes `maxcount + 1`
7765 (default: 99)
7766 pos |List| `[lnum, col, off]` value
7767 when recomputing the result.
7768 this changes "current" result
7769 value. see |cursor()|,
7770 |getpos()|
7771 (default: cursor's position)
7772
7773 Can also be used as a |method|: >
7774 GetSearchOpts()->searchcount()
7775<
7776searchdecl({name} [, {global} [, {thisblock}]]) *searchdecl()*
7777 Search for the declaration of {name}.
7778
7779 With a non-zero {global} argument it works like |gD|, find
7780 first match in the file. Otherwise it works like |gd|, find
7781 first match in the function.
7782
7783 With a non-zero {thisblock} argument matches in a {} block
7784 that ends before the cursor position are ignored. Avoids
7785 finding variable declarations only valid in another scope.
7786
7787 Moves the cursor to the found match.
7788 Returns zero for success, non-zero for failure.
7789 Example: >
7790 if searchdecl('myvar') == 0
7791 echo getline('.')
7792 endif
7793<
7794 Can also be used as a |method|: >
7795 GetName()->searchdecl()
7796<
7797 *searchpair()*
7798searchpair({start}, {middle}, {end} [, {flags} [, {skip}
7799 [, {stopline} [, {timeout}]]]])
7800 Search for the match of a nested start-end pair. This can be
7801 used to find the "endif" that matches an "if", while other
7802 if/endif pairs in between are ignored.
7803 The search starts at the cursor. The default is to search
7804 forward, include 'b' in {flags} to search backward.
7805 If a match is found, the cursor is positioned at it and the
7806 line number is returned. If no match is found 0 or -1 is
7807 returned and the cursor doesn't move. No error message is
7808 given.
7809
7810 {start}, {middle} and {end} are patterns, see |pattern|. They
7811 must not contain \( \) pairs. Use of \%( \) is allowed. When
7812 {middle} is not empty, it is found when searching from either
7813 direction, but only when not in a nested start-end pair. A
7814 typical use is: >
7815 searchpair('\<if\>', '\<else\>', '\<endif\>')
7816< By leaving {middle} empty the "else" is skipped.
7817
7818 {flags} 'b', 'c', 'n', 's', 'w' and 'W' are used like with
7819 |search()|. Additionally:
7820 'r' Repeat until no more matches found; will find the
7821 outer pair. Implies the 'W' flag.
7822 'm' Return number of matches instead of line number with
7823 the match; will be > 1 when 'r' is used.
7824 Note: it's nearly always a good idea to use the 'W' flag, to
7825 avoid wrapping around the end of the file.
7826
7827 When a match for {start}, {middle} or {end} is found, the
7828 {skip} expression is evaluated with the cursor positioned on
7829 the start of the match. It should return non-zero if this
7830 match is to be skipped. E.g., because it is inside a comment
7831 or a string.
7832 When {skip} is omitted or empty, every match is accepted.
7833 When evaluating {skip} causes an error the search is aborted
7834 and -1 returned.
7835 {skip} can be a string, a lambda, a funcref or a partial.
7836 Anything else makes the function fail.
7837 In a `:def` function when the {skip} argument is a string
7838 constant it is compiled into instructions.
7839
7840 For {stopline} and {timeout} see |search()|.
7841
7842 The value of 'ignorecase' is used. 'magic' is ignored, the
7843 patterns are used like it's on.
7844
7845 The search starts exactly at the cursor. A match with
7846 {start}, {middle} or {end} at the next character, in the
7847 direction of searching, is the first one found. Example: >
7848 if 1
7849 if 2
7850 endif 2
7851 endif 1
7852< When starting at the "if 2", with the cursor on the "i", and
7853 searching forwards, the "endif 2" is found. When starting on
7854 the character just before the "if 2", the "endif 1" will be
7855 found. That's because the "if 2" will be found first, and
7856 then this is considered to be a nested if/endif from "if 2" to
7857 "endif 2".
7858 When searching backwards and {end} is more than one character,
7859 it may be useful to put "\zs" at the end of the pattern, so
7860 that when the cursor is inside a match with the end it finds
7861 the matching start.
7862
7863 Example, to find the "endif" command in a Vim script: >
7864
7865 :echo searchpair('\<if\>', '\<el\%[seif]\>', '\<en\%[dif]\>', 'W',
7866 \ 'getline(".") =~ "^\\s*\""')
7867
7868< The cursor must be at or after the "if" for which a match is
7869 to be found. Note that single-quote strings are used to avoid
7870 having to double the backslashes. The skip expression only
7871 catches comments at the start of a line, not after a command.
7872 Also, a word "en" or "if" halfway a line is considered a
7873 match.
7874 Another example, to search for the matching "{" of a "}": >
7875
7876 :echo searchpair('{', '', '}', 'bW')
7877
7878< This works when the cursor is at or before the "}" for which a
7879 match is to be found. To reject matches that syntax
7880 highlighting recognized as strings: >
7881
7882 :echo searchpair('{', '', '}', 'bW',
7883 \ 'synIDattr(synID(line("."), col("."), 0), "name") =~? "string"')
7884<
7885 *searchpairpos()*
7886searchpairpos({start}, {middle}, {end} [, {flags} [, {skip}
7887 [, {stopline} [, {timeout}]]]])
7888 Same as |searchpair()|, but returns a |List| with the line and
7889 column position of the match. The first element of the |List|
7890 is the line number and the second element is the byte index of
7891 the column position of the match. If no match is found,
7892 returns [0, 0]. >
7893
7894 :let [lnum,col] = searchpairpos('{', '', '}', 'n')
7895<
7896 See |match-parens| for a bigger and more useful example.
7897
7898 *searchpos()*
7899searchpos({pattern} [, {flags} [, {stopline} [, {timeout} [, {skip}]]]])
7900 Same as |search()|, but returns a |List| with the line and
7901 column position of the match. The first element of the |List|
7902 is the line number and the second element is the byte index of
7903 the column position of the match. If no match is found,
7904 returns [0, 0].
7905 Example: >
7906 :let [lnum, col] = searchpos('mypattern', 'n')
7907
7908< When the 'p' flag is given then there is an extra item with
7909 the sub-pattern match number |search()-sub-match|. Example: >
7910 :let [lnum, col, submatch] = searchpos('\(\l\)\|\(\u\)', 'np')
7911< In this example "submatch" is 2 when a lowercase letter is
7912 found |/\l|, 3 when an uppercase letter is found |/\u|.
7913
7914 Can also be used as a |method|: >
7915 GetPattern()->searchpos()
7916
7917server2client({clientid}, {string}) *server2client()*
7918 Send a reply string to {clientid}. The most recent {clientid}
7919 that sent a string can be retrieved with expand("<client>").
7920 {only available when compiled with the |+clientserver| feature}
7921 Returns zero for success, -1 for failure.
7922 Note:
7923 This id has to be stored before the next command can be
7924 received. I.e. before returning from the received command and
7925 before calling any commands that waits for input.
7926 See also |clientserver|.
7927 Example: >
7928 :echo server2client(expand("<client>"), "HELLO")
7929
7930< Can also be used as a |method|: >
7931 GetClientId()->server2client(string)
7932<
7933serverlist() *serverlist()*
7934 Return a list of available server names, one per line.
7935 When there are no servers or the information is not available
7936 an empty string is returned. See also |clientserver|.
7937 {only available when compiled with the |+clientserver| feature}
7938 Example: >
7939 :echo serverlist()
7940<
7941setbufline({buf}, {lnum}, {text}) *setbufline()*
7942 Set line {lnum} to {text} in buffer {buf}. This works like
7943 |setline()| for the specified buffer.
7944
7945 This function works only for loaded buffers. First call
7946 |bufload()| if needed.
7947
7948 To insert lines use |appendbufline()|.
7949 Any text properties in {lnum} are cleared.
7950
Bram Moolenaarcd9c8d42022-11-05 23:46:43 +00007951 {text} can be a string to set one line, or a List of strings
7952 to set multiple lines. If the List extends below the last
7953 line then those lines are added. If the List is empty then
7954 nothing is changed and zero is returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007955
7956 For the use of {buf}, see |bufname()| above.
7957
7958 {lnum} is used like with |setline()|.
7959 Use "$" to refer to the last line in buffer {buf}.
7960 When {lnum} is just below the last line the {text} will be
7961 added below the last line.
7962
7963 When {buf} is not a valid buffer, the buffer is not loaded or
7964 {lnum} is not valid then 1 is returned. In |Vim9| script an
7965 error is given.
7966 On success 0 is returned.
7967
7968 Can also be used as a |method|, the base is passed as the
7969 third argument: >
7970 GetText()->setbufline(buf, lnum)
7971
7972setbufvar({buf}, {varname}, {val}) *setbufvar()*
7973 Set option or local variable {varname} in buffer {buf} to
7974 {val}.
7975 This also works for a global or local window option, but it
7976 doesn't work for a global or local window variable.
7977 For a local window option the global value is unchanged.
7978 For the use of {buf}, see |bufname()| above.
7979 The {varname} argument is a string.
7980 Note that the variable name without "b:" must be used.
7981 Examples: >
7982 :call setbufvar(1, "&mod", 1)
7983 :call setbufvar("todo", "myvar", "foobar")
7984< This function is not available in the |sandbox|.
7985
7986 Can also be used as a |method|, the base is passed as the
7987 third argument: >
7988 GetValue()->setbufvar(buf, varname)
7989
7990
7991setcellwidths({list}) *setcellwidths()*
7992 Specify overrides for cell widths of character ranges. This
Bram Moolenaarb59ae592022-11-23 23:46:31 +00007993 tells Vim how wide characters are when displayed in the
7994 terminal, counted in screen cells. The values override
7995 'ambiwidth'. Example: >
7996 call setcellwidths([
Bram Moolenaar938ae282023-02-20 20:44:55 +00007997 \ [0x111, 0x111, 1],
Bram Moolenaarb59ae592022-11-23 23:46:31 +00007998 \ [0x2194, 0x2199, 2],
7999 \ ])
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008000
Bram Moolenaarb59ae592022-11-23 23:46:31 +00008001< The {list} argument is a List of Lists with each three
8002 numbers: [{low}, {high}, {width}]. *E1109* *E1110*
8003 {low} and {high} can be the same, in which case this refers to
8004 one character. Otherwise it is the range of characters from
8005 {low} to {high} (inclusive). *E1111* *E1114*
K.Takata71933232023-01-20 16:00:55 +00008006 Only characters with value 0x80 and higher can be used.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008007
Bram Moolenaarb59ae592022-11-23 23:46:31 +00008008 {width} must be either 1 or 2, indicating the character width
8009 in screen cells. *E1112*
8010 An error is given if the argument is invalid, also when a
Bram Moolenaar938ae282023-02-20 20:44:55 +00008011 range overlaps with another. *E1113*
Bram Moolenaarb59ae592022-11-23 23:46:31 +00008012
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008013 If the new value causes 'fillchars' or 'listchars' to become
8014 invalid it is rejected and an error is given.
8015
Bram Moolenaarb59ae592022-11-23 23:46:31 +00008016 To clear the overrides pass an empty {list}: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008017 setcellwidths([]);
Bram Moolenaarb59ae592022-11-23 23:46:31 +00008018
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008019< You can use the script $VIMRUNTIME/tools/emoji_list.vim to see
Bram Moolenaarb59ae592022-11-23 23:46:31 +00008020 the effect for known emoji characters. Move the cursor
8021 through the text to check if the cell widths of your terminal
8022 match with what Vim knows about each emoji. If it doesn't
8023 look right you need to adjust the {list} argument.
8024
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008025
8026setcharpos({expr}, {list}) *setcharpos()*
8027 Same as |setpos()| but uses the specified column number as the
8028 character index instead of the byte index in the line.
8029
8030 Example:
8031 With the text "여보세요" in line 8: >
8032 call setcharpos('.', [0, 8, 4, 0])
8033< positions the cursor on the fourth character '요'. >
8034 call setpos('.', [0, 8, 4, 0])
8035< positions the cursor on the second character '보'.
8036
8037 Can also be used as a |method|: >
8038 GetPosition()->setcharpos('.')
8039
8040setcharsearch({dict}) *setcharsearch()*
8041 Set the current character search information to {dict},
8042 which contains one or more of the following entries:
8043
8044 char character which will be used for a subsequent
8045 |,| or |;| command; an empty string clears the
8046 character search
8047 forward direction of character search; 1 for forward,
8048 0 for backward
8049 until type of character search; 1 for a |t| or |T|
8050 character search, 0 for an |f| or |F|
8051 character search
8052
8053 This can be useful to save/restore a user's character search
8054 from a script: >
8055 :let prevsearch = getcharsearch()
8056 :" Perform a command which clobbers user's search
8057 :call setcharsearch(prevsearch)
8058< Also see |getcharsearch()|.
8059
8060 Can also be used as a |method|: >
8061 SavedSearch()->setcharsearch()
8062
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01008063setcmdline({str} [, {pos}]) *setcmdline()*
8064 Set the command line to {str} and set the cursor position to
8065 {pos}.
8066 If {pos} is omitted, the cursor is positioned after the text.
8067 Returns 0 when successful, 1 when not editing the command
8068 line.
8069
8070 Can also be used as a |method|: >
8071 GetText()->setcmdline()
8072
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008073setcmdpos({pos}) *setcmdpos()*
8074 Set the cursor position in the command line to byte position
8075 {pos}. The first position is 1.
8076 Use |getcmdpos()| to obtain the current position.
8077 Only works while editing the command line, thus you must use
8078 |c_CTRL-\_e|, |c_CTRL-R_=| or |c_CTRL-R_CTRL-R| with '='. For
8079 |c_CTRL-\_e| and |c_CTRL-R_CTRL-R| with '=' the position is
8080 set after the command line is set to the expression. For
8081 |c_CTRL-R_=| it is set after evaluating the expression but
8082 before inserting the resulting text.
8083 When the number is too big the cursor is put at the end of the
8084 line. A number smaller than one has undefined results.
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01008085 Returns 0 when successful, 1 when not editing the command
8086 line.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008087
8088 Can also be used as a |method|: >
8089 GetPos()->setcmdpos()
8090
8091setcursorcharpos({lnum}, {col} [, {off}]) *setcursorcharpos()*
8092setcursorcharpos({list})
8093 Same as |cursor()| but uses the specified column number as the
8094 character index instead of the byte index in the line.
8095
8096 Example:
8097 With the text "여보세요" in line 4: >
8098 call setcursorcharpos(4, 3)
8099< positions the cursor on the third character '세'. >
8100 call cursor(4, 3)
8101< positions the cursor on the first character '여'.
8102
8103 Can also be used as a |method|: >
8104 GetCursorPos()->setcursorcharpos()
8105
8106
8107setenv({name}, {val}) *setenv()*
8108 Set environment variable {name} to {val}. Example: >
8109 call setenv('HOME', '/home/myhome')
8110
8111< When {val} is |v:null| the environment variable is deleted.
8112 See also |expr-env|.
8113
8114 Can also be used as a |method|, the base is passed as the
8115 second argument: >
8116 GetPath()->setenv('PATH')
8117
8118setfperm({fname}, {mode}) *setfperm()* *chmod*
8119 Set the file permissions for {fname} to {mode}.
8120 {mode} must be a string with 9 characters. It is of the form
8121 "rwxrwxrwx", where each group of "rwx" flags represent, in
8122 turn, the permissions of the owner of the file, the group the
8123 file belongs to, and other users. A '-' character means the
8124 permission is off, any other character means on. Multi-byte
8125 characters are not supported.
8126
8127 For example "rw-r-----" means read-write for the user,
8128 readable by the group, not accessible by others. "xx-x-----"
8129 would do the same thing.
8130
8131 Returns non-zero for success, zero for failure.
8132
8133 Can also be used as a |method|: >
8134 GetFilename()->setfperm(mode)
8135<
8136 To read permissions see |getfperm()|.
8137
8138
8139setline({lnum}, {text}) *setline()*
8140 Set line {lnum} of the current buffer to {text}. To insert
8141 lines use |append()|. To set lines in another buffer use
8142 |setbufline()|. Any text properties in {lnum} are cleared.
8143
8144 {lnum} is used like with |getline()|.
8145 When {lnum} is just below the last line the {text} will be
8146 added below the last line.
8147 {text} can be any type or a List of any type, each item is
Bram Moolenaarcd9c8d42022-11-05 23:46:43 +00008148 converted to a String. When {text} is an empty List then
8149 nothing is changed and FALSE is returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008150
8151 If this succeeds, FALSE is returned. If this fails (most likely
8152 because {lnum} is invalid) TRUE is returned.
8153 In |Vim9| script an error is given if {lnum} is invalid.
8154
8155 Example: >
8156 :call setline(5, strftime("%c"))
8157
8158< When {text} is a |List| then line {lnum} and following lines
8159 will be set to the items in the list. Example: >
8160 :call setline(5, ['aaa', 'bbb', 'ccc'])
8161< This is equivalent to: >
8162 :for [n, l] in [[5, 'aaa'], [6, 'bbb'], [7, 'ccc']]
8163 : call setline(n, l)
8164 :endfor
8165
8166< Note: The '[ and '] marks are not set.
8167
8168 Can also be used as a |method|, the base is passed as the
8169 second argument: >
8170 GetText()->setline(lnum)
8171
8172setloclist({nr}, {list} [, {action} [, {what}]]) *setloclist()*
8173 Create or replace or add to the location list for window {nr}.
8174 {nr} can be the window number or the |window-ID|.
8175 When {nr} is zero the current window is used.
8176
8177 For a location list window, the displayed location list is
8178 modified. For an invalid window number {nr}, -1 is returned.
8179 Otherwise, same as |setqflist()|.
8180 Also see |location-list|.
8181
8182 For {action} see |setqflist-action|.
8183
8184 If the optional {what} dictionary argument is supplied, then
8185 only the items listed in {what} are set. Refer to |setqflist()|
8186 for the list of supported keys in {what}.
8187
8188 Can also be used as a |method|, the base is passed as the
8189 second argument: >
8190 GetLoclist()->setloclist(winnr)
8191
8192setmatches({list} [, {win}]) *setmatches()*
8193 Restores a list of matches saved by |getmatches()| for the
8194 current window. Returns 0 if successful, otherwise -1. All
8195 current matches are cleared before the list is restored. See
8196 example for |getmatches()|.
8197 If {win} is specified, use the window with this number or
8198 window ID instead of the current window.
8199
8200 Can also be used as a |method|: >
8201 GetMatches()->setmatches()
8202<
8203 *setpos()*
8204setpos({expr}, {list})
8205 Set the position for String {expr}. Possible values:
8206 . the cursor
8207 'x mark x
8208
8209 {list} must be a |List| with four or five numbers:
8210 [bufnum, lnum, col, off]
8211 [bufnum, lnum, col, off, curswant]
8212
8213 "bufnum" is the buffer number. Zero can be used for the
8214 current buffer. When setting an uppercase mark "bufnum" is
8215 used for the mark position. For other marks it specifies the
8216 buffer to set the mark in. You can use the |bufnr()| function
8217 to turn a file name into a buffer number.
8218 For setting the cursor and the ' mark "bufnum" is ignored,
8219 since these are associated with a window, not a buffer.
8220 Does not change the jumplist.
8221
8222 "lnum" and "col" are the position in the buffer. The first
8223 column is 1. Use a zero "lnum" to delete a mark. If "col" is
8224 smaller than 1 then 1 is used. To use the character count
8225 instead of the byte count, use |setcharpos()|.
8226
8227 The "off" number is only used when 'virtualedit' is set. Then
8228 it is the offset in screen columns from the start of the
8229 character. E.g., a position within a <Tab> or after the last
8230 character.
8231
8232 The "curswant" number is only used when setting the cursor
8233 position. It sets the preferred column for when moving the
8234 cursor vertically. When the "curswant" number is missing the
8235 preferred column is not set. When it is present and setting a
8236 mark position it is not used.
8237
8238 Note that for '< and '> changing the line number may result in
8239 the marks to be effectively be swapped, so that '< is always
8240 before '>.
8241
8242 Returns 0 when the position could be set, -1 otherwise.
8243 An error message is given if {expr} is invalid.
8244
8245 Also see |setcharpos()|, |getpos()| and |getcurpos()|.
8246
8247 This does not restore the preferred column for moving
8248 vertically; if you set the cursor position with this, |j| and
8249 |k| motions will jump to previous columns! Use |cursor()| to
8250 also set the preferred column. Also see the "curswant" key in
8251 |winrestview()|.
8252
8253 Can also be used as a |method|: >
8254 GetPosition()->setpos('.')
8255
8256setqflist({list} [, {action} [, {what}]]) *setqflist()*
8257 Create or replace or add to the quickfix list.
8258
8259 If the optional {what} dictionary argument is supplied, then
8260 only the items listed in {what} are set. The first {list}
8261 argument is ignored. See below for the supported items in
8262 {what}.
8263 *setqflist-what*
8264 When {what} is not present, the items in {list} are used. Each
8265 item must be a dictionary. Non-dictionary items in {list} are
8266 ignored. Each dictionary item can contain the following
8267 entries:
8268
8269 bufnr buffer number; must be the number of a valid
8270 buffer
8271 filename name of a file; only used when "bufnr" is not
8272 present or it is invalid.
8273 module name of a module; if given it will be used in
8274 quickfix error window instead of the filename.
8275 lnum line number in the file
Bram Moolenaara2baa732022-02-04 16:09:54 +00008276 end_lnum end of lines, if the item spans multiple lines
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008277 pattern search pattern used to locate the error
8278 col column number
8279 vcol when non-zero: "col" is visual column
8280 when zero: "col" is byte index
Bram Moolenaara2baa732022-02-04 16:09:54 +00008281 end_col end column, if the item spans multiple columns
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008282 nr error number
8283 text description of the error
8284 type single-character error type, 'E', 'W', etc.
8285 valid recognized error message
8286
8287 The "col", "vcol", "nr", "type" and "text" entries are
8288 optional. Either "lnum" or "pattern" entry can be used to
8289 locate a matching error line.
8290 If the "filename" and "bufnr" entries are not present or
8291 neither the "lnum" or "pattern" entries are present, then the
8292 item will not be handled as an error line.
8293 If both "pattern" and "lnum" are present then "pattern" will
8294 be used.
8295 If the "valid" entry is not supplied, then the valid flag is
8296 set when "bufnr" is a valid buffer or "filename" exists.
8297 If you supply an empty {list}, the quickfix list will be
8298 cleared.
8299 Note that the list is not exactly the same as what
8300 |getqflist()| returns.
8301
8302 {action} values: *setqflist-action* *E927*
8303 'a' The items from {list} are added to the existing
8304 quickfix list. If there is no existing list, then a
8305 new list is created.
8306
8307 'r' The items from the current quickfix list are replaced
8308 with the items from {list}. This can also be used to
8309 clear the list: >
8310 :call setqflist([], 'r')
8311<
8312 'f' All the quickfix lists in the quickfix stack are
8313 freed.
8314
8315 If {action} is not present or is set to ' ', then a new list
8316 is created. The new quickfix list is added after the current
8317 quickfix list in the stack and all the following lists are
8318 freed. To add a new quickfix list at the end of the stack,
8319 set "nr" in {what} to "$".
8320
8321 The following items can be specified in dictionary {what}:
8322 context quickfix list context. See |quickfix-context|
8323 efm errorformat to use when parsing text from
8324 "lines". If this is not present, then the
8325 'errorformat' option value is used.
8326 See |quickfix-parse|
8327 id quickfix list identifier |quickfix-ID|
8328 idx index of the current entry in the quickfix
8329 list specified by 'id' or 'nr'. If set to '$',
8330 then the last entry in the list is set as the
8331 current entry. See |quickfix-index|
8332 items list of quickfix entries. Same as the {list}
8333 argument.
8334 lines use 'errorformat' to parse a list of lines and
8335 add the resulting entries to the quickfix list
8336 {nr} or {id}. Only a |List| value is supported.
8337 See |quickfix-parse|
8338 nr list number in the quickfix stack; zero
8339 means the current quickfix list and "$" means
8340 the last quickfix list.
8341 quickfixtextfunc
8342 function to get the text to display in the
8343 quickfix window. The value can be the name of
8344 a function or a funcref or a lambda. Refer to
8345 |quickfix-window-function| for an explanation
8346 of how to write the function and an example.
8347 title quickfix list title text. See |quickfix-title|
8348 Unsupported keys in {what} are ignored.
8349 If the "nr" item is not present, then the current quickfix list
8350 is modified. When creating a new quickfix list, "nr" can be
8351 set to a value one greater than the quickfix stack size.
8352 When modifying a quickfix list, to guarantee that the correct
8353 list is modified, "id" should be used instead of "nr" to
8354 specify the list.
8355
8356 Examples (See also |setqflist-examples|): >
8357 :call setqflist([], 'r', {'title': 'My search'})
8358 :call setqflist([], 'r', {'nr': 2, 'title': 'Errors'})
8359 :call setqflist([], 'a', {'id':qfid, 'lines':["F1:10:L10"]})
8360<
8361 Returns zero for success, -1 for failure.
8362
8363 This function can be used to create a quickfix list
8364 independent of the 'errorformat' setting. Use a command like
8365 `:cc 1` to jump to the first position.
8366
8367 Can also be used as a |method|, the base is passed as the
8368 second argument: >
8369 GetErrorlist()->setqflist()
8370<
8371 *setreg()*
8372setreg({regname}, {value} [, {options}])
8373 Set the register {regname} to {value}.
8374 If {regname} is "" or "@", the unnamed register '"' is used.
8375 The {regname} argument is a string. In |Vim9-script|
8376 {regname} must be one character.
8377
8378 {value} may be any value returned by |getreg()| or
8379 |getreginfo()|, including a |List| or |Dict|.
8380 If {options} contains "a" or {regname} is upper case,
8381 then the value is appended.
8382
8383 {options} can also contain a register type specification:
8384 "c" or "v" |characterwise| mode
8385 "l" or "V" |linewise| mode
8386 "b" or "<CTRL-V>" |blockwise-visual| mode
8387 If a number immediately follows "b" or "<CTRL-V>" then this is
8388 used as the width of the selection - if it is not specified
8389 then the width of the block is set to the number of characters
8390 in the longest line (counting a <Tab> as 1 character).
8391
8392 If {options} contains no register settings, then the default
8393 is to use character mode unless {value} ends in a <NL> for
8394 string {value} and linewise mode for list {value}. Blockwise
8395 mode is never selected automatically.
8396 Returns zero for success, non-zero for failure.
8397
8398 *E883*
8399 Note: you may not use |List| containing more than one item to
8400 set search and expression registers. Lists containing no
8401 items act like empty strings.
8402
8403 Examples: >
8404 :call setreg(v:register, @*)
8405 :call setreg('*', @%, 'ac')
8406 :call setreg('a', "1\n2\n3", 'b5')
8407 :call setreg('"', { 'points_to': 'a'})
8408
8409< This example shows using the functions to save and restore a
8410 register: >
8411 :let var_a = getreginfo()
8412 :call setreg('a', var_a)
8413< or: >
8414 :let var_a = getreg('a', 1, 1)
8415 :let var_amode = getregtype('a')
8416 ....
8417 :call setreg('a', var_a, var_amode)
8418< Note: you may not reliably restore register value
8419 without using the third argument to |getreg()| as without it
8420 newlines are represented as newlines AND Nul bytes are
8421 represented as newlines as well, see |NL-used-for-Nul|.
8422
8423 You can also change the type of a register by appending
8424 nothing: >
8425 :call setreg('a', '', 'al')
8426
8427< Can also be used as a |method|, the base is passed as the
8428 second argument: >
8429 GetText()->setreg('a')
8430
8431settabvar({tabnr}, {varname}, {val}) *settabvar()*
8432 Set tab-local variable {varname} to {val} in tab page {tabnr}.
8433 |t:var|
8434 The {varname} argument is a string.
8435 Note that autocommands are blocked, side effects may not be
8436 triggered, e.g. when setting 'filetype'.
8437 Note that the variable name without "t:" must be used.
8438 Tabs are numbered starting with one.
8439 This function is not available in the |sandbox|.
8440
8441 Can also be used as a |method|, the base is passed as the
8442 third argument: >
8443 GetValue()->settabvar(tab, name)
8444
8445settabwinvar({tabnr}, {winnr}, {varname}, {val}) *settabwinvar()*
8446 Set option or local variable {varname} in window {winnr} to
8447 {val}.
8448 Tabs are numbered starting with one. For the current tabpage
8449 use |setwinvar()|.
8450 {winnr} can be the window number or the |window-ID|.
8451 When {winnr} is zero the current window is used.
8452 Note that autocommands are blocked, side effects may not be
8453 triggered, e.g. when setting 'filetype' or 'syntax'.
8454 This also works for a global or local buffer option, but it
8455 doesn't work for a global or local buffer variable.
8456 For a local buffer option the global value is unchanged.
8457 Note that the variable name without "w:" must be used.
8458 Examples: >
8459 :call settabwinvar(1, 1, "&list", 0)
8460 :call settabwinvar(3, 2, "myvar", "foobar")
8461< This function is not available in the |sandbox|.
8462
8463 Can also be used as a |method|, the base is passed as the
8464 fourth argument: >
8465 GetValue()->settabwinvar(tab, winnr, name)
8466
8467settagstack({nr}, {dict} [, {action}]) *settagstack()*
8468 Modify the tag stack of the window {nr} using {dict}.
8469 {nr} can be the window number or the |window-ID|.
8470
8471 For a list of supported items in {dict}, refer to
8472 |gettagstack()|. "curidx" takes effect before changing the tag
8473 stack.
8474 *E962*
8475 How the tag stack is modified depends on the {action}
8476 argument:
8477 - If {action} is not present or is set to 'r', then the tag
8478 stack is replaced.
8479 - If {action} is set to 'a', then new entries from {dict} are
8480 pushed (added) onto the tag stack.
8481 - If {action} is set to 't', then all the entries from the
8482 current entry in the tag stack or "curidx" in {dict} are
8483 removed and then new entries are pushed to the stack.
8484
8485 The current index is set to one after the length of the tag
8486 stack after the modification.
8487
8488 Returns zero for success, -1 for failure.
8489
8490 Examples (for more examples see |tagstack-examples|):
8491 Empty the tag stack of window 3: >
8492 call settagstack(3, {'items' : []})
8493
8494< Save and restore the tag stack: >
8495 let stack = gettagstack(1003)
8496 " do something else
8497 call settagstack(1003, stack)
8498 unlet stack
8499<
8500 Can also be used as a |method|, the base is passed as the
8501 second argument: >
8502 GetStack()->settagstack(winnr)
8503
8504setwinvar({winnr}, {varname}, {val}) *setwinvar()*
8505 Like |settabwinvar()| for the current tab page.
8506 Examples: >
8507 :call setwinvar(1, "&list", 0)
8508 :call setwinvar(2, "myvar", "foobar")
8509
8510< Can also be used as a |method|, the base is passed as the
8511 third argument: >
8512 GetValue()->setwinvar(winnr, name)
8513
8514sha256({string}) *sha256()*
8515 Returns a String with 64 hex characters, which is the SHA256
8516 checksum of {string}.
8517
8518 Can also be used as a |method|: >
8519 GetText()->sha256()
8520
8521< {only available when compiled with the |+cryptv| feature}
8522
8523shellescape({string} [, {special}]) *shellescape()*
8524 Escape {string} for use as a shell command argument.
8525 When the 'shell' contains powershell (MS-Windows) or pwsh
Bram Moolenaar944697a2022-02-20 19:48:20 +00008526 (MS-Windows, Linux, and macOS) then it will enclose {string}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008527 in single quotes and will double up all internal single
8528 quotes.
8529 On MS-Windows, when 'shellslash' is not set, it will enclose
8530 {string} in double quotes and double all double quotes within
8531 {string}.
8532 Otherwise it will enclose {string} in single quotes and
8533 replace all "'" with "'\''".
8534
8535 When the {special} argument is present and it's a non-zero
8536 Number or a non-empty String (|non-zero-arg|), then special
8537 items such as "!", "%", "#" and "<cword>" will be preceded by
8538 a backslash. This backslash will be removed again by the |:!|
8539 command.
8540
8541 The "!" character will be escaped (again with a |non-zero-arg|
8542 {special}) when 'shell' contains "csh" in the tail. That is
8543 because for csh and tcsh "!" is used for history replacement
8544 even when inside single quotes.
8545
8546 With a |non-zero-arg| {special} the <NL> character is also
8547 escaped. When 'shell' containing "csh" in the tail it's
8548 escaped a second time.
8549
8550 The "\" character will be escaped when 'shell' contains "fish"
8551 in the tail. That is because for fish "\" is used as an escape
8552 character inside single quotes.
8553
8554 Example of use with a |:!| command: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00008555 :exe '!dir ' .. shellescape(expand('<cfile>'), 1)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008556< This results in a directory listing for the file under the
8557 cursor. Example of use with |system()|: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00008558 :call system("chmod +w -- " .. shellescape(expand("%")))
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008559< See also |::S|.
8560
8561 Can also be used as a |method|: >
8562 GetCommand()->shellescape()
8563
8564shiftwidth([{col}]) *shiftwidth()*
8565 Returns the effective value of 'shiftwidth'. This is the
8566 'shiftwidth' value unless it is zero, in which case it is the
8567 'tabstop' value. This function was introduced with patch
8568 7.3.694 in 2012, everybody should have it by now (however it
8569 did not allow for the optional {col} argument until 8.1.542).
8570
8571 When there is one argument {col} this is used as column number
8572 for which to return the 'shiftwidth' value. This matters for the
8573 'vartabstop' feature. If the 'vartabstop' setting is enabled and
8574 no {col} argument is given, column 1 will be assumed.
8575
8576 Can also be used as a |method|: >
8577 GetColumn()->shiftwidth()
8578
8579sign_ functions are documented here: |sign-functions-details|
8580
8581
8582simplify({filename}) *simplify()*
8583 Simplify the file name as much as possible without changing
8584 the meaning. Shortcuts (on MS-Windows) or symbolic links (on
8585 Unix) are not resolved. If the first path component in
8586 {filename} designates the current directory, this will be
8587 valid for the result as well. A trailing path separator is
8588 not removed either. On Unix "//path" is unchanged, but
8589 "///path" is simplified to "/path" (this follows the Posix
8590 standard).
8591 Example: >
8592 simplify("./dir/.././/file/") == "./file/"
8593< Note: The combination "dir/.." is only removed if "dir" is
8594 a searchable directory or does not exist. On Unix, it is also
8595 removed when "dir" is a symbolic link within the same
8596 directory. In order to resolve all the involved symbolic
8597 links before simplifying the path name, use |resolve()|.
8598
8599 Can also be used as a |method|: >
8600 GetName()->simplify()
8601
8602sin({expr}) *sin()*
8603 Return the sine of {expr}, measured in radians, as a |Float|.
8604 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01008605 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008606 Examples: >
8607 :echo sin(100)
8608< -0.506366 >
8609 :echo sin(-4.01)
8610< 0.763301
8611
8612 Can also be used as a |method|: >
8613 Compute()->sin()
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008614
8615
8616sinh({expr}) *sinh()*
8617 Return the hyperbolic sine of {expr} as a |Float| in the range
8618 [-inf, inf].
8619 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01008620 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008621 Examples: >
8622 :echo sinh(0.5)
8623< 0.521095 >
8624 :echo sinh(-0.9)
8625< -1.026517
8626
8627 Can also be used as a |method|: >
8628 Compute()->sinh()
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008629
8630
8631slice({expr}, {start} [, {end}]) *slice()*
8632 Similar to using a |slice| "expr[start : end]", but "end" is
8633 used exclusive. And for a string the indexes are used as
8634 character indexes instead of byte indexes, like in
8635 |vim9script|. Also, composing characters are not counted.
8636 When {end} is omitted the slice continues to the last item.
8637 When {end} is -1 the last item is omitted.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01008638 Returns an empty value if {start} or {end} are invalid.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008639
8640 Can also be used as a |method|: >
8641 GetList()->slice(offset)
8642
8643
Bram Moolenaar2007dd42022-02-23 13:17:47 +00008644sort({list} [, {how} [, {dict}]]) *sort()* *E702*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008645 Sort the items in {list} in-place. Returns {list}.
8646
8647 If you want a list to remain unmodified make a copy first: >
8648 :let sortedlist = sort(copy(mylist))
8649
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01008650< When {how} is omitted or is a string, then sort() uses the
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008651 string representation of each item to sort on. Numbers sort
8652 after Strings, |Lists| after Numbers. For sorting text in the
8653 current buffer use |:sort|.
8654
Bram Moolenaar2007dd42022-02-23 13:17:47 +00008655 When {how} is given and it is 'i' then case is ignored.
8656 In legacy script, for backwards compatibility, the value one
8657 can be used to ignore case. Zero means to not ignore case.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008658
Bram Moolenaar2007dd42022-02-23 13:17:47 +00008659 When {how} is given and it is 'l' then the current collation
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008660 locale is used for ordering. Implementation details: strcoll()
8661 is used to compare strings. See |:language| check or set the
8662 collation locale. |v:collate| can also be used to check the
8663 current locale. Sorting using the locale typically ignores
8664 case. Example: >
8665 " ö is sorted similarly to o with English locale.
8666 :language collate en_US.UTF8
8667 :echo sort(['n', 'o', 'O', 'ö', 'p', 'z'], 'l')
8668< ['n', 'o', 'O', 'ö', 'p', 'z'] ~
8669>
8670 " ö is sorted after z with Swedish locale.
8671 :language collate sv_SE.UTF8
8672 :echo sort(['n', 'o', 'O', 'ö', 'p', 'z'], 'l')
8673< ['n', 'o', 'O', 'p', 'z', 'ö'] ~
8674 This does not work properly on Mac.
8675
Bram Moolenaar2007dd42022-02-23 13:17:47 +00008676 When {how} is given and it is 'n' then all items will be
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008677 sorted numerical (Implementation detail: this uses the
Bram Moolenaarbe19d782023-03-09 22:06:49 +00008678 strtod() function to parse numbers. Strings, Lists, Dicts and
8679 Funcrefs will be considered as being 0). Note that this won't
8680 sort a list of strings with numbers!
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008681
Bram Moolenaar2007dd42022-02-23 13:17:47 +00008682 When {how} is given and it is 'N' then all items will be
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008683 sorted numerical. This is like 'n' but a string containing
8684 digits will be used as the number they represent.
8685
Bram Moolenaar2007dd42022-02-23 13:17:47 +00008686 When {how} is given and it is 'f' then all items will be
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008687 sorted numerical. All values must be a Number or a Float.
8688
Bram Moolenaar2007dd42022-02-23 13:17:47 +00008689 When {how} is a |Funcref| or a function name, this function
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008690 is called to compare items. The function is invoked with two
8691 items as argument and must return zero if they are equal, 1 or
8692 bigger if the first one sorts after the second one, -1 or
8693 smaller if the first one sorts before the second one.
8694
8695 {dict} is for functions with the "dict" attribute. It will be
8696 used to set the local variable "self". |Dictionary-function|
8697
8698 The sort is stable, items which compare equal (as number or as
8699 string) will keep their relative position. E.g., when sorting
8700 on numbers, text strings will sort next to each other, in the
8701 same order as they were originally.
8702
8703 Can also be used as a |method|: >
8704 mylist->sort()
8705
8706< Also see |uniq()|.
8707
8708 Example: >
8709 func MyCompare(i1, i2)
8710 return a:i1 == a:i2 ? 0 : a:i1 > a:i2 ? 1 : -1
8711 endfunc
8712 eval mylist->sort("MyCompare")
8713< A shorter compare version for this specific simple case, which
8714 ignores overflow: >
8715 func MyCompare(i1, i2)
8716 return a:i1 - a:i2
8717 endfunc
8718< For a simple expression you can use a lambda: >
8719 eval mylist->sort({i1, i2 -> i1 - i2})
8720<
8721sound_clear() *sound_clear()*
8722 Stop playing all sounds.
8723
8724 On some Linux systems you may need the libcanberra-pulse
8725 package, otherwise sound may not stop.
8726
8727 {only available when compiled with the |+sound| feature}
8728
8729 *sound_playevent()*
8730sound_playevent({name} [, {callback}])
8731 Play a sound identified by {name}. Which event names are
8732 supported depends on the system. Often the XDG sound names
8733 are used. On Ubuntu they may be found in
8734 /usr/share/sounds/freedesktop/stereo. Example: >
8735 call sound_playevent('bell')
8736< On MS-Windows, {name} can be SystemAsterisk, SystemDefault,
8737 SystemExclamation, SystemExit, SystemHand, SystemQuestion,
8738 SystemStart, SystemWelcome, etc.
Yee Cheng Chin4314e4f2022-10-08 13:50:05 +01008739 On macOS, {name} refers to files located in
8740 /System/Library/Sounds (e.g. "Tink"). It will also work for
8741 custom installed sounds in folders like ~/Library/Sounds.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008742
8743 When {callback} is specified it is invoked when the sound is
8744 finished. The first argument is the sound ID, the second
8745 argument is the status:
8746 0 sound was played to the end
8747 1 sound was interrupted
8748 2 error occurred after sound started
8749 Example: >
8750 func Callback(id, status)
8751 echomsg "sound " .. a:id .. " finished with " .. a:status
8752 endfunc
8753 call sound_playevent('bell', 'Callback')
8754
8755< MS-Windows: {callback} doesn't work for this function.
8756
8757 Returns the sound ID, which can be passed to `sound_stop()`.
8758 Returns zero if the sound could not be played.
8759
8760 Can also be used as a |method|: >
8761 GetSoundName()->sound_playevent()
8762
8763< {only available when compiled with the |+sound| feature}
8764
8765 *sound_playfile()*
8766sound_playfile({path} [, {callback}])
8767 Like `sound_playevent()` but play sound file {path}. {path}
8768 must be a full path. On Ubuntu you may find files to play
8769 with this command: >
8770 :!find /usr/share/sounds -type f | grep -v index.theme
8771
8772< Can also be used as a |method|: >
8773 GetSoundPath()->sound_playfile()
8774
Bram Moolenaar1588bc82022-03-08 21:35:07 +00008775< {only available when compiled with the |+sound| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008776
8777
8778sound_stop({id}) *sound_stop()*
8779 Stop playing sound {id}. {id} must be previously returned by
8780 `sound_playevent()` or `sound_playfile()`.
8781
8782 On some Linux systems you may need the libcanberra-pulse
8783 package, otherwise sound may not stop.
8784
8785 On MS-Windows, this does not work for event sound started by
8786 `sound_playevent()`. To stop event sounds, use `sound_clear()`.
8787
8788 Can also be used as a |method|: >
8789 soundid->sound_stop()
8790
8791< {only available when compiled with the |+sound| feature}
8792
8793 *soundfold()*
8794soundfold({word})
8795 Return the sound-folded equivalent of {word}. Uses the first
8796 language in 'spelllang' for the current window that supports
8797 soundfolding. 'spell' must be set. When no sound folding is
8798 possible the {word} is returned unmodified.
8799 This can be used for making spelling suggestions. Note that
8800 the method can be quite slow.
8801
8802 Can also be used as a |method|: >
8803 GetWord()->soundfold()
8804<
8805 *spellbadword()*
8806spellbadword([{sentence}])
8807 Without argument: The result is the badly spelled word under
8808 or after the cursor. The cursor is moved to the start of the
8809 bad word. When no bad word is found in the cursor line the
8810 result is an empty string and the cursor doesn't move.
8811
8812 With argument: The result is the first word in {sentence} that
8813 is badly spelled. If there are no spelling mistakes the
8814 result is an empty string.
8815
8816 The return value is a list with two items:
8817 - The badly spelled word or an empty string.
8818 - The type of the spelling error:
8819 "bad" spelling mistake
8820 "rare" rare word
8821 "local" word only valid in another region
8822 "caps" word should start with Capital
8823 Example: >
8824 echo spellbadword("the quik brown fox")
8825< ['quik', 'bad'] ~
8826
8827 The spelling information for the current window and the value
8828 of 'spelllang' are used.
8829
8830 Can also be used as a |method|: >
8831 GetText()->spellbadword()
8832<
8833 *spellsuggest()*
8834spellsuggest({word} [, {max} [, {capital}]])
8835 Return a |List| with spelling suggestions to replace {word}.
8836 When {max} is given up to this number of suggestions are
8837 returned. Otherwise up to 25 suggestions are returned.
8838
8839 When the {capital} argument is given and it's non-zero only
8840 suggestions with a leading capital will be given. Use this
8841 after a match with 'spellcapcheck'.
8842
8843 {word} can be a badly spelled word followed by other text.
8844 This allows for joining two words that were split. The
8845 suggestions also include the following text, thus you can
8846 replace a line.
8847
8848 {word} may also be a good word. Similar words will then be
8849 returned. {word} itself is not included in the suggestions,
8850 although it may appear capitalized.
8851
8852 The spelling information for the current window is used. The
8853 values of 'spelllang' and 'spellsuggest' are used.
8854
8855 Can also be used as a |method|: >
8856 GetWord()->spellsuggest()
8857
8858split({string} [, {pattern} [, {keepempty}]]) *split()*
8859 Make a |List| out of {string}. When {pattern} is omitted or
8860 empty each white-separated sequence of characters becomes an
8861 item.
8862 Otherwise the string is split where {pattern} matches,
8863 removing the matched characters. 'ignorecase' is not used
8864 here, add \c to ignore case. |/\c|
8865 When the first or last item is empty it is omitted, unless the
8866 {keepempty} argument is given and it's non-zero.
8867 Other empty items are kept when {pattern} matches at least one
8868 character or when {keepempty} is non-zero.
8869 Example: >
8870 :let words = split(getline('.'), '\W\+')
8871< To split a string in individual characters: >
8872 :for c in split(mystring, '\zs')
8873< If you want to keep the separator you can also use '\zs' at
8874 the end of the pattern: >
8875 :echo split('abc:def:ghi', ':\zs')
8876< ['abc:', 'def:', 'ghi'] ~
8877 Splitting a table where the first element can be empty: >
8878 :let items = split(line, ':', 1)
8879< The opposite function is |join()|.
8880
8881 Can also be used as a |method|: >
8882 GetString()->split()
8883
8884sqrt({expr}) *sqrt()*
8885 Return the non-negative square root of Float {expr} as a
8886 |Float|.
8887 {expr} must evaluate to a |Float| or a |Number|. When {expr}
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01008888 is negative the result is NaN (Not a Number). Returns 0.0 if
8889 {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008890 Examples: >
8891 :echo sqrt(100)
8892< 10.0 >
8893 :echo sqrt(-4.01)
8894< nan
8895 "nan" may be different, it depends on system libraries.
8896
8897 Can also be used as a |method|: >
8898 Compute()->sqrt()
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008899
8900
8901srand([{expr}]) *srand()*
8902 Initialize seed used by |rand()|:
8903 - If {expr} is not given, seed values are initialized by
8904 reading from /dev/urandom, if possible, or using time(NULL)
8905 a.k.a. epoch time otherwise; this only has second accuracy.
8906 - If {expr} is given it must be a Number. It is used to
8907 initialize the seed values. This is useful for testing or
8908 when a predictable sequence is intended.
8909
8910 Examples: >
8911 :let seed = srand()
8912 :let seed = srand(userinput)
8913 :echo rand(seed)
8914
8915state([{what}]) *state()*
8916 Return a string which contains characters indicating the
8917 current state. Mostly useful in callbacks that want to do
8918 work that may not always be safe. Roughly this works like:
8919 - callback uses state() to check if work is safe to do.
8920 Yes: then do it right away.
8921 No: add to work queue and add a |SafeState| and/or
8922 |SafeStateAgain| autocommand (|SafeState| triggers at
8923 toplevel, |SafeStateAgain| triggers after handling
8924 messages and callbacks).
8925 - When SafeState or SafeStateAgain is triggered and executes
8926 your autocommand, check with `state()` if the work can be
8927 done now, and if yes remove it from the queue and execute.
8928 Remove the autocommand if the queue is now empty.
8929 Also see |mode()|.
8930
8931 When {what} is given only characters in this string will be
8932 added. E.g, this checks if the screen has scrolled: >
8933 if state('s') == ''
8934 " screen has not scrolled
8935<
8936 These characters indicate the state, generally indicating that
8937 something is busy:
8938 m halfway a mapping, :normal command, feedkeys() or
8939 stuffed command
8940 o operator pending, e.g. after |d|
8941 a Insert mode autocomplete active
8942 x executing an autocommand
8943 w blocked on waiting, e.g. ch_evalexpr(), ch_read() and
8944 ch_readraw() when reading json
8945 S not triggering SafeState or SafeStateAgain, e.g. after
8946 |f| or a count
8947 c callback invoked, including timer (repeats for
8948 recursiveness up to "ccc")
8949 s screen has scrolled for messages
8950
8951str2float({string} [, {quoted}]) *str2float()*
8952 Convert String {string} to a Float. This mostly works the
8953 same as when using a floating point number in an expression,
8954 see |floating-point-format|. But it's a bit more permissive.
8955 E.g., "1e40" is accepted, while in an expression you need to
8956 write "1.0e40". The hexadecimal form "0x123" is also
8957 accepted, but not others, like binary or octal.
8958 When {quoted} is present and non-zero then embedded single
8959 quotes before the dot are ignored, thus "1'000.0" is a
8960 thousand.
8961 Text after the number is silently ignored.
8962 The decimal point is always '.', no matter what the locale is
8963 set to. A comma ends the number: "12,345.67" is converted to
8964 12.0. You can strip out thousands separators with
8965 |substitute()|: >
8966 let f = str2float(substitute(text, ',', '', 'g'))
8967<
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01008968 Returns 0.0 if the conversion fails.
8969
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008970 Can also be used as a |method|: >
8971 let f = text->substitute(',', '', 'g')->str2float()
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008972
8973str2list({string} [, {utf8}]) *str2list()*
8974 Return a list containing the number values which represent
8975 each character in String {string}. Examples: >
8976 str2list(" ") returns [32]
8977 str2list("ABC") returns [65, 66, 67]
8978< |list2str()| does the opposite.
8979
8980 When {utf8} is omitted or zero, the current 'encoding' is used.
8981 When {utf8} is TRUE, always treat the String as UTF-8
8982 characters. With UTF-8 composing characters are handled
8983 properly: >
8984 str2list("á") returns [97, 769]
8985
8986< Can also be used as a |method|: >
8987 GetString()->str2list()
8988
8989
8990str2nr({string} [, {base} [, {quoted}]]) *str2nr()*
8991 Convert string {string} to a number.
8992 {base} is the conversion base, it can be 2, 8, 10 or 16.
8993 When {quoted} is present and non-zero then embedded single
8994 quotes are ignored, thus "1'000'000" is a million.
8995
8996 When {base} is omitted base 10 is used. This also means that
8997 a leading zero doesn't cause octal conversion to be used, as
8998 with the default String to Number conversion. Example: >
8999 let nr = str2nr('0123')
9000<
9001 When {base} is 16 a leading "0x" or "0X" is ignored. With a
9002 different base the result will be zero. Similarly, when
9003 {base} is 8 a leading "0", "0o" or "0O" is ignored, and when
9004 {base} is 2 a leading "0b" or "0B" is ignored.
9005 Text after the number is silently ignored.
9006
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01009007 Returns 0 if {string} is empty or on error.
9008
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009009 Can also be used as a |method|: >
9010 GetText()->str2nr()
9011
9012
9013strcharlen({string}) *strcharlen()*
9014 The result is a Number, which is the number of characters
9015 in String {string}. Composing characters are ignored.
9016 |strchars()| can count the number of characters, counting
9017 composing characters separately.
9018
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01009019 Returns 0 if {string} is empty or on error.
9020
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009021 Also see |strlen()|, |strdisplaywidth()| and |strwidth()|.
9022
9023 Can also be used as a |method|: >
9024 GetText()->strcharlen()
9025
9026
9027strcharpart({src}, {start} [, {len} [, {skipcc}]]) *strcharpart()*
9028 Like |strpart()| but using character index and length instead
9029 of byte index and length.
9030 When {skipcc} is omitted or zero, composing characters are
9031 counted separately.
9032 When {skipcc} set to 1, Composing characters are ignored,
9033 similar to |slice()|.
9034 When a character index is used where a character does not
9035 exist it is omitted and counted as one character. For
9036 example: >
9037 strcharpart('abc', -1, 2)
9038< results in 'a'.
9039
Bram Moolenaard592deb2022-06-17 15:42:40 +01009040 Returns an empty string on error.
9041
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009042 Can also be used as a |method|: >
9043 GetText()->strcharpart(5)
9044
9045
9046strchars({string} [, {skipcc}]) *strchars()*
9047 The result is a Number, which is the number of characters
9048 in String {string}.
9049 When {skipcc} is omitted or zero, composing characters are
9050 counted separately.
9051 When {skipcc} set to 1, Composing characters are ignored.
9052 |strcharlen()| always does this.
9053
Bram Moolenaard592deb2022-06-17 15:42:40 +01009054 Returns zero on error.
9055
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009056 Also see |strlen()|, |strdisplaywidth()| and |strwidth()|.
9057
9058 {skipcc} is only available after 7.4.755. For backward
9059 compatibility, you can define a wrapper function: >
9060 if has("patch-7.4.755")
9061 function s:strchars(str, skipcc)
9062 return strchars(a:str, a:skipcc)
9063 endfunction
9064 else
9065 function s:strchars(str, skipcc)
9066 if a:skipcc
9067 return strlen(substitute(a:str, ".", "x", "g"))
9068 else
9069 return strchars(a:str)
9070 endif
9071 endfunction
9072 endif
9073<
9074 Can also be used as a |method|: >
9075 GetText()->strchars()
9076
9077strdisplaywidth({string} [, {col}]) *strdisplaywidth()*
9078 The result is a Number, which is the number of display cells
9079 String {string} occupies on the screen when it starts at {col}
9080 (first column is zero). When {col} is omitted zero is used.
9081 Otherwise it is the screen column where to start. This
9082 matters for Tab characters.
9083 The option settings of the current window are used. This
9084 matters for anything that's displayed differently, such as
9085 'tabstop' and 'display'.
9086 When {string} contains characters with East Asian Width Class
9087 Ambiguous, this function's return value depends on 'ambiwidth'.
Bram Moolenaard592deb2022-06-17 15:42:40 +01009088 Returns zero on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009089 Also see |strlen()|, |strwidth()| and |strchars()|.
9090
9091 Can also be used as a |method|: >
9092 GetText()->strdisplaywidth()
9093
9094strftime({format} [, {time}]) *strftime()*
9095 The result is a String, which is a formatted date and time, as
9096 specified by the {format} string. The given {time} is used,
9097 or the current time if no time is given. The accepted
9098 {format} depends on your system, thus this is not portable!
9099 See the manual page of the C function strftime() for the
9100 format. The maximum length of the result is 80 characters.
9101 See also |localtime()|, |getftime()| and |strptime()|.
9102 The language can be changed with the |:language| command.
9103 Examples: >
9104 :echo strftime("%c") Sun Apr 27 11:49:23 1997
9105 :echo strftime("%Y %b %d %X") 1997 Apr 27 11:53:25
9106 :echo strftime("%y%m%d %T") 970427 11:53:55
9107 :echo strftime("%H:%M") 11:55
9108 :echo strftime("%c", getftime("file.c"))
9109 Show mod time of file.c.
9110< Not available on all systems. To check use: >
9111 :if exists("*strftime")
9112
9113< Can also be used as a |method|: >
9114 GetFormat()->strftime()
9115
9116strgetchar({str}, {index}) *strgetchar()*
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01009117 Get a Number corresponding to the character at {index} in
9118 {str}. This uses a zero-based character index, not a byte
9119 index. Composing characters are considered separate
9120 characters here. Use |nr2char()| to convert the Number to a
9121 String.
Bram Moolenaard592deb2022-06-17 15:42:40 +01009122 Returns -1 if {index} is invalid.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009123 Also see |strcharpart()| and |strchars()|.
9124
9125 Can also be used as a |method|: >
9126 GetText()->strgetchar(5)
9127
9128stridx({haystack}, {needle} [, {start}]) *stridx()*
9129 The result is a Number, which gives the byte index in
9130 {haystack} of the first occurrence of the String {needle}.
9131 If {start} is specified, the search starts at index {start}.
9132 This can be used to find a second match: >
9133 :let colon1 = stridx(line, ":")
9134 :let colon2 = stridx(line, ":", colon1 + 1)
9135< The search is done case-sensitive.
9136 For pattern searches use |match()|.
9137 -1 is returned if the {needle} does not occur in {haystack}.
9138 See also |strridx()|.
9139 Examples: >
9140 :echo stridx("An Example", "Example") 3
9141 :echo stridx("Starting point", "Start") 0
9142 :echo stridx("Starting point", "start") -1
9143< *strstr()* *strchr()*
9144 stridx() works similar to the C function strstr(). When used
9145 with a single character it works similar to strchr().
9146
9147 Can also be used as a |method|: >
9148 GetHaystack()->stridx(needle)
9149<
9150 *string()*
9151string({expr}) Return {expr} converted to a String. If {expr} is a Number,
9152 Float, String, Blob or a composition of them, then the result
9153 can be parsed back with |eval()|.
9154 {expr} type result ~
9155 String 'string' (single quotes are doubled)
9156 Number 123
9157 Float 123.123456 or 1.123456e8
9158 Funcref function('name')
9159 Blob 0z00112233.44556677.8899
9160 List [item, item]
9161 Dictionary {key: value, key: value}
Bram Moolenaarf1dcd142022-12-31 15:30:45 +00009162 Class class SomeName
9163 Object object of SomeName {lnum: 1, col: 3}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009164
9165 When a |List| or |Dictionary| has a recursive reference it is
9166 replaced by "[...]" or "{...}". Using eval() on the result
9167 will then fail.
9168
9169 Can also be used as a |method|: >
9170 mylist->string()
9171
9172< Also see |strtrans()|.
9173
9174
9175strlen({string}) *strlen()*
9176 The result is a Number, which is the length of the String
9177 {string} in bytes.
9178 If the argument is a Number it is first converted to a String.
Bram Moolenaard592deb2022-06-17 15:42:40 +01009179 For other types an error is given and zero is returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009180 If you want to count the number of multibyte characters use
9181 |strchars()|.
9182 Also see |len()|, |strdisplaywidth()| and |strwidth()|.
9183
9184 Can also be used as a |method|: >
9185 GetString()->strlen()
9186
9187strpart({src}, {start} [, {len} [, {chars}]]) *strpart()*
9188 The result is a String, which is part of {src}, starting from
9189 byte {start}, with the byte length {len}.
9190 When {chars} is present and TRUE then {len} is the number of
9191 characters positions (composing characters are not counted
9192 separately, thus "1" means one base character and any
9193 following composing characters).
9194 To count {start} as characters instead of bytes use
9195 |strcharpart()|.
9196
9197 When bytes are selected which do not exist, this doesn't
9198 result in an error, the bytes are simply omitted.
9199 If {len} is missing, the copy continues from {start} till the
9200 end of the {src}. >
9201 strpart("abcdefg", 3, 2) == "de"
9202 strpart("abcdefg", -2, 4) == "ab"
9203 strpart("abcdefg", 5, 4) == "fg"
9204 strpart("abcdefg", 3) == "defg"
9205
9206< Note: To get the first character, {start} must be 0. For
9207 example, to get the character under the cursor: >
9208 strpart(getline("."), col(".") - 1, 1, v:true)
9209<
Bram Moolenaard592deb2022-06-17 15:42:40 +01009210 Returns an empty string on error.
9211
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009212 Can also be used as a |method|: >
9213 GetText()->strpart(5)
9214
9215strptime({format}, {timestring}) *strptime()*
9216 The result is a Number, which is a unix timestamp representing
9217 the date and time in {timestring}, which is expected to match
9218 the format specified in {format}.
9219
9220 The accepted {format} depends on your system, thus this is not
9221 portable! See the manual page of the C function strptime()
9222 for the format. Especially avoid "%c". The value of $TZ also
9223 matters.
9224
9225 If the {timestring} cannot be parsed with {format} zero is
9226 returned. If you do not know the format of {timestring} you
9227 can try different {format} values until you get a non-zero
9228 result.
9229
9230 See also |strftime()|.
9231 Examples: >
9232 :echo strptime("%Y %b %d %X", "1997 Apr 27 11:49:23")
9233< 862156163 >
9234 :echo strftime("%c", strptime("%y%m%d %T", "970427 11:53:55"))
9235< Sun Apr 27 11:53:55 1997 >
9236 :echo strftime("%c", strptime("%Y%m%d%H%M%S", "19970427115355") + 3600)
9237< Sun Apr 27 12:53:55 1997
9238
9239 Can also be used as a |method|: >
9240 GetFormat()->strptime(timestring)
9241<
9242 Not available on all systems. To check use: >
9243 :if exists("*strptime")
9244
9245strridx({haystack}, {needle} [, {start}]) *strridx()*
9246 The result is a Number, which gives the byte index in
9247 {haystack} of the last occurrence of the String {needle}.
9248 When {start} is specified, matches beyond this index are
9249 ignored. This can be used to find a match before a previous
9250 match: >
9251 :let lastcomma = strridx(line, ",")
9252 :let comma2 = strridx(line, ",", lastcomma - 1)
9253< The search is done case-sensitive.
9254 For pattern searches use |match()|.
9255 -1 is returned if the {needle} does not occur in {haystack}.
9256 If the {needle} is empty the length of {haystack} is returned.
9257 See also |stridx()|. Examples: >
9258 :echo strridx("an angry armadillo", "an") 3
9259< *strrchr()*
9260 When used with a single character it works similar to the C
9261 function strrchr().
9262
9263 Can also be used as a |method|: >
9264 GetHaystack()->strridx(needle)
9265
9266strtrans({string}) *strtrans()*
9267 The result is a String, which is {string} with all unprintable
9268 characters translated into printable characters |'isprint'|.
9269 Like they are shown in a window. Example: >
9270 echo strtrans(@a)
9271< This displays a newline in register a as "^@" instead of
9272 starting a new line.
9273
Bram Moolenaard592deb2022-06-17 15:42:40 +01009274 Returns an empty string on error.
9275
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009276 Can also be used as a |method|: >
9277 GetString()->strtrans()
9278
Christian Brabandt67672ef2023-04-24 21:09:54 +01009279strutf16len({string} [, {countcc}]) *strutf16len()*
9280 The result is a Number, which is the number of UTF-16 code
9281 units in String {string} (after converting it to UTF-16).
9282
9283 When {countcc} is TRUE, composing characters are counted
9284 separately.
9285 When {countcc} is omitted or FALSE, composing characters are
9286 ignored.
9287
9288 Returns zero on error.
9289
9290 Also see |strlen()| and |strcharlen()|.
9291 Examples: >
9292 echo strutf16len('a') returns 1
9293 echo strutf16len('©') returns 1
9294 echo strutf16len('😊') returns 2
9295 echo strutf16len('ą́') returns 1
9296 echo strutf16len('ą́', v:true) returns 3
9297
9298 Can also be used as a |method|: >
9299 GetText()->strutf16len()
9300<
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009301strwidth({string}) *strwidth()*
9302 The result is a Number, which is the number of display cells
9303 String {string} occupies. A Tab character is counted as one
9304 cell, alternatively use |strdisplaywidth()|.
9305 When {string} contains characters with East Asian Width Class
9306 Ambiguous, this function's return value depends on 'ambiwidth'.
Bram Moolenaard592deb2022-06-17 15:42:40 +01009307 Returns zero on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009308 Also see |strlen()|, |strdisplaywidth()| and |strchars()|.
9309
9310 Can also be used as a |method|: >
9311 GetString()->strwidth()
9312
9313submatch({nr} [, {list}]) *submatch()* *E935*
9314 Only for an expression in a |:substitute| command or
9315 substitute() function.
9316 Returns the {nr}'th submatch of the matched text. When {nr}
9317 is 0 the whole matched text is returned.
9318 Note that a NL in the string can stand for a line break of a
9319 multi-line match or a NUL character in the text.
9320 Also see |sub-replace-expression|.
9321
9322 If {list} is present and non-zero then submatch() returns
9323 a list of strings, similar to |getline()| with two arguments.
9324 NL characters in the text represent NUL characters in the
9325 text.
9326 Only returns more than one item for |:substitute|, inside
9327 |substitute()| this list will always contain one or zero
9328 items, since there are no real line breaks.
9329
9330 When substitute() is used recursively only the submatches in
9331 the current (deepest) call can be obtained.
9332
Bram Moolenaard592deb2022-06-17 15:42:40 +01009333 Returns an empty string or list on error.
9334
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009335 Examples: >
9336 :s/\d\+/\=submatch(0) + 1/
9337 :echo substitute(text, '\d\+', '\=submatch(0) + 1', '')
9338< This finds the first number in the line and adds one to it.
9339 A line break is included as a newline character.
9340
9341 Can also be used as a |method|: >
9342 GetNr()->submatch()
9343
9344substitute({string}, {pat}, {sub}, {flags}) *substitute()*
9345 The result is a String, which is a copy of {string}, in which
9346 the first match of {pat} is replaced with {sub}.
9347 When {flags} is "g", all matches of {pat} in {string} are
9348 replaced. Otherwise {flags} should be "".
9349
9350 This works like the ":substitute" command (without any flags).
9351 But the matching with {pat} is always done like the 'magic'
9352 option is set and 'cpoptions' is empty (to make scripts
9353 portable). 'ignorecase' is still relevant, use |/\c| or |/\C|
9354 if you want to ignore or match case and ignore 'ignorecase'.
9355 'smartcase' is not used. See |string-match| for how {pat} is
9356 used.
9357
9358 A "~" in {sub} is not replaced with the previous {sub}.
9359 Note that some codes in {sub} have a special meaning
9360 |sub-replace-special|. For example, to replace something with
9361 "\n" (two characters), use "\\\\n" or '\\n'.
9362
9363 When {pat} does not match in {string}, {string} is returned
9364 unmodified.
9365
9366 Example: >
9367 :let &path = substitute(&path, ",\\=[^,]*$", "", "")
9368< This removes the last component of the 'path' option. >
9369 :echo substitute("testing", ".*", "\\U\\0", "")
9370< results in "TESTING".
9371
9372 When {sub} starts with "\=", the remainder is interpreted as
9373 an expression. See |sub-replace-expression|. Example: >
9374 :echo substitute(s, '%\(\x\x\)',
Bram Moolenaarc51cf032022-02-26 12:25:45 +00009375 \ '\=nr2char("0x" .. submatch(1))', 'g')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009376
9377< When {sub} is a Funcref that function is called, with one
9378 optional argument. Example: >
9379 :echo substitute(s, '%\(\x\x\)', SubNr, 'g')
9380< The optional argument is a list which contains the whole
9381 matched string and up to nine submatches, like what
9382 |submatch()| returns. Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00009383 :echo substitute(s, '%\(\x\x\)', {m -> '0x' .. m[1]}, 'g')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009384
Bram Moolenaard592deb2022-06-17 15:42:40 +01009385< Returns an empty string on error.
9386
9387 Can also be used as a |method|: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009388 GetString()->substitute(pat, sub, flags)
9389
Bram Moolenaarc216a7a2022-12-05 13:50:55 +00009390swapfilelist() *swapfilelist()*
9391 Returns a list of swap file names, like what "vim -r" shows.
9392 See the |-r| command argument. The 'directory' option is used
9393 for the directories to inspect. If you only want to get a
9394 list of swap files in the current directory then temporarily
9395 set 'directory' to a dot: >
9396 let save_dir = &directory
9397 let &directory = '.'
9398 let swapfiles = swapfilelist()
9399 let &directory = save_dir
9400
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009401swapinfo({fname}) *swapinfo()*
9402 The result is a dictionary, which holds information about the
9403 swapfile {fname}. The available fields are:
9404 version Vim version
9405 user user name
9406 host host name
9407 fname original file name
9408 pid PID of the Vim process that created the swap
9409 file
9410 mtime last modification time in seconds
9411 inode Optional: INODE number of the file
9412 dirty 1 if file was modified, 0 if not
9413 Note that "user" and "host" are truncated to at most 39 bytes.
9414 In case of failure an "error" item is added with the reason:
9415 Cannot open file: file not found or in accessible
9416 Cannot read file: cannot read first block
9417 Not a swap file: does not contain correct block ID
9418 Magic number mismatch: Info in first block is invalid
9419
9420 Can also be used as a |method|: >
9421 GetFilename()->swapinfo()
9422
9423swapname({buf}) *swapname()*
9424 The result is the swap file path of the buffer {expr}.
9425 For the use of {buf}, see |bufname()| above.
9426 If buffer {buf} is the current buffer, the result is equal to
9427 |:swapname| (unless there is no swap file).
9428 If buffer {buf} has no swap file, returns an empty string.
9429
9430 Can also be used as a |method|: >
9431 GetBufname()->swapname()
9432
9433synID({lnum}, {col}, {trans}) *synID()*
9434 The result is a Number, which is the syntax ID at the position
9435 {lnum} and {col} in the current window.
9436 The syntax ID can be used with |synIDattr()| and
9437 |synIDtrans()| to obtain syntax information about text.
9438
9439 {col} is 1 for the leftmost column, {lnum} is 1 for the first
9440 line. 'synmaxcol' applies, in a longer line zero is returned.
9441 Note that when the position is after the last character,
9442 that's where the cursor can be in Insert mode, synID() returns
9443 zero. {lnum} is used like with |getline()|.
9444
9445 When {trans} is |TRUE|, transparent items are reduced to the
9446 item that they reveal. This is useful when wanting to know
9447 the effective color. When {trans} is |FALSE|, the transparent
9448 item is returned. This is useful when wanting to know which
9449 syntax item is effective (e.g. inside parens).
9450 Warning: This function can be very slow. Best speed is
9451 obtained by going through the file in forward direction.
9452
Bram Moolenaard592deb2022-06-17 15:42:40 +01009453 Returns zero on error.
9454
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009455 Example (echoes the name of the syntax item under the cursor): >
9456 :echo synIDattr(synID(line("."), col("."), 1), "name")
9457<
9458
9459synIDattr({synID}, {what} [, {mode}]) *synIDattr()*
9460 The result is a String, which is the {what} attribute of
9461 syntax ID {synID}. This can be used to obtain information
9462 about a syntax item.
9463 {mode} can be "gui", "cterm" or "term", to get the attributes
9464 for that mode. When {mode} is omitted, or an invalid value is
9465 used, the attributes for the currently active highlighting are
9466 used (GUI, cterm or term).
9467 Use synIDtrans() to follow linked highlight groups.
9468 {what} result
9469 "name" the name of the syntax item
9470 "fg" foreground color (GUI: color name used to set
9471 the color, cterm: color number as a string,
9472 term: empty string)
9473 "bg" background color (as with "fg")
9474 "font" font name (only available in the GUI)
9475 |highlight-font|
9476 "sp" special color for the GUI (as with "fg")
9477 |highlight-guisp|
9478 "ul" underline color for cterm: number as a string
9479 "fg#" like "fg", but for the GUI and the GUI is
9480 running the name in "#RRGGBB" form
9481 "bg#" like "fg#" for "bg"
9482 "sp#" like "fg#" for "sp"
9483 "bold" "1" if bold
9484 "italic" "1" if italic
9485 "reverse" "1" if reverse
9486 "inverse" "1" if inverse (= reverse)
9487 "standout" "1" if standout
9488 "underline" "1" if underlined
9489 "undercurl" "1" if undercurled
9490 "strike" "1" if strikethrough
Bram Moolenaarde786322022-07-30 14:56:17 +01009491 "nocombine" "1" if nocombine
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009492
Bram Moolenaard592deb2022-06-17 15:42:40 +01009493 Returns an empty string on error.
9494
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009495 Example (echoes the color of the syntax item under the
9496 cursor): >
9497 :echo synIDattr(synIDtrans(synID(line("."), col("."), 1)), "fg")
9498<
9499 Can also be used as a |method|: >
9500 :echo synID(line("."), col("."), 1)->synIDtrans()->synIDattr("fg")
9501
9502
9503synIDtrans({synID}) *synIDtrans()*
9504 The result is a Number, which is the translated syntax ID of
9505 {synID}. This is the syntax group ID of what is being used to
9506 highlight the character. Highlight links given with
9507 ":highlight link" are followed.
9508
Bram Moolenaard592deb2022-06-17 15:42:40 +01009509 Returns zero on error.
9510
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009511 Can also be used as a |method|: >
9512 :echo synID(line("."), col("."), 1)->synIDtrans()->synIDattr("fg")
9513
9514synconcealed({lnum}, {col}) *synconcealed()*
9515 The result is a |List| with currently three items:
9516 1. The first item in the list is 0 if the character at the
9517 position {lnum} and {col} is not part of a concealable
9518 region, 1 if it is. {lnum} is used like with |getline()|.
9519 2. The second item in the list is a string. If the first item
9520 is 1, the second item contains the text which will be
9521 displayed in place of the concealed text, depending on the
9522 current setting of 'conceallevel' and 'listchars'.
9523 3. The third and final item in the list is a number
9524 representing the specific syntax region matched in the
9525 line. When the character is not concealed the value is
9526 zero. This allows detection of the beginning of a new
9527 concealable region if there are two consecutive regions
9528 with the same replacement character. For an example, if
9529 the text is "123456" and both "23" and "45" are concealed
9530 and replaced by the character "X", then:
9531 call returns ~
9532 synconcealed(lnum, 1) [0, '', 0]
9533 synconcealed(lnum, 2) [1, 'X', 1]
9534 synconcealed(lnum, 3) [1, 'X', 1]
9535 synconcealed(lnum, 4) [1, 'X', 2]
9536 synconcealed(lnum, 5) [1, 'X', 2]
9537 synconcealed(lnum, 6) [0, '', 0]
9538
9539
9540synstack({lnum}, {col}) *synstack()*
9541 Return a |List|, which is the stack of syntax items at the
9542 position {lnum} and {col} in the current window. {lnum} is
9543 used like with |getline()|. Each item in the List is an ID
9544 like what |synID()| returns.
9545 The first item in the List is the outer region, following are
9546 items contained in that one. The last one is what |synID()|
9547 returns, unless not the whole item is highlighted or it is a
9548 transparent item.
9549 This function is useful for debugging a syntax file.
9550 Example that shows the syntax stack under the cursor: >
9551 for id in synstack(line("."), col("."))
9552 echo synIDattr(id, "name")
9553 endfor
9554< When the position specified with {lnum} and {col} is invalid
Bram Moolenaard592deb2022-06-17 15:42:40 +01009555 an empty List is returned. The position just after the last
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009556 character in a line and the first column in an empty line are
9557 valid positions.
9558
9559system({expr} [, {input}]) *system()* *E677*
9560 Get the output of the shell command {expr} as a |String|. See
9561 |systemlist()| to get the output as a |List|.
9562
9563 When {input} is given and is a |String| this string is written
9564 to a file and passed as stdin to the command. The string is
9565 written as-is, you need to take care of using the correct line
9566 separators yourself.
9567 If {input} is given and is a |List| it is written to the file
9568 in a way |writefile()| does with {binary} set to "b" (i.e.
9569 with a newline between each list item with newlines inside
9570 list items converted to NULs).
9571 When {input} is given and is a number that is a valid id for
9572 an existing buffer then the content of the buffer is written
9573 to the file line by line, each line terminated by a NL and
9574 NULs characters where the text has a NL.
9575
9576 Pipes are not used, the 'shelltemp' option is not used.
9577
9578 When prepended by |:silent| the terminal will not be set to
9579 cooked mode. This is meant to be used for commands that do
9580 not need the user to type. It avoids stray characters showing
9581 up on the screen which require |CTRL-L| to remove. >
9582 :silent let f = system('ls *.vim')
9583<
9584 Note: Use |shellescape()| or |::S| with |expand()| or
9585 |fnamemodify()| to escape special characters in a command
9586 argument. Newlines in {expr} may cause the command to fail.
9587 The characters in 'shellquote' and 'shellxquote' may also
9588 cause trouble.
9589 This is not to be used for interactive commands.
9590
9591 The result is a String. Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00009592 :let files = system('ls ' .. shellescape(expand('%:h')))
9593 :let files = system('ls ' .. expand('%:h:S'))
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009594
9595< To make the result more system-independent, the shell output
9596 is filtered to replace <CR> with <NL> for Macintosh, and
9597 <CR><NL> with <NL> for DOS-like systems.
9598 To avoid the string being truncated at a NUL, all NUL
9599 characters are replaced with SOH (0x01).
9600
9601 The command executed is constructed using several options:
9602 'shell' 'shellcmdflag' 'shellxquote' {expr} 'shellredir' {tmp} 'shellxquote'
9603 ({tmp} is an automatically generated file name).
9604 For Unix, braces are put around {expr} to allow for
9605 concatenated commands.
9606
9607 The command will be executed in "cooked" mode, so that a
9608 CTRL-C will interrupt the command (on Unix at least).
9609
9610 The resulting error code can be found in |v:shell_error|.
9611 This function will fail in |restricted-mode|.
9612
9613 Note that any wrong value in the options mentioned above may
9614 make the function fail. It has also been reported to fail
9615 when using a security agent application.
9616 Unlike ":!cmd" there is no automatic check for changed files.
9617 Use |:checktime| to force a check.
9618
9619 Can also be used as a |method|: >
9620 :echo GetCmd()->system()
9621
9622
9623systemlist({expr} [, {input}]) *systemlist()*
9624 Same as |system()|, but returns a |List| with lines (parts of
9625 output separated by NL) with NULs transformed into NLs. Output
9626 is the same as |readfile()| will output with {binary} argument
9627 set to "b", except that there is no extra empty item when the
9628 result ends in a NL.
9629 Note that on MS-Windows you may get trailing CR characters.
9630
9631 To see the difference between "echo hello" and "echo -n hello"
9632 use |system()| and |split()|: >
9633 echo system('echo hello')->split('\n', 1)
9634<
9635 Returns an empty string on error.
9636
9637 Can also be used as a |method|: >
9638 :echo GetCmd()->systemlist()
9639
9640
9641tabpagebuflist([{arg}]) *tabpagebuflist()*
9642 The result is a |List|, where each item is the number of the
9643 buffer associated with each window in the current tab page.
9644 {arg} specifies the number of the tab page to be used. When
9645 omitted the current tab page is used.
9646 When {arg} is invalid the number zero is returned.
9647 To get a list of all buffers in all tabs use this: >
9648 let buflist = []
9649 for i in range(tabpagenr('$'))
9650 call extend(buflist, tabpagebuflist(i + 1))
9651 endfor
9652< Note that a buffer may appear in more than one window.
9653
9654 Can also be used as a |method|: >
9655 GetTabpage()->tabpagebuflist()
9656
9657tabpagenr([{arg}]) *tabpagenr()*
9658 The result is a Number, which is the number of the current
9659 tab page. The first tab page has number 1.
9660
9661 The optional argument {arg} supports the following values:
9662 $ the number of the last tab page (the tab page
9663 count).
9664 # the number of the last accessed tab page
9665 (where |g<Tab>| goes to). if there is no
9666 previous tab page 0 is returned.
9667 The number can be used with the |:tab| command.
9668
Bram Moolenaard592deb2022-06-17 15:42:40 +01009669 Returns zero on error.
9670
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009671
9672tabpagewinnr({tabarg} [, {arg}]) *tabpagewinnr()*
9673 Like |winnr()| but for tab page {tabarg}.
9674 {tabarg} specifies the number of tab page to be used.
9675 {arg} is used like with |winnr()|:
9676 - When omitted the current window number is returned. This is
9677 the window which will be used when going to this tab page.
9678 - When "$" the number of windows is returned.
9679 - When "#" the previous window nr is returned.
9680 Useful examples: >
9681 tabpagewinnr(1) " current window of tab page 1
9682 tabpagewinnr(4, '$') " number of windows in tab page 4
9683< When {tabarg} is invalid zero is returned.
9684
9685 Can also be used as a |method|: >
9686 GetTabpage()->tabpagewinnr()
9687<
9688 *tagfiles()*
9689tagfiles() Returns a |List| with the file names used to search for tags
9690 for the current buffer. This is the 'tags' option expanded.
9691
9692
9693taglist({expr} [, {filename}]) *taglist()*
9694 Returns a |List| of tags matching the regular expression {expr}.
9695
9696 If {filename} is passed it is used to prioritize the results
9697 in the same way that |:tselect| does. See |tag-priority|.
9698 {filename} should be the full path of the file.
9699
9700 Each list item is a dictionary with at least the following
9701 entries:
9702 name Name of the tag.
9703 filename Name of the file where the tag is
9704 defined. It is either relative to the
9705 current directory or a full path.
9706 cmd Ex command used to locate the tag in
9707 the file.
9708 kind Type of the tag. The value for this
9709 entry depends on the language specific
9710 kind values. Only available when
9711 using a tags file generated by
Bram Moolenaar47c532e2022-03-19 15:18:53 +00009712 Universal/Exuberant ctags or hdrtag.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009713 static A file specific tag. Refer to
9714 |static-tag| for more information.
9715 More entries may be present, depending on the content of the
9716 tags file: access, implementation, inherits and signature.
9717 Refer to the ctags documentation for information about these
9718 fields. For C code the fields "struct", "class" and "enum"
9719 may appear, they give the name of the entity the tag is
9720 contained in.
9721
9722 The ex-command "cmd" can be either an ex search pattern, a
9723 line number or a line number followed by a byte number.
9724
9725 If there are no matching tags, then an empty list is returned.
9726
9727 To get an exact tag match, the anchors '^' and '$' should be
9728 used in {expr}. This also make the function work faster.
9729 Refer to |tag-regexp| for more information about the tag
9730 search regular expression pattern.
9731
9732 Refer to |'tags'| for information about how the tags file is
9733 located by Vim. Refer to |tags-file-format| for the format of
9734 the tags file generated by the different ctags tools.
9735
9736 Can also be used as a |method|: >
9737 GetTagpattern()->taglist()
9738
9739tan({expr}) *tan()*
9740 Return the tangent of {expr}, measured in radians, as a |Float|
9741 in the range [-inf, inf].
9742 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaard592deb2022-06-17 15:42:40 +01009743 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009744 Examples: >
9745 :echo tan(10)
9746< 0.648361 >
9747 :echo tan(-4.01)
9748< -1.181502
9749
9750 Can also be used as a |method|: >
9751 Compute()->tan()
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009752
9753
9754tanh({expr}) *tanh()*
9755 Return the hyperbolic tangent of {expr} as a |Float| in the
9756 range [-1, 1].
9757 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaard592deb2022-06-17 15:42:40 +01009758 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009759 Examples: >
9760 :echo tanh(0.5)
9761< 0.462117 >
9762 :echo tanh(-1)
9763< -0.761594
9764
9765 Can also be used as a |method|: >
9766 Compute()->tanh()
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009767
9768
9769tempname() *tempname()* *temp-file-name*
9770 The result is a String, which is the name of a file that
9771 doesn't exist. It can be used for a temporary file. The name
9772 is different for at least 26 consecutive calls. Example: >
9773 :let tmpfile = tempname()
Bram Moolenaarc51cf032022-02-26 12:25:45 +00009774 :exe "redir > " .. tmpfile
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009775< For Unix, the file will be in a private directory |tempfile|.
9776 For MS-Windows forward slashes are used when the 'shellslash'
9777 option is set, or when 'shellcmdflag' starts with '-' and
9778 'shell' does not contain powershell or pwsh.
9779
9780
9781term_ functions are documented here: |terminal-function-details|
9782
9783
9784terminalprops() *terminalprops()*
9785 Returns a |Dictionary| with properties of the terminal that Vim
9786 detected from the response to |t_RV| request. See
9787 |v:termresponse| for the response itself. If |v:termresponse|
9788 is empty most values here will be 'u' for unknown.
9789 cursor_style whether sending |t_RS| works **
9790 cursor_blink_mode whether sending |t_RC| works **
9791 underline_rgb whether |t_8u| works **
9792 mouse mouse type supported
Bram Moolenaar4bc85f22022-10-21 14:17:24 +01009793 kitty whether Kitty terminal was detected
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009794
9795 ** value 'u' for unknown, 'y' for yes, 'n' for no
9796
9797 If the |+termresponse| feature is missing then the result is
9798 an empty dictionary.
9799
9800 If "cursor_style" is 'y' then |t_RS| will be sent to request the
9801 current cursor style.
9802 If "cursor_blink_mode" is 'y' then |t_RC| will be sent to
9803 request the cursor blink status.
9804 "cursor_style" and "cursor_blink_mode" are also set if |t_u7|
9805 is not empty, Vim will detect the working of sending |t_RS|
9806 and |t_RC| on startup.
9807
9808 When "underline_rgb" is not 'y', then |t_8u| will be made empty.
9809 This avoids sending it to xterm, which would clear the colors.
9810
9811 For "mouse" the value 'u' is unknown
9812
9813 Also see:
9814 - 'ambiwidth' - detected by using |t_u7|.
9815 - |v:termstyleresp| and |v:termblinkresp| for the response to
9816 |t_RS| and |t_RC|.
9817
9818
9819test_ functions are documented here: |test-functions-details|
9820
9821
9822 *timer_info()*
9823timer_info([{id}])
9824 Return a list with information about timers.
9825 When {id} is given only information about this timer is
9826 returned. When timer {id} does not exist an empty list is
9827 returned.
9828 When {id} is omitted information about all timers is returned.
9829
9830 For each timer the information is stored in a |Dictionary| with
9831 these items:
9832 "id" the timer ID
9833 "time" time the timer was started with
9834 "remaining" time until the timer fires
9835 "repeat" number of times the timer will still fire;
9836 -1 means forever
9837 "callback" the callback
9838 "paused" 1 if the timer is paused, 0 otherwise
9839
9840 Can also be used as a |method|: >
9841 GetTimer()->timer_info()
9842
9843< {only available when compiled with the |+timers| feature}
9844
9845timer_pause({timer}, {paused}) *timer_pause()*
9846 Pause or unpause a timer. A paused timer does not invoke its
9847 callback when its time expires. Unpausing a timer may cause
9848 the callback to be invoked almost immediately if enough time
9849 has passed.
9850
9851 Pausing a timer is useful to avoid the callback to be called
9852 for a short time.
9853
9854 If {paused} evaluates to a non-zero Number or a non-empty
9855 String, then the timer is paused, otherwise it is unpaused.
9856 See |non-zero-arg|.
9857
9858 Can also be used as a |method|: >
9859 GetTimer()->timer_pause(1)
9860
9861< {only available when compiled with the |+timers| feature}
9862
9863 *timer_start()* *timer* *timers*
9864timer_start({time}, {callback} [, {options}])
9865 Create a timer and return the timer ID.
9866
9867 {time} is the waiting time in milliseconds. This is the
9868 minimum time before invoking the callback. When the system is
9869 busy or Vim is not waiting for input the time will be longer.
Bram Moolenaardd60c362023-02-27 15:49:53 +00009870 Zero can be used to execute the callback when Vim is back in
9871 the main loop.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009872
9873 {callback} is the function to call. It can be the name of a
9874 function or a |Funcref|. It is called with one argument, which
9875 is the timer ID. The callback is only invoked when Vim is
9876 waiting for input.
9877 If you want to show a message look at |popup_notification()|
9878 to avoid interfering with what the user is doing.
9879
9880 {options} is a dictionary. Supported entries:
9881 "repeat" Number of times to repeat calling the
9882 callback. -1 means forever. When not present
9883 the callback will be called once.
9884 If the timer causes an error three times in a
9885 row the repeat is cancelled. This avoids that
9886 Vim becomes unusable because of all the error
9887 messages.
9888
Bram Moolenaard592deb2022-06-17 15:42:40 +01009889 Returns -1 on error.
9890
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009891 Example: >
9892 func MyHandler(timer)
9893 echo 'Handler called'
9894 endfunc
9895 let timer = timer_start(500, 'MyHandler',
9896 \ {'repeat': 3})
9897< This will invoke MyHandler() three times at 500 msec
9898 intervals.
9899
9900 Can also be used as a |method|: >
9901 GetMsec()->timer_start(callback)
9902
9903< Not available in the |sandbox|.
9904 {only available when compiled with the |+timers| feature}
9905
9906timer_stop({timer}) *timer_stop()*
9907 Stop a timer. The timer callback will no longer be invoked.
9908 {timer} is an ID returned by timer_start(), thus it must be a
9909 Number. If {timer} does not exist there is no error.
9910
9911 Can also be used as a |method|: >
9912 GetTimer()->timer_stop()
9913
9914< {only available when compiled with the |+timers| feature}
9915
9916timer_stopall() *timer_stopall()*
9917 Stop all timers. The timer callbacks will no longer be
9918 invoked. Useful if a timer is misbehaving. If there are no
9919 timers there is no error.
9920
9921 {only available when compiled with the |+timers| feature}
9922
9923tolower({expr}) *tolower()*
9924 The result is a copy of the String given, with all uppercase
9925 characters turned into lowercase (just like applying |gu| to
Bram Moolenaard592deb2022-06-17 15:42:40 +01009926 the string). Returns an empty string on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009927
9928 Can also be used as a |method|: >
9929 GetText()->tolower()
9930
9931toupper({expr}) *toupper()*
9932 The result is a copy of the String given, with all lowercase
9933 characters turned into uppercase (just like applying |gU| to
Bram Moolenaard592deb2022-06-17 15:42:40 +01009934 the string). Returns an empty string on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009935
9936 Can also be used as a |method|: >
9937 GetText()->toupper()
9938
9939tr({src}, {fromstr}, {tostr}) *tr()*
9940 The result is a copy of the {src} string with all characters
9941 which appear in {fromstr} replaced by the character in that
9942 position in the {tostr} string. Thus the first character in
9943 {fromstr} is translated into the first character in {tostr}
9944 and so on. Exactly like the unix "tr" command.
9945 This code also deals with multibyte characters properly.
9946
Bram Moolenaard592deb2022-06-17 15:42:40 +01009947 Returns an empty string on error.
9948
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009949 Examples: >
9950 echo tr("hello there", "ht", "HT")
9951< returns "Hello THere" >
9952 echo tr("<blob>", "<>", "{}")
9953< returns "{blob}"
9954
9955 Can also be used as a |method|: >
9956 GetText()->tr(from, to)
9957
9958trim({text} [, {mask} [, {dir}]]) *trim()*
9959 Return {text} as a String where any character in {mask} is
9960 removed from the beginning and/or end of {text}.
9961
9962 If {mask} is not given, {mask} is all characters up to 0x20,
9963 which includes Tab, space, NL and CR, plus the non-breaking
9964 space character 0xa0.
9965
9966 The optional {dir} argument specifies where to remove the
9967 characters:
9968 0 remove from the beginning and end of {text}
9969 1 remove only at the beginning of {text}
9970 2 remove only at the end of {text}
9971 When omitted both ends are trimmed.
9972
9973 This function deals with multibyte characters properly.
Bram Moolenaard592deb2022-06-17 15:42:40 +01009974 Returns an empty string on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009975
9976 Examples: >
9977 echo trim(" some text ")
9978< returns "some text" >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00009979 echo trim(" \r\t\t\r RESERVE \t\n\x0B\xA0") .. "_TAIL"
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009980< returns "RESERVE_TAIL" >
9981 echo trim("rm<Xrm<>X>rrm", "rm<>")
9982< returns "Xrm<>X" (characters in the middle are not removed) >
9983 echo trim(" vim ", " ", 2)
9984< returns " vim"
9985
9986 Can also be used as a |method|: >
9987 GetText()->trim()
9988
9989trunc({expr}) *trunc()*
9990 Return the largest integral value with magnitude less than or
9991 equal to {expr} as a |Float| (truncate towards zero).
9992 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaard592deb2022-06-17 15:42:40 +01009993 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009994 Examples: >
9995 echo trunc(1.456)
9996< 1.0 >
9997 echo trunc(-5.456)
9998< -5.0 >
9999 echo trunc(4.0)
10000< 4.0
10001
10002 Can also be used as a |method|: >
10003 Compute()->trunc()
10004<
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010005 *type()*
10006type({expr}) The result is a Number representing the type of {expr}.
10007 Instead of using the number directly, it is better to use the
10008 v:t_ variable that has the value:
10009 Number: 0 |v:t_number|
10010 String: 1 |v:t_string|
10011 Funcref: 2 |v:t_func|
10012 List: 3 |v:t_list|
10013 Dictionary: 4 |v:t_dict|
10014 Float: 5 |v:t_float|
10015 Boolean: 6 |v:t_bool| (v:false and v:true)
10016 None: 7 |v:t_none| (v:null and v:none)
10017 Job: 8 |v:t_job|
10018 Channel: 9 |v:t_channel|
10019 Blob: 10 |v:t_blob|
Bram Moolenaarc0c2c262023-01-12 21:08:53 +000010020 Class 12 |v:t_class|
10021 Object 13 |v:t_object|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010022 For backward compatibility, this method can be used: >
10023 :if type(myvar) == type(0)
10024 :if type(myvar) == type("")
10025 :if type(myvar) == type(function("tr"))
10026 :if type(myvar) == type([])
10027 :if type(myvar) == type({})
10028 :if type(myvar) == type(0.0)
10029 :if type(myvar) == type(v:false)
10030 :if type(myvar) == type(v:none)
10031< To check if the v:t_ variables exist use this: >
10032 :if exists('v:t_number')
10033
10034< Can also be used as a |method|: >
10035 mylist->type()
10036
10037
10038typename({expr}) *typename()*
10039 Return a string representation of the type of {expr}.
10040 Example: >
10041 echo typename([1, 2, 3])
Kota Kato66bb9ae2023-01-17 18:31:56 +000010042< list<number> ~
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010043
10044
10045undofile({name}) *undofile()*
10046 Return the name of the undo file that would be used for a file
10047 with name {name} when writing. This uses the 'undodir'
10048 option, finding directories that exist. It does not check if
10049 the undo file exists.
10050 {name} is always expanded to the full path, since that is what
10051 is used internally.
10052 If {name} is empty undofile() returns an empty string, since a
10053 buffer without a file name will not write an undo file.
10054 Useful in combination with |:wundo| and |:rundo|.
10055 When compiled without the |+persistent_undo| option this always
10056 returns an empty string.
10057
10058 Can also be used as a |method|: >
10059 GetFilename()->undofile()
10060
10061undotree() *undotree()*
10062 Return the current state of the undo tree in a dictionary with
10063 the following items:
10064 "seq_last" The highest undo sequence number used.
10065 "seq_cur" The sequence number of the current position in
10066 the undo tree. This differs from "seq_last"
10067 when some changes were undone.
10068 "time_cur" Time last used for |:earlier| and related
10069 commands. Use |strftime()| to convert to
10070 something readable.
10071 "save_last" Number of the last file write. Zero when no
10072 write yet.
10073 "save_cur" Number of the current position in the undo
10074 tree.
10075 "synced" Non-zero when the last undo block was synced.
10076 This happens when waiting from input from the
10077 user. See |undo-blocks|.
10078 "entries" A list of dictionaries with information about
10079 undo blocks.
10080
10081 The first item in the "entries" list is the oldest undo item.
10082 Each List item is a |Dictionary| with these items:
10083 "seq" Undo sequence number. Same as what appears in
10084 |:undolist|.
10085 "time" Timestamp when the change happened. Use
10086 |strftime()| to convert to something readable.
10087 "newhead" Only appears in the item that is the last one
10088 that was added. This marks the last change
10089 and where further changes will be added.
10090 "curhead" Only appears in the item that is the last one
10091 that was undone. This marks the current
10092 position in the undo tree, the block that will
10093 be used by a redo command. When nothing was
10094 undone after the last change this item will
10095 not appear anywhere.
10096 "save" Only appears on the last block before a file
10097 write. The number is the write count. The
10098 first write has number 1, the last one the
10099 "save_last" mentioned above.
10100 "alt" Alternate entry. This is again a List of undo
10101 blocks. Each item may again have an "alt"
10102 item.
10103
10104uniq({list} [, {func} [, {dict}]]) *uniq()* *E882*
10105 Remove second and succeeding copies of repeated adjacent
10106 {list} items in-place. Returns {list}. If you want a list
10107 to remain unmodified make a copy first: >
10108 :let newlist = uniq(copy(mylist))
10109< The default compare function uses the string representation of
10110 each item. For the use of {func} and {dict} see |sort()|.
10111
Bram Moolenaard592deb2022-06-17 15:42:40 +010010112 Returns zero if {list} is not a |List|.
10113
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010114 Can also be used as a |method|: >
10115 mylist->uniq()
Christian Brabandt67672ef2023-04-24 21:09:54 +010010116<
10117 *utf16idx()*
10118utf16idx({string}, {idx} [, {countcc} [, {charidx}]])
10119 Same as |charidx()| but returns the UTF-16 index of the byte
10120 at {idx} in {string} (after converting it to UTF-16).
10121
10122 When {charidx} is present and TRUE, {idx} is used as the
10123 character index in the String {string} instead of as the byte
10124 index.
10125 An {idx} in the middle of a UTF-8 sequence is rounded upwards
10126 to the end of that sequence.
10127
10128 See |byteidx()| and |byteidxcomp()| for getting the byte index
10129 from the UTF-16 index and |charidx()| for getting the
10130 character index from the UTF-16 index.
10131 Refer to |string-offset-encoding| for more information.
10132 Examples: >
10133 echo utf16idx('a😊😊', 3) returns 2
10134 echo utf16idx('a😊😊', 7) returns 4
10135 echo utf16idx('a😊😊', 1, 0, 1) returns 2
10136 echo utf16idx('a😊😊', 2, 0, 1) returns 4
10137 echo utf16idx('aą́c', 6) returns 2
10138 echo utf16idx('aą́c', 6, 1) returns 4
10139 echo utf16idx('a😊😊', 9) returns -1
10140<
10141 Can also be used as a |method|: >
10142 GetName()->utf16idx(idx)
10143
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010144
10145values({dict}) *values()*
10146 Return a |List| with all the values of {dict}. The |List| is
10147 in arbitrary order. Also see |items()| and |keys()|.
Bram Moolenaard592deb2022-06-17 15:42:40 +010010148 Returns zero if {dict} is not a |Dict|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010149
10150 Can also be used as a |method|: >
10151 mydict->values()
10152
LemonBoy0f7a3e12022-05-26 12:10:37 +010010153virtcol({expr} [, {list}]) *virtcol()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010154 The result is a Number, which is the screen column of the file
10155 position given with {expr}. That is, the last screen position
10156 occupied by the character at that position, when the screen
10157 would be of unlimited width. When there is a <Tab> at the
10158 position, the returned Number will be the column at the end of
10159 the <Tab>. For example, for a <Tab> in column 1, with 'ts'
10160 set to 8, it returns 8. |conceal| is ignored.
10161 For the byte position use |col()|.
LemonBoy0f7a3e12022-05-26 12:10:37 +010010162
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010163 For the use of {expr} see |col()|.
LemonBoy0f7a3e12022-05-26 12:10:37 +010010164
10165 When 'virtualedit' is used {expr} can be [lnum, col, off],
10166 where "off" is the offset in screen columns from the start of
10167 the character. E.g., a position within a <Tab> or after the
10168 last character. When "off" is omitted zero is used. When
10169 Virtual editing is active in the current mode, a position
10170 beyond the end of the line can be returned. Also see
10171 |'virtualedit'|
10172
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010173 The accepted positions are:
10174 . the cursor position
10175 $ the end of the cursor line (the result is the
10176 number of displayed characters in the cursor line
10177 plus one)
10178 'x position of mark x (if the mark is not set, 0 is
10179 returned)
10180 v In Visual mode: the start of the Visual area (the
10181 cursor is the end). When not in Visual mode
10182 returns the cursor position. Differs from |'<| in
10183 that it's updated right away.
LemonBoy0f7a3e12022-05-26 12:10:37 +010010184
10185 If {list} is present and non-zero then virtcol() returns a List
10186 with the first and last screen position occupied by the
10187 character.
10188
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010189 Note that only marks in the current file can be used.
10190 Examples: >
LemonBoy0f7a3e12022-05-26 12:10:37 +010010191 " With text "foo^Lbar" and cursor on the "^L":
10192
10193 virtcol(".") " returns 5
10194 virtcol(".", 1) " returns [4, 5]
10195 virtcol("$") " returns 9
10196
10197 " With text " there", with 't at 'h':
10198
10199 virtcol("'t") " returns 6
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010200< The first column is 1. 0 is returned for an error.
10201 A more advanced example that echoes the maximum length of
10202 all lines: >
10203 echo max(map(range(1, line('$')), "virtcol([v:val, '$'])"))
10204
10205< Can also be used as a |method|: >
10206 GetPos()->virtcol()
10207
Bram Moolenaar5a6ec102022-05-27 21:58:00 +010010208virtcol2col({winid}, {lnum}, {col}) *virtcol2col()*
10209 The result is a Number, which is the byte index of the
10210 character in window {winid} at buffer line {lnum} and virtual
10211 column {col}.
10212
10213 If {col} is greater than the last virtual column in line
10214 {lnum}, then the byte index of the character at the last
10215 virtual column is returned.
10216
10217 The {winid} argument can be the window number or the
10218 |window-ID|. If this is zero, then the current window is used.
10219
10220 Returns -1 if the window {winid} doesn't exist or the buffer
10221 line {lnum} or virtual column {col} is invalid.
10222
10223 See also |screenpos()|, |virtcol()| and |col()|.
10224
10225 Can also be used as a |method|: >
10226 GetWinid()->virtcol2col(lnum, col)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010227
10228visualmode([{expr}]) *visualmode()*
10229 The result is a String, which describes the last Visual mode
10230 used in the current buffer. Initially it returns an empty
10231 string, but once Visual mode has been used, it returns "v",
10232 "V", or "<CTRL-V>" (a single CTRL-V character) for
10233 character-wise, line-wise, or block-wise Visual mode
10234 respectively.
10235 Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +000010236 :exe "normal " .. visualmode()
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010237< This enters the same Visual mode as before. It is also useful
10238 in scripts if you wish to act differently depending on the
10239 Visual mode that was used.
10240 If Visual mode is active, use |mode()| to get the Visual mode
10241 (e.g., in a |:vmap|).
10242 If {expr} is supplied and it evaluates to a non-zero Number or
10243 a non-empty String, then the Visual mode will be cleared and
10244 the old value is returned. See |non-zero-arg|.
10245
10246wildmenumode() *wildmenumode()*
10247 Returns |TRUE| when the wildmenu is active and |FALSE|
10248 otherwise. See 'wildmenu' and 'wildmode'.
10249 This can be used in mappings to handle the 'wildcharm' option
10250 gracefully. (Makes only sense with |mapmode-c| mappings).
10251
10252 For example to make <c-j> work like <down> in wildmode, use: >
10253 :cnoremap <expr> <C-j> wildmenumode() ? "\<Down>\<Tab>" : "\<c-j>"
10254<
10255 (Note, this needs the 'wildcharm' option set appropriately).
10256
10257win_execute({id}, {command} [, {silent}]) *win_execute()*
10258 Like `execute()` but in the context of window {id}.
10259 The window will temporarily be made the current window,
10260 without triggering autocommands or changing directory. When
10261 executing {command} autocommands will be triggered, this may
10262 have unexpected side effects. Use |:noautocmd| if needed.
10263 Example: >
10264 call win_execute(winid, 'set syntax=python')
10265< Doing the same with `setwinvar()` would not trigger
10266 autocommands and not actually show syntax highlighting.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010267 *E994*
10268 Not all commands are allowed in popup windows.
10269 When window {id} does not exist then no error is given and
10270 an empty string is returned.
10271
10272 Can also be used as a |method|, the base is passed as the
10273 second argument: >
10274 GetCommand()->win_execute(winid)
10275
10276win_findbuf({bufnr}) *win_findbuf()*
10277 Returns a |List| with |window-ID|s for windows that contain
10278 buffer {bufnr}. When there is none the list is empty.
10279
10280 Can also be used as a |method|: >
10281 GetBufnr()->win_findbuf()
10282
10283win_getid([{win} [, {tab}]]) *win_getid()*
10284 Get the |window-ID| for the specified window.
10285 When {win} is missing use the current window.
10286 With {win} this is the window number. The top window has
10287 number 1.
10288 Without {tab} use the current tab, otherwise the tab with
10289 number {tab}. The first tab has number one.
10290 Return zero if the window cannot be found.
10291
10292 Can also be used as a |method|: >
10293 GetWinnr()->win_getid()
10294
10295
10296win_gettype([{nr}]) *win_gettype()*
10297 Return the type of the window:
10298 "autocmd" autocommand window. Temporary window
10299 used to execute autocommands.
10300 "command" command-line window |cmdwin|
10301 (empty) normal window
10302 "loclist" |location-list-window|
10303 "popup" popup window |popup|
10304 "preview" preview window |preview-window|
10305 "quickfix" |quickfix-window|
10306 "unknown" window {nr} not found
10307
10308 When {nr} is omitted return the type of the current window.
10309 When {nr} is given return the type of this window by number or
10310 |window-ID|.
10311
10312 Also see the 'buftype' option. When running a terminal in a
10313 popup window then 'buftype' is "terminal" and win_gettype()
10314 returns "popup".
10315
10316 Can also be used as a |method|: >
10317 GetWinid()->win_gettype()
10318<
10319win_gotoid({expr}) *win_gotoid()*
10320 Go to window with ID {expr}. This may also change the current
10321 tabpage.
10322 Return TRUE if successful, FALSE if the window cannot be found.
10323
10324 Can also be used as a |method|: >
10325 GetWinid()->win_gotoid()
10326
10327win_id2tabwin({expr}) *win_id2tabwin()*
10328 Return a list with the tab number and window number of window
10329 with ID {expr}: [tabnr, winnr].
10330 Return [0, 0] if the window cannot be found.
10331
10332 Can also be used as a |method|: >
10333 GetWinid()->win_id2tabwin()
10334
10335win_id2win({expr}) *win_id2win()*
10336 Return the window number of window with ID {expr}.
10337 Return 0 if the window cannot be found in the current tabpage.
10338
10339 Can also be used as a |method|: >
10340 GetWinid()->win_id2win()
10341
Daniel Steinbergee630312022-01-10 13:36:34 +000010342win_move_separator({nr}, {offset}) *win_move_separator()*
10343 Move window {nr}'s vertical separator (i.e., the right border)
10344 by {offset} columns, as if being dragged by the mouse. {nr}
10345 can be a window number or |window-ID|. A positive {offset}
10346 moves right and a negative {offset} moves left. Moving a
10347 window's vertical separator will change the width of the
10348 window and the width of other windows adjacent to the vertical
10349 separator. The magnitude of movement may be smaller than
10350 specified (e.g., as a consequence of maintaining
10351 'winminwidth'). Returns TRUE if the window can be found and
10352 FALSE otherwise.
Bram Moolenaard592deb2022-06-17 15:42:40 +010010353 This will fail for the rightmost window and a full-width
10354 window, since it has no separator on the right.
Bram Moolenaar76db9e02022-11-09 21:21:04 +000010355 Only works for the current tab page. *E1308*
Daniel Steinbergee630312022-01-10 13:36:34 +000010356
10357 Can also be used as a |method|: >
10358 GetWinnr()->win_move_separator(offset)
10359
10360win_move_statusline({nr}, {offset}) *win_move_statusline()*
10361 Move window {nr}'s status line (i.e., the bottom border) by
10362 {offset} rows, as if being dragged by the mouse. {nr} can be a
10363 window number or |window-ID|. A positive {offset} moves down
10364 and a negative {offset} moves up. Moving a window's status
10365 line will change the height of the window and the height of
10366 other windows adjacent to the status line. The magnitude of
10367 movement may be smaller than specified (e.g., as a consequence
10368 of maintaining 'winminheight'). Returns TRUE if the window can
10369 be found and FALSE otherwise.
Bram Moolenaar76db9e02022-11-09 21:21:04 +000010370 Only works for the current tab page.
Daniel Steinbergee630312022-01-10 13:36:34 +000010371
10372 Can also be used as a |method|: >
10373 GetWinnr()->win_move_statusline(offset)
10374
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010375win_screenpos({nr}) *win_screenpos()*
10376 Return the screen position of window {nr} as a list with two
10377 numbers: [row, col]. The first window always has position
10378 [1, 1], unless there is a tabline, then it is [2, 1].
10379 {nr} can be the window number or the |window-ID|. Use zero
10380 for the current window.
10381 Returns [0, 0] if the window cannot be found in the current
10382 tabpage.
10383
10384 Can also be used as a |method|: >
10385 GetWinid()->win_screenpos()
10386<
10387win_splitmove({nr}, {target} [, {options}]) *win_splitmove()*
10388 Move the window {nr} to a new split of the window {target}.
10389 This is similar to moving to {target}, creating a new window
10390 using |:split| but having the same contents as window {nr}, and
10391 then closing {nr}.
10392
10393 Both {nr} and {target} can be window numbers or |window-ID|s.
10394 Both must be in the current tab page.
10395
10396 Returns zero for success, non-zero for failure.
10397
10398 {options} is a |Dictionary| with the following optional entries:
10399 "vertical" When TRUE, the split is created vertically,
10400 like with |:vsplit|.
10401 "rightbelow" When TRUE, the split is made below or to the
10402 right (if vertical). When FALSE, it is done
10403 above or to the left (if vertical). When not
10404 present, the values of 'splitbelow' and
10405 'splitright' are used.
10406
10407 Can also be used as a |method|: >
10408 GetWinid()->win_splitmove(target)
10409<
10410
10411 *winbufnr()*
10412winbufnr({nr}) The result is a Number, which is the number of the buffer
10413 associated with window {nr}. {nr} can be the window number or
10414 the |window-ID|.
10415 When {nr} is zero, the number of the buffer in the current
10416 window is returned.
10417 When window {nr} doesn't exist, -1 is returned.
10418 Example: >
10419 :echo "The file in the current window is " . bufname(winbufnr(0))
10420<
10421 Can also be used as a |method|: >
10422 FindWindow()->winbufnr()->bufname()
10423<
10424 *wincol()*
10425wincol() The result is a Number, which is the virtual column of the
10426 cursor in the window. This is counting screen cells from the
10427 left side of the window. The leftmost column is one.
10428
10429 *windowsversion()*
10430windowsversion()
10431 The result is a String. For MS-Windows it indicates the OS
10432 version. E.g, Windows 10 is "10.0", Windows 8 is "6.2",
10433 Windows XP is "5.1". For non-MS-Windows systems the result is
10434 an empty string.
10435
10436winheight({nr}) *winheight()*
10437 The result is a Number, which is the height of window {nr}.
10438 {nr} can be the window number or the |window-ID|.
10439 When {nr} is zero, the height of the current window is
10440 returned. When window {nr} doesn't exist, -1 is returned.
10441 An existing window always has a height of zero or more.
10442 This excludes any window toolbar line.
10443 Examples: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +000010444 :echo "The current window has " .. winheight(0) .. " lines."
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010445
10446< Can also be used as a |method|: >
10447 GetWinid()->winheight()
10448<
10449winlayout([{tabnr}]) *winlayout()*
10450 The result is a nested List containing the layout of windows
10451 in a tabpage.
10452
10453 Without {tabnr} use the current tabpage, otherwise the tabpage
10454 with number {tabnr}. If the tabpage {tabnr} is not found,
10455 returns an empty list.
10456
10457 For a leaf window, it returns:
10458 ['leaf', {winid}]
10459 For horizontally split windows, which form a column, it
10460 returns:
10461 ['col', [{nested list of windows}]]
10462 For vertically split windows, which form a row, it returns:
10463 ['row', [{nested list of windows}]]
10464
10465 Example: >
10466 " Only one window in the tab page
10467 :echo winlayout()
10468 ['leaf', 1000]
10469 " Two horizontally split windows
10470 :echo winlayout()
10471 ['col', [['leaf', 1000], ['leaf', 1001]]]
10472 " The second tab page, with three horizontally split
10473 " windows, with two vertically split windows in the
10474 " middle window
10475 :echo winlayout(2)
10476 ['col', [['leaf', 1002], ['row', [['leaf', 1003],
10477 ['leaf', 1001]]], ['leaf', 1000]]]
10478<
10479 Can also be used as a |method|: >
10480 GetTabnr()->winlayout()
10481<
10482 *winline()*
10483winline() The result is a Number, which is the screen line of the cursor
10484 in the window. This is counting screen lines from the top of
10485 the window. The first line is one.
10486 If the cursor was moved the view on the file will be updated
10487 first, this may cause a scroll.
10488
10489 *winnr()*
10490winnr([{arg}]) The result is a Number, which is the number of the current
10491 window. The top window has number 1.
10492 Returns zero for a popup window.
10493
10494 The optional argument {arg} supports the following values:
10495 $ the number of the last window (the window
10496 count).
10497 # the number of the last accessed window (where
10498 |CTRL-W_p| goes to). If there is no previous
10499 window or it is in another tab page 0 is
10500 returned.
10501 {N}j the number of the Nth window below the
10502 current window (where |CTRL-W_j| goes to).
10503 {N}k the number of the Nth window above the current
10504 window (where |CTRL-W_k| goes to).
10505 {N}h the number of the Nth window left of the
10506 current window (where |CTRL-W_h| goes to).
10507 {N}l the number of the Nth window right of the
10508 current window (where |CTRL-W_l| goes to).
10509 The number can be used with |CTRL-W_w| and ":wincmd w"
10510 |:wincmd|.
Bram Moolenaar016188f2022-06-06 20:52:59 +010010511 When {arg} is invalid an error is given and zero is returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010512 Also see |tabpagewinnr()| and |win_getid()|.
10513 Examples: >
10514 let window_count = winnr('$')
10515 let prev_window = winnr('#')
10516 let wnum = winnr('3k')
10517
10518< Can also be used as a |method|: >
10519 GetWinval()->winnr()
10520<
10521 *winrestcmd()*
10522winrestcmd() Returns a sequence of |:resize| commands that should restore
10523 the current window sizes. Only works properly when no windows
10524 are opened or closed and the current window and tab page is
10525 unchanged.
10526 Example: >
10527 :let cmd = winrestcmd()
10528 :call MessWithWindowSizes()
10529 :exe cmd
10530<
10531 *winrestview()*
10532winrestview({dict})
10533 Uses the |Dictionary| returned by |winsaveview()| to restore
10534 the view of the current window.
10535 Note: The {dict} does not have to contain all values, that are
10536 returned by |winsaveview()|. If values are missing, those
10537 settings won't be restored. So you can use: >
10538 :call winrestview({'curswant': 4})
10539<
10540 This will only set the curswant value (the column the cursor
10541 wants to move on vertical movements) of the cursor to column 5
10542 (yes, that is 5), while all other settings will remain the
10543 same. This is useful, if you set the cursor position manually.
10544
10545 If you have changed the values the result is unpredictable.
10546 If the window size changed the result won't be the same.
10547
10548 Can also be used as a |method|: >
10549 GetView()->winrestview()
10550<
10551 *winsaveview()*
10552winsaveview() Returns a |Dictionary| that contains information to restore
10553 the view of the current window. Use |winrestview()| to
10554 restore the view.
10555 This is useful if you have a mapping that jumps around in the
10556 buffer and you want to go back to the original view.
10557 This does not save fold information. Use the 'foldenable'
10558 option to temporarily switch off folding, so that folds are
10559 not opened when moving around. This may have side effects.
10560 The return value includes:
10561 lnum cursor line number
10562 col cursor column (Note: the first column
naohiro ono56200ee2022-01-01 14:59:44 +000010563 zero, as opposed to what |getcurpos()|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010564 returns)
10565 coladd cursor column offset for 'virtualedit'
naohiro ono56200ee2022-01-01 14:59:44 +000010566 curswant column for vertical movement (Note:
10567 the first column is zero, as opposed
10568 to what |getcurpos()| returns). After
10569 |$| command it will be a very large
10570 number equal to |v:maxcol|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010571 topline first line in the window
10572 topfill filler lines, only in diff mode
10573 leftcol first column displayed; only used when
10574 'wrap' is off
10575 skipcol columns skipped
10576 Note that no option values are saved.
10577
10578
10579winwidth({nr}) *winwidth()*
10580 The result is a Number, which is the width of window {nr}.
10581 {nr} can be the window number or the |window-ID|.
10582 When {nr} is zero, the width of the current window is
10583 returned. When window {nr} doesn't exist, -1 is returned.
10584 An existing window always has a width of zero or more.
10585 Examples: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +000010586 :echo "The current window has " .. winwidth(0) .. " columns."
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010587 :if winwidth(0) <= 50
10588 : 50 wincmd |
10589 :endif
10590< For getting the terminal or screen size, see the 'columns'
10591 option.
10592
10593 Can also be used as a |method|: >
10594 GetWinid()->winwidth()
10595
10596
10597wordcount() *wordcount()*
10598 The result is a dictionary of byte/chars/word statistics for
10599 the current buffer. This is the same info as provided by
10600 |g_CTRL-G|
10601 The return value includes:
10602 bytes Number of bytes in the buffer
10603 chars Number of chars in the buffer
10604 words Number of words in the buffer
10605 cursor_bytes Number of bytes before cursor position
10606 (not in Visual mode)
10607 cursor_chars Number of chars before cursor position
10608 (not in Visual mode)
10609 cursor_words Number of words before cursor position
10610 (not in Visual mode)
10611 visual_bytes Number of bytes visually selected
10612 (only in Visual mode)
10613 visual_chars Number of chars visually selected
10614 (only in Visual mode)
10615 visual_words Number of words visually selected
10616 (only in Visual mode)
10617
10618
10619 *writefile()*
10620writefile({object}, {fname} [, {flags}])
10621 When {object} is a |List| write it to file {fname}. Each list
10622 item is separated with a NL. Each list item must be a String
10623 or Number.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010624 All NL characters are replaced with a NUL character.
10625 Inserting CR characters needs to be done before passing {list}
10626 to writefile().
Bram Moolenaar806a2732022-09-04 15:40:36 +010010627
10628 When {object} is a |Blob| write the bytes to file {fname}
10629 unmodified, also when binary mode is not specified.
10630
10631 {flags} must be a String. These characters are recognized:
10632
10633 'b' Binary mode is used: There will not be a NL after the
10634 last list item. An empty item at the end does cause the
10635 last line in the file to end in a NL.
10636
10637 'a' Append mode is used, lines are appended to the file: >
10638 :call writefile(["foo"], "event.log", "a")
10639 :call writefile(["bar"], "event.log", "a")
10640<
10641 'D' Delete the file when the current function ends. This
10642 works like: >
Bram Moolenaar938ae282023-02-20 20:44:55 +000010643 :defer delete({fname})
Bram Moolenaar806a2732022-09-04 15:40:36 +010010644< Fails when not in a function. Also see |:defer|.
10645
10646 's' fsync() is called after writing the file. This flushes
10647 the file to disk, if possible. This takes more time but
10648 avoids losing the file if the system crashes.
10649
10650 'S' fsync() is not called, even when 'fsync' is set.
10651
10652 When {flags} does not contain "S" or "s" then fsync() is
10653 called if the 'fsync' option is set.
10654
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010655 An existing file is overwritten, if possible.
Bram Moolenaar806a2732022-09-04 15:40:36 +010010656
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010657 When the write fails -1 is returned, otherwise 0. There is an
10658 error message if the file can't be created or when writing
10659 fails.
Bram Moolenaar806a2732022-09-04 15:40:36 +010010660
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010661 Also see |readfile()|.
10662 To copy a file byte for byte: >
10663 :let fl = readfile("foo", "b")
10664 :call writefile(fl, "foocopy", "b")
10665
10666< Can also be used as a |method|: >
10667 GetText()->writefile("thefile")
10668
10669
10670xor({expr}, {expr}) *xor()*
10671 Bitwise XOR on the two arguments. The arguments are converted
10672 to a number. A List, Dict or Float argument causes an error.
Bram Moolenaar5a6ec102022-05-27 21:58:00 +010010673 Also see `and()` and `or()`.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010674 Example: >
10675 :let bits = xor(bits, 0x80)
10676<
10677 Can also be used as a |method|: >
10678 :let bits = bits->xor(0x80)
10679<
10680
10681==============================================================================
106823. Feature list *feature-list*
10683
10684There are three types of features:
106851. Features that are only supported when they have been enabled when Vim
10686 was compiled |+feature-list|. Example: >
10687 :if has("cindent")
10688< *gui_running*
106892. Features that are only supported when certain conditions have been met.
10690 Example: >
10691 :if has("gui_running")
10692< *has-patch*
106933. Beyond a certain version or at a certain version and including a specific
10694 patch. The "patch-7.4.248" feature means that the Vim version is 7.5 or
10695 later, or it is version 7.4 and patch 248 was included. Example: >
10696 :if has("patch-7.4.248")
10697< Note that it's possible for patch 248 to be omitted even though 249 is
10698 included. Only happens when cherry-picking patches.
10699 Note that this form only works for patch 7.4.237 and later, before that
10700 you need to check for the patch and the v:version. Example (checking
10701 version 6.2.148 or later): >
10702 :if v:version > 602 || (v:version == 602 && has("patch148"))
10703
10704Hint: To find out if Vim supports backslashes in a file name (MS-Windows),
10705use: `if exists('+shellslash')`
10706
10707
10708acl Compiled with |ACL| support.
Bram Moolenaar2ee347f2022-08-26 17:53:44 +010010709all_builtin_terms Compiled with all builtin terminals enabled. (always
10710 true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010711amiga Amiga version of Vim.
10712arabic Compiled with Arabic support |Arabic|.
10713arp Compiled with ARP support (Amiga).
10714autocmd Compiled with autocommand support. (always true)
10715autochdir Compiled with support for 'autochdir'
10716autoservername Automatically enable |clientserver|
10717balloon_eval Compiled with |balloon-eval| support.
10718balloon_multiline GUI supports multiline balloons.
10719beos BeOS version of Vim.
10720browse Compiled with |:browse| support, and browse() will
10721 work.
10722browsefilter Compiled with support for |browsefilter|.
10723bsd Compiled on an OS in the BSD family (excluding macOS).
Bram Moolenaar2ee347f2022-08-26 17:53:44 +010010724builtin_terms Compiled with some builtin terminals. (always true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010725byte_offset Compiled with support for 'o' in 'statusline'
10726channel Compiled with support for |channel| and |job|
Bram Moolenaare1dc76f2022-06-25 18:01:32 +010010727cindent Compiled with 'cindent' support. (always true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010728clientserver Compiled with remote invocation support |clientserver|.
10729clipboard Compiled with 'clipboard' support.
10730clipboard_working Compiled with 'clipboard' support and it can be used.
10731cmdline_compl Compiled with |cmdline-completion| support.
10732cmdline_hist Compiled with |cmdline-history| support.
10733cmdline_info Compiled with 'showcmd' and 'ruler' support.
10734comments Compiled with |'comments'| support.
10735compatible Compiled to be very Vi compatible.
10736conpty Platform where |ConPTY| can be used.
10737cryptv Compiled with encryption support |encryption|.
10738cscope Compiled with |cscope| support.
10739cursorbind Compiled with |'cursorbind'| (always true)
10740debug Compiled with "DEBUG" defined.
10741dialog_con Compiled with console dialog support.
10742dialog_gui Compiled with GUI dialog support.
10743diff Compiled with |vimdiff| and 'diff' support.
10744digraphs Compiled with support for digraphs.
10745directx Compiled with support for DirectX and 'renderoptions'.
10746dnd Compiled with support for the "~ register |quote_~|.
10747drop_file Compiled with |drop_file| support.
10748ebcdic Compiled on a machine with ebcdic character set.
10749emacs_tags Compiled with support for Emacs tags.
10750eval Compiled with expression evaluation support. Always
10751 true, of course!
10752ex_extra |+ex_extra| (always true)
10753extra_search Compiled with support for |'incsearch'| and
10754 |'hlsearch'|
10755farsi Support for Farsi was removed |farsi|.
Bram Moolenaarf80f40a2022-08-25 16:02:23 +010010756file_in_path Compiled with support for |gf| and |<cfile>| (always
10757 true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010758filterpipe When 'shelltemp' is off pipes are used for shell
10759 read/write/filter commands
10760find_in_path Compiled with support for include file searches
10761 |+find_in_path|.
10762float Compiled with support for |Float|.
10763fname_case Case in file names matters (for Amiga and MS-Windows
10764 this is not present).
10765folding Compiled with |folding| support.
10766footer Compiled with GUI footer support. |gui-footer|
10767fork Compiled to use fork()/exec() instead of system().
10768gettext Compiled with message translation |multi-lang|
10769gui Compiled with GUI enabled.
Bram Moolenaarcbaff5e2022-04-08 17:45:08 +010010770gui_athena Compiled with Athena GUI (always false).
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010771gui_gnome Compiled with Gnome support (gui_gtk is also defined).
10772gui_gtk Compiled with GTK+ GUI (any version).
10773gui_gtk2 Compiled with GTK+ 2 GUI (gui_gtk is also defined).
10774gui_gtk3 Compiled with GTK+ 3 GUI (gui_gtk is also defined).
10775gui_haiku Compiled with Haiku GUI.
10776gui_mac Compiled with Macintosh GUI.
10777gui_motif Compiled with Motif GUI.
10778gui_photon Compiled with Photon GUI.
10779gui_running Vim is running in the GUI, or it will start soon.
10780gui_win32 Compiled with MS-Windows Win32 GUI.
10781gui_win32s idem, and Win32s system being used (Windows 3.1)
10782haiku Haiku version of Vim.
10783hangul_input Compiled with Hangul input support. |hangul|
10784hpux HP-UX version of Vim.
10785iconv Can use iconv() for conversion.
10786insert_expand Compiled with support for CTRL-X expansion commands in
10787 Insert mode. (always true)
10788job Compiled with support for |channel| and |job|
10789ipv6 Compiled with support for IPv6 networking in |channel|.
Bram Moolenaare1dc76f2022-06-25 18:01:32 +010010790jumplist Compiled with |jumplist| support. (always true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010791keymap Compiled with 'keymap' support.
10792lambda Compiled with |lambda| support.
10793langmap Compiled with 'langmap' support.
10794libcall Compiled with |libcall()| support.
10795linebreak Compiled with 'linebreak', 'breakat', 'showbreak' and
10796 'breakindent' support.
10797linux Linux version of Vim.
10798lispindent Compiled with support for lisp indenting.
Bram Moolenaare1dc76f2022-06-25 18:01:32 +010010799 (always true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010800listcmds Compiled with commands for the buffer list |:files|
10801 and the argument list |arglist|.
10802localmap Compiled with local mappings and abbr. |:map-local|
10803lua Compiled with Lua interface |Lua|.
10804mac Any Macintosh version of Vim cf. osx
10805macunix Synonym for osxdarwin
10806menu Compiled with support for |:menu|.
10807mksession Compiled with support for |:mksession|.
10808modify_fname Compiled with file name modifiers. |filename-modifiers|
10809 (always true)
10810mouse Compiled with support for mouse.
10811mouse_dec Compiled with support for Dec terminal mouse.
10812mouse_gpm Compiled with support for gpm (Linux console mouse)
10813mouse_gpm_enabled GPM mouse is working
10814mouse_netterm Compiled with support for netterm mouse.
10815mouse_pterm Compiled with support for qnx pterm mouse.
10816mouse_sysmouse Compiled with support for sysmouse (*BSD console mouse)
10817mouse_sgr Compiled with support for sgr mouse.
10818mouse_urxvt Compiled with support for urxvt mouse.
10819mouse_xterm Compiled with support for xterm mouse.
10820mouseshape Compiled with support for 'mouseshape'.
10821multi_byte Compiled with support for 'encoding' (always true)
10822multi_byte_encoding 'encoding' is set to a multibyte encoding.
10823multi_byte_ime Compiled with support for IME input method.
10824multi_lang Compiled with support for multiple languages.
10825mzscheme Compiled with MzScheme interface |mzscheme|.
10826nanotime Compiled with sub-second time stamp checks.
10827netbeans_enabled Compiled with support for |netbeans| and connected.
10828netbeans_intg Compiled with support for |netbeans|.
Bram Moolenaare1dc76f2022-06-25 18:01:32 +010010829num64 Compiled with 64-bit |Number| support. (always true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010830ole Compiled with OLE automation support for Win32.
10831osx Compiled for macOS cf. mac
10832osxdarwin Compiled for macOS, with |mac-darwin-feature|
10833packages Compiled with |packages| support.
10834path_extra Compiled with up/downwards search in 'path' and 'tags'
10835perl Compiled with Perl interface.
10836persistent_undo Compiled with support for persistent undo history.
10837postscript Compiled with PostScript file printing.
10838printer Compiled with |:hardcopy| support.
10839profile Compiled with |:profile| support.
Bram Moolenaar71badf92023-04-22 22:40:14 +010010840prof_nsec Profile results are in nanoseconds.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010841python Python 2.x interface available. |has-python|
10842python_compiled Compiled with Python 2.x interface. |has-python|
10843python_dynamic Python 2.x interface is dynamically loaded. |has-python|
10844python3 Python 3.x interface available. |has-python|
10845python3_compiled Compiled with Python 3.x interface. |has-python|
10846python3_dynamic Python 3.x interface is dynamically loaded. |has-python|
10847pythonx Python 2.x and/or 3.x interface available. |python_x|
10848qnx QNX version of Vim.
10849quickfix Compiled with |quickfix| support.
10850reltime Compiled with |reltime()| support.
10851rightleft Compiled with 'rightleft' support.
10852ruby Compiled with Ruby interface |ruby|.
10853scrollbind Compiled with 'scrollbind' support. (always true)
10854showcmd Compiled with 'showcmd' support.
10855signs Compiled with |:sign| support.
Bram Moolenaare1dc76f2022-06-25 18:01:32 +010010856smartindent Compiled with 'smartindent' support. (always true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010857sodium Compiled with libsodium for better crypt support
10858sound Compiled with sound support, e.g. `sound_playevent()`
10859spell Compiled with spell checking support |spell|.
10860startuptime Compiled with |--startuptime| support.
10861statusline Compiled with support for 'statusline', 'rulerformat'
10862 and special formats of 'titlestring' and 'iconstring'.
10863sun SunOS version of Vim.
10864sun_workshop Support for Sun |workshop| has been removed.
10865syntax Compiled with syntax highlighting support |syntax|.
10866syntax_items There are active syntax highlighting items for the
10867 current buffer.
10868system Compiled to use system() instead of fork()/exec().
10869tag_binary Compiled with binary searching in tags files
Bram Moolenaare1dc76f2022-06-25 18:01:32 +010010870 |tag-binary-search|. (always true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010871tag_old_static Support for old static tags was removed, see
10872 |tag-old-static|.
10873tcl Compiled with Tcl interface.
10874termguicolors Compiled with true color in terminal support.
10875terminal Compiled with |terminal| support.
10876terminfo Compiled with terminfo instead of termcap.
10877termresponse Compiled with support for |t_RV| and |v:termresponse|.
10878textobjects Compiled with support for |text-objects|.
10879textprop Compiled with support for |text-properties|.
10880tgetent Compiled with tgetent support, able to use a termcap
10881 or terminfo file.
10882timers Compiled with |timer_start()| support.
10883title Compiled with window title support |'title'|.
Bram Moolenaare1dc76f2022-06-25 18:01:32 +010010884 (always true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010885toolbar Compiled with support for |gui-toolbar|.
10886ttyin input is a terminal (tty)
10887ttyout output is a terminal (tty)
10888unix Unix version of Vim. *+unix*
10889unnamedplus Compiled with support for "unnamedplus" in 'clipboard'
10890user_commands User-defined commands. (always true)
10891vartabs Compiled with variable tabstop support |'vartabstop'|.
10892vcon Win32: Virtual console support is working, can use
10893 'termguicolors'. Also see |+vtp|.
10894vertsplit Compiled with vertically split windows |:vsplit|.
10895 (always true)
10896vim_starting True while initial source'ing takes place. |startup|
10897 *vim_starting*
Bram Moolenaara6feb162022-01-02 12:06:33 +000010898vim9script Compiled with |Vim9| script support
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010899viminfo Compiled with viminfo support.
10900vimscript-1 Compiled Vim script version 1 support
10901vimscript-2 Compiled Vim script version 2 support
10902vimscript-3 Compiled Vim script version 3 support
Bram Moolenaar8a3b8052022-06-26 12:21:15 +010010903vimscript-4 Compiled Vim script version 4 support
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010904virtualedit Compiled with 'virtualedit' option. (always true)
10905visual Compiled with Visual mode. (always true)
10906visualextra Compiled with extra Visual mode commands. (always
10907 true) |blockwise-operators|.
10908vms VMS version of Vim.
10909vreplace Compiled with |gR| and |gr| commands. (always true)
10910vtp Compiled for vcon support |+vtp| (check vcon to find
10911 out if it works in the current console).
10912wildignore Compiled with 'wildignore' option.
10913wildmenu Compiled with 'wildmenu' option.
10914win16 old version for MS-Windows 3.1 (always false)
10915win32 Win32 version of Vim (MS-Windows 95 and later, 32 or
10916 64 bits)
10917win32unix Win32 version of Vim, using Unix files (Cygwin)
10918win64 Win64 version of Vim (MS-Windows 64 bit).
10919win95 Win32 version for MS-Windows 95/98/ME (always false)
10920winaltkeys Compiled with 'winaltkeys' option.
10921windows Compiled with support for more than one window.
10922 (always true)
10923writebackup Compiled with 'writebackup' default on.
10924xfontset Compiled with X fontset support |xfontset|.
10925xim Compiled with X input method support |xim|.
10926xpm Compiled with pixmap support.
10927xpm_w32 Compiled with pixmap support for Win32. (Only for
10928 backward compatibility. Use "xpm" instead.)
10929xsmp Compiled with X session management support.
10930xsmp_interact Compiled with interactive X session management support.
10931xterm_clipboard Compiled with support for xterm clipboard.
10932xterm_save Compiled with support for saving and restoring the
10933 xterm screen.
10934x11 Compiled with X11 support.
10935
10936
10937==============================================================================
109384. Matching a pattern in a String *string-match*
10939
10940This is common between several functions. A regexp pattern as explained at
10941|pattern| is normally used to find a match in the buffer lines. When a
10942pattern is used to find a match in a String, almost everything works in the
10943same way. The difference is that a String is handled like it is one line.
10944When it contains a "\n" character, this is not seen as a line break for the
10945pattern. It can be matched with a "\n" in the pattern, or with ".". Example:
10946>
10947 :let a = "aaaa\nxxxx"
10948 :echo matchstr(a, "..\n..")
10949 aa
10950 xx
10951 :echo matchstr(a, "a.x")
10952 a
10953 x
10954
10955Don't forget that "^" will only match at the first character of the String and
10956"$" at the last character of the string. They don't match after or before a
10957"\n".
10958
10959 vim:tw=78:ts=8:noet:ft=help:norl: