blob: e72a3883020f5b1c80e77a25ce68a2d4eb7891b1 [file] [log] [blame]
Bram Moolenaar1c6737b2020-09-07 22:18:52 +02001*eval.txt* For Vim version 8.2. Last change: 2020 Sep 06
Bram Moolenaar071d4272004-06-13 20:20:40 +00002
3
Bram Moolenaar446cb832008-06-24 21:56:24 +00004 VIM REFERENCE MANUAL by Bram Moolenaar
Bram Moolenaar071d4272004-06-13 20:20:40 +00005
6
7Expression evaluation *expression* *expr* *E15* *eval*
8
9Using expressions is introduced in chapter 41 of the user manual |usr_41.txt|.
10
11Note: Expression evaluation can be disabled at compile time. If this has been
Bram Moolenaar58b85342016-08-14 19:54:54 +020012done, the features in this document are not available. See |+eval| and
Bram Moolenaard8b02732005-01-14 21:48:43 +000013|no-eval-feature|.
Bram Moolenaar071d4272004-06-13 20:20:40 +000014
Bram Moolenaar8a7d6542020-01-26 15:56:19 +010015This file is about the backwards compatible Vim script. For Vim9 script,
16which executes much faster, supports type checking and much more, see
17|vim9.txt|.
18
Bram Moolenaar13065c42005-01-08 16:08:21 +0000191. Variables |variables|
20 1.1 Variable types
Bram Moolenaar9588a0f2005-01-08 21:45:39 +000021 1.2 Function references |Funcref|
Bram Moolenaar7c626922005-02-07 22:01:03 +000022 1.3 Lists |Lists|
Bram Moolenaard8b02732005-01-14 21:48:43 +000023 1.4 Dictionaries |Dictionaries|
Bram Moolenaard8968242019-01-15 22:51:57 +010024 1.5 Blobs |Blobs|
25 1.6 More about variables |more-variables|
Bram Moolenaar13065c42005-01-08 16:08:21 +0000262. Expression syntax |expression-syntax|
273. Internal variable |internal-variables|
284. Builtin Functions |functions|
295. Defining functions |user-functions|
306. Curly braces names |curly-braces-names|
317. Commands |expression-commands|
328. Exception handling |exception-handling|
339. Examples |eval-examples|
Bram Moolenaar558ca4a2019-04-04 18:15:38 +02003410. Vim script version |vimscript-version|
3511. No +eval feature |no-eval-feature|
3612. The sandbox |eval-sandbox|
3713. Textlock |textlock|
Bram Moolenaared997ad2019-07-21 16:42:00 +020038
39Testing support is documented in |testing.txt|.
40Profiling is documented at |profiling|.
Bram Moolenaar071d4272004-06-13 20:20:40 +000041
Bram Moolenaar071d4272004-06-13 20:20:40 +000042==============================================================================
431. Variables *variables*
44
Bram Moolenaar13065c42005-01-08 16:08:21 +0000451.1 Variable types ~
Bram Moolenaarbf821bc2019-01-23 21:15:02 +010046 *E712* *E896* *E897* *E899*
Bram Moolenaar06fe74a2019-08-31 16:20:32 +020047There are ten types of variables:
Bram Moolenaar071d4272004-06-13 20:20:40 +000048
Bram Moolenaar664f3cf2019-12-07 16:03:51 +010049 *Number* *Integer*
50Number A 32 or 64 bit signed number. |expr-number|
Bram Moolenaarf9706e92020-02-22 14:27:04 +010051 The number of bits is available in |v:numbersize|.
Bram Moolenaar7571d552016-08-18 22:54:46 +020052 Examples: -123 0x10 0177 0b1011
Bram Moolenaard8b02732005-01-14 21:48:43 +000053
Bram Moolenaar446cb832008-06-24 21:56:24 +000054Float A floating point number. |floating-point-format| *Float*
55 {only when compiled with the |+float| feature}
56 Examples: 123.456 1.15e-6 -1.1e3
57
Bram Moolenaar06481422016-04-30 15:13:38 +020058 *E928*
Bram Moolenaard8b02732005-01-14 21:48:43 +000059String A NUL terminated string of 8-bit unsigned characters (bytes).
Bram Moolenaar446cb832008-06-24 21:56:24 +000060 |expr-string| Examples: "ab\txx\"--" 'x-z''a,c'
Bram Moolenaard8b02732005-01-14 21:48:43 +000061
Bram Moolenaard8968242019-01-15 22:51:57 +010062List An ordered sequence of items, see |List| for details.
Bram Moolenaard8b02732005-01-14 21:48:43 +000063 Example: [1, 2, ['a', 'b']]
Bram Moolenaar071d4272004-06-13 20:20:40 +000064
Bram Moolenaar39a58ca2005-06-27 22:42:44 +000065Dictionary An associative, unordered array: Each entry has a key and a
66 value. |Dictionary|
Bram Moolenaard5abb4c2019-07-13 22:46:10 +020067 Examples:
68 {'blue': "#0000ff", 'red': "#ff0000"}
Bram Moolenaar4c6d9042019-07-16 22:04:02 +020069 #{blue: "#0000ff", red: "#ff0000"}
Bram Moolenaar39a58ca2005-06-27 22:42:44 +000070
Bram Moolenaar835dc632016-02-07 14:27:38 +010071Funcref A reference to a function |Funcref|.
72 Example: function("strlen")
Bram Moolenaar1d429612016-05-24 15:44:17 +020073 It can be bound to a dictionary and arguments, it then works
74 like a Partial.
75 Example: function("Callback", [arg], myDict)
Bram Moolenaar835dc632016-02-07 14:27:38 +010076
Bram Moolenaar02e83b42016-02-21 20:10:26 +010077Special |v:false|, |v:true|, |v:none| and |v:null|. *Special*
Bram Moolenaar835dc632016-02-07 14:27:38 +010078
Bram Moolenaarebf7dfa2016-04-14 12:46:51 +020079Job Used for a job, see |job_start()|. *Job* *Jobs*
Bram Moolenaar38a55632016-02-15 22:07:32 +010080
Bram Moolenaarebf7dfa2016-04-14 12:46:51 +020081Channel Used for a channel, see |ch_open()|. *Channel* *Channels*
Bram Moolenaar835dc632016-02-07 14:27:38 +010082
Bram Moolenaard8968242019-01-15 22:51:57 +010083Blob Binary Large Object. Stores any sequence of bytes. See |Blob|
84 for details
Bram Moolenaar6e5ea8d2019-01-12 22:47:31 +010085 Example: 0zFF00ED015DAF
86 0z is an empty Blob.
87
Bram Moolenaard7ee7ce2005-01-03 21:02:03 +000088The Number and String types are converted automatically, depending on how they
89are used.
Bram Moolenaar071d4272004-06-13 20:20:40 +000090
91Conversion from a Number to a String is by making the ASCII representation of
Bram Moolenaar24ea3ba2010-09-19 19:01:21 +020092the Number. Examples:
93 Number 123 --> String "123" ~
94 Number 0 --> String "0" ~
95 Number -1 --> String "-1" ~
Bram Moolenaar00a927d2010-05-14 23:24:24 +020096 *octal*
Bram Moolenaard43906d2020-07-20 21:31:32 +020097Conversion from a String to a Number only happens in legacy Vim script, not in
98Vim9 script. It is done by converting the first digits to a number.
99Hexadecimal "0xf9", Octal "017" or "0o17", and Binary "0b10"
Bram Moolenaarc17e66c2020-06-02 21:38:22 +0200100numbers are recognized (NOTE: when using |scriptversion-4| octal with a
101leading "0" is not recognized). If the String doesn't start with digits, the
102result is zero.
Bram Moolenaarfa735342016-01-03 22:14:44 +0100103Examples:
Bram Moolenaar24ea3ba2010-09-19 19:01:21 +0200104 String "456" --> Number 456 ~
105 String "6bar" --> Number 6 ~
106 String "foo" --> Number 0 ~
107 String "0xf1" --> Number 241 ~
108 String "0100" --> Number 64 ~
Bram Moolenaarc17e66c2020-06-02 21:38:22 +0200109 String "0o100" --> Number 64 ~
Bram Moolenaarfa735342016-01-03 22:14:44 +0100110 String "0b101" --> Number 5 ~
Bram Moolenaar24ea3ba2010-09-19 19:01:21 +0200111 String "-8" --> Number -8 ~
112 String "+8" --> Number 0 ~
Bram Moolenaar071d4272004-06-13 20:20:40 +0000113
114To force conversion from String to Number, add zero to it: >
115 :echo "0100" + 0
Bram Moolenaar97b2ad32006-03-18 21:40:56 +0000116< 64 ~
117
118To avoid a leading zero to cause octal conversion, or for using a different
119base, use |str2nr()|.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000120
Bram Moolenaard09091d2019-01-17 16:07:22 +0100121 *TRUE* *FALSE* *Boolean*
Bram Moolenaar071d4272004-06-13 20:20:40 +0000122For boolean operators Numbers are used. Zero is FALSE, non-zero is TRUE.
Bram Moolenaar1c6737b2020-09-07 22:18:52 +0200123You can also use |v:false| and |v:true|. In Vim9 script |false| and |true|.
124When TRUE is returned from a function it is the Number one, FALSE is the
125number zero.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000126
Bram Moolenaare381d3d2016-07-07 14:50:41 +0200127Note that in the command: >
Bram Moolenaar071d4272004-06-13 20:20:40 +0000128 :if "foo"
Bram Moolenaare381d3d2016-07-07 14:50:41 +0200129 :" NOT executed
130"foo" is converted to 0, which means FALSE. If the string starts with a
131non-zero number it means TRUE: >
132 :if "8foo"
133 :" executed
134To test for a non-empty string, use empty(): >
Bram Moolenaar3a0d8092012-10-21 03:02:54 +0200135 :if !empty("foo")
Bram Moolenaar835dc632016-02-07 14:27:38 +0100136<
Bram Moolenaare381d3d2016-07-07 14:50:41 +0200137 *non-zero-arg*
138Function arguments often behave slightly different from |TRUE|: If the
139argument is present and it evaluates to a non-zero Number, |v:true| or a
Bram Moolenaar64d8e252016-09-06 22:12:34 +0200140non-empty String, then the value is considered to be TRUE.
Bram Moolenaar01164a62017-11-02 22:58:42 +0100141Note that " " and "0" are also non-empty strings, thus considered to be TRUE.
142A List, Dictionary or Float is not a Number or String, thus evaluate to FALSE.
Bram Moolenaare381d3d2016-07-07 14:50:41 +0200143
Bram Moolenaar38a55632016-02-15 22:07:32 +0100144 *E745* *E728* *E703* *E729* *E730* *E731* *E908* *E910* *E913*
Bram Moolenaar6e5ea8d2019-01-12 22:47:31 +0100145 *E974* *E975* *E976*
Bram Moolenaard09091d2019-01-17 16:07:22 +0100146|List|, |Dictionary|, |Funcref|, |Job|, |Channel| and |Blob| types are not
147automatically converted.
Bram Moolenaard7ee7ce2005-01-03 21:02:03 +0000148
Bram Moolenaar446cb832008-06-24 21:56:24 +0000149 *E805* *E806* *E808*
Bram Moolenaar58b85342016-08-14 19:54:54 +0200150When mixing Number and Float the Number is converted to Float. Otherwise
Bram Moolenaar446cb832008-06-24 21:56:24 +0000151there is no automatic conversion of Float. You can use str2float() for String
152to Float, printf() for Float to String and float2nr() for Float to Number.
153
Bram Moolenaar38a55632016-02-15 22:07:32 +0100154 *E891* *E892* *E893* *E894* *E907* *E911* *E914*
Bram Moolenaar13d5aee2016-01-21 23:36:05 +0100155When expecting a Float a Number can also be used, but nothing else.
156
Bram Moolenaarf6f32c32016-03-12 19:03:59 +0100157 *no-type-checking*
158You will not get an error if you try to change the type of a variable.
Bram Moolenaard7ee7ce2005-01-03 21:02:03 +0000159
Bram Moolenaar13065c42005-01-08 16:08:21 +0000160
Bram Moolenaar9588a0f2005-01-08 21:45:39 +00001611.2 Function references ~
Bram Moolenaare46a4402020-06-30 20:38:27 +0200162 *Funcref* *E695* *E718*
Bram Moolenaar58b85342016-08-14 19:54:54 +0200163A Funcref variable is obtained with the |function()| function, the |funcref()|
164function or created with the lambda expression |expr-lambda|. It can be used
165in an expression in the place of a function name, before the parenthesis
166around the arguments, to invoke the function it refers to. Example: >
Bram Moolenaard7ee7ce2005-01-03 21:02:03 +0000167
168 :let Fn = function("MyFunc")
169 :echo Fn()
Bram Moolenaar3a3a7232005-01-17 22:16:15 +0000170< *E704* *E705* *E707*
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000171A Funcref variable must start with a capital, "s:", "w:", "t:" or "b:". You
Bram Moolenaar7cba6c02013-09-05 22:13:31 +0200172can use "g:" but the following name must still start with a capital. You
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000173cannot have both a Funcref variable and a function with the same name.
Bram Moolenaard7ee7ce2005-01-03 21:02:03 +0000174
Bram Moolenaar3a3a7232005-01-17 22:16:15 +0000175A special case is defining a function and directly assigning its Funcref to a
176Dictionary entry. Example: >
177 :function dict.init() dict
178 : let self.val = 0
179 :endfunction
180
181The key of the Dictionary can start with a lower case letter. The actual
182function name is not used here. Also see |numbered-function|.
183
184A Funcref can also be used with the |:call| command: >
185 :call Fn()
186 :call dict.init()
Bram Moolenaar13065c42005-01-08 16:08:21 +0000187
188The name of the referenced function can be obtained with |string()|. >
Bram Moolenaar383f9bc2005-01-19 22:18:32 +0000189 :let func = string(Fn)
Bram Moolenaar13065c42005-01-08 16:08:21 +0000190
191You can use |call()| to invoke a Funcref and use a list variable for the
192arguments: >
Bram Moolenaar383f9bc2005-01-19 22:18:32 +0000193 :let r = call(Fn, mylist)
Bram Moolenaar1d429612016-05-24 15:44:17 +0200194<
195 *Partial*
196A Funcref optionally binds a Dictionary and/or arguments. This is also called
197a Partial. This is created by passing the Dictionary and/or arguments to
Bram Moolenaar58b85342016-08-14 19:54:54 +0200198function() or funcref(). When calling the function the Dictionary and/or
199arguments will be passed to the function. Example: >
Bram Moolenaar1d429612016-05-24 15:44:17 +0200200
201 let Cb = function('Callback', ['foo'], myDict)
Bram Moolenaarba3ff532018-11-04 14:45:49 +0100202 call Cb('bar')
Bram Moolenaar1d429612016-05-24 15:44:17 +0200203
204This will invoke the function as if using: >
Bram Moolenaarba3ff532018-11-04 14:45:49 +0100205 call myDict.Callback('foo', 'bar')
Bram Moolenaar1d429612016-05-24 15:44:17 +0200206
207This is very useful when passing a function around, e.g. in the arguments of
208|ch_open()|.
209
210Note that binding a function to a Dictionary also happens when the function is
211a member of the Dictionary: >
212
213 let myDict.myFunction = MyFunction
214 call myDict.myFunction()
215
216Here MyFunction() will get myDict passed as "self". This happens when the
217"myFunction" member is accessed. When making assigning "myFunction" to
218otherDict and calling it, it will be bound to otherDict: >
219
220 let otherDict.myFunction = myDict.myFunction
221 call otherDict.myFunction()
222
223Now "self" will be "otherDict". But when the dictionary was bound explicitly
224this won't happen: >
225
226 let myDict.myFunction = function(MyFunction, myDict)
227 let otherDict.myFunction = myDict.myFunction
228 call otherDict.myFunction()
229
Bram Moolenaard823fa92016-08-12 16:29:27 +0200230Here "self" will be "myDict", because it was bound explicitly.
Bram Moolenaard7ee7ce2005-01-03 21:02:03 +0000231
232
Bram Moolenaar9588a0f2005-01-08 21:45:39 +00002331.3 Lists ~
Bram Moolenaar7e38ea22014-04-05 22:55:53 +0200234 *list* *List* *Lists* *E686*
Bram Moolenaard7ee7ce2005-01-03 21:02:03 +0000235A List is an ordered sequence of items. An item can be of any type. Items
Bram Moolenaar58b85342016-08-14 19:54:54 +0200236can be accessed by their index number. Items can be added and removed at any
Bram Moolenaard7ee7ce2005-01-03 21:02:03 +0000237position in the sequence.
238
Bram Moolenaar13065c42005-01-08 16:08:21 +0000239
240List creation ~
241 *E696* *E697*
Bram Moolenaard7ee7ce2005-01-03 21:02:03 +0000242A List is created with a comma separated list of items in square brackets.
Bram Moolenaar13065c42005-01-08 16:08:21 +0000243Examples: >
244 :let mylist = [1, two, 3, "four"]
245 :let emptylist = []
Bram Moolenaard7ee7ce2005-01-03 21:02:03 +0000246
Bram Moolenaar58b85342016-08-14 19:54:54 +0200247An item can be any expression. Using a List for an item creates a
Bram Moolenaarf9393ef2006-04-24 19:47:27 +0000248List of Lists: >
Bram Moolenaar13065c42005-01-08 16:08:21 +0000249 :let nestlist = [[11, 12], [21, 22], [31, 32]]
Bram Moolenaard7ee7ce2005-01-03 21:02:03 +0000250
251An extra comma after the last item is ignored.
252
Bram Moolenaar13065c42005-01-08 16:08:21 +0000253
254List index ~
255 *list-index* *E684*
Bram Moolenaard7ee7ce2005-01-03 21:02:03 +0000256An item in the List can be accessed by putting the index in square brackets
Bram Moolenaar13065c42005-01-08 16:08:21 +0000257after the List. Indexes are zero-based, thus the first item has index zero. >
258 :let item = mylist[0] " get the first item: 1
Bram Moolenaard7ee7ce2005-01-03 21:02:03 +0000259 :let item = mylist[2] " get the third item: 3
Bram Moolenaar13065c42005-01-08 16:08:21 +0000260
Bram Moolenaar9588a0f2005-01-08 21:45:39 +0000261When the resulting item is a list this can be repeated: >
Bram Moolenaar13065c42005-01-08 16:08:21 +0000262 :let item = nestlist[0][1] " get the first list, second item: 12
Bram Moolenaard7ee7ce2005-01-03 21:02:03 +0000263<
Bram Moolenaar13065c42005-01-08 16:08:21 +0000264A negative index is counted from the end. Index -1 refers to the last item in
265the List, -2 to the last but one item, etc. >
Bram Moolenaard7ee7ce2005-01-03 21:02:03 +0000266 :let last = mylist[-1] " get the last item: "four"
267
Bram Moolenaar13065c42005-01-08 16:08:21 +0000268To avoid an error for an invalid index use the |get()| function. When an item
Bram Moolenaar9588a0f2005-01-08 21:45:39 +0000269is not available it returns zero or the default value you specify: >
Bram Moolenaar13065c42005-01-08 16:08:21 +0000270 :echo get(mylist, idx)
271 :echo get(mylist, idx, "NONE")
272
273
274List concatenation ~
275
276Two lists can be concatenated with the "+" operator: >
277 :let longlist = mylist + [5, 6]
Bram Moolenaar383f9bc2005-01-19 22:18:32 +0000278 :let mylist += [7, 8]
Bram Moolenaar13065c42005-01-08 16:08:21 +0000279
280To prepend or append an item turn the item into a list by putting [] around
281it. To change a list in-place see |list-modification| below.
282
283
284Sublist ~
Bram Moolenaarbc8801c2016-08-02 21:04:33 +0200285 *sublist*
Bram Moolenaard7ee7ce2005-01-03 21:02:03 +0000286A part of the List can be obtained by specifying the first and last index,
287separated by a colon in square brackets: >
Bram Moolenaar13065c42005-01-08 16:08:21 +0000288 :let shortlist = mylist[2:-1] " get List [3, "four"]
Bram Moolenaard7ee7ce2005-01-03 21:02:03 +0000289
290Omitting the first index is similar to zero. Omitting the last index is
Bram Moolenaaref2f6562007-05-06 13:32:59 +0000291similar to -1. >
Bram Moolenaar540d6e32005-01-09 21:20:18 +0000292 :let endlist = mylist[2:] " from item 2 to the end: [3, "four"]
293 :let shortlist = mylist[2:2] " List with one item: [3]
294 :let otherlist = mylist[:] " make a copy of the List
Bram Moolenaard7ee7ce2005-01-03 21:02:03 +0000295
Bram Moolenaarf9393ef2006-04-24 19:47:27 +0000296If the first index is beyond the last item of the List or the second item is
297before the first item, the result is an empty list. There is no error
298message.
299
300If the second index is equal to or greater than the length of the list the
301length minus one is used: >
Bram Moolenaar9e54a0e2006-04-14 20:42:25 +0000302 :let mylist = [0, 1, 2, 3]
303 :echo mylist[2:8] " result: [2, 3]
304
Bram Moolenaara7fc0102005-05-18 22:17:12 +0000305NOTE: mylist[s:e] means using the variable "s:e" as index. Watch out for
Bram Moolenaar58b85342016-08-14 19:54:54 +0200306using a single letter variable before the ":". Insert a space when needed:
Bram Moolenaara7fc0102005-05-18 22:17:12 +0000307mylist[s : e].
308
Bram Moolenaard7ee7ce2005-01-03 21:02:03 +0000309
Bram Moolenaar13065c42005-01-08 16:08:21 +0000310List identity ~
Bram Moolenaard8b02732005-01-14 21:48:43 +0000311 *list-identity*
Bram Moolenaar13065c42005-01-08 16:08:21 +0000312When variable "aa" is a list and you assign it to another variable "bb", both
313variables refer to the same list. Thus changing the list "aa" will also
314change "bb": >
315 :let aa = [1, 2, 3]
316 :let bb = aa
317 :call add(aa, 4)
318 :echo bb
Bram Moolenaar3a3a7232005-01-17 22:16:15 +0000319< [1, 2, 3, 4]
Bram Moolenaar13065c42005-01-08 16:08:21 +0000320
321Making a copy of a list is done with the |copy()| function. Using [:] also
322works, as explained above. This creates a shallow copy of the list: Changing
Bram Moolenaar9588a0f2005-01-08 21:45:39 +0000323a list item in the list will also change the item in the copied list: >
Bram Moolenaar13065c42005-01-08 16:08:21 +0000324 :let aa = [[1, 'a'], 2, 3]
325 :let bb = copy(aa)
Bram Moolenaar3a3a7232005-01-17 22:16:15 +0000326 :call add(aa, 4)
Bram Moolenaar13065c42005-01-08 16:08:21 +0000327 :let aa[0][1] = 'aaa'
328 :echo aa
Bram Moolenaar3a3a7232005-01-17 22:16:15 +0000329< [[1, aaa], 2, 3, 4] >
Bram Moolenaar13065c42005-01-08 16:08:21 +0000330 :echo bb
Bram Moolenaar3a3a7232005-01-17 22:16:15 +0000331< [[1, aaa], 2, 3]
Bram Moolenaar13065c42005-01-08 16:08:21 +0000332
Bram Moolenaar9588a0f2005-01-08 21:45:39 +0000333To make a completely independent list use |deepcopy()|. This also makes a
Bram Moolenaar3a3a7232005-01-17 22:16:15 +0000334copy of the values in the list, recursively. Up to a hundred levels deep.
Bram Moolenaar13065c42005-01-08 16:08:21 +0000335
336The operator "is" can be used to check if two variables refer to the same
Bram Moolenaar3a3a7232005-01-17 22:16:15 +0000337List. "isnot" does the opposite. In contrast "==" compares if two lists have
Bram Moolenaar9588a0f2005-01-08 21:45:39 +0000338the same value. >
339 :let alist = [1, 2, 3]
340 :let blist = [1, 2, 3]
341 :echo alist is blist
Bram Moolenaar3a3a7232005-01-17 22:16:15 +0000342< 0 >
Bram Moolenaar9588a0f2005-01-08 21:45:39 +0000343 :echo alist == blist
Bram Moolenaar3a3a7232005-01-17 22:16:15 +0000344< 1
Bram Moolenaar13065c42005-01-08 16:08:21 +0000345
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +0000346Note about comparing lists: Two lists are considered equal if they have the
347same length and all items compare equal, as with using "==". There is one
Bram Moolenaar7d1f5db2005-07-03 21:39:27 +0000348exception: When comparing a number with a string they are considered
349different. There is no automatic type conversion, as with using "==" on
350variables. Example: >
351 echo 4 == "4"
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +0000352< 1 >
Bram Moolenaar7d1f5db2005-07-03 21:39:27 +0000353 echo [4] == ["4"]
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +0000354< 0
355
Bram Moolenaar7d1f5db2005-07-03 21:39:27 +0000356Thus comparing Lists is more strict than comparing numbers and strings. You
Bram Moolenaar446cb832008-06-24 21:56:24 +0000357can compare simple values this way too by putting them in a list: >
Bram Moolenaar7d1f5db2005-07-03 21:39:27 +0000358
359 :let a = 5
360 :let b = "5"
Bram Moolenaar446cb832008-06-24 21:56:24 +0000361 :echo a == b
Bram Moolenaar7d1f5db2005-07-03 21:39:27 +0000362< 1 >
Bram Moolenaar446cb832008-06-24 21:56:24 +0000363 :echo [a] == [b]
Bram Moolenaar7d1f5db2005-07-03 21:39:27 +0000364< 0
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +0000365
Bram Moolenaar13065c42005-01-08 16:08:21 +0000366
367List unpack ~
368
369To unpack the items in a list to individual variables, put the variables in
370square brackets, like list items: >
371 :let [var1, var2] = mylist
372
373When the number of variables does not match the number of items in the list
374this produces an error. To handle any extra items from the list append ";"
375and a variable name: >
376 :let [var1, var2; rest] = mylist
377
378This works like: >
379 :let var1 = mylist[0]
380 :let var2 = mylist[1]
Bram Moolenaar5f2bb9f2005-01-11 21:29:04 +0000381 :let rest = mylist[2:]
Bram Moolenaar13065c42005-01-08 16:08:21 +0000382
383Except that there is no error if there are only two items. "rest" will be an
384empty list then.
385
386
387List modification ~
388 *list-modification*
Bram Moolenaar9588a0f2005-01-08 21:45:39 +0000389To change a specific item of a list use |:let| this way: >
Bram Moolenaar13065c42005-01-08 16:08:21 +0000390 :let list[4] = "four"
391 :let listlist[0][3] = item
392
Bram Moolenaar9588a0f2005-01-08 21:45:39 +0000393To change part of a list you can specify the first and last item to be
Bram Moolenaar3a3a7232005-01-17 22:16:15 +0000394modified. The value must at least have the number of items in the range: >
Bram Moolenaar9588a0f2005-01-08 21:45:39 +0000395 :let list[3:5] = [3, 4, 5]
396
Bram Moolenaar13065c42005-01-08 16:08:21 +0000397Adding and removing items from a list is done with functions. Here are a few
398examples: >
399 :call insert(list, 'a') " prepend item 'a'
400 :call insert(list, 'a', 3) " insert item 'a' before list[3]
401 :call add(list, "new") " append String item
Bram Moolenaar3a3a7232005-01-17 22:16:15 +0000402 :call add(list, [1, 2]) " append a List as one new item
Bram Moolenaar13065c42005-01-08 16:08:21 +0000403 :call extend(list, [1, 2]) " extend the list with two more items
404 :let i = remove(list, 3) " remove item 3
Bram Moolenaar9cd15162005-01-16 22:02:49 +0000405 :unlet list[3] " idem
Bram Moolenaar13065c42005-01-08 16:08:21 +0000406 :let l = remove(list, 3, -1) " remove items 3 to last item
Bram Moolenaar9cd15162005-01-16 22:02:49 +0000407 :unlet list[3 : ] " idem
Bram Moolenaar3a3a7232005-01-17 22:16:15 +0000408 :call filter(list, 'v:val !~ "x"') " remove items with an 'x'
Bram Moolenaar13065c42005-01-08 16:08:21 +0000409
Bram Moolenaar3a3a7232005-01-17 22:16:15 +0000410Changing the order of items in a list: >
Bram Moolenaar9588a0f2005-01-08 21:45:39 +0000411 :call sort(list) " sort a list alphabetically
412 :call reverse(list) " reverse the order of items
Bram Moolenaar327aa022014-03-25 18:24:23 +0100413 :call uniq(sort(list)) " sort and remove duplicates
Bram Moolenaar9588a0f2005-01-08 21:45:39 +0000414
Bram Moolenaar13065c42005-01-08 16:08:21 +0000415
416For loop ~
417
Bram Moolenaar9588a0f2005-01-08 21:45:39 +0000418The |:for| loop executes commands for each item in a list. A variable is set
419to each item in the list in sequence. Example: >
Bram Moolenaar3a3a7232005-01-17 22:16:15 +0000420 :for item in mylist
421 : call Doit(item)
Bram Moolenaar13065c42005-01-08 16:08:21 +0000422 :endfor
423
424This works like: >
425 :let index = 0
426 :while index < len(mylist)
Bram Moolenaar3a3a7232005-01-17 22:16:15 +0000427 : let item = mylist[index]
428 : :call Doit(item)
Bram Moolenaar13065c42005-01-08 16:08:21 +0000429 : let index = index + 1
430 :endwhile
431
Bram Moolenaar5f2bb9f2005-01-11 21:29:04 +0000432If all you want to do is modify each item in the list then the |map()|
Bram Moolenaar3a3a7232005-01-17 22:16:15 +0000433function will be a simpler method than a for loop.
Bram Moolenaar5f2bb9f2005-01-11 21:29:04 +0000434
Bram Moolenaar58b85342016-08-14 19:54:54 +0200435Just like the |:let| command, |:for| also accepts a list of variables. This
Bram Moolenaar13065c42005-01-08 16:08:21 +0000436requires the argument to be a list of lists. >
437 :for [lnum, col] in [[1, 3], [2, 8], [3, 0]]
438 : call Doit(lnum, col)
439 :endfor
440
441This works like a |:let| command is done for each list item. Again, the types
442must remain the same to avoid an error.
443
Bram Moolenaar3a3a7232005-01-17 22:16:15 +0000444It is also possible to put remaining items in a List variable: >
Bram Moolenaar13065c42005-01-08 16:08:21 +0000445 :for [i, j; rest] in listlist
446 : call Doit(i, j)
447 : if !empty(rest)
448 : echo "remainder: " . string(rest)
449 : endif
450 :endfor
451
452
453List functions ~
Bram Moolenaar3a3a7232005-01-17 22:16:15 +0000454 *E714*
Bram Moolenaar13065c42005-01-08 16:08:21 +0000455Functions that are useful with a List: >
Bram Moolenaar9588a0f2005-01-08 21:45:39 +0000456 :let r = call(funcname, list) " call a function with an argument list
Bram Moolenaar13065c42005-01-08 16:08:21 +0000457 :if empty(list) " check if list is empty
Bram Moolenaar2fda12f2005-01-15 22:14:15 +0000458 :let l = len(list) " number of items in list
459 :let big = max(list) " maximum value in list
460 :let small = min(list) " minimum value in list
Bram Moolenaar9588a0f2005-01-08 21:45:39 +0000461 :let xs = count(list, 'x') " count nr of times 'x' appears in list
462 :let i = index(list, 'x') " index of first 'x' in list
Bram Moolenaar13065c42005-01-08 16:08:21 +0000463 :let lines = getline(1, 10) " get ten text lines from buffer
464 :call append('$', lines) " append text lines in buffer
Bram Moolenaar5f2bb9f2005-01-11 21:29:04 +0000465 :let list = split("a b c") " create list from items in a string
466 :let string = join(list, ', ') " create string from list items
Bram Moolenaar2fda12f2005-01-15 22:14:15 +0000467 :let s = string(list) " String representation of list
468 :call map(list, '">> " . v:val') " prepend ">> " to each item
Bram Moolenaar13065c42005-01-08 16:08:21 +0000469
Bram Moolenaar0cb032e2005-04-23 20:52:00 +0000470Don't forget that a combination of features can make things simple. For
471example, to add up all the numbers in a list: >
472 :exe 'let sum = ' . join(nrlist, '+')
473
Bram Moolenaar13065c42005-01-08 16:08:21 +0000474
Bram Moolenaard8b02732005-01-14 21:48:43 +00004751.4 Dictionaries ~
Bram Moolenaard8968242019-01-15 22:51:57 +0100476 *dict* *Dict* *Dictionaries* *Dictionary*
Bram Moolenaard8b02732005-01-14 21:48:43 +0000477A Dictionary is an associative array: Each entry has a key and a value. The
Bram Moolenaar3a3a7232005-01-17 22:16:15 +0000478entry can be located with the key. The entries are stored without a specific
479ordering.
Bram Moolenaard8b02732005-01-14 21:48:43 +0000480
481
482Dictionary creation ~
Bram Moolenaar3a3a7232005-01-17 22:16:15 +0000483 *E720* *E721* *E722* *E723*
Bram Moolenaard8b02732005-01-14 21:48:43 +0000484A Dictionary is created with a comma separated list of entries in curly
Bram Moolenaar3a3a7232005-01-17 22:16:15 +0000485braces. Each entry has a key and a value, separated by a colon. Each key can
486only appear once. Examples: >
Bram Moolenaard8b02732005-01-14 21:48:43 +0000487 :let mydict = {1: 'one', 2: 'two', 3: 'three'}
488 :let emptydict = {}
Bram Moolenaar3a3a7232005-01-17 22:16:15 +0000489< *E713* *E716* *E717*
Bram Moolenaard8b02732005-01-14 21:48:43 +0000490A key is always a String. You can use a Number, it will be converted to a
491String automatically. Thus the String '4' and the number 4 will find the same
Bram Moolenaar58b85342016-08-14 19:54:54 +0200492entry. Note that the String '04' and the Number 04 are different, since the
Bram Moolenaard5abb4c2019-07-13 22:46:10 +0200493Number will be converted to the String '4'. The empty string can also be used
494as a key.
Bram Moolenaar56c860c2019-08-17 20:09:31 +0200495 *literal-Dict* *#{}*
Bram Moolenaar4c6d9042019-07-16 22:04:02 +0200496To avoid having to put quotes around every key the #{} form can be used. This
Bram Moolenaard5abb4c2019-07-13 22:46:10 +0200497does require the key to consist only of ASCII letters, digits, '-' and '_'.
498Example: >
Bram Moolenaar10455d42019-11-21 15:36:18 +0100499 :let mydict = #{zero: 0, one_key: 1, two-key: 2, 333: 3}
Bram Moolenaar4c6d9042019-07-16 22:04:02 +0200500Note that 333 here is the string "333". Empty keys are not possible with #{}.
Bram Moolenaard8b02732005-01-14 21:48:43 +0000501
Bram Moolenaar58b85342016-08-14 19:54:54 +0200502A value can be any expression. Using a Dictionary for a value creates a
Bram Moolenaard8b02732005-01-14 21:48:43 +0000503nested Dictionary: >
504 :let nestdict = {1: {11: 'a', 12: 'b'}, 2: {21: 'c'}}
505
506An extra comma after the last entry is ignored.
507
508
509Accessing entries ~
510
511The normal way to access an entry is by putting the key in square brackets: >
512 :let val = mydict["one"]
513 :let mydict["four"] = 4
514
Bram Moolenaar3a3a7232005-01-17 22:16:15 +0000515You can add new entries to an existing Dictionary this way, unlike Lists.
Bram Moolenaard8b02732005-01-14 21:48:43 +0000516
517For keys that consist entirely of letters, digits and underscore the following
518form can be used |expr-entry|: >
519 :let val = mydict.one
520 :let mydict.four = 4
521
522Since an entry can be any type, also a List and a Dictionary, the indexing and
523key lookup can be repeated: >
Bram Moolenaar3a3a7232005-01-17 22:16:15 +0000524 :echo dict.key[idx].key
Bram Moolenaard8b02732005-01-14 21:48:43 +0000525
526
527Dictionary to List conversion ~
528
Bram Moolenaar58b85342016-08-14 19:54:54 +0200529You may want to loop over the entries in a dictionary. For this you need to
Bram Moolenaard8b02732005-01-14 21:48:43 +0000530turn the Dictionary into a List and pass it to |:for|.
531
532Most often you want to loop over the keys, using the |keys()| function: >
533 :for key in keys(mydict)
534 : echo key . ': ' . mydict[key]
535 :endfor
536
537The List of keys is unsorted. You may want to sort them first: >
538 :for key in sort(keys(mydict))
539
540To loop over the values use the |values()| function: >
541 :for v in values(mydict)
542 : echo "value: " . v
543 :endfor
544
545If you want both the key and the value use the |items()| function. It returns
Bram Moolenaard47d5222018-12-09 20:43:55 +0100546a List in which each item is a List with two items, the key and the value: >
Bram Moolenaaref2f6562007-05-06 13:32:59 +0000547 :for [key, value] in items(mydict)
548 : echo key . ': ' . value
Bram Moolenaard8b02732005-01-14 21:48:43 +0000549 :endfor
550
551
552Dictionary identity ~
Bram Moolenaar7c626922005-02-07 22:01:03 +0000553 *dict-identity*
Bram Moolenaard8b02732005-01-14 21:48:43 +0000554Just like Lists you need to use |copy()| and |deepcopy()| to make a copy of a
555Dictionary. Otherwise, assignment results in referring to the same
556Dictionary: >
557 :let onedict = {'a': 1, 'b': 2}
558 :let adict = onedict
559 :let adict['a'] = 11
560 :echo onedict['a']
561 11
562
Bram Moolenaarf3bd51a2005-06-14 22:11:18 +0000563Two Dictionaries compare equal if all the key-value pairs compare equal. For
564more info see |list-identity|.
Bram Moolenaard8b02732005-01-14 21:48:43 +0000565
566
567Dictionary modification ~
568 *dict-modification*
569To change an already existing entry of a Dictionary, or to add a new entry,
570use |:let| this way: >
571 :let dict[4] = "four"
572 :let dict['one'] = item
573
Bram Moolenaar9cd15162005-01-16 22:02:49 +0000574Removing an entry from a Dictionary is done with |remove()| or |:unlet|.
575Three ways to remove the entry with key "aaa" from dict: >
576 :let i = remove(dict, 'aaa')
577 :unlet dict.aaa
578 :unlet dict['aaa']
Bram Moolenaard8b02732005-01-14 21:48:43 +0000579
580Merging a Dictionary with another is done with |extend()|: >
Bram Moolenaar3a3a7232005-01-17 22:16:15 +0000581 :call extend(adict, bdict)
582This extends adict with all entries from bdict. Duplicate keys cause entries
583in adict to be overwritten. An optional third argument can change this.
Bram Moolenaar383f9bc2005-01-19 22:18:32 +0000584Note that the order of entries in a Dictionary is irrelevant, thus don't
585expect ":echo adict" to show the items from bdict after the older entries in
586adict.
Bram Moolenaard8b02732005-01-14 21:48:43 +0000587
588Weeding out entries from a Dictionary can be done with |filter()|: >
Bram Moolenaaref2f6562007-05-06 13:32:59 +0000589 :call filter(dict, 'v:val =~ "x"')
Bram Moolenaar3a3a7232005-01-17 22:16:15 +0000590This removes all entries from "dict" with a value not matching 'x'.
Bram Moolenaar388a5d42020-05-26 21:20:45 +0200591This can also be used to remove all entries: >
592 call filter(dict, 0)
Bram Moolenaar2fda12f2005-01-15 22:14:15 +0000593
594
595Dictionary function ~
Bram Moolenaar26402cb2013-02-20 21:26:00 +0100596 *Dictionary-function* *self* *E725* *E862*
Bram Moolenaar2fda12f2005-01-15 22:14:15 +0000597When a function is defined with the "dict" attribute it can be used in a
Bram Moolenaar58b85342016-08-14 19:54:54 +0200598special way with a dictionary. Example: >
Bram Moolenaar2fda12f2005-01-15 22:14:15 +0000599 :function Mylen() dict
Bram Moolenaar3a3a7232005-01-17 22:16:15 +0000600 : return len(self.data)
Bram Moolenaar2fda12f2005-01-15 22:14:15 +0000601 :endfunction
Bram Moolenaar3a3a7232005-01-17 22:16:15 +0000602 :let mydict = {'data': [0, 1, 2, 3], 'len': function("Mylen")}
603 :echo mydict.len()
Bram Moolenaar2fda12f2005-01-15 22:14:15 +0000604
605This is like a method in object oriented programming. The entry in the
606Dictionary is a |Funcref|. The local variable "self" refers to the dictionary
607the function was invoked from.
608
Bram Moolenaar3a3a7232005-01-17 22:16:15 +0000609It is also possible to add a function without the "dict" attribute as a
610Funcref to a Dictionary, but the "self" variable is not available then.
611
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000612 *numbered-function* *anonymous-function*
Bram Moolenaar2fda12f2005-01-15 22:14:15 +0000613To avoid the extra name for the function it can be defined and directly
614assigned to a Dictionary in this way: >
Bram Moolenaar3a3a7232005-01-17 22:16:15 +0000615 :let mydict = {'data': [0, 1, 2, 3]}
Bram Moolenaar5a5f4592015-04-13 12:43:06 +0200616 :function mydict.len()
Bram Moolenaar3a3a7232005-01-17 22:16:15 +0000617 : return len(self.data)
Bram Moolenaar2fda12f2005-01-15 22:14:15 +0000618 :endfunction
Bram Moolenaar3a3a7232005-01-17 22:16:15 +0000619 :echo mydict.len()
Bram Moolenaar2fda12f2005-01-15 22:14:15 +0000620
Bram Moolenaar3a3a7232005-01-17 22:16:15 +0000621The function will then get a number and the value of dict.len is a |Funcref|
Bram Moolenaar58b85342016-08-14 19:54:54 +0200622that references this function. The function can only be used through a
Bram Moolenaar3a3a7232005-01-17 22:16:15 +0000623|Funcref|. It will automatically be deleted when there is no |Funcref|
624remaining that refers to it.
625
626It is not necessary to use the "dict" attribute for a numbered function.
Bram Moolenaar2fda12f2005-01-15 22:14:15 +0000627
Bram Moolenaar1affd722010-08-04 17:49:30 +0200628If you get an error for a numbered function, you can find out what it is with
629a trick. Assuming the function is 42, the command is: >
630 :function {42}
631
Bram Moolenaar2fda12f2005-01-15 22:14:15 +0000632
633Functions for Dictionaries ~
Bram Moolenaar3a3a7232005-01-17 22:16:15 +0000634 *E715*
635Functions that can be used with a Dictionary: >
Bram Moolenaar2fda12f2005-01-15 22:14:15 +0000636 :if has_key(dict, 'foo') " TRUE if dict has entry with key "foo"
637 :if empty(dict) " TRUE if dict is empty
638 :let l = len(dict) " number of items in dict
639 :let big = max(dict) " maximum value in dict
640 :let small = min(dict) " minimum value in dict
641 :let xs = count(dict, 'x') " count nr of times 'x' appears in dict
642 :let s = string(dict) " String representation of dict
643 :call map(dict, '">> " . v:val') " prepend ">> " to each item
Bram Moolenaard8b02732005-01-14 21:48:43 +0000644
645
Bram Moolenaard8968242019-01-15 22:51:57 +01006461.5 Blobs ~
647 *blob* *Blob* *Blobs* *E978*
Bram Moolenaaraff74912019-03-30 18:11:49 +0100648A Blob is a binary object. It can be used to read an image from a file and
649send it over a channel, for example.
650
651A Blob mostly behaves like a |List| of numbers, where each number has the
652value of an 8-bit byte, from 0 to 255.
Bram Moolenaard8968242019-01-15 22:51:57 +0100653
654
655Blob creation ~
656
657A Blob can be created with a |blob-literal|: >
658 :let b = 0zFF00ED015DAF
Bram Moolenaar0d17f0d2019-01-22 22:20:38 +0100659Dots can be inserted between bytes (pair of hex characters) for readability,
660they don't change the value: >
661 :let b = 0zFF00.ED01.5DAF
Bram Moolenaard8968242019-01-15 22:51:57 +0100662
663A blob can be read from a file with |readfile()| passing the {type} argument
664set to "B", for example: >
665 :let b = readfile('image.png', 'B')
666
667A blob can be read from a channel with the |ch_readblob()| function.
668
669
670Blob index ~
671 *blob-index* *E979*
672A byte in the Blob can be accessed by putting the index in square brackets
673after the Blob. Indexes are zero-based, thus the first byte has index zero. >
674 :let myblob = 0z00112233
675 :let byte = myblob[0] " get the first byte: 0x00
676 :let byte = myblob[2] " get the third byte: 0x22
677
678A negative index is counted from the end. Index -1 refers to the last byte in
679the Blob, -2 to the last but one byte, etc. >
680 :let last = myblob[-1] " get the last byte: 0x33
681
682To avoid an error for an invalid index use the |get()| function. When an item
683is not available it returns -1 or the default value you specify: >
684 :echo get(myblob, idx)
685 :echo get(myblob, idx, 999)
686
687
Bram Moolenaar5e66b422019-01-24 21:58:10 +0100688Blob iteration ~
689
690The |:for| loop executes commands for each byte of a Blob. The loop variable is
691set to each byte in the Blob. Example: >
692 :for byte in 0z112233
693 : call Doit(byte)
694 :endfor
695This calls Doit() with 0x11, 0x22 and 0x33.
696
697
Bram Moolenaard8968242019-01-15 22:51:57 +0100698Blob concatenation ~
699
700Two blobs can be concatenated with the "+" operator: >
701 :let longblob = myblob + 0z4455
702 :let myblob += 0z6677
703
704To change a blob in-place see |blob-modification| below.
705
706
707Part of a blob ~
708
709A part of the Blob can be obtained by specifying the first and last index,
710separated by a colon in square brackets: >
711 :let myblob = 0z00112233
Bram Moolenaard09091d2019-01-17 16:07:22 +0100712 :let shortblob = myblob[1:2] " get 0z1122
Bram Moolenaard8968242019-01-15 22:51:57 +0100713 :let shortblob = myblob[2:-1] " get 0z2233
714
715Omitting the first index is similar to zero. Omitting the last index is
716similar to -1. >
717 :let endblob = myblob[2:] " from item 2 to the end: 0z2233
718 :let shortblob = myblob[2:2] " Blob with one byte: 0z22
719 :let otherblob = myblob[:] " make a copy of the Blob
720
Bram Moolenaard09091d2019-01-17 16:07:22 +0100721If the first index is beyond the last byte of the Blob or the second index is
Bram Moolenaaraa5df7e2019-02-03 14:53:10 +0100722before the first index, the result is an empty Blob. There is no error
Bram Moolenaard8968242019-01-15 22:51:57 +0100723message.
724
725If the second index is equal to or greater than the length of the list the
726length minus one is used: >
727 :echo myblob[2:8] " result: 0z2233
728
729
730Blob modification ~
731 *blob-modification*
732To change a specific byte of a blob use |:let| this way: >
733 :let blob[4] = 0x44
734
735When the index is just one beyond the end of the Blob, it is appended. Any
736higher index is an error.
737
738To change a sequence of bytes the [:] notation can be used: >
739 let blob[1:3] = 0z445566
Bram Moolenaard09091d2019-01-17 16:07:22 +0100740The length of the replaced bytes must be exactly the same as the value
Bram Moolenaard8968242019-01-15 22:51:57 +0100741provided. *E972*
742
743To change part of a blob you can specify the first and last byte to be
Bram Moolenaard09091d2019-01-17 16:07:22 +0100744modified. The value must have the same number of bytes in the range: >
745 :let blob[3:5] = 0z334455
Bram Moolenaard8968242019-01-15 22:51:57 +0100746
747You can also use the functions |add()|, |remove()| and |insert()|.
748
749
750Blob identity ~
751
752Blobs can be compared for equality: >
753 if blob == 0z001122
754And for equal identity: >
755 if blob is otherblob
756< *blob-identity* *E977*
757When variable "aa" is a Blob and you assign it to another variable "bb", both
758variables refer to the same Blob. Then the "is" operator returns true.
759
760When making a copy using [:] or |copy()| the values are the same, but the
761identity is different: >
762 :let blob = 0z112233
763 :let blob2 = blob
764 :echo blob == blob2
765< 1 >
766 :echo blob is blob2
767< 1 >
768 :let blob3 = blob[:]
769 :echo blob == blob3
770< 1 >
771 :echo blob is blob3
772< 0
773
Bram Moolenaard09091d2019-01-17 16:07:22 +0100774Making a copy of a Blob is done with the |copy()| function. Using [:] also
Bram Moolenaard8968242019-01-15 22:51:57 +0100775works, as explained above.
776
777
7781.6 More about variables ~
Bram Moolenaar13065c42005-01-08 16:08:21 +0000779 *more-variables*
Bram Moolenaar071d4272004-06-13 20:20:40 +0000780If you need to know the type of a variable or expression, use the |type()|
781function.
782
783When the '!' flag is included in the 'viminfo' option, global variables that
784start with an uppercase letter, and don't contain a lowercase letter, are
785stored in the viminfo file |viminfo-file|.
786
787When the 'sessionoptions' option contains "global", global variables that
788start with an uppercase letter and contain at least one lowercase letter are
789stored in the session file |session-file|.
790
791variable name can be stored where ~
792my_var_6 not
793My_Var_6 session file
794MY_VAR_6 viminfo file
795
796
797It's possible to form a variable name with curly braces, see
798|curly-braces-names|.
799
800==============================================================================
8012. Expression syntax *expression-syntax*
802
803Expression syntax summary, from least to most significant:
804
Bram Moolenaar50ba5262016-09-22 22:33:02 +0200805|expr1| expr2
Bram Moolenaar89bcfda2016-08-30 23:26:57 +0200806 expr2 ? expr1 : expr1 if-then-else
Bram Moolenaar071d4272004-06-13 20:20:40 +0000807
Bram Moolenaar89bcfda2016-08-30 23:26:57 +0200808|expr2| expr3
Bram Moolenaar0f248b02019-04-04 15:36:05 +0200809 expr3 || expr3 ... logical OR
Bram Moolenaar071d4272004-06-13 20:20:40 +0000810
Bram Moolenaar89bcfda2016-08-30 23:26:57 +0200811|expr3| expr4
Bram Moolenaar0f248b02019-04-04 15:36:05 +0200812 expr4 && expr4 ... logical AND
Bram Moolenaar071d4272004-06-13 20:20:40 +0000813
Bram Moolenaar89bcfda2016-08-30 23:26:57 +0200814|expr4| expr5
815 expr5 == expr5 equal
Bram Moolenaar071d4272004-06-13 20:20:40 +0000816 expr5 != expr5 not equal
817 expr5 > expr5 greater than
818 expr5 >= expr5 greater than or equal
819 expr5 < expr5 smaller than
820 expr5 <= expr5 smaller than or equal
821 expr5 =~ expr5 regexp matches
822 expr5 !~ expr5 regexp doesn't match
823
824 expr5 ==? expr5 equal, ignoring case
825 expr5 ==# expr5 equal, match case
826 etc. As above, append ? for ignoring case, # for
827 matching case
828
Bram Moolenaar5e66b422019-01-24 21:58:10 +0100829 expr5 is expr5 same |List|, |Dictionary| or |Blob| instance
830 expr5 isnot expr5 different |List|, |Dictionary| or |Blob|
831 instance
Bram Moolenaarde8866b2005-01-06 23:24:37 +0000832
Bram Moolenaar89bcfda2016-08-30 23:26:57 +0200833|expr5| expr6
Bram Moolenaar0f248b02019-04-04 15:36:05 +0200834 expr6 + expr6 ... number addition, list or blob concatenation
835 expr6 - expr6 ... number subtraction
836 expr6 . expr6 ... string concatenation
837 expr6 .. expr6 ... string concatenation
Bram Moolenaar071d4272004-06-13 20:20:40 +0000838
Bram Moolenaar89bcfda2016-08-30 23:26:57 +0200839|expr6| expr7
Bram Moolenaar0f248b02019-04-04 15:36:05 +0200840 expr7 * expr7 ... number multiplication
841 expr7 / expr7 ... number division
842 expr7 % expr7 ... number modulo
Bram Moolenaar071d4272004-06-13 20:20:40 +0000843
Bram Moolenaar89bcfda2016-08-30 23:26:57 +0200844|expr7| expr8
845 ! expr7 logical NOT
Bram Moolenaar071d4272004-06-13 20:20:40 +0000846 - expr7 unary minus
847 + expr7 unary plus
Bram Moolenaar071d4272004-06-13 20:20:40 +0000848
Bram Moolenaar89bcfda2016-08-30 23:26:57 +0200849|expr8| expr9
850 expr8[expr1] byte of a String or item of a |List|
Bram Moolenaar32466aa2006-02-24 23:53:04 +0000851 expr8[expr1 : expr1] substring of a String or sublist of a |List|
852 expr8.name entry in a |Dictionary|
853 expr8(expr1, ...) function call with |Funcref| variable
Bram Moolenaar25e42232019-08-04 15:04:10 +0200854 expr8->name(expr1, ...) |method| call
Bram Moolenaar2fda12f2005-01-15 22:14:15 +0000855
Bram Moolenaar50ba5262016-09-22 22:33:02 +0200856|expr9| number number constant
Bram Moolenaar3fdfa4a2004-10-07 21:02:47 +0000857 "string" string constant, backslash is special
Bram Moolenaard8b02732005-01-14 21:48:43 +0000858 'string' string constant, ' is doubled
Bram Moolenaar32466aa2006-02-24 23:53:04 +0000859 [expr1, ...] |List|
860 {expr1: expr1, ...} |Dictionary|
Bram Moolenaar25e42232019-08-04 15:04:10 +0200861 #{key: expr1, ...} |Dictionary|
Bram Moolenaar071d4272004-06-13 20:20:40 +0000862 &option option value
863 (expr1) nested expression
864 variable internal variable
865 va{ria}ble internal variable with curly braces
866 $VAR environment variable
867 @r contents of register 'r'
868 function(expr1, ...) function call
869 func{ti}on(expr1, ...) function call with curly braces
Bram Moolenaar069c1e72016-07-15 21:25:08 +0200870 {args -> expr1} lambda expression
Bram Moolenaar071d4272004-06-13 20:20:40 +0000871
872
Bram Moolenaar0f248b02019-04-04 15:36:05 +0200873"..." indicates that the operations in this level can be concatenated.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000874Example: >
875 &nu || &list && &shell == "csh"
876
877All expressions within one level are parsed from left to right.
878
879
880expr1 *expr1* *E109*
881-----
882
883expr2 ? expr1 : expr1
884
885The expression before the '?' is evaluated to a number. If it evaluates to
Bram Moolenaare381d3d2016-07-07 14:50:41 +0200886|TRUE|, the result is the value of the expression between the '?' and ':',
Bram Moolenaar071d4272004-06-13 20:20:40 +0000887otherwise the result is the value of the expression after the ':'.
888Example: >
889 :echo lnum == 1 ? "top" : lnum
890
891Since the first expression is an "expr2", it cannot contain another ?:. The
892other two expressions can, thus allow for recursive use of ?:.
893Example: >
894 :echo lnum == 1 ? "top" : lnum == 1000 ? "last" : lnum
895
896To keep this readable, using |line-continuation| is suggested: >
897 :echo lnum == 1
898 :\ ? "top"
899 :\ : lnum == 1000
900 :\ ? "last"
901 :\ : lnum
902
Bram Moolenaaref2f6562007-05-06 13:32:59 +0000903You should always put a space before the ':', otherwise it can be mistaken for
904use in a variable such as "a:1".
905
Bram Moolenaar071d4272004-06-13 20:20:40 +0000906
907expr2 and expr3 *expr2* *expr3*
908---------------
909
Bram Moolenaar04186092016-08-29 21:55:35 +0200910expr3 || expr3 .. logical OR *expr-barbar*
911expr4 && expr4 .. logical AND *expr-&&*
912
Bram Moolenaar071d4272004-06-13 20:20:40 +0000913The "||" and "&&" operators take one argument on each side. The arguments
914are (converted to) Numbers. The result is:
915
Bram Moolenaare381d3d2016-07-07 14:50:41 +0200916 input output ~
917n1 n2 n1 || n2 n1 && n2 ~
918|FALSE| |FALSE| |FALSE| |FALSE|
919|FALSE| |TRUE| |TRUE| |FALSE|
920|TRUE| |FALSE| |TRUE| |FALSE|
921|TRUE| |TRUE| |TRUE| |TRUE|
Bram Moolenaar071d4272004-06-13 20:20:40 +0000922
923The operators can be concatenated, for example: >
924
925 &nu || &list && &shell == "csh"
926
927Note that "&&" takes precedence over "||", so this has the meaning of: >
928
929 &nu || (&list && &shell == "csh")
930
931Once the result is known, the expression "short-circuits", that is, further
932arguments are not evaluated. This is like what happens in C. For example: >
933
934 let a = 1
935 echo a || b
936
Bram Moolenaare381d3d2016-07-07 14:50:41 +0200937This is valid even if there is no variable called "b" because "a" is |TRUE|,
938so the result must be |TRUE|. Similarly below: >
Bram Moolenaar071d4272004-06-13 20:20:40 +0000939
940 echo exists("b") && b == "yes"
941
942This is valid whether "b" has been defined or not. The second clause will
943only be evaluated if "b" has been defined.
944
945
946expr4 *expr4*
947-----
948
949expr5 {cmp} expr5
950
951Compare two expr5 expressions, resulting in a 0 if it evaluates to false, or 1
952if it evaluates to true.
953
Bram Moolenaar446cb832008-06-24 21:56:24 +0000954 *expr-==* *expr-!=* *expr->* *expr->=*
Bram Moolenaar071d4272004-06-13 20:20:40 +0000955 *expr-<* *expr-<=* *expr-=~* *expr-!~*
956 *expr-==#* *expr-!=#* *expr->#* *expr->=#*
957 *expr-<#* *expr-<=#* *expr-=~#* *expr-!~#*
958 *expr-==?* *expr-!=?* *expr->?* *expr->=?*
959 *expr-<?* *expr-<=?* *expr-=~?* *expr-!~?*
Bram Moolenaar251e1912011-06-19 05:09:16 +0200960 *expr-is* *expr-isnot* *expr-is#* *expr-isnot#*
961 *expr-is?* *expr-isnot?*
Bram Moolenaar071d4272004-06-13 20:20:40 +0000962 use 'ignorecase' match case ignore case ~
963equal == ==# ==?
964not equal != !=# !=?
965greater than > ># >?
966greater than or equal >= >=# >=?
967smaller than < <# <?
968smaller than or equal <= <=# <=?
969regexp matches =~ =~# =~?
970regexp doesn't match !~ !~# !~?
Bram Moolenaar251e1912011-06-19 05:09:16 +0200971same instance is is# is?
972different instance isnot isnot# isnot?
Bram Moolenaar071d4272004-06-13 20:20:40 +0000973
974Examples:
975"abc" ==# "Abc" evaluates to 0
976"abc" ==? "Abc" evaluates to 1
977"abc" == "Abc" evaluates to 1 if 'ignorecase' is set, 0 otherwise
978
Bram Moolenaar13065c42005-01-08 16:08:21 +0000979 *E691* *E692*
Bram Moolenaar01164a62017-11-02 22:58:42 +0100980A |List| can only be compared with a |List| and only "equal", "not equal",
981"is" and "isnot" can be used. This compares the values of the list,
982recursively. Ignoring case means case is ignored when comparing item values.
Bram Moolenaarde8866b2005-01-06 23:24:37 +0000983
Bram Moolenaar3a3a7232005-01-17 22:16:15 +0000984 *E735* *E736*
Bram Moolenaar32466aa2006-02-24 23:53:04 +0000985A |Dictionary| can only be compared with a |Dictionary| and only "equal", "not
Bram Moolenaar01164a62017-11-02 22:58:42 +0100986equal", "is" and "isnot" can be used. This compares the key/values of the
987|Dictionary| recursively. Ignoring case means case is ignored when comparing
988item values.
Bram Moolenaar3a3a7232005-01-17 22:16:15 +0000989
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +0200990 *E694*
Bram Moolenaare18dbe82016-07-02 21:42:23 +0200991A |Funcref| can only be compared with a |Funcref| and only "equal", "not
992equal", "is" and "isnot" can be used. Case is never ignored. Whether
993arguments or a Dictionary are bound (with a partial) matters. The
994Dictionaries must also be equal (or the same, in case of "is") and the
995arguments must be equal (or the same).
996
997To compare Funcrefs to see if they refer to the same function, ignoring bound
998Dictionary and arguments, use |get()| to get the function name: >
999 if get(Part1, 'name') == get(Part2, 'name')
1000 " Part1 and Part2 refer to the same function
Bram Moolenaarde8866b2005-01-06 23:24:37 +00001001
Bram Moolenaar5e66b422019-01-24 21:58:10 +01001002Using "is" or "isnot" with a |List|, |Dictionary| or |Blob| checks whether
1003the expressions are referring to the same |List|, |Dictionary| or |Blob|
1004instance. A copy of a |List| is different from the original |List|. When
1005using "is" without a |List|, |Dictionary| or |Blob|, it is equivalent to
1006using "equal", using "isnot" equivalent to using "not equal". Except that
1007a different type means the values are different: >
Bram Moolenaar86edef62016-03-13 18:07:30 +01001008 echo 4 == '4'
1009 1
1010 echo 4 is '4'
1011 0
1012 echo 0 is []
1013 0
1014"is#"/"isnot#" and "is?"/"isnot?" can be used to match and ignore case.
Bram Moolenaarde8866b2005-01-06 23:24:37 +00001015
Bram Moolenaar071d4272004-06-13 20:20:40 +00001016When comparing a String with a Number, the String is converted to a Number,
Bram Moolenaar58b85342016-08-14 19:54:54 +02001017and the comparison is done on Numbers. This means that: >
Bram Moolenaar86edef62016-03-13 18:07:30 +01001018 echo 0 == 'x'
1019 1
1020because 'x' converted to a Number is zero. However: >
1021 echo [0] == ['x']
1022 0
1023Inside a List or Dictionary this conversion is not used.
Bram Moolenaar071d4272004-06-13 20:20:40 +00001024
1025When comparing two Strings, this is done with strcmp() or stricmp(). This
1026results in the mathematical difference (comparing byte values), not
1027necessarily the alphabetical difference in the local language.
1028
Bram Moolenaar446cb832008-06-24 21:56:24 +00001029When using the operators with a trailing '#', or the short version and
Bram Moolenaaref2f6562007-05-06 13:32:59 +00001030'ignorecase' is off, the comparing is done with strcmp(): case matters.
Bram Moolenaar071d4272004-06-13 20:20:40 +00001031
1032When using the operators with a trailing '?', or the short version and
Bram Moolenaaref2f6562007-05-06 13:32:59 +00001033'ignorecase' is set, the comparing is done with stricmp(): case is ignored.
1034
1035'smartcase' is not used.
Bram Moolenaar071d4272004-06-13 20:20:40 +00001036
1037The "=~" and "!~" operators match the lefthand argument with the righthand
1038argument, which is used as a pattern. See |pattern| for what a pattern is.
1039This matching is always done like 'magic' was set and 'cpoptions' is empty, no
1040matter what the actual value of 'magic' or 'cpoptions' is. This makes scripts
1041portable. To avoid backslashes in the regexp pattern to be doubled, use a
1042single-quote string, see |literal-string|.
1043Since a string is considered to be a single line, a multi-line pattern
1044(containing \n, backslash-n) will not match. However, a literal NL character
1045can be matched like an ordinary character. Examples:
1046 "foo\nbar" =~ "\n" evaluates to 1
1047 "foo\nbar" =~ "\\n" evaluates to 0
1048
1049
1050expr5 and expr6 *expr5* *expr6*
1051---------------
Bram Moolenaar0f248b02019-04-04 15:36:05 +02001052expr6 + expr6 Number addition, |List| or |Blob| concatenation *expr-+*
1053expr6 - expr6 Number subtraction *expr--*
1054expr6 . expr6 String concatenation *expr-.*
1055expr6 .. expr6 String concatenation *expr-..*
Bram Moolenaar071d4272004-06-13 20:20:40 +00001056
Bram Moolenaara23ccb82006-02-27 00:08:02 +00001057For |Lists| only "+" is possible and then both expr6 must be a list. The
Bram Moolenaar32466aa2006-02-24 23:53:04 +00001058result is a new list with the two lists Concatenated.
Bram Moolenaarde8866b2005-01-06 23:24:37 +00001059
Bram Moolenaar0f248b02019-04-04 15:36:05 +02001060For String concatenation ".." is preferred, since "." is ambiguous, it is also
1061used for |Dict| member access and floating point numbers.
Bram Moolenaar558ca4a2019-04-04 18:15:38 +02001062When |vimscript-version| is 2 or higher, using "." is not allowed.
Bram Moolenaar0f248b02019-04-04 15:36:05 +02001063
Bram Moolenaar5e66b422019-01-24 21:58:10 +01001064expr7 * expr7 Number multiplication *expr-star*
1065expr7 / expr7 Number division *expr-/*
1066expr7 % expr7 Number modulo *expr-%*
Bram Moolenaar071d4272004-06-13 20:20:40 +00001067
Bram Moolenaar62e1bb42019-04-08 16:25:07 +02001068For all, except "." and "..", Strings are converted to Numbers.
Bram Moolenaard6e256c2011-12-14 15:32:50 +01001069For bitwise operators see |and()|, |or()| and |xor()|.
Bram Moolenaar071d4272004-06-13 20:20:40 +00001070
1071Note the difference between "+" and ".":
1072 "123" + "456" = 579
1073 "123" . "456" = "123456"
1074
Bram Moolenaar446cb832008-06-24 21:56:24 +00001075Since '.' has the same precedence as '+' and '-', you need to read: >
1076 1 . 90 + 90.0
1077As: >
1078 (1 . 90) + 90.0
1079That works, since the String "190" is automatically converted to the Number
1080190, which can be added to the Float 90.0. However: >
1081 1 . 90 * 90.0
1082Should be read as: >
1083 1 . (90 * 90.0)
1084Since '.' has lower precedence than '*'. This does NOT work, since this
1085attempts to concatenate a Float and a String.
1086
1087When dividing a Number by zero the result depends on the value:
1088 0 / 0 = -0x80000000 (like NaN for Float)
1089 >0 / 0 = 0x7fffffff (like positive infinity)
1090 <0 / 0 = -0x7fffffff (like negative infinity)
1091 (before Vim 7.2 it was always 0x7fffffff)
1092
Bram Moolenaar22fcfad2016-07-01 18:17:26 +02001093When 64-bit Number support is enabled:
1094 0 / 0 = -0x8000000000000000 (like NaN for Float)
1095 >0 / 0 = 0x7fffffffffffffff (like positive infinity)
1096 <0 / 0 = -0x7fffffffffffffff (like negative infinity)
1097
Bram Moolenaar071d4272004-06-13 20:20:40 +00001098When the righthand side of '%' is zero, the result is 0.
1099
Bram Moolenaar32466aa2006-02-24 23:53:04 +00001100None of these work for |Funcref|s.
Bram Moolenaarde8866b2005-01-06 23:24:37 +00001101
Bram Moolenaar446cb832008-06-24 21:56:24 +00001102. and % do not work for Float. *E804*
1103
Bram Moolenaar071d4272004-06-13 20:20:40 +00001104
1105expr7 *expr7*
1106-----
1107! expr7 logical NOT *expr-!*
1108- expr7 unary minus *expr-unary--*
1109+ expr7 unary plus *expr-unary-+*
1110
Bram Moolenaare381d3d2016-07-07 14:50:41 +02001111For '!' |TRUE| becomes |FALSE|, |FALSE| becomes |TRUE| (one).
Bram Moolenaar071d4272004-06-13 20:20:40 +00001112For '-' the sign of the number is changed.
1113For '+' the number is unchanged.
1114
1115A String will be converted to a Number first.
1116
Bram Moolenaar58b85342016-08-14 19:54:54 +02001117These three can be repeated and mixed. Examples:
Bram Moolenaar071d4272004-06-13 20:20:40 +00001118 !-1 == 0
1119 !!8 == 1
1120 --9 == 9
1121
1122
1123expr8 *expr8*
1124-----
Bram Moolenaarfc65cab2018-08-28 22:58:02 +02001125This expression is either |expr9| or a sequence of the alternatives below,
1126in any order. E.g., these are all possible:
Bram Moolenaar25e42232019-08-04 15:04:10 +02001127 expr8[expr1].name
1128 expr8.name[expr1]
1129 expr8(expr1, ...)[expr1].name
1130 expr8->(expr1, ...)[expr1]
Bram Moolenaarac92e252019-08-03 21:58:38 +02001131Evaluation is always from left to right.
Bram Moolenaarfc65cab2018-08-28 22:58:02 +02001132
Bram Moolenaar32466aa2006-02-24 23:53:04 +00001133expr8[expr1] item of String or |List| *expr-[]* *E111*
Bram Moolenaar03413f42016-04-12 21:07:15 +02001134 *E909* *subscript*
Bram Moolenaare3c37d82020-08-15 18:39:05 +02001135In legacy Vim script:
Bram Moolenaar2fda12f2005-01-15 22:14:15 +00001136If expr8 is a Number or String this results in a String that contains the
Bram Moolenaare3c37d82020-08-15 18:39:05 +02001137expr1'th single byte from expr8. expr8 is used as a String (a number is
1138automatically converted to a String), expr1 as a Number. This doesn't
Bram Moolenaar207f0092020-08-30 17:20:20 +02001139recognize multibyte encodings, see `byteidx()` for an alternative, or use
Bram Moolenaare3c37d82020-08-15 18:39:05 +02001140`split()` to turn the string into a list of characters. Example, to get the
1141byte under the cursor: >
Bram Moolenaar61660ea2006-04-07 21:40:07 +00001142 :let c = getline(".")[col(".") - 1]
Bram Moolenaar071d4272004-06-13 20:20:40 +00001143
Bram Moolenaare3c37d82020-08-15 18:39:05 +02001144In Vim9 script:
1145If expr8 is a String this results in a String that contains the expr1'th
1146single character from expr8. To use byte indexes use |strpart()|.
1147
1148Index zero gives the first byte or character. Careful: text column numbers
1149start with one!
1150
Bram Moolenaar071d4272004-06-13 20:20:40 +00001151If the length of the String is less than the index, the result is an empty
Bram Moolenaar85084ef2016-01-17 22:26:33 +01001152String. A negative index always results in an empty string (reason: backward
Bram Moolenaare3c37d82020-08-15 18:39:05 +02001153compatibility). Use [-1:] to get the last byte or character.
Bram Moolenaard7ee7ce2005-01-03 21:02:03 +00001154
Bram Moolenaar32466aa2006-02-24 23:53:04 +00001155If expr8 is a |List| then it results the item at index expr1. See |list-index|
Bram Moolenaard7ee7ce2005-01-03 21:02:03 +00001156for possible index values. If the index is out of range this results in an
Bram Moolenaar58b85342016-08-14 19:54:54 +02001157error. Example: >
Bram Moolenaard7ee7ce2005-01-03 21:02:03 +00001158 :let item = mylist[-1] " get last item
1159
Bram Moolenaar32466aa2006-02-24 23:53:04 +00001160Generally, if a |List| index is equal to or higher than the length of the
1161|List|, or more negative than the length of the |List|, this results in an
1162error.
Bram Moolenaard7ee7ce2005-01-03 21:02:03 +00001163
Bram Moolenaard8b02732005-01-14 21:48:43 +00001164
Bram Moolenaar2fda12f2005-01-15 22:14:15 +00001165expr8[expr1a : expr1b] substring or sublist *expr-[:]*
Bram Moolenaard7ee7ce2005-01-03 21:02:03 +00001166
Bram Moolenaar207f0092020-08-30 17:20:20 +02001167If expr8 is a String this results in the substring with the bytes or
1168characters from expr1a to and including expr1b. expr8 is used as a String,
1169expr1a and expr1b are used as a Number.
Bram Moolenaare3c37d82020-08-15 18:39:05 +02001170
1171In legacy Vim script the indexes are byte indexes. This doesn't recognize
Bram Moolenaar207f0092020-08-30 17:20:20 +02001172multibyte encodings, see |byteidx()| for computing the indexes. If expr8 is
Bram Moolenaare3c37d82020-08-15 18:39:05 +02001173a Number it is first converted to a String.
1174
1175In Vim9 script the indexes are character indexes. To use byte indexes use
1176|strpart()|.
Bram Moolenaard7ee7ce2005-01-03 21:02:03 +00001177
1178If expr1a is omitted zero is used. If expr1b is omitted the length of the
1179string minus one is used.
1180
1181A negative number can be used to measure from the end of the string. -1 is
1182the last character, -2 the last but one, etc.
1183
1184If an index goes out of range for the string characters are omitted. If
1185expr1b is smaller than expr1a the result is an empty string.
1186
1187Examples: >
1188 :let c = name[-1:] " last byte of a string
Bram Moolenaar207f0092020-08-30 17:20:20 +02001189 :let c = name[0:-1] " the whole string
Bram Moolenaard7ee7ce2005-01-03 21:02:03 +00001190 :let c = name[-2:-2] " last but one byte of a string
1191 :let s = line(".")[4:] " from the fifth byte to the end
1192 :let s = s[:-3] " remove last two bytes
Bram Moolenaar8f3f58f2010-01-06 20:52:26 +01001193<
Bram Moolenaarbc8801c2016-08-02 21:04:33 +02001194 *slice*
Bram Moolenaar32466aa2006-02-24 23:53:04 +00001195If expr8 is a |List| this results in a new |List| with the items indicated by
Bram Moolenaar58b85342016-08-14 19:54:54 +02001196the indexes expr1a and expr1b. This works like with a String, as explained
Bram Moolenaarbc8801c2016-08-02 21:04:33 +02001197just above. Also see |sublist| below. Examples: >
Bram Moolenaard7ee7ce2005-01-03 21:02:03 +00001198 :let l = mylist[:3] " first four items
1199 :let l = mylist[4:4] " List with one item
1200 :let l = mylist[:] " shallow copy of a List
1201
Bram Moolenaar6e5ea8d2019-01-12 22:47:31 +01001202If expr8 is a |Blob| this results in a new |Blob| with the bytes in the
1203indexes expr1a and expr1b, inclusive. Examples: >
1204 :let b = 0zDEADBEEF
1205 :let bs = b[1:2] " 0zADBE
Bram Moolenaard09091d2019-01-17 16:07:22 +01001206 :let bs = b[:] " copy of 0zDEADBEEF
Bram Moolenaar6e5ea8d2019-01-12 22:47:31 +01001207
Bram Moolenaar32466aa2006-02-24 23:53:04 +00001208Using expr8[expr1] or expr8[expr1a : expr1b] on a |Funcref| results in an
1209error.
Bram Moolenaar071d4272004-06-13 20:20:40 +00001210
Bram Moolenaarda440d22016-01-16 21:27:23 +01001211Watch out for confusion between a namespace and a variable followed by a colon
1212for a sublist: >
1213 mylist[n:] " uses variable n
1214 mylist[s:] " uses namespace s:, error!
1215
Bram Moolenaard8b02732005-01-14 21:48:43 +00001216
Bram Moolenaar32466aa2006-02-24 23:53:04 +00001217expr8.name entry in a |Dictionary| *expr-entry*
Bram Moolenaard8b02732005-01-14 21:48:43 +00001218
Bram Moolenaar32466aa2006-02-24 23:53:04 +00001219If expr8 is a |Dictionary| and it is followed by a dot, then the following
1220name will be used as a key in the |Dictionary|. This is just like:
1221expr8[name].
Bram Moolenaard8b02732005-01-14 21:48:43 +00001222
1223The name must consist of alphanumeric characters, just like a variable name,
1224but it may start with a number. Curly braces cannot be used.
1225
1226There must not be white space before or after the dot.
1227
1228Examples: >
1229 :let dict = {"one": 1, 2: "two"}
Bram Moolenaar68e65602019-05-26 21:33:31 +02001230 :echo dict.one " shows "1"
1231 :echo dict.2 " shows "two"
1232 :echo dict .2 " error because of space before the dot
Bram Moolenaard8b02732005-01-14 21:48:43 +00001233
1234Note that the dot is also used for String concatenation. To avoid confusion
1235always put spaces around the dot for String concatenation.
1236
1237
Bram Moolenaar32466aa2006-02-24 23:53:04 +00001238expr8(expr1, ...) |Funcref| function call
Bram Moolenaar2fda12f2005-01-15 22:14:15 +00001239
1240When expr8 is a |Funcref| type variable, invoke the function it refers to.
1241
1242
Bram Moolenaar22a0c0c2019-08-09 23:25:08 +02001243expr8->name([args]) method call *method* *->*
1244expr8->{lambda}([args])
Bram Moolenaar56c860c2019-08-17 20:09:31 +02001245 *E276*
Bram Moolenaar25e42232019-08-04 15:04:10 +02001246For methods that are also available as global functions this is the same as: >
Bram Moolenaarac92e252019-08-03 21:58:38 +02001247 name(expr8 [, args])
1248There can also be methods specifically for the type of "expr8".
Bram Moolenaar2fda12f2005-01-15 22:14:15 +00001249
Bram Moolenaar51841322019-08-08 21:10:01 +02001250This allows for chaining, passing the value that one method returns to the
1251next method: >
Bram Moolenaar25e42232019-08-04 15:04:10 +02001252 mylist->filter(filterexpr)->map(mapexpr)->sort()->join()
1253<
Bram Moolenaar22a0c0c2019-08-09 23:25:08 +02001254Example of using a lambda: >
Bram Moolenaar02b31112019-08-31 22:16:38 +02001255 GetPercentage()->{x -> x * 100}()->printf('%d%%')
Bram Moolenaar56c860c2019-08-17 20:09:31 +02001256<
Bram Moolenaar93cf85f2019-08-17 21:36:28 +02001257When using -> the |expr7| operators will be applied first, thus: >
1258 -1.234->string()
1259Is equivalent to: >
1260 (-1.234)->string()
1261And NOT: >
1262 -(1.234->string())
1263<
Bram Moolenaar51841322019-08-08 21:10:01 +02001264 *E274*
1265"->name(" must not contain white space. There can be white space before the
1266"->" and after the "(", thus you can split the lines like this: >
1267 mylist
1268 \ ->filter(filterexpr)
1269 \ ->map(mapexpr)
1270 \ ->sort()
1271 \ ->join()
Bram Moolenaar56c860c2019-08-17 20:09:31 +02001272
1273When using the lambda form there must be no white space between the } and the
1274(.
1275
Bram Moolenaar25e42232019-08-04 15:04:10 +02001276
Bram Moolenaar2fda12f2005-01-15 22:14:15 +00001277 *expr9*
Bram Moolenaar071d4272004-06-13 20:20:40 +00001278number
1279------
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01001280number number constant *expr-number*
Bram Moolenaar7571d552016-08-18 22:54:46 +02001281 *hex-number* *octal-number* *binary-number*
Bram Moolenaar071d4272004-06-13 20:20:40 +00001282
Bram Moolenaar7571d552016-08-18 22:54:46 +02001283Decimal, Hexadecimal (starting with 0x or 0X), Binary (starting with 0b or 0B)
Bram Moolenaarc17e66c2020-06-02 21:38:22 +02001284and Octal (starting with 0, 0o or 0O).
Bram Moolenaar071d4272004-06-13 20:20:40 +00001285
Bram Moolenaar446cb832008-06-24 21:56:24 +00001286 *floating-point-format*
1287Floating point numbers can be written in two forms:
1288
1289 [-+]{N}.{M}
Bram Moolenaar8a94d872015-01-25 13:02:57 +01001290 [-+]{N}.{M}[eE][-+]{exp}
Bram Moolenaar446cb832008-06-24 21:56:24 +00001291
1292{N} and {M} are numbers. Both {N} and {M} must be present and can only
1293contain digits.
1294[-+] means there is an optional plus or minus sign.
1295{exp} is the exponent, power of 10.
Bram Moolenaar58b85342016-08-14 19:54:54 +02001296Only a decimal point is accepted, not a comma. No matter what the current
Bram Moolenaar446cb832008-06-24 21:56:24 +00001297locale is.
1298{only when compiled with the |+float| feature}
1299
1300Examples:
1301 123.456
1302 +0.0001
1303 55.0
1304 -0.123
1305 1.234e03
1306 1.0E-6
1307 -3.1416e+88
1308
1309These are INVALID:
1310 3. empty {M}
1311 1e40 missing .{M}
1312
1313Rationale:
1314Before floating point was introduced, the text "123.456" was interpreted as
1315the two numbers "123" and "456", both converted to a string and concatenated,
1316resulting in the string "123456". Since this was considered pointless, and we
Bram Moolenaare37d50a2008-08-06 17:06:04 +00001317could not find it intentionally being used in Vim scripts, this backwards
Bram Moolenaar446cb832008-06-24 21:56:24 +00001318incompatibility was accepted in favor of being able to use the normal notation
1319for floating point numbers.
1320
Bram Moolenaard47d5222018-12-09 20:43:55 +01001321 *float-pi* *float-e*
1322A few useful values to copy&paste: >
1323 :let pi = 3.14159265359
1324 :let e = 2.71828182846
1325Or, if you don't want to write them in as floating-point literals, you can
1326also use functions, like the following: >
1327 :let pi = acos(-1.0)
1328 :let e = exp(1.0)
Bram Moolenaar98aefe72018-12-13 22:20:09 +01001329<
Bram Moolenaar446cb832008-06-24 21:56:24 +00001330 *floating-point-precision*
1331The precision and range of floating points numbers depends on what "double"
1332means in the library Vim was compiled with. There is no way to change this at
1333runtime.
1334
1335The default for displaying a |Float| is to use 6 decimal places, like using
1336printf("%g", f). You can select something else when using the |printf()|
1337function. Example: >
1338 :echo printf('%.15e', atan(1))
1339< 7.853981633974483e-01
1340
1341
Bram Moolenaar071d4272004-06-13 20:20:40 +00001342
Bram Moolenaar979243b2015-06-26 19:35:49 +02001343string *string* *String* *expr-string* *E114*
Bram Moolenaar071d4272004-06-13 20:20:40 +00001344------
1345"string" string constant *expr-quote*
1346
1347Note that double quotes are used.
1348
1349A string constant accepts these special characters:
1350\... three-digit octal number (e.g., "\316")
1351\.. two-digit octal number (must be followed by non-digit)
1352\. one-digit octal number (must be followed by non-digit)
1353\x.. byte specified with two hex numbers (e.g., "\x1f")
1354\x. byte specified with one hex number (must be followed by non-hex char)
1355\X.. same as \x..
1356\X. same as \x.
Bram Moolenaar446cb832008-06-24 21:56:24 +00001357\u.... character specified with up to 4 hex numbers, stored according to the
Bram Moolenaar071d4272004-06-13 20:20:40 +00001358 current value of 'encoding' (e.g., "\u02a4")
Bram Moolenaar541f92d2015-06-19 13:27:23 +02001359\U.... same as \u but allows up to 8 hex numbers.
Bram Moolenaar071d4272004-06-13 20:20:40 +00001360\b backspace <BS>
1361\e escape <Esc>
1362\f formfeed <FF>
1363\n newline <NL>
1364\r return <CR>
1365\t tab <Tab>
1366\\ backslash
1367\" double quote
Bram Moolenaar00a927d2010-05-14 23:24:24 +02001368\<xxx> Special key named "xxx". e.g. "\<C-W>" for CTRL-W. This is for use
Bram Moolenaar58b85342016-08-14 19:54:54 +02001369 in mappings, the 0x80 byte is escaped.
1370 To use the double quote character it must be escaped: "<M-\">".
1371 Don't use <Char-xxxx> to get a utf-8 character, use \uxxxx as
1372 mentioned above.
Bram Moolenaarfccd93f2020-05-31 22:06:51 +02001373\<*xxx> Like \<xxx> but prepends a modifier instead of including it in the
1374 character. E.g. "\<C-w>" is one character 0x17 while "\<*C-w>" is four
Bram Moolenaarebe9d342020-05-30 21:52:54 +02001375 bytes: 3 for the CTRL modifier and then character "W".
Bram Moolenaar071d4272004-06-13 20:20:40 +00001376
Bram Moolenaaref2f6562007-05-06 13:32:59 +00001377Note that "\xff" is stored as the byte 255, which may be invalid in some
1378encodings. Use "\u00ff" to store character 255 according to the current value
1379of 'encoding'.
1380
Bram Moolenaar071d4272004-06-13 20:20:40 +00001381Note that "\000" and "\x00" force the end of the string.
1382
1383
Bram Moolenaard8968242019-01-15 22:51:57 +01001384blob-literal *blob-literal* *E973*
Bram Moolenaar6e5ea8d2019-01-12 22:47:31 +01001385------------
1386
1387Hexadecimal starting with 0z or 0Z, with an arbitrary number of bytes.
1388The sequence must be an even number of hex characters. Example: >
1389 :let b = 0zFF00ED015DAF
1390
1391
Bram Moolenaar071d4272004-06-13 20:20:40 +00001392literal-string *literal-string* *E115*
1393---------------
Bram Moolenaar3fdfa4a2004-10-07 21:02:47 +00001394'string' string constant *expr-'*
Bram Moolenaar071d4272004-06-13 20:20:40 +00001395
1396Note that single quotes are used.
1397
Bram Moolenaar58b85342016-08-14 19:54:54 +02001398This string is taken as it is. No backslashes are removed or have a special
Bram Moolenaard8b02732005-01-14 21:48:43 +00001399meaning. The only exception is that two quotes stand for one quote.
Bram Moolenaar3fdfa4a2004-10-07 21:02:47 +00001400
1401Single quoted strings are useful for patterns, so that backslashes do not need
Bram Moolenaar58b85342016-08-14 19:54:54 +02001402to be doubled. These two commands are equivalent: >
Bram Moolenaar3fdfa4a2004-10-07 21:02:47 +00001403 if a =~ "\\s*"
1404 if a =~ '\s*'
Bram Moolenaar071d4272004-06-13 20:20:40 +00001405
1406
1407option *expr-option* *E112* *E113*
1408------
1409&option option value, local value if possible
1410&g:option global option value
1411&l:option local option value
1412
1413Examples: >
1414 echo "tabstop is " . &tabstop
1415 if &insertmode
1416
1417Any option name can be used here. See |options|. When using the local value
1418and there is no buffer-local or window-local value, the global value is used
1419anyway.
1420
1421
Bram Moolenaaref2f6562007-05-06 13:32:59 +00001422register *expr-register* *@r*
Bram Moolenaar071d4272004-06-13 20:20:40 +00001423--------
1424@r contents of register 'r'
1425
1426The result is the contents of the named register, as a single string.
1427Newlines are inserted where required. To get the contents of the unnamed
Bram Moolenaar58b85342016-08-14 19:54:54 +02001428register use @" or @@. See |registers| for an explanation of the available
Bram Moolenaare7566042005-06-17 22:00:15 +00001429registers.
1430
1431When using the '=' register you get the expression itself, not what it
1432evaluates to. Use |eval()| to evaluate it.
Bram Moolenaar071d4272004-06-13 20:20:40 +00001433
1434
1435nesting *expr-nesting* *E110*
1436-------
1437(expr1) nested expression
1438
1439
1440environment variable *expr-env*
1441--------------------
1442$VAR environment variable
1443
1444The String value of any environment variable. When it is not defined, the
1445result is an empty string.
Bram Moolenaar691ddee2019-05-09 14:52:41 +02001446
1447The functions `getenv()` and `setenv()` can also be used and work for
1448environment variables with non-alphanumeric names.
1449The function `environ()` can be used to get a Dict with all environment
1450variables.
1451
1452
Bram Moolenaar071d4272004-06-13 20:20:40 +00001453 *expr-env-expand*
1454Note that there is a difference between using $VAR directly and using
1455expand("$VAR"). Using it directly will only expand environment variables that
1456are known inside the current Vim session. Using expand() will first try using
1457the environment variables known inside the current Vim session. If that
1458fails, a shell will be used to expand the variable. This can be slow, but it
1459does expand all variables that the shell knows about. Example: >
Bram Moolenaar34401cc2014-08-29 15:12:19 +02001460 :echo $shell
1461 :echo expand("$shell")
1462The first one probably doesn't echo anything, the second echoes the $shell
Bram Moolenaar071d4272004-06-13 20:20:40 +00001463variable (if your shell supports it).
1464
1465
1466internal variable *expr-variable*
1467-----------------
1468variable internal variable
1469See below |internal-variables|.
1470
1471
Bram Moolenaar05159a02005-02-26 23:04:13 +00001472function call *expr-function* *E116* *E118* *E119* *E120*
Bram Moolenaar071d4272004-06-13 20:20:40 +00001473-------------
1474function(expr1, ...) function call
1475See below |functions|.
1476
1477
Bram Moolenaar069c1e72016-07-15 21:25:08 +02001478lambda expression *expr-lambda* *lambda*
1479-----------------
1480{args -> expr1} lambda expression
1481
1482A lambda expression creates a new unnamed function which returns the result of
Bram Moolenaar42ebd062016-07-17 13:35:14 +02001483evaluating |expr1|. Lambda expressions differ from |user-functions| in
Bram Moolenaar069c1e72016-07-15 21:25:08 +02001484the following ways:
1485
14861. The body of the lambda expression is an |expr1| and not a sequence of |Ex|
1487 commands.
Bram Moolenaar1e96d9b2016-07-29 22:15:09 +020014882. The prefix "a:" should not be used for arguments. E.g.: >
Bram Moolenaar069c1e72016-07-15 21:25:08 +02001489 :let F = {arg1, arg2 -> arg1 - arg2}
1490 :echo F(5, 2)
1491< 3
1492
1493The arguments are optional. Example: >
1494 :let F = {-> 'error function'}
1495 :echo F()
1496< error function
Bram Moolenaar1e96d9b2016-07-29 22:15:09 +02001497 *closure*
1498Lambda expressions can access outer scope variables and arguments. This is
Bram Moolenaar50ba5262016-09-22 22:33:02 +02001499often called a closure. Example where "i" and "a:arg" are used in a lambda
Bram Moolenaar6bb2cdf2018-02-24 19:53:53 +01001500while they already exist in the function scope. They remain valid even after
1501the function returns: >
Bram Moolenaar1e96d9b2016-07-29 22:15:09 +02001502 :function Foo(arg)
1503 : let i = 3
1504 : return {x -> x + i - a:arg}
1505 :endfunction
1506 :let Bar = Foo(4)
1507 :echo Bar(6)
1508< 5
Bram Moolenaar437bafe2016-08-01 15:40:54 +02001509
Bram Moolenaar388a5d42020-05-26 21:20:45 +02001510Note that the variables must exist in the outer scope before the lambda is
Bram Moolenaar6bb2cdf2018-02-24 19:53:53 +01001511defined for this to work. See also |:func-closure|.
1512
1513Lambda and closure support can be checked with: >
Bram Moolenaar437bafe2016-08-01 15:40:54 +02001514 if has('lambda')
Bram Moolenaar069c1e72016-07-15 21:25:08 +02001515
1516Examples for using a lambda expression with |sort()|, |map()| and |filter()|: >
1517 :echo map([1, 2, 3], {idx, val -> val + 1})
1518< [2, 3, 4] >
1519 :echo sort([3,7,2,1,4], {a, b -> a - b})
1520< [1, 2, 3, 4, 7]
1521
1522The lambda expression is also useful for Channel, Job and timer: >
1523 :let timer = timer_start(500,
1524 \ {-> execute("echo 'Handler called'", "")},
1525 \ {'repeat': 3})
1526< Handler called
1527 Handler called
1528 Handler called
1529
1530Note how execute() is used to execute an Ex command. That's ugly though.
1531
Bram Moolenaar1e96d9b2016-07-29 22:15:09 +02001532
1533Lambda expressions have internal names like '<lambda>42'. If you get an error
1534for a lambda expression, you can find what it is with the following command: >
1535 :function {'<lambda>42'}
1536See also: |numbered-function|
1537
Bram Moolenaar071d4272004-06-13 20:20:40 +00001538==============================================================================
Bram Moolenaar4a748032010-09-30 21:47:56 +020015393. Internal variable *internal-variables* *E461*
1540
Bram Moolenaar071d4272004-06-13 20:20:40 +00001541An internal variable name can be made up of letters, digits and '_'. But it
1542cannot start with a digit. It's also possible to use curly braces, see
1543|curly-braces-names|.
1544
1545An internal variable is created with the ":let" command |:let|.
Bram Moolenaar9588a0f2005-01-08 21:45:39 +00001546An internal variable is explicitly destroyed with the ":unlet" command
1547|:unlet|.
1548Using a name that is not an internal variable or refers to a variable that has
1549been destroyed results in an error.
Bram Moolenaar071d4272004-06-13 20:20:40 +00001550
Bram Moolenaar65e0d772020-06-14 17:29:55 +02001551 *variable-scope*
Bram Moolenaar071d4272004-06-13 20:20:40 +00001552There are several name spaces for variables. Which one is to be used is
1553specified by what is prepended:
1554
1555 (nothing) In a function: local to a function; otherwise: global
1556|buffer-variable| b: Local to the current buffer.
1557|window-variable| w: Local to the current window.
Bram Moolenaar910f66f2006-04-05 20:41:53 +00001558|tabpage-variable| t: Local to the current tab page.
Bram Moolenaar071d4272004-06-13 20:20:40 +00001559|global-variable| g: Global.
1560|local-variable| l: Local to a function.
1561|script-variable| s: Local to a |:source|'ed Vim script.
1562|function-argument| a: Function argument (only inside a function).
Bram Moolenaar75b81562014-04-06 14:09:13 +02001563|vim-variable| v: Global, predefined by Vim.
Bram Moolenaar071d4272004-06-13 20:20:40 +00001564
Bram Moolenaar32466aa2006-02-24 23:53:04 +00001565The scope name by itself can be used as a |Dictionary|. For example, to
1566delete all script-local variables: >
Bram Moolenaar8f999f12005-01-25 22:12:55 +00001567 :for k in keys(s:)
1568 : unlet s:[k]
1569 :endfor
Bram Moolenaar65e0d772020-06-14 17:29:55 +02001570
1571Note: in Vim9 script this is different, see |vim9-scopes|.
1572
Bram Moolenaar531da592013-05-06 05:58:55 +02001573 *buffer-variable* *b:var* *b:*
Bram Moolenaar071d4272004-06-13 20:20:40 +00001574A variable name that is preceded with "b:" is local to the current buffer.
1575Thus you can have several "b:foo" variables, one for each buffer.
1576This kind of variable is deleted when the buffer is wiped out or deleted with
1577|:bdelete|.
1578
1579One local buffer variable is predefined:
Bram Moolenaarbf884932013-04-05 22:26:15 +02001580 *b:changedtick* *changetick*
Bram Moolenaar071d4272004-06-13 20:20:40 +00001581b:changedtick The total number of changes to the current buffer. It is
1582 incremented for each change. An undo command is also a change
Bram Moolenaarc024b462019-06-08 18:07:21 +02001583 in this case. Resetting 'modified' when writing the buffer is
1584 also counted.
1585 This can be used to perform an action only when the buffer has
1586 changed. Example: >
Bram Moolenaar071d4272004-06-13 20:20:40 +00001587 :if my_changedtick != b:changedtick
Bram Moolenaar446cb832008-06-24 21:56:24 +00001588 : let my_changedtick = b:changedtick
1589 : call My_Update()
Bram Moolenaar071d4272004-06-13 20:20:40 +00001590 :endif
Bram Moolenaar3df01732017-02-17 22:47:16 +01001591< You cannot change or delete the b:changedtick variable.
1592
Bram Moolenaar531da592013-05-06 05:58:55 +02001593 *window-variable* *w:var* *w:*
Bram Moolenaar071d4272004-06-13 20:20:40 +00001594A variable name that is preceded with "w:" is local to the current window. It
1595is deleted when the window is closed.
1596
Bram Moolenaarad3b3662013-05-17 18:14:19 +02001597 *tabpage-variable* *t:var* *t:*
Bram Moolenaar910f66f2006-04-05 20:41:53 +00001598A variable name that is preceded with "t:" is local to the current tab page,
1599It is deleted when the tab page is closed. {not available when compiled
Bram Moolenaardb84e452010-08-15 13:50:43 +02001600without the |+windows| feature}
Bram Moolenaar910f66f2006-04-05 20:41:53 +00001601
Bram Moolenaar531da592013-05-06 05:58:55 +02001602 *global-variable* *g:var* *g:*
Bram Moolenaar071d4272004-06-13 20:20:40 +00001603Inside functions global variables are accessed with "g:". Omitting this will
Bram Moolenaar58b85342016-08-14 19:54:54 +02001604access a variable local to a function. But "g:" can also be used in any other
Bram Moolenaar071d4272004-06-13 20:20:40 +00001605place if you like.
1606
Bram Moolenaar531da592013-05-06 05:58:55 +02001607 *local-variable* *l:var* *l:*
Bram Moolenaar071d4272004-06-13 20:20:40 +00001608Inside functions local variables are accessed without prepending anything.
Bram Moolenaaref2f6562007-05-06 13:32:59 +00001609But you can also prepend "l:" if you like. However, without prepending "l:"
1610you may run into reserved variable names. For example "count". By itself it
1611refers to "v:count". Using "l:count" you can have a local variable with the
1612same name.
Bram Moolenaar071d4272004-06-13 20:20:40 +00001613
1614 *script-variable* *s:var*
1615In a Vim script variables starting with "s:" can be used. They cannot be
1616accessed from outside of the scripts, thus are local to the script.
1617
1618They can be used in:
1619- commands executed while the script is sourced
1620- functions defined in the script
1621- autocommands defined in the script
1622- functions and autocommands defined in functions and autocommands which were
1623 defined in the script (recursively)
1624- user defined commands defined in the script
1625Thus not in:
1626- other scripts sourced from this one
1627- mappings
Bram Moolenaar8f3f58f2010-01-06 20:52:26 +01001628- menus
Bram Moolenaar071d4272004-06-13 20:20:40 +00001629- etc.
1630
Bram Moolenaaref2f6562007-05-06 13:32:59 +00001631Script variables can be used to avoid conflicts with global variable names.
1632Take this example: >
Bram Moolenaar071d4272004-06-13 20:20:40 +00001633
1634 let s:counter = 0
1635 function MyCounter()
1636 let s:counter = s:counter + 1
1637 echo s:counter
1638 endfunction
1639 command Tick call MyCounter()
1640
1641You can now invoke "Tick" from any script, and the "s:counter" variable in
1642that script will not be changed, only the "s:counter" in the script where
1643"Tick" was defined is used.
1644
1645Another example that does the same: >
1646
1647 let s:counter = 0
1648 command Tick let s:counter = s:counter + 1 | echo s:counter
1649
1650When calling a function and invoking a user-defined command, the context for
Bram Moolenaar69a7cb42004-06-20 12:51:53 +00001651script variables is set to the script where the function or command was
Bram Moolenaar071d4272004-06-13 20:20:40 +00001652defined.
1653
1654The script variables are also available when a function is defined inside a
1655function that is defined in a script. Example: >
1656
1657 let s:counter = 0
1658 function StartCounting(incr)
1659 if a:incr
1660 function MyCounter()
1661 let s:counter = s:counter + 1
1662 endfunction
1663 else
1664 function MyCounter()
1665 let s:counter = s:counter - 1
1666 endfunction
1667 endif
1668 endfunction
1669
1670This defines the MyCounter() function either for counting up or counting down
1671when calling StartCounting(). It doesn't matter from where StartCounting() is
1672called, the s:counter variable will be accessible in MyCounter().
1673
1674When the same script is sourced again it will use the same script variables.
1675They will remain valid as long as Vim is running. This can be used to
1676maintain a counter: >
1677
1678 if !exists("s:counter")
1679 let s:counter = 1
1680 echo "script executed for the first time"
1681 else
1682 let s:counter = s:counter + 1
1683 echo "script executed " . s:counter . " times now"
1684 endif
1685
1686Note that this means that filetype plugins don't get a different set of script
1687variables for each buffer. Use local buffer variables instead |b:var|.
1688
1689
Bram Moolenaard47d5222018-12-09 20:43:55 +01001690PREDEFINED VIM VARIABLES *vim-variable* *v:var* *v:*
1691 *E963*
1692Some variables can be set by the user, but the type cannot be changed.
Bram Moolenaar071d4272004-06-13 20:20:40 +00001693
Bram Moolenaar69bf6342019-10-29 04:16:57 +01001694 *v:argv* *argv-variable*
1695v:argv The command line arguments Vim was invoked with. This is a
1696 list of strings. The first item is the Vim command.
1697
Bram Moolenaare4efc3b2005-03-07 23:16:51 +00001698 *v:beval_col* *beval_col-variable*
1699v:beval_col The number of the column, over which the mouse pointer is.
1700 This is the byte index in the |v:beval_lnum| line.
1701 Only valid while evaluating the 'balloonexpr' option.
1702
1703 *v:beval_bufnr* *beval_bufnr-variable*
1704v:beval_bufnr The number of the buffer, over which the mouse pointer is. Only
1705 valid while evaluating the 'balloonexpr' option.
1706
1707 *v:beval_lnum* *beval_lnum-variable*
1708v:beval_lnum The number of the line, over which the mouse pointer is. Only
1709 valid while evaluating the 'balloonexpr' option.
1710
1711 *v:beval_text* *beval_text-variable*
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00001712v:beval_text The text under or after the mouse pointer. Usually a word as
1713 it is useful for debugging a C program. 'iskeyword' applies,
1714 but a dot and "->" before the position is included. When on a
1715 ']' the text before it is used, including the matching '[' and
Bram Moolenaare4efc3b2005-03-07 23:16:51 +00001716 word before it. When on a Visual area within one line the
Bram Moolenaarb4d5fba2017-09-11 19:31:28 +02001717 highlighted text is used. Also see |<cexpr>|.
Bram Moolenaare4efc3b2005-03-07 23:16:51 +00001718 Only valid while evaluating the 'balloonexpr' option.
1719
1720 *v:beval_winnr* *beval_winnr-variable*
1721v:beval_winnr The number of the window, over which the mouse pointer is. Only
Bram Moolenaar00654022011-02-25 14:42:19 +01001722 valid while evaluating the 'balloonexpr' option. The first
1723 window has number zero (unlike most other places where a
1724 window gets a number).
Bram Moolenaare4efc3b2005-03-07 23:16:51 +00001725
Bram Moolenaar511972d2016-06-04 18:09:59 +02001726 *v:beval_winid* *beval_winid-variable*
Bram Moolenaar7571d552016-08-18 22:54:46 +02001727v:beval_winid The |window-ID| of the window, over which the mouse pointer
1728 is. Otherwise like v:beval_winnr.
Bram Moolenaar511972d2016-06-04 18:09:59 +02001729
Bram Moolenaarf193fff2006-04-27 00:02:13 +00001730 *v:char* *char-variable*
Bram Moolenaar8f3f58f2010-01-06 20:52:26 +01001731v:char Argument for evaluating 'formatexpr' and used for the typed
Bram Moolenaar945e2db2010-06-05 17:43:32 +02001732 character when using <expr> in an abbreviation |:map-<expr>|.
Bram Moolenaare6ae6222013-05-21 21:01:10 +02001733 It is also used by the |InsertCharPre| and |InsertEnter| events.
Bram Moolenaarf193fff2006-04-27 00:02:13 +00001734
Bram Moolenaar071d4272004-06-13 20:20:40 +00001735 *v:charconvert_from* *charconvert_from-variable*
1736v:charconvert_from
1737 The name of the character encoding of a file to be converted.
1738 Only valid while evaluating the 'charconvert' option.
1739
1740 *v:charconvert_to* *charconvert_to-variable*
1741v:charconvert_to
1742 The name of the character encoding of a file after conversion.
1743 Only valid while evaluating the 'charconvert' option.
1744
1745 *v:cmdarg* *cmdarg-variable*
1746v:cmdarg This variable is used for two purposes:
1747 1. The extra arguments given to a file read/write command.
1748 Currently these are "++enc=" and "++ff=". This variable is
1749 set before an autocommand event for a file read/write
1750 command is triggered. There is a leading space to make it
1751 possible to append this variable directly after the
Bram Moolenaar58b85342016-08-14 19:54:54 +02001752 read/write command. Note: The "+cmd" argument isn't
Bram Moolenaar071d4272004-06-13 20:20:40 +00001753 included here, because it will be executed anyway.
1754 2. When printing a PostScript file with ":hardcopy" this is
1755 the argument for the ":hardcopy" command. This can be used
1756 in 'printexpr'.
1757
1758 *v:cmdbang* *cmdbang-variable*
1759v:cmdbang Set like v:cmdarg for a file read/write command. When a "!"
1760 was used the value is 1, otherwise it is 0. Note that this
1761 can only be used in autocommands. For user commands |<bang>|
1762 can be used.
Bram Moolenaar84cf6bd2020-06-16 20:03:43 +02001763 *v:collate* *collate-variable*
1764v:collate The current locale setting for collation order of the runtime
1765 environment. This allows Vim scripts to be aware of the
1766 current locale encoding. Technical: it's the value of
1767 LC_COLLATE. When not using a locale the value is "C".
1768 This variable can not be set directly, use the |:language|
1769 command.
1770 See |multi-lang|.
Bram Moolenaar071d4272004-06-13 20:20:40 +00001771
Bram Moolenaar42a45122015-07-10 17:56:23 +02001772 *v:completed_item* *completed_item-variable*
1773v:completed_item
1774 |Dictionary| containing the |complete-items| for the most
1775 recently completed word after |CompleteDone|. The
1776 |Dictionary| is empty if the completion failed.
1777
Bram Moolenaar071d4272004-06-13 20:20:40 +00001778 *v:count* *count-variable*
1779v:count The count given for the last Normal mode command. Can be used
Bram Moolenaar58b85342016-08-14 19:54:54 +02001780 to get the count before a mapping. Read-only. Example: >
Bram Moolenaar071d4272004-06-13 20:20:40 +00001781 :map _x :<C-U>echo "the count is " . v:count<CR>
1782< Note: The <C-U> is required to remove the line range that you
1783 get when typing ':' after a count.
Bram Moolenaar8f3f58f2010-01-06 20:52:26 +01001784 When there are two counts, as in "3d2w", they are multiplied,
1785 just like what happens in the command, "d6w" for the example.
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00001786 Also used for evaluating the 'formatexpr' option.
Bram Moolenaard2e716e2019-04-20 14:39:52 +02001787 "count" also works, for backwards compatibility, unless
1788 |scriptversion| is 3 or higher.
Bram Moolenaar071d4272004-06-13 20:20:40 +00001789
1790 *v:count1* *count1-variable*
1791v:count1 Just like "v:count", but defaults to one when no count is
1792 used.
1793
1794 *v:ctype* *ctype-variable*
1795v:ctype The current locale setting for characters of the runtime
1796 environment. This allows Vim scripts to be aware of the
1797 current locale encoding. Technical: it's the value of
1798 LC_CTYPE. When not using a locale the value is "C".
1799 This variable can not be set directly, use the |:language|
1800 command.
1801 See |multi-lang|.
1802
1803 *v:dying* *dying-variable*
Bram Moolenaar58b85342016-08-14 19:54:54 +02001804v:dying Normally zero. When a deadly signal is caught it's set to
Bram Moolenaar071d4272004-06-13 20:20:40 +00001805 one. When multiple signals are caught the number increases.
1806 Can be used in an autocommand to check if Vim didn't
1807 terminate normally. {only works on Unix}
1808 Example: >
1809 :au VimLeave * if v:dying | echo "\nAAAAaaaarrrggghhhh!!!\n" | endif
Bram Moolenaar0e1e25f2010-05-28 21:07:08 +02001810< Note: if another deadly signal is caught when v:dying is one,
1811 VimLeave autocommands will not be executed.
1812
Bram Moolenaar37f4cbd2019-08-23 20:58:45 +02001813 *v:echospace* *echospace-variable*
1814v:echospace Number of screen cells that can be used for an `:echo` message
1815 in the last screen line before causing the |hit-enter-prompt|.
1816 Depends on 'showcmd', 'ruler' and 'columns'. You need to
1817 check 'cmdheight' for whether there are full-width lines
1818 available above the last line.
1819
Bram Moolenaar071d4272004-06-13 20:20:40 +00001820 *v:errmsg* *errmsg-variable*
1821v:errmsg Last given error message. It's allowed to set this variable.
1822 Example: >
1823 :let v:errmsg = ""
1824 :silent! next
1825 :if v:errmsg != ""
1826 : ... handle error
Bram Moolenaard2e716e2019-04-20 14:39:52 +02001827< "errmsg" also works, for backwards compatibility, unless
1828 |scriptversion| is 3 or higher.
Bram Moolenaar071d4272004-06-13 20:20:40 +00001829
Bram Moolenaar65a54642018-04-28 16:56:53 +02001830 *v:errors* *errors-variable* *assert-return*
Bram Moolenaar683fa182015-11-30 21:38:24 +01001831v:errors Errors found by assert functions, such as |assert_true()|.
Bram Moolenaar43345542015-11-29 17:35:35 +01001832 This is a list of strings.
1833 The assert functions append an item when an assert fails.
Bram Moolenaar65a54642018-04-28 16:56:53 +02001834 The return value indicates this: a one is returned if an item
1835 was added to v:errors, otherwise zero is returned.
Bram Moolenaar43345542015-11-29 17:35:35 +01001836 To remove old results make it empty: >
1837 :let v:errors = []
1838< If v:errors is set to anything but a list it is made an empty
1839 list by the assert function.
1840
Bram Moolenaar7e1652c2017-12-16 18:27:02 +01001841 *v:event* *event-variable*
1842v:event Dictionary containing information about the current
Bram Moolenaar560979e2020-02-04 22:53:05 +01001843 |autocommand|. See the specific event for what it puts in
1844 this dictionary.
Bram Moolenaar2c7f8c52020-04-20 19:52:53 +02001845 The dictionary is emptied when the |autocommand| finishes,
1846 please refer to |dict-identity| for how to get an independent
1847 copy of it. Use |deepcopy()| if you want to keep the
1848 information after the event triggers. Example: >
1849 au TextYankPost * let g:foo = deepcopy(v:event)
1850<
Bram Moolenaar071d4272004-06-13 20:20:40 +00001851 *v:exception* *exception-variable*
1852v:exception The value of the exception most recently caught and not
1853 finished. See also |v:throwpoint| and |throw-variables|.
1854 Example: >
1855 :try
1856 : throw "oops"
1857 :catch /.*/
Bram Moolenaar54775062019-07-31 21:07:14 +02001858 : echo "caught " .. v:exception
Bram Moolenaar071d4272004-06-13 20:20:40 +00001859 :endtry
1860< Output: "caught oops".
1861
Bram Moolenaar520e1e42016-01-23 19:46:28 +01001862 *v:false* *false-variable*
1863v:false A Number with value zero. Used to put "false" in JSON. See
Bram Moolenaar6463ca22016-02-13 17:04:46 +01001864 |json_encode()|.
Bram Moolenaarc95a3022016-06-12 23:01:46 +02001865 When used as a string this evaluates to "v:false". >
Bram Moolenaar705ada12016-01-24 17:56:50 +01001866 echo v:false
Bram Moolenaarc95a3022016-06-12 23:01:46 +02001867< v:false ~
1868 That is so that eval() can parse the string back to the same
Bram Moolenaardf48fb42016-07-22 21:50:18 +02001869 value. Read-only.
Bram Moolenaar520e1e42016-01-23 19:46:28 +01001870
Bram Moolenaar19a09a12005-03-04 23:39:37 +00001871 *v:fcs_reason* *fcs_reason-variable*
1872v:fcs_reason The reason why the |FileChangedShell| event was triggered.
1873 Can be used in an autocommand to decide what to do and/or what
1874 to set v:fcs_choice to. Possible values:
1875 deleted file no longer exists
1876 conflict file contents, mode or timestamp was
1877 changed and buffer is modified
1878 changed file contents has changed
1879 mode mode of file changed
1880 time only file timestamp changed
1881
1882 *v:fcs_choice* *fcs_choice-variable*
1883v:fcs_choice What should happen after a |FileChangedShell| event was
1884 triggered. Can be used in an autocommand to tell Vim what to
1885 do with the affected buffer:
1886 reload Reload the buffer (does not work if
1887 the file was deleted).
1888 ask Ask the user what to do, as if there
1889 was no autocommand. Except that when
1890 only the timestamp changed nothing
1891 will happen.
1892 <empty> Nothing, the autocommand should do
1893 everything that needs to be done.
1894 The default is empty. If another (invalid) value is used then
1895 Vim behaves like it is empty, there is no warning message.
1896
Bram Moolenaar071d4272004-06-13 20:20:40 +00001897 *v:fname_in* *fname_in-variable*
Bram Moolenaar4e330bb2005-12-07 21:04:31 +00001898v:fname_in The name of the input file. Valid while evaluating:
Bram Moolenaar071d4272004-06-13 20:20:40 +00001899 option used for ~
1900 'charconvert' file to be converted
1901 'diffexpr' original file
1902 'patchexpr' original file
1903 'printexpr' file to be printed
Bram Moolenaar2c7a29c2005-12-12 22:02:31 +00001904 And set to the swap file name for |SwapExists|.
Bram Moolenaar071d4272004-06-13 20:20:40 +00001905
1906 *v:fname_out* *fname_out-variable*
1907v:fname_out The name of the output file. Only valid while
1908 evaluating:
1909 option used for ~
1910 'charconvert' resulting converted file (*)
1911 'diffexpr' output of diff
1912 'patchexpr' resulting patched file
1913 (*) When doing conversion for a write command (e.g., ":w
Bram Moolenaar58b85342016-08-14 19:54:54 +02001914 file") it will be equal to v:fname_in. When doing conversion
Bram Moolenaar071d4272004-06-13 20:20:40 +00001915 for a read command (e.g., ":e file") it will be a temporary
1916 file and different from v:fname_in.
1917
1918 *v:fname_new* *fname_new-variable*
1919v:fname_new The name of the new version of the file. Only valid while
1920 evaluating 'diffexpr'.
1921
1922 *v:fname_diff* *fname_diff-variable*
1923v:fname_diff The name of the diff (patch) file. Only valid while
1924 evaluating 'patchexpr'.
1925
1926 *v:folddashes* *folddashes-variable*
1927v:folddashes Used for 'foldtext': dashes representing foldlevel of a closed
1928 fold.
Bram Moolenaar7b0294c2004-10-11 10:16:09 +00001929 Read-only in the |sandbox|. |fold-foldtext|
Bram Moolenaar071d4272004-06-13 20:20:40 +00001930
1931 *v:foldlevel* *foldlevel-variable*
1932v:foldlevel Used for 'foldtext': foldlevel of closed fold.
Bram Moolenaar7b0294c2004-10-11 10:16:09 +00001933 Read-only in the |sandbox|. |fold-foldtext|
Bram Moolenaar071d4272004-06-13 20:20:40 +00001934
1935 *v:foldend* *foldend-variable*
1936v:foldend Used for 'foldtext': last line of closed fold.
Bram Moolenaar7b0294c2004-10-11 10:16:09 +00001937 Read-only in the |sandbox|. |fold-foldtext|
Bram Moolenaar071d4272004-06-13 20:20:40 +00001938
1939 *v:foldstart* *foldstart-variable*
1940v:foldstart Used for 'foldtext': first line of closed fold.
Bram Moolenaar7b0294c2004-10-11 10:16:09 +00001941 Read-only in the |sandbox|. |fold-foldtext|
Bram Moolenaar071d4272004-06-13 20:20:40 +00001942
Bram Moolenaar817a8802013-11-09 01:44:43 +01001943 *v:hlsearch* *hlsearch-variable*
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01001944v:hlsearch Variable that indicates whether search highlighting is on.
Bram Moolenaar76440e22014-11-27 19:14:49 +01001945 Setting it makes sense only if 'hlsearch' is enabled which
1946 requires |+extra_search|. Setting this variable to zero acts
Bram Moolenaar705ada12016-01-24 17:56:50 +01001947 like the |:nohlsearch| command, setting it to one acts like >
Bram Moolenaar817a8802013-11-09 01:44:43 +01001948 let &hlsearch = &hlsearch
Bram Moolenaar86ae7202015-07-10 19:31:35 +02001949< Note that the value is restored when returning from a
1950 function. |function-search-undo|.
1951
Bram Moolenaar843ee412004-06-30 16:16:41 +00001952 *v:insertmode* *insertmode-variable*
1953v:insertmode Used for the |InsertEnter| and |InsertChange| autocommand
1954 events. Values:
1955 i Insert mode
1956 r Replace mode
1957 v Virtual Replace mode
1958
Bram Moolenaar2fda12f2005-01-15 22:14:15 +00001959 *v:key* *key-variable*
Bram Moolenaar32466aa2006-02-24 23:53:04 +00001960v:key Key of the current item of a |Dictionary|. Only valid while
Bram Moolenaar2fda12f2005-01-15 22:14:15 +00001961 evaluating the expression used with |map()| and |filter()|.
1962 Read-only.
1963
Bram Moolenaar071d4272004-06-13 20:20:40 +00001964 *v:lang* *lang-variable*
1965v:lang The current locale setting for messages of the runtime
1966 environment. This allows Vim scripts to be aware of the
1967 current language. Technical: it's the value of LC_MESSAGES.
1968 The value is system dependent.
1969 This variable can not be set directly, use the |:language|
1970 command.
1971 It can be different from |v:ctype| when messages are desired
1972 in a different language than what is used for character
1973 encoding. See |multi-lang|.
1974
1975 *v:lc_time* *lc_time-variable*
1976v:lc_time The current locale setting for time messages of the runtime
1977 environment. This allows Vim scripts to be aware of the
1978 current language. Technical: it's the value of LC_TIME.
1979 This variable can not be set directly, use the |:language|
1980 command. See |multi-lang|.
1981
1982 *v:lnum* *lnum-variable*
Bram Moolenaar368373e2010-07-19 20:46:22 +02001983v:lnum Line number for the 'foldexpr' |fold-expr|, 'formatexpr' and
1984 'indentexpr' expressions, tab page number for 'guitablabel'
1985 and 'guitabtooltip'. Only valid while one of these
1986 expressions is being evaluated. Read-only when in the
1987 |sandbox|.
Bram Moolenaar071d4272004-06-13 20:20:40 +00001988
Bram Moolenaar219b8702006-11-01 14:32:36 +00001989 *v:mouse_win* *mouse_win-variable*
1990v:mouse_win Window number for a mouse click obtained with |getchar()|.
1991 First window has number 1, like with |winnr()|. The value is
1992 zero when there was no mouse button click.
1993
Bram Moolenaar511972d2016-06-04 18:09:59 +02001994 *v:mouse_winid* *mouse_winid-variable*
1995v:mouse_winid Window ID for a mouse click obtained with |getchar()|.
1996 The value is zero when there was no mouse button click.
1997
Bram Moolenaar219b8702006-11-01 14:32:36 +00001998 *v:mouse_lnum* *mouse_lnum-variable*
1999v:mouse_lnum Line number for a mouse click obtained with |getchar()|.
2000 This is the text line number, not the screen line number. The
2001 value is zero when there was no mouse button click.
2002
2003 *v:mouse_col* *mouse_col-variable*
2004v:mouse_col Column number for a mouse click obtained with |getchar()|.
2005 This is the screen column number, like with |virtcol()|. The
2006 value is zero when there was no mouse button click.
2007
Bram Moolenaard09091d2019-01-17 16:07:22 +01002008 *v:none* *none-variable* *None*
Bram Moolenaar520e1e42016-01-23 19:46:28 +01002009v:none An empty String. Used to put an empty item in JSON. See
Bram Moolenaar6463ca22016-02-13 17:04:46 +01002010 |json_encode()|.
Bram Moolenaar2547aa92020-07-26 17:00:44 +02002011 This can also be used as a function argument to use the
2012 default value, see |none-function_argument|.
Bram Moolenaar705ada12016-01-24 17:56:50 +01002013 When used as a number this evaluates to zero.
Bram Moolenaarc95a3022016-06-12 23:01:46 +02002014 When used as a string this evaluates to "v:none". >
Bram Moolenaar705ada12016-01-24 17:56:50 +01002015 echo v:none
Bram Moolenaarc95a3022016-06-12 23:01:46 +02002016< v:none ~
2017 That is so that eval() can parse the string back to the same
Bram Moolenaardf48fb42016-07-22 21:50:18 +02002018 value. Read-only.
Bram Moolenaar520e1e42016-01-23 19:46:28 +01002019
2020 *v:null* *null-variable*
2021v:null An empty String. Used to put "null" in JSON. See
Bram Moolenaar6463ca22016-02-13 17:04:46 +01002022 |json_encode()|.
Bram Moolenaar705ada12016-01-24 17:56:50 +01002023 When used as a number this evaluates to zero.
Bram Moolenaarc95a3022016-06-12 23:01:46 +02002024 When used as a string this evaluates to "v:null". >
Bram Moolenaar705ada12016-01-24 17:56:50 +01002025 echo v:null
Bram Moolenaarc95a3022016-06-12 23:01:46 +02002026< v:null ~
2027 That is so that eval() can parse the string back to the same
Bram Moolenaardf48fb42016-07-22 21:50:18 +02002028 value. Read-only.
Bram Moolenaar520e1e42016-01-23 19:46:28 +01002029
Bram Moolenaarf9706e92020-02-22 14:27:04 +01002030 *v:numbersize* *numbersize-variable*
2031v:numbersize Number of bits in a Number. This is normally 64, but on some
Bram Moolenaarbc93ceb2020-02-26 13:36:21 +01002032 systems it may be 32.
Bram Moolenaarf9706e92020-02-22 14:27:04 +01002033
Bram Moolenaard812df62008-11-09 12:46:09 +00002034 *v:oldfiles* *oldfiles-variable*
2035v:oldfiles List of file names that is loaded from the |viminfo| file on
2036 startup. These are the files that Vim remembers marks for.
2037 The length of the List is limited by the ' argument of the
2038 'viminfo' option (default is 100).
Bram Moolenaar8d043172014-01-23 14:24:41 +01002039 When the |viminfo| file is not used the List is empty.
Bram Moolenaard812df62008-11-09 12:46:09 +00002040 Also see |:oldfiles| and |c_#<|.
2041 The List can be modified, but this has no effect on what is
2042 stored in the |viminfo| file later. If you use values other
2043 than String this will cause trouble.
Bram Moolenaardb84e452010-08-15 13:50:43 +02002044 {only when compiled with the |+viminfo| feature}
Bram Moolenaard812df62008-11-09 12:46:09 +00002045
Bram Moolenaar53744302015-07-17 17:38:22 +02002046 *v:option_new*
2047v:option_new New value of the option. Valid while executing an |OptionSet|
2048 autocommand.
2049 *v:option_old*
2050v:option_old Old value of the option. Valid while executing an |OptionSet|
Bram Moolenaard7c96872019-06-15 17:12:48 +02002051 autocommand. Depending on the command used for setting and the
2052 kind of option this is either the local old value or the
2053 global old value.
2054 *v:option_oldlocal*
2055v:option_oldlocal
2056 Old local value of the option. Valid while executing an
2057 |OptionSet| autocommand.
2058 *v:option_oldglobal*
2059v:option_oldglobal
2060 Old global value of the option. Valid while executing an
2061 |OptionSet| autocommand.
Bram Moolenaar53744302015-07-17 17:38:22 +02002062 *v:option_type*
2063v:option_type Scope of the set command. Valid while executing an
2064 |OptionSet| autocommand. Can be either "global" or "local"
Bram Moolenaard7c96872019-06-15 17:12:48 +02002065 *v:option_command*
2066v:option_command
2067 Command used to set the option. Valid while executing an
2068 |OptionSet| autocommand.
2069 value option was set via ~
2070 "setlocal" |:setlocal| or ":let l:xxx"
2071 "setglobal" |:setglobal| or ":let g:xxx"
2072 "set" |:set| or |:let|
2073 "modeline" |modeline|
Bram Moolenaar8af1fbf2008-01-05 12:35:21 +00002074 *v:operator* *operator-variable*
2075v:operator The last operator given in Normal mode. This is a single
2076 character except for commands starting with <g> or <z>,
2077 in which case it is two characters. Best used alongside
2078 |v:prevcount| and |v:register|. Useful if you want to cancel
2079 Operator-pending mode and then use the operator, e.g.: >
2080 :omap O <Esc>:call MyMotion(v:operator)<CR>
2081< The value remains set until another operator is entered, thus
2082 don't expect it to be empty.
2083 v:operator is not set for |:delete|, |:yank| or other Ex
2084 commands.
2085 Read-only.
2086
Bram Moolenaar071d4272004-06-13 20:20:40 +00002087 *v:prevcount* *prevcount-variable*
2088v:prevcount The count given for the last but one Normal mode command.
2089 This is the v:count value of the previous command. Useful if
Bram Moolenaar8af1fbf2008-01-05 12:35:21 +00002090 you want to cancel Visual or Operator-pending mode and then
2091 use the count, e.g.: >
Bram Moolenaar071d4272004-06-13 20:20:40 +00002092 :vmap % <Esc>:call MyFilter(v:prevcount)<CR>
2093< Read-only.
2094
Bram Moolenaar05159a02005-02-26 23:04:13 +00002095 *v:profiling* *profiling-variable*
Bram Moolenaar58b85342016-08-14 19:54:54 +02002096v:profiling Normally zero. Set to one after using ":profile start".
Bram Moolenaar05159a02005-02-26 23:04:13 +00002097 See |profiling|.
2098
Bram Moolenaar071d4272004-06-13 20:20:40 +00002099 *v:progname* *progname-variable*
2100v:progname Contains the name (with path removed) with which Vim was
Bram Moolenaard38b0552012-04-25 19:07:41 +02002101 invoked. Allows you to do special initialisations for |view|,
2102 |evim| etc., or any other name you might symlink to Vim.
Bram Moolenaar071d4272004-06-13 20:20:40 +00002103 Read-only.
2104
Bram Moolenaara1706c92014-04-01 19:55:49 +02002105 *v:progpath* *progpath-variable*
Bram Moolenaar56c860c2019-08-17 20:09:31 +02002106v:progpath Contains the command with which Vim was invoked, in a form
2107 that when passed to the shell will run the same Vim executable
2108 as the current one (if $PATH remains unchanged).
2109 Useful if you want to message a Vim server using a
Bram Moolenaara1706c92014-04-01 19:55:49 +02002110 |--remote-expr|.
Bram Moolenaarc7f02552014-04-01 21:00:59 +02002111 To get the full path use: >
2112 echo exepath(v:progpath)
Bram Moolenaar56c860c2019-08-17 20:09:31 +02002113< If the command has a relative path it will be expanded to the
2114 full path, so that it still works after `:cd`. Thus starting
2115 "./vim" results in "/home/user/path/to/vim/src/vim".
2116 On Linux and other systems it will always be the full path.
2117 On Mac it may just be "vim" and using exepath() as mentioned
2118 above should be used to get the full path.
Bram Moolenaar08cab962017-03-04 14:37:18 +01002119 On MS-Windows the executable may be called "vim.exe", but the
2120 ".exe" is not added to v:progpath.
Bram Moolenaara1706c92014-04-01 19:55:49 +02002121 Read-only.
2122
Bram Moolenaar071d4272004-06-13 20:20:40 +00002123 *v:register* *register-variable*
Bram Moolenaard58e9292011-02-09 17:07:58 +01002124v:register The name of the register in effect for the current normal mode
Bram Moolenaard38b0552012-04-25 19:07:41 +02002125 command (regardless of whether that command actually used a
2126 register). Or for the currently executing normal mode mapping
2127 (use this in custom commands that take a register).
2128 If none is supplied it is the default register '"', unless
2129 'clipboard' contains "unnamed" or "unnamedplus", then it is
2130 '*' or '+'.
Bram Moolenaard58e9292011-02-09 17:07:58 +01002131 Also see |getreg()| and |setreg()|
Bram Moolenaar071d4272004-06-13 20:20:40 +00002132
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00002133 *v:scrollstart* *scrollstart-variable*
2134v:scrollstart String describing the script or function that caused the
2135 screen to scroll up. It's only set when it is empty, thus the
2136 first reason is remembered. It is set to "Unknown" for a
2137 typed command.
2138 This can be used to find out why your script causes the
2139 hit-enter prompt.
2140
Bram Moolenaar071d4272004-06-13 20:20:40 +00002141 *v:servername* *servername-variable*
Bram Moolenaarc2ce52c2017-08-01 18:35:38 +02002142v:servername The resulting registered |client-server-name| if any.
Bram Moolenaar071d4272004-06-13 20:20:40 +00002143 Read-only.
2144
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01002145
Bram Moolenaar446cb832008-06-24 21:56:24 +00002146v:searchforward *v:searchforward* *searchforward-variable*
2147 Search direction: 1 after a forward search, 0 after a
2148 backward search. It is reset to forward when directly setting
2149 the last search pattern, see |quote/|.
2150 Note that the value is restored when returning from a
2151 function. |function-search-undo|.
2152 Read-write.
2153
Bram Moolenaar071d4272004-06-13 20:20:40 +00002154 *v:shell_error* *shell_error-variable*
2155v:shell_error Result of the last shell command. When non-zero, the last
2156 shell command had an error. When zero, there was no problem.
2157 This only works when the shell returns the error code to Vim.
2158 The value -1 is often used when the command could not be
2159 executed. Read-only.
2160 Example: >
2161 :!mv foo bar
2162 :if v:shell_error
2163 : echo 'could not rename "foo" to "bar"!'
2164 :endif
Bram Moolenaard2e716e2019-04-20 14:39:52 +02002165< "shell_error" also works, for backwards compatibility, unless
2166 |scriptversion| is 3 or higher.
Bram Moolenaar071d4272004-06-13 20:20:40 +00002167
2168 *v:statusmsg* *statusmsg-variable*
2169v:statusmsg Last given status message. It's allowed to set this variable.
2170
Bram Moolenaar4e330bb2005-12-07 21:04:31 +00002171 *v:swapname* *swapname-variable*
2172v:swapname Only valid when executing |SwapExists| autocommands: Name of
2173 the swap file found. Read-only.
2174
2175 *v:swapchoice* *swapchoice-variable*
2176v:swapchoice |SwapExists| autocommands can set this to the selected choice
2177 for handling an existing swap file:
2178 'o' Open read-only
2179 'e' Edit anyway
2180 'r' Recover
2181 'd' Delete swapfile
2182 'q' Quit
2183 'a' Abort
Bram Moolenaar58b85342016-08-14 19:54:54 +02002184 The value should be a single-character string. An empty value
Bram Moolenaar4e330bb2005-12-07 21:04:31 +00002185 results in the user being asked, as would happen when there is
2186 no SwapExists autocommand. The default is empty.
2187
Bram Moolenaarb3480382005-12-11 21:33:32 +00002188 *v:swapcommand* *swapcommand-variable*
Bram Moolenaar4770d092006-01-12 23:22:24 +00002189v:swapcommand Normal mode command to be executed after a file has been
Bram Moolenaarb3480382005-12-11 21:33:32 +00002190 opened. Can be used for a |SwapExists| autocommand to have
Bram Moolenaar58b85342016-08-14 19:54:54 +02002191 another Vim open the file and jump to the right place. For
Bram Moolenaarb3480382005-12-11 21:33:32 +00002192 example, when jumping to a tag the value is ":tag tagname\r".
Bram Moolenaar1f35bf92006-03-07 22:38:47 +00002193 For ":edit +cmd file" the value is ":cmd\r".
Bram Moolenaarb3480382005-12-11 21:33:32 +00002194
Bram Moolenaard823fa92016-08-12 16:29:27 +02002195 *v:t_TYPE* *v:t_bool* *t_bool-variable*
Bram Moolenaard09091d2019-01-17 16:07:22 +01002196v:t_bool Value of |Boolean| type. Read-only. See: |type()|
Bram Moolenaard823fa92016-08-12 16:29:27 +02002197 *v:t_channel* *t_channel-variable*
Bram Moolenaard09091d2019-01-17 16:07:22 +01002198v:t_channel Value of |Channel| type. Read-only. See: |type()|
Bram Moolenaard823fa92016-08-12 16:29:27 +02002199 *v:t_dict* *t_dict-variable*
Bram Moolenaard09091d2019-01-17 16:07:22 +01002200v:t_dict Value of |Dictionary| type. Read-only. See: |type()|
Bram Moolenaard823fa92016-08-12 16:29:27 +02002201 *v:t_float* *t_float-variable*
Bram Moolenaard09091d2019-01-17 16:07:22 +01002202v:t_float Value of |Float| type. Read-only. See: |type()|
Bram Moolenaard823fa92016-08-12 16:29:27 +02002203 *v:t_func* *t_func-variable*
Bram Moolenaard09091d2019-01-17 16:07:22 +01002204v:t_func Value of |Funcref| type. Read-only. See: |type()|
Bram Moolenaard823fa92016-08-12 16:29:27 +02002205 *v:t_job* *t_job-variable*
Bram Moolenaard09091d2019-01-17 16:07:22 +01002206v:t_job Value of |Job| type. Read-only. See: |type()|
Bram Moolenaard823fa92016-08-12 16:29:27 +02002207 *v:t_list* *t_list-variable*
Bram Moolenaard09091d2019-01-17 16:07:22 +01002208v:t_list Value of |List| type. Read-only. See: |type()|
Bram Moolenaard823fa92016-08-12 16:29:27 +02002209 *v:t_none* *t_none-variable*
Bram Moolenaard09091d2019-01-17 16:07:22 +01002210v:t_none Value of |None| type. Read-only. See: |type()|
Bram Moolenaard823fa92016-08-12 16:29:27 +02002211 *v:t_number* *t_number-variable*
Bram Moolenaard09091d2019-01-17 16:07:22 +01002212v:t_number Value of |Number| type. Read-only. See: |type()|
Bram Moolenaard823fa92016-08-12 16:29:27 +02002213 *v:t_string* *t_string-variable*
Bram Moolenaard09091d2019-01-17 16:07:22 +01002214v:t_string Value of |String| type. Read-only. See: |type()|
Bram Moolenaar6e5ea8d2019-01-12 22:47:31 +01002215 *v:t_blob* *t_blob-variable*
Bram Moolenaard09091d2019-01-17 16:07:22 +01002216v:t_blob Value of |Blob| type. Read-only. See: |type()|
Bram Moolenaarf562e722016-07-19 17:25:25 +02002217
Bram Moolenaar071d4272004-06-13 20:20:40 +00002218 *v:termresponse* *termresponse-variable*
2219v:termresponse The escape sequence returned by the terminal for the |t_RV|
Bram Moolenaar58b85342016-08-14 19:54:54 +02002220 termcap entry. It is set when Vim receives an escape sequence
Bram Moolenaarb4230122019-05-30 18:40:53 +02002221 that starts with ESC [ or CSI, then '>' or '?' and ends in a
2222 'c', with only digits and ';' in between.
Bram Moolenaar071d4272004-06-13 20:20:40 +00002223 When this option is set, the TermResponse autocommand event is
2224 fired, so that you can react to the response from the
Bram Moolenaar0c0eddd2020-06-13 15:47:25 +02002225 terminal. You can use |terminalprops()| to see what Vim
2226 figured out about the terminal.
Bram Moolenaarb4230122019-05-30 18:40:53 +02002227 The response from a new xterm is: "<Esc>[> Pp ; Pv ; Pc c". Pp
Bram Moolenaar071d4272004-06-13 20:20:40 +00002228 is the terminal type: 0 for vt100 and 1 for vt220. Pv is the
2229 patch level (since this was introduced in patch 95, it's
2230 always 95 or bigger). Pc is always zero.
2231 {only when compiled with |+termresponse| feature}
2232
Bram Moolenaarf3af54e2017-08-30 14:53:06 +02002233 *v:termblinkresp*
2234v:termblinkresp The escape sequence returned by the terminal for the |t_RC|
2235 termcap entry. This is used to find out whether the terminal
2236 cursor is blinking. This is used by |term_getcursor()|.
2237
2238 *v:termstyleresp*
2239v:termstyleresp The escape sequence returned by the terminal for the |t_RS|
2240 termcap entry. This is used to find out what the shape of the
2241 cursor is. This is used by |term_getcursor()|.
2242
Bram Moolenaar65e4c4f2017-10-14 23:24:25 +02002243 *v:termrbgresp*
2244v:termrbgresp The escape sequence returned by the terminal for the |t_RB|
Bram Moolenaarf3af54e2017-08-30 14:53:06 +02002245 termcap entry. This is used to find out what the terminal
2246 background color is, see 'background'.
2247
Bram Moolenaar65e4c4f2017-10-14 23:24:25 +02002248 *v:termrfgresp*
2249v:termrfgresp The escape sequence returned by the terminal for the |t_RF|
2250 termcap entry. This is used to find out what the terminal
2251 foreground color is.
2252
Bram Moolenaarf3af54e2017-08-30 14:53:06 +02002253 *v:termu7resp*
2254v:termu7resp The escape sequence returned by the terminal for the |t_u7|
2255 termcap entry. This is used to find out what the terminal
2256 does with ambiguous width characters, see 'ambiwidth'.
2257
Bram Moolenaarebf7dfa2016-04-14 12:46:51 +02002258 *v:testing* *testing-variable*
Bram Moolenaar8e8df252016-05-25 21:23:21 +02002259v:testing Must be set before using `test_garbagecollect_now()`.
Bram Moolenaar036986f2017-03-16 17:41:02 +01002260 Also, when set certain error messages won't be shown for 2
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01002261 seconds. (e.g. "'dictionary' option is empty")
Bram Moolenaarebf7dfa2016-04-14 12:46:51 +02002262
Bram Moolenaar071d4272004-06-13 20:20:40 +00002263 *v:this_session* *this_session-variable*
2264v:this_session Full filename of the last loaded or saved session file. See
2265 |:mksession|. It is allowed to set this variable. When no
2266 session file has been saved, this variable is empty.
Bram Moolenaard2e716e2019-04-20 14:39:52 +02002267 "this_session" also works, for backwards compatibility, unless
2268 |scriptversion| is 3 or higher
Bram Moolenaar071d4272004-06-13 20:20:40 +00002269
2270 *v:throwpoint* *throwpoint-variable*
2271v:throwpoint The point where the exception most recently caught and not
Bram Moolenaar58b85342016-08-14 19:54:54 +02002272 finished was thrown. Not set when commands are typed. See
Bram Moolenaar071d4272004-06-13 20:20:40 +00002273 also |v:exception| and |throw-variables|.
2274 Example: >
2275 :try
2276 : throw "oops"
2277 :catch /.*/
2278 : echo "Exception from" v:throwpoint
2279 :endtry
2280< Output: "Exception from test.vim, line 2"
2281
Bram Moolenaar520e1e42016-01-23 19:46:28 +01002282 *v:true* *true-variable*
2283v:true A Number with value one. Used to put "true" in JSON. See
Bram Moolenaar6463ca22016-02-13 17:04:46 +01002284 |json_encode()|.
Bram Moolenaarc95a3022016-06-12 23:01:46 +02002285 When used as a string this evaluates to "v:true". >
Bram Moolenaar705ada12016-01-24 17:56:50 +01002286 echo v:true
Bram Moolenaarc95a3022016-06-12 23:01:46 +02002287< v:true ~
2288 That is so that eval() can parse the string back to the same
Bram Moolenaardf48fb42016-07-22 21:50:18 +02002289 value. Read-only.
Bram Moolenaar2fda12f2005-01-15 22:14:15 +00002290 *v:val* *val-variable*
Bram Moolenaar58b85342016-08-14 19:54:54 +02002291v:val Value of the current item of a |List| or |Dictionary|. Only
Bram Moolenaar32466aa2006-02-24 23:53:04 +00002292 valid while evaluating the expression used with |map()| and
Bram Moolenaar2fda12f2005-01-15 22:14:15 +00002293 |filter()|. Read-only.
2294
Bram Moolenaar071d4272004-06-13 20:20:40 +00002295 *v:version* *version-variable*
2296v:version Version number of Vim: Major version number times 100 plus
Bram Moolenaar9b283522019-06-17 22:19:33 +02002297 minor version number. Version 5.0 is 500. Version 5.1
Bram Moolenaar071d4272004-06-13 20:20:40 +00002298 is 501. Read-only. "version" also works, for backwards
Bram Moolenaard2e716e2019-04-20 14:39:52 +02002299 compatibility, unless |scriptversion| is 3 or higher.
Bram Moolenaar071d4272004-06-13 20:20:40 +00002300 Use |has()| to check if a certain patch was included, e.g.: >
Bram Moolenaar6716d9a2014-04-02 12:12:08 +02002301 if has("patch-7.4.123")
Bram Moolenaar071d4272004-06-13 20:20:40 +00002302< Note that patch numbers are specific to the version, thus both
2303 version 5.0 and 5.1 may have a patch 123, but these are
2304 completely different.
2305
Bram Moolenaar37df9a42019-06-14 14:39:51 +02002306 *v:versionlong* *versionlong-variable*
Bram Moolenaar9b283522019-06-17 22:19:33 +02002307v:versionlong Like v:version, but also including the patchlevel in the last
2308 four digits. Version 8.1 with patch 123 has value 8010123.
2309 This can be used like this: >
2310 if v:versionlong >= 8010123
Bram Moolenaar37df9a42019-06-14 14:39:51 +02002311< However, if there are gaps in the list of patches included
2312 this will not work well. This can happen if a recent patch
2313 was included into an older version, e.g. for a security fix.
2314 Use the has() function to make sure the patch is actually
2315 included.
2316
Bram Moolenaar14735512016-03-26 21:00:08 +01002317 *v:vim_did_enter* *vim_did_enter-variable*
2318v:vim_did_enter Zero until most of startup is done. It is set to one just
2319 before |VimEnter| autocommands are triggered.
2320
Bram Moolenaar071d4272004-06-13 20:20:40 +00002321 *v:warningmsg* *warningmsg-variable*
2322v:warningmsg Last given warning message. It's allowed to set this variable.
2323
Bram Moolenaar727c8762010-10-20 19:17:48 +02002324 *v:windowid* *windowid-variable*
2325v:windowid When any X11 based GUI is running or when running in a
2326 terminal and Vim connects to the X server (|-X|) this will be
Bram Moolenaar264e9fd2010-10-27 12:33:17 +02002327 set to the window ID.
2328 When an MS-Windows GUI is running this will be set to the
2329 window handle.
2330 Otherwise the value is zero.
Bram Moolenaar7571d552016-08-18 22:54:46 +02002331 Note: for windows inside Vim use |winnr()| or |win_getid()|,
2332 see |window-ID|.
Bram Moolenaar727c8762010-10-20 19:17:48 +02002333
Bram Moolenaar071d4272004-06-13 20:20:40 +00002334==============================================================================
23354. Builtin Functions *functions*
2336
2337See |function-list| for a list grouped by what the function is used for.
2338
Bram Moolenaar402d2fe2005-04-15 21:00:38 +00002339(Use CTRL-] on the function name to jump to the full explanation.)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002340
2341USAGE RESULT DESCRIPTION ~
2342
Bram Moolenaar81edd172016-04-14 13:51:37 +02002343abs({expr}) Float or Number absolute value of {expr}
2344acos({expr}) Float arc cosine of {expr}
Bram Moolenaard8968242019-01-15 22:51:57 +01002345add({object}, {item}) List/Blob append {item} to {object}
Bram Moolenaara06ecab2016-07-16 14:47:36 +02002346and({expr}, {expr}) Number bitwise AND
Bram Moolenaar95bafa22018-10-02 13:26:25 +02002347append({lnum}, {text}) Number append {text} below line {lnum}
2348appendbufline({expr}, {lnum}, {text})
2349 Number append {text} below line {lnum}
2350 in buffer {expr}
Bram Moolenaarf0d58ef2018-11-16 16:13:44 +01002351argc([{winid}]) Number number of files in the argument list
Bram Moolenaard7ee7ce2005-01-03 21:02:03 +00002352argidx() Number current index in the argument list
Bram Moolenaar81edd172016-04-14 13:51:37 +02002353arglistid([{winnr} [, {tabnr}]]) Number argument list id
Bram Moolenaare6e39892018-10-25 12:32:11 +02002354argv({nr} [, {winid}]) String {nr} entry of the argument list
2355argv([-1, {winid}]) List the argument list
Bram Moolenaarfb517ba2020-06-03 19:55:35 +02002356asin({expr}) Float arc sine of {expr}
Bram Moolenaar65a54642018-04-28 16:56:53 +02002357assert_beeps({cmd}) Number assert {cmd} causes a beep
Bram Moolenaar42205552017-03-18 19:42:22 +01002358assert_equal({exp}, {act} [, {msg}])
Bram Moolenaar65a54642018-04-28 16:56:53 +02002359 Number assert {exp} is equal to {act}
Bram Moolenaarfb517ba2020-06-03 19:55:35 +02002360assert_equalfile({fname-one}, {fname-two} [, {msg}])
2361 Number assert file contents are equal
Bram Moolenaar42205552017-03-18 19:42:22 +01002362assert_exception({error} [, {msg}])
Bram Moolenaar65a54642018-04-28 16:56:53 +02002363 Number assert {error} is in v:exception
Bram Moolenaar1c6737b2020-09-07 22:18:52 +02002364assert_fails({cmd} [, {error} [, {msg} [, {lnum} [, {context}]]]])
Bram Moolenaar2c64ca12018-10-19 16:22:31 +02002365 Number assert {cmd} fails
Bram Moolenaar42205552017-03-18 19:42:22 +01002366assert_false({actual} [, {msg}])
Bram Moolenaar65a54642018-04-28 16:56:53 +02002367 Number assert {actual} is false
Bram Moolenaar61c04492016-07-23 15:35:35 +02002368assert_inrange({lower}, {upper}, {actual} [, {msg}])
Bram Moolenaar65a54642018-04-28 16:56:53 +02002369 Number assert {actual} is inside the range
Bram Moolenaar42205552017-03-18 19:42:22 +01002370assert_match({pat}, {text} [, {msg}])
Bram Moolenaar65a54642018-04-28 16:56:53 +02002371 Number assert {pat} matches {text}
Bram Moolenaar42205552017-03-18 19:42:22 +01002372assert_notequal({exp}, {act} [, {msg}])
Bram Moolenaar65a54642018-04-28 16:56:53 +02002373 Number assert {exp} is not equal {act}
Bram Moolenaar42205552017-03-18 19:42:22 +01002374assert_notmatch({pat}, {text} [, {msg}])
Bram Moolenaar65a54642018-04-28 16:56:53 +02002375 Number assert {pat} not matches {text}
2376assert_report({msg}) Number report a test failure
2377assert_true({actual} [, {msg}]) Number assert {actual} is true
Bram Moolenaar81edd172016-04-14 13:51:37 +02002378atan({expr}) Float arc tangent of {expr}
Bram Moolenaar04186092016-08-29 21:55:35 +02002379atan2({expr1}, {expr2}) Float arc tangent of {expr1} / {expr2}
Bram Moolenaarbe0a2592019-05-09 13:50:16 +02002380balloon_gettext() String current text in the balloon
Bram Moolenaar74240d32017-12-10 15:26:15 +01002381balloon_show({expr}) none show {expr} inside the balloon
Bram Moolenaar246fe032017-11-19 19:56:27 +01002382balloon_split({msg}) List split {msg} as used for a balloon
Bram Moolenaar81edd172016-04-14 13:51:37 +02002383browse({save}, {title}, {initdir}, {default})
Bram Moolenaar071d4272004-06-13 20:20:40 +00002384 String put up a file requester
Bram Moolenaar81edd172016-04-14 13:51:37 +02002385browsedir({title}, {initdir}) String put up a directory requester
Bram Moolenaar15e248e2019-06-30 20:21:37 +02002386bufadd({name}) Number add a buffer to the buffer list
Bram Moolenaare381d3d2016-07-07 14:50:41 +02002387bufexists({expr}) Number |TRUE| if buffer {expr} exists
2388buflisted({expr}) Number |TRUE| if buffer {expr} is listed
Bram Moolenaar15e248e2019-06-30 20:21:37 +02002389bufload({expr}) Number load buffer {expr} if not loaded yet
Bram Moolenaare381d3d2016-07-07 14:50:41 +02002390bufloaded({expr}) Number |TRUE| if buffer {expr} is loaded
Bram Moolenaara8eee212019-08-24 22:14:58 +02002391bufname([{expr}]) String Name of the buffer {expr}
2392bufnr([{expr} [, {create}]]) Number Number of the buffer {expr}
Bram Moolenaarb3619a92016-06-04 17:58:52 +02002393bufwinid({expr}) Number window ID of buffer {expr}
Bram Moolenaar81edd172016-04-14 13:51:37 +02002394bufwinnr({expr}) Number window number of buffer {expr}
2395byte2line({byte}) Number line number at byte count {byte}
2396byteidx({expr}, {nr}) Number byte index of {nr}'th char in {expr}
2397byteidxcomp({expr}, {nr}) Number byte index of {nr}'th char in {expr}
2398call({func}, {arglist} [, {dict}])
Bram Moolenaar2fda12f2005-01-15 22:14:15 +00002399 any call {func} with arguments {arglist}
Bram Moolenaar81edd172016-04-14 13:51:37 +02002400ceil({expr}) Float round {expr} up
Bram Moolenaar4b785f62016-11-29 21:54:44 +01002401ch_canread({handle}) Number check if there is something to read
Bram Moolenaar81edd172016-04-14 13:51:37 +02002402ch_close({handle}) none close {handle}
Bram Moolenaar0874a832016-09-01 15:11:51 +02002403ch_close_in({handle}) none close in part of {handle}
Bram Moolenaar81edd172016-04-14 13:51:37 +02002404ch_evalexpr({handle}, {expr} [, {options}])
Bram Moolenaar5f148ec2016-03-07 22:59:26 +01002405 any evaluate {expr} on JSON {handle}
Bram Moolenaar81edd172016-04-14 13:51:37 +02002406ch_evalraw({handle}, {string} [, {options}])
Bram Moolenaar5f148ec2016-03-07 22:59:26 +01002407 any evaluate {string} on raw {handle}
Bram Moolenaar81edd172016-04-14 13:51:37 +02002408ch_getbufnr({handle}, {what}) Number get buffer number for {handle}/{what}
2409ch_getjob({channel}) Job get the Job of {channel}
Bram Moolenaara06ecab2016-07-16 14:47:36 +02002410ch_info({handle}) String info about channel {handle}
Bram Moolenaar81edd172016-04-14 13:51:37 +02002411ch_log({msg} [, {handle}]) none write {msg} in the channel log file
2412ch_logfile({fname} [, {mode}]) none start logging channel activity
2413ch_open({address} [, {options}])
Bram Moolenaara06ecab2016-07-16 14:47:36 +02002414 Channel open a channel to {address}
2415ch_read({handle} [, {options}]) String read from {handle}
Bram Moolenaar6e5ea8d2019-01-12 22:47:31 +01002416ch_readblob({handle} [, {options}])
2417 Blob read Blob from {handle}
Bram Moolenaar81edd172016-04-14 13:51:37 +02002418ch_readraw({handle} [, {options}])
Bram Moolenaara06ecab2016-07-16 14:47:36 +02002419 String read raw from {handle}
Bram Moolenaar81edd172016-04-14 13:51:37 +02002420ch_sendexpr({handle}, {expr} [, {options}])
Bram Moolenaar5f148ec2016-03-07 22:59:26 +01002421 any send {expr} over JSON {handle}
Bram Moolenaar6e5ea8d2019-01-12 22:47:31 +01002422ch_sendraw({handle}, {expr} [, {options}])
2423 any send {expr} over raw {handle}
Bram Moolenaar81edd172016-04-14 13:51:37 +02002424ch_setoptions({handle}, {options})
2425 none set options for {handle}
Bram Moolenaar7ef38102016-09-26 22:36:58 +02002426ch_status({handle} [, {options}])
2427 String status of channel {handle}
Bram Moolenaar446cb832008-06-24 21:56:24 +00002428changenr() Number current change number
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01002429char2nr({expr} [, {utf8}]) Number ASCII/UTF8 value of first char in {expr}
Bram Moolenaar4e4473c2020-08-28 22:24:57 +02002430charclass({string}) Number character class of {string}
Bram Moolenaar1063f3d2019-05-07 22:06:52 +02002431chdir({dir}) String change current working directory
Bram Moolenaar81edd172016-04-14 13:51:37 +02002432cindent({lnum}) Number C indent for line {lnum}
Bram Moolenaaraff74912019-03-30 18:11:49 +01002433clearmatches([{win}]) none clear all matches
Bram Moolenaar81edd172016-04-14 13:51:37 +02002434col({expr}) Number column nr of cursor or mark
2435complete({startcol}, {matches}) none set Insert mode completion
2436complete_add({expr}) Number add completion match
Bram Moolenaar446cb832008-06-24 21:56:24 +00002437complete_check() Number check for key typed during completion
Bram Moolenaarfd133322019-03-29 12:20:27 +01002438complete_info([{what}]) Dict get current completion information
Bram Moolenaar81edd172016-04-14 13:51:37 +02002439confirm({msg} [, {choices} [, {default} [, {type}]]])
Bram Moolenaar071d4272004-06-13 20:20:40 +00002440 Number number of choice picked by user
Bram Moolenaar81edd172016-04-14 13:51:37 +02002441copy({expr}) any make a shallow copy of {expr}
2442cos({expr}) Float cosine of {expr}
2443cosh({expr}) Float hyperbolic cosine of {expr}
Bram Moolenaar95bafa22018-10-02 13:26:25 +02002444count({comp}, {expr} [, {ic} [, {start}]])
2445 Number count how many {expr} are in {comp}
Bram Moolenaardc1f1642016-08-16 18:33:43 +02002446cscope_connection([{num}, {dbpath} [, {prepend}]])
Bram Moolenaar071d4272004-06-13 20:20:40 +00002447 Number checks existence of cscope connection
Bram Moolenaar81edd172016-04-14 13:51:37 +02002448cursor({lnum}, {col} [, {off}])
Bram Moolenaar2f3b5102014-11-19 18:54:17 +01002449 Number move cursor to {lnum}, {col}, {off}
Bram Moolenaar81edd172016-04-14 13:51:37 +02002450cursor({list}) Number move cursor to position in {list}
Bram Moolenaar4551c0a2018-06-20 22:38:21 +02002451debugbreak({pid}) Number interrupt process being debugged
Bram Moolenaar81edd172016-04-14 13:51:37 +02002452deepcopy({expr} [, {noref}]) any make a full copy of {expr}
2453delete({fname} [, {flags}]) Number delete the file or directory {fname}
Bram Moolenaard473c8c2018-08-11 18:00:22 +02002454deletebufline({expr}, {first} [, {last}])
Bram Moolenaard79a2622018-06-07 18:17:46 +02002455 Number delete lines from buffer {expr}
Bram Moolenaare381d3d2016-07-07 14:50:41 +02002456did_filetype() Number |TRUE| if FileType autocmd event used
Bram Moolenaar81edd172016-04-14 13:51:37 +02002457diff_filler({lnum}) Number diff filler lines about {lnum}
2458diff_hlID({lnum}, {col}) Number diff highlighting at {lnum}/{col}
Bram Moolenaar4132eb52020-02-14 16:53:00 +01002459echoraw({expr}) none output {expr} as-is
Bram Moolenaare381d3d2016-07-07 14:50:41 +02002460empty({expr}) Number |TRUE| if {expr} is empty
Bram Moolenaar691ddee2019-05-09 14:52:41 +02002461environ() Dict return environment variables
Bram Moolenaar81edd172016-04-14 13:51:37 +02002462escape({string}, {chars}) String escape {chars} in {string} with '\'
2463eval({string}) any evaluate {string} into its value
Bram Moolenaare381d3d2016-07-07 14:50:41 +02002464eventhandler() Number |TRUE| if inside an event handler
Bram Moolenaar81edd172016-04-14 13:51:37 +02002465executable({expr}) Number 1 if executable {expr} exists
Bram Moolenaar79815f12016-07-09 17:07:29 +02002466execute({command}) String execute {command} and get the output
Bram Moolenaara06ecab2016-07-16 14:47:36 +02002467exepath({expr}) String full path of the command {expr}
Bram Moolenaare381d3d2016-07-07 14:50:41 +02002468exists({expr}) Number |TRUE| if {expr} exists
Bram Moolenaar81edd172016-04-14 13:51:37 +02002469exp({expr}) Float exponential of {expr}
2470expand({expr} [, {nosuf} [, {list}]])
Bram Moolenaar146e9c32012-03-07 19:18:23 +01002471 any expand special keywords in {expr}
Bram Moolenaar80dad482019-06-09 17:22:31 +02002472expandcmd({expr}) String expand {expr} like with `:edit`
Bram Moolenaarebacddb2020-06-04 15:22:21 +02002473extend({expr1}, {expr2} [, {expr3}])
2474 List/Dict insert items of {expr2} into {expr1}
Bram Moolenaar81edd172016-04-14 13:51:37 +02002475feedkeys({string} [, {mode}]) Number add key sequence to typeahead buffer
Bram Moolenaare381d3d2016-07-07 14:50:41 +02002476filereadable({file}) Number |TRUE| if {file} is a readable file
2477filewritable({file}) Number |TRUE| if {file} is a writable file
Bram Moolenaar50ba5262016-09-22 22:33:02 +02002478filter({expr1}, {expr2}) List/Dict remove items from {expr1} where
2479 {expr2} is 0
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01002480finddir({name} [, {path} [, {count}]])
Bram Moolenaarc6fe9192006-04-09 21:54:49 +00002481 String find directory {name} in {path}
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01002482findfile({name} [, {path} [, {count}]])
Bram Moolenaarc6fe9192006-04-09 21:54:49 +00002483 String find file {name} in {path}
Bram Moolenaar077a1e62020-06-08 20:50:43 +02002484flatten({list} [, {maxdepth}]) List flatten {list} up to {maxdepth} levels
Bram Moolenaar81edd172016-04-14 13:51:37 +02002485float2nr({expr}) Number convert Float {expr} to a Number
2486floor({expr}) Float round {expr} down
2487fmod({expr1}, {expr2}) Float remainder of {expr1} / {expr2}
2488fnameescape({fname}) String escape special characters in {fname}
2489fnamemodify({fname}, {mods}) String modify file name
2490foldclosed({lnum}) Number first line of fold at {lnum} if closed
2491foldclosedend({lnum}) Number last line of fold at {lnum} if closed
2492foldlevel({lnum}) Number fold level at {lnum}
Bram Moolenaare0fa3742016-02-20 15:47:01 +01002493foldtext() String line displayed for closed fold
Bram Moolenaar81edd172016-04-14 13:51:37 +02002494foldtextresult({lnum}) String text for closed fold at {lnum}
Bram Moolenaare0fa3742016-02-20 15:47:01 +01002495foreground() Number bring the Vim window to the foreground
Bram Moolenaar437bafe2016-08-01 15:40:54 +02002496funcref({name} [, {arglist}] [, {dict}])
Bram Moolenaara06ecab2016-07-16 14:47:36 +02002497 Funcref reference to function {name}
Bram Moolenaar437bafe2016-08-01 15:40:54 +02002498function({name} [, {arglist}] [, {dict}])
2499 Funcref named reference to function {name}
Bram Moolenaar81edd172016-04-14 13:51:37 +02002500garbagecollect([{atexit}]) none free memory, breaking cyclic references
Bram Moolenaar81edd172016-04-14 13:51:37 +02002501get({list}, {idx} [, {def}]) any get item {idx} from {list} or {def}
2502get({dict}, {key} [, {def}]) any get item {key} from {dict} or {def}
Bram Moolenaar03e19a02016-05-24 22:29:49 +02002503get({func}, {what}) any get property of funcref/partial {func}
Bram Moolenaar50ba5262016-09-22 22:33:02 +02002504getbufinfo([{expr}]) List information about buffers
Bram Moolenaar81edd172016-04-14 13:51:37 +02002505getbufline({expr}, {lnum} [, {end}])
Bram Moolenaar45360022005-07-21 21:08:21 +00002506 List lines {lnum} to {end} of buffer {expr}
Bram Moolenaar81edd172016-04-14 13:51:37 +02002507getbufvar({expr}, {varname} [, {def}])
Bram Moolenaar63dbda12013-02-20 21:12:10 +01002508 any variable {varname} in buffer {expr}
Bram Moolenaar4c313b12019-08-24 22:58:31 +02002509getchangelist([{expr}]) List list of change list items
Bram Moolenaar81edd172016-04-14 13:51:37 +02002510getchar([expr]) Number get one character from the user
Bram Moolenaare0fa3742016-02-20 15:47:01 +01002511getcharmod() Number modifiers for the last typed character
Bram Moolenaarfc39ecf2015-08-11 20:34:49 +02002512getcharsearch() Dict last character search
Bram Moolenaar071d4272004-06-13 20:20:40 +00002513getcmdline() String return the current command-line
2514getcmdpos() Number return cursor position in command-line
Bram Moolenaarfb539272014-08-22 19:21:47 +02002515getcmdtype() String return current command-line type
2516getcmdwintype() String return current command-line window type
Bram Moolenaare9d58a62016-08-13 15:07:41 +02002517getcompletion({pat}, {type} [, {filtered}])
2518 List list of cmdline completion matches
Bram Moolenaar6f6c0f82014-05-28 20:31:42 +02002519getcurpos() List position of the cursor
Bram Moolenaar81edd172016-04-14 13:51:37 +02002520getcwd([{winnr} [, {tabnr}]]) String get the current working directory
Bram Moolenaar691ddee2019-05-09 14:52:41 +02002521getenv({name}) String return environment variable
Bram Moolenaar81edd172016-04-14 13:51:37 +02002522getfontname([{name}]) String name of font being used
2523getfperm({fname}) String file permissions of file {fname}
2524getfsize({fname}) Number size in bytes of file {fname}
2525getftime({fname}) Number last modification time of file
2526getftype({fname}) String description of type of file {fname}
Bram Moolenaara3a12462019-09-07 15:08:38 +02002527getimstatus() Number |TRUE| if the IME status is active
Bram Moolenaar4f505882018-02-10 21:06:32 +01002528getjumplist([{winnr} [, {tabnr}]])
2529 List list of jump list items
Bram Moolenaar81edd172016-04-14 13:51:37 +02002530getline({lnum}) String line {lnum} of current buffer
2531getline({lnum}, {end}) List lines {lnum} to {end} of current buffer
Bram Moolenaare46a4402020-06-30 20:38:27 +02002532getloclist({nr}) List list of location list items
2533getloclist({nr}, {what}) Dict get specific location list properties
Bram Moolenaarcfb4b472020-05-31 15:41:57 +02002534getmarklist([{expr}]) List list of global/local marks
Bram Moolenaaraff74912019-03-30 18:11:49 +01002535getmatches([{win}]) List list of current matches
Bram Moolenaardb3a2052019-11-16 18:22:41 +01002536getmousepos() Dict last known mouse position
Bram Moolenaar18081e32008-02-20 19:11:07 +00002537getpid() Number process ID of Vim
Bram Moolenaar81edd172016-04-14 13:51:37 +02002538getpos({expr}) List position of cursor, mark, etc.
Bram Moolenaare46a4402020-06-30 20:38:27 +02002539getqflist() List list of quickfix items
2540getqflist({what}) Dict get specific quickfix list properties
Bram Moolenaar81edd172016-04-14 13:51:37 +02002541getreg([{regname} [, 1 [, {list}]]])
Bram Moolenaarbb861e22020-06-07 18:16:36 +02002542 String or List contents of a register
2543getreginfo([{regname}]) Dict information about a register
2544getregtype([{regname}]) String type of a register
Bram Moolenaar50ba5262016-09-22 22:33:02 +02002545gettabinfo([{expr}]) List list of tab pages
Bram Moolenaar81edd172016-04-14 13:51:37 +02002546gettabvar({nr}, {varname} [, {def}])
Bram Moolenaar63dbda12013-02-20 21:12:10 +01002547 any variable {varname} in tab {nr} or {def}
Bram Moolenaar81edd172016-04-14 13:51:37 +02002548gettabwinvar({tabnr}, {winnr}, {name} [, {def}])
Bram Moolenaarc6249bb2006-04-15 20:25:09 +00002549 any {name} in {winnr} in tab page {tabnr}
Bram Moolenaarf49cc602018-11-11 15:21:05 +01002550gettagstack([{nr}]) Dict get the tag stack of window {nr}
Bram Moolenaar0b39c3f2020-08-30 15:52:10 +02002551gettext({text}) String lookup translation of {text}
Bram Moolenaar7132ddc2018-07-15 17:01:11 +02002552getwininfo([{winid}]) List list of info about each window
Bram Moolenaar98ef2332018-03-18 14:44:37 +01002553getwinpos([{timeout}]) List X and Y coord in pixels of the Vim window
Bram Moolenaar3f54fd32018-03-03 21:29:55 +01002554getwinposx() Number X coord in pixels of the Vim window
2555getwinposy() Number Y coord in pixels of the Vim window
Bram Moolenaar81edd172016-04-14 13:51:37 +02002556getwinvar({nr}, {varname} [, {def}])
Bram Moolenaar63dbda12013-02-20 21:12:10 +01002557 any variable {varname} in window {nr}
Bram Moolenaar81edd172016-04-14 13:51:37 +02002558glob({expr} [, {nosuf} [, {list} [, {alllinks}]]])
Bram Moolenaar146e9c32012-03-07 19:18:23 +01002559 any expand file wildcards in {expr}
Bram Moolenaara06ecab2016-07-16 14:47:36 +02002560glob2regpat({expr}) String convert a glob pat into a search pat
Bram Moolenaar81edd172016-04-14 13:51:37 +02002561globpath({path}, {expr} [, {nosuf} [, {list} [, {alllinks}]]])
Bram Moolenaarbb5ddda2008-11-28 10:01:10 +00002562 String do glob({expr}) for all dirs in {path}
Bram Moolenaar79296512020-03-22 16:17:14 +01002563has({feature} [, {check}]) Number |TRUE| if feature {feature} supported
Bram Moolenaare381d3d2016-07-07 14:50:41 +02002564has_key({dict}, {key}) Number |TRUE| if {dict} has entry {key}
Bram Moolenaar81edd172016-04-14 13:51:37 +02002565haslocaldir([{winnr} [, {tabnr}]])
Bram Moolenaare381d3d2016-07-07 14:50:41 +02002566 Number |TRUE| if the window executed |:lcd|
Bram Moolenaar00aa0692019-04-27 20:37:57 +02002567 or |:tcd|
Bram Moolenaar81edd172016-04-14 13:51:37 +02002568hasmapto({what} [, {mode} [, {abbr}]])
Bram Moolenaare381d3d2016-07-07 14:50:41 +02002569 Number |TRUE| if mapping to {what} exists
Bram Moolenaar8a7d6542020-01-26 15:56:19 +01002570histadd({history}, {item}) Number add an item to a history
2571histdel({history} [, {item}]) Number remove an item from a history
Bram Moolenaar81edd172016-04-14 13:51:37 +02002572histget({history} [, {index}]) String get the item {index} from a history
2573histnr({history}) Number highest index of a history
Bram Moolenaar81edd172016-04-14 13:51:37 +02002574hlID({name}) Number syntax ID of highlight group {name}
Bram Moolenaarebacddb2020-06-04 15:22:21 +02002575hlexists({name}) Number |TRUE| if highlight group {name} exists
Bram Moolenaar071d4272004-06-13 20:20:40 +00002576hostname() String name of the machine Vim is running on
Bram Moolenaar81edd172016-04-14 13:51:37 +02002577iconv({expr}, {from}, {to}) String convert encoding of {expr}
2578indent({lnum}) Number indent of line {lnum}
Bram Moolenaar6e5ea8d2019-01-12 22:47:31 +01002579index({object}, {expr} [, {start} [, {ic}]])
2580 Number index in {object} where {expr} appears
Bram Moolenaar81edd172016-04-14 13:51:37 +02002581input({prompt} [, {text} [, {completion}]])
Bram Moolenaarbfd8fc02005-09-20 23:22:24 +00002582 String get input from the user
Bram Moolenaarb6e0ec62017-07-23 22:12:20 +02002583inputdialog({prompt} [, {text} [, {completion}]])
Bram Moolenaara06ecab2016-07-16 14:47:36 +02002584 String like input() but in a GUI dialog
Bram Moolenaar81edd172016-04-14 13:51:37 +02002585inputlist({textlist}) Number let the user pick from a choice list
Bram Moolenaard7ee7ce2005-01-03 21:02:03 +00002586inputrestore() Number restore typeahead
2587inputsave() Number save and clear typeahead
Bram Moolenaara06ecab2016-07-16 14:47:36 +02002588inputsecret({prompt} [, {text}]) String like input() but hiding the text
Bram Moolenaar6e5ea8d2019-01-12 22:47:31 +01002589insert({object}, {item} [, {idx}]) List insert {item} in {object} [before {idx}]
Bram Moolenaar67a2deb2019-11-25 00:05:32 +01002590interrupt() none interrupt script execution
Bram Moolenaara06ecab2016-07-16 14:47:36 +02002591invert({expr}) Number bitwise invert
Bram Moolenaare381d3d2016-07-07 14:50:41 +02002592isdirectory({directory}) Number |TRUE| if {directory} is a directory
Bram Moolenaarfda1bff2019-04-04 13:44:37 +02002593isinf({expr}) Number determine if {expr} is infinity value
2594 (positive or negative)
Bram Moolenaare381d3d2016-07-07 14:50:41 +02002595islocked({expr}) Number |TRUE| if {expr} is locked
Bram Moolenaara06ecab2016-07-16 14:47:36 +02002596isnan({expr}) Number |TRUE| if {expr} is NaN
Bram Moolenaar81edd172016-04-14 13:51:37 +02002597items({dict}) List key-value pairs in {dict}
2598job_getchannel({job}) Channel get the channel handle for {job}
Bram Moolenaare1fc5152018-04-21 19:49:08 +02002599job_info([{job}]) Dict get information about {job}
Bram Moolenaar81edd172016-04-14 13:51:37 +02002600job_setoptions({job}, {options}) none set options for {job}
2601job_start({command} [, {options}])
Bram Moolenaara06ecab2016-07-16 14:47:36 +02002602 Job start a job
Bram Moolenaar81edd172016-04-14 13:51:37 +02002603job_status({job}) String get the status of {job}
2604job_stop({job} [, {how}]) Number stop {job}
2605join({list} [, {sep}]) String join {list} items into one String
2606js_decode({string}) any decode JS style JSON
2607js_encode({expr}) String encode JS style JSON
2608json_decode({string}) any decode JSON
2609json_encode({expr}) String encode JSON
2610keys({dict}) List keys in {dict}
2611len({expr}) Number the length of {expr}
2612libcall({lib}, {func}, {arg}) String call {func} in library {lib} with {arg}
Bram Moolenaara06ecab2016-07-16 14:47:36 +02002613libcallnr({lib}, {func}, {arg}) Number idem, but return a Number
Bram Moolenaara0d1fef2019-09-04 22:29:14 +02002614line({expr} [, {winid}]) Number line nr of cursor, last line or mark
Bram Moolenaar81edd172016-04-14 13:51:37 +02002615line2byte({lnum}) Number byte count of line {lnum}
2616lispindent({lnum}) Number Lisp indent for line {lnum}
Bram Moolenaar9d401282019-04-06 13:18:12 +02002617list2str({list} [, {utf8}]) String turn numbers in {list} into a String
Bram Moolenaara3347722019-05-11 21:14:24 +02002618listener_add({callback} [, {buf}])
2619 Number add a callback to listen to changes
Bram Moolenaarfe1ade02019-05-14 21:20:36 +02002620listener_flush([{buf}]) none invoke listener callbacks
Bram Moolenaara3347722019-05-11 21:14:24 +02002621listener_remove({id}) none remove a listener callback
Bram Moolenaar071d4272004-06-13 20:20:40 +00002622localtime() Number current time
Bram Moolenaar81edd172016-04-14 13:51:37 +02002623log({expr}) Float natural logarithm (base e) of {expr}
2624log10({expr}) Float logarithm of Float {expr} to base 10
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01002625luaeval({expr} [, {expr}]) any evaluate |Lua| expression
Bram Moolenaar50ba5262016-09-22 22:33:02 +02002626map({expr1}, {expr2}) List/Dict change each item in {expr1} to {expr}
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01002627maparg({name} [, {mode} [, {abbr} [, {dict}]]])
Bram Moolenaarf1568ec2011-12-14 21:17:39 +01002628 String or Dict
2629 rhs of mapping {name} in mode {mode}
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01002630mapcheck({name} [, {mode} [, {abbr}]])
Bram Moolenaar97b2ad32006-03-18 21:40:56 +00002631 String check for mappings matching {name}
Bram Moolenaar9c652532020-05-24 13:10:18 +02002632mapset({mode}, {abbr}, {dict})
Bram Moolenaar4c9243f2020-05-22 13:10:44 +02002633 none restore mapping from |maparg()| result
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01002634match({expr}, {pat} [, {start} [, {count}]])
Bram Moolenaar071d4272004-06-13 20:20:40 +00002635 Number position where {pat} matches in {expr}
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01002636matchadd({group}, {pattern} [, {priority} [, {id} [, {dict}]]])
Bram Moolenaar6ee10162007-07-26 20:58:42 +00002637 Number highlight {pattern} with {group}
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01002638matchaddpos({group}, {pos} [, {priority} [, {id} [, {dict}]]])
Bram Moolenaarb3414592014-06-17 17:48:32 +02002639 Number highlight positions with {group}
Bram Moolenaar81edd172016-04-14 13:51:37 +02002640matcharg({nr}) List arguments of |:match|
Bram Moolenaaraff74912019-03-30 18:11:49 +01002641matchdelete({id} [, {win}]) Number delete match identified by {id}
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01002642matchend({expr}, {pat} [, {start} [, {count}]])
Bram Moolenaar071d4272004-06-13 20:20:40 +00002643 Number position where {pat} ends in {expr}
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01002644matchlist({expr}, {pat} [, {start} [, {count}]])
Bram Moolenaar3a7c85b2005-02-05 21:39:53 +00002645 List match and submatches of {pat} in {expr}
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01002646matchstr({expr}, {pat} [, {start} [, {count}]])
Bram Moolenaar89cb5e02004-07-19 20:55:54 +00002647 String {count}'th match of {pat} in {expr}
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01002648matchstrpos({expr}, {pat} [, {start} [, {count}]])
Bram Moolenaar7fed5c12016-03-29 23:10:31 +02002649 List {count}'th match of {pat} in {expr}
Bram Moolenaar690afe12017-01-28 18:34:47 +01002650max({expr}) Number maximum value of items in {expr}
Bram Moolenaar0eabd4d2020-03-15 16:13:53 +01002651menu_info({name} [, {mode}]) Dict get menu item information
Bram Moolenaar690afe12017-01-28 18:34:47 +01002652min({expr}) Number minimum value of items in {expr}
Bram Moolenaar81edd172016-04-14 13:51:37 +02002653mkdir({name} [, {path} [, {prot}]])
Bram Moolenaar26a60b42005-02-22 08:49:11 +00002654 Number create directory {name}
Bram Moolenaar81edd172016-04-14 13:51:37 +02002655mode([expr]) String current editing mode
2656mzeval({expr}) any evaluate |MzScheme| expression
2657nextnonblank({lnum}) Number line nr of non-blank line >= {lnum}
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01002658nr2char({expr} [, {utf8}]) String single char with ASCII/UTF8 value {expr}
Bram Moolenaara06ecab2016-07-16 14:47:36 +02002659or({expr}, {expr}) Number bitwise OR
Bram Moolenaar81edd172016-04-14 13:51:37 +02002660pathshorten({expr}) String shorten directory names in a path
2661perleval({expr}) any evaluate |Perl| expression
Bram Moolenaar931a2772019-07-04 16:54:54 +02002662popup_atcursor({what}, {options}) Number create popup window near the cursor
Bram Moolenaar589edb32019-09-20 14:38:13 +02002663popup_beval({what}, {options}) Number create popup window for 'ballooneval'
Bram Moolenaar931a2772019-07-04 16:54:54 +02002664popup_clear() none close all popup windows
2665popup_close({id} [, {result}]) none close popup window {id}
2666popup_create({what}, {options}) Number create a popup window
2667popup_dialog({what}, {options}) Number create a popup window used as a dialog
2668popup_filter_menu({id}, {key}) Number filter for a menu popup window
2669popup_filter_yesno({id}, {key}) Number filter for a dialog popup window
Bram Moolenaare49fbff2019-08-21 22:50:07 +02002670popup_findinfo() Number get window ID of info popup window
2671popup_findpreview() Number get window ID of preview popup window
Bram Moolenaar931a2772019-07-04 16:54:54 +02002672popup_getoptions({id}) Dict get options of popup window {id}
2673popup_getpos({id}) Dict get position of popup window {id}
2674popup_hide({id}) none hide popup menu {id}
Bram Moolenaarebacddb2020-06-04 15:22:21 +02002675popup_list() List get a list of window IDs of all popups
Bram Moolenaaref6b9792020-05-13 16:34:15 +02002676popup_locate({row}, {col}) Number get window ID of popup at position
Bram Moolenaar931a2772019-07-04 16:54:54 +02002677popup_menu({what}, {options}) Number create a popup window used as a menu
2678popup_move({id}, {options}) none set position of popup window {id}
2679popup_notification({what}, {options})
2680 Number create a notification popup window
Bram Moolenaar931a2772019-07-04 16:54:54 +02002681popup_setoptions({id}, {options})
2682 none set options for popup window {id}
2683popup_settext({id}, {text}) none set the text of popup window {id}
Bram Moolenaarebacddb2020-06-04 15:22:21 +02002684popup_show({id}) none unhide popup window {id}
Bram Moolenaar81edd172016-04-14 13:51:37 +02002685pow({x}, {y}) Float {x} to the power of {y}
2686prevnonblank({lnum}) Number line nr of non-blank line <= {lnum}
2687printf({fmt}, {expr1}...) String format text
Bram Moolenaar077cc7a2020-09-04 16:35:35 +02002688prompt_getprompt({buf}) String get prompt text
Bram Moolenaarf2732452018-06-03 14:47:35 +02002689prompt_setcallback({buf}, {expr}) none set prompt callback function
Bram Moolenaar0e5979a2018-06-17 19:36:33 +02002690prompt_setinterrupt({buf}, {text}) none set prompt interrupt function
2691prompt_setprompt({buf}, {text}) none set prompt text
Bram Moolenaar98aefe72018-12-13 22:20:09 +01002692prop_add({lnum}, {col}, {props}) none add a text property
Bram Moolenaare3d31b02018-12-24 23:07:04 +01002693prop_clear({lnum} [, {lnum-end} [, {props}]])
Bram Moolenaar98aefe72018-12-13 22:20:09 +01002694 none remove all text properties
2695prop_find({props} [, {direction}])
2696 Dict search for a text property
Bram Moolenaar7ceefb32020-05-01 16:07:38 +02002697prop_list({lnum} [, {props}]) List text properties in {lnum}
Bram Moolenaarc8c88492018-12-27 23:59:26 +01002698prop_remove({props} [, {lnum} [, {lnum-end}]])
Bram Moolenaar98aefe72018-12-13 22:20:09 +01002699 Number remove a text property
2700prop_type_add({name}, {props}) none define a new property type
2701prop_type_change({name}, {props})
2702 none change an existing property type
2703prop_type_delete({name} [, {props}])
2704 none delete a property type
Bram Moolenaar7ceefb32020-05-01 16:07:38 +02002705prop_type_get([{name} [, {props}]])
Bram Moolenaar98aefe72018-12-13 22:20:09 +01002706 Dict get property type values
2707prop_type_list([{props}]) List get list of property types
Bram Moolenaare9bd5722019-08-17 19:36:06 +02002708pum_getpos() Dict position and size of pum if visible
Bram Moolenaar446cb832008-06-24 21:56:24 +00002709pumvisible() Number whether popup menu is visible
Bram Moolenaar81edd172016-04-14 13:51:37 +02002710py3eval({expr}) any evaluate |python3| expression
Bram Moolenaarebacddb2020-06-04 15:22:21 +02002711pyeval({expr}) any evaluate |Python| expression
Bram Moolenaarf42dd3c2017-01-28 16:06:38 +01002712pyxeval({expr}) any evaluate |python_x| expression
Bram Moolenaar06b0b4b2019-11-25 15:40:55 +01002713rand([{expr}]) Number get pseudo-random number
Bram Moolenaar81edd172016-04-14 13:51:37 +02002714range({expr} [, {max} [, {stride}]])
Bram Moolenaard8b02732005-01-14 21:48:43 +00002715 List items from {expr} to {max}
Bram Moolenaar84cf6bd2020-06-16 20:03:43 +02002716readdir({dir} [, {expr} [, {dict}]])
2717 List file names in {dir} selected by {expr}
2718readdirex({dir} [, {expr} [, {dict}]])
2719 List file info in {dir} selected by {expr}
Bram Moolenaar6e5ea8d2019-01-12 22:47:31 +01002720readfile({fname} [, {type} [, {max}]])
Bram Moolenaar26a60b42005-02-22 08:49:11 +00002721 List get list of lines from file {fname}
Bram Moolenaar85629982020-06-01 18:39:20 +02002722reduce({object}, {func} [, {initial}])
2723 any reduce {object} using {func}
Bram Moolenaarf2732452018-06-03 14:47:35 +02002724reg_executing() String get the executing register name
Bram Moolenaar0b6d9112018-05-22 20:35:17 +02002725reg_recording() String get the recording register name
Bram Moolenaar81edd172016-04-14 13:51:37 +02002726reltime([{start} [, {end}]]) List get time value
2727reltimefloat({time}) Float turn the time value into a Float
2728reltimestr({time}) String turn time value into a String
Bram Moolenaar3c2881d2017-03-21 19:18:29 +01002729remote_expr({server}, {string} [, {idvar} [, {timeout}]])
Bram Moolenaar071d4272004-06-13 20:20:40 +00002730 String send expression
Bram Moolenaar81edd172016-04-14 13:51:37 +02002731remote_foreground({server}) Number bring Vim server to the foreground
2732remote_peek({serverid} [, {retvar}])
Bram Moolenaar071d4272004-06-13 20:20:40 +00002733 Number check for reply string
Bram Moolenaar3c2881d2017-03-21 19:18:29 +01002734remote_read({serverid} [, {timeout}])
2735 String read reply string
Bram Moolenaar81edd172016-04-14 13:51:37 +02002736remote_send({server}, {string} [, {idvar}])
Bram Moolenaar071d4272004-06-13 20:20:40 +00002737 String send key sequence
Bram Moolenaar7416f3e2017-03-18 18:10:13 +01002738remote_startserver({name}) none become server {name}
Bram Moolenaar10455d42019-11-21 15:36:18 +01002739remove({list}, {idx} [, {end}]) any/List
Bram Moolenaar39536dd2019-01-29 22:58:21 +01002740 remove items {idx}-{end} from {list}
2741remove({blob}, {idx} [, {end}]) Number/Blob
2742 remove bytes {idx}-{end} from {blob}
Bram Moolenaar81edd172016-04-14 13:51:37 +02002743remove({dict}, {key}) any remove entry {key} from {dict}
2744rename({from}, {to}) Number rename (move) file from {from} to {to}
2745repeat({expr}, {count}) String repeat {expr} {count} times
2746resolve({filename}) String get filename a shortcut points to
2747reverse({list}) List reverse {list} in-place
2748round({expr}) Float round off {expr}
Bram Moolenaare99be0e2019-03-26 22:51:09 +01002749rubyeval({expr}) any evaluate |Ruby| expression
Bram Moolenaar81edd172016-04-14 13:51:37 +02002750screenattr({row}, {col}) Number attribute at screen position
2751screenchar({row}, {col}) Number character at screen position
Bram Moolenaar2912abb2019-03-29 14:16:42 +01002752screenchars({row}, {col}) List List of characters at screen position
Bram Moolenaar9750bb12012-12-05 16:10:42 +01002753screencol() Number current cursor column
Bram Moolenaarb3d17a22019-07-07 18:28:14 +02002754screenpos({winid}, {lnum}, {col}) Dict screen row and col of a text character
Bram Moolenaar9750bb12012-12-05 16:10:42 +01002755screenrow() Number current cursor row
Bram Moolenaar2912abb2019-03-29 14:16:42 +01002756screenstring({row}, {col}) String characters at screen position
Bram Moolenaaradc17a52020-06-06 18:37:51 +02002757search({pattern} [, {flags} [, {stopline} [, {timeout} [, {skip}]]]])
Bram Moolenaar76929292008-01-06 19:07:36 +00002758 Number search for {pattern}
Bram Moolenaare8f5ec02020-06-01 17:28:35 +02002759searchcount([{options}]) Dict get or update search stats
Bram Moolenaar81edd172016-04-14 13:51:37 +02002760searchdecl({name} [, {global} [, {thisblock}]])
Bram Moolenaar446cb832008-06-24 21:56:24 +00002761 Number search for variable declaration
Bram Moolenaar81edd172016-04-14 13:51:37 +02002762searchpair({start}, {middle}, {end} [, {flags} [, {skip} [...]]])
Bram Moolenaard7ee7ce2005-01-03 21:02:03 +00002763 Number search for other end of start/end pair
Bram Moolenaar81edd172016-04-14 13:51:37 +02002764searchpairpos({start}, {middle}, {end} [, {flags} [, {skip} [...]]])
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00002765 List search for other end of start/end pair
Bram Moolenaaradc17a52020-06-06 18:37:51 +02002766searchpos({pattern} [, {flags} [, {stopline} [, {timeout} [, {skip}]]]])
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00002767 List search for {pattern}
Bram Moolenaar81edd172016-04-14 13:51:37 +02002768server2client({clientid}, {string})
Bram Moolenaar071d4272004-06-13 20:20:40 +00002769 Number send reply string
2770serverlist() String get a list of available servers
Bram Moolenaar95bafa22018-10-02 13:26:25 +02002771setbufline({expr}, {lnum}, {text})
2772 Number set line {lnum} to {text} in buffer
Bram Moolenaarb31cf2b2017-09-02 19:45:19 +02002773 {expr}
Bram Moolenaar81edd172016-04-14 13:51:37 +02002774setbufvar({expr}, {varname}, {val})
2775 none set {varname} in buffer {expr} to {val}
Bram Moolenaar08aac3c2020-08-28 21:04:24 +02002776setcellwidths({list}) none set character cell width overrides
Bram Moolenaar81edd172016-04-14 13:51:37 +02002777setcharsearch({dict}) Dict set character search from {dict}
2778setcmdpos({pos}) Number set cursor position in command-line
Bram Moolenaar691ddee2019-05-09 14:52:41 +02002779setenv({name}, {val}) none set environment variable
Bram Moolenaar81edd172016-04-14 13:51:37 +02002780setfperm({fname}, {mode}) Number set {fname} file permissions to {mode}
2781setline({lnum}, {line}) Number set line {lnum} to {line}
Bram Moolenaare46a4402020-06-30 20:38:27 +02002782setloclist({nr}, {list} [, {action}])
2783 Number modify location list using {list}
2784setloclist({nr}, {list}, {action}, {what})
2785 Number modify specific location list props
Bram Moolenaaraff74912019-03-30 18:11:49 +01002786setmatches({list} [, {win}]) Number restore a list of matches
Bram Moolenaar81edd172016-04-14 13:51:37 +02002787setpos({expr}, {list}) Number set the {expr} position to {list}
Bram Moolenaare46a4402020-06-30 20:38:27 +02002788setqflist({list} [, {action}]) Number modify quickfix list using {list}
2789setqflist({list}, {action}, {what})
2790 Number modify specific quickfix list props
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01002791setreg({n}, {v} [, {opt}]) Number set register to value and type
Bram Moolenaar81edd172016-04-14 13:51:37 +02002792settabvar({nr}, {varname}, {val}) none set {varname} in tab page {nr} to {val}
2793settabwinvar({tabnr}, {winnr}, {varname}, {val})
2794 none set {varname} in window {winnr} in tab
2795 page {tabnr} to {val}
Bram Moolenaarf49cc602018-11-11 15:21:05 +01002796settagstack({nr}, {dict} [, {action}])
2797 Number modify tag stack using {dict}
Bram Moolenaar81edd172016-04-14 13:51:37 +02002798setwinvar({nr}, {varname}, {val}) none set {varname} in window {nr} to {val}
2799sha256({string}) String SHA256 checksum of {string}
2800shellescape({string} [, {special}])
Bram Moolenaar05bb9532008-07-04 09:44:11 +00002801 String escape {string} for use as shell
Bram Moolenaar60a495f2006-10-03 12:44:42 +00002802 command argument
Bram Moolenaarf9514162018-11-22 03:08:29 +01002803shiftwidth([{col}]) Number effective value of 'shiftwidth'
Bram Moolenaar162b7142018-12-21 15:17:36 +01002804sign_define({name} [, {dict}]) Number define or update a sign
Bram Moolenaar809ce4d2019-07-13 21:21:40 +02002805sign_define({list}) List define or update a list of signs
Bram Moolenaar162b7142018-12-21 15:17:36 +01002806sign_getdefined([{name}]) List get a list of defined signs
2807sign_getplaced([{expr} [, {dict}]])
2808 List get a list of placed signs
Bram Moolenaar6b7b7192019-01-11 13:42:41 +01002809sign_jump({id}, {group}, {expr})
2810 Number jump to a sign
Bram Moolenaar162b7142018-12-21 15:17:36 +01002811sign_place({id}, {group}, {name}, {expr} [, {dict}])
2812 Number place a sign
Bram Moolenaar809ce4d2019-07-13 21:21:40 +02002813sign_placelist({list}) List place a list of signs
Bram Moolenaar162b7142018-12-21 15:17:36 +01002814sign_undefine([{name}]) Number undefine a sign
Bram Moolenaar809ce4d2019-07-13 21:21:40 +02002815sign_undefine({list}) List undefine a list of signs
Bram Moolenaar162b7142018-12-21 15:17:36 +01002816sign_unplace({group} [, {dict}])
2817 Number unplace a sign
Bram Moolenaar809ce4d2019-07-13 21:21:40 +02002818sign_unplacelist({list}) List unplace a list of signs
Bram Moolenaar81edd172016-04-14 13:51:37 +02002819simplify({filename}) String simplify filename as much as possible
2820sin({expr}) Float sine of {expr}
2821sinh({expr}) Float hyperbolic sine of {expr}
2822sort({list} [, {func} [, {dict}]])
Bram Moolenaar5f894962011-06-19 02:55:37 +02002823 List sort {list}, using {func} to compare
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +02002824sound_clear() none stop playing all sounds
Bram Moolenaar427f5b62019-06-09 13:43:51 +02002825sound_playevent({name} [, {callback}])
2826 Number play an event sound
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +02002827sound_playfile({path} [, {callback}])
2828 Number play sound file {path}
Bram Moolenaar427f5b62019-06-09 13:43:51 +02002829sound_stop({id}) none stop playing sound {id}
Bram Moolenaar81edd172016-04-14 13:51:37 +02002830soundfold({word}) String sound-fold {word}
Bram Moolenaard857f0e2005-06-21 22:37:39 +00002831spellbadword() String badly spelled word at cursor
Bram Moolenaar81edd172016-04-14 13:51:37 +02002832spellsuggest({word} [, {max} [, {capital}]])
Bram Moolenaarc54b8a72005-09-30 21:20:29 +00002833 List spelling suggestions
Bram Moolenaar81edd172016-04-14 13:51:37 +02002834split({expr} [, {pat} [, {keepempty}]])
Bram Moolenaar32466aa2006-02-24 23:53:04 +00002835 List make |List| from {pat} separated {expr}
Bram Moolenaar81edd172016-04-14 13:51:37 +02002836sqrt({expr}) Float square root of {expr}
Bram Moolenaar06b0b4b2019-11-25 15:40:55 +01002837srand([{expr}]) List get seed for |rand()|
Bram Moolenaar0e57dd82019-09-16 22:56:03 +02002838state([{what}]) String current state of Vim
Bram Moolenaar81edd172016-04-14 13:51:37 +02002839str2float({expr}) Float convert String to Float
Bram Moolenaar9d401282019-04-06 13:18:12 +02002840str2list({expr} [, {utf8}]) List convert each character of {expr} to
2841 ASCII/UTF8 value
Bram Moolenaar60a8de22019-09-15 14:33:22 +02002842str2nr({expr} [, {base} [, {quoted}]])
2843 Number convert String to Number
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01002844strcharpart({str}, {start} [, {len}])
Bram Moolenaar6c53fca2020-08-23 17:34:46 +02002845 String {len} characters of {str} at
2846 character {start}
Bram Moolenaarebacddb2020-06-04 15:22:21 +02002847strchars({expr} [, {skipcc}]) Number character length of the String {expr}
Bram Moolenaar81edd172016-04-14 13:51:37 +02002848strdisplaywidth({expr} [, {col}]) Number display length of the String {expr}
Bram Moolenaar10455d42019-11-21 15:36:18 +01002849strftime({format} [, {time}]) String format time with a specified format
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02002850strgetchar({str}, {index}) Number get char {index} from {str}
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01002851stridx({haystack}, {needle} [, {start}])
Bram Moolenaar8f999f12005-01-25 22:12:55 +00002852 Number index of {needle} in {haystack}
Bram Moolenaar81edd172016-04-14 13:51:37 +02002853string({expr}) String String representation of {expr} value
2854strlen({expr}) Number length of the String {expr}
Bram Moolenaar6c53fca2020-08-23 17:34:46 +02002855strpart({str}, {start} [, {len} [, {chars}]])
2856 String {len} bytes/chars of {str} at
2857 byte {start}
Bram Moolenaar10455d42019-11-21 15:36:18 +01002858strptime({format}, {timestring})
2859 Number Convert {timestring} to unix timestamp
Bram Moolenaar81edd172016-04-14 13:51:37 +02002860strridx({haystack}, {needle} [, {start}])
Bram Moolenaar677ee682005-01-27 14:41:15 +00002861 Number last index of {needle} in {haystack}
Bram Moolenaar81edd172016-04-14 13:51:37 +02002862strtrans({expr}) String translate string to make it printable
2863strwidth({expr}) Number display cell length of the String {expr}
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01002864submatch({nr} [, {list}]) String or List
Bram Moolenaar41571762014-04-02 19:00:58 +02002865 specific match in ":s" or substitute()
Bram Moolenaar81edd172016-04-14 13:51:37 +02002866substitute({expr}, {pat}, {sub}, {flags})
Bram Moolenaar071d4272004-06-13 20:20:40 +00002867 String all {pat} in {expr} replaced with {sub}
Bram Moolenaar00f123a2018-08-21 20:28:54 +02002868swapinfo({fname}) Dict information about swap file {fname}
Bram Moolenaar110bd602018-09-16 18:46:59 +02002869swapname({expr}) String swap file of buffer {expr}
Bram Moolenaar81edd172016-04-14 13:51:37 +02002870synID({lnum}, {col}, {trans}) Number syntax ID at {lnum} and {col}
2871synIDattr({synID}, {what} [, {mode}])
Bram Moolenaar071d4272004-06-13 20:20:40 +00002872 String attribute {what} of syntax ID {synID}
Bram Moolenaar81edd172016-04-14 13:51:37 +02002873synIDtrans({synID}) Number translated syntax ID of {synID}
Bram Moolenaara06ecab2016-07-16 14:47:36 +02002874synconcealed({lnum}, {col}) List info about concealing
Bram Moolenaar81edd172016-04-14 13:51:37 +02002875synstack({lnum}, {col}) List stack of syntax IDs at {lnum} and {col}
2876system({expr} [, {input}]) String output of shell command/filter {expr}
2877systemlist({expr} [, {input}]) List output of shell command/filter {expr}
Bram Moolenaar802a0d92016-06-26 16:17:58 +02002878tabpagebuflist([{arg}]) List list of buffer numbers in tab page
Bram Moolenaar81edd172016-04-14 13:51:37 +02002879tabpagenr([{arg}]) Number number of current or last tab page
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01002880tabpagewinnr({tabarg} [, {arg}]) Number number of current window in tab page
Bram Moolenaar446cb832008-06-24 21:56:24 +00002881tagfiles() List tags files used
Bram Moolenaarebacddb2020-06-04 15:22:21 +02002882taglist({expr} [, {filename}]) List list of tags matching {expr}
Bram Moolenaar81edd172016-04-14 13:51:37 +02002883tan({expr}) Float tangent of {expr}
2884tanh({expr}) Float hyperbolic tangent of {expr}
Bram Moolenaar975b5272016-03-15 23:10:59 +01002885tempname() String name for a temporary file
Bram Moolenaard96ff162018-02-18 22:13:29 +01002886term_dumpdiff({filename}, {filename} [, {options}])
2887 Number display difference between two dumps
2888term_dumpload({filename} [, {options}])
2889 Number displaying a screen dump
Bram Moolenaar6bb2cdf2018-02-24 19:53:53 +01002890term_dumpwrite({buf}, {filename} [, {options}])
Bram Moolenaard96ff162018-02-18 22:13:29 +01002891 none dump terminal window contents
Bram Moolenaare41e3b42017-08-11 16:24:50 +02002892term_getaltscreen({buf}) Number get the alternate screen flag
Bram Moolenaarf59c6e82018-04-10 15:59:11 +02002893term_getansicolors({buf}) List get ANSI palette in GUI color mode
Bram Moolenaar45356542017-08-06 17:53:31 +02002894term_getattr({attr}, {what}) Number get the value of attribute {what}
Bram Moolenaar97870002017-07-30 18:28:38 +02002895term_getcursor({buf}) List get the cursor position of a terminal
Bram Moolenaarc6df10e2017-07-29 20:15:08 +02002896term_getjob({buf}) Job get the job associated with a terminal
Bram Moolenaarc2ce52c2017-08-01 18:35:38 +02002897term_getline({buf}, {row}) String get a line of text from a terminal
Bram Moolenaar82b9ca02017-08-08 23:06:46 +02002898term_getscrolled({buf}) Number get the scroll count of a terminal
Bram Moolenaarc6df10e2017-07-29 20:15:08 +02002899term_getsize({buf}) List get the size of a terminal
Bram Moolenaarb000e322017-07-30 19:38:21 +02002900term_getstatus({buf}) String get the status of a terminal
2901term_gettitle({buf}) String get the title of a terminal
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01002902term_gettty({buf}, [{input}]) String get the tty name of a terminal
Bram Moolenaarc6df10e2017-07-29 20:15:08 +02002903term_list() List get the list of terminal buffers
Bram Moolenaarc2ce52c2017-08-01 18:35:38 +02002904term_scrape({buf}, {row}) List get row of a terminal screen
Bram Moolenaarc6df10e2017-07-29 20:15:08 +02002905term_sendkeys({buf}, {keys}) none send keystrokes to a terminal
Bram Moolenaarf59c6e82018-04-10 15:59:11 +02002906term_setansicolors({buf}, {colors})
2907 none set ANSI palette in GUI color mode
Bram Moolenaarebacddb2020-06-04 15:22:21 +02002908term_setapi({buf}, {expr}) none set |terminal-api| function name prefix
Bram Moolenaar7dda86f2018-04-20 22:36:41 +02002909term_setkill({buf}, {how}) none set signal to stop job in terminal
Bram Moolenaarb5b75622018-03-09 22:22:21 +01002910term_setrestore({buf}, {command}) none set command to restore terminal
Bram Moolenaar7dda86f2018-04-20 22:36:41 +02002911term_setsize({buf}, {rows}, {cols})
2912 none set the size of a terminal
Bram Moolenaar911ead12019-04-21 00:03:35 +02002913term_start({cmd} [, {options}]) Number open a terminal window and run a job
Bram Moolenaarf3402b12017-08-06 19:07:08 +02002914term_wait({buf} [, {time}]) Number wait for screen to be updated
Bram Moolenaar0c0eddd2020-06-13 15:47:25 +02002915terminalprops() Dict properties of the terminal
Bram Moolenaar8e8df252016-05-25 21:23:21 +02002916test_alloc_fail({id}, {countdown}, {repeat})
2917 none make memory allocation fail
Bram Moolenaar6f1d9a02016-07-24 14:12:38 +02002918test_autochdir() none enable 'autochdir' during startup
Bram Moolenaar95bafa22018-10-02 13:26:25 +02002919test_feedinput({string}) none add key sequence to input buffer
Bram Moolenaar574860b2016-05-24 17:33:34 +02002920test_garbagecollect_now() none free memory right now for testing
Bram Moolenaaradc67142019-06-22 01:40:42 +02002921test_garbagecollect_soon() none free memory soon for testing
Bram Moolenaareda65222019-05-16 20:29:44 +02002922test_getvalue({string}) any get value of an internal variable
Bram Moolenaare0c31f62017-03-01 15:07:05 +01002923test_ignore_error({expr}) none ignore a specific error
Bram Moolenaarc0f5a782019-01-13 15:16:13 +01002924test_null_blob() Blob null value for testing
Bram Moolenaar574860b2016-05-24 17:33:34 +02002925test_null_channel() Channel null value for testing
2926test_null_dict() Dict null value for testing
Bram Moolenaare69f6d02020-04-01 22:11:01 +02002927test_null_function() Funcref null value for testing
Bram Moolenaar574860b2016-05-24 17:33:34 +02002928test_null_job() Job null value for testing
2929test_null_list() List null value for testing
2930test_null_partial() Funcref null value for testing
2931test_null_string() String null value for testing
Bram Moolenaar2c64ca12018-10-19 16:22:31 +02002932test_option_not_set({name}) none reset flag indicating option was set
2933test_override({expr}, {val}) none test with Vim internal overrides
Bram Moolenaarc3e92c12019-03-23 14:23:07 +01002934test_refcount({expr}) Number get the reference count of {expr}
Bram Moolenaarab186732018-09-14 21:27:06 +02002935test_scrollbar({which}, {value}, {dragging})
2936 none scroll in the GUI for testing
Bram Moolenaarbb8476b2019-05-04 15:47:48 +02002937test_setmouse({row}, {col}) none set the mouse position for testing
Bram Moolenaarc95a3022016-06-12 23:01:46 +02002938test_settime({expr}) none set current time for testing
Bram Moolenaarebacddb2020-06-04 15:22:21 +02002939test_srand_seed([seed]) none set seed for testing srand()
2940test_unknown() any unknown value for testing
2941test_void() any void value for testing
Bram Moolenaar8e97bd72016-08-06 22:05:07 +02002942timer_info([{id}]) List information about timers
Bram Moolenaarb73598e2016-08-07 18:22:53 +02002943timer_pause({id}, {pause}) none pause or unpause a timer
Bram Moolenaar81edd172016-04-14 13:51:37 +02002944timer_start({time}, {callback} [, {options}])
Bram Moolenaar975b5272016-03-15 23:10:59 +01002945 Number create a timer
Bram Moolenaar81edd172016-04-14 13:51:37 +02002946timer_stop({timer}) none stop a timer
Bram Moolenaarb73598e2016-08-07 18:22:53 +02002947timer_stopall() none stop all timers
Bram Moolenaar81edd172016-04-14 13:51:37 +02002948tolower({expr}) String the String {expr} switched to lowercase
2949toupper({expr}) String the String {expr} switched to uppercase
2950tr({src}, {fromstr}, {tostr}) String translate chars of {src} in {fromstr}
Bram Moolenaar8299df92004-07-10 09:47:34 +00002951 to chars in {tostr}
Bram Moolenaar2245ae12020-05-31 22:20:36 +02002952trim({text} [, {mask} [, {dir}]])
2953 String trim characters in {mask} from {text}
Bram Moolenaar81edd172016-04-14 13:51:37 +02002954trunc({expr}) Float truncate Float {expr}
2955type({name}) Number type of variable {name}
2956undofile({name}) String undo file name for {name}
Bram Moolenaara800b422010-06-27 01:15:55 +02002957undotree() List undo file tree
Bram Moolenaar81edd172016-04-14 13:51:37 +02002958uniq({list} [, {func} [, {dict}]])
Bram Moolenaar327aa022014-03-25 18:24:23 +01002959 List remove adjacent duplicates from a list
Bram Moolenaar81edd172016-04-14 13:51:37 +02002960values({dict}) List values in {dict}
2961virtcol({expr}) Number screen column of cursor or mark
2962visualmode([expr]) String last visual mode used
Bram Moolenaar8738fc12013-02-20 17:59:11 +01002963wildmenumode() Number whether 'wildmenu' mode is active
Bram Moolenaar868b7b62019-05-29 21:44:40 +02002964win_execute({id}, {command} [, {silent}])
2965 String execute {command} in window {id}
Bram Moolenaar81edd172016-04-14 13:51:37 +02002966win_findbuf({bufnr}) List find windows containing {bufnr}
2967win_getid([{win} [, {tab}]]) Number get window ID for {win} in {tab}
Bram Moolenaar2c7f8c52020-04-20 19:52:53 +02002968win_gettype([{nr}]) String type of window {nr}
Bram Moolenaar81edd172016-04-14 13:51:37 +02002969win_gotoid({expr}) Number go to window with ID {expr}
2970win_id2tabwin({expr}) List get tab and window nr from window ID
2971win_id2win({expr}) Number get window nr from window ID
Bram Moolenaar22044dc2017-12-02 15:43:37 +01002972win_screenpos({nr}) List get screen position of window {nr}
Bram Moolenaard20dcb32019-09-10 21:22:58 +02002973win_splitmove({nr}, {target} [, {options}])
Bram Moolenaar2e693a82019-10-16 22:35:02 +02002974 Number move window {nr} to split of {target}
Bram Moolenaar81edd172016-04-14 13:51:37 +02002975winbufnr({nr}) Number buffer number of window {nr}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002976wincol() Number window column of the cursor
Bram Moolenaar388a5d42020-05-26 21:20:45 +02002977windowsversion() String MS-Windows OS version
Bram Moolenaar81edd172016-04-14 13:51:37 +02002978winheight({nr}) Number height of window {nr}
Bram Moolenaar0f6b4f02018-08-21 16:56:34 +02002979winlayout([{tabnr}]) List layout of windows in tab {tabnr}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002980winline() Number window line of the cursor
Bram Moolenaar81edd172016-04-14 13:51:37 +02002981winnr([{expr}]) Number number of current window
Bram Moolenaard7ee7ce2005-01-03 21:02:03 +00002982winrestcmd() String returns command to restore window sizes
Bram Moolenaar81edd172016-04-14 13:51:37 +02002983winrestview({dict}) none restore view of current window
Bram Moolenaar87b5ca52006-03-04 21:55:31 +00002984winsaveview() Dict save view of current window
Bram Moolenaar81edd172016-04-14 13:51:37 +02002985winwidth({nr}) Number width of window {nr}
Bram Moolenaared767a22016-01-03 22:49:16 +01002986wordcount() Dict get byte/char/word statistics
Bram Moolenaar6e5ea8d2019-01-12 22:47:31 +01002987writefile({object}, {fname} [, {flags}])
2988 Number write |Blob| or |List| of lines to file
Bram Moolenaara06ecab2016-07-16 14:47:36 +02002989xor({expr}, {expr}) Number bitwise XOR
Bram Moolenaar071d4272004-06-13 20:20:40 +00002990
Bram Moolenaar03413f42016-04-12 21:07:15 +02002991
Bram Moolenaar446cb832008-06-24 21:56:24 +00002992abs({expr}) *abs()*
2993 Return the absolute value of {expr}. When {expr} evaluates to
2994 a |Float| abs() returns a |Float|. When {expr} can be
2995 converted to a |Number| abs() returns a |Number|. Otherwise
2996 abs() gives an error message and returns -1.
2997 Examples: >
2998 echo abs(1.456)
2999< 1.456 >
3000 echo abs(-5.456)
3001< 5.456 >
3002 echo abs(-4)
3003< 4
Bram Moolenaar93cf85f2019-08-17 21:36:28 +02003004
3005 Can also be used as a |method|: >
3006 Compute()->abs()
3007
3008< {only available when compiled with the |+float| feature}
Bram Moolenaar446cb832008-06-24 21:56:24 +00003009
Bram Moolenaardb7c6862010-05-21 16:33:48 +02003010
3011acos({expr}) *acos()*
3012 Return the arc cosine of {expr} measured in radians, as a
Bram Moolenaar9855d6b2010-07-18 14:34:51 +02003013 |Float| in the range of [0, pi].
3014 {expr} must evaluate to a |Float| or a |Number| in the range
Bram Moolenaardb7c6862010-05-21 16:33:48 +02003015 [-1, 1].
3016 Examples: >
3017 :echo acos(0)
3018< 1.570796 >
3019 :echo acos(-0.5)
3020< 2.094395
Bram Moolenaar93cf85f2019-08-17 21:36:28 +02003021
3022 Can also be used as a |method|: >
3023 Compute()->acos()
3024
3025< {only available when compiled with the |+float| feature}
Bram Moolenaardb7c6862010-05-21 16:33:48 +02003026
3027
Bram Moolenaard8968242019-01-15 22:51:57 +01003028add({object}, {expr}) *add()*
3029 Append the item {expr} to |List| or |Blob| {object}. Returns
3030 the resulting |List| or |Blob|. Examples: >
Bram Moolenaara14de3d2005-01-07 21:48:26 +00003031 :let alist = add([1, 2, 3], item)
3032 :call add(mylist, "woodstock")
Bram Moolenaar32466aa2006-02-24 23:53:04 +00003033< Note that when {expr} is a |List| it is appended as a single
Bram Moolenaara23ccb82006-02-27 00:08:02 +00003034 item. Use |extend()| to concatenate |Lists|.
Bram Moolenaard8968242019-01-15 22:51:57 +01003035 When {object} is a |Blob| then {expr} must be a number.
Bram Moolenaar13065c42005-01-08 16:08:21 +00003036 Use |insert()| to add an item at another position.
Bram Moolenaar93cf85f2019-08-17 21:36:28 +02003037
Bram Moolenaarac92e252019-08-03 21:58:38 +02003038 Can also be used as a |method|: >
3039 mylist->add(val1)->add(val2)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003040
Bram Moolenaara14de3d2005-01-07 21:48:26 +00003041
Bram Moolenaard6e256c2011-12-14 15:32:50 +01003042and({expr}, {expr}) *and()*
3043 Bitwise AND on the two arguments. The arguments are converted
3044 to a number. A List, Dict or Float argument causes an error.
3045 Example: >
3046 :let flag = and(bits, 0x80)
Bram Moolenaar073e4b92019-08-18 23:01:56 +02003047< Can also be used as a |method|: >
3048 :let flag = bits->and(0x80)
Bram Moolenaard6e256c2011-12-14 15:32:50 +01003049
3050
Bram Moolenaar95bafa22018-10-02 13:26:25 +02003051append({lnum}, {text}) *append()*
3052 When {text} is a |List|: Append each item of the |List| as a
Bram Moolenaar32466aa2006-02-24 23:53:04 +00003053 text line below line {lnum} in the current buffer.
Bram Moolenaar95bafa22018-10-02 13:26:25 +02003054 Otherwise append {text} as one text line below line {lnum} in
Bram Moolenaar748bf032005-02-02 23:04:36 +00003055 the current buffer.
3056 {lnum} can be zero to insert a line before the first one.
Bram Moolenaara14de3d2005-01-07 21:48:26 +00003057 Returns 1 for failure ({lnum} out of range or out of memory),
Bram Moolenaar58b85342016-08-14 19:54:54 +02003058 0 for success. Example: >
Bram Moolenaard7ee7ce2005-01-03 21:02:03 +00003059 :let failed = append(line('$'), "# THE END")
Bram Moolenaara14de3d2005-01-07 21:48:26 +00003060 :let failed = append(0, ["Chapter 1", "the beginning"])
Bram Moolenaarca851592018-06-06 21:04:07 +02003061
Bram Moolenaar7ff78462020-07-10 22:00:53 +02003062< Can also be used as a |method| after a List, the base is
3063 passed as the second argument: >
Bram Moolenaar25e42232019-08-04 15:04:10 +02003064 mylist->append(lnum)
3065
3066
Bram Moolenaarca851592018-06-06 21:04:07 +02003067appendbufline({expr}, {lnum}, {text}) *appendbufline()*
3068 Like |append()| but append the text in buffer {expr}.
3069
Bram Moolenaar2e693a82019-10-16 22:35:02 +02003070 This function works only for loaded buffers. First call
3071 |bufload()| if needed.
3072
Bram Moolenaarca851592018-06-06 21:04:07 +02003073 For the use of {expr}, see |bufname()|.
3074
3075 {lnum} is used like with |append()|. Note that using |line()|
3076 would use the current buffer, not the one appending to.
3077 Use "$" to append at the end of the buffer.
3078
3079 On success 0 is returned, on failure 1 is returned.
3080
3081 If {expr} is not a valid buffer or {lnum} is not valid, an
3082 error message is given. Example: >
3083 :let failed = appendbufline(13, 0, "# THE START")
Bram Moolenaard7ee7ce2005-01-03 21:02:03 +00003084<
Bram Moolenaar7ff78462020-07-10 22:00:53 +02003085< Can also be used as a |method| after a List, the base is
3086 passed as the second argument: >
Bram Moolenaar25e42232019-08-04 15:04:10 +02003087 mylist->appendbufline(buf, lnum)
3088
3089
3090argc([{winid}]) *argc()*
Bram Moolenaare6e39892018-10-25 12:32:11 +02003091 The result is the number of files in the argument list. See
3092 |arglist|.
3093 If {winid} is not supplied, the argument list of the current
3094 window is used.
3095 If {winid} is -1, the global argument list is used.
3096 Otherwise {winid} specifies the window of which the argument
3097 list is used: either the window number or the window ID.
3098 Returns -1 if the {winid} argument is invalid.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003099
3100 *argidx()*
3101argidx() The result is the current index in the argument list. 0 is
3102 the first file. argc() - 1 is the last one. See |arglist|.
3103
Bram Moolenaar2d1fe052014-05-28 18:22:57 +02003104 *arglistid()*
Bram Moolenaare0fa3742016-02-20 15:47:01 +01003105arglistid([{winnr} [, {tabnr}]])
Bram Moolenaar2d1fe052014-05-28 18:22:57 +02003106 Return the argument list ID. This is a number which
3107 identifies the argument list being used. Zero is used for the
Bram Moolenaarfb539272014-08-22 19:21:47 +02003108 global argument list. See |arglist|.
Bram Moolenaare6e39892018-10-25 12:32:11 +02003109 Returns -1 if the arguments are invalid.
Bram Moolenaar2d1fe052014-05-28 18:22:57 +02003110
3111 Without arguments use the current window.
3112 With {winnr} only use this window in the current tab page.
3113 With {winnr} and {tabnr} use the window in the specified tab
3114 page.
Bram Moolenaar7571d552016-08-18 22:54:46 +02003115 {winnr} can be the window number or the |window-ID|.
Bram Moolenaar2d1fe052014-05-28 18:22:57 +02003116
Bram Moolenaar071d4272004-06-13 20:20:40 +00003117 *argv()*
Bram Moolenaar7ceefb32020-05-01 16:07:38 +02003118argv([{nr} [, {winid}]])
Bram Moolenaare6e39892018-10-25 12:32:11 +02003119 The result is the {nr}th file in the argument list. See
3120 |arglist|. "argv(0)" is the first one. Example: >
Bram Moolenaar071d4272004-06-13 20:20:40 +00003121 :let i = 0
3122 :while i < argc()
Bram Moolenaar446cb832008-06-24 21:56:24 +00003123 : let f = escape(fnameescape(argv(i)), '.')
Bram Moolenaar071d4272004-06-13 20:20:40 +00003124 : exe 'amenu Arg.' . f . ' :e ' . f . '<CR>'
3125 : let i = i + 1
3126 :endwhile
Bram Moolenaare6e39892018-10-25 12:32:11 +02003127< Without the {nr} argument, or when {nr} is -1, a |List| with
3128 the whole |arglist| is returned.
3129
3130 The {winid} argument specifies the window ID, see |argc()|.
Bram Moolenaar69bf6342019-10-29 04:16:57 +01003131 For the Vim command line arguments see |v:argv|.
Bram Moolenaare2f98b92006-03-29 21:18:24 +00003132
Bram Moolenaardb7c6862010-05-21 16:33:48 +02003133asin({expr}) *asin()*
Bram Moolenaar9855d6b2010-07-18 14:34:51 +02003134 Return the arc sine of {expr} measured in radians, as a |Float|
Bram Moolenaardb7c6862010-05-21 16:33:48 +02003135 in the range of [-pi/2, pi/2].
Bram Moolenaar9855d6b2010-07-18 14:34:51 +02003136 {expr} must evaluate to a |Float| or a |Number| in the range
Bram Moolenaardb7c6862010-05-21 16:33:48 +02003137 [-1, 1].
3138 Examples: >
3139 :echo asin(0.8)
3140< 0.927295 >
3141 :echo asin(-0.5)
3142< -0.523599
Bram Moolenaar93cf85f2019-08-17 21:36:28 +02003143
3144 Can also be used as a |method|: >
3145 Compute()->asin()
3146<
Bram Moolenaardb84e452010-08-15 13:50:43 +02003147 {only available when compiled with the |+float| feature}
Bram Moolenaardb7c6862010-05-21 16:33:48 +02003148
3149
Bram Moolenaar29634562020-01-09 21:46:04 +01003150assert_ functions are documented here: |assert-functions-details|
3151
3152
3153
Bram Moolenaar446cb832008-06-24 21:56:24 +00003154atan({expr}) *atan()*
3155 Return the principal value of the arc tangent of {expr}, in
3156 the range [-pi/2, +pi/2] radians, as a |Float|.
3157 {expr} must evaluate to a |Float| or a |Number|.
3158 Examples: >
3159 :echo atan(100)
3160< 1.560797 >
3161 :echo atan(-4.01)
3162< -1.326405
Bram Moolenaar93cf85f2019-08-17 21:36:28 +02003163
3164 Can also be used as a |method|: >
3165 Compute()->atan()
3166<
Bram Moolenaar446cb832008-06-24 21:56:24 +00003167 {only available when compiled with the |+float| feature}
3168
Bram Moolenaardb7c6862010-05-21 16:33:48 +02003169
3170atan2({expr1}, {expr2}) *atan2()*
3171 Return the arc tangent of {expr1} / {expr2}, measured in
Bram Moolenaar9855d6b2010-07-18 14:34:51 +02003172 radians, as a |Float| in the range [-pi, pi].
3173 {expr1} and {expr2} must evaluate to a |Float| or a |Number|.
Bram Moolenaardb7c6862010-05-21 16:33:48 +02003174 Examples: >
3175 :echo atan2(-1, 1)
3176< -0.785398 >
3177 :echo atan2(1, -1)
3178< 2.356194
Bram Moolenaar93cf85f2019-08-17 21:36:28 +02003179
3180 Can also be used as a |method|: >
3181 Compute()->atan(1)
3182<
Bram Moolenaardb84e452010-08-15 13:50:43 +02003183 {only available when compiled with the |+float| feature}
Bram Moolenaardb7c6862010-05-21 16:33:48 +02003184
Bram Moolenaarbe0a2592019-05-09 13:50:16 +02003185balloon_gettext() *balloon_gettext()*
3186 Return the current text in the balloon. Only for the string,
3187 not used for the List.
3188
Bram Moolenaar246fe032017-11-19 19:56:27 +01003189balloon_show({expr}) *balloon_show()*
3190 Show {expr} inside the balloon. For the GUI {expr} is used as
3191 a string. For a terminal {expr} can be a list, which contains
3192 the lines of the balloon. If {expr} is not a list it will be
3193 split with |balloon_split()|.
Bram Moolenaarbe0a2592019-05-09 13:50:16 +02003194 If {expr} is an empty string any existing balloon is removed.
Bram Moolenaar246fe032017-11-19 19:56:27 +01003195
Bram Moolenaar214641f2017-03-05 17:04:09 +01003196 Example: >
Bram Moolenaar59716a22017-03-01 20:32:44 +01003197 func GetBalloonContent()
Bram Moolenaarbe0a2592019-05-09 13:50:16 +02003198 " ... initiate getting the content
Bram Moolenaar59716a22017-03-01 20:32:44 +01003199 return ''
3200 endfunc
3201 set balloonexpr=GetBalloonContent()
3202
3203 func BalloonCallback(result)
Bram Moolenaar214641f2017-03-05 17:04:09 +01003204 call balloon_show(a:result)
Bram Moolenaar59716a22017-03-01 20:32:44 +01003205 endfunc
Bram Moolenaar073e4b92019-08-18 23:01:56 +02003206< Can also be used as a |method|: >
3207 GetText()->balloon_show()
Bram Moolenaar59716a22017-03-01 20:32:44 +01003208<
3209 The intended use is that fetching the content of the balloon
3210 is initiated from 'balloonexpr'. It will invoke an
3211 asynchronous method, in which a callback invokes
3212 balloon_show(). The 'balloonexpr' itself can return an
3213 empty string or a placeholder.
Bram Moolenaar214641f2017-03-05 17:04:09 +01003214
3215 When showing a balloon is not possible nothing happens, no
3216 error message.
Bram Moolenaar95bafa22018-10-02 13:26:25 +02003217 {only available when compiled with the |+balloon_eval| or
3218 |+balloon_eval_term| feature}
Bram Moolenaardb7c6862010-05-21 16:33:48 +02003219
Bram Moolenaar246fe032017-11-19 19:56:27 +01003220balloon_split({msg}) *balloon_split()*
3221 Split {msg} into lines to be displayed in a balloon. The
3222 splits are made for the current window size and optimize to
3223 show debugger output.
3224 Returns a |List| with the split lines.
Bram Moolenaar073e4b92019-08-18 23:01:56 +02003225 Can also be used as a |method|: >
3226 GetText()->balloon_split()->balloon_show()
3227
3228< {only available when compiled with the |+balloon_eval_term|
Bram Moolenaar669a8282017-11-19 20:13:05 +01003229 feature}
Bram Moolenaar246fe032017-11-19 19:56:27 +01003230
Bram Moolenaar071d4272004-06-13 20:20:40 +00003231 *browse()*
3232browse({save}, {title}, {initdir}, {default})
3233 Put up a file requester. This only works when "has("browse")"
Bram Moolenaare381d3d2016-07-07 14:50:41 +02003234 returns |TRUE| (only in some GUI versions).
Bram Moolenaar071d4272004-06-13 20:20:40 +00003235 The input fields are:
Bram Moolenaare381d3d2016-07-07 14:50:41 +02003236 {save} when |TRUE|, select file to write
Bram Moolenaar071d4272004-06-13 20:20:40 +00003237 {title} title for the requester
3238 {initdir} directory to start browsing in
3239 {default} default file name
Bram Moolenaar073e4b92019-08-18 23:01:56 +02003240 An empty string is returned when the "Cancel" button is hit,
3241 something went wrong, or browsing is not possible.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003242
Bram Moolenaar7b0294c2004-10-11 10:16:09 +00003243 *browsedir()*
3244browsedir({title}, {initdir})
3245 Put up a directory requester. This only works when
Bram Moolenaare381d3d2016-07-07 14:50:41 +02003246 "has("browse")" returns |TRUE| (only in some GUI versions).
Bram Moolenaar7b0294c2004-10-11 10:16:09 +00003247 On systems where a directory browser is not supported a file
3248 browser is used. In that case: select a file in the directory
3249 to be used.
3250 The input fields are:
3251 {title} title for the requester
3252 {initdir} directory to start browsing in
3253 When the "Cancel" button is hit, something went wrong, or
3254 browsing is not possible, an empty string is returned.
3255
Bram Moolenaar15e248e2019-06-30 20:21:37 +02003256bufadd({name}) *bufadd()*
3257 Add a buffer to the buffer list with {name}.
3258 If a buffer for file {name} already exists, return that buffer
3259 number. Otherwise return the buffer number of the newly
3260 created buffer. When {name} is an empty string then a new
3261 buffer is always created.
Bram Moolenaaraad222c2019-09-06 22:46:09 +02003262 The buffer will not have 'buflisted' set and not be loaded
Bram Moolenaar5ca1ac32019-07-04 15:39:28 +02003263 yet. To add some text to the buffer use this: >
3264 let bufnr = bufadd('someName')
3265 call bufload(bufnr)
3266 call setbufline(bufnr, 1, ['some', 'text'])
Bram Moolenaar073e4b92019-08-18 23:01:56 +02003267< Can also be used as a |method|: >
3268 let bufnr = 'somename'->bufadd()
Bram Moolenaar15e248e2019-06-30 20:21:37 +02003269
Bram Moolenaar071d4272004-06-13 20:20:40 +00003270bufexists({expr}) *bufexists()*
Bram Moolenaare381d3d2016-07-07 14:50:41 +02003271 The result is a Number, which is |TRUE| if a buffer called
Bram Moolenaar071d4272004-06-13 20:20:40 +00003272 {expr} exists.
Bram Moolenaar69a7cb42004-06-20 12:51:53 +00003273 If the {expr} argument is a number, buffer numbers are used.
Bram Moolenaara2a80162017-11-21 23:09:50 +01003274 Number zero is the alternate buffer for the current window.
3275
Bram Moolenaar071d4272004-06-13 20:20:40 +00003276 If the {expr} argument is a string it must match a buffer name
Bram Moolenaar69a7cb42004-06-20 12:51:53 +00003277 exactly. The name can be:
3278 - Relative to the current directory.
3279 - A full path.
Bram Moolenaar446cb832008-06-24 21:56:24 +00003280 - The name of a buffer with 'buftype' set to "nofile".
Bram Moolenaar69a7cb42004-06-20 12:51:53 +00003281 - A URL name.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003282 Unlisted buffers will be found.
3283 Note that help files are listed by their short name in the
3284 output of |:buffers|, but bufexists() requires using their
3285 long name to be able to find them.
Bram Moolenaar446cb832008-06-24 21:56:24 +00003286 bufexists() may report a buffer exists, but to use the name
3287 with a |:buffer| command you may need to use |expand()|. Esp
3288 for MS-Windows 8.3 names in the form "c:\DOCUME~1"
Bram Moolenaar071d4272004-06-13 20:20:40 +00003289 Use "bufexists(0)" to test for the existence of an alternate
3290 file name.
Bram Moolenaar073e4b92019-08-18 23:01:56 +02003291
3292 Can also be used as a |method|: >
3293 let exists = 'somename'->bufexists()
3294<
3295 Obsolete name: buffer_exists(). *buffer_exists()*
Bram Moolenaar071d4272004-06-13 20:20:40 +00003296
3297buflisted({expr}) *buflisted()*
Bram Moolenaare381d3d2016-07-07 14:50:41 +02003298 The result is a Number, which is |TRUE| if a buffer called
Bram Moolenaar071d4272004-06-13 20:20:40 +00003299 {expr} exists and is listed (has the 'buflisted' option set).
Bram Moolenaar69a7cb42004-06-20 12:51:53 +00003300 The {expr} argument is used like with |bufexists()|.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003301
Bram Moolenaar073e4b92019-08-18 23:01:56 +02003302 Can also be used as a |method|: >
3303 let listed = 'somename'->buflisted()
3304
Bram Moolenaar15e248e2019-06-30 20:21:37 +02003305bufload({expr}) *bufload()*
3306 Ensure the buffer {expr} is loaded. When the buffer name
3307 refers to an existing file then the file is read. Otherwise
3308 the buffer will be empty. If the buffer was already loaded
3309 then there is no change.
3310 If there is an existing swap file for the file of the buffer,
3311 there will be no dialog, the buffer will be loaded anyway.
3312 The {expr} argument is used like with |bufexists()|.
3313
Bram Moolenaar073e4b92019-08-18 23:01:56 +02003314 Can also be used as a |method|: >
3315 eval 'somename'->bufload()
3316
Bram Moolenaar071d4272004-06-13 20:20:40 +00003317bufloaded({expr}) *bufloaded()*
Bram Moolenaare381d3d2016-07-07 14:50:41 +02003318 The result is a Number, which is |TRUE| if a buffer called
Bram Moolenaar071d4272004-06-13 20:20:40 +00003319 {expr} exists and is loaded (shown in a window or hidden).
Bram Moolenaar69a7cb42004-06-20 12:51:53 +00003320 The {expr} argument is used like with |bufexists()|.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003321
Bram Moolenaar073e4b92019-08-18 23:01:56 +02003322 Can also be used as a |method|: >
3323 let loaded = 'somename'->bufloaded()
3324
Bram Moolenaara8eee212019-08-24 22:14:58 +02003325bufname([{expr}]) *bufname()*
Bram Moolenaar071d4272004-06-13 20:20:40 +00003326 The result is the name of a buffer, as it is displayed by the
3327 ":ls" command.
Bram Moolenaara8eee212019-08-24 22:14:58 +02003328 If {expr} is omitted the current buffer is used.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003329 If {expr} is a Number, that buffer number's name is given.
3330 Number zero is the alternate buffer for the current window.
3331 If {expr} is a String, it is used as a |file-pattern| to match
Bram Moolenaar58b85342016-08-14 19:54:54 +02003332 with the buffer names. This is always done like 'magic' is
Bram Moolenaar071d4272004-06-13 20:20:40 +00003333 set and 'cpoptions' is empty. When there is more than one
3334 match an empty string is returned.
3335 "" or "%" can be used for the current buffer, "#" for the
3336 alternate buffer.
3337 A full match is preferred, otherwise a match at the start, end
Bram Moolenaaref2f6562007-05-06 13:32:59 +00003338 or middle of the buffer name is accepted. If you only want a
3339 full match then put "^" at the start and "$" at the end of the
3340 pattern.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003341 Listed buffers are found first. If there is a single match
3342 with a listed buffer, that one is returned. Next unlisted
3343 buffers are searched for.
3344 If the {expr} is a String, but you want to use it as a buffer
3345 number, force it to be a Number by adding zero to it: >
3346 :echo bufname("3" + 0)
Bram Moolenaar073e4b92019-08-18 23:01:56 +02003347< Can also be used as a |method|: >
3348 echo bufnr->bufname()
3349
Bram Moolenaar071d4272004-06-13 20:20:40 +00003350< If the buffer doesn't exist, or doesn't have a name, an empty
3351 string is returned. >
3352 bufname("#") alternate buffer name
3353 bufname(3) name of buffer 3
3354 bufname("%") name of current buffer
3355 bufname("file2") name of buffer where "file2" matches.
3356< *buffer_name()*
3357 Obsolete name: buffer_name().
3358
3359 *bufnr()*
Bram Moolenaara8eee212019-08-24 22:14:58 +02003360bufnr([{expr} [, {create}]])
Bram Moolenaar65c923a2006-03-03 22:56:30 +00003361 The result is the number of a buffer, as it is displayed by
Bram Moolenaar071d4272004-06-13 20:20:40 +00003362 the ":ls" command. For the use of {expr}, see |bufname()|
Bram Moolenaar65c923a2006-03-03 22:56:30 +00003363 above.
Bram Moolenaard2842ea2019-09-26 23:08:54 +02003364
Bram Moolenaar65c923a2006-03-03 22:56:30 +00003365 If the buffer doesn't exist, -1 is returned. Or, if the
Bram Moolenaar1c6737b2020-09-07 22:18:52 +02003366 {create} argument is present and TRUE, a new, unlisted,
Bram Moolenaard2842ea2019-09-26 23:08:54 +02003367 buffer is created and its number is returned. Example: >
3368 let newbuf = bufnr('Scratch001', 1)
3369< Using an empty name uses the current buffer. To create a new
3370 buffer with an empty name use |bufadd()|.
3371
Bram Moolenaar071d4272004-06-13 20:20:40 +00003372 bufnr("$") is the last buffer: >
Bram Moolenaara8eee212019-08-24 22:14:58 +02003373 :let last_buffer = bufnr("$")
Bram Moolenaar071d4272004-06-13 20:20:40 +00003374< The result is a Number, which is the highest buffer number
3375 of existing buffers. Note that not all buffers with a smaller
3376 number necessarily exist, because ":bwipeout" may have removed
3377 them. Use bufexists() to test for the existence of a buffer.
Bram Moolenaar073e4b92019-08-18 23:01:56 +02003378
3379 Can also be used as a |method|: >
3380 echo bufref->bufnr()
3381<
3382 Obsolete name: buffer_number(). *buffer_number()*
Bram Moolenaar071d4272004-06-13 20:20:40 +00003383 *last_buffer_nr()*
3384 Obsolete name for bufnr("$"): last_buffer_nr().
3385
Bram Moolenaarb3619a92016-06-04 17:58:52 +02003386bufwinid({expr}) *bufwinid()*
Bram Moolenaar7571d552016-08-18 22:54:46 +02003387 The result is a Number, which is the |window-ID| of the first
Bram Moolenaarb3619a92016-06-04 17:58:52 +02003388 window associated with buffer {expr}. For the use of {expr},
Bram Moolenaar58b85342016-08-14 19:54:54 +02003389 see |bufname()| above. If buffer {expr} doesn't exist or
Bram Moolenaarb3619a92016-06-04 17:58:52 +02003390 there is no such window, -1 is returned. Example: >
3391
3392 echo "A window containing buffer 1 is " . (bufwinid(1))
3393<
3394 Only deals with the current tab page.
3395
Bram Moolenaare49fbff2019-08-21 22:50:07 +02003396 Can also be used as a |method|: >
3397 FindBuffer()->bufwinid()
3398
Bram Moolenaar071d4272004-06-13 20:20:40 +00003399bufwinnr({expr}) *bufwinnr()*
Bram Moolenaare49fbff2019-08-21 22:50:07 +02003400 Like |bufwinid()| but return the window number instead of the
3401 |window-ID|.
3402 If buffer {expr} doesn't exist or there is no such window, -1
3403 is returned. Example: >
Bram Moolenaar071d4272004-06-13 20:20:40 +00003404
3405 echo "A window containing buffer 1 is " . (bufwinnr(1))
3406
3407< The number can be used with |CTRL-W_w| and ":wincmd w"
3408 |:wincmd|.
Bram Moolenaare49fbff2019-08-21 22:50:07 +02003409
3410 Can also be used as a |method|: >
3411 FindBuffer()->bufwinnr()
Bram Moolenaar071d4272004-06-13 20:20:40 +00003412
Bram Moolenaar071d4272004-06-13 20:20:40 +00003413byte2line({byte}) *byte2line()*
3414 Return the line number that contains the character at byte
3415 count {byte} in the current buffer. This includes the
3416 end-of-line character, depending on the 'fileformat' option
3417 for the current buffer. The first character has byte count
3418 one.
3419 Also see |line2byte()|, |go| and |:goto|.
Bram Moolenaar64b4d732019-08-22 22:18:17 +02003420
3421 Can also be used as a |method|: >
3422 GetOffset()->byte2line()
3423
3424< {not available when compiled without the |+byte_offset|
Bram Moolenaar071d4272004-06-13 20:20:40 +00003425 feature}
3426
Bram Moolenaarab79bcb2004-07-18 21:34:53 +00003427byteidx({expr}, {nr}) *byteidx()*
3428 Return byte index of the {nr}'th character in the string
Bram Moolenaar6c53fca2020-08-23 17:34:46 +02003429 {expr}. Use zero for the first character, it then returns
3430 zero.
Bram Moolenaarab79bcb2004-07-18 21:34:53 +00003431 This function is only useful when there are multibyte
3432 characters, otherwise the returned value is equal to {nr}.
Bram Moolenaar0ffbbf92013-11-02 23:29:26 +01003433 Composing characters are not counted separately, their byte
3434 length is added to the preceding base character. See
3435 |byteidxcomp()| below for counting composing characters
3436 separately.
Bram Moolenaarab79bcb2004-07-18 21:34:53 +00003437 Example : >
3438 echo matchstr(str, ".", byteidx(str, 3))
3439< will display the fourth character. Another way to do the
3440 same: >
3441 let s = strpart(str, byteidx(str, 3))
3442 echo strpart(s, 0, byteidx(s, 1))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02003443< Also see |strgetchar()| and |strcharpart()|.
3444
3445 If there are less than {nr} characters -1 is returned.
Bram Moolenaarab79bcb2004-07-18 21:34:53 +00003446 If there are exactly {nr} characters the length of the string
Bram Moolenaar0ffbbf92013-11-02 23:29:26 +01003447 in bytes is returned.
3448
Bram Moolenaar64b4d732019-08-22 22:18:17 +02003449 Can also be used as a |method|: >
3450 GetName()->byteidx(idx)
3451
Bram Moolenaar0ffbbf92013-11-02 23:29:26 +01003452byteidxcomp({expr}, {nr}) *byteidxcomp()*
3453 Like byteidx(), except that a composing character is counted
3454 as a separate character. Example: >
3455 let s = 'e' . nr2char(0x301)
3456 echo byteidx(s, 1)
3457 echo byteidxcomp(s, 1)
3458 echo byteidxcomp(s, 2)
3459< The first and third echo result in 3 ('e' plus composing
3460 character is 3 bytes), the second echo results in 1 ('e' is
3461 one byte).
3462 Only works different from byteidx() when 'encoding' is set to
3463 a Unicode encoding.
Bram Moolenaarab79bcb2004-07-18 21:34:53 +00003464
Bram Moolenaar64b4d732019-08-22 22:18:17 +02003465 Can also be used as a |method|: >
3466 GetName()->byteidxcomp(idx)
3467
Bram Moolenaar2fda12f2005-01-15 22:14:15 +00003468call({func}, {arglist} [, {dict}]) *call()* *E699*
Bram Moolenaar32466aa2006-02-24 23:53:04 +00003469 Call function {func} with the items in |List| {arglist} as
Bram Moolenaarde8866b2005-01-06 23:24:37 +00003470 arguments.
Bram Moolenaar32466aa2006-02-24 23:53:04 +00003471 {func} can either be a |Funcref| or the name of a function.
Bram Moolenaarde8866b2005-01-06 23:24:37 +00003472 a:firstline and a:lastline are set to the cursor line.
3473 Returns the return value of the called function.
Bram Moolenaar2fda12f2005-01-15 22:14:15 +00003474 {dict} is for functions with the "dict" attribute. It will be
3475 used to set the local variable "self". |Dictionary-function|
Bram Moolenaarde8866b2005-01-06 23:24:37 +00003476
Bram Moolenaar64b4d732019-08-22 22:18:17 +02003477 Can also be used as a |method|: >
3478 GetFunc()->call([arg, arg], dict)
3479
Bram Moolenaar446cb832008-06-24 21:56:24 +00003480ceil({expr}) *ceil()*
3481 Return the smallest integral value greater than or equal to
3482 {expr} as a |Float| (round up).
3483 {expr} must evaluate to a |Float| or a |Number|.
3484 Examples: >
3485 echo ceil(1.456)
3486< 2.0 >
3487 echo ceil(-5.456)
3488< -5.0 >
3489 echo ceil(4.0)
3490< 4.0
Bram Moolenaar93cf85f2019-08-17 21:36:28 +02003491
3492 Can also be used as a |method|: >
3493 Compute()->ceil()
3494<
Bram Moolenaar446cb832008-06-24 21:56:24 +00003495 {only available when compiled with the |+float| feature}
3496
Bram Moolenaar4b785f62016-11-29 21:54:44 +01003497
Bram Moolenaared997ad2019-07-21 16:42:00 +02003498ch_ functions are documented here: |channel-functions-details|
Bram Moolenaar82b9ca02017-08-08 23:06:46 +02003499
Bram Moolenaar328da0d2016-03-04 22:22:32 +01003500
Bram Moolenaar214641f2017-03-05 17:04:09 +01003501changenr() *changenr()*
3502 Return the number of the most recent change. This is the same
3503 number as what is displayed with |:undolist| and can be used
3504 with the |:undo| command.
3505 When a change was made it is the number of that change. After
3506 redo it is the number of the redone change. After undo it is
3507 one less than the number of the undone change.
3508
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01003509char2nr({expr} [, {utf8}]) *char2nr()*
Bram Moolenaar214641f2017-03-05 17:04:09 +01003510 Return number value of the first char in {expr}. Examples: >
3511 char2nr(" ") returns 32
3512 char2nr("ABC") returns 65
3513< When {utf8} is omitted or zero, the current 'encoding' is used.
3514 Example for "utf-8": >
Bram Moolenaar98ef2332018-03-18 14:44:37 +01003515 char2nr("á") returns 225
3516 char2nr("á"[0]) returns 195
Bram Moolenaar1c6737b2020-09-07 22:18:52 +02003517< With {utf8} set to TRUE, always treat as utf-8 characters.
Bram Moolenaar214641f2017-03-05 17:04:09 +01003518 A combining character is a separate character.
3519 |nr2char()| does the opposite.
Bram Moolenaaraff74912019-03-30 18:11:49 +01003520 To turn a string into a list of character numbers: >
3521 let str = "ABC"
3522 let list = map(split(str, '\zs'), {_, val -> char2nr(val)})
3523< Result: [65, 66, 67]
Bram Moolenaar214641f2017-03-05 17:04:09 +01003524
Bram Moolenaar1a3a8912019-08-23 22:31:37 +02003525 Can also be used as a |method|: >
3526 GetChar()->char2nr()
3527
Bram Moolenaar4e4473c2020-08-28 22:24:57 +02003528
3529charclass({string}) *charclass()*
3530 Return the character class of the first character in {string}.
3531 The character class is one of:
3532 0 blank
3533 1 punctuation
3534 2 word character
3535 3 emoji
3536 other specific Unicode class
3537 The class is used in patterns and word motions.
3538
3539
Bram Moolenaar1063f3d2019-05-07 22:06:52 +02003540chdir({dir}) *chdir()*
3541 Change the current working directory to {dir}. The scope of
3542 the directory change depends on the directory of the current
3543 window:
3544 - If the current window has a window-local directory
3545 (|:lcd|), then changes the window local directory.
3546 - Otherwise, if the current tabpage has a local
3547 directory (|:tcd|) then changes the tabpage local
3548 directory.
3549 - Otherwise, changes the global directory.
Bram Moolenaar560979e2020-02-04 22:53:05 +01003550 {dir} must be a String.
Bram Moolenaar1063f3d2019-05-07 22:06:52 +02003551 If successful, returns the previous working directory. Pass
3552 this to another chdir() to restore the directory.
3553 On failure, returns an empty string.
3554
3555 Example: >
3556 let save_dir = chdir(newdir)
Bram Moolenaar68e65602019-05-26 21:33:31 +02003557 if save_dir != ""
Bram Moolenaar1063f3d2019-05-07 22:06:52 +02003558 " ... do some work
3559 call chdir(save_dir)
3560 endif
Bram Moolenaar1a3a8912019-08-23 22:31:37 +02003561
3562< Can also be used as a |method|: >
3563 GetDir()->chdir()
Bram Moolenaar1063f3d2019-05-07 22:06:52 +02003564<
Bram Moolenaar214641f2017-03-05 17:04:09 +01003565cindent({lnum}) *cindent()*
3566 Get the amount of indent for line {lnum} according the C
3567 indenting rules, as with 'cindent'.
3568 The indent is counted in spaces, the value of 'tabstop' is
3569 relevant. {lnum} is used just like in |getline()|.
3570 When {lnum} is invalid or Vim was not compiled the |+cindent|
3571 feature, -1 is returned.
3572 See |C-indenting|.
3573
Bram Moolenaar1a3a8912019-08-23 22:31:37 +02003574 Can also be used as a |method|: >
3575 GetLnum()->cindent()
3576
Bram Moolenaaraff74912019-03-30 18:11:49 +01003577clearmatches([{win}]) *clearmatches()*
Bram Moolenaarfd133322019-03-29 12:20:27 +01003578 Clears all matches previously defined for the current window
3579 by |matchadd()| and the |:match| commands.
Bram Moolenaaraff74912019-03-30 18:11:49 +01003580 If {win} is specified, use the window with this number or
3581 window ID instead of the current window.
Bram Moolenaar214641f2017-03-05 17:04:09 +01003582
Bram Moolenaar1a3a8912019-08-23 22:31:37 +02003583 Can also be used as a |method|: >
3584 GetWin()->clearmatches()
3585<
Bram Moolenaar214641f2017-03-05 17:04:09 +01003586 *col()*
3587col({expr}) The result is a Number, which is the byte index of the column
3588 position given with {expr}. The accepted positions are:
3589 . the cursor position
3590 $ the end of the cursor line (the result is the
3591 number of bytes in the cursor line plus one)
3592 'x position of mark x (if the mark is not set, 0 is
3593 returned)
3594 v In Visual mode: the start of the Visual area (the
3595 cursor is the end). When not in Visual mode
3596 returns the cursor position. Differs from |'<| in
3597 that it's updated right away.
3598 Additionally {expr} can be [lnum, col]: a |List| with the line
3599 and column number. Most useful when the column is "$", to get
3600 the last column of a specific line. When "lnum" or "col" is
3601 out of range then col() returns zero.
3602 To get the line number use |line()|. To get both use
3603 |getpos()|.
3604 For the screen column position use |virtcol()|.
3605 Note that only marks in the current file can be used.
3606 Examples: >
3607 col(".") column of cursor
3608 col("$") length of cursor line plus one
3609 col("'t") column of mark t
3610 col("'" . markname) column of mark markname
3611< The first column is 1. 0 is returned for an error.
3612 For an uppercase mark the column may actually be in another
3613 buffer.
3614 For the cursor position, when 'virtualedit' is active, the
3615 column is one higher if the cursor is after the end of the
3616 line. This can be used to obtain the column in Insert mode: >
3617 :imap <F2> <C-O>:let save_ve = &ve<CR>
3618 \<C-O>:set ve=all<CR>
3619 \<C-O>:echo col(".") . "\n" <Bar>
3620 \let &ve = save_ve<CR>
Bram Moolenaar1a3a8912019-08-23 22:31:37 +02003621
3622< Can also be used as a |method|: >
3623 GetPos()->col()
Bram Moolenaar214641f2017-03-05 17:04:09 +01003624<
3625
3626complete({startcol}, {matches}) *complete()* *E785*
3627 Set the matches for Insert mode completion.
3628 Can only be used in Insert mode. You need to use a mapping
3629 with CTRL-R = (see |i_CTRL-R|). It does not work after CTRL-O
3630 or with an expression mapping.
3631 {startcol} is the byte offset in the line where the completed
3632 text start. The text up to the cursor is the original text
3633 that will be replaced by the matches. Use col('.') for an
3634 empty string. "col('.') - 1" will replace one character by a
3635 match.
3636 {matches} must be a |List|. Each |List| item is one match.
3637 See |complete-items| for the kind of items that are possible.
3638 Note that the after calling this function you need to avoid
3639 inserting anything that would cause completion to stop.
3640 The match can be selected with CTRL-N and CTRL-P as usual with
3641 Insert mode completion. The popup menu will appear if
3642 specified, see |ins-completion-menu|.
3643 Example: >
3644 inoremap <F5> <C-R>=ListMonths()<CR>
3645
3646 func! ListMonths()
3647 call complete(col('.'), ['January', 'February', 'March',
3648 \ 'April', 'May', 'June', 'July', 'August', 'September',
3649 \ 'October', 'November', 'December'])
3650 return ''
3651 endfunc
3652< This isn't very useful, but it shows how it works. Note that
3653 an empty string is returned to avoid a zero being inserted.
3654
Bram Moolenaar2e693a82019-10-16 22:35:02 +02003655 Can also be used as a |method|, the base is passed as the
3656 second argument: >
Bram Moolenaar1a3a8912019-08-23 22:31:37 +02003657 GetMatches()->complete(col('.'))
3658
Bram Moolenaar214641f2017-03-05 17:04:09 +01003659complete_add({expr}) *complete_add()*
3660 Add {expr} to the list of matches. Only to be used by the
3661 function specified with the 'completefunc' option.
3662 Returns 0 for failure (empty string or out of memory),
3663 1 when the match was added, 2 when the match was already in
3664 the list.
3665 See |complete-functions| for an explanation of {expr}. It is
3666 the same as one item in the list that 'omnifunc' would return.
3667
Bram Moolenaar1a3a8912019-08-23 22:31:37 +02003668 Can also be used as a |method|: >
3669 GetMoreMatches()->complete_add()
3670
Bram Moolenaar214641f2017-03-05 17:04:09 +01003671complete_check() *complete_check()*
3672 Check for a key typed while looking for completion matches.
3673 This is to be used when looking for matches takes some time.
3674 Returns |TRUE| when searching for matches is to be aborted,
3675 zero otherwise.
3676 Only to be used by the function specified with the
3677 'completefunc' option.
3678
Bram Moolenaarfd133322019-03-29 12:20:27 +01003679 *complete_info()*
3680complete_info([{what}])
Bram Moolenaare46a4402020-06-30 20:38:27 +02003681 Returns a |Dictionary| with information about Insert mode
Bram Moolenaarfd133322019-03-29 12:20:27 +01003682 completion. See |ins-completion|.
3683 The items are:
3684 mode Current completion mode name string.
Bram Moolenaar723dd942019-04-04 13:11:03 +02003685 See |complete_info_mode| for the values.
Bram Moolenaarfd133322019-03-29 12:20:27 +01003686 pum_visible |TRUE| if popup menu is visible.
3687 See |pumvisible()|.
3688 items List of completion matches. Each item is a
3689 dictionary containing the entries "word",
3690 "abbr", "menu", "kind", "info" and "user_data".
3691 See |complete-items|.
3692 selected Selected item index. First index is zero.
3693 Index is -1 if no item is selected (showing
3694 typed text only)
3695 inserted Inserted string. [NOT IMPLEMENT YET]
3696
3697 *complete_info_mode*
3698 mode values are:
3699 "" Not in completion mode
3700 "keyword" Keyword completion |i_CTRL-X_CTRL-N|
3701 "ctrl_x" Just pressed CTRL-X |i_CTRL-X|
3702 "whole_line" Whole lines |i_CTRL-X_CTRL-L|
3703 "files" File names |i_CTRL-X_CTRL-F|
3704 "tags" Tags |i_CTRL-X_CTRL-]|
3705 "path_defines" Definition completion |i_CTRL-X_CTRL-D|
3706 "path_patterns" Include completion |i_CTRL-X_CTRL-I|
3707 "dictionary" Dictionary |i_CTRL-X_CTRL-K|
3708 "thesaurus" Thesaurus |i_CTRL-X_CTRL-T|
3709 "cmdline" Vim Command line |i_CTRL-X_CTRL-V|
3710 "function" User defined completion |i_CTRL-X_CTRL-U|
3711 "omni" Omni completion |i_CTRL-X_CTRL-O|
3712 "spell" Spelling suggestions |i_CTRL-X_s|
Bram Moolenaar73fef332020-06-21 22:12:03 +02003713 "eval" |complete()| completion
Bram Moolenaarfd133322019-03-29 12:20:27 +01003714 "unknown" Other internal modes
3715
3716 If the optional {what} list argument is supplied, then only
3717 the items listed in {what} are returned. Unsupported items in
3718 {what} are silently ignored.
3719
Bram Moolenaare9bd5722019-08-17 19:36:06 +02003720 To get the position and size of the popup menu, see
3721 |pum_getpos()|. It's also available in |v:event| during the
3722 |CompleteChanged| event.
3723
Bram Moolenaarfd133322019-03-29 12:20:27 +01003724 Examples: >
3725 " Get all items
3726 call complete_info()
3727 " Get only 'mode'
3728 call complete_info(['mode'])
3729 " Get only 'mode' and 'pum_visible'
3730 call complete_info(['mode', 'pum_visible'])
Bram Moolenaar1a3a8912019-08-23 22:31:37 +02003731
3732< Can also be used as a |method|: >
3733 GetItems()->complete_info()
Bram Moolenaarfd133322019-03-29 12:20:27 +01003734<
Bram Moolenaar214641f2017-03-05 17:04:09 +01003735 *confirm()*
3736confirm({msg} [, {choices} [, {default} [, {type}]]])
Bram Moolenaar647e24b2019-03-17 16:39:46 +01003737 confirm() offers the user a dialog, from which a choice can be
Bram Moolenaar214641f2017-03-05 17:04:09 +01003738 made. It returns the number of the choice. For the first
3739 choice this is 1.
3740 Note: confirm() is only supported when compiled with dialog
3741 support, see |+dialog_con| and |+dialog_gui|.
3742
3743 {msg} is displayed in a |dialog| with {choices} as the
3744 alternatives. When {choices} is missing or empty, "&OK" is
3745 used (and translated).
3746 {msg} is a String, use '\n' to include a newline. Only on
3747 some systems the string is wrapped when it doesn't fit.
3748
3749 {choices} is a String, with the individual choices separated
3750 by '\n', e.g. >
3751 confirm("Save changes?", "&Yes\n&No\n&Cancel")
3752< The letter after the '&' is the shortcut key for that choice.
3753 Thus you can type 'c' to select "Cancel". The shortcut does
3754 not need to be the first letter: >
3755 confirm("file has been modified", "&Save\nSave &All")
3756< For the console, the first letter of each choice is used as
3757 the default shortcut key.
3758
3759 The optional {default} argument is the number of the choice
3760 that is made if the user hits <CR>. Use 1 to make the first
3761 choice the default one. Use 0 to not set a default. If
3762 {default} is omitted, 1 is used.
3763
3764 The optional {type} argument gives the type of dialog. This
3765 is only used for the icon of the GTK, Mac, Motif and Win32
3766 GUI. It can be one of these values: "Error", "Question",
3767 "Info", "Warning" or "Generic". Only the first character is
3768 relevant. When {type} is omitted, "Generic" is used.
3769
3770 If the user aborts the dialog by pressing <Esc>, CTRL-C,
3771 or another valid interrupt key, confirm() returns 0.
3772
3773 An example: >
3774 :let choice = confirm("What do you want?", "&Apples\n&Oranges\n&Bananas", 2)
3775 :if choice == 0
3776 : echo "make up your mind!"
3777 :elseif choice == 3
3778 : echo "tasteful"
3779 :else
3780 : echo "I prefer bananas myself."
3781 :endif
3782< In a GUI dialog, buttons are used. The layout of the buttons
3783 depends on the 'v' flag in 'guioptions'. If it is included,
3784 the buttons are always put vertically. Otherwise, confirm()
3785 tries to put the buttons in one horizontal line. If they
3786 don't fit, a vertical layout is used anyway. For some systems
3787 the horizontal layout is always used.
3788
Bram Moolenaar1a3a8912019-08-23 22:31:37 +02003789 Can also be used as a |method|in: >
3790 BuildMessage()->confirm("&Yes\n&No")
Bram Moolenaar2e693a82019-10-16 22:35:02 +02003791<
Bram Moolenaard7ee7ce2005-01-03 21:02:03 +00003792 *copy()*
Bram Moolenaar58b85342016-08-14 19:54:54 +02003793copy({expr}) Make a copy of {expr}. For Numbers and Strings this isn't
Bram Moolenaard7ee7ce2005-01-03 21:02:03 +00003794 different from using {expr} directly.
Bram Moolenaar32466aa2006-02-24 23:53:04 +00003795 When {expr} is a |List| a shallow copy is created. This means
3796 that the original |List| can be changed without changing the
Bram Moolenaar446cb832008-06-24 21:56:24 +00003797 copy, and vice versa. But the items are identical, thus
Bram Moolenaar7823a3b2016-02-11 21:08:32 +01003798 changing an item changes the contents of both |Lists|.
3799 A |Dictionary| is copied in a similar way as a |List|.
3800 Also see |deepcopy()|.
Bram Moolenaarac92e252019-08-03 21:58:38 +02003801 Can also be used as a |method|: >
3802 mylist->copy()
Bram Moolenaard7ee7ce2005-01-03 21:02:03 +00003803
Bram Moolenaar446cb832008-06-24 21:56:24 +00003804cos({expr}) *cos()*
3805 Return the cosine of {expr}, measured in radians, as a |Float|.
3806 {expr} must evaluate to a |Float| or a |Number|.
3807 Examples: >
3808 :echo cos(100)
3809< 0.862319 >
3810 :echo cos(-4.01)
3811< -0.646043
Bram Moolenaar93cf85f2019-08-17 21:36:28 +02003812
3813 Can also be used as a |method|: >
3814 Compute()->cos()
3815<
Bram Moolenaar446cb832008-06-24 21:56:24 +00003816 {only available when compiled with the |+float| feature}
3817
Bram Moolenaardb7c6862010-05-21 16:33:48 +02003818
3819cosh({expr}) *cosh()*
Bram Moolenaar9855d6b2010-07-18 14:34:51 +02003820 Return the hyperbolic cosine of {expr} as a |Float| in the range
Bram Moolenaardb7c6862010-05-21 16:33:48 +02003821 [1, inf].
Bram Moolenaar9855d6b2010-07-18 14:34:51 +02003822 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaardb7c6862010-05-21 16:33:48 +02003823 Examples: >
3824 :echo cosh(0.5)
3825< 1.127626 >
3826 :echo cosh(-0.5)
3827< -1.127626
Bram Moolenaar93cf85f2019-08-17 21:36:28 +02003828
3829 Can also be used as a |method|: >
3830 Compute()->cosh()
3831<
Bram Moolenaardb84e452010-08-15 13:50:43 +02003832 {only available when compiled with the |+float| feature}
Bram Moolenaardb7c6862010-05-21 16:33:48 +02003833
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01003834
Bram Moolenaar2fda12f2005-01-15 22:14:15 +00003835count({comp}, {expr} [, {ic} [, {start}]]) *count()*
Bram Moolenaarde8866b2005-01-06 23:24:37 +00003836 Return the number of times an item with value {expr} appears
Bram Moolenaar9966b212017-07-28 16:46:57 +02003837 in |String|, |List| or |Dictionary| {comp}.
3838
Bram Moolenaar2fda12f2005-01-15 22:14:15 +00003839 If {start} is given then start with the item with this index.
Bram Moolenaar32466aa2006-02-24 23:53:04 +00003840 {start} can only be used with a |List|.
Bram Moolenaar9966b212017-07-28 16:46:57 +02003841
Bram Moolenaare381d3d2016-07-07 14:50:41 +02003842 When {ic} is given and it's |TRUE| then case is ignored.
Bram Moolenaarde8866b2005-01-06 23:24:37 +00003843
Bram Moolenaar9966b212017-07-28 16:46:57 +02003844 When {comp} is a string then the number of not overlapping
Bram Moolenaar338e47f2017-12-19 11:55:26 +01003845 occurrences of {expr} is returned. Zero is returned when
3846 {expr} is an empty string.
Bram Moolenaara74e4942019-08-04 17:35:53 +02003847
Bram Moolenaarac92e252019-08-03 21:58:38 +02003848 Can also be used as a |method|: >
3849 mylist->count(val)
Bram Moolenaara74e4942019-08-04 17:35:53 +02003850<
Bram Moolenaar071d4272004-06-13 20:20:40 +00003851 *cscope_connection()*
3852cscope_connection([{num} , {dbpath} [, {prepend}]])
3853 Checks for the existence of a |cscope| connection. If no
3854 parameters are specified, then the function returns:
3855 0, if cscope was not available (not compiled in), or
3856 if there are no cscope connections;
3857 1, if there is at least one cscope connection.
3858
3859 If parameters are specified, then the value of {num}
3860 determines how existence of a cscope connection is checked:
3861
3862 {num} Description of existence check
3863 ----- ------------------------------
3864 0 Same as no parameters (e.g., "cscope_connection()").
3865 1 Ignore {prepend}, and use partial string matches for
3866 {dbpath}.
3867 2 Ignore {prepend}, and use exact string matches for
3868 {dbpath}.
3869 3 Use {prepend}, use partial string matches for both
3870 {dbpath} and {prepend}.
3871 4 Use {prepend}, use exact string matches for both
3872 {dbpath} and {prepend}.
3873
3874 Note: All string comparisons are case sensitive!
3875
3876 Examples. Suppose we had the following (from ":cs show"): >
3877
3878 # pid database name prepend path
3879 0 27664 cscope.out /usr/local
3880<
3881 Invocation Return Val ~
3882 ---------- ---------- >
3883 cscope_connection() 1
3884 cscope_connection(1, "out") 1
3885 cscope_connection(2, "out") 0
3886 cscope_connection(3, "out") 0
3887 cscope_connection(3, "out", "local") 1
3888 cscope_connection(4, "out") 0
3889 cscope_connection(4, "out", "local") 0
3890 cscope_connection(4, "cscope.out", "/usr/local") 1
3891<
Bram Moolenaar0b238792006-03-02 22:49:12 +00003892cursor({lnum}, {col} [, {off}]) *cursor()*
3893cursor({list})
Bram Moolenaaref2f6562007-05-06 13:32:59 +00003894 Positions the cursor at the column (byte count) {col} in the
3895 line {lnum}. The first column is one.
Bram Moolenaar493c1782014-05-28 14:34:46 +02003896
Bram Moolenaar0b238792006-03-02 22:49:12 +00003897 When there is one argument {list} this is used as a |List|
Bram Moolenaar493c1782014-05-28 14:34:46 +02003898 with two, three or four item:
Bram Moolenaar03413f42016-04-12 21:07:15 +02003899 [{lnum}, {col}]
Bram Moolenaar493c1782014-05-28 14:34:46 +02003900 [{lnum}, {col}, {off}]
3901 [{lnum}, {col}, {off}, {curswant}]
Bram Moolenaar946e27a2014-06-25 18:50:27 +02003902 This is like the return value of |getpos()| or |getcurpos()|,
Bram Moolenaar6f6c0f82014-05-28 20:31:42 +02003903 but without the first item.
Bram Moolenaar493c1782014-05-28 14:34:46 +02003904
Bram Moolenaar071d4272004-06-13 20:20:40 +00003905 Does not change the jumplist.
3906 If {lnum} is greater than the number of lines in the buffer,
3907 the cursor will be positioned at the last line in the buffer.
3908 If {lnum} is zero, the cursor will stay in the current line.
Bram Moolenaar6f16eb82005-08-23 21:02:42 +00003909 If {col} is greater than the number of bytes in the line,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003910 the cursor will be positioned at the last character in the
3911 line.
3912 If {col} is zero, the cursor will stay in the current column.
Bram Moolenaar6f6c0f82014-05-28 20:31:42 +02003913 If {curswant} is given it is used to set the preferred column
Bram Moolenaar34401cc2014-08-29 15:12:19 +02003914 for vertical movement. Otherwise {col} is used.
Bram Moolenaar2f3b5102014-11-19 18:54:17 +01003915
Bram Moolenaar0b238792006-03-02 22:49:12 +00003916 When 'virtualedit' is used {off} specifies the offset in
3917 screen columns from the start of the character. E.g., a
Bram Moolenaard46bbc72007-05-12 14:38:41 +00003918 position within a <Tab> or after the last character.
Bram Moolenaar798b30b2009-04-22 10:56:16 +00003919 Returns 0 when the position could be set, -1 otherwise.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003920
Bram Moolenaar1a3a8912019-08-23 22:31:37 +02003921 Can also be used as a |method|: >
3922 GetCursorPos()->cursor()
3923
Bram Moolenaar4551c0a2018-06-20 22:38:21 +02003924debugbreak({pid}) *debugbreak()*
3925 Specifically used to interrupt a program being debugged. It
3926 will cause process {pid} to get a SIGTRAP. Behavior for other
3927 processes is undefined. See |terminal-debugger|.
3928 {only available on MS-Windows}
Bram Moolenaard7ee7ce2005-01-03 21:02:03 +00003929
Bram Moolenaar1a3a8912019-08-23 22:31:37 +02003930 Can also be used as a |method|: >
3931 GetPid()->debugbreak()
3932
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01003933deepcopy({expr} [, {noref}]) *deepcopy()* *E698*
Bram Moolenaar58b85342016-08-14 19:54:54 +02003934 Make a copy of {expr}. For Numbers and Strings this isn't
Bram Moolenaard7ee7ce2005-01-03 21:02:03 +00003935 different from using {expr} directly.
Bram Moolenaar32466aa2006-02-24 23:53:04 +00003936 When {expr} is a |List| a full copy is created. This means
3937 that the original |List| can be changed without changing the
Bram Moolenaar6463ca22016-02-13 17:04:46 +01003938 copy, and vice versa. When an item is a |List| or
3939 |Dictionary|, a copy for it is made, recursively. Thus
3940 changing an item in the copy does not change the contents of
3941 the original |List|.
3942 A |Dictionary| is copied in a similar way as a |List|.
Bram Moolenaar7ff78462020-07-10 22:00:53 +02003943
Bram Moolenaar32466aa2006-02-24 23:53:04 +00003944 When {noref} is omitted or zero a contained |List| or
3945 |Dictionary| is only copied once. All references point to
3946 this single copy. With {noref} set to 1 every occurrence of a
3947 |List| or |Dictionary| results in a new copy. This also means
3948 that a cyclic reference causes deepcopy() to fail.
Bram Moolenaar3a3a7232005-01-17 22:16:15 +00003949 *E724*
3950 Nesting is possible up to 100 levels. When there is an item
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003951 that refers back to a higher level making a deep copy with
3952 {noref} set to 1 will fail.
Bram Moolenaard7ee7ce2005-01-03 21:02:03 +00003953 Also see |copy()|.
3954
Bram Moolenaar1a3a8912019-08-23 22:31:37 +02003955 Can also be used as a |method|: >
3956 GetObject()->deepcopy()
3957
Bram Moolenaarda440d22016-01-16 21:27:23 +01003958delete({fname} [, {flags}]) *delete()*
3959 Without {flags} or with {flags} empty: Deletes the file by the
Bram Moolenaar43a34f92016-01-17 15:56:34 +01003960 name {fname}. This also works when {fname} is a symbolic link.
Bram Moolenaarda440d22016-01-16 21:27:23 +01003961
3962 When {flags} is "d": Deletes the directory by the name
Bram Moolenaar43a34f92016-01-17 15:56:34 +01003963 {fname}. This fails when directory {fname} is not empty.
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01003964
Bram Moolenaarda440d22016-01-16 21:27:23 +01003965 When {flags} is "rf": Deletes the directory by the name
Bram Moolenaar43a34f92016-01-17 15:56:34 +01003966 {fname} and everything in it, recursively. BE CAREFUL!
Bram Moolenaar36f44c22016-08-28 18:17:20 +02003967 Note: on MS-Windows it is not possible to delete a directory
3968 that is being used.
Bram Moolenaar818078d2016-08-27 21:58:42 +02003969
Bram Moolenaar43a34f92016-01-17 15:56:34 +01003970 A symbolic link itself is deleted, not what it points to.
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01003971
Bram Moolenaarda440d22016-01-16 21:27:23 +01003972 The result is a Number, which is 0 if the delete operation was
3973 successful and -1 when the deletion failed or partly failed.
3974
Bram Moolenaar32466aa2006-02-24 23:53:04 +00003975 Use |remove()| to delete an item from a |List|.
Bram Moolenaard79a2622018-06-07 18:17:46 +02003976 To delete a line from the buffer use |:delete| or
3977 |deletebufline()|.
3978
Bram Moolenaar1a3a8912019-08-23 22:31:37 +02003979 Can also be used as a |method|: >
3980 GetName()->delete()
3981
Bram Moolenaard473c8c2018-08-11 18:00:22 +02003982deletebufline({expr}, {first} [, {last}]) *deletebufline()*
Bram Moolenaard79a2622018-06-07 18:17:46 +02003983 Delete lines {first} to {last} (inclusive) from buffer {expr}.
3984 If {last} is omitted then delete line {first} only.
3985 On success 0 is returned, on failure 1 is returned.
3986
Bram Moolenaar2e693a82019-10-16 22:35:02 +02003987 This function works only for loaded buffers. First call
3988 |bufload()| if needed.
3989
Bram Moolenaard79a2622018-06-07 18:17:46 +02003990 For the use of {expr}, see |bufname()| above.
3991
Bram Moolenaar95bafa22018-10-02 13:26:25 +02003992 {first} and {last} are used like with |getline()|. Note that
Bram Moolenaard79a2622018-06-07 18:17:46 +02003993 when using |line()| this refers to the current buffer. Use "$"
3994 to refer to the last line in buffer {expr}.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003995
Bram Moolenaar1a3a8912019-08-23 22:31:37 +02003996 Can also be used as a |method|: >
3997 GetBuffer()->deletebufline(1)
Bram Moolenaar2e693a82019-10-16 22:35:02 +02003998<
Bram Moolenaar071d4272004-06-13 20:20:40 +00003999 *did_filetype()*
Bram Moolenaare381d3d2016-07-07 14:50:41 +02004000did_filetype() Returns |TRUE| when autocommands are being executed and the
Bram Moolenaar071d4272004-06-13 20:20:40 +00004001 FileType event has been triggered at least once. Can be used
4002 to avoid triggering the FileType event again in the scripts
4003 that detect the file type. |FileType|
Bram Moolenaar6aa8cea2017-06-05 14:44:35 +02004004 Returns |FALSE| when `:setf FALLBACK` was used.
Bram Moolenaar071d4272004-06-13 20:20:40 +00004005 When editing another file, the counter is reset, thus this
4006 really checks if the FileType event has been triggered for the
4007 current buffer. This allows an autocommand that starts
4008 editing another buffer to set 'filetype' and load a syntax
4009 file.
4010
Bram Moolenaar47136d72004-10-12 20:02:24 +00004011diff_filler({lnum}) *diff_filler()*
4012 Returns the number of filler lines above line {lnum}.
4013 These are the lines that were inserted at this point in
4014 another diff'ed window. These filler lines are shown in the
4015 display but don't exist in the buffer.
4016 {lnum} is used like with |getline()|. Thus "." is the current
4017 line, "'m" mark m, etc.
4018 Returns 0 if the current window is not in diff mode.
4019
Bram Moolenaar1a3a8912019-08-23 22:31:37 +02004020 Can also be used as a |method|: >
4021 GetLnum()->diff_filler()
4022
Bram Moolenaar47136d72004-10-12 20:02:24 +00004023diff_hlID({lnum}, {col}) *diff_hlID()*
4024 Returns the highlight ID for diff mode at line {lnum} column
4025 {col} (byte index). When the current line does not have a
4026 diff change zero is returned.
4027 {lnum} is used like with |getline()|. Thus "." is the current
4028 line, "'m" mark m, etc.
4029 {col} is 1 for the leftmost column, {lnum} is 1 for the first
4030 line.
4031 The highlight ID can be used with |synIDattr()| to obtain
4032 syntax information about the highlighting.
4033
Bram Moolenaar1a3a8912019-08-23 22:31:37 +02004034 Can also be used as a |method|: >
4035 GetLnum()->diff_hlID(col)
Bram Moolenaar691ddee2019-05-09 14:52:41 +02004036
Bram Moolenaar4132eb52020-02-14 16:53:00 +01004037
4038echoraw({expr}) *echoraw()*
4039 Output {expr} as-is, including unprintable characters. This
4040 can be used to output a terminal code. For example, to disable
4041 modifyOtherKeys: >
4042 call echoraw(&t_TE)
4043< and to enable it again: >
4044 call echoraw(&t_TI)
4045< Use with care, you can mess up the terminal this way.
4046
4047
Bram Moolenaar13065c42005-01-08 16:08:21 +00004048empty({expr}) *empty()*
4049 Return the Number 1 if {expr} is empty, zero otherwise.
Bram Moolenaar835dc632016-02-07 14:27:38 +01004050 - A |List| or |Dictionary| is empty when it does not have any
4051 items.
Bram Moolenaard8968242019-01-15 22:51:57 +01004052 - A |String| is empty when its length is zero.
4053 - A |Number| and |Float| are empty when their value is zero.
Bram Moolenaar835dc632016-02-07 14:27:38 +01004054 - |v:false|, |v:none| and |v:null| are empty, |v:true| is not.
Bram Moolenaard8968242019-01-15 22:51:57 +01004055 - A |Job| is empty when it failed to start.
4056 - A |Channel| is empty when it is closed.
Bram Moolenaard09091d2019-01-17 16:07:22 +01004057 - A |Blob| is empty when its length is zero.
Bram Moolenaar835dc632016-02-07 14:27:38 +01004058
Bram Moolenaar8f3f58f2010-01-06 20:52:26 +01004059 For a long |List| this is much faster than comparing the
Bram Moolenaar32466aa2006-02-24 23:53:04 +00004060 length with zero.
Bram Moolenaara4208962019-08-24 20:50:19 +02004061
Bram Moolenaarac92e252019-08-03 21:58:38 +02004062 Can also be used as a |method|: >
4063 mylist->empty()
Bram Moolenaar13065c42005-01-08 16:08:21 +00004064
Bram Moolenaar29634562020-01-09 21:46:04 +01004065environ() *environ()*
4066 Return all of environment variables as dictionary. You can
4067 check if an environment variable exists like this: >
4068 :echo has_key(environ(), 'HOME')
4069< Note that the variable name may be CamelCase; to ignore case
4070 use this: >
4071 :echo index(keys(environ()), 'HOME', 0, 1) != -1
4072
Bram Moolenaar071d4272004-06-13 20:20:40 +00004073escape({string}, {chars}) *escape()*
4074 Escape the characters in {chars} that occur in {string} with a
4075 backslash. Example: >
4076 :echo escape('c:\program files\vim', ' \')
4077< results in: >
4078 c:\\program\ files\\vim
Bram Moolenaarb4d5fba2017-09-11 19:31:28 +02004079< Also see |shellescape()| and |fnameescape()|.
Bram Moolenaar5f2bb9f2005-01-11 21:29:04 +00004080
Bram Moolenaara4208962019-08-24 20:50:19 +02004081 Can also be used as a |method|: >
4082 GetText()->escape(' \')
4083<
Bram Moolenaar446cb832008-06-24 21:56:24 +00004084 *eval()*
Bram Moolenaar5f2bb9f2005-01-11 21:29:04 +00004085eval({string}) Evaluate {string} and return the result. Especially useful to
4086 turn the result of |string()| back into the original value.
Bram Moolenaar0d17f0d2019-01-22 22:20:38 +01004087 This works for Numbers, Floats, Strings, Blobs and composites
4088 of them. Also works for |Funcref|s that refer to existing
Bram Moolenaar446cb832008-06-24 21:56:24 +00004089 functions.
Bram Moolenaar5f2bb9f2005-01-11 21:29:04 +00004090
Bram Moolenaar25e42232019-08-04 15:04:10 +02004091 Can also be used as a |method|: >
4092 argv->join()->eval()
4093
Bram Moolenaar071d4272004-06-13 20:20:40 +00004094eventhandler() *eventhandler()*
4095 Returns 1 when inside an event handler. That is that Vim got
4096 interrupted while waiting for the user to type a character,
4097 e.g., when dropping a file on Vim. This means interactive
4098 commands cannot be used. Otherwise zero is returned.
4099
4100executable({expr}) *executable()*
4101 This function checks if an executable with the name {expr}
4102 exists. {expr} must be the name of the program without any
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00004103 arguments.
4104 executable() uses the value of $PATH and/or the normal
4105 searchpath for programs. *PATHEXT*
Bram Moolenaar5666fcd2019-12-26 14:35:26 +01004106 On MS-Windows the ".exe", ".bat", etc. can optionally be
4107 included. Then the extensions in $PATHEXT are tried. Thus if
4108 "foo.exe" does not exist, "foo.exe.bat" can be found. If
Bram Moolenaar95da1362020-05-30 18:37:55 +02004109 $PATHEXT is not set then ".com;.exe;.bat;.cmd" is used. A dot
Bram Moolenaar5666fcd2019-12-26 14:35:26 +01004110 by itself can be used in $PATHEXT to try using the name
4111 without an extension. When 'shell' looks like a Unix shell,
4112 then the name is also tried without adding an extension.
4113 On MS-Windows it only checks if the file exists and is not a
4114 directory, not if it's really executable.
Bram Moolenaar910f66f2006-04-05 20:41:53 +00004115 On MS-Windows an executable in the same directory as Vim is
4116 always found. Since this directory is added to $PATH it
4117 should also work to execute it |win32-PATH|.
Bram Moolenaar071d4272004-06-13 20:20:40 +00004118 The result is a Number:
4119 1 exists
4120 0 does not exist
4121 -1 not implemented on this system
Bram Moolenaar6dc819b2018-07-03 16:42:19 +02004122 |exepath()| can be used to get the full path of an executable.
Bram Moolenaar071d4272004-06-13 20:20:40 +00004123
Bram Moolenaara4208962019-08-24 20:50:19 +02004124 Can also be used as a |method|: >
4125 GetCommand()->executable()
4126
Bram Moolenaar79815f12016-07-09 17:07:29 +02004127execute({command} [, {silent}]) *execute()*
4128 Execute an Ex command or commands and return the output as a
4129 string.
4130 {command} can be a string or a List. In case of a List the
4131 lines are executed one by one.
4132 This is equivalent to: >
4133 redir => var
4134 {command}
4135 redir END
4136<
4137 The optional {silent} argument can have these values:
4138 "" no `:silent` used
4139 "silent" `:silent` used
4140 "silent!" `:silent!` used
Bram Moolenaar214641f2017-03-05 17:04:09 +01004141 The default is "silent". Note that with "silent!", unlike
Bram Moolenaar069c1e72016-07-15 21:25:08 +02004142 `:redir`, error messages are dropped. When using an external
4143 command the screen may be messed up, use `system()` instead.
Bram Moolenaar79815f12016-07-09 17:07:29 +02004144 *E930*
4145 It is not possible to use `:redir` anywhere in {command}.
4146
4147 To get a list of lines use |split()| on the result: >
Bram Moolenaar063b9d12016-07-09 20:21:48 +02004148 split(execute('args'), "\n")
Bram Moolenaar79815f12016-07-09 17:07:29 +02004149
Bram Moolenaar868b7b62019-05-29 21:44:40 +02004150< To execute a command in another window than the current one
4151 use `win_execute()`.
4152
4153 When used recursively the output of the recursive call is not
Bram Moolenaar79815f12016-07-09 17:07:29 +02004154 included in the output of the higher level call.
4155
Bram Moolenaara4208962019-08-24 20:50:19 +02004156 Can also be used as a |method|: >
4157 GetCommand()->execute()
4158
Bram Moolenaarc7f02552014-04-01 21:00:59 +02004159exepath({expr}) *exepath()*
4160 If {expr} is an executable and is either an absolute path, a
4161 relative path or found in $PATH, return the full path.
4162 Note that the current directory is used when {expr} starts
4163 with "./", which may be a problem for Vim: >
4164 echo exepath(v:progpath)
Bram Moolenaar7e38ea22014-04-05 22:55:53 +02004165< If {expr} cannot be found in $PATH or is not executable then
Bram Moolenaarc7f02552014-04-01 21:00:59 +02004166 an empty string is returned.
4167
Bram Moolenaara4208962019-08-24 20:50:19 +02004168 Can also be used as a |method|: >
4169 GetCommand()->exepath()
Bram Moolenaar2e693a82019-10-16 22:35:02 +02004170<
Bram Moolenaar071d4272004-06-13 20:20:40 +00004171 *exists()*
Bram Moolenaar8e97bd72016-08-06 22:05:07 +02004172exists({expr}) The result is a Number, which is |TRUE| if {expr} is defined,
4173 zero otherwise.
4174
4175 For checking for a supported feature use |has()|.
4176 For checking if a file exists use |filereadable()|.
4177
4178 The {expr} argument is a string, which contains one of these:
Bram Moolenaar071d4272004-06-13 20:20:40 +00004179 &option-name Vim option (only checks if it exists,
4180 not if it really works)
4181 +option-name Vim option that works.
4182 $ENVNAME environment variable (could also be
4183 done by comparing with an empty
4184 string)
4185 *funcname built-in function (see |functions|)
4186 or user defined function (see
Bram Moolenaar15c47602020-03-26 22:16:48 +01004187 |user-functions|) that is implemented.
4188 Also works for a variable that is a
4189 Funcref.
4190 ?funcname built-in function that could be
4191 implemented; to be used to check if
4192 "funcname" is valid
Bram Moolenaar071d4272004-06-13 20:20:40 +00004193 varname internal variable (see
Bram Moolenaar58b85342016-08-14 19:54:54 +02004194 |internal-variables|). Also works
Bram Moolenaar32466aa2006-02-24 23:53:04 +00004195 for |curly-braces-names|, |Dictionary|
4196 entries, |List| items, etc. Beware
Bram Moolenaarc236c162008-07-13 17:41:49 +00004197 that evaluating an index may cause an
4198 error message for an invalid
4199 expression. E.g.: >
4200 :let l = [1, 2, 3]
4201 :echo exists("l[5]")
4202< 0 >
4203 :echo exists("l[xx]")
4204< E121: Undefined variable: xx
4205 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00004206 :cmdname Ex command: built-in command, user
4207 command or command modifier |:command|.
4208 Returns:
4209 1 for match with start of a command
4210 2 full match with a command
4211 3 matches several user commands
4212 To check for a supported command
4213 always check the return value to be 2.
Bram Moolenaar14716812006-05-04 21:54:08 +00004214 :2match The |:2match| command.
4215 :3match The |:3match| command.
Bram Moolenaar071d4272004-06-13 20:20:40 +00004216 #event autocommand defined for this event
4217 #event#pattern autocommand defined for this event and
4218 pattern (the pattern is taken
4219 literally and compared to the
4220 autocommand patterns character by
4221 character)
Bram Moolenaara9b1e742005-12-19 22:14:58 +00004222 #group autocommand group exists
4223 #group#event autocommand defined for this group and
4224 event.
4225 #group#event#pattern
Bram Moolenaarc9b4b052006-04-30 18:54:39 +00004226 autocommand defined for this group,
Bram Moolenaara9b1e742005-12-19 22:14:58 +00004227 event and pattern.
Bram Moolenaarf4cd3e82005-12-22 22:47:02 +00004228 ##event autocommand for this event is
4229 supported.
Bram Moolenaar071d4272004-06-13 20:20:40 +00004230
4231 Examples: >
4232 exists("&shortname")
4233 exists("$HOSTNAME")
4234 exists("*strftime")
4235 exists("*s:MyFunc")
4236 exists("bufcount")
4237 exists(":Make")
Bram Moolenaara9b1e742005-12-19 22:14:58 +00004238 exists("#CursorHold")
Bram Moolenaar071d4272004-06-13 20:20:40 +00004239 exists("#BufReadPre#*.gz")
Bram Moolenaara9b1e742005-12-19 22:14:58 +00004240 exists("#filetypeindent")
4241 exists("#filetypeindent#FileType")
4242 exists("#filetypeindent#FileType#*")
Bram Moolenaarf4cd3e82005-12-22 22:47:02 +00004243 exists("##ColorScheme")
Bram Moolenaar071d4272004-06-13 20:20:40 +00004244< There must be no space between the symbol (&/$/*/#) and the
4245 name.
Bram Moolenaar91170f82006-05-05 21:15:17 +00004246 There must be no extra characters after the name, although in
4247 a few cases this is ignored. That may become more strict in
4248 the future, thus don't count on it!
4249 Working example: >
4250 exists(":make")
4251< NOT working example: >
4252 exists(":make install")
Bram Moolenaar9c102382006-05-03 21:26:49 +00004253
4254< Note that the argument must be a string, not the name of the
4255 variable itself. For example: >
Bram Moolenaar071d4272004-06-13 20:20:40 +00004256 exists(bufcount)
4257< This doesn't check for existence of the "bufcount" variable,
Bram Moolenaar06a89a52006-04-29 22:01:03 +00004258 but gets the value of "bufcount", and checks if that exists.
Bram Moolenaar071d4272004-06-13 20:20:40 +00004259
Bram Moolenaara4208962019-08-24 20:50:19 +02004260 Can also be used as a |method|: >
4261 Varname()->exists()
4262
Bram Moolenaardb7c6862010-05-21 16:33:48 +02004263exp({expr}) *exp()*
Bram Moolenaar9855d6b2010-07-18 14:34:51 +02004264 Return the exponential of {expr} as a |Float| in the range
Bram Moolenaardb7c6862010-05-21 16:33:48 +02004265 [0, inf].
Bram Moolenaar9855d6b2010-07-18 14:34:51 +02004266 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaardb7c6862010-05-21 16:33:48 +02004267 Examples: >
4268 :echo exp(2)
4269< 7.389056 >
4270 :echo exp(-1)
4271< 0.367879
Bram Moolenaar93cf85f2019-08-17 21:36:28 +02004272
4273 Can also be used as a |method|: >
4274 Compute()->exp()
4275<
Bram Moolenaardb84e452010-08-15 13:50:43 +02004276 {only available when compiled with the |+float| feature}
Bram Moolenaardb7c6862010-05-21 16:33:48 +02004277
4278
Bram Moolenaar84f72352012-03-11 15:57:40 +01004279expand({expr} [, {nosuf} [, {list}]]) *expand()*
Bram Moolenaar071d4272004-06-13 20:20:40 +00004280 Expand wildcards and the following special keywords in {expr}.
Bram Moolenaar84f72352012-03-11 15:57:40 +01004281 'wildignorecase' applies.
Bram Moolenaar071d4272004-06-13 20:20:40 +00004282
Bram Moolenaare381d3d2016-07-07 14:50:41 +02004283 If {list} is given and it is |TRUE|, a List will be returned.
Bram Moolenaar84f72352012-03-11 15:57:40 +01004284 Otherwise the result is a String and when there are several
4285 matches, they are separated by <NL> characters. [Note: in
4286 version 5.0 a space was used, which caused problems when a
4287 file name contains a space]
Bram Moolenaar071d4272004-06-13 20:20:40 +00004288
Bram Moolenaar58b85342016-08-14 19:54:54 +02004289 If the expansion fails, the result is an empty string. A name
Bram Moolenaarec7944a2013-06-12 21:29:15 +02004290 for a non-existing file is not included, unless {expr} does
4291 not start with '%', '#' or '<', see below.
Bram Moolenaar071d4272004-06-13 20:20:40 +00004292
4293 When {expr} starts with '%', '#' or '<', the expansion is done
4294 like for the |cmdline-special| variables with their associated
4295 modifiers. Here is a short overview:
4296
4297 % current file name
4298 # alternate file name
4299 #n alternate file name n
4300 <cfile> file name under the cursor
4301 <afile> autocmd file name
4302 <abuf> autocmd buffer number (as a String!)
4303 <amatch> autocmd matched name
Bram Moolenaara6878372014-03-22 21:02:50 +01004304 <sfile> sourced script file or function name
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02004305 <slnum> sourced script line number or function
4306 line number
4307 <sflnum> script file line number, also when in
4308 a function
Bram Moolenaaraa970ab2020-08-02 16:10:39 +02004309 <SID> "<SNR>123_" where "123" is the
4310 current script ID |<SID>|
Bram Moolenaar071d4272004-06-13 20:20:40 +00004311 <cword> word under the cursor
4312 <cWORD> WORD under the cursor
4313 <client> the {clientid} of the last received
4314 message |server2client()|
4315 Modifiers:
4316 :p expand to full path
4317 :h head (last path component removed)
4318 :t tail (last path component only)
4319 :r root (one extension removed)
4320 :e extension only
4321
4322 Example: >
4323 :let &tags = expand("%:p:h") . "/tags"
4324< Note that when expanding a string that starts with '%', '#' or
4325 '<', any following text is ignored. This does NOT work: >
4326 :let doesntwork = expand("%:h.bak")
4327< Use this: >
4328 :let doeswork = expand("%:h") . ".bak"
4329< Also note that expanding "<cfile>" and others only returns the
4330 referenced file name without further expansion. If "<cfile>"
4331 is "~/.cshrc", you need to do another expand() to have the
4332 "~/" expanded into the path of the home directory: >
4333 :echo expand(expand("<cfile>"))
4334<
4335 There cannot be white space between the variables and the
4336 following modifier. The |fnamemodify()| function can be used
4337 to modify normal file names.
4338
4339 When using '%' or '#', and the current or alternate file name
4340 is not defined, an empty string is used. Using "%:p" in a
4341 buffer with no name, results in the current directory, with a
4342 '/' added.
4343
4344 When {expr} does not start with '%', '#' or '<', it is
4345 expanded like a file name is expanded on the command line.
4346 'suffixes' and 'wildignore' are used, unless the optional
Bram Moolenaare381d3d2016-07-07 14:50:41 +02004347 {nosuf} argument is given and it is |TRUE|.
Bram Moolenaar146e9c32012-03-07 19:18:23 +01004348 Names for non-existing files are included. The "**" item can
4349 be used to search in a directory tree. For example, to find
4350 all "README" files in the current directory and below: >
Bram Moolenaar02743632005-07-25 20:42:36 +00004351 :echo expand("**/README")
4352<
Bram Moolenaar647e24b2019-03-17 16:39:46 +01004353 expand() can also be used to expand variables and environment
Bram Moolenaar071d4272004-06-13 20:20:40 +00004354 variables that are only known in a shell. But this can be
Bram Moolenaar34401cc2014-08-29 15:12:19 +02004355 slow, because a shell may be used to do the expansion. See
4356 |expr-env-expand|.
Bram Moolenaar071d4272004-06-13 20:20:40 +00004357 The expanded variable is still handled like a list of file
Bram Moolenaar58b85342016-08-14 19:54:54 +02004358 names. When an environment variable cannot be expanded, it is
Bram Moolenaar071d4272004-06-13 20:20:40 +00004359 left unchanged. Thus ":echo expand('$FOOBAR')" results in
4360 "$FOOBAR".
4361
4362 See |glob()| for finding existing files. See |system()| for
4363 getting the raw output of an external command.
4364
Bram Moolenaara4208962019-08-24 20:50:19 +02004365 Can also be used as a |method|: >
4366 Getpattern()->expand()
4367
Bram Moolenaar80dad482019-06-09 17:22:31 +02004368expandcmd({expr}) *expandcmd()*
4369 Expand special items in {expr} like what is done for an Ex
4370 command such as `:edit`. This expands special keywords, like
4371 with |expand()|, and environment variables, anywhere in
Bram Moolenaar96f45c02019-10-26 19:53:45 +02004372 {expr}. "~user" and "~/path" are only expanded at the start.
4373 Returns the expanded string. Example: >
Bram Moolenaar80dad482019-06-09 17:22:31 +02004374 :echo expandcmd('make %<.o')
Bram Moolenaara4208962019-08-24 20:50:19 +02004375
4376< Can also be used as a |method|: >
4377 GetCommand()->expandcmd()
Bram Moolenaar80dad482019-06-09 17:22:31 +02004378<
Bram Moolenaar2fda12f2005-01-15 22:14:15 +00004379extend({expr1}, {expr2} [, {expr3}]) *extend()*
Bram Moolenaara23ccb82006-02-27 00:08:02 +00004380 {expr1} and {expr2} must be both |Lists| or both
4381 |Dictionaries|.
Bram Moolenaar2fda12f2005-01-15 22:14:15 +00004382
Bram Moolenaara23ccb82006-02-27 00:08:02 +00004383 If they are |Lists|: Append {expr2} to {expr1}.
Bram Moolenaar2fda12f2005-01-15 22:14:15 +00004384 If {expr3} is given insert the items of {expr2} before item
4385 {expr3} in {expr1}. When {expr3} is zero insert before the
4386 first item. When {expr3} is equal to len({expr1}) then
4387 {expr2} is appended.
Bram Moolenaarde8866b2005-01-06 23:24:37 +00004388 Examples: >
4389 :echo sort(extend(mylist, [7, 5]))
4390 :call extend(mylist, [2, 3], 1)
Bram Moolenaardc9cf9c2008-08-08 10:36:31 +00004391< When {expr1} is the same List as {expr2} then the number of
4392 items copied is equal to the original length of the List.
4393 E.g., when {expr3} is 1 you get N new copies of the first item
4394 (where N is the original length of the List).
Bram Moolenaar58b85342016-08-14 19:54:54 +02004395 Use |add()| to concatenate one item to a list. To concatenate
Bram Moolenaara14de3d2005-01-07 21:48:26 +00004396 two lists into a new list use the + operator: >
Bram Moolenaarde8866b2005-01-06 23:24:37 +00004397 :let newlist = [1, 2, 3] + [4, 5]
Bram Moolenaar2fda12f2005-01-15 22:14:15 +00004398<
Bram Moolenaara23ccb82006-02-27 00:08:02 +00004399 If they are |Dictionaries|:
Bram Moolenaar2fda12f2005-01-15 22:14:15 +00004400 Add all entries from {expr2} to {expr1}.
4401 If a key exists in both {expr1} and {expr2} then {expr3} is
4402 used to decide what to do:
4403 {expr3} = "keep": keep the value of {expr1}
4404 {expr3} = "force": use the value of {expr2}
Bram Moolenaarc9b4b052006-04-30 18:54:39 +00004405 {expr3} = "error": give an error message *E737*
Bram Moolenaar2fda12f2005-01-15 22:14:15 +00004406 When {expr3} is omitted then "force" is assumed.
4407
4408 {expr1} is changed when {expr2} is not empty. If necessary
4409 make a copy of {expr1} first.
4410 {expr2} remains unchanged.
Bram Moolenaarf2571c62015-06-09 19:44:55 +02004411 When {expr1} is locked and {expr2} is not empty the operation
4412 fails.
Bram Moolenaar2fda12f2005-01-15 22:14:15 +00004413 Returns {expr1}.
4414
Bram Moolenaarac92e252019-08-03 21:58:38 +02004415 Can also be used as a |method|: >
4416 mylist->extend(otherlist)
4417
Bram Moolenaarde8866b2005-01-06 23:24:37 +00004418
Bram Moolenaarf9393ef2006-04-24 19:47:27 +00004419feedkeys({string} [, {mode}]) *feedkeys()*
4420 Characters in {string} are queued for processing as if they
Bram Moolenaar0a988df2015-01-27 15:19:24 +01004421 come from a mapping or were typed by the user.
Bram Moolenaarb328cca2019-01-06 16:24:01 +01004422
Bram Moolenaar0a988df2015-01-27 15:19:24 +01004423 By default the string is added to the end of the typeahead
4424 buffer, thus if a mapping is still being executed the
4425 characters come after them. Use the 'i' flag to insert before
4426 other characters, they will be executed next, before any
4427 characters from a mapping.
Bram Moolenaarb328cca2019-01-06 16:24:01 +01004428
Bram Moolenaarf9393ef2006-04-24 19:47:27 +00004429 The function does not wait for processing of keys contained in
4430 {string}.
Bram Moolenaarb328cca2019-01-06 16:24:01 +01004431
Bram Moolenaarf9393ef2006-04-24 19:47:27 +00004432 To include special keys into {string}, use double-quotes
4433 and "\..." notation |expr-quote|. For example,
Bram Moolenaar79166c42007-05-10 18:29:51 +00004434 feedkeys("\<CR>") simulates pressing of the <Enter> key. But
Bram Moolenaarf9393ef2006-04-24 19:47:27 +00004435 feedkeys('\<CR>') pushes 5 characters.
Bram Moolenaarbe0a2592019-05-09 13:50:16 +02004436 A special code that might be useful is <Ignore>, it exits the
4437 wait for a character without doing anything. *<Ignore>*
Bram Moolenaarb328cca2019-01-06 16:24:01 +01004438
Bram Moolenaarf9393ef2006-04-24 19:47:27 +00004439 {mode} is a String, which can contain these character flags:
Bram Moolenaarb328cca2019-01-06 16:24:01 +01004440 'm' Remap keys. This is default. If {mode} is absent,
4441 keys are remapped.
Bram Moolenaar551dbcc2006-04-25 22:13:59 +00004442 'n' Do not remap keys.
4443 't' Handle keys as if typed; otherwise they are handled as
4444 if coming from a mapping. This matters for undo,
4445 opening folds, etc.
Bram Moolenaar5e66b422019-01-24 21:58:10 +01004446 'L' Lowlevel input. Only works for Unix or when using the
4447 GUI. Keys are used as if they were coming from the
4448 terminal. Other flags are not used. *E980*
Bram Moolenaar79296512020-03-22 16:17:14 +01004449 When a CTRL-C interrupts and 't' is included it sets
4450 the internal "got_int" flag.
Bram Moolenaar0a988df2015-01-27 15:19:24 +01004451 'i' Insert the string instead of appending (see above).
Bram Moolenaar25281632016-01-21 23:32:32 +01004452 'x' Execute commands until typeahead is empty. This is
4453 similar to using ":normal!". You can call feedkeys()
4454 several times without 'x' and then one time with 'x'
4455 (possibly with an empty {string}) to execute all the
Bram Moolenaar03413f42016-04-12 21:07:15 +02004456 typeahead. Note that when Vim ends in Insert mode it
4457 will behave as if <Esc> is typed, to avoid getting
4458 stuck, waiting for a character to be typed before the
4459 script continues.
Bram Moolenaarb328cca2019-01-06 16:24:01 +01004460 Note that if you manage to call feedkeys() while
Bram Moolenaar5b69c222019-01-11 14:50:06 +01004461 executing commands, thus calling it recursively, then
Bram Moolenaarebacddb2020-06-04 15:22:21 +02004462 all typeahead will be consumed by the last call.
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004463 '!' When used with 'x' will not end Insert mode. Can be
4464 used in a test when a timer is set to exit Insert mode
4465 a little later. Useful for testing CursorHoldI.
4466
Bram Moolenaarf9393ef2006-04-24 19:47:27 +00004467 Return value is always 0.
4468
Bram Moolenaara4208962019-08-24 20:50:19 +02004469 Can also be used as a |method|: >
4470 GetInput()->feedkeys()
4471
Bram Moolenaar071d4272004-06-13 20:20:40 +00004472filereadable({file}) *filereadable()*
Bram Moolenaare381d3d2016-07-07 14:50:41 +02004473 The result is a Number, which is |TRUE| when a file with the
Bram Moolenaar071d4272004-06-13 20:20:40 +00004474 name {file} exists, and can be read. If {file} doesn't exist,
Bram Moolenaare381d3d2016-07-07 14:50:41 +02004475 or is a directory, the result is |FALSE|. {file} is any
Bram Moolenaar071d4272004-06-13 20:20:40 +00004476 expression, which is used as a String.
Bram Moolenaaref2f6562007-05-06 13:32:59 +00004477 If you don't care about the file being readable you can use
4478 |glob()|.
Bram Moolenaar25e42232019-08-04 15:04:10 +02004479 {file} is used as-is, you may want to expand wildcards first: >
4480 echo filereadable('~/.vimrc')
4481 0
4482 echo filereadable(expand('~/.vimrc'))
4483 1
Bram Moolenaara4208962019-08-24 20:50:19 +02004484
4485< Can also be used as a |method|: >
4486 GetName()->filereadable()
Bram Moolenaar25e42232019-08-04 15:04:10 +02004487< *file_readable()*
Bram Moolenaar071d4272004-06-13 20:20:40 +00004488 Obsolete name: file_readable().
4489
Bram Moolenaar5f2bb9f2005-01-11 21:29:04 +00004490
Bram Moolenaaref2f6562007-05-06 13:32:59 +00004491filewritable({file}) *filewritable()*
4492 The result is a Number, which is 1 when a file with the
4493 name {file} exists, and can be written. If {file} doesn't
Bram Moolenaar446cb832008-06-24 21:56:24 +00004494 exist, or is not writable, the result is 0. If {file} is a
Bram Moolenaaref2f6562007-05-06 13:32:59 +00004495 directory, and we can write to it, the result is 2.
4496
Bram Moolenaara4208962019-08-24 20:50:19 +02004497 Can also be used as a |method|: >
Bram Moolenaarebacddb2020-06-04 15:22:21 +02004498 GetName()->filewritable()
Bram Moolenaara4208962019-08-24 20:50:19 +02004499
Bram Moolenaaref2f6562007-05-06 13:32:59 +00004500
Bram Moolenaarb33c7eb2016-07-04 22:29:49 +02004501filter({expr1}, {expr2}) *filter()*
4502 {expr1} must be a |List| or a |Dictionary|.
4503 For each item in {expr1} evaluate {expr2} and when the result
Bram Moolenaar32466aa2006-02-24 23:53:04 +00004504 is zero remove the item from the |List| or |Dictionary|.
Bram Moolenaarb33c7eb2016-07-04 22:29:49 +02004505 {expr2} must be a |string| or |Funcref|.
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01004506
Bram Moolenaar50ba5262016-09-22 22:33:02 +02004507 If {expr2} is a |string|, inside {expr2} |v:val| has the value
Bram Moolenaarb33c7eb2016-07-04 22:29:49 +02004508 of the current item. For a |Dictionary| |v:key| has the key
Bram Moolenaar50ba5262016-09-22 22:33:02 +02004509 of the current item and for a |List| |v:key| has the index of
4510 the current item.
Bram Moolenaar2fda12f2005-01-15 22:14:15 +00004511 Examples: >
Bram Moolenaarb33c7eb2016-07-04 22:29:49 +02004512 call filter(mylist, 'v:val !~ "OLD"')
Bram Moolenaar2fda12f2005-01-15 22:14:15 +00004513< Removes the items where "OLD" appears. >
Bram Moolenaarb33c7eb2016-07-04 22:29:49 +02004514 call filter(mydict, 'v:key >= 8')
Bram Moolenaar2fda12f2005-01-15 22:14:15 +00004515< Removes the items with a key below 8. >
Bram Moolenaarb33c7eb2016-07-04 22:29:49 +02004516 call filter(var, 0)
Bram Moolenaar32466aa2006-02-24 23:53:04 +00004517< Removes all the items, thus clears the |List| or |Dictionary|.
Bram Moolenaard8b02732005-01-14 21:48:43 +00004518
Bram Moolenaarb33c7eb2016-07-04 22:29:49 +02004519 Note that {expr2} is the result of expression and is then
Bram Moolenaar2fda12f2005-01-15 22:14:15 +00004520 used as an expression again. Often it is good to use a
4521 |literal-string| to avoid having to double backslashes.
4522
Bram Moolenaarb33c7eb2016-07-04 22:29:49 +02004523 If {expr2} is a |Funcref| it must take two arguments:
4524 1. the key or the index of the current item.
4525 2. the value of the current item.
Bram Moolenaare381d3d2016-07-07 14:50:41 +02004526 The function must return |TRUE| if the item should be kept.
Bram Moolenaarb33c7eb2016-07-04 22:29:49 +02004527 Example that keeps the odd items of a list: >
4528 func Odd(idx, val)
4529 return a:idx % 2 == 1
4530 endfunc
4531 call filter(mylist, function('Odd'))
Bram Moolenaar50ba5262016-09-22 22:33:02 +02004532< It is shorter when using a |lambda|: >
4533 call filter(myList, {idx, val -> idx * val <= 42})
4534< If you do not use "val" you can leave it out: >
4535 call filter(myList, {idx -> idx % 2 == 1})
Bram Moolenaar2ec618c2016-10-01 14:47:05 +02004536<
Bram Moolenaar32466aa2006-02-24 23:53:04 +00004537 The operation is done in-place. If you want a |List| or
4538 |Dictionary| to remain unmodified make a copy first: >
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00004539 :let l = filter(copy(mylist), 'v:val =~ "KEEP"')
Bram Moolenaar2fda12f2005-01-15 22:14:15 +00004540
Bram Moolenaarb33c7eb2016-07-04 22:29:49 +02004541< Returns {expr1}, the |List| or |Dictionary| that was filtered.
4542 When an error is encountered while evaluating {expr2} no
4543 further items in {expr1} are processed. When {expr2} is a
4544 Funcref errors inside a function are ignored, unless it was
4545 defined with the "abort" flag.
Bram Moolenaar5f2bb9f2005-01-11 21:29:04 +00004546
Bram Moolenaarac92e252019-08-03 21:58:38 +02004547 Can also be used as a |method|: >
4548 mylist->filter(expr2)
Bram Moolenaar5f2bb9f2005-01-11 21:29:04 +00004549
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01004550finddir({name} [, {path} [, {count}]]) *finddir()*
Bram Moolenaar5b6b1ca2007-03-27 08:19:43 +00004551 Find directory {name} in {path}. Supports both downwards and
4552 upwards recursive directory searches. See |file-searching|
4553 for the syntax of {path}.
4554 Returns the path of the first found match. When the found
4555 directory is below the current directory a relative path is
4556 returned. Otherwise a full path is returned.
Bram Moolenaar89cb5e02004-07-19 20:55:54 +00004557 If {path} is omitted or empty then 'path' is used.
4558 If the optional {count} is given, find {count}'s occurrence of
Bram Moolenaar433f7c82006-03-21 21:29:36 +00004559 {name} in {path} instead of the first one.
Bram Moolenaar899dddf2006-03-26 21:06:50 +00004560 When {count} is negative return all the matches in a |List|.
Bram Moolenaar89cb5e02004-07-19 20:55:54 +00004561 This is quite similar to the ex-command |:find|.
Bram Moolenaardb84e452010-08-15 13:50:43 +02004562 {only available when compiled with the |+file_in_path|
4563 feature}
Bram Moolenaar89cb5e02004-07-19 20:55:54 +00004564
Bram Moolenaara4208962019-08-24 20:50:19 +02004565 Can also be used as a |method|: >
4566 GetName()->finddir()
4567
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01004568findfile({name} [, {path} [, {count}]]) *findfile()*
Bram Moolenaar89cb5e02004-07-19 20:55:54 +00004569 Just like |finddir()|, but find a file instead of a directory.
Bram Moolenaar433f7c82006-03-21 21:29:36 +00004570 Uses 'suffixesadd'.
4571 Example: >
4572 :echo findfile("tags.vim", ".;")
Bram Moolenaaref2f6562007-05-06 13:32:59 +00004573< Searches from the directory of the current file upwards until
4574 it finds the file "tags.vim".
Bram Moolenaar071d4272004-06-13 20:20:40 +00004575
Bram Moolenaara4208962019-08-24 20:50:19 +02004576 Can also be used as a |method|: >
4577 GetName()->findfile()
4578
Bram Moolenaar077a1e62020-06-08 20:50:43 +02004579flatten({list} [, {maxdepth}]) *flatten()*
4580 Flatten {list} up to {maxdepth} levels. Without {maxdepth}
4581 the result is a |List| without nesting, as if {maxdepth} is
4582 a very large number.
4583 The {list} is changed in place, make a copy first if you do
4584 not want that.
Bram Moolenaar73fef332020-06-21 22:12:03 +02004585 *E900*
Bram Moolenaar077a1e62020-06-08 20:50:43 +02004586 {maxdepth} means how deep in nested lists changes are made.
4587 {list} is not modified when {maxdepth} is 0.
4588 {maxdepth} must be positive number.
4589
4590 If there is an error the number zero is returned.
4591
4592 Example: >
4593 :echo flatten([1, [2, [3, 4]], 5])
4594< [1, 2, 3, 4, 5] >
4595 :echo flatten([1, [2, [3, 4]], 5], 1)
4596< [1, 2, [3, 4], 5]
4597
Bram Moolenaar446cb832008-06-24 21:56:24 +00004598float2nr({expr}) *float2nr()*
4599 Convert {expr} to a Number by omitting the part after the
4600 decimal point.
4601 {expr} must evaluate to a |Float| or a Number.
4602 When the value of {expr} is out of range for a |Number| the
Bram Moolenaar22fcfad2016-07-01 18:17:26 +02004603 result is truncated to 0x7fffffff or -0x7fffffff (or when
4604 64-bit Number support is enabled, 0x7fffffffffffffff or
Bram Moolenaarb4d5fba2017-09-11 19:31:28 +02004605 -0x7fffffffffffffff). NaN results in -0x80000000 (or when
Bram Moolenaar22fcfad2016-07-01 18:17:26 +02004606 64-bit Number support is enabled, -0x8000000000000000).
Bram Moolenaar446cb832008-06-24 21:56:24 +00004607 Examples: >
4608 echo float2nr(3.95)
4609< 3 >
4610 echo float2nr(-23.45)
4611< -23 >
4612 echo float2nr(1.0e100)
Bram Moolenaar22fcfad2016-07-01 18:17:26 +02004613< 2147483647 (or 9223372036854775807) >
Bram Moolenaar446cb832008-06-24 21:56:24 +00004614 echo float2nr(-1.0e150)
Bram Moolenaar22fcfad2016-07-01 18:17:26 +02004615< -2147483647 (or -9223372036854775807) >
Bram Moolenaar446cb832008-06-24 21:56:24 +00004616 echo float2nr(1.0e-100)
4617< 0
Bram Moolenaar93cf85f2019-08-17 21:36:28 +02004618
4619 Can also be used as a |method|: >
4620 Compute()->float2nr()
4621<
Bram Moolenaar446cb832008-06-24 21:56:24 +00004622 {only available when compiled with the |+float| feature}
4623
4624
4625floor({expr}) *floor()*
4626 Return the largest integral value less than or equal to
4627 {expr} as a |Float| (round down).
4628 {expr} must evaluate to a |Float| or a |Number|.
4629 Examples: >
4630 echo floor(1.856)
4631< 1.0 >
4632 echo floor(-5.456)
4633< -6.0 >
4634 echo floor(4.0)
4635< 4.0
Bram Moolenaar93cf85f2019-08-17 21:36:28 +02004636
4637 Can also be used as a |method|: >
4638 Compute()->floor()
4639<
Bram Moolenaar446cb832008-06-24 21:56:24 +00004640 {only available when compiled with the |+float| feature}
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01004641
Bram Moolenaardb7c6862010-05-21 16:33:48 +02004642
4643fmod({expr1}, {expr2}) *fmod()*
4644 Return the remainder of {expr1} / {expr2}, even if the
4645 division is not representable. Returns {expr1} - i * {expr2}
4646 for some integer i such that if {expr2} is non-zero, the
4647 result has the same sign as {expr1} and magnitude less than
4648 the magnitude of {expr2}. If {expr2} is zero, the value
Bram Moolenaar9855d6b2010-07-18 14:34:51 +02004649 returned is zero. The value returned is a |Float|.
4650 {expr1} and {expr2} must evaluate to a |Float| or a |Number|.
Bram Moolenaardb7c6862010-05-21 16:33:48 +02004651 Examples: >
4652 :echo fmod(12.33, 1.22)
4653< 0.13 >
4654 :echo fmod(-12.33, 1.22)
4655< -0.13
Bram Moolenaar93cf85f2019-08-17 21:36:28 +02004656
4657 Can also be used as a |method|: >
4658 Compute()->fmod(1.22)
4659<
Bram Moolenaardb84e452010-08-15 13:50:43 +02004660 {only available when compiled with |+float| feature}
Bram Moolenaardb7c6862010-05-21 16:33:48 +02004661
4662
Bram Moolenaaraebaf892008-05-28 14:49:58 +00004663fnameescape({string}) *fnameescape()*
Bram Moolenaar58b85342016-08-14 19:54:54 +02004664 Escape {string} for use as file name command argument. All
Bram Moolenaaraebaf892008-05-28 14:49:58 +00004665 characters that have a special meaning, such as '%' and '|'
4666 are escaped with a backslash.
Bram Moolenaar446cb832008-06-24 21:56:24 +00004667 For most systems the characters escaped are
4668 " \t\n*?[{`$\\%#'\"|!<". For systems where a backslash
4669 appears in a filename, it depends on the value of 'isfname'.
Bram Moolenaar1b24e4b2008-08-08 10:59:17 +00004670 A leading '+' and '>' is also escaped (special after |:edit|
4671 and |:write|). And a "-" by itself (special after |:cd|).
Bram Moolenaaraebaf892008-05-28 14:49:58 +00004672 Example: >
Bram Moolenaar1b24e4b2008-08-08 10:59:17 +00004673 :let fname = '+some str%nge|name'
Bram Moolenaaraebaf892008-05-28 14:49:58 +00004674 :exe "edit " . fnameescape(fname)
4675< results in executing: >
Bram Moolenaar1b24e4b2008-08-08 10:59:17 +00004676 edit \+some\ str\%nge\|name
Bram Moolenaara4208962019-08-24 20:50:19 +02004677<
4678 Can also be used as a |method|: >
4679 GetName()->fnameescape()
Bram Moolenaaraebaf892008-05-28 14:49:58 +00004680
Bram Moolenaar071d4272004-06-13 20:20:40 +00004681fnamemodify({fname}, {mods}) *fnamemodify()*
4682 Modify file name {fname} according to {mods}. {mods} is a
4683 string of characters like it is used for file names on the
4684 command line. See |filename-modifiers|.
4685 Example: >
4686 :echo fnamemodify("main.c", ":p:h")
4687< results in: >
4688 /home/mool/vim/vim/src
Bram Moolenaar446cb832008-06-24 21:56:24 +00004689< Note: Environment variables don't work in {fname}, use
Bram Moolenaar071d4272004-06-13 20:20:40 +00004690 |expand()| first then.
4691
Bram Moolenaara4208962019-08-24 20:50:19 +02004692 Can also be used as a |method|: >
4693 GetName()->fnamemodify(':p:h')
4694
Bram Moolenaar071d4272004-06-13 20:20:40 +00004695foldclosed({lnum}) *foldclosed()*
4696 The result is a Number. If the line {lnum} is in a closed
4697 fold, the result is the number of the first line in that fold.
4698 If the line {lnum} is not in a closed fold, -1 is returned.
4699
Bram Moolenaara4208962019-08-24 20:50:19 +02004700 Can also be used as a |method|: >
4701 GetLnum()->foldclosed()
4702
Bram Moolenaar071d4272004-06-13 20:20:40 +00004703foldclosedend({lnum}) *foldclosedend()*
4704 The result is a Number. If the line {lnum} is in a closed
4705 fold, the result is the number of the last line in that fold.
4706 If the line {lnum} is not in a closed fold, -1 is returned.
4707
Bram Moolenaara4208962019-08-24 20:50:19 +02004708 Can also be used as a |method|: >
4709 GetLnum()->foldclosedend()
4710
Bram Moolenaar071d4272004-06-13 20:20:40 +00004711foldlevel({lnum}) *foldlevel()*
4712 The result is a Number, which is the foldlevel of line {lnum}
Bram Moolenaar58b85342016-08-14 19:54:54 +02004713 in the current buffer. For nested folds the deepest level is
Bram Moolenaar071d4272004-06-13 20:20:40 +00004714 returned. If there is no fold at line {lnum}, zero is
4715 returned. It doesn't matter if the folds are open or closed.
4716 When used while updating folds (from 'foldexpr') -1 is
4717 returned for lines where folds are still to be updated and the
4718 foldlevel is unknown. As a special case the level of the
4719 previous line is usually available.
4720
Bram Moolenaara4208962019-08-24 20:50:19 +02004721 Can also be used as a |method|: >
4722 GetLnum()->foldlevel()
Bram Moolenaar2e693a82019-10-16 22:35:02 +02004723<
Bram Moolenaar071d4272004-06-13 20:20:40 +00004724 *foldtext()*
4725foldtext() Returns a String, to be displayed for a closed fold. This is
4726 the default function used for the 'foldtext' option and should
4727 only be called from evaluating 'foldtext'. It uses the
4728 |v:foldstart|, |v:foldend| and |v:folddashes| variables.
4729 The returned string looks like this: >
4730 +-- 45 lines: abcdef
Bram Moolenaar42205552017-03-18 19:42:22 +01004731< The number of leading dashes depends on the foldlevel. The
4732 "45" is the number of lines in the fold. "abcdef" is the text
4733 in the first non-blank line of the fold. Leading white space,
4734 "//" or "/*" and the text from the 'foldmarker' and
4735 'commentstring' options is removed.
4736 When used to draw the actual foldtext, the rest of the line
4737 will be filled with the fold char from the 'fillchars'
4738 setting.
Bram Moolenaar071d4272004-06-13 20:20:40 +00004739 {not available when compiled without the |+folding| feature}
4740
Bram Moolenaar7b0294c2004-10-11 10:16:09 +00004741foldtextresult({lnum}) *foldtextresult()*
4742 Returns the text that is displayed for the closed fold at line
4743 {lnum}. Evaluates 'foldtext' in the appropriate context.
4744 When there is no closed fold at {lnum} an empty string is
4745 returned.
4746 {lnum} is used like with |getline()|. Thus "." is the current
4747 line, "'m" mark m, etc.
4748 Useful when exporting folded text, e.g., to HTML.
4749 {not available when compiled without the |+folding| feature}
4750
Bram Moolenaara4208962019-08-24 20:50:19 +02004751
4752 Can also be used as a |method|: >
4753 GetLnum()->foldtextresult()
4754<
Bram Moolenaar071d4272004-06-13 20:20:40 +00004755 *foreground()*
Bram Moolenaar58b85342016-08-14 19:54:54 +02004756foreground() Move the Vim window to the foreground. Useful when sent from
Bram Moolenaar071d4272004-06-13 20:20:40 +00004757 a client to a Vim server. |remote_send()|
4758 On Win32 systems this might not work, the OS does not always
4759 allow a window to bring itself to the foreground. Use
4760 |remote_foreground()| instead.
4761 {only in the Win32, Athena, Motif and GTK GUI versions and the
4762 Win32 console version}
4763
Bram Moolenaar437bafe2016-08-01 15:40:54 +02004764 *funcref()*
4765funcref({name} [, {arglist}] [, {dict}])
4766 Just like |function()|, but the returned Funcref will lookup
4767 the function by reference, not by name. This matters when the
4768 function {name} is redefined later.
4769
4770 Unlike |function()|, {name} must be an existing user function.
4771 Also for autoloaded functions. {name} cannot be a builtin
4772 function.
Bram Moolenaara14de3d2005-01-07 21:48:26 +00004773
Bram Moolenaara4208962019-08-24 20:50:19 +02004774 Can also be used as a |method|: >
4775 GetFuncname()->funcref([arg])
4776<
Bram Moolenaar1735bc92016-03-14 23:05:14 +01004777 *function()* *E700* *E922* *E923*
4778function({name} [, {arglist}] [, {dict}])
Bram Moolenaar32466aa2006-02-24 23:53:04 +00004779 Return a |Funcref| variable that refers to function {name}.
Bram Moolenaar975b5272016-03-15 23:10:59 +01004780 {name} can be the name of a user defined function or an
4781 internal function.
Bram Moolenaard7ee7ce2005-01-03 21:02:03 +00004782
Bram Moolenaar437bafe2016-08-01 15:40:54 +02004783 {name} can also be a Funcref or a partial. When it is a
Bram Moolenaar975b5272016-03-15 23:10:59 +01004784 partial the dict stored in it will be used and the {dict}
4785 argument is not allowed. E.g.: >
4786 let FuncWithArg = function(dict.Func, [arg])
4787 let Broken = function(dict.Func, [arg], dict)
4788<
Bram Moolenaar437bafe2016-08-01 15:40:54 +02004789 When using the Funcref the function will be found by {name},
4790 also when it was redefined later. Use |funcref()| to keep the
4791 same function.
4792
Bram Moolenaar1735bc92016-03-14 23:05:14 +01004793 When {arglist} or {dict} is present this creates a partial.
Bram Moolenaar06d2d382016-05-20 17:24:11 +02004794 That means the argument list and/or the dictionary is stored in
Bram Moolenaar1735bc92016-03-14 23:05:14 +01004795 the Funcref and will be used when the Funcref is called.
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01004796
Bram Moolenaar1735bc92016-03-14 23:05:14 +01004797 The arguments are passed to the function in front of other
Bram Moolenaar088e8e32019-08-08 22:15:18 +02004798 arguments, but after any argument from |method|. Example: >
Bram Moolenaar1735bc92016-03-14 23:05:14 +01004799 func Callback(arg1, arg2, name)
4800 ...
Bram Moolenaar088e8e32019-08-08 22:15:18 +02004801 let Partial = function('Callback', ['one', 'two'])
Bram Moolenaar1735bc92016-03-14 23:05:14 +01004802 ...
Bram Moolenaar088e8e32019-08-08 22:15:18 +02004803 call Partial('name')
Bram Moolenaar1735bc92016-03-14 23:05:14 +01004804< Invokes the function as with: >
4805 call Callback('one', 'two', 'name')
4806
Bram Moolenaar088e8e32019-08-08 22:15:18 +02004807< With a |method|: >
4808 func Callback(one, two, three)
4809 ...
4810 let Partial = function('Callback', ['two'])
4811 ...
4812 eval 'one'->Partial('three')
4813< Invokes the function as with: >
4814 call Callback('one', 'two', 'three')
4815
Bram Moolenaar03602ec2016-03-20 20:57:45 +01004816< The function() call can be nested to add more arguments to the
4817 Funcref. The extra arguments are appended to the list of
4818 arguments. Example: >
4819 func Callback(arg1, arg2, name)
4820 ...
4821 let Func = function('Callback', ['one'])
4822 let Func2 = function(Func, ['two'])
4823 ...
4824 call Func2('name')
4825< Invokes the function as with: >
4826 call Callback('one', 'two', 'name')
4827
Bram Moolenaar1735bc92016-03-14 23:05:14 +01004828< The Dictionary is only useful when calling a "dict" function.
4829 In that case the {dict} is passed in as "self". Example: >
4830 function Callback() dict
4831 echo "called for " . self.name
4832 endfunction
4833 ...
4834 let context = {"name": "example"}
4835 let Func = function('Callback', context)
4836 ...
4837 call Func() " will echo: called for example
Bram Moolenaar975b5272016-03-15 23:10:59 +01004838< The use of function() is not needed when there are no extra
4839 arguments, these two are equivalent: >
4840 let Func = function('Callback', context)
4841 let Func = context.Callback
Bram Moolenaar1735bc92016-03-14 23:05:14 +01004842
4843< The argument list and the Dictionary can be combined: >
4844 function Callback(arg1, count) dict
4845 ...
4846 let context = {"name": "example"}
4847 let Func = function('Callback', ['one'], context)
4848 ...
4849 call Func(500)
4850< Invokes the function as with: >
4851 call context.Callback('one', 500)
Bram Moolenaara4208962019-08-24 20:50:19 +02004852<
4853 Can also be used as a |method|: >
4854 GetFuncname()->function([arg])
Bram Moolenaar1735bc92016-03-14 23:05:14 +01004855
Bram Moolenaara14de3d2005-01-07 21:48:26 +00004856
Bram Moolenaarf1568ec2011-12-14 21:17:39 +01004857garbagecollect([{atexit}]) *garbagecollect()*
Bram Moolenaarebf7dfa2016-04-14 12:46:51 +02004858 Cleanup unused |Lists|, |Dictionaries|, |Channels| and |Jobs|
4859 that have circular references.
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01004860
Bram Moolenaarebf7dfa2016-04-14 12:46:51 +02004861 There is hardly ever a need to invoke this function, as it is
4862 automatically done when Vim runs out of memory or is waiting
4863 for the user to press a key after 'updatetime'. Items without
4864 circular references are always freed when they become unused.
Bram Moolenaar32466aa2006-02-24 23:53:04 +00004865 This is useful if you have deleted a very big |List| and/or
4866 |Dictionary| with circular references in a script that runs
4867 for a long time.
Bram Moolenaarebf7dfa2016-04-14 12:46:51 +02004868
Bram Moolenaarf1568ec2011-12-14 21:17:39 +01004869 When the optional {atexit} argument is one, garbage
Bram Moolenaar9d2c8c12007-09-25 16:00:00 +00004870 collection will also be done when exiting Vim, if it wasn't
4871 done before. This is useful when checking for memory leaks.
Bram Moolenaar39a58ca2005-06-27 22:42:44 +00004872
Bram Moolenaar574860b2016-05-24 17:33:34 +02004873 The garbage collection is not done immediately but only when
4874 it's safe to perform. This is when waiting for the user to
4875 type a character. To force garbage collection immediately use
4876 |test_garbagecollect_now()|.
Bram Moolenaarebf7dfa2016-04-14 12:46:51 +02004877
Bram Moolenaar677ee682005-01-27 14:41:15 +00004878get({list}, {idx} [, {default}]) *get()*
Bram Moolenaar32466aa2006-02-24 23:53:04 +00004879 Get item {idx} from |List| {list}. When this item is not
Bram Moolenaara14de3d2005-01-07 21:48:26 +00004880 available return {default}. Return zero when {default} is
4881 omitted.
Bram Moolenaar7ff78462020-07-10 22:00:53 +02004882 Preferably used as a |method|: >
Bram Moolenaarac92e252019-08-03 21:58:38 +02004883 mylist->get(idx)
Bram Moolenaard8968242019-01-15 22:51:57 +01004884get({blob}, {idx} [, {default}])
4885 Get byte {idx} from |Blob| {blob}. When this byte is not
4886 available return {default}. Return -1 when {default} is
4887 omitted.
Bram Moolenaar7ff78462020-07-10 22:00:53 +02004888 Preferably used as a |method|: >
4889 myblob->get(idx)
Bram Moolenaar2fda12f2005-01-15 22:14:15 +00004890get({dict}, {key} [, {default}])
Bram Moolenaar32466aa2006-02-24 23:53:04 +00004891 Get item with key {key} from |Dictionary| {dict}. When this
Bram Moolenaar2fda12f2005-01-15 22:14:15 +00004892 item is not available return {default}. Return zero when
Bram Moolenaar54775062019-07-31 21:07:14 +02004893 {default} is omitted. Useful example: >
4894 let val = get(g:, 'var_name', 'default')
4895< This gets the value of g:var_name if it exists, and uses
4896 'default' when it does not exist.
Bram Moolenaar7ff78462020-07-10 22:00:53 +02004897 Preferably used as a |method|: >
4898 mydict->get(key)
Bram Moolenaar03e19a02016-05-24 22:29:49 +02004899get({func}, {what})
4900 Get an item with from Funcref {func}. Possible values for
Bram Moolenaar2bbf8ef2016-05-24 18:37:12 +02004901 {what} are:
Bram Moolenaar214641f2017-03-05 17:04:09 +01004902 "name" The function name
4903 "func" The function
4904 "dict" The dictionary
4905 "args" The list with arguments
Bram Moolenaar7ff78462020-07-10 22:00:53 +02004906 Preferably used as a |method|: >
4907 myfunc->get(what)
4908<
Bram Moolenaarb5ae48e2016-08-12 22:23:25 +02004909 *getbufinfo()*
4910getbufinfo([{expr}])
4911getbufinfo([{dict}])
Bram Moolenaar58b85342016-08-14 19:54:54 +02004912 Get information about buffers as a List of Dictionaries.
Bram Moolenaarb5ae48e2016-08-12 22:23:25 +02004913
4914 Without an argument information about all the buffers is
4915 returned.
4916
Bram Moolenaare46a4402020-06-30 20:38:27 +02004917 When the argument is a |Dictionary| only the buffers matching
Bram Moolenaarb5ae48e2016-08-12 22:23:25 +02004918 the specified criteria are returned. The following keys can
4919 be specified in {dict}:
4920 buflisted include only listed buffers.
4921 bufloaded include only loaded buffers.
Bram Moolenaar8e6a31d2017-12-10 21:06:22 +01004922 bufmodified include only modified buffers.
Bram Moolenaarb5ae48e2016-08-12 22:23:25 +02004923
4924 Otherwise, {expr} specifies a particular buffer to return
4925 information for. For the use of {expr}, see |bufname()|
4926 above. If the buffer is found the returned List has one item.
4927 Otherwise the result is an empty list.
4928
4929 Each returned List item is a dictionary with the following
4930 entries:
Bram Moolenaare7b1ea02020-08-07 19:54:59 +02004931 bufnr Buffer number.
Bram Moolenaarb5ae48e2016-08-12 22:23:25 +02004932 changed TRUE if the buffer is modified.
Bram Moolenaare7b1ea02020-08-07 19:54:59 +02004933 changedtick Number of changes made to the buffer.
Bram Moolenaarb5ae48e2016-08-12 22:23:25 +02004934 hidden TRUE if the buffer is hidden.
Bram Moolenaare7b1ea02020-08-07 19:54:59 +02004935 lastused Timestamp in seconds, like
Bram Moolenaar52410572019-10-27 05:12:45 +01004936 |localtime()|, when the buffer was
4937 last used.
4938 {only with the |+viminfo| feature}
Bram Moolenaarb5ae48e2016-08-12 22:23:25 +02004939 listed TRUE if the buffer is listed.
Bram Moolenaare7b1ea02020-08-07 19:54:59 +02004940 lnum Line number used for the buffer when
4941 opened in the current window.
4942 linecount Number of lines in the buffer (only
Bram Moolenaara9e96792019-12-17 22:40:15 +01004943 valid when loaded)
Bram Moolenaarb5ae48e2016-08-12 22:23:25 +02004944 loaded TRUE if the buffer is loaded.
Bram Moolenaare7b1ea02020-08-07 19:54:59 +02004945 name Full path to the file in the buffer.
4946 signs List of signs placed in the buffer.
Bram Moolenaarb5ae48e2016-08-12 22:23:25 +02004947 Each list item is a dictionary with
4948 the following fields:
4949 id sign identifier
4950 lnum line number
4951 name sign name
Bram Moolenaare7b1ea02020-08-07 19:54:59 +02004952 variables A reference to the dictionary with
Bram Moolenaar30567352016-08-27 21:25:44 +02004953 buffer-local variables.
Bram Moolenaare7b1ea02020-08-07 19:54:59 +02004954 windows List of |window-ID|s that display this
Bram Moolenaar30567352016-08-27 21:25:44 +02004955 buffer
Bram Moolenaare7b1ea02020-08-07 19:54:59 +02004956 popups List of popup |window-ID|s that
Bram Moolenaar5ca1ac32019-07-04 15:39:28 +02004957 display this buffer
Bram Moolenaarb5ae48e2016-08-12 22:23:25 +02004958
4959 Examples: >
4960 for buf in getbufinfo()
4961 echo buf.name
4962 endfor
4963 for buf in getbufinfo({'buflisted':1})
Bram Moolenaar30567352016-08-27 21:25:44 +02004964 if buf.changed
Bram Moolenaarb5ae48e2016-08-12 22:23:25 +02004965 ....
4966 endif
4967 endfor
4968<
Bram Moolenaar30567352016-08-27 21:25:44 +02004969 To get buffer-local options use: >
Bram Moolenaard473c8c2018-08-11 18:00:22 +02004970 getbufvar({bufnr}, '&option_name')
Bram Moolenaar30567352016-08-27 21:25:44 +02004971<
Bram Moolenaar6434fc52020-07-18 22:24:22 +02004972 Can also be used as a |method|: >
4973 GetBufnr()->getbufinfo()
4974<
4975
Bram Moolenaar45360022005-07-21 21:08:21 +00004976 *getbufline()*
4977getbufline({expr}, {lnum} [, {end}])
Bram Moolenaar32466aa2006-02-24 23:53:04 +00004978 Return a |List| with the lines starting from {lnum} to {end}
4979 (inclusive) in the buffer {expr}. If {end} is omitted, a
4980 |List| with only the line {lnum} is returned.
Bram Moolenaar45360022005-07-21 21:08:21 +00004981
4982 For the use of {expr}, see |bufname()| above.
4983
Bram Moolenaar661b1822005-07-28 22:36:45 +00004984 For {lnum} and {end} "$" can be used for the last line of the
4985 buffer. Otherwise a number must be used.
Bram Moolenaar45360022005-07-21 21:08:21 +00004986
4987 When {lnum} is smaller than 1 or bigger than the number of
Bram Moolenaar32466aa2006-02-24 23:53:04 +00004988 lines in the buffer, an empty |List| is returned.
Bram Moolenaar45360022005-07-21 21:08:21 +00004989
4990 When {end} is greater than the number of lines in the buffer,
4991 it is treated as {end} is set to the number of lines in the
Bram Moolenaar32466aa2006-02-24 23:53:04 +00004992 buffer. When {end} is before {lnum} an empty |List| is
Bram Moolenaar45360022005-07-21 21:08:21 +00004993 returned.
4994
Bram Moolenaar661b1822005-07-28 22:36:45 +00004995 This function works only for loaded buffers. For unloaded and
Bram Moolenaar32466aa2006-02-24 23:53:04 +00004996 non-existing buffers, an empty |List| is returned.
Bram Moolenaar45360022005-07-21 21:08:21 +00004997
4998 Example: >
4999 :let lines = getbufline(bufnr("myfile"), 1, "$")
Bram Moolenaara14de3d2005-01-07 21:48:26 +00005000
Bram Moolenaar4c313b12019-08-24 22:58:31 +02005001< Can also be used as a |method|: >
5002 GetBufnr()->getbufline(lnum)
5003
Bram Moolenaar63dbda12013-02-20 21:12:10 +01005004getbufvar({expr}, {varname} [, {def}]) *getbufvar()*
Bram Moolenaara14de3d2005-01-07 21:48:26 +00005005 The result is the value of option or local buffer variable
5006 {varname} in buffer {expr}. Note that the name without "b:"
5007 must be used.
Bram Moolenaarc236c162008-07-13 17:41:49 +00005008 When {varname} is empty returns a dictionary with all the
5009 buffer-local variables.
Bram Moolenaar30567352016-08-27 21:25:44 +02005010 When {varname} is equal to "&" returns a dictionary with all
5011 the buffer-local options.
5012 Otherwise, when {varname} starts with "&" returns the value of
5013 a buffer-local option.
Bram Moolenaar4317d9b2005-03-18 20:25:31 +00005014 This also works for a global or buffer-local option, but it
5015 doesn't work for a global variable, window-local variable or
5016 window-local option.
Bram Moolenaara14de3d2005-01-07 21:48:26 +00005017 For the use of {expr}, see |bufname()| above.
Bram Moolenaar63dbda12013-02-20 21:12:10 +01005018 When the buffer or variable doesn't exist {def} or an empty
5019 string is returned, there is no error message.
Bram Moolenaara14de3d2005-01-07 21:48:26 +00005020 Examples: >
5021 :let bufmodified = getbufvar(1, "&mod")
5022 :echo "todo myvar = " . getbufvar("todo", "myvar")
Bram Moolenaar4c313b12019-08-24 22:58:31 +02005023
5024< Can also be used as a |method|: >
5025 GetBufnr()->getbufvar(varname)
Bram Moolenaara14de3d2005-01-07 21:48:26 +00005026<
Bram Moolenaar4c313b12019-08-24 22:58:31 +02005027getchangelist([{expr}]) *getchangelist()*
Bram Moolenaar07ad8162018-02-13 13:59:59 +01005028 Returns the |changelist| for the buffer {expr}. For the use
5029 of {expr}, see |bufname()| above. If buffer {expr} doesn't
5030 exist, an empty list is returned.
5031
5032 The returned list contains two entries: a list with the change
5033 locations and the current position in the list. Each
5034 entry in the change list is a dictionary with the following
5035 entries:
5036 col column number
5037 coladd column offset for 'virtualedit'
5038 lnum line number
5039 If buffer {expr} is the current buffer, then the current
5040 position refers to the position in the list. For other
5041 buffers, it is set to the length of the list.
5042
Bram Moolenaar4c313b12019-08-24 22:58:31 +02005043 Can also be used as a |method|: >
5044 GetBufnr()->getchangelist()
5045
Bram Moolenaar071d4272004-06-13 20:20:40 +00005046getchar([expr]) *getchar()*
Bram Moolenaar91170f82006-05-05 21:15:17 +00005047 Get a single character from the user or input stream.
Bram Moolenaar071d4272004-06-13 20:20:40 +00005048 If [expr] is omitted, wait until a character is available.
5049 If [expr] is 0, only get a character when one is available.
Bram Moolenaar91170f82006-05-05 21:15:17 +00005050 Return zero otherwise.
Bram Moolenaar071d4272004-06-13 20:20:40 +00005051 If [expr] is 1, only check if a character is available, it is
Bram Moolenaar91170f82006-05-05 21:15:17 +00005052 not consumed. Return zero if no character available.
5053
Bram Moolenaardfb18412013-12-11 18:53:29 +01005054 Without [expr] and when [expr] is 0 a whole character or
Bram Moolenaarc577d812017-07-08 22:37:34 +02005055 special key is returned. If it is a single character, the
Bram Moolenaar91170f82006-05-05 21:15:17 +00005056 result is a number. Use nr2char() to convert it to a String.
5057 Otherwise a String is returned with the encoded character.
Bram Moolenaarc577d812017-07-08 22:37:34 +02005058 For a special key it's a String with a sequence of bytes
5059 starting with 0x80 (decimal: 128). This is the same value as
5060 the String "\<Key>", e.g., "\<Left>". The returned value is
5061 also a String when a modifier (shift, control, alt) was used
5062 that is not included in the character.
Bram Moolenaar91170f82006-05-05 21:15:17 +00005063
Bram Moolenaar822ff862014-06-12 21:46:14 +02005064 When [expr] is 0 and Esc is typed, there will be a short delay
5065 while Vim waits to see if this is the start of an escape
5066 sequence.
5067
Bram Moolenaardfb18412013-12-11 18:53:29 +01005068 When [expr] is 1 only the first byte is returned. For a
Bram Moolenaar56a907a2006-05-06 21:44:30 +00005069 one-byte character it is the character itself as a number.
5070 Use nr2char() to convert it to a String.
Bram Moolenaar91170f82006-05-05 21:15:17 +00005071
Bram Moolenaarf1568ec2011-12-14 21:17:39 +01005072 Use getcharmod() to obtain any additional modifiers.
5073
Bram Moolenaar219b8702006-11-01 14:32:36 +00005074 When the user clicks a mouse button, the mouse event will be
5075 returned. The position can then be found in |v:mouse_col|,
Bram Moolenaardb3a2052019-11-16 18:22:41 +01005076 |v:mouse_lnum|, |v:mouse_winid| and |v:mouse_win|.
Bram Moolenaarae97b942020-07-09 19:16:35 +02005077 |getmousepos()| can also be used. Mouse move events will be
5078 ignored.
5079 This example positions the mouse as it would normally happen: >
Bram Moolenaar219b8702006-11-01 14:32:36 +00005080 let c = getchar()
Bram Moolenaar446cb832008-06-24 21:56:24 +00005081 if c == "\<LeftMouse>" && v:mouse_win > 0
Bram Moolenaar219b8702006-11-01 14:32:36 +00005082 exe v:mouse_win . "wincmd w"
5083 exe v:mouse_lnum
5084 exe "normal " . v:mouse_col . "|"
5085 endif
5086<
Bram Moolenaar690afe12017-01-28 18:34:47 +01005087 When using bracketed paste only the first character is
5088 returned, the rest of the pasted text is dropped.
5089 |xterm-bracketed-paste|.
5090
Bram Moolenaar071d4272004-06-13 20:20:40 +00005091 There is no prompt, you will somehow have to make clear to the
5092 user that a character has to be typed.
5093 There is no mapping for the character.
5094 Key codes are replaced, thus when the user presses the <Del>
5095 key you get the code for the <Del> key, not the raw character
5096 sequence. Examples: >
5097 getchar() == "\<Del>"
5098 getchar() == "\<S-Left>"
5099< This example redefines "f" to ignore case: >
5100 :nmap f :call FindChar()<CR>
5101 :function FindChar()
5102 : let c = nr2char(getchar())
5103 : while col('.') < col('$') - 1
5104 : normal l
5105 : if getline('.')[col('.') - 1] ==? c
5106 : break
5107 : endif
5108 : endwhile
5109 :endfunction
Bram Moolenaared32d942014-12-06 23:33:00 +01005110<
Bram Moolenaar2b8388b2015-02-28 13:11:45 +01005111 You may also receive synthetic characters, such as
Bram Moolenaared32d942014-12-06 23:33:00 +01005112 |<CursorHold>|. Often you will want to ignore this and get
5113 another character: >
5114 :function GetKey()
5115 : let c = getchar()
5116 : while c == "\<CursorHold>"
5117 : let c = getchar()
5118 : endwhile
5119 : return c
5120 :endfunction
Bram Moolenaar071d4272004-06-13 20:20:40 +00005121
5122getcharmod() *getcharmod()*
5123 The result is a Number which is the state of the modifiers for
5124 the last obtained character with getchar() or in another way.
5125 These values are added together:
5126 2 shift
5127 4 control
5128 8 alt (meta)
Bram Moolenaarf1568ec2011-12-14 21:17:39 +01005129 16 meta (when it's different from ALT)
5130 32 mouse double click
5131 64 mouse triple click
5132 96 mouse quadruple click (== 32 + 64)
5133 128 command (Macintosh only)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005134 Only the modifiers that have not been included in the
Bram Moolenaar58b85342016-08-14 19:54:54 +02005135 character itself are obtained. Thus Shift-a results in "A"
Bram Moolenaar8f3f58f2010-01-06 20:52:26 +01005136 without a modifier.
Bram Moolenaar071d4272004-06-13 20:20:40 +00005137
Bram Moolenaardbd24b52015-08-11 14:26:19 +02005138getcharsearch() *getcharsearch()*
5139 Return the current character search information as a {dict}
5140 with the following entries:
5141
5142 char character previously used for a character
5143 search (|t|, |f|, |T|, or |F|); empty string
5144 if no character search has been performed
5145 forward direction of character search; 1 for forward,
5146 0 for backward
5147 until type of character search; 1 for a |t| or |T|
5148 character search, 0 for an |f| or |F|
5149 character search
5150
5151 This can be useful to always have |;| and |,| search
5152 forward/backward regardless of the direction of the previous
5153 character search: >
5154 :nnoremap <expr> ; getcharsearch().forward ? ';' : ','
5155 :nnoremap <expr> , getcharsearch().forward ? ',' : ';'
5156< Also see |setcharsearch()|.
5157
Bram Moolenaar071d4272004-06-13 20:20:40 +00005158getcmdline() *getcmdline()*
5159 Return the current command-line. Only works when the command
5160 line is being edited, thus requires use of |c_CTRL-\_e| or
5161 |c_CTRL-R_=|.
5162 Example: >
5163 :cmap <F7> <C-\>eescape(getcmdline(), ' \')<CR>
Bram Moolenaarbfd8fc02005-09-20 23:22:24 +00005164< Also see |getcmdtype()|, |getcmdpos()| and |setcmdpos()|.
Bram Moolenaar95bafa22018-10-02 13:26:25 +02005165 Returns an empty string when entering a password or using
5166 |inputsecret()|.
Bram Moolenaar071d4272004-06-13 20:20:40 +00005167
Bram Moolenaar5f2bb9f2005-01-11 21:29:04 +00005168getcmdpos() *getcmdpos()*
Bram Moolenaar071d4272004-06-13 20:20:40 +00005169 Return the position of the cursor in the command line as a
5170 byte count. The first column is 1.
5171 Only works when editing the command line, thus requires use of
Bram Moolenaar5b435d62012-04-05 17:33:26 +02005172 |c_CTRL-\_e| or |c_CTRL-R_=| or an expression mapping.
5173 Returns 0 otherwise.
Bram Moolenaarbfd8fc02005-09-20 23:22:24 +00005174 Also see |getcmdtype()|, |setcmdpos()| and |getcmdline()|.
5175
5176getcmdtype() *getcmdtype()*
5177 Return the current command-line type. Possible return values
5178 are:
Bram Moolenaar1e015462005-09-25 22:16:38 +00005179 : normal Ex command
5180 > debug mode command |debug-mode|
5181 / forward search command
5182 ? backward search command
5183 @ |input()| command
5184 - |:insert| or |:append| command
Bram Moolenaar6e932462014-09-09 18:48:09 +02005185 = |i_CTRL-R_=|
Bram Moolenaarbfd8fc02005-09-20 23:22:24 +00005186 Only works when editing the command line, thus requires use of
Bram Moolenaar5b435d62012-04-05 17:33:26 +02005187 |c_CTRL-\_e| or |c_CTRL-R_=| or an expression mapping.
5188 Returns an empty string otherwise.
Bram Moolenaarbfd8fc02005-09-20 23:22:24 +00005189 Also see |getcmdpos()|, |setcmdpos()| and |getcmdline()|.
Bram Moolenaar071d4272004-06-13 20:20:40 +00005190
Bram Moolenaarfb539272014-08-22 19:21:47 +02005191getcmdwintype() *getcmdwintype()*
5192 Return the current |command-line-window| type. Possible return
5193 values are the same as |getcmdtype()|. Returns an empty string
5194 when not in the command-line window.
5195
Bram Moolenaare9d58a62016-08-13 15:07:41 +02005196getcompletion({pat}, {type} [, {filtered}]) *getcompletion()*
Bram Moolenaaraa4d7322016-07-09 18:50:29 +02005197 Return a list of command-line completion matches. {type}
5198 specifies what for. The following completion types are
5199 supported:
5200
Bram Moolenaarcd43eff2018-03-29 15:55:38 +02005201 arglist file names in argument list
Bram Moolenaaraa4d7322016-07-09 18:50:29 +02005202 augroup autocmd groups
5203 buffer buffer names
5204 behave :behave suboptions
5205 color color schemes
5206 command Ex command (and arguments)
Bram Moolenaar1f1fd442020-06-07 18:45:14 +02005207 cmdline |cmdline-completion| result
Bram Moolenaaraa4d7322016-07-09 18:50:29 +02005208 compiler compilers
5209 cscope |:cscope| suboptions
Bram Moolenaarae7dba82019-12-29 13:56:33 +01005210 diff_buffer |:diffget| and |:diffput| completion
Bram Moolenaaraa4d7322016-07-09 18:50:29 +02005211 dir directory names
5212 environment environment variable names
5213 event autocommand events
5214 expression Vim expression
5215 file file and directory names
5216 file_in_path file and directory names in |'path'|
5217 filetype filetype names |'filetype'|
5218 function function name
5219 help help subjects
5220 highlight highlight groups
5221 history :history suboptions
5222 locale locale names (as output of locale -a)
Bram Moolenaar73fef332020-06-21 22:12:03 +02005223 mapclear buffer argument
Bram Moolenaaraa4d7322016-07-09 18:50:29 +02005224 mapping mapping name
5225 menu menus
Bram Moolenaar9e507ca2016-10-15 15:39:39 +02005226 messages |:messages| suboptions
Bram Moolenaaraa4d7322016-07-09 18:50:29 +02005227 option options
Bram Moolenaar9e507ca2016-10-15 15:39:39 +02005228 packadd optional package |pack-add| names
Bram Moolenaaraa4d7322016-07-09 18:50:29 +02005229 shellcmd Shell command
5230 sign |:sign| suboptions
5231 syntax syntax file names |'syntax'|
5232 syntime |:syntime| suboptions
5233 tag tags
5234 tag_listfiles tags, file names
5235 user user names
5236 var user variables
5237
Bram Moolenaar1f1fd442020-06-07 18:45:14 +02005238 If {pat} is an empty string, then all the matches are
5239 returned. Otherwise only items matching {pat} are returned.
5240 See |wildcards| for the use of special characters in {pat}.
Bram Moolenaaraa4d7322016-07-09 18:50:29 +02005241
Bram Moolenaare9d58a62016-08-13 15:07:41 +02005242 If the optional {filtered} flag is set to 1, then 'wildignore'
5243 is applied to filter the results. Otherwise all the matches
5244 are returned. The 'wildignorecase' option always applies.
5245
Bram Moolenaar1f1fd442020-06-07 18:45:14 +02005246 If {type} is "cmdline", then the |cmdline-completion| result is
5247 returned. For example, to complete the possible values after
5248 a ":call" command: >
Bram Moolenaar73fef332020-06-21 22:12:03 +02005249 echo getcompletion('call ', 'cmdline')
Bram Moolenaar1f1fd442020-06-07 18:45:14 +02005250<
Bram Moolenaaraa4d7322016-07-09 18:50:29 +02005251 If there are no matches, an empty list is returned. An
5252 invalid value for {type} produces an error.
5253
Bram Moolenaar4c313b12019-08-24 22:58:31 +02005254 Can also be used as a |method|: >
5255 GetPattern()->getcompletion('color')
5256<
Bram Moolenaar6f6c0f82014-05-28 20:31:42 +02005257 *getcurpos()*
5258getcurpos() Get the position of the cursor. This is like getpos('.'), but
Bram Moolenaard1caa942020-04-10 22:10:56 +02005259 includes an extra "curswant" item in the list:
5260 [0, lnum, col, off, curswant] ~
Bram Moolenaar6f6c0f82014-05-28 20:31:42 +02005261 The "curswant" number is the preferred column when moving the
Bram Moolenaarcd5c8f82017-04-09 20:11:58 +02005262 cursor vertically. Also see |getpos()|.
Bram Moolenaard1caa942020-04-10 22:10:56 +02005263 The first "bufnum" item is always zero.
Bram Moolenaarcd5c8f82017-04-09 20:11:58 +02005264
Bram Moolenaar6f6c0f82014-05-28 20:31:42 +02005265 This can be used to save and restore the cursor position: >
5266 let save_cursor = getcurpos()
5267 MoveTheCursorAround
5268 call setpos('.', save_cursor)
Bram Moolenaarcd5c8f82017-04-09 20:11:58 +02005269< Note that this only works within the window. See
5270 |winrestview()| for restoring more state.
Bram Moolenaar071d4272004-06-13 20:20:40 +00005271 *getcwd()*
Bram Moolenaarc9703302016-01-17 21:49:33 +01005272getcwd([{winnr} [, {tabnr}]])
5273 The result is a String, which is the name of the current
Bram Moolenaar071d4272004-06-13 20:20:40 +00005274 working directory.
Bram Moolenaarc9703302016-01-17 21:49:33 +01005275
5276 With {winnr} return the local current directory of this window
Bram Moolenaar54591292018-02-09 20:53:59 +01005277 in the current tab page. {winnr} can be the window number or
5278 the |window-ID|.
5279 If {winnr} is -1 return the name of the global working
5280 directory. See also |haslocaldir()|.
5281
Bram Moolenaarc9703302016-01-17 21:49:33 +01005282 With {winnr} and {tabnr} return the local current directory of
Bram Moolenaar00aa0692019-04-27 20:37:57 +02005283 the window in the specified tab page. If {winnr} is -1 return
5284 the working directory of the tabpage.
5285 If {winnr} is zero use the current window, if {tabnr} is zero
5286 use the current tabpage.
5287 Without any arguments, return the working directory of the
5288 current window.
Bram Moolenaarc9703302016-01-17 21:49:33 +01005289 Return an empty string if the arguments are invalid.
Bram Moolenaar071d4272004-06-13 20:20:40 +00005290
Bram Moolenaar00aa0692019-04-27 20:37:57 +02005291 Examples: >
5292 " Get the working directory of the current window
5293 :echo getcwd()
5294 :echo getcwd(0)
5295 :echo getcwd(0, 0)
5296 " Get the working directory of window 3 in tabpage 2
5297 :echo getcwd(3, 2)
5298 " Get the global working directory
5299 :echo getcwd(-1)
5300 " Get the working directory of tabpage 3
5301 :echo getcwd(-1, 3)
5302 " Get the working directory of current tabpage
5303 :echo getcwd(-1, 0)
Bram Moolenaar4c313b12019-08-24 22:58:31 +02005304
5305< Can also be used as a |method|: >
5306 GetWinnr()->getcwd()
Bram Moolenaar00aa0692019-04-27 20:37:57 +02005307<
Bram Moolenaar691ddee2019-05-09 14:52:41 +02005308getenv({name}) *getenv()*
5309 Return the value of environment variable {name}.
5310 When the variable does not exist |v:null| is returned. That
Bram Moolenaar54775062019-07-31 21:07:14 +02005311 is different from a variable set to an empty string, although
5312 some systems interpret the empty value as the variable being
5313 deleted. See also |expr-env|.
Bram Moolenaar071d4272004-06-13 20:20:40 +00005314
Bram Moolenaar4c313b12019-08-24 22:58:31 +02005315 Can also be used as a |method|: >
5316 GetVarname()->getenv()
5317
Bram Moolenaard8b0cf12004-12-12 11:33:30 +00005318getfontname([{name}]) *getfontname()*
5319 Without an argument returns the name of the normal font being
5320 used. Like what is used for the Normal highlight group
5321 |hl-Normal|.
5322 With an argument a check is done whether {name} is a valid
5323 font name. If not then an empty string is returned.
5324 Otherwise the actual font name is returned, or {name} if the
5325 GUI does not support obtaining the real name.
Bram Moolenaarc6fe9192006-04-09 21:54:49 +00005326 Only works when the GUI is running, thus not in your vimrc or
Bram Moolenaard8b0cf12004-12-12 11:33:30 +00005327 gvimrc file. Use the |GUIEnter| autocommand to use this
5328 function just after the GUI has started.
Bram Moolenaar3df01732017-02-17 22:47:16 +01005329 Note that the GTK GUI accepts any font name, thus checking for
5330 a valid name does not work.
Bram Moolenaard8b0cf12004-12-12 11:33:30 +00005331
Bram Moolenaar5eb86f92004-07-26 12:53:41 +00005332getfperm({fname}) *getfperm()*
5333 The result is a String, which is the read, write, and execute
5334 permissions of the given file {fname}.
5335 If {fname} does not exist or its directory cannot be read, an
5336 empty string is returned.
5337 The result is of the form "rwxrwxrwx", where each group of
5338 "rwx" flags represent, in turn, the permissions of the owner
5339 of the file, the group the file belongs to, and other users.
5340 If a user does not have a given permission the flag for this
Bram Moolenaar9b451252012-08-15 17:43:31 +02005341 is replaced with the string "-". Examples: >
Bram Moolenaar5eb86f92004-07-26 12:53:41 +00005342 :echo getfperm("/etc/passwd")
Bram Moolenaar9b451252012-08-15 17:43:31 +02005343 :echo getfperm(expand("~/.vimrc"))
Bram Moolenaar5eb86f92004-07-26 12:53:41 +00005344< This will hopefully (from a security point of view) display
5345 the string "rw-r--r--" or even "rw-------".
Bram Moolenaare2cc9702005-03-15 22:43:58 +00005346
Bram Moolenaar4c313b12019-08-24 22:58:31 +02005347 Can also be used as a |method|: >
5348 GetFilename()->getfperm()
5349<
Bram Moolenaar2ec618c2016-10-01 14:47:05 +02005350 For setting permissions use |setfperm()|.
Bram Moolenaar80492532016-03-08 17:08:53 +01005351
Bram Moolenaar691ddee2019-05-09 14:52:41 +02005352getfsize({fname}) *getfsize()*
5353 The result is a Number, which is the size in bytes of the
5354 given file {fname}.
5355 If {fname} is a directory, 0 is returned.
5356 If the file {fname} can't be found, -1 is returned.
5357 If the size of {fname} is too big to fit in a Number then -2
5358 is returned.
5359
Bram Moolenaar4c313b12019-08-24 22:58:31 +02005360 Can also be used as a |method|: >
5361 GetFilename()->getfsize()
5362
Bram Moolenaar071d4272004-06-13 20:20:40 +00005363getftime({fname}) *getftime()*
5364 The result is a Number, which is the last modification time of
5365 the given file {fname}. The value is measured as seconds
5366 since 1st Jan 1970, and may be passed to strftime(). See also
5367 |localtime()| and |strftime()|.
5368 If the file {fname} can't be found -1 is returned.
5369
Bram Moolenaar4c313b12019-08-24 22:58:31 +02005370 Can also be used as a |method|: >
5371 GetFilename()->getftime()
5372
Bram Moolenaar5eb86f92004-07-26 12:53:41 +00005373getftype({fname}) *getftype()*
5374 The result is a String, which is a description of the kind of
5375 file of the given file {fname}.
5376 If {fname} does not exist an empty string is returned.
5377 Here is a table over different kinds of files and their
5378 results:
5379 Normal file "file"
5380 Directory "dir"
5381 Symbolic link "link"
5382 Block device "bdev"
5383 Character device "cdev"
5384 Socket "socket"
5385 FIFO "fifo"
5386 All other "other"
5387 Example: >
5388 getftype("/home")
5389< Note that a type such as "link" will only be returned on
5390 systems that support it. On some systems only "dir" and
Bram Moolenaar13d5aee2016-01-21 23:36:05 +01005391 "file" are returned. On MS-Windows a symbolic link to a
5392 directory returns "dir" instead of "link".
Bram Moolenaar5eb86f92004-07-26 12:53:41 +00005393
Bram Moolenaar4c313b12019-08-24 22:58:31 +02005394 Can also be used as a |method|: >
5395 GetFilename()->getftype()
5396
Bram Moolenaara3a12462019-09-07 15:08:38 +02005397getimstatus() *getimstatus()*
5398 The result is a Number, which is |TRUE| when the IME status is
5399 active.
5400 See 'imstatusfunc'.
5401
Bram Moolenaard96ff162018-02-18 22:13:29 +01005402getjumplist([{winnr} [, {tabnr}]]) *getjumplist()*
Bram Moolenaar4f505882018-02-10 21:06:32 +01005403 Returns the |jumplist| for the specified window.
5404
5405 Without arguments use the current window.
5406 With {winnr} only use this window in the current tab page.
5407 {winnr} can also be a |window-ID|.
5408 With {winnr} and {tabnr} use the window in the specified tab
5409 page.
5410
5411 The returned list contains two entries: a list with the jump
5412 locations and the last used jump position number in the list.
5413 Each entry in the jump location list is a dictionary with
5414 the following entries:
5415 bufnr buffer number
5416 col column number
5417 coladd column offset for 'virtualedit'
5418 filename filename if available
5419 lnum line number
5420
Bram Moolenaar4c313b12019-08-24 22:58:31 +02005421 Can also be used as a |method|: >
5422 GetWinnr()->getjumplist()
5423
5424< *getline()*
Bram Moolenaara14de3d2005-01-07 21:48:26 +00005425getline({lnum} [, {end}])
5426 Without {end} the result is a String, which is line {lnum}
5427 from the current buffer. Example: >
Bram Moolenaar071d4272004-06-13 20:20:40 +00005428 getline(1)
5429< When {lnum} is a String that doesn't start with a
Bram Moolenaarf2732452018-06-03 14:47:35 +02005430 digit, |line()| is called to translate the String into a Number.
Bram Moolenaar071d4272004-06-13 20:20:40 +00005431 To get the line under the cursor: >
5432 getline(".")
5433< When {lnum} is smaller than 1 or bigger than the number of
5434 lines in the buffer, an empty string is returned.
5435
Bram Moolenaar32466aa2006-02-24 23:53:04 +00005436 When {end} is given the result is a |List| where each item is
5437 a line from the current buffer in the range {lnum} to {end},
Bram Moolenaara14de3d2005-01-07 21:48:26 +00005438 including line {end}.
5439 {end} is used in the same way as {lnum}.
5440 Non-existing lines are silently omitted.
Bram Moolenaar32466aa2006-02-24 23:53:04 +00005441 When {end} is before {lnum} an empty |List| is returned.
Bram Moolenaara14de3d2005-01-07 21:48:26 +00005442 Example: >
5443 :let start = line('.')
5444 :let end = search("^$") - 1
5445 :let lines = getline(start, end)
5446
Bram Moolenaar4c313b12019-08-24 22:58:31 +02005447< Can also be used as a |method|: >
5448 ComputeLnum()->getline()
5449
Bram Moolenaaref2f6562007-05-06 13:32:59 +00005450< To get lines from another buffer see |getbufline()|
5451
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01005452getloclist({nr} [, {what}]) *getloclist()*
Bram Moolenaare46a4402020-06-30 20:38:27 +02005453 Returns a |List| with all the entries in the location list for
Bram Moolenaar7571d552016-08-18 22:54:46 +02005454 window {nr}. {nr} can be the window number or the |window-ID|.
Bram Moolenaar888ccac2016-06-04 18:49:36 +02005455 When {nr} is zero the current window is used.
5456
Bram Moolenaar17c7c012006-01-26 22:25:15 +00005457 For a location list window, the displayed location list is
Bram Moolenaar280f1262006-01-30 00:14:18 +00005458 returned. For an invalid window number {nr}, an empty list is
Bram Moolenaar8f3f58f2010-01-06 20:52:26 +01005459 returned. Otherwise, same as |getqflist()|.
Bram Moolenaara14de3d2005-01-07 21:48:26 +00005460
Bram Moolenaard823fa92016-08-12 16:29:27 +02005461 If the optional {what} dictionary argument is supplied, then
5462 returns the items listed in {what} as a dictionary. Refer to
5463 |getqflist()| for the supported items in {what}.
Bram Moolenaar647e24b2019-03-17 16:39:46 +01005464
5465 In addition to the items supported by |getqflist()| in {what},
5466 the following item is supported by |getloclist()|:
5467
Bram Moolenaar68e65602019-05-26 21:33:31 +02005468 filewinid id of the window used to display files
Bram Moolenaar647e24b2019-03-17 16:39:46 +01005469 from the location list. This field is
5470 applicable only when called from a
5471 location list window. See
5472 |location-list-file-window| for more
5473 details.
Bram Moolenaard823fa92016-08-12 16:29:27 +02005474
Bram Moolenaare46a4402020-06-30 20:38:27 +02005475 Returns an empty Dictionary if there is no location list for
5476 the window {nr} or the window is not present.
5477
5478 Examples (See also |getqflist-examples|): >
5479 :echo getloclist(3, {'all': 0})
5480 :echo getloclist(5, {'filewinid': 0})
5481
5482
Bram Moolenaare7b1ea02020-08-07 19:54:59 +02005483getmarklist([{expr}]) *getmarklist()*
Bram Moolenaarcfb4b472020-05-31 15:41:57 +02005484 Without the {expr} argument returns a |List| with information
5485 about all the global marks. |mark|
5486
5487 If the optional {expr} argument is specified, returns the
5488 local marks defined in buffer {expr}. For the use of {expr},
5489 see |bufname()|.
5490
5491 Each item in the retuned List is a |Dict| with the following:
5492 name - name of the mark prefixed by "'"
5493 pos - a |List| with the position of the mark:
5494 [bufnum, lnum, col, off]
5495 Refer to |getpos()| for more information.
5496 file - file name
5497
5498 Refer to |getpos()| for getting information about a specific
5499 mark.
5500
Bram Moolenaarf17e7ea2020-06-01 14:14:44 +02005501 Can also be used as a |method|: >
5502 GetBufnr()->getmarklist()
Bram Moolenaarcfb4b472020-05-31 15:41:57 +02005503
Bram Moolenaaraff74912019-03-30 18:11:49 +01005504getmatches([{win}]) *getmatches()*
Bram Moolenaarfd133322019-03-29 12:20:27 +01005505 Returns a |List| with all matches previously defined for the
5506 current window by |matchadd()| and the |:match| commands.
5507 |getmatches()| is useful in combination with |setmatches()|,
5508 as |setmatches()| can restore a list of matches saved by
5509 |getmatches()|.
Bram Moolenaar6ee10162007-07-26 20:58:42 +00005510 Example: >
5511 :echo getmatches()
5512< [{'group': 'MyGroup1', 'pattern': 'TODO',
5513 'priority': 10, 'id': 1}, {'group': 'MyGroup2',
5514 'pattern': 'FIXME', 'priority': 10, 'id': 2}] >
5515 :let m = getmatches()
5516 :call clearmatches()
5517 :echo getmatches()
5518< [] >
5519 :call setmatches(m)
5520 :echo getmatches()
5521< [{'group': 'MyGroup1', 'pattern': 'TODO',
5522 'priority': 10, 'id': 1}, {'group': 'MyGroup2',
5523 'pattern': 'FIXME', 'priority': 10, 'id': 2}] >
5524 :unlet m
5525<
Bram Moolenaardb3a2052019-11-16 18:22:41 +01005526getmousepos() *getmousepos()*
Bram Moolenaare46a4402020-06-30 20:38:27 +02005527 Returns a |Dictionary| with the last known position of the
Bram Moolenaardb3a2052019-11-16 18:22:41 +01005528 mouse. This can be used in a mapping for a mouse click or in
5529 a filter of a popup window. The items are:
5530 screenrow screen row
5531 screencol screen column
5532 winid Window ID of the click
5533 winrow row inside "winid"
5534 wincol column inside "winid"
5535 line text line inside "winid"
5536 column text column inside "winid"
5537 All numbers are 1-based.
5538
5539 If not over a window, e.g. when in the command line, then only
5540 "screenrow" and "screencol" are valid, the others are zero.
5541
5542 When on the status line below a window or the vertical
Bram Moolenaarebacddb2020-06-04 15:22:21 +02005543 separator right of a window, the "line" and "column" values
Bram Moolenaardb3a2052019-11-16 18:22:41 +01005544 are zero.
5545
5546 When the position is after the text then "column" is the
5547 length of the text in bytes.
5548
5549 If the mouse is over a popup window then that window is used.
5550
5551
5552 When using |getchar()| the Vim variables |v:mouse_lnum|,
5553 |v:mouse_col| and |v:mouse_winid| also provide these values.
5554
Bram Moolenaar822ff862014-06-12 21:46:14 +02005555 *getpid()*
5556getpid() Return a Number which is the process ID of the Vim process.
5557 On Unix and MS-Windows this is a unique number, until Vim
Bram Moolenaar5666fcd2019-12-26 14:35:26 +01005558 exits.
Bram Moolenaar822ff862014-06-12 21:46:14 +02005559
5560 *getpos()*
5561getpos({expr}) Get the position for {expr}. For possible values of {expr}
5562 see |line()|. For getting the cursor position see
5563 |getcurpos()|.
5564 The result is a |List| with four numbers:
5565 [bufnum, lnum, col, off]
5566 "bufnum" is zero, unless a mark like '0 or 'A is used, then it
5567 is the buffer number of the mark.
5568 "lnum" and "col" are the position in the buffer. The first
5569 column is 1.
5570 The "off" number is zero, unless 'virtualedit' is used. Then
5571 it is the offset in screen columns from the start of the
5572 character. E.g., a position within a <Tab> or after the last
5573 character.
5574 Note that for '< and '> Visual mode matters: when it is "V"
5575 (visual line mode) the column of '< is zero and the column of
5576 '> is a large number.
5577 This can be used to save and restore the position of a mark: >
5578 let save_a_mark = getpos("'a")
5579 ...
Bram Moolenaared32d942014-12-06 23:33:00 +01005580 call setpos("'a", save_a_mark)
Bram Moolenaar822ff862014-06-12 21:46:14 +02005581< Also see |getcurpos()| and |setpos()|.
5582
Bram Moolenaar4c313b12019-08-24 22:58:31 +02005583 Can also be used as a |method|: >
5584 GetMark()->getpos()
5585
Bram Moolenaar6ee10162007-07-26 20:58:42 +00005586
Bram Moolenaard823fa92016-08-12 16:29:27 +02005587getqflist([{what}]) *getqflist()*
Bram Moolenaar68b76a62005-03-25 21:53:48 +00005588 Returns a list with all the current quickfix errors. Each
5589 list item is a dictionary with these entries:
5590 bufnr number of buffer that has the file name, use
5591 bufname() to get the name
Bram Moolenaard76ce852018-05-01 15:02:04 +02005592 module module name
Bram Moolenaar68b76a62005-03-25 21:53:48 +00005593 lnum line number in the buffer (first line is 1)
5594 col column number (first column is 1)
Bram Moolenaare381d3d2016-07-07 14:50:41 +02005595 vcol |TRUE|: "col" is visual column
5596 |FALSE|: "col" is byte index
Bram Moolenaar68b76a62005-03-25 21:53:48 +00005597 nr error number
Bram Moolenaar48b66fb2007-02-04 01:58:18 +00005598 pattern search pattern used to locate the error
Bram Moolenaar68b76a62005-03-25 21:53:48 +00005599 text description of the error
5600 type type of the error, 'E', '1', etc.
Bram Moolenaare381d3d2016-07-07 14:50:41 +02005601 valid |TRUE|: recognized error message
Bram Moolenaar68b76a62005-03-25 21:53:48 +00005602
Bram Moolenaar7571d552016-08-18 22:54:46 +02005603 When there is no error list or it's empty, an empty list is
Bram Moolenaar48b66fb2007-02-04 01:58:18 +00005604 returned. Quickfix list entries with non-existing buffer
5605 number are returned with "bufnr" set to zero.
Bram Moolenaare7eb9df2005-09-09 19:49:30 +00005606
Bram Moolenaar68b76a62005-03-25 21:53:48 +00005607 Useful application: Find pattern matches in multiple files and
5608 do something with them: >
5609 :vimgrep /theword/jg *.c
5610 :for d in getqflist()
5611 : echo bufname(d.bufnr) ':' d.lnum '=' d.text
5612 :endfor
Bram Moolenaard823fa92016-08-12 16:29:27 +02005613<
5614 If the optional {what} dictionary argument is supplied, then
5615 returns only the items listed in {what} as a dictionary. The
5616 following string items are supported in {what}:
Bram Moolenaarb254af32017-12-18 19:48:58 +01005617 changedtick get the total number of changes made
Bram Moolenaar15142e22018-04-30 22:19:58 +02005618 to the list |quickfix-changedtick|
5619 context get the |quickfix-context|
Bram Moolenaar36538222017-09-02 19:51:44 +02005620 efm errorformat to use when parsing "lines". If
Bram Moolenaar2f058492017-11-30 20:27:52 +01005621 not present, then the 'errorformat' option
Bram Moolenaar36538222017-09-02 19:51:44 +02005622 value is used.
Bram Moolenaara539f4f2017-08-30 20:33:55 +02005623 id get information for the quickfix list with
5624 |quickfix-ID|; zero means the id for the
Bram Moolenaar2f058492017-11-30 20:27:52 +01005625 current list or the list specified by "nr"
Bram Moolenaar858ba062020-05-31 23:11:59 +02005626 idx get information for the quickfix entry at this
5627 index in the list specified by 'id' or 'nr'.
5628 If set to zero, then uses the current entry.
Bram Moolenaar5b69c222019-01-11 14:50:06 +01005629 See |quickfix-index|
Bram Moolenaar6a8958d2017-06-22 21:33:20 +02005630 items quickfix list entries
Bram Moolenaar15142e22018-04-30 22:19:58 +02005631 lines parse a list of lines using 'efm' and return
5632 the resulting entries. Only a |List| type is
5633 accepted. The current quickfix list is not
5634 modified. See |quickfix-parse|.
Bram Moolenaar890680c2016-09-27 21:28:56 +02005635 nr get information for this quickfix list; zero
Bram Moolenaar36538222017-09-02 19:51:44 +02005636 means the current quickfix list and "$" means
Bram Moolenaar875feea2017-06-11 16:07:51 +02005637 the last quickfix list
Bram Moolenaar647e24b2019-03-17 16:39:46 +01005638 qfbufnr number of the buffer displayed in the quickfix
5639 window. Returns 0 if the quickfix buffer is
5640 not present. See |quickfix-buffer|.
Bram Moolenaarfc2b2702017-09-15 22:43:07 +02005641 size number of entries in the quickfix list
Bram Moolenaar15142e22018-04-30 22:19:58 +02005642 title get the list title |quickfix-title|
Bram Moolenaar74240d32017-12-10 15:26:15 +01005643 winid get the quickfix |window-ID|
Bram Moolenaard823fa92016-08-12 16:29:27 +02005644 all all of the above quickfix properties
Bram Moolenaar74240d32017-12-10 15:26:15 +01005645 Non-string items in {what} are ignored. To get the value of a
Bram Moolenaara6d48492017-12-12 22:45:31 +01005646 particular item, set it to zero.
Bram Moolenaard823fa92016-08-12 16:29:27 +02005647 If "nr" is not present then the current quickfix list is used.
Bram Moolenaara539f4f2017-08-30 20:33:55 +02005648 If both "nr" and a non-zero "id" are specified, then the list
5649 specified by "id" is used.
Bram Moolenaarb4d5fba2017-09-11 19:31:28 +02005650 To get the number of lists in the quickfix stack, set "nr" to
5651 "$" in {what}. The "nr" value in the returned dictionary
Bram Moolenaar875feea2017-06-11 16:07:51 +02005652 contains the quickfix stack size.
Bram Moolenaarb4d5fba2017-09-11 19:31:28 +02005653 When "lines" is specified, all the other items except "efm"
5654 are ignored. The returned dictionary contains the entry
5655 "items" with the list of entries.
Bram Moolenaar68b76a62005-03-25 21:53:48 +00005656
Bram Moolenaard823fa92016-08-12 16:29:27 +02005657 The returned dictionary contains the following entries:
Bram Moolenaarb254af32017-12-18 19:48:58 +01005658 changedtick total number of changes made to the
5659 list |quickfix-changedtick|
Bram Moolenaar15142e22018-04-30 22:19:58 +02005660 context quickfix list context. See |quickfix-context|
Bram Moolenaara6d48492017-12-12 22:45:31 +01005661 If not present, set to "".
5662 id quickfix list ID |quickfix-ID|. If not
5663 present, set to 0.
Bram Moolenaar858ba062020-05-31 23:11:59 +02005664 idx index of the quickfix entry in the list. If not
Bram Moolenaara6d48492017-12-12 22:45:31 +01005665 present, set to 0.
5666 items quickfix list entries. If not present, set to
5667 an empty list.
5668 nr quickfix list number. If not present, set to 0
Bram Moolenaar647e24b2019-03-17 16:39:46 +01005669 qfbufnr number of the buffer displayed in the quickfix
5670 window. If not present, set to 0.
Bram Moolenaara6d48492017-12-12 22:45:31 +01005671 size number of entries in the quickfix list. If not
5672 present, set to 0.
5673 title quickfix list title text. If not present, set
5674 to "".
Bram Moolenaar74240d32017-12-10 15:26:15 +01005675 winid quickfix |window-ID|. If not present, set to 0
Bram Moolenaard823fa92016-08-12 16:29:27 +02005676
Bram Moolenaar15142e22018-04-30 22:19:58 +02005677 Examples (See also |getqflist-examples|): >
Bram Moolenaard823fa92016-08-12 16:29:27 +02005678 :echo getqflist({'all': 1})
5679 :echo getqflist({'nr': 2, 'title': 1})
Bram Moolenaar2c809b72017-09-01 18:34:02 +02005680 :echo getqflist({'lines' : ["F1:10:L10"]})
Bram Moolenaard823fa92016-08-12 16:29:27 +02005681<
Bram Moolenaarb7cb42b2014-04-02 19:55:10 +02005682getreg([{regname} [, 1 [, {list}]]]) *getreg()*
Bram Moolenaar071d4272004-06-13 20:20:40 +00005683 The result is a String, which is the contents of register
Bram Moolenaar402d2fe2005-04-15 21:00:38 +00005684 {regname}. Example: >
Bram Moolenaar071d4272004-06-13 20:20:40 +00005685 :let cliptext = getreg('*')
Bram Moolenaardc1f1642016-08-16 18:33:43 +02005686< When {regname} was not set the result is an empty string.
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02005687
5688 getreg('=') returns the last evaluated value of the expression
Bram Moolenaar402d2fe2005-04-15 21:00:38 +00005689 register. (For use in maps.)
Bram Moolenaar2389c3c2005-05-22 22:07:59 +00005690 getreg('=', 1) returns the expression itself, so that it can
5691 be restored with |setreg()|. For other registers the extra
5692 argument is ignored, thus you can always give it.
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02005693
Bram Moolenaare381d3d2016-07-07 14:50:41 +02005694 If {list} is present and |TRUE|, the result type is changed
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02005695 to |List|. Each list item is one text line. Use it if you care
Bram Moolenaarb7cb42b2014-04-02 19:55:10 +02005696 about zero bytes possibly present inside register: without
5697 third argument both NLs and zero bytes are represented as NLs
5698 (see |NL-used-for-Nul|).
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02005699 When the register was not set an empty list is returned.
5700
Bram Moolenaar071d4272004-06-13 20:20:40 +00005701 If {regname} is not specified, |v:register| is used.
5702
Bram Moolenaar4c313b12019-08-24 22:58:31 +02005703 Can also be used as a |method|: >
5704 GetRegname()->getreg()
5705
Bram Moolenaarbb861e22020-06-07 18:16:36 +02005706getreginfo([{regname}]) *getreginfo()*
5707 Returns detailed information about register {regname} as a
5708 Dictionary with the following entries:
5709 regcontents List of lines contained in register
5710 {regname}, like
5711 |getreg|({regname}, 1, 1).
5712 regtype the type of register {regname}, as in
5713 |getregtype()|.
5714 isunnamed Boolean flag, v:true if this register
5715 is currently pointed to by the unnamed
5716 register.
5717 points_to for the unnamed register, gives the
5718 single letter name of the register
5719 currently pointed to (see |quotequote|).
5720 For example, after deleting a line
5721 with `dd`, this field will be "1",
5722 which is the register that got the
5723 deleted text.
5724
5725 If {regname} is invalid or not set, an empty Dictionary
5726 will be returned.
5727 If {regname} is not specified, |v:register| is used.
Bram Moolenaar207f0092020-08-30 17:20:20 +02005728 The returned Dictionary can be passed to |setreg()|.
Bram Moolenaarbb861e22020-06-07 18:16:36 +02005729
5730 Can also be used as a |method|: >
5731 GetRegname()->getreginfo()
Bram Moolenaara14de3d2005-01-07 21:48:26 +00005732
Bram Moolenaar071d4272004-06-13 20:20:40 +00005733getregtype([{regname}]) *getregtype()*
5734 The result is a String, which is type of register {regname}.
5735 The value will be one of:
5736 "v" for |characterwise| text
5737 "V" for |linewise| text
5738 "<CTRL-V>{width}" for |blockwise-visual| text
Bram Moolenaar32b92012014-01-14 12:33:36 +01005739 "" for an empty or unknown register
Bram Moolenaar071d4272004-06-13 20:20:40 +00005740 <CTRL-V> is one character with value 0x16.
5741 If {regname} is not specified, |v:register| is used.
5742
Bram Moolenaar4c313b12019-08-24 22:58:31 +02005743 Can also be used as a |method|: >
5744 GetRegname()->getregtype()
5745
Bram Moolenaarb5ae48e2016-08-12 22:23:25 +02005746gettabinfo([{arg}]) *gettabinfo()*
5747 If {arg} is not specified, then information about all the tab
Bram Moolenaare46a4402020-06-30 20:38:27 +02005748 pages is returned as a |List|. Each List item is a |Dictionary|.
Bram Moolenaarb5ae48e2016-08-12 22:23:25 +02005749 Otherwise, {arg} specifies the tab page number and information
5750 about that one is returned. If the tab page does not exist an
5751 empty List is returned.
5752
Bram Moolenaare46a4402020-06-30 20:38:27 +02005753 Each List item is a |Dictionary| with the following entries:
Bram Moolenaar7571d552016-08-18 22:54:46 +02005754 tabnr tab page number.
Bram Moolenaar30567352016-08-27 21:25:44 +02005755 variables a reference to the dictionary with
5756 tabpage-local variables
Bram Moolenaarf6b40102019-02-22 15:24:03 +01005757 windows List of |window-ID|s in the tab page.
Bram Moolenaarb5ae48e2016-08-12 22:23:25 +02005758
Bram Moolenaar4c313b12019-08-24 22:58:31 +02005759 Can also be used as a |method|: >
5760 GetTabnr()->gettabinfo()
5761
Bram Moolenaar63dbda12013-02-20 21:12:10 +01005762gettabvar({tabnr}, {varname} [, {def}]) *gettabvar()*
Bram Moolenaar06b5d512010-05-22 15:37:44 +02005763 Get the value of a tab-local variable {varname} in tab page
5764 {tabnr}. |t:var|
5765 Tabs are numbered starting with one.
Bram Moolenaar0e2ea1b2014-09-09 16:13:08 +02005766 When {varname} is empty a dictionary with all tab-local
5767 variables is returned.
Bram Moolenaar06b5d512010-05-22 15:37:44 +02005768 Note that the name without "t:" must be used.
Bram Moolenaar63dbda12013-02-20 21:12:10 +01005769 When the tab or variable doesn't exist {def} or an empty
5770 string is returned, there is no error message.
Bram Moolenaar06b5d512010-05-22 15:37:44 +02005771
Bram Moolenaar4c313b12019-08-24 22:58:31 +02005772 Can also be used as a |method|: >
5773 GetTabnr()->gettabvar(varname)
5774
Bram Moolenaar63dbda12013-02-20 21:12:10 +01005775gettabwinvar({tabnr}, {winnr}, {varname} [, {def}]) *gettabwinvar()*
Bram Moolenaaref2f6562007-05-06 13:32:59 +00005776 Get the value of window-local variable {varname} in window
5777 {winnr} in tab page {tabnr}.
Bram Moolenaar63dbda12013-02-20 21:12:10 +01005778 When {varname} is empty a dictionary with all window-local
5779 variables is returned.
Bram Moolenaar30567352016-08-27 21:25:44 +02005780 When {varname} is equal to "&" get the values of all
Bram Moolenaare46a4402020-06-30 20:38:27 +02005781 window-local options in a |Dictionary|.
Bram Moolenaar30567352016-08-27 21:25:44 +02005782 Otherwise, when {varname} starts with "&" get the value of a
5783 window-local option.
Bram Moolenaar63dbda12013-02-20 21:12:10 +01005784 Note that {varname} must be the name without "w:".
Bram Moolenaarc6249bb2006-04-15 20:25:09 +00005785 Tabs are numbered starting with one. For the current tabpage
5786 use |getwinvar()|.
Bram Moolenaar7571d552016-08-18 22:54:46 +02005787 {winnr} can be the window number or the |window-ID|.
Bram Moolenaarc6249bb2006-04-15 20:25:09 +00005788 When {winnr} is zero the current window is used.
5789 This also works for a global option, buffer-local option and
5790 window-local option, but it doesn't work for a global variable
5791 or buffer-local variable.
Bram Moolenaar63dbda12013-02-20 21:12:10 +01005792 When the tab, window or variable doesn't exist {def} or an
5793 empty string is returned, there is no error message.
Bram Moolenaarc6249bb2006-04-15 20:25:09 +00005794 Examples: >
5795 :let list_is_on = gettabwinvar(1, 2, '&list')
5796 :echo "myvar = " . gettabwinvar(3, 1, 'myvar')
Bram Moolenaard46bbc72007-05-12 14:38:41 +00005797<
Bram Moolenaarb477af22018-07-15 20:20:18 +02005798 To obtain all window-local variables use: >
5799 gettabwinvar({tabnr}, {winnr}, '&')
5800
Bram Moolenaar4c313b12019-08-24 22:58:31 +02005801< Can also be used as a |method|: >
Bram Moolenaar5d69fdb2019-08-31 19:13:58 +02005802 GetTabnr()->gettabwinvar(winnr, varname)
Bram Moolenaar4c313b12019-08-24 22:58:31 +02005803
Bram Moolenaarf49cc602018-11-11 15:21:05 +01005804gettagstack([{nr}]) *gettagstack()*
5805 The result is a Dict, which is the tag stack of window {nr}.
5806 {nr} can be the window number or the |window-ID|.
5807 When {nr} is not specified, the current window is used.
5808 When window {nr} doesn't exist, an empty Dict is returned.
5809
5810 The returned dictionary contains the following entries:
5811 curidx Current index in the stack. When at
5812 top of the stack, set to (length + 1).
5813 Index of bottom of the stack is 1.
5814 items List of items in the stack. Each item
5815 is a dictionary containing the
5816 entries described below.
5817 length Number of entries in the stack.
5818
5819 Each item in the stack is a dictionary with the following
5820 entries:
5821 bufnr buffer number of the current jump
5822 from cursor position before the tag jump.
5823 See |getpos()| for the format of the
5824 returned list.
5825 matchnr current matching tag number. Used when
5826 multiple matching tags are found for a
5827 name.
5828 tagname name of the tag
5829
5830 See |tagstack| for more information about the tag stack.
5831
Bram Moolenaar5d69fdb2019-08-31 19:13:58 +02005832 Can also be used as a |method|: >
5833 GetWinnr()->gettagstack()
5834
Bram Moolenaar0b39c3f2020-08-30 15:52:10 +02005835
5836gettext({text}) *gettext()*
5837 Translate {text} if possible.
5838 This is mainly for use in the distributed Vim scripts. When
5839 generating message translations the {text} is extracted by
5840 xgettext, the translator can add the translated message in the
5841 .po file and Vim will lookup the translation when gettext() is
5842 called.
5843 For {text} double quoted strings are preferred, because
5844 xgettext does not understand escaping in single quoted
5845 strings.
5846
5847
Bram Moolenaar7132ddc2018-07-15 17:01:11 +02005848getwininfo([{winid}]) *getwininfo()*
Bram Moolenaare46a4402020-06-30 20:38:27 +02005849 Returns information about windows as a |List| with Dictionaries.
Bram Moolenaar7132ddc2018-07-15 17:01:11 +02005850
5851 If {winid} is given Information about the window with that ID
Bram Moolenaare46a4402020-06-30 20:38:27 +02005852 is returned, as a |List| with one item. If the window does not
Bram Moolenaar73fef332020-06-21 22:12:03 +02005853 exist the result is an empty list.
Bram Moolenaar7132ddc2018-07-15 17:01:11 +02005854
5855 Without {winid} information about all the windows in all the
5856 tab pages is returned.
5857
Bram Moolenaare46a4402020-06-30 20:38:27 +02005858 Each List item is a |Dictionary| with the following entries:
Bram Moolenaar8fcb60f2019-03-04 13:18:30 +01005859 botline last displayed buffer line
Bram Moolenaar7132ddc2018-07-15 17:01:11 +02005860 bufnr number of buffer in the window
5861 height window height (excluding winbar)
Bram Moolenaar7132ddc2018-07-15 17:01:11 +02005862 loclist 1 if showing a location list
5863 {only with the +quickfix feature}
5864 quickfix 1 if quickfix or location list window
5865 {only with the +quickfix feature}
5866 terminal 1 if a terminal window
5867 {only with the +terminal feature}
5868 tabnr tab page number
Bram Moolenaar10455d42019-11-21 15:36:18 +01005869 topline first displayed buffer line
Bram Moolenaar7132ddc2018-07-15 17:01:11 +02005870 variables a reference to the dictionary with
5871 window-local variables
5872 width window width
Bram Moolenaarb477af22018-07-15 20:20:18 +02005873 winbar 1 if the window has a toolbar, 0
5874 otherwise
Bram Moolenaar7132ddc2018-07-15 17:01:11 +02005875 wincol leftmost screen column of the window,
5876 col from |win_screenpos()|
5877 winid |window-ID|
5878 winnr window number
5879 winrow topmost screen column of the window,
5880 row from |win_screenpos()|
5881
Bram Moolenaar5d69fdb2019-08-31 19:13:58 +02005882 Can also be used as a |method|: >
5883 GetWinnr()->getwininfo()
5884
Bram Moolenaar3f54fd32018-03-03 21:29:55 +01005885getwinpos([{timeout}]) *getwinpos()*
Bram Moolenaare46a4402020-06-30 20:38:27 +02005886 The result is a |List| with two numbers, the result of
Bram Moolenaar10455d42019-11-21 15:36:18 +01005887 |getwinposx()| and |getwinposy()| combined:
Bram Moolenaar3f54fd32018-03-03 21:29:55 +01005888 [x-pos, y-pos]
5889 {timeout} can be used to specify how long to wait in msec for
5890 a response from the terminal. When omitted 100 msec is used.
Bram Moolenaarb5b75622018-03-09 22:22:21 +01005891 Use a longer time for a remote terminal.
5892 When using a value less than 10 and no response is received
5893 within that time, a previously reported position is returned,
5894 if available. This can be used to poll for the position and
Bram Moolenaar5b69c222019-01-11 14:50:06 +01005895 do some work in the meantime: >
Bram Moolenaarb5b75622018-03-09 22:22:21 +01005896 while 1
5897 let res = getwinpos(1)
5898 if res[0] >= 0
5899 break
5900 endif
5901 " Do some work here
5902 endwhile
5903<
Bram Moolenaar5d69fdb2019-08-31 19:13:58 +02005904
5905 Can also be used as a |method|: >
5906 GetTimeout()->getwinpos()
5907<
Bram Moolenaar071d4272004-06-13 20:20:40 +00005908 *getwinposx()*
5909getwinposx() The result is a Number, which is the X coordinate in pixels of
Bram Moolenaarcd5c8f82017-04-09 20:11:58 +02005910 the left hand side of the GUI Vim window. Also works for an
Bram Moolenaar3f54fd32018-03-03 21:29:55 +01005911 xterm (uses a timeout of 100 msec).
Bram Moolenaarcd5c8f82017-04-09 20:11:58 +02005912 The result will be -1 if the information is not available.
5913 The value can be used with `:winpos`.
Bram Moolenaar071d4272004-06-13 20:20:40 +00005914
5915 *getwinposy()*
5916getwinposy() The result is a Number, which is the Y coordinate in pixels of
Bram Moolenaar3f54fd32018-03-03 21:29:55 +01005917 the top of the GUI Vim window. Also works for an xterm (uses
5918 a timeout of 100 msec).
Bram Moolenaarcd5c8f82017-04-09 20:11:58 +02005919 The result will be -1 if the information is not available.
5920 The value can be used with `:winpos`.
Bram Moolenaar071d4272004-06-13 20:20:40 +00005921
Bram Moolenaar63dbda12013-02-20 21:12:10 +01005922getwinvar({winnr}, {varname} [, {def}]) *getwinvar()*
Bram Moolenaarc6249bb2006-04-15 20:25:09 +00005923 Like |gettabwinvar()| for the current tabpage.
Bram Moolenaar071d4272004-06-13 20:20:40 +00005924 Examples: >
5925 :let list_is_on = getwinvar(2, '&list')
5926 :echo "myvar = " . getwinvar(1, 'myvar')
Bram Moolenaar5d69fdb2019-08-31 19:13:58 +02005927
5928< Can also be used as a |method|: >
5929 GetWinnr()->getwinvar(varname)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005930<
Bram Moolenaard8b77f72015-03-05 21:21:19 +01005931glob({expr} [, {nosuf} [, {list} [, {alllinks}]]]) *glob()*
Bram Moolenaarbb5ddda2008-11-28 10:01:10 +00005932 Expand the file wildcards in {expr}. See |wildcards| for the
Bram Moolenaaref2f6562007-05-06 13:32:59 +00005933 use of special characters.
Bram Moolenaar84f72352012-03-11 15:57:40 +01005934
Bram Moolenaare381d3d2016-07-07 14:50:41 +02005935 Unless the optional {nosuf} argument is given and is |TRUE|,
Bram Moolenaarbb5ddda2008-11-28 10:01:10 +00005936 the 'suffixes' and 'wildignore' options apply: Names matching
5937 one of the patterns in 'wildignore' will be skipped and
5938 'suffixes' affect the ordering of matches.
Bram Moolenaar81af9252010-12-10 20:35:50 +01005939 'wildignorecase' always applies.
Bram Moolenaar84f72352012-03-11 15:57:40 +01005940
Bram Moolenaare46a4402020-06-30 20:38:27 +02005941 When {list} is present and it is |TRUE| the result is a |List|
Bram Moolenaar84f72352012-03-11 15:57:40 +01005942 with all matching files. The advantage of using a List is,
5943 you also get filenames containing newlines correctly.
5944 Otherwise the result is a String and when there are several
5945 matches, they are separated by <NL> characters.
5946
5947 If the expansion fails, the result is an empty String or List.
Bram Moolenaard8b77f72015-03-05 21:21:19 +01005948
Bram Moolenaar62e1bb42019-04-08 16:25:07 +02005949 You can also use |readdir()| if you need to do complicated
5950 things, such as limiting the number of matches.
5951
Bram Moolenaar61d35bd2012-03-28 20:51:51 +02005952 A name for a non-existing file is not included. A symbolic
5953 link is only included if it points to an existing file.
Bram Moolenaard8b77f72015-03-05 21:21:19 +01005954 However, when the {alllinks} argument is present and it is
Bram Moolenaare381d3d2016-07-07 14:50:41 +02005955 |TRUE| then all symbolic links are included.
Bram Moolenaar071d4272004-06-13 20:20:40 +00005956
5957 For most systems backticks can be used to get files names from
5958 any external command. Example: >
5959 :let tagfiles = glob("`find . -name tags -print`")
5960 :let &tags = substitute(tagfiles, "\n", ",", "g")
5961< The result of the program inside the backticks should be one
Bram Moolenaar58b85342016-08-14 19:54:54 +02005962 item per line. Spaces inside an item are allowed.
Bram Moolenaar071d4272004-06-13 20:20:40 +00005963
5964 See |expand()| for expanding special Vim variables. See
5965 |system()| for getting the raw output of an external command.
5966
Bram Moolenaar5d69fdb2019-08-31 19:13:58 +02005967 Can also be used as a |method|: >
5968 GetExpr()->glob()
5969
Bram Moolenaar5837f1f2015-03-21 18:06:14 +01005970glob2regpat({expr}) *glob2regpat()*
5971 Convert a file pattern, as used by glob(), into a search
5972 pattern. The result can be used to match with a string that
5973 is a file name. E.g. >
5974 if filename =~ glob2regpat('Make*.mak')
5975< This is equivalent to: >
5976 if filename =~ '^Make.*\.mak$'
Bram Moolenaar3b5f9292016-01-28 22:37:01 +01005977< When {expr} is an empty string the result is "^$", match an
5978 empty string.
Bram Moolenaard823fa92016-08-12 16:29:27 +02005979 Note that the result depends on the system. On MS-Windows
Bram Moolenaar58b85342016-08-14 19:54:54 +02005980 a backslash usually means a path separator.
Bram Moolenaar3b5f9292016-01-28 22:37:01 +01005981
Bram Moolenaar5d69fdb2019-08-31 19:13:58 +02005982 Can also be used as a |method|: >
5983 GetExpr()->glob2regpat()
5984< *globpath()*
Bram Moolenaar6463ca22016-02-13 17:04:46 +01005985globpath({path}, {expr} [, {nosuf} [, {list} [, {alllinks}]]])
Bram Moolenaara0d1fef2019-09-04 22:29:14 +02005986 Perform glob() for {expr} on all directories in {path} and
5987 concatenate the results. Example: >
Bram Moolenaar071d4272004-06-13 20:20:40 +00005988 :echo globpath(&rtp, "syntax/c.vim")
Bram Moolenaar1b1063a2014-05-07 18:35:30 +02005989<
5990 {path} is a comma-separated list of directory names. Each
Bram Moolenaar071d4272004-06-13 20:20:40 +00005991 directory name is prepended to {expr} and expanded like with
Bram Moolenaarbb5ddda2008-11-28 10:01:10 +00005992 |glob()|. A path separator is inserted when needed.
Bram Moolenaar071d4272004-06-13 20:20:40 +00005993 To add a comma inside a directory name escape it with a
5994 backslash. Note that on MS-Windows a directory may have a
5995 trailing backslash, remove it if you put a comma after it.
5996 If the expansion fails for one of the directories, there is no
5997 error message.
Bram Moolenaar1b1063a2014-05-07 18:35:30 +02005998
Bram Moolenaare381d3d2016-07-07 14:50:41 +02005999 Unless the optional {nosuf} argument is given and is |TRUE|,
Bram Moolenaarbb5ddda2008-11-28 10:01:10 +00006000 the 'suffixes' and 'wildignore' options apply: Names matching
6001 one of the patterns in 'wildignore' will be skipped and
6002 'suffixes' affect the ordering of matches.
Bram Moolenaar071d4272004-06-13 20:20:40 +00006003
Bram Moolenaare46a4402020-06-30 20:38:27 +02006004 When {list} is present and it is |TRUE| the result is a |List|
Bram Moolenaar1b1063a2014-05-07 18:35:30 +02006005 with all matching files. The advantage of using a List is, you
6006 also get filenames containing newlines correctly. Otherwise
6007 the result is a String and when there are several matches,
6008 they are separated by <NL> characters. Example: >
6009 :echo globpath(&rtp, "syntax/c.vim", 0, 1)
6010<
Bram Moolenaar6463ca22016-02-13 17:04:46 +01006011 {alllinks} is used as with |glob()|.
Bram Moolenaard8b77f72015-03-05 21:21:19 +01006012
Bram Moolenaar02743632005-07-25 20:42:36 +00006013 The "**" item can be used to search in a directory tree.
6014 For example, to find all "README.txt" files in the directories
6015 in 'runtimepath' and below: >
6016 :echo globpath(&rtp, "**/README.txt")
Bram Moolenaarc236c162008-07-13 17:41:49 +00006017< Upwards search and limiting the depth of "**" is not
6018 supported, thus using 'path' will not always work properly.
6019
Bram Moolenaar5d69fdb2019-08-31 19:13:58 +02006020 Can also be used as a |method|, the base is passed as the
6021 second argument: >
6022 GetExpr()->globpath(&rtp)
6023<
Bram Moolenaar071d4272004-06-13 20:20:40 +00006024 *has()*
Bram Moolenaar79296512020-03-22 16:17:14 +01006025has({feature} [, {check}])
6026 When {check} is omitted or is zero: The result is a Number,
6027 which is 1 if the feature {feature} is supported, zero
6028 otherwise. The {feature} argument is a string, case is
6029 ignored. See |feature-list| below.
6030
6031 When {check} is present and not zero: The result is a Number,
6032 which is 1 if the feature {feature} could ever be supported,
6033 zero otherwise. This is useful to check for a typo in
Bram Moolenaar191acfd2020-03-27 20:42:43 +01006034 {feature} and to detect dead code. Keep in mind that an older
6035 Vim version will not know about a feature added later and
Bram Moolenaar207f0092020-08-30 17:20:20 +02006036 features that have been abandoned will not be known by the
Bram Moolenaar191acfd2020-03-27 20:42:43 +01006037 current Vim version.
Bram Moolenaar79296512020-03-22 16:17:14 +01006038
Bram Moolenaar071d4272004-06-13 20:20:40 +00006039 Also see |exists()|.
Bram Moolenaar79296512020-03-22 16:17:14 +01006040
Bram Moolenaarb17893a2020-03-14 08:19:51 +01006041 Note that to skip code that has a syntax error when the
6042 feature is not available, Vim may skip the rest of the line
Bram Moolenaar7ceefb32020-05-01 16:07:38 +02006043 and miss a following `endif`. Therefore put the `endif` on a
Bram Moolenaarb17893a2020-03-14 08:19:51 +01006044 separate line: >
6045 if has('feature')
6046 let x = this->breaks->without->the->feature
6047 endif
Bram Moolenaarff781552020-03-19 20:37:11 +01006048< If the `endif` would be moved to the second line as "| endif" it
6049 would not be found.
Bram Moolenaar071d4272004-06-13 20:20:40 +00006050
Bram Moolenaar2fda12f2005-01-15 22:14:15 +00006051
6052has_key({dict}, {key}) *has_key()*
Bram Moolenaar32466aa2006-02-24 23:53:04 +00006053 The result is a Number, which is 1 if |Dictionary| {dict} has
6054 an entry with key {key}. Zero otherwise.
Bram Moolenaar2fda12f2005-01-15 22:14:15 +00006055
Bram Moolenaara74e4942019-08-04 17:35:53 +02006056 Can also be used as a |method|: >
6057 mydict->has_key(key)
6058
Bram Moolenaarc9703302016-01-17 21:49:33 +01006059haslocaldir([{winnr} [, {tabnr}]]) *haslocaldir()*
Bram Moolenaar00aa0692019-04-27 20:37:57 +02006060 The result is a Number:
6061 1 when the window has set a local directory via |:lcd|
6062 2 when the tab-page has set a local directory via |:tcd|
6063 0 otherwise.
Bram Moolenaarc9703302016-01-17 21:49:33 +01006064
6065 Without arguments use the current window.
6066 With {winnr} use this window in the current tab page.
6067 With {winnr} and {tabnr} use the window in the specified tab
6068 page.
Bram Moolenaar7571d552016-08-18 22:54:46 +02006069 {winnr} can be the window number or the |window-ID|.
Bram Moolenaar00aa0692019-04-27 20:37:57 +02006070 If {winnr} is -1 it is ignored and only the tabpage is used.
Bram Moolenaarc9703302016-01-17 21:49:33 +01006071 Return 0 if the arguments are invalid.
Bram Moolenaar00aa0692019-04-27 20:37:57 +02006072 Examples: >
6073 if haslocaldir() == 1
6074 " window local directory case
6075 elseif haslocaldir() == 2
6076 " tab-local directory case
6077 else
6078 " global directory case
6079 endif
Bram Moolenaar2fda12f2005-01-15 22:14:15 +00006080
Bram Moolenaar00aa0692019-04-27 20:37:57 +02006081 " current window
6082 :echo haslocaldir()
6083 :echo haslocaldir(0)
6084 :echo haslocaldir(0, 0)
6085 " window n in current tab page
6086 :echo haslocaldir(n)
6087 :echo haslocaldir(n, 0)
6088 " window n in tab page m
6089 :echo haslocaldir(n, m)
6090 " tab page m
6091 :echo haslocaldir(-1, m)
6092<
Bram Moolenaarf9f24ce2019-08-31 21:17:39 +02006093 Can also be used as a |method|: >
6094 GetWinnr()->haslocaldir()
6095
Bram Moolenaar97b2ad32006-03-18 21:40:56 +00006096hasmapto({what} [, {mode} [, {abbr}]]) *hasmapto()*
Bram Moolenaar071d4272004-06-13 20:20:40 +00006097 The result is a Number, which is 1 if there is a mapping that
6098 contains {what} in somewhere in the rhs (what it is mapped to)
6099 and this mapping exists in one of the modes indicated by
6100 {mode}.
Bram Moolenaare381d3d2016-07-07 14:50:41 +02006101 When {abbr} is there and it is |TRUE| use abbreviations
Bram Moolenaar39f05632006-03-19 22:15:26 +00006102 instead of mappings. Don't forget to specify Insert and/or
6103 Command-line mode.
Bram Moolenaar071d4272004-06-13 20:20:40 +00006104 Both the global mappings and the mappings local to the current
6105 buffer are checked for a match.
6106 If no matching mapping is found 0 is returned.
6107 The following characters are recognized in {mode}:
6108 n Normal mode
Bram Moolenaara0d1fef2019-09-04 22:29:14 +02006109 v Visual and Select mode
6110 x Visual mode
6111 s Select mode
Bram Moolenaar071d4272004-06-13 20:20:40 +00006112 o Operator-pending mode
6113 i Insert mode
6114 l Language-Argument ("r", "f", "t", etc.)
6115 c Command-line mode
6116 When {mode} is omitted, "nvo" is used.
6117
6118 This function is useful to check if a mapping already exists
Bram Moolenaar58b85342016-08-14 19:54:54 +02006119 to a function in a Vim script. Example: >
Bram Moolenaar071d4272004-06-13 20:20:40 +00006120 :if !hasmapto('\ABCdoit')
6121 : map <Leader>d \ABCdoit
6122 :endif
6123< This installs the mapping to "\ABCdoit" only if there isn't
6124 already a mapping to "\ABCdoit".
6125
Bram Moolenaarf9f24ce2019-08-31 21:17:39 +02006126 Can also be used as a |method|: >
6127 GetRHS()->hasmapto()
6128
Bram Moolenaar071d4272004-06-13 20:20:40 +00006129histadd({history}, {item}) *histadd()*
6130 Add the String {item} to the history {history} which can be
6131 one of: *hist-names*
6132 "cmd" or ":" command line history
6133 "search" or "/" search pattern history
Bram Moolenaar446cb832008-06-24 21:56:24 +00006134 "expr" or "=" typed expression history
Bram Moolenaar071d4272004-06-13 20:20:40 +00006135 "input" or "@" input line history
Bram Moolenaar30b65812012-07-12 22:01:11 +02006136 "debug" or ">" debug command history
Bram Moolenaar3e496b02016-09-25 22:11:48 +02006137 empty the current or last used history
Bram Moolenaar30b65812012-07-12 22:01:11 +02006138 The {history} string does not need to be the whole name, one
6139 character is sufficient.
Bram Moolenaar071d4272004-06-13 20:20:40 +00006140 If {item} does already exist in the history, it will be
6141 shifted to become the newest entry.
6142 The result is a Number: 1 if the operation was successful,
6143 otherwise 0 is returned.
6144
6145 Example: >
6146 :call histadd("input", strftime("%Y %b %d"))
6147 :let date=input("Enter date: ")
6148< This function is not available in the |sandbox|.
6149
Bram Moolenaar2e693a82019-10-16 22:35:02 +02006150 Can also be used as a |method|, the base is passed as the
Bram Moolenaarf9f24ce2019-08-31 21:17:39 +02006151 second argument: >
Bram Moolenaar196b4662019-09-06 21:34:30 +02006152 GetHistory()->histadd('search')
Bram Moolenaarf9f24ce2019-08-31 21:17:39 +02006153
Bram Moolenaar071d4272004-06-13 20:20:40 +00006154histdel({history} [, {item}]) *histdel()*
Bram Moolenaar402d2fe2005-04-15 21:00:38 +00006155 Clear {history}, i.e. delete all its entries. See |hist-names|
Bram Moolenaar071d4272004-06-13 20:20:40 +00006156 for the possible values of {history}.
6157
Bram Moolenaarc236c162008-07-13 17:41:49 +00006158 If the parameter {item} evaluates to a String, it is used as a
6159 regular expression. All entries matching that expression will
6160 be removed from the history (if there are any).
Bram Moolenaar071d4272004-06-13 20:20:40 +00006161 Upper/lowercase must match, unless "\c" is used |/\c|.
Bram Moolenaarc236c162008-07-13 17:41:49 +00006162 If {item} evaluates to a Number, it will be interpreted as
6163 an index, see |:history-indexing|. The respective entry will
6164 be removed if it exists.
Bram Moolenaar071d4272004-06-13 20:20:40 +00006165
6166 The result is a Number: 1 for a successful operation,
6167 otherwise 0 is returned.
6168
6169 Examples:
6170 Clear expression register history: >
6171 :call histdel("expr")
6172<
6173 Remove all entries starting with "*" from the search history: >
6174 :call histdel("/", '^\*')
6175<
6176 The following three are equivalent: >
6177 :call histdel("search", histnr("search"))
6178 :call histdel("search", -1)
6179 :call histdel("search", '^'.histget("search", -1).'$')
6180<
6181 To delete the last search pattern and use the last-but-one for
6182 the "n" command and 'hlsearch': >
6183 :call histdel("search", -1)
6184 :let @/ = histget("search", -1)
Bram Moolenaarf9f24ce2019-08-31 21:17:39 +02006185<
6186 Can also be used as a |method|: >
6187 GetHistory()->histdel()
Bram Moolenaar071d4272004-06-13 20:20:40 +00006188
6189histget({history} [, {index}]) *histget()*
6190 The result is a String, the entry with Number {index} from
6191 {history}. See |hist-names| for the possible values of
6192 {history}, and |:history-indexing| for {index}. If there is
6193 no such entry, an empty String is returned. When {index} is
6194 omitted, the most recent item from the history is used.
6195
6196 Examples:
6197 Redo the second last search from history. >
6198 :execute '/' . histget("search", -2)
6199
6200< Define an Ex command ":H {num}" that supports re-execution of
6201 the {num}th entry from the output of |:history|. >
6202 :command -nargs=1 H execute histget("cmd", 0+<args>)
6203<
Bram Moolenaarf9f24ce2019-08-31 21:17:39 +02006204 Can also be used as a |method|: >
6205 GetHistory()->histget()
6206
Bram Moolenaar071d4272004-06-13 20:20:40 +00006207histnr({history}) *histnr()*
6208 The result is the Number of the current entry in {history}.
6209 See |hist-names| for the possible values of {history}.
6210 If an error occurred, -1 is returned.
6211
6212 Example: >
6213 :let inp_index = histnr("expr")
Bram Moolenaarf9f24ce2019-08-31 21:17:39 +02006214
6215< Can also be used as a |method|: >
6216 GetHistory()->histnr()
Bram Moolenaar071d4272004-06-13 20:20:40 +00006217<
6218hlexists({name}) *hlexists()*
6219 The result is a Number, which is non-zero if a highlight group
6220 called {name} exists. This is when the group has been
6221 defined in some way. Not necessarily when highlighting has
6222 been defined for it, it may also have been used for a syntax
6223 item.
6224 *highlight_exists()*
6225 Obsolete name: highlight_exists().
6226
Bram Moolenaarf9f24ce2019-08-31 21:17:39 +02006227 Can also be used as a |method|: >
6228 GetName()->hlexists()
6229<
Bram Moolenaar071d4272004-06-13 20:20:40 +00006230 *hlID()*
6231hlID({name}) The result is a Number, which is the ID of the highlight group
6232 with name {name}. When the highlight group doesn't exist,
6233 zero is returned.
6234 This can be used to retrieve information about the highlight
Bram Moolenaar58b85342016-08-14 19:54:54 +02006235 group. For example, to get the background color of the
Bram Moolenaar071d4272004-06-13 20:20:40 +00006236 "Comment" group: >
6237 :echo synIDattr(synIDtrans(hlID("Comment")), "bg")
6238< *highlightID()*
6239 Obsolete name: highlightID().
6240
Bram Moolenaarf9f24ce2019-08-31 21:17:39 +02006241 Can also be used as a |method|: >
6242 GetName()->hlID()
6243
Bram Moolenaar071d4272004-06-13 20:20:40 +00006244hostname() *hostname()*
6245 The result is a String, which is the name of the machine on
Bram Moolenaar402d2fe2005-04-15 21:00:38 +00006246 which Vim is currently running. Machine names greater than
Bram Moolenaar071d4272004-06-13 20:20:40 +00006247 256 characters long are truncated.
6248
6249iconv({expr}, {from}, {to}) *iconv()*
6250 The result is a String, which is the text {expr} converted
6251 from encoding {from} to encoding {to}.
Bram Moolenaar8f3f58f2010-01-06 20:52:26 +01006252 When the conversion completely fails an empty string is
6253 returned. When some characters could not be converted they
6254 are replaced with "?".
Bram Moolenaar071d4272004-06-13 20:20:40 +00006255 The encoding names are whatever the iconv() library function
6256 can accept, see ":!man 3 iconv".
6257 Most conversions require Vim to be compiled with the |+iconv|
6258 feature. Otherwise only UTF-8 to latin1 conversion and back
6259 can be done.
6260 This can be used to display messages with special characters,
6261 no matter what 'encoding' is set to. Write the message in
6262 UTF-8 and use: >
6263 echo iconv(utf8_str, "utf-8", &enc)
6264< Note that Vim uses UTF-8 for all Unicode encodings, conversion
6265 from/to UCS-2 is automatically changed to use UTF-8. You
6266 cannot use UCS-2 in a string anyway, because of the NUL bytes.
Bram Moolenaar071d4272004-06-13 20:20:40 +00006267
Bram Moolenaarf9f24ce2019-08-31 21:17:39 +02006268 Can also be used as a |method|: >
6269 GetText()->iconv('latin1', 'utf-8')
6270<
Bram Moolenaar071d4272004-06-13 20:20:40 +00006271 *indent()*
6272indent({lnum}) The result is a Number, which is indent of line {lnum} in the
6273 current buffer. The indent is counted in spaces, the value
6274 of 'tabstop' is relevant. {lnum} is used just like in
6275 |getline()|.
6276 When {lnum} is invalid -1 is returned.
6277
Bram Moolenaarf9f24ce2019-08-31 21:17:39 +02006278 Can also be used as a |method|: >
6279 GetLnum()->indent()
Bram Moolenaarde8866b2005-01-06 23:24:37 +00006280
Bram Moolenaar6e5ea8d2019-01-12 22:47:31 +01006281index({object}, {expr} [, {start} [, {ic}]]) *index()*
6282 If {object} is a |List| return the lowest index where the item
6283 has a value equal to {expr}. There is no automatic
6284 conversion, so the String "4" is different from the Number 4.
6285 And the number 4 is different from the Float 4.0. The value
6286 of 'ignorecase' is not used here, case always matters.
6287
6288 If {object} is |Blob| return the lowest index where the byte
6289 value is equal to {expr}.
6290
Bram Moolenaar748bf032005-02-02 23:04:36 +00006291 If {start} is given then start looking at the item with index
6292 {start} (may be negative for an item relative to the end).
Bram Moolenaare381d3d2016-07-07 14:50:41 +02006293 When {ic} is given and it is |TRUE|, ignore case. Otherwise
Bram Moolenaarde8866b2005-01-06 23:24:37 +00006294 case must match.
Bram Moolenaar6e5ea8d2019-01-12 22:47:31 +01006295 -1 is returned when {expr} is not found in {object}.
Bram Moolenaarde8866b2005-01-06 23:24:37 +00006296 Example: >
6297 :let idx = index(words, "the")
Bram Moolenaar9588a0f2005-01-08 21:45:39 +00006298 :if index(numbers, 123) >= 0
Bram Moolenaarde8866b2005-01-06 23:24:37 +00006299
Bram Moolenaarf9f24ce2019-08-31 21:17:39 +02006300< Can also be used as a |method|: >
6301 GetObject()->index(what)
Bram Moolenaarde8866b2005-01-06 23:24:37 +00006302
Bram Moolenaarbfd8fc02005-09-20 23:22:24 +00006303input({prompt} [, {text} [, {completion}]]) *input()*
Bram Moolenaar071d4272004-06-13 20:20:40 +00006304 The result is a String, which is whatever the user typed on
Bram Moolenaar8f3f58f2010-01-06 20:52:26 +01006305 the command-line. The {prompt} argument is either a prompt
6306 string, or a blank string (for no prompt). A '\n' can be used
6307 in the prompt to start a new line.
Bram Moolenaarbfd8fc02005-09-20 23:22:24 +00006308 The highlighting set with |:echohl| is used for the prompt.
6309 The input is entered just like a command-line, with the same
Bram Moolenaar58b85342016-08-14 19:54:54 +02006310 editing commands and mappings. There is a separate history
Bram Moolenaarbfd8fc02005-09-20 23:22:24 +00006311 for lines typed for input().
6312 Example: >
6313 :if input("Coffee or beer? ") == "beer"
6314 : echo "Cheers!"
6315 :endif
6316<
Bram Moolenaar8f3f58f2010-01-06 20:52:26 +01006317 If the optional {text} argument is present and not empty, this
6318 is used for the default reply, as if the user typed this.
6319 Example: >
Bram Moolenaarbfd8fc02005-09-20 23:22:24 +00006320 :let color = input("Color? ", "white")
6321
6322< The optional {completion} argument specifies the type of
6323 completion supported for the input. Without it completion is
Bram Moolenaar58b85342016-08-14 19:54:54 +02006324 not performed. The supported completion types are the same as
Bram Moolenaarbfd8fc02005-09-20 23:22:24 +00006325 that can be supplied to a user-defined command using the
Bram Moolenaar58b85342016-08-14 19:54:54 +02006326 "-complete=" argument. Refer to |:command-completion| for
Bram Moolenaarbfd8fc02005-09-20 23:22:24 +00006327 more information. Example: >
6328 let fname = input("File: ", "", "file")
6329<
6330 NOTE: This function must not be used in a startup file, for
6331 the versions that only run in GUI mode (e.g., the Win32 GUI).
Bram Moolenaar071d4272004-06-13 20:20:40 +00006332 Note: When input() is called from within a mapping it will
6333 consume remaining characters from that mapping, because a
6334 mapping is handled like the characters were typed.
6335 Use |inputsave()| before input() and |inputrestore()|
6336 after input() to avoid that. Another solution is to avoid
6337 that further characters follow in the mapping, e.g., by using
6338 |:execute| or |:normal|.
6339
Bram Moolenaarbfd8fc02005-09-20 23:22:24 +00006340 Example with a mapping: >
Bram Moolenaar071d4272004-06-13 20:20:40 +00006341 :nmap \x :call GetFoo()<CR>:exe "/" . Foo<CR>
6342 :function GetFoo()
6343 : call inputsave()
6344 : let g:Foo = input("enter search pattern: ")
6345 : call inputrestore()
6346 :endfunction
6347
Bram Moolenaarf9f24ce2019-08-31 21:17:39 +02006348< Can also be used as a |method|: >
6349 GetPrompt()->input()
6350
Bram Moolenaar071d4272004-06-13 20:20:40 +00006351inputdialog({prompt} [, {text} [, {cancelreturn}]]) *inputdialog()*
Bram Moolenaar8f3f58f2010-01-06 20:52:26 +01006352 Like |input()|, but when the GUI is running and text dialogs
6353 are supported, a dialog window pops up to input the text.
Bram Moolenaar071d4272004-06-13 20:20:40 +00006354 Example: >
Bram Moolenaar2d17fa32012-10-21 00:45:18 +02006355 :let n = inputdialog("value for shiftwidth", shiftwidth())
6356 :if n != ""
6357 : let &sw = n
6358 :endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006359< When the dialog is cancelled {cancelreturn} is returned. When
6360 omitted an empty string is returned.
6361 Hitting <Enter> works like pressing the OK button. Hitting
6362 <Esc> works like pressing the Cancel button.
Bram Moolenaarbfd8fc02005-09-20 23:22:24 +00006363 NOTE: Command-line completion is not supported.
Bram Moolenaar071d4272004-06-13 20:20:40 +00006364
Bram Moolenaarf9f24ce2019-08-31 21:17:39 +02006365 Can also be used as a |method|: >
6366 GetPrompt()->inputdialog()
6367
Bram Moolenaar578b49e2005-09-10 19:22:57 +00006368inputlist({textlist}) *inputlist()*
Bram Moolenaar910f66f2006-04-05 20:41:53 +00006369 {textlist} must be a |List| of strings. This |List| is
6370 displayed, one string per line. The user will be prompted to
6371 enter a number, which is returned.
Bram Moolenaar578b49e2005-09-10 19:22:57 +00006372 The user can also select an item by clicking on it with the
Bram Moolenaar65e0d772020-06-14 17:29:55 +02006373 mouse, if the mouse is enabled in the command line ('mouse' is
6374 "a" or includes "c"). For the first string 0 is returned.
6375 When clicking above the first item a negative number is
6376 returned. When clicking on the prompt one more than the
6377 length of {textlist} is returned.
Bram Moolenaar8f3f58f2010-01-06 20:52:26 +01006378 Make sure {textlist} has less than 'lines' entries, otherwise
Bram Moolenaar58b85342016-08-14 19:54:54 +02006379 it won't work. It's a good idea to put the entry number at
Bram Moolenaaref2f6562007-05-06 13:32:59 +00006380 the start of the string. And put a prompt in the first item.
6381 Example: >
Bram Moolenaar578b49e2005-09-10 19:22:57 +00006382 let color = inputlist(['Select color:', '1. red',
6383 \ '2. green', '3. blue'])
6384
Bram Moolenaarf9f24ce2019-08-31 21:17:39 +02006385< Can also be used as a |method|: >
6386 GetChoices()->inputlist()
6387
Bram Moolenaar071d4272004-06-13 20:20:40 +00006388inputrestore() *inputrestore()*
Bram Moolenaar8f3f58f2010-01-06 20:52:26 +01006389 Restore typeahead that was saved with a previous |inputsave()|.
Bram Moolenaar071d4272004-06-13 20:20:40 +00006390 Should be called the same number of times inputsave() is
6391 called. Calling it more often is harmless though.
6392 Returns 1 when there is nothing to restore, 0 otherwise.
6393
6394inputsave() *inputsave()*
6395 Preserve typeahead (also from mappings) and clear it, so that
6396 a following prompt gets input from the user. Should be
6397 followed by a matching inputrestore() after the prompt. Can
6398 be used several times, in which case there must be just as
6399 many inputrestore() calls.
6400 Returns 1 when out of memory, 0 otherwise.
6401
6402inputsecret({prompt} [, {text}]) *inputsecret()*
6403 This function acts much like the |input()| function with but
6404 two exceptions:
6405 a) the user's response will be displayed as a sequence of
6406 asterisks ("*") thereby keeping the entry secret, and
6407 b) the user's response will not be recorded on the input
6408 |history| stack.
6409 The result is a String, which is whatever the user actually
6410 typed on the command-line in response to the issued prompt.
Bram Moolenaarbfd8fc02005-09-20 23:22:24 +00006411 NOTE: Command-line completion is not supported.
Bram Moolenaar071d4272004-06-13 20:20:40 +00006412
Bram Moolenaarf9f24ce2019-08-31 21:17:39 +02006413 Can also be used as a |method|: >
6414 GetPrompt()->inputsecret()
6415
Bram Moolenaar6e5ea8d2019-01-12 22:47:31 +01006416insert({object}, {item} [, {idx}]) *insert()*
6417 When {object} is a |List| or a |Blob| insert {item} at the start
6418 of it.
6419
Bram Moolenaard7ee7ce2005-01-03 21:02:03 +00006420 If {idx} is specified insert {item} before the item with index
Bram Moolenaar58b85342016-08-14 19:54:54 +02006421 {idx}. If {idx} is zero it goes before the first item, just
Bram Moolenaard7ee7ce2005-01-03 21:02:03 +00006422 like omitting {idx}. A negative {idx} is also possible, see
6423 |list-index|. -1 inserts just before the last item.
Bram Moolenaar6e5ea8d2019-01-12 22:47:31 +01006424
6425 Returns the resulting |List| or |Blob|. Examples: >
Bram Moolenaard7ee7ce2005-01-03 21:02:03 +00006426 :let mylist = insert([2, 3, 5], 1)
6427 :call insert(mylist, 4, -1)
6428 :call insert(mylist, 6, len(mylist))
Bram Moolenaara14de3d2005-01-07 21:48:26 +00006429< The last example can be done simpler with |add()|.
Bram Moolenaar32466aa2006-02-24 23:53:04 +00006430 Note that when {item} is a |List| it is inserted as a single
Bram Moolenaara23ccb82006-02-27 00:08:02 +00006431 item. Use |extend()| to concatenate |Lists|.
Bram Moolenaard7ee7ce2005-01-03 21:02:03 +00006432
Bram Moolenaarac92e252019-08-03 21:58:38 +02006433 Can also be used as a |method|: >
6434 mylist->insert(item)
6435
Bram Moolenaar67a2deb2019-11-25 00:05:32 +01006436interrupt() *interrupt()*
6437 Interrupt script execution. It works more or less like the
6438 user typing CTRL-C, most commands won't execute and control
6439 returns to the user. This is useful to abort execution
6440 from lower down, e.g. in an autocommand. Example: >
6441 :function s:check_typoname(file)
6442 : if fnamemodify(a:file, ':t') == '['
6443 : echomsg 'Maybe typo'
6444 : call interrupt()
6445 : endif
6446 :endfunction
6447 :au BufWritePre * call s:check_typoname(expand('<amatch>'))
6448
Bram Moolenaard6e256c2011-12-14 15:32:50 +01006449invert({expr}) *invert()*
6450 Bitwise invert. The argument is converted to a number. A
6451 List, Dict or Float argument causes an error. Example: >
6452 :let bits = invert(bits)
Bram Moolenaar073e4b92019-08-18 23:01:56 +02006453< Can also be used as a |method|: >
6454 :let bits = bits->invert()
Bram Moolenaard6e256c2011-12-14 15:32:50 +01006455
Bram Moolenaar071d4272004-06-13 20:20:40 +00006456isdirectory({directory}) *isdirectory()*
Bram Moolenaare381d3d2016-07-07 14:50:41 +02006457 The result is a Number, which is |TRUE| when a directory
Bram Moolenaar071d4272004-06-13 20:20:40 +00006458 with the name {directory} exists. If {directory} doesn't
Bram Moolenaare381d3d2016-07-07 14:50:41 +02006459 exist, or isn't a directory, the result is |FALSE|. {directory}
Bram Moolenaar071d4272004-06-13 20:20:40 +00006460 is any expression, which is used as a String.
6461
Bram Moolenaarf9f24ce2019-08-31 21:17:39 +02006462 Can also be used as a |method|: >
6463 GetName()->isdirectory()
6464
Bram Moolenaarfda1bff2019-04-04 13:44:37 +02006465isinf({expr}) *isinf()*
6466 Return 1 if {expr} is a positive infinity, or -1 a negative
6467 infinity, otherwise 0. >
6468 :echo isinf(1.0 / 0.0)
6469< 1 >
6470 :echo isinf(-1.0 / 0.0)
6471< -1
6472
Bram Moolenaar93cf85f2019-08-17 21:36:28 +02006473 Can also be used as a |method|: >
6474 Compute()->isinf()
6475<
Bram Moolenaarfda1bff2019-04-04 13:44:37 +02006476 {only available when compiled with the |+float| feature}
6477
Bram Moolenaar910f66f2006-04-05 20:41:53 +00006478islocked({expr}) *islocked()* *E786*
Bram Moolenaare381d3d2016-07-07 14:50:41 +02006479 The result is a Number, which is |TRUE| when {expr} is the
Bram Moolenaar2ce06f62005-01-31 19:19:04 +00006480 name of a locked variable.
Bram Moolenaar32466aa2006-02-24 23:53:04 +00006481 {expr} must be the name of a variable, |List| item or
6482 |Dictionary| entry, not the variable itself! Example: >
Bram Moolenaar2ce06f62005-01-31 19:19:04 +00006483 :let alist = [0, ['a', 'b'], 2, 3]
6484 :lockvar 1 alist
6485 :echo islocked('alist') " 1
6486 :echo islocked('alist[1]') " 0
6487
6488< When {expr} is a variable that does not exist you get an error
Bram Moolenaar551dbcc2006-04-25 22:13:59 +00006489 message. Use |exists()| to check for existence.
Bram Moolenaar2ce06f62005-01-31 19:19:04 +00006490
Bram Moolenaarf9f24ce2019-08-31 21:17:39 +02006491 Can also be used as a |method|: >
6492 GetName()->islocked()
6493
Bram Moolenaarf3913272016-02-25 00:00:01 +01006494isnan({expr}) *isnan()*
Bram Moolenaare381d3d2016-07-07 14:50:41 +02006495 Return |TRUE| if {expr} is a float with value NaN. >
Bram Moolenaarf3913272016-02-25 00:00:01 +01006496 echo isnan(0.0 / 0.0)
Bram Moolenaar0f248b02019-04-04 15:36:05 +02006497< 1
Bram Moolenaarf3913272016-02-25 00:00:01 +01006498
Bram Moolenaar93cf85f2019-08-17 21:36:28 +02006499 Can also be used as a |method|: >
6500 Compute()->isnan()
6501<
Bram Moolenaarf3913272016-02-25 00:00:01 +01006502 {only available when compiled with the |+float| feature}
6503
Bram Moolenaar677ee682005-01-27 14:41:15 +00006504items({dict}) *items()*
Bram Moolenaar32466aa2006-02-24 23:53:04 +00006505 Return a |List| with all the key-value pairs of {dict}. Each
6506 |List| item is a list with two items: the key of a {dict}
6507 entry and the value of this entry. The |List| is in arbitrary
Bram Moolenaar0d17f0d2019-01-22 22:20:38 +01006508 order. Also see |keys()| and |values()|.
6509 Example: >
6510 for [key, value] in items(mydict)
6511 echo key . ': ' . value
6512 endfor
Bram Moolenaar677ee682005-01-27 14:41:15 +00006513
Bram Moolenaarac92e252019-08-03 21:58:38 +02006514< Can also be used as a |method|: >
6515 mydict->items()
Bram Moolenaar38a55632016-02-15 22:07:32 +01006516
Bram Moolenaared997ad2019-07-21 16:42:00 +02006517job_ functions are documented here: |job-functions-details|
Bram Moolenaarf6f32c32016-03-12 19:03:59 +01006518
Bram Moolenaar835dc632016-02-07 14:27:38 +01006519
Bram Moolenaar5f2bb9f2005-01-11 21:29:04 +00006520join({list} [, {sep}]) *join()*
6521 Join the items in {list} together into one String.
6522 When {sep} is specified it is put in between the items. If
6523 {sep} is omitted a single space is used.
6524 Note that {sep} is not added at the end. You might want to
6525 add it there too: >
6526 let lines = join(mylist, "\n") . "\n"
Bram Moolenaara23ccb82006-02-27 00:08:02 +00006527< String items are used as-is. |Lists| and |Dictionaries| are
Bram Moolenaar5f2bb9f2005-01-11 21:29:04 +00006528 converted into a string like with |string()|.
6529 The opposite function is |split()|.
6530
Bram Moolenaarac92e252019-08-03 21:58:38 +02006531 Can also be used as a |method|: >
6532 mylist->join()
6533
Bram Moolenaar7823a3b2016-02-11 21:08:32 +01006534js_decode({string}) *js_decode()*
6535 This is similar to |json_decode()| with these differences:
Bram Moolenaar595e64e2016-02-07 19:19:53 +01006536 - Object key names do not have to be in quotes.
Bram Moolenaaree142ad2017-01-11 21:50:08 +01006537 - Strings can be in single quotes.
Bram Moolenaar595e64e2016-02-07 19:19:53 +01006538 - Empty items in an array (between two commas) are allowed and
6539 result in v:none items.
6540
Bram Moolenaar02b31112019-08-31 22:16:38 +02006541 Can also be used as a |method|: >
6542 ReadObject()->js_decode()
6543
Bram Moolenaar7823a3b2016-02-11 21:08:32 +01006544js_encode({expr}) *js_encode()*
6545 This is similar to |json_encode()| with these differences:
Bram Moolenaar595e64e2016-02-07 19:19:53 +01006546 - Object key names are not in quotes.
6547 - v:none items in an array result in an empty item between
6548 commas.
6549 For example, the Vim object:
Bram Moolenaar7823a3b2016-02-11 21:08:32 +01006550 [1,v:none,{"one":1},v:none] ~
Bram Moolenaar595e64e2016-02-07 19:19:53 +01006551 Will be encoded as:
6552 [1,,{one:1},,] ~
Bram Moolenaar7823a3b2016-02-11 21:08:32 +01006553 While json_encode() would produce:
Bram Moolenaar595e64e2016-02-07 19:19:53 +01006554 [1,null,{"one":1},null] ~
6555 This encoding is valid for JavaScript. It is more efficient
6556 than JSON, especially when using an array with optional items.
6557
Bram Moolenaar02b31112019-08-31 22:16:38 +02006558 Can also be used as a |method|: >
6559 GetObject()->js_encode()
Bram Moolenaar595e64e2016-02-07 19:19:53 +01006560
Bram Moolenaar7823a3b2016-02-11 21:08:32 +01006561json_decode({string}) *json_decode()*
Bram Moolenaar705ada12016-01-24 17:56:50 +01006562 This parses a JSON formatted string and returns the equivalent
Bram Moolenaar7823a3b2016-02-11 21:08:32 +01006563 in Vim values. See |json_encode()| for the relation between
Bram Moolenaar705ada12016-01-24 17:56:50 +01006564 JSON and Vim values.
6565 The decoding is permissive:
Bram Moolenaarcd5c8f82017-04-09 20:11:58 +02006566 - A trailing comma in an array and object is ignored, e.g.
6567 "[1, 2, ]" is the same as "[1, 2]".
Bram Moolenaard09091d2019-01-17 16:07:22 +01006568 - Integer keys are accepted in objects, e.g. {1:2} is the
Bram Moolenaar0d17f0d2019-01-22 22:20:38 +01006569 same as {"1":2}.
Bram Moolenaar705ada12016-01-24 17:56:50 +01006570 - More floating point numbers are recognized, e.g. "1." for
Bram Moolenaarcd5c8f82017-04-09 20:11:58 +02006571 "1.0", or "001.2" for "1.2". Special floating point values
Bram Moolenaar5f6b3792019-01-12 14:24:27 +01006572 "Infinity", "-Infinity" and "NaN" (capitalization ignored)
6573 are accepted.
Bram Moolenaarcd5c8f82017-04-09 20:11:58 +02006574 - Leading zeroes in integer numbers are ignored, e.g. "012"
6575 for "12" or "-012" for "-12".
6576 - Capitalization is ignored in literal names null, true or
6577 false, e.g. "NULL" for "null", "True" for "true".
6578 - Control characters U+0000 through U+001F which are not
6579 escaped in strings are accepted, e.g. " " (tab
6580 character in string) for "\t".
Bram Moolenaar0d17f0d2019-01-22 22:20:38 +01006581 - An empty JSON expression or made of only spaces is accepted
6582 and results in v:none.
Bram Moolenaarcd5c8f82017-04-09 20:11:58 +02006583 - Backslash in an invalid 2-character sequence escape is
6584 ignored, e.g. "\a" is decoded as "a".
6585 - A correct surrogate pair in JSON strings should normally be
6586 a 12 character sequence such as "\uD834\uDD1E", but
6587 json_decode() silently accepts truncated surrogate pairs
6588 such as "\uD834" or "\uD834\u"
6589 *E938*
6590 A duplicate key in an object, valid in rfc7159, is not
6591 accepted by json_decode() as the result must be a valid Vim
6592 type, e.g. this fails: {"a":"b", "a":"c"}
6593
Bram Moolenaar02b31112019-08-31 22:16:38 +02006594 Can also be used as a |method|: >
6595 ReadObject()->json_decode()
Bram Moolenaar520e1e42016-01-23 19:46:28 +01006596
Bram Moolenaar7823a3b2016-02-11 21:08:32 +01006597json_encode({expr}) *json_encode()*
Bram Moolenaar705ada12016-01-24 17:56:50 +01006598 Encode {expr} as JSON and return this as a string.
Bram Moolenaar520e1e42016-01-23 19:46:28 +01006599 The encoding is specified in:
Bram Moolenaar009d84a2016-01-28 14:12:00 +01006600 https://tools.ietf.org/html/rfc7159.html
Bram Moolenaar520e1e42016-01-23 19:46:28 +01006601 Vim values are converted as follows:
Bram Moolenaard09091d2019-01-17 16:07:22 +01006602 |Number| decimal number
6603 |Float| floating point number
Bram Moolenaar7ce686c2016-02-27 16:33:22 +01006604 Float nan "NaN"
6605 Float inf "Infinity"
Bram Moolenaar5f6b3792019-01-12 14:24:27 +01006606 Float -inf "-Infinity"
Bram Moolenaard09091d2019-01-17 16:07:22 +01006607 |String| in double quotes (possibly null)
6608 |Funcref| not possible, error
6609 |List| as an array (possibly null); when
Bram Moolenaar81edd172016-04-14 13:51:37 +02006610 used recursively: []
Bram Moolenaard09091d2019-01-17 16:07:22 +01006611 |Dict| as an object (possibly null); when
Bram Moolenaar81edd172016-04-14 13:51:37 +02006612 used recursively: {}
Bram Moolenaard09091d2019-01-17 16:07:22 +01006613 |Blob| as an array of the individual bytes
Bram Moolenaar520e1e42016-01-23 19:46:28 +01006614 v:false "false"
6615 v:true "true"
Bram Moolenaar595e64e2016-02-07 19:19:53 +01006616 v:none "null"
Bram Moolenaar520e1e42016-01-23 19:46:28 +01006617 v:null "null"
Bram Moolenaar7ce686c2016-02-27 16:33:22 +01006618 Note that NaN and Infinity are passed on as values. This is
6619 missing in the JSON standard, but several implementations do
6620 allow it. If not then you will get an error.
Bram Moolenaar520e1e42016-01-23 19:46:28 +01006621
Bram Moolenaar02b31112019-08-31 22:16:38 +02006622 Can also be used as a |method|: >
6623 GetObject()->json_encode()
6624
Bram Moolenaard8b02732005-01-14 21:48:43 +00006625keys({dict}) *keys()*
Bram Moolenaar32466aa2006-02-24 23:53:04 +00006626 Return a |List| with all the keys of {dict}. The |List| is in
Bram Moolenaar0d17f0d2019-01-22 22:20:38 +01006627 arbitrary order. Also see |items()| and |values()|.
Bram Moolenaard8b02732005-01-14 21:48:43 +00006628
Bram Moolenaarac92e252019-08-03 21:58:38 +02006629 Can also be used as a |method|: >
6630 mydict->keys()
6631
6632< *len()* *E701*
Bram Moolenaard7ee7ce2005-01-03 21:02:03 +00006633len({expr}) The result is a Number, which is the length of the argument.
6634 When {expr} is a String or a Number the length in bytes is
6635 used, as with |strlen()|.
Bram Moolenaar32466aa2006-02-24 23:53:04 +00006636 When {expr} is a |List| the number of items in the |List| is
Bram Moolenaard7ee7ce2005-01-03 21:02:03 +00006637 returned.
Bram Moolenaard09091d2019-01-17 16:07:22 +01006638 When {expr} is a |Blob| the number of bytes is returned.
Bram Moolenaar32466aa2006-02-24 23:53:04 +00006639 When {expr} is a |Dictionary| the number of entries in the
6640 |Dictionary| is returned.
Bram Moolenaard7ee7ce2005-01-03 21:02:03 +00006641 Otherwise an error is given.
6642
Bram Moolenaarac92e252019-08-03 21:58:38 +02006643 Can also be used as a |method|: >
6644 mylist->len()
6645
6646< *libcall()* *E364* *E368*
Bram Moolenaar071d4272004-06-13 20:20:40 +00006647libcall({libname}, {funcname}, {argument})
6648 Call function {funcname} in the run-time library {libname}
6649 with single argument {argument}.
6650 This is useful to call functions in a library that you
6651 especially made to be used with Vim. Since only one argument
6652 is possible, calling standard library functions is rather
6653 limited.
6654 The result is the String returned by the function. If the
6655 function returns NULL, this will appear as an empty string ""
6656 to Vim.
6657 If the function returns a number, use libcallnr()!
6658 If {argument} is a number, it is passed to the function as an
6659 int; if {argument} is a string, it is passed as a
6660 null-terminated string.
6661 This function will fail in |restricted-mode|.
6662
6663 libcall() allows you to write your own 'plug-in' extensions to
6664 Vim without having to recompile the program. It is NOT a
6665 means to call system functions! If you try to do so Vim will
6666 very probably crash.
6667
6668 For Win32, the functions you write must be placed in a DLL
6669 and use the normal C calling convention (NOT Pascal which is
6670 used in Windows System DLLs). The function must take exactly
6671 one parameter, either a character pointer or a long integer,
6672 and must return a character pointer or NULL. The character
6673 pointer returned must point to memory that will remain valid
6674 after the function has returned (e.g. in static data in the
6675 DLL). If it points to allocated memory, that memory will
6676 leak away. Using a static buffer in the function should work,
6677 it's then freed when the DLL is unloaded.
6678
6679 WARNING: If the function returns a non-valid pointer, Vim may
Bram Moolenaar446cb832008-06-24 21:56:24 +00006680 crash! This also happens if the function returns a number,
Bram Moolenaar071d4272004-06-13 20:20:40 +00006681 because Vim thinks it's a pointer.
6682 For Win32 systems, {libname} should be the filename of the DLL
6683 without the ".DLL" suffix. A full path is only required if
6684 the DLL is not in the usual places.
6685 For Unix: When compiling your own plugins, remember that the
6686 object code must be compiled as position-independent ('PIC').
Bram Moolenaar8f3f58f2010-01-06 20:52:26 +01006687 {only in Win32 and some Unix versions, when the |+libcall|
Bram Moolenaar071d4272004-06-13 20:20:40 +00006688 feature is present}
6689 Examples: >
6690 :echo libcall("libc.so", "getenv", "HOME")
Bram Moolenaar02b31112019-08-31 22:16:38 +02006691
Bram Moolenaar2e693a82019-10-16 22:35:02 +02006692< Can also be used as a |method|, the base is passed as the
6693 third argument: >
Bram Moolenaar02b31112019-08-31 22:16:38 +02006694 GetValue()->libcall("libc.so", "getenv")
Bram Moolenaar071d4272004-06-13 20:20:40 +00006695<
6696 *libcallnr()*
6697libcallnr({libname}, {funcname}, {argument})
Bram Moolenaar8f3f58f2010-01-06 20:52:26 +01006698 Just like |libcall()|, but used for a function that returns an
Bram Moolenaar071d4272004-06-13 20:20:40 +00006699 int instead of a string.
6700 {only in Win32 on some Unix versions, when the |+libcall|
6701 feature is present}
Bram Moolenaar446cb832008-06-24 21:56:24 +00006702 Examples: >
6703 :echo libcallnr("/usr/lib/libc.so", "getpid", "")
Bram Moolenaar071d4272004-06-13 20:20:40 +00006704 :call libcallnr("libc.so", "printf", "Hello World!\n")
6705 :call libcallnr("libc.so", "sleep", 10)
6706<
Bram Moolenaar2e693a82019-10-16 22:35:02 +02006707 Can also be used as a |method|, the base is passed as the
6708 third argument: >
Bram Moolenaar02b31112019-08-31 22:16:38 +02006709 GetValue()->libcallnr("libc.so", "printf")
6710<
Bram Moolenaara0d1fef2019-09-04 22:29:14 +02006711
6712line({expr} [, {winid}]) *line()*
6713 The result is a Number, which is the line number of the file
Bram Moolenaar071d4272004-06-13 20:20:40 +00006714 position given with {expr}. The accepted positions are:
6715 . the cursor position
6716 $ the last line in the current buffer
6717 'x position of mark x (if the mark is not set, 0 is
6718 returned)
Bram Moolenaara1d5fa62017-04-03 22:02:55 +02006719 w0 first line visible in current window (one if the
6720 display isn't updated, e.g. in silent Ex mode)
6721 w$ last line visible in current window (this is one
6722 less than "w0" if no lines are visible)
Bram Moolenaar9ecd0232008-06-20 15:31:51 +00006723 v In Visual mode: the start of the Visual area (the
6724 cursor is the end). When not in Visual mode
6725 returns the cursor position. Differs from |'<| in
6726 that it's updated right away.
Bram Moolenaaref2f6562007-05-06 13:32:59 +00006727 Note that a mark in another file can be used. The line number
6728 then applies to another buffer.
Bram Moolenaar0b238792006-03-02 22:49:12 +00006729 To get the column number use |col()|. To get both use
6730 |getpos()|.
Bram Moolenaara0d1fef2019-09-04 22:29:14 +02006731 With the optional {winid} argument the values are obtained for
6732 that window instead of the current window.
Bram Moolenaar071d4272004-06-13 20:20:40 +00006733 Examples: >
6734 line(".") line number of the cursor
Bram Moolenaara0d1fef2019-09-04 22:29:14 +02006735 line(".", winid) idem, in window "winid"
Bram Moolenaar071d4272004-06-13 20:20:40 +00006736 line("'t") line number of mark t
6737 line("'" . marker) line number of mark marker
Bram Moolenaar39536dd2019-01-29 22:58:21 +01006738<
6739 To jump to the last known position when opening a file see
6740 |last-position-jump|.
Bram Moolenaar69a7cb42004-06-20 12:51:53 +00006741
Bram Moolenaar02b31112019-08-31 22:16:38 +02006742 Can also be used as a |method|: >
6743 GetValue()->line()
6744
Bram Moolenaar071d4272004-06-13 20:20:40 +00006745line2byte({lnum}) *line2byte()*
6746 Return the byte count from the start of the buffer for line
6747 {lnum}. This includes the end-of-line character, depending on
6748 the 'fileformat' option for the current buffer. The first
Bram Moolenaarb6b046b2011-12-30 13:11:27 +01006749 line returns 1. 'encoding' matters, 'fileencoding' is ignored.
Bram Moolenaar071d4272004-06-13 20:20:40 +00006750 This can also be used to get the byte count for the line just
6751 below the last line: >
6752 line2byte(line("$") + 1)
Bram Moolenaarb6b046b2011-12-30 13:11:27 +01006753< This is the buffer size plus one. If 'fileencoding' is empty
6754 it is the file size plus one.
Bram Moolenaar071d4272004-06-13 20:20:40 +00006755 When {lnum} is invalid, or the |+byte_offset| feature has been
6756 disabled at compile time, -1 is returned.
6757 Also see |byte2line()|, |go| and |:goto|.
6758
Bram Moolenaar02b31112019-08-31 22:16:38 +02006759 Can also be used as a |method|: >
6760 GetLnum()->line2byte()
6761
Bram Moolenaar071d4272004-06-13 20:20:40 +00006762lispindent({lnum}) *lispindent()*
6763 Get the amount of indent for line {lnum} according the lisp
6764 indenting rules, as with 'lisp'.
6765 The indent is counted in spaces, the value of 'tabstop' is
6766 relevant. {lnum} is used just like in |getline()|.
6767 When {lnum} is invalid or Vim was not compiled the
6768 |+lispindent| feature, -1 is returned.
6769
Bram Moolenaar02b31112019-08-31 22:16:38 +02006770 Can also be used as a |method|: >
6771 GetLnum()->lispindent()
6772
Bram Moolenaar9d401282019-04-06 13:18:12 +02006773list2str({list} [, {utf8}]) *list2str()*
6774 Convert each number in {list} to a character string can
6775 concatenate them all. Examples: >
6776 list2str([32]) returns " "
6777 list2str([65, 66, 67]) returns "ABC"
6778< The same can be done (slowly) with: >
6779 join(map(list, {nr, val -> nr2char(val)}), '')
6780< |str2list()| does the opposite.
6781
6782 When {utf8} is omitted or zero, the current 'encoding' is used.
6783 With {utf8} is 1, always return utf-8 characters.
6784 With utf-8 composing characters work as expected: >
6785 list2str([97, 769]) returns "á"
6786<
Bram Moolenaar02b31112019-08-31 22:16:38 +02006787 Can also be used as a |method|: >
6788 GetList()->list2str()
6789
Bram Moolenaara3347722019-05-11 21:14:24 +02006790listener_add({callback} [, {buf}]) *listener_add()*
6791 Add a callback function that will be invoked when changes have
6792 been made to buffer {buf}.
6793 {buf} refers to a buffer name or number. For the accepted
6794 values, see |bufname()|. When {buf} is omitted the current
6795 buffer is used.
6796 Returns a unique ID that can be passed to |listener_remove()|.
6797
Bram Moolenaaraad222c2019-09-06 22:46:09 +02006798 The {callback} is invoked with five arguments:
Bram Moolenaarfe1ade02019-05-14 21:20:36 +02006799 a:bufnr the buffer that was changed
6800 a:start first changed line number
6801 a:end first line number below the change
Bram Moolenaar96f45c02019-10-26 19:53:45 +02006802 a:added number of lines added, negative if lines were
6803 deleted
Bram Moolenaarfe1ade02019-05-14 21:20:36 +02006804 a:changes a List of items with details about the changes
6805
6806 Example: >
6807 func Listener(bufnr, start, end, added, changes)
6808 echo 'lines ' .. a:start .. ' until ' .. a:end .. ' changed'
6809 endfunc
6810 call listener_add('Listener', bufnr)
6811
6812< The List cannot be changed. Each item in a:changes is a
Bram Moolenaar8aad88d2019-05-12 13:53:50 +02006813 dictionary with these entries:
Bram Moolenaara3347722019-05-11 21:14:24 +02006814 lnum the first line number of the change
6815 end the first line below the change
6816 added number of lines added; negative if lines were
6817 deleted
6818 col first column in "lnum" that was affected by
6819 the change; one if unknown or the whole line
6820 was affected; this is a byte index, first
6821 character has a value of one.
6822 When lines are inserted the values are:
Bram Moolenaar68e65602019-05-26 21:33:31 +02006823 lnum line above which the new line is added
Bram Moolenaara3347722019-05-11 21:14:24 +02006824 end equal to "lnum"
6825 added number of lines inserted
Bram Moolenaarfe1ade02019-05-14 21:20:36 +02006826 col 1
Bram Moolenaara3347722019-05-11 21:14:24 +02006827 When lines are deleted the values are:
6828 lnum the first deleted line
6829 end the line below the first deleted line, before
6830 the deletion was done
6831 added negative, number of lines deleted
Bram Moolenaarfe1ade02019-05-14 21:20:36 +02006832 col 1
Bram Moolenaara3347722019-05-11 21:14:24 +02006833 When lines are changed:
6834 lnum the first changed line
6835 end the line below the last changed line
Bram Moolenaarfe1ade02019-05-14 21:20:36 +02006836 added 0
6837 col first column with a change or 1
Bram Moolenaara3347722019-05-11 21:14:24 +02006838
Bram Moolenaarfe1ade02019-05-14 21:20:36 +02006839 The entries are in the order the changes were made, thus the
6840 most recent change is at the end. The line numbers are valid
6841 when the callback is invoked, but later changes may make them
6842 invalid, thus keeping a copy for later might not work.
Bram Moolenaar8aad88d2019-05-12 13:53:50 +02006843
Bram Moolenaarfe1ade02019-05-14 21:20:36 +02006844 The {callback} is invoked just before the screen is updated,
6845 when |listener_flush()| is called or when a change is being
6846 made that changes the line count in a way it causes a line
6847 number in the list of changes to become invalid.
Bram Moolenaar8aad88d2019-05-12 13:53:50 +02006848
Bram Moolenaarfe1ade02019-05-14 21:20:36 +02006849 The {callback} is invoked with the text locked, see
6850 |textlock|. If you do need to make changes to the buffer, use
6851 a timer to do this later |timer_start()|.
Bram Moolenaara3347722019-05-11 21:14:24 +02006852
6853 The {callback} is not invoked when the buffer is first loaded.
6854 Use the |BufReadPost| autocmd event to handle the initial text
6855 of a buffer.
6856 The {callback} is also not invoked when the buffer is
6857 unloaded, use the |BufUnload| autocmd event for that.
6858
Bram Moolenaar2e693a82019-10-16 22:35:02 +02006859 Can also be used as a |method|, the base is passed as the
6860 second argument: >
Bram Moolenaar02b31112019-08-31 22:16:38 +02006861 GetBuffer()->listener_add(callback)
6862
Bram Moolenaarfe1ade02019-05-14 21:20:36 +02006863listener_flush([{buf}]) *listener_flush()*
6864 Invoke listener callbacks for buffer {buf}. If there are no
6865 pending changes then no callbacks are invoked.
6866
6867 {buf} refers to a buffer name or number. For the accepted
6868 values, see |bufname()|. When {buf} is omitted the current
6869 buffer is used.
6870
Bram Moolenaar02b31112019-08-31 22:16:38 +02006871 Can also be used as a |method|: >
6872 GetBuffer()->listener_flush()
6873
Bram Moolenaara3347722019-05-11 21:14:24 +02006874listener_remove({id}) *listener_remove()*
6875 Remove a listener previously added with listener_add().
Bram Moolenaar809ce4d2019-07-13 21:21:40 +02006876 Returns zero when {id} could not be found, one when {id} was
6877 removed.
Bram Moolenaara3347722019-05-11 21:14:24 +02006878
Bram Moolenaar02b31112019-08-31 22:16:38 +02006879 Can also be used as a |method|: >
6880 GetListenerId()->listener_remove()
6881
Bram Moolenaar071d4272004-06-13 20:20:40 +00006882localtime() *localtime()*
6883 Return the current time, measured as seconds since 1st Jan
Bram Moolenaar10455d42019-11-21 15:36:18 +01006884 1970. See also |strftime()|, |strptime()| and |getftime()|.
Bram Moolenaar071d4272004-06-13 20:20:40 +00006885
Bram Moolenaar5f2bb9f2005-01-11 21:29:04 +00006886
Bram Moolenaardb7c6862010-05-21 16:33:48 +02006887log({expr}) *log()*
Bram Moolenaar9855d6b2010-07-18 14:34:51 +02006888 Return the natural logarithm (base e) of {expr} as a |Float|.
6889 {expr} must evaluate to a |Float| or a |Number| in the range
Bram Moolenaardb7c6862010-05-21 16:33:48 +02006890 (0, inf].
6891 Examples: >
6892 :echo log(10)
6893< 2.302585 >
6894 :echo log(exp(5))
6895< 5.0
Bram Moolenaar93cf85f2019-08-17 21:36:28 +02006896
6897 Can also be used as a |method|: >
6898 Compute()->log()
6899<
Bram Moolenaardb84e452010-08-15 13:50:43 +02006900 {only available when compiled with the |+float| feature}
Bram Moolenaardb7c6862010-05-21 16:33:48 +02006901
6902
Bram Moolenaar446cb832008-06-24 21:56:24 +00006903log10({expr}) *log10()*
6904 Return the logarithm of Float {expr} to base 10 as a |Float|.
6905 {expr} must evaluate to a |Float| or a |Number|.
6906 Examples: >
6907 :echo log10(1000)
6908< 3.0 >
6909 :echo log10(0.01)
6910< -2.0
Bram Moolenaar93cf85f2019-08-17 21:36:28 +02006911
6912 Can also be used as a |method|: >
6913 Compute()->log10()
6914<
Bram Moolenaar446cb832008-06-24 21:56:24 +00006915 {only available when compiled with the |+float| feature}
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01006916
6917luaeval({expr} [, {expr}]) *luaeval()*
6918 Evaluate Lua expression {expr} and return its result converted
6919 to Vim data structures. Second {expr} may hold additional
Bram Moolenaard38b0552012-04-25 19:07:41 +02006920 argument accessible as _A inside first {expr}.
6921 Strings are returned as they are.
6922 Boolean objects are converted to numbers.
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01006923 Numbers are converted to |Float| values if vim was compiled
Bram Moolenaard38b0552012-04-25 19:07:41 +02006924 with |+float| and to numbers otherwise.
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01006925 Dictionaries and lists obtained by vim.eval() are returned
Bram Moolenaard38b0552012-04-25 19:07:41 +02006926 as-is.
6927 Other objects are returned as zero without any errors.
6928 See |lua-luaeval| for more details.
Bram Moolenaar02b31112019-08-31 22:16:38 +02006929
6930 Can also be used as a |method|: >
6931 GetExpr()->luaeval()
6932
6933< {only available when compiled with the |+lua| feature}
Bram Moolenaard38b0552012-04-25 19:07:41 +02006934
Bram Moolenaarb33c7eb2016-07-04 22:29:49 +02006935map({expr1}, {expr2}) *map()*
6936 {expr1} must be a |List| or a |Dictionary|.
6937 Replace each item in {expr1} with the result of evaluating
6938 {expr2}. {expr2} must be a |string| or |Funcref|.
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01006939
Bram Moolenaarb33c7eb2016-07-04 22:29:49 +02006940 If {expr2} is a |string|, inside {expr2} |v:val| has the value
6941 of the current item. For a |Dictionary| |v:key| has the key
6942 of the current item and for a |List| |v:key| has the index of
6943 the current item.
Bram Moolenaar2fda12f2005-01-15 22:14:15 +00006944 Example: >
6945 :call map(mylist, '"> " . v:val . " <"')
Bram Moolenaar5f2bb9f2005-01-11 21:29:04 +00006946< This puts "> " before and " <" after each item in "mylist".
Bram Moolenaar2fda12f2005-01-15 22:14:15 +00006947
Bram Moolenaarb33c7eb2016-07-04 22:29:49 +02006948 Note that {expr2} is the result of an expression and is then
Bram Moolenaar2fda12f2005-01-15 22:14:15 +00006949 used as an expression again. Often it is good to use a
Bram Moolenaar3a7c85b2005-02-05 21:39:53 +00006950 |literal-string| to avoid having to double backslashes. You
6951 still have to double ' quotes
Bram Moolenaar2fda12f2005-01-15 22:14:15 +00006952
Bram Moolenaarb33c7eb2016-07-04 22:29:49 +02006953 If {expr2} is a |Funcref| it is called with two arguments:
6954 1. The key or the index of the current item.
6955 2. the value of the current item.
6956 The function must return the new value of the item. Example
6957 that changes each value by "key-value": >
6958 func KeyValue(key, val)
6959 return a:key . '-' . a:val
6960 endfunc
6961 call map(myDict, function('KeyValue'))
Bram Moolenaar50ba5262016-09-22 22:33:02 +02006962< It is shorter when using a |lambda|: >
6963 call map(myDict, {key, val -> key . '-' . val})
6964< If you do not use "val" you can leave it out: >
6965 call map(myDict, {key -> 'item: ' . key})
Bram Moolenaar088e8e32019-08-08 22:15:18 +02006966< If you do not use "key" you can use a short name: >
6967 call map(myDict, {_, val -> 'item: ' . val})
Bram Moolenaarb33c7eb2016-07-04 22:29:49 +02006968<
Bram Moolenaar32466aa2006-02-24 23:53:04 +00006969 The operation is done in-place. If you want a |List| or
6970 |Dictionary| to remain unmodified make a copy first: >
Bram Moolenaar30b65812012-07-12 22:01:11 +02006971 :let tlist = map(copy(mylist), ' v:val . "\t"')
Bram Moolenaar2fda12f2005-01-15 22:14:15 +00006972
Bram Moolenaarb33c7eb2016-07-04 22:29:49 +02006973< Returns {expr1}, the |List| or |Dictionary| that was filtered.
6974 When an error is encountered while evaluating {expr2} no
6975 further items in {expr1} are processed. When {expr2} is a
6976 Funcref errors inside a function are ignored, unless it was
6977 defined with the "abort" flag.
Bram Moolenaar5f2bb9f2005-01-11 21:29:04 +00006978
Bram Moolenaarac92e252019-08-03 21:58:38 +02006979 Can also be used as a |method|: >
6980 mylist->map(expr2)
Bram Moolenaar5f2bb9f2005-01-11 21:29:04 +00006981
Bram Moolenaar4c9243f2020-05-22 13:10:44 +02006982
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01006983maparg({name} [, {mode} [, {abbr} [, {dict}]]]) *maparg()*
Bram Moolenaarbd743252010-10-20 21:23:33 +02006984 When {dict} is omitted or zero: Return the rhs of mapping
6985 {name} in mode {mode}. The returned String has special
6986 characters translated like in the output of the ":map" command
6987 listing.
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01006988
Bram Moolenaarbd743252010-10-20 21:23:33 +02006989 When there is no mapping for {name}, an empty String is
Bram Moolenaar0b0f0992018-05-22 21:41:30 +02006990 returned. When the mapping for {name} is empty, then "<Nop>"
6991 is returned.
Bram Moolenaarbd743252010-10-20 21:23:33 +02006992
6993 The {name} can have special key names, like in the ":map"
6994 command.
6995
Bram Moolenaard12f5c12006-01-25 22:10:52 +00006996 {mode} can be one of these strings:
Bram Moolenaar071d4272004-06-13 20:20:40 +00006997 "n" Normal
Bram Moolenaarbd743252010-10-20 21:23:33 +02006998 "v" Visual (including Select)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006999 "o" Operator-pending
7000 "i" Insert
7001 "c" Cmd-line
Bram Moolenaarbd743252010-10-20 21:23:33 +02007002 "s" Select
7003 "x" Visual
Bram Moolenaar071d4272004-06-13 20:20:40 +00007004 "l" langmap |language-mapping|
Bram Moolenaar37c64c72017-09-19 22:06:03 +02007005 "t" Terminal-Job
Bram Moolenaar071d4272004-06-13 20:20:40 +00007006 "" Normal, Visual and Operator-pending
Bram Moolenaard12f5c12006-01-25 22:10:52 +00007007 When {mode} is omitted, the modes for "" are used.
Bram Moolenaarbd743252010-10-20 21:23:33 +02007008
Bram Moolenaare381d3d2016-07-07 14:50:41 +02007009 When {abbr} is there and it is |TRUE| use abbreviations
Bram Moolenaar97b2ad32006-03-18 21:40:56 +00007010 instead of mappings.
Bram Moolenaarbd743252010-10-20 21:23:33 +02007011
Bram Moolenaare381d3d2016-07-07 14:50:41 +02007012 When {dict} is there and it is |TRUE| return a dictionary
Bram Moolenaarbd743252010-10-20 21:23:33 +02007013 containing all the information of the mapping with the
7014 following items:
Bram Moolenaar9c652532020-05-24 13:10:18 +02007015 "lhs" The {lhs} of the mapping as it would be typed
7016 "lhsraw" The {lhs} of the mapping as raw bytes
7017 "lhsrawalt" The {lhs} of the mapping as raw bytes, alternate
7018 form, only present when it differs from "lhsraw"
Bram Moolenaarbd743252010-10-20 21:23:33 +02007019 "rhs" The {rhs} of the mapping as typed.
7020 "silent" 1 for a |:map-silent| mapping, else 0.
Bram Moolenaar05365702010-10-27 18:34:44 +02007021 "noremap" 1 if the {rhs} of the mapping is not remappable.
Bram Moolenaar2da0f0c2020-04-01 19:22:12 +02007022 "script" 1 if mapping was defined with <script>.
Bram Moolenaarbd743252010-10-20 21:23:33 +02007023 "expr" 1 for an expression mapping (|:map-<expr>|).
7024 "buffer" 1 for a buffer local mapping (|:map-local|).
7025 "mode" Modes for which the mapping is defined. In
7026 addition to the modes mentioned above, these
7027 characters will be used:
7028 " " Normal, Visual and Operator-pending
7029 "!" Insert and Commandline mode
Bram Moolenaar166af9b2010-11-16 20:34:40 +01007030 (|mapmode-ic|)
Bram Moolenaar05365702010-10-27 18:34:44 +02007031 "sid" The script local ID, used for <sid> mappings
7032 (|<SID>|).
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02007033 "lnum" The line number in "sid", zero if unknown.
Bram Moolenaardfb18412013-12-11 18:53:29 +01007034 "nowait" Do not wait for other, longer mappings.
7035 (|:map-<nowait>|).
Bram Moolenaar4c9243f2020-05-22 13:10:44 +02007036
7037 The dictionary can be used to restore a mapping with
7038 |mapset()|.
Bram Moolenaarbd743252010-10-20 21:23:33 +02007039
Bram Moolenaar071d4272004-06-13 20:20:40 +00007040 The mappings local to the current buffer are checked first,
7041 then the global mappings.
Bram Moolenaara40ceaf2006-01-13 22:35:40 +00007042 This function can be used to map a key even when it's already
7043 mapped, and have it do the original mapping too. Sketch: >
7044 exe 'nnoremap <Tab> ==' . maparg('<Tab>', 'n')
7045
Bram Moolenaara1449832019-09-01 20:16:52 +02007046< Can also be used as a |method|: >
7047 GetKey()->maparg('n')
Bram Moolenaar071d4272004-06-13 20:20:40 +00007048
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01007049mapcheck({name} [, {mode} [, {abbr}]]) *mapcheck()*
Bram Moolenaar071d4272004-06-13 20:20:40 +00007050 Check if there is a mapping that matches with {name} in mode
7051 {mode}. See |maparg()| for {mode} and special names in
7052 {name}.
Bram Moolenaare381d3d2016-07-07 14:50:41 +02007053 When {abbr} is there and it is |TRUE| use abbreviations
Bram Moolenaar97b2ad32006-03-18 21:40:56 +00007054 instead of mappings.
Bram Moolenaar071d4272004-06-13 20:20:40 +00007055 A match happens with a mapping that starts with {name} and
7056 with a mapping which is equal to the start of {name}.
7057
Bram Moolenaar446cb832008-06-24 21:56:24 +00007058 matches mapping "a" "ab" "abc" ~
Bram Moolenaar071d4272004-06-13 20:20:40 +00007059 mapcheck("a") yes yes yes
7060 mapcheck("abc") yes yes yes
7061 mapcheck("ax") yes no no
7062 mapcheck("b") no no no
7063
7064 The difference with maparg() is that mapcheck() finds a
7065 mapping that matches with {name}, while maparg() only finds a
7066 mapping for {name} exactly.
7067 When there is no mapping that starts with {name}, an empty
Bram Moolenaar0b0f0992018-05-22 21:41:30 +02007068 String is returned. If there is one, the RHS of that mapping
Bram Moolenaar071d4272004-06-13 20:20:40 +00007069 is returned. If there are several mappings that start with
Bram Moolenaar0b0f0992018-05-22 21:41:30 +02007070 {name}, the RHS of one of them is returned. This will be
7071 "<Nop>" if the RHS is empty.
Bram Moolenaar071d4272004-06-13 20:20:40 +00007072 The mappings local to the current buffer are checked first,
7073 then the global mappings.
7074 This function can be used to check if a mapping can be added
7075 without being ambiguous. Example: >
7076 :if mapcheck("_vv") == ""
7077 : map _vv :set guifont=7x13<CR>
7078 :endif
7079< This avoids adding the "_vv" mapping when there already is a
7080 mapping for "_v" or for "_vvv".
7081
Bram Moolenaara1449832019-09-01 20:16:52 +02007082 Can also be used as a |method|: >
7083 GetKey()->mapcheck('n')
7084
Bram Moolenaar9c652532020-05-24 13:10:18 +02007085
Bram Moolenaar4c9243f2020-05-22 13:10:44 +02007086mapset({mode}, {abbr}, {dict}) *mapset()*
7087 Restore a mapping from a dictionary returned by |maparg()|.
Bram Moolenaar9c652532020-05-24 13:10:18 +02007088 {mode} and {abbr} should be the same as for the call to
7089 |maparg()|. *E460*
Bram Moolenaar4c9243f2020-05-22 13:10:44 +02007090 {mode} is used to define the mode in which the mapping is set,
7091 not the "mode" entry in {dict}.
7092 Example for saving and restoring a mapping: >
7093 let save_map = maparg('K', 'n', 0, 1)
7094 nnoremap K somethingelse
7095 ...
7096 call mapset('n', 0, save_map)
Bram Moolenaar9c652532020-05-24 13:10:18 +02007097< Note that if you are going to replace a map in several modes,
7098 e.g. with `:map!`, you need to save the mapping for all of
Bram Moolenaarebacddb2020-06-04 15:22:21 +02007099 them, since they can differ.
Bram Moolenaar9c652532020-05-24 13:10:18 +02007100
7101
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01007102match({expr}, {pat} [, {start} [, {count}]]) *match()*
Bram Moolenaar32466aa2006-02-24 23:53:04 +00007103 When {expr} is a |List| then this returns the index of the
7104 first item where {pat} matches. Each item is used as a
Bram Moolenaara23ccb82006-02-27 00:08:02 +00007105 String, |Lists| and |Dictionaries| are used as echoed.
Bram Moolenaar93a1df22018-09-10 11:51:50 +02007106
Bram Moolenaar58b85342016-08-14 19:54:54 +02007107 Otherwise, {expr} is used as a String. The result is a
Bram Moolenaar5f2bb9f2005-01-11 21:29:04 +00007108 Number, which gives the index (byte offset) in {expr} where
7109 {pat} matches.
Bram Moolenaar93a1df22018-09-10 11:51:50 +02007110
Bram Moolenaar32466aa2006-02-24 23:53:04 +00007111 A match at the first character or |List| item returns zero.
Bram Moolenaar89cb5e02004-07-19 20:55:54 +00007112 If there is no match -1 is returned.
Bram Moolenaar93a1df22018-09-10 11:51:50 +02007113
Bram Moolenaar20f90cf2011-05-19 12:22:51 +02007114 For getting submatches see |matchlist()|.
Bram Moolenaar89cb5e02004-07-19 20:55:54 +00007115 Example: >
Bram Moolenaar5f2bb9f2005-01-11 21:29:04 +00007116 :echo match("testing", "ing") " results in 4
Bram Moolenaar362e1a32006-03-06 23:29:24 +00007117 :echo match([1, 'x'], '\a') " results in 1
Bram Moolenaar5f2bb9f2005-01-11 21:29:04 +00007118< See |string-match| for how {pat} is used.
Bram Moolenaar05159a02005-02-26 23:04:13 +00007119 *strpbrk()*
Bram Moolenaar58b85342016-08-14 19:54:54 +02007120 Vim doesn't have a strpbrk() function. But you can do: >
Bram Moolenaar05159a02005-02-26 23:04:13 +00007121 :let sepidx = match(line, '[.,;: \t]')
7122< *strcasestr()*
7123 Vim doesn't have a strcasestr() function. But you can add
7124 "\c" to the pattern to ignore case: >
7125 :let idx = match(haystack, '\cneedle')
7126<
Bram Moolenaar5f2bb9f2005-01-11 21:29:04 +00007127 If {start} is given, the search starts from byte index
Bram Moolenaar32466aa2006-02-24 23:53:04 +00007128 {start} in a String or item {start} in a |List|.
Bram Moolenaar071d4272004-06-13 20:20:40 +00007129 The result, however, is still the index counted from the
Bram Moolenaar402d2fe2005-04-15 21:00:38 +00007130 first character/item. Example: >
Bram Moolenaar071d4272004-06-13 20:20:40 +00007131 :echo match("testing", "ing", 2)
7132< result is again "4". >
7133 :echo match("testing", "ing", 4)
7134< result is again "4". >
7135 :echo match("testing", "t", 2)
7136< result is "3".
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007137 For a String, if {start} > 0 then it is like the string starts
Bram Moolenaar0b238792006-03-02 22:49:12 +00007138 {start} bytes later, thus "^" will match at {start}. Except
7139 when {count} is given, then it's like matches before the
7140 {start} byte are ignored (this is a bit complicated to keep it
7141 backwards compatible).
Bram Moolenaar5f2bb9f2005-01-11 21:29:04 +00007142 For a String, if {start} < 0, it will be set to 0. For a list
7143 the index is counted from the end.
Bram Moolenaare224ffa2006-03-01 00:01:28 +00007144 If {start} is out of range ({start} > strlen({expr}) for a
7145 String or {start} > len({expr}) for a |List|) -1 is returned.
Bram Moolenaar5f2bb9f2005-01-11 21:29:04 +00007146
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007147 When {count} is given use the {count}'th match. When a match
Bram Moolenaare224ffa2006-03-01 00:01:28 +00007148 is found in a String the search for the next one starts one
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007149 character further. Thus this example results in 1: >
7150 echo match("testing", "..", 0, 2)
7151< In a |List| the search continues in the next item.
Bram Moolenaar0b238792006-03-02 22:49:12 +00007152 Note that when {count} is added the way {start} works changes,
7153 see above.
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007154
Bram Moolenaar071d4272004-06-13 20:20:40 +00007155 See |pattern| for the patterns that are accepted.
7156 The 'ignorecase' option is used to set the ignore-caseness of
Bram Moolenaar58b85342016-08-14 19:54:54 +02007157 the pattern. 'smartcase' is NOT used. The matching is always
Bram Moolenaar071d4272004-06-13 20:20:40 +00007158 done like 'magic' is set and 'cpoptions' is empty.
Bram Moolenaarbc93ceb2020-02-26 13:36:21 +01007159 Note that a match at the start is preferred, thus when the
7160 pattern is using "*" (any number of matches) it tends to find
7161 zero matches at the start instead of a number of matches
7162 further down in the text.
Bram Moolenaar071d4272004-06-13 20:20:40 +00007163
Bram Moolenaara1449832019-09-01 20:16:52 +02007164 Can also be used as a |method|: >
7165 GetList()->match('word')
7166<
Bram Moolenaar95e51472018-07-28 16:55:56 +02007167 *matchadd()* *E798* *E799* *E801* *E957*
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01007168matchadd({group}, {pattern} [, {priority} [, {id} [, {dict}]]])
Bram Moolenaar6ee10162007-07-26 20:58:42 +00007169 Defines a pattern to be highlighted in the current window (a
7170 "match"). It will be highlighted with {group}. Returns an
7171 identification number (ID), which can be used to delete the
Bram Moolenaaraff74912019-03-30 18:11:49 +01007172 match using |matchdelete()|. The ID is bound to the window.
Bram Moolenaar8e69b4a2013-11-09 03:41:58 +01007173 Matching is case sensitive and magic, unless case sensitivity
7174 or magicness are explicitly overridden in {pattern}. The
7175 'magic', 'smartcase' and 'ignorecase' options are not used.
Bram Moolenaarf9132812015-07-21 19:19:13 +02007176 The "Conceal" value is special, it causes the match to be
7177 concealed.
Bram Moolenaar6ee10162007-07-26 20:58:42 +00007178
7179 The optional {priority} argument assigns a priority to the
Bram Moolenaar58b85342016-08-14 19:54:54 +02007180 match. A match with a high priority will have its
Bram Moolenaar6ee10162007-07-26 20:58:42 +00007181 highlighting overrule that of a match with a lower priority.
7182 A priority is specified as an integer (negative numbers are no
7183 exception). If the {priority} argument is not specified, the
7184 default priority is 10. The priority of 'hlsearch' is zero,
7185 hence all matches with a priority greater than zero will
7186 overrule it. Syntax highlighting (see 'syntax') is a separate
7187 mechanism, and regardless of the chosen priority a match will
7188 always overrule syntax highlighting.
7189
7190 The optional {id} argument allows the request for a specific
7191 match ID. If a specified ID is already taken, an error
7192 message will appear and the match will not be added. An ID
7193 is specified as a positive integer (zero excluded). IDs 1, 2
7194 and 3 are reserved for |:match|, |:2match| and |:3match|,
Bram Moolenaar6561d522015-07-21 15:48:27 +02007195 respectively. If the {id} argument is not specified or -1,
Bram Moolenaar6ee10162007-07-26 20:58:42 +00007196 |matchadd()| automatically chooses a free ID.
7197
Bram Moolenaar85084ef2016-01-17 22:26:33 +01007198 The optional {dict} argument allows for further custom
7199 values. Currently this is used to specify a match specific
Bram Moolenaar6561d522015-07-21 15:48:27 +02007200 conceal character that will be shown for |hl-Conceal|
7201 highlighted matches. The dict can have the following members:
7202
7203 conceal Special character to show instead of the
Bram Moolenaar6463ca22016-02-13 17:04:46 +01007204 match (only for |hl-Conceal| highlighted
Bram Moolenaar6561d522015-07-21 15:48:27 +02007205 matches, see |:syn-cchar|)
Bram Moolenaar95e51472018-07-28 16:55:56 +02007206 window Instead of the current window use the
7207 window with this number or window ID.
Bram Moolenaar6561d522015-07-21 15:48:27 +02007208
Bram Moolenaar6ee10162007-07-26 20:58:42 +00007209 The number of matches is not limited, as it is the case with
7210 the |:match| commands.
7211
7212 Example: >
7213 :highlight MyGroup ctermbg=green guibg=green
7214 :let m = matchadd("MyGroup", "TODO")
7215< Deletion of the pattern: >
7216 :call matchdelete(m)
7217
7218< A list of matches defined by |matchadd()| and |:match| are
Bram Moolenaar58b85342016-08-14 19:54:54 +02007219 available from |getmatches()|. All matches can be deleted in
Bram Moolenaar6ee10162007-07-26 20:58:42 +00007220 one operation by |clearmatches()|.
Bram Moolenaar910f66f2006-04-05 20:41:53 +00007221
Bram Moolenaara1449832019-09-01 20:16:52 +02007222 Can also be used as a |method|: >
7223 GetGroup()->matchadd('TODO')
7224<
Bram Moolenaar8e97bd72016-08-06 22:05:07 +02007225 *matchaddpos()*
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01007226matchaddpos({group}, {pos} [, {priority} [, {id} [, {dict}]]])
Bram Moolenaarb3414592014-06-17 17:48:32 +02007227 Same as |matchadd()|, but requires a list of positions {pos}
7228 instead of a pattern. This command is faster than |matchadd()|
7229 because it does not require to handle regular expressions and
7230 sets buffer line boundaries to redraw screen. It is supposed
7231 to be used when fast match additions and deletions are
7232 required, for example to highlight matching parentheses.
7233
7234 The list {pos} can contain one of these items:
Bram Moolenaarb6da44a2014-06-25 18:15:22 +02007235 - A number. This whole line will be highlighted. The first
Bram Moolenaarb3414592014-06-17 17:48:32 +02007236 line has number 1.
7237 - A list with one number, e.g., [23]. The whole line with this
7238 number will be highlighted.
7239 - A list with two numbers, e.g., [23, 11]. The first number is
Bram Moolenaarb6da44a2014-06-25 18:15:22 +02007240 the line number, the second one is the column number (first
7241 column is 1, the value must correspond to the byte index as
7242 |col()| would return). The character at this position will
7243 be highlighted.
Bram Moolenaarb3414592014-06-17 17:48:32 +02007244 - A list with three numbers, e.g., [23, 11, 3]. As above, but
Bram Moolenaarb6da44a2014-06-25 18:15:22 +02007245 the third number gives the length of the highlight in bytes.
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01007246
Bram Moolenaarb3414592014-06-17 17:48:32 +02007247 The maximum number of positions is 8.
7248
7249 Example: >
7250 :highlight MyGroup ctermbg=green guibg=green
7251 :let m = matchaddpos("MyGroup", [[23, 24], 34])
7252< Deletion of the pattern: >
7253 :call matchdelete(m)
7254
7255< Matches added by |matchaddpos()| are returned by
7256 |getmatches()| with an entry "pos1", "pos2", etc., with the
7257 value a list like the {pos} item.
Bram Moolenaarb3414592014-06-17 17:48:32 +02007258
Bram Moolenaara1449832019-09-01 20:16:52 +02007259 Can also be used as a |method|: >
7260 GetGroup()->matchaddpos([23, 11])
7261
Bram Moolenaar910f66f2006-04-05 20:41:53 +00007262matcharg({nr}) *matcharg()*
Bram Moolenaarc9b4b052006-04-30 18:54:39 +00007263 Selects the {nr} match item, as set with a |:match|,
Bram Moolenaar910f66f2006-04-05 20:41:53 +00007264 |:2match| or |:3match| command.
7265 Return a |List| with two elements:
7266 The name of the highlight group used
7267 The pattern used.
7268 When {nr} is not 1, 2 or 3 returns an empty |List|.
7269 When there is no match item set returns ['', ''].
Bram Moolenaar6ee10162007-07-26 20:58:42 +00007270 This is useful to save and restore a |:match|.
7271 Highlighting matches using the |:match| commands are limited
7272 to three matches. |matchadd()| does not have this limitation.
Bram Moolenaar910f66f2006-04-05 20:41:53 +00007273
Bram Moolenaara1449832019-09-01 20:16:52 +02007274 Can also be used as a |method|: >
7275 GetMatch()->matcharg()
7276
Bram Moolenaaraff74912019-03-30 18:11:49 +01007277matchdelete({id} [, {win}) *matchdelete()* *E802* *E803*
Bram Moolenaar6ee10162007-07-26 20:58:42 +00007278 Deletes a match with ID {id} previously defined by |matchadd()|
Bram Moolenaar446cb832008-06-24 21:56:24 +00007279 or one of the |:match| commands. Returns 0 if successful,
Bram Moolenaar6ee10162007-07-26 20:58:42 +00007280 otherwise -1. See example for |matchadd()|. All matches can
7281 be deleted in one operation by |clearmatches()|.
Bram Moolenaaraff74912019-03-30 18:11:49 +01007282 If {win} is specified, use the window with this number or
7283 window ID instead of the current window.
Bram Moolenaar910f66f2006-04-05 20:41:53 +00007284
Bram Moolenaara1449832019-09-01 20:16:52 +02007285 Can also be used as a |method|: >
7286 GetMatch()->matchdelete()
7287
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01007288matchend({expr}, {pat} [, {start} [, {count}]]) *matchend()*
Bram Moolenaar8f3f58f2010-01-06 20:52:26 +01007289 Same as |match()|, but return the index of first character
7290 after the match. Example: >
Bram Moolenaar071d4272004-06-13 20:20:40 +00007291 :echo matchend("testing", "ing")
7292< results in "7".
Bram Moolenaar05159a02005-02-26 23:04:13 +00007293 *strspn()* *strcspn()*
7294 Vim doesn't have a strspn() or strcspn() function, but you can
7295 do it with matchend(): >
7296 :let span = matchend(line, '[a-zA-Z]')
7297 :let span = matchend(line, '[^a-zA-Z]')
7298< Except that -1 is returned when there are no matches.
7299
Bram Moolenaar8f3f58f2010-01-06 20:52:26 +01007300 The {start}, if given, has the same meaning as for |match()|. >
Bram Moolenaar071d4272004-06-13 20:20:40 +00007301 :echo matchend("testing", "ing", 2)
7302< results in "7". >
7303 :echo matchend("testing", "ing", 5)
7304< result is "-1".
Bram Moolenaar8f3f58f2010-01-06 20:52:26 +01007305 When {expr} is a |List| the result is equal to |match()|.
Bram Moolenaar071d4272004-06-13 20:20:40 +00007306
Bram Moolenaara1449832019-09-01 20:16:52 +02007307 Can also be used as a |method|: >
7308 GetText()->matchend('word')
7309
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01007310matchlist({expr}, {pat} [, {start} [, {count}]]) *matchlist()*
Bram Moolenaar8f3f58f2010-01-06 20:52:26 +01007311 Same as |match()|, but return a |List|. The first item in the
Bram Moolenaar3a7c85b2005-02-05 21:39:53 +00007312 list is the matched string, same as what matchstr() would
7313 return. Following items are submatches, like "\1", "\2", etc.
Bram Moolenaarf9393ef2006-04-24 19:47:27 +00007314 in |:substitute|. When an optional submatch didn't match an
7315 empty string is used. Example: >
7316 echo matchlist('acd', '\(a\)\?\(b\)\?\(c\)\?\(.*\)')
7317< Results in: ['acd', 'a', '', 'c', 'd', '', '', '', '', '']
Bram Moolenaar3a7c85b2005-02-05 21:39:53 +00007318 When there is no match an empty list is returned.
7319
Bram Moolenaara1449832019-09-01 20:16:52 +02007320 Can also be used as a |method|: >
7321 GetList()->matchlist('word')
7322
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01007323matchstr({expr}, {pat} [, {start} [, {count}]]) *matchstr()*
Bram Moolenaar446cb832008-06-24 21:56:24 +00007324 Same as |match()|, but return the matched string. Example: >
Bram Moolenaar071d4272004-06-13 20:20:40 +00007325 :echo matchstr("testing", "ing")
7326< results in "ing".
7327 When there is no match "" is returned.
Bram Moolenaar8f3f58f2010-01-06 20:52:26 +01007328 The {start}, if given, has the same meaning as for |match()|. >
Bram Moolenaar071d4272004-06-13 20:20:40 +00007329 :echo matchstr("testing", "ing", 2)
7330< results in "ing". >
7331 :echo matchstr("testing", "ing", 5)
7332< result is "".
Bram Moolenaar32466aa2006-02-24 23:53:04 +00007333 When {expr} is a |List| then the matching item is returned.
Bram Moolenaar5f2bb9f2005-01-11 21:29:04 +00007334 The type isn't changed, it's not necessarily a String.
Bram Moolenaar071d4272004-06-13 20:20:40 +00007335
Bram Moolenaara1449832019-09-01 20:16:52 +02007336 Can also be used as a |method|: >
7337 GetText()->matchstr('word')
7338
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01007339matchstrpos({expr}, {pat} [, {start} [, {count}]]) *matchstrpos()*
Bram Moolenaar7fed5c12016-03-29 23:10:31 +02007340 Same as |matchstr()|, but return the matched string, the start
7341 position and the end position of the match. Example: >
7342 :echo matchstrpos("testing", "ing")
7343< results in ["ing", 4, 7].
7344 When there is no match ["", -1, -1] is returned.
7345 The {start}, if given, has the same meaning as for |match()|. >
7346 :echo matchstrpos("testing", "ing", 2)
7347< results in ["ing", 4, 7]. >
7348 :echo matchstrpos("testing", "ing", 5)
7349< result is ["", -1, -1].
7350 When {expr} is a |List| then the matching item, the index
7351 of first item where {pat} matches, the start position and the
7352 end position of the match are returned. >
7353 :echo matchstrpos([1, '__x'], '\a')
7354< result is ["x", 1, 2, 3].
7355 The type isn't changed, it's not necessarily a String.
7356
Bram Moolenaara1449832019-09-01 20:16:52 +02007357 Can also be used as a |method|: >
7358 GetText()->matchstrpos('word')
Bram Moolenaar2e693a82019-10-16 22:35:02 +02007359<
Bram Moolenaar0eabd4d2020-03-15 16:13:53 +01007360
Bram Moolenaar9588a0f2005-01-08 21:45:39 +00007361 *max()*
Bram Moolenaar690afe12017-01-28 18:34:47 +01007362max({expr}) Return the maximum value of all items in {expr}.
Bram Moolenaare46a4402020-06-30 20:38:27 +02007363 {expr} can be a |List| or a |Dictionary|. For a Dictionary,
Bram Moolenaar29634562020-01-09 21:46:04 +01007364 it returns the maximum of all values in the Dictionary.
7365 If {expr} is neither a List nor a Dictionary, or one of the
Bram Moolenaar690afe12017-01-28 18:34:47 +01007366 items in {expr} cannot be used as a Number this results in
Bram Moolenaarf8be4612017-06-23 20:52:40 +02007367 an error. An empty |List| or |Dictionary| results in zero.
Bram Moolenaar9588a0f2005-01-08 21:45:39 +00007368
Bram Moolenaarac92e252019-08-03 21:58:38 +02007369 Can also be used as a |method|: >
7370 mylist->max()
7371
Bram Moolenaar0eabd4d2020-03-15 16:13:53 +01007372
7373menu_info({name} [, {mode}]) *menu_info()*
7374 Return information about the specified menu {name} in
7375 mode {mode}. The menu name should be specified without the
7376 shortcut character ('&').
7377
7378 {mode} can be one of these strings:
7379 "n" Normal
7380 "v" Visual (including Select)
7381 "o" Operator-pending
7382 "i" Insert
7383 "c" Cmd-line
7384 "s" Select
7385 "x" Visual
7386 "t" Terminal-Job
7387 "" Normal, Visual and Operator-pending
7388 "!" Insert and Cmd-line
7389 When {mode} is omitted, the modes for "" are used.
7390
7391 Returns a |Dictionary| containing the following items:
7392 accel menu item accelerator text |menu-text|
7393 display display name (name without '&')
7394 enabled v:true if this menu item is enabled
7395 Refer to |:menu-enable|
7396 icon name of the icon file (for toolbar)
7397 |toolbar-icon|
7398 iconidx index of a built-in icon
7399 modes modes for which the menu is defined. In
7400 addition to the modes mentioned above, these
7401 characters will be used:
7402 " " Normal, Visual and Operator-pending
7403 name menu item name.
7404 noremenu v:true if the {rhs} of the menu item is not
7405 remappable else v:false.
7406 priority menu order priority |menu-priority|
7407 rhs right-hand-side of the menu item. The returned
7408 string has special characters translated like
7409 in the output of the ":menu" command listing.
7410 When the {rhs} of a menu item is empty, then
7411 "<Nop>" is returned.
7412 script v:true if script-local remapping of {rhs} is
7413 allowed else v:false. See |:menu-script|.
7414 shortcut shortcut key (character after '&' in
7415 the menu name) |menu-shortcut|
7416 silent v:true if the menu item is created
7417 with <silent> argument |:menu-silent|
7418 submenus |List| containing the names of
7419 all the submenus. Present only if the menu
7420 item has submenus.
7421
7422 Returns an empty dictionary if the menu item is not found.
7423
7424 Examples: >
Bram Moolenaarff781552020-03-19 20:37:11 +01007425 :echo menu_info('Edit.Cut')
7426 :echo menu_info('File.Save', 'n')
Bram Moolenaar0eabd4d2020-03-15 16:13:53 +01007427<
7428 Can also be used as a |method|: >
Bram Moolenaarff781552020-03-19 20:37:11 +01007429 GetMenuName()->menu_info('v')
Bram Moolenaar0eabd4d2020-03-15 16:13:53 +01007430
7431
Bram Moolenaarac92e252019-08-03 21:58:38 +02007432< *min()*
Bram Moolenaar690afe12017-01-28 18:34:47 +01007433min({expr}) Return the minimum value of all items in {expr}.
Bram Moolenaare46a4402020-06-30 20:38:27 +02007434 {expr} can be a |List| or a |Dictionary|. For a Dictionary,
Bram Moolenaar29634562020-01-09 21:46:04 +01007435 it returns the minimum of all values in the Dictionary.
7436 If {expr} is neither a List nor a Dictionary, or one of the
Bram Moolenaar690afe12017-01-28 18:34:47 +01007437 items in {expr} cannot be used as a Number this results in
Bram Moolenaarf8be4612017-06-23 20:52:40 +02007438 an error. An empty |List| or |Dictionary| results in zero.
Bram Moolenaar9588a0f2005-01-08 21:45:39 +00007439
Bram Moolenaarac92e252019-08-03 21:58:38 +02007440 Can also be used as a |method|: >
7441 mylist->min()
7442
7443< *mkdir()* *E739*
Bram Moolenaar26a60b42005-02-22 08:49:11 +00007444mkdir({name} [, {path} [, {prot}]])
7445 Create directory {name}.
Bram Moolenaar39536dd2019-01-29 22:58:21 +01007446
Bram Moolenaar26a60b42005-02-22 08:49:11 +00007447 If {path} is "p" then intermediate directories are created as
7448 necessary. Otherwise it must be "".
Bram Moolenaar39536dd2019-01-29 22:58:21 +01007449
Bram Moolenaar26a60b42005-02-22 08:49:11 +00007450 If {prot} is given it is used to set the protection bits of
7451 the new directory. The default is 0755 (rwxr-xr-x: r/w for
Bram Moolenaar58b85342016-08-14 19:54:54 +02007452 the user readable for others). Use 0700 to make it unreadable
Bram Moolenaared39e1d2008-08-09 17:55:22 +00007453 for others. This is only used for the last part of {name}.
7454 Thus if you create /tmp/foo/bar then /tmp/foo will be created
7455 with 0755.
7456 Example: >
7457 :call mkdir($HOME . "/tmp/foo/bar", "p", 0700)
Bram Moolenaar39536dd2019-01-29 22:58:21 +01007458
Bram Moolenaared39e1d2008-08-09 17:55:22 +00007459< This function is not available in the |sandbox|.
Bram Moolenaar39536dd2019-01-29 22:58:21 +01007460
Bram Moolenaar78a16b02018-04-14 13:51:55 +02007461 There is no error if the directory already exists and the "p"
Bram Moolenaar39536dd2019-01-29 22:58:21 +01007462 flag is passed (since patch 8.0.1708). However, without the
Bram Moolenaar10455d42019-11-21 15:36:18 +01007463 "p" option the call will fail.
Bram Moolenaar39536dd2019-01-29 22:58:21 +01007464
Bram Moolenaar10455d42019-11-21 15:36:18 +01007465 The function result is a Number, which is 1 if the call was
Bram Moolenaar39536dd2019-01-29 22:58:21 +01007466 successful or 0 if the directory creation failed or partly
7467 failed.
7468
Bram Moolenaar26a60b42005-02-22 08:49:11 +00007469 Not available on all systems. To check use: >
7470 :if exists("*mkdir")
Bram Moolenaara1449832019-09-01 20:16:52 +02007471
7472< Can also be used as a |method|: >
7473 GetName()->mkdir()
Bram Moolenaar26a60b42005-02-22 08:49:11 +00007474<
Bram Moolenaar071d4272004-06-13 20:20:40 +00007475 *mode()*
Bram Moolenaar446cb832008-06-24 21:56:24 +00007476mode([expr]) Return a string that indicates the current mode.
Bram Moolenaar05bb9532008-07-04 09:44:11 +00007477 If [expr] is supplied and it evaluates to a non-zero Number or
7478 a non-empty String (|non-zero-arg|), then the full mode is
Bram Moolenaare381d3d2016-07-07 14:50:41 +02007479 returned, otherwise only the first letter is returned.
Bram Moolenaar0e57dd82019-09-16 22:56:03 +02007480 Also see |state()|.
Bram Moolenaar446cb832008-06-24 21:56:24 +00007481
Bram Moolenaar612cc382018-07-29 15:34:26 +02007482 n Normal, Terminal-Normal
7483 no Operator-pending
Bram Moolenaar5976f8f2018-12-27 23:44:44 +01007484 nov Operator-pending (forced characterwise |o_v|)
7485 noV Operator-pending (forced linewise |o_V|)
7486 noCTRL-V Operator-pending (forced blockwise |o_CTRL-V|);
Bram Moolenaar5b69c222019-01-11 14:50:06 +01007487 CTRL-V is one character
Bram Moolenaar612cc382018-07-29 15:34:26 +02007488 niI Normal using |i_CTRL-O| in |Insert-mode|
7489 niR Normal using |i_CTRL-O| in |Replace-mode|
7490 niV Normal using |i_CTRL-O| in |Virtual-Replace-mode|
7491 v Visual by character
7492 V Visual by line
7493 CTRL-V Visual blockwise
7494 s Select by character
7495 S Select by line
7496 CTRL-S Select blockwise
7497 i Insert
7498 ic Insert mode completion |compl-generic|
7499 ix Insert mode |i_CTRL-X| completion
7500 R Replace |R|
7501 Rc Replace mode completion |compl-generic|
7502 Rv Virtual Replace |gR|
7503 Rx Replace mode |i_CTRL-X| completion
7504 c Command-line editing
7505 cv Vim Ex mode |gQ|
7506 ce Normal Ex mode |Q|
7507 r Hit-enter prompt
7508 rm The -- more -- prompt
7509 r? A |:confirm| query of some sort
7510 ! Shell or external command is executing
7511 t Terminal-Job mode: keys go to the job
Bram Moolenaar446cb832008-06-24 21:56:24 +00007512 This is useful in the 'statusline' option or when used
7513 with |remote_expr()| In most other places it always returns
7514 "c" or "n".
Bram Moolenaar612cc382018-07-29 15:34:26 +02007515 Note that in the future more modes and more specific modes may
7516 be added. It's better not to compare the whole string but only
7517 the leading character(s).
Bram Moolenaar446cb832008-06-24 21:56:24 +00007518 Also see |visualmode()|.
Bram Moolenaar071d4272004-06-13 20:20:40 +00007519
Bram Moolenaara1449832019-09-01 20:16:52 +02007520 Can also be used as a |method|: >
7521 DoFull()->mode()
7522
Bram Moolenaar7e506b62010-01-19 15:55:06 +01007523mzeval({expr}) *mzeval()*
7524 Evaluate MzScheme expression {expr} and return its result
Bram Moolenaard38b0552012-04-25 19:07:41 +02007525 converted to Vim data structures.
Bram Moolenaar7e506b62010-01-19 15:55:06 +01007526 Numbers and strings are returned as they are.
7527 Pairs (including lists and improper lists) and vectors are
7528 returned as Vim |Lists|.
7529 Hash tables are represented as Vim |Dictionary| type with keys
7530 converted to strings.
7531 All other types are converted to string with display function.
7532 Examples: >
7533 :mz (define l (list 1 2 3))
7534 :mz (define h (make-hash)) (hash-set! h "list" l)
7535 :echo mzeval("l")
7536 :echo mzeval("h")
7537<
Bram Moolenaara1449832019-09-01 20:16:52 +02007538 Can also be used as a |method|: >
7539 GetExpr()->mzeval()
7540<
Bram Moolenaar7e506b62010-01-19 15:55:06 +01007541 {only available when compiled with the |+mzscheme| feature}
7542
Bram Moolenaar071d4272004-06-13 20:20:40 +00007543nextnonblank({lnum}) *nextnonblank()*
7544 Return the line number of the first line at or below {lnum}
7545 that is not blank. Example: >
7546 if getline(nextnonblank(1)) =~ "Java"
7547< When {lnum} is invalid or there is no non-blank line at or
7548 below it, zero is returned.
7549 See also |prevnonblank()|.
7550
Bram Moolenaar3f4f3d82019-09-04 20:05:59 +02007551 Can also be used as a |method|: >
7552 GetLnum()->nextnonblank()
7553
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01007554nr2char({expr} [, {utf8}]) *nr2char()*
Bram Moolenaar071d4272004-06-13 20:20:40 +00007555 Return a string with a single character, which has the number
7556 value {expr}. Examples: >
7557 nr2char(64) returns "@"
7558 nr2char(32) returns " "
Bram Moolenaard35d7842013-01-23 17:17:10 +01007559< When {utf8} is omitted or zero, the current 'encoding' is used.
7560 Example for "utf-8": >
Bram Moolenaar071d4272004-06-13 20:20:40 +00007561 nr2char(300) returns I with bow character
Bram Moolenaard35d7842013-01-23 17:17:10 +01007562< With {utf8} set to 1, always return utf-8 characters.
7563 Note that a NUL character in the file is specified with
Bram Moolenaar071d4272004-06-13 20:20:40 +00007564 nr2char(10), because NULs are represented with newline
7565 characters. nr2char(0) is a real NUL and terminates the
Bram Moolenaar383f9bc2005-01-19 22:18:32 +00007566 string, thus results in an empty string.
Bram Moolenaaraff74912019-03-30 18:11:49 +01007567 To turn a list of character numbers into a string: >
7568 let list = [65, 66, 67]
7569 let str = join(map(list, {_, val -> nr2char(val)}), '')
7570< Result: "ABC"
Bram Moolenaar071d4272004-06-13 20:20:40 +00007571
Bram Moolenaar3f4f3d82019-09-04 20:05:59 +02007572 Can also be used as a |method|: >
7573 GetNumber()->nr2char()
Bram Moolenaar073e4b92019-08-18 23:01:56 +02007574
Bram Moolenaard6e256c2011-12-14 15:32:50 +01007575or({expr}, {expr}) *or()*
7576 Bitwise OR on the two arguments. The arguments are converted
7577 to a number. A List, Dict or Float argument causes an error.
7578 Example: >
7579 :let bits = or(bits, 0x80)
Bram Moolenaar073e4b92019-08-18 23:01:56 +02007580< Can also be used as a |method|: >
7581 :let bits = bits->or(0x80)
Bram Moolenaard6e256c2011-12-14 15:32:50 +01007582
7583
Bram Moolenaar910f66f2006-04-05 20:41:53 +00007584pathshorten({expr}) *pathshorten()*
7585 Shorten directory names in the path {expr} and return the
7586 result. The tail, the file name, is kept as-is. The other
7587 components in the path are reduced to single letters. Leading
7588 '~' and '.' characters are kept. Example: >
7589 :echo pathshorten('~/.vim/autoload/myfile.vim')
7590< ~/.v/a/myfile.vim ~
7591 It doesn't matter if the path exists or not.
7592
Bram Moolenaar3f4f3d82019-09-04 20:05:59 +02007593 Can also be used as a |method|: >
7594 GetDirectories()->pathshorten()
7595
Bram Moolenaare9b892e2016-01-17 21:15:58 +01007596perleval({expr}) *perleval()*
7597 Evaluate Perl expression {expr} in scalar context and return
7598 its result converted to Vim data structures. If value can't be
Bram Moolenaar85084ef2016-01-17 22:26:33 +01007599 converted, it is returned as a string Perl representation.
7600 Note: If you want an array or hash, {expr} must return a
7601 reference to it.
Bram Moolenaare9b892e2016-01-17 21:15:58 +01007602 Example: >
7603 :echo perleval('[1 .. 4]')
7604< [1, 2, 3, 4]
Bram Moolenaar3f4f3d82019-09-04 20:05:59 +02007605
7606 Can also be used as a |method|: >
7607 GetExpr()->perleval()
7608
7609< {only available when compiled with the |+perl| feature}
Bram Moolenaare9b892e2016-01-17 21:15:58 +01007610
Bram Moolenaar931a2772019-07-04 16:54:54 +02007611
Bram Moolenaar1c6737b2020-09-07 22:18:52 +02007612popup_ functions are documented here: |popup-functions|
Bram Moolenaar931a2772019-07-04 16:54:54 +02007613
7614
Bram Moolenaar446cb832008-06-24 21:56:24 +00007615pow({x}, {y}) *pow()*
7616 Return the power of {x} to the exponent {y} as a |Float|.
7617 {x} and {y} must evaluate to a |Float| or a |Number|.
7618 Examples: >
7619 :echo pow(3, 3)
7620< 27.0 >
7621 :echo pow(2, 16)
7622< 65536.0 >
7623 :echo pow(32, 0.20)
7624< 2.0
Bram Moolenaar93cf85f2019-08-17 21:36:28 +02007625
7626 Can also be used as a |method|: >
7627 Compute()->pow(3)
7628<
Bram Moolenaar446cb832008-06-24 21:56:24 +00007629 {only available when compiled with the |+float| feature}
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01007630
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00007631prevnonblank({lnum}) *prevnonblank()*
7632 Return the line number of the first line at or above {lnum}
7633 that is not blank. Example: >
7634 let ind = indent(prevnonblank(v:lnum - 1))
7635< When {lnum} is invalid or there is no non-blank line at or
7636 above it, zero is returned.
7637 Also see |nextnonblank()|.
7638
Bram Moolenaar3f4f3d82019-09-04 20:05:59 +02007639 Can also be used as a |method|: >
7640 GetLnum()->prevnonblank()
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00007641
Bram Moolenaar4be06f92005-07-29 22:36:03 +00007642printf({fmt}, {expr1} ...) *printf()*
7643 Return a String with {fmt}, where "%" items are replaced by
7644 the formatted form of their respective arguments. Example: >
Bram Moolenaar5a8684e2005-07-30 22:43:24 +00007645 printf("%4d: E%d %.30s", lnum, errno, msg)
Bram Moolenaar4be06f92005-07-29 22:36:03 +00007646< May result in:
Bram Moolenaar5a8684e2005-07-30 22:43:24 +00007647 " 99: E42 asdfasdfasdfasdfasdfasdfasdfas" ~
Bram Moolenaar4be06f92005-07-29 22:36:03 +00007648
Bram Moolenaarfd8ca212019-08-10 00:13:30 +02007649 When used as a |method| the base is passed as the second
7650 argument: >
7651 Compute()->printf("result: %d")
7652
7653< Often used items are:
Bram Moolenaarc9b4b052006-04-30 18:54:39 +00007654 %s string
Bram Moolenaar3ab72c52012-11-14 18:10:56 +01007655 %6S string right-aligned in 6 display cells
Bram Moolenaar98692072006-02-04 00:57:42 +00007656 %6s string right-aligned in 6 bytes
Bram Moolenaar446cb832008-06-24 21:56:24 +00007657 %.9s string truncated to 9 bytes
7658 %c single byte
7659 %d decimal number
7660 %5d decimal number padded with spaces to 5 characters
7661 %x hex number
7662 %04x hex number padded with zeros to at least 4 characters
7663 %X hex number using upper case letters
7664 %o octal number
Bram Moolenaar91984b92016-08-16 21:58:41 +02007665 %08b binary number padded with zeros to at least 8 chars
Bram Moolenaar04186092016-08-29 21:55:35 +02007666 %f floating point number as 12.23, inf, -inf or nan
7667 %F floating point number as 12.23, INF, -INF or NAN
7668 %e floating point number as 1.23e3, inf, -inf or nan
7669 %E floating point number as 1.23E3, INF, -INF or NAN
Bram Moolenaar446cb832008-06-24 21:56:24 +00007670 %g floating point number, as %f or %e depending on value
Bram Moolenaar3df01732017-02-17 22:47:16 +01007671 %G floating point number, as %F or %E depending on value
Bram Moolenaar446cb832008-06-24 21:56:24 +00007672 %% the % character itself
Bram Moolenaar4be06f92005-07-29 22:36:03 +00007673
7674 Conversion specifications start with '%' and end with the
7675 conversion type. All other characters are copied unchanged to
7676 the result.
7677
7678 The "%" starts a conversion specification. The following
Bram Moolenaar5a8684e2005-07-30 22:43:24 +00007679 arguments appear in sequence:
Bram Moolenaar4be06f92005-07-29 22:36:03 +00007680
Bram Moolenaar5a8684e2005-07-30 22:43:24 +00007681 % [flags] [field-width] [.precision] type
Bram Moolenaar4be06f92005-07-29 22:36:03 +00007682
Bram Moolenaarc9b4b052006-04-30 18:54:39 +00007683 flags
Bram Moolenaar5a8684e2005-07-30 22:43:24 +00007684 Zero or more of the following flags:
7685
Bram Moolenaar4be06f92005-07-29 22:36:03 +00007686 # The value should be converted to an "alternate
7687 form". For c, d, and s conversions, this option
7688 has no effect. For o conversions, the precision
7689 of the number is increased to force the first
7690 character of the output string to a zero (except
7691 if a zero value is printed with an explicit
7692 precision of zero).
Bram Moolenaar91984b92016-08-16 21:58:41 +02007693 For b and B conversions, a non-zero result has
7694 the string "0b" (or "0B" for B conversions)
7695 prepended to it.
Bram Moolenaar4be06f92005-07-29 22:36:03 +00007696 For x and X conversions, a non-zero result has
7697 the string "0x" (or "0X" for X conversions)
7698 prepended to it.
Bram Moolenaar5a8684e2005-07-30 22:43:24 +00007699
Bram Moolenaar4be06f92005-07-29 22:36:03 +00007700 0 (zero) Zero padding. For all conversions the converted
7701 value is padded on the left with zeros rather
7702 than blanks. If a precision is given with a
Bram Moolenaar91984b92016-08-16 21:58:41 +02007703 numeric conversion (d, b, B, o, x, and X), the 0
7704 flag is ignored.
Bram Moolenaar5a8684e2005-07-30 22:43:24 +00007705
Bram Moolenaar4be06f92005-07-29 22:36:03 +00007706 - A negative field width flag; the converted value
7707 is to be left adjusted on the field boundary.
7708 The converted value is padded on the right with
7709 blanks, rather than on the left with blanks or
7710 zeros. A - overrides a 0 if both are given.
Bram Moolenaar5a8684e2005-07-30 22:43:24 +00007711
Bram Moolenaar4be06f92005-07-29 22:36:03 +00007712 ' ' (space) A blank should be left before a positive
7713 number produced by a signed conversion (d).
Bram Moolenaar5a8684e2005-07-30 22:43:24 +00007714
Bram Moolenaar4be06f92005-07-29 22:36:03 +00007715 + A sign must always be placed before a number
Bram Moolenaar58b85342016-08-14 19:54:54 +02007716 produced by a signed conversion. A + overrides
Bram Moolenaar4be06f92005-07-29 22:36:03 +00007717 a space if both are used.
Bram Moolenaar5a8684e2005-07-30 22:43:24 +00007718
7719 field-width
7720 An optional decimal digit string specifying a minimum
Bram Moolenaar98692072006-02-04 00:57:42 +00007721 field width. If the converted value has fewer bytes
7722 than the field width, it will be padded with spaces on
7723 the left (or right, if the left-adjustment flag has
7724 been given) to fill out the field width.
Bram Moolenaar5a8684e2005-07-30 22:43:24 +00007725
7726 .precision
7727 An optional precision, in the form of a period '.'
7728 followed by an optional digit string. If the digit
7729 string is omitted, the precision is taken as zero.
7730 This gives the minimum number of digits to appear for
7731 d, o, x, and X conversions, or the maximum number of
Bram Moolenaar98692072006-02-04 00:57:42 +00007732 bytes to be printed from a string for s conversions.
Bram Moolenaar446cb832008-06-24 21:56:24 +00007733 For floating point it is the number of digits after
7734 the decimal point.
Bram Moolenaar5a8684e2005-07-30 22:43:24 +00007735
7736 type
7737 A character that specifies the type of conversion to
7738 be applied, see below.
7739
Bram Moolenaar4be06f92005-07-29 22:36:03 +00007740 A field width or precision, or both, may be indicated by an
7741 asterisk '*' instead of a digit string. In this case, a
Bram Moolenaar58b85342016-08-14 19:54:54 +02007742 Number argument supplies the field width or precision. A
Bram Moolenaar4be06f92005-07-29 22:36:03 +00007743 negative field width is treated as a left adjustment flag
7744 followed by a positive field width; a negative precision is
7745 treated as though it were missing. Example: >
Bram Moolenaar5a8684e2005-07-30 22:43:24 +00007746 :echo printf("%d: %.*s", nr, width, line)
Bram Moolenaar4be06f92005-07-29 22:36:03 +00007747< This limits the length of the text used from "line" to
Bram Moolenaar5a8684e2005-07-30 22:43:24 +00007748 "width" bytes.
Bram Moolenaar4be06f92005-07-29 22:36:03 +00007749
Bram Moolenaarc9b4b052006-04-30 18:54:39 +00007750 The conversion specifiers and their meanings are:
Bram Moolenaar5a8684e2005-07-30 22:43:24 +00007751
Bram Moolenaar91984b92016-08-16 21:58:41 +02007752 *printf-d* *printf-b* *printf-B* *printf-o*
7753 *printf-x* *printf-X*
7754 dbBoxX The Number argument is converted to signed decimal
7755 (d), unsigned binary (b and B), unsigned octal (o), or
7756 unsigned hexadecimal (x and X) notation. The letters
7757 "abcdef" are used for x conversions; the letters
7758 "ABCDEF" are used for X conversions.
Bram Moolenaar5a8684e2005-07-30 22:43:24 +00007759 The precision, if any, gives the minimum number of
7760 digits that must appear; if the converted value
7761 requires fewer digits, it is padded on the left with
7762 zeros.
7763 In no case does a non-existent or small field width
7764 cause truncation of a numeric field; if the result of
7765 a conversion is wider than the field width, the field
7766 is expanded to contain the conversion result.
Bram Moolenaar30567352016-08-27 21:25:44 +02007767 The 'h' modifier indicates the argument is 16 bits.
7768 The 'l' modifier indicates the argument is 32 bits.
7769 The 'L' modifier indicates the argument is 64 bits.
7770 Generally, these modifiers are not useful. They are
7771 ignored when type is known from the argument.
7772
7773 i alias for d
7774 D alias for ld
7775 U alias for lu
7776 O alias for lo
Bram Moolenaar5a8684e2005-07-30 22:43:24 +00007777
Bram Moolenaar446cb832008-06-24 21:56:24 +00007778 *printf-c*
Bram Moolenaar5a8684e2005-07-30 22:43:24 +00007779 c The Number argument is converted to a byte, and the
7780 resulting character is written.
7781
Bram Moolenaar446cb832008-06-24 21:56:24 +00007782 *printf-s*
Bram Moolenaar5a8684e2005-07-30 22:43:24 +00007783 s The text of the String argument is used. If a
7784 precision is specified, no more bytes than the number
7785 specified are used.
Bram Moolenaar7571d552016-08-18 22:54:46 +02007786 If the argument is not a String type, it is
7787 automatically converted to text with the same format
7788 as ":echo".
Bram Moolenaar0122c402015-02-03 19:13:34 +01007789 *printf-S*
Bram Moolenaar3ab72c52012-11-14 18:10:56 +01007790 S The text of the String argument is used. If a
7791 precision is specified, no more display cells than the
Bram Moolenaar4c92e752019-02-17 21:18:32 +01007792 number specified are used.
Bram Moolenaar5a8684e2005-07-30 22:43:24 +00007793
Bram Moolenaar446cb832008-06-24 21:56:24 +00007794 *printf-f* *E807*
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01007795 f F The Float argument is converted into a string of the
Bram Moolenaar446cb832008-06-24 21:56:24 +00007796 form 123.456. The precision specifies the number of
7797 digits after the decimal point. When the precision is
7798 zero the decimal point is omitted. When the precision
7799 is not specified 6 is used. A really big number
Bram Moolenaar04186092016-08-29 21:55:35 +02007800 (out of range or dividing by zero) results in "inf"
Bram Moolenaarf8be4612017-06-23 20:52:40 +02007801 or "-inf" with %f (INF or -INF with %F).
7802 "0.0 / 0.0" results in "nan" with %f (NAN with %F).
Bram Moolenaar446cb832008-06-24 21:56:24 +00007803 Example: >
7804 echo printf("%.2f", 12.115)
7805< 12.12
7806 Note that roundoff depends on the system libraries.
7807 Use |round()| when in doubt.
7808
7809 *printf-e* *printf-E*
7810 e E The Float argument is converted into a string of the
7811 form 1.234e+03 or 1.234E+03 when using 'E'. The
7812 precision specifies the number of digits after the
7813 decimal point, like with 'f'.
7814
7815 *printf-g* *printf-G*
7816 g G The Float argument is converted like with 'f' if the
7817 value is between 0.001 (inclusive) and 10000000.0
7818 (exclusive). Otherwise 'e' is used for 'g' and 'E'
7819 for 'G'. When no precision is specified superfluous
7820 zeroes and '+' signs are removed, except for the zero
7821 immediately after the decimal point. Thus 10000000.0
7822 results in 1.0e7.
7823
7824 *printf-%*
Bram Moolenaar4be06f92005-07-29 22:36:03 +00007825 % A '%' is written. No argument is converted. The
7826 complete conversion specification is "%%".
Bram Moolenaar4be06f92005-07-29 22:36:03 +00007827
Bram Moolenaarc236c162008-07-13 17:41:49 +00007828 When a Number argument is expected a String argument is also
7829 accepted and automatically converted.
7830 When a Float or String argument is expected a Number argument
7831 is also accepted and automatically converted.
7832 Any other argument type results in an error message.
Bram Moolenaar4be06f92005-07-29 22:36:03 +00007833
Bram Moolenaar83bab712005-08-01 21:58:57 +00007834 *E766* *E767*
Bram Moolenaar4be06f92005-07-29 22:36:03 +00007835 The number of {exprN} arguments must exactly match the number
7836 of "%" items. If there are not sufficient or too many
Bram Moolenaar5a8684e2005-07-30 22:43:24 +00007837 arguments an error is given. Up to 18 arguments can be used.
Bram Moolenaar4be06f92005-07-29 22:36:03 +00007838
7839
Bram Moolenaar077cc7a2020-09-04 16:35:35 +02007840prompt_getprompt({buf}) *prompt_getprompt()*
7841 Returns the effective prompt text for buffer {buf}. {buf} can
7842 be a buffer name or number. |prompt-buffer|.
7843
7844 If the buffer doesn't exist or isn't a prompt buffer, an empty
7845 string is returned.
7846
7847 Can also be used as a |method|: >
7848 GetBuffer()->prompt_getprompt()
7849
7850
Bram Moolenaarf2732452018-06-03 14:47:35 +02007851prompt_setcallback({buf}, {expr}) *prompt_setcallback()*
Bram Moolenaar0e5979a2018-06-17 19:36:33 +02007852 Set prompt callback for buffer {buf} to {expr}. When {expr}
7853 is an empty string the callback is removed. This has only
Bram Moolenaarf2732452018-06-03 14:47:35 +02007854 effect if {buf} has 'buftype' set to "prompt".
Bram Moolenaar0e5979a2018-06-17 19:36:33 +02007855
Bram Moolenaarf2732452018-06-03 14:47:35 +02007856 The callback is invoked when pressing Enter. The current
7857 buffer will always be the prompt buffer. A new line for a
7858 prompt is added before invoking the callback, thus the prompt
7859 for which the callback was invoked will be in the last but one
7860 line.
7861 If the callback wants to add text to the buffer, it must
7862 insert it above the last line, since that is where the current
7863 prompt is. This can also be done asynchronously.
7864 The callback is invoked with one argument, which is the text
7865 that was entered at the prompt. This can be an empty string
7866 if the user only typed Enter.
7867 Example: >
Bram Moolenaara8eee212019-08-24 22:14:58 +02007868 call prompt_setcallback(bufnr(), function('s:TextEntered'))
Bram Moolenaarf2732452018-06-03 14:47:35 +02007869 func s:TextEntered(text)
7870 if a:text == 'exit' || a:text == 'quit'
7871 stopinsert
7872 close
7873 else
7874 call append(line('$') - 1, 'Entered: "' . a:text . '"')
7875 " Reset 'modified' to allow the buffer to be closed.
7876 set nomodified
7877 endif
7878 endfunc
7879
Bram Moolenaar3f4f3d82019-09-04 20:05:59 +02007880< Can also be used as a |method|: >
7881 GetBuffer()->prompt_setcallback(callback)
7882
7883
Bram Moolenaar0e5979a2018-06-17 19:36:33 +02007884prompt_setinterrupt({buf}, {expr}) *prompt_setinterrupt()*
7885 Set a callback for buffer {buf} to {expr}. When {expr} is an
7886 empty string the callback is removed. This has only effect if
7887 {buf} has 'buftype' set to "prompt".
7888
7889 This callback will be invoked when pressing CTRL-C in Insert
7890 mode. Without setting a callback Vim will exit Insert mode,
7891 as in any buffer.
7892
Bram Moolenaar3f4f3d82019-09-04 20:05:59 +02007893 Can also be used as a |method|: >
7894 GetBuffer()->prompt_setinterrupt(callback)
7895
Bram Moolenaar0e5979a2018-06-17 19:36:33 +02007896prompt_setprompt({buf}, {text}) *prompt_setprompt()*
7897 Set prompt for buffer {buf} to {text}. You most likely want
7898 {text} to end in a space.
7899 The result is only visible if {buf} has 'buftype' set to
7900 "prompt". Example: >
Bram Moolenaara8eee212019-08-24 22:14:58 +02007901 call prompt_setprompt(bufnr(), 'command: ')
Bram Moolenaar98aefe72018-12-13 22:20:09 +01007902<
Bram Moolenaar3f4f3d82019-09-04 20:05:59 +02007903 Can also be used as a |method|: >
7904 GetBuffer()->prompt_setprompt('command: ')
7905
Bram Moolenaar077cc7a2020-09-04 16:35:35 +02007906prop_ functions are documented here: |text-prop-functions|
Bram Moolenaarf2732452018-06-03 14:47:35 +02007907
Bram Moolenaare9bd5722019-08-17 19:36:06 +02007908pum_getpos() *pum_getpos()*
7909 If the popup menu (see |ins-completion-menu|) is not visible,
7910 returns an empty |Dictionary|, otherwise, returns a
7911 |Dictionary| with the following keys:
7912 height nr of items visible
7913 width screen cells
7914 row top screen row (0 first row)
7915 col leftmost screen column (0 first col)
7916 size total nr of items
Bram Moolenaar96f45c02019-10-26 19:53:45 +02007917 scrollbar |TRUE| if scrollbar is visible
Bram Moolenaare9bd5722019-08-17 19:36:06 +02007918
7919 The values are the same as in |v:event| during
7920 |CompleteChanged|.
7921
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00007922pumvisible() *pumvisible()*
7923 Returns non-zero when the popup menu is visible, zero
7924 otherwise. See |ins-completion-menu|.
Bram Moolenaar87b5ca52006-03-04 21:55:31 +00007925 This can be used to avoid some things that would remove the
7926 popup menu.
Bram Moolenaar071d4272004-06-13 20:20:40 +00007927
Bram Moolenaar30b65812012-07-12 22:01:11 +02007928py3eval({expr}) *py3eval()*
7929 Evaluate Python expression {expr} and return its result
7930 converted to Vim data structures.
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01007931 Numbers and strings are returned as they are (strings are
7932 copied though, Unicode strings are additionally converted to
Bram Moolenaar30b65812012-07-12 22:01:11 +02007933 'encoding').
7934 Lists are represented as Vim |List| type.
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01007935 Dictionaries are represented as Vim |Dictionary| type with
Bram Moolenaar30b65812012-07-12 22:01:11 +02007936 keys converted to strings.
Bram Moolenaar3f4f3d82019-09-04 20:05:59 +02007937
7938 Can also be used as a |method|: >
7939 GetExpr()->py3eval()
7940
7941< {only available when compiled with the |+python3| feature}
Bram Moolenaar30b65812012-07-12 22:01:11 +02007942
7943 *E858* *E859*
7944pyeval({expr}) *pyeval()*
7945 Evaluate Python expression {expr} and return its result
7946 converted to Vim data structures.
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01007947 Numbers and strings are returned as they are (strings are
Bram Moolenaar30b65812012-07-12 22:01:11 +02007948 copied though).
7949 Lists are represented as Vim |List| type.
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01007950 Dictionaries are represented as Vim |Dictionary| type,
Bram Moolenaard09acef2012-09-21 14:54:30 +02007951 non-string keys result in error.
Bram Moolenaar3f4f3d82019-09-04 20:05:59 +02007952
7953 Can also be used as a |method|: >
7954 GetExpr()->pyeval()
7955
7956< {only available when compiled with the |+python| feature}
Bram Moolenaar30b65812012-07-12 22:01:11 +02007957
Bram Moolenaarf42dd3c2017-01-28 16:06:38 +01007958pyxeval({expr}) *pyxeval()*
7959 Evaluate Python expression {expr} and return its result
7960 converted to Vim data structures.
7961 Uses Python 2 or 3, see |python_x| and 'pyxversion'.
7962 See also: |pyeval()|, |py3eval()|
Bram Moolenaar3f4f3d82019-09-04 20:05:59 +02007963
7964 Can also be used as a |method|: >
7965 GetExpr()->pyxeval()
7966
7967< {only available when compiled with the |+python| or the
Bram Moolenaarf42dd3c2017-01-28 16:06:38 +01007968 |+python3| feature}
7969
Bram Moolenaar3a3a7232005-01-17 22:16:15 +00007970 *E726* *E727*
Bram Moolenaard8b02732005-01-14 21:48:43 +00007971range({expr} [, {max} [, {stride}]]) *range()*
Bram Moolenaar32466aa2006-02-24 23:53:04 +00007972 Returns a |List| with Numbers:
Bram Moolenaard8b02732005-01-14 21:48:43 +00007973 - If only {expr} is specified: [0, 1, ..., {expr} - 1]
7974 - If {max} is specified: [{expr}, {expr} + 1, ..., {max}]
7975 - If {stride} is specified: [{expr}, {expr} + {stride}, ...,
7976 {max}] (increasing {expr} with {stride} each time, not
7977 producing a value past {max}).
Bram Moolenaare7566042005-06-17 22:00:15 +00007978 When the maximum is one before the start the result is an
7979 empty list. When the maximum is more than one before the
7980 start this is an error.
Bram Moolenaard8b02732005-01-14 21:48:43 +00007981 Examples: >
Bram Moolenaarc9b4b052006-04-30 18:54:39 +00007982 range(4) " [0, 1, 2, 3]
Bram Moolenaard8b02732005-01-14 21:48:43 +00007983 range(2, 4) " [2, 3, 4]
7984 range(2, 9, 3) " [2, 5, 8]
Bram Moolenaarc9b4b052006-04-30 18:54:39 +00007985 range(2, -2, -1) " [2, 1, 0, -1, -2]
Bram Moolenaare7566042005-06-17 22:00:15 +00007986 range(0) " []
7987 range(2, 0) " error!
Bram Moolenaard8b02732005-01-14 21:48:43 +00007988<
Bram Moolenaara0d1fef2019-09-04 22:29:14 +02007989 Can also be used as a |method|: >
7990 GetExpr()->range()
7991<
Bram Moolenaar06b0b4b2019-11-25 15:40:55 +01007992
Bram Moolenaar2c7f8c52020-04-20 19:52:53 +02007993rand([{expr}]) *rand()* *random*
Bram Moolenaarf8c1f922019-11-28 22:13:14 +01007994 Return a pseudo-random Number generated with an xoshiro128**
Bram Moolenaar0c0734d2019-11-26 21:44:46 +01007995 algorithm using seed {expr}. The returned number is 32 bits,
7996 also on 64 bits systems, for consistency.
7997 {expr} can be initialized by |srand()| and will be updated by
7998 rand(). If {expr} is omitted, an internal seed value is used
7999 and updated.
Bram Moolenaar06b0b4b2019-11-25 15:40:55 +01008000
8001 Examples: >
8002 :echo rand()
8003 :let seed = srand()
8004 :echo rand(seed)
Bram Moolenaar0c0734d2019-11-26 21:44:46 +01008005 :echo rand(seed) % 16 " random number 0 - 15
Bram Moolenaar06b0b4b2019-11-25 15:40:55 +01008006<
Bram Moolenaar84cf6bd2020-06-16 20:03:43 +02008007readdir({directory} [, {expr} [, {dict}]]) *readdir()*
Bram Moolenaar543c9b12019-04-05 22:50:40 +02008008 Return a list with file and directory names in {directory}.
Bram Moolenaar62e1bb42019-04-08 16:25:07 +02008009 You can also use |glob()| if you don't need to do complicated
8010 things, such as limiting the number of matches.
Bram Moolenaar84cf6bd2020-06-16 20:03:43 +02008011 The list will be sorted (case sensitive), see the {dict}
8012 argument below for changing the sort order.
Bram Moolenaar543c9b12019-04-05 22:50:40 +02008013
8014 When {expr} is omitted all entries are included.
8015 When {expr} is given, it is evaluated to check what to do:
8016 If {expr} results in -1 then no further entries will
8017 be handled.
8018 If {expr} results in 0 then this entry will not be
8019 added to the list.
8020 If {expr} results in 1 then this entry will be added
8021 to the list.
Bram Moolenaar6c9ba042020-06-01 16:09:41 +02008022 The entries "." and ".." are always excluded.
Bram Moolenaar543c9b12019-04-05 22:50:40 +02008023 Each time {expr} is evaluated |v:val| is set to the entry name.
8024 When {expr} is a function the name is passed as the argument.
8025 For example, to get a list of files ending in ".txt": >
8026 readdir(dirname, {n -> n =~ '.txt$'})
8027< To skip hidden and backup files: >
8028 readdir(dirname, {n -> n !~ '^\.\|\~$'})
8029
Bram Moolenaar84cf6bd2020-06-16 20:03:43 +02008030< The optional {dict} argument allows for further custom
8031 values. Currently this is used to specify if and how sorting
8032 should be performed. The dict can have the following members:
8033
8034 sort How to sort the result returned from the system.
8035 Valid values are:
8036 "none" do not sort (fastest method)
8037 "case" sort case sensitive (byte value of
8038 each character, technically, using
8039 strcmp()) (default)
8040 "icase" sort case insensitive (technically
8041 using strcasecmp())
8042 "collate" sort using the collation order
8043 of the "POSIX" or "C" |locale|
8044 (technically using strcoll())
8045 Other values are silently ignored.
8046
8047 For example, to get a list of all files in the current
8048 directory without sorting the individual entries: >
8049 readdir('.', '1', #{sort: 'none'})
Bram Moolenaar543c9b12019-04-05 22:50:40 +02008050< If you want to get a directory tree: >
Bram Moolenaar84cf6bd2020-06-16 20:03:43 +02008051 function! s:tree(dir)
8052 return {a:dir : map(readdir(a:dir),
Bram Moolenaar543c9b12019-04-05 22:50:40 +02008053 \ {_, x -> isdirectory(x) ?
Bram Moolenaar84cf6bd2020-06-16 20:03:43 +02008054 \ {x : s:tree(a:dir . '/' . x)} : x})}
8055 endfunction
8056 echo s:tree(".")
Bram Moolenaar543c9b12019-04-05 22:50:40 +02008057<
Bram Moolenaara0d1fef2019-09-04 22:29:14 +02008058 Can also be used as a |method|: >
8059 GetDirName()->readdir()
8060<
Bram Moolenaar84cf6bd2020-06-16 20:03:43 +02008061readdirex({directory} [, {expr} [, {dict}]]) *readdirex()*
Bram Moolenaar6c9ba042020-06-01 16:09:41 +02008062 Extended version of |readdir()|.
8063 Return a list of Dictionaries with file and directory
8064 information in {directory}.
8065 This is useful if you want to get the attributes of file and
8066 directory at the same time as getting a list of a directory.
8067 This is much faster than calling |readdir()| then calling
8068 |getfperm()|, |getfsize()|, |getftime()| and |getftype()| for
8069 each file and directory especially on MS-Windows.
Bram Moolenaar84cf6bd2020-06-16 20:03:43 +02008070 The list will by default be sorted by name (case sensitive),
8071 the sorting can be changed by using the optional {dict}
8072 argument, see |readdir()|.
Bram Moolenaar6c9ba042020-06-01 16:09:41 +02008073
8074 The Dictionary for file and directory information has the
8075 following items:
8076 group Group name of the entry. (Only on Unix)
8077 name Name of the entry.
8078 perm Permissions of the entry. See |getfperm()|.
8079 size Size of the entry. See |getfsize()|.
8080 time Timestamp of the entry. See |getftime()|.
8081 type Type of the entry.
8082 On Unix, almost same as |getftype()| except:
8083 Symlink to a dir "linkd"
8084 Other symlink "link"
8085 On MS-Windows:
8086 Normal file "file"
8087 Directory "dir"
8088 Junction "junction"
8089 Symlink to a dir "linkd"
8090 Other symlink "link"
8091 Other reparse point "reparse"
8092 user User name of the entry's owner. (Only on Unix)
8093 On Unix, if the entry is a symlink, the Dictionary includes
8094 the information of the target (except the "type" item).
8095 On MS-Windows, it includes the information of the symlink
8096 itself because of performance reasons.
8097
8098 When {expr} is omitted all entries are included.
8099 When {expr} is given, it is evaluated to check what to do:
8100 If {expr} results in -1 then no further entries will
8101 be handled.
8102 If {expr} results in 0 then this entry will not be
8103 added to the list.
8104 If {expr} results in 1 then this entry will be added
8105 to the list.
8106 The entries "." and ".." are always excluded.
Bram Moolenaare46a4402020-06-30 20:38:27 +02008107 Each time {expr} is evaluated |v:val| is set to a |Dictionary|
Bram Moolenaar6c9ba042020-06-01 16:09:41 +02008108 of the entry.
8109 When {expr} is a function the entry is passed as the argument.
8110 For example, to get a list of files ending in ".txt": >
8111 readdirex(dirname, {e -> e.name =~ '.txt$'})
8112<
Bram Moolenaar84cf6bd2020-06-16 20:03:43 +02008113 For example, to get a list of all files in the current
8114 directory without sorting the individual entries: >
8115 readdirex(dirname, '1', #{sort: 'none'})
8116
8117<
Bram Moolenaar6c9ba042020-06-01 16:09:41 +02008118 Can also be used as a |method|: >
8119 GetDirName()->readdirex()
8120<
Bram Moolenaar3a7c85b2005-02-05 21:39:53 +00008121 *readfile()*
Bram Moolenaar6e5ea8d2019-01-12 22:47:31 +01008122readfile({fname} [, {type} [, {max}]])
Bram Moolenaar32466aa2006-02-24 23:53:04 +00008123 Read file {fname} and return a |List|, each line of the file
Bram Moolenaar6100d022016-10-02 16:51:57 +02008124 as an item. Lines are broken at NL characters. Macintosh
8125 files separated with CR will result in a single long line
8126 (unless a NL appears somewhere).
Bram Moolenaar06583f12010-08-07 20:30:49 +02008127 All NUL characters are replaced with a NL character.
Bram Moolenaar6e5ea8d2019-01-12 22:47:31 +01008128 When {type} contains "b" binary mode is used:
Bram Moolenaar3a7c85b2005-02-05 21:39:53 +00008129 - When the last line ends in a NL an extra empty list item is
8130 added.
8131 - No CR characters are removed.
Bram Moolenaar6e5ea8d2019-01-12 22:47:31 +01008132 When {type} contains "B" a |Blob| is returned with the binary
8133 data of the file unmodified.
Bram Moolenaar3a7c85b2005-02-05 21:39:53 +00008134 Otherwise:
8135 - CR characters that appear before a NL are removed.
8136 - Whether the last line ends in a NL or not does not matter.
Bram Moolenaar06583f12010-08-07 20:30:49 +02008137 - When 'encoding' is Unicode any UTF-8 byte order mark is
8138 removed from the text.
Bram Moolenaar26a60b42005-02-22 08:49:11 +00008139 When {max} is given this specifies the maximum number of lines
8140 to be read. Useful if you only want to check the first ten
8141 lines of a file: >
8142 :for line in readfile(fname, '', 10)
8143 : if line =~ 'Date' | echo line | endif
8144 :endfor
Bram Moolenaar582fd852005-03-28 20:58:01 +00008145< When {max} is negative -{max} lines from the end of the file
8146 are returned, or as many as there are.
8147 When {max} is zero the result is an empty list.
Bram Moolenaar26a60b42005-02-22 08:49:11 +00008148 Note that without {max} the whole file is read into memory.
8149 Also note that there is no recognition of encoding. Read a
8150 file into a buffer if you need to.
Bram Moolenaar3a7c85b2005-02-05 21:39:53 +00008151 When the file can't be opened an error message is given and
8152 the result is an empty list.
8153 Also see |writefile()|.
8154
Bram Moolenaara0d1fef2019-09-04 22:29:14 +02008155 Can also be used as a |method|: >
8156 GetFileName()->readfile()
8157
Bram Moolenaar85629982020-06-01 18:39:20 +02008158reduce({object}, {func} [, {initial}]) *reduce()* *E998*
8159 {func} is called for every item in {object}, which can be a
8160 |List| or a |Blob|. {func} is called with two arguments: the
8161 result so far and current item. After processing all items
8162 the result is returned.
8163
8164 {initial} is the initial result. When omitted, the first item
8165 in {object} is used and {func} is first called for the second
8166 item. If {initial} is not given and {object} is empty no
8167 result can be computed, an E998 error is given.
8168
8169 Examples: >
8170 echo reduce([1, 3, 5], { acc, val -> acc + val })
8171 echo reduce(['x', 'y'], { acc, val -> acc .. val }, 'a')
8172 echo reduce(0z1122, { acc, val -> 2 * acc + val })
8173<
8174 Can also be used as a |method|: >
8175 echo mylist->reduce({ acc, val -> acc + val }, 0)
8176
8177
Bram Moolenaar0b6d9112018-05-22 20:35:17 +02008178reg_executing() *reg_executing()*
8179 Returns the single letter name of the register being executed.
8180 Returns an empty string when no register is being executed.
8181 See |@|.
8182
8183reg_recording() *reg_recording()*
8184 Returns the single letter name of the register being recorded.
Bram Moolenaar62e1bb42019-04-08 16:25:07 +02008185 Returns an empty string when not recording. See |q|.
Bram Moolenaar0b6d9112018-05-22 20:35:17 +02008186
Bram Moolenaar433f7c82006-03-21 21:29:36 +00008187reltime([{start} [, {end}]]) *reltime()*
8188 Return an item that represents a time value. The format of
8189 the item depends on the system. It can be passed to
Bram Moolenaar03413f42016-04-12 21:07:15 +02008190 |reltimestr()| to convert it to a string or |reltimefloat()|
8191 to convert to a Float.
Bram Moolenaar433f7c82006-03-21 21:29:36 +00008192 Without an argument it returns the current time.
8193 With one argument is returns the time passed since the time
8194 specified in the argument.
Bram Moolenaar551dbcc2006-04-25 22:13:59 +00008195 With two arguments it returns the time passed between {start}
Bram Moolenaar433f7c82006-03-21 21:29:36 +00008196 and {end}.
8197 The {start} and {end} arguments must be values returned by
8198 reltime().
Bram Moolenaara0d1fef2019-09-04 22:29:14 +02008199
8200 Can also be used as a |method|: >
8201 GetStart()->reltime()
8202<
Bram Moolenaardb84e452010-08-15 13:50:43 +02008203 {only available when compiled with the |+reltime| feature}
Bram Moolenaar433f7c82006-03-21 21:29:36 +00008204
Bram Moolenaar03413f42016-04-12 21:07:15 +02008205reltimefloat({time}) *reltimefloat()*
8206 Return a Float that represents the time value of {time}.
8207 Example: >
8208 let start = reltime()
8209 call MyFunction()
8210 let seconds = reltimefloat(reltime(start))
8211< See the note of reltimestr() about overhead.
8212 Also see |profiling|.
Bram Moolenaara0d1fef2019-09-04 22:29:14 +02008213
8214 Can also be used as a |method|: >
8215 reltime(start)->reltimefloat()
8216
8217< {only available when compiled with the |+reltime| feature}
Bram Moolenaar03413f42016-04-12 21:07:15 +02008218
Bram Moolenaar433f7c82006-03-21 21:29:36 +00008219reltimestr({time}) *reltimestr()*
8220 Return a String that represents the time value of {time}.
8221 This is the number of seconds, a dot and the number of
8222 microseconds. Example: >
8223 let start = reltime()
8224 call MyFunction()
8225 echo reltimestr(reltime(start))
8226< Note that overhead for the commands will be added to the time.
8227 The accuracy depends on the system.
Bram Moolenaaref2f6562007-05-06 13:32:59 +00008228 Leading spaces are used to make the string align nicely. You
8229 can use split() to remove it. >
8230 echo split(reltimestr(reltime(start)))[0]
8231< Also see |profiling|.
Bram Moolenaara0d1fef2019-09-04 22:29:14 +02008232
8233 Can also be used as a |method|: >
8234 reltime(start)->reltimestr()
8235
8236< {only available when compiled with the |+reltime| feature}
Bram Moolenaar433f7c82006-03-21 21:29:36 +00008237
Bram Moolenaar071d4272004-06-13 20:20:40 +00008238 *remote_expr()* *E449*
Bram Moolenaar81b9d0b2017-03-19 21:20:53 +01008239remote_expr({server}, {string} [, {idvar} [, {timeout}]])
Bram Moolenaar58b85342016-08-14 19:54:54 +02008240 Send the {string} to {server}. The string is sent as an
Bram Moolenaar071d4272004-06-13 20:20:40 +00008241 expression and the result is returned after evaluation.
Bram Moolenaar362e1a32006-03-06 23:29:24 +00008242 The result must be a String or a |List|. A |List| is turned
8243 into a String by joining the items with a line break in
8244 between (not at the end), like with join(expr, "\n").
Bram Moolenaar81b9d0b2017-03-19 21:20:53 +01008245 If {idvar} is present and not empty, it is taken as the name
8246 of a variable and a {serverid} for later use with
Bram Moolenaar6bb2cdf2018-02-24 19:53:53 +01008247 |remote_read()| is stored there.
Bram Moolenaar81b9d0b2017-03-19 21:20:53 +01008248 If {timeout} is given the read times out after this many
8249 seconds. Otherwise a timeout of 600 seconds is used.
Bram Moolenaar071d4272004-06-13 20:20:40 +00008250 See also |clientserver| |RemoteReply|.
8251 This function is not available in the |sandbox|.
8252 {only available when compiled with the |+clientserver| feature}
8253 Note: Any errors will cause a local error message to be issued
8254 and the result will be the empty string.
Bram Moolenaar01164a62017-11-02 22:58:42 +01008255
8256 Variables will be evaluated in the global namespace,
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01008257 independent of a function currently being active. Except
Bram Moolenaar01164a62017-11-02 22:58:42 +01008258 when in debug mode, then local function variables and
8259 arguments can be evaluated.
8260
Bram Moolenaar071d4272004-06-13 20:20:40 +00008261 Examples: >
8262 :echo remote_expr("gvim", "2+2")
8263 :echo remote_expr("gvim1", "b:current_syntax")
8264<
Bram Moolenaara0d1fef2019-09-04 22:29:14 +02008265 Can also be used as a |method|: >
8266 ServerName()->remote_expr(expr)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008267
8268remote_foreground({server}) *remote_foreground()*
8269 Move the Vim server with the name {server} to the foreground.
8270 This works like: >
8271 remote_expr({server}, "foreground()")
8272< Except that on Win32 systems the client does the work, to work
8273 around the problem that the OS doesn't always allow the server
8274 to bring itself to the foreground.
Bram Moolenaar9372a112005-12-06 19:59:18 +00008275 Note: This does not restore the window if it was minimized,
8276 like foreground() does.
Bram Moolenaar071d4272004-06-13 20:20:40 +00008277 This function is not available in the |sandbox|.
Bram Moolenaara0d1fef2019-09-04 22:29:14 +02008278
8279 Can also be used as a |method|: >
8280 ServerName()->remote_foreground()
8281
8282< {only in the Win32, Athena, Motif and GTK GUI versions and the
Bram Moolenaar071d4272004-06-13 20:20:40 +00008283 Win32 console version}
8284
8285
8286remote_peek({serverid} [, {retvar}]) *remote_peek()*
8287 Returns a positive number if there are available strings
8288 from {serverid}. Copies any reply string into the variable
Bram Moolenaar58b85342016-08-14 19:54:54 +02008289 {retvar} if specified. {retvar} must be a string with the
Bram Moolenaar071d4272004-06-13 20:20:40 +00008290 name of a variable.
8291 Returns zero if none are available.
8292 Returns -1 if something is wrong.
8293 See also |clientserver|.
8294 This function is not available in the |sandbox|.
8295 {only available when compiled with the |+clientserver| feature}
8296 Examples: >
8297 :let repl = ""
8298 :echo "PEEK: ".remote_peek(id, "repl").": ".repl
8299
Bram Moolenaara0d1fef2019-09-04 22:29:14 +02008300< Can also be used as a |method|: >
8301 ServerId()->remote_peek()
8302
Bram Moolenaar81b9d0b2017-03-19 21:20:53 +01008303remote_read({serverid}, [{timeout}]) *remote_read()*
Bram Moolenaar071d4272004-06-13 20:20:40 +00008304 Return the oldest available reply from {serverid} and consume
Bram Moolenaar81b9d0b2017-03-19 21:20:53 +01008305 it. Unless a {timeout} in seconds is given, it blocks until a
8306 reply is available.
Bram Moolenaar071d4272004-06-13 20:20:40 +00008307 See also |clientserver|.
8308 This function is not available in the |sandbox|.
8309 {only available when compiled with the |+clientserver| feature}
8310 Example: >
8311 :echo remote_read(id)
Bram Moolenaara0d1fef2019-09-04 22:29:14 +02008312
8313< Can also be used as a |method|: >
8314 ServerId()->remote_read()
Bram Moolenaar071d4272004-06-13 20:20:40 +00008315<
8316 *remote_send()* *E241*
8317remote_send({server}, {string} [, {idvar}])
Bram Moolenaar58b85342016-08-14 19:54:54 +02008318 Send the {string} to {server}. The string is sent as input
Bram Moolenaard4755bb2004-09-02 19:12:26 +00008319 keys and the function returns immediately. At the Vim server
8320 the keys are not mapped |:map|.
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00008321 If {idvar} is present, it is taken as the name of a variable
8322 and a {serverid} for later use with remote_read() is stored
8323 there.
Bram Moolenaar071d4272004-06-13 20:20:40 +00008324 See also |clientserver| |RemoteReply|.
8325 This function is not available in the |sandbox|.
8326 {only available when compiled with the |+clientserver| feature}
Bram Moolenaar7416f3e2017-03-18 18:10:13 +01008327
Bram Moolenaar071d4272004-06-13 20:20:40 +00008328 Note: Any errors will be reported in the server and may mess
8329 up the display.
8330 Examples: >
8331 :echo remote_send("gvim", ":DropAndReply ".file, "serverid").
8332 \ remote_read(serverid)
8333
8334 :autocmd NONE RemoteReply *
8335 \ echo remote_read(expand("<amatch>"))
8336 :echo remote_send("gvim", ":sleep 10 | echo ".
8337 \ 'server2client(expand("<client>"), "HELLO")<CR>')
Bram Moolenaara14de3d2005-01-07 21:48:26 +00008338<
Bram Moolenaara0d1fef2019-09-04 22:29:14 +02008339 Can also be used as a |method|: >
8340 ServerName()->remote_send(keys)
8341<
Bram Moolenaar7416f3e2017-03-18 18:10:13 +01008342 *remote_startserver()* *E941* *E942*
8343remote_startserver({name})
8344 Become the server {name}. This fails if already running as a
8345 server, when |v:servername| is not empty.
Bram Moolenaara0d1fef2019-09-04 22:29:14 +02008346
8347 Can also be used as a |method|: >
8348 ServerName()->remote_startserver()
8349
8350< {only available when compiled with the |+clientserver| feature}
Bram Moolenaar7416f3e2017-03-18 18:10:13 +01008351
Bram Moolenaarde8866b2005-01-06 23:24:37 +00008352remove({list}, {idx} [, {end}]) *remove()*
Bram Moolenaar32466aa2006-02-24 23:53:04 +00008353 Without {end}: Remove the item at {idx} from |List| {list} and
Bram Moolenaar8f3f58f2010-01-06 20:52:26 +01008354 return the item.
Bram Moolenaarde8866b2005-01-06 23:24:37 +00008355 With {end}: Remove items from {idx} to {end} (inclusive) and
Bram Moolenaare46a4402020-06-30 20:38:27 +02008356 return a |List| with these items. When {idx} points to the same
Bram Moolenaarde8866b2005-01-06 23:24:37 +00008357 item as {end} a list with one item is returned. When {end}
8358 points to an item before {idx} this is an error.
8359 See |list-index| for possible values of {idx} and {end}.
Bram Moolenaard7ee7ce2005-01-03 21:02:03 +00008360 Example: >
8361 :echo "last item: " . remove(mylist, -1)
Bram Moolenaarde8866b2005-01-06 23:24:37 +00008362 :call remove(mylist, 0, 9)
Bram Moolenaar39536dd2019-01-29 22:58:21 +01008363<
8364 Use |delete()| to remove a file.
8365
Bram Moolenaarac92e252019-08-03 21:58:38 +02008366 Can also be used as a |method|: >
8367 mylist->remove(idx)
8368
Bram Moolenaar6e5ea8d2019-01-12 22:47:31 +01008369remove({blob}, {idx} [, {end}])
8370 Without {end}: Remove the byte at {idx} from |Blob| {blob} and
8371 return the byte.
8372 With {end}: Remove bytes from {idx} to {end} (inclusive) and
8373 return a |Blob| with these bytes. When {idx} points to the same
8374 byte as {end} a |Blob| with one byte is returned. When {end}
8375 points to a byte before {idx} this is an error.
8376 Example: >
8377 :echo "last byte: " . remove(myblob, -1)
8378 :call remove(mylist, 0, 9)
Bram Moolenaar39536dd2019-01-29 22:58:21 +01008379
Bram Moolenaard8b02732005-01-14 21:48:43 +00008380remove({dict}, {key})
Bram Moolenaar54775062019-07-31 21:07:14 +02008381 Remove the entry from {dict} with key {key} and return it.
8382 Example: >
Bram Moolenaard8b02732005-01-14 21:48:43 +00008383 :echo "removed " . remove(dict, "one")
8384< If there is no {key} in {dict} this is an error.
8385
Bram Moolenaar071d4272004-06-13 20:20:40 +00008386rename({from}, {to}) *rename()*
8387 Rename the file by the name {from} to the name {to}. This
8388 should also work to move files across file systems. The
8389 result is a Number, which is 0 if the file was renamed
8390 successfully, and non-zero when the renaming failed.
Bram Moolenaar798b30b2009-04-22 10:56:16 +00008391 NOTE: If {to} exists it is overwritten without warning.
Bram Moolenaar071d4272004-06-13 20:20:40 +00008392 This function is not available in the |sandbox|.
8393
Bram Moolenaara0d1fef2019-09-04 22:29:14 +02008394 Can also be used as a |method|: >
8395 GetOldName()->rename(newname)
8396
Bram Moolenaarab79bcb2004-07-18 21:34:53 +00008397repeat({expr}, {count}) *repeat()*
8398 Repeat {expr} {count} times and return the concatenated
8399 result. Example: >
Bram Moolenaar551dbcc2006-04-25 22:13:59 +00008400 :let separator = repeat('-', 80)
Bram Moolenaarab79bcb2004-07-18 21:34:53 +00008401< When {count} is zero or negative the result is empty.
Bram Moolenaar32466aa2006-02-24 23:53:04 +00008402 When {expr} is a |List| the result is {expr} concatenated
Bram Moolenaar58b85342016-08-14 19:54:54 +02008403 {count} times. Example: >
Bram Moolenaarde8866b2005-01-06 23:24:37 +00008404 :let longlist = repeat(['a', 'b'], 3)
8405< Results in ['a', 'b', 'a', 'b', 'a', 'b'].
Bram Moolenaarab79bcb2004-07-18 21:34:53 +00008406
Bram Moolenaarac92e252019-08-03 21:58:38 +02008407 Can also be used as a |method|: >
8408 mylist->repeat(count)
Bram Moolenaara14de3d2005-01-07 21:48:26 +00008409
Bram Moolenaar071d4272004-06-13 20:20:40 +00008410resolve({filename}) *resolve()* *E655*
8411 On MS-Windows, when {filename} is a shortcut (a .lnk file),
8412 returns the path the shortcut points to in a simplified form.
Bram Moolenaardce1e892019-02-10 23:18:53 +01008413 When {filename} is a symbolic link or junction point, return
8414 the full path to the target. If the target of junction is
8415 removed, return {filename}.
Bram Moolenaar071d4272004-06-13 20:20:40 +00008416 On Unix, repeat resolving symbolic links in all path
8417 components of {filename} and return the simplified result.
8418 To cope with link cycles, resolving of symbolic links is
8419 stopped after 100 iterations.
8420 On other systems, return the simplified {filename}.
8421 The simplification step is done as by |simplify()|.
8422 resolve() keeps a leading path component specifying the
8423 current directory (provided the result is still a relative
8424 path name) and also keeps a trailing path separator.
8425
Bram Moolenaara0d1fef2019-09-04 22:29:14 +02008426 Can also be used as a |method|: >
8427 GetName()->resolve()
Bram Moolenaarac92e252019-08-03 21:58:38 +02008428
8429reverse({object}) *reverse()*
Bram Moolenaar6e5ea8d2019-01-12 22:47:31 +01008430 Reverse the order of items in {object} in-place.
8431 {object} can be a |List| or a |Blob|.
8432 Returns {object}.
8433 If you want an object to remain unmodified make a copy first: >
Bram Moolenaara14de3d2005-01-07 21:48:26 +00008434 :let revlist = reverse(copy(mylist))
Bram Moolenaarac92e252019-08-03 21:58:38 +02008435< Can also be used as a |method|: >
8436 mylist->reverse()
Bram Moolenaara14de3d2005-01-07 21:48:26 +00008437
Bram Moolenaar446cb832008-06-24 21:56:24 +00008438round({expr}) *round()*
Bram Moolenaarc236c162008-07-13 17:41:49 +00008439 Round off {expr} to the nearest integral value and return it
Bram Moolenaar446cb832008-06-24 21:56:24 +00008440 as a |Float|. If {expr} lies halfway between two integral
8441 values, then use the larger one (away from zero).
8442 {expr} must evaluate to a |Float| or a |Number|.
8443 Examples: >
8444 echo round(0.456)
8445< 0.0 >
8446 echo round(4.5)
8447< 5.0 >
8448 echo round(-4.5)
8449< -5.0
Bram Moolenaar93cf85f2019-08-17 21:36:28 +02008450
8451 Can also be used as a |method|: >
8452 Compute()->round()
8453<
Bram Moolenaar446cb832008-06-24 21:56:24 +00008454 {only available when compiled with the |+float| feature}
Bram Moolenaar34feacb2012-12-05 19:01:43 +01008455
Bram Moolenaare99be0e2019-03-26 22:51:09 +01008456rubyeval({expr}) *rubyeval()*
8457 Evaluate Ruby expression {expr} and return its result
8458 converted to Vim data structures.
8459 Numbers, floats and strings are returned as they are (strings
8460 are copied though).
8461 Arrays are represented as Vim |List| type.
8462 Hashes are represented as Vim |Dictionary| type.
8463 Other objects are represented as strings resulted from their
8464 "Object#to_s" method.
Bram Moolenaara0d1fef2019-09-04 22:29:14 +02008465
8466 Can also be used as a |method|: >
8467 GetRubyExpr()->rubyeval()
8468
8469< {only available when compiled with the |+ruby| feature}
Bram Moolenaare99be0e2019-03-26 22:51:09 +01008470
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01008471screenattr({row}, {col}) *screenattr()*
Bram Moolenaar36f44c22016-08-28 18:17:20 +02008472 Like |screenchar()|, but return the attribute. This is a rather
Bram Moolenaar9a773482013-06-11 18:40:13 +02008473 arbitrary number that can only be used to compare to the
8474 attribute at other positions.
8475
Bram Moolenaar196b4662019-09-06 21:34:30 +02008476 Can also be used as a |method|: >
8477 GetRow()->screenattr(col)
8478
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01008479screenchar({row}, {col}) *screenchar()*
Bram Moolenaar9a773482013-06-11 18:40:13 +02008480 The result is a Number, which is the character at position
8481 [row, col] on the screen. This works for every possible
8482 screen position, also status lines, window separators and the
8483 command line. The top left position is row one, column one
8484 The character excludes composing characters. For double-byte
8485 encodings it may only be the first byte.
8486 This is mainly to be used for testing.
8487 Returns -1 when row or col is out of range.
8488
Bram Moolenaar196b4662019-09-06 21:34:30 +02008489 Can also be used as a |method|: >
8490 GetRow()->screenchar(col)
8491
Bram Moolenaar2912abb2019-03-29 14:16:42 +01008492screenchars({row}, {col}) *screenchars()*
Bram Moolenaare46a4402020-06-30 20:38:27 +02008493 The result is a |List| of Numbers. The first number is the same
Bram Moolenaar2912abb2019-03-29 14:16:42 +01008494 as what |screenchar()| returns. Further numbers are
8495 composing characters on top of the base character.
8496 This is mainly to be used for testing.
8497 Returns an empty List when row or col is out of range.
8498
Bram Moolenaar196b4662019-09-06 21:34:30 +02008499 Can also be used as a |method|: >
8500 GetRow()->screenchars(col)
8501
Bram Moolenaar34feacb2012-12-05 19:01:43 +01008502screencol() *screencol()*
8503 The result is a Number, which is the current screen column of
8504 the cursor. The leftmost column has number 1.
8505 This function is mainly used for testing.
8506
8507 Note: Always returns the current screen column, thus if used
8508 in a command (e.g. ":echo screencol()") it will return the
8509 column inside the command line, which is 1 when the command is
8510 executed. To get the cursor position in the file use one of
8511 the following mappings: >
8512 nnoremap <expr> GG ":echom ".screencol()."\n"
8513 nnoremap <silent> GG :echom screencol()<CR>
8514<
Bram Moolenaarb3d17a22019-07-07 18:28:14 +02008515screenpos({winid}, {lnum}, {col}) *screenpos()*
8516 The result is a Dict with the screen position of the text
8517 character in window {winid} at buffer line {lnum} and column
8518 {col}. {col} is a one-based byte index.
8519 The Dict has these members:
8520 row screen row
8521 col first screen column
8522 endcol last screen column
8523 curscol cursor screen column
8524 If the specified position is not visible, all values are zero.
8525 The "endcol" value differs from "col" when the character
8526 occupies more than one screen cell. E.g. for a Tab "col" can
8527 be 1 and "endcol" can be 8.
8528 The "curscol" value is where the cursor would be placed. For
8529 a Tab it would be the same as "endcol", while for a double
8530 width character it would be the same as "col".
8531
Bram Moolenaar196b4662019-09-06 21:34:30 +02008532 Can also be used as a |method|: >
8533 GetWinid()->screenpos(lnum, col)
8534
Bram Moolenaar34feacb2012-12-05 19:01:43 +01008535screenrow() *screenrow()*
8536 The result is a Number, which is the current screen row of the
8537 cursor. The top line has number one.
8538 This function is mainly used for testing.
Bram Moolenaar437bafe2016-08-01 15:40:54 +02008539 Alternatively you can use |winline()|.
Bram Moolenaar34feacb2012-12-05 19:01:43 +01008540
8541 Note: Same restrictions as with |screencol()|.
8542
Bram Moolenaar2912abb2019-03-29 14:16:42 +01008543screenstring({row}, {col}) *screenstring()*
8544 The result is a String that contains the base character and
8545 any composing characters at position [row, col] on the screen.
8546 This is like |screenchars()| but returning a String with the
8547 characters.
8548 This is mainly to be used for testing.
8549 Returns an empty String when row or col is out of range.
8550
Bram Moolenaar196b4662019-09-06 21:34:30 +02008551 Can also be used as a |method|: >
8552 GetRow()->screenstring(col)
Bram Moolenaaradc17a52020-06-06 18:37:51 +02008553<
8554 *search()*
8555search({pattern} [, {flags} [, {stopline} [, {timeout} [, {skip}]]]])
Bram Moolenaar071d4272004-06-13 20:20:40 +00008556 Search for regexp pattern {pattern}. The search starts at the
Bram Moolenaar383f9bc2005-01-19 22:18:32 +00008557 cursor position (you can use |cursor()| to set it).
Bram Moolenaar65c923a2006-03-03 22:56:30 +00008558
Bram Moolenaar2df58b42012-11-28 18:21:11 +01008559 When a match has been found its line number is returned.
Bram Moolenaarb8ff1fb2012-02-04 21:59:01 +01008560 If there is no match a 0 is returned and the cursor doesn't
8561 move. No error message is given.
Bram Moolenaarb8ff1fb2012-02-04 21:59:01 +01008562
Bram Moolenaar071d4272004-06-13 20:20:40 +00008563 {flags} is a String, which can contain these character flags:
Bram Moolenaarad4d8a12015-12-28 19:20:36 +01008564 'b' search Backward instead of forward
8565 'c' accept a match at the Cursor position
Bram Moolenaar87b5ca52006-03-04 21:55:31 +00008566 'e' move to the End of the match
Bram Moolenaar5eb86f92004-07-26 12:53:41 +00008567 'n' do Not move the cursor
Bram Moolenaarad4d8a12015-12-28 19:20:36 +01008568 'p' return number of matching sub-Pattern (see below)
8569 's' Set the ' mark at the previous location of the cursor
8570 'w' Wrap around the end of the file
8571 'W' don't Wrap around the end of the file
8572 'z' start searching at the cursor column instead of zero
Bram Moolenaar071d4272004-06-13 20:20:40 +00008573 If neither 'w' or 'W' is given, the 'wrapscan' option applies.
8574
Bram Moolenaar02743632005-07-25 20:42:36 +00008575 If the 's' flag is supplied, the ' mark is set, only if the
8576 cursor is moved. The 's' flag cannot be combined with the 'n'
8577 flag.
8578
Bram Moolenaaref2f6562007-05-06 13:32:59 +00008579 'ignorecase', 'smartcase' and 'magic' are used.
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01008580
Bram Moolenaar85084ef2016-01-17 22:26:33 +01008581 When the 'z' flag is not given, searching always starts in
Bram Moolenaarad4d8a12015-12-28 19:20:36 +01008582 column zero and then matches before the cursor are skipped.
8583 When the 'c' flag is present in 'cpo' the next search starts
8584 after the match. Without the 'c' flag the next search starts
8585 one column further.
Bram Moolenaaref2f6562007-05-06 13:32:59 +00008586
Bram Moolenaara23ccb82006-02-27 00:08:02 +00008587 When the {stopline} argument is given then the search stops
8588 after searching this line. This is useful to restrict the
8589 search to a range of lines. Examples: >
8590 let match = search('(', 'b', line("w0"))
8591 let end = search('END', '', line("w$"))
8592< When {stopline} is used and it is not zero this also implies
8593 that the search does not wrap around the end of the file.
Bram Moolenaar76929292008-01-06 19:07:36 +00008594 A zero value is equal to not giving the argument.
8595
8596 When the {timeout} argument is given the search stops when
Bram Moolenaar58b85342016-08-14 19:54:54 +02008597 more than this many milliseconds have passed. Thus when
Bram Moolenaar76929292008-01-06 19:07:36 +00008598 {timeout} is 500 the search stops after half a second.
8599 The value must not be negative. A zero value is like not
8600 giving the argument.
Bram Moolenaardb84e452010-08-15 13:50:43 +02008601 {only available when compiled with the |+reltime| feature}
Bram Moolenaara23ccb82006-02-27 00:08:02 +00008602
Bram Moolenaaradc17a52020-06-06 18:37:51 +02008603 If the {skip} expression is given it is evaluated with the
8604 cursor positioned on the start of a match. If it evaluates to
8605 non-zero this match is skipped. This can be used, for
8606 example, to skip a match in a comment or a string.
8607 {skip} can be a string, which is evaluated as an expression, a
8608 function reference or a lambda.
8609 When {skip} is omitted or empty, every match is accepted.
8610 When evaluating {skip} causes an error the search is aborted
8611 and -1 returned.
Bram Moolenaar362e1a32006-03-06 23:29:24 +00008612 *search()-sub-match*
8613 With the 'p' flag the returned value is one more than the
8614 first sub-match in \(\). One if none of them matched but the
8615 whole pattern did match.
Bram Moolenaara23ccb82006-02-27 00:08:02 +00008616 To get the column number too use |searchpos()|.
Bram Moolenaar071d4272004-06-13 20:20:40 +00008617
Bram Moolenaar87b5ca52006-03-04 21:55:31 +00008618 The cursor will be positioned at the match, unless the 'n'
8619 flag is used.
8620
Bram Moolenaar071d4272004-06-13 20:20:40 +00008621 Example (goes over all files in the argument list): >
8622 :let n = 1
8623 :while n <= argc() " loop over all files in arglist
8624 : exe "argument " . n
8625 : " start at the last char in the file and wrap for the
8626 : " first search to find match at start of file
8627 : normal G$
8628 : let flags = "w"
8629 : while search("foo", flags) > 0
Bram Moolenaar446cb832008-06-24 21:56:24 +00008630 : s/foo/bar/g
Bram Moolenaar071d4272004-06-13 20:20:40 +00008631 : let flags = "W"
8632 : endwhile
8633 : update " write the file if modified
8634 : let n = n + 1
8635 :endwhile
8636<
Bram Moolenaar87b5ca52006-03-04 21:55:31 +00008637 Example for using some flags: >
8638 :echo search('\<if\|\(else\)\|\(endif\)', 'ncpe')
8639< This will search for the keywords "if", "else", and "endif"
8640 under or after the cursor. Because of the 'p' flag, it
8641 returns 1, 2, or 3 depending on which keyword is found, or 0
8642 if the search fails. With the cursor on the first word of the
8643 line:
8644 if (foo == 0) | let foo = foo + 1 | endif ~
8645 the function returns 1. Without the 'c' flag, the function
8646 finds the "endif" and returns 3. The same thing happens
8647 without the 'e' flag if the cursor is on the "f" of "if".
8648 The 'n' flag tells the function not to move the cursor.
8649
Bram Moolenaar196b4662019-09-06 21:34:30 +02008650 Can also be used as a |method|: >
8651 GetPattern()->search()
Bram Moolenaar92d640f2005-09-05 22:11:52 +00008652
Bram Moolenaare8f5ec02020-06-01 17:28:35 +02008653searchcount([{options}]) *searchcount()*
8654 Get or update the last search count, like what is displayed
8655 without the "S" flag in 'shortmess'. This works even if
8656 'shortmess' does contain the "S" flag.
8657
Bram Moolenaare46a4402020-06-30 20:38:27 +02008658 This returns a |Dictionary|. The dictionary is empty if the
Bram Moolenaare8f5ec02020-06-01 17:28:35 +02008659 previous pattern was not set and "pattern" was not specified.
8660
8661 key type meaning ~
8662 current |Number| current position of match;
8663 0 if the cursor position is
8664 before the first match
8665 exact_match |Boolean| 1 if "current" is matched on
8666 "pos", otherwise 0
8667 total |Number| total count of matches found
8668 incomplete |Number| 0: search was fully completed
8669 1: recomputing was timed out
8670 2: max count exceeded
8671
8672 For {options} see further down.
8673
8674 To get the last search count when |n| or |N| was pressed, call
8675 this function with `recompute: 0` . This sometimes returns
8676 wrong information because |n| and |N|'s maximum count is 99.
8677 If it exceeded 99 the result must be max count + 1 (100). If
8678 you want to get correct information, specify `recompute: 1`: >
8679
8680 " result == maxcount + 1 (100) when many matches
8681 let result = searchcount(#{recompute: 0})
8682
8683 " Below returns correct result (recompute defaults
8684 " to 1)
8685 let result = searchcount()
8686<
8687 The function is useful to add the count to |statusline|: >
8688 function! LastSearchCount() abort
8689 let result = searchcount(#{recompute: 0})
8690 if empty(result)
8691 return ''
8692 endif
8693 if result.incomplete ==# 1 " timed out
8694 return printf(' /%s [?/??]', @/)
8695 elseif result.incomplete ==# 2 " max count exceeded
8696 if result.total > result.maxcount &&
8697 \ result.current > result.maxcount
8698 return printf(' /%s [>%d/>%d]', @/,
Bram Moolenaar73fef332020-06-21 22:12:03 +02008699 \ result.current, result.total)
Bram Moolenaare8f5ec02020-06-01 17:28:35 +02008700 elseif result.total > result.maxcount
8701 return printf(' /%s [%d/>%d]', @/,
Bram Moolenaar73fef332020-06-21 22:12:03 +02008702 \ result.current, result.total)
Bram Moolenaare8f5ec02020-06-01 17:28:35 +02008703 endif
8704 endif
8705 return printf(' /%s [%d/%d]', @/,
Bram Moolenaar73fef332020-06-21 22:12:03 +02008706 \ result.current, result.total)
Bram Moolenaare8f5ec02020-06-01 17:28:35 +02008707 endfunction
8708 let &statusline .= '%{LastSearchCount()}'
8709
8710 " Or if you want to show the count only when
8711 " 'hlsearch' was on
8712 " let &statusline .=
8713 " \ '%{v:hlsearch ? LastSearchCount() : ""}'
8714<
8715 You can also update the search count, which can be useful in a
8716 |CursorMoved| or |CursorMovedI| autocommand: >
8717
8718 autocmd CursorMoved,CursorMovedI *
8719 \ let s:searchcount_timer = timer_start(
8720 \ 200, function('s:update_searchcount'))
8721 function! s:update_searchcount(timer) abort
8722 if a:timer ==# s:searchcount_timer
8723 call searchcount(#{
8724 \ recompute: 1, maxcount: 0, timeout: 100})
8725 redrawstatus
8726 endif
8727 endfunction
8728<
8729 This can also be used to count matched texts with specified
8730 pattern in the current buffer using "pattern": >
8731
8732 " Count '\<foo\>' in this buffer
8733 " (Note that it also updates search count)
8734 let result = searchcount(#{pattern: '\<foo\>'})
8735
8736 " To restore old search count by old pattern,
8737 " search again
8738 call searchcount()
8739<
Bram Moolenaare46a4402020-06-30 20:38:27 +02008740 {options} must be a |Dictionary|. It can contain:
Bram Moolenaare8f5ec02020-06-01 17:28:35 +02008741 key type meaning ~
8742 recompute |Boolean| if |TRUE|, recompute the count
8743 like |n| or |N| was executed.
8744 otherwise returns the last
Bram Moolenaarebacddb2020-06-04 15:22:21 +02008745 computed result (when |n| or
8746 |N| was used when "S" is not
8747 in 'shortmess', or this
8748 function was called).
Bram Moolenaare8f5ec02020-06-01 17:28:35 +02008749 (default: |TRUE|)
8750 pattern |String| recompute if this was given
8751 and different with |@/|.
8752 this works as same as the
8753 below command is executed
8754 before calling this function >
8755 let @/ = pattern
8756< (default: |@/|)
8757 timeout |Number| 0 or negative number is no
8758 timeout. timeout milliseconds
8759 for recomputing the result
8760 (default: 0)
8761 maxcount |Number| 0 or negative number is no
8762 limit. max count of matched
8763 text while recomputing the
8764 result. if search exceeded
8765 total count, "total" value
8766 becomes `maxcount + 1`
8767 (default: 0)
8768 pos |List| `[lnum, col, off]` value
8769 when recomputing the result.
8770 this changes "current" result
Bram Moolenaare7b1ea02020-08-07 19:54:59 +02008771 value. see |cursor()|,
8772 |getpos()|
Bram Moolenaare8f5ec02020-06-01 17:28:35 +02008773 (default: cursor's position)
8774
8775
Bram Moolenaarf75a9632005-09-13 21:20:47 +00008776searchdecl({name} [, {global} [, {thisblock}]]) *searchdecl()*
8777 Search for the declaration of {name}.
Bram Moolenaarc9b4b052006-04-30 18:54:39 +00008778
Bram Moolenaarf75a9632005-09-13 21:20:47 +00008779 With a non-zero {global} argument it works like |gD|, find
8780 first match in the file. Otherwise it works like |gd|, find
8781 first match in the function.
8782
8783 With a non-zero {thisblock} argument matches in a {} block
8784 that ends before the cursor position are ignored. Avoids
8785 finding variable declarations only valid in another scope.
8786
Bram Moolenaar92d640f2005-09-05 22:11:52 +00008787 Moves the cursor to the found match.
8788 Returns zero for success, non-zero for failure.
8789 Example: >
8790 if searchdecl('myvar') == 0
8791 echo getline('.')
8792 endif
8793<
Bram Moolenaar196b4662019-09-06 21:34:30 +02008794 Can also be used as a |method|: >
8795 GetName()->searchdecl()
8796<
Bram Moolenaar071d4272004-06-13 20:20:40 +00008797 *searchpair()*
Bram Moolenaar76929292008-01-06 19:07:36 +00008798searchpair({start}, {middle}, {end} [, {flags} [, {skip}
8799 [, {stopline} [, {timeout}]]]])
Bram Moolenaar071d4272004-06-13 20:20:40 +00008800 Search for the match of a nested start-end pair. This can be
8801 used to find the "endif" that matches an "if", while other
8802 if/endif pairs in between are ignored.
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00008803 The search starts at the cursor. The default is to search
8804 forward, include 'b' in {flags} to search backward.
8805 If a match is found, the cursor is positioned at it and the
8806 line number is returned. If no match is found 0 or -1 is
8807 returned and the cursor doesn't move. No error message is
8808 given.
Bram Moolenaar071d4272004-06-13 20:20:40 +00008809
8810 {start}, {middle} and {end} are patterns, see |pattern|. They
8811 must not contain \( \) pairs. Use of \%( \) is allowed. When
8812 {middle} is not empty, it is found when searching from either
8813 direction, but only when not in a nested start-end pair. A
8814 typical use is: >
8815 searchpair('\<if\>', '\<else\>', '\<endif\>')
8816< By leaving {middle} empty the "else" is skipped.
8817
Bram Moolenaar87b5ca52006-03-04 21:55:31 +00008818 {flags} 'b', 'c', 'n', 's', 'w' and 'W' are used like with
8819 |search()|. Additionally:
Bram Moolenaar071d4272004-06-13 20:20:40 +00008820 'r' Repeat until no more matches found; will find the
Bram Moolenaar446cb832008-06-24 21:56:24 +00008821 outer pair. Implies the 'W' flag.
8822 'm' Return number of matches instead of line number with
Bram Moolenaar87b5ca52006-03-04 21:55:31 +00008823 the match; will be > 1 when 'r' is used.
Bram Moolenaar446cb832008-06-24 21:56:24 +00008824 Note: it's nearly always a good idea to use the 'W' flag, to
8825 avoid wrapping around the end of the file.
Bram Moolenaar071d4272004-06-13 20:20:40 +00008826
8827 When a match for {start}, {middle} or {end} is found, the
8828 {skip} expression is evaluated with the cursor positioned on
8829 the start of the match. It should return non-zero if this
8830 match is to be skipped. E.g., because it is inside a comment
8831 or a string.
8832 When {skip} is omitted or empty, every match is accepted.
8833 When evaluating {skip} causes an error the search is aborted
8834 and -1 returned.
Bram Moolenaar48570482017-10-30 21:48:41 +01008835 {skip} can be a string, a lambda, a funcref or a partial.
Bram Moolenaar675e8d62018-06-24 20:42:01 +02008836 Anything else makes the function fail.
Bram Moolenaar071d4272004-06-13 20:20:40 +00008837
Bram Moolenaar76929292008-01-06 19:07:36 +00008838 For {stopline} and {timeout} see |search()|.
Bram Moolenaara23ccb82006-02-27 00:08:02 +00008839
Bram Moolenaar071d4272004-06-13 20:20:40 +00008840 The value of 'ignorecase' is used. 'magic' is ignored, the
8841 patterns are used like it's on.
8842
8843 The search starts exactly at the cursor. A match with
8844 {start}, {middle} or {end} at the next character, in the
8845 direction of searching, is the first one found. Example: >
8846 if 1
8847 if 2
8848 endif 2
8849 endif 1
8850< When starting at the "if 2", with the cursor on the "i", and
8851 searching forwards, the "endif 2" is found. When starting on
8852 the character just before the "if 2", the "endif 1" will be
Bram Moolenaar58b85342016-08-14 19:54:54 +02008853 found. That's because the "if 2" will be found first, and
Bram Moolenaar071d4272004-06-13 20:20:40 +00008854 then this is considered to be a nested if/endif from "if 2" to
8855 "endif 2".
8856 When searching backwards and {end} is more than one character,
8857 it may be useful to put "\zs" at the end of the pattern, so
8858 that when the cursor is inside a match with the end it finds
8859 the matching start.
8860
8861 Example, to find the "endif" command in a Vim script: >
8862
8863 :echo searchpair('\<if\>', '\<el\%[seif]\>', '\<en\%[dif]\>', 'W',
8864 \ 'getline(".") =~ "^\\s*\""')
8865
8866< The cursor must be at or after the "if" for which a match is
8867 to be found. Note that single-quote strings are used to avoid
8868 having to double the backslashes. The skip expression only
8869 catches comments at the start of a line, not after a command.
8870 Also, a word "en" or "if" halfway a line is considered a
8871 match.
8872 Another example, to search for the matching "{" of a "}": >
8873
8874 :echo searchpair('{', '', '}', 'bW')
8875
8876< This works when the cursor is at or before the "}" for which a
8877 match is to be found. To reject matches that syntax
8878 highlighting recognized as strings: >
8879
8880 :echo searchpair('{', '', '}', 'bW',
8881 \ 'synIDattr(synID(line("."), col("."), 0), "name") =~? "string"')
8882<
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00008883 *searchpairpos()*
Bram Moolenaar76929292008-01-06 19:07:36 +00008884searchpairpos({start}, {middle}, {end} [, {flags} [, {skip}
8885 [, {stopline} [, {timeout}]]]])
Bram Moolenaar8f3f58f2010-01-06 20:52:26 +01008886 Same as |searchpair()|, but returns a |List| with the line and
Bram Moolenaar32466aa2006-02-24 23:53:04 +00008887 column position of the match. The first element of the |List|
8888 is the line number and the second element is the byte index of
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00008889 the column position of the match. If no match is found,
Bram Moolenaar9855d6b2010-07-18 14:34:51 +02008890 returns [0, 0]. >
8891
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00008892 :let [lnum,col] = searchpairpos('{', '', '}', 'n')
8893<
8894 See |match-parens| for a bigger and more useful example.
8895
Bram Moolenaaradc17a52020-06-06 18:37:51 +02008896 *searchpos()*
8897searchpos({pattern} [, {flags} [, {stopline} [, {timeout} [, {skip}]]]])
Bram Moolenaara23ccb82006-02-27 00:08:02 +00008898 Same as |search()|, but returns a |List| with the line and
Bram Moolenaar32466aa2006-02-24 23:53:04 +00008899 column position of the match. The first element of the |List|
8900 is the line number and the second element is the byte index of
8901 the column position of the match. If no match is found,
8902 returns [0, 0].
Bram Moolenaar362e1a32006-03-06 23:29:24 +00008903 Example: >
8904 :let [lnum, col] = searchpos('mypattern', 'n')
8905
8906< When the 'p' flag is given then there is an extra item with
8907 the sub-pattern match number |search()-sub-match|. Example: >
8908 :let [lnum, col, submatch] = searchpos('\(\l\)\|\(\u\)', 'np')
8909< In this example "submatch" is 2 when a lowercase letter is
8910 found |/\l|, 3 when an uppercase letter is found |/\u|.
8911
Bram Moolenaar196b4662019-09-06 21:34:30 +02008912 Can also be used as a |method|: >
8913 GetPattern()->searchpos()
8914
Bram Moolenaar81edd172016-04-14 13:51:37 +02008915server2client({clientid}, {string}) *server2client()*
Bram Moolenaar071d4272004-06-13 20:20:40 +00008916 Send a reply string to {clientid}. The most recent {clientid}
8917 that sent a string can be retrieved with expand("<client>").
8918 {only available when compiled with the |+clientserver| feature}
8919 Note:
8920 This id has to be stored before the next command can be
Bram Moolenaar402d2fe2005-04-15 21:00:38 +00008921 received. I.e. before returning from the received command and
Bram Moolenaar071d4272004-06-13 20:20:40 +00008922 before calling any commands that waits for input.
8923 See also |clientserver|.
8924 Example: >
8925 :echo server2client(expand("<client>"), "HELLO")
Bram Moolenaar196b4662019-09-06 21:34:30 +02008926
8927< Can also be used as a |method|: >
8928 GetClientId()->server2client(string)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008929<
8930serverlist() *serverlist()*
8931 Return a list of available server names, one per line.
8932 When there are no servers or the information is not available
8933 an empty string is returned. See also |clientserver|.
8934 {only available when compiled with the |+clientserver| feature}
8935 Example: >
8936 :echo serverlist()
8937<
Bram Moolenaarb31cf2b2017-09-02 19:45:19 +02008938setbufline({expr}, {lnum}, {text}) *setbufline()*
Bram Moolenaar2e693a82019-10-16 22:35:02 +02008939 Set line {lnum} to {text} in buffer {expr}. This works like
8940 |setline()| for the specified buffer.
8941
8942 This function works only for loaded buffers. First call
8943 |bufload()| if needed.
8944
8945 To insert lines use |appendbufline()|.
8946 Any text properties in {lnum} are cleared.
8947
8948 {text} can be a string to set one line, or a list of strings
8949 to set multiple lines. If the list extends below the last
8950 line then those lines are added.
Bram Moolenaarb31cf2b2017-09-02 19:45:19 +02008951
8952 For the use of {expr}, see |bufname()| above.
8953
8954 {lnum} is used like with |setline()|.
Bram Moolenaar2e693a82019-10-16 22:35:02 +02008955 When {lnum} is just below the last line the {text} will be
8956 added below the last line.
Bram Moolenaarb31cf2b2017-09-02 19:45:19 +02008957
Bram Moolenaar6bf2c622019-07-04 17:12:09 +02008958 When {expr} is not a valid buffer, the buffer is not loaded or
8959 {lnum} is not valid then 1 is returned. On success 0 is
8960 returned.
Bram Moolenaarb31cf2b2017-09-02 19:45:19 +02008961
Bram Moolenaar2e693a82019-10-16 22:35:02 +02008962 Can also be used as a |method|, the base is passed as the
8963 third argument: >
Bram Moolenaar196b4662019-09-06 21:34:30 +02008964 GetText()->setbufline(buf, lnum)
8965
Bram Moolenaar071d4272004-06-13 20:20:40 +00008966setbufvar({expr}, {varname}, {val}) *setbufvar()*
8967 Set option or local variable {varname} in buffer {expr} to
8968 {val}.
8969 This also works for a global or local window option, but it
8970 doesn't work for a global or local window variable.
8971 For a local window option the global value is unchanged.
8972 For the use of {expr}, see |bufname()| above.
8973 Note that the variable name without "b:" must be used.
8974 Examples: >
8975 :call setbufvar(1, "&mod", 1)
8976 :call setbufvar("todo", "myvar", "foobar")
8977< This function is not available in the |sandbox|.
8978
Bram Moolenaar2e693a82019-10-16 22:35:02 +02008979 Can also be used as a |method|, the base is passed as the
8980 third argument: >
Bram Moolenaar196b4662019-09-06 21:34:30 +02008981 GetValue()->setbufvar(buf, varname)
8982
Bram Moolenaar08aac3c2020-08-28 21:04:24 +02008983
8984setcellwidths({list}) *setcellwidths()*
8985 Specify overrides for cell widths of character ranges. This
8986 tells Vim how wide characters are, counted in screen cells.
8987 This overrides 'ambiwidth'. Example: >
8988 setcellwidths([[0xad, 0xad, 1],
Bram Moolenaar207f0092020-08-30 17:20:20 +02008989 \ [0x2194, 0x2199, 2]])
Bram Moolenaar08aac3c2020-08-28 21:04:24 +02008990
8991< *E1109* *E1110* *E1111* *E1112* *E1113*
8992 The {list} argument is a list of lists with each three
8993 numbers. These three numbers are [low, high, width]. "low"
8994 and "high" can be the same, in which case this refers to one
8995 character. Otherwise it is the range of characters from "low"
8996 to "high" (inclusive). "width" is either 1 or 2, indicating
8997 the character width in screen cells.
8998 An error is given if the argument is invalid, also when a
8999 range overlaps with another.
9000 Only characters with value 0x100 and higher can be used.
9001
9002 To clear the overrides pass an empty list: >
9003 setcellwidths([]);
Bram Moolenaar207f0092020-08-30 17:20:20 +02009004< You can use the script $VIMRUNTIME/tools/emoji_list.vim to see
9005 the effect for known emoji characters.
Bram Moolenaar08aac3c2020-08-28 21:04:24 +02009006
9007
Bram Moolenaar12969c02015-09-08 23:36:10 +02009008setcharsearch({dict}) *setcharsearch()*
Bram Moolenaardbd24b52015-08-11 14:26:19 +02009009 Set the current character search information to {dict},
9010 which contains one or more of the following entries:
9011
9012 char character which will be used for a subsequent
9013 |,| or |;| command; an empty string clears the
9014 character search
9015 forward direction of character search; 1 for forward,
9016 0 for backward
9017 until type of character search; 1 for a |t| or |T|
9018 character search, 0 for an |f| or |F|
9019 character search
9020
9021 This can be useful to save/restore a user's character search
9022 from a script: >
9023 :let prevsearch = getcharsearch()
9024 :" Perform a command which clobbers user's search
9025 :call setcharsearch(prevsearch)
9026< Also see |getcharsearch()|.
9027
Bram Moolenaar196b4662019-09-06 21:34:30 +02009028 Can also be used as a |method|: >
9029 SavedSearch()->setcharsearch()
9030
Bram Moolenaar071d4272004-06-13 20:20:40 +00009031setcmdpos({pos}) *setcmdpos()*
9032 Set the cursor position in the command line to byte position
Bram Moolenaar58b85342016-08-14 19:54:54 +02009033 {pos}. The first position is 1.
Bram Moolenaar071d4272004-06-13 20:20:40 +00009034 Use |getcmdpos()| to obtain the current position.
9035 Only works while editing the command line, thus you must use
Bram Moolenaard8b02732005-01-14 21:48:43 +00009036 |c_CTRL-\_e|, |c_CTRL-R_=| or |c_CTRL-R_CTRL-R| with '='. For
9037 |c_CTRL-\_e| and |c_CTRL-R_CTRL-R| with '=' the position is
9038 set after the command line is set to the expression. For
9039 |c_CTRL-R_=| it is set after evaluating the expression but
9040 before inserting the resulting text.
Bram Moolenaar071d4272004-06-13 20:20:40 +00009041 When the number is too big the cursor is put at the end of the
9042 line. A number smaller than one has undefined results.
9043 Returns 0 when successful, 1 when not editing the command
9044 line.
9045
Bram Moolenaar196b4662019-09-06 21:34:30 +02009046 Can also be used as a |method|: >
9047 GetPos()->setcmdpos()
9048
Bram Moolenaar691ddee2019-05-09 14:52:41 +02009049setenv({name}, {val}) *setenv()*
9050 Set environment variable {name} to {val}.
9051 When {val} is |v:null| the environment variable is deleted.
9052 See also |expr-env|.
9053
Bram Moolenaar2e693a82019-10-16 22:35:02 +02009054 Can also be used as a |method|, the base is passed as the
9055 second argument: >
Bram Moolenaar196b4662019-09-06 21:34:30 +02009056 GetPath()->setenv('PATH')
9057
Bram Moolenaar80492532016-03-08 17:08:53 +01009058setfperm({fname}, {mode}) *setfperm()* *chmod*
9059 Set the file permissions for {fname} to {mode}.
9060 {mode} must be a string with 9 characters. It is of the form
9061 "rwxrwxrwx", where each group of "rwx" flags represent, in
9062 turn, the permissions of the owner of the file, the group the
9063 file belongs to, and other users. A '-' character means the
9064 permission is off, any other character means on. Multi-byte
9065 characters are not supported.
9066
9067 For example "rw-r-----" means read-write for the user,
9068 readable by the group, not accessible by others. "xx-x-----"
9069 would do the same thing.
9070
9071 Returns non-zero for success, zero for failure.
9072
Bram Moolenaar4c313b12019-08-24 22:58:31 +02009073 Can also be used as a |method|: >
9074 GetFilename()->setfperm(mode)
9075<
Bram Moolenaar80492532016-03-08 17:08:53 +01009076 To read permissions see |getfperm()|.
9077
9078
Bram Moolenaar446cb832008-06-24 21:56:24 +00009079setline({lnum}, {text}) *setline()*
Bram Moolenaarb8ff1fb2012-02-04 21:59:01 +01009080 Set line {lnum} of the current buffer to {text}. To insert
Bram Moolenaarb31cf2b2017-09-02 19:45:19 +02009081 lines use |append()|. To set lines in another buffer use
Bram Moolenaarb328cca2019-01-06 16:24:01 +01009082 |setbufline()|. Any text properties in {lnum} are cleared.
Bram Moolenaarb31cf2b2017-09-02 19:45:19 +02009083
Bram Moolenaar402d2fe2005-04-15 21:00:38 +00009084 {lnum} is used like with |getline()|.
Bram Moolenaar446cb832008-06-24 21:56:24 +00009085 When {lnum} is just below the last line the {text} will be
Bram Moolenaar2e693a82019-10-16 22:35:02 +02009086 added below the last line.
Bram Moolenaarb31cf2b2017-09-02 19:45:19 +02009087
Bram Moolenaar402d2fe2005-04-15 21:00:38 +00009088 If this succeeds, 0 is returned. If this fails (most likely
Bram Moolenaarb31cf2b2017-09-02 19:45:19 +02009089 because {lnum} is invalid) 1 is returned.
9090
9091 Example: >
Bram Moolenaar071d4272004-06-13 20:20:40 +00009092 :call setline(5, strftime("%c"))
Bram Moolenaarb31cf2b2017-09-02 19:45:19 +02009093
Bram Moolenaar446cb832008-06-24 21:56:24 +00009094< When {text} is a |List| then line {lnum} and following lines
Bram Moolenaar2389c3c2005-05-22 22:07:59 +00009095 will be set to the items in the list. Example: >
9096 :call setline(5, ['aaa', 'bbb', 'ccc'])
9097< This is equivalent to: >
Bram Moolenaar53bfca22012-04-13 23:04:47 +02009098 :for [n, l] in [[5, 'aaa'], [6, 'bbb'], [7, 'ccc']]
Bram Moolenaar2389c3c2005-05-22 22:07:59 +00009099 : call setline(n, l)
9100 :endfor
Bram Moolenaarb4d5fba2017-09-11 19:31:28 +02009101
Bram Moolenaar071d4272004-06-13 20:20:40 +00009102< Note: The '[ and '] marks are not set.
9103
Bram Moolenaar2e693a82019-10-16 22:35:02 +02009104 Can also be used as a |method|, the base is passed as the
9105 second argument: >
Bram Moolenaar196b4662019-09-06 21:34:30 +02009106 GetText()->setline(lnum)
9107
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01009108setloclist({nr}, {list} [, {action} [, {what}]]) *setloclist()*
Bram Moolenaar17c7c012006-01-26 22:25:15 +00009109 Create or replace or add to the location list for window {nr}.
Bram Moolenaar7571d552016-08-18 22:54:46 +02009110 {nr} can be the window number or the |window-ID|.
Bram Moolenaar888ccac2016-06-04 18:49:36 +02009111 When {nr} is zero the current window is used.
9112
9113 For a location list window, the displayed location list is
9114 modified. For an invalid window number {nr}, -1 is returned.
Bram Moolenaar6ee10162007-07-26 20:58:42 +00009115 Otherwise, same as |setqflist()|.
9116 Also see |location-list|.
9117
Bram Moolenaar7ff78462020-07-10 22:00:53 +02009118 For {action} see |setqflist-action|.
9119
Bram Moolenaard823fa92016-08-12 16:29:27 +02009120 If the optional {what} dictionary argument is supplied, then
9121 only the items listed in {what} are set. Refer to |setqflist()|
9122 for the list of supported keys in {what}.
9123
Bram Moolenaaraad222c2019-09-06 22:46:09 +02009124 Can also be used as a |method|, the base is passed as the
9125 second argument: >
9126 GetLoclist()->setloclist(winnr)
9127
Bram Moolenaaraff74912019-03-30 18:11:49 +01009128setmatches({list} [, {win}]) *setmatches()*
Bram Moolenaar99fa7212020-04-26 15:59:55 +02009129 Restores a list of matches saved by |getmatches()| for the
9130 current window. Returns 0 if successful, otherwise -1. All
Bram Moolenaarfd133322019-03-29 12:20:27 +01009131 current matches are cleared before the list is restored. See
9132 example for |getmatches()|.
Bram Moolenaaraff74912019-03-30 18:11:49 +01009133 If {win} is specified, use the window with this number or
9134 window ID instead of the current window.
Bram Moolenaar68b76a62005-03-25 21:53:48 +00009135
Bram Moolenaaraad222c2019-09-06 22:46:09 +02009136 Can also be used as a |method|: >
9137 GetMatches()->setmatches()
9138<
Bram Moolenaar65c923a2006-03-03 22:56:30 +00009139 *setpos()*
9140setpos({expr}, {list})
9141 Set the position for {expr}. Possible values:
9142 . the cursor
9143 'x mark x
9144
Bram Moolenaar493c1782014-05-28 14:34:46 +02009145 {list} must be a |List| with four or five numbers:
Bram Moolenaar65c923a2006-03-03 22:56:30 +00009146 [bufnum, lnum, col, off]
Bram Moolenaar493c1782014-05-28 14:34:46 +02009147 [bufnum, lnum, col, off, curswant]
Bram Moolenaar65c923a2006-03-03 22:56:30 +00009148
Bram Moolenaar58b85342016-08-14 19:54:54 +02009149 "bufnum" is the buffer number. Zero can be used for the
Bram Moolenaarf13e00b2017-01-28 18:23:54 +01009150 current buffer. When setting an uppercase mark "bufnum" is
9151 used for the mark position. For other marks it specifies the
9152 buffer to set the mark in. You can use the |bufnr()| function
9153 to turn a file name into a buffer number.
9154 For setting the cursor and the ' mark "bufnum" is ignored,
9155 since these are associated with a window, not a buffer.
Bram Moolenaardb552d602006-03-23 22:59:57 +00009156 Does not change the jumplist.
Bram Moolenaar65c923a2006-03-03 22:56:30 +00009157
9158 "lnum" and "col" are the position in the buffer. The first
Bram Moolenaar8f3f58f2010-01-06 20:52:26 +01009159 column is 1. Use a zero "lnum" to delete a mark. If "col" is
9160 smaller than 1 then 1 is used.
Bram Moolenaar65c923a2006-03-03 22:56:30 +00009161
9162 The "off" number is only used when 'virtualedit' is set. Then
9163 it is the offset in screen columns from the start of the
Bram Moolenaard46bbc72007-05-12 14:38:41 +00009164 character. E.g., a position within a <Tab> or after the last
Bram Moolenaar65c923a2006-03-03 22:56:30 +00009165 character.
9166
Bram Moolenaar493c1782014-05-28 14:34:46 +02009167 The "curswant" number is only used when setting the cursor
9168 position. It sets the preferred column for when moving the
9169 cursor vertically. When the "curswant" number is missing the
9170 preferred column is not set. When it is present and setting a
9171 mark position it is not used.
9172
Bram Moolenaardfb18412013-12-11 18:53:29 +01009173 Note that for '< and '> changing the line number may result in
9174 the marks to be effectively be swapped, so that '< is always
9175 before '>.
9176
Bram Moolenaar08250432008-02-13 11:42:46 +00009177 Returns 0 when the position could be set, -1 otherwise.
9178 An error message is given if {expr} is invalid.
9179
Bram Moolenaar6f6c0f82014-05-28 20:31:42 +02009180 Also see |getpos()| and |getcurpos()|.
Bram Moolenaar65c923a2006-03-03 22:56:30 +00009181
Bram Moolenaaref2f6562007-05-06 13:32:59 +00009182 This does not restore the preferred column for moving
Bram Moolenaar493c1782014-05-28 14:34:46 +02009183 vertically; if you set the cursor position with this, |j| and
9184 |k| motions will jump to previous columns! Use |cursor()| to
9185 also set the preferred column. Also see the "curswant" key in
9186 |winrestview()|.
Bram Moolenaaref2f6562007-05-06 13:32:59 +00009187
Bram Moolenaaraad222c2019-09-06 22:46:09 +02009188 Can also be used as a |method|: >
9189 GetPosition()->setpos('.')
9190
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01009191setqflist({list} [, {action} [, {what}]]) *setqflist()*
Bram Moolenaarae338332017-08-11 20:25:26 +02009192 Create or replace or add to the quickfix list.
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01009193
Bram Moolenaarb17893a2020-03-14 08:19:51 +01009194 If the optional {what} dictionary argument is supplied, then
9195 only the items listed in {what} are set. The first {list}
9196 argument is ignored. See below for the supported items in
9197 {what}.
Bram Moolenaar7ff78462020-07-10 22:00:53 +02009198 *setqflist-what*
Bram Moolenaare7b1ea02020-08-07 19:54:59 +02009199 When {what} is not present, the items in {list} are used. Each
Bram Moolenaarae338332017-08-11 20:25:26 +02009200 item must be a dictionary. Non-dictionary items in {list} are
9201 ignored. Each dictionary item can contain the following
9202 entries:
Bram Moolenaar68b76a62005-03-25 21:53:48 +00009203
Bram Moolenaar48b66fb2007-02-04 01:58:18 +00009204 bufnr buffer number; must be the number of a valid
Bram Moolenaar446cb832008-06-24 21:56:24 +00009205 buffer
Bram Moolenaar48b66fb2007-02-04 01:58:18 +00009206 filename name of a file; only used when "bufnr" is not
Bram Moolenaar446cb832008-06-24 21:56:24 +00009207 present or it is invalid.
Bram Moolenaard76ce852018-05-01 15:02:04 +02009208 module name of a module; if given it will be used in
9209 quickfix error window instead of the filename.
Bram Moolenaar68b76a62005-03-25 21:53:48 +00009210 lnum line number in the file
Bram Moolenaar68b76a62005-03-25 21:53:48 +00009211 pattern search pattern used to locate the error
Bram Moolenaar582fd852005-03-28 20:58:01 +00009212 col column number
9213 vcol when non-zero: "col" is visual column
Bram Moolenaarc9b4b052006-04-30 18:54:39 +00009214 when zero: "col" is byte index
Bram Moolenaar582fd852005-03-28 20:58:01 +00009215 nr error number
Bram Moolenaar68b76a62005-03-25 21:53:48 +00009216 text description of the error
Bram Moolenaar582fd852005-03-28 20:58:01 +00009217 type single-character error type, 'E', 'W', etc.
Bram Moolenaarf1d21c82017-04-22 21:20:46 +02009218 valid recognized error message
Bram Moolenaar68b76a62005-03-25 21:53:48 +00009219
Bram Moolenaar582fd852005-03-28 20:58:01 +00009220 The "col", "vcol", "nr", "type" and "text" entries are
9221 optional. Either "lnum" or "pattern" entry can be used to
9222 locate a matching error line.
Bram Moolenaar48b66fb2007-02-04 01:58:18 +00009223 If the "filename" and "bufnr" entries are not present or
9224 neither the "lnum" or "pattern" entries are present, then the
9225 item will not be handled as an error line.
Bram Moolenaar68b76a62005-03-25 21:53:48 +00009226 If both "pattern" and "lnum" are present then "pattern" will
9227 be used.
Bram Moolenaarf1d21c82017-04-22 21:20:46 +02009228 If the "valid" entry is not supplied, then the valid flag is
9229 set when "bufnr" is a valid buffer or "filename" exists.
Bram Moolenaar00a927d2010-05-14 23:24:24 +02009230 If you supply an empty {list}, the quickfix list will be
9231 cleared.
Bram Moolenaar48b66fb2007-02-04 01:58:18 +00009232 Note that the list is not exactly the same as what
9233 |getqflist()| returns.
Bram Moolenaar68b76a62005-03-25 21:53:48 +00009234
Bram Moolenaar7ff78462020-07-10 22:00:53 +02009235 {action} values: *setqflist-action* *E927*
Bram Moolenaarb6fa30c2017-03-29 14:19:25 +02009236 'a' The items from {list} are added to the existing
9237 quickfix list. If there is no existing list, then a
9238 new list is created.
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01009239
Bram Moolenaarb6fa30c2017-03-29 14:19:25 +02009240 'r' The items from the current quickfix list are replaced
9241 with the items from {list}. This can also be used to
9242 clear the list: >
9243 :call setqflist([], 'r')
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01009244<
Bram Moolenaarb6fa30c2017-03-29 14:19:25 +02009245 'f' All the quickfix lists in the quickfix stack are
9246 freed.
9247
Bram Moolenaar511972d2016-06-04 18:09:59 +02009248 If {action} is not present or is set to ' ', then a new list
Bram Moolenaar55b69262017-08-13 13:42:01 +02009249 is created. The new quickfix list is added after the current
9250 quickfix list in the stack and all the following lists are
9251 freed. To add a new quickfix list at the end of the stack,
Bram Moolenaar36538222017-09-02 19:51:44 +02009252 set "nr" in {what} to "$".
Bram Moolenaar35c54e52005-05-20 21:25:31 +00009253
Bram Moolenaarb17893a2020-03-14 08:19:51 +01009254 The following items can be specified in dictionary {what}:
Bram Moolenaar15142e22018-04-30 22:19:58 +02009255 context quickfix list context. See |quickfix-context|
Bram Moolenaar36538222017-09-02 19:51:44 +02009256 efm errorformat to use when parsing text from
9257 "lines". If this is not present, then the
9258 'errorformat' option value is used.
Bram Moolenaar5b69c222019-01-11 14:50:06 +01009259 See |quickfix-parse|
Bram Moolenaara539f4f2017-08-30 20:33:55 +02009260 id quickfix list identifier |quickfix-ID|
Bram Moolenaar5b69c222019-01-11 14:50:06 +01009261 idx index of the current entry in the quickfix
9262 list specified by 'id' or 'nr'. If set to '$',
9263 then the last entry in the list is set as the
9264 current entry. See |quickfix-index|
Bram Moolenaar6a8958d2017-06-22 21:33:20 +02009265 items list of quickfix entries. Same as the {list}
9266 argument.
Bram Moolenaar2c809b72017-09-01 18:34:02 +02009267 lines use 'errorformat' to parse a list of lines and
9268 add the resulting entries to the quickfix list
9269 {nr} or {id}. Only a |List| value is supported.
Bram Moolenaar5b69c222019-01-11 14:50:06 +01009270 See |quickfix-parse|
Bram Moolenaar875feea2017-06-11 16:07:51 +02009271 nr list number in the quickfix stack; zero
Bram Moolenaar36538222017-09-02 19:51:44 +02009272 means the current quickfix list and "$" means
Bram Moolenaar5b69c222019-01-11 14:50:06 +01009273 the last quickfix list.
Bram Moolenaar858ba062020-05-31 23:11:59 +02009274 quickfixtextfunc
9275 function to get the text to display in the
Bram Moolenaard43906d2020-07-20 21:31:32 +02009276 quickfix window. The value can be the name of
9277 a function or a funcref or a lambda. Refer to
Bram Moolenaar858ba062020-05-31 23:11:59 +02009278 |quickfix-window-function| for an explanation
9279 of how to write the function and an example.
Bram Moolenaar5b69c222019-01-11 14:50:06 +01009280 title quickfix list title text. See |quickfix-title|
Bram Moolenaard823fa92016-08-12 16:29:27 +02009281 Unsupported keys in {what} are ignored.
9282 If the "nr" item is not present, then the current quickfix list
Bram Moolenaar86f100dc2017-06-28 21:26:27 +02009283 is modified. When creating a new quickfix list, "nr" can be
9284 set to a value one greater than the quickfix stack size.
Bram Moolenaara539f4f2017-08-30 20:33:55 +02009285 When modifying a quickfix list, to guarantee that the correct
Bram Moolenaar36538222017-09-02 19:51:44 +02009286 list is modified, "id" should be used instead of "nr" to
Bram Moolenaara539f4f2017-08-30 20:33:55 +02009287 specify the list.
Bram Moolenaard823fa92016-08-12 16:29:27 +02009288
Bram Moolenaar15142e22018-04-30 22:19:58 +02009289 Examples (See also |setqflist-examples|): >
Bram Moolenaar2c809b72017-09-01 18:34:02 +02009290 :call setqflist([], 'r', {'title': 'My search'})
9291 :call setqflist([], 'r', {'nr': 2, 'title': 'Errors'})
Bram Moolenaar15142e22018-04-30 22:19:58 +02009292 :call setqflist([], 'a', {'id':qfid, 'lines':["F1:10:L10"]})
Bram Moolenaard823fa92016-08-12 16:29:27 +02009293<
Bram Moolenaar68b76a62005-03-25 21:53:48 +00009294 Returns zero for success, -1 for failure.
9295
9296 This function can be used to create a quickfix list
9297 independent of the 'errorformat' setting. Use a command like
Bram Moolenaar94237492017-04-23 18:40:21 +02009298 `:cc 1` to jump to the first position.
Bram Moolenaar68b76a62005-03-25 21:53:48 +00009299
Bram Moolenaaraad222c2019-09-06 22:46:09 +02009300 Can also be used as a |method|, the base is passed as the
9301 second argument: >
9302 GetErrorlist()->setqflist()
9303<
Bram Moolenaar071d4272004-06-13 20:20:40 +00009304 *setreg()*
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009305setreg({regname}, {value} [, {options}])
Bram Moolenaar071d4272004-06-13 20:20:40 +00009306 Set the register {regname} to {value}.
Bram Moolenaar0e05de42020-03-25 22:23:46 +01009307 If {regname} is "" or "@", the unnamed register '"' is used.
Bram Moolenaare46a4402020-06-30 20:38:27 +02009308
Bram Moolenaarbb861e22020-06-07 18:16:36 +02009309 {value} may be any value returned by |getreg()| or
9310 |getreginfo()|, including a |List| or |Dict|.
Bram Moolenaar071d4272004-06-13 20:20:40 +00009311 If {options} contains "a" or {regname} is upper case,
9312 then the value is appended.
Bram Moolenaare46a4402020-06-30 20:38:27 +02009313
Bram Moolenaarc6485bc2010-07-28 17:02:55 +02009314 {options} can also contain a register type specification:
Bram Moolenaar071d4272004-06-13 20:20:40 +00009315 "c" or "v" |characterwise| mode
9316 "l" or "V" |linewise| mode
9317 "b" or "<CTRL-V>" |blockwise-visual| mode
9318 If a number immediately follows "b" or "<CTRL-V>" then this is
9319 used as the width of the selection - if it is not specified
9320 then the width of the block is set to the number of characters
Bram Moolenaard46bbc72007-05-12 14:38:41 +00009321 in the longest line (counting a <Tab> as 1 character).
Bram Moolenaar071d4272004-06-13 20:20:40 +00009322
9323 If {options} contains no register settings, then the default
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01009324 is to use character mode unless {value} ends in a <NL> for
9325 string {value} and linewise mode for list {value}. Blockwise
Bram Moolenaar5a50c222014-04-02 22:17:10 +02009326 mode is never selected automatically.
9327 Returns zero for success, non-zero for failure.
9328
9329 *E883*
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01009330 Note: you may not use |List| containing more than one item to
9331 set search and expression registers. Lists containing no
Bram Moolenaar5a50c222014-04-02 22:17:10 +02009332 items act like empty strings.
Bram Moolenaar071d4272004-06-13 20:20:40 +00009333
9334 Examples: >
9335 :call setreg(v:register, @*)
9336 :call setreg('*', @%, 'ac')
9337 :call setreg('a', "1\n2\n3", 'b5')
Bram Moolenaarbb861e22020-06-07 18:16:36 +02009338 :call setreg('"', { 'points_to': 'a'})
Bram Moolenaar071d4272004-06-13 20:20:40 +00009339
9340< This example shows using the functions to save and restore a
Bram Moolenaarb4d5fba2017-09-11 19:31:28 +02009341 register: >
Bram Moolenaarbb861e22020-06-07 18:16:36 +02009342 :let var_a = getreginfo()
9343 :call setreg('a', var_a)
Bram Moolenaare46a4402020-06-30 20:38:27 +02009344< or: >
Bram Moolenaar5a50c222014-04-02 22:17:10 +02009345 :let var_a = getreg('a', 1, 1)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009346 :let var_amode = getregtype('a')
9347 ....
9348 :call setreg('a', var_a, var_amode)
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01009349< Note: you may not reliably restore register value
9350 without using the third argument to |getreg()| as without it
Bram Moolenaarb4d5fba2017-09-11 19:31:28 +02009351 newlines are represented as newlines AND Nul bytes are
9352 represented as newlines as well, see |NL-used-for-Nul|.
Bram Moolenaar071d4272004-06-13 20:20:40 +00009353
Bram Moolenaarb4d5fba2017-09-11 19:31:28 +02009354 You can also change the type of a register by appending
Bram Moolenaar071d4272004-06-13 20:20:40 +00009355 nothing: >
9356 :call setreg('a', '', 'al')
9357
Bram Moolenaaraad222c2019-09-06 22:46:09 +02009358< Can also be used as a |method|, the base is passed as the
9359 second argument: >
9360 GetText()->setreg('a')
9361
Bram Moolenaar06b5d512010-05-22 15:37:44 +02009362settabvar({tabnr}, {varname}, {val}) *settabvar()*
9363 Set tab-local variable {varname} to {val} in tab page {tabnr}.
9364 |t:var|
Bram Moolenaarb4230122019-05-30 18:40:53 +02009365 Note that autocommands are blocked, side effects may not be
9366 triggered, e.g. when setting 'filetype'.
Bram Moolenaar06b5d512010-05-22 15:37:44 +02009367 Note that the variable name without "t:" must be used.
9368 Tabs are numbered starting with one.
Bram Moolenaar06b5d512010-05-22 15:37:44 +02009369 This function is not available in the |sandbox|.
9370
Bram Moolenaar2e693a82019-10-16 22:35:02 +02009371 Can also be used as a |method|, the base is passed as the
9372 third argument: >
Bram Moolenaaraad222c2019-09-06 22:46:09 +02009373 GetValue()->settabvar(tab, name)
9374
Bram Moolenaarc6249bb2006-04-15 20:25:09 +00009375settabwinvar({tabnr}, {winnr}, {varname}, {val}) *settabwinvar()*
9376 Set option or local variable {varname} in window {winnr} to
9377 {val}.
9378 Tabs are numbered starting with one. For the current tabpage
9379 use |setwinvar()|.
Bram Moolenaar7571d552016-08-18 22:54:46 +02009380 {winnr} can be the window number or the |window-ID|.
Bram Moolenaarc6249bb2006-04-15 20:25:09 +00009381 When {winnr} is zero the current window is used.
Bram Moolenaarb4230122019-05-30 18:40:53 +02009382 Note that autocommands are blocked, side effects may not be
9383 triggered, e.g. when setting 'filetype' or 'syntax'.
Bram Moolenaar071d4272004-06-13 20:20:40 +00009384 This also works for a global or local buffer option, but it
9385 doesn't work for a global or local buffer variable.
9386 For a local buffer option the global value is unchanged.
9387 Note that the variable name without "w:" must be used.
Bram Moolenaarc6249bb2006-04-15 20:25:09 +00009388 Examples: >
9389 :call settabwinvar(1, 1, "&list", 0)
9390 :call settabwinvar(3, 2, "myvar", "foobar")
9391< This function is not available in the |sandbox|.
9392
Bram Moolenaar2e693a82019-10-16 22:35:02 +02009393 Can also be used as a |method|, the base is passed as the
9394 fourth argument: >
Bram Moolenaaraad222c2019-09-06 22:46:09 +02009395 GetValue()->settabvar(tab, winnr, name)
9396
Bram Moolenaarf49cc602018-11-11 15:21:05 +01009397settagstack({nr}, {dict} [, {action}]) *settagstack()*
9398 Modify the tag stack of the window {nr} using {dict}.
9399 {nr} can be the window number or the |window-ID|.
9400
9401 For a list of supported items in {dict}, refer to
Bram Moolenaar271fa082020-01-02 14:02:16 +01009402 |gettagstack()|. "curidx" takes effect before changing the tag
9403 stack.
Bram Moolenaarf49cc602018-11-11 15:21:05 +01009404 *E962*
Bram Moolenaar271fa082020-01-02 14:02:16 +01009405 How the tag stack is modified depends on the {action}
9406 argument:
9407 - If {action} is not present or is set to 'r', then the tag
9408 stack is replaced.
9409 - If {action} is set to 'a', then new entries from {dict} are
9410 pushed (added) onto the tag stack.
9411 - If {action} is set to 't', then all the entries from the
9412 current entry in the tag stack or "curidx" in {dict} are
9413 removed and then new entries are pushed to the stack.
9414
9415 The current index is set to one after the length of the tag
9416 stack after the modification.
Bram Moolenaarf49cc602018-11-11 15:21:05 +01009417
9418 Returns zero for success, -1 for failure.
9419
Bram Moolenaare7b1ea02020-08-07 19:54:59 +02009420 Examples (for more examples see |tagstack-examples|):
Bram Moolenaard1caa942020-04-10 22:10:56 +02009421 Empty the tag stack of window 3: >
Bram Moolenaarf49cc602018-11-11 15:21:05 +01009422 call settagstack(3, {'items' : []})
9423
Bram Moolenaarf49cc602018-11-11 15:21:05 +01009424< Save and restore the tag stack: >
9425 let stack = gettagstack(1003)
9426 " do something else
9427 call settagstack(1003, stack)
9428 unlet stack
9429<
Bram Moolenaar2e693a82019-10-16 22:35:02 +02009430 Can also be used as a |method|, the base is passed as the
9431 second argument: >
Bram Moolenaaraad222c2019-09-06 22:46:09 +02009432 GetStack()->settagstack(winnr)
9433
9434setwinvar({winnr}, {varname}, {val}) *setwinvar()*
Bram Moolenaarc6249bb2006-04-15 20:25:09 +00009435 Like |settabwinvar()| for the current tab page.
Bram Moolenaar071d4272004-06-13 20:20:40 +00009436 Examples: >
9437 :call setwinvar(1, "&list", 0)
9438 :call setwinvar(2, "myvar", "foobar")
Bram Moolenaar071d4272004-06-13 20:20:40 +00009439
Bram Moolenaar2e693a82019-10-16 22:35:02 +02009440< Can also be used as a |method|, the base is passed as the
9441 third argument: >
Bram Moolenaaraad222c2019-09-06 22:46:09 +02009442 GetValue()->setwinvar(winnr, name)
9443
Bram Moolenaaraf9aeb92013-02-13 17:35:04 +01009444sha256({string}) *sha256()*
Bram Moolenaar2b8388b2015-02-28 13:11:45 +01009445 Returns a String with 64 hex characters, which is the SHA256
Bram Moolenaaraf9aeb92013-02-13 17:35:04 +01009446 checksum of {string}.
Bram Moolenaaraad222c2019-09-06 22:46:09 +02009447
9448 Can also be used as a |method|: >
9449 GetText()->sha256()
9450
9451< {only available when compiled with the |+cryptv| feature}
Bram Moolenaaraf9aeb92013-02-13 17:35:04 +01009452
Bram Moolenaar05bb9532008-07-04 09:44:11 +00009453shellescape({string} [, {special}]) *shellescape()*
Bram Moolenaar8f3f58f2010-01-06 20:52:26 +01009454 Escape {string} for use as a shell command argument.
Bram Moolenaar25e42232019-08-04 15:04:10 +02009455 On MS-Windows, when 'shellslash' is not set, it will enclose
9456 {string} in double quotes and double all double quotes within
9457 {string}.
Bram Moolenaare381d3d2016-07-07 14:50:41 +02009458 Otherwise it will enclose {string} in single quotes and
9459 replace all "'" with "'\''".
Bram Moolenaar875feea2017-06-11 16:07:51 +02009460
Bram Moolenaar05bb9532008-07-04 09:44:11 +00009461 When the {special} argument is present and it's a non-zero
9462 Number or a non-empty String (|non-zero-arg|), then special
Bram Moolenaare37d50a2008-08-06 17:06:04 +00009463 items such as "!", "%", "#" and "<cword>" will be preceded by
9464 a backslash. This backslash will be removed again by the |:!|
Bram Moolenaar05bb9532008-07-04 09:44:11 +00009465 command.
Bram Moolenaar875feea2017-06-11 16:07:51 +02009466
Bram Moolenaare37d50a2008-08-06 17:06:04 +00009467 The "!" character will be escaped (again with a |non-zero-arg|
9468 {special}) when 'shell' contains "csh" in the tail. That is
9469 because for csh and tcsh "!" is used for history replacement
9470 even when inside single quotes.
Bram Moolenaar875feea2017-06-11 16:07:51 +02009471
9472 With a |non-zero-arg| {special} the <NL> character is also
9473 escaped. When 'shell' containing "csh" in the tail it's
Bram Moolenaare37d50a2008-08-06 17:06:04 +00009474 escaped a second time.
Bram Moolenaar875feea2017-06-11 16:07:51 +02009475
Bram Moolenaar05bb9532008-07-04 09:44:11 +00009476 Example of use with a |:!| command: >
9477 :exe '!dir ' . shellescape(expand('<cfile>'), 1)
9478< This results in a directory listing for the file under the
9479 cursor. Example of use with |system()|: >
9480 :call system("chmod +w -- " . shellescape(expand("%")))
Bram Moolenaar26df0922014-02-23 23:39:13 +01009481< See also |::S|.
Bram Moolenaar60a495f2006-10-03 12:44:42 +00009482
Bram Moolenaaraad222c2019-09-06 22:46:09 +02009483 Can also be used as a |method|: >
9484 GetCommand()->shellescape()
Bram Moolenaar60a495f2006-10-03 12:44:42 +00009485
Bram Moolenaarf9514162018-11-22 03:08:29 +01009486shiftwidth([{col}]) *shiftwidth()*
Bram Moolenaar2d17fa32012-10-21 00:45:18 +02009487 Returns the effective value of 'shiftwidth'. This is the
9488 'shiftwidth' value unless it is zero, in which case it is the
Bram Moolenaar009d84a2016-01-28 14:12:00 +01009489 'tabstop' value. This function was introduced with patch
Bram Moolenaarf9514162018-11-22 03:08:29 +01009490 7.3.694 in 2012, everybody should have it by now (however it
9491 did not allow for the optional {col} argument until 8.1.542).
Bram Moolenaar2d17fa32012-10-21 00:45:18 +02009492
Bram Moolenaarf9514162018-11-22 03:08:29 +01009493 When there is one argument {col} this is used as column number
9494 for which to return the 'shiftwidth' value. This matters for the
9495 'vartabstop' feature. If the 'vartabstop' setting is enabled and
9496 no {col} argument is given, column 1 will be assumed.
Bram Moolenaarf0d58ef2018-11-16 16:13:44 +01009497
Bram Moolenaaraad222c2019-09-06 22:46:09 +02009498 Can also be used as a |method|: >
9499 GetColumn()->shiftwidth()
9500
Bram Moolenaared997ad2019-07-21 16:42:00 +02009501sign_ functions are documented here: |sign-functions-details|
Bram Moolenaar2d17fa32012-10-21 00:45:18 +02009502
Bram Moolenaar162b7142018-12-21 15:17:36 +01009503
Bram Moolenaar071d4272004-06-13 20:20:40 +00009504simplify({filename}) *simplify()*
9505 Simplify the file name as much as possible without changing
9506 the meaning. Shortcuts (on MS-Windows) or symbolic links (on
9507 Unix) are not resolved. If the first path component in
9508 {filename} designates the current directory, this will be
9509 valid for the result as well. A trailing path separator is
Bram Moolenaar73fef332020-06-21 22:12:03 +02009510 not removed either. On Unix "//path" is unchanged, but
9511 "///path" is simplified to "/path" (this follows the Posix
9512 standard).
Bram Moolenaar071d4272004-06-13 20:20:40 +00009513 Example: >
9514 simplify("./dir/.././/file/") == "./file/"
9515< Note: The combination "dir/.." is only removed if "dir" is
9516 a searchable directory or does not exist. On Unix, it is also
9517 removed when "dir" is a symbolic link within the same
9518 directory. In order to resolve all the involved symbolic
9519 links before simplifying the path name, use |resolve()|.
9520
Bram Moolenaar7035fd92020-04-08 20:03:52 +02009521 Can also be used as a |method|: >
9522 GetName()->simplify()
Bram Moolenaara14de3d2005-01-07 21:48:26 +00009523
Bram Moolenaar446cb832008-06-24 21:56:24 +00009524sin({expr}) *sin()*
9525 Return the sine of {expr}, measured in radians, as a |Float|.
9526 {expr} must evaluate to a |Float| or a |Number|.
9527 Examples: >
9528 :echo sin(100)
9529< -0.506366 >
9530 :echo sin(-4.01)
9531< 0.763301
Bram Moolenaar93cf85f2019-08-17 21:36:28 +02009532
9533 Can also be used as a |method|: >
9534 Compute()->sin()
9535<
Bram Moolenaar446cb832008-06-24 21:56:24 +00009536 {only available when compiled with the |+float| feature}
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01009537
Bram Moolenaar446cb832008-06-24 21:56:24 +00009538
Bram Moolenaardb7c6862010-05-21 16:33:48 +02009539sinh({expr}) *sinh()*
Bram Moolenaar9855d6b2010-07-18 14:34:51 +02009540 Return the hyperbolic sine of {expr} as a |Float| in the range
Bram Moolenaardb7c6862010-05-21 16:33:48 +02009541 [-inf, inf].
Bram Moolenaar9855d6b2010-07-18 14:34:51 +02009542 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaardb7c6862010-05-21 16:33:48 +02009543 Examples: >
9544 :echo sinh(0.5)
9545< 0.521095 >
9546 :echo sinh(-0.9)
9547< -1.026517
Bram Moolenaar93cf85f2019-08-17 21:36:28 +02009548
9549 Can also be used as a |method|: >
9550 Compute()->sinh()
9551<
Bram Moolenaardb84e452010-08-15 13:50:43 +02009552 {only available when compiled with the |+float| feature}
Bram Moolenaardb7c6862010-05-21 16:33:48 +02009553
9554
Bram Moolenaar5f894962011-06-19 02:55:37 +02009555sort({list} [, {func} [, {dict}]]) *sort()* *E702*
Bram Moolenaar327aa022014-03-25 18:24:23 +01009556 Sort the items in {list} in-place. Returns {list}.
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01009557
Bram Moolenaar327aa022014-03-25 18:24:23 +01009558 If you want a list to remain unmodified make a copy first: >
Bram Moolenaara14de3d2005-01-07 21:48:26 +00009559 :let sortedlist = sort(copy(mylist))
Bram Moolenaar822ff862014-06-12 21:46:14 +02009560
Bram Moolenaar946e27a2014-06-25 18:50:27 +02009561< When {func} is omitted, is empty or zero, then sort() uses the
9562 string representation of each item to sort on. Numbers sort
9563 after Strings, |Lists| after Numbers. For sorting text in the
9564 current buffer use |:sort|.
Bram Moolenaar327aa022014-03-25 18:24:23 +01009565
Bram Moolenaar34401cc2014-08-29 15:12:19 +02009566 When {func} is given and it is '1' or 'i' then case is
Bram Moolenaar946e27a2014-06-25 18:50:27 +02009567 ignored.
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01009568
Bram Moolenaar946e27a2014-06-25 18:50:27 +02009569 When {func} is given and it is 'n' then all items will be
9570 sorted numerical (Implementation detail: This uses the
9571 strtod() function to parse numbers, Strings, Lists, Dicts and
9572 Funcrefs will be considered as being 0).
9573
Bram Moolenaarb00da1d2015-12-03 16:33:12 +01009574 When {func} is given and it is 'N' then all items will be
9575 sorted numerical. This is like 'n' but a string containing
9576 digits will be used as the number they represent.
9577
Bram Moolenaar13d5aee2016-01-21 23:36:05 +01009578 When {func} is given and it is 'f' then all items will be
9579 sorted numerical. All values must be a Number or a Float.
9580
Bram Moolenaar32466aa2006-02-24 23:53:04 +00009581 When {func} is a |Funcref| or a function name, this function
9582 is called to compare items. The function is invoked with two
Bram Moolenaar8f3f58f2010-01-06 20:52:26 +01009583 items as argument and must return zero if they are equal, 1 or
9584 bigger if the first one sorts after the second one, -1 or
9585 smaller if the first one sorts before the second one.
Bram Moolenaar327aa022014-03-25 18:24:23 +01009586
9587 {dict} is for functions with the "dict" attribute. It will be
9588 used to set the local variable "self". |Dictionary-function|
9589
Bram Moolenaar8bb1c3e2014-07-04 16:43:17 +02009590 The sort is stable, items which compare equal (as number or as
9591 string) will keep their relative position. E.g., when sorting
Bram Moolenaardb6ea062014-07-10 22:01:47 +02009592 on numbers, text strings will sort next to each other, in the
Bram Moolenaar8bb1c3e2014-07-04 16:43:17 +02009593 same order as they were originally.
9594
Bram Moolenaarac92e252019-08-03 21:58:38 +02009595 Can also be used as a |method|: >
9596 mylist->sort()
9597
9598< Also see |uniq()|.
Bram Moolenaar327aa022014-03-25 18:24:23 +01009599
Bram Moolenaar8f3f58f2010-01-06 20:52:26 +01009600 Example: >
Bram Moolenaara14de3d2005-01-07 21:48:26 +00009601 func MyCompare(i1, i2)
9602 return a:i1 == a:i2 ? 0 : a:i1 > a:i2 ? 1 : -1
9603 endfunc
9604 let sortedlist = sort(mylist, "MyCompare")
Bram Moolenaar8f3f58f2010-01-06 20:52:26 +01009605< A shorter compare version for this specific simple case, which
9606 ignores overflow: >
9607 func MyCompare(i1, i2)
9608 return a:i1 - a:i2
9609 endfunc
Bram Moolenaard857f0e2005-06-21 22:37:39 +00009610<
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +02009611sound_clear() *sound_clear()*
9612 Stop playing all sounds.
Bram Moolenaar9b283522019-06-17 22:19:33 +02009613 {only available when compiled with the |+sound| feature}
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +02009614
Bram Moolenaar427f5b62019-06-09 13:43:51 +02009615 *sound_playevent()*
9616sound_playevent({name} [, {callback}])
9617 Play a sound identified by {name}. Which event names are
9618 supported depends on the system. Often the XDG sound names
9619 are used. On Ubuntu they may be found in
9620 /usr/share/sounds/freedesktop/stereo. Example: >
9621 call sound_playevent('bell')
Bram Moolenaar9b283522019-06-17 22:19:33 +02009622< On MS-Windows, {name} can be SystemAsterisk, SystemDefault,
9623 SystemExclamation, SystemExit, SystemHand, SystemQuestion,
9624 SystemStart, SystemWelcome, etc.
Bram Moolenaar427f5b62019-06-09 13:43:51 +02009625
Bram Moolenaar9b283522019-06-17 22:19:33 +02009626 When {callback} is specified it is invoked when the sound is
Bram Moolenaar427f5b62019-06-09 13:43:51 +02009627 finished. The first argument is the sound ID, the second
9628 argument is the status:
9629 0 sound was played to the end
Bram Moolenaar12ee7ff2019-06-10 22:47:40 +02009630 1 sound was interrupted
Bram Moolenaar6c1e1572019-06-22 02:13:00 +02009631 2 error occurred after sound started
Bram Moolenaar427f5b62019-06-09 13:43:51 +02009632 Example: >
9633 func Callback(id, status)
9634 echomsg "sound " .. a:id .. " finished with " .. a:status
9635 endfunc
9636 call sound_playevent('bell', 'Callback')
9637
Bram Moolenaar9b283522019-06-17 22:19:33 +02009638< MS-Windows: {callback} doesn't work for this function.
9639
9640 Returns the sound ID, which can be passed to `sound_stop()`.
Bram Moolenaar427f5b62019-06-09 13:43:51 +02009641 Returns zero if the sound could not be played.
Bram Moolenaarf6ed61e2019-09-07 19:05:09 +02009642
9643 Can also be used as a |method|: >
9644 GetSoundName()->sound_playevent()
9645
9646< {only available when compiled with the |+sound| feature}
Bram Moolenaar427f5b62019-06-09 13:43:51 +02009647
9648 *sound_playfile()*
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +02009649sound_playfile({path} [, {callback}])
9650 Like `sound_playevent()` but play sound file {path}. {path}
Bram Moolenaar427f5b62019-06-09 13:43:51 +02009651 must be a full path. On Ubuntu you may find files to play
9652 with this command: >
9653 :!find /usr/share/sounds -type f | grep -v index.theme
Bram Moolenaarf6ed61e2019-09-07 19:05:09 +02009654
9655< Can also be used as a |method|: >
9656 GetSoundPath()->sound_playfile()
9657
Bram Moolenaar12ee7ff2019-06-10 22:47:40 +02009658< {only available when compiled with the |+sound| feature}
Bram Moolenaar427f5b62019-06-09 13:43:51 +02009659
9660
9661sound_stop({id}) *sound_stop()*
9662 Stop playing sound {id}. {id} must be previously returned by
9663 `sound_playevent()` or `sound_playfile()`.
Bram Moolenaar9b283522019-06-17 22:19:33 +02009664
9665 On MS-Windows, this does not work for event sound started by
9666 `sound_playevent()`. To stop event sounds, use `sound_clear()`.
9667
Bram Moolenaarf6ed61e2019-09-07 19:05:09 +02009668 Can also be used as a |method|: >
9669 soundid->sound_stop()
9670
9671< {only available when compiled with the |+sound| feature}
Bram Moolenaar427f5b62019-06-09 13:43:51 +02009672
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00009673 *soundfold()*
9674soundfold({word})
9675 Return the sound-folded equivalent of {word}. Uses the first
Bram Moolenaar446cb832008-06-24 21:56:24 +00009676 language in 'spelllang' for the current window that supports
Bram Moolenaar42eeac32005-06-29 22:40:58 +00009677 soundfolding. 'spell' must be set. When no sound folding is
9678 possible the {word} is returned unmodified.
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00009679 This can be used for making spelling suggestions. Note that
9680 the method can be quite slow.
9681
Bram Moolenaarf6ed61e2019-09-07 19:05:09 +02009682 Can also be used as a |method|: >
9683 GetWord()->soundfold()
9684<
Bram Moolenaard857f0e2005-06-21 22:37:39 +00009685 *spellbadword()*
Bram Moolenaar1e015462005-09-25 22:16:38 +00009686spellbadword([{sentence}])
9687 Without argument: The result is the badly spelled word under
9688 or after the cursor. The cursor is moved to the start of the
9689 bad word. When no bad word is found in the cursor line the
9690 result is an empty string and the cursor doesn't move.
9691
9692 With argument: The result is the first word in {sentence} that
9693 is badly spelled. If there are no spelling mistakes the
9694 result is an empty string.
9695
9696 The return value is a list with two items:
9697 - The badly spelled word or an empty string.
9698 - The type of the spelling error:
Bram Moolenaarc9b4b052006-04-30 18:54:39 +00009699 "bad" spelling mistake
Bram Moolenaar1e015462005-09-25 22:16:38 +00009700 "rare" rare word
9701 "local" word only valid in another region
9702 "caps" word should start with Capital
9703 Example: >
9704 echo spellbadword("the quik brown fox")
9705< ['quik', 'bad'] ~
9706
Bram Moolenaar152e79e2020-06-10 15:32:08 +02009707 The spelling information for the current window and the value
9708 of 'spelllang' are used.
Bram Moolenaard857f0e2005-06-21 22:37:39 +00009709
Bram Moolenaarf6ed61e2019-09-07 19:05:09 +02009710 Can also be used as a |method|: >
9711 GetText()->spellbadword()
9712<
Bram Moolenaard857f0e2005-06-21 22:37:39 +00009713 *spellsuggest()*
Bram Moolenaarc54b8a72005-09-30 21:20:29 +00009714spellsuggest({word} [, {max} [, {capital}]])
Bram Moolenaar32466aa2006-02-24 23:53:04 +00009715 Return a |List| with spelling suggestions to replace {word}.
Bram Moolenaard857f0e2005-06-21 22:37:39 +00009716 When {max} is given up to this number of suggestions are
9717 returned. Otherwise up to 25 suggestions are returned.
9718
Bram Moolenaarc54b8a72005-09-30 21:20:29 +00009719 When the {capital} argument is given and it's non-zero only
9720 suggestions with a leading capital will be given. Use this
9721 after a match with 'spellcapcheck'.
9722
Bram Moolenaard857f0e2005-06-21 22:37:39 +00009723 {word} can be a badly spelled word followed by other text.
9724 This allows for joining two words that were split. The
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00009725 suggestions also include the following text, thus you can
9726 replace a line.
9727
9728 {word} may also be a good word. Similar words will then be
Bram Moolenaarc54b8a72005-09-30 21:20:29 +00009729 returned. {word} itself is not included in the suggestions,
9730 although it may appear capitalized.
Bram Moolenaard857f0e2005-06-21 22:37:39 +00009731
9732 The spelling information for the current window is used. The
Bram Moolenaar152e79e2020-06-10 15:32:08 +02009733 values of 'spelllang' and 'spellsuggest' are used.
Bram Moolenaard857f0e2005-06-21 22:37:39 +00009734
Bram Moolenaarf6ed61e2019-09-07 19:05:09 +02009735 Can also be used as a |method|: >
9736 GetWord()->spellsuggest()
Bram Moolenaara14de3d2005-01-07 21:48:26 +00009737
Bram Moolenaar2389c3c2005-05-22 22:07:59 +00009738split({expr} [, {pattern} [, {keepempty}]]) *split()*
Bram Moolenaar32466aa2006-02-24 23:53:04 +00009739 Make a |List| out of {expr}. When {pattern} is omitted or
9740 empty each white-separated sequence of characters becomes an
9741 item.
Bram Moolenaara14de3d2005-01-07 21:48:26 +00009742 Otherwise the string is split where {pattern} matches,
Bram Moolenaar97d62492012-11-15 21:28:22 +01009743 removing the matched characters. 'ignorecase' is not used
9744 here, add \c to ignore case. |/\c|
Bram Moolenaar2389c3c2005-05-22 22:07:59 +00009745 When the first or last item is empty it is omitted, unless the
9746 {keepempty} argument is given and it's non-zero.
Bram Moolenaar5c06f8b2005-05-31 22:14:58 +00009747 Other empty items are kept when {pattern} matches at least one
9748 character or when {keepempty} is non-zero.
Bram Moolenaara14de3d2005-01-07 21:48:26 +00009749 Example: >
Bram Moolenaar5f2bb9f2005-01-11 21:29:04 +00009750 :let words = split(getline('.'), '\W\+')
Bram Moolenaar2389c3c2005-05-22 22:07:59 +00009751< To split a string in individual characters: >
Bram Moolenaar402d2fe2005-04-15 21:00:38 +00009752 :for c in split(mystring, '\zs')
Bram Moolenaar12969c02015-09-08 23:36:10 +02009753< If you want to keep the separator you can also use '\zs' at
9754 the end of the pattern: >
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00009755 :echo split('abc:def:ghi', ':\zs')
9756< ['abc:', 'def:', 'ghi'] ~
Bram Moolenaar2389c3c2005-05-22 22:07:59 +00009757 Splitting a table where the first element can be empty: >
9758 :let items = split(line, ':', 1)
9759< The opposite function is |join()|.
Bram Moolenaara14de3d2005-01-07 21:48:26 +00009760
Bram Moolenaara74e4942019-08-04 17:35:53 +02009761 Can also be used as a |method|: >
9762 GetString()->split()
Bram Moolenaara14de3d2005-01-07 21:48:26 +00009763
Bram Moolenaar446cb832008-06-24 21:56:24 +00009764sqrt({expr}) *sqrt()*
9765 Return the non-negative square root of Float {expr} as a
9766 |Float|.
9767 {expr} must evaluate to a |Float| or a |Number|. When {expr}
9768 is negative the result is NaN (Not a Number).
9769 Examples: >
9770 :echo sqrt(100)
9771< 10.0 >
9772 :echo sqrt(-4.01)
9773< nan
Bram Moolenaarc236c162008-07-13 17:41:49 +00009774 "nan" may be different, it depends on system libraries.
Bram Moolenaar93cf85f2019-08-17 21:36:28 +02009775
9776 Can also be used as a |method|: >
9777 Compute()->sqrt()
9778<
Bram Moolenaar446cb832008-06-24 21:56:24 +00009779 {only available when compiled with the |+float| feature}
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01009780
Bram Moolenaar446cb832008-06-24 21:56:24 +00009781
Bram Moolenaar06b0b4b2019-11-25 15:40:55 +01009782srand([{expr}]) *srand()*
9783 Initialize seed used by |rand()|:
9784 - If {expr} is not given, seed values are initialized by
Bram Moolenaarf8c1f922019-11-28 22:13:14 +01009785 reading from /dev/urandom, if possible, or using time(NULL)
9786 a.k.a. epoch time otherwise; this only has second accuracy.
9787 - If {expr} is given it must be a Number. It is used to
9788 initialize the seed values. This is useful for testing or
9789 when a predictable sequence is intended.
Bram Moolenaar06b0b4b2019-11-25 15:40:55 +01009790
9791 Examples: >
9792 :let seed = srand()
9793 :let seed = srand(userinput)
9794 :echo rand(seed)
9795
Bram Moolenaar0e57dd82019-09-16 22:56:03 +02009796state([{what}]) *state()*
9797 Return a string which contains characters indicating the
9798 current state. Mostly useful in callbacks that want to do
9799 work that may not always be safe. Roughly this works like:
9800 - callback uses state() to check if work is safe to do.
Bram Moolenaar589edb32019-09-20 14:38:13 +02009801 Yes: then do it right away.
9802 No: add to work queue and add a |SafeState| and/or
9803 |SafeStateAgain| autocommand (|SafeState| triggers at
9804 toplevel, |SafeStateAgain| triggers after handling
9805 messages and callbacks).
9806 - When SafeState or SafeStateAgain is triggered and executes
9807 your autocommand, check with `state()` if the work can be
9808 done now, and if yes remove it from the queue and execute.
9809 Remove the autocommand if the queue is now empty.
Bram Moolenaar0e57dd82019-09-16 22:56:03 +02009810 Also see |mode()|.
9811
9812 When {what} is given only characters in this string will be
9813 added. E.g, this checks if the screen has scrolled: >
Bram Moolenaar589edb32019-09-20 14:38:13 +02009814 if state('s') == ''
9815 " screen has not scrolled
Bram Moolenaar0e57dd82019-09-16 22:56:03 +02009816<
Bram Moolenaard103ee72019-09-18 21:15:31 +02009817 These characters indicate the state, generally indicating that
9818 something is busy:
Bram Moolenaar589edb32019-09-20 14:38:13 +02009819 m halfway a mapping, :normal command, feedkeys() or
9820 stuffed command
Bram Moolenaare46a4402020-06-30 20:38:27 +02009821 o operator pending, e.g. after |d|
Bram Moolenaar589edb32019-09-20 14:38:13 +02009822 a Insert mode autocomplete active
9823 x executing an autocommand
Bram Moolenaar2e693a82019-10-16 22:35:02 +02009824 w blocked on waiting, e.g. ch_evalexpr(), ch_read() and
Bram Moolenaare46a4402020-06-30 20:38:27 +02009825 ch_readraw() when reading json
9826 S not triggering SafeState or SafeStateAgain, e.g. after
9827 |f| or a count
Bram Moolenaar589edb32019-09-20 14:38:13 +02009828 c callback invoked, including timer (repeats for
9829 recursiveness up to "ccc")
9830 s screen has scrolled for messages
Bram Moolenaar0e57dd82019-09-16 22:56:03 +02009831
Bram Moolenaar81edd172016-04-14 13:51:37 +02009832str2float({expr}) *str2float()*
Bram Moolenaar446cb832008-06-24 21:56:24 +00009833 Convert String {expr} to a Float. This mostly works the same
9834 as when using a floating point number in an expression, see
9835 |floating-point-format|. But it's a bit more permissive.
9836 E.g., "1e40" is accepted, while in an expression you need to
Bram Moolenaard47d5222018-12-09 20:43:55 +01009837 write "1.0e40". The hexadecimal form "0x123" is also
9838 accepted, but not others, like binary or octal.
Bram Moolenaar446cb832008-06-24 21:56:24 +00009839 Text after the number is silently ignored.
9840 The decimal point is always '.', no matter what the locale is
9841 set to. A comma ends the number: "12,345.67" is converted to
9842 12.0. You can strip out thousands separators with
9843 |substitute()|: >
9844 let f = str2float(substitute(text, ',', '', 'g'))
Bram Moolenaar93cf85f2019-08-17 21:36:28 +02009845<
9846 Can also be used as a |method|: >
9847 let f = text->substitute(',', '', 'g')->str2float()
9848<
9849 {only available when compiled with the |+float| feature}
Bram Moolenaar446cb832008-06-24 21:56:24 +00009850
Bram Moolenaar9d401282019-04-06 13:18:12 +02009851str2list({expr} [, {utf8}]) *str2list()*
9852 Return a list containing the number values which represent
9853 each character in String {expr}. Examples: >
9854 str2list(" ") returns [32]
9855 str2list("ABC") returns [65, 66, 67]
9856< |list2str()| does the opposite.
9857
9858 When {utf8} is omitted or zero, the current 'encoding' is used.
9859 With {utf8} set to 1, always treat the String as utf-8
9860 characters. With utf-8 composing characters are handled
9861 properly: >
9862 str2list("á") returns [97, 769]
Bram Moolenaar446cb832008-06-24 21:56:24 +00009863
Bram Moolenaara74e4942019-08-04 17:35:53 +02009864< Can also be used as a |method|: >
9865 GetString()->str2list()
9866
9867
Bram Moolenaar60a8de22019-09-15 14:33:22 +02009868str2nr({expr} [, {base} [, {quoted}]]) *str2nr()*
Bram Moolenaar97b2ad32006-03-18 21:40:56 +00009869 Convert string {expr} to a number.
Bram Moolenaarfa735342016-01-03 22:14:44 +01009870 {base} is the conversion base, it can be 2, 8, 10 or 16.
Bram Moolenaar60a8de22019-09-15 14:33:22 +02009871 When {quoted} is present and non-zero then embedded single
9872 quotes are ignored, thus "1'000'000" is a million.
Bram Moolenaara74e4942019-08-04 17:35:53 +02009873
Bram Moolenaar97b2ad32006-03-18 21:40:56 +00009874 When {base} is omitted base 10 is used. This also means that
9875 a leading zero doesn't cause octal conversion to be used, as
Bram Moolenaara74e4942019-08-04 17:35:53 +02009876 with the default String to Number conversion. Example: >
Bram Moolenaar2e693a82019-10-16 22:35:02 +02009877 let nr = str2nr('0123')
Bram Moolenaara74e4942019-08-04 17:35:53 +02009878<
Bram Moolenaar97b2ad32006-03-18 21:40:56 +00009879 When {base} is 16 a leading "0x" or "0X" is ignored. With a
Bram Moolenaarfa735342016-01-03 22:14:44 +01009880 different base the result will be zero. Similarly, when
Bram Moolenaarc17e66c2020-06-02 21:38:22 +02009881 {base} is 8 a leading "0", "0o" or "0O" is ignored, and when
9882 {base} is 2 a leading "0b" or "0B" is ignored.
Bram Moolenaar97b2ad32006-03-18 21:40:56 +00009883 Text after the number is silently ignored.
Bram Moolenaarc9b4b052006-04-30 18:54:39 +00009884
Bram Moolenaarf6ed61e2019-09-07 19:05:09 +02009885 Can also be used as a |method|: >
9886 GetText()->str2nr()
9887
9888strcharpart({src}, {start} [, {len}]) *strcharpart()*
9889 Like |strpart()| but using character index and length instead
9890 of byte index and length.
9891 When a character index is used where a character does not
9892 exist it is assumed to be one character. For example: >
9893 strcharpart('abc', -1, 2)
9894< results in 'a'.
9895
9896 Can also be used as a |method|: >
9897 GetText()->strcharpart(5)
Bram Moolenaar97b2ad32006-03-18 21:40:56 +00009898
Bram Moolenaar979243b2015-06-26 19:35:49 +02009899strchars({expr} [, {skipcc}]) *strchars()*
Bram Moolenaar72597a52010-07-18 15:31:08 +02009900 The result is a Number, which is the number of characters
Bram Moolenaar979243b2015-06-26 19:35:49 +02009901 in String {expr}.
9902 When {skipcc} is omitted or zero, composing characters are
9903 counted separately.
9904 When {skipcc} set to 1, Composing characters are ignored.
Bram Moolenaardc536092010-07-18 15:45:49 +02009905 Also see |strlen()|, |strdisplaywidth()| and |strwidth()|.
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01009906
Bram Moolenaar86ae7202015-07-10 19:31:35 +02009907 {skipcc} is only available after 7.4.755. For backward
9908 compatibility, you can define a wrapper function: >
9909 if has("patch-7.4.755")
9910 function s:strchars(str, skipcc)
9911 return strchars(a:str, a:skipcc)
9912 endfunction
9913 else
9914 function s:strchars(str, skipcc)
9915 if a:skipcc
9916 return strlen(substitute(a:str, ".", "x", "g"))
9917 else
9918 return strchars(a:str)
9919 endif
9920 endfunction
9921 endif
9922<
Bram Moolenaarf6ed61e2019-09-07 19:05:09 +02009923 Can also be used as a |method|: >
9924 GetText()->strchars()
Bram Moolenaar86ae7202015-07-10 19:31:35 +02009925
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01009926strdisplaywidth({expr} [, {col}]) *strdisplaywidth()*
Bram Moolenaardc536092010-07-18 15:45:49 +02009927 The result is a Number, which is the number of display cells
Bram Moolenaar4c92e752019-02-17 21:18:32 +01009928 String {expr} occupies on the screen when it starts at {col}
9929 (first column is zero). When {col} is omitted zero is used.
9930 Otherwise it is the screen column where to start. This
9931 matters for Tab characters.
Bram Moolenaar4d32c2d2010-07-18 22:10:01 +02009932 The option settings of the current window are used. This
9933 matters for anything that's displayed differently, such as
9934 'tabstop' and 'display'.
Bram Moolenaardc536092010-07-18 15:45:49 +02009935 When {expr} contains characters with East Asian Width Class
9936 Ambiguous, this function's return value depends on 'ambiwidth'.
9937 Also see |strlen()|, |strwidth()| and |strchars()|.
Bram Moolenaar72597a52010-07-18 15:31:08 +02009938
Bram Moolenaarf6ed61e2019-09-07 19:05:09 +02009939 Can also be used as a |method|: >
9940 GetText()->strdisplaywidth()
9941
Bram Moolenaar071d4272004-06-13 20:20:40 +00009942strftime({format} [, {time}]) *strftime()*
9943 The result is a String, which is a formatted date and time, as
9944 specified by the {format} string. The given {time} is used,
9945 or the current time if no time is given. The accepted
9946 {format} depends on your system, thus this is not portable!
9947 See the manual page of the C function strftime() for the
9948 format. The maximum length of the result is 80 characters.
Bram Moolenaar10455d42019-11-21 15:36:18 +01009949 See also |localtime()|, |getftime()| and |strptime()|.
Bram Moolenaar071d4272004-06-13 20:20:40 +00009950 The language can be changed with the |:language| command.
9951 Examples: >
9952 :echo strftime("%c") Sun Apr 27 11:49:23 1997
9953 :echo strftime("%Y %b %d %X") 1997 Apr 27 11:53:25
9954 :echo strftime("%y%m%d %T") 970427 11:53:55
9955 :echo strftime("%H:%M") 11:55
9956 :echo strftime("%c", getftime("file.c"))
9957 Show mod time of file.c.
Bram Moolenaara14de3d2005-01-07 21:48:26 +00009958< Not available on all systems. To check use: >
9959 :if exists("*strftime")
9960
Bram Moolenaarf6ed61e2019-09-07 19:05:09 +02009961< Can also be used as a |method|: >
9962 GetFormat()->strftime()
9963
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009964strgetchar({str}, {index}) *strgetchar()*
9965 Get character {index} from {str}. This uses a character
9966 index, not a byte index. Composing characters are considered
9967 separate characters here.
9968 Also see |strcharpart()| and |strchars()|.
9969
Bram Moolenaarf6ed61e2019-09-07 19:05:09 +02009970 Can also be used as a |method|: >
9971 GetText()->strgetchar(5)
9972
Bram Moolenaar8f999f12005-01-25 22:12:55 +00009973stridx({haystack}, {needle} [, {start}]) *stridx()*
9974 The result is a Number, which gives the byte index in
9975 {haystack} of the first occurrence of the String {needle}.
Bram Moolenaar677ee682005-01-27 14:41:15 +00009976 If {start} is specified, the search starts at index {start}.
9977 This can be used to find a second match: >
Bram Moolenaar81af9252010-12-10 20:35:50 +01009978 :let colon1 = stridx(line, ":")
9979 :let colon2 = stridx(line, ":", colon1 + 1)
Bram Moolenaar677ee682005-01-27 14:41:15 +00009980< The search is done case-sensitive.
Bram Moolenaare2cc9702005-03-15 22:43:58 +00009981 For pattern searches use |match()|.
Bram Moolenaar8f999f12005-01-25 22:12:55 +00009982 -1 is returned if the {needle} does not occur in {haystack}.
Bram Moolenaar677ee682005-01-27 14:41:15 +00009983 See also |strridx()|.
9984 Examples: >
Bram Moolenaar071d4272004-06-13 20:20:40 +00009985 :echo stridx("An Example", "Example") 3
9986 :echo stridx("Starting point", "Start") 0
9987 :echo stridx("Starting point", "start") -1
Bram Moolenaarc9b4b052006-04-30 18:54:39 +00009988< *strstr()* *strchr()*
Bram Moolenaar05159a02005-02-26 23:04:13 +00009989 stridx() works similar to the C function strstr(). When used
9990 with a single character it works similar to strchr().
9991
Bram Moolenaarf6ed61e2019-09-07 19:05:09 +02009992 Can also be used as a |method|: >
9993 GetHaystack()->stridx(needle)
Bram Moolenaar2e693a82019-10-16 22:35:02 +02009994<
Bram Moolenaard7ee7ce2005-01-03 21:02:03 +00009995 *string()*
Bram Moolenaar5f2bb9f2005-01-11 21:29:04 +00009996string({expr}) Return {expr} converted to a String. If {expr} is a Number,
Bram Moolenaar0d17f0d2019-01-22 22:20:38 +01009997 Float, String, Blob or a composition of them, then the result
9998 can be parsed back with |eval()|.
Bram Moolenaard7ee7ce2005-01-03 21:02:03 +00009999 {expr} type result ~
Bram Moolenaar4f3f6682016-03-26 23:01:59 +010010000 String 'string' (single quotes are doubled)
Bram Moolenaar5f2bb9f2005-01-11 21:29:04 +000010001 Number 123
Bram Moolenaar446cb832008-06-24 21:56:24 +000010002 Float 123.123456 or 1.123456e8
Bram Moolenaard8b02732005-01-14 21:48:43 +000010003 Funcref function('name')
Bram Moolenaar0d17f0d2019-01-22 22:20:38 +010010004 Blob 0z00112233.44556677.8899
Bram Moolenaar5f2bb9f2005-01-11 21:29:04 +000010005 List [item, item]
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +000010006 Dictionary {key: value, key: value}
Bram Moolenaar4f3f6682016-03-26 23:01:59 +010010007
Bram Moolenaare46a4402020-06-30 20:38:27 +020010008 When a |List| or |Dictionary| has a recursive reference it is
Bram Moolenaar4f3f6682016-03-26 23:01:59 +010010009 replaced by "[...]" or "{...}". Using eval() on the result
10010 will then fail.
10011
Bram Moolenaarac92e252019-08-03 21:58:38 +020010012 Can also be used as a |method|: >
10013 mylist->string()
10014
10015< Also see |strtrans()|.
Bram Moolenaard7ee7ce2005-01-03 21:02:03 +000010016
Bram Moolenaar071d4272004-06-13 20:20:40 +000010017 *strlen()*
10018strlen({expr}) The result is a Number, which is the length of the String
Bram Moolenaare344bea2005-09-01 20:46:49 +000010019 {expr} in bytes.
Bram Moolenaard7ee7ce2005-01-03 21:02:03 +000010020 If the argument is a Number it is first converted to a String.
10021 For other types an error is given.
Bram Moolenaar6c53fca2020-08-23 17:34:46 +020010022 If you want to count the number of multibyte characters use
Bram Moolenaar641e48c2015-06-25 16:09:26 +020010023 |strchars()|.
10024 Also see |len()|, |strdisplaywidth()| and |strwidth()|.
Bram Moolenaar071d4272004-06-13 20:20:40 +000010025
Bram Moolenaara74e4942019-08-04 17:35:53 +020010026 Can also be used as a |method|: >
10027 GetString()->strlen()
10028
Bram Moolenaar6c53fca2020-08-23 17:34:46 +020010029strpart({src}, {start} [, {len} [, {chars}]]) *strpart()*
Bram Moolenaar071d4272004-06-13 20:20:40 +000010030 The result is a String, which is part of {src}, starting from
Bram Moolenaar9372a112005-12-06 19:59:18 +000010031 byte {start}, with the byte length {len}.
Bram Moolenaar6c53fca2020-08-23 17:34:46 +020010032 When {chars} is present and TRUE then {len} is the number of
10033 characters positions (composing characters are not counted
10034 separately, thus "1" means one base character and any
10035 following composing characters).
10036 To count {start} as characters instead of bytes use
10037 |strcharpart()|.
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010038
10039 When bytes are selected which do not exist, this doesn't
10040 result in an error, the bytes are simply omitted.
Bram Moolenaar071d4272004-06-13 20:20:40 +000010041 If {len} is missing, the copy continues from {start} till the
10042 end of the {src}. >
10043 strpart("abcdefg", 3, 2) == "de"
10044 strpart("abcdefg", -2, 4) == "ab"
10045 strpart("abcdefg", 5, 4) == "fg"
Bram Moolenaar446cb832008-06-24 21:56:24 +000010046 strpart("abcdefg", 3) == "defg"
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010047
Bram Moolenaar071d4272004-06-13 20:20:40 +000010048< Note: To get the first character, {start} must be 0. For
Bram Moolenaar6c53fca2020-08-23 17:34:46 +020010049 example, to get the character under the cursor: >
10050 strpart(getline("."), col(".") - 1, 1, v:true)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010051<
Bram Moolenaarf6ed61e2019-09-07 19:05:09 +020010052 Can also be used as a |method|: >
10053 GetText()->strpart(5)
10054
Bram Moolenaar10455d42019-11-21 15:36:18 +010010055strptime({format}, {timestring}) *strptime()*
10056 The result is a Number, which is a unix timestamp representing
10057 the date and time in {timestring}, which is expected to match
10058 the format specified in {format}.
10059
10060 The accepted {format} depends on your system, thus this is not
10061 portable! See the manual page of the C function strptime()
10062 for the format. Especially avoid "%c". The value of $TZ also
10063 matters.
10064
10065 If the {timestring} cannot be parsed with {format} zero is
10066 returned. If you do not know the format of {timestring} you
10067 can try different {format} values until you get a non-zero
10068 result.
10069
10070 See also |strftime()|.
10071 Examples: >
10072 :echo strptime("%Y %b %d %X", "1997 Apr 27 11:49:23")
10073< 862156163 >
10074 :echo strftime("%c", strptime("%y%m%d %T", "970427 11:53:55"))
10075< Sun Apr 27 11:53:55 1997 >
10076 :echo strftime("%c", strptime("%Y%m%d%H%M%S", "19970427115355") + 3600)
10077< Sun Apr 27 12:53:55 1997
10078
10079 Not available on all systems. To check use: >
10080 :if exists("*strptime")
10081
10082
Bram Moolenaar677ee682005-01-27 14:41:15 +000010083strridx({haystack}, {needle} [, {start}]) *strridx()*
10084 The result is a Number, which gives the byte index in
10085 {haystack} of the last occurrence of the String {needle}.
10086 When {start} is specified, matches beyond this index are
10087 ignored. This can be used to find a match before a previous
10088 match: >
10089 :let lastcomma = strridx(line, ",")
10090 :let comma2 = strridx(line, ",", lastcomma - 1)
10091< The search is done case-sensitive.
Bram Moolenaar8f999f12005-01-25 22:12:55 +000010092 For pattern searches use |match()|.
10093 -1 is returned if the {needle} does not occur in {haystack}.
Bram Moolenaard4755bb2004-09-02 19:12:26 +000010094 If the {needle} is empty the length of {haystack} is returned.
Bram Moolenaar402d2fe2005-04-15 21:00:38 +000010095 See also |stridx()|. Examples: >
Bram Moolenaar071d4272004-06-13 20:20:40 +000010096 :echo strridx("an angry armadillo", "an") 3
Bram Moolenaarc9b4b052006-04-30 18:54:39 +000010097< *strrchr()*
Bram Moolenaar05159a02005-02-26 23:04:13 +000010098 When used with a single character it works similar to the C
10099 function strrchr().
10100
Bram Moolenaarf6ed61e2019-09-07 19:05:09 +020010101 Can also be used as a |method|: >
10102 GetHaystack()->strridx(needle)
10103
Bram Moolenaar071d4272004-06-13 20:20:40 +000010104strtrans({expr}) *strtrans()*
10105 The result is a String, which is {expr} with all unprintable
10106 characters translated into printable characters |'isprint'|.
10107 Like they are shown in a window. Example: >
10108 echo strtrans(@a)
10109< This displays a newline in register a as "^@" instead of
10110 starting a new line.
10111
Bram Moolenaara74e4942019-08-04 17:35:53 +020010112 Can also be used as a |method|: >
10113 GetString()->strtrans()
10114
Bram Moolenaar72597a52010-07-18 15:31:08 +020010115strwidth({expr}) *strwidth()*
10116 The result is a Number, which is the number of display cells
10117 String {expr} occupies. A Tab character is counted as one
Bram Moolenaardc536092010-07-18 15:45:49 +020010118 cell, alternatively use |strdisplaywidth()|.
Bram Moolenaar72597a52010-07-18 15:31:08 +020010119 When {expr} contains characters with East Asian Width Class
10120 Ambiguous, this function's return value depends on 'ambiwidth'.
Bram Moolenaardc536092010-07-18 15:45:49 +020010121 Also see |strlen()|, |strdisplaywidth()| and |strchars()|.
Bram Moolenaar72597a52010-07-18 15:31:08 +020010122
Bram Moolenaara74e4942019-08-04 17:35:53 +020010123 Can also be used as a |method|: >
10124 GetString()->strwidth()
10125
Bram Moolenaarb0d45e72017-11-05 18:19:24 +010010126submatch({nr} [, {list}]) *submatch()* *E935*
Bram Moolenaar251e1912011-06-19 05:09:16 +020010127 Only for an expression in a |:substitute| command or
10128 substitute() function.
10129 Returns the {nr}'th submatch of the matched text. When {nr}
10130 is 0 the whole matched text is returned.
Bram Moolenaar41571762014-04-02 19:00:58 +020010131 Note that a NL in the string can stand for a line break of a
10132 multi-line match or a NUL character in the text.
Bram Moolenaar251e1912011-06-19 05:09:16 +020010133 Also see |sub-replace-expression|.
Bram Moolenaar41571762014-04-02 19:00:58 +020010134
Bram Moolenaarb0d45e72017-11-05 18:19:24 +010010135 If {list} is present and non-zero then submatch() returns
10136 a list of strings, similar to |getline()| with two arguments.
Bram Moolenaar41571762014-04-02 19:00:58 +020010137 NL characters in the text represent NUL characters in the
10138 text.
10139 Only returns more than one item for |:substitute|, inside
10140 |substitute()| this list will always contain one or zero
10141 items, since there are no real line breaks.
10142
Bram Moolenaar6100d022016-10-02 16:51:57 +020010143 When substitute() is used recursively only the submatches in
10144 the current (deepest) call can be obtained.
10145
Bram Moolenaar2f058492017-11-30 20:27:52 +010010146 Examples: >
Bram Moolenaar071d4272004-06-13 20:20:40 +000010147 :s/\d\+/\=submatch(0) + 1/
Bram Moolenaar2f058492017-11-30 20:27:52 +010010148 :echo substitute(text, '\d\+', '\=submatch(0) + 1', '')
Bram Moolenaar071d4272004-06-13 20:20:40 +000010149< This finds the first number in the line and adds one to it.
10150 A line break is included as a newline character.
10151
Bram Moolenaarf6ed61e2019-09-07 19:05:09 +020010152 Can also be used as a |method|: >
10153 GetNr()->submatch()
10154
Bram Moolenaar071d4272004-06-13 20:20:40 +000010155substitute({expr}, {pat}, {sub}, {flags}) *substitute()*
10156 The result is a String, which is a copy of {expr}, in which
Bram Moolenaar251e1912011-06-19 05:09:16 +020010157 the first match of {pat} is replaced with {sub}.
10158 When {flags} is "g", all matches of {pat} in {expr} are
10159 replaced. Otherwise {flags} should be "".
Bram Moolenaarb0d45e72017-11-05 18:19:24 +010010160
Bram Moolenaar251e1912011-06-19 05:09:16 +020010161 This works like the ":substitute" command (without any flags).
10162 But the matching with {pat} is always done like the 'magic'
10163 option is set and 'cpoptions' is empty (to make scripts
Bram Moolenaar2df58b42012-11-28 18:21:11 +010010164 portable). 'ignorecase' is still relevant, use |/\c| or |/\C|
10165 if you want to ignore or match case and ignore 'ignorecase'.
10166 'smartcase' is not used. See |string-match| for how {pat} is
10167 used.
Bram Moolenaar251e1912011-06-19 05:09:16 +020010168
10169 A "~" in {sub} is not replaced with the previous {sub}.
Bram Moolenaar071d4272004-06-13 20:20:40 +000010170 Note that some codes in {sub} have a special meaning
Bram Moolenaar58b85342016-08-14 19:54:54 +020010171 |sub-replace-special|. For example, to replace something with
Bram Moolenaar071d4272004-06-13 20:20:40 +000010172 "\n" (two characters), use "\\\\n" or '\\n'.
Bram Moolenaar251e1912011-06-19 05:09:16 +020010173
Bram Moolenaar071d4272004-06-13 20:20:40 +000010174 When {pat} does not match in {expr}, {expr} is returned
10175 unmodified.
Bram Moolenaar251e1912011-06-19 05:09:16 +020010176
Bram Moolenaar071d4272004-06-13 20:20:40 +000010177 Example: >
Bram Moolenaardf48fb42016-07-22 21:50:18 +020010178 :let &path = substitute(&path, ",\\=[^,]*$", "", "")
Bram Moolenaar071d4272004-06-13 20:20:40 +000010179< This removes the last component of the 'path' option. >
Bram Moolenaardf48fb42016-07-22 21:50:18 +020010180 :echo substitute("testing", ".*", "\\U\\0", "")
Bram Moolenaar071d4272004-06-13 20:20:40 +000010181< results in "TESTING".
Bram Moolenaar251e1912011-06-19 05:09:16 +020010182
10183 When {sub} starts with "\=", the remainder is interpreted as
10184 an expression. See |sub-replace-expression|. Example: >
Bram Moolenaardf48fb42016-07-22 21:50:18 +020010185 :echo substitute(s, '%\(\x\x\)',
Bram Moolenaar20f90cf2011-05-19 12:22:51 +020010186 \ '\=nr2char("0x" . submatch(1))', 'g')
Bram Moolenaar071d4272004-06-13 20:20:40 +000010187
Bram Moolenaardf48fb42016-07-22 21:50:18 +020010188< When {sub} is a Funcref that function is called, with one
10189 optional argument. Example: >
10190 :echo substitute(s, '%\(\x\x\)', SubNr, 'g')
10191< The optional argument is a list which contains the whole
Bram Moolenaar58b85342016-08-14 19:54:54 +020010192 matched string and up to nine submatches, like what
10193 |submatch()| returns. Example: >
10194 :echo substitute(s, '%\(\x\x\)', {m -> '0x' . m[1]}, 'g')
Bram Moolenaardf48fb42016-07-22 21:50:18 +020010195
Bram Moolenaara74e4942019-08-04 17:35:53 +020010196< Can also be used as a |method|: >
10197 GetString()->substitute(pat, sub, flags)
10198
Bram Moolenaar20aac6c2018-09-02 21:07:30 +020010199swapinfo({fname}) *swapinfo()*
Bram Moolenaar00f123a2018-08-21 20:28:54 +020010200 The result is a dictionary, which holds information about the
10201 swapfile {fname}. The available fields are:
Bram Moolenaar95bafa22018-10-02 13:26:25 +020010202 version Vim version
Bram Moolenaar00f123a2018-08-21 20:28:54 +020010203 user user name
10204 host host name
10205 fname original file name
Bram Moolenaar95bafa22018-10-02 13:26:25 +020010206 pid PID of the Vim process that created the swap
Bram Moolenaar00f123a2018-08-21 20:28:54 +020010207 file
10208 mtime last modification time in seconds
10209 inode Optional: INODE number of the file
Bram Moolenaar47ad5652018-08-21 21:09:07 +020010210 dirty 1 if file was modified, 0 if not
Bram Moolenaarfc65cab2018-08-28 22:58:02 +020010211 Note that "user" and "host" are truncated to at most 39 bytes.
Bram Moolenaar00f123a2018-08-21 20:28:54 +020010212 In case of failure an "error" item is added with the reason:
10213 Cannot open file: file not found or in accessible
10214 Cannot read file: cannot read first block
Bram Moolenaar47ad5652018-08-21 21:09:07 +020010215 Not a swap file: does not contain correct block ID
10216 Magic number mismatch: Info in first block is invalid
Bram Moolenaar00f123a2018-08-21 20:28:54 +020010217
Bram Moolenaarf6ed61e2019-09-07 19:05:09 +020010218 Can also be used as a |method|: >
10219 GetFilename()->swapinfo()
10220
Bram Moolenaar110bd602018-09-16 18:46:59 +020010221swapname({expr}) *swapname()*
10222 The result is the swap file path of the buffer {expr}.
10223 For the use of {expr}, see |bufname()| above.
10224 If buffer {expr} is the current buffer, the result is equal to
Bram Moolenaare7b1ea02020-08-07 19:54:59 +020010225 |:swapname| (unless there is no swap file).
Bram Moolenaar110bd602018-09-16 18:46:59 +020010226 If buffer {expr} has no swap file, returns an empty string.
10227
Bram Moolenaarf6ed61e2019-09-07 19:05:09 +020010228 Can also be used as a |method|: >
10229 GetBufname()->swapname()
10230
Bram Moolenaar47136d72004-10-12 20:02:24 +000010231synID({lnum}, {col}, {trans}) *synID()*
Bram Moolenaar071d4272004-06-13 20:20:40 +000010232 The result is a Number, which is the syntax ID at the position
Bram Moolenaar47136d72004-10-12 20:02:24 +000010233 {lnum} and {col} in the current window.
Bram Moolenaar071d4272004-06-13 20:20:40 +000010234 The syntax ID can be used with |synIDattr()| and
10235 |synIDtrans()| to obtain syntax information about text.
Bram Moolenaarce0842a2005-07-18 21:58:11 +000010236
Bram Moolenaar47136d72004-10-12 20:02:24 +000010237 {col} is 1 for the leftmost column, {lnum} is 1 for the first
Bram Moolenaarce0842a2005-07-18 21:58:11 +000010238 line. 'synmaxcol' applies, in a longer line zero is returned.
Bram Moolenaarca635012015-09-25 20:34:21 +020010239 Note that when the position is after the last character,
10240 that's where the cursor can be in Insert mode, synID() returns
10241 zero.
Bram Moolenaarce0842a2005-07-18 21:58:11 +000010242
Bram Moolenaar79815f12016-07-09 17:07:29 +020010243 When {trans} is |TRUE|, transparent items are reduced to the
Bram Moolenaar58b85342016-08-14 19:54:54 +020010244 item that they reveal. This is useful when wanting to know
Bram Moolenaar79815f12016-07-09 17:07:29 +020010245 the effective color. When {trans} is |FALSE|, the transparent
Bram Moolenaar071d4272004-06-13 20:20:40 +000010246 item is returned. This is useful when wanting to know which
10247 syntax item is effective (e.g. inside parens).
10248 Warning: This function can be very slow. Best speed is
10249 obtained by going through the file in forward direction.
10250
10251 Example (echoes the name of the syntax item under the cursor): >
10252 :echo synIDattr(synID(line("."), col("."), 1), "name")
10253<
Bram Moolenaar7510fe72010-07-25 12:46:44 +020010254
Bram Moolenaar071d4272004-06-13 20:20:40 +000010255synIDattr({synID}, {what} [, {mode}]) *synIDattr()*
10256 The result is a String, which is the {what} attribute of
10257 syntax ID {synID}. This can be used to obtain information
10258 about a syntax item.
10259 {mode} can be "gui", "cterm" or "term", to get the attributes
Bram Moolenaar58b85342016-08-14 19:54:54 +020010260 for that mode. When {mode} is omitted, or an invalid value is
Bram Moolenaar071d4272004-06-13 20:20:40 +000010261 used, the attributes for the currently active highlighting are
10262 used (GUI, cterm or term).
10263 Use synIDtrans() to follow linked highlight groups.
10264 {what} result
10265 "name" the name of the syntax item
10266 "fg" foreground color (GUI: color name used to set
10267 the color, cterm: color number as a string,
10268 term: empty string)
Bram Moolenaar6f507d62008-11-28 10:16:05 +000010269 "bg" background color (as with "fg")
Bram Moolenaar12682fd2010-03-10 13:43:49 +010010270 "font" font name (only available in the GUI)
10271 |highlight-font|
Bram Moolenaar6f507d62008-11-28 10:16:05 +000010272 "sp" special color (as with "fg") |highlight-guisp|
Bram Moolenaar071d4272004-06-13 20:20:40 +000010273 "fg#" like "fg", but for the GUI and the GUI is
10274 running the name in "#RRGGBB" form
10275 "bg#" like "fg#" for "bg"
Bram Moolenaar6f507d62008-11-28 10:16:05 +000010276 "sp#" like "fg#" for "sp"
Bram Moolenaar071d4272004-06-13 20:20:40 +000010277 "bold" "1" if bold
10278 "italic" "1" if italic
10279 "reverse" "1" if reverse
10280 "inverse" "1" if inverse (= reverse)
Bram Moolenaar12682fd2010-03-10 13:43:49 +010010281 "standout" "1" if standout
Bram Moolenaar071d4272004-06-13 20:20:40 +000010282 "underline" "1" if underlined
Bram Moolenaare2cc9702005-03-15 22:43:58 +000010283 "undercurl" "1" if undercurled
Bram Moolenaarcf4b00c2017-09-02 18:33:56 +020010284 "strike" "1" if strikethrough
Bram Moolenaar071d4272004-06-13 20:20:40 +000010285
10286 Example (echoes the color of the syntax item under the
10287 cursor): >
10288 :echo synIDattr(synIDtrans(synID(line("."), col("."), 1)), "fg")
10289<
Bram Moolenaara74e4942019-08-04 17:35:53 +020010290 Can also be used as a |method|: >
10291 :echo synID(line("."), col("."), 1)->synIDtrans()->synIDattr("fg")
10292
10293
Bram Moolenaar071d4272004-06-13 20:20:40 +000010294synIDtrans({synID}) *synIDtrans()*
10295 The result is a Number, which is the translated syntax ID of
10296 {synID}. This is the syntax group ID of what is being used to
10297 highlight the character. Highlight links given with
10298 ":highlight link" are followed.
10299
Bram Moolenaara74e4942019-08-04 17:35:53 +020010300 Can also be used as a |method|: >
10301 :echo synID(line("."), col("."), 1)->synIDtrans()->synIDattr("fg")
10302
Bram Moolenaar483c5d82010-10-20 18:45:33 +020010303synconcealed({lnum}, {col}) *synconcealed()*
Bram Moolenaare46a4402020-06-30 20:38:27 +020010304 The result is a |List| with currently three items:
Bram Moolenaar4d785892017-06-22 22:00:50 +020010305 1. The first item in the list is 0 if the character at the
10306 position {lnum} and {col} is not part of a concealable
10307 region, 1 if it is.
10308 2. The second item in the list is a string. If the first item
10309 is 1, the second item contains the text which will be
10310 displayed in place of the concealed text, depending on the
10311 current setting of 'conceallevel' and 'listchars'.
Bram Moolenaarcc0750d2017-06-24 22:29:24 +020010312 3. The third and final item in the list is a number
10313 representing the specific syntax region matched in the
10314 line. When the character is not concealed the value is
10315 zero. This allows detection of the beginning of a new
10316 concealable region if there are two consecutive regions
10317 with the same replacement character. For an example, if
10318 the text is "123456" and both "23" and "45" are concealed
Bram Moolenaar95bafa22018-10-02 13:26:25 +020010319 and replaced by the character "X", then:
Bram Moolenaarcc0750d2017-06-24 22:29:24 +020010320 call returns ~
Bram Moolenaarc572da52017-08-27 16:52:01 +020010321 synconcealed(lnum, 1) [0, '', 0]
10322 synconcealed(lnum, 2) [1, 'X', 1]
10323 synconcealed(lnum, 3) [1, 'X', 1]
10324 synconcealed(lnum, 4) [1, 'X', 2]
10325 synconcealed(lnum, 5) [1, 'X', 2]
10326 synconcealed(lnum, 6) [0, '', 0]
Bram Moolenaar483c5d82010-10-20 18:45:33 +020010327
10328
Bram Moolenaar9d188ab2008-01-10 21:24:39 +000010329synstack({lnum}, {col}) *synstack()*
10330 Return a |List|, which is the stack of syntax items at the
10331 position {lnum} and {col} in the current window. Each item in
10332 the List is an ID like what |synID()| returns.
Bram Moolenaar9d188ab2008-01-10 21:24:39 +000010333 The first item in the List is the outer region, following are
10334 items contained in that one. The last one is what |synID()|
10335 returns, unless not the whole item is highlighted or it is a
10336 transparent item.
10337 This function is useful for debugging a syntax file.
10338 Example that shows the syntax stack under the cursor: >
10339 for id in synstack(line("."), col("."))
10340 echo synIDattr(id, "name")
10341 endfor
Bram Moolenaar0bc380a2010-07-10 13:52:13 +020010342< When the position specified with {lnum} and {col} is invalid
10343 nothing is returned. The position just after the last
10344 character in a line and the first column in an empty line are
10345 valid positions.
Bram Moolenaar9d188ab2008-01-10 21:24:39 +000010346
Bram Moolenaarc0197e22004-09-13 20:26:32 +000010347system({expr} [, {input}]) *system()* *E677*
Bram Moolenaar39c29ed2014-04-05 19:44:40 +020010348 Get the output of the shell command {expr} as a string. See
Bram Moolenaare46a4402020-06-30 20:38:27 +020010349 |systemlist()| to get the output as a |List|.
Bram Moolenaar57ebe6e2014-04-05 18:55:46 +020010350
Bram Moolenaarb0d45e72017-11-05 18:19:24 +010010351 When {input} is given and is a string this string is written
10352 to a file and passed as stdin to the command. The string is
10353 written as-is, you need to take care of using the correct line
Bram Moolenaar57ebe6e2014-04-05 18:55:46 +020010354 separators yourself.
10355 If {input} is given and is a |List| it is written to the file
10356 in a way |writefile()| does with {binary} set to "b" (i.e.
10357 with a newline between each list item with newlines inside
Bram Moolenaar12c44922017-01-08 13:26:03 +010010358 list items converted to NULs).
10359 When {input} is given and is a number that is a valid id for
10360 an existing buffer then the content of the buffer is written
10361 to the file line by line, each line terminated by a NL and
10362 NULs characters where the text has a NL.
Bram Moolenaar069c1e72016-07-15 21:25:08 +020010363
10364 Pipes are not used, the 'shelltemp' option is not used.
Bram Moolenaar57ebe6e2014-04-05 18:55:46 +020010365
Bram Moolenaar04186092016-08-29 21:55:35 +020010366 When prepended by |:silent| the terminal will not be set to
Bram Moolenaar52a72462014-08-29 15:53:52 +020010367 cooked mode. This is meant to be used for commands that do
10368 not need the user to type. It avoids stray characters showing
10369 up on the screen which require |CTRL-L| to remove. >
10370 :silent let f = system('ls *.vim')
10371<
Bram Moolenaarb0d45e72017-11-05 18:19:24 +010010372 Note: Use |shellescape()| or |::S| with |expand()| or
10373 |fnamemodify()| to escape special characters in a command
10374 argument. Newlines in {expr} may cause the command to fail.
10375 The characters in 'shellquote' and 'shellxquote' may also
Bram Moolenaar26df0922014-02-23 23:39:13 +010010376 cause trouble.
Bram Moolenaar071d4272004-06-13 20:20:40 +000010377 This is not to be used for interactive commands.
Bram Moolenaar071d4272004-06-13 20:20:40 +000010378
Bram Moolenaar05bb9532008-07-04 09:44:11 +000010379 The result is a String. Example: >
10380 :let files = system("ls " . shellescape(expand('%:h')))
Bram Moolenaar26df0922014-02-23 23:39:13 +010010381 :let files = system('ls ' . expand('%:h:S'))
Bram Moolenaar071d4272004-06-13 20:20:40 +000010382
10383< To make the result more system-independent, the shell output
10384 is filtered to replace <CR> with <NL> for Macintosh, and
10385 <CR><NL> with <NL> for DOS-like systems.
Bram Moolenaar9d98fe92013-08-03 18:35:36 +020010386 To avoid the string being truncated at a NUL, all NUL
10387 characters are replaced with SOH (0x01).
10388
Bram Moolenaar071d4272004-06-13 20:20:40 +000010389 The command executed is constructed using several options:
10390 'shell' 'shellcmdflag' 'shellxquote' {expr} 'shellredir' {tmp} 'shellxquote'
10391 ({tmp} is an automatically generated file name).
Bram Moolenaar6f345a12019-12-17 21:27:18 +010010392 For Unix, braces are put around {expr} to allow for
Bram Moolenaar071d4272004-06-13 20:20:40 +000010393 concatenated commands.
10394
Bram Moolenaar433f7c82006-03-21 21:29:36 +000010395 The command will be executed in "cooked" mode, so that a
10396 CTRL-C will interrupt the command (on Unix at least).
10397
Bram Moolenaar071d4272004-06-13 20:20:40 +000010398 The resulting error code can be found in |v:shell_error|.
10399 This function will fail in |restricted-mode|.
Bram Moolenaar4770d092006-01-12 23:22:24 +000010400
10401 Note that any wrong value in the options mentioned above may
10402 make the function fail. It has also been reported to fail
10403 when using a security agent application.
Bram Moolenaar071d4272004-06-13 20:20:40 +000010404 Unlike ":!cmd" there is no automatic check for changed files.
10405 Use |:checktime| to force a check.
10406
Bram Moolenaara74e4942019-08-04 17:35:53 +020010407 Can also be used as a |method|: >
10408 :echo GetCmd()->system()
10409
Bram Moolenaare2cc9702005-03-15 22:43:58 +000010410
Bram Moolenaar39c29ed2014-04-05 19:44:40 +020010411systemlist({expr} [, {input}]) *systemlist()*
Bram Moolenaarb0d45e72017-11-05 18:19:24 +010010412 Same as |system()|, but returns a |List| with lines (parts of
10413 output separated by NL) with NULs transformed into NLs. Output
10414 is the same as |readfile()| will output with {binary} argument
Bram Moolenaar5be4cee2019-09-27 19:34:08 +020010415 set to "b", except that there is no extra empty item when the
10416 result ends in a NL.
10417 Note that on MS-Windows you may get trailing CR characters.
Bram Moolenaar39c29ed2014-04-05 19:44:40 +020010418
Bram Moolenaar5be4cee2019-09-27 19:34:08 +020010419 To see the difference between "echo hello" and "echo -n hello"
10420 use |system()| and |split()|: >
10421 echo system('echo hello')->split('\n', 1)
10422<
Bram Moolenaar975b5272016-03-15 23:10:59 +010010423 Returns an empty string on error.
Bram Moolenaar39c29ed2014-04-05 19:44:40 +020010424
Bram Moolenaara74e4942019-08-04 17:35:53 +020010425 Can also be used as a |method|: >
10426 :echo GetCmd()->systemlist()
10427
Bram Moolenaar39c29ed2014-04-05 19:44:40 +020010428
Bram Moolenaarfaa959a2006-02-20 21:37:40 +000010429tabpagebuflist([{arg}]) *tabpagebuflist()*
Bram Moolenaar32466aa2006-02-24 23:53:04 +000010430 The result is a |List|, where each item is the number of the
Bram Moolenaarfaa959a2006-02-20 21:37:40 +000010431 buffer associated with each window in the current tab page.
Bram Moolenaardc1f1642016-08-16 18:33:43 +020010432 {arg} specifies the number of the tab page to be used. When
Bram Moolenaarfaa959a2006-02-20 21:37:40 +000010433 omitted the current tab page is used.
10434 When {arg} is invalid the number zero is returned.
10435 To get a list of all buffers in all tabs use this: >
Bram Moolenaar61d35bd2012-03-28 20:51:51 +020010436 let buflist = []
Bram Moolenaarfaa959a2006-02-20 21:37:40 +000010437 for i in range(tabpagenr('$'))
Bram Moolenaar61d35bd2012-03-28 20:51:51 +020010438 call extend(buflist, tabpagebuflist(i + 1))
Bram Moolenaarfaa959a2006-02-20 21:37:40 +000010439 endfor
10440< Note that a buffer may appear in more than one window.
10441
Bram Moolenaarce90e362019-09-08 18:58:44 +020010442 Can also be used as a |method|: >
10443 GetTabpage()->tabpagebuflist()
Bram Moolenaarfaa959a2006-02-20 21:37:40 +000010444
10445tabpagenr([{arg}]) *tabpagenr()*
Bram Moolenaar7e8fd632006-02-18 22:14:51 +000010446 The result is a Number, which is the number of the current
10447 tab page. The first tab page has number 1.
Bram Moolenaar62a23252020-08-09 14:04:42 +020010448
10449 The optional argument {arg} supports the following values:
10450 $ the number of the last tab page (the tab page
10451 count).
10452 # the number of the last accessed tab page
10453 (where |g<Tab>| goes to). if there is no
10454 previous tab page 0 is returned.
Bram Moolenaar7e8fd632006-02-18 22:14:51 +000010455 The number can be used with the |:tab| command.
10456
10457
Bram Moolenaar76f3b1a2014-03-27 22:30:07 +010010458tabpagewinnr({tabarg} [, {arg}]) *tabpagewinnr()*
Bram Moolenaard04f4402010-08-15 13:30:34 +020010459 Like |winnr()| but for tab page {tabarg}.
Bram Moolenaarfaa959a2006-02-20 21:37:40 +000010460 {tabarg} specifies the number of tab page to be used.
10461 {arg} is used like with |winnr()|:
10462 - When omitted the current window number is returned. This is
10463 the window which will be used when going to this tab page.
10464 - When "$" the number of windows is returned.
10465 - When "#" the previous window nr is returned.
10466 Useful examples: >
10467 tabpagewinnr(1) " current window of tab page 1
10468 tabpagewinnr(4, '$') " number of windows in tab page 4
10469< When {tabarg} is invalid zero is returned.
10470
Bram Moolenaarce90e362019-09-08 18:58:44 +020010471 Can also be used as a |method|: >
10472 GetTabpage()->tabpagewinnr()
10473<
Bram Moolenaarfa1d1402006-03-25 21:59:56 +000010474 *tagfiles()*
10475tagfiles() Returns a |List| with the file names used to search for tags
10476 for the current buffer. This is the 'tags' option expanded.
10477
10478
Bram Moolenaarb0d45e72017-11-05 18:19:24 +010010479taglist({expr} [, {filename}]) *taglist()*
Bram Moolenaare2cc9702005-03-15 22:43:58 +000010480 Returns a list of tags matching the regular expression {expr}.
Bram Moolenaarc6aafba2017-03-21 17:09:10 +010010481
10482 If {filename} is passed it is used to prioritize the results
10483 in the same way that |:tselect| does. See |tag-priority|.
10484 {filename} should be the full path of the file.
10485
Bram Moolenaard8c00872005-07-22 21:52:15 +000010486 Each list item is a dictionary with at least the following
10487 entries:
Bram Moolenaar280f1262006-01-30 00:14:18 +000010488 name Name of the tag.
10489 filename Name of the file where the tag is
Bram Moolenaaref2f6562007-05-06 13:32:59 +000010490 defined. It is either relative to the
10491 current directory or a full path.
Bram Moolenaare2cc9702005-03-15 22:43:58 +000010492 cmd Ex command used to locate the tag in
10493 the file.
Bram Moolenaar280f1262006-01-30 00:14:18 +000010494 kind Type of the tag. The value for this
Bram Moolenaare2cc9702005-03-15 22:43:58 +000010495 entry depends on the language specific
Bram Moolenaaref2f6562007-05-06 13:32:59 +000010496 kind values. Only available when
10497 using a tags file generated by
10498 Exuberant ctags or hdrtag.
Bram Moolenaar280f1262006-01-30 00:14:18 +000010499 static A file specific tag. Refer to
Bram Moolenaare2cc9702005-03-15 22:43:58 +000010500 |static-tag| for more information.
Bram Moolenaaref2f6562007-05-06 13:32:59 +000010501 More entries may be present, depending on the content of the
10502 tags file: access, implementation, inherits and signature.
10503 Refer to the ctags documentation for information about these
10504 fields. For C code the fields "struct", "class" and "enum"
10505 may appear, they give the name of the entity the tag is
10506 contained in.
Bram Moolenaar5a8684e2005-07-30 22:43:24 +000010507
Bram Moolenaar214641f2017-03-05 17:04:09 +010010508 The ex-command "cmd" can be either an ex search pattern, a
Bram Moolenaar4317d9b2005-03-18 20:25:31 +000010509 line number or a line number followed by a byte number.
Bram Moolenaare2cc9702005-03-15 22:43:58 +000010510
10511 If there are no matching tags, then an empty list is returned.
10512
10513 To get an exact tag match, the anchors '^' and '$' should be
Bram Moolenaara3e6bc92013-01-30 14:18:00 +010010514 used in {expr}. This also make the function work faster.
10515 Refer to |tag-regexp| for more information about the tag
10516 search regular expression pattern.
Bram Moolenaare2cc9702005-03-15 22:43:58 +000010517
10518 Refer to |'tags'| for information about how the tags file is
10519 located by Vim. Refer to |tags-file-format| for the format of
10520 the tags file generated by the different ctags tools.
10521
Bram Moolenaarce90e362019-09-08 18:58:44 +020010522 Can also be used as a |method|: >
10523 GetTagpattern()->taglist()
10524
Bram Moolenaardb7c6862010-05-21 16:33:48 +020010525tan({expr}) *tan()*
Bram Moolenaar9855d6b2010-07-18 14:34:51 +020010526 Return the tangent of {expr}, measured in radians, as a |Float|
Bram Moolenaardb7c6862010-05-21 16:33:48 +020010527 in the range [-inf, inf].
Bram Moolenaar9855d6b2010-07-18 14:34:51 +020010528 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaardb7c6862010-05-21 16:33:48 +020010529 Examples: >
10530 :echo tan(10)
10531< 0.648361 >
10532 :echo tan(-4.01)
10533< -1.181502
Bram Moolenaar93cf85f2019-08-17 21:36:28 +020010534
10535 Can also be used as a |method|: >
10536 Compute()->tan()
10537<
Bram Moolenaardb84e452010-08-15 13:50:43 +020010538 {only available when compiled with the |+float| feature}
Bram Moolenaardb7c6862010-05-21 16:33:48 +020010539
10540
10541tanh({expr}) *tanh()*
Bram Moolenaar9855d6b2010-07-18 14:34:51 +020010542 Return the hyperbolic tangent of {expr} as a |Float| in the
Bram Moolenaardb7c6862010-05-21 16:33:48 +020010543 range [-1, 1].
Bram Moolenaar9855d6b2010-07-18 14:34:51 +020010544 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaardb7c6862010-05-21 16:33:48 +020010545 Examples: >
10546 :echo tanh(0.5)
10547< 0.462117 >
10548 :echo tanh(-1)
10549< -0.761594
Bram Moolenaar93cf85f2019-08-17 21:36:28 +020010550
10551 Can also be used as a |method|: >
10552 Compute()->tanh()
10553<
Bram Moolenaardb84e452010-08-15 13:50:43 +020010554 {only available when compiled with the |+float| feature}
Bram Moolenaardb7c6862010-05-21 16:33:48 +020010555
10556
Bram Moolenaar574860b2016-05-24 17:33:34 +020010557tempname() *tempname()* *temp-file-name*
10558 The result is a String, which is the name of a file that
Bram Moolenaar58b85342016-08-14 19:54:54 +020010559 doesn't exist. It can be used for a temporary file. The name
Bram Moolenaar574860b2016-05-24 17:33:34 +020010560 is different for at least 26 consecutive calls. Example: >
10561 :let tmpfile = tempname()
10562 :exe "redir > " . tmpfile
10563< For Unix, the file will be in a private directory |tempfile|.
10564 For MS-Windows forward slashes are used when the 'shellslash'
10565 option is set or when 'shellcmdflag' starts with '-'.
10566
Bram Moolenaared997ad2019-07-21 16:42:00 +020010567
Bram Moolenaar6bf2c622019-07-04 17:12:09 +020010568term_ functions are documented here: |terminal-function-details|
Bram Moolenaar574860b2016-05-24 17:33:34 +020010569
Bram Moolenaar0c0eddd2020-06-13 15:47:25 +020010570
10571terminalprops() *terminalprops()*
10572 Returns a dictionary with properties of the terminal that Vim
10573 detected from the response to |t_RV| request. See
10574 |v:termresponse| for the response itself. If |v:termresponse|
10575 is empty most values here will be 'u' for unknown.
10576 cursor_style wether sending |t_RS| works **
10577 cursor_blink_mode wether sending |t_RC| works **
10578 underline_rgb whether |t_8u| works **
10579 mouse mouse type supported
10580
10581 ** value 'u' for unknown, 'y' for yes, 'n' for no
10582
10583 If the |+termresponse| feature is missing then the result is
10584 an empty dictionary.
10585
Bram Moolenaar73fef332020-06-21 22:12:03 +020010586 If "cursor_style" is 'y' then |t_RS| will be sent to request the
Bram Moolenaar0c0eddd2020-06-13 15:47:25 +020010587 current cursor style.
Bram Moolenaar73fef332020-06-21 22:12:03 +020010588 If "cursor_blink_mode" is 'y' then |t_RC| will be sent to
Bram Moolenaar0c0eddd2020-06-13 15:47:25 +020010589 request the cursor blink status.
10590 "cursor_style" and "cursor_blink_mode" are also set if |t_u7|
10591 is not empty, Vim will detect the working of sending |t_RS|
10592 and |t_RC| on startup.
10593
10594 When "underline_rgb" is not 'y', then |t_8u| will be made empty.
10595 This avoids sending it to xterm, which would clear the colors.
10596
10597 For "mouse" the value 'u' is unknown
10598
10599 Also see:
10600 - 'ambiwidth' - detected by using |t_u7|.
10601 - |v:termstyleresp| and |v:termblinkresp| for the response to
10602 |t_RS| and |t_RC|.
10603
10604
Bram Moolenaar54775062019-07-31 21:07:14 +020010605test_ functions are documented here: |test-functions-details|
Bram Moolenaar8e8df252016-05-25 21:23:21 +020010606
Bram Moolenaar574860b2016-05-24 17:33:34 +020010607
Bram Moolenaar8e97bd72016-08-06 22:05:07 +020010608 *timer_info()*
10609timer_info([{id}])
10610 Return a list with information about timers.
10611 When {id} is given only information about this timer is
10612 returned. When timer {id} does not exist an empty list is
10613 returned.
10614 When {id} is omitted information about all timers is returned.
10615
Bram Moolenaare46a4402020-06-30 20:38:27 +020010616 For each timer the information is stored in a |Dictionary| with
Bram Moolenaar8e97bd72016-08-06 22:05:07 +020010617 these items:
10618 "id" the timer ID
10619 "time" time the timer was started with
10620 "remaining" time until the timer fires
10621 "repeat" number of times the timer will still fire;
Bram Moolenaarb73598e2016-08-07 18:22:53 +020010622 -1 means forever
Bram Moolenaar8e97bd72016-08-06 22:05:07 +020010623 "callback" the callback
Bram Moolenaarb73598e2016-08-07 18:22:53 +020010624 "paused" 1 if the timer is paused, 0 otherwise
10625
Bram Moolenaarf92e58c2019-09-08 21:51:41 +020010626 Can also be used as a |method|: >
10627 GetTimer()->timer_info()
10628
10629< {only available when compiled with the |+timers| feature}
Bram Moolenaarb73598e2016-08-07 18:22:53 +020010630
10631timer_pause({timer}, {paused}) *timer_pause()*
10632 Pause or unpause a timer. A paused timer does not invoke its
Bram Moolenaardc1f1642016-08-16 18:33:43 +020010633 callback when its time expires. Unpausing a timer may cause
10634 the callback to be invoked almost immediately if enough time
10635 has passed.
Bram Moolenaarb73598e2016-08-07 18:22:53 +020010636
10637 Pausing a timer is useful to avoid the callback to be called
10638 for a short time.
10639
10640 If {paused} evaluates to a non-zero Number or a non-empty
10641 String, then the timer is paused, otherwise it is unpaused.
10642 See |non-zero-arg|.
10643
Bram Moolenaarf92e58c2019-09-08 21:51:41 +020010644 Can also be used as a |method|: >
10645 GetTimer()->timer_pause(1)
10646
10647< {only available when compiled with the |+timers| feature}
Bram Moolenaar8e97bd72016-08-06 22:05:07 +020010648
Bram Moolenaardc1f1642016-08-16 18:33:43 +020010649 *timer_start()* *timer* *timers*
Bram Moolenaar975b5272016-03-15 23:10:59 +010010650timer_start({time}, {callback} [, {options}])
10651 Create a timer and return the timer ID.
10652
10653 {time} is the waiting time in milliseconds. This is the
10654 minimum time before invoking the callback. When the system is
10655 busy or Vim is not waiting for input the time will be longer.
10656
10657 {callback} is the function to call. It can be the name of a
Bram Moolenaarf37506f2016-08-31 22:22:10 +020010658 function or a |Funcref|. It is called with one argument, which
Bram Moolenaar975b5272016-03-15 23:10:59 +010010659 is the timer ID. The callback is only invoked when Vim is
10660 waiting for input.
10661
10662 {options} is a dictionary. Supported entries:
10663 "repeat" Number of times to repeat calling the
Bram Moolenaarabd468e2016-09-08 22:22:43 +020010664 callback. -1 means forever. When not present
10665 the callback will be called once.
Bram Moolenaarc577d812017-07-08 22:37:34 +020010666 If the timer causes an error three times in a
10667 row the repeat is cancelled. This avoids that
10668 Vim becomes unusable because of all the error
10669 messages.
Bram Moolenaar975b5272016-03-15 23:10:59 +010010670
10671 Example: >
10672 func MyHandler(timer)
10673 echo 'Handler called'
10674 endfunc
10675 let timer = timer_start(500, 'MyHandler',
10676 \ {'repeat': 3})
10677< This will invoke MyHandler() three times at 500 msec
10678 intervals.
Bram Moolenaarb73598e2016-08-07 18:22:53 +020010679
Bram Moolenaarf92e58c2019-09-08 21:51:41 +020010680 Can also be used as a |method|: >
10681 GetMsec()->timer_start(callback)
10682
10683< Not available in the |sandbox|.
Bram Moolenaar975b5272016-03-15 23:10:59 +010010684 {only available when compiled with the |+timers| feature}
10685
Bram Moolenaar03602ec2016-03-20 20:57:45 +010010686timer_stop({timer}) *timer_stop()*
Bram Moolenaar06d2d382016-05-20 17:24:11 +020010687 Stop a timer. The timer callback will no longer be invoked.
10688 {timer} is an ID returned by timer_start(), thus it must be a
Bram Moolenaar8e97bd72016-08-06 22:05:07 +020010689 Number. If {timer} does not exist there is no error.
Bram Moolenaar03602ec2016-03-20 20:57:45 +010010690
Bram Moolenaarf92e58c2019-09-08 21:51:41 +020010691 Can also be used as a |method|: >
10692 GetTimer()->timer_stop()
10693
10694< {only available when compiled with the |+timers| feature}
Bram Moolenaarb73598e2016-08-07 18:22:53 +020010695
10696timer_stopall() *timer_stopall()*
10697 Stop all timers. The timer callbacks will no longer be
Bram Moolenaar809ce4d2019-07-13 21:21:40 +020010698 invoked. Useful if a timer is misbehaving. If there are no
10699 timers there is no error.
Bram Moolenaarb73598e2016-08-07 18:22:53 +020010700
10701 {only available when compiled with the |+timers| feature}
10702
Bram Moolenaar071d4272004-06-13 20:20:40 +000010703tolower({expr}) *tolower()*
10704 The result is a copy of the String given, with all uppercase
10705 characters turned into lowercase (just like applying |gu| to
10706 the string).
10707
Bram Moolenaarf92e58c2019-09-08 21:51:41 +020010708 Can also be used as a |method|: >
10709 GetText()->tolower()
10710
Bram Moolenaar071d4272004-06-13 20:20:40 +000010711toupper({expr}) *toupper()*
10712 The result is a copy of the String given, with all lowercase
10713 characters turned into uppercase (just like applying |gU| to
10714 the string).
10715
Bram Moolenaarf92e58c2019-09-08 21:51:41 +020010716 Can also be used as a |method|: >
10717 GetText()->toupper()
10718
Bram Moolenaar8299df92004-07-10 09:47:34 +000010719tr({src}, {fromstr}, {tostr}) *tr()*
10720 The result is a copy of the {src} string with all characters
10721 which appear in {fromstr} replaced by the character in that
10722 position in the {tostr} string. Thus the first character in
10723 {fromstr} is translated into the first character in {tostr}
10724 and so on. Exactly like the unix "tr" command.
10725 This code also deals with multibyte characters properly.
10726
10727 Examples: >
10728 echo tr("hello there", "ht", "HT")
10729< returns "Hello THere" >
10730 echo tr("<blob>", "<>", "{}")
10731< returns "{blob}"
10732
Bram Moolenaarf92e58c2019-09-08 21:51:41 +020010733 Can also be used as a |method|: >
10734 GetText()->tr(from, to)
10735
Bram Moolenaar2245ae12020-05-31 22:20:36 +020010736trim({text} [, {mask} [, {dir}]]) *trim()*
Bram Moolenaar295ac5a2018-03-22 23:04:02 +010010737 Return {text} as a String where any character in {mask} is
Bram Moolenaar2245ae12020-05-31 22:20:36 +020010738 removed from the beginning and/or end of {text}.
10739
Bram Moolenaar295ac5a2018-03-22 23:04:02 +010010740 If {mask} is not given, {mask} is all characters up to 0x20,
10741 which includes Tab, space, NL and CR, plus the non-breaking
10742 space character 0xa0.
Bram Moolenaar2245ae12020-05-31 22:20:36 +020010743
10744 The optional {dir} argument specifies where to remove the
10745 characters:
10746 0 remove from the beginning and end of {text}
10747 1 remove only at the beginning of {text}
10748 2 remove only at the end of {text}
10749 When omitted both ends are trimmed.
10750
10751 This function deals with multibyte characters properly.
Bram Moolenaar295ac5a2018-03-22 23:04:02 +010010752
10753 Examples: >
Bram Moolenaarab943432018-03-29 18:27:07 +020010754 echo trim(" some text ")
10755< returns "some text" >
10756 echo trim(" \r\t\t\r RESERVE \t\n\x0B\xA0") . "_TAIL"
Bram Moolenaar295ac5a2018-03-22 23:04:02 +010010757< returns "RESERVE_TAIL" >
Bram Moolenaarab943432018-03-29 18:27:07 +020010758 echo trim("rm<Xrm<>X>rrm", "rm<>")
Bram Moolenaar2245ae12020-05-31 22:20:36 +020010759< returns "Xrm<>X" (characters in the middle are not removed) >
10760 echo trim(" vim ", " ", 2)
10761< returns " vim"
Bram Moolenaar295ac5a2018-03-22 23:04:02 +010010762
Bram Moolenaarf92e58c2019-09-08 21:51:41 +020010763 Can also be used as a |method|: >
10764 GetText()->trim()
10765
Bram Moolenaar446cb832008-06-24 21:56:24 +000010766trunc({expr}) *trunc()*
Bram Moolenaarc236c162008-07-13 17:41:49 +000010767 Return the largest integral value with magnitude less than or
Bram Moolenaar446cb832008-06-24 21:56:24 +000010768 equal to {expr} as a |Float| (truncate towards zero).
10769 {expr} must evaluate to a |Float| or a |Number|.
10770 Examples: >
10771 echo trunc(1.456)
10772< 1.0 >
10773 echo trunc(-5.456)
10774< -5.0 >
10775 echo trunc(4.0)
10776< 4.0
Bram Moolenaar93cf85f2019-08-17 21:36:28 +020010777
10778 Can also be used as a |method|: >
10779 Compute()->trunc()
10780<
Bram Moolenaar446cb832008-06-24 21:56:24 +000010781 {only available when compiled with the |+float| feature}
Bram Moolenaarb0d45e72017-11-05 18:19:24 +010010782
Bram Moolenaar9588a0f2005-01-08 21:45:39 +000010783 *type()*
Bram Moolenaardf48fb42016-07-22 21:50:18 +020010784type({expr}) The result is a Number representing the type of {expr}.
10785 Instead of using the number directly, it is better to use the
10786 v:t_ variable that has the value:
10787 Number: 0 |v:t_number|
10788 String: 1 |v:t_string|
10789 Funcref: 2 |v:t_func|
10790 List: 3 |v:t_list|
10791 Dictionary: 4 |v:t_dict|
10792 Float: 5 |v:t_float|
10793 Boolean: 6 |v:t_bool| (v:false and v:true)
Bram Moolenaar39536dd2019-01-29 22:58:21 +010010794 None: 7 |v:t_none| (v:null and v:none)
10795 Job: 8 |v:t_job|
10796 Channel: 9 |v:t_channel|
10797 Blob: 10 |v:t_blob|
Bram Moolenaardf48fb42016-07-22 21:50:18 +020010798 For backward compatibility, this method can be used: >
Bram Moolenaar9588a0f2005-01-08 21:45:39 +000010799 :if type(myvar) == type(0)
10800 :if type(myvar) == type("")
10801 :if type(myvar) == type(function("tr"))
10802 :if type(myvar) == type([])
Bram Moolenaar748bf032005-02-02 23:04:36 +000010803 :if type(myvar) == type({})
Bram Moolenaar446cb832008-06-24 21:56:24 +000010804 :if type(myvar) == type(0.0)
Bram Moolenaar705ada12016-01-24 17:56:50 +010010805 :if type(myvar) == type(v:false)
Bram Moolenaar6463ca22016-02-13 17:04:46 +010010806 :if type(myvar) == type(v:none)
Bram Moolenaardf48fb42016-07-22 21:50:18 +020010807< To check if the v:t_ variables exist use this: >
10808 :if exists('v:t_number')
Bram Moolenaar071d4272004-06-13 20:20:40 +000010809
Bram Moolenaarac92e252019-08-03 21:58:38 +020010810< Can also be used as a |method|: >
10811 mylist->type()
10812
Bram Moolenaara17d4c12010-05-30 18:30:36 +020010813undofile({name}) *undofile()*
10814 Return the name of the undo file that would be used for a file
10815 with name {name} when writing. This uses the 'undodir'
10816 option, finding directories that exist. It does not check if
Bram Moolenaar860cae12010-06-05 23:22:07 +020010817 the undo file exists.
Bram Moolenaar945e2db2010-06-05 17:43:32 +020010818 {name} is always expanded to the full path, since that is what
10819 is used internally.
Bram Moolenaar80716072012-05-01 21:14:34 +020010820 If {name} is empty undofile() returns an empty string, since a
10821 buffer without a file name will not write an undo file.
Bram Moolenaara17d4c12010-05-30 18:30:36 +020010822 Useful in combination with |:wundo| and |:rundo|.
Bram Moolenaarb328cca2019-01-06 16:24:01 +010010823 When compiled without the |+persistent_undo| option this always
Bram Moolenaara17d4c12010-05-30 18:30:36 +020010824 returns an empty string.
10825
Bram Moolenaarf92e58c2019-09-08 21:51:41 +020010826 Can also be used as a |method|: >
10827 GetFilename()->undofile()
10828
Bram Moolenaara800b422010-06-27 01:15:55 +020010829undotree() *undotree()*
10830 Return the current state of the undo tree in a dictionary with
10831 the following items:
10832 "seq_last" The highest undo sequence number used.
10833 "seq_cur" The sequence number of the current position in
10834 the undo tree. This differs from "seq_last"
10835 when some changes were undone.
10836 "time_cur" Time last used for |:earlier| and related
10837 commands. Use |strftime()| to convert to
10838 something readable.
10839 "save_last" Number of the last file write. Zero when no
10840 write yet.
Bram Moolenaar730cde92010-06-27 05:18:54 +020010841 "save_cur" Number of the current position in the undo
Bram Moolenaarb0d45e72017-11-05 18:19:24 +010010842 tree.
Bram Moolenaara800b422010-06-27 01:15:55 +020010843 "synced" Non-zero when the last undo block was synced.
10844 This happens when waiting from input from the
10845 user. See |undo-blocks|.
10846 "entries" A list of dictionaries with information about
10847 undo blocks.
10848
10849 The first item in the "entries" list is the oldest undo item.
Bram Moolenaare46a4402020-06-30 20:38:27 +020010850 Each List item is a |Dictionary| with these items:
Bram Moolenaara800b422010-06-27 01:15:55 +020010851 "seq" Undo sequence number. Same as what appears in
10852 |:undolist|.
10853 "time" Timestamp when the change happened. Use
10854 |strftime()| to convert to something readable.
10855 "newhead" Only appears in the item that is the last one
10856 that was added. This marks the last change
10857 and where further changes will be added.
10858 "curhead" Only appears in the item that is the last one
10859 that was undone. This marks the current
10860 position in the undo tree, the block that will
10861 be used by a redo command. When nothing was
10862 undone after the last change this item will
10863 not appear anywhere.
10864 "save" Only appears on the last block before a file
10865 write. The number is the write count. The
10866 first write has number 1, the last one the
10867 "save_last" mentioned above.
10868 "alt" Alternate entry. This is again a List of undo
10869 blocks. Each item may again have an "alt"
10870 item.
10871
Bram Moolenaar327aa022014-03-25 18:24:23 +010010872uniq({list} [, {func} [, {dict}]]) *uniq()* *E882*
10873 Remove second and succeeding copies of repeated adjacent
10874 {list} items in-place. Returns {list}. If you want a list
10875 to remain unmodified make a copy first: >
10876 :let newlist = uniq(copy(mylist))
10877< The default compare function uses the string representation of
10878 each item. For the use of {func} and {dict} see |sort()|.
10879
Bram Moolenaarac92e252019-08-03 21:58:38 +020010880 Can also be used as a |method|: >
10881 mylist->uniq()
10882
Bram Moolenaar677ee682005-01-27 14:41:15 +000010883values({dict}) *values()*
Bram Moolenaar58b85342016-08-14 19:54:54 +020010884 Return a |List| with all the values of {dict}. The |List| is
Bram Moolenaar0d17f0d2019-01-22 22:20:38 +010010885 in arbitrary order. Also see |items()| and |keys()|.
Bram Moolenaar677ee682005-01-27 14:41:15 +000010886
Bram Moolenaarac92e252019-08-03 21:58:38 +020010887 Can also be used as a |method|: >
10888 mydict->values()
Bram Moolenaar677ee682005-01-27 14:41:15 +000010889
Bram Moolenaar071d4272004-06-13 20:20:40 +000010890virtcol({expr}) *virtcol()*
10891 The result is a Number, which is the screen column of the file
10892 position given with {expr}. That is, the last screen position
10893 occupied by the character at that position, when the screen
10894 would be of unlimited width. When there is a <Tab> at the
10895 position, the returned Number will be the column at the end of
10896 the <Tab>. For example, for a <Tab> in column 1, with 'ts'
Bram Moolenaar61d35bd2012-03-28 20:51:51 +020010897 set to 8, it returns 8. |conceal| is ignored.
Bram Moolenaar477933c2007-07-17 14:32:23 +000010898 For the byte position use |col()|.
10899 For the use of {expr} see |col()|.
10900 When 'virtualedit' is used {expr} can be [lnum, col, off], where
Bram Moolenaar0b238792006-03-02 22:49:12 +000010901 "off" is the offset in screen columns from the start of the
Bram Moolenaard46bbc72007-05-12 14:38:41 +000010902 character. E.g., a position within a <Tab> or after the last
Bram Moolenaar97293012011-07-18 19:40:27 +020010903 character. When "off" is omitted zero is used.
Bram Moolenaar071d4272004-06-13 20:20:40 +000010904 When Virtual editing is active in the current mode, a position
10905 beyond the end of the line can be returned. |'virtualedit'|
10906 The accepted positions are:
10907 . the cursor position
10908 $ the end of the cursor line (the result is the
10909 number of displayed characters in the cursor line
10910 plus one)
10911 'x position of mark x (if the mark is not set, 0 is
10912 returned)
Bram Moolenaare3faf442014-12-14 01:27:49 +010010913 v In Visual mode: the start of the Visual area (the
10914 cursor is the end). When not in Visual mode
10915 returns the cursor position. Differs from |'<| in
10916 that it's updated right away.
Bram Moolenaar071d4272004-06-13 20:20:40 +000010917 Note that only marks in the current file can be used.
10918 Examples: >
10919 virtcol(".") with text "foo^Lbar", with cursor on the "^L", returns 5
10920 virtcol("$") with text "foo^Lbar", returns 9
Bram Moolenaar446cb832008-06-24 21:56:24 +000010921 virtcol("'t") with text " there", with 't at 'h', returns 6
Bram Moolenaar58b85342016-08-14 19:54:54 +020010922< The first column is 1. 0 is returned for an error.
Bram Moolenaaref2f6562007-05-06 13:32:59 +000010923 A more advanced example that echoes the maximum length of
10924 all lines: >
10925 echo max(map(range(1, line('$')), "virtcol([v:val, '$'])"))
10926
Bram Moolenaarf92e58c2019-09-08 21:51:41 +020010927< Can also be used as a |method|: >
10928 GetPos()->virtcol()
Bram Moolenaar071d4272004-06-13 20:20:40 +000010929
Bram Moolenaarf92e58c2019-09-08 21:51:41 +020010930
10931visualmode([{expr}]) *visualmode()*
Bram Moolenaar071d4272004-06-13 20:20:40 +000010932 The result is a String, which describes the last Visual mode
Bram Moolenaarc9b4b052006-04-30 18:54:39 +000010933 used in the current buffer. Initially it returns an empty
10934 string, but once Visual mode has been used, it returns "v",
10935 "V", or "<CTRL-V>" (a single CTRL-V character) for
10936 character-wise, line-wise, or block-wise Visual mode
10937 respectively.
Bram Moolenaar071d4272004-06-13 20:20:40 +000010938 Example: >
10939 :exe "normal " . visualmode()
10940< This enters the same Visual mode as before. It is also useful
10941 in scripts if you wish to act differently depending on the
10942 Visual mode that was used.
Bram Moolenaar446cb832008-06-24 21:56:24 +000010943 If Visual mode is active, use |mode()| to get the Visual mode
10944 (e.g., in a |:vmap|).
Bram Moolenaarf92e58c2019-09-08 21:51:41 +020010945 If {expr} is supplied and it evaluates to a non-zero Number or
Bram Moolenaar05bb9532008-07-04 09:44:11 +000010946 a non-empty String, then the Visual mode will be cleared and
Bram Moolenaare381d3d2016-07-07 14:50:41 +020010947 the old value is returned. See |non-zero-arg|.
Bram Moolenaar071d4272004-06-13 20:20:40 +000010948
Bram Moolenaar8738fc12013-02-20 17:59:11 +010010949wildmenumode() *wildmenumode()*
Bram Moolenaare381d3d2016-07-07 14:50:41 +020010950 Returns |TRUE| when the wildmenu is active and |FALSE|
Bram Moolenaar8738fc12013-02-20 17:59:11 +010010951 otherwise. See 'wildmenu' and 'wildmode'.
10952 This can be used in mappings to handle the 'wildcharm' option
10953 gracefully. (Makes only sense with |mapmode-c| mappings).
10954
10955 For example to make <c-j> work like <down> in wildmode, use: >
10956 :cnoremap <expr> <C-j> wildmenumode() ? "\<Down>\<Tab>" : "\<c-j>"
10957<
10958 (Note, this needs the 'wildcharm' option set appropriately).
10959
Bram Moolenaar868b7b62019-05-29 21:44:40 +020010960win_execute({id}, {command} [, {silent}]) *win_execute()*
10961 Like `execute()` but in the context of window {id}.
10962 The window will temporarily be made the current window,
Bram Moolenaarb4230122019-05-30 18:40:53 +020010963 without triggering autocommands. When executing {command}
10964 autocommands will be triggered, this may have unexpected side
10965 effects. Use |:noautocmd| if needed.
Bram Moolenaar868b7b62019-05-29 21:44:40 +020010966 Example: >
Bram Moolenaarb4230122019-05-30 18:40:53 +020010967 call win_execute(winid, 'set syntax=python')
10968< Doing the same with `setwinvar()` would not trigger
10969 autocommands and not actually show syntax highlighting.
Bram Moolenaar61da1bf2019-06-06 12:14:49 +020010970 *E994*
10971 Not all commands are allowed in popup windows.
Bram Moolenaar56c860c2019-08-17 20:09:31 +020010972 When window {id} does not exist then no error is given.
Bram Moolenaar8738fc12013-02-20 17:59:11 +010010973
Bram Moolenaar2e693a82019-10-16 22:35:02 +020010974 Can also be used as a |method|, the base is passed as the
10975 second argument: >
Bram Moolenaarf92e58c2019-09-08 21:51:41 +020010976 GetCommand()->win_execute(winid)
10977
Bram Moolenaar9cdf86b2016-03-13 19:04:51 +010010978win_findbuf({bufnr}) *win_findbuf()*
Bram Moolenaar7571d552016-08-18 22:54:46 +020010979 Returns a list with |window-ID|s for windows that contain
10980 buffer {bufnr}. When there is none the list is empty.
Bram Moolenaar9cdf86b2016-03-13 19:04:51 +010010981
Bram Moolenaarf92e58c2019-09-08 21:51:41 +020010982 Can also be used as a |method|: >
10983 GetBufnr()->win_findbuf()
10984
Bram Moolenaar86edef62016-03-13 18:07:30 +010010985win_getid([{win} [, {tab}]]) *win_getid()*
Bram Moolenaar7571d552016-08-18 22:54:46 +020010986 Get the |window-ID| for the specified window.
Bram Moolenaar86edef62016-03-13 18:07:30 +010010987 When {win} is missing use the current window.
10988 With {win} this is the window number. The top window has
Bram Moolenaarba3ff532018-11-04 14:45:49 +010010989 number 1.
Bram Moolenaar86edef62016-03-13 18:07:30 +010010990 Without {tab} use the current tab, otherwise the tab with
10991 number {tab}. The first tab has number one.
10992 Return zero if the window cannot be found.
10993
Bram Moolenaarf92e58c2019-09-08 21:51:41 +020010994 Can also be used as a |method|: >
10995 GetWinnr()->win_getid()
10996
Bram Moolenaar00f3b4e2020-02-14 14:32:22 +010010997
10998win_gettype([{nr}]) *win_gettype()*
10999 Return the type of the window:
Bram Moolenaar40a019f2020-06-17 21:41:35 +020011000 "autocmd" autocommand window. Temporary window
Bram Moolenaar0fe937f2020-06-16 22:42:04 +020011001 used to execute autocommands.
Bram Moolenaar00f3b4e2020-02-14 14:32:22 +010011002 "popup" popup window |popup|
Bram Moolenaar0fe937f2020-06-16 22:42:04 +020011003 "preview" preview window |preview-window|
Bram Moolenaar00f3b4e2020-02-14 14:32:22 +010011004 "command" command-line window |cmdwin|
11005 (empty) normal window
11006 "unknown" window {nr} not found
11007
11008 When {nr} is omitted return the type of the current window.
11009 When {nr} is given return the type of this window by number or
11010 |window-ID|.
11011
11012 Also see the 'buftype' option. When running a terminal in a
11013 popup window then 'buftype' is "terminal" and win_gettype()
11014 returns "popup".
11015
11016
Bram Moolenaar86edef62016-03-13 18:07:30 +010011017win_gotoid({expr}) *win_gotoid()*
11018 Go to window with ID {expr}. This may also change the current
11019 tabpage.
11020 Return 1 if successful, 0 if the window cannot be found.
11021
Bram Moolenaarf92e58c2019-09-08 21:51:41 +020011022 Can also be used as a |method|: >
11023 GetWinid()->win_gotoid()
11024
Bram Moolenaar03413f42016-04-12 21:07:15 +020011025win_id2tabwin({expr}) *win_id2tabwin()*
Bram Moolenaar86edef62016-03-13 18:07:30 +010011026 Return a list with the tab number and window number of window
11027 with ID {expr}: [tabnr, winnr].
11028 Return [0, 0] if the window cannot be found.
11029
Bram Moolenaarf92e58c2019-09-08 21:51:41 +020011030 Can also be used as a |method|: >
11031 GetWinid()->win_id2tabwin()
11032
Bram Moolenaar86edef62016-03-13 18:07:30 +010011033win_id2win({expr}) *win_id2win()*
11034 Return the window number of window with ID {expr}.
11035 Return 0 if the window cannot be found in the current tabpage.
11036
Bram Moolenaarf92e58c2019-09-08 21:51:41 +020011037 Can also be used as a |method|: >
11038 GetWinid()->win_id2win()
11039
Bram Moolenaar22044dc2017-12-02 15:43:37 +010011040win_screenpos({nr}) *win_screenpos()*
11041 Return the screen position of window {nr} as a list with two
11042 numbers: [row, col]. The first window always has position
Bram Moolenaar7132ddc2018-07-15 17:01:11 +020011043 [1, 1], unless there is a tabline, then it is [2, 1].
Bram Moolenaar1c6737b2020-09-07 22:18:52 +020011044 {nr} can be the window number or the |window-ID|. Use zero
11045 for the current window.
Bram Moolenaar22044dc2017-12-02 15:43:37 +010011046 Return [0, 0] if the window cannot be found in the current
11047 tabpage.
11048
Bram Moolenaarf92e58c2019-09-08 21:51:41 +020011049 Can also be used as a |method|: >
11050 GetWinid()->win_screenpos()
11051<
Bram Moolenaard20dcb32019-09-10 21:22:58 +020011052win_splitmove({nr}, {target} [, {options}]) *win_splitmove()*
Bram Moolenaar73fef332020-06-21 22:12:03 +020011053 Move the window {nr} to a new split of the window {target}.
Bram Moolenaard20dcb32019-09-10 21:22:58 +020011054 This is similar to moving to {target}, creating a new window
11055 using |:split| but having the same contents as window {nr}, and
11056 then closing {nr}.
11057
11058 Both {nr} and {target} can be window numbers or |window-ID|s.
Bram Moolenaar29634562020-01-09 21:46:04 +010011059 Both must be in the current tab page.
Bram Moolenaard20dcb32019-09-10 21:22:58 +020011060
11061 Returns zero for success, non-zero for failure.
11062
Bram Moolenaare46a4402020-06-30 20:38:27 +020011063 {options} is a |Dictionary| with the following optional entries:
Bram Moolenaard20dcb32019-09-10 21:22:58 +020011064 "vertical" When TRUE, the split is created vertically,
11065 like with |:vsplit|.
11066 "rightbelow" When TRUE, the split is made below or to the
11067 right (if vertical). When FALSE, it is done
11068 above or to the left (if vertical). When not
11069 present, the values of 'splitbelow' and
11070 'splitright' are used.
11071
11072 Can also be used as a |method|: >
11073 GetWinid()->win_splitmove(target)
11074<
Bram Moolenaar4132eb52020-02-14 16:53:00 +010011075
Bram Moolenaar071d4272004-06-13 20:20:40 +000011076 *winbufnr()*
11077winbufnr({nr}) The result is a Number, which is the number of the buffer
Bram Moolenaar888ccac2016-06-04 18:49:36 +020011078 associated with window {nr}. {nr} can be the window number or
Bram Moolenaar7571d552016-08-18 22:54:46 +020011079 the |window-ID|.
Bram Moolenaar888ccac2016-06-04 18:49:36 +020011080 When {nr} is zero, the number of the buffer in the current
11081 window is returned.
11082 When window {nr} doesn't exist, -1 is returned.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011083 Example: >
11084 :echo "The file in the current window is " . bufname(winbufnr(0))
11085<
Bram Moolenaare49fbff2019-08-21 22:50:07 +020011086 Can also be used as a |method|: >
11087 FindWindow()->winbufnr()->bufname()
11088<
Bram Moolenaar071d4272004-06-13 20:20:40 +000011089 *wincol()*
11090wincol() The result is a Number, which is the virtual column of the
11091 cursor in the window. This is counting screen cells from the
11092 left side of the window. The leftmost column is one.
11093
Bram Moolenaar0c1e3742019-12-27 13:49:24 +010011094 *windowsversion()*
11095windowsversion()
11096 The result is a String. For MS-Windows it indicates the OS
11097 version. E.g, Windows 10 is "10.0", Windows 8 is "6.2",
11098 Windows XP is "5.1". For non-MS-Windows systems the result is
11099 an empty string.
11100
Bram Moolenaar071d4272004-06-13 20:20:40 +000011101winheight({nr}) *winheight()*
11102 The result is a Number, which is the height of window {nr}.
Bram Moolenaar7571d552016-08-18 22:54:46 +020011103 {nr} can be the window number or the |window-ID|.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011104 When {nr} is zero, the height of the current window is
11105 returned. When window {nr} doesn't exist, -1 is returned.
11106 An existing window always has a height of zero or more.
Bram Moolenaar37c64c72017-09-19 22:06:03 +020011107 This excludes any window toolbar line.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011108 Examples: >
11109 :echo "The current window has " . winheight(0) . " lines."
Bram Moolenaarf92e58c2019-09-08 21:51:41 +020011110
11111< Can also be used as a |method|: >
11112 GetWinid()->winheight()
Bram Moolenaar071d4272004-06-13 20:20:40 +000011113<
Bram Moolenaar0f6b4f02018-08-21 16:56:34 +020011114winlayout([{tabnr}]) *winlayout()*
11115 The result is a nested List containing the layout of windows
11116 in a tabpage.
11117
11118 Without {tabnr} use the current tabpage, otherwise the tabpage
11119 with number {tabnr}. If the tabpage {tabnr} is not found,
11120 returns an empty list.
11121
11122 For a leaf window, it returns:
11123 ['leaf', {winid}]
11124 For horizontally split windows, which form a column, it
11125 returns:
11126 ['col', [{nested list of windows}]]
11127 For vertically split windows, which form a row, it returns:
11128 ['row', [{nested list of windows}]]
11129
11130 Example: >
11131 " Only one window in the tab page
11132 :echo winlayout()
11133 ['leaf', 1000]
11134 " Two horizontally split windows
11135 :echo winlayout()
11136 ['col', [['leaf', 1000], ['leaf', 1001]]]
Bram Moolenaarb17893a2020-03-14 08:19:51 +010011137 " The second tab page, with three horizontally split
11138 " windows, with two vertically split windows in the
11139 " middle window
Bram Moolenaar0f6b4f02018-08-21 16:56:34 +020011140 :echo winlayout(2)
Bram Moolenaarb17893a2020-03-14 08:19:51 +010011141 ['col', [['leaf', 1002], ['row', [['leaf', 1003],
11142 ['leaf', 1001]]], ['leaf', 1000]]]
Bram Moolenaar0f6b4f02018-08-21 16:56:34 +020011143<
Bram Moolenaarf92e58c2019-09-08 21:51:41 +020011144 Can also be used as a |method|: >
11145 GetTabnr()->winlayout()
11146<
Bram Moolenaar071d4272004-06-13 20:20:40 +000011147 *winline()*
11148winline() The result is a Number, which is the screen line of the cursor
Bram Moolenaar58b85342016-08-14 19:54:54 +020011149 in the window. This is counting screen lines from the top of
Bram Moolenaar071d4272004-06-13 20:20:40 +000011150 the window. The first line is one.
Bram Moolenaarbfd8fc02005-09-20 23:22:24 +000011151 If the cursor was moved the view on the file will be updated
11152 first, this may cause a scroll.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011153
11154 *winnr()*
Bram Moolenaar5eb86f92004-07-26 12:53:41 +000011155winnr([{arg}]) The result is a Number, which is the number of the current
11156 window. The top window has number 1.
Bram Moolenaar560979e2020-02-04 22:53:05 +010011157 Returns zero for a popup window.
Bram Moolenaar46ad2882019-04-08 20:01:47 +020011158
11159 The optional argument {arg} supports the following values:
11160 $ the number of the last window (the window
11161 count).
11162 # the number of the last accessed window (where
11163 |CTRL-W_p| goes to). If there is no previous
11164 window or it is in another tab page 0 is
11165 returned.
11166 {N}j the number of the Nth window below the
11167 current window (where |CTRL-W_j| goes to).
11168 {N}k the number of the Nth window above the current
11169 window (where |CTRL-W_k| goes to).
11170 {N}h the number of the Nth window left of the
11171 current window (where |CTRL-W_h| goes to).
11172 {N}l the number of the Nth window right of the
11173 current window (where |CTRL-W_l| goes to).
Bram Moolenaar5eb86f92004-07-26 12:53:41 +000011174 The number can be used with |CTRL-W_w| and ":wincmd w"
11175 |:wincmd|.
Bram Moolenaar690afe12017-01-28 18:34:47 +010011176 Also see |tabpagewinnr()| and |win_getid()|.
Bram Moolenaar46ad2882019-04-08 20:01:47 +020011177 Examples: >
11178 let window_count = winnr('$')
11179 let prev_window = winnr('#')
11180 let wnum = winnr('3k')
Bram Moolenaarf92e58c2019-09-08 21:51:41 +020011181
11182< Can also be used as a |method|: >
11183 GetWinval()->winnr()
Bram Moolenaar46ad2882019-04-08 20:01:47 +020011184<
Bram Moolenaar071d4272004-06-13 20:20:40 +000011185 *winrestcmd()*
11186winrestcmd() Returns a sequence of |:resize| commands that should restore
11187 the current window sizes. Only works properly when no windows
Bram Moolenaar87b5ca52006-03-04 21:55:31 +000011188 are opened or closed and the current window and tab page is
11189 unchanged.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011190 Example: >
11191 :let cmd = winrestcmd()
11192 :call MessWithWindowSizes()
11193 :exe cmd
Bram Moolenaar87b5ca52006-03-04 21:55:31 +000011194<
11195 *winrestview()*
11196winrestview({dict})
11197 Uses the |Dictionary| returned by |winsaveview()| to restore
11198 the view of the current window.
Bram Moolenaar82c25852014-05-28 16:47:16 +020011199 Note: The {dict} does not have to contain all values, that are
11200 returned by |winsaveview()|. If values are missing, those
11201 settings won't be restored. So you can use: >
11202 :call winrestview({'curswant': 4})
11203<
11204 This will only set the curswant value (the column the cursor
11205 wants to move on vertical movements) of the cursor to column 5
11206 (yes, that is 5), while all other settings will remain the
11207 same. This is useful, if you set the cursor position manually.
11208
Bram Moolenaar87b5ca52006-03-04 21:55:31 +000011209 If you have changed the values the result is unpredictable.
11210 If the window size changed the result won't be the same.
11211
Bram Moolenaarf92e58c2019-09-08 21:51:41 +020011212 Can also be used as a |method|: >
11213 GetView()->winrestview()
11214<
Bram Moolenaar87b5ca52006-03-04 21:55:31 +000011215 *winsaveview()*
11216winsaveview() Returns a |Dictionary| that contains information to restore
11217 the view of the current window. Use |winrestview()| to
11218 restore the view.
11219 This is useful if you have a mapping that jumps around in the
11220 buffer and you want to go back to the original view.
11221 This does not save fold information. Use the 'foldenable'
Bram Moolenaardb552d602006-03-23 22:59:57 +000011222 option to temporarily switch off folding, so that folds are
Bram Moolenaar07d87792014-07-19 14:04:47 +020011223 not opened when moving around. This may have side effects.
Bram Moolenaar87b5ca52006-03-04 21:55:31 +000011224 The return value includes:
11225 lnum cursor line number
Bram Moolenaar82c25852014-05-28 16:47:16 +020011226 col cursor column (Note: the first column
11227 zero, as opposed to what getpos()
11228 returns)
Bram Moolenaar87b5ca52006-03-04 21:55:31 +000011229 coladd cursor column offset for 'virtualedit'
11230 curswant column for vertical movement
11231 topline first line in the window
11232 topfill filler lines, only in diff mode
11233 leftcol first column displayed
11234 skipcol columns skipped
11235 Note that no option values are saved.
11236
Bram Moolenaar071d4272004-06-13 20:20:40 +000011237
11238winwidth({nr}) *winwidth()*
11239 The result is a Number, which is the width of window {nr}.
Bram Moolenaar7571d552016-08-18 22:54:46 +020011240 {nr} can be the window number or the |window-ID|.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011241 When {nr} is zero, the width of the current window is
11242 returned. When window {nr} doesn't exist, -1 is returned.
11243 An existing window always has a width of zero or more.
11244 Examples: >
11245 :echo "The current window has " . winwidth(0) . " columns."
11246 :if winwidth(0) <= 50
Bram Moolenaar7567d0b2017-11-16 23:04:15 +010011247 : 50 wincmd |
Bram Moolenaar071d4272004-06-13 20:20:40 +000011248 :endif
Bram Moolenaarf8be4612017-06-23 20:52:40 +020011249< For getting the terminal or screen size, see the 'columns'
11250 option.
Bram Moolenaar22fcfad2016-07-01 18:17:26 +020011251
Bram Moolenaarf92e58c2019-09-08 21:51:41 +020011252 Can also be used as a |method|: >
11253 GetWinid()->winwidth()
11254
Bram Moolenaar22fcfad2016-07-01 18:17:26 +020011255
Bram Moolenaared767a22016-01-03 22:49:16 +010011256wordcount() *wordcount()*
11257 The result is a dictionary of byte/chars/word statistics for
11258 the current buffer. This is the same info as provided by
11259 |g_CTRL-G|
11260 The return value includes:
11261 bytes Number of bytes in the buffer
11262 chars Number of chars in the buffer
11263 words Number of words in the buffer
11264 cursor_bytes Number of bytes before cursor position
11265 (not in Visual mode)
11266 cursor_chars Number of chars before cursor position
11267 (not in Visual mode)
11268 cursor_words Number of words before cursor position
11269 (not in Visual mode)
11270 visual_bytes Number of bytes visually selected
Bram Moolenaarf8be4612017-06-23 20:52:40 +020011271 (only in Visual mode)
Bram Moolenaared767a22016-01-03 22:49:16 +010011272 visual_chars Number of chars visually selected
Bram Moolenaarf8be4612017-06-23 20:52:40 +020011273 (only in Visual mode)
Bram Moolenaarc572da52017-08-27 16:52:01 +020011274 visual_words Number of words visually selected
Bram Moolenaarf8be4612017-06-23 20:52:40 +020011275 (only in Visual mode)
Bram Moolenaared767a22016-01-03 22:49:16 +010011276
11277
Bram Moolenaar3a7c85b2005-02-05 21:39:53 +000011278 *writefile()*
Bram Moolenaar6e5ea8d2019-01-12 22:47:31 +010011279writefile({object}, {fname} [, {flags}])
11280 When {object} is a |List| write it to file {fname}. Each list
11281 item is separated with a NL. Each list item must be a String
11282 or Number.
Bram Moolenaar6b2e9382014-11-05 18:06:01 +010011283 When {flags} contains "b" then binary mode is used: There will
Bram Moolenaar3a7c85b2005-02-05 21:39:53 +000011284 not be a NL after the last list item. An empty item at the
11285 end does cause the last line in the file to end in a NL.
Bram Moolenaar6b2e9382014-11-05 18:06:01 +010011286
Bram Moolenaar6e5ea8d2019-01-12 22:47:31 +010011287 When {object} is a |Blob| write the bytes to file {fname}
11288 unmodified.
11289
Bram Moolenaar6b2e9382014-11-05 18:06:01 +010011290 When {flags} contains "a" then append mode is used, lines are
Bram Moolenaar46fceaa2016-10-23 21:21:08 +020011291 appended to the file: >
Bram Moolenaar6b2e9382014-11-05 18:06:01 +010011292 :call writefile(["foo"], "event.log", "a")
11293 :call writefile(["bar"], "event.log", "a")
Bram Moolenaar7567d0b2017-11-16 23:04:15 +010011294<
11295 When {flags} contains "s" then fsync() is called after writing
11296 the file. This flushes the file to disk, if possible. This
11297 takes more time but avoids losing the file if the system
11298 crashes.
Bram Moolenaar74240d32017-12-10 15:26:15 +010011299 When {flags} does not contain "S" or "s" then fsync() is
11300 called if the 'fsync' option is set.
Bram Moolenaar7567d0b2017-11-16 23:04:15 +010011301 When {flags} contains "S" then fsync() is not called, even
11302 when 'fsync' is set.
Bram Moolenaarb0d45e72017-11-05 18:19:24 +010011303
Bram Moolenaar7567d0b2017-11-16 23:04:15 +010011304 All NL characters are replaced with a NUL character.
Bram Moolenaar3a7c85b2005-02-05 21:39:53 +000011305 Inserting CR characters needs to be done before passing {list}
11306 to writefile().
11307 An existing file is overwritten, if possible.
11308 When the write fails -1 is returned, otherwise 0. There is an
11309 error message if the file can't be created or when writing
11310 fails.
11311 Also see |readfile()|.
11312 To copy a file byte for byte: >
11313 :let fl = readfile("foo", "b")
11314 :call writefile(fl, "foocopy", "b")
Bram Moolenaard6e256c2011-12-14 15:32:50 +010011315
Bram Moolenaarf92e58c2019-09-08 21:51:41 +020011316< Can also be used as a |method|: >
11317 GetText()->writefile("thefile")
11318
Bram Moolenaard6e256c2011-12-14 15:32:50 +010011319
11320xor({expr}, {expr}) *xor()*
11321 Bitwise XOR on the two arguments. The arguments are converted
11322 to a number. A List, Dict or Float argument causes an error.
11323 Example: >
11324 :let bits = xor(bits, 0x80)
Bram Moolenaar2e693a82019-10-16 22:35:02 +020011325<
11326 Can also be used as a |method|: >
Bram Moolenaar073e4b92019-08-18 23:01:56 +020011327 :let bits = bits->xor(0x80)
Bram Moolenaar6ee8d892012-01-10 14:55:01 +010011328<
Bram Moolenaard6e256c2011-12-14 15:32:50 +010011329
Bram Moolenaar071d4272004-06-13 20:20:40 +000011330 *feature-list*
Bram Moolenaarade0d392020-01-21 22:33:58 +010011331There are three types of features:
Bram Moolenaar071d4272004-06-13 20:20:40 +0000113321. Features that are only supported when they have been enabled when Vim
11333 was compiled |+feature-list|. Example: >
11334 :if has("cindent")
113352. Features that are only supported when certain conditions have been met.
11336 Example: >
11337 :if has("gui_running")
11338< *has-patch*
Bram Moolenaar2f018892018-05-18 18:12:06 +0200113393. Beyond a certain version or at a certain version and including a specific
11340 patch. The "patch-7.4.248" feature means that the Vim version is 7.5 or
11341 later, or it is version 7.4 and patch 248 was included. Example: >
Bram Moolenaarbcb98982014-05-01 14:08:19 +020011342 :if has("patch-7.4.248")
Bram Moolenaar2f018892018-05-18 18:12:06 +020011343< Note that it's possible for patch 248 to be omitted even though 249 is
11344 included. Only happens when cherry-picking patches.
11345 Note that this form only works for patch 7.4.237 and later, before that
11346 you need to check for the patch and the v:version. Example (checking
11347 version 6.2.148 or later): >
11348 :if v:version > 602 || (v:version == 602 && has("patch148"))
Bram Moolenaar071d4272004-06-13 20:20:40 +000011349
Bram Moolenaard823fa92016-08-12 16:29:27 +020011350Hint: To find out if Vim supports backslashes in a file name (MS-Windows),
11351use: `if exists('+shellslash')`
11352
11353
Bram Moolenaar7cba6c02013-09-05 22:13:31 +020011354acl Compiled with |ACL| support.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011355all_builtin_terms Compiled with all builtin terminals enabled.
11356amiga Amiga version of Vim.
11357arabic Compiled with Arabic support |Arabic|.
11358arp Compiled with ARP support (Amiga).
Bram Moolenaar39536dd2019-01-29 22:58:21 +010011359autocmd Compiled with autocommand support. (always true)
Bram Moolenaar91f84f62018-07-29 15:07:52 +020011360autochdir Compiled with support for 'autochdir'
Bram Moolenaare42a6d22017-11-12 19:21:51 +010011361autoservername Automatically enable |clientserver|
Bram Moolenaar071d4272004-06-13 20:20:40 +000011362balloon_eval Compiled with |balloon-eval| support.
Bram Moolenaar45360022005-07-21 21:08:21 +000011363balloon_multiline GUI supports multiline balloons.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011364beos BeOS version of Vim.
11365browse Compiled with |:browse| support, and browse() will
11366 work.
Bram Moolenaar30b65812012-07-12 22:01:11 +020011367browsefilter Compiled with support for |browsefilter|.
Bram Moolenaar39536dd2019-01-29 22:58:21 +010011368bsd Compiled on an OS in the BSD family (excluding macOS).
Bram Moolenaar071d4272004-06-13 20:20:40 +000011369builtin_terms Compiled with some builtin terminals.
11370byte_offset Compiled with support for 'o' in 'statusline'
Bram Moolenaarbc93ceb2020-02-26 13:36:21 +010011371channel Compiled with support for |channel| and |job|
Bram Moolenaar071d4272004-06-13 20:20:40 +000011372cindent Compiled with 'cindent' support.
11373clientserver Compiled with remote invocation support |clientserver|.
11374clipboard Compiled with 'clipboard' support.
Bram Moolenaar4999a7f2019-08-10 22:21:48 +020011375clipboard_working Compiled with 'clipboard' support and it can be used.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011376cmdline_compl Compiled with |cmdline-completion| support.
11377cmdline_hist Compiled with |cmdline-history| support.
11378cmdline_info Compiled with 'showcmd' and 'ruler' support.
11379comments Compiled with |'comments'| support.
Bram Moolenaar2a8a3ec2011-01-08 16:06:37 +010011380compatible Compiled to be very Vi compatible.
Bram Moolenaaraa5df7e2019-02-03 14:53:10 +010011381conpty Platform where |ConPTY| can be used.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011382cryptv Compiled with encryption support |encryption|.
11383cscope Compiled with |cscope| support.
Bram Moolenaar314dd792019-02-03 15:27:20 +010011384cursorbind Compiled with |'cursorbind'| (always true)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011385debug Compiled with "DEBUG" defined.
11386dialog_con Compiled with console dialog support.
11387dialog_gui Compiled with GUI dialog support.
11388diff Compiled with |vimdiff| and 'diff' support.
11389digraphs Compiled with support for digraphs.
Bram Moolenaar58b85342016-08-14 19:54:54 +020011390directx Compiled with support for DirectX and 'renderoptions'.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011391dnd Compiled with support for the "~ register |quote_~|.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011392ebcdic Compiled on a machine with ebcdic character set.
11393emacs_tags Compiled with support for Emacs tags.
11394eval Compiled with expression evaluation support. Always
11395 true, of course!
Bram Moolenaar39536dd2019-01-29 22:58:21 +010011396ex_extra |+ex_extra| (always true)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011397extra_search Compiled with support for |'incsearch'| and
11398 |'hlsearch'|
Bram Moolenaar4ceaa3a2019-12-03 22:49:09 +010011399farsi Support for Farsi was removed |farsi|.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011400file_in_path Compiled with support for |gf| and |<cfile>|
Bram Moolenaar26a60b42005-02-22 08:49:11 +000011401filterpipe When 'shelltemp' is off pipes are used for shell
11402 read/write/filter commands
Bram Moolenaar071d4272004-06-13 20:20:40 +000011403find_in_path Compiled with support for include file searches
11404 |+find_in_path|.
Bram Moolenaar446cb832008-06-24 21:56:24 +000011405float Compiled with support for |Float|.
Bram Moolenaar5666fcd2019-12-26 14:35:26 +010011406fname_case Case in file names matters (for Amiga and MS-Windows
11407 this is not present).
Bram Moolenaar071d4272004-06-13 20:20:40 +000011408folding Compiled with |folding| support.
11409footer Compiled with GUI footer support. |gui-footer|
11410fork Compiled to use fork()/exec() instead of system().
11411gettext Compiled with message translation |multi-lang|
11412gui Compiled with GUI enabled.
11413gui_athena Compiled with Athena GUI.
Bram Moolenaar2a8a3ec2011-01-08 16:06:37 +010011414gui_gnome Compiled with Gnome support (gui_gtk is also defined).
Bram Moolenaar071d4272004-06-13 20:20:40 +000011415gui_gtk Compiled with GTK+ GUI (any version).
11416gui_gtk2 Compiled with GTK+ 2 GUI (gui_gtk is also defined).
Bram Moolenaar98921892016-02-23 17:14:37 +010011417gui_gtk3 Compiled with GTK+ 3 GUI (gui_gtk is also defined).
Bram Moolenaarb3f74062020-02-26 16:16:53 +010011418gui_haiku Compiled with Haiku GUI.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011419gui_mac Compiled with Macintosh GUI.
11420gui_motif Compiled with Motif GUI.
11421gui_photon Compiled with Photon GUI.
Bram Moolenaar2a8a3ec2011-01-08 16:06:37 +010011422gui_running Vim is running in the GUI, or it will start soon.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011423gui_win32 Compiled with MS Windows Win32 GUI.
11424gui_win32s idem, and Win32s system being used (Windows 3.1)
Bram Moolenaarb3f74062020-02-26 16:16:53 +010011425haiku Haiku version of Vim.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011426hangul_input Compiled with Hangul input support. |hangul|
Bram Moolenaar39536dd2019-01-29 22:58:21 +010011427hpux HP-UX version of Vim.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011428iconv Can use iconv() for conversion.
11429insert_expand Compiled with support for CTRL-X expansion commands in
Bram Moolenaare49fbff2019-08-21 22:50:07 +020011430 Insert mode. (always true)
Bram Moolenaard1caa942020-04-10 22:10:56 +020011431job Compiled with support for |channel| and |job|
Bram Moolenaar352f5542020-04-13 19:04:21 +020011432ipv6 Compiled with support for IPv6 networking in |channel|.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011433jumplist Compiled with |jumplist| support.
11434keymap Compiled with 'keymap' support.
Bram Moolenaar437bafe2016-08-01 15:40:54 +020011435lambda Compiled with |lambda| support.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011436langmap Compiled with 'langmap' support.
11437libcall Compiled with |libcall()| support.
Bram Moolenaar597a4222014-06-25 14:39:50 +020011438linebreak Compiled with 'linebreak', 'breakat', 'showbreak' and
11439 'breakindent' support.
Bram Moolenaar39536dd2019-01-29 22:58:21 +010011440linux Linux version of Vim.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011441lispindent Compiled with support for lisp indenting.
11442listcmds Compiled with commands for the buffer list |:files|
11443 and the argument list |arglist|.
11444localmap Compiled with local mappings and abbr. |:map-local|
Bram Moolenaar0ba04292010-07-14 23:23:17 +020011445lua Compiled with Lua interface |Lua|.
Bram Moolenaard0573012017-10-28 21:11:06 +020011446mac Any Macintosh version of Vim cf. osx
11447macunix Synonym for osxdarwin
Bram Moolenaar071d4272004-06-13 20:20:40 +000011448menu Compiled with support for |:menu|.
11449mksession Compiled with support for |:mksession|.
11450modify_fname Compiled with file name modifiers. |filename-modifiers|
Bram Moolenaara0d1fef2019-09-04 22:29:14 +020011451 (always true)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011452mouse Compiled with support mouse.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011453mouse_dec Compiled with support for Dec terminal mouse.
11454mouse_gpm Compiled with support for gpm (Linux console mouse)
Bram Moolenaar4b8366b2019-05-04 17:34:34 +020011455mouse_gpm_enabled GPM mouse is working
Bram Moolenaar071d4272004-06-13 20:20:40 +000011456mouse_netterm Compiled with support for netterm mouse.
11457mouse_pterm Compiled with support for qnx pterm mouse.
Bram Moolenaar446cb832008-06-24 21:56:24 +000011458mouse_sysmouse Compiled with support for sysmouse (*BSD console mouse)
Bram Moolenaar9b451252012-08-15 17:43:31 +020011459mouse_sgr Compiled with support for sgr mouse.
Bram Moolenaarf1568ec2011-12-14 21:17:39 +010011460mouse_urxvt Compiled with support for urxvt mouse.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011461mouse_xterm Compiled with support for xterm mouse.
Bram Moolenaar2a8a3ec2011-01-08 16:06:37 +010011462mouseshape Compiled with support for 'mouseshape'.
Bram Moolenaar4c92e752019-02-17 21:18:32 +010011463multi_byte Compiled with support for 'encoding' (always true)
Bram Moolenaar207f0092020-08-30 17:20:20 +020011464multi_byte_encoding 'encoding' is set to a multibyte encoding.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011465multi_byte_ime Compiled with support for IME input method.
11466multi_lang Compiled with support for multiple languages.
Bram Moolenaar325b7a22004-07-05 15:58:32 +000011467mzscheme Compiled with MzScheme interface |mzscheme|.
Bram Moolenaarb26e6322010-05-22 21:34:09 +020011468netbeans_enabled Compiled with support for |netbeans| and connected.
Bram Moolenaar2a8a3ec2011-01-08 16:06:37 +010011469netbeans_intg Compiled with support for |netbeans|.
Bram Moolenaar22fcfad2016-07-01 18:17:26 +020011470num64 Compiled with 64-bit |Number| support.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011471ole Compiled with OLE automation support for Win32.
Bram Moolenaard0573012017-10-28 21:11:06 +020011472osx Compiled for macOS cf. mac
11473osxdarwin Compiled for macOS, with |mac-darwin-feature|
Bram Moolenaar91c49372016-05-08 09:50:29 +020011474packages Compiled with |packages| support.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011475path_extra Compiled with up/downwards search in 'path' and 'tags'
11476perl Compiled with Perl interface.
Bram Moolenaar55debbe2010-05-23 23:34:36 +020011477persistent_undo Compiled with support for persistent undo history.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011478postscript Compiled with PostScript file printing.
11479printer Compiled with |:hardcopy| support.
Bram Moolenaar05159a02005-02-26 23:04:13 +000011480profile Compiled with |:profile| support.
Bram Moolenaar84b242c2018-01-28 17:45:49 +010011481python Python 2.x interface available. |has-python|
11482python_compiled Compiled with Python 2.x interface. |has-python|
11483python_dynamic Python 2.x interface is dynamically loaded. |has-python|
11484python3 Python 3.x interface available. |has-python|
11485python3_compiled Compiled with Python 3.x interface. |has-python|
11486python3_dynamic Python 3.x interface is dynamically loaded. |has-python|
Bram Moolenaarbc93ceb2020-02-26 13:36:21 +010011487pythonx Python 2.x and/or 3.x interface available. |python_x|
Bram Moolenaar071d4272004-06-13 20:20:40 +000011488qnx QNX version of Vim.
11489quickfix Compiled with |quickfix| support.
Bram Moolenaard68071d2006-05-02 22:08:30 +000011490reltime Compiled with |reltime()| support.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011491rightleft Compiled with 'rightleft' support.
11492ruby Compiled with Ruby interface |ruby|.
Bram Moolenaar39536dd2019-01-29 22:58:21 +010011493scrollbind Compiled with 'scrollbind' support. (always true)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011494showcmd Compiled with 'showcmd' support.
11495signs Compiled with |:sign| support.
11496smartindent Compiled with 'smartindent' support.
Bram Moolenaar427f5b62019-06-09 13:43:51 +020011497sound Compiled with sound support, e.g. `sound_playevent()`
Bram Moolenaar2a8a3ec2011-01-08 16:06:37 +010011498spell Compiled with spell checking support |spell|.
Bram Moolenaaref94eec2009-11-11 13:22:11 +000011499startuptime Compiled with |--startuptime| support.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011500statusline Compiled with support for 'statusline', 'rulerformat'
11501 and special formats of 'titlestring' and 'iconstring'.
Bram Moolenaar39536dd2019-01-29 22:58:21 +010011502sun SunOS version of Vim.
Bram Moolenaard09091d2019-01-17 16:07:22 +010011503sun_workshop Support for Sun |workshop| has been removed.
Bram Moolenaar82cf9b62005-06-07 21:09:25 +000011504syntax Compiled with syntax highlighting support |syntax|.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011505syntax_items There are active syntax highlighting items for the
11506 current buffer.
11507system Compiled to use system() instead of fork()/exec().
11508tag_binary Compiled with binary searching in tags files
11509 |tag-binary-search|.
Bram Moolenaar723dd942019-04-04 13:11:03 +020011510tag_old_static Support for old static tags was removed, see
Bram Moolenaar071d4272004-06-13 20:20:40 +000011511 |tag-old-static|.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011512tcl Compiled with Tcl interface.
Bram Moolenaar91c49372016-05-08 09:50:29 +020011513termguicolors Compiled with true color in terminal support.
Bram Moolenaarc2ce52c2017-08-01 18:35:38 +020011514terminal Compiled with |terminal| support.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011515terminfo Compiled with terminfo instead of termcap.
11516termresponse Compiled with support for |t_RV| and |v:termresponse|.
11517textobjects Compiled with support for |text-objects|.
Bram Moolenaar98aefe72018-12-13 22:20:09 +010011518textprop Compiled with support for |text-properties|.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011519tgetent Compiled with tgetent support, able to use a termcap
11520 or terminfo file.
Bram Moolenaar975b5272016-03-15 23:10:59 +010011521timers Compiled with |timer_start()| support.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011522title Compiled with window title support |'title'|.
11523toolbar Compiled with support for |gui-toolbar|.
Bram Moolenaar2cab0e12016-11-24 15:09:07 +010011524ttyin input is a terminal (tty)
11525ttyout output is a terminal (tty)
Bram Moolenaar37c64c72017-09-19 22:06:03 +020011526unix Unix version of Vim. *+unix*
Bram Moolenaar3df01732017-02-17 22:47:16 +010011527unnamedplus Compiled with support for "unnamedplus" in 'clipboard'
Bram Moolenaarac9fb182019-04-27 13:04:13 +020011528user_commands User-defined commands. (always true)
Bram Moolenaar4ceaa3a2019-12-03 22:49:09 +010011529vartabs Compiled with variable tabstop support |'vartabstop'|.
Bram Moolenaar22f1d0e2018-02-27 14:53:30 +010011530vcon Win32: Virtual console support is working, can use
11531 'termguicolors'. Also see |+vtp|.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011532vertsplit Compiled with vertically split windows |:vsplit|.
Bram Moolenaar39536dd2019-01-29 22:58:21 +010011533 (always true)
Bram Moolenaar2a8a3ec2011-01-08 16:06:37 +010011534vim_starting True while initial source'ing takes place. |startup|
Bram Moolenaar4f3f6682016-03-26 23:01:59 +010011535 *vim_starting*
Bram Moolenaar2a8a3ec2011-01-08 16:06:37 +010011536viminfo Compiled with viminfo support.
Bram Moolenaar558ca4a2019-04-04 18:15:38 +020011537vimscript-1 Compiled Vim script version 1 support
11538vimscript-2 Compiled Vim script version 2 support
Bram Moolenaar911ead12019-04-21 00:03:35 +020011539vimscript-3 Compiled Vim script version 3 support
Bram Moolenaar39536dd2019-01-29 22:58:21 +010011540virtualedit Compiled with 'virtualedit' option. (always true)
Bram Moolenaar5b69c222019-01-11 14:50:06 +010011541visual Compiled with Visual mode. (always true)
11542visualextra Compiled with extra Visual mode commands. (always
11543 true) |blockwise-operators|.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011544vms VMS version of Vim.
Bram Moolenaar39536dd2019-01-29 22:58:21 +010011545vreplace Compiled with |gR| and |gr| commands. (always true)
Bram Moolenaar98ef2332018-03-18 14:44:37 +010011546vtp Compiled for vcon support |+vtp| (check vcon to find
Bram Moolenaar5a3a49e2018-03-20 18:35:53 +010011547 out if it works in the current console).
Bram Moolenaar071d4272004-06-13 20:20:40 +000011548wildignore Compiled with 'wildignore' option.
11549wildmenu Compiled with 'wildmenu' option.
Bram Moolenaar39536dd2019-01-29 22:58:21 +010011550win16 old version for MS-Windows 3.1 (always false)
Bram Moolenaard58e9292011-02-09 17:07:58 +010011551win32 Win32 version of Vim (MS-Windows 95 and later, 32 or
11552 64 bits)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011553win32unix Win32 version of Vim, using Unix files (Cygwin)
Bram Moolenaar2a8a3ec2011-01-08 16:06:37 +010011554win64 Win64 version of Vim (MS-Windows 64 bit).
Bram Moolenaar39536dd2019-01-29 22:58:21 +010011555win95 Win32 version for MS-Windows 95/98/ME (always false)
Bram Moolenaar2a8a3ec2011-01-08 16:06:37 +010011556winaltkeys Compiled with 'winaltkeys' option.
11557windows Compiled with support for more than one window.
Bram Moolenaar39536dd2019-01-29 22:58:21 +010011558 (always true)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011559writebackup Compiled with 'writebackup' default on.
11560xfontset Compiled with X fontset support |xfontset|.
11561xim Compiled with X input method support |xim|.
Bram Moolenaar7cba6c02013-09-05 22:13:31 +020011562xpm Compiled with pixmap support.
11563xpm_w32 Compiled with pixmap support for Win32. (Only for
11564 backward compatibility. Use "xpm" instead.)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011565xsmp Compiled with X session management support.
11566xsmp_interact Compiled with interactive X session management support.
11567xterm_clipboard Compiled with support for xterm clipboard.
11568xterm_save Compiled with support for saving and restoring the
11569 xterm screen.
11570x11 Compiled with X11 support.
11571
11572 *string-match*
11573Matching a pattern in a String
11574
11575A regexp pattern as explained at |pattern| is normally used to find a match in
11576the buffer lines. When a pattern is used to find a match in a String, almost
11577everything works in the same way. The difference is that a String is handled
11578like it is one line. When it contains a "\n" character, this is not seen as a
11579line break for the pattern. It can be matched with a "\n" in the pattern, or
11580with ".". Example: >
11581 :let a = "aaaa\nxxxx"
11582 :echo matchstr(a, "..\n..")
11583 aa
11584 xx
11585 :echo matchstr(a, "a.x")
11586 a
11587 x
11588
11589Don't forget that "^" will only match at the first character of the String and
11590"$" at the last character of the string. They don't match after or before a
11591"\n".
11592
11593==============================================================================
115945. Defining functions *user-functions*
11595
11596New functions can be defined. These can be called just like builtin
11597functions. The function executes a sequence of Ex commands. Normal mode
11598commands can be executed with the |:normal| command.
11599
Bram Moolenaar8a7d6542020-01-26 15:56:19 +010011600This section is about the legacy functions. For the Vim9 functions, which
11601execute much faster, support type checking and more, see |vim9.txt|.
11602
Bram Moolenaar071d4272004-06-13 20:20:40 +000011603The function name must start with an uppercase letter, to avoid confusion with
11604builtin functions. To prevent from using the same name in different scripts
11605avoid obvious, short names. A good habit is to start the function name with
11606the name of the script, e.g., "HTMLcolor()".
11607
Bram Moolenaar92d640f2005-09-05 22:11:52 +000011608It's also possible to use curly braces, see |curly-braces-names|. And the
11609|autoload| facility is useful to define a function only when it's called.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011610
11611 *local-function*
11612A function local to a script must start with "s:". A local script function
11613can only be called from within the script and from functions, user commands
11614and autocommands defined in the script. It is also possible to call the
Bram Moolenaare37d50a2008-08-06 17:06:04 +000011615function from a mapping defined in the script, but then |<SID>| must be used
Bram Moolenaar071d4272004-06-13 20:20:40 +000011616instead of "s:" when the mapping is expanded outside of the script.
Bram Moolenaarbcb98982014-05-01 14:08:19 +020011617There are only script-local functions, no buffer-local or window-local
11618functions.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011619
11620 *:fu* *:function* *E128* *E129* *E123*
11621:fu[nction] List all functions and their arguments.
11622
11623:fu[nction] {name} List function {name}.
Bram Moolenaar32466aa2006-02-24 23:53:04 +000011624 {name} can also be a |Dictionary| entry that is a
11625 |Funcref|: >
Bram Moolenaar3a3a7232005-01-17 22:16:15 +000011626 :function dict.init
Bram Moolenaar92d640f2005-09-05 22:11:52 +000011627
11628:fu[nction] /{pattern} List functions with a name matching {pattern}.
11629 Example that lists all functions ending with "File": >
11630 :function /File$
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +000011631<
11632 *:function-verbose*
11633When 'verbose' is non-zero, listing a function will also display where it was
11634last defined. Example: >
11635
11636 :verbose function SetFileTypeSH
11637 function SetFileTypeSH(name)
11638 Last set from /usr/share/vim/vim-7.0/filetype.vim
11639<
Bram Moolenaar8aff23a2005-08-19 20:40:30 +000011640See |:verbose-cmd| for more information.
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +000011641
Bram Moolenaarbcb98982014-05-01 14:08:19 +020011642 *E124* *E125* *E853* *E884*
Bram Moolenaar10ce39a2016-07-29 22:37:06 +020011643:fu[nction][!] {name}([arguments]) [range] [abort] [dict] [closure]
Bram Moolenaar01164a62017-11-02 22:58:42 +010011644 Define a new function by the name {name}. The body of
11645 the function follows in the next lines, until the
11646 matching |:endfunction|.
Bram Moolenaarb0d45e72017-11-05 18:19:24 +010011647
Bram Moolenaar01164a62017-11-02 22:58:42 +010011648 The name must be made of alphanumeric characters and
11649 '_', and must start with a capital or "s:" (see
11650 above). Note that using "b:" or "g:" is not allowed.
11651 (since patch 7.4.260 E884 is given if the function
11652 name has a colon in the name, e.g. for "foo:bar()".
11653 Before that patch no error was given).
Bram Moolenaar3a3a7232005-01-17 22:16:15 +000011654
Bram Moolenaar32466aa2006-02-24 23:53:04 +000011655 {name} can also be a |Dictionary| entry that is a
11656 |Funcref|: >
Bram Moolenaar3a3a7232005-01-17 22:16:15 +000011657 :function dict.init(arg)
Bram Moolenaar58b85342016-08-14 19:54:54 +020011658< "dict" must be an existing dictionary. The entry
Bram Moolenaar3a3a7232005-01-17 22:16:15 +000011659 "init" is added if it didn't exist yet. Otherwise [!]
Bram Moolenaar58b85342016-08-14 19:54:54 +020011660 is required to overwrite an existing function. The
Bram Moolenaar3a3a7232005-01-17 22:16:15 +000011661 result is a |Funcref| to a numbered function. The
11662 function can only be used with a |Funcref| and will be
11663 deleted if there are no more references to it.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011664 *E127* *E122*
11665 When a function by this name already exists and [!] is
Bram Moolenaarded5f1b2018-11-10 17:33:29 +010011666 not used an error message is given. There is one
11667 exception: When sourcing a script again, a function
11668 that was previously defined in that script will be
11669 silently replaced.
11670 When [!] is used, an existing function is silently
11671 replaced. Unless it is currently being executed, that
11672 is an error.
Bram Moolenaarf8be4612017-06-23 20:52:40 +020011673 NOTE: Use ! wisely. If used without care it can cause
11674 an existing function to be replaced unexpectedly,
11675 which is hard to debug.
Bram Moolenaar388a5d42020-05-26 21:20:45 +020011676 NOTE: In Vim9 script script-local functions cannot be
11677 deleted or redefined.
Bram Moolenaar8f999f12005-01-25 22:12:55 +000011678
11679 For the {arguments} see |function-argument|.
11680
Bram Moolenaar8d043172014-01-23 14:24:41 +010011681 *:func-range* *a:firstline* *a:lastline*
Bram Moolenaar071d4272004-06-13 20:20:40 +000011682 When the [range] argument is added, the function is
11683 expected to take care of a range itself. The range is
11684 passed as "a:firstline" and "a:lastline". If [range]
11685 is excluded, ":{range}call" will call the function for
11686 each line in the range, with the cursor on the start
11687 of each line. See |function-range-example|.
Bram Moolenaar2df58b42012-11-28 18:21:11 +010011688 The cursor is still moved to the first line of the
11689 range, as is the case with all Ex commands.
Bram Moolenaar8d043172014-01-23 14:24:41 +010011690 *:func-abort*
Bram Moolenaar071d4272004-06-13 20:20:40 +000011691 When the [abort] argument is added, the function will
11692 abort as soon as an error is detected.
Bram Moolenaar8d043172014-01-23 14:24:41 +010011693 *:func-dict*
Bram Moolenaar2fda12f2005-01-15 22:14:15 +000011694 When the [dict] argument is added, the function must
Bram Moolenaar58b85342016-08-14 19:54:54 +020011695 be invoked through an entry in a |Dictionary|. The
Bram Moolenaar2fda12f2005-01-15 22:14:15 +000011696 local variable "self" will then be set to the
11697 dictionary. See |Dictionary-function|.
Bram Moolenaar10ce39a2016-07-29 22:37:06 +020011698 *:func-closure* *E932*
11699 When the [closure] argument is added, the function
11700 can access variables and arguments from the outer
11701 scope. This is usually called a closure. In this
11702 example Bar() uses "x" from the scope of Foo(). It
11703 remains referenced even after Foo() returns: >
11704 :function! Foo()
11705 : let x = 0
11706 : function! Bar() closure
11707 : let x += 1
11708 : return x
11709 : endfunction
Bram Moolenaarbc8801c2016-08-02 21:04:33 +020011710 : return funcref('Bar')
Bram Moolenaar10ce39a2016-07-29 22:37:06 +020011711 :endfunction
11712
11713 :let F = Foo()
11714 :echo F()
11715< 1 >
11716 :echo F()
11717< 2 >
11718 :echo F()
11719< 3
Bram Moolenaar071d4272004-06-13 20:20:40 +000011720
Bram Moolenaar446cb832008-06-24 21:56:24 +000011721 *function-search-undo*
Bram Moolenaar98692072006-02-04 00:57:42 +000011722 The last used search pattern and the redo command "."
Bram Moolenaar446cb832008-06-24 21:56:24 +000011723 will not be changed by the function. This also
11724 implies that the effect of |:nohlsearch| is undone
11725 when the function returns.
Bram Moolenaar98692072006-02-04 00:57:42 +000011726
Bram Moolenaarf8be4612017-06-23 20:52:40 +020011727 *:endf* *:endfunction* *E126* *E193* *W22*
Bram Moolenaar663bb232017-06-22 19:12:10 +020011728:endf[unction] [argument]
11729 The end of a function definition. Best is to put it
11730 on a line by its own, without [argument].
11731
11732 [argument] can be:
11733 | command command to execute next
11734 \n command command to execute next
11735 " comment always ignored
Bram Moolenaarf8be4612017-06-23 20:52:40 +020011736 anything else ignored, warning given when
11737 'verbose' is non-zero
Bram Moolenaar663bb232017-06-22 19:12:10 +020011738 The support for a following command was added in Vim
11739 8.0.0654, before that any argument was silently
11740 ignored.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011741
Bram Moolenaarf8be4612017-06-23 20:52:40 +020011742 To be able to define a function inside an `:execute`
11743 command, use line breaks instead of |:bar|: >
11744 :exe "func Foo()\necho 'foo'\nendfunc"
11745<
Bram Moolenaar437bafe2016-08-01 15:40:54 +020011746 *:delf* *:delfunction* *E130* *E131* *E933*
Bram Moolenaar663bb232017-06-22 19:12:10 +020011747:delf[unction][!] {name}
11748 Delete function {name}.
Bram Moolenaar32466aa2006-02-24 23:53:04 +000011749 {name} can also be a |Dictionary| entry that is a
11750 |Funcref|: >
Bram Moolenaar3a3a7232005-01-17 22:16:15 +000011751 :delfunc dict.init
Bram Moolenaar58b85342016-08-14 19:54:54 +020011752< This will remove the "init" entry from "dict". The
Bram Moolenaar3a3a7232005-01-17 22:16:15 +000011753 function is deleted if there are no more references to
11754 it.
Bram Moolenaar663bb232017-06-22 19:12:10 +020011755 With the ! there is no error if the function does not
11756 exist.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011757 *:retu* *:return* *E133*
11758:retu[rn] [expr] Return from a function. When "[expr]" is given, it is
11759 evaluated and returned as the result of the function.
11760 If "[expr]" is not given, the number 0 is returned.
11761 When a function ends without an explicit ":return",
11762 the number 0 is returned.
11763 Note that there is no check for unreachable lines,
11764 thus there is no warning if commands follow ":return".
11765
11766 If the ":return" is used after a |:try| but before the
11767 matching |:finally| (if present), the commands
11768 following the ":finally" up to the matching |:endtry|
11769 are executed first. This process applies to all
11770 nested ":try"s inside the function. The function
11771 returns at the outermost ":endtry".
11772
Bram Moolenaar8f999f12005-01-25 22:12:55 +000011773 *function-argument* *a:var*
Bram Moolenaar58b85342016-08-14 19:54:54 +020011774An argument can be defined by giving its name. In the function this can then
Bram Moolenaar8f999f12005-01-25 22:12:55 +000011775be used as "a:name" ("a:" for argument).
Bram Moolenaaref2f6562007-05-06 13:32:59 +000011776 *a:0* *a:1* *a:000* *E740* *...*
Bram Moolenaar8f999f12005-01-25 22:12:55 +000011777Up to 20 arguments can be given, separated by commas. After the named
11778arguments an argument "..." can be specified, which means that more arguments
11779may optionally be following. In the function the extra arguments can be used
11780as "a:1", "a:2", etc. "a:0" is set to the number of extra arguments (which
Bram Moolenaar32466aa2006-02-24 23:53:04 +000011781can be 0). "a:000" is set to a |List| that contains these arguments. Note
11782that "a:1" is the same as "a:000[0]".
Bram Moolenaar2ce06f62005-01-31 19:19:04 +000011783 *E742*
11784The a: scope and the variables in it cannot be changed, they are fixed.
Bram Moolenaar069c1e72016-07-15 21:25:08 +020011785However, if a composite type is used, such as |List| or |Dictionary| , you can
11786change their contents. Thus you can pass a |List| to a function and have the
11787function add an item to it. If you want to make sure the function cannot
11788change a |List| or |Dictionary| use |:lockvar|.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011789
Bram Moolenaar8f999f12005-01-25 22:12:55 +000011790It is also possible to define a function without any arguments. You must
Bram Moolenaar01164a62017-11-02 22:58:42 +010011791still supply the () then.
11792
Bram Moolenaar98ef2332018-03-18 14:44:37 +010011793It is allowed to define another function inside a function body.
Bram Moolenaar8f999f12005-01-25 22:12:55 +000011794
Bram Moolenaar42ae78c2019-05-09 21:08:58 +020011795 *optional-function-argument*
11796You can provide default values for positional named arguments. This makes
11797them optional for function calls. When a positional argument is not
11798specified at a call, the default expression is used to initialize it.
Bram Moolenaard1caa942020-04-10 22:10:56 +020011799This only works for functions declared with `:function` or `:def`, not for
11800lambda expressions |expr-lambda|.
Bram Moolenaar42ae78c2019-05-09 21:08:58 +020011801
11802Example: >
11803 function Something(key, value = 10)
Bram Moolenaar8aad88d2019-05-12 13:53:50 +020011804 echo a:key .. ": " .. a:value
Bram Moolenaar42ae78c2019-05-09 21:08:58 +020011805 endfunction
11806 call Something('empty') "empty: 10"
Bram Moolenaar8aad88d2019-05-12 13:53:50 +020011807 call Something('key', 20) "key: 20"
Bram Moolenaar42ae78c2019-05-09 21:08:58 +020011808
11809The argument default expressions are evaluated at the time of the function
11810call, not definition. Thus it is possible to use an expression which is
Bram Moolenaar68e65602019-05-26 21:33:31 +020011811invalid the moment the function is defined. The expressions are also only
Bram Moolenaar42ae78c2019-05-09 21:08:58 +020011812evaluated when arguments are not specified during a call.
Bram Moolenaar2547aa92020-07-26 17:00:44 +020011813 *none-function_argument*
Bram Moolenaar42ae78c2019-05-09 21:08:58 +020011814You can pass |v:none| to use the default expression. Note that this means you
11815cannot pass v:none as an ordinary value when an argument has a default
11816expression.
11817
11818Example: >
11819 function Something(a = 10, b = 20, c = 30)
11820 endfunction
11821 call Something(1, v:none, 3) " b = 20
11822<
11823 *E989*
11824Optional arguments with default expressions must occur after any mandatory
11825arguments. You can use "..." after all optional named arguments.
11826
11827It is possible for later argument defaults to refer to prior arguments,
11828but not the other way around. They must be prefixed with "a:", as with all
11829arguments.
11830
11831Example that works: >
11832 :function Okay(mandatory, optional = a:mandatory)
11833 :endfunction
11834Example that does NOT work: >
11835 :function NoGood(first = a:second, second = 10)
11836 :endfunction
11837<
Bram Moolenaard1caa942020-04-10 22:10:56 +020011838When not using "...", the number of arguments in a function call must be at
11839least equal to the number of mandatory named arguments. When using "...", the
11840number of arguments may be larger than the total of mandatory and optional
11841arguments.
Bram Moolenaar42ae78c2019-05-09 21:08:58 +020011842
Bram Moolenaar8f999f12005-01-25 22:12:55 +000011843 *local-variables*
Bram Moolenaar069c1e72016-07-15 21:25:08 +020011844Inside a function local variables can be used. These will disappear when the
11845function returns. Global variables need to be accessed with "g:".
Bram Moolenaar071d4272004-06-13 20:20:40 +000011846
11847Example: >
11848 :function Table(title, ...)
11849 : echohl Title
11850 : echo a:title
11851 : echohl None
Bram Moolenaar677ee682005-01-27 14:41:15 +000011852 : echo a:0 . " items:"
11853 : for s in a:000
11854 : echon ' ' . s
11855 : endfor
Bram Moolenaar071d4272004-06-13 20:20:40 +000011856 :endfunction
11857
11858This function can then be called with: >
Bram Moolenaar677ee682005-01-27 14:41:15 +000011859 call Table("Table", "line1", "line2")
11860 call Table("Empty Table")
Bram Moolenaar071d4272004-06-13 20:20:40 +000011861
Bram Moolenaaref2f6562007-05-06 13:32:59 +000011862To return more than one value, return a |List|: >
11863 :function Compute(n1, n2)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011864 : if a:n2 == 0
Bram Moolenaaref2f6562007-05-06 13:32:59 +000011865 : return ["fail", 0]
Bram Moolenaar071d4272004-06-13 20:20:40 +000011866 : endif
Bram Moolenaaref2f6562007-05-06 13:32:59 +000011867 : return ["ok", a:n1 / a:n2]
Bram Moolenaar071d4272004-06-13 20:20:40 +000011868 :endfunction
11869
11870This function can then be called with: >
Bram Moolenaaref2f6562007-05-06 13:32:59 +000011871 :let [success, div] = Compute(102, 6)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011872 :if success == "ok"
11873 : echo div
11874 :endif
Bram Moolenaaref2f6562007-05-06 13:32:59 +000011875<
Bram Moolenaar39f05632006-03-19 22:15:26 +000011876 *:cal* *:call* *E107* *E117*
Bram Moolenaar071d4272004-06-13 20:20:40 +000011877:[range]cal[l] {name}([arguments])
11878 Call a function. The name of the function and its arguments
Bram Moolenaar68e65602019-05-26 21:33:31 +020011879 are as specified with `:function`. Up to 20 arguments can be
Bram Moolenaaref2f6562007-05-06 13:32:59 +000011880 used. The returned value is discarded.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011881 Without a range and for functions that accept a range, the
11882 function is called once. When a range is given the cursor is
11883 positioned at the start of the first line before executing the
11884 function.
11885 When a range is given and the function doesn't handle it
11886 itself, the function is executed for each line in the range,
11887 with the cursor in the first column of that line. The cursor
11888 is left at the last line (possibly moved by the last function
Bram Moolenaar58b85342016-08-14 19:54:54 +020011889 call). The arguments are re-evaluated for each line. Thus
Bram Moolenaar071d4272004-06-13 20:20:40 +000011890 this works:
11891 *function-range-example* >
11892 :function Mynumber(arg)
11893 : echo line(".") . " " . a:arg
11894 :endfunction
11895 :1,5call Mynumber(getline("."))
11896<
11897 The "a:firstline" and "a:lastline" are defined anyway, they
11898 can be used to do something different at the start or end of
11899 the range.
11900
11901 Example of a function that handles the range itself: >
11902
11903 :function Cont() range
11904 : execute (a:firstline + 1) . "," . a:lastline . 's/^/\t\\ '
11905 :endfunction
11906 :4,8call Cont()
11907<
11908 This function inserts the continuation character "\" in front
11909 of all the lines in the range, except the first one.
11910
Bram Moolenaaref2f6562007-05-06 13:32:59 +000011911 When the function returns a composite value it can be further
11912 dereferenced, but the range will not be used then. Example: >
11913 :4,8call GetDict().method()
11914< Here GetDict() gets the range but method() does not.
11915
Bram Moolenaar071d4272004-06-13 20:20:40 +000011916 *E132*
11917The recursiveness of user functions is restricted with the |'maxfuncdepth'|
11918option.
11919
Bram Moolenaar25e42232019-08-04 15:04:10 +020011920It is also possible to use `:eval`. It does not support a range, but does
11921allow for method chaining, e.g.: >
11922 eval GetList()->Filter()->append('$')
11923
Bram Moolenaar088e8e32019-08-08 22:15:18 +020011924A function can also be called as part of evaluating an expression or when it
11925is used as a method: >
11926 let x = GetList()
11927 let y = GetList()->Filter()
11928
Bram Moolenaar7c626922005-02-07 22:01:03 +000011929
11930AUTOMATICALLY LOADING FUNCTIONS ~
Bram Moolenaar071d4272004-06-13 20:20:40 +000011931 *autoload-functions*
11932When using many or large functions, it's possible to automatically define them
Bram Moolenaar7c626922005-02-07 22:01:03 +000011933only when they are used. There are two methods: with an autocommand and with
11934the "autoload" directory in 'runtimepath'.
11935
11936
11937Using an autocommand ~
11938
Bram Moolenaar05159a02005-02-26 23:04:13 +000011939This is introduced in the user manual, section |41.14|.
11940
Bram Moolenaar7c626922005-02-07 22:01:03 +000011941The autocommand is useful if you have a plugin that is a long Vim script file.
Bram Moolenaar68e65602019-05-26 21:33:31 +020011942You can define the autocommand and quickly quit the script with `:finish`.
Bram Moolenaar58b85342016-08-14 19:54:54 +020011943That makes Vim startup faster. The autocommand should then load the same file
Bram Moolenaar68e65602019-05-26 21:33:31 +020011944again, setting a variable to skip the `:finish` command.
Bram Moolenaar7c626922005-02-07 22:01:03 +000011945
11946Use the FuncUndefined autocommand event with a pattern that matches the
11947function(s) to be defined. Example: >
Bram Moolenaar071d4272004-06-13 20:20:40 +000011948
11949 :au FuncUndefined BufNet* source ~/vim/bufnetfuncs.vim
11950
11951The file "~/vim/bufnetfuncs.vim" should then define functions that start with
11952"BufNet". Also see |FuncUndefined|.
11953
Bram Moolenaar7c626922005-02-07 22:01:03 +000011954
11955Using an autoload script ~
Bram Moolenaar26a60b42005-02-22 08:49:11 +000011956 *autoload* *E746*
Bram Moolenaar05159a02005-02-26 23:04:13 +000011957This is introduced in the user manual, section |41.15|.
11958
Bram Moolenaar7c626922005-02-07 22:01:03 +000011959Using a script in the "autoload" directory is simpler, but requires using
11960exactly the right file name. A function that can be autoloaded has a name
11961like this: >
11962
Bram Moolenaara7fc0102005-05-18 22:17:12 +000011963 :call filename#funcname()
Bram Moolenaar7c626922005-02-07 22:01:03 +000011964
Bram Moolenaar65e0d772020-06-14 17:29:55 +020011965These functions are always global, in Vim9 script "g:" needs to be used: >
11966 :call g:filename#funcname()
11967
Bram Moolenaar7c626922005-02-07 22:01:03 +000011968When such a function is called, and it is not defined yet, Vim will search the
11969"autoload" directories in 'runtimepath' for a script file called
11970"filename.vim". For example "~/.vim/autoload/filename.vim". That file should
11971then define the function like this: >
11972
Bram Moolenaara7fc0102005-05-18 22:17:12 +000011973 function filename#funcname()
Bram Moolenaar7c626922005-02-07 22:01:03 +000011974 echo "Done!"
11975 endfunction
11976
Bram Moolenaar60a795a2005-09-16 21:55:43 +000011977The file name and the name used before the # in the function must match
Bram Moolenaar7c626922005-02-07 22:01:03 +000011978exactly, and the defined function must have the name exactly as it will be
Bram Moolenaar65e0d772020-06-14 17:29:55 +020011979called. In Vim9 script the "g:" prefix must be used: >
11980 function g:filename#funcname()
11981
11982or for a compiled function: >
11983 def g:filename#funcname()
Bram Moolenaar7c626922005-02-07 22:01:03 +000011984
Bram Moolenaara7fc0102005-05-18 22:17:12 +000011985It is possible to use subdirectories. Every # in the function name works like
11986a path separator. Thus when calling a function: >
Bram Moolenaar7c626922005-02-07 22:01:03 +000011987
Bram Moolenaara7fc0102005-05-18 22:17:12 +000011988 :call foo#bar#func()
Bram Moolenaar7c626922005-02-07 22:01:03 +000011989
11990Vim will look for the file "autoload/foo/bar.vim" in 'runtimepath'.
11991
Bram Moolenaar26a60b42005-02-22 08:49:11 +000011992This also works when reading a variable that has not been set yet: >
11993
Bram Moolenaara7fc0102005-05-18 22:17:12 +000011994 :let l = foo#bar#lvar
Bram Moolenaar26a60b42005-02-22 08:49:11 +000011995
Bram Moolenaara5792f52005-11-23 21:25:05 +000011996However, when the autoload script was already loaded it won't be loaded again
11997for an unknown variable.
11998
Bram Moolenaar26a60b42005-02-22 08:49:11 +000011999When assigning a value to such a variable nothing special happens. This can
12000be used to pass settings to the autoload script before it's loaded: >
12001
Bram Moolenaara7fc0102005-05-18 22:17:12 +000012002 :let foo#bar#toggle = 1
12003 :call foo#bar#func()
Bram Moolenaar26a60b42005-02-22 08:49:11 +000012004
Bram Moolenaar4399ef42005-02-12 14:29:27 +000012005Note that when you make a mistake and call a function that is supposed to be
12006defined in an autoload script, but the script doesn't actually define the
12007function, the script will be sourced every time you try to call the function.
Bram Moolenaar26a60b42005-02-22 08:49:11 +000012008And you will get an error message every time.
12009
12010Also note that if you have two script files, and one calls a function in the
Bram Moolenaar446cb832008-06-24 21:56:24 +000012011other and vice versa, before the used function is defined, it won't work.
Bram Moolenaar26a60b42005-02-22 08:49:11 +000012012Avoid using the autoload functionality at the toplevel.
Bram Moolenaar7c626922005-02-07 22:01:03 +000012013
Bram Moolenaar433f7c82006-03-21 21:29:36 +000012014Hint: If you distribute a bunch of scripts you can pack them together with the
12015|vimball| utility. Also read the user manual |distribute-script|.
12016
Bram Moolenaar071d4272004-06-13 20:20:40 +000012017==============================================================================
120186. Curly braces names *curly-braces-names*
12019
Bram Moolenaar84f72352012-03-11 15:57:40 +010012020In most places where you can use a variable, you can use a "curly braces name"
12021variable. This is a regular variable name with one or more expressions
12022wrapped in braces {} like this: >
Bram Moolenaar071d4272004-06-13 20:20:40 +000012023 my_{adjective}_variable
12024
12025When Vim encounters this, it evaluates the expression inside the braces, puts
12026that in place of the expression, and re-interprets the whole as a variable
12027name. So in the above example, if the variable "adjective" was set to
12028"noisy", then the reference would be to "my_noisy_variable", whereas if
12029"adjective" was set to "quiet", then it would be to "my_quiet_variable".
12030
12031One application for this is to create a set of variables governed by an option
Bram Moolenaar58b85342016-08-14 19:54:54 +020012032value. For example, the statement >
Bram Moolenaar071d4272004-06-13 20:20:40 +000012033 echo my_{&background}_message
12034
12035would output the contents of "my_dark_message" or "my_light_message" depending
12036on the current value of 'background'.
12037
12038You can use multiple brace pairs: >
12039 echo my_{adverb}_{adjective}_message
12040..or even nest them: >
12041 echo my_{ad{end_of_word}}_message
12042where "end_of_word" is either "verb" or "jective".
12043
12044However, the expression inside the braces must evaluate to a valid single
Bram Moolenaar402d2fe2005-04-15 21:00:38 +000012045variable name, e.g. this is invalid: >
Bram Moolenaar071d4272004-06-13 20:20:40 +000012046 :let foo='a + b'
12047 :echo c{foo}d
12048.. since the result of expansion is "ca + bd", which is not a variable name.
12049
12050 *curly-braces-function-names*
12051You can call and define functions by an evaluated name in a similar way.
12052Example: >
12053 :let func_end='whizz'
12054 :call my_func_{func_end}(parameter)
12055
12056This would call the function "my_func_whizz(parameter)".
12057
Bram Moolenaar84f72352012-03-11 15:57:40 +010012058This does NOT work: >
12059 :let i = 3
12060 :let @{i} = '' " error
12061 :echo @{i} " error
12062
Bram Moolenaar071d4272004-06-13 20:20:40 +000012063==============================================================================
120647. Commands *expression-commands*
12065
Bram Moolenaar65e0d772020-06-14 17:29:55 +020012066Note: in Vim9 script `:let` is used for variable declaration, not assignment.
12067An assignment leaves out the `:let` command. |vim9-declaration|
12068
Bram Moolenaar071d4272004-06-13 20:20:40 +000012069:let {var-name} = {expr1} *:let* *E18*
12070 Set internal variable {var-name} to the result of the
12071 expression {expr1}. The variable will get the type
12072 from the {expr}. If {var-name} didn't exist yet, it
12073 is created.
12074
Bram Moolenaar13065c42005-01-08 16:08:21 +000012075:let {var-name}[{idx}] = {expr1} *E689*
12076 Set a list item to the result of the expression
12077 {expr1}. {var-name} must refer to a list and {idx}
12078 must be a valid index in that list. For nested list
12079 the index can be repeated.
Bram Moolenaar446cb832008-06-24 21:56:24 +000012080 This cannot be used to add an item to a |List|.
Bram Moolenaar58b85342016-08-14 19:54:54 +020012081 This cannot be used to set a byte in a String. You
Bram Moolenaar446cb832008-06-24 21:56:24 +000012082 can do that like this: >
12083 :let var = var[0:2] . 'X' . var[4:]
Bram Moolenaar6e5ea8d2019-01-12 22:47:31 +010012084< When {var-name} is a |Blob| then {idx} can be the
12085 length of the blob, in which case one byte is
12086 appended.
12087
Bram Moolenaar3a3a7232005-01-17 22:16:15 +000012088 *E711* *E719*
12089:let {var-name}[{idx1}:{idx2}] = {expr1} *E708* *E709* *E710*
Bram Moolenaar32466aa2006-02-24 23:53:04 +000012090 Set a sequence of items in a |List| to the result of
12091 the expression {expr1}, which must be a list with the
Bram Moolenaar9588a0f2005-01-08 21:45:39 +000012092 correct number of items.
12093 {idx1} can be omitted, zero is used instead.
12094 {idx2} can be omitted, meaning the end of the list.
12095 When the selected range of items is partly past the
12096 end of the list, items will be added.
12097
Bram Moolenaar558ca4a2019-04-04 18:15:38 +020012098 *:let+=* *:let-=* *:letstar=*
12099 *:let/=* *:let%=* *:let.=* *:let..=* *E734* *E985*
Bram Moolenaar3a3a7232005-01-17 22:16:15 +000012100:let {var} += {expr1} Like ":let {var} = {var} + {expr1}".
12101:let {var} -= {expr1} Like ":let {var} = {var} - {expr1}".
Bram Moolenaarff697e62019-02-12 22:28:33 +010012102:let {var} *= {expr1} Like ":let {var} = {var} * {expr1}".
12103:let {var} /= {expr1} Like ":let {var} = {var} / {expr1}".
12104:let {var} %= {expr1} Like ":let {var} = {var} % {expr1}".
Bram Moolenaar3a3a7232005-01-17 22:16:15 +000012105:let {var} .= {expr1} Like ":let {var} = {var} . {expr1}".
Bram Moolenaar558ca4a2019-04-04 18:15:38 +020012106:let {var} ..= {expr1} Like ":let {var} = {var} .. {expr1}".
Bram Moolenaar3a3a7232005-01-17 22:16:15 +000012107 These fail if {var} was not set yet and when the type
12108 of {var} and {expr1} don't fit the operator.
Bram Moolenaar558ca4a2019-04-04 18:15:38 +020012109 `.=` is not supported with Vim script version 2 and
12110 later, see |vimscript-version|.
Bram Moolenaar3a3a7232005-01-17 22:16:15 +000012111
12112
Bram Moolenaar071d4272004-06-13 20:20:40 +000012113:let ${env-name} = {expr1} *:let-environment* *:let-$*
12114 Set environment variable {env-name} to the result of
12115 the expression {expr1}. The type is always String.
Bram Moolenaar56c860c2019-08-17 20:09:31 +020012116
12117 On some systems making an environment variable empty
12118 causes it to be deleted. Many systems do not make a
12119 difference between an environment variable that is not
12120 set and an environment variable that is empty.
12121
Bram Moolenaar3a3a7232005-01-17 22:16:15 +000012122:let ${env-name} .= {expr1}
12123 Append {expr1} to the environment variable {env-name}.
12124 If the environment variable didn't exist yet this
12125 works like "=".
Bram Moolenaar071d4272004-06-13 20:20:40 +000012126
12127:let @{reg-name} = {expr1} *:let-register* *:let-@*
12128 Write the result of the expression {expr1} in register
12129 {reg-name}. {reg-name} must be a single letter, and
12130 must be the name of a writable register (see
12131 |registers|). "@@" can be used for the unnamed
12132 register, "@/" for the search pattern.
12133 If the result of {expr1} ends in a <CR> or <NL>, the
12134 register will be linewise, otherwise it will be set to
12135 characterwise.
12136 This can be used to clear the last search pattern: >
12137 :let @/ = ""
12138< This is different from searching for an empty string,
12139 that would match everywhere.
12140
Bram Moolenaar3a3a7232005-01-17 22:16:15 +000012141:let @{reg-name} .= {expr1}
Bram Moolenaar58b85342016-08-14 19:54:54 +020012142 Append {expr1} to register {reg-name}. If the
Bram Moolenaar3a3a7232005-01-17 22:16:15 +000012143 register was empty it's like setting it to {expr1}.
12144
Bram Moolenaaref2f6562007-05-06 13:32:59 +000012145:let &{option-name} = {expr1} *:let-option* *:let-&*
Bram Moolenaar071d4272004-06-13 20:20:40 +000012146 Set option {option-name} to the result of the
Bram Moolenaarfca34d62005-01-04 21:38:36 +000012147 expression {expr1}. A String or Number value is
12148 always converted to the type of the option.
Bram Moolenaar071d4272004-06-13 20:20:40 +000012149 For an option local to a window or buffer the effect
12150 is just like using the |:set| command: both the local
Bram Moolenaara5fac542005-10-12 20:58:49 +000012151 value and the global value are changed.
Bram Moolenaarfca34d62005-01-04 21:38:36 +000012152 Example: >
12153 :let &path = &path . ',/usr/local/include'
Bram Moolenaar3df01732017-02-17 22:47:16 +010012154< This also works for terminal codes in the form t_xx.
12155 But only for alphanumerical names. Example: >
12156 :let &t_k1 = "\<Esc>[234;"
12157< When the code does not exist yet it will be created as
12158 a terminal key code, there is no error.
Bram Moolenaar071d4272004-06-13 20:20:40 +000012159
Bram Moolenaar3a3a7232005-01-17 22:16:15 +000012160:let &{option-name} .= {expr1}
12161 For a string option: Append {expr1} to the value.
12162 Does not insert a comma like |:set+=|.
12163
12164:let &{option-name} += {expr1}
12165:let &{option-name} -= {expr1}
12166 For a number or boolean option: Add or subtract
12167 {expr1}.
12168
Bram Moolenaar071d4272004-06-13 20:20:40 +000012169:let &l:{option-name} = {expr1}
Bram Moolenaar3a3a7232005-01-17 22:16:15 +000012170:let &l:{option-name} .= {expr1}
12171:let &l:{option-name} += {expr1}
12172:let &l:{option-name} -= {expr1}
Bram Moolenaar071d4272004-06-13 20:20:40 +000012173 Like above, but only set the local value of an option
12174 (if there is one). Works like |:setlocal|.
12175
12176:let &g:{option-name} = {expr1}
Bram Moolenaar3a3a7232005-01-17 22:16:15 +000012177:let &g:{option-name} .= {expr1}
12178:let &g:{option-name} += {expr1}
12179:let &g:{option-name} -= {expr1}
Bram Moolenaar071d4272004-06-13 20:20:40 +000012180 Like above, but only set the global value of an option
12181 (if there is one). Works like |:setglobal|.
12182
Bram Moolenaar13065c42005-01-08 16:08:21 +000012183:let [{name1}, {name2}, ...] = {expr1} *:let-unpack* *E687* *E688*
Bram Moolenaar32466aa2006-02-24 23:53:04 +000012184 {expr1} must evaluate to a |List|. The first item in
Bram Moolenaarfca34d62005-01-04 21:38:36 +000012185 the list is assigned to {name1}, the second item to
12186 {name2}, etc.
12187 The number of names must match the number of items in
Bram Moolenaar32466aa2006-02-24 23:53:04 +000012188 the |List|.
Bram Moolenaarfca34d62005-01-04 21:38:36 +000012189 Each name can be one of the items of the ":let"
12190 command as mentioned above.
12191 Example: >
12192 :let [s, item] = GetItem(s)
Bram Moolenaar3a3a7232005-01-17 22:16:15 +000012193< Detail: {expr1} is evaluated first, then the
12194 assignments are done in sequence. This matters if
12195 {name2} depends on {name1}. Example: >
12196 :let x = [0, 1]
12197 :let i = 0
12198 :let [i, x[i]] = [1, 2]
12199 :echo x
12200< The result is [0, 2].
12201
12202:let [{name1}, {name2}, ...] .= {expr1}
12203:let [{name1}, {name2}, ...] += {expr1}
12204:let [{name1}, {name2}, ...] -= {expr1}
12205 Like above, but append/add/subtract the value for each
Bram Moolenaar32466aa2006-02-24 23:53:04 +000012206 |List| item.
Bram Moolenaarfca34d62005-01-04 21:38:36 +000012207
Bram Moolenaard1caa942020-04-10 22:10:56 +020012208:let [{name}, ..., ; {lastname}] = {expr1} *E452*
Bram Moolenaar32466aa2006-02-24 23:53:04 +000012209 Like |:let-unpack| above, but the |List| may have more
Bram Moolenaar3a3a7232005-01-17 22:16:15 +000012210 items than there are names. A list of the remaining
12211 items is assigned to {lastname}. If there are no
12212 remaining items {lastname} is set to an empty list.
Bram Moolenaarfca34d62005-01-04 21:38:36 +000012213 Example: >
12214 :let [a, b; rest] = ["aval", "bval", 3, 4]
12215<
Bram Moolenaar3a3a7232005-01-17 22:16:15 +000012216:let [{name}, ..., ; {lastname}] .= {expr1}
12217:let [{name}, ..., ; {lastname}] += {expr1}
12218:let [{name}, ..., ; {lastname}] -= {expr1}
12219 Like above, but append/add/subtract the value for each
Bram Moolenaar32466aa2006-02-24 23:53:04 +000012220 |List| item.
Bram Moolenaar4a748032010-09-30 21:47:56 +020012221
Bram Moolenaar24582002019-07-21 14:14:26 +020012222 *:let=<<* *:let-heredoc*
12223 *E990* *E991* *E172* *E221*
Bram Moolenaar2e693a82019-10-16 22:35:02 +020012224:let {var-name} =<< [trim] {endmarker}
Bram Moolenaarf5842c52019-05-19 18:41:26 +020012225text...
12226text...
Bram Moolenaar2e693a82019-10-16 22:35:02 +020012227{endmarker}
Bram Moolenaare46a4402020-06-30 20:38:27 +020012228 Set internal variable {var-name} to a |List|
12229 containing the lines of text bounded by the string
Bram Moolenaaraa970ab2020-08-02 16:10:39 +020012230 {endmarker}. The lines of text is used as a
12231 |literal-string|.
Bram Moolenaar2e693a82019-10-16 22:35:02 +020012232 {endmarker} must not contain white space.
12233 {endmarker} cannot start with a lower case character.
12234 The last line should end only with the {endmarker}
12235 string without any other character. Watch out for
12236 white space after {endmarker}!
Bram Moolenaarf5842c52019-05-19 18:41:26 +020012237
Bram Moolenaare7eb9272019-06-24 00:58:07 +020012238 Without "trim" any white space characters in the lines
12239 of text are preserved. If "trim" is specified before
Bram Moolenaar2e693a82019-10-16 22:35:02 +020012240 {endmarker}, then indentation is stripped so you can
12241 do: >
Bram Moolenaare7eb9272019-06-24 00:58:07 +020012242 let text =<< trim END
12243 if ok
12244 echo 'done'
12245 endif
12246 END
12247< Results in: ["if ok", " echo 'done'", "endif"]
12248 The marker must line up with "let" and the indentation
12249 of the first line is removed from all the text lines.
12250 Specifically: all the leading indentation exactly
12251 matching the leading indentation of the first
12252 non-empty text line is stripped from the input lines.
12253 All leading indentation exactly matching the leading
12254 indentation before `let` is stripped from the line
Bram Moolenaar2e693a82019-10-16 22:35:02 +020012255 containing {endmarker}. Note that the difference
12256 between space and tab matters here.
Bram Moolenaarf5842c52019-05-19 18:41:26 +020012257
12258 If {var-name} didn't exist yet, it is created.
12259 Cannot be followed by another command, but can be
12260 followed by a comment.
12261
Bram Moolenaar2e693a82019-10-16 22:35:02 +020012262 To avoid line continuation to be applied, consider
12263 adding 'C' to 'cpoptions': >
12264 set cpo+=C
12265 let var =<< END
12266 \ leading backslash
12267 END
12268 set cpo-=C
12269<
Bram Moolenaarf5842c52019-05-19 18:41:26 +020012270 Examples: >
12271 let var1 =<< END
Bram Moolenaar2e693a82019-10-16 22:35:02 +020012272 Sample text 1
12273 Sample text 2
12274 Sample text 3
12275 END
Bram Moolenaarf5842c52019-05-19 18:41:26 +020012276
12277 let data =<< trim DATA
Bram Moolenaar2e693a82019-10-16 22:35:02 +020012278 1 2 3 4
12279 5 6 7 8
Bram Moolenaarf5842c52019-05-19 18:41:26 +020012280 DATA
12281<
Bram Moolenaar4a748032010-09-30 21:47:56 +020012282 *E121*
Bram Moolenaar58b85342016-08-14 19:54:54 +020012283:let {var-name} .. List the value of variable {var-name}. Multiple
Bram Moolenaardcaf10e2005-01-21 11:55:25 +000012284 variable names may be given. Special names recognized
12285 here: *E738*
Bram Moolenaarca003e12006-03-17 23:19:38 +000012286 g: global variables
12287 b: local buffer variables
12288 w: local window variables
Bram Moolenaar910f66f2006-04-05 20:41:53 +000012289 t: local tab page variables
Bram Moolenaarca003e12006-03-17 23:19:38 +000012290 s: script-local variables
12291 l: local function variables
Bram Moolenaardcaf10e2005-01-21 11:55:25 +000012292 v: Vim variables.
Bram Moolenaar65e0d772020-06-14 17:29:55 +020012293 This does not work in Vim9 script. |vim9-declaration|
Bram Moolenaar071d4272004-06-13 20:20:40 +000012294
Bram Moolenaard7ee7ce2005-01-03 21:02:03 +000012295:let List the values of all variables. The type of the
12296 variable is indicated before the value:
12297 <nothing> String
12298 # Number
Bram Moolenaarc9b4b052006-04-30 18:54:39 +000012299 * Funcref
Bram Moolenaar65e0d772020-06-14 17:29:55 +020012300 This does not work in Vim9 script. |vim9-declaration|
Bram Moolenaar071d4272004-06-13 20:20:40 +000012301
Bram Moolenaaref2f6562007-05-06 13:32:59 +000012302:unl[et][!] {name} ... *:unlet* *:unl* *E108* *E795*
Bram Moolenaar2ce06f62005-01-31 19:19:04 +000012303 Remove the internal variable {name}. Several variable
12304 names can be given, they are all removed. The name
Bram Moolenaar32466aa2006-02-24 23:53:04 +000012305 may also be a |List| or |Dictionary| item.
Bram Moolenaar071d4272004-06-13 20:20:40 +000012306 With [!] no error message is given for non-existing
12307 variables.
Bram Moolenaar32466aa2006-02-24 23:53:04 +000012308 One or more items from a |List| can be removed: >
Bram Moolenaar9cd15162005-01-16 22:02:49 +000012309 :unlet list[3] " remove fourth item
12310 :unlet list[3:] " remove fourth item to last
Bram Moolenaar32466aa2006-02-24 23:53:04 +000012311< One item from a |Dictionary| can be removed at a time: >
Bram Moolenaar9cd15162005-01-16 22:02:49 +000012312 :unlet dict['two']
12313 :unlet dict.two
Bram Moolenaarc236c162008-07-13 17:41:49 +000012314< This is especially useful to clean up used global
12315 variables and script-local variables (these are not
12316 deleted when the script ends). Function-local
12317 variables are automatically deleted when the function
12318 ends.
Bram Moolenaar071d4272004-06-13 20:20:40 +000012319
Bram Moolenaar137374f2018-05-13 15:59:50 +020012320:unl[et] ${env-name} ... *:unlet-environment* *:unlet-$*
12321 Remove environment variable {env-name}.
12322 Can mix {name} and ${env-name} in one :unlet command.
12323 No error message is given for a non-existing
12324 variable, also without !.
12325 If the system does not support deleting an environment
Bram Moolenaar9937a052019-06-15 15:45:06 +020012326 variable, it is made empty.
Bram Moolenaar137374f2018-05-13 15:59:50 +020012327
Bram Moolenaar1c196e72019-06-16 15:41:58 +020012328 *:cons* *:const*
Bram Moolenaar9937a052019-06-15 15:45:06 +020012329:cons[t] {var-name} = {expr1}
12330:cons[t] [{name1}, {name2}, ...] = {expr1}
Bram Moolenaar9937a052019-06-15 15:45:06 +020012331:cons[t] [{name}, ..., ; {lastname}] = {expr1}
12332:cons[t] {var-name} =<< [trim] {marker}
12333text...
12334text...
12335{marker}
12336 Similar to |:let|, but additionally lock the variable
12337 after setting the value. This is the same as locking
12338 the variable with |:lockvar| just after |:let|, thus: >
12339 :const x = 1
12340< is equivalent to: >
12341 :let x = 1
Bram Moolenaar021bda52020-08-17 21:07:22 +020012342 :lockvar! x
Bram Moolenaar9937a052019-06-15 15:45:06 +020012343< This is useful if you want to make sure the variable
Bram Moolenaar021bda52020-08-17 21:07:22 +020012344 is not modified. If the value is a List or Dictionary
12345 literal then the items also cannot be changed: >
12346 const ll = [1, 2, 3]
12347 let ll[1] = 5 " Error!
12348< Nested references are not locked: >
12349 let lvar = ['a']
12350 const lconst = [0, lvar]
12351 let lconst[0] = 2 " Error!
12352 let lconst[1][0] = 'b' " OK
12353< *E995*
Bram Moolenaar9b283522019-06-17 22:19:33 +020012354 |:const| does not allow to for changing a variable: >
Bram Moolenaar9937a052019-06-15 15:45:06 +020012355 :let x = 1
12356 :const x = 2 " Error!
Bram Moolenaar1c196e72019-06-16 15:41:58 +020012357< *E996*
12358 Note that environment variables, option values and
12359 register values cannot be used here, since they cannot
12360 be locked.
12361
Bram Moolenaar85850f32019-07-19 22:05:51 +020012362:cons[t]
12363:cons[t] {var-name}
12364 If no argument is given or only {var-name} is given,
12365 the behavior is the same as |:let|.
12366
Bram Moolenaar2ce06f62005-01-31 19:19:04 +000012367:lockv[ar][!] [depth] {name} ... *:lockvar* *:lockv*
12368 Lock the internal variable {name}. Locking means that
12369 it can no longer be changed (until it is unlocked).
12370 A locked variable can be deleted: >
12371 :lockvar v
12372 :let v = 'asdf' " fails!
12373 :unlet v
Bram Moolenaare7877fe2017-02-20 22:35:33 +010012374< *E741* *E940*
Bram Moolenaar2ce06f62005-01-31 19:19:04 +000012375 If you try to change a locked variable you get an
Bram Moolenaare7877fe2017-02-20 22:35:33 +010012376 error message: "E741: Value is locked: {name}".
12377 If you try to lock or unlock a built-in variable you
12378 get an error message: "E940: Cannot lock or unlock
12379 variable {name}".
Bram Moolenaar2ce06f62005-01-31 19:19:04 +000012380
Bram Moolenaar32466aa2006-02-24 23:53:04 +000012381 [depth] is relevant when locking a |List| or
12382 |Dictionary|. It specifies how deep the locking goes:
12383 1 Lock the |List| or |Dictionary| itself,
Bram Moolenaar2ce06f62005-01-31 19:19:04 +000012384 cannot add or remove items, but can
12385 still change their values.
12386 2 Also lock the values, cannot change
Bram Moolenaar32466aa2006-02-24 23:53:04 +000012387 the items. If an item is a |List| or
12388 |Dictionary|, cannot add or remove
Bram Moolenaar2ce06f62005-01-31 19:19:04 +000012389 items, but can still change the
12390 values.
Bram Moolenaar32466aa2006-02-24 23:53:04 +000012391 3 Like 2 but for the |List| /
12392 |Dictionary| in the |List| /
12393 |Dictionary|, one level deeper.
12394 The default [depth] is 2, thus when {name} is a |List|
12395 or |Dictionary| the values cannot be changed.
Bram Moolenaar2ce06f62005-01-31 19:19:04 +000012396 *E743*
12397 For unlimited depth use [!] and omit [depth].
12398 However, there is a maximum depth of 100 to catch
12399 loops.
12400
Bram Moolenaar32466aa2006-02-24 23:53:04 +000012401 Note that when two variables refer to the same |List|
12402 and you lock one of them, the |List| will also be
Bram Moolenaar910f66f2006-04-05 20:41:53 +000012403 locked when used through the other variable.
12404 Example: >
Bram Moolenaar2ce06f62005-01-31 19:19:04 +000012405 :let l = [0, 1, 2, 3]
12406 :let cl = l
12407 :lockvar l
12408 :let cl[1] = 99 " won't work!
12409< You may want to make a copy of a list to avoid this.
12410 See |deepcopy()|.
12411
12412
12413:unlo[ckvar][!] [depth] {name} ... *:unlockvar* *:unlo*
12414 Unlock the internal variable {name}. Does the
12415 opposite of |:lockvar|.
12416
Bram Moolenaar61da1bf2019-06-06 12:14:49 +020012417:if {expr1} *:if* *:end* *:endif* *:en* *E171* *E579* *E580*
Bram Moolenaar071d4272004-06-13 20:20:40 +000012418:en[dif] Execute the commands until the next matching ":else"
12419 or ":endif" if {expr1} evaluates to non-zero.
12420
12421 From Vim version 4.5 until 5.0, every Ex command in
12422 between the ":if" and ":endif" is ignored. These two
12423 commands were just to allow for future expansions in a
Bram Moolenaar85084ef2016-01-17 22:26:33 +010012424 backward compatible way. Nesting was allowed. Note
Bram Moolenaar071d4272004-06-13 20:20:40 +000012425 that any ":else" or ":elseif" was ignored, the "else"
12426 part was not executed either.
12427
12428 You can use this to remain compatible with older
12429 versions: >
12430 :if version >= 500
12431 : version-5-specific-commands
12432 :endif
12433< The commands still need to be parsed to find the
12434 "endif". Sometimes an older Vim has a problem with a
12435 new command. For example, ":silent" is recognized as
12436 a ":substitute" command. In that case ":execute" can
12437 avoid problems: >
12438 :if version >= 600
12439 : execute "silent 1,$delete"
12440 :endif
12441<
12442 NOTE: The ":append" and ":insert" commands don't work
12443 properly in between ":if" and ":endif".
12444
12445 *:else* *:el* *E581* *E583*
12446:el[se] Execute the commands until the next matching ":else"
12447 or ":endif" if they previously were not being
12448 executed.
12449
12450 *:elseif* *:elsei* *E582* *E584*
12451:elsei[f] {expr1} Short for ":else" ":if", with the addition that there
12452 is no extra ":endif".
12453
12454:wh[ile] {expr1} *:while* *:endwhile* *:wh* *:endw*
Bram Moolenaar3a3a7232005-01-17 22:16:15 +000012455 *E170* *E585* *E588* *E733*
Bram Moolenaar071d4272004-06-13 20:20:40 +000012456:endw[hile] Repeat the commands between ":while" and ":endwhile",
12457 as long as {expr1} evaluates to non-zero.
12458 When an error is detected from a command inside the
12459 loop, execution continues after the "endwhile".
Bram Moolenaar12805862005-01-05 22:16:17 +000012460 Example: >
12461 :let lnum = 1
12462 :while lnum <= line("$")
12463 :call FixLine(lnum)
12464 :let lnum = lnum + 1
12465 :endwhile
12466<
Bram Moolenaar071d4272004-06-13 20:20:40 +000012467 NOTE: The ":append" and ":insert" commands don't work
Bram Moolenaard8b02732005-01-14 21:48:43 +000012468 properly inside a ":while" and ":for" loop.
Bram Moolenaar071d4272004-06-13 20:20:40 +000012469
Bram Moolenaar5e66b422019-01-24 21:58:10 +010012470:for {var} in {object} *:for* *E690* *E732*
Bram Moolenaar12805862005-01-05 22:16:17 +000012471:endfo[r] *:endfo* *:endfor*
12472 Repeat the commands between ":for" and ":endfor" for
Bram Moolenaar5e66b422019-01-24 21:58:10 +010012473 each item in {object}. {object} can be a |List| or
12474 a |Blob|. Variable {var} is set to the value of each
12475 item. When an error is detected for a command inside
12476 the loop, execution continues after the "endfor".
12477 Changing {object} inside the loop affects what items
12478 are used. Make a copy if this is unwanted: >
Bram Moolenaarde8866b2005-01-06 23:24:37 +000012479 :for item in copy(mylist)
Bram Moolenaar5e66b422019-01-24 21:58:10 +010012480<
12481 When {object} is a |List| and not making a copy, Vim
12482 stores a reference to the next item in the |List|
12483 before executing the commands with the current item.
12484 Thus the current item can be removed without effect.
12485 Removing any later item means it will not be found.
12486 Thus the following example works (an inefficient way
12487 to make a |List| empty): >
Bram Moolenaar8f3f58f2010-01-06 20:52:26 +010012488 for item in mylist
12489 call remove(mylist, 0)
12490 endfor
Bram Moolenaar5e66b422019-01-24 21:58:10 +010012491< Note that reordering the |List| (e.g., with sort() or
Bram Moolenaar9588a0f2005-01-08 21:45:39 +000012492 reverse()) may have unexpected effects.
Bram Moolenaar12805862005-01-05 22:16:17 +000012493
Bram Moolenaar5e66b422019-01-24 21:58:10 +010012494 When {object} is a |Blob|, Vim always makes a copy to
12495 iterate over. Unlike with |List|, modifying the
12496 |Blob| does not affect the iteration.
12497
Bram Moolenaar12805862005-01-05 22:16:17 +000012498:for [{var1}, {var2}, ...] in {listlist}
12499:endfo[r]
12500 Like ":for" above, but each item in {listlist} must be
12501 a list, of which each item is assigned to {var1},
12502 {var2}, etc. Example: >
12503 :for [lnum, col] in [[1, 3], [2, 5], [3, 8]]
12504 :echo getline(lnum)[col]
12505 :endfor
12506<
Bram Moolenaar071d4272004-06-13 20:20:40 +000012507 *:continue* *:con* *E586*
Bram Moolenaar12805862005-01-05 22:16:17 +000012508:con[tinue] When used inside a ":while" or ":for" loop, jumps back
12509 to the start of the loop.
12510 If it is used after a |:try| inside the loop but
12511 before the matching |:finally| (if present), the
12512 commands following the ":finally" up to the matching
12513 |:endtry| are executed first. This process applies to
12514 all nested ":try"s inside the loop. The outermost
12515 ":endtry" then jumps back to the start of the loop.
Bram Moolenaar071d4272004-06-13 20:20:40 +000012516
12517 *:break* *:brea* *E587*
Bram Moolenaar12805862005-01-05 22:16:17 +000012518:brea[k] When used inside a ":while" or ":for" loop, skips to
12519 the command after the matching ":endwhile" or
12520 ":endfor".
12521 If it is used after a |:try| inside the loop but
12522 before the matching |:finally| (if present), the
12523 commands following the ":finally" up to the matching
12524 |:endtry| are executed first. This process applies to
12525 all nested ":try"s inside the loop. The outermost
12526 ":endtry" then jumps to the command after the loop.
Bram Moolenaar071d4272004-06-13 20:20:40 +000012527
12528:try *:try* *:endt* *:endtry* *E600* *E601* *E602*
12529:endt[ry] Change the error handling for the commands between
12530 ":try" and ":endtry" including everything being
12531 executed across ":source" commands, function calls,
12532 or autocommand invocations.
12533
12534 When an error or interrupt is detected and there is
12535 a |:finally| command following, execution continues
12536 after the ":finally". Otherwise, or when the
12537 ":endtry" is reached thereafter, the next
12538 (dynamically) surrounding ":try" is checked for
12539 a corresponding ":finally" etc. Then the script
Bram Moolenaarbc93ceb2020-02-26 13:36:21 +010012540 processing is terminated. Whether a function
12541 definition has an "abort" argument does not matter.
Bram Moolenaar071d4272004-06-13 20:20:40 +000012542 Example: >
Bram Moolenaarbc93ceb2020-02-26 13:36:21 +010012543 try | call Unknown() | finally | echomsg "cleanup" | endtry
12544 echomsg "not reached"
Bram Moolenaar071d4272004-06-13 20:20:40 +000012545<
12546 Moreover, an error or interrupt (dynamically) inside
12547 ":try" and ":endtry" is converted to an exception. It
12548 can be caught as if it were thrown by a |:throw|
12549 command (see |:catch|). In this case, the script
12550 processing is not terminated.
12551
12552 The value "Vim:Interrupt" is used for an interrupt
12553 exception. An error in a Vim command is converted
12554 to a value of the form "Vim({command}):{errmsg}",
12555 other errors are converted to a value of the form
12556 "Vim:{errmsg}". {command} is the full command name,
12557 and {errmsg} is the message that is displayed if the
12558 error exception is not caught, always beginning with
12559 the error number.
12560 Examples: >
Bram Moolenaarbc93ceb2020-02-26 13:36:21 +010012561 try | sleep 100 | catch /^Vim:Interrupt$/ | endtry
12562 try | edit | catch /^Vim(edit):E\d\+/ | echo "error" | endtry
Bram Moolenaar071d4272004-06-13 20:20:40 +000012563<
12564 *:cat* *:catch* *E603* *E604* *E605*
Bram Moolenaar8f3f58f2010-01-06 20:52:26 +010012565:cat[ch] /{pattern}/ The following commands until the next |:catch|,
Bram Moolenaar071d4272004-06-13 20:20:40 +000012566 |:finally|, or |:endtry| that belongs to the same
12567 |:try| as the ":catch" are executed when an exception
12568 matching {pattern} is being thrown and has not yet
12569 been caught by a previous ":catch". Otherwise, these
12570 commands are skipped.
12571 When {pattern} is omitted all errors are caught.
12572 Examples: >
Bram Moolenaar647e24b2019-03-17 16:39:46 +010012573 :catch /^Vim:Interrupt$/ " catch interrupts (CTRL-C)
12574 :catch /^Vim\%((\a\+)\)\=:E/ " catch all Vim errors
12575 :catch /^Vim\%((\a\+)\)\=:/ " catch errors and interrupts
12576 :catch /^Vim(write):/ " catch all errors in :write
12577 :catch /^Vim\%((\a\+)\)\=:E123:/ " catch error E123
12578 :catch /my-exception/ " catch user exception
12579 :catch /.*/ " catch everything
12580 :catch " same as /.*/
Bram Moolenaar071d4272004-06-13 20:20:40 +000012581<
12582 Another character can be used instead of / around the
12583 {pattern}, so long as it does not have a special
12584 meaning (e.g., '|' or '"') and doesn't occur inside
12585 {pattern}.
Bram Moolenaar7e38ea22014-04-05 22:55:53 +020012586 Information about the exception is available in
12587 |v:exception|. Also see |throw-variables|.
Bram Moolenaar071d4272004-06-13 20:20:40 +000012588 NOTE: It is not reliable to ":catch" the TEXT of
12589 an error message because it may vary in different
12590 locales.
12591
12592 *:fina* *:finally* *E606* *E607*
12593:fina[lly] The following commands until the matching |:endtry|
12594 are executed whenever the part between the matching
12595 |:try| and the ":finally" is left: either by falling
12596 through to the ":finally" or by a |:continue|,
12597 |:break|, |:finish|, or |:return|, or by an error or
12598 interrupt or exception (see |:throw|).
12599
12600 *:th* *:throw* *E608*
12601:th[row] {expr1} The {expr1} is evaluated and thrown as an exception.
12602 If the ":throw" is used after a |:try| but before the
12603 first corresponding |:catch|, commands are skipped
12604 until the first ":catch" matching {expr1} is reached.
12605 If there is no such ":catch" or if the ":throw" is
12606 used after a ":catch" but before the |:finally|, the
12607 commands following the ":finally" (if present) up to
12608 the matching |:endtry| are executed. If the ":throw"
12609 is after the ":finally", commands up to the ":endtry"
12610 are skipped. At the ":endtry", this process applies
12611 again for the next dynamically surrounding ":try"
12612 (which may be found in a calling function or sourcing
12613 script), until a matching ":catch" has been found.
12614 If the exception is not caught, the command processing
12615 is terminated.
12616 Example: >
12617 :try | throw "oops" | catch /^oo/ | echo "caught" | endtry
Bram Moolenaar662db672011-03-22 14:05:35 +010012618< Note that "catch" may need to be on a separate line
12619 for when an error causes the parsing to skip the whole
12620 line and not see the "|" that separates the commands.
Bram Moolenaar071d4272004-06-13 20:20:40 +000012621
12622 *:ec* *:echo*
12623:ec[ho] {expr1} .. Echoes each {expr1}, with a space in between. The
12624 first {expr1} starts on a new line.
12625 Also see |:comment|.
12626 Use "\n" to start a new line. Use "\r" to move the
12627 cursor to the first column.
12628 Uses the highlighting set by the |:echohl| command.
12629 Cannot be followed by a comment.
12630 Example: >
12631 :echo "the value of 'shell' is" &shell
Bram Moolenaaref2f6562007-05-06 13:32:59 +000012632< *:echo-redraw*
12633 A later redraw may make the message disappear again.
12634 And since Vim mostly postpones redrawing until it's
12635 finished with a sequence of commands this happens
12636 quite often. To avoid that a command from before the
12637 ":echo" causes a redraw afterwards (redraws are often
12638 postponed until you type something), force a redraw
12639 with the |:redraw| command. Example: >
Bram Moolenaar071d4272004-06-13 20:20:40 +000012640 :new | redraw | echo "there is a new window"
12641<
12642 *:echon*
12643:echon {expr1} .. Echoes each {expr1}, without anything added. Also see
12644 |:comment|.
12645 Uses the highlighting set by the |:echohl| command.
12646 Cannot be followed by a comment.
12647 Example: >
12648 :echon "the value of 'shell' is " &shell
12649<
12650 Note the difference between using ":echo", which is a
12651 Vim command, and ":!echo", which is an external shell
12652 command: >
12653 :!echo % --> filename
12654< The arguments of ":!" are expanded, see |:_%|. >
12655 :!echo "%" --> filename or "filename"
12656< Like the previous example. Whether you see the double
12657 quotes or not depends on your 'shell'. >
12658 :echo % --> nothing
12659< The '%' is an illegal character in an expression. >
12660 :echo "%" --> %
12661< This just echoes the '%' character. >
12662 :echo expand("%") --> filename
12663< This calls the expand() function to expand the '%'.
12664
12665 *:echoh* *:echohl*
12666:echoh[l] {name} Use the highlight group {name} for the following
12667 |:echo|, |:echon| and |:echomsg| commands. Also used
12668 for the |input()| prompt. Example: >
12669 :echohl WarningMsg | echo "Don't panic!" | echohl None
12670< Don't forget to set the group back to "None",
12671 otherwise all following echo's will be highlighted.
12672
12673 *:echom* *:echomsg*
12674:echom[sg] {expr1} .. Echo the expression(s) as a true message, saving the
12675 message in the |message-history|.
12676 Spaces are placed between the arguments as with the
12677 |:echo| command. But unprintable characters are
12678 displayed, not interpreted.
Bram Moolenaaref2f6562007-05-06 13:32:59 +000012679 The parsing works slightly different from |:echo|,
12680 more like |:execute|. All the expressions are first
12681 evaluated and concatenated before echoing anything.
Bram Moolenaar461a7fc2018-12-22 13:28:07 +010012682 If expressions does not evaluate to a Number or
12683 String, string() is used to turn it into a string.
Bram Moolenaar071d4272004-06-13 20:20:40 +000012684 Uses the highlighting set by the |:echohl| command.
12685 Example: >
12686 :echomsg "It's a Zizzer Zazzer Zuzz, as you can plainly see."
Bram Moolenaaref2f6562007-05-06 13:32:59 +000012687< See |:echo-redraw| to avoid the message disappearing
12688 when the screen is redrawn.
Bram Moolenaar071d4272004-06-13 20:20:40 +000012689 *:echoe* *:echoerr*
12690:echoe[rr] {expr1} .. Echo the expression(s) as an error message, saving the
12691 message in the |message-history|. When used in a
12692 script or function the line number will be added.
12693 Spaces are placed between the arguments as with the
Bram Moolenaar461a7fc2018-12-22 13:28:07 +010012694 |:echomsg| command. When used inside a try conditional,
Bram Moolenaar071d4272004-06-13 20:20:40 +000012695 the message is raised as an error exception instead
12696 (see |try-echoerr|).
12697 Example: >
12698 :echoerr "This script just failed!"
12699< If you just want a highlighted message use |:echohl|.
12700 And to get a beep: >
12701 :exe "normal \<Esc>"
12702<
Bram Moolenaar09c6f262019-11-17 15:55:14 +010012703 *:eval*
12704:eval {expr} Evaluate {expr} and discard the result. Example: >
12705 :eval Getlist()->Filter()->append('$')
12706
12707< The expression is supposed to have a side effect,
12708 since the resulting value is not used. In the example
12709 the `append()` call appends the List with text to the
12710 buffer. This is similar to `:call` but works with any
12711 expression.
12712
12713 The command can be shortened to `:ev` or `:eva`, but
12714 these are hard to recognize and therefore not to be
12715 used.
12716
Bram Moolenaarbc93ceb2020-02-26 13:36:21 +010012717 The command cannot be followed by "|" and another
12718 command, since "|" is seen as part of the expression.
12719
Bram Moolenaar09c6f262019-11-17 15:55:14 +010012720
Bram Moolenaar071d4272004-06-13 20:20:40 +000012721 *:exe* *:execute*
12722:exe[cute] {expr1} .. Executes the string that results from the evaluation
Bram Moolenaar00a927d2010-05-14 23:24:24 +020012723 of {expr1} as an Ex command.
12724 Multiple arguments are concatenated, with a space in
12725 between. To avoid the extra space use the "."
12726 operator to concatenate strings into one argument.
12727 {expr1} is used as the processed command, command line
12728 editing keys are not recognized.
Bram Moolenaar071d4272004-06-13 20:20:40 +000012729 Cannot be followed by a comment.
12730 Examples: >
Bram Moolenaar00a927d2010-05-14 23:24:24 +020012731 :execute "buffer" nextbuf
12732 :execute "normal" count . "w"
Bram Moolenaar071d4272004-06-13 20:20:40 +000012733<
12734 ":execute" can be used to append a command to commands
12735 that don't accept a '|'. Example: >
12736 :execute '!ls' | echo "theend"
12737
12738< ":execute" is also a nice way to avoid having to type
12739 control characters in a Vim script for a ":normal"
12740 command: >
12741 :execute "normal ixxx\<Esc>"
12742< This has an <Esc> character, see |expr-string|.
12743
Bram Moolenaar446cb832008-06-24 21:56:24 +000012744 Be careful to correctly escape special characters in
12745 file names. The |fnameescape()| function can be used
Bram Moolenaar05bb9532008-07-04 09:44:11 +000012746 for Vim commands, |shellescape()| for |:!| commands.
12747 Examples: >
Bram Moolenaar446cb832008-06-24 21:56:24 +000012748 :execute "e " . fnameescape(filename)
Bram Moolenaar251835e2014-02-24 02:51:51 +010012749 :execute "!ls " . shellescape(filename, 1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000012750<
Bram Moolenaar071d4272004-06-13 20:20:40 +000012751 Note: The executed string may be any command-line, but
Bram Moolenaar76f3b1a2014-03-27 22:30:07 +010012752 starting or ending "if", "while" and "for" does not
12753 always work, because when commands are skipped the
12754 ":execute" is not evaluated and Vim loses track of
12755 where blocks start and end. Also "break" and
12756 "continue" should not be inside ":execute".
12757 This example does not work, because the ":execute" is
12758 not evaluated and Vim does not see the "while", and
12759 gives an error for finding an ":endwhile": >
12760 :if 0
12761 : execute 'while i > 5'
12762 : echo "test"
12763 : endwhile
12764 :endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000012765<
12766 It is allowed to have a "while" or "if" command
12767 completely in the executed string: >
12768 :execute 'while i < 5 | echo i | let i = i + 1 | endwhile'
12769<
12770
Bram Moolenaar8f3f58f2010-01-06 20:52:26 +010012771 *:exe-comment*
Bram Moolenaar071d4272004-06-13 20:20:40 +000012772 ":execute", ":echo" and ":echon" cannot be followed by
12773 a comment directly, because they see the '"' as the
12774 start of a string. But, you can use '|' followed by a
12775 comment. Example: >
12776 :echo "foo" | "this is a comment
12777
12778==============================================================================
127798. Exception handling *exception-handling*
12780
12781The Vim script language comprises an exception handling feature. This section
12782explains how it can be used in a Vim script.
12783
12784Exceptions may be raised by Vim on an error or on interrupt, see
12785|catch-errors| and |catch-interrupt|. You can also explicitly throw an
12786exception by using the ":throw" command, see |throw-catch|.
12787
12788
12789TRY CONDITIONALS *try-conditionals*
12790
12791Exceptions can be caught or can cause cleanup code to be executed. You can
12792use a try conditional to specify catch clauses (that catch exceptions) and/or
12793a finally clause (to be executed for cleanup).
12794 A try conditional begins with a |:try| command and ends at the matching
12795|:endtry| command. In between, you can use a |:catch| command to start
12796a catch clause, or a |:finally| command to start a finally clause. There may
12797be none or multiple catch clauses, but there is at most one finally clause,
12798which must not be followed by any catch clauses. The lines before the catch
12799clauses and the finally clause is called a try block. >
12800
12801 :try
Bram Moolenaar446cb832008-06-24 21:56:24 +000012802 : ...
12803 : ... TRY BLOCK
12804 : ...
Bram Moolenaar071d4272004-06-13 20:20:40 +000012805 :catch /{pattern}/
Bram Moolenaar446cb832008-06-24 21:56:24 +000012806 : ...
12807 : ... CATCH CLAUSE
12808 : ...
Bram Moolenaar071d4272004-06-13 20:20:40 +000012809 :catch /{pattern}/
Bram Moolenaar446cb832008-06-24 21:56:24 +000012810 : ...
12811 : ... CATCH CLAUSE
12812 : ...
Bram Moolenaar071d4272004-06-13 20:20:40 +000012813 :finally
Bram Moolenaar446cb832008-06-24 21:56:24 +000012814 : ...
12815 : ... FINALLY CLAUSE
12816 : ...
Bram Moolenaar071d4272004-06-13 20:20:40 +000012817 :endtry
12818
12819The try conditional allows to watch code for exceptions and to take the
12820appropriate actions. Exceptions from the try block may be caught. Exceptions
12821from the try block and also the catch clauses may cause cleanup actions.
12822 When no exception is thrown during execution of the try block, the control
12823is transferred to the finally clause, if present. After its execution, the
12824script continues with the line following the ":endtry".
12825 When an exception occurs during execution of the try block, the remaining
12826lines in the try block are skipped. The exception is matched against the
12827patterns specified as arguments to the ":catch" commands. The catch clause
12828after the first matching ":catch" is taken, other catch clauses are not
12829executed. The catch clause ends when the next ":catch", ":finally", or
12830":endtry" command is reached - whatever is first. Then, the finally clause
12831(if present) is executed. When the ":endtry" is reached, the script execution
12832continues in the following line as usual.
12833 When an exception that does not match any of the patterns specified by the
12834":catch" commands is thrown in the try block, the exception is not caught by
12835that try conditional and none of the catch clauses is executed. Only the
12836finally clause, if present, is taken. The exception pends during execution of
12837the finally clause. It is resumed at the ":endtry", so that commands after
12838the ":endtry" are not executed and the exception might be caught elsewhere,
12839see |try-nesting|.
12840 When during execution of a catch clause another exception is thrown, the
Bram Moolenaar58b85342016-08-14 19:54:54 +020012841remaining lines in that catch clause are not executed. The new exception is
Bram Moolenaar071d4272004-06-13 20:20:40 +000012842not matched against the patterns in any of the ":catch" commands of the same
12843try conditional and none of its catch clauses is taken. If there is, however,
12844a finally clause, it is executed, and the exception pends during its
12845execution. The commands following the ":endtry" are not executed. The new
12846exception might, however, be caught elsewhere, see |try-nesting|.
12847 When during execution of the finally clause (if present) an exception is
Bram Moolenaar58b85342016-08-14 19:54:54 +020012848thrown, the remaining lines in the finally clause are skipped. If the finally
Bram Moolenaar071d4272004-06-13 20:20:40 +000012849clause has been taken because of an exception from the try block or one of the
12850catch clauses, the original (pending) exception is discarded. The commands
12851following the ":endtry" are not executed, and the exception from the finally
12852clause is propagated and can be caught elsewhere, see |try-nesting|.
12853
12854The finally clause is also executed, when a ":break" or ":continue" for
12855a ":while" loop enclosing the complete try conditional is executed from the
12856try block or a catch clause. Or when a ":return" or ":finish" is executed
12857from the try block or a catch clause of a try conditional in a function or
12858sourced script, respectively. The ":break", ":continue", ":return", or
12859":finish" pends during execution of the finally clause and is resumed when the
12860":endtry" is reached. It is, however, discarded when an exception is thrown
12861from the finally clause.
12862 When a ":break" or ":continue" for a ":while" loop enclosing the complete
12863try conditional or when a ":return" or ":finish" is encountered in the finally
12864clause, the rest of the finally clause is skipped, and the ":break",
12865":continue", ":return" or ":finish" is executed as usual. If the finally
12866clause has been taken because of an exception or an earlier ":break",
12867":continue", ":return", or ":finish" from the try block or a catch clause,
12868this pending exception or command is discarded.
12869
12870For examples see |throw-catch| and |try-finally|.
12871
12872
12873NESTING OF TRY CONDITIONALS *try-nesting*
12874
12875Try conditionals can be nested arbitrarily. That is, a complete try
12876conditional can be put into the try block, a catch clause, or the finally
12877clause of another try conditional. If the inner try conditional does not
12878catch an exception thrown in its try block or throws a new exception from one
12879of its catch clauses or its finally clause, the outer try conditional is
12880checked according to the rules above. If the inner try conditional is in the
12881try block of the outer try conditional, its catch clauses are checked, but
Bram Moolenaar58b85342016-08-14 19:54:54 +020012882otherwise only the finally clause is executed. It does not matter for
Bram Moolenaar071d4272004-06-13 20:20:40 +000012883nesting, whether the inner try conditional is directly contained in the outer
12884one, or whether the outer one sources a script or calls a function containing
12885the inner try conditional.
12886
12887When none of the active try conditionals catches an exception, just their
12888finally clauses are executed. Thereafter, the script processing terminates.
12889An error message is displayed in case of an uncaught exception explicitly
12890thrown by a ":throw" command. For uncaught error and interrupt exceptions
12891implicitly raised by Vim, the error message(s) or interrupt message are shown
12892as usual.
12893
12894For examples see |throw-catch|.
12895
12896
12897EXAMINING EXCEPTION HANDLING CODE *except-examine*
12898
12899Exception handling code can get tricky. If you are in doubt what happens, set
12900'verbose' to 13 or use the ":13verbose" command modifier when sourcing your
12901script file. Then you see when an exception is thrown, discarded, caught, or
12902finished. When using a verbosity level of at least 14, things pending in
12903a finally clause are also shown. This information is also given in debug mode
12904(see |debug-scripts|).
12905
12906
12907THROWING AND CATCHING EXCEPTIONS *throw-catch*
12908
12909You can throw any number or string as an exception. Use the |:throw| command
12910and pass the value to be thrown as argument: >
12911 :throw 4711
12912 :throw "string"
12913< *throw-expression*
12914You can also specify an expression argument. The expression is then evaluated
12915first, and the result is thrown: >
12916 :throw 4705 + strlen("string")
12917 :throw strpart("strings", 0, 6)
12918
12919An exception might be thrown during evaluation of the argument of the ":throw"
12920command. Unless it is caught there, the expression evaluation is abandoned.
12921The ":throw" command then does not throw a new exception.
12922 Example: >
12923
12924 :function! Foo(arg)
12925 : try
12926 : throw a:arg
12927 : catch /foo/
12928 : endtry
12929 : return 1
12930 :endfunction
12931 :
12932 :function! Bar()
12933 : echo "in Bar"
12934 : return 4710
12935 :endfunction
12936 :
12937 :throw Foo("arrgh") + Bar()
12938
12939This throws "arrgh", and "in Bar" is not displayed since Bar() is not
12940executed. >
12941 :throw Foo("foo") + Bar()
12942however displays "in Bar" and throws 4711.
12943
12944Any other command that takes an expression as argument might also be
Bram Moolenaar58b85342016-08-14 19:54:54 +020012945abandoned by an (uncaught) exception during the expression evaluation. The
Bram Moolenaar071d4272004-06-13 20:20:40 +000012946exception is then propagated to the caller of the command.
12947 Example: >
12948
12949 :if Foo("arrgh")
12950 : echo "then"
12951 :else
12952 : echo "else"
12953 :endif
12954
12955Here neither of "then" or "else" is displayed.
12956
12957 *catch-order*
12958Exceptions can be caught by a try conditional with one or more |:catch|
12959commands, see |try-conditionals|. The values to be caught by each ":catch"
12960command can be specified as a pattern argument. The subsequent catch clause
12961gets executed when a matching exception is caught.
12962 Example: >
12963
12964 :function! Foo(value)
12965 : try
12966 : throw a:value
12967 : catch /^\d\+$/
12968 : echo "Number thrown"
12969 : catch /.*/
12970 : echo "String thrown"
12971 : endtry
12972 :endfunction
12973 :
12974 :call Foo(0x1267)
12975 :call Foo('string')
12976
12977The first call to Foo() displays "Number thrown", the second "String thrown".
12978An exception is matched against the ":catch" commands in the order they are
12979specified. Only the first match counts. So you should place the more
12980specific ":catch" first. The following order does not make sense: >
12981
12982 : catch /.*/
12983 : echo "String thrown"
12984 : catch /^\d\+$/
12985 : echo "Number thrown"
12986
12987The first ":catch" here matches always, so that the second catch clause is
12988never taken.
12989
12990 *throw-variables*
12991If you catch an exception by a general pattern, you may access the exact value
12992in the variable |v:exception|: >
12993
12994 : catch /^\d\+$/
12995 : echo "Number thrown. Value is" v:exception
12996
12997You may also be interested where an exception was thrown. This is stored in
12998|v:throwpoint|. Note that "v:exception" and "v:throwpoint" are valid for the
12999exception most recently caught as long it is not finished.
13000 Example: >
13001
13002 :function! Caught()
13003 : if v:exception != ""
13004 : echo 'Caught "' . v:exception . '" in ' . v:throwpoint
13005 : else
13006 : echo 'Nothing caught'
13007 : endif
13008 :endfunction
13009 :
13010 :function! Foo()
13011 : try
13012 : try
13013 : try
13014 : throw 4711
13015 : finally
13016 : call Caught()
13017 : endtry
13018 : catch /.*/
13019 : call Caught()
13020 : throw "oops"
13021 : endtry
13022 : catch /.*/
13023 : call Caught()
13024 : finally
13025 : call Caught()
13026 : endtry
13027 :endfunction
13028 :
13029 :call Foo()
13030
13031This displays >
13032
13033 Nothing caught
13034 Caught "4711" in function Foo, line 4
13035 Caught "oops" in function Foo, line 10
13036 Nothing caught
13037
13038A practical example: The following command ":LineNumber" displays the line
13039number in the script or function where it has been used: >
13040
13041 :function! LineNumber()
13042 : return substitute(v:throwpoint, '.*\D\(\d\+\).*', '\1', "")
13043 :endfunction
13044 :command! LineNumber try | throw "" | catch | echo LineNumber() | endtry
13045<
13046 *try-nested*
13047An exception that is not caught by a try conditional can be caught by
13048a surrounding try conditional: >
13049
13050 :try
13051 : try
13052 : throw "foo"
13053 : catch /foobar/
13054 : echo "foobar"
13055 : finally
13056 : echo "inner finally"
13057 : endtry
13058 :catch /foo/
13059 : echo "foo"
13060 :endtry
13061
13062The inner try conditional does not catch the exception, just its finally
13063clause is executed. The exception is then caught by the outer try
13064conditional. The example displays "inner finally" and then "foo".
13065
13066 *throw-from-catch*
13067You can catch an exception and throw a new one to be caught elsewhere from the
13068catch clause: >
13069
13070 :function! Foo()
13071 : throw "foo"
13072 :endfunction
13073 :
13074 :function! Bar()
13075 : try
13076 : call Foo()
13077 : catch /foo/
13078 : echo "Caught foo, throw bar"
13079 : throw "bar"
13080 : endtry
13081 :endfunction
13082 :
13083 :try
13084 : call Bar()
13085 :catch /.*/
13086 : echo "Caught" v:exception
13087 :endtry
13088
13089This displays "Caught foo, throw bar" and then "Caught bar".
13090
13091 *rethrow*
13092There is no real rethrow in the Vim script language, but you may throw
13093"v:exception" instead: >
13094
13095 :function! Bar()
13096 : try
13097 : call Foo()
13098 : catch /.*/
13099 : echo "Rethrow" v:exception
13100 : throw v:exception
13101 : endtry
13102 :endfunction
13103< *try-echoerr*
13104Note that this method cannot be used to "rethrow" Vim error or interrupt
13105exceptions, because it is not possible to fake Vim internal exceptions.
13106Trying so causes an error exception. You should throw your own exception
13107denoting the situation. If you want to cause a Vim error exception containing
13108the original error exception value, you can use the |:echoerr| command: >
13109
13110 :try
13111 : try
13112 : asdf
13113 : catch /.*/
13114 : echoerr v:exception
13115 : endtry
13116 :catch /.*/
13117 : echo v:exception
13118 :endtry
13119
13120This code displays
13121
Bram Moolenaar446cb832008-06-24 21:56:24 +000013122 Vim(echoerr):Vim:E492: Not an editor command: asdf ~
Bram Moolenaar071d4272004-06-13 20:20:40 +000013123
13124
13125CLEANUP CODE *try-finally*
13126
13127Scripts often change global settings and restore them at their end. If the
13128user however interrupts the script by pressing CTRL-C, the settings remain in
Bram Moolenaar58b85342016-08-14 19:54:54 +020013129an inconsistent state. The same may happen to you in the development phase of
Bram Moolenaar071d4272004-06-13 20:20:40 +000013130a script when an error occurs or you explicitly throw an exception without
13131catching it. You can solve these problems by using a try conditional with
13132a finally clause for restoring the settings. Its execution is guaranteed on
13133normal control flow, on error, on an explicit ":throw", and on interrupt.
13134(Note that errors and interrupts from inside the try conditional are converted
Bram Moolenaar58b85342016-08-14 19:54:54 +020013135to exceptions. When not caught, they terminate the script after the finally
Bram Moolenaar071d4272004-06-13 20:20:40 +000013136clause has been executed.)
13137Example: >
13138
13139 :try
13140 : let s:saved_ts = &ts
13141 : set ts=17
13142 :
13143 : " Do the hard work here.
13144 :
13145 :finally
13146 : let &ts = s:saved_ts
13147 : unlet s:saved_ts
13148 :endtry
13149
13150This method should be used locally whenever a function or part of a script
13151changes global settings which need to be restored on failure or normal exit of
13152that function or script part.
13153
13154 *break-finally*
13155Cleanup code works also when the try block or a catch clause is left by
13156a ":continue", ":break", ":return", or ":finish".
13157 Example: >
13158
13159 :let first = 1
13160 :while 1
13161 : try
13162 : if first
13163 : echo "first"
13164 : let first = 0
13165 : continue
13166 : else
13167 : throw "second"
13168 : endif
13169 : catch /.*/
13170 : echo v:exception
13171 : break
13172 : finally
13173 : echo "cleanup"
13174 : endtry
13175 : echo "still in while"
13176 :endwhile
13177 :echo "end"
13178
13179This displays "first", "cleanup", "second", "cleanup", and "end". >
13180
13181 :function! Foo()
13182 : try
13183 : return 4711
13184 : finally
13185 : echo "cleanup\n"
13186 : endtry
13187 : echo "Foo still active"
13188 :endfunction
13189 :
13190 :echo Foo() "returned by Foo"
13191
13192This displays "cleanup" and "4711 returned by Foo". You don't need to add an
Bram Moolenaar58b85342016-08-14 19:54:54 +020013193extra ":return" in the finally clause. (Above all, this would override the
Bram Moolenaar071d4272004-06-13 20:20:40 +000013194return value.)
13195
13196 *except-from-finally*
13197Using either of ":continue", ":break", ":return", ":finish", or ":throw" in
13198a finally clause is possible, but not recommended since it abandons the
13199cleanup actions for the try conditional. But, of course, interrupt and error
13200exceptions might get raised from a finally clause.
13201 Example where an error in the finally clause stops an interrupt from
13202working correctly: >
13203
13204 :try
13205 : try
13206 : echo "Press CTRL-C for interrupt"
13207 : while 1
13208 : endwhile
13209 : finally
13210 : unlet novar
13211 : endtry
13212 :catch /novar/
13213 :endtry
13214 :echo "Script still running"
13215 :sleep 1
13216
13217If you need to put commands that could fail into a finally clause, you should
13218think about catching or ignoring the errors in these commands, see
13219|catch-errors| and |ignore-errors|.
13220
13221
13222CATCHING ERRORS *catch-errors*
13223
13224If you want to catch specific errors, you just have to put the code to be
13225watched in a try block and add a catch clause for the error message. The
13226presence of the try conditional causes all errors to be converted to an
13227exception. No message is displayed and |v:errmsg| is not set then. To find
13228the right pattern for the ":catch" command, you have to know how the format of
13229the error exception is.
13230 Error exceptions have the following format: >
13231
13232 Vim({cmdname}):{errmsg}
13233or >
13234 Vim:{errmsg}
13235
13236{cmdname} is the name of the command that failed; the second form is used when
Bram Moolenaar58b85342016-08-14 19:54:54 +020013237the command name is not known. {errmsg} is the error message usually produced
Bram Moolenaar071d4272004-06-13 20:20:40 +000013238when the error occurs outside try conditionals. It always begins with
13239a capital "E", followed by a two or three-digit error number, a colon, and
13240a space.
13241
13242Examples:
13243
13244The command >
13245 :unlet novar
13246normally produces the error message >
13247 E108: No such variable: "novar"
13248which is converted inside try conditionals to an exception >
13249 Vim(unlet):E108: No such variable: "novar"
13250
13251The command >
13252 :dwim
13253normally produces the error message >
13254 E492: Not an editor command: dwim
13255which is converted inside try conditionals to an exception >
13256 Vim:E492: Not an editor command: dwim
13257
13258You can catch all ":unlet" errors by a >
13259 :catch /^Vim(unlet):/
13260or all errors for misspelled command names by a >
13261 :catch /^Vim:E492:/
13262
13263Some error messages may be produced by different commands: >
13264 :function nofunc
13265and >
13266 :delfunction nofunc
13267both produce the error message >
13268 E128: Function name must start with a capital: nofunc
13269which is converted inside try conditionals to an exception >
13270 Vim(function):E128: Function name must start with a capital: nofunc
13271or >
13272 Vim(delfunction):E128: Function name must start with a capital: nofunc
13273respectively. You can catch the error by its number independently on the
13274command that caused it if you use the following pattern: >
13275 :catch /^Vim(\a\+):E128:/
13276
13277Some commands like >
13278 :let x = novar
13279produce multiple error messages, here: >
13280 E121: Undefined variable: novar
13281 E15: Invalid expression: novar
13282Only the first is used for the exception value, since it is the most specific
13283one (see |except-several-errors|). So you can catch it by >
13284 :catch /^Vim(\a\+):E121:/
13285
13286You can catch all errors related to the name "nofunc" by >
13287 :catch /\<nofunc\>/
13288
13289You can catch all Vim errors in the ":write" and ":read" commands by >
13290 :catch /^Vim(\(write\|read\)):E\d\+:/
13291
13292You can catch all Vim errors by the pattern >
13293 :catch /^Vim\((\a\+)\)\=:E\d\+:/
13294<
13295 *catch-text*
13296NOTE: You should never catch the error message text itself: >
13297 :catch /No such variable/
Bram Moolenaar2b8388b2015-02-28 13:11:45 +010013298only works in the English locale, but not when the user has selected
Bram Moolenaar071d4272004-06-13 20:20:40 +000013299a different language by the |:language| command. It is however helpful to
13300cite the message text in a comment: >
13301 :catch /^Vim(\a\+):E108:/ " No such variable
13302
13303
13304IGNORING ERRORS *ignore-errors*
13305
13306You can ignore errors in a specific Vim command by catching them locally: >
13307
13308 :try
13309 : write
13310 :catch
13311 :endtry
13312
13313But you are strongly recommended NOT to use this simple form, since it could
13314catch more than you want. With the ":write" command, some autocommands could
13315be executed and cause errors not related to writing, for instance: >
13316
13317 :au BufWritePre * unlet novar
13318
13319There could even be such errors you are not responsible for as a script
13320writer: a user of your script might have defined such autocommands. You would
13321then hide the error from the user.
13322 It is much better to use >
13323
13324 :try
13325 : write
13326 :catch /^Vim(write):/
13327 :endtry
13328
13329which only catches real write errors. So catch only what you'd like to ignore
13330intentionally.
13331
13332For a single command that does not cause execution of autocommands, you could
13333even suppress the conversion of errors to exceptions by the ":silent!"
13334command: >
13335 :silent! nunmap k
13336This works also when a try conditional is active.
13337
13338
13339CATCHING INTERRUPTS *catch-interrupt*
13340
13341When there are active try conditionals, an interrupt (CTRL-C) is converted to
Bram Moolenaar58b85342016-08-14 19:54:54 +020013342the exception "Vim:Interrupt". You can catch it like every exception. The
Bram Moolenaar071d4272004-06-13 20:20:40 +000013343script is not terminated, then.
13344 Example: >
13345
13346 :function! TASK1()
13347 : sleep 10
13348 :endfunction
13349
13350 :function! TASK2()
13351 : sleep 20
13352 :endfunction
13353
13354 :while 1
13355 : let command = input("Type a command: ")
13356 : try
13357 : if command == ""
13358 : continue
13359 : elseif command == "END"
13360 : break
13361 : elseif command == "TASK1"
13362 : call TASK1()
13363 : elseif command == "TASK2"
13364 : call TASK2()
13365 : else
13366 : echo "\nIllegal command:" command
13367 : continue
13368 : endif
13369 : catch /^Vim:Interrupt$/
13370 : echo "\nCommand interrupted"
13371 : " Caught the interrupt. Continue with next prompt.
13372 : endtry
13373 :endwhile
13374
13375You can interrupt a task here by pressing CTRL-C; the script then asks for
Bram Moolenaar58b85342016-08-14 19:54:54 +020013376a new command. If you press CTRL-C at the prompt, the script is terminated.
Bram Moolenaar071d4272004-06-13 20:20:40 +000013377
13378For testing what happens when CTRL-C would be pressed on a specific line in
13379your script, use the debug mode and execute the |>quit| or |>interrupt|
13380command on that line. See |debug-scripts|.
13381
13382
13383CATCHING ALL *catch-all*
13384
13385The commands >
13386
13387 :catch /.*/
13388 :catch //
13389 :catch
13390
13391catch everything, error exceptions, interrupt exceptions and exceptions
13392explicitly thrown by the |:throw| command. This is useful at the top level of
13393a script in order to catch unexpected things.
13394 Example: >
13395
13396 :try
13397 :
13398 : " do the hard work here
13399 :
13400 :catch /MyException/
13401 :
13402 : " handle known problem
13403 :
13404 :catch /^Vim:Interrupt$/
13405 : echo "Script interrupted"
13406 :catch /.*/
13407 : echo "Internal error (" . v:exception . ")"
13408 : echo " - occurred at " . v:throwpoint
13409 :endtry
13410 :" end of script
13411
13412Note: Catching all might catch more things than you want. Thus, you are
13413strongly encouraged to catch only for problems that you can really handle by
13414specifying a pattern argument to the ":catch".
13415 Example: Catching all could make it nearly impossible to interrupt a script
13416by pressing CTRL-C: >
13417
13418 :while 1
13419 : try
13420 : sleep 1
13421 : catch
13422 : endtry
13423 :endwhile
13424
13425
13426EXCEPTIONS AND AUTOCOMMANDS *except-autocmd*
13427
13428Exceptions may be used during execution of autocommands. Example: >
13429
13430 :autocmd User x try
13431 :autocmd User x throw "Oops!"
13432 :autocmd User x catch
13433 :autocmd User x echo v:exception
13434 :autocmd User x endtry
13435 :autocmd User x throw "Arrgh!"
13436 :autocmd User x echo "Should not be displayed"
13437 :
13438 :try
13439 : doautocmd User x
13440 :catch
13441 : echo v:exception
13442 :endtry
13443
13444This displays "Oops!" and "Arrgh!".
13445
13446 *except-autocmd-Pre*
13447For some commands, autocommands get executed before the main action of the
13448command takes place. If an exception is thrown and not caught in the sequence
13449of autocommands, the sequence and the command that caused its execution are
13450abandoned and the exception is propagated to the caller of the command.
13451 Example: >
13452
13453 :autocmd BufWritePre * throw "FAIL"
13454 :autocmd BufWritePre * echo "Should not be displayed"
13455 :
13456 :try
13457 : write
13458 :catch
13459 : echo "Caught:" v:exception "from" v:throwpoint
13460 :endtry
13461
13462Here, the ":write" command does not write the file currently being edited (as
13463you can see by checking 'modified'), since the exception from the BufWritePre
13464autocommand abandons the ":write". The exception is then caught and the
13465script displays: >
13466
13467 Caught: FAIL from BufWrite Auto commands for "*"
13468<
13469 *except-autocmd-Post*
13470For some commands, autocommands get executed after the main action of the
13471command has taken place. If this main action fails and the command is inside
13472an active try conditional, the autocommands are skipped and an error exception
13473is thrown that can be caught by the caller of the command.
13474 Example: >
13475
13476 :autocmd BufWritePost * echo "File successfully written!"
13477 :
13478 :try
13479 : write /i/m/p/o/s/s/i/b/l/e
13480 :catch
13481 : echo v:exception
13482 :endtry
13483
13484This just displays: >
13485
13486 Vim(write):E212: Can't open file for writing (/i/m/p/o/s/s/i/b/l/e)
13487
13488If you really need to execute the autocommands even when the main action
13489fails, trigger the event from the catch clause.
13490 Example: >
13491
13492 :autocmd BufWritePre * set noreadonly
13493 :autocmd BufWritePost * set readonly
13494 :
13495 :try
13496 : write /i/m/p/o/s/s/i/b/l/e
13497 :catch
13498 : doautocmd BufWritePost /i/m/p/o/s/s/i/b/l/e
13499 :endtry
13500<
13501You can also use ":silent!": >
13502
13503 :let x = "ok"
13504 :let v:errmsg = ""
13505 :autocmd BufWritePost * if v:errmsg != ""
13506 :autocmd BufWritePost * let x = "after fail"
13507 :autocmd BufWritePost * endif
13508 :try
13509 : silent! write /i/m/p/o/s/s/i/b/l/e
13510 :catch
13511 :endtry
13512 :echo x
13513
13514This displays "after fail".
13515
13516If the main action of the command does not fail, exceptions from the
13517autocommands will be catchable by the caller of the command: >
13518
13519 :autocmd BufWritePost * throw ":-("
13520 :autocmd BufWritePost * echo "Should not be displayed"
13521 :
13522 :try
13523 : write
13524 :catch
13525 : echo v:exception
13526 :endtry
13527<
13528 *except-autocmd-Cmd*
13529For some commands, the normal action can be replaced by a sequence of
13530autocommands. Exceptions from that sequence will be catchable by the caller
13531of the command.
13532 Example: For the ":write" command, the caller cannot know whether the file
Bram Moolenaar58b85342016-08-14 19:54:54 +020013533had actually been written when the exception occurred. You need to tell it in
Bram Moolenaar071d4272004-06-13 20:20:40 +000013534some way. >
13535
13536 :if !exists("cnt")
13537 : let cnt = 0
13538 :
13539 : autocmd BufWriteCmd * if &modified
13540 : autocmd BufWriteCmd * let cnt = cnt + 1
13541 : autocmd BufWriteCmd * if cnt % 3 == 2
13542 : autocmd BufWriteCmd * throw "BufWriteCmdError"
13543 : autocmd BufWriteCmd * endif
13544 : autocmd BufWriteCmd * write | set nomodified
13545 : autocmd BufWriteCmd * if cnt % 3 == 0
13546 : autocmd BufWriteCmd * throw "BufWriteCmdError"
13547 : autocmd BufWriteCmd * endif
13548 : autocmd BufWriteCmd * echo "File successfully written!"
13549 : autocmd BufWriteCmd * endif
13550 :endif
13551 :
13552 :try
13553 : write
13554 :catch /^BufWriteCmdError$/
13555 : if &modified
13556 : echo "Error on writing (file contents not changed)"
13557 : else
13558 : echo "Error after writing"
13559 : endif
13560 :catch /^Vim(write):/
13561 : echo "Error on writing"
13562 :endtry
13563
13564When this script is sourced several times after making changes, it displays
13565first >
13566 File successfully written!
13567then >
13568 Error on writing (file contents not changed)
13569then >
13570 Error after writing
13571etc.
13572
13573 *except-autocmd-ill*
13574You cannot spread a try conditional over autocommands for different events.
13575The following code is ill-formed: >
13576
13577 :autocmd BufWritePre * try
13578 :
13579 :autocmd BufWritePost * catch
13580 :autocmd BufWritePost * echo v:exception
13581 :autocmd BufWritePost * endtry
13582 :
13583 :write
13584
13585
13586EXCEPTION HIERARCHIES AND PARAMETERIZED EXCEPTIONS *except-hier-param*
13587
13588Some programming languages allow to use hierarchies of exception classes or to
13589pass additional information with the object of an exception class. You can do
13590similar things in Vim.
13591 In order to throw an exception from a hierarchy, just throw the complete
13592class name with the components separated by a colon, for instance throw the
13593string "EXCEPT:MATHERR:OVERFLOW" for an overflow in a mathematical library.
13594 When you want to pass additional information with your exception class, add
13595it in parentheses, for instance throw the string "EXCEPT:IO:WRITEERR(myfile)"
13596for an error when writing "myfile".
13597 With the appropriate patterns in the ":catch" command, you can catch for
13598base classes or derived classes of your hierarchy. Additional information in
13599parentheses can be cut out from |v:exception| with the ":substitute" command.
13600 Example: >
13601
13602 :function! CheckRange(a, func)
13603 : if a:a < 0
13604 : throw "EXCEPT:MATHERR:RANGE(" . a:func . ")"
13605 : endif
13606 :endfunction
13607 :
13608 :function! Add(a, b)
13609 : call CheckRange(a:a, "Add")
13610 : call CheckRange(a:b, "Add")
13611 : let c = a:a + a:b
13612 : if c < 0
13613 : throw "EXCEPT:MATHERR:OVERFLOW"
13614 : endif
13615 : return c
13616 :endfunction
13617 :
13618 :function! Div(a, b)
13619 : call CheckRange(a:a, "Div")
13620 : call CheckRange(a:b, "Div")
13621 : if (a:b == 0)
13622 : throw "EXCEPT:MATHERR:ZERODIV"
13623 : endif
13624 : return a:a / a:b
13625 :endfunction
13626 :
13627 :function! Write(file)
13628 : try
Bram Moolenaar446cb832008-06-24 21:56:24 +000013629 : execute "write" fnameescape(a:file)
Bram Moolenaar071d4272004-06-13 20:20:40 +000013630 : catch /^Vim(write):/
13631 : throw "EXCEPT:IO(" . getcwd() . ", " . a:file . "):WRITEERR"
13632 : endtry
13633 :endfunction
13634 :
13635 :try
13636 :
13637 : " something with arithmetics and I/O
13638 :
13639 :catch /^EXCEPT:MATHERR:RANGE/
13640 : let function = substitute(v:exception, '.*(\(\a\+\)).*', '\1', "")
13641 : echo "Range error in" function
13642 :
13643 :catch /^EXCEPT:MATHERR/ " catches OVERFLOW and ZERODIV
13644 : echo "Math error"
13645 :
13646 :catch /^EXCEPT:IO/
13647 : let dir = substitute(v:exception, '.*(\(.\+\),\s*.\+).*', '\1', "")
13648 : let file = substitute(v:exception, '.*(.\+,\s*\(.\+\)).*', '\1', "")
13649 : if file !~ '^/'
13650 : let file = dir . "/" . file
13651 : endif
13652 : echo 'I/O error for "' . file . '"'
13653 :
13654 :catch /^EXCEPT/
13655 : echo "Unspecified error"
13656 :
13657 :endtry
13658
13659The exceptions raised by Vim itself (on error or when pressing CTRL-C) use
13660a flat hierarchy: they are all in the "Vim" class. You cannot throw yourself
13661exceptions with the "Vim" prefix; they are reserved for Vim.
13662 Vim error exceptions are parameterized with the name of the command that
13663failed, if known. See |catch-errors|.
13664
13665
13666PECULIARITIES
13667 *except-compat*
13668The exception handling concept requires that the command sequence causing the
13669exception is aborted immediately and control is transferred to finally clauses
13670and/or a catch clause.
13671
13672In the Vim script language there are cases where scripts and functions
13673continue after an error: in functions without the "abort" flag or in a command
13674after ":silent!", control flow goes to the following line, and outside
13675functions, control flow goes to the line following the outermost ":endwhile"
13676or ":endif". On the other hand, errors should be catchable as exceptions
13677(thus, requiring the immediate abortion).
13678
13679This problem has been solved by converting errors to exceptions and using
13680immediate abortion (if not suppressed by ":silent!") only when a try
Bram Moolenaar58b85342016-08-14 19:54:54 +020013681conditional is active. This is no restriction since an (error) exception can
13682be caught only from an active try conditional. If you want an immediate
Bram Moolenaar071d4272004-06-13 20:20:40 +000013683termination without catching the error, just use a try conditional without
13684catch clause. (You can cause cleanup code being executed before termination
13685by specifying a finally clause.)
13686
13687When no try conditional is active, the usual abortion and continuation
13688behavior is used instead of immediate abortion. This ensures compatibility of
13689scripts written for Vim 6.1 and earlier.
13690
13691However, when sourcing an existing script that does not use exception handling
13692commands (or when calling one of its functions) from inside an active try
13693conditional of a new script, you might change the control flow of the existing
13694script on error. You get the immediate abortion on error and can catch the
13695error in the new script. If however the sourced script suppresses error
13696messages by using the ":silent!" command (checking for errors by testing
Bram Moolenaar58b85342016-08-14 19:54:54 +020013697|v:errmsg| if appropriate), its execution path is not changed. The error is
13698not converted to an exception. (See |:silent|.) So the only remaining cause
Bram Moolenaar071d4272004-06-13 20:20:40 +000013699where this happens is for scripts that don't care about errors and produce
13700error messages. You probably won't want to use such code from your new
13701scripts.
13702
13703 *except-syntax-err*
13704Syntax errors in the exception handling commands are never caught by any of
13705the ":catch" commands of the try conditional they belong to. Its finally
13706clauses, however, is executed.
13707 Example: >
13708
13709 :try
13710 : try
13711 : throw 4711
13712 : catch /\(/
13713 : echo "in catch with syntax error"
13714 : catch
13715 : echo "inner catch-all"
13716 : finally
13717 : echo "inner finally"
13718 : endtry
13719 :catch
13720 : echo 'outer catch-all caught "' . v:exception . '"'
13721 : finally
13722 : echo "outer finally"
13723 :endtry
13724
13725This displays: >
13726 inner finally
13727 outer catch-all caught "Vim(catch):E54: Unmatched \("
13728 outer finally
13729The original exception is discarded and an error exception is raised, instead.
13730
13731 *except-single-line*
13732The ":try", ":catch", ":finally", and ":endtry" commands can be put on
13733a single line, but then syntax errors may make it difficult to recognize the
13734"catch" line, thus you better avoid this.
13735 Example: >
13736 :try | unlet! foo # | catch | endtry
13737raises an error exception for the trailing characters after the ":unlet!"
13738argument, but does not see the ":catch" and ":endtry" commands, so that the
13739error exception is discarded and the "E488: Trailing characters" message gets
13740displayed.
13741
13742 *except-several-errors*
13743When several errors appear in a single command, the first error message is
13744usually the most specific one and therefor converted to the error exception.
13745 Example: >
13746 echo novar
13747causes >
13748 E121: Undefined variable: novar
13749 E15: Invalid expression: novar
13750The value of the error exception inside try conditionals is: >
13751 Vim(echo):E121: Undefined variable: novar
13752< *except-syntax-error*
13753But when a syntax error is detected after a normal error in the same command,
13754the syntax error is used for the exception being thrown.
13755 Example: >
13756 unlet novar #
13757causes >
13758 E108: No such variable: "novar"
13759 E488: Trailing characters
13760The value of the error exception inside try conditionals is: >
13761 Vim(unlet):E488: Trailing characters
13762This is done because the syntax error might change the execution path in a way
13763not intended by the user. Example: >
13764 try
13765 try | unlet novar # | catch | echo v:exception | endtry
13766 catch /.*/
13767 echo "outer catch:" v:exception
13768 endtry
13769This displays "outer catch: Vim(unlet):E488: Trailing characters", and then
13770a "E600: Missing :endtry" error message is given, see |except-single-line|.
13771
13772==============================================================================
137739. Examples *eval-examples*
13774
Bram Moolenaaref2f6562007-05-06 13:32:59 +000013775Printing in Binary ~
Bram Moolenaar071d4272004-06-13 20:20:40 +000013776>
Bram Moolenaar8f3f58f2010-01-06 20:52:26 +010013777 :" The function Nr2Bin() returns the binary string representation of a number.
Bram Moolenaaref2f6562007-05-06 13:32:59 +000013778 :func Nr2Bin(nr)
Bram Moolenaar071d4272004-06-13 20:20:40 +000013779 : let n = a:nr
13780 : let r = ""
13781 : while n
Bram Moolenaaref2f6562007-05-06 13:32:59 +000013782 : let r = '01'[n % 2] . r
13783 : let n = n / 2
Bram Moolenaar071d4272004-06-13 20:20:40 +000013784 : endwhile
13785 : return r
13786 :endfunc
13787
Bram Moolenaaref2f6562007-05-06 13:32:59 +000013788 :" The function String2Bin() converts each character in a string to a
13789 :" binary string, separated with dashes.
13790 :func String2Bin(str)
Bram Moolenaar071d4272004-06-13 20:20:40 +000013791 : let out = ''
Bram Moolenaaref2f6562007-05-06 13:32:59 +000013792 : for ix in range(strlen(a:str))
13793 : let out = out . '-' . Nr2Bin(char2nr(a:str[ix]))
13794 : endfor
13795 : return out[1:]
Bram Moolenaar071d4272004-06-13 20:20:40 +000013796 :endfunc
13797
13798Example of its use: >
Bram Moolenaaref2f6562007-05-06 13:32:59 +000013799 :echo Nr2Bin(32)
13800result: "100000" >
13801 :echo String2Bin("32")
13802result: "110011-110010"
Bram Moolenaar071d4272004-06-13 20:20:40 +000013803
13804
Bram Moolenaaref2f6562007-05-06 13:32:59 +000013805Sorting lines ~
Bram Moolenaar071d4272004-06-13 20:20:40 +000013806
Bram Moolenaaref2f6562007-05-06 13:32:59 +000013807This example sorts lines with a specific compare function. >
13808
13809 :func SortBuffer()
13810 : let lines = getline(1, '$')
13811 : call sort(lines, function("Strcmp"))
13812 : call setline(1, lines)
Bram Moolenaar071d4272004-06-13 20:20:40 +000013813 :endfunction
13814
Bram Moolenaaref2f6562007-05-06 13:32:59 +000013815As a one-liner: >
13816 :call setline(1, sort(getline(1, '$'), function("Strcmp")))
Bram Moolenaar071d4272004-06-13 20:20:40 +000013817
Bram Moolenaar071d4272004-06-13 20:20:40 +000013818
Bram Moolenaaref2f6562007-05-06 13:32:59 +000013819scanf() replacement ~
Bram Moolenaar071d4272004-06-13 20:20:40 +000013820 *sscanf*
13821There is no sscanf() function in Vim. If you need to extract parts from a
13822line, you can use matchstr() and substitute() to do it. This example shows
13823how to get the file name, line number and column number out of a line like
13824"foobar.txt, 123, 45". >
13825 :" Set up the match bit
13826 :let mx='\(\f\+\),\s*\(\d\+\),\s*\(\d\+\)'
13827 :"get the part matching the whole expression
13828 :let l = matchstr(line, mx)
13829 :"get each item out of the match
13830 :let file = substitute(l, mx, '\1', '')
13831 :let lnum = substitute(l, mx, '\2', '')
13832 :let col = substitute(l, mx, '\3', '')
13833
13834The input is in the variable "line", the results in the variables "file",
13835"lnum" and "col". (idea from Michael Geddes)
13836
Bram Moolenaaref2f6562007-05-06 13:32:59 +000013837
13838getting the scriptnames in a Dictionary ~
13839 *scriptnames-dictionary*
13840The |:scriptnames| command can be used to get a list of all script files that
13841have been sourced. There is no equivalent function or variable for this
13842(because it's rarely needed). In case you need to manipulate the list this
13843code can be used: >
13844 " Get the output of ":scriptnames" in the scriptnames_output variable.
13845 let scriptnames_output = ''
13846 redir => scriptnames_output
13847 silent scriptnames
13848 redir END
Bram Moolenaarb0d45e72017-11-05 18:19:24 +010013849
Bram Moolenaar446cb832008-06-24 21:56:24 +000013850 " Split the output into lines and parse each line. Add an entry to the
Bram Moolenaaref2f6562007-05-06 13:32:59 +000013851 " "scripts" dictionary.
13852 let scripts = {}
13853 for line in split(scriptnames_output, "\n")
13854 " Only do non-blank lines.
13855 if line =~ '\S'
13856 " Get the first number in the line.
Bram Moolenaar446cb832008-06-24 21:56:24 +000013857 let nr = matchstr(line, '\d\+')
Bram Moolenaaref2f6562007-05-06 13:32:59 +000013858 " Get the file name, remove the script number " 123: ".
Bram Moolenaar446cb832008-06-24 21:56:24 +000013859 let name = substitute(line, '.\+:\s*', '', '')
Bram Moolenaaref2f6562007-05-06 13:32:59 +000013860 " Add an item to the Dictionary
Bram Moolenaar446cb832008-06-24 21:56:24 +000013861 let scripts[nr] = name
Bram Moolenaaref2f6562007-05-06 13:32:59 +000013862 endif
13863 endfor
13864 unlet scriptnames_output
13865
Bram Moolenaar071d4272004-06-13 20:20:40 +000013866==============================================================================
Bram Moolenaar558ca4a2019-04-04 18:15:38 +02001386710. Vim script versions *vimscript-version* *vimscript-versions*
Bram Moolenaar911ead12019-04-21 00:03:35 +020013868 *scriptversion*
Bram Moolenaar558ca4a2019-04-04 18:15:38 +020013869Over time many features have been added to Vim script. This includes Ex
13870commands, functions, variable types, etc. Each individual feature can be
13871checked with the |has()| and |exists()| functions.
13872
13873Sometimes old syntax of functionality gets in the way of making Vim better.
13874When support is taken away this will break older Vim scripts. To make this
13875explicit the |:scriptversion| command can be used. When a Vim script is not
13876compatible with older versions of Vim this will give an explicit error,
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +020013877instead of failing in mysterious ways.
Bram Moolenaar558ca4a2019-04-04 18:15:38 +020013878
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +020013879 *scriptversion-1* >
Bram Moolenaar558ca4a2019-04-04 18:15:38 +020013880 :scriptversion 1
13881< This is the original Vim script, same as not using a |:scriptversion|
13882 command. Can be used to go back to old syntax for a range of lines.
13883 Test for support with: >
13884 has('vimscript-1')
13885
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +020013886< *scriptversion-2* >
Bram Moolenaar558ca4a2019-04-04 18:15:38 +020013887 :scriptversion 2
Bram Moolenaar68e65602019-05-26 21:33:31 +020013888< String concatenation with "." is not supported, use ".." instead.
Bram Moolenaar558ca4a2019-04-04 18:15:38 +020013889 This avoids the ambiguity using "." for Dict member access and
13890 floating point numbers. Now ".5" means the number 0.5.
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +020013891
13892 *scriptversion-3* >
Bram Moolenaar911ead12019-04-21 00:03:35 +020013893 :scriptversion 3
13894< All |vim-variable|s must be prefixed by "v:". E.g. "version" doesn't
13895 work as |v:version| anymore, it can be used as a normal variable.
13896 Same for some obvious names as "count" and others.
Bram Moolenaar558ca4a2019-04-04 18:15:38 +020013897
Bram Moolenaar911ead12019-04-21 00:03:35 +020013898 Test for support with: >
13899 has('vimscript-3')
Bram Moolenaar60a8de22019-09-15 14:33:22 +020013900<
13901 *scriptversion-4* >
13902 :scriptversion 4
Bram Moolenaarc17e66c2020-06-02 21:38:22 +020013903< Numbers with a leading zero are not recognized as octal. "0o" or "0O"
13904 is still recognized as octal. With the
Bram Moolenaar60a8de22019-09-15 14:33:22 +020013905 previous version you get: >
Bram Moolenaarc17e66c2020-06-02 21:38:22 +020013906 echo 017 " displays 15 (octal)
13907 echo 0o17 " displays 15 (octal)
13908 echo 018 " displays 18 (decimal)
Bram Moolenaar60a8de22019-09-15 14:33:22 +020013909< with script version 4: >
Bram Moolenaarc17e66c2020-06-02 21:38:22 +020013910 echo 017 " displays 17 (decimal)
13911 echo 0o17 " displays 15 (octal)
13912 echo 018 " displays 18 (decimal)
Bram Moolenaar60a8de22019-09-15 14:33:22 +020013913< Also, it is possible to use single quotes inside numbers to make them
13914 easier to read: >
13915 echo 1'000'000
13916< The quotes must be surrounded by digits.
13917
13918 Test for support with: >
13919 has('vimscript-4')
Bram Moolenaar558ca4a2019-04-04 18:15:38 +020013920
13921==============================================================================
1392211. No +eval feature *no-eval-feature*
Bram Moolenaar071d4272004-06-13 20:20:40 +000013923
13924When the |+eval| feature was disabled at compile time, none of the expression
13925evaluation commands are available. To prevent this from causing Vim scripts
13926to generate all kinds of errors, the ":if" and ":endif" commands are still
13927recognized, though the argument of the ":if" and everything between the ":if"
13928and the matching ":endif" is ignored. Nesting of ":if" blocks is allowed, but
13929only if the commands are at the start of the line. The ":else" command is not
13930recognized.
13931
13932Example of how to avoid executing commands when the |+eval| feature is
13933missing: >
13934
13935 :if 1
13936 : echo "Expression evaluation is compiled in"
13937 :else
13938 : echo "You will _never_ see this message"
13939 :endif
13940
Bram Moolenaar773a97c2019-06-06 20:39:55 +020013941To execute a command only when the |+eval| feature is disabled can be done in
13942two ways. The simplest is to exit the script (or Vim) prematurely: >
13943 if 1
13944 echo "commands executed with +eval"
13945 finish
13946 endif
13947 args " command executed without +eval
13948
13949If you do not want to abort loading the script you can use a trick, as this
13950example shows: >
Bram Moolenaar45d2cca2017-04-30 16:36:05 +020013951
13952 silent! while 0
13953 set history=111
13954 silent! endwhile
13955
13956When the |+eval| feature is available the command is skipped because of the
13957"while 0". Without the |+eval| feature the "while 0" is an error, which is
13958silently ignored, and the command is executed.
Bram Moolenaarcd5c8f82017-04-09 20:11:58 +020013959
Bram Moolenaar071d4272004-06-13 20:20:40 +000013960==============================================================================
Bram Moolenaar558ca4a2019-04-04 18:15:38 +02001396112. The sandbox *eval-sandbox* *sandbox* *E48*
Bram Moolenaar071d4272004-06-13 20:20:40 +000013962
Bram Moolenaar368373e2010-07-19 20:46:22 +020013963The 'foldexpr', 'formatexpr', 'includeexpr', 'indentexpr', 'statusline' and
13964'foldtext' options may be evaluated in a sandbox. This means that you are
13965protected from these expressions having nasty side effects. This gives some
13966safety for when these options are set from a modeline. It is also used when
13967the command from a tags file is executed and for CTRL-R = in the command line.
Bram Moolenaar7b0294c2004-10-11 10:16:09 +000013968The sandbox is also used for the |:sandbox| command.
Bram Moolenaar071d4272004-06-13 20:20:40 +000013969
13970These items are not allowed in the sandbox:
13971 - changing the buffer text
Bram Moolenaarb477af22018-07-15 20:20:18 +020013972 - defining or changing mapping, autocommands, user commands
Bram Moolenaar071d4272004-06-13 20:20:40 +000013973 - setting certain options (see |option-summary|)
Bram Moolenaaref2f6562007-05-06 13:32:59 +000013974 - setting certain v: variables (see |v:var|) *E794*
Bram Moolenaar071d4272004-06-13 20:20:40 +000013975 - executing a shell command
13976 - reading or writing a file
13977 - jumping to another buffer or editing a file
Bram Moolenaar4770d092006-01-12 23:22:24 +000013978 - executing Python, Perl, etc. commands
Bram Moolenaar7b0294c2004-10-11 10:16:09 +000013979This is not guaranteed 100% secure, but it should block most attacks.
13980
13981 *:san* *:sandbox*
Bram Moolenaar045e82d2005-07-08 22:25:33 +000013982:san[dbox] {cmd} Execute {cmd} in the sandbox. Useful to evaluate an
Bram Moolenaar7b0294c2004-10-11 10:16:09 +000013983 option that may have been set from a modeline, e.g.
13984 'foldexpr'.
13985
Bram Moolenaarb71eaae2006-01-20 23:10:18 +000013986 *sandbox-option*
13987A few options contain an expression. When this expression is evaluated it may
Bram Moolenaar9b2200a2006-03-20 21:55:45 +000013988have to be done in the sandbox to avoid a security risk. But the sandbox is
Bram Moolenaarb71eaae2006-01-20 23:10:18 +000013989restrictive, thus this only happens when the option was set from an insecure
13990location. Insecure in this context are:
Bram Moolenaar551dbcc2006-04-25 22:13:59 +000013991- sourcing a .vimrc or .exrc in the current directory
Bram Moolenaarb71eaae2006-01-20 23:10:18 +000013992- while executing in the sandbox
13993- value coming from a modeline
Bram Moolenaarb477af22018-07-15 20:20:18 +020013994- executing a function that was defined in the sandbox
Bram Moolenaarb71eaae2006-01-20 23:10:18 +000013995
13996Note that when in the sandbox and saving an option value and restoring it, the
13997option will still be marked as it was set in the sandbox.
13998
13999==============================================================================
Bram Moolenaar558ca4a2019-04-04 18:15:38 +02001400013. Textlock *textlock*
Bram Moolenaarb71eaae2006-01-20 23:10:18 +000014001
14002In a few situations it is not allowed to change the text in the buffer, jump
14003to another window and some other things that might confuse or break what Vim
14004is currently doing. This mostly applies to things that happen when Vim is
Bram Moolenaar58b85342016-08-14 19:54:54 +020014005actually doing something else. For example, evaluating the 'balloonexpr' may
Bram Moolenaarb71eaae2006-01-20 23:10:18 +000014006happen any moment the mouse cursor is resting at some position.
14007
14008This is not allowed when the textlock is active:
14009 - changing the buffer text
14010 - jumping to another buffer or window
14011 - editing another file
14012 - closing a window or quitting Vim
14013 - etc.
14014
Bram Moolenaar071d4272004-06-13 20:20:40 +000014015
Bram Moolenaar91f84f62018-07-29 15:07:52 +020014016 vim:tw=78:ts=8:noet:ft=help:norl: