blob: a64f249665f510727dc1793e77ccdd7393ab0d36 [file] [log] [blame]
Bram Moolenaarc0f5a782019-01-13 15:16:13 +01001*eval.txt* For Vim version 8.1. Last change: 2019 Jan 13
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 Moolenaar13065c42005-01-08 16:08:21 +0000151. Variables |variables|
16 1.1 Variable types
Bram Moolenaar9588a0f2005-01-08 21:45:39 +000017 1.2 Function references |Funcref|
Bram Moolenaar7c626922005-02-07 22:01:03 +000018 1.3 Lists |Lists|
Bram Moolenaard8b02732005-01-14 21:48:43 +000019 1.4 Dictionaries |Dictionaries|
20 1.5 More about variables |more-variables|
Bram Moolenaar13065c42005-01-08 16:08:21 +0000212. Expression syntax |expression-syntax|
223. Internal variable |internal-variables|
234. Builtin Functions |functions|
245. Defining functions |user-functions|
256. Curly braces names |curly-braces-names|
267. Commands |expression-commands|
278. Exception handling |exception-handling|
289. Examples |eval-examples|
2910. No +eval feature |no-eval-feature|
3011. The sandbox |eval-sandbox|
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00003112. Textlock |textlock|
Bram Moolenaardc1f1642016-08-16 18:33:43 +02003213. Testing |testing|
Bram Moolenaar071d4272004-06-13 20:20:40 +000033
34{Vi does not have any of these commands}
35
36==============================================================================
371. Variables *variables*
38
Bram Moolenaar13065c42005-01-08 16:08:21 +0000391.1 Variable types ~
Bram Moolenaar3a3a7232005-01-17 22:16:15 +000040 *E712*
Bram Moolenaar38a55632016-02-15 22:07:32 +010041There are nine types of variables:
Bram Moolenaar071d4272004-06-13 20:20:40 +000042
Bram Moolenaar5302d9e2011-09-14 17:55:08 +020043Number A 32 or 64 bit signed number. |expr-number| *Number*
Bram Moolenaar1e96d9b2016-07-29 22:15:09 +020044 64-bit Numbers are available only when compiled with the
Bram Moolenaar22fcfad2016-07-01 18:17:26 +020045 |+num64| feature.
Bram Moolenaar7571d552016-08-18 22:54:46 +020046 Examples: -123 0x10 0177 0b1011
Bram Moolenaard8b02732005-01-14 21:48:43 +000047
Bram Moolenaar446cb832008-06-24 21:56:24 +000048Float A floating point number. |floating-point-format| *Float*
49 {only when compiled with the |+float| feature}
50 Examples: 123.456 1.15e-6 -1.1e3
51
Bram Moolenaar06481422016-04-30 15:13:38 +020052 *E928*
Bram Moolenaard8b02732005-01-14 21:48:43 +000053String A NUL terminated string of 8-bit unsigned characters (bytes).
Bram Moolenaar446cb832008-06-24 21:56:24 +000054 |expr-string| Examples: "ab\txx\"--" 'x-z''a,c'
Bram Moolenaard8b02732005-01-14 21:48:43 +000055
Bram Moolenaard8b02732005-01-14 21:48:43 +000056List An ordered sequence of items |List|.
57 Example: [1, 2, ['a', 'b']]
Bram Moolenaar071d4272004-06-13 20:20:40 +000058
Bram Moolenaar39a58ca2005-06-27 22:42:44 +000059Dictionary An associative, unordered array: Each entry has a key and a
60 value. |Dictionary|
61 Example: {'blue': "#0000ff", 'red': "#ff0000"}
62
Bram Moolenaar835dc632016-02-07 14:27:38 +010063Funcref A reference to a function |Funcref|.
64 Example: function("strlen")
Bram Moolenaar1d429612016-05-24 15:44:17 +020065 It can be bound to a dictionary and arguments, it then works
66 like a Partial.
67 Example: function("Callback", [arg], myDict)
Bram Moolenaar835dc632016-02-07 14:27:38 +010068
Bram Moolenaar02e83b42016-02-21 20:10:26 +010069Special |v:false|, |v:true|, |v:none| and |v:null|. *Special*
Bram Moolenaar835dc632016-02-07 14:27:38 +010070
Bram Moolenaarebf7dfa2016-04-14 12:46:51 +020071Job Used for a job, see |job_start()|. *Job* *Jobs*
Bram Moolenaar38a55632016-02-15 22:07:32 +010072
Bram Moolenaarebf7dfa2016-04-14 12:46:51 +020073Channel Used for a channel, see |ch_open()|. *Channel* *Channels*
Bram Moolenaar835dc632016-02-07 14:27:38 +010074
Bram Moolenaar6e5ea8d2019-01-12 22:47:31 +010075Blob Binary Large Object. Stores any sequence of bytes. *Blob*
76 Example: 0zFF00ED015DAF
77 0z is an empty Blob.
78
Bram Moolenaard7ee7ce2005-01-03 21:02:03 +000079The Number and String types are converted automatically, depending on how they
80are used.
Bram Moolenaar071d4272004-06-13 20:20:40 +000081
82Conversion from a Number to a String is by making the ASCII representation of
Bram Moolenaar24ea3ba2010-09-19 19:01:21 +020083the Number. Examples:
84 Number 123 --> String "123" ~
85 Number 0 --> String "0" ~
86 Number -1 --> String "-1" ~
Bram Moolenaar00a927d2010-05-14 23:24:24 +020087 *octal*
Bram Moolenaarfa735342016-01-03 22:14:44 +010088Conversion from a String to a Number is done by converting the first digits to
89a number. Hexadecimal "0xf9", Octal "017", and Binary "0b10" numbers are
90recognized. If the String doesn't start with digits, the result is zero.
91Examples:
Bram Moolenaar24ea3ba2010-09-19 19:01:21 +020092 String "456" --> Number 456 ~
93 String "6bar" --> Number 6 ~
94 String "foo" --> Number 0 ~
95 String "0xf1" --> Number 241 ~
96 String "0100" --> Number 64 ~
Bram Moolenaarfa735342016-01-03 22:14:44 +010097 String "0b101" --> Number 5 ~
Bram Moolenaar24ea3ba2010-09-19 19:01:21 +020098 String "-8" --> Number -8 ~
99 String "+8" --> Number 0 ~
Bram Moolenaar071d4272004-06-13 20:20:40 +0000100
101To force conversion from String to Number, add zero to it: >
102 :echo "0100" + 0
Bram Moolenaar97b2ad32006-03-18 21:40:56 +0000103< 64 ~
104
105To avoid a leading zero to cause octal conversion, or for using a different
106base, use |str2nr()|.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000107
Bram Moolenaare381d3d2016-07-07 14:50:41 +0200108 *TRUE* *FALSE*
Bram Moolenaar071d4272004-06-13 20:20:40 +0000109For boolean operators Numbers are used. Zero is FALSE, non-zero is TRUE.
Bram Moolenaare381d3d2016-07-07 14:50:41 +0200110You can also use |v:false| and |v:true|. When TRUE is returned from a
111function it is the Number one, FALSE is the number zero.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000112
Bram Moolenaare381d3d2016-07-07 14:50:41 +0200113Note that in the command: >
Bram Moolenaar071d4272004-06-13 20:20:40 +0000114 :if "foo"
Bram Moolenaare381d3d2016-07-07 14:50:41 +0200115 :" NOT executed
116"foo" is converted to 0, which means FALSE. If the string starts with a
117non-zero number it means TRUE: >
118 :if "8foo"
119 :" executed
120To test for a non-empty string, use empty(): >
Bram Moolenaar3a0d8092012-10-21 03:02:54 +0200121 :if !empty("foo")
Bram Moolenaar835dc632016-02-07 14:27:38 +0100122<
Bram Moolenaare381d3d2016-07-07 14:50:41 +0200123 *non-zero-arg*
124Function arguments often behave slightly different from |TRUE|: If the
125argument is present and it evaluates to a non-zero Number, |v:true| or a
Bram Moolenaar64d8e252016-09-06 22:12:34 +0200126non-empty String, then the value is considered to be TRUE.
Bram Moolenaar01164a62017-11-02 22:58:42 +0100127Note that " " and "0" are also non-empty strings, thus considered to be TRUE.
128A List, Dictionary or Float is not a Number or String, thus evaluate to FALSE.
Bram Moolenaare381d3d2016-07-07 14:50:41 +0200129
Bram Moolenaar38a55632016-02-15 22:07:32 +0100130 *E745* *E728* *E703* *E729* *E730* *E731* *E908* *E910* *E913*
Bram Moolenaar6e5ea8d2019-01-12 22:47:31 +0100131 *E974* *E975* *E976*
132List, Dictionary, Funcref, Job, Channel and Blob types are not automatically
Bram Moolenaar50ba5262016-09-22 22:33:02 +0200133converted.
Bram Moolenaard7ee7ce2005-01-03 21:02:03 +0000134
Bram Moolenaar446cb832008-06-24 21:56:24 +0000135 *E805* *E806* *E808*
Bram Moolenaar58b85342016-08-14 19:54:54 +0200136When mixing Number and Float the Number is converted to Float. Otherwise
Bram Moolenaar446cb832008-06-24 21:56:24 +0000137there is no automatic conversion of Float. You can use str2float() for String
138to Float, printf() for Float to String and float2nr() for Float to Number.
139
Bram Moolenaar38a55632016-02-15 22:07:32 +0100140 *E891* *E892* *E893* *E894* *E907* *E911* *E914*
Bram Moolenaar13d5aee2016-01-21 23:36:05 +0100141When expecting a Float a Number can also be used, but nothing else.
142
Bram Moolenaarf6f32c32016-03-12 19:03:59 +0100143 *no-type-checking*
144You will not get an error if you try to change the type of a variable.
Bram Moolenaard7ee7ce2005-01-03 21:02:03 +0000145
Bram Moolenaar13065c42005-01-08 16:08:21 +0000146
Bram Moolenaar9588a0f2005-01-08 21:45:39 +00001471.2 Function references ~
Bram Moolenaar748bf032005-02-02 23:04:36 +0000148 *Funcref* *E695* *E718*
Bram Moolenaar58b85342016-08-14 19:54:54 +0200149A Funcref variable is obtained with the |function()| function, the |funcref()|
150function or created with the lambda expression |expr-lambda|. It can be used
151in an expression in the place of a function name, before the parenthesis
152around the arguments, to invoke the function it refers to. Example: >
Bram Moolenaard7ee7ce2005-01-03 21:02:03 +0000153
154 :let Fn = function("MyFunc")
155 :echo Fn()
Bram Moolenaar3a3a7232005-01-17 22:16:15 +0000156< *E704* *E705* *E707*
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000157A Funcref variable must start with a capital, "s:", "w:", "t:" or "b:". You
Bram Moolenaar7cba6c02013-09-05 22:13:31 +0200158can use "g:" but the following name must still start with a capital. You
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000159cannot have both a Funcref variable and a function with the same name.
Bram Moolenaard7ee7ce2005-01-03 21:02:03 +0000160
Bram Moolenaar3a3a7232005-01-17 22:16:15 +0000161A special case is defining a function and directly assigning its Funcref to a
162Dictionary entry. Example: >
163 :function dict.init() dict
164 : let self.val = 0
165 :endfunction
166
167The key of the Dictionary can start with a lower case letter. The actual
168function name is not used here. Also see |numbered-function|.
169
170A Funcref can also be used with the |:call| command: >
171 :call Fn()
172 :call dict.init()
Bram Moolenaar13065c42005-01-08 16:08:21 +0000173
174The name of the referenced function can be obtained with |string()|. >
Bram Moolenaar383f9bc2005-01-19 22:18:32 +0000175 :let func = string(Fn)
Bram Moolenaar13065c42005-01-08 16:08:21 +0000176
177You can use |call()| to invoke a Funcref and use a list variable for the
178arguments: >
Bram Moolenaar383f9bc2005-01-19 22:18:32 +0000179 :let r = call(Fn, mylist)
Bram Moolenaar1d429612016-05-24 15:44:17 +0200180<
181 *Partial*
182A Funcref optionally binds a Dictionary and/or arguments. This is also called
183a Partial. This is created by passing the Dictionary and/or arguments to
Bram Moolenaar58b85342016-08-14 19:54:54 +0200184function() or funcref(). When calling the function the Dictionary and/or
185arguments will be passed to the function. Example: >
Bram Moolenaar1d429612016-05-24 15:44:17 +0200186
187 let Cb = function('Callback', ['foo'], myDict)
Bram Moolenaarba3ff532018-11-04 14:45:49 +0100188 call Cb('bar')
Bram Moolenaar1d429612016-05-24 15:44:17 +0200189
190This will invoke the function as if using: >
Bram Moolenaarba3ff532018-11-04 14:45:49 +0100191 call myDict.Callback('foo', 'bar')
Bram Moolenaar1d429612016-05-24 15:44:17 +0200192
193This is very useful when passing a function around, e.g. in the arguments of
194|ch_open()|.
195
196Note that binding a function to a Dictionary also happens when the function is
197a member of the Dictionary: >
198
199 let myDict.myFunction = MyFunction
200 call myDict.myFunction()
201
202Here MyFunction() will get myDict passed as "self". This happens when the
203"myFunction" member is accessed. When making assigning "myFunction" to
204otherDict and calling it, it will be bound to otherDict: >
205
206 let otherDict.myFunction = myDict.myFunction
207 call otherDict.myFunction()
208
209Now "self" will be "otherDict". But when the dictionary was bound explicitly
210this won't happen: >
211
212 let myDict.myFunction = function(MyFunction, myDict)
213 let otherDict.myFunction = myDict.myFunction
214 call otherDict.myFunction()
215
Bram Moolenaard823fa92016-08-12 16:29:27 +0200216Here "self" will be "myDict", because it was bound explicitly.
Bram Moolenaard7ee7ce2005-01-03 21:02:03 +0000217
218
Bram Moolenaar9588a0f2005-01-08 21:45:39 +00002191.3 Lists ~
Bram Moolenaar7e38ea22014-04-05 22:55:53 +0200220 *list* *List* *Lists* *E686*
Bram Moolenaard7ee7ce2005-01-03 21:02:03 +0000221A List is an ordered sequence of items. An item can be of any type. Items
Bram Moolenaar58b85342016-08-14 19:54:54 +0200222can be accessed by their index number. Items can be added and removed at any
Bram Moolenaard7ee7ce2005-01-03 21:02:03 +0000223position in the sequence.
224
Bram Moolenaar13065c42005-01-08 16:08:21 +0000225
226List creation ~
227 *E696* *E697*
Bram Moolenaard7ee7ce2005-01-03 21:02:03 +0000228A List is created with a comma separated list of items in square brackets.
Bram Moolenaar13065c42005-01-08 16:08:21 +0000229Examples: >
230 :let mylist = [1, two, 3, "four"]
231 :let emptylist = []
Bram Moolenaard7ee7ce2005-01-03 21:02:03 +0000232
Bram Moolenaar58b85342016-08-14 19:54:54 +0200233An item can be any expression. Using a List for an item creates a
Bram Moolenaarf9393ef2006-04-24 19:47:27 +0000234List of Lists: >
Bram Moolenaar13065c42005-01-08 16:08:21 +0000235 :let nestlist = [[11, 12], [21, 22], [31, 32]]
Bram Moolenaard7ee7ce2005-01-03 21:02:03 +0000236
237An extra comma after the last item is ignored.
238
Bram Moolenaar13065c42005-01-08 16:08:21 +0000239
240List index ~
241 *list-index* *E684*
Bram Moolenaard7ee7ce2005-01-03 21:02:03 +0000242An item in the List can be accessed by putting the index in square brackets
Bram Moolenaar13065c42005-01-08 16:08:21 +0000243after the List. Indexes are zero-based, thus the first item has index zero. >
244 :let item = mylist[0] " get the first item: 1
Bram Moolenaard7ee7ce2005-01-03 21:02:03 +0000245 :let item = mylist[2] " get the third item: 3
Bram Moolenaar13065c42005-01-08 16:08:21 +0000246
Bram Moolenaar9588a0f2005-01-08 21:45:39 +0000247When the resulting item is a list this can be repeated: >
Bram Moolenaar13065c42005-01-08 16:08:21 +0000248 :let item = nestlist[0][1] " get the first list, second item: 12
Bram Moolenaard7ee7ce2005-01-03 21:02:03 +0000249<
Bram Moolenaar13065c42005-01-08 16:08:21 +0000250A negative index is counted from the end. Index -1 refers to the last item in
251the List, -2 to the last but one item, etc. >
Bram Moolenaard7ee7ce2005-01-03 21:02:03 +0000252 :let last = mylist[-1] " get the last item: "four"
253
Bram Moolenaar13065c42005-01-08 16:08:21 +0000254To avoid an error for an invalid index use the |get()| function. When an item
Bram Moolenaar9588a0f2005-01-08 21:45:39 +0000255is not available it returns zero or the default value you specify: >
Bram Moolenaar13065c42005-01-08 16:08:21 +0000256 :echo get(mylist, idx)
257 :echo get(mylist, idx, "NONE")
258
259
260List concatenation ~
261
262Two lists can be concatenated with the "+" operator: >
263 :let longlist = mylist + [5, 6]
Bram Moolenaar383f9bc2005-01-19 22:18:32 +0000264 :let mylist += [7, 8]
Bram Moolenaar13065c42005-01-08 16:08:21 +0000265
266To prepend or append an item turn the item into a list by putting [] around
267it. To change a list in-place see |list-modification| below.
268
269
270Sublist ~
Bram Moolenaarbc8801c2016-08-02 21:04:33 +0200271 *sublist*
Bram Moolenaard7ee7ce2005-01-03 21:02:03 +0000272A part of the List can be obtained by specifying the first and last index,
273separated by a colon in square brackets: >
Bram Moolenaar13065c42005-01-08 16:08:21 +0000274 :let shortlist = mylist[2:-1] " get List [3, "four"]
Bram Moolenaard7ee7ce2005-01-03 21:02:03 +0000275
276Omitting the first index is similar to zero. Omitting the last index is
Bram Moolenaaref2f6562007-05-06 13:32:59 +0000277similar to -1. >
Bram Moolenaar540d6e32005-01-09 21:20:18 +0000278 :let endlist = mylist[2:] " from item 2 to the end: [3, "four"]
279 :let shortlist = mylist[2:2] " List with one item: [3]
280 :let otherlist = mylist[:] " make a copy of the List
Bram Moolenaard7ee7ce2005-01-03 21:02:03 +0000281
Bram Moolenaarf9393ef2006-04-24 19:47:27 +0000282If the first index is beyond the last item of the List or the second item is
283before the first item, the result is an empty list. There is no error
284message.
285
286If the second index is equal to or greater than the length of the list the
287length minus one is used: >
Bram Moolenaar9e54a0e2006-04-14 20:42:25 +0000288 :let mylist = [0, 1, 2, 3]
289 :echo mylist[2:8] " result: [2, 3]
290
Bram Moolenaara7fc0102005-05-18 22:17:12 +0000291NOTE: mylist[s:e] means using the variable "s:e" as index. Watch out for
Bram Moolenaar58b85342016-08-14 19:54:54 +0200292using a single letter variable before the ":". Insert a space when needed:
Bram Moolenaara7fc0102005-05-18 22:17:12 +0000293mylist[s : e].
294
Bram Moolenaard7ee7ce2005-01-03 21:02:03 +0000295
Bram Moolenaar13065c42005-01-08 16:08:21 +0000296List identity ~
Bram Moolenaard8b02732005-01-14 21:48:43 +0000297 *list-identity*
Bram Moolenaar13065c42005-01-08 16:08:21 +0000298When variable "aa" is a list and you assign it to another variable "bb", both
299variables refer to the same list. Thus changing the list "aa" will also
300change "bb": >
301 :let aa = [1, 2, 3]
302 :let bb = aa
303 :call add(aa, 4)
304 :echo bb
Bram Moolenaar3a3a7232005-01-17 22:16:15 +0000305< [1, 2, 3, 4]
Bram Moolenaar13065c42005-01-08 16:08:21 +0000306
307Making a copy of a list is done with the |copy()| function. Using [:] also
308works, as explained above. This creates a shallow copy of the list: Changing
Bram Moolenaar9588a0f2005-01-08 21:45:39 +0000309a list item in the list will also change the item in the copied list: >
Bram Moolenaar13065c42005-01-08 16:08:21 +0000310 :let aa = [[1, 'a'], 2, 3]
311 :let bb = copy(aa)
Bram Moolenaar3a3a7232005-01-17 22:16:15 +0000312 :call add(aa, 4)
Bram Moolenaar13065c42005-01-08 16:08:21 +0000313 :let aa[0][1] = 'aaa'
314 :echo aa
Bram Moolenaar3a3a7232005-01-17 22:16:15 +0000315< [[1, aaa], 2, 3, 4] >
Bram Moolenaar13065c42005-01-08 16:08:21 +0000316 :echo bb
Bram Moolenaar3a3a7232005-01-17 22:16:15 +0000317< [[1, aaa], 2, 3]
Bram Moolenaar13065c42005-01-08 16:08:21 +0000318
Bram Moolenaar9588a0f2005-01-08 21:45:39 +0000319To make a completely independent list use |deepcopy()|. This also makes a
Bram Moolenaar3a3a7232005-01-17 22:16:15 +0000320copy of the values in the list, recursively. Up to a hundred levels deep.
Bram Moolenaar13065c42005-01-08 16:08:21 +0000321
322The operator "is" can be used to check if two variables refer to the same
Bram Moolenaar3a3a7232005-01-17 22:16:15 +0000323List. "isnot" does the opposite. In contrast "==" compares if two lists have
Bram Moolenaar9588a0f2005-01-08 21:45:39 +0000324the same value. >
325 :let alist = [1, 2, 3]
326 :let blist = [1, 2, 3]
327 :echo alist is blist
Bram Moolenaar3a3a7232005-01-17 22:16:15 +0000328< 0 >
Bram Moolenaar9588a0f2005-01-08 21:45:39 +0000329 :echo alist == blist
Bram Moolenaar3a3a7232005-01-17 22:16:15 +0000330< 1
Bram Moolenaar13065c42005-01-08 16:08:21 +0000331
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +0000332Note about comparing lists: Two lists are considered equal if they have the
333same length and all items compare equal, as with using "==". There is one
Bram Moolenaar7d1f5db2005-07-03 21:39:27 +0000334exception: When comparing a number with a string they are considered
335different. There is no automatic type conversion, as with using "==" on
336variables. Example: >
337 echo 4 == "4"
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +0000338< 1 >
Bram Moolenaar7d1f5db2005-07-03 21:39:27 +0000339 echo [4] == ["4"]
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +0000340< 0
341
Bram Moolenaar7d1f5db2005-07-03 21:39:27 +0000342Thus comparing Lists is more strict than comparing numbers and strings. You
Bram Moolenaar446cb832008-06-24 21:56:24 +0000343can compare simple values this way too by putting them in a list: >
Bram Moolenaar7d1f5db2005-07-03 21:39:27 +0000344
345 :let a = 5
346 :let b = "5"
Bram Moolenaar446cb832008-06-24 21:56:24 +0000347 :echo a == b
Bram Moolenaar7d1f5db2005-07-03 21:39:27 +0000348< 1 >
Bram Moolenaar446cb832008-06-24 21:56:24 +0000349 :echo [a] == [b]
Bram Moolenaar7d1f5db2005-07-03 21:39:27 +0000350< 0
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +0000351
Bram Moolenaar13065c42005-01-08 16:08:21 +0000352
353List unpack ~
354
355To unpack the items in a list to individual variables, put the variables in
356square brackets, like list items: >
357 :let [var1, var2] = mylist
358
359When the number of variables does not match the number of items in the list
360this produces an error. To handle any extra items from the list append ";"
361and a variable name: >
362 :let [var1, var2; rest] = mylist
363
364This works like: >
365 :let var1 = mylist[0]
366 :let var2 = mylist[1]
Bram Moolenaar5f2bb9f2005-01-11 21:29:04 +0000367 :let rest = mylist[2:]
Bram Moolenaar13065c42005-01-08 16:08:21 +0000368
369Except that there is no error if there are only two items. "rest" will be an
370empty list then.
371
372
373List modification ~
374 *list-modification*
Bram Moolenaar9588a0f2005-01-08 21:45:39 +0000375To change a specific item of a list use |:let| this way: >
Bram Moolenaar13065c42005-01-08 16:08:21 +0000376 :let list[4] = "four"
377 :let listlist[0][3] = item
378
Bram Moolenaar9588a0f2005-01-08 21:45:39 +0000379To change part of a list you can specify the first and last item to be
Bram Moolenaar3a3a7232005-01-17 22:16:15 +0000380modified. The value must at least have the number of items in the range: >
Bram Moolenaar9588a0f2005-01-08 21:45:39 +0000381 :let list[3:5] = [3, 4, 5]
382
Bram Moolenaar13065c42005-01-08 16:08:21 +0000383Adding and removing items from a list is done with functions. Here are a few
384examples: >
385 :call insert(list, 'a') " prepend item 'a'
386 :call insert(list, 'a', 3) " insert item 'a' before list[3]
387 :call add(list, "new") " append String item
Bram Moolenaar3a3a7232005-01-17 22:16:15 +0000388 :call add(list, [1, 2]) " append a List as one new item
Bram Moolenaar13065c42005-01-08 16:08:21 +0000389 :call extend(list, [1, 2]) " extend the list with two more items
390 :let i = remove(list, 3) " remove item 3
Bram Moolenaar9cd15162005-01-16 22:02:49 +0000391 :unlet list[3] " idem
Bram Moolenaar13065c42005-01-08 16:08:21 +0000392 :let l = remove(list, 3, -1) " remove items 3 to last item
Bram Moolenaar9cd15162005-01-16 22:02:49 +0000393 :unlet list[3 : ] " idem
Bram Moolenaar3a3a7232005-01-17 22:16:15 +0000394 :call filter(list, 'v:val !~ "x"') " remove items with an 'x'
Bram Moolenaar13065c42005-01-08 16:08:21 +0000395
Bram Moolenaar3a3a7232005-01-17 22:16:15 +0000396Changing the order of items in a list: >
Bram Moolenaar9588a0f2005-01-08 21:45:39 +0000397 :call sort(list) " sort a list alphabetically
398 :call reverse(list) " reverse the order of items
Bram Moolenaar327aa022014-03-25 18:24:23 +0100399 :call uniq(sort(list)) " sort and remove duplicates
Bram Moolenaar9588a0f2005-01-08 21:45:39 +0000400
Bram Moolenaar13065c42005-01-08 16:08:21 +0000401
402For loop ~
403
Bram Moolenaar9588a0f2005-01-08 21:45:39 +0000404The |:for| loop executes commands for each item in a list. A variable is set
405to each item in the list in sequence. Example: >
Bram Moolenaar3a3a7232005-01-17 22:16:15 +0000406 :for item in mylist
407 : call Doit(item)
Bram Moolenaar13065c42005-01-08 16:08:21 +0000408 :endfor
409
410This works like: >
411 :let index = 0
412 :while index < len(mylist)
Bram Moolenaar3a3a7232005-01-17 22:16:15 +0000413 : let item = mylist[index]
414 : :call Doit(item)
Bram Moolenaar13065c42005-01-08 16:08:21 +0000415 : let index = index + 1
416 :endwhile
417
Bram Moolenaar5f2bb9f2005-01-11 21:29:04 +0000418If all you want to do is modify each item in the list then the |map()|
Bram Moolenaar3a3a7232005-01-17 22:16:15 +0000419function will be a simpler method than a for loop.
Bram Moolenaar5f2bb9f2005-01-11 21:29:04 +0000420
Bram Moolenaar58b85342016-08-14 19:54:54 +0200421Just like the |:let| command, |:for| also accepts a list of variables. This
Bram Moolenaar13065c42005-01-08 16:08:21 +0000422requires the argument to be a list of lists. >
423 :for [lnum, col] in [[1, 3], [2, 8], [3, 0]]
424 : call Doit(lnum, col)
425 :endfor
426
427This works like a |:let| command is done for each list item. Again, the types
428must remain the same to avoid an error.
429
Bram Moolenaar3a3a7232005-01-17 22:16:15 +0000430It is also possible to put remaining items in a List variable: >
Bram Moolenaar13065c42005-01-08 16:08:21 +0000431 :for [i, j; rest] in listlist
432 : call Doit(i, j)
433 : if !empty(rest)
434 : echo "remainder: " . string(rest)
435 : endif
436 :endfor
437
438
439List functions ~
Bram Moolenaar3a3a7232005-01-17 22:16:15 +0000440 *E714*
Bram Moolenaar13065c42005-01-08 16:08:21 +0000441Functions that are useful with a List: >
Bram Moolenaar9588a0f2005-01-08 21:45:39 +0000442 :let r = call(funcname, list) " call a function with an argument list
Bram Moolenaar13065c42005-01-08 16:08:21 +0000443 :if empty(list) " check if list is empty
Bram Moolenaar2fda12f2005-01-15 22:14:15 +0000444 :let l = len(list) " number of items in list
445 :let big = max(list) " maximum value in list
446 :let small = min(list) " minimum value in list
Bram Moolenaar9588a0f2005-01-08 21:45:39 +0000447 :let xs = count(list, 'x') " count nr of times 'x' appears in list
448 :let i = index(list, 'x') " index of first 'x' in list
Bram Moolenaar13065c42005-01-08 16:08:21 +0000449 :let lines = getline(1, 10) " get ten text lines from buffer
450 :call append('$', lines) " append text lines in buffer
Bram Moolenaar5f2bb9f2005-01-11 21:29:04 +0000451 :let list = split("a b c") " create list from items in a string
452 :let string = join(list, ', ') " create string from list items
Bram Moolenaar2fda12f2005-01-15 22:14:15 +0000453 :let s = string(list) " String representation of list
454 :call map(list, '">> " . v:val') " prepend ">> " to each item
Bram Moolenaar13065c42005-01-08 16:08:21 +0000455
Bram Moolenaar0cb032e2005-04-23 20:52:00 +0000456Don't forget that a combination of features can make things simple. For
457example, to add up all the numbers in a list: >
458 :exe 'let sum = ' . join(nrlist, '+')
459
Bram Moolenaar13065c42005-01-08 16:08:21 +0000460
Bram Moolenaard8b02732005-01-14 21:48:43 +00004611.4 Dictionaries ~
Bram Moolenaar7e38ea22014-04-05 22:55:53 +0200462 *dict* *Dictionaries* *Dictionary*
Bram Moolenaard8b02732005-01-14 21:48:43 +0000463A Dictionary is an associative array: Each entry has a key and a value. The
Bram Moolenaar3a3a7232005-01-17 22:16:15 +0000464entry can be located with the key. The entries are stored without a specific
465ordering.
Bram Moolenaard8b02732005-01-14 21:48:43 +0000466
467
468Dictionary creation ~
Bram Moolenaar3a3a7232005-01-17 22:16:15 +0000469 *E720* *E721* *E722* *E723*
Bram Moolenaard8b02732005-01-14 21:48:43 +0000470A Dictionary is created with a comma separated list of entries in curly
Bram Moolenaar3a3a7232005-01-17 22:16:15 +0000471braces. Each entry has a key and a value, separated by a colon. Each key can
472only appear once. Examples: >
Bram Moolenaard8b02732005-01-14 21:48:43 +0000473 :let mydict = {1: 'one', 2: 'two', 3: 'three'}
474 :let emptydict = {}
Bram Moolenaar3a3a7232005-01-17 22:16:15 +0000475< *E713* *E716* *E717*
Bram Moolenaard8b02732005-01-14 21:48:43 +0000476A key is always a String. You can use a Number, it will be converted to a
477String automatically. Thus the String '4' and the number 4 will find the same
Bram Moolenaar58b85342016-08-14 19:54:54 +0200478entry. Note that the String '04' and the Number 04 are different, since the
Bram Moolenaar03413f42016-04-12 21:07:15 +0200479Number will be converted to the String '4'. The empty string can be used as a
480key.
Bram Moolenaard8b02732005-01-14 21:48:43 +0000481
Bram Moolenaar58b85342016-08-14 19:54:54 +0200482A value can be any expression. Using a Dictionary for a value creates a
Bram Moolenaard8b02732005-01-14 21:48:43 +0000483nested Dictionary: >
484 :let nestdict = {1: {11: 'a', 12: 'b'}, 2: {21: 'c'}}
485
486An extra comma after the last entry is ignored.
487
488
489Accessing entries ~
490
491The normal way to access an entry is by putting the key in square brackets: >
492 :let val = mydict["one"]
493 :let mydict["four"] = 4
494
Bram Moolenaar3a3a7232005-01-17 22:16:15 +0000495You can add new entries to an existing Dictionary this way, unlike Lists.
Bram Moolenaard8b02732005-01-14 21:48:43 +0000496
497For keys that consist entirely of letters, digits and underscore the following
498form can be used |expr-entry|: >
499 :let val = mydict.one
500 :let mydict.four = 4
501
502Since an entry can be any type, also a List and a Dictionary, the indexing and
503key lookup can be repeated: >
Bram Moolenaar3a3a7232005-01-17 22:16:15 +0000504 :echo dict.key[idx].key
Bram Moolenaard8b02732005-01-14 21:48:43 +0000505
506
507Dictionary to List conversion ~
508
Bram Moolenaar58b85342016-08-14 19:54:54 +0200509You may want to loop over the entries in a dictionary. For this you need to
Bram Moolenaard8b02732005-01-14 21:48:43 +0000510turn the Dictionary into a List and pass it to |:for|.
511
512Most often you want to loop over the keys, using the |keys()| function: >
513 :for key in keys(mydict)
514 : echo key . ': ' . mydict[key]
515 :endfor
516
517The List of keys is unsorted. You may want to sort them first: >
518 :for key in sort(keys(mydict))
519
520To loop over the values use the |values()| function: >
521 :for v in values(mydict)
522 : echo "value: " . v
523 :endfor
524
525If you want both the key and the value use the |items()| function. It returns
Bram Moolenaard47d5222018-12-09 20:43:55 +0100526a List in which each item is a List with two items, the key and the value: >
Bram Moolenaaref2f6562007-05-06 13:32:59 +0000527 :for [key, value] in items(mydict)
528 : echo key . ': ' . value
Bram Moolenaard8b02732005-01-14 21:48:43 +0000529 :endfor
530
531
532Dictionary identity ~
Bram Moolenaar7c626922005-02-07 22:01:03 +0000533 *dict-identity*
Bram Moolenaard8b02732005-01-14 21:48:43 +0000534Just like Lists you need to use |copy()| and |deepcopy()| to make a copy of a
535Dictionary. Otherwise, assignment results in referring to the same
536Dictionary: >
537 :let onedict = {'a': 1, 'b': 2}
538 :let adict = onedict
539 :let adict['a'] = 11
540 :echo onedict['a']
541 11
542
Bram Moolenaarf3bd51a2005-06-14 22:11:18 +0000543Two Dictionaries compare equal if all the key-value pairs compare equal. For
544more info see |list-identity|.
Bram Moolenaard8b02732005-01-14 21:48:43 +0000545
546
547Dictionary modification ~
548 *dict-modification*
549To change an already existing entry of a Dictionary, or to add a new entry,
550use |:let| this way: >
551 :let dict[4] = "four"
552 :let dict['one'] = item
553
Bram Moolenaar9cd15162005-01-16 22:02:49 +0000554Removing an entry from a Dictionary is done with |remove()| or |:unlet|.
555Three ways to remove the entry with key "aaa" from dict: >
556 :let i = remove(dict, 'aaa')
557 :unlet dict.aaa
558 :unlet dict['aaa']
Bram Moolenaard8b02732005-01-14 21:48:43 +0000559
560Merging a Dictionary with another is done with |extend()|: >
Bram Moolenaar3a3a7232005-01-17 22:16:15 +0000561 :call extend(adict, bdict)
562This extends adict with all entries from bdict. Duplicate keys cause entries
563in adict to be overwritten. An optional third argument can change this.
Bram Moolenaar383f9bc2005-01-19 22:18:32 +0000564Note that the order of entries in a Dictionary is irrelevant, thus don't
565expect ":echo adict" to show the items from bdict after the older entries in
566adict.
Bram Moolenaard8b02732005-01-14 21:48:43 +0000567
568Weeding out entries from a Dictionary can be done with |filter()|: >
Bram Moolenaaref2f6562007-05-06 13:32:59 +0000569 :call filter(dict, 'v:val =~ "x"')
Bram Moolenaar3a3a7232005-01-17 22:16:15 +0000570This removes all entries from "dict" with a value not matching 'x'.
Bram Moolenaar2fda12f2005-01-15 22:14:15 +0000571
572
573Dictionary function ~
Bram Moolenaar26402cb2013-02-20 21:26:00 +0100574 *Dictionary-function* *self* *E725* *E862*
Bram Moolenaar2fda12f2005-01-15 22:14:15 +0000575When a function is defined with the "dict" attribute it can be used in a
Bram Moolenaar58b85342016-08-14 19:54:54 +0200576special way with a dictionary. Example: >
Bram Moolenaar2fda12f2005-01-15 22:14:15 +0000577 :function Mylen() dict
Bram Moolenaar3a3a7232005-01-17 22:16:15 +0000578 : return len(self.data)
Bram Moolenaar2fda12f2005-01-15 22:14:15 +0000579 :endfunction
Bram Moolenaar3a3a7232005-01-17 22:16:15 +0000580 :let mydict = {'data': [0, 1, 2, 3], 'len': function("Mylen")}
581 :echo mydict.len()
Bram Moolenaar2fda12f2005-01-15 22:14:15 +0000582
583This is like a method in object oriented programming. The entry in the
584Dictionary is a |Funcref|. The local variable "self" refers to the dictionary
585the function was invoked from.
586
Bram Moolenaar3a3a7232005-01-17 22:16:15 +0000587It is also possible to add a function without the "dict" attribute as a
588Funcref to a Dictionary, but the "self" variable is not available then.
589
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000590 *numbered-function* *anonymous-function*
Bram Moolenaar2fda12f2005-01-15 22:14:15 +0000591To avoid the extra name for the function it can be defined and directly
592assigned to a Dictionary in this way: >
Bram Moolenaar3a3a7232005-01-17 22:16:15 +0000593 :let mydict = {'data': [0, 1, 2, 3]}
Bram Moolenaar5a5f4592015-04-13 12:43:06 +0200594 :function mydict.len()
Bram Moolenaar3a3a7232005-01-17 22:16:15 +0000595 : return len(self.data)
Bram Moolenaar2fda12f2005-01-15 22:14:15 +0000596 :endfunction
Bram Moolenaar3a3a7232005-01-17 22:16:15 +0000597 :echo mydict.len()
Bram Moolenaar2fda12f2005-01-15 22:14:15 +0000598
Bram Moolenaar3a3a7232005-01-17 22:16:15 +0000599The function will then get a number and the value of dict.len is a |Funcref|
Bram Moolenaar58b85342016-08-14 19:54:54 +0200600that references this function. The function can only be used through a
Bram Moolenaar3a3a7232005-01-17 22:16:15 +0000601|Funcref|. It will automatically be deleted when there is no |Funcref|
602remaining that refers to it.
603
604It is not necessary to use the "dict" attribute for a numbered function.
Bram Moolenaar2fda12f2005-01-15 22:14:15 +0000605
Bram Moolenaar1affd722010-08-04 17:49:30 +0200606If you get an error for a numbered function, you can find out what it is with
607a trick. Assuming the function is 42, the command is: >
608 :function {42}
609
Bram Moolenaar2fda12f2005-01-15 22:14:15 +0000610
611Functions for Dictionaries ~
Bram Moolenaar3a3a7232005-01-17 22:16:15 +0000612 *E715*
613Functions that can be used with a Dictionary: >
Bram Moolenaar2fda12f2005-01-15 22:14:15 +0000614 :if has_key(dict, 'foo') " TRUE if dict has entry with key "foo"
615 :if empty(dict) " TRUE if dict is empty
616 :let l = len(dict) " number of items in dict
617 :let big = max(dict) " maximum value in dict
618 :let small = min(dict) " minimum value in dict
619 :let xs = count(dict, 'x') " count nr of times 'x' appears in dict
620 :let s = string(dict) " String representation of dict
621 :call map(dict, '">> " . v:val') " prepend ">> " to each item
Bram Moolenaard8b02732005-01-14 21:48:43 +0000622
623
6241.5 More about variables ~
Bram Moolenaar13065c42005-01-08 16:08:21 +0000625 *more-variables*
Bram Moolenaar071d4272004-06-13 20:20:40 +0000626If you need to know the type of a variable or expression, use the |type()|
627function.
628
629When the '!' flag is included in the 'viminfo' option, global variables that
630start with an uppercase letter, and don't contain a lowercase letter, are
631stored in the viminfo file |viminfo-file|.
632
633When the 'sessionoptions' option contains "global", global variables that
634start with an uppercase letter and contain at least one lowercase letter are
635stored in the session file |session-file|.
636
637variable name can be stored where ~
638my_var_6 not
639My_Var_6 session file
640MY_VAR_6 viminfo file
641
642
643It's possible to form a variable name with curly braces, see
644|curly-braces-names|.
645
646==============================================================================
6472. Expression syntax *expression-syntax*
648
649Expression syntax summary, from least to most significant:
650
Bram Moolenaar50ba5262016-09-22 22:33:02 +0200651|expr1| expr2
Bram Moolenaar89bcfda2016-08-30 23:26:57 +0200652 expr2 ? expr1 : expr1 if-then-else
Bram Moolenaar071d4272004-06-13 20:20:40 +0000653
Bram Moolenaar89bcfda2016-08-30 23:26:57 +0200654|expr2| expr3
655 expr3 || expr3 .. logical OR
Bram Moolenaar071d4272004-06-13 20:20:40 +0000656
Bram Moolenaar89bcfda2016-08-30 23:26:57 +0200657|expr3| expr4
658 expr4 && expr4 .. logical AND
Bram Moolenaar071d4272004-06-13 20:20:40 +0000659
Bram Moolenaar89bcfda2016-08-30 23:26:57 +0200660|expr4| expr5
661 expr5 == expr5 equal
Bram Moolenaar071d4272004-06-13 20:20:40 +0000662 expr5 != expr5 not equal
663 expr5 > expr5 greater than
664 expr5 >= expr5 greater than or equal
665 expr5 < expr5 smaller than
666 expr5 <= expr5 smaller than or equal
667 expr5 =~ expr5 regexp matches
668 expr5 !~ expr5 regexp doesn't match
669
670 expr5 ==? expr5 equal, ignoring case
671 expr5 ==# expr5 equal, match case
672 etc. As above, append ? for ignoring case, # for
673 matching case
674
Bram Moolenaar32466aa2006-02-24 23:53:04 +0000675 expr5 is expr5 same |List| instance
676 expr5 isnot expr5 different |List| instance
Bram Moolenaarde8866b2005-01-06 23:24:37 +0000677
Bram Moolenaar89bcfda2016-08-30 23:26:57 +0200678|expr5| expr6
679 expr6 + expr6 .. number addition or list concatenation
Bram Moolenaar071d4272004-06-13 20:20:40 +0000680 expr6 - expr6 .. number subtraction
681 expr6 . expr6 .. string concatenation
682
Bram Moolenaar89bcfda2016-08-30 23:26:57 +0200683|expr6| expr7
684 expr7 * expr7 .. number multiplication
Bram Moolenaar071d4272004-06-13 20:20:40 +0000685 expr7 / expr7 .. number division
686 expr7 % expr7 .. number modulo
687
Bram Moolenaar89bcfda2016-08-30 23:26:57 +0200688|expr7| expr8
689 ! expr7 logical NOT
Bram Moolenaar071d4272004-06-13 20:20:40 +0000690 - expr7 unary minus
691 + expr7 unary plus
Bram Moolenaar071d4272004-06-13 20:20:40 +0000692
Bram Moolenaar89bcfda2016-08-30 23:26:57 +0200693|expr8| expr9
694 expr8[expr1] byte of a String or item of a |List|
Bram Moolenaar32466aa2006-02-24 23:53:04 +0000695 expr8[expr1 : expr1] substring of a String or sublist of a |List|
696 expr8.name entry in a |Dictionary|
697 expr8(expr1, ...) function call with |Funcref| variable
Bram Moolenaar2fda12f2005-01-15 22:14:15 +0000698
Bram Moolenaar50ba5262016-09-22 22:33:02 +0200699|expr9| number number constant
Bram Moolenaar3fdfa4a2004-10-07 21:02:47 +0000700 "string" string constant, backslash is special
Bram Moolenaard8b02732005-01-14 21:48:43 +0000701 'string' string constant, ' is doubled
Bram Moolenaar32466aa2006-02-24 23:53:04 +0000702 [expr1, ...] |List|
703 {expr1: expr1, ...} |Dictionary|
Bram Moolenaar071d4272004-06-13 20:20:40 +0000704 &option option value
705 (expr1) nested expression
706 variable internal variable
707 va{ria}ble internal variable with curly braces
708 $VAR environment variable
709 @r contents of register 'r'
710 function(expr1, ...) function call
711 func{ti}on(expr1, ...) function call with curly braces
Bram Moolenaar069c1e72016-07-15 21:25:08 +0200712 {args -> expr1} lambda expression
Bram Moolenaar071d4272004-06-13 20:20:40 +0000713
714
715".." indicates that the operations in this level can be concatenated.
716Example: >
717 &nu || &list && &shell == "csh"
718
719All expressions within one level are parsed from left to right.
720
721
722expr1 *expr1* *E109*
723-----
724
725expr2 ? expr1 : expr1
726
727The expression before the '?' is evaluated to a number. If it evaluates to
Bram Moolenaare381d3d2016-07-07 14:50:41 +0200728|TRUE|, the result is the value of the expression between the '?' and ':',
Bram Moolenaar071d4272004-06-13 20:20:40 +0000729otherwise the result is the value of the expression after the ':'.
730Example: >
731 :echo lnum == 1 ? "top" : lnum
732
733Since the first expression is an "expr2", it cannot contain another ?:. The
734other two expressions can, thus allow for recursive use of ?:.
735Example: >
736 :echo lnum == 1 ? "top" : lnum == 1000 ? "last" : lnum
737
738To keep this readable, using |line-continuation| is suggested: >
739 :echo lnum == 1
740 :\ ? "top"
741 :\ : lnum == 1000
742 :\ ? "last"
743 :\ : lnum
744
Bram Moolenaaref2f6562007-05-06 13:32:59 +0000745You should always put a space before the ':', otherwise it can be mistaken for
746use in a variable such as "a:1".
747
Bram Moolenaar071d4272004-06-13 20:20:40 +0000748
749expr2 and expr3 *expr2* *expr3*
750---------------
751
Bram Moolenaar04186092016-08-29 21:55:35 +0200752expr3 || expr3 .. logical OR *expr-barbar*
753expr4 && expr4 .. logical AND *expr-&&*
754
Bram Moolenaar071d4272004-06-13 20:20:40 +0000755The "||" and "&&" operators take one argument on each side. The arguments
756are (converted to) Numbers. The result is:
757
Bram Moolenaare381d3d2016-07-07 14:50:41 +0200758 input output ~
759n1 n2 n1 || n2 n1 && n2 ~
760|FALSE| |FALSE| |FALSE| |FALSE|
761|FALSE| |TRUE| |TRUE| |FALSE|
762|TRUE| |FALSE| |TRUE| |FALSE|
763|TRUE| |TRUE| |TRUE| |TRUE|
Bram Moolenaar071d4272004-06-13 20:20:40 +0000764
765The operators can be concatenated, for example: >
766
767 &nu || &list && &shell == "csh"
768
769Note that "&&" takes precedence over "||", so this has the meaning of: >
770
771 &nu || (&list && &shell == "csh")
772
773Once the result is known, the expression "short-circuits", that is, further
774arguments are not evaluated. This is like what happens in C. For example: >
775
776 let a = 1
777 echo a || b
778
Bram Moolenaare381d3d2016-07-07 14:50:41 +0200779This is valid even if there is no variable called "b" because "a" is |TRUE|,
780so the result must be |TRUE|. Similarly below: >
Bram Moolenaar071d4272004-06-13 20:20:40 +0000781
782 echo exists("b") && b == "yes"
783
784This is valid whether "b" has been defined or not. The second clause will
785only be evaluated if "b" has been defined.
786
787
788expr4 *expr4*
789-----
790
791expr5 {cmp} expr5
792
793Compare two expr5 expressions, resulting in a 0 if it evaluates to false, or 1
794if it evaluates to true.
795
Bram Moolenaar446cb832008-06-24 21:56:24 +0000796 *expr-==* *expr-!=* *expr->* *expr->=*
Bram Moolenaar071d4272004-06-13 20:20:40 +0000797 *expr-<* *expr-<=* *expr-=~* *expr-!~*
798 *expr-==#* *expr-!=#* *expr->#* *expr->=#*
799 *expr-<#* *expr-<=#* *expr-=~#* *expr-!~#*
800 *expr-==?* *expr-!=?* *expr->?* *expr->=?*
801 *expr-<?* *expr-<=?* *expr-=~?* *expr-!~?*
Bram Moolenaar251e1912011-06-19 05:09:16 +0200802 *expr-is* *expr-isnot* *expr-is#* *expr-isnot#*
803 *expr-is?* *expr-isnot?*
Bram Moolenaar071d4272004-06-13 20:20:40 +0000804 use 'ignorecase' match case ignore case ~
805equal == ==# ==?
806not equal != !=# !=?
807greater than > ># >?
808greater than or equal >= >=# >=?
809smaller than < <# <?
810smaller than or equal <= <=# <=?
811regexp matches =~ =~# =~?
812regexp doesn't match !~ !~# !~?
Bram Moolenaar251e1912011-06-19 05:09:16 +0200813same instance is is# is?
814different instance isnot isnot# isnot?
Bram Moolenaar071d4272004-06-13 20:20:40 +0000815
816Examples:
817"abc" ==# "Abc" evaluates to 0
818"abc" ==? "Abc" evaluates to 1
819"abc" == "Abc" evaluates to 1 if 'ignorecase' is set, 0 otherwise
820
Bram Moolenaar13065c42005-01-08 16:08:21 +0000821 *E691* *E692*
Bram Moolenaar01164a62017-11-02 22:58:42 +0100822A |List| can only be compared with a |List| and only "equal", "not equal",
823"is" and "isnot" can be used. This compares the values of the list,
824recursively. Ignoring case means case is ignored when comparing item values.
Bram Moolenaarde8866b2005-01-06 23:24:37 +0000825
Bram Moolenaar3a3a7232005-01-17 22:16:15 +0000826 *E735* *E736*
Bram Moolenaar32466aa2006-02-24 23:53:04 +0000827A |Dictionary| can only be compared with a |Dictionary| and only "equal", "not
Bram Moolenaar01164a62017-11-02 22:58:42 +0100828equal", "is" and "isnot" can be used. This compares the key/values of the
829|Dictionary| recursively. Ignoring case means case is ignored when comparing
830item values.
Bram Moolenaar3a3a7232005-01-17 22:16:15 +0000831
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +0200832 *E694*
Bram Moolenaare18dbe82016-07-02 21:42:23 +0200833A |Funcref| can only be compared with a |Funcref| and only "equal", "not
834equal", "is" and "isnot" can be used. Case is never ignored. Whether
835arguments or a Dictionary are bound (with a partial) matters. The
836Dictionaries must also be equal (or the same, in case of "is") and the
837arguments must be equal (or the same).
838
839To compare Funcrefs to see if they refer to the same function, ignoring bound
840Dictionary and arguments, use |get()| to get the function name: >
841 if get(Part1, 'name') == get(Part2, 'name')
842 " Part1 and Part2 refer to the same function
Bram Moolenaarde8866b2005-01-06 23:24:37 +0000843
Bram Moolenaar251e1912011-06-19 05:09:16 +0200844When using "is" or "isnot" with a |List| or a |Dictionary| this checks if the
845expressions are referring to the same |List| or |Dictionary| instance. A copy
846of a |List| is different from the original |List|. When using "is" without
847a |List| or a |Dictionary| it is equivalent to using "equal", using "isnot"
848equivalent to using "not equal". Except that a different type means the
Bram Moolenaar86edef62016-03-13 18:07:30 +0100849values are different: >
850 echo 4 == '4'
851 1
852 echo 4 is '4'
853 0
854 echo 0 is []
855 0
856"is#"/"isnot#" and "is?"/"isnot?" can be used to match and ignore case.
Bram Moolenaarde8866b2005-01-06 23:24:37 +0000857
Bram Moolenaar071d4272004-06-13 20:20:40 +0000858When comparing a String with a Number, the String is converted to a Number,
Bram Moolenaar58b85342016-08-14 19:54:54 +0200859and the comparison is done on Numbers. This means that: >
Bram Moolenaar86edef62016-03-13 18:07:30 +0100860 echo 0 == 'x'
861 1
862because 'x' converted to a Number is zero. However: >
863 echo [0] == ['x']
864 0
865Inside a List or Dictionary this conversion is not used.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000866
867When comparing two Strings, this is done with strcmp() or stricmp(). This
868results in the mathematical difference (comparing byte values), not
869necessarily the alphabetical difference in the local language.
870
Bram Moolenaar446cb832008-06-24 21:56:24 +0000871When using the operators with a trailing '#', or the short version and
Bram Moolenaaref2f6562007-05-06 13:32:59 +0000872'ignorecase' is off, the comparing is done with strcmp(): case matters.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000873
874When using the operators with a trailing '?', or the short version and
Bram Moolenaaref2f6562007-05-06 13:32:59 +0000875'ignorecase' is set, the comparing is done with stricmp(): case is ignored.
876
877'smartcase' is not used.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000878
879The "=~" and "!~" operators match the lefthand argument with the righthand
880argument, which is used as a pattern. See |pattern| for what a pattern is.
881This matching is always done like 'magic' was set and 'cpoptions' is empty, no
882matter what the actual value of 'magic' or 'cpoptions' is. This makes scripts
883portable. To avoid backslashes in the regexp pattern to be doubled, use a
884single-quote string, see |literal-string|.
885Since a string is considered to be a single line, a multi-line pattern
886(containing \n, backslash-n) will not match. However, a literal NL character
887can be matched like an ordinary character. Examples:
888 "foo\nbar" =~ "\n" evaluates to 1
889 "foo\nbar" =~ "\\n" evaluates to 0
890
891
892expr5 and expr6 *expr5* *expr6*
893---------------
Bram Moolenaar32466aa2006-02-24 23:53:04 +0000894expr6 + expr6 .. Number addition or |List| concatenation *expr-+*
Bram Moolenaarde8866b2005-01-06 23:24:37 +0000895expr6 - expr6 .. Number subtraction *expr--*
896expr6 . expr6 .. String concatenation *expr-.*
Bram Moolenaar071d4272004-06-13 20:20:40 +0000897
Bram Moolenaara23ccb82006-02-27 00:08:02 +0000898For |Lists| only "+" is possible and then both expr6 must be a list. The
Bram Moolenaar32466aa2006-02-24 23:53:04 +0000899result is a new list with the two lists Concatenated.
Bram Moolenaarde8866b2005-01-06 23:24:37 +0000900
Bram Moolenaard6e256c2011-12-14 15:32:50 +0100901expr7 * expr7 .. Number multiplication *expr-star*
902expr7 / expr7 .. Number division *expr-/*
903expr7 % expr7 .. Number modulo *expr-%*
Bram Moolenaar071d4272004-06-13 20:20:40 +0000904
905For all, except ".", Strings are converted to Numbers.
Bram Moolenaard6e256c2011-12-14 15:32:50 +0100906For bitwise operators see |and()|, |or()| and |xor()|.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000907
908Note the difference between "+" and ".":
909 "123" + "456" = 579
910 "123" . "456" = "123456"
911
Bram Moolenaar446cb832008-06-24 21:56:24 +0000912Since '.' has the same precedence as '+' and '-', you need to read: >
913 1 . 90 + 90.0
914As: >
915 (1 . 90) + 90.0
916That works, since the String "190" is automatically converted to the Number
917190, which can be added to the Float 90.0. However: >
918 1 . 90 * 90.0
919Should be read as: >
920 1 . (90 * 90.0)
921Since '.' has lower precedence than '*'. This does NOT work, since this
922attempts to concatenate a Float and a String.
923
924When dividing a Number by zero the result depends on the value:
925 0 / 0 = -0x80000000 (like NaN for Float)
926 >0 / 0 = 0x7fffffff (like positive infinity)
927 <0 / 0 = -0x7fffffff (like negative infinity)
928 (before Vim 7.2 it was always 0x7fffffff)
929
Bram Moolenaar22fcfad2016-07-01 18:17:26 +0200930When 64-bit Number support is enabled:
931 0 / 0 = -0x8000000000000000 (like NaN for Float)
932 >0 / 0 = 0x7fffffffffffffff (like positive infinity)
933 <0 / 0 = -0x7fffffffffffffff (like negative infinity)
934
Bram Moolenaar071d4272004-06-13 20:20:40 +0000935When the righthand side of '%' is zero, the result is 0.
936
Bram Moolenaar32466aa2006-02-24 23:53:04 +0000937None of these work for |Funcref|s.
Bram Moolenaarde8866b2005-01-06 23:24:37 +0000938
Bram Moolenaar446cb832008-06-24 21:56:24 +0000939. and % do not work for Float. *E804*
940
Bram Moolenaar071d4272004-06-13 20:20:40 +0000941
942expr7 *expr7*
943-----
944! expr7 logical NOT *expr-!*
945- expr7 unary minus *expr-unary--*
946+ expr7 unary plus *expr-unary-+*
947
Bram Moolenaare381d3d2016-07-07 14:50:41 +0200948For '!' |TRUE| becomes |FALSE|, |FALSE| becomes |TRUE| (one).
Bram Moolenaar071d4272004-06-13 20:20:40 +0000949For '-' the sign of the number is changed.
950For '+' the number is unchanged.
951
952A String will be converted to a Number first.
953
Bram Moolenaar58b85342016-08-14 19:54:54 +0200954These three can be repeated and mixed. Examples:
Bram Moolenaar071d4272004-06-13 20:20:40 +0000955 !-1 == 0
956 !!8 == 1
957 --9 == 9
958
959
960expr8 *expr8*
961-----
Bram Moolenaarfc65cab2018-08-28 22:58:02 +0200962This expression is either |expr9| or a sequence of the alternatives below,
963in any order. E.g., these are all possible:
964 expr9[expr1].name
965 expr9.name[expr1]
966 expr9(expr1, ...)[expr1].name
967
968
Bram Moolenaar32466aa2006-02-24 23:53:04 +0000969expr8[expr1] item of String or |List| *expr-[]* *E111*
Bram Moolenaar03413f42016-04-12 21:07:15 +0200970 *E909* *subscript*
Bram Moolenaar2fda12f2005-01-15 22:14:15 +0000971If expr8 is a Number or String this results in a String that contains the
972expr1'th single byte from expr8. expr8 is used as a String, expr1 as a
Bram Moolenaar50ba5262016-09-22 22:33:02 +0200973Number. This doesn't recognize multi-byte encodings, see `byteidx()` for
Bram Moolenaar03413f42016-04-12 21:07:15 +0200974an alternative, or use `split()` to turn the string into a list of characters.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000975
Bram Moolenaar256972a2015-12-29 19:10:25 +0100976Index zero gives the first byte. This is like it works in C. Careful:
977text column numbers start with one! Example, to get the byte under the
Bram Moolenaard7ee7ce2005-01-03 21:02:03 +0000978cursor: >
Bram Moolenaar61660ea2006-04-07 21:40:07 +0000979 :let c = getline(".")[col(".") - 1]
Bram Moolenaar071d4272004-06-13 20:20:40 +0000980
981If the length of the String is less than the index, the result is an empty
Bram Moolenaar85084ef2016-01-17 22:26:33 +0100982String. A negative index always results in an empty string (reason: backward
Bram Moolenaard7ee7ce2005-01-03 21:02:03 +0000983compatibility). Use [-1:] to get the last byte.
984
Bram Moolenaar32466aa2006-02-24 23:53:04 +0000985If expr8 is a |List| then it results the item at index expr1. See |list-index|
Bram Moolenaard7ee7ce2005-01-03 21:02:03 +0000986for possible index values. If the index is out of range this results in an
Bram Moolenaar58b85342016-08-14 19:54:54 +0200987error. Example: >
Bram Moolenaard7ee7ce2005-01-03 21:02:03 +0000988 :let item = mylist[-1] " get last item
989
Bram Moolenaar32466aa2006-02-24 23:53:04 +0000990Generally, if a |List| index is equal to or higher than the length of the
991|List|, or more negative than the length of the |List|, this results in an
992error.
Bram Moolenaard7ee7ce2005-01-03 21:02:03 +0000993
Bram Moolenaard8b02732005-01-14 21:48:43 +0000994
Bram Moolenaar2fda12f2005-01-15 22:14:15 +0000995expr8[expr1a : expr1b] substring or sublist *expr-[:]*
Bram Moolenaard7ee7ce2005-01-03 21:02:03 +0000996
Bram Moolenaar2fda12f2005-01-15 22:14:15 +0000997If expr8 is a Number or String this results in the substring with the bytes
998from expr1a to and including expr1b. expr8 is used as a String, expr1a and
Bram Moolenaar8f3f58f2010-01-06 20:52:26 +0100999expr1b are used as a Number. This doesn't recognize multi-byte encodings, see
1000|byteidx()| for computing the indexes.
Bram Moolenaard7ee7ce2005-01-03 21:02:03 +00001001
1002If expr1a is omitted zero is used. If expr1b is omitted the length of the
1003string minus one is used.
1004
1005A negative number can be used to measure from the end of the string. -1 is
1006the last character, -2 the last but one, etc.
1007
1008If an index goes out of range for the string characters are omitted. If
1009expr1b is smaller than expr1a the result is an empty string.
1010
1011Examples: >
1012 :let c = name[-1:] " last byte of a string
1013 :let c = name[-2:-2] " last but one byte of a string
1014 :let s = line(".")[4:] " from the fifth byte to the end
1015 :let s = s[:-3] " remove last two bytes
Bram Moolenaar8f3f58f2010-01-06 20:52:26 +01001016<
Bram Moolenaarbc8801c2016-08-02 21:04:33 +02001017 *slice*
Bram Moolenaar32466aa2006-02-24 23:53:04 +00001018If expr8 is a |List| this results in a new |List| with the items indicated by
Bram Moolenaar58b85342016-08-14 19:54:54 +02001019the indexes expr1a and expr1b. This works like with a String, as explained
Bram Moolenaarbc8801c2016-08-02 21:04:33 +02001020just above. Also see |sublist| below. Examples: >
Bram Moolenaard7ee7ce2005-01-03 21:02:03 +00001021 :let l = mylist[:3] " first four items
1022 :let l = mylist[4:4] " List with one item
1023 :let l = mylist[:] " shallow copy of a List
1024
Bram Moolenaar6e5ea8d2019-01-12 22:47:31 +01001025If expr8 is a |Blob| this results in a new |Blob| with the bytes in the
1026indexes expr1a and expr1b, inclusive. Examples: >
1027 :let b = 0zDEADBEEF
1028 :let bs = b[1:2] " 0zADBE
1029 :let bs = b[] " copy ov 0zDEADBEEF
1030
Bram Moolenaar32466aa2006-02-24 23:53:04 +00001031Using expr8[expr1] or expr8[expr1a : expr1b] on a |Funcref| results in an
1032error.
Bram Moolenaar071d4272004-06-13 20:20:40 +00001033
Bram Moolenaarda440d22016-01-16 21:27:23 +01001034Watch out for confusion between a namespace and a variable followed by a colon
1035for a sublist: >
1036 mylist[n:] " uses variable n
1037 mylist[s:] " uses namespace s:, error!
1038
Bram Moolenaard8b02732005-01-14 21:48:43 +00001039
Bram Moolenaar32466aa2006-02-24 23:53:04 +00001040expr8.name entry in a |Dictionary| *expr-entry*
Bram Moolenaard8b02732005-01-14 21:48:43 +00001041
Bram Moolenaar32466aa2006-02-24 23:53:04 +00001042If expr8 is a |Dictionary| and it is followed by a dot, then the following
1043name will be used as a key in the |Dictionary|. This is just like:
1044expr8[name].
Bram Moolenaard8b02732005-01-14 21:48:43 +00001045
1046The name must consist of alphanumeric characters, just like a variable name,
1047but it may start with a number. Curly braces cannot be used.
1048
1049There must not be white space before or after the dot.
1050
1051Examples: >
1052 :let dict = {"one": 1, 2: "two"}
1053 :echo dict.one
1054 :echo dict .2
1055
1056Note that the dot is also used for String concatenation. To avoid confusion
1057always put spaces around the dot for String concatenation.
1058
1059
Bram Moolenaar32466aa2006-02-24 23:53:04 +00001060expr8(expr1, ...) |Funcref| function call
Bram Moolenaar2fda12f2005-01-15 22:14:15 +00001061
1062When expr8 is a |Funcref| type variable, invoke the function it refers to.
1063
1064
1065
1066 *expr9*
Bram Moolenaar071d4272004-06-13 20:20:40 +00001067number
1068------
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01001069number number constant *expr-number*
Bram Moolenaar7571d552016-08-18 22:54:46 +02001070 *hex-number* *octal-number* *binary-number*
Bram Moolenaar071d4272004-06-13 20:20:40 +00001071
Bram Moolenaar7571d552016-08-18 22:54:46 +02001072Decimal, Hexadecimal (starting with 0x or 0X), Binary (starting with 0b or 0B)
1073and Octal (starting with 0).
Bram Moolenaar071d4272004-06-13 20:20:40 +00001074
Bram Moolenaar446cb832008-06-24 21:56:24 +00001075 *floating-point-format*
1076Floating point numbers can be written in two forms:
1077
1078 [-+]{N}.{M}
Bram Moolenaar8a94d872015-01-25 13:02:57 +01001079 [-+]{N}.{M}[eE][-+]{exp}
Bram Moolenaar446cb832008-06-24 21:56:24 +00001080
1081{N} and {M} are numbers. Both {N} and {M} must be present and can only
1082contain digits.
1083[-+] means there is an optional plus or minus sign.
1084{exp} is the exponent, power of 10.
Bram Moolenaar58b85342016-08-14 19:54:54 +02001085Only a decimal point is accepted, not a comma. No matter what the current
Bram Moolenaar446cb832008-06-24 21:56:24 +00001086locale is.
1087{only when compiled with the |+float| feature}
1088
1089Examples:
1090 123.456
1091 +0.0001
1092 55.0
1093 -0.123
1094 1.234e03
1095 1.0E-6
1096 -3.1416e+88
1097
1098These are INVALID:
1099 3. empty {M}
1100 1e40 missing .{M}
1101
1102Rationale:
1103Before floating point was introduced, the text "123.456" was interpreted as
1104the two numbers "123" and "456", both converted to a string and concatenated,
1105resulting in the string "123456". Since this was considered pointless, and we
Bram Moolenaare37d50a2008-08-06 17:06:04 +00001106could not find it intentionally being used in Vim scripts, this backwards
Bram Moolenaar446cb832008-06-24 21:56:24 +00001107incompatibility was accepted in favor of being able to use the normal notation
1108for floating point numbers.
1109
Bram Moolenaard47d5222018-12-09 20:43:55 +01001110 *float-pi* *float-e*
1111A few useful values to copy&paste: >
1112 :let pi = 3.14159265359
1113 :let e = 2.71828182846
1114Or, if you don't want to write them in as floating-point literals, you can
1115also use functions, like the following: >
1116 :let pi = acos(-1.0)
1117 :let e = exp(1.0)
Bram Moolenaar98aefe72018-12-13 22:20:09 +01001118<
Bram Moolenaar446cb832008-06-24 21:56:24 +00001119 *floating-point-precision*
1120The precision and range of floating points numbers depends on what "double"
1121means in the library Vim was compiled with. There is no way to change this at
1122runtime.
1123
1124The default for displaying a |Float| is to use 6 decimal places, like using
1125printf("%g", f). You can select something else when using the |printf()|
1126function. Example: >
1127 :echo printf('%.15e', atan(1))
1128< 7.853981633974483e-01
1129
1130
Bram Moolenaar071d4272004-06-13 20:20:40 +00001131
Bram Moolenaar979243b2015-06-26 19:35:49 +02001132string *string* *String* *expr-string* *E114*
Bram Moolenaar071d4272004-06-13 20:20:40 +00001133------
1134"string" string constant *expr-quote*
1135
1136Note that double quotes are used.
1137
1138A string constant accepts these special characters:
1139\... three-digit octal number (e.g., "\316")
1140\.. two-digit octal number (must be followed by non-digit)
1141\. one-digit octal number (must be followed by non-digit)
1142\x.. byte specified with two hex numbers (e.g., "\x1f")
1143\x. byte specified with one hex number (must be followed by non-hex char)
1144\X.. same as \x..
1145\X. same as \x.
Bram Moolenaar446cb832008-06-24 21:56:24 +00001146\u.... character specified with up to 4 hex numbers, stored according to the
Bram Moolenaar071d4272004-06-13 20:20:40 +00001147 current value of 'encoding' (e.g., "\u02a4")
Bram Moolenaar541f92d2015-06-19 13:27:23 +02001148\U.... same as \u but allows up to 8 hex numbers.
Bram Moolenaar071d4272004-06-13 20:20:40 +00001149\b backspace <BS>
1150\e escape <Esc>
1151\f formfeed <FF>
1152\n newline <NL>
1153\r return <CR>
1154\t tab <Tab>
1155\\ backslash
1156\" double quote
Bram Moolenaar00a927d2010-05-14 23:24:24 +02001157\<xxx> Special key named "xxx". e.g. "\<C-W>" for CTRL-W. This is for use
Bram Moolenaar58b85342016-08-14 19:54:54 +02001158 in mappings, the 0x80 byte is escaped.
1159 To use the double quote character it must be escaped: "<M-\">".
1160 Don't use <Char-xxxx> to get a utf-8 character, use \uxxxx as
1161 mentioned above.
Bram Moolenaar071d4272004-06-13 20:20:40 +00001162
Bram Moolenaaref2f6562007-05-06 13:32:59 +00001163Note that "\xff" is stored as the byte 255, which may be invalid in some
1164encodings. Use "\u00ff" to store character 255 according to the current value
1165of 'encoding'.
1166
Bram Moolenaar071d4272004-06-13 20:20:40 +00001167Note that "\000" and "\x00" force the end of the string.
1168
1169
Bram Moolenaar6e5ea8d2019-01-12 22:47:31 +01001170blob-literal *blob-literal* *E973* *E977* *E978*
1171------------
1172
1173Hexadecimal starting with 0z or 0Z, with an arbitrary number of bytes.
1174The sequence must be an even number of hex characters. Example: >
1175 :let b = 0zFF00ED015DAF
1176
1177
Bram Moolenaar071d4272004-06-13 20:20:40 +00001178literal-string *literal-string* *E115*
1179---------------
Bram Moolenaar3fdfa4a2004-10-07 21:02:47 +00001180'string' string constant *expr-'*
Bram Moolenaar071d4272004-06-13 20:20:40 +00001181
1182Note that single quotes are used.
1183
Bram Moolenaar58b85342016-08-14 19:54:54 +02001184This string is taken as it is. No backslashes are removed or have a special
Bram Moolenaard8b02732005-01-14 21:48:43 +00001185meaning. The only exception is that two quotes stand for one quote.
Bram Moolenaar3fdfa4a2004-10-07 21:02:47 +00001186
1187Single quoted strings are useful for patterns, so that backslashes do not need
Bram Moolenaar58b85342016-08-14 19:54:54 +02001188to be doubled. These two commands are equivalent: >
Bram Moolenaar3fdfa4a2004-10-07 21:02:47 +00001189 if a =~ "\\s*"
1190 if a =~ '\s*'
Bram Moolenaar071d4272004-06-13 20:20:40 +00001191
1192
1193option *expr-option* *E112* *E113*
1194------
1195&option option value, local value if possible
1196&g:option global option value
1197&l:option local option value
1198
1199Examples: >
1200 echo "tabstop is " . &tabstop
1201 if &insertmode
1202
1203Any option name can be used here. See |options|. When using the local value
1204and there is no buffer-local or window-local value, the global value is used
1205anyway.
1206
1207
Bram Moolenaaref2f6562007-05-06 13:32:59 +00001208register *expr-register* *@r*
Bram Moolenaar071d4272004-06-13 20:20:40 +00001209--------
1210@r contents of register 'r'
1211
1212The result is the contents of the named register, as a single string.
1213Newlines are inserted where required. To get the contents of the unnamed
Bram Moolenaar58b85342016-08-14 19:54:54 +02001214register use @" or @@. See |registers| for an explanation of the available
Bram Moolenaare7566042005-06-17 22:00:15 +00001215registers.
1216
1217When using the '=' register you get the expression itself, not what it
1218evaluates to. Use |eval()| to evaluate it.
Bram Moolenaar071d4272004-06-13 20:20:40 +00001219
1220
1221nesting *expr-nesting* *E110*
1222-------
1223(expr1) nested expression
1224
1225
1226environment variable *expr-env*
1227--------------------
1228$VAR environment variable
1229
1230The String value of any environment variable. When it is not defined, the
1231result is an empty string.
1232 *expr-env-expand*
1233Note that there is a difference between using $VAR directly and using
1234expand("$VAR"). Using it directly will only expand environment variables that
1235are known inside the current Vim session. Using expand() will first try using
1236the environment variables known inside the current Vim session. If that
1237fails, a shell will be used to expand the variable. This can be slow, but it
1238does expand all variables that the shell knows about. Example: >
Bram Moolenaar34401cc2014-08-29 15:12:19 +02001239 :echo $shell
1240 :echo expand("$shell")
1241The first one probably doesn't echo anything, the second echoes the $shell
Bram Moolenaar071d4272004-06-13 20:20:40 +00001242variable (if your shell supports it).
1243
1244
1245internal variable *expr-variable*
1246-----------------
1247variable internal variable
1248See below |internal-variables|.
1249
1250
Bram Moolenaar05159a02005-02-26 23:04:13 +00001251function call *expr-function* *E116* *E118* *E119* *E120*
Bram Moolenaar071d4272004-06-13 20:20:40 +00001252-------------
1253function(expr1, ...) function call
1254See below |functions|.
1255
1256
Bram Moolenaar069c1e72016-07-15 21:25:08 +02001257lambda expression *expr-lambda* *lambda*
1258-----------------
1259{args -> expr1} lambda expression
1260
1261A lambda expression creates a new unnamed function which returns the result of
Bram Moolenaar42ebd062016-07-17 13:35:14 +02001262evaluating |expr1|. Lambda expressions differ from |user-functions| in
Bram Moolenaar069c1e72016-07-15 21:25:08 +02001263the following ways:
1264
12651. The body of the lambda expression is an |expr1| and not a sequence of |Ex|
1266 commands.
Bram Moolenaar1e96d9b2016-07-29 22:15:09 +020012672. The prefix "a:" should not be used for arguments. E.g.: >
Bram Moolenaar069c1e72016-07-15 21:25:08 +02001268 :let F = {arg1, arg2 -> arg1 - arg2}
1269 :echo F(5, 2)
1270< 3
1271
1272The arguments are optional. Example: >
1273 :let F = {-> 'error function'}
1274 :echo F()
1275< error function
Bram Moolenaar1e96d9b2016-07-29 22:15:09 +02001276 *closure*
1277Lambda expressions can access outer scope variables and arguments. This is
Bram Moolenaar50ba5262016-09-22 22:33:02 +02001278often called a closure. Example where "i" and "a:arg" are used in a lambda
Bram Moolenaar6bb2cdf2018-02-24 19:53:53 +01001279while they already exist in the function scope. They remain valid even after
1280the function returns: >
Bram Moolenaar1e96d9b2016-07-29 22:15:09 +02001281 :function Foo(arg)
1282 : let i = 3
1283 : return {x -> x + i - a:arg}
1284 :endfunction
1285 :let Bar = Foo(4)
1286 :echo Bar(6)
1287< 5
Bram Moolenaar437bafe2016-08-01 15:40:54 +02001288
Bram Moolenaar6bb2cdf2018-02-24 19:53:53 +01001289Note that the variables must exist in the outer scope before the lamba is
1290defined for this to work. See also |:func-closure|.
1291
1292Lambda and closure support can be checked with: >
Bram Moolenaar437bafe2016-08-01 15:40:54 +02001293 if has('lambda')
Bram Moolenaar069c1e72016-07-15 21:25:08 +02001294
1295Examples for using a lambda expression with |sort()|, |map()| and |filter()|: >
1296 :echo map([1, 2, 3], {idx, val -> val + 1})
1297< [2, 3, 4] >
1298 :echo sort([3,7,2,1,4], {a, b -> a - b})
1299< [1, 2, 3, 4, 7]
1300
1301The lambda expression is also useful for Channel, Job and timer: >
1302 :let timer = timer_start(500,
1303 \ {-> execute("echo 'Handler called'", "")},
1304 \ {'repeat': 3})
1305< Handler called
1306 Handler called
1307 Handler called
1308
1309Note how execute() is used to execute an Ex command. That's ugly though.
1310
Bram Moolenaar1e96d9b2016-07-29 22:15:09 +02001311
1312Lambda expressions have internal names like '<lambda>42'. If you get an error
1313for a lambda expression, you can find what it is with the following command: >
1314 :function {'<lambda>42'}
1315See also: |numbered-function|
1316
Bram Moolenaar071d4272004-06-13 20:20:40 +00001317==============================================================================
Bram Moolenaar4a748032010-09-30 21:47:56 +020013183. Internal variable *internal-variables* *E461*
1319
Bram Moolenaar071d4272004-06-13 20:20:40 +00001320An internal variable name can be made up of letters, digits and '_'. But it
1321cannot start with a digit. It's also possible to use curly braces, see
1322|curly-braces-names|.
1323
1324An internal variable is created with the ":let" command |:let|.
Bram Moolenaar9588a0f2005-01-08 21:45:39 +00001325An internal variable is explicitly destroyed with the ":unlet" command
1326|:unlet|.
1327Using a name that is not an internal variable or refers to a variable that has
1328been destroyed results in an error.
Bram Moolenaar071d4272004-06-13 20:20:40 +00001329
1330There are several name spaces for variables. Which one is to be used is
1331specified by what is prepended:
1332
1333 (nothing) In a function: local to a function; otherwise: global
1334|buffer-variable| b: Local to the current buffer.
1335|window-variable| w: Local to the current window.
Bram Moolenaar910f66f2006-04-05 20:41:53 +00001336|tabpage-variable| t: Local to the current tab page.
Bram Moolenaar071d4272004-06-13 20:20:40 +00001337|global-variable| g: Global.
1338|local-variable| l: Local to a function.
1339|script-variable| s: Local to a |:source|'ed Vim script.
1340|function-argument| a: Function argument (only inside a function).
Bram Moolenaar75b81562014-04-06 14:09:13 +02001341|vim-variable| v: Global, predefined by Vim.
Bram Moolenaar071d4272004-06-13 20:20:40 +00001342
Bram Moolenaar32466aa2006-02-24 23:53:04 +00001343The scope name by itself can be used as a |Dictionary|. For example, to
1344delete all script-local variables: >
Bram Moolenaar8f999f12005-01-25 22:12:55 +00001345 :for k in keys(s:)
1346 : unlet s:[k]
1347 :endfor
1348<
Bram Moolenaar531da592013-05-06 05:58:55 +02001349 *buffer-variable* *b:var* *b:*
Bram Moolenaar071d4272004-06-13 20:20:40 +00001350A variable name that is preceded with "b:" is local to the current buffer.
1351Thus you can have several "b:foo" variables, one for each buffer.
1352This kind of variable is deleted when the buffer is wiped out or deleted with
1353|:bdelete|.
1354
1355One local buffer variable is predefined:
Bram Moolenaarbf884932013-04-05 22:26:15 +02001356 *b:changedtick* *changetick*
Bram Moolenaar071d4272004-06-13 20:20:40 +00001357b:changedtick The total number of changes to the current buffer. It is
1358 incremented for each change. An undo command is also a change
1359 in this case. This can be used to perform an action only when
1360 the buffer has changed. Example: >
1361 :if my_changedtick != b:changedtick
Bram Moolenaar446cb832008-06-24 21:56:24 +00001362 : let my_changedtick = b:changedtick
1363 : call My_Update()
Bram Moolenaar071d4272004-06-13 20:20:40 +00001364 :endif
Bram Moolenaar3df01732017-02-17 22:47:16 +01001365< You cannot change or delete the b:changedtick variable.
1366
Bram Moolenaar531da592013-05-06 05:58:55 +02001367 *window-variable* *w:var* *w:*
Bram Moolenaar071d4272004-06-13 20:20:40 +00001368A variable name that is preceded with "w:" is local to the current window. It
1369is deleted when the window is closed.
1370
Bram Moolenaarad3b3662013-05-17 18:14:19 +02001371 *tabpage-variable* *t:var* *t:*
Bram Moolenaar910f66f2006-04-05 20:41:53 +00001372A variable name that is preceded with "t:" is local to the current tab page,
1373It is deleted when the tab page is closed. {not available when compiled
Bram Moolenaardb84e452010-08-15 13:50:43 +02001374without the |+windows| feature}
Bram Moolenaar910f66f2006-04-05 20:41:53 +00001375
Bram Moolenaar531da592013-05-06 05:58:55 +02001376 *global-variable* *g:var* *g:*
Bram Moolenaar071d4272004-06-13 20:20:40 +00001377Inside functions global variables are accessed with "g:". Omitting this will
Bram Moolenaar58b85342016-08-14 19:54:54 +02001378access a variable local to a function. But "g:" can also be used in any other
Bram Moolenaar071d4272004-06-13 20:20:40 +00001379place if you like.
1380
Bram Moolenaar531da592013-05-06 05:58:55 +02001381 *local-variable* *l:var* *l:*
Bram Moolenaar071d4272004-06-13 20:20:40 +00001382Inside functions local variables are accessed without prepending anything.
Bram Moolenaaref2f6562007-05-06 13:32:59 +00001383But you can also prepend "l:" if you like. However, without prepending "l:"
1384you may run into reserved variable names. For example "count". By itself it
1385refers to "v:count". Using "l:count" you can have a local variable with the
1386same name.
Bram Moolenaar071d4272004-06-13 20:20:40 +00001387
1388 *script-variable* *s:var*
1389In a Vim script variables starting with "s:" can be used. They cannot be
1390accessed from outside of the scripts, thus are local to the script.
1391
1392They can be used in:
1393- commands executed while the script is sourced
1394- functions defined in the script
1395- autocommands defined in the script
1396- functions and autocommands defined in functions and autocommands which were
1397 defined in the script (recursively)
1398- user defined commands defined in the script
1399Thus not in:
1400- other scripts sourced from this one
1401- mappings
Bram Moolenaar8f3f58f2010-01-06 20:52:26 +01001402- menus
Bram Moolenaar071d4272004-06-13 20:20:40 +00001403- etc.
1404
Bram Moolenaaref2f6562007-05-06 13:32:59 +00001405Script variables can be used to avoid conflicts with global variable names.
1406Take this example: >
Bram Moolenaar071d4272004-06-13 20:20:40 +00001407
1408 let s:counter = 0
1409 function MyCounter()
1410 let s:counter = s:counter + 1
1411 echo s:counter
1412 endfunction
1413 command Tick call MyCounter()
1414
1415You can now invoke "Tick" from any script, and the "s:counter" variable in
1416that script will not be changed, only the "s:counter" in the script where
1417"Tick" was defined is used.
1418
1419Another example that does the same: >
1420
1421 let s:counter = 0
1422 command Tick let s:counter = s:counter + 1 | echo s:counter
1423
1424When calling a function and invoking a user-defined command, the context for
Bram Moolenaar69a7cb42004-06-20 12:51:53 +00001425script variables is set to the script where the function or command was
Bram Moolenaar071d4272004-06-13 20:20:40 +00001426defined.
1427
1428The script variables are also available when a function is defined inside a
1429function that is defined in a script. Example: >
1430
1431 let s:counter = 0
1432 function StartCounting(incr)
1433 if a:incr
1434 function MyCounter()
1435 let s:counter = s:counter + 1
1436 endfunction
1437 else
1438 function MyCounter()
1439 let s:counter = s:counter - 1
1440 endfunction
1441 endif
1442 endfunction
1443
1444This defines the MyCounter() function either for counting up or counting down
1445when calling StartCounting(). It doesn't matter from where StartCounting() is
1446called, the s:counter variable will be accessible in MyCounter().
1447
1448When the same script is sourced again it will use the same script variables.
1449They will remain valid as long as Vim is running. This can be used to
1450maintain a counter: >
1451
1452 if !exists("s:counter")
1453 let s:counter = 1
1454 echo "script executed for the first time"
1455 else
1456 let s:counter = s:counter + 1
1457 echo "script executed " . s:counter . " times now"
1458 endif
1459
1460Note that this means that filetype plugins don't get a different set of script
1461variables for each buffer. Use local buffer variables instead |b:var|.
1462
1463
Bram Moolenaard47d5222018-12-09 20:43:55 +01001464PREDEFINED VIM VARIABLES *vim-variable* *v:var* *v:*
1465 *E963*
1466Some variables can be set by the user, but the type cannot be changed.
Bram Moolenaar071d4272004-06-13 20:20:40 +00001467
Bram Moolenaare4efc3b2005-03-07 23:16:51 +00001468 *v:beval_col* *beval_col-variable*
1469v:beval_col The number of the column, over which the mouse pointer is.
1470 This is the byte index in the |v:beval_lnum| line.
1471 Only valid while evaluating the 'balloonexpr' option.
1472
1473 *v:beval_bufnr* *beval_bufnr-variable*
1474v:beval_bufnr The number of the buffer, over which the mouse pointer is. Only
1475 valid while evaluating the 'balloonexpr' option.
1476
1477 *v:beval_lnum* *beval_lnum-variable*
1478v:beval_lnum The number of the line, over which the mouse pointer is. Only
1479 valid while evaluating the 'balloonexpr' option.
1480
1481 *v:beval_text* *beval_text-variable*
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00001482v:beval_text The text under or after the mouse pointer. Usually a word as
1483 it is useful for debugging a C program. 'iskeyword' applies,
1484 but a dot and "->" before the position is included. When on a
1485 ']' the text before it is used, including the matching '[' and
Bram Moolenaare4efc3b2005-03-07 23:16:51 +00001486 word before it. When on a Visual area within one line the
Bram Moolenaarb4d5fba2017-09-11 19:31:28 +02001487 highlighted text is used. Also see |<cexpr>|.
Bram Moolenaare4efc3b2005-03-07 23:16:51 +00001488 Only valid while evaluating the 'balloonexpr' option.
1489
1490 *v:beval_winnr* *beval_winnr-variable*
1491v:beval_winnr The number of the window, over which the mouse pointer is. Only
Bram Moolenaar00654022011-02-25 14:42:19 +01001492 valid while evaluating the 'balloonexpr' option. The first
1493 window has number zero (unlike most other places where a
1494 window gets a number).
Bram Moolenaare4efc3b2005-03-07 23:16:51 +00001495
Bram Moolenaar511972d2016-06-04 18:09:59 +02001496 *v:beval_winid* *beval_winid-variable*
Bram Moolenaar7571d552016-08-18 22:54:46 +02001497v:beval_winid The |window-ID| of the window, over which the mouse pointer
1498 is. Otherwise like v:beval_winnr.
Bram Moolenaar511972d2016-06-04 18:09:59 +02001499
Bram Moolenaarf193fff2006-04-27 00:02:13 +00001500 *v:char* *char-variable*
Bram Moolenaar8f3f58f2010-01-06 20:52:26 +01001501v:char Argument for evaluating 'formatexpr' and used for the typed
Bram Moolenaar945e2db2010-06-05 17:43:32 +02001502 character when using <expr> in an abbreviation |:map-<expr>|.
Bram Moolenaare6ae6222013-05-21 21:01:10 +02001503 It is also used by the |InsertCharPre| and |InsertEnter| events.
Bram Moolenaarf193fff2006-04-27 00:02:13 +00001504
Bram Moolenaar071d4272004-06-13 20:20:40 +00001505 *v:charconvert_from* *charconvert_from-variable*
1506v:charconvert_from
1507 The name of the character encoding of a file to be converted.
1508 Only valid while evaluating the 'charconvert' option.
1509
1510 *v:charconvert_to* *charconvert_to-variable*
1511v:charconvert_to
1512 The name of the character encoding of a file after conversion.
1513 Only valid while evaluating the 'charconvert' option.
1514
1515 *v:cmdarg* *cmdarg-variable*
1516v:cmdarg This variable is used for two purposes:
1517 1. The extra arguments given to a file read/write command.
1518 Currently these are "++enc=" and "++ff=". This variable is
1519 set before an autocommand event for a file read/write
1520 command is triggered. There is a leading space to make it
1521 possible to append this variable directly after the
Bram Moolenaar58b85342016-08-14 19:54:54 +02001522 read/write command. Note: The "+cmd" argument isn't
Bram Moolenaar071d4272004-06-13 20:20:40 +00001523 included here, because it will be executed anyway.
1524 2. When printing a PostScript file with ":hardcopy" this is
1525 the argument for the ":hardcopy" command. This can be used
1526 in 'printexpr'.
1527
1528 *v:cmdbang* *cmdbang-variable*
1529v:cmdbang Set like v:cmdarg for a file read/write command. When a "!"
1530 was used the value is 1, otherwise it is 0. Note that this
1531 can only be used in autocommands. For user commands |<bang>|
1532 can be used.
1533
Bram Moolenaar42a45122015-07-10 17:56:23 +02001534 *v:completed_item* *completed_item-variable*
1535v:completed_item
1536 |Dictionary| containing the |complete-items| for the most
1537 recently completed word after |CompleteDone|. The
1538 |Dictionary| is empty if the completion failed.
1539
Bram Moolenaar071d4272004-06-13 20:20:40 +00001540 *v:count* *count-variable*
1541v:count The count given for the last Normal mode command. Can be used
Bram Moolenaar58b85342016-08-14 19:54:54 +02001542 to get the count before a mapping. Read-only. Example: >
Bram Moolenaar071d4272004-06-13 20:20:40 +00001543 :map _x :<C-U>echo "the count is " . v:count<CR>
1544< Note: The <C-U> is required to remove the line range that you
1545 get when typing ':' after a count.
Bram Moolenaar8f3f58f2010-01-06 20:52:26 +01001546 When there are two counts, as in "3d2w", they are multiplied,
1547 just like what happens in the command, "d6w" for the example.
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00001548 Also used for evaluating the 'formatexpr' option.
Bram Moolenaar071d4272004-06-13 20:20:40 +00001549 "count" also works, for backwards compatibility.
1550
1551 *v:count1* *count1-variable*
1552v:count1 Just like "v:count", but defaults to one when no count is
1553 used.
1554
1555 *v:ctype* *ctype-variable*
1556v:ctype The current locale setting for characters of the runtime
1557 environment. This allows Vim scripts to be aware of the
1558 current locale encoding. Technical: it's the value of
1559 LC_CTYPE. When not using a locale the value is "C".
1560 This variable can not be set directly, use the |:language|
1561 command.
1562 See |multi-lang|.
1563
1564 *v:dying* *dying-variable*
Bram Moolenaar58b85342016-08-14 19:54:54 +02001565v:dying Normally zero. When a deadly signal is caught it's set to
Bram Moolenaar071d4272004-06-13 20:20:40 +00001566 one. When multiple signals are caught the number increases.
1567 Can be used in an autocommand to check if Vim didn't
1568 terminate normally. {only works on Unix}
1569 Example: >
1570 :au VimLeave * if v:dying | echo "\nAAAAaaaarrrggghhhh!!!\n" | endif
Bram Moolenaar0e1e25f2010-05-28 21:07:08 +02001571< Note: if another deadly signal is caught when v:dying is one,
1572 VimLeave autocommands will not be executed.
1573
Bram Moolenaar071d4272004-06-13 20:20:40 +00001574 *v:errmsg* *errmsg-variable*
1575v:errmsg Last given error message. It's allowed to set this variable.
1576 Example: >
1577 :let v:errmsg = ""
1578 :silent! next
1579 :if v:errmsg != ""
1580 : ... handle error
1581< "errmsg" also works, for backwards compatibility.
1582
Bram Moolenaar65a54642018-04-28 16:56:53 +02001583 *v:errors* *errors-variable* *assert-return*
Bram Moolenaar683fa182015-11-30 21:38:24 +01001584v:errors Errors found by assert functions, such as |assert_true()|.
Bram Moolenaar43345542015-11-29 17:35:35 +01001585 This is a list of strings.
1586 The assert functions append an item when an assert fails.
Bram Moolenaar65a54642018-04-28 16:56:53 +02001587 The return value indicates this: a one is returned if an item
1588 was added to v:errors, otherwise zero is returned.
Bram Moolenaar43345542015-11-29 17:35:35 +01001589 To remove old results make it empty: >
1590 :let v:errors = []
1591< If v:errors is set to anything but a list it is made an empty
1592 list by the assert function.
1593
Bram Moolenaar7e1652c2017-12-16 18:27:02 +01001594 *v:event* *event-variable*
1595v:event Dictionary containing information about the current
1596 |autocommand|. The dictionary is emptied when the |autocommand|
1597 finishes, please refer to |dict-identity| for how to get an
1598 independent copy of it.
1599
Bram Moolenaar071d4272004-06-13 20:20:40 +00001600 *v:exception* *exception-variable*
1601v:exception The value of the exception most recently caught and not
1602 finished. See also |v:throwpoint| and |throw-variables|.
1603 Example: >
1604 :try
1605 : throw "oops"
1606 :catch /.*/
1607 : echo "caught" v:exception
1608 :endtry
1609< Output: "caught oops".
1610
Bram Moolenaar520e1e42016-01-23 19:46:28 +01001611 *v:false* *false-variable*
1612v:false A Number with value zero. Used to put "false" in JSON. See
Bram Moolenaar6463ca22016-02-13 17:04:46 +01001613 |json_encode()|.
Bram Moolenaarc95a3022016-06-12 23:01:46 +02001614 When used as a string this evaluates to "v:false". >
Bram Moolenaar705ada12016-01-24 17:56:50 +01001615 echo v:false
Bram Moolenaarc95a3022016-06-12 23:01:46 +02001616< v:false ~
1617 That is so that eval() can parse the string back to the same
Bram Moolenaardf48fb42016-07-22 21:50:18 +02001618 value. Read-only.
Bram Moolenaar520e1e42016-01-23 19:46:28 +01001619
Bram Moolenaar19a09a12005-03-04 23:39:37 +00001620 *v:fcs_reason* *fcs_reason-variable*
1621v:fcs_reason The reason why the |FileChangedShell| event was triggered.
1622 Can be used in an autocommand to decide what to do and/or what
1623 to set v:fcs_choice to. Possible values:
1624 deleted file no longer exists
1625 conflict file contents, mode or timestamp was
1626 changed and buffer is modified
1627 changed file contents has changed
1628 mode mode of file changed
1629 time only file timestamp changed
1630
1631 *v:fcs_choice* *fcs_choice-variable*
1632v:fcs_choice What should happen after a |FileChangedShell| event was
1633 triggered. Can be used in an autocommand to tell Vim what to
1634 do with the affected buffer:
1635 reload Reload the buffer (does not work if
1636 the file was deleted).
1637 ask Ask the user what to do, as if there
1638 was no autocommand. Except that when
1639 only the timestamp changed nothing
1640 will happen.
1641 <empty> Nothing, the autocommand should do
1642 everything that needs to be done.
1643 The default is empty. If another (invalid) value is used then
1644 Vim behaves like it is empty, there is no warning message.
1645
Bram Moolenaar071d4272004-06-13 20:20:40 +00001646 *v:fname_in* *fname_in-variable*
Bram Moolenaar4e330bb2005-12-07 21:04:31 +00001647v:fname_in The name of the input file. Valid while evaluating:
Bram Moolenaar071d4272004-06-13 20:20:40 +00001648 option used for ~
1649 'charconvert' file to be converted
1650 'diffexpr' original file
1651 'patchexpr' original file
1652 'printexpr' file to be printed
Bram Moolenaar2c7a29c2005-12-12 22:02:31 +00001653 And set to the swap file name for |SwapExists|.
Bram Moolenaar071d4272004-06-13 20:20:40 +00001654
1655 *v:fname_out* *fname_out-variable*
1656v:fname_out The name of the output file. Only valid while
1657 evaluating:
1658 option used for ~
1659 'charconvert' resulting converted file (*)
1660 'diffexpr' output of diff
1661 'patchexpr' resulting patched file
1662 (*) When doing conversion for a write command (e.g., ":w
Bram Moolenaar58b85342016-08-14 19:54:54 +02001663 file") it will be equal to v:fname_in. When doing conversion
Bram Moolenaar071d4272004-06-13 20:20:40 +00001664 for a read command (e.g., ":e file") it will be a temporary
1665 file and different from v:fname_in.
1666
1667 *v:fname_new* *fname_new-variable*
1668v:fname_new The name of the new version of the file. Only valid while
1669 evaluating 'diffexpr'.
1670
1671 *v:fname_diff* *fname_diff-variable*
1672v:fname_diff The name of the diff (patch) file. Only valid while
1673 evaluating 'patchexpr'.
1674
1675 *v:folddashes* *folddashes-variable*
1676v:folddashes Used for 'foldtext': dashes representing foldlevel of a closed
1677 fold.
Bram Moolenaar7b0294c2004-10-11 10:16:09 +00001678 Read-only in the |sandbox|. |fold-foldtext|
Bram Moolenaar071d4272004-06-13 20:20:40 +00001679
1680 *v:foldlevel* *foldlevel-variable*
1681v:foldlevel Used for 'foldtext': foldlevel of closed fold.
Bram Moolenaar7b0294c2004-10-11 10:16:09 +00001682 Read-only in the |sandbox|. |fold-foldtext|
Bram Moolenaar071d4272004-06-13 20:20:40 +00001683
1684 *v:foldend* *foldend-variable*
1685v:foldend Used for 'foldtext': last line of closed fold.
Bram Moolenaar7b0294c2004-10-11 10:16:09 +00001686 Read-only in the |sandbox|. |fold-foldtext|
Bram Moolenaar071d4272004-06-13 20:20:40 +00001687
1688 *v:foldstart* *foldstart-variable*
1689v:foldstart Used for 'foldtext': first line of closed fold.
Bram Moolenaar7b0294c2004-10-11 10:16:09 +00001690 Read-only in the |sandbox|. |fold-foldtext|
Bram Moolenaar071d4272004-06-13 20:20:40 +00001691
Bram Moolenaar817a8802013-11-09 01:44:43 +01001692 *v:hlsearch* *hlsearch-variable*
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01001693v:hlsearch Variable that indicates whether search highlighting is on.
Bram Moolenaar76440e22014-11-27 19:14:49 +01001694 Setting it makes sense only if 'hlsearch' is enabled which
1695 requires |+extra_search|. Setting this variable to zero acts
Bram Moolenaar705ada12016-01-24 17:56:50 +01001696 like the |:nohlsearch| command, setting it to one acts like >
Bram Moolenaar817a8802013-11-09 01:44:43 +01001697 let &hlsearch = &hlsearch
Bram Moolenaar86ae7202015-07-10 19:31:35 +02001698< Note that the value is restored when returning from a
1699 function. |function-search-undo|.
1700
Bram Moolenaar843ee412004-06-30 16:16:41 +00001701 *v:insertmode* *insertmode-variable*
1702v:insertmode Used for the |InsertEnter| and |InsertChange| autocommand
1703 events. Values:
1704 i Insert mode
1705 r Replace mode
1706 v Virtual Replace mode
1707
Bram Moolenaar2fda12f2005-01-15 22:14:15 +00001708 *v:key* *key-variable*
Bram Moolenaar32466aa2006-02-24 23:53:04 +00001709v:key Key of the current item of a |Dictionary|. Only valid while
Bram Moolenaar2fda12f2005-01-15 22:14:15 +00001710 evaluating the expression used with |map()| and |filter()|.
1711 Read-only.
1712
Bram Moolenaar071d4272004-06-13 20:20:40 +00001713 *v:lang* *lang-variable*
1714v:lang The current locale setting for messages of the runtime
1715 environment. This allows Vim scripts to be aware of the
1716 current language. Technical: it's the value of LC_MESSAGES.
1717 The value is system dependent.
1718 This variable can not be set directly, use the |:language|
1719 command.
1720 It can be different from |v:ctype| when messages are desired
1721 in a different language than what is used for character
1722 encoding. See |multi-lang|.
1723
1724 *v:lc_time* *lc_time-variable*
1725v:lc_time The current locale setting for time messages of the runtime
1726 environment. This allows Vim scripts to be aware of the
1727 current language. Technical: it's the value of LC_TIME.
1728 This variable can not be set directly, use the |:language|
1729 command. See |multi-lang|.
1730
1731 *v:lnum* *lnum-variable*
Bram Moolenaar368373e2010-07-19 20:46:22 +02001732v:lnum Line number for the 'foldexpr' |fold-expr|, 'formatexpr' and
1733 'indentexpr' expressions, tab page number for 'guitablabel'
1734 and 'guitabtooltip'. Only valid while one of these
1735 expressions is being evaluated. Read-only when in the
1736 |sandbox|.
Bram Moolenaar071d4272004-06-13 20:20:40 +00001737
Bram Moolenaar219b8702006-11-01 14:32:36 +00001738 *v:mouse_win* *mouse_win-variable*
1739v:mouse_win Window number for a mouse click obtained with |getchar()|.
1740 First window has number 1, like with |winnr()|. The value is
1741 zero when there was no mouse button click.
1742
Bram Moolenaar511972d2016-06-04 18:09:59 +02001743 *v:mouse_winid* *mouse_winid-variable*
1744v:mouse_winid Window ID for a mouse click obtained with |getchar()|.
1745 The value is zero when there was no mouse button click.
1746
Bram Moolenaar219b8702006-11-01 14:32:36 +00001747 *v:mouse_lnum* *mouse_lnum-variable*
1748v:mouse_lnum Line number for a mouse click obtained with |getchar()|.
1749 This is the text line number, not the screen line number. The
1750 value is zero when there was no mouse button click.
1751
1752 *v:mouse_col* *mouse_col-variable*
1753v:mouse_col Column number for a mouse click obtained with |getchar()|.
1754 This is the screen column number, like with |virtcol()|. The
1755 value is zero when there was no mouse button click.
1756
Bram Moolenaar520e1e42016-01-23 19:46:28 +01001757 *v:none* *none-variable*
1758v:none An empty String. Used to put an empty item in JSON. See
Bram Moolenaar6463ca22016-02-13 17:04:46 +01001759 |json_encode()|.
Bram Moolenaar705ada12016-01-24 17:56:50 +01001760 When used as a number this evaluates to zero.
Bram Moolenaarc95a3022016-06-12 23:01:46 +02001761 When used as a string this evaluates to "v:none". >
Bram Moolenaar705ada12016-01-24 17:56:50 +01001762 echo v:none
Bram Moolenaarc95a3022016-06-12 23:01:46 +02001763< v:none ~
1764 That is so that eval() can parse the string back to the same
Bram Moolenaardf48fb42016-07-22 21:50:18 +02001765 value. Read-only.
Bram Moolenaar520e1e42016-01-23 19:46:28 +01001766
1767 *v:null* *null-variable*
1768v:null An empty String. Used to put "null" in JSON. See
Bram Moolenaar6463ca22016-02-13 17:04:46 +01001769 |json_encode()|.
Bram Moolenaar705ada12016-01-24 17:56:50 +01001770 When used as a number this evaluates to zero.
Bram Moolenaarc95a3022016-06-12 23:01:46 +02001771 When used as a string this evaluates to "v:null". >
Bram Moolenaar705ada12016-01-24 17:56:50 +01001772 echo v:null
Bram Moolenaarc95a3022016-06-12 23:01:46 +02001773< v:null ~
1774 That is so that eval() can parse the string back to the same
Bram Moolenaardf48fb42016-07-22 21:50:18 +02001775 value. Read-only.
Bram Moolenaar520e1e42016-01-23 19:46:28 +01001776
Bram Moolenaard812df62008-11-09 12:46:09 +00001777 *v:oldfiles* *oldfiles-variable*
1778v:oldfiles List of file names that is loaded from the |viminfo| file on
1779 startup. These are the files that Vim remembers marks for.
1780 The length of the List is limited by the ' argument of the
1781 'viminfo' option (default is 100).
Bram Moolenaar8d043172014-01-23 14:24:41 +01001782 When the |viminfo| file is not used the List is empty.
Bram Moolenaard812df62008-11-09 12:46:09 +00001783 Also see |:oldfiles| and |c_#<|.
1784 The List can be modified, but this has no effect on what is
1785 stored in the |viminfo| file later. If you use values other
1786 than String this will cause trouble.
Bram Moolenaardb84e452010-08-15 13:50:43 +02001787 {only when compiled with the |+viminfo| feature}
Bram Moolenaard812df62008-11-09 12:46:09 +00001788
Bram Moolenaar53744302015-07-17 17:38:22 +02001789 *v:option_new*
1790v:option_new New value of the option. Valid while executing an |OptionSet|
1791 autocommand.
1792 *v:option_old*
1793v:option_old Old value of the option. Valid while executing an |OptionSet|
1794 autocommand.
1795 *v:option_type*
1796v:option_type Scope of the set command. Valid while executing an
1797 |OptionSet| autocommand. Can be either "global" or "local"
Bram Moolenaar8af1fbf2008-01-05 12:35:21 +00001798 *v:operator* *operator-variable*
1799v:operator The last operator given in Normal mode. This is a single
1800 character except for commands starting with <g> or <z>,
1801 in which case it is two characters. Best used alongside
1802 |v:prevcount| and |v:register|. Useful if you want to cancel
1803 Operator-pending mode and then use the operator, e.g.: >
1804 :omap O <Esc>:call MyMotion(v:operator)<CR>
1805< The value remains set until another operator is entered, thus
1806 don't expect it to be empty.
1807 v:operator is not set for |:delete|, |:yank| or other Ex
1808 commands.
1809 Read-only.
1810
Bram Moolenaar071d4272004-06-13 20:20:40 +00001811 *v:prevcount* *prevcount-variable*
1812v:prevcount The count given for the last but one Normal mode command.
1813 This is the v:count value of the previous command. Useful if
Bram Moolenaar8af1fbf2008-01-05 12:35:21 +00001814 you want to cancel Visual or Operator-pending mode and then
1815 use the count, e.g.: >
Bram Moolenaar071d4272004-06-13 20:20:40 +00001816 :vmap % <Esc>:call MyFilter(v:prevcount)<CR>
1817< Read-only.
1818
Bram Moolenaar05159a02005-02-26 23:04:13 +00001819 *v:profiling* *profiling-variable*
Bram Moolenaar58b85342016-08-14 19:54:54 +02001820v:profiling Normally zero. Set to one after using ":profile start".
Bram Moolenaar05159a02005-02-26 23:04:13 +00001821 See |profiling|.
1822
Bram Moolenaar071d4272004-06-13 20:20:40 +00001823 *v:progname* *progname-variable*
1824v:progname Contains the name (with path removed) with which Vim was
Bram Moolenaard38b0552012-04-25 19:07:41 +02001825 invoked. Allows you to do special initialisations for |view|,
1826 |evim| etc., or any other name you might symlink to Vim.
Bram Moolenaar071d4272004-06-13 20:20:40 +00001827 Read-only.
1828
Bram Moolenaara1706c92014-04-01 19:55:49 +02001829 *v:progpath* *progpath-variable*
1830v:progpath Contains the command with which Vim was invoked, including the
1831 path. Useful if you want to message a Vim server using a
1832 |--remote-expr|.
Bram Moolenaarc7f02552014-04-01 21:00:59 +02001833 To get the full path use: >
1834 echo exepath(v:progpath)
Bram Moolenaar08cab962017-03-04 14:37:18 +01001835< If the path is relative it will be expanded to the full path,
1836 so that it still works after `:cd`. Thus starting "./vim"
1837 results in "/home/user/path/to/vim/src/vim".
1838 On MS-Windows the executable may be called "vim.exe", but the
1839 ".exe" is not added to v:progpath.
Bram Moolenaara1706c92014-04-01 19:55:49 +02001840 Read-only.
1841
Bram Moolenaar071d4272004-06-13 20:20:40 +00001842 *v:register* *register-variable*
Bram Moolenaard58e9292011-02-09 17:07:58 +01001843v:register The name of the register in effect for the current normal mode
Bram Moolenaard38b0552012-04-25 19:07:41 +02001844 command (regardless of whether that command actually used a
1845 register). Or for the currently executing normal mode mapping
1846 (use this in custom commands that take a register).
1847 If none is supplied it is the default register '"', unless
1848 'clipboard' contains "unnamed" or "unnamedplus", then it is
1849 '*' or '+'.
Bram Moolenaard58e9292011-02-09 17:07:58 +01001850 Also see |getreg()| and |setreg()|
Bram Moolenaar071d4272004-06-13 20:20:40 +00001851
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00001852 *v:scrollstart* *scrollstart-variable*
1853v:scrollstart String describing the script or function that caused the
1854 screen to scroll up. It's only set when it is empty, thus the
1855 first reason is remembered. It is set to "Unknown" for a
1856 typed command.
1857 This can be used to find out why your script causes the
1858 hit-enter prompt.
1859
Bram Moolenaar071d4272004-06-13 20:20:40 +00001860 *v:servername* *servername-variable*
Bram Moolenaarc2ce52c2017-08-01 18:35:38 +02001861v:servername The resulting registered |client-server-name| if any.
Bram Moolenaar071d4272004-06-13 20:20:40 +00001862 Read-only.
1863
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01001864
Bram Moolenaar446cb832008-06-24 21:56:24 +00001865v:searchforward *v:searchforward* *searchforward-variable*
1866 Search direction: 1 after a forward search, 0 after a
1867 backward search. It is reset to forward when directly setting
1868 the last search pattern, see |quote/|.
1869 Note that the value is restored when returning from a
1870 function. |function-search-undo|.
1871 Read-write.
1872
Bram Moolenaar071d4272004-06-13 20:20:40 +00001873 *v:shell_error* *shell_error-variable*
1874v:shell_error Result of the last shell command. When non-zero, the last
1875 shell command had an error. When zero, there was no problem.
1876 This only works when the shell returns the error code to Vim.
1877 The value -1 is often used when the command could not be
1878 executed. Read-only.
1879 Example: >
1880 :!mv foo bar
1881 :if v:shell_error
1882 : echo 'could not rename "foo" to "bar"!'
1883 :endif
1884< "shell_error" also works, for backwards compatibility.
1885
1886 *v:statusmsg* *statusmsg-variable*
1887v:statusmsg Last given status message. It's allowed to set this variable.
1888
Bram Moolenaar4e330bb2005-12-07 21:04:31 +00001889 *v:swapname* *swapname-variable*
1890v:swapname Only valid when executing |SwapExists| autocommands: Name of
1891 the swap file found. Read-only.
1892
1893 *v:swapchoice* *swapchoice-variable*
1894v:swapchoice |SwapExists| autocommands can set this to the selected choice
1895 for handling an existing swap file:
1896 'o' Open read-only
1897 'e' Edit anyway
1898 'r' Recover
1899 'd' Delete swapfile
1900 'q' Quit
1901 'a' Abort
Bram Moolenaar58b85342016-08-14 19:54:54 +02001902 The value should be a single-character string. An empty value
Bram Moolenaar4e330bb2005-12-07 21:04:31 +00001903 results in the user being asked, as would happen when there is
1904 no SwapExists autocommand. The default is empty.
1905
Bram Moolenaarb3480382005-12-11 21:33:32 +00001906 *v:swapcommand* *swapcommand-variable*
Bram Moolenaar4770d092006-01-12 23:22:24 +00001907v:swapcommand Normal mode command to be executed after a file has been
Bram Moolenaarb3480382005-12-11 21:33:32 +00001908 opened. Can be used for a |SwapExists| autocommand to have
Bram Moolenaar58b85342016-08-14 19:54:54 +02001909 another Vim open the file and jump to the right place. For
Bram Moolenaarb3480382005-12-11 21:33:32 +00001910 example, when jumping to a tag the value is ":tag tagname\r".
Bram Moolenaar1f35bf92006-03-07 22:38:47 +00001911 For ":edit +cmd file" the value is ":cmd\r".
Bram Moolenaarb3480382005-12-11 21:33:32 +00001912
Bram Moolenaard823fa92016-08-12 16:29:27 +02001913 *v:t_TYPE* *v:t_bool* *t_bool-variable*
Bram Moolenaarf562e722016-07-19 17:25:25 +02001914v:t_bool Value of Boolean type. Read-only. See: |type()|
Bram Moolenaard823fa92016-08-12 16:29:27 +02001915 *v:t_channel* *t_channel-variable*
Bram Moolenaarf562e722016-07-19 17:25:25 +02001916v:t_channel Value of Channel type. Read-only. See: |type()|
Bram Moolenaard823fa92016-08-12 16:29:27 +02001917 *v:t_dict* *t_dict-variable*
Bram Moolenaarf562e722016-07-19 17:25:25 +02001918v:t_dict Value of Dictionary type. Read-only. See: |type()|
Bram Moolenaard823fa92016-08-12 16:29:27 +02001919 *v:t_float* *t_float-variable*
Bram Moolenaarf562e722016-07-19 17:25:25 +02001920v:t_float Value of Float type. Read-only. See: |type()|
Bram Moolenaard823fa92016-08-12 16:29:27 +02001921 *v:t_func* *t_func-variable*
Bram Moolenaarf562e722016-07-19 17:25:25 +02001922v:t_func Value of Funcref type. Read-only. See: |type()|
Bram Moolenaard823fa92016-08-12 16:29:27 +02001923 *v:t_job* *t_job-variable*
Bram Moolenaarf562e722016-07-19 17:25:25 +02001924v:t_job Value of Job type. Read-only. See: |type()|
Bram Moolenaard823fa92016-08-12 16:29:27 +02001925 *v:t_list* *t_list-variable*
Bram Moolenaarf562e722016-07-19 17:25:25 +02001926v:t_list Value of List type. Read-only. See: |type()|
Bram Moolenaard823fa92016-08-12 16:29:27 +02001927 *v:t_none* *t_none-variable*
Bram Moolenaarf562e722016-07-19 17:25:25 +02001928v:t_none Value of None type. Read-only. See: |type()|
Bram Moolenaard823fa92016-08-12 16:29:27 +02001929 *v:t_number* *t_number-variable*
Bram Moolenaarf562e722016-07-19 17:25:25 +02001930v:t_number Value of Number type. Read-only. See: |type()|
Bram Moolenaard823fa92016-08-12 16:29:27 +02001931 *v:t_string* *t_string-variable*
Bram Moolenaarf562e722016-07-19 17:25:25 +02001932v:t_string Value of String type. Read-only. See: |type()|
Bram Moolenaar6e5ea8d2019-01-12 22:47:31 +01001933 *v:t_blob* *t_blob-variable*
1934v:t_blob Value of Blob type. Read-only. See: |type()|
Bram Moolenaarf562e722016-07-19 17:25:25 +02001935
Bram Moolenaar071d4272004-06-13 20:20:40 +00001936 *v:termresponse* *termresponse-variable*
1937v:termresponse The escape sequence returned by the terminal for the |t_RV|
Bram Moolenaar58b85342016-08-14 19:54:54 +02001938 termcap entry. It is set when Vim receives an escape sequence
Bram Moolenaar071d4272004-06-13 20:20:40 +00001939 that starts with ESC [ or CSI and ends in a 'c', with only
1940 digits, ';' and '.' in between.
1941 When this option is set, the TermResponse autocommand event is
1942 fired, so that you can react to the response from the
1943 terminal.
1944 The response from a new xterm is: "<Esc>[ Pp ; Pv ; Pc c". Pp
1945 is the terminal type: 0 for vt100 and 1 for vt220. Pv is the
1946 patch level (since this was introduced in patch 95, it's
1947 always 95 or bigger). Pc is always zero.
1948 {only when compiled with |+termresponse| feature}
1949
Bram Moolenaarf3af54e2017-08-30 14:53:06 +02001950 *v:termblinkresp*
1951v:termblinkresp The escape sequence returned by the terminal for the |t_RC|
1952 termcap entry. This is used to find out whether the terminal
1953 cursor is blinking. This is used by |term_getcursor()|.
1954
1955 *v:termstyleresp*
1956v:termstyleresp The escape sequence returned by the terminal for the |t_RS|
1957 termcap entry. This is used to find out what the shape of the
1958 cursor is. This is used by |term_getcursor()|.
1959
Bram Moolenaar65e4c4f2017-10-14 23:24:25 +02001960 *v:termrbgresp*
1961v:termrbgresp The escape sequence returned by the terminal for the |t_RB|
Bram Moolenaarf3af54e2017-08-30 14:53:06 +02001962 termcap entry. This is used to find out what the terminal
1963 background color is, see 'background'.
1964
Bram Moolenaar65e4c4f2017-10-14 23:24:25 +02001965 *v:termrfgresp*
1966v:termrfgresp The escape sequence returned by the terminal for the |t_RF|
1967 termcap entry. This is used to find out what the terminal
1968 foreground color is.
1969
Bram Moolenaarf3af54e2017-08-30 14:53:06 +02001970 *v:termu7resp*
1971v:termu7resp The escape sequence returned by the terminal for the |t_u7|
1972 termcap entry. This is used to find out what the terminal
1973 does with ambiguous width characters, see 'ambiwidth'.
1974
Bram Moolenaarebf7dfa2016-04-14 12:46:51 +02001975 *v:testing* *testing-variable*
Bram Moolenaar8e8df252016-05-25 21:23:21 +02001976v:testing Must be set before using `test_garbagecollect_now()`.
Bram Moolenaar036986f2017-03-16 17:41:02 +01001977 Also, when set certain error messages won't be shown for 2
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01001978 seconds. (e.g. "'dictionary' option is empty")
Bram Moolenaarebf7dfa2016-04-14 12:46:51 +02001979
Bram Moolenaar071d4272004-06-13 20:20:40 +00001980 *v:this_session* *this_session-variable*
1981v:this_session Full filename of the last loaded or saved session file. See
1982 |:mksession|. It is allowed to set this variable. When no
1983 session file has been saved, this variable is empty.
1984 "this_session" also works, for backwards compatibility.
1985
1986 *v:throwpoint* *throwpoint-variable*
1987v:throwpoint The point where the exception most recently caught and not
Bram Moolenaar58b85342016-08-14 19:54:54 +02001988 finished was thrown. Not set when commands are typed. See
Bram Moolenaar071d4272004-06-13 20:20:40 +00001989 also |v:exception| and |throw-variables|.
1990 Example: >
1991 :try
1992 : throw "oops"
1993 :catch /.*/
1994 : echo "Exception from" v:throwpoint
1995 :endtry
1996< Output: "Exception from test.vim, line 2"
1997
Bram Moolenaar520e1e42016-01-23 19:46:28 +01001998 *v:true* *true-variable*
1999v:true A Number with value one. Used to put "true" in JSON. See
Bram Moolenaar6463ca22016-02-13 17:04:46 +01002000 |json_encode()|.
Bram Moolenaarc95a3022016-06-12 23:01:46 +02002001 When used as a string this evaluates to "v:true". >
Bram Moolenaar705ada12016-01-24 17:56:50 +01002002 echo v:true
Bram Moolenaarc95a3022016-06-12 23:01:46 +02002003< v:true ~
2004 That is so that eval() can parse the string back to the same
Bram Moolenaardf48fb42016-07-22 21:50:18 +02002005 value. Read-only.
Bram Moolenaar2fda12f2005-01-15 22:14:15 +00002006 *v:val* *val-variable*
Bram Moolenaar58b85342016-08-14 19:54:54 +02002007v:val Value of the current item of a |List| or |Dictionary|. Only
Bram Moolenaar32466aa2006-02-24 23:53:04 +00002008 valid while evaluating the expression used with |map()| and
Bram Moolenaar2fda12f2005-01-15 22:14:15 +00002009 |filter()|. Read-only.
2010
Bram Moolenaar071d4272004-06-13 20:20:40 +00002011 *v:version* *version-variable*
2012v:version Version number of Vim: Major version number times 100 plus
2013 minor version number. Version 5.0 is 500. Version 5.1 (5.01)
2014 is 501. Read-only. "version" also works, for backwards
2015 compatibility.
2016 Use |has()| to check if a certain patch was included, e.g.: >
Bram Moolenaar6716d9a2014-04-02 12:12:08 +02002017 if has("patch-7.4.123")
Bram Moolenaar071d4272004-06-13 20:20:40 +00002018< Note that patch numbers are specific to the version, thus both
2019 version 5.0 and 5.1 may have a patch 123, but these are
2020 completely different.
2021
Bram Moolenaar14735512016-03-26 21:00:08 +01002022 *v:vim_did_enter* *vim_did_enter-variable*
2023v:vim_did_enter Zero until most of startup is done. It is set to one just
2024 before |VimEnter| autocommands are triggered.
2025
Bram Moolenaar071d4272004-06-13 20:20:40 +00002026 *v:warningmsg* *warningmsg-variable*
2027v:warningmsg Last given warning message. It's allowed to set this variable.
2028
Bram Moolenaar727c8762010-10-20 19:17:48 +02002029 *v:windowid* *windowid-variable*
2030v:windowid When any X11 based GUI is running or when running in a
2031 terminal and Vim connects to the X server (|-X|) this will be
Bram Moolenaar264e9fd2010-10-27 12:33:17 +02002032 set to the window ID.
2033 When an MS-Windows GUI is running this will be set to the
2034 window handle.
2035 Otherwise the value is zero.
Bram Moolenaar7571d552016-08-18 22:54:46 +02002036 Note: for windows inside Vim use |winnr()| or |win_getid()|,
2037 see |window-ID|.
Bram Moolenaar727c8762010-10-20 19:17:48 +02002038
Bram Moolenaar071d4272004-06-13 20:20:40 +00002039==============================================================================
20404. Builtin Functions *functions*
2041
2042See |function-list| for a list grouped by what the function is used for.
2043
Bram Moolenaar402d2fe2005-04-15 21:00:38 +00002044(Use CTRL-] on the function name to jump to the full explanation.)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002045
2046USAGE RESULT DESCRIPTION ~
2047
Bram Moolenaar81edd172016-04-14 13:51:37 +02002048abs({expr}) Float or Number absolute value of {expr}
2049acos({expr}) Float arc cosine of {expr}
2050add({list}, {item}) List append {item} to |List| {list}
Bram Moolenaara06ecab2016-07-16 14:47:36 +02002051and({expr}, {expr}) Number bitwise AND
Bram Moolenaar95bafa22018-10-02 13:26:25 +02002052append({lnum}, {text}) Number append {text} below line {lnum}
2053appendbufline({expr}, {lnum}, {text})
2054 Number append {text} below line {lnum}
2055 in buffer {expr}
Bram Moolenaarf0d58ef2018-11-16 16:13:44 +01002056argc([{winid}]) Number number of files in the argument list
Bram Moolenaard7ee7ce2005-01-03 21:02:03 +00002057argidx() Number current index in the argument list
Bram Moolenaar81edd172016-04-14 13:51:37 +02002058arglistid([{winnr} [, {tabnr}]]) Number argument list id
Bram Moolenaare6e39892018-10-25 12:32:11 +02002059argv({nr} [, {winid}]) String {nr} entry of the argument list
2060argv([-1, {winid}]) List the argument list
Bram Moolenaar65a54642018-04-28 16:56:53 +02002061assert_beeps({cmd}) Number assert {cmd} causes a beep
Bram Moolenaar42205552017-03-18 19:42:22 +01002062assert_equal({exp}, {act} [, {msg}])
Bram Moolenaar65a54642018-04-28 16:56:53 +02002063 Number assert {exp} is equal to {act}
Bram Moolenaard96ff162018-02-18 22:13:29 +01002064assert_equalfile({fname-one}, {fname-two})
Bram Moolenaar65a54642018-04-28 16:56:53 +02002065 Number assert file contents is equal
Bram Moolenaar42205552017-03-18 19:42:22 +01002066assert_exception({error} [, {msg}])
Bram Moolenaar65a54642018-04-28 16:56:53 +02002067 Number assert {error} is in v:exception
Bram Moolenaar2c64ca12018-10-19 16:22:31 +02002068assert_fails({cmd} [, {error} [, {msg}]])
2069 Number assert {cmd} fails
Bram Moolenaar42205552017-03-18 19:42:22 +01002070assert_false({actual} [, {msg}])
Bram Moolenaar65a54642018-04-28 16:56:53 +02002071 Number assert {actual} is false
Bram Moolenaar61c04492016-07-23 15:35:35 +02002072assert_inrange({lower}, {upper}, {actual} [, {msg}])
Bram Moolenaar65a54642018-04-28 16:56:53 +02002073 Number assert {actual} is inside the range
Bram Moolenaar42205552017-03-18 19:42:22 +01002074assert_match({pat}, {text} [, {msg}])
Bram Moolenaar65a54642018-04-28 16:56:53 +02002075 Number assert {pat} matches {text}
Bram Moolenaar42205552017-03-18 19:42:22 +01002076assert_notequal({exp}, {act} [, {msg}])
Bram Moolenaar65a54642018-04-28 16:56:53 +02002077 Number assert {exp} is not equal {act}
Bram Moolenaar42205552017-03-18 19:42:22 +01002078assert_notmatch({pat}, {text} [, {msg}])
Bram Moolenaar65a54642018-04-28 16:56:53 +02002079 Number assert {pat} not matches {text}
2080assert_report({msg}) Number report a test failure
2081assert_true({actual} [, {msg}]) Number assert {actual} is true
Bram Moolenaar81edd172016-04-14 13:51:37 +02002082asin({expr}) Float arc sine of {expr}
2083atan({expr}) Float arc tangent of {expr}
Bram Moolenaar04186092016-08-29 21:55:35 +02002084atan2({expr1}, {expr2}) Float arc tangent of {expr1} / {expr2}
Bram Moolenaar74240d32017-12-10 15:26:15 +01002085balloon_show({expr}) none show {expr} inside the balloon
Bram Moolenaar246fe032017-11-19 19:56:27 +01002086balloon_split({msg}) List split {msg} as used for a balloon
Bram Moolenaar81edd172016-04-14 13:51:37 +02002087browse({save}, {title}, {initdir}, {default})
Bram Moolenaar071d4272004-06-13 20:20:40 +00002088 String put up a file requester
Bram Moolenaar81edd172016-04-14 13:51:37 +02002089browsedir({title}, {initdir}) String put up a directory requester
Bram Moolenaare381d3d2016-07-07 14:50:41 +02002090bufexists({expr}) Number |TRUE| if buffer {expr} exists
2091buflisted({expr}) Number |TRUE| if buffer {expr} is listed
2092bufloaded({expr}) Number |TRUE| if buffer {expr} is loaded
Bram Moolenaar81edd172016-04-14 13:51:37 +02002093bufname({expr}) String Name of the buffer {expr}
2094bufnr({expr} [, {create}]) Number Number of the buffer {expr}
Bram Moolenaarb3619a92016-06-04 17:58:52 +02002095bufwinid({expr}) Number window ID of buffer {expr}
Bram Moolenaar81edd172016-04-14 13:51:37 +02002096bufwinnr({expr}) Number window number of buffer {expr}
2097byte2line({byte}) Number line number at byte count {byte}
2098byteidx({expr}, {nr}) Number byte index of {nr}'th char in {expr}
2099byteidxcomp({expr}, {nr}) Number byte index of {nr}'th char in {expr}
2100call({func}, {arglist} [, {dict}])
Bram Moolenaar2fda12f2005-01-15 22:14:15 +00002101 any call {func} with arguments {arglist}
Bram Moolenaar81edd172016-04-14 13:51:37 +02002102ceil({expr}) Float round {expr} up
Bram Moolenaar4b785f62016-11-29 21:54:44 +01002103ch_canread({handle}) Number check if there is something to read
Bram Moolenaar81edd172016-04-14 13:51:37 +02002104ch_close({handle}) none close {handle}
Bram Moolenaar0874a832016-09-01 15:11:51 +02002105ch_close_in({handle}) none close in part of {handle}
Bram Moolenaar81edd172016-04-14 13:51:37 +02002106ch_evalexpr({handle}, {expr} [, {options}])
Bram Moolenaar5f148ec2016-03-07 22:59:26 +01002107 any evaluate {expr} on JSON {handle}
Bram Moolenaar81edd172016-04-14 13:51:37 +02002108ch_evalraw({handle}, {string} [, {options}])
Bram Moolenaar5f148ec2016-03-07 22:59:26 +01002109 any evaluate {string} on raw {handle}
Bram Moolenaar81edd172016-04-14 13:51:37 +02002110ch_getbufnr({handle}, {what}) Number get buffer number for {handle}/{what}
2111ch_getjob({channel}) Job get the Job of {channel}
Bram Moolenaara06ecab2016-07-16 14:47:36 +02002112ch_info({handle}) String info about channel {handle}
Bram Moolenaar81edd172016-04-14 13:51:37 +02002113ch_log({msg} [, {handle}]) none write {msg} in the channel log file
2114ch_logfile({fname} [, {mode}]) none start logging channel activity
2115ch_open({address} [, {options}])
Bram Moolenaara06ecab2016-07-16 14:47:36 +02002116 Channel open a channel to {address}
2117ch_read({handle} [, {options}]) String read from {handle}
Bram Moolenaar6e5ea8d2019-01-12 22:47:31 +01002118ch_readblob({handle} [, {options}])
2119 Blob read Blob from {handle}
Bram Moolenaar81edd172016-04-14 13:51:37 +02002120ch_readraw({handle} [, {options}])
Bram Moolenaara06ecab2016-07-16 14:47:36 +02002121 String read raw from {handle}
Bram Moolenaar81edd172016-04-14 13:51:37 +02002122ch_sendexpr({handle}, {expr} [, {options}])
Bram Moolenaar5f148ec2016-03-07 22:59:26 +01002123 any send {expr} over JSON {handle}
Bram Moolenaar6e5ea8d2019-01-12 22:47:31 +01002124ch_sendraw({handle}, {expr} [, {options}])
2125 any send {expr} over raw {handle}
Bram Moolenaar81edd172016-04-14 13:51:37 +02002126ch_setoptions({handle}, {options})
2127 none set options for {handle}
Bram Moolenaar7ef38102016-09-26 22:36:58 +02002128ch_status({handle} [, {options}])
2129 String status of channel {handle}
Bram Moolenaar446cb832008-06-24 21:56:24 +00002130changenr() Number current change number
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01002131char2nr({expr} [, {utf8}]) Number ASCII/UTF8 value of first char in {expr}
Bram Moolenaar81edd172016-04-14 13:51:37 +02002132cindent({lnum}) Number C indent for line {lnum}
Bram Moolenaar8f3f58f2010-01-06 20:52:26 +01002133clearmatches() none clear all matches
Bram Moolenaar81edd172016-04-14 13:51:37 +02002134col({expr}) Number column nr of cursor or mark
2135complete({startcol}, {matches}) none set Insert mode completion
2136complete_add({expr}) Number add completion match
Bram Moolenaar446cb832008-06-24 21:56:24 +00002137complete_check() Number check for key typed during completion
Bram Moolenaar81edd172016-04-14 13:51:37 +02002138confirm({msg} [, {choices} [, {default} [, {type}]]])
Bram Moolenaar071d4272004-06-13 20:20:40 +00002139 Number number of choice picked by user
Bram Moolenaar81edd172016-04-14 13:51:37 +02002140copy({expr}) any make a shallow copy of {expr}
2141cos({expr}) Float cosine of {expr}
2142cosh({expr}) Float hyperbolic cosine of {expr}
Bram Moolenaar95bafa22018-10-02 13:26:25 +02002143count({comp}, {expr} [, {ic} [, {start}]])
2144 Number count how many {expr} are in {comp}
Bram Moolenaardc1f1642016-08-16 18:33:43 +02002145cscope_connection([{num}, {dbpath} [, {prepend}]])
Bram Moolenaar071d4272004-06-13 20:20:40 +00002146 Number checks existence of cscope connection
Bram Moolenaar81edd172016-04-14 13:51:37 +02002147cursor({lnum}, {col} [, {off}])
Bram Moolenaar2f3b5102014-11-19 18:54:17 +01002148 Number move cursor to {lnum}, {col}, {off}
Bram Moolenaar81edd172016-04-14 13:51:37 +02002149cursor({list}) Number move cursor to position in {list}
Bram Moolenaar4551c0a2018-06-20 22:38:21 +02002150debugbreak({pid}) Number interrupt process being debugged
Bram Moolenaar81edd172016-04-14 13:51:37 +02002151deepcopy({expr} [, {noref}]) any make a full copy of {expr}
2152delete({fname} [, {flags}]) Number delete the file or directory {fname}
Bram Moolenaard473c8c2018-08-11 18:00:22 +02002153deletebufline({expr}, {first} [, {last}])
Bram Moolenaard79a2622018-06-07 18:17:46 +02002154 Number delete lines from buffer {expr}
Bram Moolenaare381d3d2016-07-07 14:50:41 +02002155did_filetype() Number |TRUE| if FileType autocmd event used
Bram Moolenaar81edd172016-04-14 13:51:37 +02002156diff_filler({lnum}) Number diff filler lines about {lnum}
2157diff_hlID({lnum}, {col}) Number diff highlighting at {lnum}/{col}
Bram Moolenaare381d3d2016-07-07 14:50:41 +02002158empty({expr}) Number |TRUE| if {expr} is empty
Bram Moolenaar81edd172016-04-14 13:51:37 +02002159escape({string}, {chars}) String escape {chars} in {string} with '\'
2160eval({string}) any evaluate {string} into its value
Bram Moolenaare381d3d2016-07-07 14:50:41 +02002161eventhandler() Number |TRUE| if inside an event handler
Bram Moolenaar81edd172016-04-14 13:51:37 +02002162executable({expr}) Number 1 if executable {expr} exists
Bram Moolenaar79815f12016-07-09 17:07:29 +02002163execute({command}) String execute {command} and get the output
Bram Moolenaara06ecab2016-07-16 14:47:36 +02002164exepath({expr}) String full path of the command {expr}
Bram Moolenaare381d3d2016-07-07 14:50:41 +02002165exists({expr}) Number |TRUE| if {expr} exists
Bram Moolenaar81edd172016-04-14 13:51:37 +02002166extend({expr1}, {expr2} [, {expr3}])
Bram Moolenaarc6fe9192006-04-09 21:54:49 +00002167 List/Dict insert items of {expr2} into {expr1}
Bram Moolenaar81edd172016-04-14 13:51:37 +02002168exp({expr}) Float exponential of {expr}
2169expand({expr} [, {nosuf} [, {list}]])
Bram Moolenaar146e9c32012-03-07 19:18:23 +01002170 any expand special keywords in {expr}
Bram Moolenaar81edd172016-04-14 13:51:37 +02002171feedkeys({string} [, {mode}]) Number add key sequence to typeahead buffer
Bram Moolenaare381d3d2016-07-07 14:50:41 +02002172filereadable({file}) Number |TRUE| if {file} is a readable file
2173filewritable({file}) Number |TRUE| if {file} is a writable file
Bram Moolenaar50ba5262016-09-22 22:33:02 +02002174filter({expr1}, {expr2}) List/Dict remove items from {expr1} where
2175 {expr2} is 0
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01002176finddir({name} [, {path} [, {count}]])
Bram Moolenaarc6fe9192006-04-09 21:54:49 +00002177 String find directory {name} in {path}
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01002178findfile({name} [, {path} [, {count}]])
Bram Moolenaarc6fe9192006-04-09 21:54:49 +00002179 String find file {name} in {path}
Bram Moolenaar81edd172016-04-14 13:51:37 +02002180float2nr({expr}) Number convert Float {expr} to a Number
2181floor({expr}) Float round {expr} down
2182fmod({expr1}, {expr2}) Float remainder of {expr1} / {expr2}
2183fnameescape({fname}) String escape special characters in {fname}
2184fnamemodify({fname}, {mods}) String modify file name
2185foldclosed({lnum}) Number first line of fold at {lnum} if closed
2186foldclosedend({lnum}) Number last line of fold at {lnum} if closed
2187foldlevel({lnum}) Number fold level at {lnum}
Bram Moolenaare0fa3742016-02-20 15:47:01 +01002188foldtext() String line displayed for closed fold
Bram Moolenaar81edd172016-04-14 13:51:37 +02002189foldtextresult({lnum}) String text for closed fold at {lnum}
Bram Moolenaare0fa3742016-02-20 15:47:01 +01002190foreground() Number bring the Vim window to the foreground
Bram Moolenaar437bafe2016-08-01 15:40:54 +02002191funcref({name} [, {arglist}] [, {dict}])
Bram Moolenaara06ecab2016-07-16 14:47:36 +02002192 Funcref reference to function {name}
Bram Moolenaar437bafe2016-08-01 15:40:54 +02002193function({name} [, {arglist}] [, {dict}])
2194 Funcref named reference to function {name}
Bram Moolenaar81edd172016-04-14 13:51:37 +02002195garbagecollect([{atexit}]) none free memory, breaking cyclic references
Bram Moolenaar81edd172016-04-14 13:51:37 +02002196get({list}, {idx} [, {def}]) any get item {idx} from {list} or {def}
2197get({dict}, {key} [, {def}]) any get item {key} from {dict} or {def}
Bram Moolenaar03e19a02016-05-24 22:29:49 +02002198get({func}, {what}) any get property of funcref/partial {func}
Bram Moolenaar50ba5262016-09-22 22:33:02 +02002199getbufinfo([{expr}]) List information about buffers
Bram Moolenaar81edd172016-04-14 13:51:37 +02002200getbufline({expr}, {lnum} [, {end}])
Bram Moolenaar45360022005-07-21 21:08:21 +00002201 List lines {lnum} to {end} of buffer {expr}
Bram Moolenaar81edd172016-04-14 13:51:37 +02002202getbufvar({expr}, {varname} [, {def}])
Bram Moolenaar63dbda12013-02-20 21:12:10 +01002203 any variable {varname} in buffer {expr}
Bram Moolenaar07ad8162018-02-13 13:59:59 +01002204getchangelist({expr}) List list of change list items
Bram Moolenaar81edd172016-04-14 13:51:37 +02002205getchar([expr]) Number get one character from the user
Bram Moolenaare0fa3742016-02-20 15:47:01 +01002206getcharmod() Number modifiers for the last typed character
Bram Moolenaarfc39ecf2015-08-11 20:34:49 +02002207getcharsearch() Dict last character search
Bram Moolenaar071d4272004-06-13 20:20:40 +00002208getcmdline() String return the current command-line
2209getcmdpos() Number return cursor position in command-line
Bram Moolenaarfb539272014-08-22 19:21:47 +02002210getcmdtype() String return current command-line type
2211getcmdwintype() String return current command-line window type
Bram Moolenaare9d58a62016-08-13 15:07:41 +02002212getcompletion({pat}, {type} [, {filtered}])
2213 List list of cmdline completion matches
Bram Moolenaar6f6c0f82014-05-28 20:31:42 +02002214getcurpos() List position of the cursor
Bram Moolenaar81edd172016-04-14 13:51:37 +02002215getcwd([{winnr} [, {tabnr}]]) String get the current working directory
2216getfontname([{name}]) String name of font being used
2217getfperm({fname}) String file permissions of file {fname}
2218getfsize({fname}) Number size in bytes of file {fname}
2219getftime({fname}) Number last modification time of file
2220getftype({fname}) String description of type of file {fname}
Bram Moolenaar4f505882018-02-10 21:06:32 +01002221getjumplist([{winnr} [, {tabnr}]])
2222 List list of jump list items
Bram Moolenaar81edd172016-04-14 13:51:37 +02002223getline({lnum}) String line {lnum} of current buffer
2224getline({lnum}, {end}) List lines {lnum} to {end} of current buffer
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01002225getloclist({nr} [, {what}]) List list of location list items
Bram Moolenaar6ee10162007-07-26 20:58:42 +00002226getmatches() List list of current matches
Bram Moolenaar18081e32008-02-20 19:11:07 +00002227getpid() Number process ID of Vim
Bram Moolenaar81edd172016-04-14 13:51:37 +02002228getpos({expr}) List position of cursor, mark, etc.
Bram Moolenaard823fa92016-08-12 16:29:27 +02002229getqflist([{what}]) List list of quickfix items
Bram Moolenaar81edd172016-04-14 13:51:37 +02002230getreg([{regname} [, 1 [, {list}]]])
Bram Moolenaarb7cb42b2014-04-02 19:55:10 +02002231 String or List contents of register
Bram Moolenaar81edd172016-04-14 13:51:37 +02002232getregtype([{regname}]) String type of register
Bram Moolenaar50ba5262016-09-22 22:33:02 +02002233gettabinfo([{expr}]) List list of tab pages
Bram Moolenaar81edd172016-04-14 13:51:37 +02002234gettabvar({nr}, {varname} [, {def}])
Bram Moolenaar63dbda12013-02-20 21:12:10 +01002235 any variable {varname} in tab {nr} or {def}
Bram Moolenaar81edd172016-04-14 13:51:37 +02002236gettabwinvar({tabnr}, {winnr}, {name} [, {def}])
Bram Moolenaarc6249bb2006-04-15 20:25:09 +00002237 any {name} in {winnr} in tab page {tabnr}
Bram Moolenaarf49cc602018-11-11 15:21:05 +01002238gettagstack([{nr}]) Dict get the tag stack of window {nr}
Bram Moolenaar7132ddc2018-07-15 17:01:11 +02002239getwininfo([{winid}]) List list of info about each window
Bram Moolenaar98ef2332018-03-18 14:44:37 +01002240getwinpos([{timeout}]) List X and Y coord in pixels of the Vim window
Bram Moolenaar3f54fd32018-03-03 21:29:55 +01002241getwinposx() Number X coord in pixels of the Vim window
2242getwinposy() Number Y coord in pixels of the Vim window
Bram Moolenaar81edd172016-04-14 13:51:37 +02002243getwinvar({nr}, {varname} [, {def}])
Bram Moolenaar63dbda12013-02-20 21:12:10 +01002244 any variable {varname} in window {nr}
Bram Moolenaar81edd172016-04-14 13:51:37 +02002245glob({expr} [, {nosuf} [, {list} [, {alllinks}]]])
Bram Moolenaar146e9c32012-03-07 19:18:23 +01002246 any expand file wildcards in {expr}
Bram Moolenaara06ecab2016-07-16 14:47:36 +02002247glob2regpat({expr}) String convert a glob pat into a search pat
Bram Moolenaar81edd172016-04-14 13:51:37 +02002248globpath({path}, {expr} [, {nosuf} [, {list} [, {alllinks}]]])
Bram Moolenaarbb5ddda2008-11-28 10:01:10 +00002249 String do glob({expr}) for all dirs in {path}
Bram Moolenaare381d3d2016-07-07 14:50:41 +02002250has({feature}) Number |TRUE| if feature {feature} supported
2251has_key({dict}, {key}) Number |TRUE| if {dict} has entry {key}
Bram Moolenaar81edd172016-04-14 13:51:37 +02002252haslocaldir([{winnr} [, {tabnr}]])
Bram Moolenaare381d3d2016-07-07 14:50:41 +02002253 Number |TRUE| if the window executed |:lcd|
Bram Moolenaar81edd172016-04-14 13:51:37 +02002254hasmapto({what} [, {mode} [, {abbr}]])
Bram Moolenaare381d3d2016-07-07 14:50:41 +02002255 Number |TRUE| if mapping to {what} exists
Bram Moolenaar81edd172016-04-14 13:51:37 +02002256histadd({history}, {item}) String add an item to a history
2257histdel({history} [, {item}]) String remove an item from a history
2258histget({history} [, {index}]) String get the item {index} from a history
2259histnr({history}) Number highest index of a history
Bram Moolenaare381d3d2016-07-07 14:50:41 +02002260hlexists({name}) Number |TRUE| if highlight group {name} exists
Bram Moolenaar81edd172016-04-14 13:51:37 +02002261hlID({name}) Number syntax ID of highlight group {name}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002262hostname() String name of the machine Vim is running on
Bram Moolenaar81edd172016-04-14 13:51:37 +02002263iconv({expr}, {from}, {to}) String convert encoding of {expr}
2264indent({lnum}) Number indent of line {lnum}
Bram Moolenaar6e5ea8d2019-01-12 22:47:31 +01002265index({object}, {expr} [, {start} [, {ic}]])
2266 Number index in {object} where {expr} appears
Bram Moolenaar81edd172016-04-14 13:51:37 +02002267input({prompt} [, {text} [, {completion}]])
Bram Moolenaarbfd8fc02005-09-20 23:22:24 +00002268 String get input from the user
Bram Moolenaarb6e0ec62017-07-23 22:12:20 +02002269inputdialog({prompt} [, {text} [, {completion}]])
Bram Moolenaara06ecab2016-07-16 14:47:36 +02002270 String like input() but in a GUI dialog
Bram Moolenaar81edd172016-04-14 13:51:37 +02002271inputlist({textlist}) Number let the user pick from a choice list
Bram Moolenaard7ee7ce2005-01-03 21:02:03 +00002272inputrestore() Number restore typeahead
2273inputsave() Number save and clear typeahead
Bram Moolenaara06ecab2016-07-16 14:47:36 +02002274inputsecret({prompt} [, {text}]) String like input() but hiding the text
Bram Moolenaar6e5ea8d2019-01-12 22:47:31 +01002275insert({object}, {item} [, {idx}]) List insert {item} in {object} [before {idx}]
Bram Moolenaara06ecab2016-07-16 14:47:36 +02002276invert({expr}) Number bitwise invert
Bram Moolenaare381d3d2016-07-07 14:50:41 +02002277isdirectory({directory}) Number |TRUE| if {directory} is a directory
2278islocked({expr}) Number |TRUE| if {expr} is locked
Bram Moolenaara06ecab2016-07-16 14:47:36 +02002279isnan({expr}) Number |TRUE| if {expr} is NaN
Bram Moolenaar81edd172016-04-14 13:51:37 +02002280items({dict}) List key-value pairs in {dict}
2281job_getchannel({job}) Channel get the channel handle for {job}
Bram Moolenaare1fc5152018-04-21 19:49:08 +02002282job_info([{job}]) Dict get information about {job}
Bram Moolenaar81edd172016-04-14 13:51:37 +02002283job_setoptions({job}, {options}) none set options for {job}
2284job_start({command} [, {options}])
Bram Moolenaara06ecab2016-07-16 14:47:36 +02002285 Job start a job
Bram Moolenaar81edd172016-04-14 13:51:37 +02002286job_status({job}) String get the status of {job}
2287job_stop({job} [, {how}]) Number stop {job}
2288join({list} [, {sep}]) String join {list} items into one String
2289js_decode({string}) any decode JS style JSON
2290js_encode({expr}) String encode JS style JSON
2291json_decode({string}) any decode JSON
2292json_encode({expr}) String encode JSON
2293keys({dict}) List keys in {dict}
2294len({expr}) Number the length of {expr}
2295libcall({lib}, {func}, {arg}) String call {func} in library {lib} with {arg}
Bram Moolenaara06ecab2016-07-16 14:47:36 +02002296libcallnr({lib}, {func}, {arg}) Number idem, but return a Number
Bram Moolenaar81edd172016-04-14 13:51:37 +02002297line({expr}) Number line nr of cursor, last line or mark
2298line2byte({lnum}) Number byte count of line {lnum}
2299lispindent({lnum}) Number Lisp indent for line {lnum}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002300localtime() Number current time
Bram Moolenaar81edd172016-04-14 13:51:37 +02002301log({expr}) Float natural logarithm (base e) of {expr}
2302log10({expr}) Float logarithm of Float {expr} to base 10
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01002303luaeval({expr} [, {expr}]) any evaluate |Lua| expression
Bram Moolenaar50ba5262016-09-22 22:33:02 +02002304map({expr1}, {expr2}) List/Dict change each item in {expr1} to {expr}
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01002305maparg({name} [, {mode} [, {abbr} [, {dict}]]])
Bram Moolenaarf1568ec2011-12-14 21:17:39 +01002306 String or Dict
2307 rhs of mapping {name} in mode {mode}
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01002308mapcheck({name} [, {mode} [, {abbr}]])
Bram Moolenaar97b2ad32006-03-18 21:40:56 +00002309 String check for mappings matching {name}
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01002310match({expr}, {pat} [, {start} [, {count}]])
Bram Moolenaar071d4272004-06-13 20:20:40 +00002311 Number position where {pat} matches in {expr}
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01002312matchadd({group}, {pattern} [, {priority} [, {id} [, {dict}]]])
Bram Moolenaar6ee10162007-07-26 20:58:42 +00002313 Number highlight {pattern} with {group}
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01002314matchaddpos({group}, {pos} [, {priority} [, {id} [, {dict}]]])
Bram Moolenaarb3414592014-06-17 17:48:32 +02002315 Number highlight positions with {group}
Bram Moolenaar81edd172016-04-14 13:51:37 +02002316matcharg({nr}) List arguments of |:match|
2317matchdelete({id}) Number delete match identified by {id}
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01002318matchend({expr}, {pat} [, {start} [, {count}]])
Bram Moolenaar071d4272004-06-13 20:20:40 +00002319 Number position where {pat} ends in {expr}
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01002320matchlist({expr}, {pat} [, {start} [, {count}]])
Bram Moolenaar3a7c85b2005-02-05 21:39:53 +00002321 List match and submatches of {pat} in {expr}
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01002322matchstr({expr}, {pat} [, {start} [, {count}]])
Bram Moolenaar89cb5e02004-07-19 20:55:54 +00002323 String {count}'th match of {pat} in {expr}
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01002324matchstrpos({expr}, {pat} [, {start} [, {count}]])
Bram Moolenaar7fed5c12016-03-29 23:10:31 +02002325 List {count}'th match of {pat} in {expr}
Bram Moolenaar690afe12017-01-28 18:34:47 +01002326max({expr}) Number maximum value of items in {expr}
2327min({expr}) Number minimum value of items in {expr}
Bram Moolenaar81edd172016-04-14 13:51:37 +02002328mkdir({name} [, {path} [, {prot}]])
Bram Moolenaar26a60b42005-02-22 08:49:11 +00002329 Number create directory {name}
Bram Moolenaar81edd172016-04-14 13:51:37 +02002330mode([expr]) String current editing mode
2331mzeval({expr}) any evaluate |MzScheme| expression
2332nextnonblank({lnum}) Number line nr of non-blank line >= {lnum}
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01002333nr2char({expr} [, {utf8}]) String single char with ASCII/UTF8 value {expr}
Bram Moolenaara06ecab2016-07-16 14:47:36 +02002334or({expr}, {expr}) Number bitwise OR
Bram Moolenaar81edd172016-04-14 13:51:37 +02002335pathshorten({expr}) String shorten directory names in a path
2336perleval({expr}) any evaluate |Perl| expression
2337pow({x}, {y}) Float {x} to the power of {y}
2338prevnonblank({lnum}) Number line nr of non-blank line <= {lnum}
2339printf({fmt}, {expr1}...) String format text
Bram Moolenaarf2732452018-06-03 14:47:35 +02002340prompt_setcallback({buf}, {expr}) none set prompt callback function
Bram Moolenaar0e5979a2018-06-17 19:36:33 +02002341prompt_setinterrupt({buf}, {text}) none set prompt interrupt function
2342prompt_setprompt({buf}, {text}) none set prompt text
Bram Moolenaar98aefe72018-12-13 22:20:09 +01002343prop_add({lnum}, {col}, {props}) none add a text property
Bram Moolenaare3d31b02018-12-24 23:07:04 +01002344prop_clear({lnum} [, {lnum-end} [, {props}]])
Bram Moolenaar98aefe72018-12-13 22:20:09 +01002345 none remove all text properties
2346prop_find({props} [, {direction}])
2347 Dict search for a text property
Bram Moolenaar5b69c222019-01-11 14:50:06 +01002348prop_list({lnum} [, {props}) List text properties in {lnum}
Bram Moolenaarc8c88492018-12-27 23:59:26 +01002349prop_remove({props} [, {lnum} [, {lnum-end}]])
Bram Moolenaar98aefe72018-12-13 22:20:09 +01002350 Number remove a text property
2351prop_type_add({name}, {props}) none define a new property type
2352prop_type_change({name}, {props})
2353 none change an existing property type
2354prop_type_delete({name} [, {props}])
2355 none delete a property type
2356prop_type_get([{name} [, {props}])
2357 Dict get property type values
2358prop_type_list([{props}]) List get list of property types
Bram Moolenaar446cb832008-06-24 21:56:24 +00002359pumvisible() Number whether popup menu is visible
Bram Moolenaar81edd172016-04-14 13:51:37 +02002360pyeval({expr}) any evaluate |Python| expression
2361py3eval({expr}) any evaluate |python3| expression
Bram Moolenaarf42dd3c2017-01-28 16:06:38 +01002362pyxeval({expr}) any evaluate |python_x| expression
Bram Moolenaar81edd172016-04-14 13:51:37 +02002363range({expr} [, {max} [, {stride}]])
Bram Moolenaard8b02732005-01-14 21:48:43 +00002364 List items from {expr} to {max}
Bram Moolenaar6e5ea8d2019-01-12 22:47:31 +01002365readfile({fname} [, {type} [, {max}]])
Bram Moolenaar26a60b42005-02-22 08:49:11 +00002366 List get list of lines from file {fname}
Bram Moolenaarf2732452018-06-03 14:47:35 +02002367reg_executing() String get the executing register name
Bram Moolenaar0b6d9112018-05-22 20:35:17 +02002368reg_recording() String get the recording register name
Bram Moolenaar81edd172016-04-14 13:51:37 +02002369reltime([{start} [, {end}]]) List get time value
2370reltimefloat({time}) Float turn the time value into a Float
2371reltimestr({time}) String turn time value into a String
Bram Moolenaar3c2881d2017-03-21 19:18:29 +01002372remote_expr({server}, {string} [, {idvar} [, {timeout}]])
Bram Moolenaar071d4272004-06-13 20:20:40 +00002373 String send expression
Bram Moolenaar81edd172016-04-14 13:51:37 +02002374remote_foreground({server}) Number bring Vim server to the foreground
2375remote_peek({serverid} [, {retvar}])
Bram Moolenaar071d4272004-06-13 20:20:40 +00002376 Number check for reply string
Bram Moolenaar3c2881d2017-03-21 19:18:29 +01002377remote_read({serverid} [, {timeout}])
2378 String read reply string
Bram Moolenaar81edd172016-04-14 13:51:37 +02002379remote_send({server}, {string} [, {idvar}])
Bram Moolenaar071d4272004-06-13 20:20:40 +00002380 String send key sequence
Bram Moolenaar7416f3e2017-03-18 18:10:13 +01002381remote_startserver({name}) none become server {name}
Bram Moolenaar802a0d92016-06-26 16:17:58 +02002382remove({list}, {idx} [, {end}]) any remove items {idx}-{end} from {list}
Bram Moolenaar81edd172016-04-14 13:51:37 +02002383remove({dict}, {key}) any remove entry {key} from {dict}
2384rename({from}, {to}) Number rename (move) file from {from} to {to}
2385repeat({expr}, {count}) String repeat {expr} {count} times
2386resolve({filename}) String get filename a shortcut points to
2387reverse({list}) List reverse {list} in-place
2388round({expr}) Float round off {expr}
2389screenattr({row}, {col}) Number attribute at screen position
2390screenchar({row}, {col}) Number character at screen position
Bram Moolenaar9750bb12012-12-05 16:10:42 +01002391screencol() Number current cursor column
2392screenrow() Number current cursor row
Bram Moolenaar81edd172016-04-14 13:51:37 +02002393search({pattern} [, {flags} [, {stopline} [, {timeout}]]])
Bram Moolenaar76929292008-01-06 19:07:36 +00002394 Number search for {pattern}
Bram Moolenaar81edd172016-04-14 13:51:37 +02002395searchdecl({name} [, {global} [, {thisblock}]])
Bram Moolenaar446cb832008-06-24 21:56:24 +00002396 Number search for variable declaration
Bram Moolenaar81edd172016-04-14 13:51:37 +02002397searchpair({start}, {middle}, {end} [, {flags} [, {skip} [...]]])
Bram Moolenaard7ee7ce2005-01-03 21:02:03 +00002398 Number search for other end of start/end pair
Bram Moolenaar81edd172016-04-14 13:51:37 +02002399searchpairpos({start}, {middle}, {end} [, {flags} [, {skip} [...]]])
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00002400 List search for other end of start/end pair
Bram Moolenaar81edd172016-04-14 13:51:37 +02002401searchpos({pattern} [, {flags} [, {stopline} [, {timeout}]]])
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00002402 List search for {pattern}
Bram Moolenaar81edd172016-04-14 13:51:37 +02002403server2client({clientid}, {string})
Bram Moolenaar071d4272004-06-13 20:20:40 +00002404 Number send reply string
2405serverlist() String get a list of available servers
Bram Moolenaar95bafa22018-10-02 13:26:25 +02002406setbufline({expr}, {lnum}, {text})
2407 Number set line {lnum} to {text} in buffer
Bram Moolenaarb31cf2b2017-09-02 19:45:19 +02002408 {expr}
Bram Moolenaar81edd172016-04-14 13:51:37 +02002409setbufvar({expr}, {varname}, {val})
2410 none set {varname} in buffer {expr} to {val}
2411setcharsearch({dict}) Dict set character search from {dict}
2412setcmdpos({pos}) Number set cursor position in command-line
2413setfperm({fname}, {mode}) Number set {fname} file permissions to {mode}
2414setline({lnum}, {line}) Number set line {lnum} to {line}
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01002415setloclist({nr}, {list} [, {action} [, {what}]])
Bram Moolenaar17c7c012006-01-26 22:25:15 +00002416 Number modify location list using {list}
Bram Moolenaar81edd172016-04-14 13:51:37 +02002417setmatches({list}) Number restore a list of matches
2418setpos({expr}, {list}) Number set the {expr} position to {list}
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01002419setqflist({list} [, {action} [, {what}]])
Bram Moolenaard823fa92016-08-12 16:29:27 +02002420 Number modify quickfix list using {list}
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01002421setreg({n}, {v} [, {opt}]) Number set register to value and type
Bram Moolenaar81edd172016-04-14 13:51:37 +02002422settabvar({nr}, {varname}, {val}) none set {varname} in tab page {nr} to {val}
2423settabwinvar({tabnr}, {winnr}, {varname}, {val})
2424 none set {varname} in window {winnr} in tab
2425 page {tabnr} to {val}
Bram Moolenaarf49cc602018-11-11 15:21:05 +01002426settagstack({nr}, {dict} [, {action}])
2427 Number modify tag stack using {dict}
Bram Moolenaar81edd172016-04-14 13:51:37 +02002428setwinvar({nr}, {varname}, {val}) none set {varname} in window {nr} to {val}
2429sha256({string}) String SHA256 checksum of {string}
2430shellescape({string} [, {special}])
Bram Moolenaar05bb9532008-07-04 09:44:11 +00002431 String escape {string} for use as shell
Bram Moolenaar60a495f2006-10-03 12:44:42 +00002432 command argument
Bram Moolenaarf9514162018-11-22 03:08:29 +01002433shiftwidth([{col}]) Number effective value of 'shiftwidth'
Bram Moolenaar162b7142018-12-21 15:17:36 +01002434sign_define({name} [, {dict}]) Number define or update a sign
2435sign_getdefined([{name}]) List get a list of defined signs
2436sign_getplaced([{expr} [, {dict}]])
2437 List get a list of placed signs
Bram Moolenaar6b7b7192019-01-11 13:42:41 +01002438sign_jump({id}, {group}, {expr})
2439 Number jump to a sign
Bram Moolenaar162b7142018-12-21 15:17:36 +01002440sign_place({id}, {group}, {name}, {expr} [, {dict}])
2441 Number place a sign
2442sign_undefine([{name}]) Number undefine a sign
2443sign_unplace({group} [, {dict}])
2444 Number unplace a sign
Bram Moolenaar81edd172016-04-14 13:51:37 +02002445simplify({filename}) String simplify filename as much as possible
2446sin({expr}) Float sine of {expr}
2447sinh({expr}) Float hyperbolic sine of {expr}
2448sort({list} [, {func} [, {dict}]])
Bram Moolenaar5f894962011-06-19 02:55:37 +02002449 List sort {list}, using {func} to compare
Bram Moolenaar81edd172016-04-14 13:51:37 +02002450soundfold({word}) String sound-fold {word}
Bram Moolenaard857f0e2005-06-21 22:37:39 +00002451spellbadword() String badly spelled word at cursor
Bram Moolenaar81edd172016-04-14 13:51:37 +02002452spellsuggest({word} [, {max} [, {capital}]])
Bram Moolenaarc54b8a72005-09-30 21:20:29 +00002453 List spelling suggestions
Bram Moolenaar81edd172016-04-14 13:51:37 +02002454split({expr} [, {pat} [, {keepempty}]])
Bram Moolenaar32466aa2006-02-24 23:53:04 +00002455 List make |List| from {pat} separated {expr}
Bram Moolenaar81edd172016-04-14 13:51:37 +02002456sqrt({expr}) Float square root of {expr}
2457str2float({expr}) Float convert String to Float
2458str2nr({expr} [, {base}]) Number convert String to Number
2459strchars({expr} [, {skipcc}]) Number character length of the String {expr}
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01002460strcharpart({str}, {start} [, {len}])
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02002461 String {len} characters of {str} at {start}
Bram Moolenaar81edd172016-04-14 13:51:37 +02002462strdisplaywidth({expr} [, {col}]) Number display length of the String {expr}
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01002463strftime({format} [, {time}]) String time in specified format
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02002464strgetchar({str}, {index}) Number get char {index} from {str}
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01002465stridx({haystack}, {needle} [, {start}])
Bram Moolenaar8f999f12005-01-25 22:12:55 +00002466 Number index of {needle} in {haystack}
Bram Moolenaar81edd172016-04-14 13:51:37 +02002467string({expr}) String String representation of {expr} value
2468strlen({expr}) Number length of the String {expr}
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01002469strpart({str}, {start} [, {len}])
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02002470 String {len} characters of {str} at {start}
Bram Moolenaar81edd172016-04-14 13:51:37 +02002471strridx({haystack}, {needle} [, {start}])
Bram Moolenaar677ee682005-01-27 14:41:15 +00002472 Number last index of {needle} in {haystack}
Bram Moolenaar81edd172016-04-14 13:51:37 +02002473strtrans({expr}) String translate string to make it printable
2474strwidth({expr}) Number display cell length of the String {expr}
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01002475submatch({nr} [, {list}]) String or List
Bram Moolenaar41571762014-04-02 19:00:58 +02002476 specific match in ":s" or substitute()
Bram Moolenaar81edd172016-04-14 13:51:37 +02002477substitute({expr}, {pat}, {sub}, {flags})
Bram Moolenaar071d4272004-06-13 20:20:40 +00002478 String all {pat} in {expr} replaced with {sub}
Bram Moolenaar00f123a2018-08-21 20:28:54 +02002479swapinfo({fname}) Dict information about swap file {fname}
Bram Moolenaar110bd602018-09-16 18:46:59 +02002480swapname({expr}) String swap file of buffer {expr}
Bram Moolenaar81edd172016-04-14 13:51:37 +02002481synID({lnum}, {col}, {trans}) Number syntax ID at {lnum} and {col}
2482synIDattr({synID}, {what} [, {mode}])
Bram Moolenaar071d4272004-06-13 20:20:40 +00002483 String attribute {what} of syntax ID {synID}
Bram Moolenaar81edd172016-04-14 13:51:37 +02002484synIDtrans({synID}) Number translated syntax ID of {synID}
Bram Moolenaara06ecab2016-07-16 14:47:36 +02002485synconcealed({lnum}, {col}) List info about concealing
Bram Moolenaar81edd172016-04-14 13:51:37 +02002486synstack({lnum}, {col}) List stack of syntax IDs at {lnum} and {col}
2487system({expr} [, {input}]) String output of shell command/filter {expr}
2488systemlist({expr} [, {input}]) List output of shell command/filter {expr}
Bram Moolenaar802a0d92016-06-26 16:17:58 +02002489tabpagebuflist([{arg}]) List list of buffer numbers in tab page
Bram Moolenaar81edd172016-04-14 13:51:37 +02002490tabpagenr([{arg}]) Number number of current or last tab page
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01002491tabpagewinnr({tabarg} [, {arg}]) Number number of current window in tab page
2492taglist({expr} [, {filename}]) List list of tags matching {expr}
Bram Moolenaar446cb832008-06-24 21:56:24 +00002493tagfiles() List tags files used
Bram Moolenaar81edd172016-04-14 13:51:37 +02002494tan({expr}) Float tangent of {expr}
2495tanh({expr}) Float hyperbolic tangent of {expr}
Bram Moolenaar975b5272016-03-15 23:10:59 +01002496tempname() String name for a temporary file
Bram Moolenaard96ff162018-02-18 22:13:29 +01002497term_dumpdiff({filename}, {filename} [, {options}])
2498 Number display difference between two dumps
2499term_dumpload({filename} [, {options}])
2500 Number displaying a screen dump
Bram Moolenaar6bb2cdf2018-02-24 19:53:53 +01002501term_dumpwrite({buf}, {filename} [, {options}])
Bram Moolenaard96ff162018-02-18 22:13:29 +01002502 none dump terminal window contents
Bram Moolenaare41e3b42017-08-11 16:24:50 +02002503term_getaltscreen({buf}) Number get the alternate screen flag
Bram Moolenaarf59c6e82018-04-10 15:59:11 +02002504term_getansicolors({buf}) List get ANSI palette in GUI color mode
Bram Moolenaar45356542017-08-06 17:53:31 +02002505term_getattr({attr}, {what}) Number get the value of attribute {what}
Bram Moolenaar97870002017-07-30 18:28:38 +02002506term_getcursor({buf}) List get the cursor position of a terminal
Bram Moolenaarc6df10e2017-07-29 20:15:08 +02002507term_getjob({buf}) Job get the job associated with a terminal
Bram Moolenaarc2ce52c2017-08-01 18:35:38 +02002508term_getline({buf}, {row}) String get a line of text from a terminal
Bram Moolenaar82b9ca02017-08-08 23:06:46 +02002509term_getscrolled({buf}) Number get the scroll count of a terminal
Bram Moolenaarc6df10e2017-07-29 20:15:08 +02002510term_getsize({buf}) List get the size of a terminal
Bram Moolenaarb000e322017-07-30 19:38:21 +02002511term_getstatus({buf}) String get the status of a terminal
2512term_gettitle({buf}) String get the title of a terminal
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01002513term_gettty({buf}, [{input}]) String get the tty name of a terminal
Bram Moolenaarc6df10e2017-07-29 20:15:08 +02002514term_list() List get the list of terminal buffers
Bram Moolenaarc2ce52c2017-08-01 18:35:38 +02002515term_scrape({buf}, {row}) List get row of a terminal screen
Bram Moolenaarc6df10e2017-07-29 20:15:08 +02002516term_sendkeys({buf}, {keys}) none send keystrokes to a terminal
Bram Moolenaarf59c6e82018-04-10 15:59:11 +02002517term_setansicolors({buf}, {colors})
2518 none set ANSI palette in GUI color mode
Bram Moolenaar7dda86f2018-04-20 22:36:41 +02002519term_setkill({buf}, {how}) none set signal to stop job in terminal
Bram Moolenaarb5b75622018-03-09 22:22:21 +01002520term_setrestore({buf}, {command}) none set command to restore terminal
Bram Moolenaar7dda86f2018-04-20 22:36:41 +02002521term_setsize({buf}, {rows}, {cols})
2522 none set the size of a terminal
Bram Moolenaar2c64ca12018-10-19 16:22:31 +02002523term_start({cmd}, {options}) Number open a terminal window and run a job
Bram Moolenaarf3402b12017-08-06 19:07:08 +02002524term_wait({buf} [, {time}]) Number wait for screen to be updated
Bram Moolenaar8e8df252016-05-25 21:23:21 +02002525test_alloc_fail({id}, {countdown}, {repeat})
2526 none make memory allocation fail
Bram Moolenaar6f1d9a02016-07-24 14:12:38 +02002527test_autochdir() none enable 'autochdir' during startup
Bram Moolenaar95bafa22018-10-02 13:26:25 +02002528test_feedinput({string}) none add key sequence to input buffer
Bram Moolenaar574860b2016-05-24 17:33:34 +02002529test_garbagecollect_now() none free memory right now for testing
Bram Moolenaare0c31f62017-03-01 15:07:05 +01002530test_ignore_error({expr}) none ignore a specific error
Bram Moolenaarc0f5a782019-01-13 15:16:13 +01002531test_null_blob() Blob null value for testing
Bram Moolenaar574860b2016-05-24 17:33:34 +02002532test_null_channel() Channel null value for testing
2533test_null_dict() Dict null value for testing
2534test_null_job() Job null value for testing
2535test_null_list() List null value for testing
2536test_null_partial() Funcref null value for testing
2537test_null_string() String null value for testing
Bram Moolenaar2c64ca12018-10-19 16:22:31 +02002538test_option_not_set({name}) none reset flag indicating option was set
2539test_override({expr}, {val}) none test with Vim internal overrides
Bram Moolenaarab186732018-09-14 21:27:06 +02002540test_scrollbar({which}, {value}, {dragging})
2541 none scroll in the GUI for testing
Bram Moolenaarc95a3022016-06-12 23:01:46 +02002542test_settime({expr}) none set current time for testing
Bram Moolenaar8e97bd72016-08-06 22:05:07 +02002543timer_info([{id}]) List information about timers
Bram Moolenaarb73598e2016-08-07 18:22:53 +02002544timer_pause({id}, {pause}) none pause or unpause a timer
Bram Moolenaar81edd172016-04-14 13:51:37 +02002545timer_start({time}, {callback} [, {options}])
Bram Moolenaar975b5272016-03-15 23:10:59 +01002546 Number create a timer
Bram Moolenaar81edd172016-04-14 13:51:37 +02002547timer_stop({timer}) none stop a timer
Bram Moolenaarb73598e2016-08-07 18:22:53 +02002548timer_stopall() none stop all timers
Bram Moolenaar81edd172016-04-14 13:51:37 +02002549tolower({expr}) String the String {expr} switched to lowercase
2550toupper({expr}) String the String {expr} switched to uppercase
2551tr({src}, {fromstr}, {tostr}) String translate chars of {src} in {fromstr}
Bram Moolenaar8299df92004-07-10 09:47:34 +00002552 to chars in {tostr}
Bram Moolenaard473c8c2018-08-11 18:00:22 +02002553trim({text} [, {mask}]) String trim characters in {mask} from {text}
Bram Moolenaar81edd172016-04-14 13:51:37 +02002554trunc({expr}) Float truncate Float {expr}
2555type({name}) Number type of variable {name}
2556undofile({name}) String undo file name for {name}
Bram Moolenaara800b422010-06-27 01:15:55 +02002557undotree() List undo file tree
Bram Moolenaar81edd172016-04-14 13:51:37 +02002558uniq({list} [, {func} [, {dict}]])
Bram Moolenaar327aa022014-03-25 18:24:23 +01002559 List remove adjacent duplicates from a list
Bram Moolenaar81edd172016-04-14 13:51:37 +02002560values({dict}) List values in {dict}
2561virtcol({expr}) Number screen column of cursor or mark
2562visualmode([expr]) String last visual mode used
Bram Moolenaar8738fc12013-02-20 17:59:11 +01002563wildmenumode() Number whether 'wildmenu' mode is active
Bram Moolenaar81edd172016-04-14 13:51:37 +02002564win_findbuf({bufnr}) List find windows containing {bufnr}
2565win_getid([{win} [, {tab}]]) Number get window ID for {win} in {tab}
2566win_gotoid({expr}) Number go to window with ID {expr}
2567win_id2tabwin({expr}) List get tab and window nr from window ID
2568win_id2win({expr}) Number get window nr from window ID
Bram Moolenaar22044dc2017-12-02 15:43:37 +01002569win_screenpos({nr}) List get screen position of window {nr}
Bram Moolenaar81edd172016-04-14 13:51:37 +02002570winbufnr({nr}) Number buffer number of window {nr}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002571wincol() Number window column of the cursor
Bram Moolenaar81edd172016-04-14 13:51:37 +02002572winheight({nr}) Number height of window {nr}
Bram Moolenaar0f6b4f02018-08-21 16:56:34 +02002573winlayout([{tabnr}]) List layout of windows in tab {tabnr}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002574winline() Number window line of the cursor
Bram Moolenaar81edd172016-04-14 13:51:37 +02002575winnr([{expr}]) Number number of current window
Bram Moolenaard7ee7ce2005-01-03 21:02:03 +00002576winrestcmd() String returns command to restore window sizes
Bram Moolenaar81edd172016-04-14 13:51:37 +02002577winrestview({dict}) none restore view of current window
Bram Moolenaar87b5ca52006-03-04 21:55:31 +00002578winsaveview() Dict save view of current window
Bram Moolenaar81edd172016-04-14 13:51:37 +02002579winwidth({nr}) Number width of window {nr}
Bram Moolenaared767a22016-01-03 22:49:16 +01002580wordcount() Dict get byte/char/word statistics
Bram Moolenaar6e5ea8d2019-01-12 22:47:31 +01002581writefile({object}, {fname} [, {flags}])
2582 Number write |Blob| or |List| of lines to file
Bram Moolenaara06ecab2016-07-16 14:47:36 +02002583xor({expr}, {expr}) Number bitwise XOR
Bram Moolenaar071d4272004-06-13 20:20:40 +00002584
Bram Moolenaar03413f42016-04-12 21:07:15 +02002585
Bram Moolenaar446cb832008-06-24 21:56:24 +00002586abs({expr}) *abs()*
2587 Return the absolute value of {expr}. When {expr} evaluates to
2588 a |Float| abs() returns a |Float|. When {expr} can be
2589 converted to a |Number| abs() returns a |Number|. Otherwise
2590 abs() gives an error message and returns -1.
2591 Examples: >
2592 echo abs(1.456)
2593< 1.456 >
2594 echo abs(-5.456)
2595< 5.456 >
2596 echo abs(-4)
2597< 4
2598 {only available when compiled with the |+float| feature}
2599
Bram Moolenaardb7c6862010-05-21 16:33:48 +02002600
2601acos({expr}) *acos()*
2602 Return the arc cosine of {expr} measured in radians, as a
Bram Moolenaar9855d6b2010-07-18 14:34:51 +02002603 |Float| in the range of [0, pi].
2604 {expr} must evaluate to a |Float| or a |Number| in the range
Bram Moolenaardb7c6862010-05-21 16:33:48 +02002605 [-1, 1].
2606 Examples: >
2607 :echo acos(0)
2608< 1.570796 >
2609 :echo acos(-0.5)
2610< 2.094395
Bram Moolenaardb84e452010-08-15 13:50:43 +02002611 {only available when compiled with the |+float| feature}
Bram Moolenaardb7c6862010-05-21 16:33:48 +02002612
2613
Bram Moolenaara14de3d2005-01-07 21:48:26 +00002614add({list}, {expr}) *add()*
Bram Moolenaar32466aa2006-02-24 23:53:04 +00002615 Append the item {expr} to |List| {list}. Returns the
2616 resulting |List|. Examples: >
Bram Moolenaara14de3d2005-01-07 21:48:26 +00002617 :let alist = add([1, 2, 3], item)
2618 :call add(mylist, "woodstock")
Bram Moolenaar32466aa2006-02-24 23:53:04 +00002619< Note that when {expr} is a |List| it is appended as a single
Bram Moolenaara23ccb82006-02-27 00:08:02 +00002620 item. Use |extend()| to concatenate |Lists|.
Bram Moolenaar13065c42005-01-08 16:08:21 +00002621 Use |insert()| to add an item at another position.
Bram Moolenaar071d4272004-06-13 20:20:40 +00002622
Bram Moolenaara14de3d2005-01-07 21:48:26 +00002623
Bram Moolenaard6e256c2011-12-14 15:32:50 +01002624and({expr}, {expr}) *and()*
2625 Bitwise AND on the two arguments. The arguments are converted
2626 to a number. A List, Dict or Float argument causes an error.
2627 Example: >
2628 :let flag = and(bits, 0x80)
2629
2630
Bram Moolenaar95bafa22018-10-02 13:26:25 +02002631append({lnum}, {text}) *append()*
2632 When {text} is a |List|: Append each item of the |List| as a
Bram Moolenaar32466aa2006-02-24 23:53:04 +00002633 text line below line {lnum} in the current buffer.
Bram Moolenaar95bafa22018-10-02 13:26:25 +02002634 Otherwise append {text} as one text line below line {lnum} in
Bram Moolenaar748bf032005-02-02 23:04:36 +00002635 the current buffer.
2636 {lnum} can be zero to insert a line before the first one.
Bram Moolenaara14de3d2005-01-07 21:48:26 +00002637 Returns 1 for failure ({lnum} out of range or out of memory),
Bram Moolenaar58b85342016-08-14 19:54:54 +02002638 0 for success. Example: >
Bram Moolenaard7ee7ce2005-01-03 21:02:03 +00002639 :let failed = append(line('$'), "# THE END")
Bram Moolenaara14de3d2005-01-07 21:48:26 +00002640 :let failed = append(0, ["Chapter 1", "the beginning"])
Bram Moolenaarca851592018-06-06 21:04:07 +02002641
2642appendbufline({expr}, {lnum}, {text}) *appendbufline()*
2643 Like |append()| but append the text in buffer {expr}.
2644
2645 For the use of {expr}, see |bufname()|.
2646
2647 {lnum} is used like with |append()|. Note that using |line()|
2648 would use the current buffer, not the one appending to.
2649 Use "$" to append at the end of the buffer.
2650
2651 On success 0 is returned, on failure 1 is returned.
2652
2653 If {expr} is not a valid buffer or {lnum} is not valid, an
2654 error message is given. Example: >
2655 :let failed = appendbufline(13, 0, "# THE START")
Bram Moolenaard7ee7ce2005-01-03 21:02:03 +00002656<
Bram Moolenaar071d4272004-06-13 20:20:40 +00002657 *argc()*
Bram Moolenaare6e39892018-10-25 12:32:11 +02002658argc([{winid}])
2659 The result is the number of files in the argument list. See
2660 |arglist|.
2661 If {winid} is not supplied, the argument list of the current
2662 window is used.
2663 If {winid} is -1, the global argument list is used.
2664 Otherwise {winid} specifies the window of which the argument
2665 list is used: either the window number or the window ID.
2666 Returns -1 if the {winid} argument is invalid.
Bram Moolenaar071d4272004-06-13 20:20:40 +00002667
2668 *argidx()*
2669argidx() The result is the current index in the argument list. 0 is
2670 the first file. argc() - 1 is the last one. See |arglist|.
2671
Bram Moolenaar2d1fe052014-05-28 18:22:57 +02002672 *arglistid()*
Bram Moolenaare0fa3742016-02-20 15:47:01 +01002673arglistid([{winnr} [, {tabnr}]])
Bram Moolenaar2d1fe052014-05-28 18:22:57 +02002674 Return the argument list ID. This is a number which
2675 identifies the argument list being used. Zero is used for the
Bram Moolenaarfb539272014-08-22 19:21:47 +02002676 global argument list. See |arglist|.
Bram Moolenaare6e39892018-10-25 12:32:11 +02002677 Returns -1 if the arguments are invalid.
Bram Moolenaar2d1fe052014-05-28 18:22:57 +02002678
2679 Without arguments use the current window.
2680 With {winnr} only use this window in the current tab page.
2681 With {winnr} and {tabnr} use the window in the specified tab
2682 page.
Bram Moolenaar7571d552016-08-18 22:54:46 +02002683 {winnr} can be the window number or the |window-ID|.
Bram Moolenaar2d1fe052014-05-28 18:22:57 +02002684
Bram Moolenaar071d4272004-06-13 20:20:40 +00002685 *argv()*
Bram Moolenaare6e39892018-10-25 12:32:11 +02002686argv([{nr} [, {winid}])
2687 The result is the {nr}th file in the argument list. See
2688 |arglist|. "argv(0)" is the first one. Example: >
Bram Moolenaar071d4272004-06-13 20:20:40 +00002689 :let i = 0
2690 :while i < argc()
Bram Moolenaar446cb832008-06-24 21:56:24 +00002691 : let f = escape(fnameescape(argv(i)), '.')
Bram Moolenaar071d4272004-06-13 20:20:40 +00002692 : exe 'amenu Arg.' . f . ' :e ' . f . '<CR>'
2693 : let i = i + 1
2694 :endwhile
Bram Moolenaare6e39892018-10-25 12:32:11 +02002695< Without the {nr} argument, or when {nr} is -1, a |List| with
2696 the whole |arglist| is returned.
2697
2698 The {winid} argument specifies the window ID, see |argc()|.
Bram Moolenaare2f98b92006-03-29 21:18:24 +00002699
Bram Moolenaarb48e96f2018-02-13 12:26:14 +01002700assert_beeps({cmd}) *assert_beeps()*
2701 Run {cmd} and add an error message to |v:errors| if it does
2702 NOT produce a beep or visual bell.
Bram Moolenaar65a54642018-04-28 16:56:53 +02002703 Also see |assert_fails()| and |assert-return|.
Bram Moolenaarb48e96f2018-02-13 12:26:14 +01002704
Bram Moolenaar683fa182015-11-30 21:38:24 +01002705 *assert_equal()*
Bram Moolenaara803c7f2016-01-15 15:31:39 +01002706assert_equal({expected}, {actual} [, {msg}])
Bram Moolenaar43345542015-11-29 17:35:35 +01002707 When {expected} and {actual} are not equal an error message is
Bram Moolenaar65a54642018-04-28 16:56:53 +02002708 added to |v:errors| and 1 is returned. Otherwise zero is
2709 returned |assert-return|.
Bram Moolenaar43345542015-11-29 17:35:35 +01002710 There is no automatic conversion, the String "4" is different
2711 from the Number 4. And the number 4 is different from the
2712 Float 4.0. The value of 'ignorecase' is not used here, case
2713 always matters.
Bram Moolenaar683fa182015-11-30 21:38:24 +01002714 When {msg} is omitted an error in the form "Expected
2715 {expected} but got {actual}" is produced.
Bram Moolenaar43345542015-11-29 17:35:35 +01002716 Example: >
Bram Moolenaar683fa182015-11-30 21:38:24 +01002717 assert_equal('foo', 'bar')
Bram Moolenaar43345542015-11-29 17:35:35 +01002718< Will result in a string to be added to |v:errors|:
2719 test.vim line 12: Expected 'foo' but got 'bar' ~
2720
Bram Moolenaard96ff162018-02-18 22:13:29 +01002721 *assert_equalfile()*
2722assert_equalfile({fname-one}, {fname-two})
2723 When the files {fname-one} and {fname-two} do not contain
2724 exactly the same text an error message is added to |v:errors|.
Bram Moolenaar65a54642018-04-28 16:56:53 +02002725 Also see |assert-return|.
Bram Moolenaard96ff162018-02-18 22:13:29 +01002726 When {fname-one} or {fname-two} does not exist the error will
2727 mention that.
2728 Mainly useful with |terminal-diff|.
2729
Bram Moolenaara803c7f2016-01-15 15:31:39 +01002730assert_exception({error} [, {msg}]) *assert_exception()*
2731 When v:exception does not contain the string {error} an error
Bram Moolenaar65a54642018-04-28 16:56:53 +02002732 message is added to |v:errors|. Also see |assert-return|.
Bram Moolenaara803c7f2016-01-15 15:31:39 +01002733 This can be used to assert that a command throws an exception.
2734 Using the error number, followed by a colon, avoids problems
2735 with translations: >
2736 try
2737 commandthatfails
2738 call assert_false(1, 'command should have failed')
2739 catch
2740 call assert_exception('E492:')
2741 endtry
2742
Bram Moolenaar2c64ca12018-10-19 16:22:31 +02002743assert_fails({cmd} [, {error} [, {msg}]]) *assert_fails()*
Bram Moolenaara260b872016-01-15 20:48:22 +01002744 Run {cmd} and add an error message to |v:errors| if it does
Bram Moolenaar65a54642018-04-28 16:56:53 +02002745 NOT produce an error. Also see |assert-return|.
Bram Moolenaar25de4c22016-11-06 14:48:06 +01002746 When {error} is given it must match in |v:errmsg|.
Bram Moolenaarb48e96f2018-02-13 12:26:14 +01002747 Note that beeping is not considered an error, and some failing
2748 commands only beep. Use |assert_beeps()| for those.
Bram Moolenaara260b872016-01-15 20:48:22 +01002749
Bram Moolenaara803c7f2016-01-15 15:31:39 +01002750assert_false({actual} [, {msg}]) *assert_false()*
Bram Moolenaar43345542015-11-29 17:35:35 +01002751 When {actual} is not false an error message is added to
Bram Moolenaar9d87a372018-12-18 21:41:50 +01002752 |v:errors|, like with |assert_equal()|.
Bram Moolenaar65a54642018-04-28 16:56:53 +02002753 Also see |assert-return|.
Bram Moolenaar6463ca22016-02-13 17:04:46 +01002754 A value is false when it is zero. When {actual} is not a
Bram Moolenaar43345542015-11-29 17:35:35 +01002755 number the assert fails.
Bram Moolenaar61c04492016-07-23 15:35:35 +02002756 When {msg} is omitted an error in the form
2757 "Expected False but got {actual}" is produced.
2758
2759assert_inrange({lower}, {upper}, {actual} [, {msg}]) *assert_inrange()*
2760 This asserts number values. When {actual} is lower than
2761 {lower} or higher than {upper} an error message is added to
Bram Moolenaar65a54642018-04-28 16:56:53 +02002762 |v:errors|. Also see |assert-return|.
Bram Moolenaar61c04492016-07-23 15:35:35 +02002763 When {msg} is omitted an error in the form
2764 "Expected range {lower} - {upper}, but got {actual}" is
2765 produced.
Bram Moolenaar43345542015-11-29 17:35:35 +01002766
Bram Moolenaarea6553b2016-03-27 15:13:38 +02002767 *assert_match()*
2768assert_match({pattern}, {actual} [, {msg}])
2769 When {pattern} does not match {actual} an error message is
Bram Moolenaar65a54642018-04-28 16:56:53 +02002770 added to |v:errors|. Also see |assert-return|.
Bram Moolenaarea6553b2016-03-27 15:13:38 +02002771
2772 {pattern} is used as with |=~|: The matching is always done
2773 like 'magic' was set and 'cpoptions' is empty, no matter what
2774 the actual value of 'magic' or 'cpoptions' is.
2775
2776 {actual} is used as a string, automatic conversion applies.
2777 Use "^" and "$" to match with the start and end of the text.
2778 Use both to match the whole text.
2779
Bram Moolenaar61c04492016-07-23 15:35:35 +02002780 When {msg} is omitted an error in the form
2781 "Pattern {pattern} does not match {actual}" is produced.
Bram Moolenaarea6553b2016-03-27 15:13:38 +02002782 Example: >
2783 assert_match('^f.*o$', 'foobar')
2784< Will result in a string to be added to |v:errors|:
2785 test.vim line 12: Pattern '^f.*o$' does not match 'foobar' ~
2786
Bram Moolenaarb50e5f52016-04-03 20:57:20 +02002787 *assert_notequal()*
2788assert_notequal({expected}, {actual} [, {msg}])
2789 The opposite of `assert_equal()`: add an error message to
2790 |v:errors| when {expected} and {actual} are equal.
Bram Moolenaar65a54642018-04-28 16:56:53 +02002791 Also see |assert-return|.
Bram Moolenaarb50e5f52016-04-03 20:57:20 +02002792
2793 *assert_notmatch()*
2794assert_notmatch({pattern}, {actual} [, {msg}])
2795 The opposite of `assert_match()`: add an error message to
2796 |v:errors| when {pattern} matches {actual}.
Bram Moolenaar65a54642018-04-28 16:56:53 +02002797 Also see |assert-return|.
Bram Moolenaarb50e5f52016-04-03 20:57:20 +02002798
Bram Moolenaar42205552017-03-18 19:42:22 +01002799assert_report({msg}) *assert_report()*
2800 Report a test failure directly, using {msg}.
Bram Moolenaar65a54642018-04-28 16:56:53 +02002801 Always returns one.
Bram Moolenaar42205552017-03-18 19:42:22 +01002802
2803assert_true({actual} [, {msg}]) *assert_true()*
Bram Moolenaar43345542015-11-29 17:35:35 +01002804 When {actual} is not true an error message is added to
Bram Moolenaara803c7f2016-01-15 15:31:39 +01002805 |v:errors|, like with |assert_equal()|.
Bram Moolenaar65a54642018-04-28 16:56:53 +02002806 Also see |assert-return|.
Bram Moolenaare381d3d2016-07-07 14:50:41 +02002807 A value is TRUE when it is a non-zero number. When {actual}
Bram Moolenaar43345542015-11-29 17:35:35 +01002808 is not a number the assert fails.
Bram Moolenaar683fa182015-11-30 21:38:24 +01002809 When {msg} is omitted an error in the form "Expected True but
2810 got {actual}" is produced.
Bram Moolenaar43345542015-11-29 17:35:35 +01002811
Bram Moolenaardb7c6862010-05-21 16:33:48 +02002812asin({expr}) *asin()*
Bram Moolenaar9855d6b2010-07-18 14:34:51 +02002813 Return the arc sine of {expr} measured in radians, as a |Float|
Bram Moolenaardb7c6862010-05-21 16:33:48 +02002814 in the range of [-pi/2, pi/2].
Bram Moolenaar9855d6b2010-07-18 14:34:51 +02002815 {expr} must evaluate to a |Float| or a |Number| in the range
Bram Moolenaardb7c6862010-05-21 16:33:48 +02002816 [-1, 1].
2817 Examples: >
2818 :echo asin(0.8)
2819< 0.927295 >
2820 :echo asin(-0.5)
2821< -0.523599
Bram Moolenaardb84e452010-08-15 13:50:43 +02002822 {only available when compiled with the |+float| feature}
Bram Moolenaardb7c6862010-05-21 16:33:48 +02002823
2824
Bram Moolenaar446cb832008-06-24 21:56:24 +00002825atan({expr}) *atan()*
2826 Return the principal value of the arc tangent of {expr}, in
2827 the range [-pi/2, +pi/2] radians, as a |Float|.
2828 {expr} must evaluate to a |Float| or a |Number|.
2829 Examples: >
2830 :echo atan(100)
2831< 1.560797 >
2832 :echo atan(-4.01)
2833< -1.326405
2834 {only available when compiled with the |+float| feature}
2835
Bram Moolenaardb7c6862010-05-21 16:33:48 +02002836
2837atan2({expr1}, {expr2}) *atan2()*
2838 Return the arc tangent of {expr1} / {expr2}, measured in
Bram Moolenaar9855d6b2010-07-18 14:34:51 +02002839 radians, as a |Float| in the range [-pi, pi].
2840 {expr1} and {expr2} must evaluate to a |Float| or a |Number|.
Bram Moolenaardb7c6862010-05-21 16:33:48 +02002841 Examples: >
2842 :echo atan2(-1, 1)
2843< -0.785398 >
2844 :echo atan2(1, -1)
2845< 2.356194
Bram Moolenaardb84e452010-08-15 13:50:43 +02002846 {only available when compiled with the |+float| feature}
Bram Moolenaardb7c6862010-05-21 16:33:48 +02002847
Bram Moolenaar246fe032017-11-19 19:56:27 +01002848balloon_show({expr}) *balloon_show()*
2849 Show {expr} inside the balloon. For the GUI {expr} is used as
2850 a string. For a terminal {expr} can be a list, which contains
2851 the lines of the balloon. If {expr} is not a list it will be
2852 split with |balloon_split()|.
2853
Bram Moolenaar214641f2017-03-05 17:04:09 +01002854 Example: >
Bram Moolenaar59716a22017-03-01 20:32:44 +01002855 func GetBalloonContent()
2856 " initiate getting the content
2857 return ''
2858 endfunc
2859 set balloonexpr=GetBalloonContent()
2860
2861 func BalloonCallback(result)
Bram Moolenaar214641f2017-03-05 17:04:09 +01002862 call balloon_show(a:result)
Bram Moolenaar59716a22017-03-01 20:32:44 +01002863 endfunc
2864<
2865 The intended use is that fetching the content of the balloon
2866 is initiated from 'balloonexpr'. It will invoke an
2867 asynchronous method, in which a callback invokes
2868 balloon_show(). The 'balloonexpr' itself can return an
2869 empty string or a placeholder.
Bram Moolenaar214641f2017-03-05 17:04:09 +01002870
2871 When showing a balloon is not possible nothing happens, no
2872 error message.
Bram Moolenaar95bafa22018-10-02 13:26:25 +02002873 {only available when compiled with the |+balloon_eval| or
2874 |+balloon_eval_term| feature}
Bram Moolenaardb7c6862010-05-21 16:33:48 +02002875
Bram Moolenaar246fe032017-11-19 19:56:27 +01002876balloon_split({msg}) *balloon_split()*
2877 Split {msg} into lines to be displayed in a balloon. The
2878 splits are made for the current window size and optimize to
2879 show debugger output.
2880 Returns a |List| with the split lines.
Bram Moolenaar95bafa22018-10-02 13:26:25 +02002881 {only available when compiled with the |+balloon_eval_term|
Bram Moolenaar669a8282017-11-19 20:13:05 +01002882 feature}
Bram Moolenaar246fe032017-11-19 19:56:27 +01002883
Bram Moolenaar071d4272004-06-13 20:20:40 +00002884 *browse()*
2885browse({save}, {title}, {initdir}, {default})
2886 Put up a file requester. This only works when "has("browse")"
Bram Moolenaare381d3d2016-07-07 14:50:41 +02002887 returns |TRUE| (only in some GUI versions).
Bram Moolenaar071d4272004-06-13 20:20:40 +00002888 The input fields are:
Bram Moolenaare381d3d2016-07-07 14:50:41 +02002889 {save} when |TRUE|, select file to write
Bram Moolenaar071d4272004-06-13 20:20:40 +00002890 {title} title for the requester
2891 {initdir} directory to start browsing in
2892 {default} default file name
2893 When the "Cancel" button is hit, something went wrong, or
2894 browsing is not possible, an empty string is returned.
2895
Bram Moolenaar7b0294c2004-10-11 10:16:09 +00002896 *browsedir()*
2897browsedir({title}, {initdir})
2898 Put up a directory requester. This only works when
Bram Moolenaare381d3d2016-07-07 14:50:41 +02002899 "has("browse")" returns |TRUE| (only in some GUI versions).
Bram Moolenaar7b0294c2004-10-11 10:16:09 +00002900 On systems where a directory browser is not supported a file
2901 browser is used. In that case: select a file in the directory
2902 to be used.
2903 The input fields are:
2904 {title} title for the requester
2905 {initdir} directory to start browsing in
2906 When the "Cancel" button is hit, something went wrong, or
2907 browsing is not possible, an empty string is returned.
2908
Bram Moolenaar071d4272004-06-13 20:20:40 +00002909bufexists({expr}) *bufexists()*
Bram Moolenaare381d3d2016-07-07 14:50:41 +02002910 The result is a Number, which is |TRUE| if a buffer called
Bram Moolenaar071d4272004-06-13 20:20:40 +00002911 {expr} exists.
Bram Moolenaar69a7cb42004-06-20 12:51:53 +00002912 If the {expr} argument is a number, buffer numbers are used.
Bram Moolenaara2a80162017-11-21 23:09:50 +01002913 Number zero is the alternate buffer for the current window.
2914
Bram Moolenaar071d4272004-06-13 20:20:40 +00002915 If the {expr} argument is a string it must match a buffer name
Bram Moolenaar69a7cb42004-06-20 12:51:53 +00002916 exactly. The name can be:
2917 - Relative to the current directory.
2918 - A full path.
Bram Moolenaar446cb832008-06-24 21:56:24 +00002919 - The name of a buffer with 'buftype' set to "nofile".
Bram Moolenaar69a7cb42004-06-20 12:51:53 +00002920 - A URL name.
Bram Moolenaar071d4272004-06-13 20:20:40 +00002921 Unlisted buffers will be found.
2922 Note that help files are listed by their short name in the
2923 output of |:buffers|, but bufexists() requires using their
2924 long name to be able to find them.
Bram Moolenaar446cb832008-06-24 21:56:24 +00002925 bufexists() may report a buffer exists, but to use the name
2926 with a |:buffer| command you may need to use |expand()|. Esp
2927 for MS-Windows 8.3 names in the form "c:\DOCUME~1"
Bram Moolenaar071d4272004-06-13 20:20:40 +00002928 Use "bufexists(0)" to test for the existence of an alternate
2929 file name.
2930 *buffer_exists()*
2931 Obsolete name: buffer_exists().
2932
2933buflisted({expr}) *buflisted()*
Bram Moolenaare381d3d2016-07-07 14:50:41 +02002934 The result is a Number, which is |TRUE| if a buffer called
Bram Moolenaar071d4272004-06-13 20:20:40 +00002935 {expr} exists and is listed (has the 'buflisted' option set).
Bram Moolenaar69a7cb42004-06-20 12:51:53 +00002936 The {expr} argument is used like with |bufexists()|.
Bram Moolenaar071d4272004-06-13 20:20:40 +00002937
2938bufloaded({expr}) *bufloaded()*
Bram Moolenaare381d3d2016-07-07 14:50:41 +02002939 The result is a Number, which is |TRUE| if a buffer called
Bram Moolenaar071d4272004-06-13 20:20:40 +00002940 {expr} exists and is loaded (shown in a window or hidden).
Bram Moolenaar69a7cb42004-06-20 12:51:53 +00002941 The {expr} argument is used like with |bufexists()|.
Bram Moolenaar071d4272004-06-13 20:20:40 +00002942
2943bufname({expr}) *bufname()*
2944 The result is the name of a buffer, as it is displayed by the
2945 ":ls" command.
2946 If {expr} is a Number, that buffer number's name is given.
2947 Number zero is the alternate buffer for the current window.
2948 If {expr} is a String, it is used as a |file-pattern| to match
Bram Moolenaar58b85342016-08-14 19:54:54 +02002949 with the buffer names. This is always done like 'magic' is
Bram Moolenaar071d4272004-06-13 20:20:40 +00002950 set and 'cpoptions' is empty. When there is more than one
2951 match an empty string is returned.
2952 "" or "%" can be used for the current buffer, "#" for the
2953 alternate buffer.
2954 A full match is preferred, otherwise a match at the start, end
Bram Moolenaaref2f6562007-05-06 13:32:59 +00002955 or middle of the buffer name is accepted. If you only want a
2956 full match then put "^" at the start and "$" at the end of the
2957 pattern.
Bram Moolenaar071d4272004-06-13 20:20:40 +00002958 Listed buffers are found first. If there is a single match
2959 with a listed buffer, that one is returned. Next unlisted
2960 buffers are searched for.
2961 If the {expr} is a String, but you want to use it as a buffer
2962 number, force it to be a Number by adding zero to it: >
2963 :echo bufname("3" + 0)
2964< If the buffer doesn't exist, or doesn't have a name, an empty
2965 string is returned. >
2966 bufname("#") alternate buffer name
2967 bufname(3) name of buffer 3
2968 bufname("%") name of current buffer
2969 bufname("file2") name of buffer where "file2" matches.
2970< *buffer_name()*
2971 Obsolete name: buffer_name().
2972
2973 *bufnr()*
Bram Moolenaar65c923a2006-03-03 22:56:30 +00002974bufnr({expr} [, {create}])
2975 The result is the number of a buffer, as it is displayed by
Bram Moolenaar071d4272004-06-13 20:20:40 +00002976 the ":ls" command. For the use of {expr}, see |bufname()|
Bram Moolenaar65c923a2006-03-03 22:56:30 +00002977 above.
2978 If the buffer doesn't exist, -1 is returned. Or, if the
2979 {create} argument is present and not zero, a new, unlisted,
2980 buffer is created and its number is returned.
Bram Moolenaar071d4272004-06-13 20:20:40 +00002981 bufnr("$") is the last buffer: >
2982 :let last_buffer = bufnr("$")
2983< The result is a Number, which is the highest buffer number
2984 of existing buffers. Note that not all buffers with a smaller
2985 number necessarily exist, because ":bwipeout" may have removed
2986 them. Use bufexists() to test for the existence of a buffer.
2987 *buffer_number()*
2988 Obsolete name: buffer_number().
2989 *last_buffer_nr()*
2990 Obsolete name for bufnr("$"): last_buffer_nr().
2991
Bram Moolenaarb3619a92016-06-04 17:58:52 +02002992bufwinid({expr}) *bufwinid()*
Bram Moolenaar7571d552016-08-18 22:54:46 +02002993 The result is a Number, which is the |window-ID| of the first
Bram Moolenaarb3619a92016-06-04 17:58:52 +02002994 window associated with buffer {expr}. For the use of {expr},
Bram Moolenaar58b85342016-08-14 19:54:54 +02002995 see |bufname()| above. If buffer {expr} doesn't exist or
Bram Moolenaarb3619a92016-06-04 17:58:52 +02002996 there is no such window, -1 is returned. Example: >
2997
2998 echo "A window containing buffer 1 is " . (bufwinid(1))
2999<
3000 Only deals with the current tab page.
3001
Bram Moolenaar071d4272004-06-13 20:20:40 +00003002bufwinnr({expr}) *bufwinnr()*
3003 The result is a Number, which is the number of the first
3004 window associated with buffer {expr}. For the use of {expr},
Bram Moolenaar58b85342016-08-14 19:54:54 +02003005 see |bufname()| above. If buffer {expr} doesn't exist or
Bram Moolenaar071d4272004-06-13 20:20:40 +00003006 there is no such window, -1 is returned. Example: >
3007
3008 echo "A window containing buffer 1 is " . (bufwinnr(1))
3009
3010< The number can be used with |CTRL-W_w| and ":wincmd w"
3011 |:wincmd|.
Bram Moolenaaref2f6562007-05-06 13:32:59 +00003012 Only deals with the current tab page.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003013
Bram Moolenaar071d4272004-06-13 20:20:40 +00003014byte2line({byte}) *byte2line()*
3015 Return the line number that contains the character at byte
3016 count {byte} in the current buffer. This includes the
3017 end-of-line character, depending on the 'fileformat' option
3018 for the current buffer. The first character has byte count
3019 one.
3020 Also see |line2byte()|, |go| and |:goto|.
3021 {not available when compiled without the |+byte_offset|
3022 feature}
3023
Bram Moolenaarab79bcb2004-07-18 21:34:53 +00003024byteidx({expr}, {nr}) *byteidx()*
3025 Return byte index of the {nr}'th character in the string
3026 {expr}. Use zero for the first character, it returns zero.
3027 This function is only useful when there are multibyte
3028 characters, otherwise the returned value is equal to {nr}.
Bram Moolenaar0ffbbf92013-11-02 23:29:26 +01003029 Composing characters are not counted separately, their byte
3030 length is added to the preceding base character. See
3031 |byteidxcomp()| below for counting composing characters
3032 separately.
Bram Moolenaarab79bcb2004-07-18 21:34:53 +00003033 Example : >
3034 echo matchstr(str, ".", byteidx(str, 3))
3035< will display the fourth character. Another way to do the
3036 same: >
3037 let s = strpart(str, byteidx(str, 3))
3038 echo strpart(s, 0, byteidx(s, 1))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02003039< Also see |strgetchar()| and |strcharpart()|.
3040
3041 If there are less than {nr} characters -1 is returned.
Bram Moolenaarab79bcb2004-07-18 21:34:53 +00003042 If there are exactly {nr} characters the length of the string
Bram Moolenaar0ffbbf92013-11-02 23:29:26 +01003043 in bytes is returned.
3044
3045byteidxcomp({expr}, {nr}) *byteidxcomp()*
3046 Like byteidx(), except that a composing character is counted
3047 as a separate character. Example: >
3048 let s = 'e' . nr2char(0x301)
3049 echo byteidx(s, 1)
3050 echo byteidxcomp(s, 1)
3051 echo byteidxcomp(s, 2)
3052< The first and third echo result in 3 ('e' plus composing
3053 character is 3 bytes), the second echo results in 1 ('e' is
3054 one byte).
3055 Only works different from byteidx() when 'encoding' is set to
3056 a Unicode encoding.
Bram Moolenaarab79bcb2004-07-18 21:34:53 +00003057
Bram Moolenaar2fda12f2005-01-15 22:14:15 +00003058call({func}, {arglist} [, {dict}]) *call()* *E699*
Bram Moolenaar32466aa2006-02-24 23:53:04 +00003059 Call function {func} with the items in |List| {arglist} as
Bram Moolenaarde8866b2005-01-06 23:24:37 +00003060 arguments.
Bram Moolenaar32466aa2006-02-24 23:53:04 +00003061 {func} can either be a |Funcref| or the name of a function.
Bram Moolenaarde8866b2005-01-06 23:24:37 +00003062 a:firstline and a:lastline are set to the cursor line.
3063 Returns the return value of the called function.
Bram Moolenaar2fda12f2005-01-15 22:14:15 +00003064 {dict} is for functions with the "dict" attribute. It will be
3065 used to set the local variable "self". |Dictionary-function|
Bram Moolenaarde8866b2005-01-06 23:24:37 +00003066
Bram Moolenaar446cb832008-06-24 21:56:24 +00003067ceil({expr}) *ceil()*
3068 Return the smallest integral value greater than or equal to
3069 {expr} as a |Float| (round up).
3070 {expr} must evaluate to a |Float| or a |Number|.
3071 Examples: >
3072 echo ceil(1.456)
3073< 2.0 >
3074 echo ceil(-5.456)
3075< -5.0 >
3076 echo ceil(4.0)
3077< 4.0
3078 {only available when compiled with the |+float| feature}
3079
Bram Moolenaar4b785f62016-11-29 21:54:44 +01003080ch_canread({handle}) *ch_canread()*
3081 Return non-zero when there is something to read from {handle}.
3082 {handle} can be a Channel or a Job that has a Channel.
3083
3084 This is useful to read from a channel at a convenient time,
3085 e.g. from a timer.
3086
3087 Note that messages are dropped when the channel does not have
3088 a callback. Add a close callback to avoid that.
3089
3090 {only available when compiled with the |+channel| feature}
3091
Bram Moolenaar5f148ec2016-03-07 22:59:26 +01003092ch_close({handle}) *ch_close()*
3093 Close {handle}. See |channel-close|.
Bram Moolenaar4b785f62016-11-29 21:54:44 +01003094 {handle} can be a Channel or a Job that has a Channel.
Bram Moolenaar0874a832016-09-01 15:11:51 +02003095 A close callback is not invoked.
3096
3097 {only available when compiled with the |+channel| feature}
3098
3099ch_close_in({handle}) *ch_close_in()*
3100 Close the "in" part of {handle}. See |channel-close-in|.
Bram Moolenaar4b785f62016-11-29 21:54:44 +01003101 {handle} can be a Channel or a Job that has a Channel.
Bram Moolenaar0874a832016-09-01 15:11:51 +02003102 A close callback is not invoked.
Bram Moolenaar328da0d2016-03-04 22:22:32 +01003103
Bram Moolenaar835dc632016-02-07 14:27:38 +01003104 {only available when compiled with the |+channel| feature}
Bram Moolenaarf57969a2016-02-02 20:47:49 +01003105
Bram Moolenaar5f148ec2016-03-07 22:59:26 +01003106ch_evalexpr({handle}, {expr} [, {options}]) *ch_evalexpr()*
3107 Send {expr} over {handle}. The {expr} is encoded
Bram Moolenaar8b1862a2016-02-27 19:21:24 +01003108 according to the type of channel. The function cannot be used
Bram Moolenaardae8d212016-02-27 22:40:16 +01003109 with a raw channel. See |channel-use|.
Bram Moolenaar4b785f62016-11-29 21:54:44 +01003110 {handle} can be a Channel or a Job that has a Channel.
Bram Moolenaar8b1862a2016-02-27 19:21:24 +01003111 *E917*
3112 {options} must be a Dictionary. It must not have a "callback"
Bram Moolenaar4f3f6682016-03-26 23:01:59 +01003113 entry. It can have a "timeout" entry to specify the timeout
3114 for this specific request.
Bram Moolenaar8b1862a2016-02-27 19:21:24 +01003115
3116 ch_evalexpr() waits for a response and returns the decoded
3117 expression. When there is an error or timeout it returns an
3118 empty string.
3119
3120 {only available when compiled with the |+channel| feature}
3121
Bram Moolenaar5f148ec2016-03-07 22:59:26 +01003122ch_evalraw({handle}, {string} [, {options}]) *ch_evalraw()*
3123 Send {string} over {handle}.
Bram Moolenaar4b785f62016-11-29 21:54:44 +01003124 {handle} can be a Channel or a Job that has a Channel.
Bram Moolenaar5f148ec2016-03-07 22:59:26 +01003125
Bram Moolenaar8b1862a2016-02-27 19:21:24 +01003126 Works like |ch_evalexpr()|, but does not encode the request or
3127 decode the response. The caller is responsible for the
3128 correct contents. Also does not add a newline for a channel
3129 in NL mode, the caller must do that. The NL in the response
3130 is removed.
Bram Moolenaar01164a62017-11-02 22:58:42 +01003131 Note that Vim does not know when the text received on a raw
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01003132 channel is complete, it may only return the first part and you
Bram Moolenaarc0f5a782019-01-13 15:16:13 +01003133 need to use |ch_readraw()| to fetch the rest.
Bram Moolenaar8b1862a2016-02-27 19:21:24 +01003134 See |channel-use|.
3135
3136 {only available when compiled with the |+channel| feature}
3137
Bram Moolenaar5f148ec2016-03-07 22:59:26 +01003138ch_getbufnr({handle}, {what}) *ch_getbufnr()*
3139 Get the buffer number that {handle} is using for {what}.
Bram Moolenaar4b785f62016-11-29 21:54:44 +01003140 {handle} can be a Channel or a Job that has a Channel.
Bram Moolenaarc7f0ebc2016-02-27 21:10:09 +01003141 {what} can be "err" for stderr, "out" for stdout or empty for
3142 socket output.
3143 Returns -1 when there is no buffer.
3144 {only available when compiled with the |+channel| feature}
3145
Bram Moolenaar02e83b42016-02-21 20:10:26 +01003146ch_getjob({channel}) *ch_getjob()*
3147 Get the Job associated with {channel}.
3148 If there is no job calling |job_status()| on the returned Job
3149 will result in "fail".
3150
3151 {only available when compiled with the |+channel| and
3152 |+job| features}
3153
Bram Moolenaar03602ec2016-03-20 20:57:45 +01003154ch_info({handle}) *ch_info()*
3155 Returns a Dictionary with information about {handle}. The
3156 items are:
3157 "id" number of the channel
Bram Moolenaar7ef38102016-09-26 22:36:58 +02003158 "status" "open", "buffered" or "closed", like
3159 ch_status()
Bram Moolenaar03602ec2016-03-20 20:57:45 +01003160 When opened with ch_open():
3161 "hostname" the hostname of the address
3162 "port" the port of the address
3163 "sock_status" "open" or "closed"
3164 "sock_mode" "NL", "RAW", "JSON" or "JS"
3165 "sock_io" "socket"
3166 "sock_timeout" timeout in msec
3167 When opened with job_start():
Bram Moolenaar7ef38102016-09-26 22:36:58 +02003168 "out_status" "open", "buffered" or "closed"
Bram Moolenaar03602ec2016-03-20 20:57:45 +01003169 "out_mode" "NL", "RAW", "JSON" or "JS"
3170 "out_io" "null", "pipe", "file" or "buffer"
3171 "out_timeout" timeout in msec
Bram Moolenaar7ef38102016-09-26 22:36:58 +02003172 "err_status" "open", "buffered" or "closed"
Bram Moolenaar03602ec2016-03-20 20:57:45 +01003173 "err_mode" "NL", "RAW", "JSON" or "JS"
3174 "err_io" "out", "null", "pipe", "file" or "buffer"
3175 "err_timeout" timeout in msec
3176 "in_status" "open" or "closed"
3177 "in_mode" "NL", "RAW", "JSON" or "JS"
3178 "in_io" "null", "pipe", "file" or "buffer"
3179 "in_timeout" timeout in msec
3180
Bram Moolenaar5f148ec2016-03-07 22:59:26 +01003181ch_log({msg} [, {handle}]) *ch_log()*
Bram Moolenaare0fa3742016-02-20 15:47:01 +01003182 Write {msg} in the channel log file, if it was opened with
3183 |ch_logfile()|.
Bram Moolenaar5f148ec2016-03-07 22:59:26 +01003184 When {handle} is passed the channel number is used for the
3185 message.
Bram Moolenaar51628222016-12-01 23:03:28 +01003186 {handle} can be a Channel or a Job that has a Channel. The
Bram Moolenaar2ec618c2016-10-01 14:47:05 +02003187 Channel must be open for the channel number to be used.
Bram Moolenaare0fa3742016-02-20 15:47:01 +01003188
3189ch_logfile({fname} [, {mode}]) *ch_logfile()*
Bram Moolenaar6463ca22016-02-13 17:04:46 +01003190 Start logging channel activity to {fname}.
Bram Moolenaar38a55632016-02-15 22:07:32 +01003191 When {fname} is an empty string: stop logging.
3192
Bram Moolenaar6463ca22016-02-13 17:04:46 +01003193 When {mode} is omitted or "a" append to the file.
3194 When {mode} is "w" start with an empty file.
Bram Moolenaar38a55632016-02-15 22:07:32 +01003195
Bram Moolenaar98aefe72018-12-13 22:20:09 +01003196 Use |ch_log()| to write log messages. The file is flushed
3197 after every message, on Unix you can use "tail -f" to see what
3198 is going on in real time.
Bram Moolenaar6463ca22016-02-13 17:04:46 +01003199
Bram Moolenaar82b9ca02017-08-08 23:06:46 +02003200 This function is not available in the |sandbox|.
3201 NOTE: the channel communication is stored in the file, be
3202 aware that this may contain confidential and privacy sensitive
3203 information, e.g. a password you type in a terminal window.
3204
Bram Moolenaar328da0d2016-03-04 22:22:32 +01003205
Bram Moolenaare0fa3742016-02-20 15:47:01 +01003206ch_open({address} [, {options}]) *ch_open()*
Bram Moolenaar3b5f9292016-01-28 22:37:01 +01003207 Open a channel to {address}. See |channel|.
Bram Moolenaar4f3f6682016-03-26 23:01:59 +01003208 Returns a Channel. Use |ch_status()| to check for failure.
Bram Moolenaar3b5f9292016-01-28 22:37:01 +01003209
3210 {address} has the form "hostname:port", e.g.,
3211 "localhost:8765".
3212
Bram Moolenaar4f3f6682016-03-26 23:01:59 +01003213 If {options} is given it must be a |Dictionary|.
3214 See |channel-open-options|.
3215
Bram Moolenaar835dc632016-02-07 14:27:38 +01003216 {only available when compiled with the |+channel| feature}
Bram Moolenaar3b5f9292016-01-28 22:37:01 +01003217
Bram Moolenaar5f148ec2016-03-07 22:59:26 +01003218ch_read({handle} [, {options}]) *ch_read()*
3219 Read from {handle} and return the received message.
Bram Moolenaar4b785f62016-11-29 21:54:44 +01003220 {handle} can be a Channel or a Job that has a Channel.
Bram Moolenaar74240d32017-12-10 15:26:15 +01003221 For a NL channel this waits for a NL to arrive, except when
3222 there is nothing more to read (channel was closed).
Bram Moolenaar4f3f6682016-03-26 23:01:59 +01003223 See |channel-more|.
3224 {only available when compiled with the |+channel| feature}
Bram Moolenaar02e83b42016-02-21 20:10:26 +01003225
Bram Moolenaar6e5ea8d2019-01-12 22:47:31 +01003226ch_readblob({handle} [, {options}]) *ch_readblob()*
3227 Like ch_read() but reads binary data and returns a Blob.
3228 See |channel-more|.
3229 {only available when compiled with the |+channel| feature}
3230
Bram Moolenaar5f148ec2016-03-07 22:59:26 +01003231ch_readraw({handle} [, {options}]) *ch_readraw()*
Bram Moolenaar02e83b42016-02-21 20:10:26 +01003232 Like ch_read() but for a JS and JSON channel does not decode
Bram Moolenaar74240d32017-12-10 15:26:15 +01003233 the message. For a NL channel it does not block waiting for
3234 the NL to arrive, but otherwise works like ch_read().
3235 See |channel-more|.
Bram Moolenaar4f3f6682016-03-26 23:01:59 +01003236 {only available when compiled with the |+channel| feature}
Bram Moolenaar02e83b42016-02-21 20:10:26 +01003237
Bram Moolenaar5f148ec2016-03-07 22:59:26 +01003238ch_sendexpr({handle}, {expr} [, {options}]) *ch_sendexpr()*
3239 Send {expr} over {handle}. The {expr} is encoded
Bram Moolenaarcbebd482016-02-07 23:02:56 +01003240 according to the type of channel. The function cannot be used
Bram Moolenaar4f3f6682016-03-26 23:01:59 +01003241 with a raw channel.
3242 See |channel-use|. *E912*
Bram Moolenaar4b785f62016-11-29 21:54:44 +01003243 {handle} can be a Channel or a Job that has a Channel.
Bram Moolenaarf57969a2016-02-02 20:47:49 +01003244
Bram Moolenaar835dc632016-02-07 14:27:38 +01003245 {only available when compiled with the |+channel| feature}
3246
Bram Moolenaar6e5ea8d2019-01-12 22:47:31 +01003247ch_sendraw({handle}, {expr} [, {options}]) *ch_sendraw()*
3248 Send string or Blob {expr} over {handle}.
Bram Moolenaarcbebd482016-02-07 23:02:56 +01003249 Works like |ch_sendexpr()|, but does not encode the request or
3250 decode the response. The caller is responsible for the
Bram Moolenaar910b8aa2016-02-16 21:03:07 +01003251 correct contents. Also does not add a newline for a channel
3252 in NL mode, the caller must do that. The NL in the response
3253 is removed.
3254 See |channel-use|.
Bram Moolenaarf57969a2016-02-02 20:47:49 +01003255
Bram Moolenaar835dc632016-02-07 14:27:38 +01003256 {only available when compiled with the |+channel| feature}
3257
Bram Moolenaar5f148ec2016-03-07 22:59:26 +01003258ch_setoptions({handle}, {options}) *ch_setoptions()*
3259 Set options on {handle}:
Bram Moolenaare0fa3742016-02-20 15:47:01 +01003260 "callback" the channel callback
3261 "timeout" default read timeout in msec
Bram Moolenaar02e83b42016-02-21 20:10:26 +01003262 "mode" mode for the whole channel
Bram Moolenaare0fa3742016-02-20 15:47:01 +01003263 See |ch_open()| for more explanation.
Bram Moolenaar4b785f62016-11-29 21:54:44 +01003264 {handle} can be a Channel or a Job that has a Channel.
Bram Moolenaare0fa3742016-02-20 15:47:01 +01003265
Bram Moolenaar02e83b42016-02-21 20:10:26 +01003266 Note that changing the mode may cause queued messages to be
3267 lost.
3268
Bram Moolenaare0fa3742016-02-20 15:47:01 +01003269 These options cannot be changed:
Bram Moolenaar7571d552016-08-18 22:54:46 +02003270 "waittime" only applies to |ch_open()|
Bram Moolenaare0fa3742016-02-20 15:47:01 +01003271
Bram Moolenaar7ef38102016-09-26 22:36:58 +02003272ch_status({handle} [, {options}]) *ch_status()*
Bram Moolenaar5f148ec2016-03-07 22:59:26 +01003273 Return the status of {handle}:
Bram Moolenaar38a55632016-02-15 22:07:32 +01003274 "fail" failed to open the channel
3275 "open" channel can be used
Bram Moolenaar06481422016-04-30 15:13:38 +02003276 "buffered" channel can be read, not written to
Bram Moolenaar38a55632016-02-15 22:07:32 +01003277 "closed" channel can not be used
Bram Moolenaar4b785f62016-11-29 21:54:44 +01003278 {handle} can be a Channel or a Job that has a Channel.
Bram Moolenaar06481422016-04-30 15:13:38 +02003279 "buffered" is used when the channel was closed but there is
3280 still data that can be obtained with |ch_read()|.
Bram Moolenaar38a55632016-02-15 22:07:32 +01003281
Bram Moolenaar7ef38102016-09-26 22:36:58 +02003282 If {options} is given it can contain a "part" entry to specify
3283 the part of the channel to return the status for: "out" or
3284 "err". For example, to get the error status: >
3285 ch_status(job, {"part": "err"})
3286<
Bram Moolenaar214641f2017-03-05 17:04:09 +01003287changenr() *changenr()*
3288 Return the number of the most recent change. This is the same
3289 number as what is displayed with |:undolist| and can be used
3290 with the |:undo| command.
3291 When a change was made it is the number of that change. After
3292 redo it is the number of the redone change. After undo it is
3293 one less than the number of the undone change.
3294
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01003295char2nr({expr} [, {utf8}]) *char2nr()*
Bram Moolenaar214641f2017-03-05 17:04:09 +01003296 Return number value of the first char in {expr}. Examples: >
3297 char2nr(" ") returns 32
3298 char2nr("ABC") returns 65
3299< When {utf8} is omitted or zero, the current 'encoding' is used.
3300 Example for "utf-8": >
Bram Moolenaar98ef2332018-03-18 14:44:37 +01003301 char2nr("á") returns 225
3302 char2nr("á"[0]) returns 195
Bram Moolenaar214641f2017-03-05 17:04:09 +01003303< With {utf8} set to 1, always treat as utf-8 characters.
3304 A combining character is a separate character.
3305 |nr2char()| does the opposite.
3306
3307cindent({lnum}) *cindent()*
3308 Get the amount of indent for line {lnum} according the C
3309 indenting rules, as with 'cindent'.
3310 The indent is counted in spaces, the value of 'tabstop' is
3311 relevant. {lnum} is used just like in |getline()|.
3312 When {lnum} is invalid or Vim was not compiled the |+cindent|
3313 feature, -1 is returned.
3314 See |C-indenting|.
3315
3316clearmatches() *clearmatches()*
3317 Clears all matches previously defined by |matchadd()| and the
3318 |:match| commands.
3319
3320 *col()*
3321col({expr}) The result is a Number, which is the byte index of the column
3322 position given with {expr}. The accepted positions are:
3323 . the cursor position
3324 $ the end of the cursor line (the result is the
3325 number of bytes in the cursor line plus one)
3326 'x position of mark x (if the mark is not set, 0 is
3327 returned)
3328 v In Visual mode: the start of the Visual area (the
3329 cursor is the end). When not in Visual mode
3330 returns the cursor position. Differs from |'<| in
3331 that it's updated right away.
3332 Additionally {expr} can be [lnum, col]: a |List| with the line
3333 and column number. Most useful when the column is "$", to get
3334 the last column of a specific line. When "lnum" or "col" is
3335 out of range then col() returns zero.
3336 To get the line number use |line()|. To get both use
3337 |getpos()|.
3338 For the screen column position use |virtcol()|.
3339 Note that only marks in the current file can be used.
3340 Examples: >
3341 col(".") column of cursor
3342 col("$") length of cursor line plus one
3343 col("'t") column of mark t
3344 col("'" . markname) column of mark markname
3345< The first column is 1. 0 is returned for an error.
3346 For an uppercase mark the column may actually be in another
3347 buffer.
3348 For the cursor position, when 'virtualedit' is active, the
3349 column is one higher if the cursor is after the end of the
3350 line. This can be used to obtain the column in Insert mode: >
3351 :imap <F2> <C-O>:let save_ve = &ve<CR>
3352 \<C-O>:set ve=all<CR>
3353 \<C-O>:echo col(".") . "\n" <Bar>
3354 \let &ve = save_ve<CR>
3355<
3356
3357complete({startcol}, {matches}) *complete()* *E785*
3358 Set the matches for Insert mode completion.
3359 Can only be used in Insert mode. You need to use a mapping
3360 with CTRL-R = (see |i_CTRL-R|). It does not work after CTRL-O
3361 or with an expression mapping.
3362 {startcol} is the byte offset in the line where the completed
3363 text start. The text up to the cursor is the original text
3364 that will be replaced by the matches. Use col('.') for an
3365 empty string. "col('.') - 1" will replace one character by a
3366 match.
3367 {matches} must be a |List|. Each |List| item is one match.
3368 See |complete-items| for the kind of items that are possible.
3369 Note that the after calling this function you need to avoid
3370 inserting anything that would cause completion to stop.
3371 The match can be selected with CTRL-N and CTRL-P as usual with
3372 Insert mode completion. The popup menu will appear if
3373 specified, see |ins-completion-menu|.
3374 Example: >
3375 inoremap <F5> <C-R>=ListMonths()<CR>
3376
3377 func! ListMonths()
3378 call complete(col('.'), ['January', 'February', 'March',
3379 \ 'April', 'May', 'June', 'July', 'August', 'September',
3380 \ 'October', 'November', 'December'])
3381 return ''
3382 endfunc
3383< This isn't very useful, but it shows how it works. Note that
3384 an empty string is returned to avoid a zero being inserted.
3385
3386complete_add({expr}) *complete_add()*
3387 Add {expr} to the list of matches. Only to be used by the
3388 function specified with the 'completefunc' option.
3389 Returns 0 for failure (empty string or out of memory),
3390 1 when the match was added, 2 when the match was already in
3391 the list.
3392 See |complete-functions| for an explanation of {expr}. It is
3393 the same as one item in the list that 'omnifunc' would return.
3394
3395complete_check() *complete_check()*
3396 Check for a key typed while looking for completion matches.
3397 This is to be used when looking for matches takes some time.
3398 Returns |TRUE| when searching for matches is to be aborted,
3399 zero otherwise.
3400 Only to be used by the function specified with the
3401 'completefunc' option.
3402
3403 *confirm()*
3404confirm({msg} [, {choices} [, {default} [, {type}]]])
3405 Confirm() offers the user a dialog, from which a choice can be
3406 made. It returns the number of the choice. For the first
3407 choice this is 1.
3408 Note: confirm() is only supported when compiled with dialog
3409 support, see |+dialog_con| and |+dialog_gui|.
3410
3411 {msg} is displayed in a |dialog| with {choices} as the
3412 alternatives. When {choices} is missing or empty, "&OK" is
3413 used (and translated).
3414 {msg} is a String, use '\n' to include a newline. Only on
3415 some systems the string is wrapped when it doesn't fit.
3416
3417 {choices} is a String, with the individual choices separated
3418 by '\n', e.g. >
3419 confirm("Save changes?", "&Yes\n&No\n&Cancel")
3420< The letter after the '&' is the shortcut key for that choice.
3421 Thus you can type 'c' to select "Cancel". The shortcut does
3422 not need to be the first letter: >
3423 confirm("file has been modified", "&Save\nSave &All")
3424< For the console, the first letter of each choice is used as
3425 the default shortcut key.
3426
3427 The optional {default} argument is the number of the choice
3428 that is made if the user hits <CR>. Use 1 to make the first
3429 choice the default one. Use 0 to not set a default. If
3430 {default} is omitted, 1 is used.
3431
3432 The optional {type} argument gives the type of dialog. This
3433 is only used for the icon of the GTK, Mac, Motif and Win32
3434 GUI. It can be one of these values: "Error", "Question",
3435 "Info", "Warning" or "Generic". Only the first character is
3436 relevant. When {type} is omitted, "Generic" is used.
3437
3438 If the user aborts the dialog by pressing <Esc>, CTRL-C,
3439 or another valid interrupt key, confirm() returns 0.
3440
3441 An example: >
3442 :let choice = confirm("What do you want?", "&Apples\n&Oranges\n&Bananas", 2)
3443 :if choice == 0
3444 : echo "make up your mind!"
3445 :elseif choice == 3
3446 : echo "tasteful"
3447 :else
3448 : echo "I prefer bananas myself."
3449 :endif
3450< In a GUI dialog, buttons are used. The layout of the buttons
3451 depends on the 'v' flag in 'guioptions'. If it is included,
3452 the buttons are always put vertically. Otherwise, confirm()
3453 tries to put the buttons in one horizontal line. If they
3454 don't fit, a vertical layout is used anyway. For some systems
3455 the horizontal layout is always used.
3456
Bram Moolenaard7ee7ce2005-01-03 21:02:03 +00003457 *copy()*
Bram Moolenaar58b85342016-08-14 19:54:54 +02003458copy({expr}) Make a copy of {expr}. For Numbers and Strings this isn't
Bram Moolenaard7ee7ce2005-01-03 21:02:03 +00003459 different from using {expr} directly.
Bram Moolenaar32466aa2006-02-24 23:53:04 +00003460 When {expr} is a |List| a shallow copy is created. This means
3461 that the original |List| can be changed without changing the
Bram Moolenaar446cb832008-06-24 21:56:24 +00003462 copy, and vice versa. But the items are identical, thus
Bram Moolenaar7823a3b2016-02-11 21:08:32 +01003463 changing an item changes the contents of both |Lists|.
3464 A |Dictionary| is copied in a similar way as a |List|.
3465 Also see |deepcopy()|.
Bram Moolenaard7ee7ce2005-01-03 21:02:03 +00003466
Bram Moolenaar446cb832008-06-24 21:56:24 +00003467cos({expr}) *cos()*
3468 Return the cosine of {expr}, measured in radians, as a |Float|.
3469 {expr} must evaluate to a |Float| or a |Number|.
3470 Examples: >
3471 :echo cos(100)
3472< 0.862319 >
3473 :echo cos(-4.01)
3474< -0.646043
3475 {only available when compiled with the |+float| feature}
3476
Bram Moolenaardb7c6862010-05-21 16:33:48 +02003477
3478cosh({expr}) *cosh()*
Bram Moolenaar9855d6b2010-07-18 14:34:51 +02003479 Return the hyperbolic cosine of {expr} as a |Float| in the range
Bram Moolenaardb7c6862010-05-21 16:33:48 +02003480 [1, inf].
Bram Moolenaar9855d6b2010-07-18 14:34:51 +02003481 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaardb7c6862010-05-21 16:33:48 +02003482 Examples: >
3483 :echo cosh(0.5)
3484< 1.127626 >
3485 :echo cosh(-0.5)
3486< -1.127626
Bram Moolenaardb84e452010-08-15 13:50:43 +02003487 {only available when compiled with the |+float| feature}
Bram Moolenaardb7c6862010-05-21 16:33:48 +02003488
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01003489
Bram Moolenaar2fda12f2005-01-15 22:14:15 +00003490count({comp}, {expr} [, {ic} [, {start}]]) *count()*
Bram Moolenaarde8866b2005-01-06 23:24:37 +00003491 Return the number of times an item with value {expr} appears
Bram Moolenaar9966b212017-07-28 16:46:57 +02003492 in |String|, |List| or |Dictionary| {comp}.
3493
Bram Moolenaar2fda12f2005-01-15 22:14:15 +00003494 If {start} is given then start with the item with this index.
Bram Moolenaar32466aa2006-02-24 23:53:04 +00003495 {start} can only be used with a |List|.
Bram Moolenaar9966b212017-07-28 16:46:57 +02003496
Bram Moolenaare381d3d2016-07-07 14:50:41 +02003497 When {ic} is given and it's |TRUE| then case is ignored.
Bram Moolenaarde8866b2005-01-06 23:24:37 +00003498
Bram Moolenaar9966b212017-07-28 16:46:57 +02003499 When {comp} is a string then the number of not overlapping
Bram Moolenaar338e47f2017-12-19 11:55:26 +01003500 occurrences of {expr} is returned. Zero is returned when
3501 {expr} is an empty string.
Bram Moolenaarde8866b2005-01-06 23:24:37 +00003502
Bram Moolenaar071d4272004-06-13 20:20:40 +00003503 *cscope_connection()*
3504cscope_connection([{num} , {dbpath} [, {prepend}]])
3505 Checks for the existence of a |cscope| connection. If no
3506 parameters are specified, then the function returns:
3507 0, if cscope was not available (not compiled in), or
3508 if there are no cscope connections;
3509 1, if there is at least one cscope connection.
3510
3511 If parameters are specified, then the value of {num}
3512 determines how existence of a cscope connection is checked:
3513
3514 {num} Description of existence check
3515 ----- ------------------------------
3516 0 Same as no parameters (e.g., "cscope_connection()").
3517 1 Ignore {prepend}, and use partial string matches for
3518 {dbpath}.
3519 2 Ignore {prepend}, and use exact string matches for
3520 {dbpath}.
3521 3 Use {prepend}, use partial string matches for both
3522 {dbpath} and {prepend}.
3523 4 Use {prepend}, use exact string matches for both
3524 {dbpath} and {prepend}.
3525
3526 Note: All string comparisons are case sensitive!
3527
3528 Examples. Suppose we had the following (from ":cs show"): >
3529
3530 # pid database name prepend path
3531 0 27664 cscope.out /usr/local
3532<
3533 Invocation Return Val ~
3534 ---------- ---------- >
3535 cscope_connection() 1
3536 cscope_connection(1, "out") 1
3537 cscope_connection(2, "out") 0
3538 cscope_connection(3, "out") 0
3539 cscope_connection(3, "out", "local") 1
3540 cscope_connection(4, "out") 0
3541 cscope_connection(4, "out", "local") 0
3542 cscope_connection(4, "cscope.out", "/usr/local") 1
3543<
Bram Moolenaar0b238792006-03-02 22:49:12 +00003544cursor({lnum}, {col} [, {off}]) *cursor()*
3545cursor({list})
Bram Moolenaaref2f6562007-05-06 13:32:59 +00003546 Positions the cursor at the column (byte count) {col} in the
3547 line {lnum}. The first column is one.
Bram Moolenaar493c1782014-05-28 14:34:46 +02003548
Bram Moolenaar0b238792006-03-02 22:49:12 +00003549 When there is one argument {list} this is used as a |List|
Bram Moolenaar493c1782014-05-28 14:34:46 +02003550 with two, three or four item:
Bram Moolenaar03413f42016-04-12 21:07:15 +02003551 [{lnum}, {col}]
Bram Moolenaar493c1782014-05-28 14:34:46 +02003552 [{lnum}, {col}, {off}]
3553 [{lnum}, {col}, {off}, {curswant}]
Bram Moolenaar946e27a2014-06-25 18:50:27 +02003554 This is like the return value of |getpos()| or |getcurpos()|,
Bram Moolenaar6f6c0f82014-05-28 20:31:42 +02003555 but without the first item.
Bram Moolenaar493c1782014-05-28 14:34:46 +02003556
Bram Moolenaar071d4272004-06-13 20:20:40 +00003557 Does not change the jumplist.
3558 If {lnum} is greater than the number of lines in the buffer,
3559 the cursor will be positioned at the last line in the buffer.
3560 If {lnum} is zero, the cursor will stay in the current line.
Bram Moolenaar6f16eb82005-08-23 21:02:42 +00003561 If {col} is greater than the number of bytes in the line,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003562 the cursor will be positioned at the last character in the
3563 line.
3564 If {col} is zero, the cursor will stay in the current column.
Bram Moolenaar6f6c0f82014-05-28 20:31:42 +02003565 If {curswant} is given it is used to set the preferred column
Bram Moolenaar34401cc2014-08-29 15:12:19 +02003566 for vertical movement. Otherwise {col} is used.
Bram Moolenaar2f3b5102014-11-19 18:54:17 +01003567
Bram Moolenaar0b238792006-03-02 22:49:12 +00003568 When 'virtualedit' is used {off} specifies the offset in
3569 screen columns from the start of the character. E.g., a
Bram Moolenaard46bbc72007-05-12 14:38:41 +00003570 position within a <Tab> or after the last character.
Bram Moolenaar798b30b2009-04-22 10:56:16 +00003571 Returns 0 when the position could be set, -1 otherwise.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003572
Bram Moolenaar4551c0a2018-06-20 22:38:21 +02003573debugbreak({pid}) *debugbreak()*
3574 Specifically used to interrupt a program being debugged. It
3575 will cause process {pid} to get a SIGTRAP. Behavior for other
3576 processes is undefined. See |terminal-debugger|.
3577 {only available on MS-Windows}
Bram Moolenaard7ee7ce2005-01-03 21:02:03 +00003578
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01003579deepcopy({expr} [, {noref}]) *deepcopy()* *E698*
Bram Moolenaar58b85342016-08-14 19:54:54 +02003580 Make a copy of {expr}. For Numbers and Strings this isn't
Bram Moolenaard7ee7ce2005-01-03 21:02:03 +00003581 different from using {expr} directly.
Bram Moolenaar32466aa2006-02-24 23:53:04 +00003582 When {expr} is a |List| a full copy is created. This means
3583 that the original |List| can be changed without changing the
Bram Moolenaar6463ca22016-02-13 17:04:46 +01003584 copy, and vice versa. When an item is a |List| or
3585 |Dictionary|, a copy for it is made, recursively. Thus
3586 changing an item in the copy does not change the contents of
3587 the original |List|.
3588 A |Dictionary| is copied in a similar way as a |List|.
Bram Moolenaar32466aa2006-02-24 23:53:04 +00003589 When {noref} is omitted or zero a contained |List| or
3590 |Dictionary| is only copied once. All references point to
3591 this single copy. With {noref} set to 1 every occurrence of a
3592 |List| or |Dictionary| results in a new copy. This also means
3593 that a cyclic reference causes deepcopy() to fail.
Bram Moolenaar3a3a7232005-01-17 22:16:15 +00003594 *E724*
3595 Nesting is possible up to 100 levels. When there is an item
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003596 that refers back to a higher level making a deep copy with
3597 {noref} set to 1 will fail.
Bram Moolenaard7ee7ce2005-01-03 21:02:03 +00003598 Also see |copy()|.
3599
Bram Moolenaarda440d22016-01-16 21:27:23 +01003600delete({fname} [, {flags}]) *delete()*
3601 Without {flags} or with {flags} empty: Deletes the file by the
Bram Moolenaar43a34f92016-01-17 15:56:34 +01003602 name {fname}. This also works when {fname} is a symbolic link.
Bram Moolenaarda440d22016-01-16 21:27:23 +01003603
3604 When {flags} is "d": Deletes the directory by the name
Bram Moolenaar43a34f92016-01-17 15:56:34 +01003605 {fname}. This fails when directory {fname} is not empty.
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01003606
Bram Moolenaarda440d22016-01-16 21:27:23 +01003607 When {flags} is "rf": Deletes the directory by the name
Bram Moolenaar43a34f92016-01-17 15:56:34 +01003608 {fname} and everything in it, recursively. BE CAREFUL!
Bram Moolenaar36f44c22016-08-28 18:17:20 +02003609 Note: on MS-Windows it is not possible to delete a directory
3610 that is being used.
Bram Moolenaar818078d2016-08-27 21:58:42 +02003611
Bram Moolenaar43a34f92016-01-17 15:56:34 +01003612 A symbolic link itself is deleted, not what it points to.
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01003613
Bram Moolenaarda440d22016-01-16 21:27:23 +01003614 The result is a Number, which is 0 if the delete operation was
3615 successful and -1 when the deletion failed or partly failed.
3616
Bram Moolenaar32466aa2006-02-24 23:53:04 +00003617 Use |remove()| to delete an item from a |List|.
Bram Moolenaard79a2622018-06-07 18:17:46 +02003618 To delete a line from the buffer use |:delete| or
3619 |deletebufline()|.
3620
Bram Moolenaard473c8c2018-08-11 18:00:22 +02003621deletebufline({expr}, {first} [, {last}]) *deletebufline()*
Bram Moolenaard79a2622018-06-07 18:17:46 +02003622 Delete lines {first} to {last} (inclusive) from buffer {expr}.
3623 If {last} is omitted then delete line {first} only.
3624 On success 0 is returned, on failure 1 is returned.
3625
3626 For the use of {expr}, see |bufname()| above.
3627
Bram Moolenaar95bafa22018-10-02 13:26:25 +02003628 {first} and {last} are used like with |getline()|. Note that
Bram Moolenaard79a2622018-06-07 18:17:46 +02003629 when using |line()| this refers to the current buffer. Use "$"
3630 to refer to the last line in buffer {expr}.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003631
3632 *did_filetype()*
Bram Moolenaare381d3d2016-07-07 14:50:41 +02003633did_filetype() Returns |TRUE| when autocommands are being executed and the
Bram Moolenaar071d4272004-06-13 20:20:40 +00003634 FileType event has been triggered at least once. Can be used
3635 to avoid triggering the FileType event again in the scripts
3636 that detect the file type. |FileType|
Bram Moolenaar6aa8cea2017-06-05 14:44:35 +02003637 Returns |FALSE| when `:setf FALLBACK` was used.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003638 When editing another file, the counter is reset, thus this
3639 really checks if the FileType event has been triggered for the
3640 current buffer. This allows an autocommand that starts
3641 editing another buffer to set 'filetype' and load a syntax
3642 file.
3643
Bram Moolenaar47136d72004-10-12 20:02:24 +00003644diff_filler({lnum}) *diff_filler()*
3645 Returns the number of filler lines above line {lnum}.
3646 These are the lines that were inserted at this point in
3647 another diff'ed window. These filler lines are shown in the
3648 display but don't exist in the buffer.
3649 {lnum} is used like with |getline()|. Thus "." is the current
3650 line, "'m" mark m, etc.
3651 Returns 0 if the current window is not in diff mode.
3652
3653diff_hlID({lnum}, {col}) *diff_hlID()*
3654 Returns the highlight ID for diff mode at line {lnum} column
3655 {col} (byte index). When the current line does not have a
3656 diff change zero is returned.
3657 {lnum} is used like with |getline()|. Thus "." is the current
3658 line, "'m" mark m, etc.
3659 {col} is 1 for the leftmost column, {lnum} is 1 for the first
3660 line.
3661 The highlight ID can be used with |synIDattr()| to obtain
3662 syntax information about the highlighting.
3663
Bram Moolenaar13065c42005-01-08 16:08:21 +00003664empty({expr}) *empty()*
3665 Return the Number 1 if {expr} is empty, zero otherwise.
Bram Moolenaar835dc632016-02-07 14:27:38 +01003666 - A |List| or |Dictionary| is empty when it does not have any
3667 items.
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01003668 - A String is empty when its length is zero.
Bram Moolenaar835dc632016-02-07 14:27:38 +01003669 - A Number and Float is empty when its value is zero.
3670 - |v:false|, |v:none| and |v:null| are empty, |v:true| is not.
3671 - A Job is empty when it failed to start.
Bram Moolenaar38a55632016-02-15 22:07:32 +01003672 - A Channel is empty when it is closed.
Bram Moolenaar835dc632016-02-07 14:27:38 +01003673
Bram Moolenaar8f3f58f2010-01-06 20:52:26 +01003674 For a long |List| this is much faster than comparing the
Bram Moolenaar32466aa2006-02-24 23:53:04 +00003675 length with zero.
Bram Moolenaar13065c42005-01-08 16:08:21 +00003676
Bram Moolenaar071d4272004-06-13 20:20:40 +00003677escape({string}, {chars}) *escape()*
3678 Escape the characters in {chars} that occur in {string} with a
3679 backslash. Example: >
3680 :echo escape('c:\program files\vim', ' \')
3681< results in: >
3682 c:\\program\ files\\vim
Bram Moolenaarb4d5fba2017-09-11 19:31:28 +02003683< Also see |shellescape()| and |fnameescape()|.
Bram Moolenaar5f2bb9f2005-01-11 21:29:04 +00003684
Bram Moolenaar446cb832008-06-24 21:56:24 +00003685 *eval()*
Bram Moolenaar5f2bb9f2005-01-11 21:29:04 +00003686eval({string}) Evaluate {string} and return the result. Especially useful to
3687 turn the result of |string()| back into the original value.
Bram Moolenaar446cb832008-06-24 21:56:24 +00003688 This works for Numbers, Floats, Strings and composites of
3689 them. Also works for |Funcref|s that refer to existing
3690 functions.
Bram Moolenaar5f2bb9f2005-01-11 21:29:04 +00003691
Bram Moolenaar071d4272004-06-13 20:20:40 +00003692eventhandler() *eventhandler()*
3693 Returns 1 when inside an event handler. That is that Vim got
3694 interrupted while waiting for the user to type a character,
3695 e.g., when dropping a file on Vim. This means interactive
3696 commands cannot be used. Otherwise zero is returned.
3697
3698executable({expr}) *executable()*
3699 This function checks if an executable with the name {expr}
3700 exists. {expr} must be the name of the program without any
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003701 arguments.
3702 executable() uses the value of $PATH and/or the normal
3703 searchpath for programs. *PATHEXT*
3704 On MS-DOS and MS-Windows the ".exe", ".bat", etc. can
3705 optionally be included. Then the extensions in $PATHEXT are
Bram Moolenaar58b85342016-08-14 19:54:54 +02003706 tried. Thus if "foo.exe" does not exist, "foo.exe.bat" can be
3707 found. If $PATHEXT is not set then ".exe;.com;.bat;.cmd" is
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003708 used. A dot by itself can be used in $PATHEXT to try using
Bram Moolenaar58b85342016-08-14 19:54:54 +02003709 the name without an extension. When 'shell' looks like a
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003710 Unix shell, then the name is also tried without adding an
3711 extension.
3712 On MS-DOS and MS-Windows it only checks if the file exists and
3713 is not a directory, not if it's really executable.
Bram Moolenaar910f66f2006-04-05 20:41:53 +00003714 On MS-Windows an executable in the same directory as Vim is
3715 always found. Since this directory is added to $PATH it
3716 should also work to execute it |win32-PATH|.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003717 The result is a Number:
3718 1 exists
3719 0 does not exist
3720 -1 not implemented on this system
Bram Moolenaar6dc819b2018-07-03 16:42:19 +02003721 |exepath()| can be used to get the full path of an executable.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003722
Bram Moolenaar79815f12016-07-09 17:07:29 +02003723execute({command} [, {silent}]) *execute()*
3724 Execute an Ex command or commands and return the output as a
3725 string.
3726 {command} can be a string or a List. In case of a List the
3727 lines are executed one by one.
3728 This is equivalent to: >
3729 redir => var
3730 {command}
3731 redir END
3732<
3733 The optional {silent} argument can have these values:
3734 "" no `:silent` used
3735 "silent" `:silent` used
3736 "silent!" `:silent!` used
Bram Moolenaar214641f2017-03-05 17:04:09 +01003737 The default is "silent". Note that with "silent!", unlike
Bram Moolenaar069c1e72016-07-15 21:25:08 +02003738 `:redir`, error messages are dropped. When using an external
3739 command the screen may be messed up, use `system()` instead.
Bram Moolenaar79815f12016-07-09 17:07:29 +02003740 *E930*
3741 It is not possible to use `:redir` anywhere in {command}.
3742
3743 To get a list of lines use |split()| on the result: >
Bram Moolenaar063b9d12016-07-09 20:21:48 +02003744 split(execute('args'), "\n")
Bram Moolenaar79815f12016-07-09 17:07:29 +02003745
3746< When used recursively the output of the recursive call is not
3747 included in the output of the higher level call.
3748
Bram Moolenaarc7f02552014-04-01 21:00:59 +02003749exepath({expr}) *exepath()*
3750 If {expr} is an executable and is either an absolute path, a
3751 relative path or found in $PATH, return the full path.
3752 Note that the current directory is used when {expr} starts
3753 with "./", which may be a problem for Vim: >
3754 echo exepath(v:progpath)
Bram Moolenaar7e38ea22014-04-05 22:55:53 +02003755< If {expr} cannot be found in $PATH or is not executable then
Bram Moolenaarc7f02552014-04-01 21:00:59 +02003756 an empty string is returned.
3757
Bram Moolenaar071d4272004-06-13 20:20:40 +00003758 *exists()*
Bram Moolenaar8e97bd72016-08-06 22:05:07 +02003759exists({expr}) The result is a Number, which is |TRUE| if {expr} is defined,
3760 zero otherwise.
3761
3762 For checking for a supported feature use |has()|.
3763 For checking if a file exists use |filereadable()|.
3764
3765 The {expr} argument is a string, which contains one of these:
Bram Moolenaar071d4272004-06-13 20:20:40 +00003766 &option-name Vim option (only checks if it exists,
3767 not if it really works)
3768 +option-name Vim option that works.
3769 $ENVNAME environment variable (could also be
3770 done by comparing with an empty
3771 string)
3772 *funcname built-in function (see |functions|)
3773 or user defined function (see
Bram Moolenaarbcb98982014-05-01 14:08:19 +02003774 |user-functions|). Also works for a
3775 variable that is a Funcref.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003776 varname internal variable (see
Bram Moolenaar58b85342016-08-14 19:54:54 +02003777 |internal-variables|). Also works
Bram Moolenaar32466aa2006-02-24 23:53:04 +00003778 for |curly-braces-names|, |Dictionary|
3779 entries, |List| items, etc. Beware
Bram Moolenaarc236c162008-07-13 17:41:49 +00003780 that evaluating an index may cause an
3781 error message for an invalid
3782 expression. E.g.: >
3783 :let l = [1, 2, 3]
3784 :echo exists("l[5]")
3785< 0 >
3786 :echo exists("l[xx]")
3787< E121: Undefined variable: xx
3788 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00003789 :cmdname Ex command: built-in command, user
3790 command or command modifier |:command|.
3791 Returns:
3792 1 for match with start of a command
3793 2 full match with a command
3794 3 matches several user commands
3795 To check for a supported command
3796 always check the return value to be 2.
Bram Moolenaar14716812006-05-04 21:54:08 +00003797 :2match The |:2match| command.
3798 :3match The |:3match| command.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003799 #event autocommand defined for this event
3800 #event#pattern autocommand defined for this event and
3801 pattern (the pattern is taken
3802 literally and compared to the
3803 autocommand patterns character by
3804 character)
Bram Moolenaara9b1e742005-12-19 22:14:58 +00003805 #group autocommand group exists
3806 #group#event autocommand defined for this group and
3807 event.
3808 #group#event#pattern
Bram Moolenaarc9b4b052006-04-30 18:54:39 +00003809 autocommand defined for this group,
Bram Moolenaara9b1e742005-12-19 22:14:58 +00003810 event and pattern.
Bram Moolenaarf4cd3e82005-12-22 22:47:02 +00003811 ##event autocommand for this event is
3812 supported.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003813
3814 Examples: >
3815 exists("&shortname")
3816 exists("$HOSTNAME")
3817 exists("*strftime")
3818 exists("*s:MyFunc")
3819 exists("bufcount")
3820 exists(":Make")
Bram Moolenaara9b1e742005-12-19 22:14:58 +00003821 exists("#CursorHold")
Bram Moolenaar071d4272004-06-13 20:20:40 +00003822 exists("#BufReadPre#*.gz")
Bram Moolenaara9b1e742005-12-19 22:14:58 +00003823 exists("#filetypeindent")
3824 exists("#filetypeindent#FileType")
3825 exists("#filetypeindent#FileType#*")
Bram Moolenaarf4cd3e82005-12-22 22:47:02 +00003826 exists("##ColorScheme")
Bram Moolenaar071d4272004-06-13 20:20:40 +00003827< There must be no space between the symbol (&/$/*/#) and the
3828 name.
Bram Moolenaar91170f82006-05-05 21:15:17 +00003829 There must be no extra characters after the name, although in
3830 a few cases this is ignored. That may become more strict in
3831 the future, thus don't count on it!
3832 Working example: >
3833 exists(":make")
3834< NOT working example: >
3835 exists(":make install")
Bram Moolenaar9c102382006-05-03 21:26:49 +00003836
3837< Note that the argument must be a string, not the name of the
3838 variable itself. For example: >
Bram Moolenaar071d4272004-06-13 20:20:40 +00003839 exists(bufcount)
3840< This doesn't check for existence of the "bufcount" variable,
Bram Moolenaar06a89a52006-04-29 22:01:03 +00003841 but gets the value of "bufcount", and checks if that exists.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003842
Bram Moolenaardb7c6862010-05-21 16:33:48 +02003843exp({expr}) *exp()*
Bram Moolenaar9855d6b2010-07-18 14:34:51 +02003844 Return the exponential of {expr} as a |Float| in the range
Bram Moolenaardb7c6862010-05-21 16:33:48 +02003845 [0, inf].
Bram Moolenaar9855d6b2010-07-18 14:34:51 +02003846 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaardb7c6862010-05-21 16:33:48 +02003847 Examples: >
3848 :echo exp(2)
3849< 7.389056 >
3850 :echo exp(-1)
3851< 0.367879
Bram Moolenaardb84e452010-08-15 13:50:43 +02003852 {only available when compiled with the |+float| feature}
Bram Moolenaardb7c6862010-05-21 16:33:48 +02003853
3854
Bram Moolenaar84f72352012-03-11 15:57:40 +01003855expand({expr} [, {nosuf} [, {list}]]) *expand()*
Bram Moolenaar071d4272004-06-13 20:20:40 +00003856 Expand wildcards and the following special keywords in {expr}.
Bram Moolenaar84f72352012-03-11 15:57:40 +01003857 'wildignorecase' applies.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003858
Bram Moolenaare381d3d2016-07-07 14:50:41 +02003859 If {list} is given and it is |TRUE|, a List will be returned.
Bram Moolenaar84f72352012-03-11 15:57:40 +01003860 Otherwise the result is a String and when there are several
3861 matches, they are separated by <NL> characters. [Note: in
3862 version 5.0 a space was used, which caused problems when a
3863 file name contains a space]
Bram Moolenaar071d4272004-06-13 20:20:40 +00003864
Bram Moolenaar58b85342016-08-14 19:54:54 +02003865 If the expansion fails, the result is an empty string. A name
Bram Moolenaarec7944a2013-06-12 21:29:15 +02003866 for a non-existing file is not included, unless {expr} does
3867 not start with '%', '#' or '<', see below.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003868
3869 When {expr} starts with '%', '#' or '<', the expansion is done
3870 like for the |cmdline-special| variables with their associated
3871 modifiers. Here is a short overview:
3872
3873 % current file name
3874 # alternate file name
3875 #n alternate file name n
3876 <cfile> file name under the cursor
3877 <afile> autocmd file name
3878 <abuf> autocmd buffer number (as a String!)
3879 <amatch> autocmd matched name
Bram Moolenaara6878372014-03-22 21:02:50 +01003880 <sfile> sourced script file or function name
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003881 <slnum> sourced script line number or function
3882 line number
3883 <sflnum> script file line number, also when in
3884 a function
Bram Moolenaar071d4272004-06-13 20:20:40 +00003885 <cword> word under the cursor
3886 <cWORD> WORD under the cursor
3887 <client> the {clientid} of the last received
3888 message |server2client()|
3889 Modifiers:
3890 :p expand to full path
3891 :h head (last path component removed)
3892 :t tail (last path component only)
3893 :r root (one extension removed)
3894 :e extension only
3895
3896 Example: >
3897 :let &tags = expand("%:p:h") . "/tags"
3898< Note that when expanding a string that starts with '%', '#' or
3899 '<', any following text is ignored. This does NOT work: >
3900 :let doesntwork = expand("%:h.bak")
3901< Use this: >
3902 :let doeswork = expand("%:h") . ".bak"
3903< Also note that expanding "<cfile>" and others only returns the
3904 referenced file name without further expansion. If "<cfile>"
3905 is "~/.cshrc", you need to do another expand() to have the
3906 "~/" expanded into the path of the home directory: >
3907 :echo expand(expand("<cfile>"))
3908<
3909 There cannot be white space between the variables and the
3910 following modifier. The |fnamemodify()| function can be used
3911 to modify normal file names.
3912
3913 When using '%' or '#', and the current or alternate file name
3914 is not defined, an empty string is used. Using "%:p" in a
3915 buffer with no name, results in the current directory, with a
3916 '/' added.
3917
3918 When {expr} does not start with '%', '#' or '<', it is
3919 expanded like a file name is expanded on the command line.
3920 'suffixes' and 'wildignore' are used, unless the optional
Bram Moolenaare381d3d2016-07-07 14:50:41 +02003921 {nosuf} argument is given and it is |TRUE|.
Bram Moolenaar146e9c32012-03-07 19:18:23 +01003922 Names for non-existing files are included. The "**" item can
3923 be used to search in a directory tree. For example, to find
3924 all "README" files in the current directory and below: >
Bram Moolenaar02743632005-07-25 20:42:36 +00003925 :echo expand("**/README")
3926<
Bram Moolenaar071d4272004-06-13 20:20:40 +00003927 Expand() can also be used to expand variables and environment
3928 variables that are only known in a shell. But this can be
Bram Moolenaar34401cc2014-08-29 15:12:19 +02003929 slow, because a shell may be used to do the expansion. See
3930 |expr-env-expand|.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003931 The expanded variable is still handled like a list of file
Bram Moolenaar58b85342016-08-14 19:54:54 +02003932 names. When an environment variable cannot be expanded, it is
Bram Moolenaar071d4272004-06-13 20:20:40 +00003933 left unchanged. Thus ":echo expand('$FOOBAR')" results in
3934 "$FOOBAR".
3935
3936 See |glob()| for finding existing files. See |system()| for
3937 getting the raw output of an external command.
3938
Bram Moolenaar2fda12f2005-01-15 22:14:15 +00003939extend({expr1}, {expr2} [, {expr3}]) *extend()*
Bram Moolenaara23ccb82006-02-27 00:08:02 +00003940 {expr1} and {expr2} must be both |Lists| or both
3941 |Dictionaries|.
Bram Moolenaar2fda12f2005-01-15 22:14:15 +00003942
Bram Moolenaara23ccb82006-02-27 00:08:02 +00003943 If they are |Lists|: Append {expr2} to {expr1}.
Bram Moolenaar2fda12f2005-01-15 22:14:15 +00003944 If {expr3} is given insert the items of {expr2} before item
3945 {expr3} in {expr1}. When {expr3} is zero insert before the
3946 first item. When {expr3} is equal to len({expr1}) then
3947 {expr2} is appended.
Bram Moolenaarde8866b2005-01-06 23:24:37 +00003948 Examples: >
3949 :echo sort(extend(mylist, [7, 5]))
3950 :call extend(mylist, [2, 3], 1)
Bram Moolenaardc9cf9c2008-08-08 10:36:31 +00003951< When {expr1} is the same List as {expr2} then the number of
3952 items copied is equal to the original length of the List.
3953 E.g., when {expr3} is 1 you get N new copies of the first item
3954 (where N is the original length of the List).
Bram Moolenaar58b85342016-08-14 19:54:54 +02003955 Use |add()| to concatenate one item to a list. To concatenate
Bram Moolenaara14de3d2005-01-07 21:48:26 +00003956 two lists into a new list use the + operator: >
Bram Moolenaarde8866b2005-01-06 23:24:37 +00003957 :let newlist = [1, 2, 3] + [4, 5]
Bram Moolenaar2fda12f2005-01-15 22:14:15 +00003958<
Bram Moolenaara23ccb82006-02-27 00:08:02 +00003959 If they are |Dictionaries|:
Bram Moolenaar2fda12f2005-01-15 22:14:15 +00003960 Add all entries from {expr2} to {expr1}.
3961 If a key exists in both {expr1} and {expr2} then {expr3} is
3962 used to decide what to do:
3963 {expr3} = "keep": keep the value of {expr1}
3964 {expr3} = "force": use the value of {expr2}
Bram Moolenaarc9b4b052006-04-30 18:54:39 +00003965 {expr3} = "error": give an error message *E737*
Bram Moolenaar2fda12f2005-01-15 22:14:15 +00003966 When {expr3} is omitted then "force" is assumed.
3967
3968 {expr1} is changed when {expr2} is not empty. If necessary
3969 make a copy of {expr1} first.
3970 {expr2} remains unchanged.
Bram Moolenaarf2571c62015-06-09 19:44:55 +02003971 When {expr1} is locked and {expr2} is not empty the operation
3972 fails.
Bram Moolenaar2fda12f2005-01-15 22:14:15 +00003973 Returns {expr1}.
3974
Bram Moolenaarde8866b2005-01-06 23:24:37 +00003975
Bram Moolenaarf9393ef2006-04-24 19:47:27 +00003976feedkeys({string} [, {mode}]) *feedkeys()*
3977 Characters in {string} are queued for processing as if they
Bram Moolenaar0a988df2015-01-27 15:19:24 +01003978 come from a mapping or were typed by the user.
Bram Moolenaarb328cca2019-01-06 16:24:01 +01003979
Bram Moolenaar0a988df2015-01-27 15:19:24 +01003980 By default the string is added to the end of the typeahead
3981 buffer, thus if a mapping is still being executed the
3982 characters come after them. Use the 'i' flag to insert before
3983 other characters, they will be executed next, before any
3984 characters from a mapping.
Bram Moolenaarb328cca2019-01-06 16:24:01 +01003985
Bram Moolenaarf9393ef2006-04-24 19:47:27 +00003986 The function does not wait for processing of keys contained in
3987 {string}.
Bram Moolenaarb328cca2019-01-06 16:24:01 +01003988
Bram Moolenaarf9393ef2006-04-24 19:47:27 +00003989 To include special keys into {string}, use double-quotes
3990 and "\..." notation |expr-quote|. For example,
Bram Moolenaar79166c42007-05-10 18:29:51 +00003991 feedkeys("\<CR>") simulates pressing of the <Enter> key. But
Bram Moolenaarf9393ef2006-04-24 19:47:27 +00003992 feedkeys('\<CR>') pushes 5 characters.
Bram Moolenaarb328cca2019-01-06 16:24:01 +01003993
Bram Moolenaarf9393ef2006-04-24 19:47:27 +00003994 {mode} is a String, which can contain these character flags:
Bram Moolenaarb328cca2019-01-06 16:24:01 +01003995 'm' Remap keys. This is default. If {mode} is absent,
3996 keys are remapped.
Bram Moolenaar551dbcc2006-04-25 22:13:59 +00003997 'n' Do not remap keys.
3998 't' Handle keys as if typed; otherwise they are handled as
3999 if coming from a mapping. This matters for undo,
4000 opening folds, etc.
Bram Moolenaar0a988df2015-01-27 15:19:24 +01004001 'i' Insert the string instead of appending (see above).
Bram Moolenaar25281632016-01-21 23:32:32 +01004002 'x' Execute commands until typeahead is empty. This is
4003 similar to using ":normal!". You can call feedkeys()
4004 several times without 'x' and then one time with 'x'
4005 (possibly with an empty {string}) to execute all the
Bram Moolenaar03413f42016-04-12 21:07:15 +02004006 typeahead. Note that when Vim ends in Insert mode it
4007 will behave as if <Esc> is typed, to avoid getting
4008 stuck, waiting for a character to be typed before the
4009 script continues.
Bram Moolenaarb328cca2019-01-06 16:24:01 +01004010 Note that if you manage to call feedkeys() while
Bram Moolenaar5b69c222019-01-11 14:50:06 +01004011 executing commands, thus calling it recursively, then
Bram Moolenaarb328cca2019-01-06 16:24:01 +01004012 all typehead will be consumed by the last call.
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004013 '!' When used with 'x' will not end Insert mode. Can be
4014 used in a test when a timer is set to exit Insert mode
4015 a little later. Useful for testing CursorHoldI.
4016
Bram Moolenaarf9393ef2006-04-24 19:47:27 +00004017 Return value is always 0.
4018
Bram Moolenaar071d4272004-06-13 20:20:40 +00004019filereadable({file}) *filereadable()*
Bram Moolenaare381d3d2016-07-07 14:50:41 +02004020 The result is a Number, which is |TRUE| when a file with the
Bram Moolenaar071d4272004-06-13 20:20:40 +00004021 name {file} exists, and can be read. If {file} doesn't exist,
Bram Moolenaare381d3d2016-07-07 14:50:41 +02004022 or is a directory, the result is |FALSE|. {file} is any
Bram Moolenaar071d4272004-06-13 20:20:40 +00004023 expression, which is used as a String.
Bram Moolenaaref2f6562007-05-06 13:32:59 +00004024 If you don't care about the file being readable you can use
4025 |glob()|.
Bram Moolenaar071d4272004-06-13 20:20:40 +00004026 *file_readable()*
4027 Obsolete name: file_readable().
4028
Bram Moolenaar5f2bb9f2005-01-11 21:29:04 +00004029
Bram Moolenaaref2f6562007-05-06 13:32:59 +00004030filewritable({file}) *filewritable()*
4031 The result is a Number, which is 1 when a file with the
4032 name {file} exists, and can be written. If {file} doesn't
Bram Moolenaar446cb832008-06-24 21:56:24 +00004033 exist, or is not writable, the result is 0. If {file} is a
Bram Moolenaaref2f6562007-05-06 13:32:59 +00004034 directory, and we can write to it, the result is 2.
4035
4036
Bram Moolenaarb33c7eb2016-07-04 22:29:49 +02004037filter({expr1}, {expr2}) *filter()*
4038 {expr1} must be a |List| or a |Dictionary|.
4039 For each item in {expr1} evaluate {expr2} and when the result
Bram Moolenaar32466aa2006-02-24 23:53:04 +00004040 is zero remove the item from the |List| or |Dictionary|.
Bram Moolenaarb33c7eb2016-07-04 22:29:49 +02004041 {expr2} must be a |string| or |Funcref|.
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01004042
Bram Moolenaar50ba5262016-09-22 22:33:02 +02004043 If {expr2} is a |string|, inside {expr2} |v:val| has the value
Bram Moolenaarb33c7eb2016-07-04 22:29:49 +02004044 of the current item. For a |Dictionary| |v:key| has the key
Bram Moolenaar50ba5262016-09-22 22:33:02 +02004045 of the current item and for a |List| |v:key| has the index of
4046 the current item.
Bram Moolenaar2fda12f2005-01-15 22:14:15 +00004047 Examples: >
Bram Moolenaarb33c7eb2016-07-04 22:29:49 +02004048 call filter(mylist, 'v:val !~ "OLD"')
Bram Moolenaar2fda12f2005-01-15 22:14:15 +00004049< Removes the items where "OLD" appears. >
Bram Moolenaarb33c7eb2016-07-04 22:29:49 +02004050 call filter(mydict, 'v:key >= 8')
Bram Moolenaar2fda12f2005-01-15 22:14:15 +00004051< Removes the items with a key below 8. >
Bram Moolenaarb33c7eb2016-07-04 22:29:49 +02004052 call filter(var, 0)
Bram Moolenaar32466aa2006-02-24 23:53:04 +00004053< Removes all the items, thus clears the |List| or |Dictionary|.
Bram Moolenaard8b02732005-01-14 21:48:43 +00004054
Bram Moolenaarb33c7eb2016-07-04 22:29:49 +02004055 Note that {expr2} is the result of expression and is then
Bram Moolenaar2fda12f2005-01-15 22:14:15 +00004056 used as an expression again. Often it is good to use a
4057 |literal-string| to avoid having to double backslashes.
4058
Bram Moolenaarb33c7eb2016-07-04 22:29:49 +02004059 If {expr2} is a |Funcref| it must take two arguments:
4060 1. the key or the index of the current item.
4061 2. the value of the current item.
Bram Moolenaare381d3d2016-07-07 14:50:41 +02004062 The function must return |TRUE| if the item should be kept.
Bram Moolenaarb33c7eb2016-07-04 22:29:49 +02004063 Example that keeps the odd items of a list: >
4064 func Odd(idx, val)
4065 return a:idx % 2 == 1
4066 endfunc
4067 call filter(mylist, function('Odd'))
Bram Moolenaar50ba5262016-09-22 22:33:02 +02004068< It is shorter when using a |lambda|: >
4069 call filter(myList, {idx, val -> idx * val <= 42})
4070< If you do not use "val" you can leave it out: >
4071 call filter(myList, {idx -> idx % 2 == 1})
Bram Moolenaar2ec618c2016-10-01 14:47:05 +02004072<
Bram Moolenaar32466aa2006-02-24 23:53:04 +00004073 The operation is done in-place. If you want a |List| or
4074 |Dictionary| to remain unmodified make a copy first: >
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00004075 :let l = filter(copy(mylist), 'v:val =~ "KEEP"')
Bram Moolenaar2fda12f2005-01-15 22:14:15 +00004076
Bram Moolenaarb33c7eb2016-07-04 22:29:49 +02004077< Returns {expr1}, the |List| or |Dictionary| that was filtered.
4078 When an error is encountered while evaluating {expr2} no
4079 further items in {expr1} are processed. When {expr2} is a
4080 Funcref errors inside a function are ignored, unless it was
4081 defined with the "abort" flag.
Bram Moolenaar5f2bb9f2005-01-11 21:29:04 +00004082
4083
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01004084finddir({name} [, {path} [, {count}]]) *finddir()*
Bram Moolenaar5b6b1ca2007-03-27 08:19:43 +00004085 Find directory {name} in {path}. Supports both downwards and
4086 upwards recursive directory searches. See |file-searching|
4087 for the syntax of {path}.
4088 Returns the path of the first found match. When the found
4089 directory is below the current directory a relative path is
4090 returned. Otherwise a full path is returned.
Bram Moolenaar89cb5e02004-07-19 20:55:54 +00004091 If {path} is omitted or empty then 'path' is used.
4092 If the optional {count} is given, find {count}'s occurrence of
Bram Moolenaar433f7c82006-03-21 21:29:36 +00004093 {name} in {path} instead of the first one.
Bram Moolenaar899dddf2006-03-26 21:06:50 +00004094 When {count} is negative return all the matches in a |List|.
Bram Moolenaar89cb5e02004-07-19 20:55:54 +00004095 This is quite similar to the ex-command |:find|.
Bram Moolenaardb84e452010-08-15 13:50:43 +02004096 {only available when compiled with the |+file_in_path|
4097 feature}
Bram Moolenaar89cb5e02004-07-19 20:55:54 +00004098
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01004099findfile({name} [, {path} [, {count}]]) *findfile()*
Bram Moolenaar89cb5e02004-07-19 20:55:54 +00004100 Just like |finddir()|, but find a file instead of a directory.
Bram Moolenaar433f7c82006-03-21 21:29:36 +00004101 Uses 'suffixesadd'.
4102 Example: >
4103 :echo findfile("tags.vim", ".;")
Bram Moolenaaref2f6562007-05-06 13:32:59 +00004104< Searches from the directory of the current file upwards until
4105 it finds the file "tags.vim".
Bram Moolenaar071d4272004-06-13 20:20:40 +00004106
Bram Moolenaar446cb832008-06-24 21:56:24 +00004107float2nr({expr}) *float2nr()*
4108 Convert {expr} to a Number by omitting the part after the
4109 decimal point.
4110 {expr} must evaluate to a |Float| or a Number.
4111 When the value of {expr} is out of range for a |Number| the
Bram Moolenaar22fcfad2016-07-01 18:17:26 +02004112 result is truncated to 0x7fffffff or -0x7fffffff (or when
4113 64-bit Number support is enabled, 0x7fffffffffffffff or
Bram Moolenaarb4d5fba2017-09-11 19:31:28 +02004114 -0x7fffffffffffffff). NaN results in -0x80000000 (or when
Bram Moolenaar22fcfad2016-07-01 18:17:26 +02004115 64-bit Number support is enabled, -0x8000000000000000).
Bram Moolenaar446cb832008-06-24 21:56:24 +00004116 Examples: >
4117 echo float2nr(3.95)
4118< 3 >
4119 echo float2nr(-23.45)
4120< -23 >
4121 echo float2nr(1.0e100)
Bram Moolenaar22fcfad2016-07-01 18:17:26 +02004122< 2147483647 (or 9223372036854775807) >
Bram Moolenaar446cb832008-06-24 21:56:24 +00004123 echo float2nr(-1.0e150)
Bram Moolenaar22fcfad2016-07-01 18:17:26 +02004124< -2147483647 (or -9223372036854775807) >
Bram Moolenaar446cb832008-06-24 21:56:24 +00004125 echo float2nr(1.0e-100)
4126< 0
4127 {only available when compiled with the |+float| feature}
4128
4129
4130floor({expr}) *floor()*
4131 Return the largest integral value less than or equal to
4132 {expr} as a |Float| (round down).
4133 {expr} must evaluate to a |Float| or a |Number|.
4134 Examples: >
4135 echo floor(1.856)
4136< 1.0 >
4137 echo floor(-5.456)
4138< -6.0 >
4139 echo floor(4.0)
4140< 4.0
4141 {only available when compiled with the |+float| feature}
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01004142
Bram Moolenaardb7c6862010-05-21 16:33:48 +02004143
4144fmod({expr1}, {expr2}) *fmod()*
4145 Return the remainder of {expr1} / {expr2}, even if the
4146 division is not representable. Returns {expr1} - i * {expr2}
4147 for some integer i such that if {expr2} is non-zero, the
4148 result has the same sign as {expr1} and magnitude less than
4149 the magnitude of {expr2}. If {expr2} is zero, the value
Bram Moolenaar9855d6b2010-07-18 14:34:51 +02004150 returned is zero. The value returned is a |Float|.
4151 {expr1} and {expr2} must evaluate to a |Float| or a |Number|.
Bram Moolenaardb7c6862010-05-21 16:33:48 +02004152 Examples: >
4153 :echo fmod(12.33, 1.22)
4154< 0.13 >
4155 :echo fmod(-12.33, 1.22)
4156< -0.13
Bram Moolenaardb84e452010-08-15 13:50:43 +02004157 {only available when compiled with |+float| feature}
Bram Moolenaardb7c6862010-05-21 16:33:48 +02004158
4159
Bram Moolenaaraebaf892008-05-28 14:49:58 +00004160fnameescape({string}) *fnameescape()*
Bram Moolenaar58b85342016-08-14 19:54:54 +02004161 Escape {string} for use as file name command argument. All
Bram Moolenaaraebaf892008-05-28 14:49:58 +00004162 characters that have a special meaning, such as '%' and '|'
4163 are escaped with a backslash.
Bram Moolenaar446cb832008-06-24 21:56:24 +00004164 For most systems the characters escaped are
4165 " \t\n*?[{`$\\%#'\"|!<". For systems where a backslash
4166 appears in a filename, it depends on the value of 'isfname'.
Bram Moolenaar1b24e4b2008-08-08 10:59:17 +00004167 A leading '+' and '>' is also escaped (special after |:edit|
4168 and |:write|). And a "-" by itself (special after |:cd|).
Bram Moolenaaraebaf892008-05-28 14:49:58 +00004169 Example: >
Bram Moolenaar1b24e4b2008-08-08 10:59:17 +00004170 :let fname = '+some str%nge|name'
Bram Moolenaaraebaf892008-05-28 14:49:58 +00004171 :exe "edit " . fnameescape(fname)
4172< results in executing: >
Bram Moolenaar1b24e4b2008-08-08 10:59:17 +00004173 edit \+some\ str\%nge\|name
Bram Moolenaaraebaf892008-05-28 14:49:58 +00004174
Bram Moolenaar071d4272004-06-13 20:20:40 +00004175fnamemodify({fname}, {mods}) *fnamemodify()*
4176 Modify file name {fname} according to {mods}. {mods} is a
4177 string of characters like it is used for file names on the
4178 command line. See |filename-modifiers|.
4179 Example: >
4180 :echo fnamemodify("main.c", ":p:h")
4181< results in: >
4182 /home/mool/vim/vim/src
Bram Moolenaar446cb832008-06-24 21:56:24 +00004183< Note: Environment variables don't work in {fname}, use
Bram Moolenaar071d4272004-06-13 20:20:40 +00004184 |expand()| first then.
4185
4186foldclosed({lnum}) *foldclosed()*
4187 The result is a Number. If the line {lnum} is in a closed
4188 fold, the result is the number of the first line in that fold.
4189 If the line {lnum} is not in a closed fold, -1 is returned.
4190
4191foldclosedend({lnum}) *foldclosedend()*
4192 The result is a Number. If the line {lnum} is in a closed
4193 fold, the result is the number of the last line in that fold.
4194 If the line {lnum} is not in a closed fold, -1 is returned.
4195
4196foldlevel({lnum}) *foldlevel()*
4197 The result is a Number, which is the foldlevel of line {lnum}
Bram Moolenaar58b85342016-08-14 19:54:54 +02004198 in the current buffer. For nested folds the deepest level is
Bram Moolenaar071d4272004-06-13 20:20:40 +00004199 returned. If there is no fold at line {lnum}, zero is
4200 returned. It doesn't matter if the folds are open or closed.
4201 When used while updating folds (from 'foldexpr') -1 is
4202 returned for lines where folds are still to be updated and the
4203 foldlevel is unknown. As a special case the level of the
4204 previous line is usually available.
4205
4206 *foldtext()*
4207foldtext() Returns a String, to be displayed for a closed fold. This is
4208 the default function used for the 'foldtext' option and should
4209 only be called from evaluating 'foldtext'. It uses the
4210 |v:foldstart|, |v:foldend| and |v:folddashes| variables.
4211 The returned string looks like this: >
4212 +-- 45 lines: abcdef
Bram Moolenaar42205552017-03-18 19:42:22 +01004213< The number of leading dashes depends on the foldlevel. The
4214 "45" is the number of lines in the fold. "abcdef" is the text
4215 in the first non-blank line of the fold. Leading white space,
4216 "//" or "/*" and the text from the 'foldmarker' and
4217 'commentstring' options is removed.
4218 When used to draw the actual foldtext, the rest of the line
4219 will be filled with the fold char from the 'fillchars'
4220 setting.
Bram Moolenaar071d4272004-06-13 20:20:40 +00004221 {not available when compiled without the |+folding| feature}
4222
Bram Moolenaar7b0294c2004-10-11 10:16:09 +00004223foldtextresult({lnum}) *foldtextresult()*
4224 Returns the text that is displayed for the closed fold at line
4225 {lnum}. Evaluates 'foldtext' in the appropriate context.
4226 When there is no closed fold at {lnum} an empty string is
4227 returned.
4228 {lnum} is used like with |getline()|. Thus "." is the current
4229 line, "'m" mark m, etc.
4230 Useful when exporting folded text, e.g., to HTML.
4231 {not available when compiled without the |+folding| feature}
4232
Bram Moolenaar071d4272004-06-13 20:20:40 +00004233 *foreground()*
Bram Moolenaar58b85342016-08-14 19:54:54 +02004234foreground() Move the Vim window to the foreground. Useful when sent from
Bram Moolenaar071d4272004-06-13 20:20:40 +00004235 a client to a Vim server. |remote_send()|
4236 On Win32 systems this might not work, the OS does not always
4237 allow a window to bring itself to the foreground. Use
4238 |remote_foreground()| instead.
4239 {only in the Win32, Athena, Motif and GTK GUI versions and the
4240 Win32 console version}
4241
Bram Moolenaar437bafe2016-08-01 15:40:54 +02004242 *funcref()*
4243funcref({name} [, {arglist}] [, {dict}])
4244 Just like |function()|, but the returned Funcref will lookup
4245 the function by reference, not by name. This matters when the
4246 function {name} is redefined later.
4247
4248 Unlike |function()|, {name} must be an existing user function.
4249 Also for autoloaded functions. {name} cannot be a builtin
4250 function.
Bram Moolenaara14de3d2005-01-07 21:48:26 +00004251
Bram Moolenaar1735bc92016-03-14 23:05:14 +01004252 *function()* *E700* *E922* *E923*
4253function({name} [, {arglist}] [, {dict}])
Bram Moolenaar32466aa2006-02-24 23:53:04 +00004254 Return a |Funcref| variable that refers to function {name}.
Bram Moolenaar975b5272016-03-15 23:10:59 +01004255 {name} can be the name of a user defined function or an
4256 internal function.
Bram Moolenaard7ee7ce2005-01-03 21:02:03 +00004257
Bram Moolenaar437bafe2016-08-01 15:40:54 +02004258 {name} can also be a Funcref or a partial. When it is a
Bram Moolenaar975b5272016-03-15 23:10:59 +01004259 partial the dict stored in it will be used and the {dict}
4260 argument is not allowed. E.g.: >
4261 let FuncWithArg = function(dict.Func, [arg])
4262 let Broken = function(dict.Func, [arg], dict)
4263<
Bram Moolenaar437bafe2016-08-01 15:40:54 +02004264 When using the Funcref the function will be found by {name},
4265 also when it was redefined later. Use |funcref()| to keep the
4266 same function.
4267
Bram Moolenaar1735bc92016-03-14 23:05:14 +01004268 When {arglist} or {dict} is present this creates a partial.
Bram Moolenaar06d2d382016-05-20 17:24:11 +02004269 That means the argument list and/or the dictionary is stored in
Bram Moolenaar1735bc92016-03-14 23:05:14 +01004270 the Funcref and will be used when the Funcref is called.
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01004271
Bram Moolenaar1735bc92016-03-14 23:05:14 +01004272 The arguments are passed to the function in front of other
4273 arguments. Example: >
4274 func Callback(arg1, arg2, name)
4275 ...
4276 let Func = function('Callback', ['one', 'two'])
4277 ...
4278 call Func('name')
4279< Invokes the function as with: >
4280 call Callback('one', 'two', 'name')
4281
Bram Moolenaar03602ec2016-03-20 20:57:45 +01004282< The function() call can be nested to add more arguments to the
4283 Funcref. The extra arguments are appended to the list of
4284 arguments. Example: >
4285 func Callback(arg1, arg2, name)
4286 ...
4287 let Func = function('Callback', ['one'])
4288 let Func2 = function(Func, ['two'])
4289 ...
4290 call Func2('name')
4291< Invokes the function as with: >
4292 call Callback('one', 'two', 'name')
4293
Bram Moolenaar1735bc92016-03-14 23:05:14 +01004294< The Dictionary is only useful when calling a "dict" function.
4295 In that case the {dict} is passed in as "self". Example: >
4296 function Callback() dict
4297 echo "called for " . self.name
4298 endfunction
4299 ...
4300 let context = {"name": "example"}
4301 let Func = function('Callback', context)
4302 ...
4303 call Func() " will echo: called for example
Bram Moolenaar975b5272016-03-15 23:10:59 +01004304< The use of function() is not needed when there are no extra
4305 arguments, these two are equivalent: >
4306 let Func = function('Callback', context)
4307 let Func = context.Callback
Bram Moolenaar1735bc92016-03-14 23:05:14 +01004308
4309< The argument list and the Dictionary can be combined: >
4310 function Callback(arg1, count) dict
4311 ...
4312 let context = {"name": "example"}
4313 let Func = function('Callback', ['one'], context)
4314 ...
4315 call Func(500)
4316< Invokes the function as with: >
4317 call context.Callback('one', 500)
4318
Bram Moolenaara14de3d2005-01-07 21:48:26 +00004319
Bram Moolenaarf1568ec2011-12-14 21:17:39 +01004320garbagecollect([{atexit}]) *garbagecollect()*
Bram Moolenaarebf7dfa2016-04-14 12:46:51 +02004321 Cleanup unused |Lists|, |Dictionaries|, |Channels| and |Jobs|
4322 that have circular references.
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01004323
Bram Moolenaarebf7dfa2016-04-14 12:46:51 +02004324 There is hardly ever a need to invoke this function, as it is
4325 automatically done when Vim runs out of memory or is waiting
4326 for the user to press a key after 'updatetime'. Items without
4327 circular references are always freed when they become unused.
Bram Moolenaar32466aa2006-02-24 23:53:04 +00004328 This is useful if you have deleted a very big |List| and/or
4329 |Dictionary| with circular references in a script that runs
4330 for a long time.
Bram Moolenaarebf7dfa2016-04-14 12:46:51 +02004331
Bram Moolenaarf1568ec2011-12-14 21:17:39 +01004332 When the optional {atexit} argument is one, garbage
Bram Moolenaar9d2c8c12007-09-25 16:00:00 +00004333 collection will also be done when exiting Vim, if it wasn't
4334 done before. This is useful when checking for memory leaks.
Bram Moolenaar39a58ca2005-06-27 22:42:44 +00004335
Bram Moolenaar574860b2016-05-24 17:33:34 +02004336 The garbage collection is not done immediately but only when
4337 it's safe to perform. This is when waiting for the user to
4338 type a character. To force garbage collection immediately use
4339 |test_garbagecollect_now()|.
Bram Moolenaarebf7dfa2016-04-14 12:46:51 +02004340
Bram Moolenaar677ee682005-01-27 14:41:15 +00004341get({list}, {idx} [, {default}]) *get()*
Bram Moolenaar32466aa2006-02-24 23:53:04 +00004342 Get item {idx} from |List| {list}. When this item is not
Bram Moolenaara14de3d2005-01-07 21:48:26 +00004343 available return {default}. Return zero when {default} is
4344 omitted.
Bram Moolenaar2fda12f2005-01-15 22:14:15 +00004345get({dict}, {key} [, {default}])
Bram Moolenaar32466aa2006-02-24 23:53:04 +00004346 Get item with key {key} from |Dictionary| {dict}. When this
Bram Moolenaar2fda12f2005-01-15 22:14:15 +00004347 item is not available return {default}. Return zero when
4348 {default} is omitted.
Bram Moolenaar03e19a02016-05-24 22:29:49 +02004349get({func}, {what})
4350 Get an item with from Funcref {func}. Possible values for
Bram Moolenaar2bbf8ef2016-05-24 18:37:12 +02004351 {what} are:
Bram Moolenaar214641f2017-03-05 17:04:09 +01004352 "name" The function name
4353 "func" The function
4354 "dict" The dictionary
4355 "args" The list with arguments
Bram Moolenaar2fda12f2005-01-15 22:14:15 +00004356
Bram Moolenaarb5ae48e2016-08-12 22:23:25 +02004357 *getbufinfo()*
4358getbufinfo([{expr}])
4359getbufinfo([{dict}])
Bram Moolenaar58b85342016-08-14 19:54:54 +02004360 Get information about buffers as a List of Dictionaries.
Bram Moolenaarb5ae48e2016-08-12 22:23:25 +02004361
4362 Without an argument information about all the buffers is
4363 returned.
4364
4365 When the argument is a Dictionary only the buffers matching
4366 the specified criteria are returned. The following keys can
4367 be specified in {dict}:
4368 buflisted include only listed buffers.
4369 bufloaded include only loaded buffers.
Bram Moolenaar8e6a31d2017-12-10 21:06:22 +01004370 bufmodified include only modified buffers.
Bram Moolenaarb5ae48e2016-08-12 22:23:25 +02004371
4372 Otherwise, {expr} specifies a particular buffer to return
4373 information for. For the use of {expr}, see |bufname()|
4374 above. If the buffer is found the returned List has one item.
4375 Otherwise the result is an empty list.
4376
4377 Each returned List item is a dictionary with the following
4378 entries:
Bram Moolenaar33928832016-08-18 21:22:04 +02004379 bufnr buffer number.
Bram Moolenaarb5ae48e2016-08-12 22:23:25 +02004380 changed TRUE if the buffer is modified.
4381 changedtick number of changes made to the buffer.
4382 hidden TRUE if the buffer is hidden.
4383 listed TRUE if the buffer is listed.
4384 lnum current line number in buffer.
4385 loaded TRUE if the buffer is loaded.
4386 name full path to the file in the buffer.
Bram Moolenaarb5ae48e2016-08-12 22:23:25 +02004387 signs list of signs placed in the buffer.
4388 Each list item is a dictionary with
4389 the following fields:
4390 id sign identifier
4391 lnum line number
4392 name sign name
Bram Moolenaar30567352016-08-27 21:25:44 +02004393 variables a reference to the dictionary with
4394 buffer-local variables.
4395 windows list of |window-ID|s that display this
4396 buffer
Bram Moolenaarb5ae48e2016-08-12 22:23:25 +02004397
4398 Examples: >
4399 for buf in getbufinfo()
4400 echo buf.name
4401 endfor
4402 for buf in getbufinfo({'buflisted':1})
Bram Moolenaar30567352016-08-27 21:25:44 +02004403 if buf.changed
Bram Moolenaarb5ae48e2016-08-12 22:23:25 +02004404 ....
4405 endif
4406 endfor
4407<
Bram Moolenaar30567352016-08-27 21:25:44 +02004408 To get buffer-local options use: >
Bram Moolenaard473c8c2018-08-11 18:00:22 +02004409 getbufvar({bufnr}, '&option_name')
Bram Moolenaar30567352016-08-27 21:25:44 +02004410
4411<
Bram Moolenaar45360022005-07-21 21:08:21 +00004412 *getbufline()*
4413getbufline({expr}, {lnum} [, {end}])
Bram Moolenaar32466aa2006-02-24 23:53:04 +00004414 Return a |List| with the lines starting from {lnum} to {end}
4415 (inclusive) in the buffer {expr}. If {end} is omitted, a
4416 |List| with only the line {lnum} is returned.
Bram Moolenaar45360022005-07-21 21:08:21 +00004417
4418 For the use of {expr}, see |bufname()| above.
4419
Bram Moolenaar661b1822005-07-28 22:36:45 +00004420 For {lnum} and {end} "$" can be used for the last line of the
4421 buffer. Otherwise a number must be used.
Bram Moolenaar45360022005-07-21 21:08:21 +00004422
4423 When {lnum} is smaller than 1 or bigger than the number of
Bram Moolenaar32466aa2006-02-24 23:53:04 +00004424 lines in the buffer, an empty |List| is returned.
Bram Moolenaar45360022005-07-21 21:08:21 +00004425
4426 When {end} is greater than the number of lines in the buffer,
4427 it is treated as {end} is set to the number of lines in the
Bram Moolenaar32466aa2006-02-24 23:53:04 +00004428 buffer. When {end} is before {lnum} an empty |List| is
Bram Moolenaar45360022005-07-21 21:08:21 +00004429 returned.
4430
Bram Moolenaar661b1822005-07-28 22:36:45 +00004431 This function works only for loaded buffers. For unloaded and
Bram Moolenaar32466aa2006-02-24 23:53:04 +00004432 non-existing buffers, an empty |List| is returned.
Bram Moolenaar45360022005-07-21 21:08:21 +00004433
4434 Example: >
4435 :let lines = getbufline(bufnr("myfile"), 1, "$")
Bram Moolenaara14de3d2005-01-07 21:48:26 +00004436
Bram Moolenaar63dbda12013-02-20 21:12:10 +01004437getbufvar({expr}, {varname} [, {def}]) *getbufvar()*
Bram Moolenaara14de3d2005-01-07 21:48:26 +00004438 The result is the value of option or local buffer variable
4439 {varname} in buffer {expr}. Note that the name without "b:"
4440 must be used.
Bram Moolenaarc236c162008-07-13 17:41:49 +00004441 When {varname} is empty returns a dictionary with all the
4442 buffer-local variables.
Bram Moolenaar30567352016-08-27 21:25:44 +02004443 When {varname} is equal to "&" returns a dictionary with all
4444 the buffer-local options.
4445 Otherwise, when {varname} starts with "&" returns the value of
4446 a buffer-local option.
Bram Moolenaar4317d9b2005-03-18 20:25:31 +00004447 This also works for a global or buffer-local option, but it
4448 doesn't work for a global variable, window-local variable or
4449 window-local option.
Bram Moolenaara14de3d2005-01-07 21:48:26 +00004450 For the use of {expr}, see |bufname()| above.
Bram Moolenaar63dbda12013-02-20 21:12:10 +01004451 When the buffer or variable doesn't exist {def} or an empty
4452 string is returned, there is no error message.
Bram Moolenaara14de3d2005-01-07 21:48:26 +00004453 Examples: >
4454 :let bufmodified = getbufvar(1, "&mod")
4455 :echo "todo myvar = " . getbufvar("todo", "myvar")
4456<
Bram Moolenaar07ad8162018-02-13 13:59:59 +01004457getchangelist({expr}) *getchangelist()*
4458 Returns the |changelist| for the buffer {expr}. For the use
4459 of {expr}, see |bufname()| above. If buffer {expr} doesn't
4460 exist, an empty list is returned.
4461
4462 The returned list contains two entries: a list with the change
4463 locations and the current position in the list. Each
4464 entry in the change list is a dictionary with the following
4465 entries:
4466 col column number
4467 coladd column offset for 'virtualedit'
4468 lnum line number
4469 If buffer {expr} is the current buffer, then the current
4470 position refers to the position in the list. For other
4471 buffers, it is set to the length of the list.
4472
Bram Moolenaar071d4272004-06-13 20:20:40 +00004473getchar([expr]) *getchar()*
Bram Moolenaar91170f82006-05-05 21:15:17 +00004474 Get a single character from the user or input stream.
Bram Moolenaar071d4272004-06-13 20:20:40 +00004475 If [expr] is omitted, wait until a character is available.
4476 If [expr] is 0, only get a character when one is available.
Bram Moolenaar91170f82006-05-05 21:15:17 +00004477 Return zero otherwise.
Bram Moolenaar071d4272004-06-13 20:20:40 +00004478 If [expr] is 1, only check if a character is available, it is
Bram Moolenaar91170f82006-05-05 21:15:17 +00004479 not consumed. Return zero if no character available.
4480
Bram Moolenaardfb18412013-12-11 18:53:29 +01004481 Without [expr] and when [expr] is 0 a whole character or
Bram Moolenaarc577d812017-07-08 22:37:34 +02004482 special key is returned. If it is a single character, the
Bram Moolenaar91170f82006-05-05 21:15:17 +00004483 result is a number. Use nr2char() to convert it to a String.
4484 Otherwise a String is returned with the encoded character.
Bram Moolenaarc577d812017-07-08 22:37:34 +02004485 For a special key it's a String with a sequence of bytes
4486 starting with 0x80 (decimal: 128). This is the same value as
4487 the String "\<Key>", e.g., "\<Left>". The returned value is
4488 also a String when a modifier (shift, control, alt) was used
4489 that is not included in the character.
Bram Moolenaar91170f82006-05-05 21:15:17 +00004490
Bram Moolenaar822ff862014-06-12 21:46:14 +02004491 When [expr] is 0 and Esc is typed, there will be a short delay
4492 while Vim waits to see if this is the start of an escape
4493 sequence.
4494
Bram Moolenaardfb18412013-12-11 18:53:29 +01004495 When [expr] is 1 only the first byte is returned. For a
Bram Moolenaar56a907a2006-05-06 21:44:30 +00004496 one-byte character it is the character itself as a number.
4497 Use nr2char() to convert it to a String.
Bram Moolenaar91170f82006-05-05 21:15:17 +00004498
Bram Moolenaarf1568ec2011-12-14 21:17:39 +01004499 Use getcharmod() to obtain any additional modifiers.
4500
Bram Moolenaar219b8702006-11-01 14:32:36 +00004501 When the user clicks a mouse button, the mouse event will be
4502 returned. The position can then be found in |v:mouse_col|,
Bram Moolenaar511972d2016-06-04 18:09:59 +02004503 |v:mouse_lnum|, |v:mouse_winid| and |v:mouse_win|. This
4504 example positions the mouse as it would normally happen: >
Bram Moolenaar219b8702006-11-01 14:32:36 +00004505 let c = getchar()
Bram Moolenaar446cb832008-06-24 21:56:24 +00004506 if c == "\<LeftMouse>" && v:mouse_win > 0
Bram Moolenaar219b8702006-11-01 14:32:36 +00004507 exe v:mouse_win . "wincmd w"
4508 exe v:mouse_lnum
4509 exe "normal " . v:mouse_col . "|"
4510 endif
4511<
Bram Moolenaar690afe12017-01-28 18:34:47 +01004512 When using bracketed paste only the first character is
4513 returned, the rest of the pasted text is dropped.
4514 |xterm-bracketed-paste|.
4515
Bram Moolenaar071d4272004-06-13 20:20:40 +00004516 There is no prompt, you will somehow have to make clear to the
4517 user that a character has to be typed.
4518 There is no mapping for the character.
4519 Key codes are replaced, thus when the user presses the <Del>
4520 key you get the code for the <Del> key, not the raw character
4521 sequence. Examples: >
4522 getchar() == "\<Del>"
4523 getchar() == "\<S-Left>"
4524< This example redefines "f" to ignore case: >
4525 :nmap f :call FindChar()<CR>
4526 :function FindChar()
4527 : let c = nr2char(getchar())
4528 : while col('.') < col('$') - 1
4529 : normal l
4530 : if getline('.')[col('.') - 1] ==? c
4531 : break
4532 : endif
4533 : endwhile
4534 :endfunction
Bram Moolenaared32d942014-12-06 23:33:00 +01004535<
Bram Moolenaar2b8388b2015-02-28 13:11:45 +01004536 You may also receive synthetic characters, such as
Bram Moolenaared32d942014-12-06 23:33:00 +01004537 |<CursorHold>|. Often you will want to ignore this and get
4538 another character: >
4539 :function GetKey()
4540 : let c = getchar()
4541 : while c == "\<CursorHold>"
4542 : let c = getchar()
4543 : endwhile
4544 : return c
4545 :endfunction
Bram Moolenaar071d4272004-06-13 20:20:40 +00004546
4547getcharmod() *getcharmod()*
4548 The result is a Number which is the state of the modifiers for
4549 the last obtained character with getchar() or in another way.
4550 These values are added together:
4551 2 shift
4552 4 control
4553 8 alt (meta)
Bram Moolenaarf1568ec2011-12-14 21:17:39 +01004554 16 meta (when it's different from ALT)
4555 32 mouse double click
4556 64 mouse triple click
4557 96 mouse quadruple click (== 32 + 64)
4558 128 command (Macintosh only)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004559 Only the modifiers that have not been included in the
Bram Moolenaar58b85342016-08-14 19:54:54 +02004560 character itself are obtained. Thus Shift-a results in "A"
Bram Moolenaar8f3f58f2010-01-06 20:52:26 +01004561 without a modifier.
Bram Moolenaar071d4272004-06-13 20:20:40 +00004562
Bram Moolenaardbd24b52015-08-11 14:26:19 +02004563getcharsearch() *getcharsearch()*
4564 Return the current character search information as a {dict}
4565 with the following entries:
4566
4567 char character previously used for a character
4568 search (|t|, |f|, |T|, or |F|); empty string
4569 if no character search has been performed
4570 forward direction of character search; 1 for forward,
4571 0 for backward
4572 until type of character search; 1 for a |t| or |T|
4573 character search, 0 for an |f| or |F|
4574 character search
4575
4576 This can be useful to always have |;| and |,| search
4577 forward/backward regardless of the direction of the previous
4578 character search: >
4579 :nnoremap <expr> ; getcharsearch().forward ? ';' : ','
4580 :nnoremap <expr> , getcharsearch().forward ? ',' : ';'
4581< Also see |setcharsearch()|.
4582
Bram Moolenaar071d4272004-06-13 20:20:40 +00004583getcmdline() *getcmdline()*
4584 Return the current command-line. Only works when the command
4585 line is being edited, thus requires use of |c_CTRL-\_e| or
4586 |c_CTRL-R_=|.
4587 Example: >
4588 :cmap <F7> <C-\>eescape(getcmdline(), ' \')<CR>
Bram Moolenaarbfd8fc02005-09-20 23:22:24 +00004589< Also see |getcmdtype()|, |getcmdpos()| and |setcmdpos()|.
Bram Moolenaar95bafa22018-10-02 13:26:25 +02004590 Returns an empty string when entering a password or using
4591 |inputsecret()|.
Bram Moolenaar071d4272004-06-13 20:20:40 +00004592
Bram Moolenaar5f2bb9f2005-01-11 21:29:04 +00004593getcmdpos() *getcmdpos()*
Bram Moolenaar071d4272004-06-13 20:20:40 +00004594 Return the position of the cursor in the command line as a
4595 byte count. The first column is 1.
4596 Only works when editing the command line, thus requires use of
Bram Moolenaar5b435d62012-04-05 17:33:26 +02004597 |c_CTRL-\_e| or |c_CTRL-R_=| or an expression mapping.
4598 Returns 0 otherwise.
Bram Moolenaarbfd8fc02005-09-20 23:22:24 +00004599 Also see |getcmdtype()|, |setcmdpos()| and |getcmdline()|.
4600
4601getcmdtype() *getcmdtype()*
4602 Return the current command-line type. Possible return values
4603 are:
Bram Moolenaar1e015462005-09-25 22:16:38 +00004604 : normal Ex command
4605 > debug mode command |debug-mode|
4606 / forward search command
4607 ? backward search command
4608 @ |input()| command
4609 - |:insert| or |:append| command
Bram Moolenaar6e932462014-09-09 18:48:09 +02004610 = |i_CTRL-R_=|
Bram Moolenaarbfd8fc02005-09-20 23:22:24 +00004611 Only works when editing the command line, thus requires use of
Bram Moolenaar5b435d62012-04-05 17:33:26 +02004612 |c_CTRL-\_e| or |c_CTRL-R_=| or an expression mapping.
4613 Returns an empty string otherwise.
Bram Moolenaarbfd8fc02005-09-20 23:22:24 +00004614 Also see |getcmdpos()|, |setcmdpos()| and |getcmdline()|.
Bram Moolenaar071d4272004-06-13 20:20:40 +00004615
Bram Moolenaarfb539272014-08-22 19:21:47 +02004616getcmdwintype() *getcmdwintype()*
4617 Return the current |command-line-window| type. Possible return
4618 values are the same as |getcmdtype()|. Returns an empty string
4619 when not in the command-line window.
4620
Bram Moolenaare9d58a62016-08-13 15:07:41 +02004621getcompletion({pat}, {type} [, {filtered}]) *getcompletion()*
Bram Moolenaaraa4d7322016-07-09 18:50:29 +02004622 Return a list of command-line completion matches. {type}
4623 specifies what for. The following completion types are
4624 supported:
4625
Bram Moolenaarcd43eff2018-03-29 15:55:38 +02004626 arglist file names in argument list
Bram Moolenaaraa4d7322016-07-09 18:50:29 +02004627 augroup autocmd groups
4628 buffer buffer names
4629 behave :behave suboptions
4630 color color schemes
4631 command Ex command (and arguments)
4632 compiler compilers
4633 cscope |:cscope| suboptions
4634 dir directory names
4635 environment environment variable names
4636 event autocommand events
4637 expression Vim expression
4638 file file and directory names
4639 file_in_path file and directory names in |'path'|
4640 filetype filetype names |'filetype'|
4641 function function name
4642 help help subjects
4643 highlight highlight groups
4644 history :history suboptions
4645 locale locale names (as output of locale -a)
Bram Moolenaarcae92dc2017-08-06 15:22:15 +02004646 mapclear buffer argument
Bram Moolenaaraa4d7322016-07-09 18:50:29 +02004647 mapping mapping name
4648 menu menus
Bram Moolenaar9e507ca2016-10-15 15:39:39 +02004649 messages |:messages| suboptions
Bram Moolenaaraa4d7322016-07-09 18:50:29 +02004650 option options
Bram Moolenaar9e507ca2016-10-15 15:39:39 +02004651 packadd optional package |pack-add| names
Bram Moolenaaraa4d7322016-07-09 18:50:29 +02004652 shellcmd Shell command
4653 sign |:sign| suboptions
4654 syntax syntax file names |'syntax'|
4655 syntime |:syntime| suboptions
4656 tag tags
4657 tag_listfiles tags, file names
4658 user user names
4659 var user variables
4660
4661 If {pat} is an empty string, then all the matches are returned.
4662 Otherwise only items matching {pat} are returned. See
4663 |wildcards| for the use of special characters in {pat}.
4664
Bram Moolenaare9d58a62016-08-13 15:07:41 +02004665 If the optional {filtered} flag is set to 1, then 'wildignore'
4666 is applied to filter the results. Otherwise all the matches
4667 are returned. The 'wildignorecase' option always applies.
4668
Bram Moolenaaraa4d7322016-07-09 18:50:29 +02004669 If there are no matches, an empty list is returned. An
4670 invalid value for {type} produces an error.
4671
Bram Moolenaar6f6c0f82014-05-28 20:31:42 +02004672 *getcurpos()*
4673getcurpos() Get the position of the cursor. This is like getpos('.'), but
4674 includes an extra item in the list:
Bram Moolenaar345efa02016-01-15 20:57:49 +01004675 [bufnum, lnum, col, off, curswant] ~
Bram Moolenaar6f6c0f82014-05-28 20:31:42 +02004676 The "curswant" number is the preferred column when moving the
Bram Moolenaarcd5c8f82017-04-09 20:11:58 +02004677 cursor vertically. Also see |getpos()|.
4678
Bram Moolenaar6f6c0f82014-05-28 20:31:42 +02004679 This can be used to save and restore the cursor position: >
4680 let save_cursor = getcurpos()
4681 MoveTheCursorAround
4682 call setpos('.', save_cursor)
Bram Moolenaarcd5c8f82017-04-09 20:11:58 +02004683< Note that this only works within the window. See
4684 |winrestview()| for restoring more state.
Bram Moolenaar071d4272004-06-13 20:20:40 +00004685 *getcwd()*
Bram Moolenaarc9703302016-01-17 21:49:33 +01004686getcwd([{winnr} [, {tabnr}]])
4687 The result is a String, which is the name of the current
Bram Moolenaar071d4272004-06-13 20:20:40 +00004688 working directory.
Bram Moolenaarc9703302016-01-17 21:49:33 +01004689
4690 With {winnr} return the local current directory of this window
Bram Moolenaar54591292018-02-09 20:53:59 +01004691 in the current tab page. {winnr} can be the window number or
4692 the |window-ID|.
4693 If {winnr} is -1 return the name of the global working
4694 directory. See also |haslocaldir()|.
4695
Bram Moolenaarc9703302016-01-17 21:49:33 +01004696 With {winnr} and {tabnr} return the local current directory of
4697 the window in the specified tab page.
4698 Return an empty string if the arguments are invalid.
Bram Moolenaar071d4272004-06-13 20:20:40 +00004699
4700getfsize({fname}) *getfsize()*
4701 The result is a Number, which is the size in bytes of the
4702 given file {fname}.
4703 If {fname} is a directory, 0 is returned.
4704 If the file {fname} can't be found, -1 is returned.
Bram Moolenaard827ada2007-06-19 15:19:55 +00004705 If the size of {fname} is too big to fit in a Number then -2
4706 is returned.
Bram Moolenaar071d4272004-06-13 20:20:40 +00004707
Bram Moolenaard8b0cf12004-12-12 11:33:30 +00004708getfontname([{name}]) *getfontname()*
4709 Without an argument returns the name of the normal font being
4710 used. Like what is used for the Normal highlight group
4711 |hl-Normal|.
4712 With an argument a check is done whether {name} is a valid
4713 font name. If not then an empty string is returned.
4714 Otherwise the actual font name is returned, or {name} if the
4715 GUI does not support obtaining the real name.
Bram Moolenaarc6fe9192006-04-09 21:54:49 +00004716 Only works when the GUI is running, thus not in your vimrc or
Bram Moolenaard8b0cf12004-12-12 11:33:30 +00004717 gvimrc file. Use the |GUIEnter| autocommand to use this
4718 function just after the GUI has started.
Bram Moolenaar3df01732017-02-17 22:47:16 +01004719 Note that the GTK GUI accepts any font name, thus checking for
4720 a valid name does not work.
Bram Moolenaard8b0cf12004-12-12 11:33:30 +00004721
Bram Moolenaar5eb86f92004-07-26 12:53:41 +00004722getfperm({fname}) *getfperm()*
4723 The result is a String, which is the read, write, and execute
4724 permissions of the given file {fname}.
4725 If {fname} does not exist or its directory cannot be read, an
4726 empty string is returned.
4727 The result is of the form "rwxrwxrwx", where each group of
4728 "rwx" flags represent, in turn, the permissions of the owner
4729 of the file, the group the file belongs to, and other users.
4730 If a user does not have a given permission the flag for this
Bram Moolenaar9b451252012-08-15 17:43:31 +02004731 is replaced with the string "-". Examples: >
Bram Moolenaar5eb86f92004-07-26 12:53:41 +00004732 :echo getfperm("/etc/passwd")
Bram Moolenaar9b451252012-08-15 17:43:31 +02004733 :echo getfperm(expand("~/.vimrc"))
Bram Moolenaar5eb86f92004-07-26 12:53:41 +00004734< This will hopefully (from a security point of view) display
4735 the string "rw-r--r--" or even "rw-------".
Bram Moolenaare2cc9702005-03-15 22:43:58 +00004736
Bram Moolenaar2ec618c2016-10-01 14:47:05 +02004737 For setting permissions use |setfperm()|.
Bram Moolenaar80492532016-03-08 17:08:53 +01004738
Bram Moolenaar071d4272004-06-13 20:20:40 +00004739getftime({fname}) *getftime()*
4740 The result is a Number, which is the last modification time of
4741 the given file {fname}. The value is measured as seconds
4742 since 1st Jan 1970, and may be passed to strftime(). See also
4743 |localtime()| and |strftime()|.
4744 If the file {fname} can't be found -1 is returned.
4745
Bram Moolenaar5eb86f92004-07-26 12:53:41 +00004746getftype({fname}) *getftype()*
4747 The result is a String, which is a description of the kind of
4748 file of the given file {fname}.
4749 If {fname} does not exist an empty string is returned.
4750 Here is a table over different kinds of files and their
4751 results:
4752 Normal file "file"
4753 Directory "dir"
4754 Symbolic link "link"
4755 Block device "bdev"
4756 Character device "cdev"
4757 Socket "socket"
4758 FIFO "fifo"
4759 All other "other"
4760 Example: >
4761 getftype("/home")
4762< Note that a type such as "link" will only be returned on
4763 systems that support it. On some systems only "dir" and
Bram Moolenaar13d5aee2016-01-21 23:36:05 +01004764 "file" are returned. On MS-Windows a symbolic link to a
4765 directory returns "dir" instead of "link".
Bram Moolenaar5eb86f92004-07-26 12:53:41 +00004766
Bram Moolenaard96ff162018-02-18 22:13:29 +01004767getjumplist([{winnr} [, {tabnr}]]) *getjumplist()*
Bram Moolenaar4f505882018-02-10 21:06:32 +01004768 Returns the |jumplist| for the specified window.
4769
4770 Without arguments use the current window.
4771 With {winnr} only use this window in the current tab page.
4772 {winnr} can also be a |window-ID|.
4773 With {winnr} and {tabnr} use the window in the specified tab
4774 page.
4775
4776 The returned list contains two entries: a list with the jump
4777 locations and the last used jump position number in the list.
4778 Each entry in the jump location list is a dictionary with
4779 the following entries:
4780 bufnr buffer number
4781 col column number
4782 coladd column offset for 'virtualedit'
4783 filename filename if available
4784 lnum line number
4785
Bram Moolenaar071d4272004-06-13 20:20:40 +00004786 *getline()*
Bram Moolenaara14de3d2005-01-07 21:48:26 +00004787getline({lnum} [, {end}])
4788 Without {end} the result is a String, which is line {lnum}
4789 from the current buffer. Example: >
Bram Moolenaar071d4272004-06-13 20:20:40 +00004790 getline(1)
4791< When {lnum} is a String that doesn't start with a
Bram Moolenaarf2732452018-06-03 14:47:35 +02004792 digit, |line()| is called to translate the String into a Number.
Bram Moolenaar071d4272004-06-13 20:20:40 +00004793 To get the line under the cursor: >
4794 getline(".")
4795< When {lnum} is smaller than 1 or bigger than the number of
4796 lines in the buffer, an empty string is returned.
4797
Bram Moolenaar32466aa2006-02-24 23:53:04 +00004798 When {end} is given the result is a |List| where each item is
4799 a line from the current buffer in the range {lnum} to {end},
Bram Moolenaara14de3d2005-01-07 21:48:26 +00004800 including line {end}.
4801 {end} is used in the same way as {lnum}.
4802 Non-existing lines are silently omitted.
Bram Moolenaar32466aa2006-02-24 23:53:04 +00004803 When {end} is before {lnum} an empty |List| is returned.
Bram Moolenaara14de3d2005-01-07 21:48:26 +00004804 Example: >
4805 :let start = line('.')
4806 :let end = search("^$") - 1
4807 :let lines = getline(start, end)
4808
Bram Moolenaaref2f6562007-05-06 13:32:59 +00004809< To get lines from another buffer see |getbufline()|
4810
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01004811getloclist({nr} [, {what}]) *getloclist()*
Bram Moolenaar17c7c012006-01-26 22:25:15 +00004812 Returns a list with all the entries in the location list for
Bram Moolenaar7571d552016-08-18 22:54:46 +02004813 window {nr}. {nr} can be the window number or the |window-ID|.
Bram Moolenaar888ccac2016-06-04 18:49:36 +02004814 When {nr} is zero the current window is used.
4815
Bram Moolenaar17c7c012006-01-26 22:25:15 +00004816 For a location list window, the displayed location list is
Bram Moolenaar280f1262006-01-30 00:14:18 +00004817 returned. For an invalid window number {nr}, an empty list is
Bram Moolenaar8f3f58f2010-01-06 20:52:26 +01004818 returned. Otherwise, same as |getqflist()|.
Bram Moolenaara14de3d2005-01-07 21:48:26 +00004819
Bram Moolenaard823fa92016-08-12 16:29:27 +02004820 If the optional {what} dictionary argument is supplied, then
4821 returns the items listed in {what} as a dictionary. Refer to
4822 |getqflist()| for the supported items in {what}.
Bram Moolenaarc9cc9c72018-09-02 15:18:42 +02004823 If {what} contains 'filewinid', then returns the id of the
4824 window used to display files from the location list. This
4825 field is applicable only when called from a location list
Bram Moolenaar5b69c222019-01-11 14:50:06 +01004826 window. See |location-list-file-window| for more details.
Bram Moolenaard823fa92016-08-12 16:29:27 +02004827
Bram Moolenaar6ee10162007-07-26 20:58:42 +00004828getmatches() *getmatches()*
4829 Returns a |List| with all matches previously defined by
4830 |matchadd()| and the |:match| commands. |getmatches()| is
4831 useful in combination with |setmatches()|, as |setmatches()|
4832 can restore a list of matches saved by |getmatches()|.
4833 Example: >
4834 :echo getmatches()
4835< [{'group': 'MyGroup1', 'pattern': 'TODO',
4836 'priority': 10, 'id': 1}, {'group': 'MyGroup2',
4837 'pattern': 'FIXME', 'priority': 10, 'id': 2}] >
4838 :let m = getmatches()
4839 :call clearmatches()
4840 :echo getmatches()
4841< [] >
4842 :call setmatches(m)
4843 :echo getmatches()
4844< [{'group': 'MyGroup1', 'pattern': 'TODO',
4845 'priority': 10, 'id': 1}, {'group': 'MyGroup2',
4846 'pattern': 'FIXME', 'priority': 10, 'id': 2}] >
4847 :unlet m
4848<
Bram Moolenaar822ff862014-06-12 21:46:14 +02004849 *getpid()*
4850getpid() Return a Number which is the process ID of the Vim process.
4851 On Unix and MS-Windows this is a unique number, until Vim
Bram Moolenaar58b85342016-08-14 19:54:54 +02004852 exits. On MS-DOS it's always zero.
Bram Moolenaar822ff862014-06-12 21:46:14 +02004853
4854 *getpos()*
4855getpos({expr}) Get the position for {expr}. For possible values of {expr}
4856 see |line()|. For getting the cursor position see
4857 |getcurpos()|.
4858 The result is a |List| with four numbers:
4859 [bufnum, lnum, col, off]
4860 "bufnum" is zero, unless a mark like '0 or 'A is used, then it
4861 is the buffer number of the mark.
4862 "lnum" and "col" are the position in the buffer. The first
4863 column is 1.
4864 The "off" number is zero, unless 'virtualedit' is used. Then
4865 it is the offset in screen columns from the start of the
4866 character. E.g., a position within a <Tab> or after the last
4867 character.
4868 Note that for '< and '> Visual mode matters: when it is "V"
4869 (visual line mode) the column of '< is zero and the column of
4870 '> is a large number.
4871 This can be used to save and restore the position of a mark: >
4872 let save_a_mark = getpos("'a")
4873 ...
Bram Moolenaared32d942014-12-06 23:33:00 +01004874 call setpos("'a", save_a_mark)
Bram Moolenaar822ff862014-06-12 21:46:14 +02004875< Also see |getcurpos()| and |setpos()|.
4876
Bram Moolenaar6ee10162007-07-26 20:58:42 +00004877
Bram Moolenaard823fa92016-08-12 16:29:27 +02004878getqflist([{what}]) *getqflist()*
Bram Moolenaar68b76a62005-03-25 21:53:48 +00004879 Returns a list with all the current quickfix errors. Each
4880 list item is a dictionary with these entries:
4881 bufnr number of buffer that has the file name, use
4882 bufname() to get the name
Bram Moolenaard76ce852018-05-01 15:02:04 +02004883 module module name
Bram Moolenaar68b76a62005-03-25 21:53:48 +00004884 lnum line number in the buffer (first line is 1)
4885 col column number (first column is 1)
Bram Moolenaare381d3d2016-07-07 14:50:41 +02004886 vcol |TRUE|: "col" is visual column
4887 |FALSE|: "col" is byte index
Bram Moolenaar68b76a62005-03-25 21:53:48 +00004888 nr error number
Bram Moolenaar48b66fb2007-02-04 01:58:18 +00004889 pattern search pattern used to locate the error
Bram Moolenaar68b76a62005-03-25 21:53:48 +00004890 text description of the error
4891 type type of the error, 'E', '1', etc.
Bram Moolenaare381d3d2016-07-07 14:50:41 +02004892 valid |TRUE|: recognized error message
Bram Moolenaar68b76a62005-03-25 21:53:48 +00004893
Bram Moolenaar7571d552016-08-18 22:54:46 +02004894 When there is no error list or it's empty, an empty list is
Bram Moolenaar48b66fb2007-02-04 01:58:18 +00004895 returned. Quickfix list entries with non-existing buffer
4896 number are returned with "bufnr" set to zero.
Bram Moolenaare7eb9df2005-09-09 19:49:30 +00004897
Bram Moolenaar68b76a62005-03-25 21:53:48 +00004898 Useful application: Find pattern matches in multiple files and
4899 do something with them: >
4900 :vimgrep /theword/jg *.c
4901 :for d in getqflist()
4902 : echo bufname(d.bufnr) ':' d.lnum '=' d.text
4903 :endfor
Bram Moolenaard823fa92016-08-12 16:29:27 +02004904<
4905 If the optional {what} dictionary argument is supplied, then
4906 returns only the items listed in {what} as a dictionary. The
4907 following string items are supported in {what}:
Bram Moolenaarb254af32017-12-18 19:48:58 +01004908 changedtick get the total number of changes made
Bram Moolenaar15142e22018-04-30 22:19:58 +02004909 to the list |quickfix-changedtick|
4910 context get the |quickfix-context|
Bram Moolenaar36538222017-09-02 19:51:44 +02004911 efm errorformat to use when parsing "lines". If
Bram Moolenaar2f058492017-11-30 20:27:52 +01004912 not present, then the 'errorformat' option
Bram Moolenaar36538222017-09-02 19:51:44 +02004913 value is used.
Bram Moolenaara539f4f2017-08-30 20:33:55 +02004914 id get information for the quickfix list with
4915 |quickfix-ID|; zero means the id for the
Bram Moolenaar2f058492017-11-30 20:27:52 +01004916 current list or the list specified by "nr"
Bram Moolenaar5b69c222019-01-11 14:50:06 +01004917 idx index of the current entry in the quickfix
4918 list specified by 'id' or 'nr'.
4919 See |quickfix-index|
Bram Moolenaar6a8958d2017-06-22 21:33:20 +02004920 items quickfix list entries
Bram Moolenaar15142e22018-04-30 22:19:58 +02004921 lines parse a list of lines using 'efm' and return
4922 the resulting entries. Only a |List| type is
4923 accepted. The current quickfix list is not
4924 modified. See |quickfix-parse|.
Bram Moolenaar890680c2016-09-27 21:28:56 +02004925 nr get information for this quickfix list; zero
Bram Moolenaar36538222017-09-02 19:51:44 +02004926 means the current quickfix list and "$" means
Bram Moolenaar875feea2017-06-11 16:07:51 +02004927 the last quickfix list
Bram Moolenaarfc2b2702017-09-15 22:43:07 +02004928 size number of entries in the quickfix list
Bram Moolenaar15142e22018-04-30 22:19:58 +02004929 title get the list title |quickfix-title|
Bram Moolenaar74240d32017-12-10 15:26:15 +01004930 winid get the quickfix |window-ID|
Bram Moolenaard823fa92016-08-12 16:29:27 +02004931 all all of the above quickfix properties
Bram Moolenaar74240d32017-12-10 15:26:15 +01004932 Non-string items in {what} are ignored. To get the value of a
Bram Moolenaara6d48492017-12-12 22:45:31 +01004933 particular item, set it to zero.
Bram Moolenaard823fa92016-08-12 16:29:27 +02004934 If "nr" is not present then the current quickfix list is used.
Bram Moolenaara539f4f2017-08-30 20:33:55 +02004935 If both "nr" and a non-zero "id" are specified, then the list
4936 specified by "id" is used.
Bram Moolenaarb4d5fba2017-09-11 19:31:28 +02004937 To get the number of lists in the quickfix stack, set "nr" to
4938 "$" in {what}. The "nr" value in the returned dictionary
Bram Moolenaar875feea2017-06-11 16:07:51 +02004939 contains the quickfix stack size.
Bram Moolenaarb4d5fba2017-09-11 19:31:28 +02004940 When "lines" is specified, all the other items except "efm"
4941 are ignored. The returned dictionary contains the entry
4942 "items" with the list of entries.
Bram Moolenaar68b76a62005-03-25 21:53:48 +00004943
Bram Moolenaard823fa92016-08-12 16:29:27 +02004944 The returned dictionary contains the following entries:
Bram Moolenaarb254af32017-12-18 19:48:58 +01004945 changedtick total number of changes made to the
4946 list |quickfix-changedtick|
Bram Moolenaar15142e22018-04-30 22:19:58 +02004947 context quickfix list context. See |quickfix-context|
Bram Moolenaara6d48492017-12-12 22:45:31 +01004948 If not present, set to "".
4949 id quickfix list ID |quickfix-ID|. If not
4950 present, set to 0.
4951 idx index of the current entry in the list. If not
4952 present, set to 0.
4953 items quickfix list entries. If not present, set to
4954 an empty list.
4955 nr quickfix list number. If not present, set to 0
4956 size number of entries in the quickfix list. If not
4957 present, set to 0.
4958 title quickfix list title text. If not present, set
4959 to "".
Bram Moolenaar74240d32017-12-10 15:26:15 +01004960 winid quickfix |window-ID|. If not present, set to 0
Bram Moolenaard823fa92016-08-12 16:29:27 +02004961
Bram Moolenaar15142e22018-04-30 22:19:58 +02004962 Examples (See also |getqflist-examples|): >
Bram Moolenaard823fa92016-08-12 16:29:27 +02004963 :echo getqflist({'all': 1})
4964 :echo getqflist({'nr': 2, 'title': 1})
Bram Moolenaar2c809b72017-09-01 18:34:02 +02004965 :echo getqflist({'lines' : ["F1:10:L10"]})
Bram Moolenaard823fa92016-08-12 16:29:27 +02004966<
Bram Moolenaarb7cb42b2014-04-02 19:55:10 +02004967getreg([{regname} [, 1 [, {list}]]]) *getreg()*
Bram Moolenaar071d4272004-06-13 20:20:40 +00004968 The result is a String, which is the contents of register
Bram Moolenaar402d2fe2005-04-15 21:00:38 +00004969 {regname}. Example: >
Bram Moolenaar071d4272004-06-13 20:20:40 +00004970 :let cliptext = getreg('*')
Bram Moolenaardc1f1642016-08-16 18:33:43 +02004971< When {regname} was not set the result is an empty string.
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004972
4973 getreg('=') returns the last evaluated value of the expression
Bram Moolenaar402d2fe2005-04-15 21:00:38 +00004974 register. (For use in maps.)
Bram Moolenaar2389c3c2005-05-22 22:07:59 +00004975 getreg('=', 1) returns the expression itself, so that it can
4976 be restored with |setreg()|. For other registers the extra
4977 argument is ignored, thus you can always give it.
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004978
Bram Moolenaare381d3d2016-07-07 14:50:41 +02004979 If {list} is present and |TRUE|, the result type is changed
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004980 to |List|. Each list item is one text line. Use it if you care
Bram Moolenaarb7cb42b2014-04-02 19:55:10 +02004981 about zero bytes possibly present inside register: without
4982 third argument both NLs and zero bytes are represented as NLs
4983 (see |NL-used-for-Nul|).
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004984 When the register was not set an empty list is returned.
4985
Bram Moolenaar071d4272004-06-13 20:20:40 +00004986 If {regname} is not specified, |v:register| is used.
4987
Bram Moolenaara14de3d2005-01-07 21:48:26 +00004988
Bram Moolenaar071d4272004-06-13 20:20:40 +00004989getregtype([{regname}]) *getregtype()*
4990 The result is a String, which is type of register {regname}.
4991 The value will be one of:
4992 "v" for |characterwise| text
4993 "V" for |linewise| text
4994 "<CTRL-V>{width}" for |blockwise-visual| text
Bram Moolenaar32b92012014-01-14 12:33:36 +01004995 "" for an empty or unknown register
Bram Moolenaar071d4272004-06-13 20:20:40 +00004996 <CTRL-V> is one character with value 0x16.
4997 If {regname} is not specified, |v:register| is used.
4998
Bram Moolenaarb5ae48e2016-08-12 22:23:25 +02004999gettabinfo([{arg}]) *gettabinfo()*
5000 If {arg} is not specified, then information about all the tab
5001 pages is returned as a List. Each List item is a Dictionary.
5002 Otherwise, {arg} specifies the tab page number and information
5003 about that one is returned. If the tab page does not exist an
5004 empty List is returned.
5005
5006 Each List item is a Dictionary with the following entries:
Bram Moolenaar7571d552016-08-18 22:54:46 +02005007 tabnr tab page number.
Bram Moolenaar30567352016-08-27 21:25:44 +02005008 variables a reference to the dictionary with
5009 tabpage-local variables
Bram Moolenaar7571d552016-08-18 22:54:46 +02005010 windows List of |window-ID|s in the tag page.
Bram Moolenaarb5ae48e2016-08-12 22:23:25 +02005011
Bram Moolenaar63dbda12013-02-20 21:12:10 +01005012gettabvar({tabnr}, {varname} [, {def}]) *gettabvar()*
Bram Moolenaar06b5d512010-05-22 15:37:44 +02005013 Get the value of a tab-local variable {varname} in tab page
5014 {tabnr}. |t:var|
5015 Tabs are numbered starting with one.
Bram Moolenaar0e2ea1b2014-09-09 16:13:08 +02005016 When {varname} is empty a dictionary with all tab-local
5017 variables is returned.
Bram Moolenaar06b5d512010-05-22 15:37:44 +02005018 Note that the name without "t:" must be used.
Bram Moolenaar63dbda12013-02-20 21:12:10 +01005019 When the tab or variable doesn't exist {def} or an empty
5020 string is returned, there is no error message.
Bram Moolenaar06b5d512010-05-22 15:37:44 +02005021
Bram Moolenaar63dbda12013-02-20 21:12:10 +01005022gettabwinvar({tabnr}, {winnr}, {varname} [, {def}]) *gettabwinvar()*
Bram Moolenaaref2f6562007-05-06 13:32:59 +00005023 Get the value of window-local variable {varname} in window
5024 {winnr} in tab page {tabnr}.
Bram Moolenaar63dbda12013-02-20 21:12:10 +01005025 When {varname} is empty a dictionary with all window-local
5026 variables is returned.
Bram Moolenaar30567352016-08-27 21:25:44 +02005027 When {varname} is equal to "&" get the values of all
5028 window-local options in a Dictionary.
5029 Otherwise, when {varname} starts with "&" get the value of a
5030 window-local option.
Bram Moolenaar63dbda12013-02-20 21:12:10 +01005031 Note that {varname} must be the name without "w:".
Bram Moolenaarc6249bb2006-04-15 20:25:09 +00005032 Tabs are numbered starting with one. For the current tabpage
5033 use |getwinvar()|.
Bram Moolenaar7571d552016-08-18 22:54:46 +02005034 {winnr} can be the window number or the |window-ID|.
Bram Moolenaarc6249bb2006-04-15 20:25:09 +00005035 When {winnr} is zero the current window is used.
5036 This also works for a global option, buffer-local option and
5037 window-local option, but it doesn't work for a global variable
5038 or buffer-local variable.
Bram Moolenaar63dbda12013-02-20 21:12:10 +01005039 When the tab, window or variable doesn't exist {def} or an
5040 empty string is returned, there is no error message.
Bram Moolenaarc6249bb2006-04-15 20:25:09 +00005041 Examples: >
5042 :let list_is_on = gettabwinvar(1, 2, '&list')
5043 :echo "myvar = " . gettabwinvar(3, 1, 'myvar')
Bram Moolenaard46bbc72007-05-12 14:38:41 +00005044<
Bram Moolenaarb477af22018-07-15 20:20:18 +02005045 To obtain all window-local variables use: >
5046 gettabwinvar({tabnr}, {winnr}, '&')
5047
Bram Moolenaarf49cc602018-11-11 15:21:05 +01005048gettagstack([{nr}]) *gettagstack()*
5049 The result is a Dict, which is the tag stack of window {nr}.
5050 {nr} can be the window number or the |window-ID|.
5051 When {nr} is not specified, the current window is used.
5052 When window {nr} doesn't exist, an empty Dict is returned.
5053
5054 The returned dictionary contains the following entries:
5055 curidx Current index in the stack. When at
5056 top of the stack, set to (length + 1).
5057 Index of bottom of the stack is 1.
5058 items List of items in the stack. Each item
5059 is a dictionary containing the
5060 entries described below.
5061 length Number of entries in the stack.
5062
5063 Each item in the stack is a dictionary with the following
5064 entries:
5065 bufnr buffer number of the current jump
5066 from cursor position before the tag jump.
5067 See |getpos()| for the format of the
5068 returned list.
5069 matchnr current matching tag number. Used when
5070 multiple matching tags are found for a
5071 name.
5072 tagname name of the tag
5073
5074 See |tagstack| for more information about the tag stack.
5075
Bram Moolenaar7132ddc2018-07-15 17:01:11 +02005076getwininfo([{winid}]) *getwininfo()*
5077 Returns information about windows as a List with Dictionaries.
5078
5079 If {winid} is given Information about the window with that ID
5080 is returned. If the window does not exist the result is an
5081 empty list.
5082
5083 Without {winid} information about all the windows in all the
5084 tab pages is returned.
5085
5086 Each List item is a Dictionary with the following entries:
5087 bufnr number of buffer in the window
5088 height window height (excluding winbar)
Bram Moolenaar7132ddc2018-07-15 17:01:11 +02005089 loclist 1 if showing a location list
5090 {only with the +quickfix feature}
5091 quickfix 1 if quickfix or location list window
5092 {only with the +quickfix feature}
5093 terminal 1 if a terminal window
5094 {only with the +terminal feature}
5095 tabnr tab page number
5096 variables a reference to the dictionary with
5097 window-local variables
5098 width window width
Bram Moolenaarb477af22018-07-15 20:20:18 +02005099 winbar 1 if the window has a toolbar, 0
5100 otherwise
Bram Moolenaar7132ddc2018-07-15 17:01:11 +02005101 wincol leftmost screen column of the window,
5102 col from |win_screenpos()|
5103 winid |window-ID|
5104 winnr window number
5105 winrow topmost screen column of the window,
5106 row from |win_screenpos()|
5107
Bram Moolenaar3f54fd32018-03-03 21:29:55 +01005108getwinpos([{timeout}]) *getwinpos()*
5109 The result is a list with two numbers, the result of
Bram Moolenaar9d87a372018-12-18 21:41:50 +01005110 getwinposx() and getwinposy() combined:
Bram Moolenaar3f54fd32018-03-03 21:29:55 +01005111 [x-pos, y-pos]
5112 {timeout} can be used to specify how long to wait in msec for
5113 a response from the terminal. When omitted 100 msec is used.
Bram Moolenaarb5b75622018-03-09 22:22:21 +01005114 Use a longer time for a remote terminal.
5115 When using a value less than 10 and no response is received
5116 within that time, a previously reported position is returned,
5117 if available. This can be used to poll for the position and
Bram Moolenaar5b69c222019-01-11 14:50:06 +01005118 do some work in the meantime: >
Bram Moolenaarb5b75622018-03-09 22:22:21 +01005119 while 1
5120 let res = getwinpos(1)
5121 if res[0] >= 0
5122 break
5123 endif
5124 " Do some work here
5125 endwhile
5126<
Bram Moolenaar071d4272004-06-13 20:20:40 +00005127 *getwinposx()*
5128getwinposx() The result is a Number, which is the X coordinate in pixels of
Bram Moolenaarcd5c8f82017-04-09 20:11:58 +02005129 the left hand side of the GUI Vim window. Also works for an
Bram Moolenaar3f54fd32018-03-03 21:29:55 +01005130 xterm (uses a timeout of 100 msec).
Bram Moolenaarcd5c8f82017-04-09 20:11:58 +02005131 The result will be -1 if the information is not available.
5132 The value can be used with `:winpos`.
Bram Moolenaar071d4272004-06-13 20:20:40 +00005133
5134 *getwinposy()*
5135getwinposy() The result is a Number, which is the Y coordinate in pixels of
Bram Moolenaar3f54fd32018-03-03 21:29:55 +01005136 the top of the GUI Vim window. Also works for an xterm (uses
5137 a timeout of 100 msec).
Bram Moolenaarcd5c8f82017-04-09 20:11:58 +02005138 The result will be -1 if the information is not available.
5139 The value can be used with `:winpos`.
Bram Moolenaar071d4272004-06-13 20:20:40 +00005140
Bram Moolenaar63dbda12013-02-20 21:12:10 +01005141getwinvar({winnr}, {varname} [, {def}]) *getwinvar()*
Bram Moolenaarc6249bb2006-04-15 20:25:09 +00005142 Like |gettabwinvar()| for the current tabpage.
Bram Moolenaar071d4272004-06-13 20:20:40 +00005143 Examples: >
5144 :let list_is_on = getwinvar(2, '&list')
5145 :echo "myvar = " . getwinvar(1, 'myvar')
5146<
Bram Moolenaard8b77f72015-03-05 21:21:19 +01005147glob({expr} [, {nosuf} [, {list} [, {alllinks}]]]) *glob()*
Bram Moolenaarbb5ddda2008-11-28 10:01:10 +00005148 Expand the file wildcards in {expr}. See |wildcards| for the
Bram Moolenaaref2f6562007-05-06 13:32:59 +00005149 use of special characters.
Bram Moolenaar84f72352012-03-11 15:57:40 +01005150
Bram Moolenaare381d3d2016-07-07 14:50:41 +02005151 Unless the optional {nosuf} argument is given and is |TRUE|,
Bram Moolenaarbb5ddda2008-11-28 10:01:10 +00005152 the 'suffixes' and 'wildignore' options apply: Names matching
5153 one of the patterns in 'wildignore' will be skipped and
5154 'suffixes' affect the ordering of matches.
Bram Moolenaar81af9252010-12-10 20:35:50 +01005155 'wildignorecase' always applies.
Bram Moolenaar84f72352012-03-11 15:57:40 +01005156
Bram Moolenaare381d3d2016-07-07 14:50:41 +02005157 When {list} is present and it is |TRUE| the result is a List
Bram Moolenaar84f72352012-03-11 15:57:40 +01005158 with all matching files. The advantage of using a List is,
5159 you also get filenames containing newlines correctly.
5160 Otherwise the result is a String and when there are several
5161 matches, they are separated by <NL> characters.
5162
5163 If the expansion fails, the result is an empty String or List.
Bram Moolenaard8b77f72015-03-05 21:21:19 +01005164
Bram Moolenaar61d35bd2012-03-28 20:51:51 +02005165 A name for a non-existing file is not included. A symbolic
5166 link is only included if it points to an existing file.
Bram Moolenaard8b77f72015-03-05 21:21:19 +01005167 However, when the {alllinks} argument is present and it is
Bram Moolenaare381d3d2016-07-07 14:50:41 +02005168 |TRUE| then all symbolic links are included.
Bram Moolenaar071d4272004-06-13 20:20:40 +00005169
5170 For most systems backticks can be used to get files names from
5171 any external command. Example: >
5172 :let tagfiles = glob("`find . -name tags -print`")
5173 :let &tags = substitute(tagfiles, "\n", ",", "g")
5174< The result of the program inside the backticks should be one
Bram Moolenaar58b85342016-08-14 19:54:54 +02005175 item per line. Spaces inside an item are allowed.
Bram Moolenaar071d4272004-06-13 20:20:40 +00005176
5177 See |expand()| for expanding special Vim variables. See
5178 |system()| for getting the raw output of an external command.
5179
Bram Moolenaar5837f1f2015-03-21 18:06:14 +01005180glob2regpat({expr}) *glob2regpat()*
5181 Convert a file pattern, as used by glob(), into a search
5182 pattern. The result can be used to match with a string that
5183 is a file name. E.g. >
5184 if filename =~ glob2regpat('Make*.mak')
5185< This is equivalent to: >
5186 if filename =~ '^Make.*\.mak$'
Bram Moolenaar3b5f9292016-01-28 22:37:01 +01005187< When {expr} is an empty string the result is "^$", match an
5188 empty string.
Bram Moolenaard823fa92016-08-12 16:29:27 +02005189 Note that the result depends on the system. On MS-Windows
Bram Moolenaar58b85342016-08-14 19:54:54 +02005190 a backslash usually means a path separator.
Bram Moolenaar3b5f9292016-01-28 22:37:01 +01005191
Bram Moolenaard8b77f72015-03-05 21:21:19 +01005192 *globpath()*
Bram Moolenaar6463ca22016-02-13 17:04:46 +01005193globpath({path}, {expr} [, {nosuf} [, {list} [, {alllinks}]]])
Bram Moolenaar071d4272004-06-13 20:20:40 +00005194 Perform glob() on all directories in {path} and concatenate
5195 the results. Example: >
5196 :echo globpath(&rtp, "syntax/c.vim")
Bram Moolenaar1b1063a2014-05-07 18:35:30 +02005197<
5198 {path} is a comma-separated list of directory names. Each
Bram Moolenaar071d4272004-06-13 20:20:40 +00005199 directory name is prepended to {expr} and expanded like with
Bram Moolenaarbb5ddda2008-11-28 10:01:10 +00005200 |glob()|. A path separator is inserted when needed.
Bram Moolenaar071d4272004-06-13 20:20:40 +00005201 To add a comma inside a directory name escape it with a
5202 backslash. Note that on MS-Windows a directory may have a
5203 trailing backslash, remove it if you put a comma after it.
5204 If the expansion fails for one of the directories, there is no
5205 error message.
Bram Moolenaar1b1063a2014-05-07 18:35:30 +02005206
Bram Moolenaare381d3d2016-07-07 14:50:41 +02005207 Unless the optional {nosuf} argument is given and is |TRUE|,
Bram Moolenaarbb5ddda2008-11-28 10:01:10 +00005208 the 'suffixes' and 'wildignore' options apply: Names matching
5209 one of the patterns in 'wildignore' will be skipped and
5210 'suffixes' affect the ordering of matches.
Bram Moolenaar071d4272004-06-13 20:20:40 +00005211
Bram Moolenaare381d3d2016-07-07 14:50:41 +02005212 When {list} is present and it is |TRUE| the result is a List
Bram Moolenaar1b1063a2014-05-07 18:35:30 +02005213 with all matching files. The advantage of using a List is, you
5214 also get filenames containing newlines correctly. Otherwise
5215 the result is a String and when there are several matches,
5216 they are separated by <NL> characters. Example: >
5217 :echo globpath(&rtp, "syntax/c.vim", 0, 1)
5218<
Bram Moolenaar6463ca22016-02-13 17:04:46 +01005219 {alllinks} is used as with |glob()|.
Bram Moolenaard8b77f72015-03-05 21:21:19 +01005220
Bram Moolenaar02743632005-07-25 20:42:36 +00005221 The "**" item can be used to search in a directory tree.
5222 For example, to find all "README.txt" files in the directories
5223 in 'runtimepath' and below: >
5224 :echo globpath(&rtp, "**/README.txt")
Bram Moolenaarc236c162008-07-13 17:41:49 +00005225< Upwards search and limiting the depth of "**" is not
5226 supported, thus using 'path' will not always work properly.
5227
Bram Moolenaar071d4272004-06-13 20:20:40 +00005228 *has()*
5229has({feature}) The result is a Number, which is 1 if the feature {feature} is
5230 supported, zero otherwise. The {feature} argument is a
5231 string. See |feature-list| below.
5232 Also see |exists()|.
5233
Bram Moolenaar2fda12f2005-01-15 22:14:15 +00005234
5235has_key({dict}, {key}) *has_key()*
Bram Moolenaar32466aa2006-02-24 23:53:04 +00005236 The result is a Number, which is 1 if |Dictionary| {dict} has
5237 an entry with key {key}. Zero otherwise.
Bram Moolenaar2fda12f2005-01-15 22:14:15 +00005238
Bram Moolenaarc9703302016-01-17 21:49:33 +01005239haslocaldir([{winnr} [, {tabnr}]]) *haslocaldir()*
5240 The result is a Number, which is 1 when the window has set a
5241 local path via |:lcd|, and 0 otherwise.
5242
5243 Without arguments use the current window.
5244 With {winnr} use this window in the current tab page.
5245 With {winnr} and {tabnr} use the window in the specified tab
5246 page.
Bram Moolenaar7571d552016-08-18 22:54:46 +02005247 {winnr} can be the window number or the |window-ID|.
Bram Moolenaarc9703302016-01-17 21:49:33 +01005248 Return 0 if the arguments are invalid.
Bram Moolenaar2fda12f2005-01-15 22:14:15 +00005249
Bram Moolenaar97b2ad32006-03-18 21:40:56 +00005250hasmapto({what} [, {mode} [, {abbr}]]) *hasmapto()*
Bram Moolenaar071d4272004-06-13 20:20:40 +00005251 The result is a Number, which is 1 if there is a mapping that
5252 contains {what} in somewhere in the rhs (what it is mapped to)
5253 and this mapping exists in one of the modes indicated by
5254 {mode}.
Bram Moolenaare381d3d2016-07-07 14:50:41 +02005255 When {abbr} is there and it is |TRUE| use abbreviations
Bram Moolenaar39f05632006-03-19 22:15:26 +00005256 instead of mappings. Don't forget to specify Insert and/or
5257 Command-line mode.
Bram Moolenaar071d4272004-06-13 20:20:40 +00005258 Both the global mappings and the mappings local to the current
5259 buffer are checked for a match.
5260 If no matching mapping is found 0 is returned.
5261 The following characters are recognized in {mode}:
5262 n Normal mode
5263 v Visual mode
5264 o Operator-pending mode
5265 i Insert mode
5266 l Language-Argument ("r", "f", "t", etc.)
5267 c Command-line mode
5268 When {mode} is omitted, "nvo" is used.
5269
5270 This function is useful to check if a mapping already exists
Bram Moolenaar58b85342016-08-14 19:54:54 +02005271 to a function in a Vim script. Example: >
Bram Moolenaar071d4272004-06-13 20:20:40 +00005272 :if !hasmapto('\ABCdoit')
5273 : map <Leader>d \ABCdoit
5274 :endif
5275< This installs the mapping to "\ABCdoit" only if there isn't
5276 already a mapping to "\ABCdoit".
5277
5278histadd({history}, {item}) *histadd()*
5279 Add the String {item} to the history {history} which can be
5280 one of: *hist-names*
5281 "cmd" or ":" command line history
5282 "search" or "/" search pattern history
Bram Moolenaar446cb832008-06-24 21:56:24 +00005283 "expr" or "=" typed expression history
Bram Moolenaar071d4272004-06-13 20:20:40 +00005284 "input" or "@" input line history
Bram Moolenaar30b65812012-07-12 22:01:11 +02005285 "debug" or ">" debug command history
Bram Moolenaar3e496b02016-09-25 22:11:48 +02005286 empty the current or last used history
Bram Moolenaar30b65812012-07-12 22:01:11 +02005287 The {history} string does not need to be the whole name, one
5288 character is sufficient.
Bram Moolenaar071d4272004-06-13 20:20:40 +00005289 If {item} does already exist in the history, it will be
5290 shifted to become the newest entry.
5291 The result is a Number: 1 if the operation was successful,
5292 otherwise 0 is returned.
5293
5294 Example: >
5295 :call histadd("input", strftime("%Y %b %d"))
5296 :let date=input("Enter date: ")
5297< This function is not available in the |sandbox|.
5298
5299histdel({history} [, {item}]) *histdel()*
Bram Moolenaar402d2fe2005-04-15 21:00:38 +00005300 Clear {history}, i.e. delete all its entries. See |hist-names|
Bram Moolenaar071d4272004-06-13 20:20:40 +00005301 for the possible values of {history}.
5302
Bram Moolenaarc236c162008-07-13 17:41:49 +00005303 If the parameter {item} evaluates to a String, it is used as a
5304 regular expression. All entries matching that expression will
5305 be removed from the history (if there are any).
Bram Moolenaar071d4272004-06-13 20:20:40 +00005306 Upper/lowercase must match, unless "\c" is used |/\c|.
Bram Moolenaarc236c162008-07-13 17:41:49 +00005307 If {item} evaluates to a Number, it will be interpreted as
5308 an index, see |:history-indexing|. The respective entry will
5309 be removed if it exists.
Bram Moolenaar071d4272004-06-13 20:20:40 +00005310
5311 The result is a Number: 1 for a successful operation,
5312 otherwise 0 is returned.
5313
5314 Examples:
5315 Clear expression register history: >
5316 :call histdel("expr")
5317<
5318 Remove all entries starting with "*" from the search history: >
5319 :call histdel("/", '^\*')
5320<
5321 The following three are equivalent: >
5322 :call histdel("search", histnr("search"))
5323 :call histdel("search", -1)
5324 :call histdel("search", '^'.histget("search", -1).'$')
5325<
5326 To delete the last search pattern and use the last-but-one for
5327 the "n" command and 'hlsearch': >
5328 :call histdel("search", -1)
5329 :let @/ = histget("search", -1)
5330
5331histget({history} [, {index}]) *histget()*
5332 The result is a String, the entry with Number {index} from
5333 {history}. See |hist-names| for the possible values of
5334 {history}, and |:history-indexing| for {index}. If there is
5335 no such entry, an empty String is returned. When {index} is
5336 omitted, the most recent item from the history is used.
5337
5338 Examples:
5339 Redo the second last search from history. >
5340 :execute '/' . histget("search", -2)
5341
5342< Define an Ex command ":H {num}" that supports re-execution of
5343 the {num}th entry from the output of |:history|. >
5344 :command -nargs=1 H execute histget("cmd", 0+<args>)
5345<
5346histnr({history}) *histnr()*
5347 The result is the Number of the current entry in {history}.
5348 See |hist-names| for the possible values of {history}.
5349 If an error occurred, -1 is returned.
5350
5351 Example: >
5352 :let inp_index = histnr("expr")
5353<
5354hlexists({name}) *hlexists()*
5355 The result is a Number, which is non-zero if a highlight group
5356 called {name} exists. This is when the group has been
5357 defined in some way. Not necessarily when highlighting has
5358 been defined for it, it may also have been used for a syntax
5359 item.
5360 *highlight_exists()*
5361 Obsolete name: highlight_exists().
5362
5363 *hlID()*
5364hlID({name}) The result is a Number, which is the ID of the highlight group
5365 with name {name}. When the highlight group doesn't exist,
5366 zero is returned.
5367 This can be used to retrieve information about the highlight
Bram Moolenaar58b85342016-08-14 19:54:54 +02005368 group. For example, to get the background color of the
Bram Moolenaar071d4272004-06-13 20:20:40 +00005369 "Comment" group: >
5370 :echo synIDattr(synIDtrans(hlID("Comment")), "bg")
5371< *highlightID()*
5372 Obsolete name: highlightID().
5373
5374hostname() *hostname()*
5375 The result is a String, which is the name of the machine on
Bram Moolenaar402d2fe2005-04-15 21:00:38 +00005376 which Vim is currently running. Machine names greater than
Bram Moolenaar071d4272004-06-13 20:20:40 +00005377 256 characters long are truncated.
5378
5379iconv({expr}, {from}, {to}) *iconv()*
5380 The result is a String, which is the text {expr} converted
5381 from encoding {from} to encoding {to}.
Bram Moolenaar8f3f58f2010-01-06 20:52:26 +01005382 When the conversion completely fails an empty string is
5383 returned. When some characters could not be converted they
5384 are replaced with "?".
Bram Moolenaar071d4272004-06-13 20:20:40 +00005385 The encoding names are whatever the iconv() library function
5386 can accept, see ":!man 3 iconv".
5387 Most conversions require Vim to be compiled with the |+iconv|
5388 feature. Otherwise only UTF-8 to latin1 conversion and back
5389 can be done.
5390 This can be used to display messages with special characters,
5391 no matter what 'encoding' is set to. Write the message in
5392 UTF-8 and use: >
5393 echo iconv(utf8_str, "utf-8", &enc)
5394< Note that Vim uses UTF-8 for all Unicode encodings, conversion
5395 from/to UCS-2 is automatically changed to use UTF-8. You
5396 cannot use UCS-2 in a string anyway, because of the NUL bytes.
Bram Moolenaardb84e452010-08-15 13:50:43 +02005397 {only available when compiled with the |+multi_byte| feature}
Bram Moolenaar071d4272004-06-13 20:20:40 +00005398
5399 *indent()*
5400indent({lnum}) The result is a Number, which is indent of line {lnum} in the
5401 current buffer. The indent is counted in spaces, the value
5402 of 'tabstop' is relevant. {lnum} is used just like in
5403 |getline()|.
5404 When {lnum} is invalid -1 is returned.
5405
Bram Moolenaarde8866b2005-01-06 23:24:37 +00005406
Bram Moolenaar6e5ea8d2019-01-12 22:47:31 +01005407index({object}, {expr} [, {start} [, {ic}]]) *index()*
5408 If {object} is a |List| return the lowest index where the item
5409 has a value equal to {expr}. There is no automatic
5410 conversion, so the String "4" is different from the Number 4.
5411 And the number 4 is different from the Float 4.0. The value
5412 of 'ignorecase' is not used here, case always matters.
5413
5414 If {object} is |Blob| return the lowest index where the byte
5415 value is equal to {expr}.
5416
Bram Moolenaar748bf032005-02-02 23:04:36 +00005417 If {start} is given then start looking at the item with index
5418 {start} (may be negative for an item relative to the end).
Bram Moolenaare381d3d2016-07-07 14:50:41 +02005419 When {ic} is given and it is |TRUE|, ignore case. Otherwise
Bram Moolenaarde8866b2005-01-06 23:24:37 +00005420 case must match.
Bram Moolenaar6e5ea8d2019-01-12 22:47:31 +01005421 -1 is returned when {expr} is not found in {object}.
Bram Moolenaarde8866b2005-01-06 23:24:37 +00005422 Example: >
5423 :let idx = index(words, "the")
Bram Moolenaar9588a0f2005-01-08 21:45:39 +00005424 :if index(numbers, 123) >= 0
Bram Moolenaarde8866b2005-01-06 23:24:37 +00005425
5426
Bram Moolenaarbfd8fc02005-09-20 23:22:24 +00005427input({prompt} [, {text} [, {completion}]]) *input()*
Bram Moolenaar071d4272004-06-13 20:20:40 +00005428 The result is a String, which is whatever the user typed on
Bram Moolenaar8f3f58f2010-01-06 20:52:26 +01005429 the command-line. The {prompt} argument is either a prompt
5430 string, or a blank string (for no prompt). A '\n' can be used
5431 in the prompt to start a new line.
Bram Moolenaarbfd8fc02005-09-20 23:22:24 +00005432 The highlighting set with |:echohl| is used for the prompt.
5433 The input is entered just like a command-line, with the same
Bram Moolenaar58b85342016-08-14 19:54:54 +02005434 editing commands and mappings. There is a separate history
Bram Moolenaarbfd8fc02005-09-20 23:22:24 +00005435 for lines typed for input().
5436 Example: >
5437 :if input("Coffee or beer? ") == "beer"
5438 : echo "Cheers!"
5439 :endif
5440<
Bram Moolenaar8f3f58f2010-01-06 20:52:26 +01005441 If the optional {text} argument is present and not empty, this
5442 is used for the default reply, as if the user typed this.
5443 Example: >
Bram Moolenaarbfd8fc02005-09-20 23:22:24 +00005444 :let color = input("Color? ", "white")
5445
5446< The optional {completion} argument specifies the type of
5447 completion supported for the input. Without it completion is
Bram Moolenaar58b85342016-08-14 19:54:54 +02005448 not performed. The supported completion types are the same as
Bram Moolenaarbfd8fc02005-09-20 23:22:24 +00005449 that can be supplied to a user-defined command using the
Bram Moolenaar58b85342016-08-14 19:54:54 +02005450 "-complete=" argument. Refer to |:command-completion| for
Bram Moolenaarbfd8fc02005-09-20 23:22:24 +00005451 more information. Example: >
5452 let fname = input("File: ", "", "file")
5453<
5454 NOTE: This function must not be used in a startup file, for
5455 the versions that only run in GUI mode (e.g., the Win32 GUI).
Bram Moolenaar071d4272004-06-13 20:20:40 +00005456 Note: When input() is called from within a mapping it will
5457 consume remaining characters from that mapping, because a
5458 mapping is handled like the characters were typed.
5459 Use |inputsave()| before input() and |inputrestore()|
5460 after input() to avoid that. Another solution is to avoid
5461 that further characters follow in the mapping, e.g., by using
5462 |:execute| or |:normal|.
5463
Bram Moolenaarbfd8fc02005-09-20 23:22:24 +00005464 Example with a mapping: >
Bram Moolenaar071d4272004-06-13 20:20:40 +00005465 :nmap \x :call GetFoo()<CR>:exe "/" . Foo<CR>
5466 :function GetFoo()
5467 : call inputsave()
5468 : let g:Foo = input("enter search pattern: ")
5469 : call inputrestore()
5470 :endfunction
5471
5472inputdialog({prompt} [, {text} [, {cancelreturn}]]) *inputdialog()*
Bram Moolenaar8f3f58f2010-01-06 20:52:26 +01005473 Like |input()|, but when the GUI is running and text dialogs
5474 are supported, a dialog window pops up to input the text.
Bram Moolenaar071d4272004-06-13 20:20:40 +00005475 Example: >
Bram Moolenaar2d17fa32012-10-21 00:45:18 +02005476 :let n = inputdialog("value for shiftwidth", shiftwidth())
5477 :if n != ""
5478 : let &sw = n
5479 :endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005480< When the dialog is cancelled {cancelreturn} is returned. When
5481 omitted an empty string is returned.
5482 Hitting <Enter> works like pressing the OK button. Hitting
5483 <Esc> works like pressing the Cancel button.
Bram Moolenaarbfd8fc02005-09-20 23:22:24 +00005484 NOTE: Command-line completion is not supported.
Bram Moolenaar071d4272004-06-13 20:20:40 +00005485
Bram Moolenaar578b49e2005-09-10 19:22:57 +00005486inputlist({textlist}) *inputlist()*
Bram Moolenaar910f66f2006-04-05 20:41:53 +00005487 {textlist} must be a |List| of strings. This |List| is
5488 displayed, one string per line. The user will be prompted to
5489 enter a number, which is returned.
Bram Moolenaar578b49e2005-09-10 19:22:57 +00005490 The user can also select an item by clicking on it with the
Bram Moolenaar58b85342016-08-14 19:54:54 +02005491 mouse. For the first string 0 is returned. When clicking
Bram Moolenaar578b49e2005-09-10 19:22:57 +00005492 above the first item a negative number is returned. When
5493 clicking on the prompt one more than the length of {textlist}
5494 is returned.
Bram Moolenaar8f3f58f2010-01-06 20:52:26 +01005495 Make sure {textlist} has less than 'lines' entries, otherwise
Bram Moolenaar58b85342016-08-14 19:54:54 +02005496 it won't work. It's a good idea to put the entry number at
Bram Moolenaaref2f6562007-05-06 13:32:59 +00005497 the start of the string. And put a prompt in the first item.
5498 Example: >
Bram Moolenaar578b49e2005-09-10 19:22:57 +00005499 let color = inputlist(['Select color:', '1. red',
5500 \ '2. green', '3. blue'])
5501
Bram Moolenaar071d4272004-06-13 20:20:40 +00005502inputrestore() *inputrestore()*
Bram Moolenaar8f3f58f2010-01-06 20:52:26 +01005503 Restore typeahead that was saved with a previous |inputsave()|.
Bram Moolenaar071d4272004-06-13 20:20:40 +00005504 Should be called the same number of times inputsave() is
5505 called. Calling it more often is harmless though.
5506 Returns 1 when there is nothing to restore, 0 otherwise.
5507
5508inputsave() *inputsave()*
5509 Preserve typeahead (also from mappings) and clear it, so that
5510 a following prompt gets input from the user. Should be
5511 followed by a matching inputrestore() after the prompt. Can
5512 be used several times, in which case there must be just as
5513 many inputrestore() calls.
5514 Returns 1 when out of memory, 0 otherwise.
5515
5516inputsecret({prompt} [, {text}]) *inputsecret()*
5517 This function acts much like the |input()| function with but
5518 two exceptions:
5519 a) the user's response will be displayed as a sequence of
5520 asterisks ("*") thereby keeping the entry secret, and
5521 b) the user's response will not be recorded on the input
5522 |history| stack.
5523 The result is a String, which is whatever the user actually
5524 typed on the command-line in response to the issued prompt.
Bram Moolenaarbfd8fc02005-09-20 23:22:24 +00005525 NOTE: Command-line completion is not supported.
Bram Moolenaar071d4272004-06-13 20:20:40 +00005526
Bram Moolenaar6e5ea8d2019-01-12 22:47:31 +01005527insert({object}, {item} [, {idx}]) *insert()*
5528 When {object} is a |List| or a |Blob| insert {item} at the start
5529 of it.
5530
Bram Moolenaard7ee7ce2005-01-03 21:02:03 +00005531 If {idx} is specified insert {item} before the item with index
Bram Moolenaar58b85342016-08-14 19:54:54 +02005532 {idx}. If {idx} is zero it goes before the first item, just
Bram Moolenaard7ee7ce2005-01-03 21:02:03 +00005533 like omitting {idx}. A negative {idx} is also possible, see
5534 |list-index|. -1 inserts just before the last item.
Bram Moolenaar6e5ea8d2019-01-12 22:47:31 +01005535
5536 Returns the resulting |List| or |Blob|. Examples: >
Bram Moolenaard7ee7ce2005-01-03 21:02:03 +00005537 :let mylist = insert([2, 3, 5], 1)
5538 :call insert(mylist, 4, -1)
5539 :call insert(mylist, 6, len(mylist))
Bram Moolenaara14de3d2005-01-07 21:48:26 +00005540< The last example can be done simpler with |add()|.
Bram Moolenaar32466aa2006-02-24 23:53:04 +00005541 Note that when {item} is a |List| it is inserted as a single
Bram Moolenaara23ccb82006-02-27 00:08:02 +00005542 item. Use |extend()| to concatenate |Lists|.
Bram Moolenaard7ee7ce2005-01-03 21:02:03 +00005543
Bram Moolenaard6e256c2011-12-14 15:32:50 +01005544invert({expr}) *invert()*
5545 Bitwise invert. The argument is converted to a number. A
5546 List, Dict or Float argument causes an error. Example: >
5547 :let bits = invert(bits)
5548
Bram Moolenaar071d4272004-06-13 20:20:40 +00005549isdirectory({directory}) *isdirectory()*
Bram Moolenaare381d3d2016-07-07 14:50:41 +02005550 The result is a Number, which is |TRUE| when a directory
Bram Moolenaar071d4272004-06-13 20:20:40 +00005551 with the name {directory} exists. If {directory} doesn't
Bram Moolenaare381d3d2016-07-07 14:50:41 +02005552 exist, or isn't a directory, the result is |FALSE|. {directory}
Bram Moolenaar071d4272004-06-13 20:20:40 +00005553 is any expression, which is used as a String.
5554
Bram Moolenaar910f66f2006-04-05 20:41:53 +00005555islocked({expr}) *islocked()* *E786*
Bram Moolenaare381d3d2016-07-07 14:50:41 +02005556 The result is a Number, which is |TRUE| when {expr} is the
Bram Moolenaar2ce06f62005-01-31 19:19:04 +00005557 name of a locked variable.
Bram Moolenaar32466aa2006-02-24 23:53:04 +00005558 {expr} must be the name of a variable, |List| item or
5559 |Dictionary| entry, not the variable itself! Example: >
Bram Moolenaar2ce06f62005-01-31 19:19:04 +00005560 :let alist = [0, ['a', 'b'], 2, 3]
5561 :lockvar 1 alist
5562 :echo islocked('alist') " 1
5563 :echo islocked('alist[1]') " 0
5564
5565< When {expr} is a variable that does not exist you get an error
Bram Moolenaar551dbcc2006-04-25 22:13:59 +00005566 message. Use |exists()| to check for existence.
Bram Moolenaar2ce06f62005-01-31 19:19:04 +00005567
Bram Moolenaarf3913272016-02-25 00:00:01 +01005568isnan({expr}) *isnan()*
Bram Moolenaare381d3d2016-07-07 14:50:41 +02005569 Return |TRUE| if {expr} is a float with value NaN. >
Bram Moolenaarf3913272016-02-25 00:00:01 +01005570 echo isnan(0.0 / 0.0)
5571< 1 ~
5572
5573 {only available when compiled with the |+float| feature}
5574
Bram Moolenaar677ee682005-01-27 14:41:15 +00005575items({dict}) *items()*
Bram Moolenaar32466aa2006-02-24 23:53:04 +00005576 Return a |List| with all the key-value pairs of {dict}. Each
5577 |List| item is a list with two items: the key of a {dict}
5578 entry and the value of this entry. The |List| is in arbitrary
5579 order.
Bram Moolenaar677ee682005-01-27 14:41:15 +00005580
Bram Moolenaar38a55632016-02-15 22:07:32 +01005581job_getchannel({job}) *job_getchannel()*
5582 Get the channel handle that {job} is using.
Bram Moolenaar77cdfd12016-03-12 12:57:59 +01005583 To check if the job has no channel: >
5584 if string(job_getchannel()) == 'channel fail'
5585<
Bram Moolenaar38a55632016-02-15 22:07:32 +01005586 {only available when compiled with the |+job| feature}
5587
Bram Moolenaar65a54642018-04-28 16:56:53 +02005588job_info([{job}]) *job_info()*
Bram Moolenaarf6f32c32016-03-12 19:03:59 +01005589 Returns a Dictionary with information about {job}:
5590 "status" what |job_status()| returns
5591 "channel" what |job_getchannel()| returns
Bram Moolenaar65a54642018-04-28 16:56:53 +02005592 "cmd" List of command arguments used to start the job
Bram Moolenaar7c9aec42017-08-03 13:51:25 +02005593 "process" process ID
Bram Moolenaar2dc9d262017-09-08 14:39:30 +02005594 "tty_in" terminal input name, empty when none
5595 "tty_out" terminal output name, empty when none
Bram Moolenaarf6f32c32016-03-12 19:03:59 +01005596 "exitval" only valid when "status" is "dead"
Bram Moolenaar975b5272016-03-15 23:10:59 +01005597 "exit_cb" function to be called on exit
Bram Moolenaarf6f32c32016-03-12 19:03:59 +01005598 "stoponexit" |job-stoponexit|
5599
Bram Moolenaar65a54642018-04-28 16:56:53 +02005600 Without any arguments, returns a List with all Job objects.
5601
Bram Moolenaar02e83b42016-02-21 20:10:26 +01005602job_setoptions({job}, {options}) *job_setoptions()*
5603 Change options for {job}. Supported are:
Bram Moolenaarf6f32c32016-03-12 19:03:59 +01005604 "stoponexit" |job-stoponexit|
Bram Moolenaar975b5272016-03-15 23:10:59 +01005605 "exit_cb" |job-exit_cb|
Bram Moolenaar02e83b42016-02-21 20:10:26 +01005606
Bram Moolenaar38a55632016-02-15 22:07:32 +01005607job_start({command} [, {options}]) *job_start()*
Bram Moolenaar835dc632016-02-07 14:27:38 +01005608 Start a job and return a Job object. Unlike |system()| and
5609 |:!cmd| this does not wait for the job to finish.
Bram Moolenaarc572da52017-08-27 16:52:01 +02005610 To start a job in a terminal window see |term_start()|.
Bram Moolenaar835dc632016-02-07 14:27:38 +01005611
Bram Moolenaar6463ca22016-02-13 17:04:46 +01005612 {command} can be a String. This works best on MS-Windows. On
Bram Moolenaar835dc632016-02-07 14:27:38 +01005613 Unix it is split up in white-separated parts to be passed to
5614 execvp(). Arguments in double quotes can contain white space.
5615
Bram Moolenaar6463ca22016-02-13 17:04:46 +01005616 {command} can be a List, where the first item is the executable
Bram Moolenaar835dc632016-02-07 14:27:38 +01005617 and further items are the arguments. All items are converted
5618 to String. This works best on Unix.
5619
Bram Moolenaar6463ca22016-02-13 17:04:46 +01005620 On MS-Windows, job_start() makes a GUI application hidden. If
5621 want to show it, Use |:!start| instead.
5622
Bram Moolenaar835dc632016-02-07 14:27:38 +01005623 The command is executed directly, not through a shell, the
5624 'shell' option is not used. To use the shell: >
5625 let job = job_start(["/bin/sh", "-c", "echo hello"])
5626< Or: >
5627 let job = job_start('/bin/sh -c "echo hello"')
Bram Moolenaar6463ca22016-02-13 17:04:46 +01005628< Note that this will start two processes, the shell and the
5629 command it executes. If you don't want this use the "exec"
5630 shell command.
Bram Moolenaar835dc632016-02-07 14:27:38 +01005631
5632 On Unix $PATH is used to search for the executable only when
5633 the command does not contain a slash.
5634
5635 The job will use the same terminal as Vim. If it reads from
5636 stdin the job and Vim will be fighting over input, that
5637 doesn't work. Redirect stdin and stdout to avoid problems: >
5638 let job = job_start(['sh', '-c', "myserver </dev/null >/dev/null"])
5639<
5640 The returned Job object can be used to get the status with
5641 |job_status()| and stop the job with |job_stop()|.
5642
Bram Moolenaard2f3a8b2018-06-19 14:35:59 +02005643 Note that the job object will be deleted if there are no
5644 references to it. This closes the stdin and stderr, which may
5645 cause the job to fail with an error. To avoid this keep a
5646 reference to the job. Thus instead of: >
5647 call job_start('my-command')
5648< use: >
5649 let myjob = job_start('my-command')
5650< and unlet "myjob" once the job is not needed or is past the
5651 point where it would fail (e.g. when it prints a message on
5652 startup). Keep in mind that variables local to a function
5653 will cease to exist if the function returns. Use a
5654 script-local variable if needed: >
5655 let s:myjob = job_start('my-command')
5656<
Bram Moolenaar6463ca22016-02-13 17:04:46 +01005657 {options} must be a Dictionary. It can contain many optional
5658 items, see |job-options|.
Bram Moolenaar835dc632016-02-07 14:27:38 +01005659
Bram Moolenaar6463ca22016-02-13 17:04:46 +01005660 {only available when compiled with the |+job| feature}
Bram Moolenaar835dc632016-02-07 14:27:38 +01005661
Bram Moolenaar02e83b42016-02-21 20:10:26 +01005662job_status({job}) *job_status()* *E916*
Bram Moolenaar835dc632016-02-07 14:27:38 +01005663 Returns a String with the status of {job}:
5664 "run" job is running
5665 "fail" job failed to start
5666 "dead" job died or was stopped after running
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01005667
Bram Moolenaar511972d2016-06-04 18:09:59 +02005668 On Unix a non-existing command results in "dead" instead of
5669 "fail", because a fork happens before the failure can be
5670 detected.
5671
Bram Moolenaar03413f42016-04-12 21:07:15 +02005672 If an exit callback was set with the "exit_cb" option and the
Bram Moolenaar02e83b42016-02-21 20:10:26 +01005673 job is now detected to be "dead" the callback will be invoked.
Bram Moolenaar835dc632016-02-07 14:27:38 +01005674
Bram Moolenaar8950a562016-03-12 15:22:55 +01005675 For more information see |job_info()|.
5676
Bram Moolenaar6463ca22016-02-13 17:04:46 +01005677 {only available when compiled with the |+job| feature}
Bram Moolenaar835dc632016-02-07 14:27:38 +01005678
5679job_stop({job} [, {how}]) *job_stop()*
5680 Stop the {job}. This can also be used to signal the job.
5681
Bram Moolenaar923d9262016-02-25 20:56:01 +01005682 When {how} is omitted or is "term" the job will be terminated.
5683 For Unix SIGTERM is sent. On MS-Windows the job will be
5684 terminated forcedly (there is no "gentle" way).
5685 This goes to the process group, thus children may also be
5686 affected.
Bram Moolenaar6463ca22016-02-13 17:04:46 +01005687
Bram Moolenaar923d9262016-02-25 20:56:01 +01005688 Effect for Unix:
5689 "term" SIGTERM (default)
5690 "hup" SIGHUP
5691 "quit" SIGQUIT
5692 "int" SIGINT
5693 "kill" SIGKILL (strongest way to stop)
5694 number signal with that number
Bram Moolenaar835dc632016-02-07 14:27:38 +01005695
Bram Moolenaar923d9262016-02-25 20:56:01 +01005696 Effect for MS-Windows:
5697 "term" terminate process forcedly (default)
5698 "hup" CTRL_BREAK
5699 "quit" CTRL_BREAK
5700 "int" CTRL_C
5701 "kill" terminate process forcedly
5702 Others CTRL_BREAK
Bram Moolenaar6463ca22016-02-13 17:04:46 +01005703
5704 On Unix the signal is sent to the process group. This means
5705 that when the job is "sh -c command" it affects both the shell
5706 and the command.
5707
Bram Moolenaar835dc632016-02-07 14:27:38 +01005708 The result is a Number: 1 if the operation could be executed,
5709 0 if "how" is not supported on the system.
5710 Note that even when the operation was executed, whether the
5711 job was actually stopped needs to be checked with
Bram Moolenaar45d2cca2017-04-30 16:36:05 +02005712 |job_status()|.
5713
5714 If the status of the job is "dead", the signal will not be
5715 sent. This is to avoid to stop the wrong job (esp. on Unix,
5716 where process numbers are recycled).
5717
5718 When using "kill" Vim will assume the job will die and close
5719 the channel.
Bram Moolenaar835dc632016-02-07 14:27:38 +01005720
Bram Moolenaar6463ca22016-02-13 17:04:46 +01005721 {only available when compiled with the |+job| feature}
Bram Moolenaar835dc632016-02-07 14:27:38 +01005722
Bram Moolenaar5f2bb9f2005-01-11 21:29:04 +00005723join({list} [, {sep}]) *join()*
5724 Join the items in {list} together into one String.
5725 When {sep} is specified it is put in between the items. If
5726 {sep} is omitted a single space is used.
5727 Note that {sep} is not added at the end. You might want to
5728 add it there too: >
5729 let lines = join(mylist, "\n") . "\n"
Bram Moolenaara23ccb82006-02-27 00:08:02 +00005730< String items are used as-is. |Lists| and |Dictionaries| are
Bram Moolenaar5f2bb9f2005-01-11 21:29:04 +00005731 converted into a string like with |string()|.
5732 The opposite function is |split()|.
5733
Bram Moolenaar7823a3b2016-02-11 21:08:32 +01005734js_decode({string}) *js_decode()*
5735 This is similar to |json_decode()| with these differences:
Bram Moolenaar595e64e2016-02-07 19:19:53 +01005736 - Object key names do not have to be in quotes.
Bram Moolenaaree142ad2017-01-11 21:50:08 +01005737 - Strings can be in single quotes.
Bram Moolenaar595e64e2016-02-07 19:19:53 +01005738 - Empty items in an array (between two commas) are allowed and
5739 result in v:none items.
5740
Bram Moolenaar7823a3b2016-02-11 21:08:32 +01005741js_encode({expr}) *js_encode()*
5742 This is similar to |json_encode()| with these differences:
Bram Moolenaar595e64e2016-02-07 19:19:53 +01005743 - Object key names are not in quotes.
5744 - v:none items in an array result in an empty item between
5745 commas.
5746 For example, the Vim object:
Bram Moolenaar7823a3b2016-02-11 21:08:32 +01005747 [1,v:none,{"one":1},v:none] ~
Bram Moolenaar595e64e2016-02-07 19:19:53 +01005748 Will be encoded as:
5749 [1,,{one:1},,] ~
Bram Moolenaar7823a3b2016-02-11 21:08:32 +01005750 While json_encode() would produce:
Bram Moolenaar595e64e2016-02-07 19:19:53 +01005751 [1,null,{"one":1},null] ~
5752 This encoding is valid for JavaScript. It is more efficient
5753 than JSON, especially when using an array with optional items.
5754
5755
Bram Moolenaar7823a3b2016-02-11 21:08:32 +01005756json_decode({string}) *json_decode()*
Bram Moolenaar705ada12016-01-24 17:56:50 +01005757 This parses a JSON formatted string and returns the equivalent
Bram Moolenaar7823a3b2016-02-11 21:08:32 +01005758 in Vim values. See |json_encode()| for the relation between
Bram Moolenaar705ada12016-01-24 17:56:50 +01005759 JSON and Vim values.
5760 The decoding is permissive:
Bram Moolenaarcd5c8f82017-04-09 20:11:58 +02005761 - A trailing comma in an array and object is ignored, e.g.
5762 "[1, 2, ]" is the same as "[1, 2]".
Bram Moolenaar705ada12016-01-24 17:56:50 +01005763 - More floating point numbers are recognized, e.g. "1." for
Bram Moolenaarcd5c8f82017-04-09 20:11:58 +02005764 "1.0", or "001.2" for "1.2". Special floating point values
Bram Moolenaar5f6b3792019-01-12 14:24:27 +01005765 "Infinity", "-Infinity" and "NaN" (capitalization ignored)
5766 are accepted.
Bram Moolenaarcd5c8f82017-04-09 20:11:58 +02005767 - Leading zeroes in integer numbers are ignored, e.g. "012"
5768 for "12" or "-012" for "-12".
5769 - Capitalization is ignored in literal names null, true or
5770 false, e.g. "NULL" for "null", "True" for "true".
5771 - Control characters U+0000 through U+001F which are not
5772 escaped in strings are accepted, e.g. " " (tab
5773 character in string) for "\t".
5774 - Backslash in an invalid 2-character sequence escape is
5775 ignored, e.g. "\a" is decoded as "a".
5776 - A correct surrogate pair in JSON strings should normally be
5777 a 12 character sequence such as "\uD834\uDD1E", but
5778 json_decode() silently accepts truncated surrogate pairs
5779 such as "\uD834" or "\uD834\u"
5780 *E938*
5781 A duplicate key in an object, valid in rfc7159, is not
5782 accepted by json_decode() as the result must be a valid Vim
5783 type, e.g. this fails: {"a":"b", "a":"c"}
5784
Bram Moolenaar520e1e42016-01-23 19:46:28 +01005785
Bram Moolenaar7823a3b2016-02-11 21:08:32 +01005786json_encode({expr}) *json_encode()*
Bram Moolenaar705ada12016-01-24 17:56:50 +01005787 Encode {expr} as JSON and return this as a string.
Bram Moolenaar520e1e42016-01-23 19:46:28 +01005788 The encoding is specified in:
Bram Moolenaar009d84a2016-01-28 14:12:00 +01005789 https://tools.ietf.org/html/rfc7159.html
Bram Moolenaar520e1e42016-01-23 19:46:28 +01005790 Vim values are converted as follows:
5791 Number decimal number
5792 Float floating point number
Bram Moolenaar7ce686c2016-02-27 16:33:22 +01005793 Float nan "NaN"
5794 Float inf "Infinity"
Bram Moolenaar5f6b3792019-01-12 14:24:27 +01005795 Float -inf "-Infinity"
Bram Moolenaar520e1e42016-01-23 19:46:28 +01005796 String in double quotes (possibly null)
Bram Moolenaar705ada12016-01-24 17:56:50 +01005797 Funcref not possible, error
Bram Moolenaar520e1e42016-01-23 19:46:28 +01005798 List as an array (possibly null); when
Bram Moolenaar81edd172016-04-14 13:51:37 +02005799 used recursively: []
Bram Moolenaar520e1e42016-01-23 19:46:28 +01005800 Dict as an object (possibly null); when
Bram Moolenaar81edd172016-04-14 13:51:37 +02005801 used recursively: {}
Bram Moolenaar6e5ea8d2019-01-12 22:47:31 +01005802 Blob as an array of the individual bytes
Bram Moolenaar520e1e42016-01-23 19:46:28 +01005803 v:false "false"
5804 v:true "true"
Bram Moolenaar595e64e2016-02-07 19:19:53 +01005805 v:none "null"
Bram Moolenaar520e1e42016-01-23 19:46:28 +01005806 v:null "null"
Bram Moolenaar7ce686c2016-02-27 16:33:22 +01005807 Note that NaN and Infinity are passed on as values. This is
5808 missing in the JSON standard, but several implementations do
5809 allow it. If not then you will get an error.
Bram Moolenaar520e1e42016-01-23 19:46:28 +01005810
Bram Moolenaard8b02732005-01-14 21:48:43 +00005811keys({dict}) *keys()*
Bram Moolenaar32466aa2006-02-24 23:53:04 +00005812 Return a |List| with all the keys of {dict}. The |List| is in
Bram Moolenaard8b02732005-01-14 21:48:43 +00005813 arbitrary order.
5814
Bram Moolenaar13065c42005-01-08 16:08:21 +00005815 *len()* *E701*
Bram Moolenaard7ee7ce2005-01-03 21:02:03 +00005816len({expr}) The result is a Number, which is the length of the argument.
5817 When {expr} is a String or a Number the length in bytes is
5818 used, as with |strlen()|.
Bram Moolenaar32466aa2006-02-24 23:53:04 +00005819 When {expr} is a |List| the number of items in the |List| is
Bram Moolenaard7ee7ce2005-01-03 21:02:03 +00005820 returned.
Bram Moolenaar32466aa2006-02-24 23:53:04 +00005821 When {expr} is a |Dictionary| the number of entries in the
5822 |Dictionary| is returned.
Bram Moolenaard7ee7ce2005-01-03 21:02:03 +00005823 Otherwise an error is given.
5824
Bram Moolenaar071d4272004-06-13 20:20:40 +00005825 *libcall()* *E364* *E368*
5826libcall({libname}, {funcname}, {argument})
5827 Call function {funcname} in the run-time library {libname}
5828 with single argument {argument}.
5829 This is useful to call functions in a library that you
5830 especially made to be used with Vim. Since only one argument
5831 is possible, calling standard library functions is rather
5832 limited.
5833 The result is the String returned by the function. If the
5834 function returns NULL, this will appear as an empty string ""
5835 to Vim.
5836 If the function returns a number, use libcallnr()!
5837 If {argument} is a number, it is passed to the function as an
5838 int; if {argument} is a string, it is passed as a
5839 null-terminated string.
5840 This function will fail in |restricted-mode|.
5841
5842 libcall() allows you to write your own 'plug-in' extensions to
5843 Vim without having to recompile the program. It is NOT a
5844 means to call system functions! If you try to do so Vim will
5845 very probably crash.
5846
5847 For Win32, the functions you write must be placed in a DLL
5848 and use the normal C calling convention (NOT Pascal which is
5849 used in Windows System DLLs). The function must take exactly
5850 one parameter, either a character pointer or a long integer,
5851 and must return a character pointer or NULL. The character
5852 pointer returned must point to memory that will remain valid
5853 after the function has returned (e.g. in static data in the
5854 DLL). If it points to allocated memory, that memory will
5855 leak away. Using a static buffer in the function should work,
5856 it's then freed when the DLL is unloaded.
5857
5858 WARNING: If the function returns a non-valid pointer, Vim may
Bram Moolenaar446cb832008-06-24 21:56:24 +00005859 crash! This also happens if the function returns a number,
Bram Moolenaar071d4272004-06-13 20:20:40 +00005860 because Vim thinks it's a pointer.
5861 For Win32 systems, {libname} should be the filename of the DLL
5862 without the ".DLL" suffix. A full path is only required if
5863 the DLL is not in the usual places.
5864 For Unix: When compiling your own plugins, remember that the
5865 object code must be compiled as position-independent ('PIC').
Bram Moolenaar8f3f58f2010-01-06 20:52:26 +01005866 {only in Win32 and some Unix versions, when the |+libcall|
Bram Moolenaar071d4272004-06-13 20:20:40 +00005867 feature is present}
5868 Examples: >
5869 :echo libcall("libc.so", "getenv", "HOME")
Bram Moolenaar071d4272004-06-13 20:20:40 +00005870<
5871 *libcallnr()*
5872libcallnr({libname}, {funcname}, {argument})
Bram Moolenaar8f3f58f2010-01-06 20:52:26 +01005873 Just like |libcall()|, but used for a function that returns an
Bram Moolenaar071d4272004-06-13 20:20:40 +00005874 int instead of a string.
5875 {only in Win32 on some Unix versions, when the |+libcall|
5876 feature is present}
Bram Moolenaar446cb832008-06-24 21:56:24 +00005877 Examples: >
5878 :echo libcallnr("/usr/lib/libc.so", "getpid", "")
Bram Moolenaar071d4272004-06-13 20:20:40 +00005879 :call libcallnr("libc.so", "printf", "Hello World!\n")
5880 :call libcallnr("libc.so", "sleep", 10)
5881<
5882 *line()*
5883line({expr}) The result is a Number, which is the line number of the file
5884 position given with {expr}. The accepted positions are:
5885 . the cursor position
5886 $ the last line in the current buffer
5887 'x position of mark x (if the mark is not set, 0 is
5888 returned)
Bram Moolenaara1d5fa62017-04-03 22:02:55 +02005889 w0 first line visible in current window (one if the
5890 display isn't updated, e.g. in silent Ex mode)
5891 w$ last line visible in current window (this is one
5892 less than "w0" if no lines are visible)
Bram Moolenaar9ecd0232008-06-20 15:31:51 +00005893 v In Visual mode: the start of the Visual area (the
5894 cursor is the end). When not in Visual mode
5895 returns the cursor position. Differs from |'<| in
5896 that it's updated right away.
Bram Moolenaaref2f6562007-05-06 13:32:59 +00005897 Note that a mark in another file can be used. The line number
5898 then applies to another buffer.
Bram Moolenaar0b238792006-03-02 22:49:12 +00005899 To get the column number use |col()|. To get both use
5900 |getpos()|.
Bram Moolenaar071d4272004-06-13 20:20:40 +00005901 Examples: >
5902 line(".") line number of the cursor
5903 line("'t") line number of mark t
5904 line("'" . marker) line number of mark marker
5905< *last-position-jump*
5906 This autocommand jumps to the last known position in a file
5907 just after opening it, if the '" mark is set: >
Bram Moolenaar3ec574f2017-06-13 18:12:01 +02005908 :au BufReadPost *
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01005909 \ if line("'\"") > 1 && line("'\"") <= line("$") && &ft !~# 'commit'
Bram Moolenaarf8be4612017-06-23 20:52:40 +02005910 \ | exe "normal! g`\""
5911 \ | endif
Bram Moolenaar69a7cb42004-06-20 12:51:53 +00005912
Bram Moolenaar071d4272004-06-13 20:20:40 +00005913line2byte({lnum}) *line2byte()*
5914 Return the byte count from the start of the buffer for line
5915 {lnum}. This includes the end-of-line character, depending on
5916 the 'fileformat' option for the current buffer. The first
Bram Moolenaarb6b046b2011-12-30 13:11:27 +01005917 line returns 1. 'encoding' matters, 'fileencoding' is ignored.
Bram Moolenaar071d4272004-06-13 20:20:40 +00005918 This can also be used to get the byte count for the line just
5919 below the last line: >
5920 line2byte(line("$") + 1)
Bram Moolenaarb6b046b2011-12-30 13:11:27 +01005921< This is the buffer size plus one. If 'fileencoding' is empty
5922 it is the file size plus one.
Bram Moolenaar071d4272004-06-13 20:20:40 +00005923 When {lnum} is invalid, or the |+byte_offset| feature has been
5924 disabled at compile time, -1 is returned.
5925 Also see |byte2line()|, |go| and |:goto|.
5926
5927lispindent({lnum}) *lispindent()*
5928 Get the amount of indent for line {lnum} according the lisp
5929 indenting rules, as with 'lisp'.
5930 The indent is counted in spaces, the value of 'tabstop' is
5931 relevant. {lnum} is used just like in |getline()|.
5932 When {lnum} is invalid or Vim was not compiled the
5933 |+lispindent| feature, -1 is returned.
5934
5935localtime() *localtime()*
5936 Return the current time, measured as seconds since 1st Jan
5937 1970. See also |strftime()| and |getftime()|.
5938
Bram Moolenaar5f2bb9f2005-01-11 21:29:04 +00005939
Bram Moolenaardb7c6862010-05-21 16:33:48 +02005940log({expr}) *log()*
Bram Moolenaar9855d6b2010-07-18 14:34:51 +02005941 Return the natural logarithm (base e) of {expr} as a |Float|.
5942 {expr} must evaluate to a |Float| or a |Number| in the range
Bram Moolenaardb7c6862010-05-21 16:33:48 +02005943 (0, inf].
5944 Examples: >
5945 :echo log(10)
5946< 2.302585 >
5947 :echo log(exp(5))
5948< 5.0
Bram Moolenaardb84e452010-08-15 13:50:43 +02005949 {only available when compiled with the |+float| feature}
Bram Moolenaardb7c6862010-05-21 16:33:48 +02005950
5951
Bram Moolenaar446cb832008-06-24 21:56:24 +00005952log10({expr}) *log10()*
5953 Return the logarithm of Float {expr} to base 10 as a |Float|.
5954 {expr} must evaluate to a |Float| or a |Number|.
5955 Examples: >
5956 :echo log10(1000)
5957< 3.0 >
5958 :echo log10(0.01)
5959< -2.0
5960 {only available when compiled with the |+float| feature}
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01005961
5962luaeval({expr} [, {expr}]) *luaeval()*
5963 Evaluate Lua expression {expr} and return its result converted
5964 to Vim data structures. Second {expr} may hold additional
Bram Moolenaard38b0552012-04-25 19:07:41 +02005965 argument accessible as _A inside first {expr}.
5966 Strings are returned as they are.
5967 Boolean objects are converted to numbers.
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01005968 Numbers are converted to |Float| values if vim was compiled
Bram Moolenaard38b0552012-04-25 19:07:41 +02005969 with |+float| and to numbers otherwise.
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01005970 Dictionaries and lists obtained by vim.eval() are returned
Bram Moolenaard38b0552012-04-25 19:07:41 +02005971 as-is.
5972 Other objects are returned as zero without any errors.
5973 See |lua-luaeval| for more details.
5974 {only available when compiled with the |+lua| feature}
5975
Bram Moolenaarb33c7eb2016-07-04 22:29:49 +02005976map({expr1}, {expr2}) *map()*
5977 {expr1} must be a |List| or a |Dictionary|.
5978 Replace each item in {expr1} with the result of evaluating
5979 {expr2}. {expr2} must be a |string| or |Funcref|.
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01005980
Bram Moolenaarb33c7eb2016-07-04 22:29:49 +02005981 If {expr2} is a |string|, inside {expr2} |v:val| has the value
5982 of the current item. For a |Dictionary| |v:key| has the key
5983 of the current item and for a |List| |v:key| has the index of
5984 the current item.
Bram Moolenaar2fda12f2005-01-15 22:14:15 +00005985 Example: >
5986 :call map(mylist, '"> " . v:val . " <"')
Bram Moolenaar5f2bb9f2005-01-11 21:29:04 +00005987< This puts "> " before and " <" after each item in "mylist".
Bram Moolenaar2fda12f2005-01-15 22:14:15 +00005988
Bram Moolenaarb33c7eb2016-07-04 22:29:49 +02005989 Note that {expr2} is the result of an expression and is then
Bram Moolenaar2fda12f2005-01-15 22:14:15 +00005990 used as an expression again. Often it is good to use a
Bram Moolenaar3a7c85b2005-02-05 21:39:53 +00005991 |literal-string| to avoid having to double backslashes. You
5992 still have to double ' quotes
Bram Moolenaar2fda12f2005-01-15 22:14:15 +00005993
Bram Moolenaarb33c7eb2016-07-04 22:29:49 +02005994 If {expr2} is a |Funcref| it is called with two arguments:
5995 1. The key or the index of the current item.
5996 2. the value of the current item.
5997 The function must return the new value of the item. Example
5998 that changes each value by "key-value": >
5999 func KeyValue(key, val)
6000 return a:key . '-' . a:val
6001 endfunc
6002 call map(myDict, function('KeyValue'))
Bram Moolenaar50ba5262016-09-22 22:33:02 +02006003< It is shorter when using a |lambda|: >
6004 call map(myDict, {key, val -> key . '-' . val})
6005< If you do not use "val" you can leave it out: >
6006 call map(myDict, {key -> 'item: ' . key})
Bram Moolenaarb33c7eb2016-07-04 22:29:49 +02006007<
Bram Moolenaar32466aa2006-02-24 23:53:04 +00006008 The operation is done in-place. If you want a |List| or
6009 |Dictionary| to remain unmodified make a copy first: >
Bram Moolenaar30b65812012-07-12 22:01:11 +02006010 :let tlist = map(copy(mylist), ' v:val . "\t"')
Bram Moolenaar2fda12f2005-01-15 22:14:15 +00006011
Bram Moolenaarb33c7eb2016-07-04 22:29:49 +02006012< Returns {expr1}, the |List| or |Dictionary| that was filtered.
6013 When an error is encountered while evaluating {expr2} no
6014 further items in {expr1} are processed. When {expr2} is a
6015 Funcref errors inside a function are ignored, unless it was
6016 defined with the "abort" flag.
Bram Moolenaar5f2bb9f2005-01-11 21:29:04 +00006017
6018
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01006019maparg({name} [, {mode} [, {abbr} [, {dict}]]]) *maparg()*
Bram Moolenaarbd743252010-10-20 21:23:33 +02006020 When {dict} is omitted or zero: Return the rhs of mapping
6021 {name} in mode {mode}. The returned String has special
6022 characters translated like in the output of the ":map" command
6023 listing.
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01006024
Bram Moolenaarbd743252010-10-20 21:23:33 +02006025 When there is no mapping for {name}, an empty String is
Bram Moolenaar0b0f0992018-05-22 21:41:30 +02006026 returned. When the mapping for {name} is empty, then "<Nop>"
6027 is returned.
Bram Moolenaarbd743252010-10-20 21:23:33 +02006028
6029 The {name} can have special key names, like in the ":map"
6030 command.
6031
Bram Moolenaard12f5c12006-01-25 22:10:52 +00006032 {mode} can be one of these strings:
Bram Moolenaar071d4272004-06-13 20:20:40 +00006033 "n" Normal
Bram Moolenaarbd743252010-10-20 21:23:33 +02006034 "v" Visual (including Select)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006035 "o" Operator-pending
6036 "i" Insert
6037 "c" Cmd-line
Bram Moolenaarbd743252010-10-20 21:23:33 +02006038 "s" Select
6039 "x" Visual
Bram Moolenaar071d4272004-06-13 20:20:40 +00006040 "l" langmap |language-mapping|
Bram Moolenaar37c64c72017-09-19 22:06:03 +02006041 "t" Terminal-Job
Bram Moolenaar071d4272004-06-13 20:20:40 +00006042 "" Normal, Visual and Operator-pending
Bram Moolenaard12f5c12006-01-25 22:10:52 +00006043 When {mode} is omitted, the modes for "" are used.
Bram Moolenaarbd743252010-10-20 21:23:33 +02006044
Bram Moolenaare381d3d2016-07-07 14:50:41 +02006045 When {abbr} is there and it is |TRUE| use abbreviations
Bram Moolenaar97b2ad32006-03-18 21:40:56 +00006046 instead of mappings.
Bram Moolenaarbd743252010-10-20 21:23:33 +02006047
Bram Moolenaare381d3d2016-07-07 14:50:41 +02006048 When {dict} is there and it is |TRUE| return a dictionary
Bram Moolenaarbd743252010-10-20 21:23:33 +02006049 containing all the information of the mapping with the
6050 following items:
6051 "lhs" The {lhs} of the mapping.
6052 "rhs" The {rhs} of the mapping as typed.
6053 "silent" 1 for a |:map-silent| mapping, else 0.
Bram Moolenaar05365702010-10-27 18:34:44 +02006054 "noremap" 1 if the {rhs} of the mapping is not remappable.
Bram Moolenaarbd743252010-10-20 21:23:33 +02006055 "expr" 1 for an expression mapping (|:map-<expr>|).
6056 "buffer" 1 for a buffer local mapping (|:map-local|).
6057 "mode" Modes for which the mapping is defined. In
6058 addition to the modes mentioned above, these
6059 characters will be used:
6060 " " Normal, Visual and Operator-pending
6061 "!" Insert and Commandline mode
Bram Moolenaar166af9b2010-11-16 20:34:40 +01006062 (|mapmode-ic|)
Bram Moolenaar05365702010-10-27 18:34:44 +02006063 "sid" The script local ID, used for <sid> mappings
6064 (|<SID>|).
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02006065 "lnum" The line number in "sid", zero if unknown.
Bram Moolenaardfb18412013-12-11 18:53:29 +01006066 "nowait" Do not wait for other, longer mappings.
6067 (|:map-<nowait>|).
Bram Moolenaarbd743252010-10-20 21:23:33 +02006068
Bram Moolenaar071d4272004-06-13 20:20:40 +00006069 The mappings local to the current buffer are checked first,
6070 then the global mappings.
Bram Moolenaara40ceaf2006-01-13 22:35:40 +00006071 This function can be used to map a key even when it's already
6072 mapped, and have it do the original mapping too. Sketch: >
6073 exe 'nnoremap <Tab> ==' . maparg('<Tab>', 'n')
6074
Bram Moolenaar071d4272004-06-13 20:20:40 +00006075
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01006076mapcheck({name} [, {mode} [, {abbr}]]) *mapcheck()*
Bram Moolenaar071d4272004-06-13 20:20:40 +00006077 Check if there is a mapping that matches with {name} in mode
6078 {mode}. See |maparg()| for {mode} and special names in
6079 {name}.
Bram Moolenaare381d3d2016-07-07 14:50:41 +02006080 When {abbr} is there and it is |TRUE| use abbreviations
Bram Moolenaar97b2ad32006-03-18 21:40:56 +00006081 instead of mappings.
Bram Moolenaar071d4272004-06-13 20:20:40 +00006082 A match happens with a mapping that starts with {name} and
6083 with a mapping which is equal to the start of {name}.
6084
Bram Moolenaar446cb832008-06-24 21:56:24 +00006085 matches mapping "a" "ab" "abc" ~
Bram Moolenaar071d4272004-06-13 20:20:40 +00006086 mapcheck("a") yes yes yes
6087 mapcheck("abc") yes yes yes
6088 mapcheck("ax") yes no no
6089 mapcheck("b") no no no
6090
6091 The difference with maparg() is that mapcheck() finds a
6092 mapping that matches with {name}, while maparg() only finds a
6093 mapping for {name} exactly.
6094 When there is no mapping that starts with {name}, an empty
Bram Moolenaar0b0f0992018-05-22 21:41:30 +02006095 String is returned. If there is one, the RHS of that mapping
Bram Moolenaar071d4272004-06-13 20:20:40 +00006096 is returned. If there are several mappings that start with
Bram Moolenaar0b0f0992018-05-22 21:41:30 +02006097 {name}, the RHS of one of them is returned. This will be
6098 "<Nop>" if the RHS is empty.
Bram Moolenaar071d4272004-06-13 20:20:40 +00006099 The mappings local to the current buffer are checked first,
6100 then the global mappings.
6101 This function can be used to check if a mapping can be added
6102 without being ambiguous. Example: >
6103 :if mapcheck("_vv") == ""
6104 : map _vv :set guifont=7x13<CR>
6105 :endif
6106< This avoids adding the "_vv" mapping when there already is a
6107 mapping for "_v" or for "_vvv".
6108
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01006109match({expr}, {pat} [, {start} [, {count}]]) *match()*
Bram Moolenaar32466aa2006-02-24 23:53:04 +00006110 When {expr} is a |List| then this returns the index of the
6111 first item where {pat} matches. Each item is used as a
Bram Moolenaara23ccb82006-02-27 00:08:02 +00006112 String, |Lists| and |Dictionaries| are used as echoed.
Bram Moolenaar93a1df22018-09-10 11:51:50 +02006113
Bram Moolenaar58b85342016-08-14 19:54:54 +02006114 Otherwise, {expr} is used as a String. The result is a
Bram Moolenaar5f2bb9f2005-01-11 21:29:04 +00006115 Number, which gives the index (byte offset) in {expr} where
6116 {pat} matches.
Bram Moolenaar93a1df22018-09-10 11:51:50 +02006117
Bram Moolenaar32466aa2006-02-24 23:53:04 +00006118 A match at the first character or |List| item returns zero.
Bram Moolenaar89cb5e02004-07-19 20:55:54 +00006119 If there is no match -1 is returned.
Bram Moolenaar93a1df22018-09-10 11:51:50 +02006120
Bram Moolenaar20f90cf2011-05-19 12:22:51 +02006121 For getting submatches see |matchlist()|.
Bram Moolenaar89cb5e02004-07-19 20:55:54 +00006122 Example: >
Bram Moolenaar5f2bb9f2005-01-11 21:29:04 +00006123 :echo match("testing", "ing") " results in 4
Bram Moolenaar362e1a32006-03-06 23:29:24 +00006124 :echo match([1, 'x'], '\a') " results in 1
Bram Moolenaar5f2bb9f2005-01-11 21:29:04 +00006125< See |string-match| for how {pat} is used.
Bram Moolenaar05159a02005-02-26 23:04:13 +00006126 *strpbrk()*
Bram Moolenaar58b85342016-08-14 19:54:54 +02006127 Vim doesn't have a strpbrk() function. But you can do: >
Bram Moolenaar05159a02005-02-26 23:04:13 +00006128 :let sepidx = match(line, '[.,;: \t]')
6129< *strcasestr()*
6130 Vim doesn't have a strcasestr() function. But you can add
6131 "\c" to the pattern to ignore case: >
6132 :let idx = match(haystack, '\cneedle')
6133<
Bram Moolenaar5f2bb9f2005-01-11 21:29:04 +00006134 If {start} is given, the search starts from byte index
Bram Moolenaar32466aa2006-02-24 23:53:04 +00006135 {start} in a String or item {start} in a |List|.
Bram Moolenaar071d4272004-06-13 20:20:40 +00006136 The result, however, is still the index counted from the
Bram Moolenaar402d2fe2005-04-15 21:00:38 +00006137 first character/item. Example: >
Bram Moolenaar071d4272004-06-13 20:20:40 +00006138 :echo match("testing", "ing", 2)
6139< result is again "4". >
6140 :echo match("testing", "ing", 4)
6141< result is again "4". >
6142 :echo match("testing", "t", 2)
6143< result is "3".
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00006144 For a String, if {start} > 0 then it is like the string starts
Bram Moolenaar0b238792006-03-02 22:49:12 +00006145 {start} bytes later, thus "^" will match at {start}. Except
6146 when {count} is given, then it's like matches before the
6147 {start} byte are ignored (this is a bit complicated to keep it
6148 backwards compatible).
Bram Moolenaar5f2bb9f2005-01-11 21:29:04 +00006149 For a String, if {start} < 0, it will be set to 0. For a list
6150 the index is counted from the end.
Bram Moolenaare224ffa2006-03-01 00:01:28 +00006151 If {start} is out of range ({start} > strlen({expr}) for a
6152 String or {start} > len({expr}) for a |List|) -1 is returned.
Bram Moolenaar5f2bb9f2005-01-11 21:29:04 +00006153
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00006154 When {count} is given use the {count}'th match. When a match
Bram Moolenaare224ffa2006-03-01 00:01:28 +00006155 is found in a String the search for the next one starts one
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00006156 character further. Thus this example results in 1: >
6157 echo match("testing", "..", 0, 2)
6158< In a |List| the search continues in the next item.
Bram Moolenaar0b238792006-03-02 22:49:12 +00006159 Note that when {count} is added the way {start} works changes,
6160 see above.
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00006161
Bram Moolenaar071d4272004-06-13 20:20:40 +00006162 See |pattern| for the patterns that are accepted.
6163 The 'ignorecase' option is used to set the ignore-caseness of
Bram Moolenaar58b85342016-08-14 19:54:54 +02006164 the pattern. 'smartcase' is NOT used. The matching is always
Bram Moolenaar071d4272004-06-13 20:20:40 +00006165 done like 'magic' is set and 'cpoptions' is empty.
6166
Bram Moolenaar95e51472018-07-28 16:55:56 +02006167 *matchadd()* *E798* *E799* *E801* *E957*
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01006168matchadd({group}, {pattern} [, {priority} [, {id} [, {dict}]]])
Bram Moolenaar6ee10162007-07-26 20:58:42 +00006169 Defines a pattern to be highlighted in the current window (a
6170 "match"). It will be highlighted with {group}. Returns an
6171 identification number (ID), which can be used to delete the
6172 match using |matchdelete()|.
Bram Moolenaar8e69b4a2013-11-09 03:41:58 +01006173 Matching is case sensitive and magic, unless case sensitivity
6174 or magicness are explicitly overridden in {pattern}. The
6175 'magic', 'smartcase' and 'ignorecase' options are not used.
Bram Moolenaarf9132812015-07-21 19:19:13 +02006176 The "Conceal" value is special, it causes the match to be
6177 concealed.
Bram Moolenaar6ee10162007-07-26 20:58:42 +00006178
6179 The optional {priority} argument assigns a priority to the
Bram Moolenaar58b85342016-08-14 19:54:54 +02006180 match. A match with a high priority will have its
Bram Moolenaar6ee10162007-07-26 20:58:42 +00006181 highlighting overrule that of a match with a lower priority.
6182 A priority is specified as an integer (negative numbers are no
6183 exception). If the {priority} argument is not specified, the
6184 default priority is 10. The priority of 'hlsearch' is zero,
6185 hence all matches with a priority greater than zero will
6186 overrule it. Syntax highlighting (see 'syntax') is a separate
6187 mechanism, and regardless of the chosen priority a match will
6188 always overrule syntax highlighting.
6189
6190 The optional {id} argument allows the request for a specific
6191 match ID. If a specified ID is already taken, an error
6192 message will appear and the match will not be added. An ID
6193 is specified as a positive integer (zero excluded). IDs 1, 2
6194 and 3 are reserved for |:match|, |:2match| and |:3match|,
Bram Moolenaar6561d522015-07-21 15:48:27 +02006195 respectively. If the {id} argument is not specified or -1,
Bram Moolenaar6ee10162007-07-26 20:58:42 +00006196 |matchadd()| automatically chooses a free ID.
6197
Bram Moolenaar85084ef2016-01-17 22:26:33 +01006198 The optional {dict} argument allows for further custom
6199 values. Currently this is used to specify a match specific
Bram Moolenaar6561d522015-07-21 15:48:27 +02006200 conceal character that will be shown for |hl-Conceal|
6201 highlighted matches. The dict can have the following members:
6202
6203 conceal Special character to show instead of the
Bram Moolenaar6463ca22016-02-13 17:04:46 +01006204 match (only for |hl-Conceal| highlighted
Bram Moolenaar6561d522015-07-21 15:48:27 +02006205 matches, see |:syn-cchar|)
Bram Moolenaar95e51472018-07-28 16:55:56 +02006206 window Instead of the current window use the
6207 window with this number or window ID.
Bram Moolenaar6561d522015-07-21 15:48:27 +02006208
Bram Moolenaar6ee10162007-07-26 20:58:42 +00006209 The number of matches is not limited, as it is the case with
6210 the |:match| commands.
6211
6212 Example: >
6213 :highlight MyGroup ctermbg=green guibg=green
6214 :let m = matchadd("MyGroup", "TODO")
6215< Deletion of the pattern: >
6216 :call matchdelete(m)
6217
6218< A list of matches defined by |matchadd()| and |:match| are
Bram Moolenaar58b85342016-08-14 19:54:54 +02006219 available from |getmatches()|. All matches can be deleted in
Bram Moolenaar6ee10162007-07-26 20:58:42 +00006220 one operation by |clearmatches()|.
Bram Moolenaar910f66f2006-04-05 20:41:53 +00006221
Bram Moolenaar8e97bd72016-08-06 22:05:07 +02006222 *matchaddpos()*
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01006223matchaddpos({group}, {pos} [, {priority} [, {id} [, {dict}]]])
Bram Moolenaarb3414592014-06-17 17:48:32 +02006224 Same as |matchadd()|, but requires a list of positions {pos}
6225 instead of a pattern. This command is faster than |matchadd()|
6226 because it does not require to handle regular expressions and
6227 sets buffer line boundaries to redraw screen. It is supposed
6228 to be used when fast match additions and deletions are
6229 required, for example to highlight matching parentheses.
6230
6231 The list {pos} can contain one of these items:
Bram Moolenaarb6da44a2014-06-25 18:15:22 +02006232 - A number. This whole line will be highlighted. The first
Bram Moolenaarb3414592014-06-17 17:48:32 +02006233 line has number 1.
6234 - A list with one number, e.g., [23]. The whole line with this
6235 number will be highlighted.
6236 - A list with two numbers, e.g., [23, 11]. The first number is
Bram Moolenaarb6da44a2014-06-25 18:15:22 +02006237 the line number, the second one is the column number (first
6238 column is 1, the value must correspond to the byte index as
6239 |col()| would return). The character at this position will
6240 be highlighted.
Bram Moolenaarb3414592014-06-17 17:48:32 +02006241 - A list with three numbers, e.g., [23, 11, 3]. As above, but
Bram Moolenaarb6da44a2014-06-25 18:15:22 +02006242 the third number gives the length of the highlight in bytes.
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01006243
Bram Moolenaarb3414592014-06-17 17:48:32 +02006244 The maximum number of positions is 8.
6245
6246 Example: >
6247 :highlight MyGroup ctermbg=green guibg=green
6248 :let m = matchaddpos("MyGroup", [[23, 24], 34])
6249< Deletion of the pattern: >
6250 :call matchdelete(m)
6251
6252< Matches added by |matchaddpos()| are returned by
6253 |getmatches()| with an entry "pos1", "pos2", etc., with the
6254 value a list like the {pos} item.
Bram Moolenaarb3414592014-06-17 17:48:32 +02006255
Bram Moolenaar910f66f2006-04-05 20:41:53 +00006256matcharg({nr}) *matcharg()*
Bram Moolenaarc9b4b052006-04-30 18:54:39 +00006257 Selects the {nr} match item, as set with a |:match|,
Bram Moolenaar910f66f2006-04-05 20:41:53 +00006258 |:2match| or |:3match| command.
6259 Return a |List| with two elements:
6260 The name of the highlight group used
6261 The pattern used.
6262 When {nr} is not 1, 2 or 3 returns an empty |List|.
6263 When there is no match item set returns ['', ''].
Bram Moolenaar6ee10162007-07-26 20:58:42 +00006264 This is useful to save and restore a |:match|.
6265 Highlighting matches using the |:match| commands are limited
6266 to three matches. |matchadd()| does not have this limitation.
Bram Moolenaar910f66f2006-04-05 20:41:53 +00006267
Bram Moolenaar6ee10162007-07-26 20:58:42 +00006268matchdelete({id}) *matchdelete()* *E802* *E803*
6269 Deletes a match with ID {id} previously defined by |matchadd()|
Bram Moolenaar446cb832008-06-24 21:56:24 +00006270 or one of the |:match| commands. Returns 0 if successful,
Bram Moolenaar6ee10162007-07-26 20:58:42 +00006271 otherwise -1. See example for |matchadd()|. All matches can
6272 be deleted in one operation by |clearmatches()|.
Bram Moolenaar910f66f2006-04-05 20:41:53 +00006273
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01006274matchend({expr}, {pat} [, {start} [, {count}]]) *matchend()*
Bram Moolenaar8f3f58f2010-01-06 20:52:26 +01006275 Same as |match()|, but return the index of first character
6276 after the match. Example: >
Bram Moolenaar071d4272004-06-13 20:20:40 +00006277 :echo matchend("testing", "ing")
6278< results in "7".
Bram Moolenaar05159a02005-02-26 23:04:13 +00006279 *strspn()* *strcspn()*
6280 Vim doesn't have a strspn() or strcspn() function, but you can
6281 do it with matchend(): >
6282 :let span = matchend(line, '[a-zA-Z]')
6283 :let span = matchend(line, '[^a-zA-Z]')
6284< Except that -1 is returned when there are no matches.
6285
Bram Moolenaar8f3f58f2010-01-06 20:52:26 +01006286 The {start}, if given, has the same meaning as for |match()|. >
Bram Moolenaar071d4272004-06-13 20:20:40 +00006287 :echo matchend("testing", "ing", 2)
6288< results in "7". >
6289 :echo matchend("testing", "ing", 5)
6290< result is "-1".
Bram Moolenaar8f3f58f2010-01-06 20:52:26 +01006291 When {expr} is a |List| the result is equal to |match()|.
Bram Moolenaar071d4272004-06-13 20:20:40 +00006292
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01006293matchlist({expr}, {pat} [, {start} [, {count}]]) *matchlist()*
Bram Moolenaar8f3f58f2010-01-06 20:52:26 +01006294 Same as |match()|, but return a |List|. The first item in the
Bram Moolenaar3a7c85b2005-02-05 21:39:53 +00006295 list is the matched string, same as what matchstr() would
6296 return. Following items are submatches, like "\1", "\2", etc.
Bram Moolenaarf9393ef2006-04-24 19:47:27 +00006297 in |:substitute|. When an optional submatch didn't match an
6298 empty string is used. Example: >
6299 echo matchlist('acd', '\(a\)\?\(b\)\?\(c\)\?\(.*\)')
6300< Results in: ['acd', 'a', '', 'c', 'd', '', '', '', '', '']
Bram Moolenaar3a7c85b2005-02-05 21:39:53 +00006301 When there is no match an empty list is returned.
6302
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01006303matchstr({expr}, {pat} [, {start} [, {count}]]) *matchstr()*
Bram Moolenaar446cb832008-06-24 21:56:24 +00006304 Same as |match()|, but return the matched string. Example: >
Bram Moolenaar071d4272004-06-13 20:20:40 +00006305 :echo matchstr("testing", "ing")
6306< results in "ing".
6307 When there is no match "" is returned.
Bram Moolenaar8f3f58f2010-01-06 20:52:26 +01006308 The {start}, if given, has the same meaning as for |match()|. >
Bram Moolenaar071d4272004-06-13 20:20:40 +00006309 :echo matchstr("testing", "ing", 2)
6310< results in "ing". >
6311 :echo matchstr("testing", "ing", 5)
6312< result is "".
Bram Moolenaar32466aa2006-02-24 23:53:04 +00006313 When {expr} is a |List| then the matching item is returned.
Bram Moolenaar5f2bb9f2005-01-11 21:29:04 +00006314 The type isn't changed, it's not necessarily a String.
Bram Moolenaar071d4272004-06-13 20:20:40 +00006315
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01006316matchstrpos({expr}, {pat} [, {start} [, {count}]]) *matchstrpos()*
Bram Moolenaar7fed5c12016-03-29 23:10:31 +02006317 Same as |matchstr()|, but return the matched string, the start
6318 position and the end position of the match. Example: >
6319 :echo matchstrpos("testing", "ing")
6320< results in ["ing", 4, 7].
6321 When there is no match ["", -1, -1] is returned.
6322 The {start}, if given, has the same meaning as for |match()|. >
6323 :echo matchstrpos("testing", "ing", 2)
6324< results in ["ing", 4, 7]. >
6325 :echo matchstrpos("testing", "ing", 5)
6326< result is ["", -1, -1].
6327 When {expr} is a |List| then the matching item, the index
6328 of first item where {pat} matches, the start position and the
6329 end position of the match are returned. >
6330 :echo matchstrpos([1, '__x'], '\a')
6331< result is ["x", 1, 2, 3].
6332 The type isn't changed, it's not necessarily a String.
6333
Bram Moolenaar9588a0f2005-01-08 21:45:39 +00006334 *max()*
Bram Moolenaar690afe12017-01-28 18:34:47 +01006335max({expr}) Return the maximum value of all items in {expr}.
6336 {expr} can be a list or a dictionary. For a dictionary,
6337 it returns the maximum of all values in the dictionary.
6338 If {expr} is neither a list nor a dictionary, or one of the
6339 items in {expr} cannot be used as a Number this results in
Bram Moolenaarf8be4612017-06-23 20:52:40 +02006340 an error. An empty |List| or |Dictionary| results in zero.
Bram Moolenaar9588a0f2005-01-08 21:45:39 +00006341
6342 *min()*
Bram Moolenaar690afe12017-01-28 18:34:47 +01006343min({expr}) Return the minimum value of all items in {expr}.
6344 {expr} can be a list or a dictionary. For a dictionary,
6345 it returns the minimum of all values in the dictionary.
6346 If {expr} is neither a list nor a dictionary, or one of the
6347 items in {expr} cannot be used as a Number this results in
Bram Moolenaarf8be4612017-06-23 20:52:40 +02006348 an error. An empty |List| or |Dictionary| results in zero.
Bram Moolenaar9588a0f2005-01-08 21:45:39 +00006349
Bram Moolenaar551dbcc2006-04-25 22:13:59 +00006350 *mkdir()* *E739*
Bram Moolenaar26a60b42005-02-22 08:49:11 +00006351mkdir({name} [, {path} [, {prot}]])
6352 Create directory {name}.
6353 If {path} is "p" then intermediate directories are created as
6354 necessary. Otherwise it must be "".
6355 If {prot} is given it is used to set the protection bits of
6356 the new directory. The default is 0755 (rwxr-xr-x: r/w for
Bram Moolenaar58b85342016-08-14 19:54:54 +02006357 the user readable for others). Use 0700 to make it unreadable
Bram Moolenaared39e1d2008-08-09 17:55:22 +00006358 for others. This is only used for the last part of {name}.
6359 Thus if you create /tmp/foo/bar then /tmp/foo will be created
6360 with 0755.
6361 Example: >
6362 :call mkdir($HOME . "/tmp/foo/bar", "p", 0700)
6363< This function is not available in the |sandbox|.
Bram Moolenaar78a16b02018-04-14 13:51:55 +02006364 There is no error if the directory already exists and the "p"
6365 flag is passed (since patch 8.0.1708).
Bram Moolenaar26a60b42005-02-22 08:49:11 +00006366 Not available on all systems. To check use: >
6367 :if exists("*mkdir")
6368<
Bram Moolenaar071d4272004-06-13 20:20:40 +00006369 *mode()*
Bram Moolenaar446cb832008-06-24 21:56:24 +00006370mode([expr]) Return a string that indicates the current mode.
Bram Moolenaar05bb9532008-07-04 09:44:11 +00006371 If [expr] is supplied and it evaluates to a non-zero Number or
6372 a non-empty String (|non-zero-arg|), then the full mode is
Bram Moolenaare381d3d2016-07-07 14:50:41 +02006373 returned, otherwise only the first letter is returned.
Bram Moolenaar446cb832008-06-24 21:56:24 +00006374
Bram Moolenaar612cc382018-07-29 15:34:26 +02006375 n Normal, Terminal-Normal
6376 no Operator-pending
Bram Moolenaar5976f8f2018-12-27 23:44:44 +01006377 nov Operator-pending (forced characterwise |o_v|)
6378 noV Operator-pending (forced linewise |o_V|)
6379 noCTRL-V Operator-pending (forced blockwise |o_CTRL-V|);
Bram Moolenaar5b69c222019-01-11 14:50:06 +01006380 CTRL-V is one character
Bram Moolenaar612cc382018-07-29 15:34:26 +02006381 niI Normal using |i_CTRL-O| in |Insert-mode|
6382 niR Normal using |i_CTRL-O| in |Replace-mode|
6383 niV Normal using |i_CTRL-O| in |Virtual-Replace-mode|
6384 v Visual by character
6385 V Visual by line
6386 CTRL-V Visual blockwise
6387 s Select by character
6388 S Select by line
6389 CTRL-S Select blockwise
6390 i Insert
6391 ic Insert mode completion |compl-generic|
6392 ix Insert mode |i_CTRL-X| completion
6393 R Replace |R|
6394 Rc Replace mode completion |compl-generic|
6395 Rv Virtual Replace |gR|
6396 Rx Replace mode |i_CTRL-X| completion
6397 c Command-line editing
6398 cv Vim Ex mode |gQ|
6399 ce Normal Ex mode |Q|
6400 r Hit-enter prompt
6401 rm The -- more -- prompt
6402 r? A |:confirm| query of some sort
6403 ! Shell or external command is executing
6404 t Terminal-Job mode: keys go to the job
Bram Moolenaar446cb832008-06-24 21:56:24 +00006405 This is useful in the 'statusline' option or when used
6406 with |remote_expr()| In most other places it always returns
6407 "c" or "n".
Bram Moolenaar612cc382018-07-29 15:34:26 +02006408 Note that in the future more modes and more specific modes may
6409 be added. It's better not to compare the whole string but only
6410 the leading character(s).
Bram Moolenaar446cb832008-06-24 21:56:24 +00006411 Also see |visualmode()|.
Bram Moolenaar071d4272004-06-13 20:20:40 +00006412
Bram Moolenaar7e506b62010-01-19 15:55:06 +01006413mzeval({expr}) *mzeval()*
6414 Evaluate MzScheme expression {expr} and return its result
Bram Moolenaard38b0552012-04-25 19:07:41 +02006415 converted to Vim data structures.
Bram Moolenaar7e506b62010-01-19 15:55:06 +01006416 Numbers and strings are returned as they are.
6417 Pairs (including lists and improper lists) and vectors are
6418 returned as Vim |Lists|.
6419 Hash tables are represented as Vim |Dictionary| type with keys
6420 converted to strings.
6421 All other types are converted to string with display function.
6422 Examples: >
6423 :mz (define l (list 1 2 3))
6424 :mz (define h (make-hash)) (hash-set! h "list" l)
6425 :echo mzeval("l")
6426 :echo mzeval("h")
6427<
6428 {only available when compiled with the |+mzscheme| feature}
6429
Bram Moolenaar071d4272004-06-13 20:20:40 +00006430nextnonblank({lnum}) *nextnonblank()*
6431 Return the line number of the first line at or below {lnum}
6432 that is not blank. Example: >
6433 if getline(nextnonblank(1)) =~ "Java"
6434< When {lnum} is invalid or there is no non-blank line at or
6435 below it, zero is returned.
6436 See also |prevnonblank()|.
6437
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01006438nr2char({expr} [, {utf8}]) *nr2char()*
Bram Moolenaar071d4272004-06-13 20:20:40 +00006439 Return a string with a single character, which has the number
6440 value {expr}. Examples: >
6441 nr2char(64) returns "@"
6442 nr2char(32) returns " "
Bram Moolenaard35d7842013-01-23 17:17:10 +01006443< When {utf8} is omitted or zero, the current 'encoding' is used.
6444 Example for "utf-8": >
Bram Moolenaar071d4272004-06-13 20:20:40 +00006445 nr2char(300) returns I with bow character
Bram Moolenaard35d7842013-01-23 17:17:10 +01006446< With {utf8} set to 1, always return utf-8 characters.
6447 Note that a NUL character in the file is specified with
Bram Moolenaar071d4272004-06-13 20:20:40 +00006448 nr2char(10), because NULs are represented with newline
6449 characters. nr2char(0) is a real NUL and terminates the
Bram Moolenaar383f9bc2005-01-19 22:18:32 +00006450 string, thus results in an empty string.
Bram Moolenaar071d4272004-06-13 20:20:40 +00006451
Bram Moolenaard6e256c2011-12-14 15:32:50 +01006452or({expr}, {expr}) *or()*
6453 Bitwise OR on the two arguments. The arguments are converted
6454 to a number. A List, Dict or Float argument causes an error.
6455 Example: >
6456 :let bits = or(bits, 0x80)
6457
6458
Bram Moolenaar910f66f2006-04-05 20:41:53 +00006459pathshorten({expr}) *pathshorten()*
6460 Shorten directory names in the path {expr} and return the
6461 result. The tail, the file name, is kept as-is. The other
6462 components in the path are reduced to single letters. Leading
6463 '~' and '.' characters are kept. Example: >
6464 :echo pathshorten('~/.vim/autoload/myfile.vim')
6465< ~/.v/a/myfile.vim ~
6466 It doesn't matter if the path exists or not.
6467
Bram Moolenaare9b892e2016-01-17 21:15:58 +01006468perleval({expr}) *perleval()*
6469 Evaluate Perl expression {expr} in scalar context and return
6470 its result converted to Vim data structures. If value can't be
Bram Moolenaar85084ef2016-01-17 22:26:33 +01006471 converted, it is returned as a string Perl representation.
6472 Note: If you want an array or hash, {expr} must return a
6473 reference to it.
Bram Moolenaare9b892e2016-01-17 21:15:58 +01006474 Example: >
6475 :echo perleval('[1 .. 4]')
6476< [1, 2, 3, 4]
6477 {only available when compiled with the |+perl| feature}
6478
Bram Moolenaar446cb832008-06-24 21:56:24 +00006479pow({x}, {y}) *pow()*
6480 Return the power of {x} to the exponent {y} as a |Float|.
6481 {x} and {y} must evaluate to a |Float| or a |Number|.
6482 Examples: >
6483 :echo pow(3, 3)
6484< 27.0 >
6485 :echo pow(2, 16)
6486< 65536.0 >
6487 :echo pow(32, 0.20)
6488< 2.0
6489 {only available when compiled with the |+float| feature}
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01006490
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00006491prevnonblank({lnum}) *prevnonblank()*
6492 Return the line number of the first line at or above {lnum}
6493 that is not blank. Example: >
6494 let ind = indent(prevnonblank(v:lnum - 1))
6495< When {lnum} is invalid or there is no non-blank line at or
6496 above it, zero is returned.
6497 Also see |nextnonblank()|.
6498
6499
Bram Moolenaar4be06f92005-07-29 22:36:03 +00006500printf({fmt}, {expr1} ...) *printf()*
6501 Return a String with {fmt}, where "%" items are replaced by
6502 the formatted form of their respective arguments. Example: >
Bram Moolenaar5a8684e2005-07-30 22:43:24 +00006503 printf("%4d: E%d %.30s", lnum, errno, msg)
Bram Moolenaar4be06f92005-07-29 22:36:03 +00006504< May result in:
Bram Moolenaar5a8684e2005-07-30 22:43:24 +00006505 " 99: E42 asdfasdfasdfasdfasdfasdfasdfas" ~
Bram Moolenaar4be06f92005-07-29 22:36:03 +00006506
6507 Often used items are:
Bram Moolenaarc9b4b052006-04-30 18:54:39 +00006508 %s string
Bram Moolenaar3ab72c52012-11-14 18:10:56 +01006509 %6S string right-aligned in 6 display cells
Bram Moolenaar98692072006-02-04 00:57:42 +00006510 %6s string right-aligned in 6 bytes
Bram Moolenaar446cb832008-06-24 21:56:24 +00006511 %.9s string truncated to 9 bytes
6512 %c single byte
6513 %d decimal number
6514 %5d decimal number padded with spaces to 5 characters
6515 %x hex number
6516 %04x hex number padded with zeros to at least 4 characters
6517 %X hex number using upper case letters
6518 %o octal number
Bram Moolenaar91984b92016-08-16 21:58:41 +02006519 %08b binary number padded with zeros to at least 8 chars
Bram Moolenaar04186092016-08-29 21:55:35 +02006520 %f floating point number as 12.23, inf, -inf or nan
6521 %F floating point number as 12.23, INF, -INF or NAN
6522 %e floating point number as 1.23e3, inf, -inf or nan
6523 %E floating point number as 1.23E3, INF, -INF or NAN
Bram Moolenaar446cb832008-06-24 21:56:24 +00006524 %g floating point number, as %f or %e depending on value
Bram Moolenaar3df01732017-02-17 22:47:16 +01006525 %G floating point number, as %F or %E depending on value
Bram Moolenaar446cb832008-06-24 21:56:24 +00006526 %% the % character itself
Bram Moolenaar4be06f92005-07-29 22:36:03 +00006527
6528 Conversion specifications start with '%' and end with the
6529 conversion type. All other characters are copied unchanged to
6530 the result.
6531
6532 The "%" starts a conversion specification. The following
Bram Moolenaar5a8684e2005-07-30 22:43:24 +00006533 arguments appear in sequence:
Bram Moolenaar4be06f92005-07-29 22:36:03 +00006534
Bram Moolenaar5a8684e2005-07-30 22:43:24 +00006535 % [flags] [field-width] [.precision] type
Bram Moolenaar4be06f92005-07-29 22:36:03 +00006536
Bram Moolenaarc9b4b052006-04-30 18:54:39 +00006537 flags
Bram Moolenaar5a8684e2005-07-30 22:43:24 +00006538 Zero or more of the following flags:
6539
Bram Moolenaar4be06f92005-07-29 22:36:03 +00006540 # The value should be converted to an "alternate
6541 form". For c, d, and s conversions, this option
6542 has no effect. For o conversions, the precision
6543 of the number is increased to force the first
6544 character of the output string to a zero (except
6545 if a zero value is printed with an explicit
6546 precision of zero).
Bram Moolenaar91984b92016-08-16 21:58:41 +02006547 For b and B conversions, a non-zero result has
6548 the string "0b" (or "0B" for B conversions)
6549 prepended to it.
Bram Moolenaar4be06f92005-07-29 22:36:03 +00006550 For x and X conversions, a non-zero result has
6551 the string "0x" (or "0X" for X conversions)
6552 prepended to it.
Bram Moolenaar5a8684e2005-07-30 22:43:24 +00006553
Bram Moolenaar4be06f92005-07-29 22:36:03 +00006554 0 (zero) Zero padding. For all conversions the converted
6555 value is padded on the left with zeros rather
6556 than blanks. If a precision is given with a
Bram Moolenaar91984b92016-08-16 21:58:41 +02006557 numeric conversion (d, b, B, o, x, and X), the 0
6558 flag is ignored.
Bram Moolenaar5a8684e2005-07-30 22:43:24 +00006559
Bram Moolenaar4be06f92005-07-29 22:36:03 +00006560 - A negative field width flag; the converted value
6561 is to be left adjusted on the field boundary.
6562 The converted value is padded on the right with
6563 blanks, rather than on the left with blanks or
6564 zeros. A - overrides a 0 if both are given.
Bram Moolenaar5a8684e2005-07-30 22:43:24 +00006565
Bram Moolenaar4be06f92005-07-29 22:36:03 +00006566 ' ' (space) A blank should be left before a positive
6567 number produced by a signed conversion (d).
Bram Moolenaar5a8684e2005-07-30 22:43:24 +00006568
Bram Moolenaar4be06f92005-07-29 22:36:03 +00006569 + A sign must always be placed before a number
Bram Moolenaar58b85342016-08-14 19:54:54 +02006570 produced by a signed conversion. A + overrides
Bram Moolenaar4be06f92005-07-29 22:36:03 +00006571 a space if both are used.
Bram Moolenaar5a8684e2005-07-30 22:43:24 +00006572
6573 field-width
6574 An optional decimal digit string specifying a minimum
Bram Moolenaar98692072006-02-04 00:57:42 +00006575 field width. If the converted value has fewer bytes
6576 than the field width, it will be padded with spaces on
6577 the left (or right, if the left-adjustment flag has
6578 been given) to fill out the field width.
Bram Moolenaar5a8684e2005-07-30 22:43:24 +00006579
6580 .precision
6581 An optional precision, in the form of a period '.'
6582 followed by an optional digit string. If the digit
6583 string is omitted, the precision is taken as zero.
6584 This gives the minimum number of digits to appear for
6585 d, o, x, and X conversions, or the maximum number of
Bram Moolenaar98692072006-02-04 00:57:42 +00006586 bytes to be printed from a string for s conversions.
Bram Moolenaar446cb832008-06-24 21:56:24 +00006587 For floating point it is the number of digits after
6588 the decimal point.
Bram Moolenaar5a8684e2005-07-30 22:43:24 +00006589
6590 type
6591 A character that specifies the type of conversion to
6592 be applied, see below.
6593
Bram Moolenaar4be06f92005-07-29 22:36:03 +00006594 A field width or precision, or both, may be indicated by an
6595 asterisk '*' instead of a digit string. In this case, a
Bram Moolenaar58b85342016-08-14 19:54:54 +02006596 Number argument supplies the field width or precision. A
Bram Moolenaar4be06f92005-07-29 22:36:03 +00006597 negative field width is treated as a left adjustment flag
6598 followed by a positive field width; a negative precision is
6599 treated as though it were missing. Example: >
Bram Moolenaar5a8684e2005-07-30 22:43:24 +00006600 :echo printf("%d: %.*s", nr, width, line)
Bram Moolenaar4be06f92005-07-29 22:36:03 +00006601< This limits the length of the text used from "line" to
Bram Moolenaar5a8684e2005-07-30 22:43:24 +00006602 "width" bytes.
Bram Moolenaar4be06f92005-07-29 22:36:03 +00006603
Bram Moolenaarc9b4b052006-04-30 18:54:39 +00006604 The conversion specifiers and their meanings are:
Bram Moolenaar5a8684e2005-07-30 22:43:24 +00006605
Bram Moolenaar91984b92016-08-16 21:58:41 +02006606 *printf-d* *printf-b* *printf-B* *printf-o*
6607 *printf-x* *printf-X*
6608 dbBoxX The Number argument is converted to signed decimal
6609 (d), unsigned binary (b and B), unsigned octal (o), or
6610 unsigned hexadecimal (x and X) notation. The letters
6611 "abcdef" are used for x conversions; the letters
6612 "ABCDEF" are used for X conversions.
Bram Moolenaar5a8684e2005-07-30 22:43:24 +00006613 The precision, if any, gives the minimum number of
6614 digits that must appear; if the converted value
6615 requires fewer digits, it is padded on the left with
6616 zeros.
6617 In no case does a non-existent or small field width
6618 cause truncation of a numeric field; if the result of
6619 a conversion is wider than the field width, the field
6620 is expanded to contain the conversion result.
Bram Moolenaar30567352016-08-27 21:25:44 +02006621 The 'h' modifier indicates the argument is 16 bits.
6622 The 'l' modifier indicates the argument is 32 bits.
6623 The 'L' modifier indicates the argument is 64 bits.
6624 Generally, these modifiers are not useful. They are
6625 ignored when type is known from the argument.
6626
6627 i alias for d
6628 D alias for ld
6629 U alias for lu
6630 O alias for lo
Bram Moolenaar5a8684e2005-07-30 22:43:24 +00006631
Bram Moolenaar446cb832008-06-24 21:56:24 +00006632 *printf-c*
Bram Moolenaar5a8684e2005-07-30 22:43:24 +00006633 c The Number argument is converted to a byte, and the
6634 resulting character is written.
6635
Bram Moolenaar446cb832008-06-24 21:56:24 +00006636 *printf-s*
Bram Moolenaar5a8684e2005-07-30 22:43:24 +00006637 s The text of the String argument is used. If a
6638 precision is specified, no more bytes than the number
6639 specified are used.
Bram Moolenaar7571d552016-08-18 22:54:46 +02006640 If the argument is not a String type, it is
6641 automatically converted to text with the same format
6642 as ":echo".
Bram Moolenaar0122c402015-02-03 19:13:34 +01006643 *printf-S*
Bram Moolenaar3ab72c52012-11-14 18:10:56 +01006644 S The text of the String argument is used. If a
6645 precision is specified, no more display cells than the
6646 number specified are used. Without the |+multi_byte|
6647 feature works just like 's'.
Bram Moolenaar5a8684e2005-07-30 22:43:24 +00006648
Bram Moolenaar446cb832008-06-24 21:56:24 +00006649 *printf-f* *E807*
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01006650 f F The Float argument is converted into a string of the
Bram Moolenaar446cb832008-06-24 21:56:24 +00006651 form 123.456. The precision specifies the number of
6652 digits after the decimal point. When the precision is
6653 zero the decimal point is omitted. When the precision
6654 is not specified 6 is used. A really big number
Bram Moolenaar04186092016-08-29 21:55:35 +02006655 (out of range or dividing by zero) results in "inf"
Bram Moolenaarf8be4612017-06-23 20:52:40 +02006656 or "-inf" with %f (INF or -INF with %F).
6657 "0.0 / 0.0" results in "nan" with %f (NAN with %F).
Bram Moolenaar446cb832008-06-24 21:56:24 +00006658 Example: >
6659 echo printf("%.2f", 12.115)
6660< 12.12
6661 Note that roundoff depends on the system libraries.
6662 Use |round()| when in doubt.
6663
6664 *printf-e* *printf-E*
6665 e E The Float argument is converted into a string of the
6666 form 1.234e+03 or 1.234E+03 when using 'E'. The
6667 precision specifies the number of digits after the
6668 decimal point, like with 'f'.
6669
6670 *printf-g* *printf-G*
6671 g G The Float argument is converted like with 'f' if the
6672 value is between 0.001 (inclusive) and 10000000.0
6673 (exclusive). Otherwise 'e' is used for 'g' and 'E'
6674 for 'G'. When no precision is specified superfluous
6675 zeroes and '+' signs are removed, except for the zero
6676 immediately after the decimal point. Thus 10000000.0
6677 results in 1.0e7.
6678
6679 *printf-%*
Bram Moolenaar4be06f92005-07-29 22:36:03 +00006680 % A '%' is written. No argument is converted. The
6681 complete conversion specification is "%%".
Bram Moolenaar4be06f92005-07-29 22:36:03 +00006682
Bram Moolenaarc236c162008-07-13 17:41:49 +00006683 When a Number argument is expected a String argument is also
6684 accepted and automatically converted.
6685 When a Float or String argument is expected a Number argument
6686 is also accepted and automatically converted.
6687 Any other argument type results in an error message.
Bram Moolenaar4be06f92005-07-29 22:36:03 +00006688
Bram Moolenaar83bab712005-08-01 21:58:57 +00006689 *E766* *E767*
Bram Moolenaar4be06f92005-07-29 22:36:03 +00006690 The number of {exprN} arguments must exactly match the number
6691 of "%" items. If there are not sufficient or too many
Bram Moolenaar5a8684e2005-07-30 22:43:24 +00006692 arguments an error is given. Up to 18 arguments can be used.
Bram Moolenaar4be06f92005-07-29 22:36:03 +00006693
6694
Bram Moolenaarf2732452018-06-03 14:47:35 +02006695prompt_setcallback({buf}, {expr}) *prompt_setcallback()*
Bram Moolenaar0e5979a2018-06-17 19:36:33 +02006696 Set prompt callback for buffer {buf} to {expr}. When {expr}
6697 is an empty string the callback is removed. This has only
Bram Moolenaarf2732452018-06-03 14:47:35 +02006698 effect if {buf} has 'buftype' set to "prompt".
Bram Moolenaar0e5979a2018-06-17 19:36:33 +02006699
Bram Moolenaarf2732452018-06-03 14:47:35 +02006700 The callback is invoked when pressing Enter. The current
6701 buffer will always be the prompt buffer. A new line for a
6702 prompt is added before invoking the callback, thus the prompt
6703 for which the callback was invoked will be in the last but one
6704 line.
6705 If the callback wants to add text to the buffer, it must
6706 insert it above the last line, since that is where the current
6707 prompt is. This can also be done asynchronously.
6708 The callback is invoked with one argument, which is the text
6709 that was entered at the prompt. This can be an empty string
6710 if the user only typed Enter.
6711 Example: >
6712 call prompt_setcallback(bufnr(''), function('s:TextEntered'))
6713 func s:TextEntered(text)
6714 if a:text == 'exit' || a:text == 'quit'
6715 stopinsert
6716 close
6717 else
6718 call append(line('$') - 1, 'Entered: "' . a:text . '"')
6719 " Reset 'modified' to allow the buffer to be closed.
6720 set nomodified
6721 endif
6722 endfunc
6723
Bram Moolenaar0e5979a2018-06-17 19:36:33 +02006724prompt_setinterrupt({buf}, {expr}) *prompt_setinterrupt()*
6725 Set a callback for buffer {buf} to {expr}. When {expr} is an
6726 empty string the callback is removed. This has only effect if
6727 {buf} has 'buftype' set to "prompt".
6728
6729 This callback will be invoked when pressing CTRL-C in Insert
6730 mode. Without setting a callback Vim will exit Insert mode,
6731 as in any buffer.
6732
6733prompt_setprompt({buf}, {text}) *prompt_setprompt()*
6734 Set prompt for buffer {buf} to {text}. You most likely want
6735 {text} to end in a space.
6736 The result is only visible if {buf} has 'buftype' set to
6737 "prompt". Example: >
6738 call prompt_setprompt(bufnr(''), 'command: ')
Bram Moolenaar98aefe72018-12-13 22:20:09 +01006739<
6740 *prop_add()* *E965*
6741prop_add({lnum}, {col}, {props})
Bram Moolenaarb9c67a52019-01-01 19:49:20 +01006742 Attach a text property at position {lnum}, {col}. {col} is
6743 counted in bytes, use one for the first column.
Bram Moolenaar98aefe72018-12-13 22:20:09 +01006744 If {lnum} is invalid an error is given. *E966*
6745 If {col} is invalid an error is given. *E964*
6746
6747 {props} is a dictionary with these fields:
Bram Moolenaarb9c67a52019-01-01 19:49:20 +01006748 length length of text in bytes, can only be used
Bram Moolenaarc8c88492018-12-27 23:59:26 +01006749 for a property that does not continue in
Bram Moolenaarb9c67a52019-01-01 19:49:20 +01006750 another line; can be zero
6751 end_lnum line number for the end of text
Bram Moolenaar5b69c222019-01-11 14:50:06 +01006752 end_col column just after the text; not used when
6753 "length" is present; when {col} and "end_col"
6754 are equal, and "end_lnum" is omitted or equal
6755 to {lnum}, this is a zero-width text property
Bram Moolenaarc8c88492018-12-27 23:59:26 +01006756 bufnr buffer to add the property to; when omitted
Bram Moolenaar5b69c222019-01-11 14:50:06 +01006757 the current buffer is used
Bram Moolenaarc8c88492018-12-27 23:59:26 +01006758 id user defined ID for the property; when omitted
6759 zero is used
6760 type name of the text property type
Bram Moolenaar98aefe72018-12-13 22:20:09 +01006761 All fields except "type" are optional.
6762
6763 It is an error when both "length" and "end_lnum" or "end_col"
Bram Moolenaarb9c67a52019-01-01 19:49:20 +01006764 are given. Either use "length" or "end_col" for a property
Bram Moolenaar98aefe72018-12-13 22:20:09 +01006765 within one line, or use "end_lnum" and "end_col" for a
6766 property that spans more than one line.
Bram Moolenaarb9c67a52019-01-01 19:49:20 +01006767 When neither "length" nor "end_col" are given the property
6768 will be zero-width. That means it will not be highlighted but
6769 will move with the text, as a kind of mark.
Bram Moolenaare3d31b02018-12-24 23:07:04 +01006770 The property can end exactly at the last character of the
6771 text, or just after it. In the last case, if text is appended
6772 to the line, the text property size will increase, also when
6773 the property type does not have "end_incl" set.
Bram Moolenaar98aefe72018-12-13 22:20:09 +01006774
6775 "type" will first be looked up in the buffer the property is
6776 added to. When not found, the global property types are used.
6777 If not found an error is given.
6778
6779 See |text-properties| for information about text properties.
6780
6781
Bram Moolenaar9d87a372018-12-18 21:41:50 +01006782prop_clear({lnum} [, {lnum-end} [, {props}]]) *prop_clear()*
Bram Moolenaar98aefe72018-12-13 22:20:09 +01006783 Remove all text properties from line {lnum}.
Bram Moolenaar9d87a372018-12-18 21:41:50 +01006784 When {lnum-end} is given, remove all text properties from line
6785 {lnum} to {lnum-end} (inclusive).
Bram Moolenaar98aefe72018-12-13 22:20:09 +01006786
6787 When {props} contains a "bufnr" item use this buffer,
6788 otherwise use the current buffer.
6789
6790 See |text-properties| for information about text properties.
6791
6792 *prop_find()*
6793prop_find({props} [, {direction}])
6794 NOT IMPLEMENTED YET
6795 Search for a text property as specified with {props}:
Bram Moolenaarc8c88492018-12-27 23:59:26 +01006796 id property with this ID
6797 type property with this type name
6798 bufnr buffer to search in; when present a
6799 start position with "lnum" and "col"
6800 must be given; when omitted the
6801 current buffer is used
Bram Moolenaar5b69c222019-01-11 14:50:06 +01006802 lnum start in this line (when omitted start
Bram Moolenaarc8c88492018-12-27 23:59:26 +01006803 at the cursor)
6804 col start at this column (when omitted
6805 and "lnum" is given: use column 1,
6806 otherwise start at the cursor)
6807 skipstart do not look for a match at the start
6808 position
Bram Moolenaar98aefe72018-12-13 22:20:09 +01006809
6810 {direction} can be "f" for forward and "b" for backward. When
6811 omitted forward search is performed.
6812
6813 If a match is found then a Dict is returned with the entries
6814 as with prop_list(), and additionally an "lnum" entry.
6815 If no match is found then an empty Dict is returned.
6816
6817 See |text-properties| for information about text properties.
6818
6819
Bram Moolenaar5b69c222019-01-11 14:50:06 +01006820prop_list({lnum} [, {props}]) *prop_list()*
Bram Moolenaar98aefe72018-12-13 22:20:09 +01006821 Return a List with all text properties in line {lnum}.
6822
6823 When {props} contains a "bufnr" item, use this buffer instead
6824 of the current buffer.
6825
6826 The properties are ordered by starting column and priority.
6827 Each property is a Dict with these entries:
Bram Moolenaarc8c88492018-12-27 23:59:26 +01006828 col starting column
Bram Moolenaar4c05fa02019-01-01 15:32:17 +01006829 length length in bytes, one more if line break is
6830 included
Bram Moolenaarc8c88492018-12-27 23:59:26 +01006831 id property ID
6832 type name of the property type, omitted if
6833 the type was deleted
6834 start when TRUE property starts in this line
6835 end when TRUE property ends in this line
Bram Moolenaar98aefe72018-12-13 22:20:09 +01006836
6837 When "start" is zero the property started in a previous line,
6838 the current one is a continuation.
6839 When "end" is zero the property continues in the next line.
6840 The line break after this line is included.
6841
6842 See |text-properties| for information about text properties.
6843
6844
6845 *prop_remove()* *E968*
Bram Moolenaarc8c88492018-12-27 23:59:26 +01006846prop_remove({props} [, {lnum} [, {lnum-end}]])
Bram Moolenaar98aefe72018-12-13 22:20:09 +01006847 Remove a matching text property from line {lnum}. When
Bram Moolenaarc8c88492018-12-27 23:59:26 +01006848 {lnum-end} is given, remove matching text properties from line
6849 {lnum} to {lnum-end} (inclusive).
Bram Moolenaar98aefe72018-12-13 22:20:09 +01006850 When {lnum} is omitted remove matching text properties from
6851 all lines.
6852
6853 {props} is a dictionary with these fields:
Bram Moolenaarc8c88492018-12-27 23:59:26 +01006854 id remove text properties with this ID
6855 type remove text properties with this type name
6856 bufnr use this buffer instead of the current one
6857 all when TRUE remove all matching text properties,
6858 not just the first one
Bram Moolenaar98aefe72018-12-13 22:20:09 +01006859 A property matches when either "id" or "type" matches.
6860
6861 Returns the number of properties that were removed.
6862
6863 See |text-properties| for information about text properties.
6864
6865
6866prop_type_add({name}, {props}) *prop_type_add()* *E969* *E970*
6867 Add a text property type {name}. If a property type with this
6868 name already exists an error is given.
6869 {props} is a dictionary with these optional fields:
Bram Moolenaarc8c88492018-12-27 23:59:26 +01006870 bufnr define the property only for this buffer; this
6871 avoids name collisions and automatically
6872 clears the property types when the buffer is
6873 deleted.
6874 highlight name of highlight group to use
6875 priority when a character has multiple text
6876 properties the one with the highest priority
6877 will be used; negative values can be used, the
6878 default priority is zero
6879 start_incl when TRUE inserts at the start position will
6880 be included in the text property
6881 end_incl when TRUE inserts at the end position will be
6882 included in the text property
Bram Moolenaar98aefe72018-12-13 22:20:09 +01006883
6884 See |text-properties| for information about text properties.
6885
6886
6887prop_type_change({name}, {props}) *prop_type_change()*
6888 Change properties of an existing text property type. If a
6889 property with this name does not exist an error is given.
6890 The {props} argument is just like |prop_type_add()|.
6891
6892 See |text-properties| for information about text properties.
6893
6894
6895prop_type_delete({name} [, {props}]) *prop_type_delete()*
6896 Remove the text property type {name}. When text properties
6897 using the type {name} are still in place, they will not have
6898 an effect and can no longer be removed by name.
6899
6900 {props} can contain a "bufnr" item. When it is given, delete
6901 a property type from this buffer instead of from the global
6902 property types.
6903
6904 When text property type {name} is not found there is no error.
6905
6906 See |text-properties| for information about text properties.
6907
6908
6909prop_type_get([{name} [, {props}]) *prop_type_get()*
6910 Returns the properties of property type {name}. This is a
6911 dictionary with the same fields as was given to
6912 prop_type_add().
6913 When the property type {name} does not exist, an empty
6914 dictionary is returned.
6915
6916 {props} can contain a "bufnr" item. When it is given, use
6917 this buffer instead of the global property types.
6918
6919 See |text-properties| for information about text properties.
6920
6921
6922prop_type_list([{props}]) *prop_type_list()*
6923 Returns a list with all property type names.
6924
6925 {props} can contain a "bufnr" item. When it is given, use
6926 this buffer instead of the global property types.
6927
6928 See |text-properties| for information about text properties.
Bram Moolenaar0e5979a2018-06-17 19:36:33 +02006929
Bram Moolenaarf2732452018-06-03 14:47:35 +02006930
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00006931pumvisible() *pumvisible()*
6932 Returns non-zero when the popup menu is visible, zero
6933 otherwise. See |ins-completion-menu|.
Bram Moolenaar87b5ca52006-03-04 21:55:31 +00006934 This can be used to avoid some things that would remove the
6935 popup menu.
Bram Moolenaar071d4272004-06-13 20:20:40 +00006936
Bram Moolenaar30b65812012-07-12 22:01:11 +02006937py3eval({expr}) *py3eval()*
6938 Evaluate Python expression {expr} and return its result
6939 converted to Vim data structures.
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01006940 Numbers and strings are returned as they are (strings are
6941 copied though, Unicode strings are additionally converted to
Bram Moolenaar30b65812012-07-12 22:01:11 +02006942 'encoding').
6943 Lists are represented as Vim |List| type.
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01006944 Dictionaries are represented as Vim |Dictionary| type with
Bram Moolenaar30b65812012-07-12 22:01:11 +02006945 keys converted to strings.
6946 {only available when compiled with the |+python3| feature}
6947
6948 *E858* *E859*
6949pyeval({expr}) *pyeval()*
6950 Evaluate Python expression {expr} and return its result
6951 converted to Vim data structures.
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01006952 Numbers and strings are returned as they are (strings are
Bram Moolenaar30b65812012-07-12 22:01:11 +02006953 copied though).
6954 Lists are represented as Vim |List| type.
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01006955 Dictionaries are represented as Vim |Dictionary| type,
Bram Moolenaard09acef2012-09-21 14:54:30 +02006956 non-string keys result in error.
Bram Moolenaar30b65812012-07-12 22:01:11 +02006957 {only available when compiled with the |+python| feature}
6958
Bram Moolenaarf42dd3c2017-01-28 16:06:38 +01006959pyxeval({expr}) *pyxeval()*
6960 Evaluate Python expression {expr} and return its result
6961 converted to Vim data structures.
6962 Uses Python 2 or 3, see |python_x| and 'pyxversion'.
6963 See also: |pyeval()|, |py3eval()|
6964 {only available when compiled with the |+python| or the
6965 |+python3| feature}
6966
Bram Moolenaar3a3a7232005-01-17 22:16:15 +00006967 *E726* *E727*
Bram Moolenaard8b02732005-01-14 21:48:43 +00006968range({expr} [, {max} [, {stride}]]) *range()*
Bram Moolenaar32466aa2006-02-24 23:53:04 +00006969 Returns a |List| with Numbers:
Bram Moolenaard8b02732005-01-14 21:48:43 +00006970 - If only {expr} is specified: [0, 1, ..., {expr} - 1]
6971 - If {max} is specified: [{expr}, {expr} + 1, ..., {max}]
6972 - If {stride} is specified: [{expr}, {expr} + {stride}, ...,
6973 {max}] (increasing {expr} with {stride} each time, not
6974 producing a value past {max}).
Bram Moolenaare7566042005-06-17 22:00:15 +00006975 When the maximum is one before the start the result is an
6976 empty list. When the maximum is more than one before the
6977 start this is an error.
Bram Moolenaard8b02732005-01-14 21:48:43 +00006978 Examples: >
Bram Moolenaarc9b4b052006-04-30 18:54:39 +00006979 range(4) " [0, 1, 2, 3]
Bram Moolenaard8b02732005-01-14 21:48:43 +00006980 range(2, 4) " [2, 3, 4]
6981 range(2, 9, 3) " [2, 5, 8]
Bram Moolenaarc9b4b052006-04-30 18:54:39 +00006982 range(2, -2, -1) " [2, 1, 0, -1, -2]
Bram Moolenaare7566042005-06-17 22:00:15 +00006983 range(0) " []
6984 range(2, 0) " error!
Bram Moolenaard8b02732005-01-14 21:48:43 +00006985<
Bram Moolenaar3a7c85b2005-02-05 21:39:53 +00006986 *readfile()*
Bram Moolenaar6e5ea8d2019-01-12 22:47:31 +01006987readfile({fname} [, {type} [, {max}]])
Bram Moolenaar32466aa2006-02-24 23:53:04 +00006988 Read file {fname} and return a |List|, each line of the file
Bram Moolenaar6100d022016-10-02 16:51:57 +02006989 as an item. Lines are broken at NL characters. Macintosh
6990 files separated with CR will result in a single long line
6991 (unless a NL appears somewhere).
Bram Moolenaar06583f12010-08-07 20:30:49 +02006992 All NUL characters are replaced with a NL character.
Bram Moolenaar6e5ea8d2019-01-12 22:47:31 +01006993 When {type} contains "b" binary mode is used:
Bram Moolenaar3a7c85b2005-02-05 21:39:53 +00006994 - When the last line ends in a NL an extra empty list item is
6995 added.
6996 - No CR characters are removed.
Bram Moolenaar6e5ea8d2019-01-12 22:47:31 +01006997 When {type} contains "B" a |Blob| is returned with the binary
6998 data of the file unmodified.
Bram Moolenaar3a7c85b2005-02-05 21:39:53 +00006999 Otherwise:
7000 - CR characters that appear before a NL are removed.
7001 - Whether the last line ends in a NL or not does not matter.
Bram Moolenaar06583f12010-08-07 20:30:49 +02007002 - When 'encoding' is Unicode any UTF-8 byte order mark is
7003 removed from the text.
Bram Moolenaar26a60b42005-02-22 08:49:11 +00007004 When {max} is given this specifies the maximum number of lines
7005 to be read. Useful if you only want to check the first ten
7006 lines of a file: >
7007 :for line in readfile(fname, '', 10)
7008 : if line =~ 'Date' | echo line | endif
7009 :endfor
Bram Moolenaar582fd852005-03-28 20:58:01 +00007010< When {max} is negative -{max} lines from the end of the file
7011 are returned, or as many as there are.
7012 When {max} is zero the result is an empty list.
Bram Moolenaar26a60b42005-02-22 08:49:11 +00007013 Note that without {max} the whole file is read into memory.
7014 Also note that there is no recognition of encoding. Read a
7015 file into a buffer if you need to.
Bram Moolenaar3a7c85b2005-02-05 21:39:53 +00007016 When the file can't be opened an error message is given and
7017 the result is an empty list.
7018 Also see |writefile()|.
7019
Bram Moolenaar0b6d9112018-05-22 20:35:17 +02007020reg_executing() *reg_executing()*
7021 Returns the single letter name of the register being executed.
7022 Returns an empty string when no register is being executed.
7023 See |@|.
7024
7025reg_recording() *reg_recording()*
7026 Returns the single letter name of the register being recorded.
7027 Returns an empty string string when not recording. See |q|.
7028
Bram Moolenaar433f7c82006-03-21 21:29:36 +00007029reltime([{start} [, {end}]]) *reltime()*
7030 Return an item that represents a time value. The format of
7031 the item depends on the system. It can be passed to
Bram Moolenaar03413f42016-04-12 21:07:15 +02007032 |reltimestr()| to convert it to a string or |reltimefloat()|
7033 to convert to a Float.
Bram Moolenaar433f7c82006-03-21 21:29:36 +00007034 Without an argument it returns the current time.
7035 With one argument is returns the time passed since the time
7036 specified in the argument.
Bram Moolenaar551dbcc2006-04-25 22:13:59 +00007037 With two arguments it returns the time passed between {start}
Bram Moolenaar433f7c82006-03-21 21:29:36 +00007038 and {end}.
7039 The {start} and {end} arguments must be values returned by
7040 reltime().
Bram Moolenaardb84e452010-08-15 13:50:43 +02007041 {only available when compiled with the |+reltime| feature}
Bram Moolenaar433f7c82006-03-21 21:29:36 +00007042
Bram Moolenaar03413f42016-04-12 21:07:15 +02007043reltimefloat({time}) *reltimefloat()*
7044 Return a Float that represents the time value of {time}.
7045 Example: >
7046 let start = reltime()
7047 call MyFunction()
7048 let seconds = reltimefloat(reltime(start))
7049< See the note of reltimestr() about overhead.
7050 Also see |profiling|.
7051 {only available when compiled with the |+reltime| feature}
7052
Bram Moolenaar433f7c82006-03-21 21:29:36 +00007053reltimestr({time}) *reltimestr()*
7054 Return a String that represents the time value of {time}.
7055 This is the number of seconds, a dot and the number of
7056 microseconds. Example: >
7057 let start = reltime()
7058 call MyFunction()
7059 echo reltimestr(reltime(start))
7060< Note that overhead for the commands will be added to the time.
7061 The accuracy depends on the system.
Bram Moolenaaref2f6562007-05-06 13:32:59 +00007062 Leading spaces are used to make the string align nicely. You
7063 can use split() to remove it. >
7064 echo split(reltimestr(reltime(start)))[0]
7065< Also see |profiling|.
Bram Moolenaardb84e452010-08-15 13:50:43 +02007066 {only available when compiled with the |+reltime| feature}
Bram Moolenaar433f7c82006-03-21 21:29:36 +00007067
Bram Moolenaar071d4272004-06-13 20:20:40 +00007068 *remote_expr()* *E449*
Bram Moolenaar81b9d0b2017-03-19 21:20:53 +01007069remote_expr({server}, {string} [, {idvar} [, {timeout}]])
Bram Moolenaar58b85342016-08-14 19:54:54 +02007070 Send the {string} to {server}. The string is sent as an
Bram Moolenaar071d4272004-06-13 20:20:40 +00007071 expression and the result is returned after evaluation.
Bram Moolenaar362e1a32006-03-06 23:29:24 +00007072 The result must be a String or a |List|. A |List| is turned
7073 into a String by joining the items with a line break in
7074 between (not at the end), like with join(expr, "\n").
Bram Moolenaar81b9d0b2017-03-19 21:20:53 +01007075 If {idvar} is present and not empty, it is taken as the name
7076 of a variable and a {serverid} for later use with
Bram Moolenaar6bb2cdf2018-02-24 19:53:53 +01007077 |remote_read()| is stored there.
Bram Moolenaar81b9d0b2017-03-19 21:20:53 +01007078 If {timeout} is given the read times out after this many
7079 seconds. Otherwise a timeout of 600 seconds is used.
Bram Moolenaar071d4272004-06-13 20:20:40 +00007080 See also |clientserver| |RemoteReply|.
7081 This function is not available in the |sandbox|.
7082 {only available when compiled with the |+clientserver| feature}
7083 Note: Any errors will cause a local error message to be issued
7084 and the result will be the empty string.
Bram Moolenaar01164a62017-11-02 22:58:42 +01007085
7086 Variables will be evaluated in the global namespace,
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01007087 independent of a function currently being active. Except
Bram Moolenaar01164a62017-11-02 22:58:42 +01007088 when in debug mode, then local function variables and
7089 arguments can be evaluated.
7090
Bram Moolenaar071d4272004-06-13 20:20:40 +00007091 Examples: >
7092 :echo remote_expr("gvim", "2+2")
7093 :echo remote_expr("gvim1", "b:current_syntax")
7094<
7095
7096remote_foreground({server}) *remote_foreground()*
7097 Move the Vim server with the name {server} to the foreground.
7098 This works like: >
7099 remote_expr({server}, "foreground()")
7100< Except that on Win32 systems the client does the work, to work
7101 around the problem that the OS doesn't always allow the server
7102 to bring itself to the foreground.
Bram Moolenaar9372a112005-12-06 19:59:18 +00007103 Note: This does not restore the window if it was minimized,
7104 like foreground() does.
Bram Moolenaar071d4272004-06-13 20:20:40 +00007105 This function is not available in the |sandbox|.
7106 {only in the Win32, Athena, Motif and GTK GUI versions and the
7107 Win32 console version}
7108
7109
7110remote_peek({serverid} [, {retvar}]) *remote_peek()*
7111 Returns a positive number if there are available strings
7112 from {serverid}. Copies any reply string into the variable
Bram Moolenaar58b85342016-08-14 19:54:54 +02007113 {retvar} if specified. {retvar} must be a string with the
Bram Moolenaar071d4272004-06-13 20:20:40 +00007114 name of a variable.
7115 Returns zero if none are available.
7116 Returns -1 if something is wrong.
7117 See also |clientserver|.
7118 This function is not available in the |sandbox|.
7119 {only available when compiled with the |+clientserver| feature}
7120 Examples: >
7121 :let repl = ""
7122 :echo "PEEK: ".remote_peek(id, "repl").": ".repl
7123
Bram Moolenaar81b9d0b2017-03-19 21:20:53 +01007124remote_read({serverid}, [{timeout}]) *remote_read()*
Bram Moolenaar071d4272004-06-13 20:20:40 +00007125 Return the oldest available reply from {serverid} and consume
Bram Moolenaar81b9d0b2017-03-19 21:20:53 +01007126 it. Unless a {timeout} in seconds is given, it blocks until a
7127 reply is available.
Bram Moolenaar071d4272004-06-13 20:20:40 +00007128 See also |clientserver|.
7129 This function is not available in the |sandbox|.
7130 {only available when compiled with the |+clientserver| feature}
7131 Example: >
7132 :echo remote_read(id)
7133<
7134 *remote_send()* *E241*
7135remote_send({server}, {string} [, {idvar}])
Bram Moolenaar58b85342016-08-14 19:54:54 +02007136 Send the {string} to {server}. The string is sent as input
Bram Moolenaard4755bb2004-09-02 19:12:26 +00007137 keys and the function returns immediately. At the Vim server
7138 the keys are not mapped |:map|.
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00007139 If {idvar} is present, it is taken as the name of a variable
7140 and a {serverid} for later use with remote_read() is stored
7141 there.
Bram Moolenaar071d4272004-06-13 20:20:40 +00007142 See also |clientserver| |RemoteReply|.
7143 This function is not available in the |sandbox|.
7144 {only available when compiled with the |+clientserver| feature}
Bram Moolenaar7416f3e2017-03-18 18:10:13 +01007145
Bram Moolenaar071d4272004-06-13 20:20:40 +00007146 Note: Any errors will be reported in the server and may mess
7147 up the display.
7148 Examples: >
7149 :echo remote_send("gvim", ":DropAndReply ".file, "serverid").
7150 \ remote_read(serverid)
7151
7152 :autocmd NONE RemoteReply *
7153 \ echo remote_read(expand("<amatch>"))
7154 :echo remote_send("gvim", ":sleep 10 | echo ".
7155 \ 'server2client(expand("<client>"), "HELLO")<CR>')
Bram Moolenaara14de3d2005-01-07 21:48:26 +00007156<
Bram Moolenaar7416f3e2017-03-18 18:10:13 +01007157 *remote_startserver()* *E941* *E942*
7158remote_startserver({name})
7159 Become the server {name}. This fails if already running as a
7160 server, when |v:servername| is not empty.
7161 {only available when compiled with the |+clientserver| feature}
7162
Bram Moolenaarde8866b2005-01-06 23:24:37 +00007163remove({list}, {idx} [, {end}]) *remove()*
Bram Moolenaar32466aa2006-02-24 23:53:04 +00007164 Without {end}: Remove the item at {idx} from |List| {list} and
Bram Moolenaar8f3f58f2010-01-06 20:52:26 +01007165 return the item.
Bram Moolenaarde8866b2005-01-06 23:24:37 +00007166 With {end}: Remove items from {idx} to {end} (inclusive) and
Bram Moolenaar8f3f58f2010-01-06 20:52:26 +01007167 return a List with these items. When {idx} points to the same
Bram Moolenaarde8866b2005-01-06 23:24:37 +00007168 item as {end} a list with one item is returned. When {end}
7169 points to an item before {idx} this is an error.
7170 See |list-index| for possible values of {idx} and {end}.
Bram Moolenaard7ee7ce2005-01-03 21:02:03 +00007171 Example: >
7172 :echo "last item: " . remove(mylist, -1)
Bram Moolenaarde8866b2005-01-06 23:24:37 +00007173 :call remove(mylist, 0, 9)
Bram Moolenaar6e5ea8d2019-01-12 22:47:31 +01007174remove({blob}, {idx} [, {end}])
7175 Without {end}: Remove the byte at {idx} from |Blob| {blob} and
7176 return the byte.
7177 With {end}: Remove bytes from {idx} to {end} (inclusive) and
7178 return a |Blob| with these bytes. When {idx} points to the same
7179 byte as {end} a |Blob| with one byte is returned. When {end}
7180 points to a byte before {idx} this is an error.
7181 Example: >
7182 :echo "last byte: " . remove(myblob, -1)
7183 :call remove(mylist, 0, 9)
Bram Moolenaard8b02732005-01-14 21:48:43 +00007184remove({dict}, {key})
7185 Remove the entry from {dict} with key {key}. Example: >
7186 :echo "removed " . remove(dict, "one")
7187< If there is no {key} in {dict} this is an error.
7188
7189 Use |delete()| to remove a file.
Bram Moolenaard7ee7ce2005-01-03 21:02:03 +00007190
Bram Moolenaar071d4272004-06-13 20:20:40 +00007191rename({from}, {to}) *rename()*
7192 Rename the file by the name {from} to the name {to}. This
7193 should also work to move files across file systems. The
7194 result is a Number, which is 0 if the file was renamed
7195 successfully, and non-zero when the renaming failed.
Bram Moolenaar798b30b2009-04-22 10:56:16 +00007196 NOTE: If {to} exists it is overwritten without warning.
Bram Moolenaar071d4272004-06-13 20:20:40 +00007197 This function is not available in the |sandbox|.
7198
Bram Moolenaarab79bcb2004-07-18 21:34:53 +00007199repeat({expr}, {count}) *repeat()*
7200 Repeat {expr} {count} times and return the concatenated
7201 result. Example: >
Bram Moolenaar551dbcc2006-04-25 22:13:59 +00007202 :let separator = repeat('-', 80)
Bram Moolenaarab79bcb2004-07-18 21:34:53 +00007203< When {count} is zero or negative the result is empty.
Bram Moolenaar32466aa2006-02-24 23:53:04 +00007204 When {expr} is a |List| the result is {expr} concatenated
Bram Moolenaar58b85342016-08-14 19:54:54 +02007205 {count} times. Example: >
Bram Moolenaarde8866b2005-01-06 23:24:37 +00007206 :let longlist = repeat(['a', 'b'], 3)
7207< Results in ['a', 'b', 'a', 'b', 'a', 'b'].
Bram Moolenaarab79bcb2004-07-18 21:34:53 +00007208
Bram Moolenaara14de3d2005-01-07 21:48:26 +00007209
Bram Moolenaar071d4272004-06-13 20:20:40 +00007210resolve({filename}) *resolve()* *E655*
7211 On MS-Windows, when {filename} is a shortcut (a .lnk file),
7212 returns the path the shortcut points to in a simplified form.
7213 On Unix, repeat resolving symbolic links in all path
7214 components of {filename} and return the simplified result.
7215 To cope with link cycles, resolving of symbolic links is
7216 stopped after 100 iterations.
7217 On other systems, return the simplified {filename}.
7218 The simplification step is done as by |simplify()|.
7219 resolve() keeps a leading path component specifying the
7220 current directory (provided the result is still a relative
7221 path name) and also keeps a trailing path separator.
7222
Bram Moolenaara14de3d2005-01-07 21:48:26 +00007223 *reverse()*
Bram Moolenaar6e5ea8d2019-01-12 22:47:31 +01007224reverse({object})
7225 Reverse the order of items in {object} in-place.
7226 {object} can be a |List| or a |Blob|.
7227 Returns {object}.
7228 If you want an object to remain unmodified make a copy first: >
Bram Moolenaara14de3d2005-01-07 21:48:26 +00007229 :let revlist = reverse(copy(mylist))
7230
Bram Moolenaar446cb832008-06-24 21:56:24 +00007231round({expr}) *round()*
Bram Moolenaarc236c162008-07-13 17:41:49 +00007232 Round off {expr} to the nearest integral value and return it
Bram Moolenaar446cb832008-06-24 21:56:24 +00007233 as a |Float|. If {expr} lies halfway between two integral
7234 values, then use the larger one (away from zero).
7235 {expr} must evaluate to a |Float| or a |Number|.
7236 Examples: >
7237 echo round(0.456)
7238< 0.0 >
7239 echo round(4.5)
7240< 5.0 >
7241 echo round(-4.5)
7242< -5.0
7243 {only available when compiled with the |+float| feature}
Bram Moolenaar34feacb2012-12-05 19:01:43 +01007244
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01007245screenattr({row}, {col}) *screenattr()*
Bram Moolenaar36f44c22016-08-28 18:17:20 +02007246 Like |screenchar()|, but return the attribute. This is a rather
Bram Moolenaar9a773482013-06-11 18:40:13 +02007247 arbitrary number that can only be used to compare to the
7248 attribute at other positions.
7249
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01007250screenchar({row}, {col}) *screenchar()*
Bram Moolenaar9a773482013-06-11 18:40:13 +02007251 The result is a Number, which is the character at position
7252 [row, col] on the screen. This works for every possible
7253 screen position, also status lines, window separators and the
7254 command line. The top left position is row one, column one
7255 The character excludes composing characters. For double-byte
7256 encodings it may only be the first byte.
7257 This is mainly to be used for testing.
7258 Returns -1 when row or col is out of range.
7259
Bram Moolenaar34feacb2012-12-05 19:01:43 +01007260screencol() *screencol()*
7261 The result is a Number, which is the current screen column of
7262 the cursor. The leftmost column has number 1.
7263 This function is mainly used for testing.
7264
7265 Note: Always returns the current screen column, thus if used
7266 in a command (e.g. ":echo screencol()") it will return the
7267 column inside the command line, which is 1 when the command is
7268 executed. To get the cursor position in the file use one of
7269 the following mappings: >
7270 nnoremap <expr> GG ":echom ".screencol()."\n"
7271 nnoremap <silent> GG :echom screencol()<CR>
7272<
7273screenrow() *screenrow()*
7274 The result is a Number, which is the current screen row of the
7275 cursor. The top line has number one.
7276 This function is mainly used for testing.
Bram Moolenaar437bafe2016-08-01 15:40:54 +02007277 Alternatively you can use |winline()|.
Bram Moolenaar34feacb2012-12-05 19:01:43 +01007278
7279 Note: Same restrictions as with |screencol()|.
7280
Bram Moolenaar76929292008-01-06 19:07:36 +00007281search({pattern} [, {flags} [, {stopline} [, {timeout}]]]) *search()*
Bram Moolenaar071d4272004-06-13 20:20:40 +00007282 Search for regexp pattern {pattern}. The search starts at the
Bram Moolenaar383f9bc2005-01-19 22:18:32 +00007283 cursor position (you can use |cursor()| to set it).
Bram Moolenaar65c923a2006-03-03 22:56:30 +00007284
Bram Moolenaar2df58b42012-11-28 18:21:11 +01007285 When a match has been found its line number is returned.
Bram Moolenaarb8ff1fb2012-02-04 21:59:01 +01007286 If there is no match a 0 is returned and the cursor doesn't
7287 move. No error message is given.
Bram Moolenaarb8ff1fb2012-02-04 21:59:01 +01007288
Bram Moolenaar071d4272004-06-13 20:20:40 +00007289 {flags} is a String, which can contain these character flags:
Bram Moolenaarad4d8a12015-12-28 19:20:36 +01007290 'b' search Backward instead of forward
7291 'c' accept a match at the Cursor position
Bram Moolenaar87b5ca52006-03-04 21:55:31 +00007292 'e' move to the End of the match
Bram Moolenaar5eb86f92004-07-26 12:53:41 +00007293 'n' do Not move the cursor
Bram Moolenaarad4d8a12015-12-28 19:20:36 +01007294 'p' return number of matching sub-Pattern (see below)
7295 's' Set the ' mark at the previous location of the cursor
7296 'w' Wrap around the end of the file
7297 'W' don't Wrap around the end of the file
7298 'z' start searching at the cursor column instead of zero
Bram Moolenaar071d4272004-06-13 20:20:40 +00007299 If neither 'w' or 'W' is given, the 'wrapscan' option applies.
7300
Bram Moolenaar02743632005-07-25 20:42:36 +00007301 If the 's' flag is supplied, the ' mark is set, only if the
7302 cursor is moved. The 's' flag cannot be combined with the 'n'
7303 flag.
7304
Bram Moolenaaref2f6562007-05-06 13:32:59 +00007305 'ignorecase', 'smartcase' and 'magic' are used.
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01007306
Bram Moolenaar85084ef2016-01-17 22:26:33 +01007307 When the 'z' flag is not given, searching always starts in
Bram Moolenaarad4d8a12015-12-28 19:20:36 +01007308 column zero and then matches before the cursor are skipped.
7309 When the 'c' flag is present in 'cpo' the next search starts
7310 after the match. Without the 'c' flag the next search starts
7311 one column further.
Bram Moolenaaref2f6562007-05-06 13:32:59 +00007312
Bram Moolenaara23ccb82006-02-27 00:08:02 +00007313 When the {stopline} argument is given then the search stops
7314 after searching this line. This is useful to restrict the
7315 search to a range of lines. Examples: >
7316 let match = search('(', 'b', line("w0"))
7317 let end = search('END', '', line("w$"))
7318< When {stopline} is used and it is not zero this also implies
7319 that the search does not wrap around the end of the file.
Bram Moolenaar76929292008-01-06 19:07:36 +00007320 A zero value is equal to not giving the argument.
7321
7322 When the {timeout} argument is given the search stops when
Bram Moolenaar58b85342016-08-14 19:54:54 +02007323 more than this many milliseconds have passed. Thus when
Bram Moolenaar76929292008-01-06 19:07:36 +00007324 {timeout} is 500 the search stops after half a second.
7325 The value must not be negative. A zero value is like not
7326 giving the argument.
Bram Moolenaardb84e452010-08-15 13:50:43 +02007327 {only available when compiled with the |+reltime| feature}
Bram Moolenaara23ccb82006-02-27 00:08:02 +00007328
Bram Moolenaar362e1a32006-03-06 23:29:24 +00007329 *search()-sub-match*
7330 With the 'p' flag the returned value is one more than the
7331 first sub-match in \(\). One if none of them matched but the
7332 whole pattern did match.
Bram Moolenaara23ccb82006-02-27 00:08:02 +00007333 To get the column number too use |searchpos()|.
Bram Moolenaar071d4272004-06-13 20:20:40 +00007334
Bram Moolenaar87b5ca52006-03-04 21:55:31 +00007335 The cursor will be positioned at the match, unless the 'n'
7336 flag is used.
7337
Bram Moolenaar071d4272004-06-13 20:20:40 +00007338 Example (goes over all files in the argument list): >
7339 :let n = 1
7340 :while n <= argc() " loop over all files in arglist
7341 : exe "argument " . n
7342 : " start at the last char in the file and wrap for the
7343 : " first search to find match at start of file
7344 : normal G$
7345 : let flags = "w"
7346 : while search("foo", flags) > 0
Bram Moolenaar446cb832008-06-24 21:56:24 +00007347 : s/foo/bar/g
Bram Moolenaar071d4272004-06-13 20:20:40 +00007348 : let flags = "W"
7349 : endwhile
7350 : update " write the file if modified
7351 : let n = n + 1
7352 :endwhile
7353<
Bram Moolenaar87b5ca52006-03-04 21:55:31 +00007354 Example for using some flags: >
7355 :echo search('\<if\|\(else\)\|\(endif\)', 'ncpe')
7356< This will search for the keywords "if", "else", and "endif"
7357 under or after the cursor. Because of the 'p' flag, it
7358 returns 1, 2, or 3 depending on which keyword is found, or 0
7359 if the search fails. With the cursor on the first word of the
7360 line:
7361 if (foo == 0) | let foo = foo + 1 | endif ~
7362 the function returns 1. Without the 'c' flag, the function
7363 finds the "endif" and returns 3. The same thing happens
7364 without the 'e' flag if the cursor is on the "f" of "if".
7365 The 'n' flag tells the function not to move the cursor.
7366
Bram Moolenaar92d640f2005-09-05 22:11:52 +00007367
Bram Moolenaarf75a9632005-09-13 21:20:47 +00007368searchdecl({name} [, {global} [, {thisblock}]]) *searchdecl()*
7369 Search for the declaration of {name}.
Bram Moolenaarc9b4b052006-04-30 18:54:39 +00007370
Bram Moolenaarf75a9632005-09-13 21:20:47 +00007371 With a non-zero {global} argument it works like |gD|, find
7372 first match in the file. Otherwise it works like |gd|, find
7373 first match in the function.
7374
7375 With a non-zero {thisblock} argument matches in a {} block
7376 that ends before the cursor position are ignored. Avoids
7377 finding variable declarations only valid in another scope.
7378
Bram Moolenaar92d640f2005-09-05 22:11:52 +00007379 Moves the cursor to the found match.
7380 Returns zero for success, non-zero for failure.
7381 Example: >
7382 if searchdecl('myvar') == 0
7383 echo getline('.')
7384 endif
7385<
Bram Moolenaar071d4272004-06-13 20:20:40 +00007386 *searchpair()*
Bram Moolenaar76929292008-01-06 19:07:36 +00007387searchpair({start}, {middle}, {end} [, {flags} [, {skip}
7388 [, {stopline} [, {timeout}]]]])
Bram Moolenaar071d4272004-06-13 20:20:40 +00007389 Search for the match of a nested start-end pair. This can be
7390 used to find the "endif" that matches an "if", while other
7391 if/endif pairs in between are ignored.
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00007392 The search starts at the cursor. The default is to search
7393 forward, include 'b' in {flags} to search backward.
7394 If a match is found, the cursor is positioned at it and the
7395 line number is returned. If no match is found 0 or -1 is
7396 returned and the cursor doesn't move. No error message is
7397 given.
Bram Moolenaar071d4272004-06-13 20:20:40 +00007398
7399 {start}, {middle} and {end} are patterns, see |pattern|. They
7400 must not contain \( \) pairs. Use of \%( \) is allowed. When
7401 {middle} is not empty, it is found when searching from either
7402 direction, but only when not in a nested start-end pair. A
7403 typical use is: >
7404 searchpair('\<if\>', '\<else\>', '\<endif\>')
7405< By leaving {middle} empty the "else" is skipped.
7406
Bram Moolenaar87b5ca52006-03-04 21:55:31 +00007407 {flags} 'b', 'c', 'n', 's', 'w' and 'W' are used like with
7408 |search()|. Additionally:
Bram Moolenaar071d4272004-06-13 20:20:40 +00007409 'r' Repeat until no more matches found; will find the
Bram Moolenaar446cb832008-06-24 21:56:24 +00007410 outer pair. Implies the 'W' flag.
7411 'm' Return number of matches instead of line number with
Bram Moolenaar87b5ca52006-03-04 21:55:31 +00007412 the match; will be > 1 when 'r' is used.
Bram Moolenaar446cb832008-06-24 21:56:24 +00007413 Note: it's nearly always a good idea to use the 'W' flag, to
7414 avoid wrapping around the end of the file.
Bram Moolenaar071d4272004-06-13 20:20:40 +00007415
7416 When a match for {start}, {middle} or {end} is found, the
7417 {skip} expression is evaluated with the cursor positioned on
7418 the start of the match. It should return non-zero if this
7419 match is to be skipped. E.g., because it is inside a comment
7420 or a string.
7421 When {skip} is omitted or empty, every match is accepted.
7422 When evaluating {skip} causes an error the search is aborted
7423 and -1 returned.
Bram Moolenaar48570482017-10-30 21:48:41 +01007424 {skip} can be a string, a lambda, a funcref or a partial.
Bram Moolenaar675e8d62018-06-24 20:42:01 +02007425 Anything else makes the function fail.
Bram Moolenaar071d4272004-06-13 20:20:40 +00007426
Bram Moolenaar76929292008-01-06 19:07:36 +00007427 For {stopline} and {timeout} see |search()|.
Bram Moolenaara23ccb82006-02-27 00:08:02 +00007428
Bram Moolenaar071d4272004-06-13 20:20:40 +00007429 The value of 'ignorecase' is used. 'magic' is ignored, the
7430 patterns are used like it's on.
7431
7432 The search starts exactly at the cursor. A match with
7433 {start}, {middle} or {end} at the next character, in the
7434 direction of searching, is the first one found. Example: >
7435 if 1
7436 if 2
7437 endif 2
7438 endif 1
7439< When starting at the "if 2", with the cursor on the "i", and
7440 searching forwards, the "endif 2" is found. When starting on
7441 the character just before the "if 2", the "endif 1" will be
Bram Moolenaar58b85342016-08-14 19:54:54 +02007442 found. That's because the "if 2" will be found first, and
Bram Moolenaar071d4272004-06-13 20:20:40 +00007443 then this is considered to be a nested if/endif from "if 2" to
7444 "endif 2".
7445 When searching backwards and {end} is more than one character,
7446 it may be useful to put "\zs" at the end of the pattern, so
7447 that when the cursor is inside a match with the end it finds
7448 the matching start.
7449
7450 Example, to find the "endif" command in a Vim script: >
7451
7452 :echo searchpair('\<if\>', '\<el\%[seif]\>', '\<en\%[dif]\>', 'W',
7453 \ 'getline(".") =~ "^\\s*\""')
7454
7455< The cursor must be at or after the "if" for which a match is
7456 to be found. Note that single-quote strings are used to avoid
7457 having to double the backslashes. The skip expression only
7458 catches comments at the start of a line, not after a command.
7459 Also, a word "en" or "if" halfway a line is considered a
7460 match.
7461 Another example, to search for the matching "{" of a "}": >
7462
7463 :echo searchpair('{', '', '}', 'bW')
7464
7465< This works when the cursor is at or before the "}" for which a
7466 match is to be found. To reject matches that syntax
7467 highlighting recognized as strings: >
7468
7469 :echo searchpair('{', '', '}', 'bW',
7470 \ 'synIDattr(synID(line("."), col("."), 0), "name") =~? "string"')
7471<
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00007472 *searchpairpos()*
Bram Moolenaar76929292008-01-06 19:07:36 +00007473searchpairpos({start}, {middle}, {end} [, {flags} [, {skip}
7474 [, {stopline} [, {timeout}]]]])
Bram Moolenaar8f3f58f2010-01-06 20:52:26 +01007475 Same as |searchpair()|, but returns a |List| with the line and
Bram Moolenaar32466aa2006-02-24 23:53:04 +00007476 column position of the match. The first element of the |List|
7477 is the line number and the second element is the byte index of
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00007478 the column position of the match. If no match is found,
Bram Moolenaar9855d6b2010-07-18 14:34:51 +02007479 returns [0, 0]. >
7480
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00007481 :let [lnum,col] = searchpairpos('{', '', '}', 'n')
7482<
7483 See |match-parens| for a bigger and more useful example.
7484
Bram Moolenaar76929292008-01-06 19:07:36 +00007485searchpos({pattern} [, {flags} [, {stopline} [, {timeout}]]]) *searchpos()*
Bram Moolenaara23ccb82006-02-27 00:08:02 +00007486 Same as |search()|, but returns a |List| with the line and
Bram Moolenaar32466aa2006-02-24 23:53:04 +00007487 column position of the match. The first element of the |List|
7488 is the line number and the second element is the byte index of
7489 the column position of the match. If no match is found,
7490 returns [0, 0].
Bram Moolenaar362e1a32006-03-06 23:29:24 +00007491 Example: >
7492 :let [lnum, col] = searchpos('mypattern', 'n')
7493
7494< When the 'p' flag is given then there is an extra item with
7495 the sub-pattern match number |search()-sub-match|. Example: >
7496 :let [lnum, col, submatch] = searchpos('\(\l\)\|\(\u\)', 'np')
7497< In this example "submatch" is 2 when a lowercase letter is
7498 found |/\l|, 3 when an uppercase letter is found |/\u|.
7499
Bram Moolenaar81edd172016-04-14 13:51:37 +02007500server2client({clientid}, {string}) *server2client()*
Bram Moolenaar071d4272004-06-13 20:20:40 +00007501 Send a reply string to {clientid}. The most recent {clientid}
7502 that sent a string can be retrieved with expand("<client>").
7503 {only available when compiled with the |+clientserver| feature}
7504 Note:
7505 This id has to be stored before the next command can be
Bram Moolenaar402d2fe2005-04-15 21:00:38 +00007506 received. I.e. before returning from the received command and
Bram Moolenaar071d4272004-06-13 20:20:40 +00007507 before calling any commands that waits for input.
7508 See also |clientserver|.
7509 Example: >
7510 :echo server2client(expand("<client>"), "HELLO")
7511<
7512serverlist() *serverlist()*
7513 Return a list of available server names, one per line.
7514 When there are no servers or the information is not available
7515 an empty string is returned. See also |clientserver|.
7516 {only available when compiled with the |+clientserver| feature}
7517 Example: >
7518 :echo serverlist()
7519<
Bram Moolenaarb31cf2b2017-09-02 19:45:19 +02007520setbufline({expr}, {lnum}, {text}) *setbufline()*
7521 Set line {lnum} to {text} in buffer {expr}. To insert
Bram Moolenaarb328cca2019-01-06 16:24:01 +01007522 lines use |append()|. Any text properties in {lnum} are
7523 cleared.
Bram Moolenaarb31cf2b2017-09-02 19:45:19 +02007524
7525 For the use of {expr}, see |bufname()| above.
7526
7527 {lnum} is used like with |setline()|.
7528 This works like |setline()| for the specified buffer.
7529 On success 0 is returned, on failure 1 is returned.
7530
7531 If {expr} is not a valid buffer or {lnum} is not valid, an
7532 error message is given.
7533
Bram Moolenaar071d4272004-06-13 20:20:40 +00007534setbufvar({expr}, {varname}, {val}) *setbufvar()*
7535 Set option or local variable {varname} in buffer {expr} to
7536 {val}.
7537 This also works for a global or local window option, but it
7538 doesn't work for a global or local window variable.
7539 For a local window option the global value is unchanged.
7540 For the use of {expr}, see |bufname()| above.
7541 Note that the variable name without "b:" must be used.
7542 Examples: >
7543 :call setbufvar(1, "&mod", 1)
7544 :call setbufvar("todo", "myvar", "foobar")
7545< This function is not available in the |sandbox|.
7546
Bram Moolenaar12969c02015-09-08 23:36:10 +02007547setcharsearch({dict}) *setcharsearch()*
Bram Moolenaardbd24b52015-08-11 14:26:19 +02007548 Set the current character search information to {dict},
7549 which contains one or more of the following entries:
7550
7551 char character which will be used for a subsequent
7552 |,| or |;| command; an empty string clears the
7553 character search
7554 forward direction of character search; 1 for forward,
7555 0 for backward
7556 until type of character search; 1 for a |t| or |T|
7557 character search, 0 for an |f| or |F|
7558 character search
7559
7560 This can be useful to save/restore a user's character search
7561 from a script: >
7562 :let prevsearch = getcharsearch()
7563 :" Perform a command which clobbers user's search
7564 :call setcharsearch(prevsearch)
7565< Also see |getcharsearch()|.
7566
Bram Moolenaar071d4272004-06-13 20:20:40 +00007567setcmdpos({pos}) *setcmdpos()*
7568 Set the cursor position in the command line to byte position
Bram Moolenaar58b85342016-08-14 19:54:54 +02007569 {pos}. The first position is 1.
Bram Moolenaar071d4272004-06-13 20:20:40 +00007570 Use |getcmdpos()| to obtain the current position.
7571 Only works while editing the command line, thus you must use
Bram Moolenaard8b02732005-01-14 21:48:43 +00007572 |c_CTRL-\_e|, |c_CTRL-R_=| or |c_CTRL-R_CTRL-R| with '='. For
7573 |c_CTRL-\_e| and |c_CTRL-R_CTRL-R| with '=' the position is
7574 set after the command line is set to the expression. For
7575 |c_CTRL-R_=| it is set after evaluating the expression but
7576 before inserting the resulting text.
Bram Moolenaar071d4272004-06-13 20:20:40 +00007577 When the number is too big the cursor is put at the end of the
7578 line. A number smaller than one has undefined results.
7579 Returns 0 when successful, 1 when not editing the command
7580 line.
7581
Bram Moolenaar80492532016-03-08 17:08:53 +01007582setfperm({fname}, {mode}) *setfperm()* *chmod*
7583 Set the file permissions for {fname} to {mode}.
7584 {mode} must be a string with 9 characters. It is of the form
7585 "rwxrwxrwx", where each group of "rwx" flags represent, in
7586 turn, the permissions of the owner of the file, the group the
7587 file belongs to, and other users. A '-' character means the
7588 permission is off, any other character means on. Multi-byte
7589 characters are not supported.
7590
7591 For example "rw-r-----" means read-write for the user,
7592 readable by the group, not accessible by others. "xx-x-----"
7593 would do the same thing.
7594
7595 Returns non-zero for success, zero for failure.
7596
7597 To read permissions see |getfperm()|.
7598
7599
Bram Moolenaar446cb832008-06-24 21:56:24 +00007600setline({lnum}, {text}) *setline()*
Bram Moolenaarb8ff1fb2012-02-04 21:59:01 +01007601 Set line {lnum} of the current buffer to {text}. To insert
Bram Moolenaarb31cf2b2017-09-02 19:45:19 +02007602 lines use |append()|. To set lines in another buffer use
Bram Moolenaarb328cca2019-01-06 16:24:01 +01007603 |setbufline()|. Any text properties in {lnum} are cleared.
Bram Moolenaarb31cf2b2017-09-02 19:45:19 +02007604
Bram Moolenaar402d2fe2005-04-15 21:00:38 +00007605 {lnum} is used like with |getline()|.
Bram Moolenaar446cb832008-06-24 21:56:24 +00007606 When {lnum} is just below the last line the {text} will be
Bram Moolenaar2389c3c2005-05-22 22:07:59 +00007607 added as a new line.
Bram Moolenaarb31cf2b2017-09-02 19:45:19 +02007608
Bram Moolenaar402d2fe2005-04-15 21:00:38 +00007609 If this succeeds, 0 is returned. If this fails (most likely
Bram Moolenaarb31cf2b2017-09-02 19:45:19 +02007610 because {lnum} is invalid) 1 is returned.
7611
7612 Example: >
Bram Moolenaar071d4272004-06-13 20:20:40 +00007613 :call setline(5, strftime("%c"))
Bram Moolenaarb31cf2b2017-09-02 19:45:19 +02007614
Bram Moolenaar446cb832008-06-24 21:56:24 +00007615< When {text} is a |List| then line {lnum} and following lines
Bram Moolenaar2389c3c2005-05-22 22:07:59 +00007616 will be set to the items in the list. Example: >
7617 :call setline(5, ['aaa', 'bbb', 'ccc'])
7618< This is equivalent to: >
Bram Moolenaar53bfca22012-04-13 23:04:47 +02007619 :for [n, l] in [[5, 'aaa'], [6, 'bbb'], [7, 'ccc']]
Bram Moolenaar2389c3c2005-05-22 22:07:59 +00007620 : call setline(n, l)
7621 :endfor
Bram Moolenaarb4d5fba2017-09-11 19:31:28 +02007622
Bram Moolenaar071d4272004-06-13 20:20:40 +00007623< Note: The '[ and '] marks are not set.
7624
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01007625setloclist({nr}, {list} [, {action} [, {what}]]) *setloclist()*
Bram Moolenaar17c7c012006-01-26 22:25:15 +00007626 Create or replace or add to the location list for window {nr}.
Bram Moolenaar7571d552016-08-18 22:54:46 +02007627 {nr} can be the window number or the |window-ID|.
Bram Moolenaar888ccac2016-06-04 18:49:36 +02007628 When {nr} is zero the current window is used.
7629
7630 For a location list window, the displayed location list is
7631 modified. For an invalid window number {nr}, -1 is returned.
Bram Moolenaar6ee10162007-07-26 20:58:42 +00007632 Otherwise, same as |setqflist()|.
7633 Also see |location-list|.
7634
Bram Moolenaard823fa92016-08-12 16:29:27 +02007635 If the optional {what} dictionary argument is supplied, then
7636 only the items listed in {what} are set. Refer to |setqflist()|
7637 for the list of supported keys in {what}.
7638
Bram Moolenaar6ee10162007-07-26 20:58:42 +00007639setmatches({list}) *setmatches()*
7640 Restores a list of matches saved by |getmatches()|. Returns 0
Bram Moolenaar446cb832008-06-24 21:56:24 +00007641 if successful, otherwise -1. All current matches are cleared
Bram Moolenaar6ee10162007-07-26 20:58:42 +00007642 before the list is restored. See example for |getmatches()|.
Bram Moolenaar68b76a62005-03-25 21:53:48 +00007643
Bram Moolenaar65c923a2006-03-03 22:56:30 +00007644 *setpos()*
7645setpos({expr}, {list})
7646 Set the position for {expr}. Possible values:
7647 . the cursor
7648 'x mark x
7649
Bram Moolenaar493c1782014-05-28 14:34:46 +02007650 {list} must be a |List| with four or five numbers:
Bram Moolenaar65c923a2006-03-03 22:56:30 +00007651 [bufnum, lnum, col, off]
Bram Moolenaar493c1782014-05-28 14:34:46 +02007652 [bufnum, lnum, col, off, curswant]
Bram Moolenaar65c923a2006-03-03 22:56:30 +00007653
Bram Moolenaar58b85342016-08-14 19:54:54 +02007654 "bufnum" is the buffer number. Zero can be used for the
Bram Moolenaarf13e00b2017-01-28 18:23:54 +01007655 current buffer. When setting an uppercase mark "bufnum" is
7656 used for the mark position. For other marks it specifies the
7657 buffer to set the mark in. You can use the |bufnr()| function
7658 to turn a file name into a buffer number.
7659 For setting the cursor and the ' mark "bufnum" is ignored,
7660 since these are associated with a window, not a buffer.
Bram Moolenaardb552d602006-03-23 22:59:57 +00007661 Does not change the jumplist.
Bram Moolenaar65c923a2006-03-03 22:56:30 +00007662
7663 "lnum" and "col" are the position in the buffer. The first
Bram Moolenaar8f3f58f2010-01-06 20:52:26 +01007664 column is 1. Use a zero "lnum" to delete a mark. If "col" is
7665 smaller than 1 then 1 is used.
Bram Moolenaar65c923a2006-03-03 22:56:30 +00007666
7667 The "off" number is only used when 'virtualedit' is set. Then
7668 it is the offset in screen columns from the start of the
Bram Moolenaard46bbc72007-05-12 14:38:41 +00007669 character. E.g., a position within a <Tab> or after the last
Bram Moolenaar65c923a2006-03-03 22:56:30 +00007670 character.
7671
Bram Moolenaar493c1782014-05-28 14:34:46 +02007672 The "curswant" number is only used when setting the cursor
7673 position. It sets the preferred column for when moving the
7674 cursor vertically. When the "curswant" number is missing the
7675 preferred column is not set. When it is present and setting a
7676 mark position it is not used.
7677
Bram Moolenaardfb18412013-12-11 18:53:29 +01007678 Note that for '< and '> changing the line number may result in
7679 the marks to be effectively be swapped, so that '< is always
7680 before '>.
7681
Bram Moolenaar08250432008-02-13 11:42:46 +00007682 Returns 0 when the position could be set, -1 otherwise.
7683 An error message is given if {expr} is invalid.
7684
Bram Moolenaar6f6c0f82014-05-28 20:31:42 +02007685 Also see |getpos()| and |getcurpos()|.
Bram Moolenaar65c923a2006-03-03 22:56:30 +00007686
Bram Moolenaaref2f6562007-05-06 13:32:59 +00007687 This does not restore the preferred column for moving
Bram Moolenaar493c1782014-05-28 14:34:46 +02007688 vertically; if you set the cursor position with this, |j| and
7689 |k| motions will jump to previous columns! Use |cursor()| to
7690 also set the preferred column. Also see the "curswant" key in
7691 |winrestview()|.
Bram Moolenaaref2f6562007-05-06 13:32:59 +00007692
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01007693setqflist({list} [, {action} [, {what}]]) *setqflist()*
Bram Moolenaarae338332017-08-11 20:25:26 +02007694 Create or replace or add to the quickfix list.
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01007695
Bram Moolenaarae338332017-08-11 20:25:26 +02007696 When {what} is not present, use the items in {list}. Each
7697 item must be a dictionary. Non-dictionary items in {list} are
7698 ignored. Each dictionary item can contain the following
7699 entries:
Bram Moolenaar68b76a62005-03-25 21:53:48 +00007700
Bram Moolenaar48b66fb2007-02-04 01:58:18 +00007701 bufnr buffer number; must be the number of a valid
Bram Moolenaar446cb832008-06-24 21:56:24 +00007702 buffer
Bram Moolenaar48b66fb2007-02-04 01:58:18 +00007703 filename name of a file; only used when "bufnr" is not
Bram Moolenaar446cb832008-06-24 21:56:24 +00007704 present or it is invalid.
Bram Moolenaard76ce852018-05-01 15:02:04 +02007705 module name of a module; if given it will be used in
7706 quickfix error window instead of the filename.
Bram Moolenaar68b76a62005-03-25 21:53:48 +00007707 lnum line number in the file
Bram Moolenaar68b76a62005-03-25 21:53:48 +00007708 pattern search pattern used to locate the error
Bram Moolenaar582fd852005-03-28 20:58:01 +00007709 col column number
7710 vcol when non-zero: "col" is visual column
Bram Moolenaarc9b4b052006-04-30 18:54:39 +00007711 when zero: "col" is byte index
Bram Moolenaar582fd852005-03-28 20:58:01 +00007712 nr error number
Bram Moolenaar68b76a62005-03-25 21:53:48 +00007713 text description of the error
Bram Moolenaar582fd852005-03-28 20:58:01 +00007714 type single-character error type, 'E', 'W', etc.
Bram Moolenaarf1d21c82017-04-22 21:20:46 +02007715 valid recognized error message
Bram Moolenaar68b76a62005-03-25 21:53:48 +00007716
Bram Moolenaar582fd852005-03-28 20:58:01 +00007717 The "col", "vcol", "nr", "type" and "text" entries are
7718 optional. Either "lnum" or "pattern" entry can be used to
7719 locate a matching error line.
Bram Moolenaar48b66fb2007-02-04 01:58:18 +00007720 If the "filename" and "bufnr" entries are not present or
7721 neither the "lnum" or "pattern" entries are present, then the
7722 item will not be handled as an error line.
Bram Moolenaar68b76a62005-03-25 21:53:48 +00007723 If both "pattern" and "lnum" are present then "pattern" will
7724 be used.
Bram Moolenaarf1d21c82017-04-22 21:20:46 +02007725 If the "valid" entry is not supplied, then the valid flag is
7726 set when "bufnr" is a valid buffer or "filename" exists.
Bram Moolenaar00a927d2010-05-14 23:24:24 +02007727 If you supply an empty {list}, the quickfix list will be
7728 cleared.
Bram Moolenaar48b66fb2007-02-04 01:58:18 +00007729 Note that the list is not exactly the same as what
7730 |getqflist()| returns.
Bram Moolenaar68b76a62005-03-25 21:53:48 +00007731
Bram Moolenaarb6fa30c2017-03-29 14:19:25 +02007732 {action} values: *E927*
7733 'a' The items from {list} are added to the existing
7734 quickfix list. If there is no existing list, then a
7735 new list is created.
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01007736
Bram Moolenaarb6fa30c2017-03-29 14:19:25 +02007737 'r' The items from the current quickfix list are replaced
7738 with the items from {list}. This can also be used to
7739 clear the list: >
7740 :call setqflist([], 'r')
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01007741<
Bram Moolenaarb6fa30c2017-03-29 14:19:25 +02007742 'f' All the quickfix lists in the quickfix stack are
7743 freed.
7744
Bram Moolenaar511972d2016-06-04 18:09:59 +02007745 If {action} is not present or is set to ' ', then a new list
Bram Moolenaar55b69262017-08-13 13:42:01 +02007746 is created. The new quickfix list is added after the current
7747 quickfix list in the stack and all the following lists are
7748 freed. To add a new quickfix list at the end of the stack,
Bram Moolenaar36538222017-09-02 19:51:44 +02007749 set "nr" in {what} to "$".
Bram Moolenaar35c54e52005-05-20 21:25:31 +00007750
Bram Moolenaard823fa92016-08-12 16:29:27 +02007751 If the optional {what} dictionary argument is supplied, then
7752 only the items listed in {what} are set. The first {list}
7753 argument is ignored. The following items can be specified in
7754 {what}:
Bram Moolenaar15142e22018-04-30 22:19:58 +02007755 context quickfix list context. See |quickfix-context|
Bram Moolenaar36538222017-09-02 19:51:44 +02007756 efm errorformat to use when parsing text from
7757 "lines". If this is not present, then the
7758 'errorformat' option value is used.
Bram Moolenaar5b69c222019-01-11 14:50:06 +01007759 See |quickfix-parse|
Bram Moolenaara539f4f2017-08-30 20:33:55 +02007760 id quickfix list identifier |quickfix-ID|
Bram Moolenaar5b69c222019-01-11 14:50:06 +01007761 idx index of the current entry in the quickfix
7762 list specified by 'id' or 'nr'. If set to '$',
7763 then the last entry in the list is set as the
7764 current entry. See |quickfix-index|
Bram Moolenaar6a8958d2017-06-22 21:33:20 +02007765 items list of quickfix entries. Same as the {list}
7766 argument.
Bram Moolenaar2c809b72017-09-01 18:34:02 +02007767 lines use 'errorformat' to parse a list of lines and
7768 add the resulting entries to the quickfix list
7769 {nr} or {id}. Only a |List| value is supported.
Bram Moolenaar5b69c222019-01-11 14:50:06 +01007770 See |quickfix-parse|
Bram Moolenaar875feea2017-06-11 16:07:51 +02007771 nr list number in the quickfix stack; zero
Bram Moolenaar36538222017-09-02 19:51:44 +02007772 means the current quickfix list and "$" means
Bram Moolenaar5b69c222019-01-11 14:50:06 +01007773 the last quickfix list.
7774 title quickfix list title text. See |quickfix-title|
Bram Moolenaard823fa92016-08-12 16:29:27 +02007775 Unsupported keys in {what} are ignored.
7776 If the "nr" item is not present, then the current quickfix list
Bram Moolenaar86f100dc2017-06-28 21:26:27 +02007777 is modified. When creating a new quickfix list, "nr" can be
7778 set to a value one greater than the quickfix stack size.
Bram Moolenaara539f4f2017-08-30 20:33:55 +02007779 When modifying a quickfix list, to guarantee that the correct
Bram Moolenaar36538222017-09-02 19:51:44 +02007780 list is modified, "id" should be used instead of "nr" to
Bram Moolenaara539f4f2017-08-30 20:33:55 +02007781 specify the list.
Bram Moolenaard823fa92016-08-12 16:29:27 +02007782
Bram Moolenaar15142e22018-04-30 22:19:58 +02007783 Examples (See also |setqflist-examples|): >
Bram Moolenaar2c809b72017-09-01 18:34:02 +02007784 :call setqflist([], 'r', {'title': 'My search'})
7785 :call setqflist([], 'r', {'nr': 2, 'title': 'Errors'})
Bram Moolenaar15142e22018-04-30 22:19:58 +02007786 :call setqflist([], 'a', {'id':qfid, 'lines':["F1:10:L10"]})
Bram Moolenaard823fa92016-08-12 16:29:27 +02007787<
Bram Moolenaar68b76a62005-03-25 21:53:48 +00007788 Returns zero for success, -1 for failure.
7789
7790 This function can be used to create a quickfix list
7791 independent of the 'errorformat' setting. Use a command like
Bram Moolenaar94237492017-04-23 18:40:21 +02007792 `:cc 1` to jump to the first position.
Bram Moolenaar68b76a62005-03-25 21:53:48 +00007793
7794
Bram Moolenaar071d4272004-06-13 20:20:40 +00007795 *setreg()*
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007796setreg({regname}, {value} [, {options}])
Bram Moolenaar071d4272004-06-13 20:20:40 +00007797 Set the register {regname} to {value}.
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01007798 {value} may be any value returned by |getreg()|, including
Bram Moolenaar5a50c222014-04-02 22:17:10 +02007799 a |List|.
Bram Moolenaar071d4272004-06-13 20:20:40 +00007800 If {options} contains "a" or {regname} is upper case,
7801 then the value is appended.
Bram Moolenaarc6485bc2010-07-28 17:02:55 +02007802 {options} can also contain a register type specification:
Bram Moolenaar071d4272004-06-13 20:20:40 +00007803 "c" or "v" |characterwise| mode
7804 "l" or "V" |linewise| mode
7805 "b" or "<CTRL-V>" |blockwise-visual| mode
7806 If a number immediately follows "b" or "<CTRL-V>" then this is
7807 used as the width of the selection - if it is not specified
7808 then the width of the block is set to the number of characters
Bram Moolenaard46bbc72007-05-12 14:38:41 +00007809 in the longest line (counting a <Tab> as 1 character).
Bram Moolenaar071d4272004-06-13 20:20:40 +00007810
7811 If {options} contains no register settings, then the default
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01007812 is to use character mode unless {value} ends in a <NL> for
7813 string {value} and linewise mode for list {value}. Blockwise
Bram Moolenaar5a50c222014-04-02 22:17:10 +02007814 mode is never selected automatically.
7815 Returns zero for success, non-zero for failure.
7816
7817 *E883*
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01007818 Note: you may not use |List| containing more than one item to
7819 set search and expression registers. Lists containing no
Bram Moolenaar5a50c222014-04-02 22:17:10 +02007820 items act like empty strings.
Bram Moolenaar071d4272004-06-13 20:20:40 +00007821
7822 Examples: >
7823 :call setreg(v:register, @*)
7824 :call setreg('*', @%, 'ac')
7825 :call setreg('a', "1\n2\n3", 'b5')
7826
7827< This example shows using the functions to save and restore a
Bram Moolenaarb4d5fba2017-09-11 19:31:28 +02007828 register: >
Bram Moolenaar5a50c222014-04-02 22:17:10 +02007829 :let var_a = getreg('a', 1, 1)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007830 :let var_amode = getregtype('a')
7831 ....
7832 :call setreg('a', var_a, var_amode)
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01007833< Note: you may not reliably restore register value
7834 without using the third argument to |getreg()| as without it
Bram Moolenaarb4d5fba2017-09-11 19:31:28 +02007835 newlines are represented as newlines AND Nul bytes are
7836 represented as newlines as well, see |NL-used-for-Nul|.
Bram Moolenaar071d4272004-06-13 20:20:40 +00007837
Bram Moolenaarb4d5fba2017-09-11 19:31:28 +02007838 You can also change the type of a register by appending
Bram Moolenaar071d4272004-06-13 20:20:40 +00007839 nothing: >
7840 :call setreg('a', '', 'al')
7841
Bram Moolenaar06b5d512010-05-22 15:37:44 +02007842settabvar({tabnr}, {varname}, {val}) *settabvar()*
7843 Set tab-local variable {varname} to {val} in tab page {tabnr}.
7844 |t:var|
7845 Note that the variable name without "t:" must be used.
7846 Tabs are numbered starting with one.
Bram Moolenaar06b5d512010-05-22 15:37:44 +02007847 This function is not available in the |sandbox|.
7848
Bram Moolenaarc6249bb2006-04-15 20:25:09 +00007849settabwinvar({tabnr}, {winnr}, {varname}, {val}) *settabwinvar()*
7850 Set option or local variable {varname} in window {winnr} to
7851 {val}.
7852 Tabs are numbered starting with one. For the current tabpage
7853 use |setwinvar()|.
Bram Moolenaar7571d552016-08-18 22:54:46 +02007854 {winnr} can be the window number or the |window-ID|.
Bram Moolenaarc6249bb2006-04-15 20:25:09 +00007855 When {winnr} is zero the current window is used.
Bram Moolenaar071d4272004-06-13 20:20:40 +00007856 This also works for a global or local buffer option, but it
7857 doesn't work for a global or local buffer variable.
7858 For a local buffer option the global value is unchanged.
7859 Note that the variable name without "w:" must be used.
Bram Moolenaarc6249bb2006-04-15 20:25:09 +00007860 Examples: >
7861 :call settabwinvar(1, 1, "&list", 0)
7862 :call settabwinvar(3, 2, "myvar", "foobar")
7863< This function is not available in the |sandbox|.
7864
Bram Moolenaarf49cc602018-11-11 15:21:05 +01007865settagstack({nr}, {dict} [, {action}]) *settagstack()*
7866 Modify the tag stack of the window {nr} using {dict}.
7867 {nr} can be the window number or the |window-ID|.
7868
7869 For a list of supported items in {dict}, refer to
7870 |gettagstack()|
7871 *E962*
7872 If {action} is not present or is set to 'r', then the tag
7873 stack is replaced. If {action} is set to 'a', then new entries
7874 from {dict} are pushed onto the tag stack.
7875
7876 Returns zero for success, -1 for failure.
7877
7878 Examples:
7879 Set current index of the tag stack to 4: >
7880 call settagstack(1005, {'curidx' : 4})
7881
7882< Empty the tag stack of window 3: >
7883 call settagstack(3, {'items' : []})
7884
7885< Push a new item onto the tag stack: >
7886 let pos = [bufnr('myfile.txt'), 10, 1, 0]
7887 let newtag = [{'tagname' : 'mytag', 'from' : pos}]
7888 call settagstack(2, {'items' : newtag}, 'a')
7889
7890< Save and restore the tag stack: >
7891 let stack = gettagstack(1003)
7892 " do something else
7893 call settagstack(1003, stack)
7894 unlet stack
7895<
Bram Moolenaarc6249bb2006-04-15 20:25:09 +00007896setwinvar({nr}, {varname}, {val}) *setwinvar()*
7897 Like |settabwinvar()| for the current tab page.
Bram Moolenaar071d4272004-06-13 20:20:40 +00007898 Examples: >
7899 :call setwinvar(1, "&list", 0)
7900 :call setwinvar(2, "myvar", "foobar")
Bram Moolenaar071d4272004-06-13 20:20:40 +00007901
Bram Moolenaaraf9aeb92013-02-13 17:35:04 +01007902sha256({string}) *sha256()*
Bram Moolenaar2b8388b2015-02-28 13:11:45 +01007903 Returns a String with 64 hex characters, which is the SHA256
Bram Moolenaaraf9aeb92013-02-13 17:35:04 +01007904 checksum of {string}.
7905 {only available when compiled with the |+cryptv| feature}
7906
Bram Moolenaar05bb9532008-07-04 09:44:11 +00007907shellescape({string} [, {special}]) *shellescape()*
Bram Moolenaar8f3f58f2010-01-06 20:52:26 +01007908 Escape {string} for use as a shell command argument.
Bram Moolenaar60a495f2006-10-03 12:44:42 +00007909 On MS-Windows and MS-DOS, when 'shellslash' is not set, it
Bram Moolenaar05bb9532008-07-04 09:44:11 +00007910 will enclose {string} in double quotes and double all double
Bram Moolenaar60a495f2006-10-03 12:44:42 +00007911 quotes within {string}.
Bram Moolenaare381d3d2016-07-07 14:50:41 +02007912 Otherwise it will enclose {string} in single quotes and
7913 replace all "'" with "'\''".
Bram Moolenaar875feea2017-06-11 16:07:51 +02007914
Bram Moolenaar05bb9532008-07-04 09:44:11 +00007915 When the {special} argument is present and it's a non-zero
7916 Number or a non-empty String (|non-zero-arg|), then special
Bram Moolenaare37d50a2008-08-06 17:06:04 +00007917 items such as "!", "%", "#" and "<cword>" will be preceded by
7918 a backslash. This backslash will be removed again by the |:!|
Bram Moolenaar05bb9532008-07-04 09:44:11 +00007919 command.
Bram Moolenaar875feea2017-06-11 16:07:51 +02007920
Bram Moolenaare37d50a2008-08-06 17:06:04 +00007921 The "!" character will be escaped (again with a |non-zero-arg|
7922 {special}) when 'shell' contains "csh" in the tail. That is
7923 because for csh and tcsh "!" is used for history replacement
7924 even when inside single quotes.
Bram Moolenaar875feea2017-06-11 16:07:51 +02007925
7926 With a |non-zero-arg| {special} the <NL> character is also
7927 escaped. When 'shell' containing "csh" in the tail it's
Bram Moolenaare37d50a2008-08-06 17:06:04 +00007928 escaped a second time.
Bram Moolenaar875feea2017-06-11 16:07:51 +02007929
Bram Moolenaar05bb9532008-07-04 09:44:11 +00007930 Example of use with a |:!| command: >
7931 :exe '!dir ' . shellescape(expand('<cfile>'), 1)
7932< This results in a directory listing for the file under the
7933 cursor. Example of use with |system()|: >
7934 :call system("chmod +w -- " . shellescape(expand("%")))
Bram Moolenaar26df0922014-02-23 23:39:13 +01007935< See also |::S|.
Bram Moolenaar60a495f2006-10-03 12:44:42 +00007936
7937
Bram Moolenaarf9514162018-11-22 03:08:29 +01007938shiftwidth([{col}]) *shiftwidth()*
Bram Moolenaar2d17fa32012-10-21 00:45:18 +02007939 Returns the effective value of 'shiftwidth'. This is the
7940 'shiftwidth' value unless it is zero, in which case it is the
Bram Moolenaar009d84a2016-01-28 14:12:00 +01007941 'tabstop' value. This function was introduced with patch
Bram Moolenaarf9514162018-11-22 03:08:29 +01007942 7.3.694 in 2012, everybody should have it by now (however it
7943 did not allow for the optional {col} argument until 8.1.542).
Bram Moolenaar2d17fa32012-10-21 00:45:18 +02007944
Bram Moolenaarf9514162018-11-22 03:08:29 +01007945 When there is one argument {col} this is used as column number
7946 for which to return the 'shiftwidth' value. This matters for the
7947 'vartabstop' feature. If the 'vartabstop' setting is enabled and
7948 no {col} argument is given, column 1 will be assumed.
Bram Moolenaarf0d58ef2018-11-16 16:13:44 +01007949
Bram Moolenaar162b7142018-12-21 15:17:36 +01007950sign_define({name} [, {dict}]) *sign_define()*
7951 Define a new sign named {name} or modify the attributes of an
7952 existing sign. This is similar to the |:sign-define| command.
Bram Moolenaar2d17fa32012-10-21 00:45:18 +02007953
Bram Moolenaar162b7142018-12-21 15:17:36 +01007954 Prefix {name} with a unique text to avoid name collisions.
7955 There is no {group} like with placing signs.
7956
7957 The {name} can be a String or a Number. The optional {dict}
7958 argument specifies the sign attributes. The following values
7959 are supported:
Bram Moolenaarc8c88492018-12-27 23:59:26 +01007960 icon full path to the bitmap file for the sign.
7961 linehl highlight group used for the whole line the
Bram Moolenaar162b7142018-12-21 15:17:36 +01007962 sign is placed in.
Bram Moolenaarc8c88492018-12-27 23:59:26 +01007963 text text that is displayed when there is no icon
Bram Moolenaar162b7142018-12-21 15:17:36 +01007964 or the GUI is not being used.
Bram Moolenaarc8c88492018-12-27 23:59:26 +01007965 texthl highlight group used for the text item
Bram Moolenaarb328cca2019-01-06 16:24:01 +01007966
7967 If the sign named {name} already exists, then the attributes
7968 of the sign are updated.
Bram Moolenaar162b7142018-12-21 15:17:36 +01007969
7970 Returns 0 on success and -1 on failure.
7971
7972 Examples: >
7973 call sign_define("mySign", {"text" : "=>", "texthl" :
7974 \ "Error", "linehl" : "Search"})
7975<
7976sign_getdefined([{name}]) *sign_getdefined()*
7977 Get a list of defined signs and their attributes.
7978 This is similar to the |:sign-list| command.
7979
7980 If the {name} is not supplied, then a list of all the defined
7981 signs is returned. Otherwise the attribute of the specified
7982 sign is returned.
7983
7984 Each list item in the returned value is a dictionary with the
7985 following entries:
Bram Moolenaarc8c88492018-12-27 23:59:26 +01007986 icon full path to the bitmap file of the sign
7987 linehl highlight group used for the whole line the
Bram Moolenaar162b7142018-12-21 15:17:36 +01007988 sign is placed in.
Bram Moolenaarc8c88492018-12-27 23:59:26 +01007989 name name of the sign
7990 text text that is displayed when there is no icon
Bram Moolenaar162b7142018-12-21 15:17:36 +01007991 or the GUI is not being used.
Bram Moolenaarc8c88492018-12-27 23:59:26 +01007992 texthl highlight group used for the text item
Bram Moolenaar162b7142018-12-21 15:17:36 +01007993
7994 Returns an empty List if there are no signs and when {name} is
7995 not found.
7996
7997 Examples: >
7998 " Get a list of all the defined signs
7999 echo sign_getdefined()
8000
8001 " Get the attribute of the sign named mySign
8002 echo sign_getdefined("mySign")
8003<
8004sign_getplaced([{expr} [, {dict}]]) *sign_getplaced()*
8005 Return a list of signs placed in a buffer or all the buffers.
8006 This is similar to the |:sign-place-list| command.
8007
8008 If the optional buffer name {expr} is specified, then only the
8009 list of signs placed in that buffer is returned. For the use
8010 of {expr}, see |bufname()|. The optional {dict} can contain
8011 the following entries:
Bram Moolenaarc8c88492018-12-27 23:59:26 +01008012 group select only signs in this group
8013 id select sign with this identifier
8014 lnum select signs placed in this line. For the use
Bram Moolenaar162b7142018-12-21 15:17:36 +01008015 of {lnum}, see |line()|.
8016 If {group} is '*', then signs in all the groups including the
Bram Moolenaar6436cd82018-12-27 00:28:33 +01008017 global group are returned. If {group} is not supplied or is an
8018 empty string, then only signs in the global group are
8019 returned. If no arguments are supplied, then signs in the
8020 global group placed in all the buffers are returned.
Bram Moolenaarb328cca2019-01-06 16:24:01 +01008021 See |sign-group|.
Bram Moolenaar162b7142018-12-21 15:17:36 +01008022
8023 Each list item in the returned value is a dictionary with the
8024 following entries:
8025 bufnr number of the buffer with the sign
8026 signs list of signs placed in {bufnr}. Each list
8027 item is a dictionary with the below listed
8028 entries
8029
8030 The dictionary for each sign contains the following entries:
8031 group sign group. Set to '' for the global group.
8032 id identifier of the sign
8033 lnum line number where the sign is placed
8034 name name of the defined sign
8035 priority sign priority
8036
Bram Moolenaarb589f952019-01-07 22:10:00 +01008037 The returned signs in a buffer are ordered by their line
8038 number.
8039
Bram Moolenaarb328cca2019-01-06 16:24:01 +01008040 Returns an empty list on failure or if there are no placed
8041 signs.
Bram Moolenaar162b7142018-12-21 15:17:36 +01008042
8043 Examples: >
8044 " Get a List of signs placed in eval.c in the
8045 " global group
8046 echo sign_getplaced("eval.c")
8047
8048 " Get a List of signs in group 'g1' placed in eval.c
8049 echo sign_getplaced("eval.c", {'group' : 'g1'})
8050
8051 " Get a List of signs placed at line 10 in eval.c
8052 echo sign_getplaced("eval.c", {'lnum' : 10})
8053
8054 " Get sign with identifier 10 placed in a.py
Bram Moolenaarc8c88492018-12-27 23:59:26 +01008055 echo sign_getplaced("a.py", {'id' : 10})
Bram Moolenaar162b7142018-12-21 15:17:36 +01008056
8057 " Get sign with id 20 in group 'g1' placed in a.py
8058 echo sign_getplaced("a.py", {'group' : 'g1',
Bram Moolenaarc8c88492018-12-27 23:59:26 +01008059 \ 'id' : 20})
Bram Moolenaar162b7142018-12-21 15:17:36 +01008060
8061 " Get a List of all the placed signs
8062 echo sign_getplaced()
8063<
Bram Moolenaar6b7b7192019-01-11 13:42:41 +01008064 *sign_jump()*
8065sign_jump({id}, {group}, {expr})
8066 Open the buffer {expr} or jump to the window that contains
8067 {expr} and position the cursor at sign {id} in group {group}.
8068 This is similar to the |:sign-jump| command.
8069
8070 For the use of {expr}, see |bufname()|.
8071
8072 Returns the line number of the sign. Returns -1 if the
8073 arguments are invalid.
8074
8075 Example: >
8076 " Jump to sign 10 in the current buffer
8077 call sign_jump(10, '', '')
8078<
Bram Moolenaar162b7142018-12-21 15:17:36 +01008079 *sign_place()*
8080sign_place({id}, {group}, {name}, {expr} [, {dict}])
8081 Place the sign defined as {name} at line {lnum} in file {expr}
8082 and assign {id} and {group} to sign. This is similar to the
8083 |:sign-place| command.
8084
8085 If the sign identifier {id} is zero, then a new identifier is
8086 allocated. Otherwise the specified number is used. {group} is
8087 the sign group name. To use the global sign group, use an
8088 empty string. {group} functions as a namespace for {id}, thus
Bram Moolenaarb328cca2019-01-06 16:24:01 +01008089 two groups can use the same IDs. Refer to |sign-identifier|
Bram Moolenaar5b69c222019-01-11 14:50:06 +01008090 and |sign-group| for more information.
Bram Moolenaarc8c88492018-12-27 23:59:26 +01008091
Bram Moolenaar162b7142018-12-21 15:17:36 +01008092 {name} refers to a defined sign.
8093 {expr} refers to a buffer name or number. For the accepted
8094 values, see |bufname()|.
8095
8096 The optional {dict} argument supports the following entries:
8097 lnum line number in the buffer {expr} where
8098 the sign is to be placed. For the
8099 accepted values, see |line()|.
8100 priority priority of the sign. See
8101 |sign-priority| for more information.
8102
8103 If the optional {dict} is not specified, then it modifies the
8104 placed sign {id} in group {group} to use the defined sign
8105 {name}.
8106
8107 Returns the sign identifier on success and -1 on failure.
8108
8109 Examples: >
8110 " Place a sign named sign1 with id 5 at line 20 in
8111 " buffer json.c
8112 call sign_place(5, '', 'sign1', 'json.c',
8113 \ {'lnum' : 20})
8114
8115 " Updates sign 5 in buffer json.c to use sign2
8116 call sign_place(5, '', 'sign2', 'json.c')
8117
8118 " Place a sign named sign3 at line 30 in
8119 " buffer json.c with a new identifier
8120 let id = sign_place(0, '', 'sign3', 'json.c',
8121 \ {'lnum' : 30})
8122
8123 " Place a sign named sign4 with id 10 in group 'g3'
8124 " at line 40 in buffer json.c with priority 90
8125 call sign_place(10, 'g3', 'sign4', 'json.c',
8126 \ {'lnum' : 40, 'priority' : 90})
8127<
8128sign_undefine([{name}]) *sign_undefine()*
8129 Deletes a previously defined sign {name}. This is similar to
8130 the |:sign-undefine| command. If {name} is not supplied, then
8131 deletes all the defined signs.
8132
8133 Returns 0 on success and -1 on failure.
8134
8135 Examples: >
8136 " Delete a sign named mySign
8137 call sign_undefine("mySign")
8138
8139 " Delete all the signs
8140 call sign_undefine()
8141<
8142sign_unplace({group} [, {dict}]) *sign_unplace()*
8143 Remove a previously placed sign in one or more buffers. This
Bram Moolenaarc8c88492018-12-27 23:59:26 +01008144 is similar to the |:sign-unplace| command.
Bram Moolenaar162b7142018-12-21 15:17:36 +01008145
8146 {group} is the sign group name. To use the global sign group,
8147 use an empty string. If {group} is set to '*', then all the
8148 groups including the global group are used.
8149 The signs in {group} are selected based on the entries in
8150 {dict}. The following optional entries in {dict} are
8151 supported:
8152 buffer buffer name or number. See |bufname()|.
8153 id sign identifier
8154 If {dict} is not supplied, then all the signs in {group} are
8155 removed.
8156
8157 Returns 0 on success and -1 on failure.
8158
8159 Examples: >
8160 " Remove sign 10 from buffer a.vim
8161 call sign_unplace('', {'buffer' : "a.vim", 'id' : 10})
8162
8163 " Remove sign 20 in group 'g1' from buffer 3
8164 call sign_unplace('g1', {'buffer' : 3, 'id' : 20})
8165
8166 " Remove all the signs in group 'g2' from buffer 10
8167 call sign_unplace('g2', {'buffer' : 10})
8168
8169 " Remove sign 30 in group 'g3' from all the buffers
8170 call sign_unplace('g3', {'id' : 30})
8171
8172 " Remove all the signs placed in buffer 5
8173 call sign_unplace('*', {'buffer' : 5})
8174
8175 " Remove the signs in group 'g4' from all the buffers
8176 call sign_unplace('g4')
8177
8178 " Remove sign 40 from all the buffers
8179 call sign_unplace('*', {'id' : 40})
8180
8181 " Remove all the placed signs from all the buffers
8182 call sign_unplace('*')
8183<
Bram Moolenaar071d4272004-06-13 20:20:40 +00008184simplify({filename}) *simplify()*
8185 Simplify the file name as much as possible without changing
8186 the meaning. Shortcuts (on MS-Windows) or symbolic links (on
8187 Unix) are not resolved. If the first path component in
8188 {filename} designates the current directory, this will be
8189 valid for the result as well. A trailing path separator is
8190 not removed either.
8191 Example: >
8192 simplify("./dir/.././/file/") == "./file/"
8193< Note: The combination "dir/.." is only removed if "dir" is
8194 a searchable directory or does not exist. On Unix, it is also
8195 removed when "dir" is a symbolic link within the same
8196 directory. In order to resolve all the involved symbolic
8197 links before simplifying the path name, use |resolve()|.
8198
Bram Moolenaara14de3d2005-01-07 21:48:26 +00008199
Bram Moolenaar446cb832008-06-24 21:56:24 +00008200sin({expr}) *sin()*
8201 Return the sine of {expr}, measured in radians, as a |Float|.
8202 {expr} must evaluate to a |Float| or a |Number|.
8203 Examples: >
8204 :echo sin(100)
8205< -0.506366 >
8206 :echo sin(-4.01)
8207< 0.763301
8208 {only available when compiled with the |+float| feature}
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01008209
Bram Moolenaar446cb832008-06-24 21:56:24 +00008210
Bram Moolenaardb7c6862010-05-21 16:33:48 +02008211sinh({expr}) *sinh()*
Bram Moolenaar9855d6b2010-07-18 14:34:51 +02008212 Return the hyperbolic sine of {expr} as a |Float| in the range
Bram Moolenaardb7c6862010-05-21 16:33:48 +02008213 [-inf, inf].
Bram Moolenaar9855d6b2010-07-18 14:34:51 +02008214 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaardb7c6862010-05-21 16:33:48 +02008215 Examples: >
8216 :echo sinh(0.5)
8217< 0.521095 >
8218 :echo sinh(-0.9)
8219< -1.026517
Bram Moolenaardb84e452010-08-15 13:50:43 +02008220 {only available when compiled with the |+float| feature}
Bram Moolenaardb7c6862010-05-21 16:33:48 +02008221
8222
Bram Moolenaar5f894962011-06-19 02:55:37 +02008223sort({list} [, {func} [, {dict}]]) *sort()* *E702*
Bram Moolenaar327aa022014-03-25 18:24:23 +01008224 Sort the items in {list} in-place. Returns {list}.
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01008225
Bram Moolenaar327aa022014-03-25 18:24:23 +01008226 If you want a list to remain unmodified make a copy first: >
Bram Moolenaara14de3d2005-01-07 21:48:26 +00008227 :let sortedlist = sort(copy(mylist))
Bram Moolenaar822ff862014-06-12 21:46:14 +02008228
Bram Moolenaar946e27a2014-06-25 18:50:27 +02008229< When {func} is omitted, is empty or zero, then sort() uses the
8230 string representation of each item to sort on. Numbers sort
8231 after Strings, |Lists| after Numbers. For sorting text in the
8232 current buffer use |:sort|.
Bram Moolenaar327aa022014-03-25 18:24:23 +01008233
Bram Moolenaar34401cc2014-08-29 15:12:19 +02008234 When {func} is given and it is '1' or 'i' then case is
Bram Moolenaar946e27a2014-06-25 18:50:27 +02008235 ignored.
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01008236
Bram Moolenaar946e27a2014-06-25 18:50:27 +02008237 When {func} is given and it is 'n' then all items will be
8238 sorted numerical (Implementation detail: This uses the
8239 strtod() function to parse numbers, Strings, Lists, Dicts and
8240 Funcrefs will be considered as being 0).
8241
Bram Moolenaarb00da1d2015-12-03 16:33:12 +01008242 When {func} is given and it is 'N' then all items will be
8243 sorted numerical. This is like 'n' but a string containing
8244 digits will be used as the number they represent.
8245
Bram Moolenaar13d5aee2016-01-21 23:36:05 +01008246 When {func} is given and it is 'f' then all items will be
8247 sorted numerical. All values must be a Number or a Float.
8248
Bram Moolenaar32466aa2006-02-24 23:53:04 +00008249 When {func} is a |Funcref| or a function name, this function
8250 is called to compare items. The function is invoked with two
Bram Moolenaar8f3f58f2010-01-06 20:52:26 +01008251 items as argument and must return zero if they are equal, 1 or
8252 bigger if the first one sorts after the second one, -1 or
8253 smaller if the first one sorts before the second one.
Bram Moolenaar327aa022014-03-25 18:24:23 +01008254
8255 {dict} is for functions with the "dict" attribute. It will be
8256 used to set the local variable "self". |Dictionary-function|
8257
Bram Moolenaar8bb1c3e2014-07-04 16:43:17 +02008258 The sort is stable, items which compare equal (as number or as
8259 string) will keep their relative position. E.g., when sorting
Bram Moolenaardb6ea062014-07-10 22:01:47 +02008260 on numbers, text strings will sort next to each other, in the
Bram Moolenaar8bb1c3e2014-07-04 16:43:17 +02008261 same order as they were originally.
8262
Bram Moolenaar327aa022014-03-25 18:24:23 +01008263 Also see |uniq()|.
8264
Bram Moolenaar8f3f58f2010-01-06 20:52:26 +01008265 Example: >
Bram Moolenaara14de3d2005-01-07 21:48:26 +00008266 func MyCompare(i1, i2)
8267 return a:i1 == a:i2 ? 0 : a:i1 > a:i2 ? 1 : -1
8268 endfunc
8269 let sortedlist = sort(mylist, "MyCompare")
Bram Moolenaar8f3f58f2010-01-06 20:52:26 +01008270< A shorter compare version for this specific simple case, which
8271 ignores overflow: >
8272 func MyCompare(i1, i2)
8273 return a:i1 - a:i2
8274 endfunc
Bram Moolenaard857f0e2005-06-21 22:37:39 +00008275<
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00008276 *soundfold()*
8277soundfold({word})
8278 Return the sound-folded equivalent of {word}. Uses the first
Bram Moolenaar446cb832008-06-24 21:56:24 +00008279 language in 'spelllang' for the current window that supports
Bram Moolenaar42eeac32005-06-29 22:40:58 +00008280 soundfolding. 'spell' must be set. When no sound folding is
8281 possible the {word} is returned unmodified.
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00008282 This can be used for making spelling suggestions. Note that
8283 the method can be quite slow.
8284
Bram Moolenaard857f0e2005-06-21 22:37:39 +00008285 *spellbadword()*
Bram Moolenaar1e015462005-09-25 22:16:38 +00008286spellbadword([{sentence}])
8287 Without argument: The result is the badly spelled word under
8288 or after the cursor. The cursor is moved to the start of the
8289 bad word. When no bad word is found in the cursor line the
8290 result is an empty string and the cursor doesn't move.
8291
8292 With argument: The result is the first word in {sentence} that
8293 is badly spelled. If there are no spelling mistakes the
8294 result is an empty string.
8295
8296 The return value is a list with two items:
8297 - The badly spelled word or an empty string.
8298 - The type of the spelling error:
Bram Moolenaarc9b4b052006-04-30 18:54:39 +00008299 "bad" spelling mistake
Bram Moolenaar1e015462005-09-25 22:16:38 +00008300 "rare" rare word
8301 "local" word only valid in another region
8302 "caps" word should start with Capital
8303 Example: >
8304 echo spellbadword("the quik brown fox")
8305< ['quik', 'bad'] ~
8306
8307 The spelling information for the current window is used. The
8308 'spell' option must be set and the value of 'spelllang' is
8309 used.
Bram Moolenaard857f0e2005-06-21 22:37:39 +00008310
8311 *spellsuggest()*
Bram Moolenaarc54b8a72005-09-30 21:20:29 +00008312spellsuggest({word} [, {max} [, {capital}]])
Bram Moolenaar32466aa2006-02-24 23:53:04 +00008313 Return a |List| with spelling suggestions to replace {word}.
Bram Moolenaard857f0e2005-06-21 22:37:39 +00008314 When {max} is given up to this number of suggestions are
8315 returned. Otherwise up to 25 suggestions are returned.
8316
Bram Moolenaarc54b8a72005-09-30 21:20:29 +00008317 When the {capital} argument is given and it's non-zero only
8318 suggestions with a leading capital will be given. Use this
8319 after a match with 'spellcapcheck'.
8320
Bram Moolenaard857f0e2005-06-21 22:37:39 +00008321 {word} can be a badly spelled word followed by other text.
8322 This allows for joining two words that were split. The
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00008323 suggestions also include the following text, thus you can
8324 replace a line.
8325
8326 {word} may also be a good word. Similar words will then be
Bram Moolenaarc54b8a72005-09-30 21:20:29 +00008327 returned. {word} itself is not included in the suggestions,
8328 although it may appear capitalized.
Bram Moolenaard857f0e2005-06-21 22:37:39 +00008329
8330 The spelling information for the current window is used. The
Bram Moolenaar42eeac32005-06-29 22:40:58 +00008331 'spell' option must be set and the values of 'spelllang' and
8332 'spellsuggest' are used.
Bram Moolenaard857f0e2005-06-21 22:37:39 +00008333
Bram Moolenaara14de3d2005-01-07 21:48:26 +00008334
Bram Moolenaar2389c3c2005-05-22 22:07:59 +00008335split({expr} [, {pattern} [, {keepempty}]]) *split()*
Bram Moolenaar32466aa2006-02-24 23:53:04 +00008336 Make a |List| out of {expr}. When {pattern} is omitted or
8337 empty each white-separated sequence of characters becomes an
8338 item.
Bram Moolenaara14de3d2005-01-07 21:48:26 +00008339 Otherwise the string is split where {pattern} matches,
Bram Moolenaar97d62492012-11-15 21:28:22 +01008340 removing the matched characters. 'ignorecase' is not used
8341 here, add \c to ignore case. |/\c|
Bram Moolenaar2389c3c2005-05-22 22:07:59 +00008342 When the first or last item is empty it is omitted, unless the
8343 {keepempty} argument is given and it's non-zero.
Bram Moolenaar5c06f8b2005-05-31 22:14:58 +00008344 Other empty items are kept when {pattern} matches at least one
8345 character or when {keepempty} is non-zero.
Bram Moolenaara14de3d2005-01-07 21:48:26 +00008346 Example: >
Bram Moolenaar5f2bb9f2005-01-11 21:29:04 +00008347 :let words = split(getline('.'), '\W\+')
Bram Moolenaar2389c3c2005-05-22 22:07:59 +00008348< To split a string in individual characters: >
Bram Moolenaar402d2fe2005-04-15 21:00:38 +00008349 :for c in split(mystring, '\zs')
Bram Moolenaar12969c02015-09-08 23:36:10 +02008350< If you want to keep the separator you can also use '\zs' at
8351 the end of the pattern: >
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00008352 :echo split('abc:def:ghi', ':\zs')
8353< ['abc:', 'def:', 'ghi'] ~
Bram Moolenaar2389c3c2005-05-22 22:07:59 +00008354 Splitting a table where the first element can be empty: >
8355 :let items = split(line, ':', 1)
8356< The opposite function is |join()|.
Bram Moolenaara14de3d2005-01-07 21:48:26 +00008357
8358
Bram Moolenaar446cb832008-06-24 21:56:24 +00008359sqrt({expr}) *sqrt()*
8360 Return the non-negative square root of Float {expr} as a
8361 |Float|.
8362 {expr} must evaluate to a |Float| or a |Number|. When {expr}
8363 is negative the result is NaN (Not a Number).
8364 Examples: >
8365 :echo sqrt(100)
8366< 10.0 >
8367 :echo sqrt(-4.01)
8368< nan
Bram Moolenaarc236c162008-07-13 17:41:49 +00008369 "nan" may be different, it depends on system libraries.
Bram Moolenaar446cb832008-06-24 21:56:24 +00008370 {only available when compiled with the |+float| feature}
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01008371
Bram Moolenaar446cb832008-06-24 21:56:24 +00008372
Bram Moolenaar81edd172016-04-14 13:51:37 +02008373str2float({expr}) *str2float()*
Bram Moolenaar446cb832008-06-24 21:56:24 +00008374 Convert String {expr} to a Float. This mostly works the same
8375 as when using a floating point number in an expression, see
8376 |floating-point-format|. But it's a bit more permissive.
8377 E.g., "1e40" is accepted, while in an expression you need to
Bram Moolenaard47d5222018-12-09 20:43:55 +01008378 write "1.0e40". The hexadecimal form "0x123" is also
8379 accepted, but not others, like binary or octal.
Bram Moolenaar446cb832008-06-24 21:56:24 +00008380 Text after the number is silently ignored.
8381 The decimal point is always '.', no matter what the locale is
8382 set to. A comma ends the number: "12,345.67" is converted to
8383 12.0. You can strip out thousands separators with
8384 |substitute()|: >
8385 let f = str2float(substitute(text, ',', '', 'g'))
8386< {only available when compiled with the |+float| feature}
8387
8388
Bram Moolenaar81edd172016-04-14 13:51:37 +02008389str2nr({expr} [, {base}]) *str2nr()*
Bram Moolenaar97b2ad32006-03-18 21:40:56 +00008390 Convert string {expr} to a number.
Bram Moolenaarfa735342016-01-03 22:14:44 +01008391 {base} is the conversion base, it can be 2, 8, 10 or 16.
Bram Moolenaar97b2ad32006-03-18 21:40:56 +00008392 When {base} is omitted base 10 is used. This also means that
8393 a leading zero doesn't cause octal conversion to be used, as
8394 with the default String to Number conversion.
8395 When {base} is 16 a leading "0x" or "0X" is ignored. With a
Bram Moolenaarfa735342016-01-03 22:14:44 +01008396 different base the result will be zero. Similarly, when
8397 {base} is 8 a leading "0" is ignored, and when {base} is 2 a
8398 leading "0b" or "0B" is ignored.
Bram Moolenaar97b2ad32006-03-18 21:40:56 +00008399 Text after the number is silently ignored.
Bram Moolenaarc9b4b052006-04-30 18:54:39 +00008400
Bram Moolenaar97b2ad32006-03-18 21:40:56 +00008401
Bram Moolenaar979243b2015-06-26 19:35:49 +02008402strchars({expr} [, {skipcc}]) *strchars()*
Bram Moolenaar72597a52010-07-18 15:31:08 +02008403 The result is a Number, which is the number of characters
Bram Moolenaar979243b2015-06-26 19:35:49 +02008404 in String {expr}.
8405 When {skipcc} is omitted or zero, composing characters are
8406 counted separately.
8407 When {skipcc} set to 1, Composing characters are ignored.
Bram Moolenaardc536092010-07-18 15:45:49 +02008408 Also see |strlen()|, |strdisplaywidth()| and |strwidth()|.
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01008409
Bram Moolenaar86ae7202015-07-10 19:31:35 +02008410 {skipcc} is only available after 7.4.755. For backward
8411 compatibility, you can define a wrapper function: >
8412 if has("patch-7.4.755")
8413 function s:strchars(str, skipcc)
8414 return strchars(a:str, a:skipcc)
8415 endfunction
8416 else
8417 function s:strchars(str, skipcc)
8418 if a:skipcc
8419 return strlen(substitute(a:str, ".", "x", "g"))
8420 else
8421 return strchars(a:str)
8422 endif
8423 endfunction
8424 endif
8425<
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01008426strcharpart({src}, {start} [, {len}]) *strcharpart()*
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02008427 Like |strpart()| but using character index and length instead
8428 of byte index and length.
8429 When a character index is used where a character does not
Bram Moolenaar369b6f52017-01-17 12:22:32 +01008430 exist it is assumed to be one character. For example: >
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02008431 strcharpart('abc', -1, 2)
8432< results in 'a'.
Bram Moolenaar86ae7202015-07-10 19:31:35 +02008433
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01008434strdisplaywidth({expr} [, {col}]) *strdisplaywidth()*
Bram Moolenaardc536092010-07-18 15:45:49 +02008435 The result is a Number, which is the number of display cells
Bram Moolenaar979243b2015-06-26 19:35:49 +02008436 String {expr} occupies on the screen when it starts at {col}.
Bram Moolenaardc536092010-07-18 15:45:49 +02008437 When {col} is omitted zero is used. Otherwise it is the
8438 screen column where to start. This matters for Tab
8439 characters.
Bram Moolenaar4d32c2d2010-07-18 22:10:01 +02008440 The option settings of the current window are used. This
8441 matters for anything that's displayed differently, such as
8442 'tabstop' and 'display'.
Bram Moolenaardc536092010-07-18 15:45:49 +02008443 When {expr} contains characters with East Asian Width Class
8444 Ambiguous, this function's return value depends on 'ambiwidth'.
8445 Also see |strlen()|, |strwidth()| and |strchars()|.
Bram Moolenaar72597a52010-07-18 15:31:08 +02008446
Bram Moolenaar071d4272004-06-13 20:20:40 +00008447strftime({format} [, {time}]) *strftime()*
8448 The result is a String, which is a formatted date and time, as
8449 specified by the {format} string. The given {time} is used,
8450 or the current time if no time is given. The accepted
8451 {format} depends on your system, thus this is not portable!
8452 See the manual page of the C function strftime() for the
8453 format. The maximum length of the result is 80 characters.
8454 See also |localtime()| and |getftime()|.
8455 The language can be changed with the |:language| command.
8456 Examples: >
8457 :echo strftime("%c") Sun Apr 27 11:49:23 1997
8458 :echo strftime("%Y %b %d %X") 1997 Apr 27 11:53:25
8459 :echo strftime("%y%m%d %T") 970427 11:53:55
8460 :echo strftime("%H:%M") 11:55
8461 :echo strftime("%c", getftime("file.c"))
8462 Show mod time of file.c.
Bram Moolenaara14de3d2005-01-07 21:48:26 +00008463< Not available on all systems. To check use: >
8464 :if exists("*strftime")
8465
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02008466strgetchar({str}, {index}) *strgetchar()*
8467 Get character {index} from {str}. This uses a character
8468 index, not a byte index. Composing characters are considered
8469 separate characters here.
8470 Also see |strcharpart()| and |strchars()|.
8471
Bram Moolenaar8f999f12005-01-25 22:12:55 +00008472stridx({haystack}, {needle} [, {start}]) *stridx()*
8473 The result is a Number, which gives the byte index in
8474 {haystack} of the first occurrence of the String {needle}.
Bram Moolenaar677ee682005-01-27 14:41:15 +00008475 If {start} is specified, the search starts at index {start}.
8476 This can be used to find a second match: >
Bram Moolenaar81af9252010-12-10 20:35:50 +01008477 :let colon1 = stridx(line, ":")
8478 :let colon2 = stridx(line, ":", colon1 + 1)
Bram Moolenaar677ee682005-01-27 14:41:15 +00008479< The search is done case-sensitive.
Bram Moolenaare2cc9702005-03-15 22:43:58 +00008480 For pattern searches use |match()|.
Bram Moolenaar8f999f12005-01-25 22:12:55 +00008481 -1 is returned if the {needle} does not occur in {haystack}.
Bram Moolenaar677ee682005-01-27 14:41:15 +00008482 See also |strridx()|.
8483 Examples: >
Bram Moolenaar071d4272004-06-13 20:20:40 +00008484 :echo stridx("An Example", "Example") 3
8485 :echo stridx("Starting point", "Start") 0
8486 :echo stridx("Starting point", "start") -1
Bram Moolenaarc9b4b052006-04-30 18:54:39 +00008487< *strstr()* *strchr()*
Bram Moolenaar05159a02005-02-26 23:04:13 +00008488 stridx() works similar to the C function strstr(). When used
8489 with a single character it works similar to strchr().
8490
Bram Moolenaard7ee7ce2005-01-03 21:02:03 +00008491 *string()*
Bram Moolenaar5f2bb9f2005-01-11 21:29:04 +00008492string({expr}) Return {expr} converted to a String. If {expr} is a Number,
Bram Moolenaar446cb832008-06-24 21:56:24 +00008493 Float, String or a composition of them, then the result can be
8494 parsed back with |eval()|.
Bram Moolenaard7ee7ce2005-01-03 21:02:03 +00008495 {expr} type result ~
Bram Moolenaar4f3f6682016-03-26 23:01:59 +01008496 String 'string' (single quotes are doubled)
Bram Moolenaar5f2bb9f2005-01-11 21:29:04 +00008497 Number 123
Bram Moolenaar446cb832008-06-24 21:56:24 +00008498 Float 123.123456 or 1.123456e8
Bram Moolenaard8b02732005-01-14 21:48:43 +00008499 Funcref function('name')
Bram Moolenaar5f2bb9f2005-01-11 21:29:04 +00008500 List [item, item]
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00008501 Dictionary {key: value, key: value}
Bram Moolenaar4f3f6682016-03-26 23:01:59 +01008502
8503 When a List or Dictionary has a recursive reference it is
8504 replaced by "[...]" or "{...}". Using eval() on the result
8505 will then fail.
8506
Bram Moolenaaref2f6562007-05-06 13:32:59 +00008507 Also see |strtrans()|.
Bram Moolenaard7ee7ce2005-01-03 21:02:03 +00008508
Bram Moolenaar071d4272004-06-13 20:20:40 +00008509 *strlen()*
8510strlen({expr}) The result is a Number, which is the length of the String
Bram Moolenaare344bea2005-09-01 20:46:49 +00008511 {expr} in bytes.
Bram Moolenaard7ee7ce2005-01-03 21:02:03 +00008512 If the argument is a Number it is first converted to a String.
8513 For other types an error is given.
Bram Moolenaar641e48c2015-06-25 16:09:26 +02008514 If you want to count the number of multi-byte characters use
8515 |strchars()|.
8516 Also see |len()|, |strdisplaywidth()| and |strwidth()|.
Bram Moolenaar071d4272004-06-13 20:20:40 +00008517
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01008518strpart({src}, {start} [, {len}]) *strpart()*
Bram Moolenaar071d4272004-06-13 20:20:40 +00008519 The result is a String, which is part of {src}, starting from
Bram Moolenaar9372a112005-12-06 19:59:18 +00008520 byte {start}, with the byte length {len}.
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02008521 To count characters instead of bytes use |strcharpart()|.
8522
8523 When bytes are selected which do not exist, this doesn't
8524 result in an error, the bytes are simply omitted.
Bram Moolenaar071d4272004-06-13 20:20:40 +00008525 If {len} is missing, the copy continues from {start} till the
8526 end of the {src}. >
8527 strpart("abcdefg", 3, 2) == "de"
8528 strpart("abcdefg", -2, 4) == "ab"
8529 strpart("abcdefg", 5, 4) == "fg"
Bram Moolenaar446cb832008-06-24 21:56:24 +00008530 strpart("abcdefg", 3) == "defg"
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02008531
Bram Moolenaar071d4272004-06-13 20:20:40 +00008532< Note: To get the first character, {start} must be 0. For
8533 example, to get three bytes under and after the cursor: >
Bram Moolenaar61660ea2006-04-07 21:40:07 +00008534 strpart(getline("."), col(".") - 1, 3)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008535<
Bram Moolenaar677ee682005-01-27 14:41:15 +00008536strridx({haystack}, {needle} [, {start}]) *strridx()*
8537 The result is a Number, which gives the byte index in
8538 {haystack} of the last occurrence of the String {needle}.
8539 When {start} is specified, matches beyond this index are
8540 ignored. This can be used to find a match before a previous
8541 match: >
8542 :let lastcomma = strridx(line, ",")
8543 :let comma2 = strridx(line, ",", lastcomma - 1)
8544< The search is done case-sensitive.
Bram Moolenaar8f999f12005-01-25 22:12:55 +00008545 For pattern searches use |match()|.
8546 -1 is returned if the {needle} does not occur in {haystack}.
Bram Moolenaard4755bb2004-09-02 19:12:26 +00008547 If the {needle} is empty the length of {haystack} is returned.
Bram Moolenaar402d2fe2005-04-15 21:00:38 +00008548 See also |stridx()|. Examples: >
Bram Moolenaar071d4272004-06-13 20:20:40 +00008549 :echo strridx("an angry armadillo", "an") 3
Bram Moolenaarc9b4b052006-04-30 18:54:39 +00008550< *strrchr()*
Bram Moolenaar05159a02005-02-26 23:04:13 +00008551 When used with a single character it works similar to the C
8552 function strrchr().
8553
Bram Moolenaar071d4272004-06-13 20:20:40 +00008554strtrans({expr}) *strtrans()*
8555 The result is a String, which is {expr} with all unprintable
8556 characters translated into printable characters |'isprint'|.
8557 Like they are shown in a window. Example: >
8558 echo strtrans(@a)
8559< This displays a newline in register a as "^@" instead of
8560 starting a new line.
8561
Bram Moolenaar72597a52010-07-18 15:31:08 +02008562strwidth({expr}) *strwidth()*
8563 The result is a Number, which is the number of display cells
8564 String {expr} occupies. A Tab character is counted as one
Bram Moolenaardc536092010-07-18 15:45:49 +02008565 cell, alternatively use |strdisplaywidth()|.
Bram Moolenaar72597a52010-07-18 15:31:08 +02008566 When {expr} contains characters with East Asian Width Class
8567 Ambiguous, this function's return value depends on 'ambiwidth'.
Bram Moolenaardc536092010-07-18 15:45:49 +02008568 Also see |strlen()|, |strdisplaywidth()| and |strchars()|.
Bram Moolenaar72597a52010-07-18 15:31:08 +02008569
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01008570submatch({nr} [, {list}]) *submatch()* *E935*
Bram Moolenaar251e1912011-06-19 05:09:16 +02008571 Only for an expression in a |:substitute| command or
8572 substitute() function.
8573 Returns the {nr}'th submatch of the matched text. When {nr}
8574 is 0 the whole matched text is returned.
Bram Moolenaar41571762014-04-02 19:00:58 +02008575 Note that a NL in the string can stand for a line break of a
8576 multi-line match or a NUL character in the text.
Bram Moolenaar251e1912011-06-19 05:09:16 +02008577 Also see |sub-replace-expression|.
Bram Moolenaar41571762014-04-02 19:00:58 +02008578
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01008579 If {list} is present and non-zero then submatch() returns
8580 a list of strings, similar to |getline()| with two arguments.
Bram Moolenaar41571762014-04-02 19:00:58 +02008581 NL characters in the text represent NUL characters in the
8582 text.
8583 Only returns more than one item for |:substitute|, inside
8584 |substitute()| this list will always contain one or zero
8585 items, since there are no real line breaks.
8586
Bram Moolenaar6100d022016-10-02 16:51:57 +02008587 When substitute() is used recursively only the submatches in
8588 the current (deepest) call can be obtained.
8589
Bram Moolenaar2f058492017-11-30 20:27:52 +01008590 Examples: >
Bram Moolenaar071d4272004-06-13 20:20:40 +00008591 :s/\d\+/\=submatch(0) + 1/
Bram Moolenaar2f058492017-11-30 20:27:52 +01008592 :echo substitute(text, '\d\+', '\=submatch(0) + 1', '')
Bram Moolenaar071d4272004-06-13 20:20:40 +00008593< This finds the first number in the line and adds one to it.
8594 A line break is included as a newline character.
8595
8596substitute({expr}, {pat}, {sub}, {flags}) *substitute()*
8597 The result is a String, which is a copy of {expr}, in which
Bram Moolenaar251e1912011-06-19 05:09:16 +02008598 the first match of {pat} is replaced with {sub}.
8599 When {flags} is "g", all matches of {pat} in {expr} are
8600 replaced. Otherwise {flags} should be "".
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01008601
Bram Moolenaar251e1912011-06-19 05:09:16 +02008602 This works like the ":substitute" command (without any flags).
8603 But the matching with {pat} is always done like the 'magic'
8604 option is set and 'cpoptions' is empty (to make scripts
Bram Moolenaar2df58b42012-11-28 18:21:11 +01008605 portable). 'ignorecase' is still relevant, use |/\c| or |/\C|
8606 if you want to ignore or match case and ignore 'ignorecase'.
8607 'smartcase' is not used. See |string-match| for how {pat} is
8608 used.
Bram Moolenaar251e1912011-06-19 05:09:16 +02008609
8610 A "~" in {sub} is not replaced with the previous {sub}.
Bram Moolenaar071d4272004-06-13 20:20:40 +00008611 Note that some codes in {sub} have a special meaning
Bram Moolenaar58b85342016-08-14 19:54:54 +02008612 |sub-replace-special|. For example, to replace something with
Bram Moolenaar071d4272004-06-13 20:20:40 +00008613 "\n" (two characters), use "\\\\n" or '\\n'.
Bram Moolenaar251e1912011-06-19 05:09:16 +02008614
Bram Moolenaar071d4272004-06-13 20:20:40 +00008615 When {pat} does not match in {expr}, {expr} is returned
8616 unmodified.
Bram Moolenaar251e1912011-06-19 05:09:16 +02008617
Bram Moolenaar071d4272004-06-13 20:20:40 +00008618 Example: >
Bram Moolenaardf48fb42016-07-22 21:50:18 +02008619 :let &path = substitute(&path, ",\\=[^,]*$", "", "")
Bram Moolenaar071d4272004-06-13 20:20:40 +00008620< This removes the last component of the 'path' option. >
Bram Moolenaardf48fb42016-07-22 21:50:18 +02008621 :echo substitute("testing", ".*", "\\U\\0", "")
Bram Moolenaar071d4272004-06-13 20:20:40 +00008622< results in "TESTING".
Bram Moolenaar251e1912011-06-19 05:09:16 +02008623
8624 When {sub} starts with "\=", the remainder is interpreted as
8625 an expression. See |sub-replace-expression|. Example: >
Bram Moolenaardf48fb42016-07-22 21:50:18 +02008626 :echo substitute(s, '%\(\x\x\)',
Bram Moolenaar20f90cf2011-05-19 12:22:51 +02008627 \ '\=nr2char("0x" . submatch(1))', 'g')
Bram Moolenaar071d4272004-06-13 20:20:40 +00008628
Bram Moolenaardf48fb42016-07-22 21:50:18 +02008629< When {sub} is a Funcref that function is called, with one
8630 optional argument. Example: >
8631 :echo substitute(s, '%\(\x\x\)', SubNr, 'g')
8632< The optional argument is a list which contains the whole
Bram Moolenaar58b85342016-08-14 19:54:54 +02008633 matched string and up to nine submatches, like what
8634 |submatch()| returns. Example: >
8635 :echo substitute(s, '%\(\x\x\)', {m -> '0x' . m[1]}, 'g')
Bram Moolenaardf48fb42016-07-22 21:50:18 +02008636
Bram Moolenaar20aac6c2018-09-02 21:07:30 +02008637swapinfo({fname}) *swapinfo()*
Bram Moolenaar00f123a2018-08-21 20:28:54 +02008638 The result is a dictionary, which holds information about the
8639 swapfile {fname}. The available fields are:
Bram Moolenaar95bafa22018-10-02 13:26:25 +02008640 version Vim version
Bram Moolenaar00f123a2018-08-21 20:28:54 +02008641 user user name
8642 host host name
8643 fname original file name
Bram Moolenaar95bafa22018-10-02 13:26:25 +02008644 pid PID of the Vim process that created the swap
Bram Moolenaar00f123a2018-08-21 20:28:54 +02008645 file
8646 mtime last modification time in seconds
8647 inode Optional: INODE number of the file
Bram Moolenaar47ad5652018-08-21 21:09:07 +02008648 dirty 1 if file was modified, 0 if not
Bram Moolenaarfc65cab2018-08-28 22:58:02 +02008649 Note that "user" and "host" are truncated to at most 39 bytes.
Bram Moolenaar00f123a2018-08-21 20:28:54 +02008650 In case of failure an "error" item is added with the reason:
8651 Cannot open file: file not found or in accessible
8652 Cannot read file: cannot read first block
Bram Moolenaar47ad5652018-08-21 21:09:07 +02008653 Not a swap file: does not contain correct block ID
8654 Magic number mismatch: Info in first block is invalid
Bram Moolenaar00f123a2018-08-21 20:28:54 +02008655
Bram Moolenaar110bd602018-09-16 18:46:59 +02008656swapname({expr}) *swapname()*
8657 The result is the swap file path of the buffer {expr}.
8658 For the use of {expr}, see |bufname()| above.
8659 If buffer {expr} is the current buffer, the result is equal to
8660 |:swapname| (unless no swap file).
8661 If buffer {expr} has no swap file, returns an empty string.
8662
Bram Moolenaar47136d72004-10-12 20:02:24 +00008663synID({lnum}, {col}, {trans}) *synID()*
Bram Moolenaar071d4272004-06-13 20:20:40 +00008664 The result is a Number, which is the syntax ID at the position
Bram Moolenaar47136d72004-10-12 20:02:24 +00008665 {lnum} and {col} in the current window.
Bram Moolenaar071d4272004-06-13 20:20:40 +00008666 The syntax ID can be used with |synIDattr()| and
8667 |synIDtrans()| to obtain syntax information about text.
Bram Moolenaarce0842a2005-07-18 21:58:11 +00008668
Bram Moolenaar47136d72004-10-12 20:02:24 +00008669 {col} is 1 for the leftmost column, {lnum} is 1 for the first
Bram Moolenaarce0842a2005-07-18 21:58:11 +00008670 line. 'synmaxcol' applies, in a longer line zero is returned.
Bram Moolenaarca635012015-09-25 20:34:21 +02008671 Note that when the position is after the last character,
8672 that's where the cursor can be in Insert mode, synID() returns
8673 zero.
Bram Moolenaarce0842a2005-07-18 21:58:11 +00008674
Bram Moolenaar79815f12016-07-09 17:07:29 +02008675 When {trans} is |TRUE|, transparent items are reduced to the
Bram Moolenaar58b85342016-08-14 19:54:54 +02008676 item that they reveal. This is useful when wanting to know
Bram Moolenaar79815f12016-07-09 17:07:29 +02008677 the effective color. When {trans} is |FALSE|, the transparent
Bram Moolenaar071d4272004-06-13 20:20:40 +00008678 item is returned. This is useful when wanting to know which
8679 syntax item is effective (e.g. inside parens).
8680 Warning: This function can be very slow. Best speed is
8681 obtained by going through the file in forward direction.
8682
8683 Example (echoes the name of the syntax item under the cursor): >
8684 :echo synIDattr(synID(line("."), col("."), 1), "name")
8685<
Bram Moolenaar7510fe72010-07-25 12:46:44 +02008686
Bram Moolenaar071d4272004-06-13 20:20:40 +00008687synIDattr({synID}, {what} [, {mode}]) *synIDattr()*
8688 The result is a String, which is the {what} attribute of
8689 syntax ID {synID}. This can be used to obtain information
8690 about a syntax item.
8691 {mode} can be "gui", "cterm" or "term", to get the attributes
Bram Moolenaar58b85342016-08-14 19:54:54 +02008692 for that mode. When {mode} is omitted, or an invalid value is
Bram Moolenaar071d4272004-06-13 20:20:40 +00008693 used, the attributes for the currently active highlighting are
8694 used (GUI, cterm or term).
8695 Use synIDtrans() to follow linked highlight groups.
8696 {what} result
8697 "name" the name of the syntax item
8698 "fg" foreground color (GUI: color name used to set
8699 the color, cterm: color number as a string,
8700 term: empty string)
Bram Moolenaar6f507d62008-11-28 10:16:05 +00008701 "bg" background color (as with "fg")
Bram Moolenaar12682fd2010-03-10 13:43:49 +01008702 "font" font name (only available in the GUI)
8703 |highlight-font|
Bram Moolenaar6f507d62008-11-28 10:16:05 +00008704 "sp" special color (as with "fg") |highlight-guisp|
Bram Moolenaar071d4272004-06-13 20:20:40 +00008705 "fg#" like "fg", but for the GUI and the GUI is
8706 running the name in "#RRGGBB" form
8707 "bg#" like "fg#" for "bg"
Bram Moolenaar6f507d62008-11-28 10:16:05 +00008708 "sp#" like "fg#" for "sp"
Bram Moolenaar071d4272004-06-13 20:20:40 +00008709 "bold" "1" if bold
8710 "italic" "1" if italic
8711 "reverse" "1" if reverse
8712 "inverse" "1" if inverse (= reverse)
Bram Moolenaar12682fd2010-03-10 13:43:49 +01008713 "standout" "1" if standout
Bram Moolenaar071d4272004-06-13 20:20:40 +00008714 "underline" "1" if underlined
Bram Moolenaare2cc9702005-03-15 22:43:58 +00008715 "undercurl" "1" if undercurled
Bram Moolenaarcf4b00c2017-09-02 18:33:56 +02008716 "strike" "1" if strikethrough
Bram Moolenaar071d4272004-06-13 20:20:40 +00008717
8718 Example (echoes the color of the syntax item under the
8719 cursor): >
8720 :echo synIDattr(synIDtrans(synID(line("."), col("."), 1)), "fg")
8721<
8722synIDtrans({synID}) *synIDtrans()*
8723 The result is a Number, which is the translated syntax ID of
8724 {synID}. This is the syntax group ID of what is being used to
8725 highlight the character. Highlight links given with
8726 ":highlight link" are followed.
8727
Bram Moolenaar483c5d82010-10-20 18:45:33 +02008728synconcealed({lnum}, {col}) *synconcealed()*
Bram Moolenaar4d785892017-06-22 22:00:50 +02008729 The result is a List with currently three items:
8730 1. The first item in the list is 0 if the character at the
8731 position {lnum} and {col} is not part of a concealable
8732 region, 1 if it is.
8733 2. The second item in the list is a string. If the first item
8734 is 1, the second item contains the text which will be
8735 displayed in place of the concealed text, depending on the
8736 current setting of 'conceallevel' and 'listchars'.
Bram Moolenaarcc0750d2017-06-24 22:29:24 +02008737 3. The third and final item in the list is a number
8738 representing the specific syntax region matched in the
8739 line. When the character is not concealed the value is
8740 zero. This allows detection of the beginning of a new
8741 concealable region if there are two consecutive regions
8742 with the same replacement character. For an example, if
8743 the text is "123456" and both "23" and "45" are concealed
Bram Moolenaar95bafa22018-10-02 13:26:25 +02008744 and replaced by the character "X", then:
Bram Moolenaarcc0750d2017-06-24 22:29:24 +02008745 call returns ~
Bram Moolenaarc572da52017-08-27 16:52:01 +02008746 synconcealed(lnum, 1) [0, '', 0]
8747 synconcealed(lnum, 2) [1, 'X', 1]
8748 synconcealed(lnum, 3) [1, 'X', 1]
8749 synconcealed(lnum, 4) [1, 'X', 2]
8750 synconcealed(lnum, 5) [1, 'X', 2]
8751 synconcealed(lnum, 6) [0, '', 0]
Bram Moolenaar483c5d82010-10-20 18:45:33 +02008752
8753
Bram Moolenaar9d188ab2008-01-10 21:24:39 +00008754synstack({lnum}, {col}) *synstack()*
8755 Return a |List|, which is the stack of syntax items at the
8756 position {lnum} and {col} in the current window. Each item in
8757 the List is an ID like what |synID()| returns.
Bram Moolenaar9d188ab2008-01-10 21:24:39 +00008758 The first item in the List is the outer region, following are
8759 items contained in that one. The last one is what |synID()|
8760 returns, unless not the whole item is highlighted or it is a
8761 transparent item.
8762 This function is useful for debugging a syntax file.
8763 Example that shows the syntax stack under the cursor: >
8764 for id in synstack(line("."), col("."))
8765 echo synIDattr(id, "name")
8766 endfor
Bram Moolenaar0bc380a2010-07-10 13:52:13 +02008767< When the position specified with {lnum} and {col} is invalid
8768 nothing is returned. The position just after the last
8769 character in a line and the first column in an empty line are
8770 valid positions.
Bram Moolenaar9d188ab2008-01-10 21:24:39 +00008771
Bram Moolenaarc0197e22004-09-13 20:26:32 +00008772system({expr} [, {input}]) *system()* *E677*
Bram Moolenaar39c29ed2014-04-05 19:44:40 +02008773 Get the output of the shell command {expr} as a string. See
8774 |systemlist()| to get the output as a List.
Bram Moolenaar57ebe6e2014-04-05 18:55:46 +02008775
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01008776 When {input} is given and is a string this string is written
8777 to a file and passed as stdin to the command. The string is
8778 written as-is, you need to take care of using the correct line
Bram Moolenaar57ebe6e2014-04-05 18:55:46 +02008779 separators yourself.
8780 If {input} is given and is a |List| it is written to the file
8781 in a way |writefile()| does with {binary} set to "b" (i.e.
8782 with a newline between each list item with newlines inside
Bram Moolenaar12c44922017-01-08 13:26:03 +01008783 list items converted to NULs).
8784 When {input} is given and is a number that is a valid id for
8785 an existing buffer then the content of the buffer is written
8786 to the file line by line, each line terminated by a NL and
8787 NULs characters where the text has a NL.
Bram Moolenaar069c1e72016-07-15 21:25:08 +02008788
8789 Pipes are not used, the 'shelltemp' option is not used.
Bram Moolenaar57ebe6e2014-04-05 18:55:46 +02008790
Bram Moolenaar04186092016-08-29 21:55:35 +02008791 When prepended by |:silent| the terminal will not be set to
Bram Moolenaar52a72462014-08-29 15:53:52 +02008792 cooked mode. This is meant to be used for commands that do
8793 not need the user to type. It avoids stray characters showing
8794 up on the screen which require |CTRL-L| to remove. >
8795 :silent let f = system('ls *.vim')
8796<
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01008797 Note: Use |shellescape()| or |::S| with |expand()| or
8798 |fnamemodify()| to escape special characters in a command
8799 argument. Newlines in {expr} may cause the command to fail.
8800 The characters in 'shellquote' and 'shellxquote' may also
Bram Moolenaar26df0922014-02-23 23:39:13 +01008801 cause trouble.
Bram Moolenaar071d4272004-06-13 20:20:40 +00008802 This is not to be used for interactive commands.
Bram Moolenaar071d4272004-06-13 20:20:40 +00008803
Bram Moolenaar05bb9532008-07-04 09:44:11 +00008804 The result is a String. Example: >
8805 :let files = system("ls " . shellescape(expand('%:h')))
Bram Moolenaar26df0922014-02-23 23:39:13 +01008806 :let files = system('ls ' . expand('%:h:S'))
Bram Moolenaar071d4272004-06-13 20:20:40 +00008807
8808< To make the result more system-independent, the shell output
8809 is filtered to replace <CR> with <NL> for Macintosh, and
8810 <CR><NL> with <NL> for DOS-like systems.
Bram Moolenaar9d98fe92013-08-03 18:35:36 +02008811 To avoid the string being truncated at a NUL, all NUL
8812 characters are replaced with SOH (0x01).
8813
Bram Moolenaar071d4272004-06-13 20:20:40 +00008814 The command executed is constructed using several options:
8815 'shell' 'shellcmdflag' 'shellxquote' {expr} 'shellredir' {tmp} 'shellxquote'
8816 ({tmp} is an automatically generated file name).
8817 For Unix and OS/2 braces are put around {expr} to allow for
8818 concatenated commands.
8819
Bram Moolenaar433f7c82006-03-21 21:29:36 +00008820 The command will be executed in "cooked" mode, so that a
8821 CTRL-C will interrupt the command (on Unix at least).
8822
Bram Moolenaar071d4272004-06-13 20:20:40 +00008823 The resulting error code can be found in |v:shell_error|.
8824 This function will fail in |restricted-mode|.
Bram Moolenaar4770d092006-01-12 23:22:24 +00008825
8826 Note that any wrong value in the options mentioned above may
8827 make the function fail. It has also been reported to fail
8828 when using a security agent application.
Bram Moolenaar071d4272004-06-13 20:20:40 +00008829 Unlike ":!cmd" there is no automatic check for changed files.
8830 Use |:checktime| to force a check.
8831
Bram Moolenaare2cc9702005-03-15 22:43:58 +00008832
Bram Moolenaar39c29ed2014-04-05 19:44:40 +02008833systemlist({expr} [, {input}]) *systemlist()*
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01008834 Same as |system()|, but returns a |List| with lines (parts of
8835 output separated by NL) with NULs transformed into NLs. Output
8836 is the same as |readfile()| will output with {binary} argument
Bram Moolenaar68563932017-01-10 13:31:15 +01008837 set to "b". Note that on MS-Windows you may get trailing CR
8838 characters.
Bram Moolenaar39c29ed2014-04-05 19:44:40 +02008839
Bram Moolenaar975b5272016-03-15 23:10:59 +01008840 Returns an empty string on error.
Bram Moolenaar39c29ed2014-04-05 19:44:40 +02008841
8842
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00008843tabpagebuflist([{arg}]) *tabpagebuflist()*
Bram Moolenaar32466aa2006-02-24 23:53:04 +00008844 The result is a |List|, where each item is the number of the
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00008845 buffer associated with each window in the current tab page.
Bram Moolenaardc1f1642016-08-16 18:33:43 +02008846 {arg} specifies the number of the tab page to be used. When
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00008847 omitted the current tab page is used.
8848 When {arg} is invalid the number zero is returned.
8849 To get a list of all buffers in all tabs use this: >
Bram Moolenaar61d35bd2012-03-28 20:51:51 +02008850 let buflist = []
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00008851 for i in range(tabpagenr('$'))
Bram Moolenaar61d35bd2012-03-28 20:51:51 +02008852 call extend(buflist, tabpagebuflist(i + 1))
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00008853 endfor
8854< Note that a buffer may appear in more than one window.
8855
8856
8857tabpagenr([{arg}]) *tabpagenr()*
Bram Moolenaar7e8fd632006-02-18 22:14:51 +00008858 The result is a Number, which is the number of the current
8859 tab page. The first tab page has number 1.
8860 When the optional argument is "$", the number of the last tab
8861 page is returned (the tab page count).
8862 The number can be used with the |:tab| command.
8863
8864
Bram Moolenaar76f3b1a2014-03-27 22:30:07 +01008865tabpagewinnr({tabarg} [, {arg}]) *tabpagewinnr()*
Bram Moolenaard04f4402010-08-15 13:30:34 +02008866 Like |winnr()| but for tab page {tabarg}.
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00008867 {tabarg} specifies the number of tab page to be used.
8868 {arg} is used like with |winnr()|:
8869 - When omitted the current window number is returned. This is
8870 the window which will be used when going to this tab page.
8871 - When "$" the number of windows is returned.
8872 - When "#" the previous window nr is returned.
8873 Useful examples: >
8874 tabpagewinnr(1) " current window of tab page 1
8875 tabpagewinnr(4, '$') " number of windows in tab page 4
8876< When {tabarg} is invalid zero is returned.
8877
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00008878 *tagfiles()*
8879tagfiles() Returns a |List| with the file names used to search for tags
8880 for the current buffer. This is the 'tags' option expanded.
8881
8882
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01008883taglist({expr} [, {filename}]) *taglist()*
Bram Moolenaare2cc9702005-03-15 22:43:58 +00008884 Returns a list of tags matching the regular expression {expr}.
Bram Moolenaarc6aafba2017-03-21 17:09:10 +01008885
8886 If {filename} is passed it is used to prioritize the results
8887 in the same way that |:tselect| does. See |tag-priority|.
8888 {filename} should be the full path of the file.
8889
Bram Moolenaard8c00872005-07-22 21:52:15 +00008890 Each list item is a dictionary with at least the following
8891 entries:
Bram Moolenaar280f1262006-01-30 00:14:18 +00008892 name Name of the tag.
8893 filename Name of the file where the tag is
Bram Moolenaaref2f6562007-05-06 13:32:59 +00008894 defined. It is either relative to the
8895 current directory or a full path.
Bram Moolenaare2cc9702005-03-15 22:43:58 +00008896 cmd Ex command used to locate the tag in
8897 the file.
Bram Moolenaar280f1262006-01-30 00:14:18 +00008898 kind Type of the tag. The value for this
Bram Moolenaare2cc9702005-03-15 22:43:58 +00008899 entry depends on the language specific
Bram Moolenaaref2f6562007-05-06 13:32:59 +00008900 kind values. Only available when
8901 using a tags file generated by
8902 Exuberant ctags or hdrtag.
Bram Moolenaar280f1262006-01-30 00:14:18 +00008903 static A file specific tag. Refer to
Bram Moolenaare2cc9702005-03-15 22:43:58 +00008904 |static-tag| for more information.
Bram Moolenaaref2f6562007-05-06 13:32:59 +00008905 More entries may be present, depending on the content of the
8906 tags file: access, implementation, inherits and signature.
8907 Refer to the ctags documentation for information about these
8908 fields. For C code the fields "struct", "class" and "enum"
8909 may appear, they give the name of the entity the tag is
8910 contained in.
Bram Moolenaar5a8684e2005-07-30 22:43:24 +00008911
Bram Moolenaar214641f2017-03-05 17:04:09 +01008912 The ex-command "cmd" can be either an ex search pattern, a
Bram Moolenaar4317d9b2005-03-18 20:25:31 +00008913 line number or a line number followed by a byte number.
Bram Moolenaare2cc9702005-03-15 22:43:58 +00008914
8915 If there are no matching tags, then an empty list is returned.
8916
8917 To get an exact tag match, the anchors '^' and '$' should be
Bram Moolenaara3e6bc92013-01-30 14:18:00 +01008918 used in {expr}. This also make the function work faster.
8919 Refer to |tag-regexp| for more information about the tag
8920 search regular expression pattern.
Bram Moolenaare2cc9702005-03-15 22:43:58 +00008921
8922 Refer to |'tags'| for information about how the tags file is
8923 located by Vim. Refer to |tags-file-format| for the format of
8924 the tags file generated by the different ctags tools.
8925
Bram Moolenaardb7c6862010-05-21 16:33:48 +02008926tan({expr}) *tan()*
Bram Moolenaar9855d6b2010-07-18 14:34:51 +02008927 Return the tangent of {expr}, measured in radians, as a |Float|
Bram Moolenaardb7c6862010-05-21 16:33:48 +02008928 in the range [-inf, inf].
Bram Moolenaar9855d6b2010-07-18 14:34:51 +02008929 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaardb7c6862010-05-21 16:33:48 +02008930 Examples: >
8931 :echo tan(10)
8932< 0.648361 >
8933 :echo tan(-4.01)
8934< -1.181502
Bram Moolenaardb84e452010-08-15 13:50:43 +02008935 {only available when compiled with the |+float| feature}
Bram Moolenaardb7c6862010-05-21 16:33:48 +02008936
8937
8938tanh({expr}) *tanh()*
Bram Moolenaar9855d6b2010-07-18 14:34:51 +02008939 Return the hyperbolic tangent of {expr} as a |Float| in the
Bram Moolenaardb7c6862010-05-21 16:33:48 +02008940 range [-1, 1].
Bram Moolenaar9855d6b2010-07-18 14:34:51 +02008941 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaardb7c6862010-05-21 16:33:48 +02008942 Examples: >
8943 :echo tanh(0.5)
8944< 0.462117 >
8945 :echo tanh(-1)
8946< -0.761594
Bram Moolenaardb84e452010-08-15 13:50:43 +02008947 {only available when compiled with the |+float| feature}
Bram Moolenaardb7c6862010-05-21 16:33:48 +02008948
8949
Bram Moolenaar574860b2016-05-24 17:33:34 +02008950tempname() *tempname()* *temp-file-name*
8951 The result is a String, which is the name of a file that
Bram Moolenaar58b85342016-08-14 19:54:54 +02008952 doesn't exist. It can be used for a temporary file. The name
Bram Moolenaar574860b2016-05-24 17:33:34 +02008953 is different for at least 26 consecutive calls. Example: >
8954 :let tmpfile = tempname()
8955 :exe "redir > " . tmpfile
8956< For Unix, the file will be in a private directory |tempfile|.
8957 For MS-Windows forward slashes are used when the 'shellslash'
8958 option is set or when 'shellcmdflag' starts with '-'.
8959
Bram Moolenaard96ff162018-02-18 22:13:29 +01008960 *term_dumpdiff()*
8961term_dumpdiff({filename}, {filename} [, {options}])
8962 Open a new window displaying the difference between the two
8963 files. The files must have been created with
8964 |term_dumpwrite()|.
8965 Returns the buffer number or zero when the diff fails.
8966 Also see |terminal-diff|.
8967 NOTE: this does not work with double-width characters yet.
8968
8969 The top part of the buffer contains the contents of the first
8970 file, the bottom part of the buffer contains the contents of
8971 the second file. The middle part shows the differences.
Bram Moolenaar95bafa22018-10-02 13:26:25 +02008972 The parts are separated by a line of equals.
Bram Moolenaard96ff162018-02-18 22:13:29 +01008973
Bram Moolenaar5a3a49e2018-03-20 18:35:53 +01008974 If the {options} argument is present, it must be a Dict with
8975 these possible members:
8976 "term_name" name to use for the buffer name, instead
8977 of the first file name.
8978 "term_rows" vertical size to use for the terminal,
Bram Moolenaar7dda86f2018-04-20 22:36:41 +02008979 instead of using 'termwinsize'
Bram Moolenaar5a3a49e2018-03-20 18:35:53 +01008980 "term_cols" horizontal size to use for the terminal,
Bram Moolenaar7dda86f2018-04-20 22:36:41 +02008981 instead of using 'termwinsize'
Bram Moolenaar5a3a49e2018-03-20 18:35:53 +01008982 "vertical" split the window vertically
8983 "curwin" use the current window, do not split the
8984 window; fails if the current buffer
8985 cannot be |abandon|ed
8986 "norestore" do not add the terminal window to a
8987 session file
Bram Moolenaard96ff162018-02-18 22:13:29 +01008988
8989 Each character in the middle part indicates a difference. If
8990 there are multiple differences only the first in this list is
8991 used:
8992 X different character
8993 w different width
8994 f different foreground color
8995 b different background color
8996 a different attribute
8997 + missing position in first file
8998 - missing position in second file
8999
9000 Using the "s" key the top and bottom parts are swapped. This
9001 makes it easy to spot a difference.
9002
9003 *term_dumpload()*
9004term_dumpload({filename} [, {options}])
9005 Open a new window displaying the contents of {filename}
9006 The file must have been created with |term_dumpwrite()|.
9007 Returns the buffer number or zero when it fails.
9008 Also see |terminal-diff|.
9009
Bram Moolenaar5a3a49e2018-03-20 18:35:53 +01009010 For {options} see |term_dumpdiff()|.
Bram Moolenaard96ff162018-02-18 22:13:29 +01009011
9012 *term_dumpwrite()*
Bram Moolenaar6bb2cdf2018-02-24 19:53:53 +01009013term_dumpwrite({buf}, {filename} [, {options}])
Bram Moolenaard96ff162018-02-18 22:13:29 +01009014 Dump the contents of the terminal screen of {buf} in the file
9015 {filename}. This uses a format that can be used with
Bram Moolenaar22f1d0e2018-02-27 14:53:30 +01009016 |term_dumpload()| and |term_dumpdiff()|.
Bram Moolenaar93a1df22018-09-10 11:51:50 +02009017 If the job in the terminal already finished an error is given:
9018 *E958*
9019 If {filename} already exists an error is given: *E953*
Bram Moolenaard96ff162018-02-18 22:13:29 +01009020 Also see |terminal-diff|.
9021
Bram Moolenaar6bb2cdf2018-02-24 19:53:53 +01009022 {options} is a dictionary with these optional entries:
9023 "rows" maximum number of rows to dump
9024 "columns" maximum number of columns to dump
9025
Bram Moolenaare41e3b42017-08-11 16:24:50 +02009026term_getaltscreen({buf}) *term_getaltscreen()*
9027 Returns 1 if the terminal of {buf} is using the alternate
9028 screen.
9029 {buf} is used as with |term_getsize()|.
9030 {only available when compiled with the |+terminal| feature}
9031
Bram Moolenaarf59c6e82018-04-10 15:59:11 +02009032term_getansicolors({buf}) *term_getansicolors()*
9033 Get the ANSI color palette in use by terminal {buf}.
9034 Returns a List of length 16 where each element is a String
9035 representing a color in hexadecimal "#rrggbb" format.
9036 Also see |term_setansicolors()| and |g:terminal_ansi_colors|.
9037 If neither was used returns the default colors.
9038
9039 {buf} is used as with |term_getsize()|. If the buffer does not
9040 exist or is not a terminal window, an empty list is returned.
9041 {only available when compiled with the |+terminal| feature and
9042 with GUI enabled and/or the |+termguicolors| feature}
9043
Bram Moolenaarc6df10e2017-07-29 20:15:08 +02009044term_getattr({attr}, {what}) *term_getattr()*
9045 Given {attr}, a value returned by term_scrape() in the "attr"
9046 item, return whether {what} is on. {what} can be one of:
9047 bold
9048 italic
9049 underline
9050 strike
9051 reverse
Bram Moolenaar45356542017-08-06 17:53:31 +02009052 {only available when compiled with the |+terminal| feature}
Bram Moolenaar74675a62017-07-15 13:53:23 +02009053
Bram Moolenaar97870002017-07-30 18:28:38 +02009054term_getcursor({buf}) *term_getcursor()*
Bram Moolenaar45356542017-08-06 17:53:31 +02009055 Get the cursor position of terminal {buf}. Returns a list with
Bram Moolenaar37c64c72017-09-19 22:06:03 +02009056 two numbers and a dictionary: [row, col, dict].
Bram Moolenaar45356542017-08-06 17:53:31 +02009057
Bram Moolenaar37c64c72017-09-19 22:06:03 +02009058 "row" and "col" are one based, the first screen cell is row
Bram Moolenaar3cd43cc2017-08-12 19:51:41 +02009059 1, column 1. This is the cursor position of the terminal
9060 itself, not of the Vim window.
9061
9062 "dict" can have these members:
9063 "visible" one when the cursor is visible, zero when it
9064 is hidden.
Bram Moolenaar95bafa22018-10-02 13:26:25 +02009065 "blink" one when the cursor is blinking, zero when it
9066 is not blinking.
Bram Moolenaar3cd43cc2017-08-12 19:51:41 +02009067 "shape" 1 for a block cursor, 2 for underline and 3
9068 for a vertical bar.
Bram Moolenaar97870002017-07-30 18:28:38 +02009069
9070 {buf} must be the buffer number of a terminal window. If the
9071 buffer does not exist or is not a terminal window, an empty
9072 list is returned.
Bram Moolenaar45356542017-08-06 17:53:31 +02009073 {only available when compiled with the |+terminal| feature}
Bram Moolenaar97870002017-07-30 18:28:38 +02009074
Bram Moolenaarc6df10e2017-07-29 20:15:08 +02009075term_getjob({buf}) *term_getjob()*
9076 Get the Job associated with terminal window {buf}.
9077 {buf} is used as with |term_getsize()|.
Bram Moolenaar7c9aec42017-08-03 13:51:25 +02009078 Returns |v:null| when there is no job.
Bram Moolenaar45356542017-08-06 17:53:31 +02009079 {only available when compiled with the |+terminal| feature}
Bram Moolenaar74675a62017-07-15 13:53:23 +02009080
Bram Moolenaarc2ce52c2017-08-01 18:35:38 +02009081term_getline({buf}, {row}) *term_getline()*
Bram Moolenaarc6df10e2017-07-29 20:15:08 +02009082 Get a line of text from the terminal window of {buf}.
9083 {buf} is used as with |term_getsize()|.
Bram Moolenaar74675a62017-07-15 13:53:23 +02009084
Bram Moolenaar45356542017-08-06 17:53:31 +02009085 The first line has {row} one. When {row} is "." the cursor
9086 line is used. When {row} is invalid an empty string is
9087 returned.
Bram Moolenaar25cdd9c2018-03-10 20:28:12 +01009088
9089 To get attributes of each character use |term_scrape()|.
Bram Moolenaar45356542017-08-06 17:53:31 +02009090 {only available when compiled with the |+terminal| feature}
Bram Moolenaar74675a62017-07-15 13:53:23 +02009091
Bram Moolenaar82b9ca02017-08-08 23:06:46 +02009092term_getscrolled({buf}) *term_getscrolled()*
9093 Return the number of lines that scrolled to above the top of
9094 terminal {buf}. This is the offset between the row number
9095 used for |term_getline()| and |getline()|, so that: >
9096 term_getline(buf, N)
9097< is equal to: >
Bram Moolenaar95bafa22018-10-02 13:26:25 +02009098 getline(N + term_getscrolled(buf))
Bram Moolenaar82b9ca02017-08-08 23:06:46 +02009099< (if that line exists).
9100
9101 {buf} is used as with |term_getsize()|.
9102 {only available when compiled with the |+terminal| feature}
9103
Bram Moolenaarc6df10e2017-07-29 20:15:08 +02009104term_getsize({buf}) *term_getsize()*
9105 Get the size of terminal {buf}. Returns a list with two
9106 numbers: [rows, cols]. This is the size of the terminal, not
9107 the window containing the terminal.
Bram Moolenaar74675a62017-07-15 13:53:23 +02009108
Bram Moolenaar7c9aec42017-08-03 13:51:25 +02009109 {buf} must be the buffer number of a terminal window. Use an
9110 empty string for the current buffer. If the buffer does not
9111 exist or is not a terminal window, an empty list is returned.
Bram Moolenaar45356542017-08-06 17:53:31 +02009112 {only available when compiled with the |+terminal| feature}
Bram Moolenaarc6df10e2017-07-29 20:15:08 +02009113
Bram Moolenaarb000e322017-07-30 19:38:21 +02009114term_getstatus({buf}) *term_getstatus()*
9115 Get the status of terminal {buf}. This returns a comma
9116 separated list of these items:
9117 running job is running
9118 finished job has finished
Bram Moolenaar45356542017-08-06 17:53:31 +02009119 normal in Terminal-Normal mode
Bram Moolenaarb000e322017-07-30 19:38:21 +02009120 One of "running" or "finished" is always present.
9121
9122 {buf} must be the buffer number of a terminal window. If the
9123 buffer does not exist or is not a terminal window, an empty
9124 string is returned.
Bram Moolenaar45356542017-08-06 17:53:31 +02009125 {only available when compiled with the |+terminal| feature}
Bram Moolenaarb000e322017-07-30 19:38:21 +02009126
9127term_gettitle({buf}) *term_gettitle()*
9128 Get the title of terminal {buf}. This is the title that the
9129 job in the terminal has set.
9130
9131 {buf} must be the buffer number of a terminal window. If the
9132 buffer does not exist or is not a terminal window, an empty
9133 string is returned.
Bram Moolenaar45356542017-08-06 17:53:31 +02009134 {only available when compiled with the |+terminal| feature}
Bram Moolenaarb000e322017-07-30 19:38:21 +02009135
Bram Moolenaar2dc9d262017-09-08 14:39:30 +02009136term_gettty({buf} [, {input}]) *term_gettty()*
Bram Moolenaar7c9aec42017-08-03 13:51:25 +02009137 Get the name of the controlling terminal associated with
Bram Moolenaar2dc9d262017-09-08 14:39:30 +02009138 terminal window {buf}. {buf} is used as with |term_getsize()|.
9139
9140 When {input} is omitted or 0, return the name for writing
9141 (stdout). When {input} is 1 return the name for reading
9142 (stdin). On UNIX, both return same name.
Bram Moolenaar45356542017-08-06 17:53:31 +02009143 {only available when compiled with the |+terminal| feature}
Bram Moolenaar7c9aec42017-08-03 13:51:25 +02009144
Bram Moolenaar22aad2f2017-07-30 18:19:46 +02009145term_list() *term_list()*
Bram Moolenaarc6df10e2017-07-29 20:15:08 +02009146 Return a list with the buffer numbers of all buffers for
9147 terminal windows.
Bram Moolenaar45356542017-08-06 17:53:31 +02009148 {only available when compiled with the |+terminal| feature}
Bram Moolenaarc6df10e2017-07-29 20:15:08 +02009149
Bram Moolenaarc2ce52c2017-08-01 18:35:38 +02009150term_scrape({buf}, {row}) *term_scrape()*
Bram Moolenaarc6df10e2017-07-29 20:15:08 +02009151 Get the contents of {row} of terminal screen of {buf}.
9152 For {buf} see |term_getsize()|.
9153
Bram Moolenaar45356542017-08-06 17:53:31 +02009154 The first line has {row} one. When {row} is "." the cursor
9155 line is used. When {row} is invalid an empty string is
9156 returned.
Bram Moolenaar22aad2f2017-07-30 18:19:46 +02009157
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01009158 Return a List containing a Dict for each screen cell:
Bram Moolenaarc6df10e2017-07-29 20:15:08 +02009159 "chars" character(s) at the cell
9160 "fg" foreground color as #rrggbb
9161 "bg" background color as #rrggbb
Bram Moolenaar7c9aec42017-08-03 13:51:25 +02009162 "attr" attributes of the cell, use |term_getattr()|
Bram Moolenaar3cd43cc2017-08-12 19:51:41 +02009163 to get the individual flags
Bram Moolenaarc6df10e2017-07-29 20:15:08 +02009164 "width" cell width: 1 or 2
Bram Moolenaar45356542017-08-06 17:53:31 +02009165 {only available when compiled with the |+terminal| feature}
Bram Moolenaarc6df10e2017-07-29 20:15:08 +02009166
9167term_sendkeys({buf}, {keys}) *term_sendkeys()*
9168 Send keystrokes {keys} to terminal {buf}.
9169 {buf} is used as with |term_getsize()|.
9170
9171 {keys} are translated as key sequences. For example, "\<c-x>"
9172 means the character CTRL-X.
Bram Moolenaar45356542017-08-06 17:53:31 +02009173 {only available when compiled with the |+terminal| feature}
Bram Moolenaarc6df10e2017-07-29 20:15:08 +02009174
Bram Moolenaarf59c6e82018-04-10 15:59:11 +02009175term_setansicolors({buf}, {colors}) *term_setansicolors()*
9176 Set the ANSI color palette used by terminal {buf}.
9177 {colors} must be a List of 16 valid color names or hexadecimal
9178 color codes, like those accepted by |highlight-guifg|.
9179 Also see |term_getansicolors()| and |g:terminal_ansi_colors|.
9180
Bram Moolenaara42d3632018-04-14 17:05:38 +02009181 The colors normally are:
9182 0 black
9183 1 dark red
9184 2 dark green
9185 3 brown
9186 4 dark blue
9187 5 dark magenta
9188 6 dark cyan
9189 7 light grey
9190 8 dark grey
9191 9 red
9192 10 green
9193 11 yellow
9194 12 blue
9195 13 magenta
9196 14 cyan
9197 15 white
9198
Bram Moolenaarf59c6e82018-04-10 15:59:11 +02009199 These colors are used in the GUI and in the terminal when
9200 'termguicolors' is set. When not using GUI colors (GUI mode
Bram Moolenaar7dda86f2018-04-20 22:36:41 +02009201 or 'termguicolors'), the terminal window always uses the 16
Bram Moolenaarf59c6e82018-04-10 15:59:11 +02009202 ANSI colors of the underlying terminal.
9203 {only available when compiled with the |+terminal| feature and
9204 with GUI enabled and/or the |+termguicolors| feature}
9205
Bram Moolenaar25cdd9c2018-03-10 20:28:12 +01009206term_setkill({buf}, {how}) *term_setkill()*
9207 When exiting Vim or trying to close the terminal window in
9208 another way, {how} defines whether the job in the terminal can
9209 be stopped.
9210 When {how} is empty (the default), the job will not be
9211 stopped, trying to exit will result in |E947|.
9212 Otherwise, {how} specifies what signal to send to the job.
9213 See |job_stop()| for the values.
9214
9215 After sending the signal Vim will wait for up to a second to
9216 check that the job actually stopped.
9217
Bram Moolenaarb5b75622018-03-09 22:22:21 +01009218term_setrestore({buf}, {command}) *term_setrestore()*
9219 Set the command to write in a session file to restore the job
9220 in this terminal. The line written in the session file is: >
9221 terminal ++curwin ++cols=%d ++rows=%d {command}
9222< Make sure to escape the command properly.
9223
9224 Use an empty {command} to run 'shell'.
9225 Use "NONE" to not restore this window.
9226 {only available when compiled with the |+terminal| feature}
9227
Bram Moolenaar7dda86f2018-04-20 22:36:41 +02009228term_setsize({buf}, {rows}, {cols}) *term_setsize()* *E955*
Bram Moolenaara42d3632018-04-14 17:05:38 +02009229 Set the size of terminal {buf}. The size of the window
9230 containing the terminal will also be adjusted, if possible.
9231 If {rows} or {cols} is zero or negative, that dimension is not
9232 changed.
9233
9234 {buf} must be the buffer number of a terminal window. Use an
9235 empty string for the current buffer. If the buffer does not
9236 exist or is not a terminal window, an error is given.
Bram Moolenaar37c64c72017-09-19 22:06:03 +02009237 {only available when compiled with the |+terminal| feature}
9238
Bram Moolenaarc6df10e2017-07-29 20:15:08 +02009239term_start({cmd}, {options}) *term_start()*
9240 Open a terminal window and run {cmd} in it.
9241
Bram Moolenaar01164a62017-11-02 22:58:42 +01009242 {cmd} can be a string or a List, like with |job_start()|. The
9243 string "NONE" can be used to open a terminal window without
9244 starting a job, the pty of the terminal can be used by a
9245 command like gdb.
9246
Bram Moolenaar08d384f2017-08-11 21:51:23 +02009247 Returns the buffer number of the terminal window. If {cmd}
9248 cannot be executed the window does open and shows an error
9249 message.
9250 If opening the window fails zero is returned.
Bram Moolenaarc6df10e2017-07-29 20:15:08 +02009251
Bram Moolenaar78712a72017-08-05 14:50:12 +02009252 {options} are similar to what is used for |job_start()|, see
9253 |job-options|. However, not all options can be used. These
9254 are supported:
9255 all timeout options
Bram Moolenaard473c8c2018-08-11 18:00:22 +02009256 "stoponexit", "cwd", "env"
9257 "callback", "out_cb", "err_cb", "exit_cb", "close_cb"
Bram Moolenaar78712a72017-08-05 14:50:12 +02009258 "in_io", "in_top", "in_bot", "in_name", "in_buf"
9259 "out_io", "out_name", "out_buf", "out_modifiable", "out_msg"
9260 "err_io", "err_name", "err_buf", "err_modifiable", "err_msg"
9261 However, at least one of stdin, stdout or stderr must be
9262 connected to the terminal. When I/O is connected to the
9263 terminal then the callback function for that part is not used.
9264
Bram Moolenaar08d384f2017-08-11 21:51:23 +02009265 There are extra options:
Bram Moolenaardd693ce2017-08-10 23:15:19 +02009266 "term_name" name to use for the buffer name, instead
9267 of the command name.
Bram Moolenaar08d384f2017-08-11 21:51:23 +02009268 "term_rows" vertical size to use for the terminal,
Bram Moolenaar7dda86f2018-04-20 22:36:41 +02009269 instead of using 'termwinsize'
Bram Moolenaar08d384f2017-08-11 21:51:23 +02009270 "term_cols" horizontal size to use for the terminal,
Bram Moolenaar7dda86f2018-04-20 22:36:41 +02009271 instead of using 'termwinsize'
Bram Moolenaar0e5979a2018-06-17 19:36:33 +02009272 "vertical" split the window vertically; note that
9273 other window position can be defined with
9274 command modifiers, such as |:belowright|.
Bram Moolenaarda43b612017-08-11 22:27:50 +02009275 "curwin" use the current window, do not split the
9276 window; fails if the current buffer
9277 cannot be |abandon|ed
Bram Moolenaarb4d5fba2017-09-11 19:31:28 +02009278 "hidden" do not open a window
Bram Moolenaarb5b75622018-03-09 22:22:21 +01009279 "norestore" do not add the terminal window to a
9280 session file
Bram Moolenaar25cdd9c2018-03-10 20:28:12 +01009281 "term_kill" what to do when trying to close the
9282 terminal window, see |term_setkill()|
Bram Moolenaar08d384f2017-08-11 21:51:23 +02009283 "term_finish" What to do when the job is finished:
Bram Moolenaardd693ce2017-08-10 23:15:19 +02009284 "close": close any windows
9285 "open": open window if needed
9286 Note that "open" can be interruptive.
9287 See |term++close| and |term++open|.
Bram Moolenaar37c45832017-08-12 16:01:04 +02009288 "term_opencmd" command to use for opening the window when
9289 "open" is used for "term_finish"; must
9290 have "%d" where the buffer number goes,
9291 e.g. "10split|buffer %d"; when not
9292 specified "botright sbuf %d" is used
Bram Moolenaaref68e4f2017-09-02 16:28:36 +02009293 "eof_chars" Text to send after all buffer lines were
9294 written to the terminal. When not set
Bram Moolenaar2dc9d262017-09-08 14:39:30 +02009295 CTRL-D is used on MS-Windows. For Python
9296 use CTRL-Z or "exit()". For a shell use
9297 "exit". A CR is always added.
Bram Moolenaarf59c6e82018-04-10 15:59:11 +02009298 "ansi_colors" A list of 16 color names or hex codes
9299 defining the ANSI palette used in GUI
9300 color modes. See |g:terminal_ansi_colors|.
Bram Moolenaar37c45832017-08-12 16:01:04 +02009301
Bram Moolenaar45356542017-08-06 17:53:31 +02009302 {only available when compiled with the |+terminal| feature}
Bram Moolenaarc6df10e2017-07-29 20:15:08 +02009303
Bram Moolenaarf3402b12017-08-06 19:07:08 +02009304term_wait({buf} [, {time}]) *term_wait()*
Bram Moolenaarc6df10e2017-07-29 20:15:08 +02009305 Wait for pending updates of {buf} to be handled.
9306 {buf} is used as with |term_getsize()|.
Bram Moolenaarf3402b12017-08-06 19:07:08 +02009307 {time} is how long to wait for updates to arrive in msec. If
9308 not set then 10 msec will be used.
Bram Moolenaar45356542017-08-06 17:53:31 +02009309 {only available when compiled with the |+terminal| feature}
Bram Moolenaar574860b2016-05-24 17:33:34 +02009310
Bram Moolenaar8e8df252016-05-25 21:23:21 +02009311test_alloc_fail({id}, {countdown}, {repeat}) *test_alloc_fail()*
9312 This is for testing: If the memory allocation with {id} is
9313 called, then decrement {countdown}, and when it reaches zero
9314 let memory allocation fail {repeat} times. When {repeat} is
9315 smaller than one it fails one time.
9316
Bram Moolenaar6f1d9a02016-07-24 14:12:38 +02009317test_autochdir() *test_autochdir()*
9318 Set a flag to enable the effect of 'autochdir' before Vim
9319 startup has finished.
Bram Moolenaar8e8df252016-05-25 21:23:21 +02009320
Bram Moolenaar5e80de32017-09-03 15:48:12 +02009321test_feedinput({string}) *test_feedinput()*
9322 Characters in {string} are queued for processing as if they
9323 were typed by the user. This uses a low level input buffer.
9324 This function works only when with |+unix| or GUI is running.
9325
Bram Moolenaar574860b2016-05-24 17:33:34 +02009326test_garbagecollect_now() *test_garbagecollect_now()*
9327 Like garbagecollect(), but executed right away. This must
9328 only be called directly to avoid any structure to exist
9329 internally, and |v:testing| must have been set before calling
9330 any function.
9331
Bram Moolenaare0c31f62017-03-01 15:07:05 +01009332test_ignore_error({expr}) *test_ignore_error()*
9333 Ignore any error containing {expr}. A normal message is given
9334 instead.
9335 This is only meant to be used in tests, where catching the
9336 error with try/catch cannot be used (because it skips over
9337 following code).
9338 {expr} is used literally, not as a pattern.
Bram Moolenaar461a7fc2018-12-22 13:28:07 +01009339 When the {expr} is the string "RESET" then the list of ignored
9340 errors is made empty.
Bram Moolenaare0c31f62017-03-01 15:07:05 +01009341
Bram Moolenaarc0f5a782019-01-13 15:16:13 +01009342test_null_blob() *test_null_blob()*
9343 Return a |Blob| that is null. Only useful for testing.
9344
Bram Moolenaar574860b2016-05-24 17:33:34 +02009345test_null_channel() *test_null_channel()*
Bram Moolenaarc0f5a782019-01-13 15:16:13 +01009346 Return a |Channel| that is null. Only useful for testing.
Bram Moolenaar574860b2016-05-24 17:33:34 +02009347 {only available when compiled with the +channel feature}
9348
9349test_null_dict() *test_null_dict()*
Bram Moolenaarc0f5a782019-01-13 15:16:13 +01009350 Return a |Dict| that is null. Only useful for testing.
Bram Moolenaar574860b2016-05-24 17:33:34 +02009351
9352test_null_job() *test_null_job()*
Bram Moolenaarc0f5a782019-01-13 15:16:13 +01009353 Return a |Job| that is null. Only useful for testing.
Bram Moolenaar574860b2016-05-24 17:33:34 +02009354 {only available when compiled with the +job feature}
9355
9356test_null_list() *test_null_list()*
Bram Moolenaarc0f5a782019-01-13 15:16:13 +01009357 Return a |List| that is null. Only useful for testing.
Bram Moolenaar574860b2016-05-24 17:33:34 +02009358
9359test_null_partial() *test_null_partial()*
Bram Moolenaarc0f5a782019-01-13 15:16:13 +01009360 Return a |Partial| that is null. Only useful for testing.
Bram Moolenaar574860b2016-05-24 17:33:34 +02009361
9362test_null_string() *test_null_string()*
Bram Moolenaarc0f5a782019-01-13 15:16:13 +01009363 Return a |String| that is null. Only useful for testing.
Bram Moolenaar574860b2016-05-24 17:33:34 +02009364
Bram Moolenaarfe8ef982018-09-13 20:31:54 +02009365test_option_not_set({name}) *test_option_not_set()*
9366 Reset the flag that indicates option {name} was set. Thus it
9367 looks like it still has the default value. Use like this: >
9368 set ambiwidth=double
9369 call test_option_not_set('ambiwidth')
9370< Now the 'ambiwidth' option behaves like it was never changed,
9371 even though the value is "double".
9372 Only to be used for testing!
9373
Bram Moolenaar036986f2017-03-16 17:41:02 +01009374test_override({name}, {val}) *test_override()*
Bram Moolenaar9d87a372018-12-18 21:41:50 +01009375 Overrides certain parts of Vim's internal processing to be able
Bram Moolenaar036986f2017-03-16 17:41:02 +01009376 to run tests. Only to be used for testing Vim!
9377 The override is enabled when {val} is non-zero and removed
9378 when {val} is zero.
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01009379 Current supported values for name are:
Bram Moolenaar036986f2017-03-16 17:41:02 +01009380
9381 name effect when {val} is non-zero ~
9382 redraw disable the redrawing() function
Bram Moolenaared5a9d62018-09-06 13:14:43 +02009383 redraw_flag ignore the RedrawingDisabled flag
Bram Moolenaar036986f2017-03-16 17:41:02 +01009384 char_avail disable the char_avail() function
Bram Moolenaar182a17b2017-06-25 20:57:18 +02009385 starting reset the "starting" variable, see below
Bram Moolenaarbcf94422018-06-23 14:21:42 +02009386 nfa_fail makes the NFA regexp engine fail to force a
9387 fallback to the old engine
Bram Moolenaar036986f2017-03-16 17:41:02 +01009388 ALL clear all overrides ({val} is not used)
9389
Bram Moolenaar182a17b2017-06-25 20:57:18 +02009390 "starting" is to be used when a test should behave like
9391 startup was done. Since the tests are run by sourcing a
9392 script the "starting" variable is non-zero. This is usually a
9393 good thing (tests run faster), but sometimes changes behavior
9394 in a way that the test doesn't work properly.
9395 When using: >
9396 call test_override('starting', 1)
Bram Moolenaar3cd43cc2017-08-12 19:51:41 +02009397< The value of "starting" is saved. It is restored by: >
Bram Moolenaar182a17b2017-06-25 20:57:18 +02009398 call test_override('starting', 0)
9399
Bram Moolenaarab186732018-09-14 21:27:06 +02009400test_scrollbar({which}, {value}, {dragging}) *test_scrollbar()*
9401 Pretend using scrollbar {which} to move it to position
9402 {value}. {which} can be:
9403 left Left scrollbar of the current window
9404 right Right scrollbar of the current window
9405 hor Horizontal scrollbar
9406
9407 For the vertical scrollbars {value} can be 1 to the
9408 line-count of the buffer. For the horizontal scrollbar the
9409 {value} can be between 1 and the maximum line length, assuming
9410 'wrap' is not set.
9411
9412 When {dragging} is non-zero it's like dragging the scrollbar,
9413 otherwise it's like clicking in the scrollbar.
9414 Only works when the {which} scrollbar actually exists,
9415 obviously only when using the GUI.
9416
Bram Moolenaarc95a3022016-06-12 23:01:46 +02009417test_settime({expr}) *test_settime()*
9418 Set the time Vim uses internally. Currently only used for
Bram Moolenaar1e96d9b2016-07-29 22:15:09 +02009419 timestamps in the history, as they are used in viminfo, and
9420 for undo.
Bram Moolenaar3df01732017-02-17 22:47:16 +01009421 Using a value of 1 makes Vim not sleep after a warning or
9422 error message.
Bram Moolenaarc95a3022016-06-12 23:01:46 +02009423 {expr} must evaluate to a number. When the value is zero the
9424 normal behavior is restored.
Bram Moolenaar574860b2016-05-24 17:33:34 +02009425
Bram Moolenaar8e97bd72016-08-06 22:05:07 +02009426 *timer_info()*
9427timer_info([{id}])
9428 Return a list with information about timers.
9429 When {id} is given only information about this timer is
9430 returned. When timer {id} does not exist an empty list is
9431 returned.
9432 When {id} is omitted information about all timers is returned.
9433
9434 For each timer the information is stored in a Dictionary with
9435 these items:
9436 "id" the timer ID
9437 "time" time the timer was started with
9438 "remaining" time until the timer fires
9439 "repeat" number of times the timer will still fire;
Bram Moolenaarb73598e2016-08-07 18:22:53 +02009440 -1 means forever
Bram Moolenaar8e97bd72016-08-06 22:05:07 +02009441 "callback" the callback
Bram Moolenaarb73598e2016-08-07 18:22:53 +02009442 "paused" 1 if the timer is paused, 0 otherwise
9443
9444 {only available when compiled with the |+timers| feature}
9445
9446timer_pause({timer}, {paused}) *timer_pause()*
9447 Pause or unpause a timer. A paused timer does not invoke its
Bram Moolenaardc1f1642016-08-16 18:33:43 +02009448 callback when its time expires. Unpausing a timer may cause
9449 the callback to be invoked almost immediately if enough time
9450 has passed.
Bram Moolenaarb73598e2016-08-07 18:22:53 +02009451
9452 Pausing a timer is useful to avoid the callback to be called
9453 for a short time.
9454
9455 If {paused} evaluates to a non-zero Number or a non-empty
9456 String, then the timer is paused, otherwise it is unpaused.
9457 See |non-zero-arg|.
9458
9459 {only available when compiled with the |+timers| feature}
Bram Moolenaar8e97bd72016-08-06 22:05:07 +02009460
Bram Moolenaardc1f1642016-08-16 18:33:43 +02009461 *timer_start()* *timer* *timers*
Bram Moolenaar975b5272016-03-15 23:10:59 +01009462timer_start({time}, {callback} [, {options}])
9463 Create a timer and return the timer ID.
9464
9465 {time} is the waiting time in milliseconds. This is the
9466 minimum time before invoking the callback. When the system is
9467 busy or Vim is not waiting for input the time will be longer.
9468
9469 {callback} is the function to call. It can be the name of a
Bram Moolenaarf37506f2016-08-31 22:22:10 +02009470 function or a |Funcref|. It is called with one argument, which
Bram Moolenaar975b5272016-03-15 23:10:59 +01009471 is the timer ID. The callback is only invoked when Vim is
9472 waiting for input.
9473
9474 {options} is a dictionary. Supported entries:
9475 "repeat" Number of times to repeat calling the
Bram Moolenaarabd468e2016-09-08 22:22:43 +02009476 callback. -1 means forever. When not present
9477 the callback will be called once.
Bram Moolenaarc577d812017-07-08 22:37:34 +02009478 If the timer causes an error three times in a
9479 row the repeat is cancelled. This avoids that
9480 Vim becomes unusable because of all the error
9481 messages.
Bram Moolenaar975b5272016-03-15 23:10:59 +01009482
9483 Example: >
9484 func MyHandler(timer)
9485 echo 'Handler called'
9486 endfunc
9487 let timer = timer_start(500, 'MyHandler',
9488 \ {'repeat': 3})
9489< This will invoke MyHandler() three times at 500 msec
9490 intervals.
Bram Moolenaarb73598e2016-08-07 18:22:53 +02009491
Bram Moolenaar975b5272016-03-15 23:10:59 +01009492 {only available when compiled with the |+timers| feature}
9493
Bram Moolenaar03602ec2016-03-20 20:57:45 +01009494timer_stop({timer}) *timer_stop()*
Bram Moolenaar06d2d382016-05-20 17:24:11 +02009495 Stop a timer. The timer callback will no longer be invoked.
9496 {timer} is an ID returned by timer_start(), thus it must be a
Bram Moolenaar8e97bd72016-08-06 22:05:07 +02009497 Number. If {timer} does not exist there is no error.
Bram Moolenaar03602ec2016-03-20 20:57:45 +01009498
Bram Moolenaarb73598e2016-08-07 18:22:53 +02009499 {only available when compiled with the |+timers| feature}
9500
9501timer_stopall() *timer_stopall()*
9502 Stop all timers. The timer callbacks will no longer be
9503 invoked. Useful if some timers is misbehaving. If there are
9504 no timers there is no error.
9505
9506 {only available when compiled with the |+timers| feature}
9507
Bram Moolenaar071d4272004-06-13 20:20:40 +00009508tolower({expr}) *tolower()*
9509 The result is a copy of the String given, with all uppercase
9510 characters turned into lowercase (just like applying |gu| to
9511 the string).
9512
9513toupper({expr}) *toupper()*
9514 The result is a copy of the String given, with all lowercase
9515 characters turned into uppercase (just like applying |gU| to
9516 the string).
9517
Bram Moolenaar8299df92004-07-10 09:47:34 +00009518tr({src}, {fromstr}, {tostr}) *tr()*
9519 The result is a copy of the {src} string with all characters
9520 which appear in {fromstr} replaced by the character in that
9521 position in the {tostr} string. Thus the first character in
9522 {fromstr} is translated into the first character in {tostr}
9523 and so on. Exactly like the unix "tr" command.
9524 This code also deals with multibyte characters properly.
9525
9526 Examples: >
9527 echo tr("hello there", "ht", "HT")
9528< returns "Hello THere" >
9529 echo tr("<blob>", "<>", "{}")
9530< returns "{blob}"
9531
Bram Moolenaard473c8c2018-08-11 18:00:22 +02009532trim({text} [, {mask}]) *trim()*
Bram Moolenaar295ac5a2018-03-22 23:04:02 +01009533 Return {text} as a String where any character in {mask} is
9534 removed from the beginning and end of {text}.
9535 If {mask} is not given, {mask} is all characters up to 0x20,
9536 which includes Tab, space, NL and CR, plus the non-breaking
9537 space character 0xa0.
9538 This code deals with multibyte characters properly.
9539
9540 Examples: >
Bram Moolenaarab943432018-03-29 18:27:07 +02009541 echo trim(" some text ")
9542< returns "some text" >
9543 echo trim(" \r\t\t\r RESERVE \t\n\x0B\xA0") . "_TAIL"
Bram Moolenaar295ac5a2018-03-22 23:04:02 +01009544< returns "RESERVE_TAIL" >
Bram Moolenaarab943432018-03-29 18:27:07 +02009545 echo trim("rm<Xrm<>X>rrm", "rm<>")
9546< returns "Xrm<>X" (characters in the middle are not removed)
Bram Moolenaar295ac5a2018-03-22 23:04:02 +01009547
Bram Moolenaar446cb832008-06-24 21:56:24 +00009548trunc({expr}) *trunc()*
Bram Moolenaarc236c162008-07-13 17:41:49 +00009549 Return the largest integral value with magnitude less than or
Bram Moolenaar446cb832008-06-24 21:56:24 +00009550 equal to {expr} as a |Float| (truncate towards zero).
9551 {expr} must evaluate to a |Float| or a |Number|.
9552 Examples: >
9553 echo trunc(1.456)
9554< 1.0 >
9555 echo trunc(-5.456)
9556< -5.0 >
9557 echo trunc(4.0)
9558< 4.0
9559 {only available when compiled with the |+float| feature}
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01009560
Bram Moolenaar9588a0f2005-01-08 21:45:39 +00009561 *type()*
Bram Moolenaardf48fb42016-07-22 21:50:18 +02009562type({expr}) The result is a Number representing the type of {expr}.
9563 Instead of using the number directly, it is better to use the
9564 v:t_ variable that has the value:
9565 Number: 0 |v:t_number|
9566 String: 1 |v:t_string|
9567 Funcref: 2 |v:t_func|
9568 List: 3 |v:t_list|
9569 Dictionary: 4 |v:t_dict|
9570 Float: 5 |v:t_float|
9571 Boolean: 6 |v:t_bool| (v:false and v:true)
9572 None 7 |v:t_none| (v:null and v:none)
9573 Job 8 |v:t_job|
9574 Channel 9 |v:t_channel|
Bram Moolenaar6e5ea8d2019-01-12 22:47:31 +01009575 Blob 10 |v:t_blob|
Bram Moolenaardf48fb42016-07-22 21:50:18 +02009576 For backward compatibility, this method can be used: >
Bram Moolenaar9588a0f2005-01-08 21:45:39 +00009577 :if type(myvar) == type(0)
9578 :if type(myvar) == type("")
9579 :if type(myvar) == type(function("tr"))
9580 :if type(myvar) == type([])
Bram Moolenaar748bf032005-02-02 23:04:36 +00009581 :if type(myvar) == type({})
Bram Moolenaar446cb832008-06-24 21:56:24 +00009582 :if type(myvar) == type(0.0)
Bram Moolenaar705ada12016-01-24 17:56:50 +01009583 :if type(myvar) == type(v:false)
Bram Moolenaar6463ca22016-02-13 17:04:46 +01009584 :if type(myvar) == type(v:none)
Bram Moolenaardf48fb42016-07-22 21:50:18 +02009585< To check if the v:t_ variables exist use this: >
9586 :if exists('v:t_number')
Bram Moolenaar071d4272004-06-13 20:20:40 +00009587
Bram Moolenaara17d4c12010-05-30 18:30:36 +02009588undofile({name}) *undofile()*
9589 Return the name of the undo file that would be used for a file
9590 with name {name} when writing. This uses the 'undodir'
9591 option, finding directories that exist. It does not check if
Bram Moolenaar860cae12010-06-05 23:22:07 +02009592 the undo file exists.
Bram Moolenaar945e2db2010-06-05 17:43:32 +02009593 {name} is always expanded to the full path, since that is what
9594 is used internally.
Bram Moolenaar80716072012-05-01 21:14:34 +02009595 If {name} is empty undofile() returns an empty string, since a
9596 buffer without a file name will not write an undo file.
Bram Moolenaara17d4c12010-05-30 18:30:36 +02009597 Useful in combination with |:wundo| and |:rundo|.
Bram Moolenaarb328cca2019-01-06 16:24:01 +01009598 When compiled without the |+persistent_undo| option this always
Bram Moolenaara17d4c12010-05-30 18:30:36 +02009599 returns an empty string.
9600
Bram Moolenaara800b422010-06-27 01:15:55 +02009601undotree() *undotree()*
9602 Return the current state of the undo tree in a dictionary with
9603 the following items:
9604 "seq_last" The highest undo sequence number used.
9605 "seq_cur" The sequence number of the current position in
9606 the undo tree. This differs from "seq_last"
9607 when some changes were undone.
9608 "time_cur" Time last used for |:earlier| and related
9609 commands. Use |strftime()| to convert to
9610 something readable.
9611 "save_last" Number of the last file write. Zero when no
9612 write yet.
Bram Moolenaar730cde92010-06-27 05:18:54 +02009613 "save_cur" Number of the current position in the undo
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01009614 tree.
Bram Moolenaara800b422010-06-27 01:15:55 +02009615 "synced" Non-zero when the last undo block was synced.
9616 This happens when waiting from input from the
9617 user. See |undo-blocks|.
9618 "entries" A list of dictionaries with information about
9619 undo blocks.
9620
9621 The first item in the "entries" list is the oldest undo item.
9622 Each List item is a Dictionary with these items:
9623 "seq" Undo sequence number. Same as what appears in
9624 |:undolist|.
9625 "time" Timestamp when the change happened. Use
9626 |strftime()| to convert to something readable.
9627 "newhead" Only appears in the item that is the last one
9628 that was added. This marks the last change
9629 and where further changes will be added.
9630 "curhead" Only appears in the item that is the last one
9631 that was undone. This marks the current
9632 position in the undo tree, the block that will
9633 be used by a redo command. When nothing was
9634 undone after the last change this item will
9635 not appear anywhere.
9636 "save" Only appears on the last block before a file
9637 write. The number is the write count. The
9638 first write has number 1, the last one the
9639 "save_last" mentioned above.
9640 "alt" Alternate entry. This is again a List of undo
9641 blocks. Each item may again have an "alt"
9642 item.
9643
Bram Moolenaar327aa022014-03-25 18:24:23 +01009644uniq({list} [, {func} [, {dict}]]) *uniq()* *E882*
9645 Remove second and succeeding copies of repeated adjacent
9646 {list} items in-place. Returns {list}. If you want a list
9647 to remain unmodified make a copy first: >
9648 :let newlist = uniq(copy(mylist))
9649< The default compare function uses the string representation of
9650 each item. For the use of {func} and {dict} see |sort()|.
9651
Bram Moolenaar677ee682005-01-27 14:41:15 +00009652values({dict}) *values()*
Bram Moolenaar58b85342016-08-14 19:54:54 +02009653 Return a |List| with all the values of {dict}. The |List| is
Bram Moolenaar32466aa2006-02-24 23:53:04 +00009654 in arbitrary order.
Bram Moolenaar677ee682005-01-27 14:41:15 +00009655
9656
Bram Moolenaar071d4272004-06-13 20:20:40 +00009657virtcol({expr}) *virtcol()*
9658 The result is a Number, which is the screen column of the file
9659 position given with {expr}. That is, the last screen position
9660 occupied by the character at that position, when the screen
9661 would be of unlimited width. When there is a <Tab> at the
9662 position, the returned Number will be the column at the end of
9663 the <Tab>. For example, for a <Tab> in column 1, with 'ts'
Bram Moolenaar61d35bd2012-03-28 20:51:51 +02009664 set to 8, it returns 8. |conceal| is ignored.
Bram Moolenaar477933c2007-07-17 14:32:23 +00009665 For the byte position use |col()|.
9666 For the use of {expr} see |col()|.
9667 When 'virtualedit' is used {expr} can be [lnum, col, off], where
Bram Moolenaar0b238792006-03-02 22:49:12 +00009668 "off" is the offset in screen columns from the start of the
Bram Moolenaard46bbc72007-05-12 14:38:41 +00009669 character. E.g., a position within a <Tab> or after the last
Bram Moolenaar97293012011-07-18 19:40:27 +02009670 character. When "off" is omitted zero is used.
Bram Moolenaar071d4272004-06-13 20:20:40 +00009671 When Virtual editing is active in the current mode, a position
9672 beyond the end of the line can be returned. |'virtualedit'|
9673 The accepted positions are:
9674 . the cursor position
9675 $ the end of the cursor line (the result is the
9676 number of displayed characters in the cursor line
9677 plus one)
9678 'x position of mark x (if the mark is not set, 0 is
9679 returned)
Bram Moolenaare3faf442014-12-14 01:27:49 +01009680 v In Visual mode: the start of the Visual area (the
9681 cursor is the end). When not in Visual mode
9682 returns the cursor position. Differs from |'<| in
9683 that it's updated right away.
Bram Moolenaar071d4272004-06-13 20:20:40 +00009684 Note that only marks in the current file can be used.
9685 Examples: >
9686 virtcol(".") with text "foo^Lbar", with cursor on the "^L", returns 5
9687 virtcol("$") with text "foo^Lbar", returns 9
Bram Moolenaar446cb832008-06-24 21:56:24 +00009688 virtcol("'t") with text " there", with 't at 'h', returns 6
Bram Moolenaar58b85342016-08-14 19:54:54 +02009689< The first column is 1. 0 is returned for an error.
Bram Moolenaaref2f6562007-05-06 13:32:59 +00009690 A more advanced example that echoes the maximum length of
9691 all lines: >
9692 echo max(map(range(1, line('$')), "virtcol([v:val, '$'])"))
9693
Bram Moolenaar071d4272004-06-13 20:20:40 +00009694
9695visualmode([expr]) *visualmode()*
9696 The result is a String, which describes the last Visual mode
Bram Moolenaarc9b4b052006-04-30 18:54:39 +00009697 used in the current buffer. Initially it returns an empty
9698 string, but once Visual mode has been used, it returns "v",
9699 "V", or "<CTRL-V>" (a single CTRL-V character) for
9700 character-wise, line-wise, or block-wise Visual mode
9701 respectively.
Bram Moolenaar071d4272004-06-13 20:20:40 +00009702 Example: >
9703 :exe "normal " . visualmode()
9704< This enters the same Visual mode as before. It is also useful
9705 in scripts if you wish to act differently depending on the
9706 Visual mode that was used.
Bram Moolenaar446cb832008-06-24 21:56:24 +00009707 If Visual mode is active, use |mode()| to get the Visual mode
9708 (e.g., in a |:vmap|).
Bram Moolenaar05bb9532008-07-04 09:44:11 +00009709 If [expr] is supplied and it evaluates to a non-zero Number or
9710 a non-empty String, then the Visual mode will be cleared and
Bram Moolenaare381d3d2016-07-07 14:50:41 +02009711 the old value is returned. See |non-zero-arg|.
Bram Moolenaar071d4272004-06-13 20:20:40 +00009712
Bram Moolenaar8738fc12013-02-20 17:59:11 +01009713wildmenumode() *wildmenumode()*
Bram Moolenaare381d3d2016-07-07 14:50:41 +02009714 Returns |TRUE| when the wildmenu is active and |FALSE|
Bram Moolenaar8738fc12013-02-20 17:59:11 +01009715 otherwise. See 'wildmenu' and 'wildmode'.
9716 This can be used in mappings to handle the 'wildcharm' option
9717 gracefully. (Makes only sense with |mapmode-c| mappings).
9718
9719 For example to make <c-j> work like <down> in wildmode, use: >
9720 :cnoremap <expr> <C-j> wildmenumode() ? "\<Down>\<Tab>" : "\<c-j>"
9721<
9722 (Note, this needs the 'wildcharm' option set appropriately).
9723
9724
Bram Moolenaar9cdf86b2016-03-13 19:04:51 +01009725win_findbuf({bufnr}) *win_findbuf()*
Bram Moolenaar7571d552016-08-18 22:54:46 +02009726 Returns a list with |window-ID|s for windows that contain
9727 buffer {bufnr}. When there is none the list is empty.
Bram Moolenaar9cdf86b2016-03-13 19:04:51 +01009728
Bram Moolenaar86edef62016-03-13 18:07:30 +01009729win_getid([{win} [, {tab}]]) *win_getid()*
Bram Moolenaar7571d552016-08-18 22:54:46 +02009730 Get the |window-ID| for the specified window.
Bram Moolenaar86edef62016-03-13 18:07:30 +01009731 When {win} is missing use the current window.
9732 With {win} this is the window number. The top window has
Bram Moolenaarba3ff532018-11-04 14:45:49 +01009733 number 1.
Bram Moolenaar86edef62016-03-13 18:07:30 +01009734 Without {tab} use the current tab, otherwise the tab with
9735 number {tab}. The first tab has number one.
9736 Return zero if the window cannot be found.
9737
9738win_gotoid({expr}) *win_gotoid()*
9739 Go to window with ID {expr}. This may also change the current
9740 tabpage.
9741 Return 1 if successful, 0 if the window cannot be found.
9742
Bram Moolenaar03413f42016-04-12 21:07:15 +02009743win_id2tabwin({expr}) *win_id2tabwin()*
Bram Moolenaar86edef62016-03-13 18:07:30 +01009744 Return a list with the tab number and window number of window
9745 with ID {expr}: [tabnr, winnr].
9746 Return [0, 0] if the window cannot be found.
9747
9748win_id2win({expr}) *win_id2win()*
9749 Return the window number of window with ID {expr}.
9750 Return 0 if the window cannot be found in the current tabpage.
9751
Bram Moolenaar22044dc2017-12-02 15:43:37 +01009752win_screenpos({nr}) *win_screenpos()*
9753 Return the screen position of window {nr} as a list with two
9754 numbers: [row, col]. The first window always has position
Bram Moolenaar7132ddc2018-07-15 17:01:11 +02009755 [1, 1], unless there is a tabline, then it is [2, 1].
Bram Moolenaar22044dc2017-12-02 15:43:37 +01009756 {nr} can be the window number or the |window-ID|.
9757 Return [0, 0] if the window cannot be found in the current
9758 tabpage.
9759
Bram Moolenaar071d4272004-06-13 20:20:40 +00009760 *winbufnr()*
9761winbufnr({nr}) The result is a Number, which is the number of the buffer
Bram Moolenaar888ccac2016-06-04 18:49:36 +02009762 associated with window {nr}. {nr} can be the window number or
Bram Moolenaar7571d552016-08-18 22:54:46 +02009763 the |window-ID|.
Bram Moolenaar888ccac2016-06-04 18:49:36 +02009764 When {nr} is zero, the number of the buffer in the current
9765 window is returned.
9766 When window {nr} doesn't exist, -1 is returned.
Bram Moolenaar071d4272004-06-13 20:20:40 +00009767 Example: >
9768 :echo "The file in the current window is " . bufname(winbufnr(0))
9769<
9770 *wincol()*
9771wincol() The result is a Number, which is the virtual column of the
9772 cursor in the window. This is counting screen cells from the
9773 left side of the window. The leftmost column is one.
9774
9775winheight({nr}) *winheight()*
9776 The result is a Number, which is the height of window {nr}.
Bram Moolenaar7571d552016-08-18 22:54:46 +02009777 {nr} can be the window number or the |window-ID|.
Bram Moolenaar071d4272004-06-13 20:20:40 +00009778 When {nr} is zero, the height of the current window is
9779 returned. When window {nr} doesn't exist, -1 is returned.
9780 An existing window always has a height of zero or more.
Bram Moolenaar37c64c72017-09-19 22:06:03 +02009781 This excludes any window toolbar line.
Bram Moolenaar071d4272004-06-13 20:20:40 +00009782 Examples: >
9783 :echo "The current window has " . winheight(0) . " lines."
9784<
Bram Moolenaar0f6b4f02018-08-21 16:56:34 +02009785winlayout([{tabnr}]) *winlayout()*
9786 The result is a nested List containing the layout of windows
9787 in a tabpage.
9788
9789 Without {tabnr} use the current tabpage, otherwise the tabpage
9790 with number {tabnr}. If the tabpage {tabnr} is not found,
9791 returns an empty list.
9792
9793 For a leaf window, it returns:
9794 ['leaf', {winid}]
9795 For horizontally split windows, which form a column, it
9796 returns:
9797 ['col', [{nested list of windows}]]
9798 For vertically split windows, which form a row, it returns:
9799 ['row', [{nested list of windows}]]
9800
9801 Example: >
9802 " Only one window in the tab page
9803 :echo winlayout()
9804 ['leaf', 1000]
9805 " Two horizontally split windows
9806 :echo winlayout()
9807 ['col', [['leaf', 1000], ['leaf', 1001]]]
9808 " Three horizontally split windows, with two
9809 " vertically split windows in the middle window
9810 :echo winlayout(2)
9811 ['col', [['leaf', 1002], ['row', ['leaf', 1003],
9812 ['leaf', 1001]]], ['leaf', 1000]]
9813<
Bram Moolenaar071d4272004-06-13 20:20:40 +00009814 *winline()*
9815winline() The result is a Number, which is the screen line of the cursor
Bram Moolenaar58b85342016-08-14 19:54:54 +02009816 in the window. This is counting screen lines from the top of
Bram Moolenaar071d4272004-06-13 20:20:40 +00009817 the window. The first line is one.
Bram Moolenaarbfd8fc02005-09-20 23:22:24 +00009818 If the cursor was moved the view on the file will be updated
9819 first, this may cause a scroll.
Bram Moolenaar071d4272004-06-13 20:20:40 +00009820
9821 *winnr()*
Bram Moolenaar5eb86f92004-07-26 12:53:41 +00009822winnr([{arg}]) The result is a Number, which is the number of the current
9823 window. The top window has number 1.
9824 When the optional argument is "$", the number of the
Bram Moolenaar2df58b42012-11-28 18:21:11 +01009825 last window is returned (the window count). >
9826 let window_count = winnr('$')
9827< When the optional argument is "#", the number of the last
Bram Moolenaar5eb86f92004-07-26 12:53:41 +00009828 accessed window is returned (where |CTRL-W_p| goes to).
Bram Moolenaaref2f6562007-05-06 13:32:59 +00009829 If there is no previous window or it is in another tab page 0
9830 is returned.
Bram Moolenaar5eb86f92004-07-26 12:53:41 +00009831 The number can be used with |CTRL-W_w| and ":wincmd w"
9832 |:wincmd|.
Bram Moolenaar690afe12017-01-28 18:34:47 +01009833 Also see |tabpagewinnr()| and |win_getid()|.
Bram Moolenaar071d4272004-06-13 20:20:40 +00009834
9835 *winrestcmd()*
9836winrestcmd() Returns a sequence of |:resize| commands that should restore
9837 the current window sizes. Only works properly when no windows
Bram Moolenaar87b5ca52006-03-04 21:55:31 +00009838 are opened or closed and the current window and tab page is
9839 unchanged.
Bram Moolenaar071d4272004-06-13 20:20:40 +00009840 Example: >
9841 :let cmd = winrestcmd()
9842 :call MessWithWindowSizes()
9843 :exe cmd
Bram Moolenaar87b5ca52006-03-04 21:55:31 +00009844<
9845 *winrestview()*
9846winrestview({dict})
9847 Uses the |Dictionary| returned by |winsaveview()| to restore
9848 the view of the current window.
Bram Moolenaar82c25852014-05-28 16:47:16 +02009849 Note: The {dict} does not have to contain all values, that are
9850 returned by |winsaveview()|. If values are missing, those
9851 settings won't be restored. So you can use: >
9852 :call winrestview({'curswant': 4})
9853<
9854 This will only set the curswant value (the column the cursor
9855 wants to move on vertical movements) of the cursor to column 5
9856 (yes, that is 5), while all other settings will remain the
9857 same. This is useful, if you set the cursor position manually.
9858
Bram Moolenaar87b5ca52006-03-04 21:55:31 +00009859 If you have changed the values the result is unpredictable.
9860 If the window size changed the result won't be the same.
9861
9862 *winsaveview()*
9863winsaveview() Returns a |Dictionary| that contains information to restore
9864 the view of the current window. Use |winrestview()| to
9865 restore the view.
9866 This is useful if you have a mapping that jumps around in the
9867 buffer and you want to go back to the original view.
9868 This does not save fold information. Use the 'foldenable'
Bram Moolenaardb552d602006-03-23 22:59:57 +00009869 option to temporarily switch off folding, so that folds are
Bram Moolenaar07d87792014-07-19 14:04:47 +02009870 not opened when moving around. This may have side effects.
Bram Moolenaar87b5ca52006-03-04 21:55:31 +00009871 The return value includes:
9872 lnum cursor line number
Bram Moolenaar82c25852014-05-28 16:47:16 +02009873 col cursor column (Note: the first column
9874 zero, as opposed to what getpos()
9875 returns)
Bram Moolenaar87b5ca52006-03-04 21:55:31 +00009876 coladd cursor column offset for 'virtualedit'
9877 curswant column for vertical movement
9878 topline first line in the window
9879 topfill filler lines, only in diff mode
9880 leftcol first column displayed
9881 skipcol columns skipped
9882 Note that no option values are saved.
9883
Bram Moolenaar071d4272004-06-13 20:20:40 +00009884
9885winwidth({nr}) *winwidth()*
9886 The result is a Number, which is the width of window {nr}.
Bram Moolenaar7571d552016-08-18 22:54:46 +02009887 {nr} can be the window number or the |window-ID|.
Bram Moolenaar071d4272004-06-13 20:20:40 +00009888 When {nr} is zero, the width of the current window is
9889 returned. When window {nr} doesn't exist, -1 is returned.
9890 An existing window always has a width of zero or more.
9891 Examples: >
9892 :echo "The current window has " . winwidth(0) . " columns."
9893 :if winwidth(0) <= 50
Bram Moolenaar7567d0b2017-11-16 23:04:15 +01009894 : 50 wincmd |
Bram Moolenaar071d4272004-06-13 20:20:40 +00009895 :endif
Bram Moolenaarf8be4612017-06-23 20:52:40 +02009896< For getting the terminal or screen size, see the 'columns'
9897 option.
Bram Moolenaar22fcfad2016-07-01 18:17:26 +02009898
9899
Bram Moolenaared767a22016-01-03 22:49:16 +01009900wordcount() *wordcount()*
9901 The result is a dictionary of byte/chars/word statistics for
9902 the current buffer. This is the same info as provided by
9903 |g_CTRL-G|
9904 The return value includes:
9905 bytes Number of bytes in the buffer
9906 chars Number of chars in the buffer
9907 words Number of words in the buffer
9908 cursor_bytes Number of bytes before cursor position
9909 (not in Visual mode)
9910 cursor_chars Number of chars before cursor position
9911 (not in Visual mode)
9912 cursor_words Number of words before cursor position
9913 (not in Visual mode)
9914 visual_bytes Number of bytes visually selected
Bram Moolenaarf8be4612017-06-23 20:52:40 +02009915 (only in Visual mode)
Bram Moolenaared767a22016-01-03 22:49:16 +01009916 visual_chars Number of chars visually selected
Bram Moolenaarf8be4612017-06-23 20:52:40 +02009917 (only in Visual mode)
Bram Moolenaarc572da52017-08-27 16:52:01 +02009918 visual_words Number of words visually selected
Bram Moolenaarf8be4612017-06-23 20:52:40 +02009919 (only in Visual mode)
Bram Moolenaared767a22016-01-03 22:49:16 +01009920
9921
Bram Moolenaar3a7c85b2005-02-05 21:39:53 +00009922 *writefile()*
Bram Moolenaar6e5ea8d2019-01-12 22:47:31 +01009923writefile({object}, {fname} [, {flags}])
9924 When {object} is a |List| write it to file {fname}. Each list
9925 item is separated with a NL. Each list item must be a String
9926 or Number.
Bram Moolenaar6b2e9382014-11-05 18:06:01 +01009927 When {flags} contains "b" then binary mode is used: There will
Bram Moolenaar3a7c85b2005-02-05 21:39:53 +00009928 not be a NL after the last list item. An empty item at the
9929 end does cause the last line in the file to end in a NL.
Bram Moolenaar6b2e9382014-11-05 18:06:01 +01009930
Bram Moolenaar6e5ea8d2019-01-12 22:47:31 +01009931 When {object} is a |Blob| write the bytes to file {fname}
9932 unmodified.
9933
Bram Moolenaar6b2e9382014-11-05 18:06:01 +01009934 When {flags} contains "a" then append mode is used, lines are
Bram Moolenaar46fceaa2016-10-23 21:21:08 +02009935 appended to the file: >
Bram Moolenaar6b2e9382014-11-05 18:06:01 +01009936 :call writefile(["foo"], "event.log", "a")
9937 :call writefile(["bar"], "event.log", "a")
Bram Moolenaar7567d0b2017-11-16 23:04:15 +01009938<
9939 When {flags} contains "s" then fsync() is called after writing
9940 the file. This flushes the file to disk, if possible. This
9941 takes more time but avoids losing the file if the system
9942 crashes.
Bram Moolenaar74240d32017-12-10 15:26:15 +01009943 When {flags} does not contain "S" or "s" then fsync() is
9944 called if the 'fsync' option is set.
Bram Moolenaar7567d0b2017-11-16 23:04:15 +01009945 When {flags} contains "S" then fsync() is not called, even
9946 when 'fsync' is set.
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01009947
Bram Moolenaar7567d0b2017-11-16 23:04:15 +01009948 All NL characters are replaced with a NUL character.
Bram Moolenaar3a7c85b2005-02-05 21:39:53 +00009949 Inserting CR characters needs to be done before passing {list}
9950 to writefile().
9951 An existing file is overwritten, if possible.
9952 When the write fails -1 is returned, otherwise 0. There is an
9953 error message if the file can't be created or when writing
9954 fails.
9955 Also see |readfile()|.
9956 To copy a file byte for byte: >
9957 :let fl = readfile("foo", "b")
9958 :call writefile(fl, "foocopy", "b")
Bram Moolenaard6e256c2011-12-14 15:32:50 +01009959
9960
9961xor({expr}, {expr}) *xor()*
9962 Bitwise XOR on the two arguments. The arguments are converted
9963 to a number. A List, Dict or Float argument causes an error.
9964 Example: >
9965 :let bits = xor(bits, 0x80)
Bram Moolenaar6ee8d892012-01-10 14:55:01 +01009966<
Bram Moolenaard6e256c2011-12-14 15:32:50 +01009967
Bram Moolenaar071d4272004-06-13 20:20:40 +00009968
9969 *feature-list*
Bram Moolenaar946e27a2014-06-25 18:50:27 +02009970There are four types of features:
Bram Moolenaar071d4272004-06-13 20:20:40 +000099711. Features that are only supported when they have been enabled when Vim
9972 was compiled |+feature-list|. Example: >
9973 :if has("cindent")
99742. Features that are only supported when certain conditions have been met.
9975 Example: >
9976 :if has("gui_running")
9977< *has-patch*
Bram Moolenaar2f018892018-05-18 18:12:06 +020099783. Beyond a certain version or at a certain version and including a specific
9979 patch. The "patch-7.4.248" feature means that the Vim version is 7.5 or
9980 later, or it is version 7.4 and patch 248 was included. Example: >
Bram Moolenaarbcb98982014-05-01 14:08:19 +02009981 :if has("patch-7.4.248")
Bram Moolenaar2f018892018-05-18 18:12:06 +02009982< Note that it's possible for patch 248 to be omitted even though 249 is
9983 included. Only happens when cherry-picking patches.
9984 Note that this form only works for patch 7.4.237 and later, before that
9985 you need to check for the patch and the v:version. Example (checking
9986 version 6.2.148 or later): >
9987 :if v:version > 602 || (v:version == 602 && has("patch148"))
Bram Moolenaar071d4272004-06-13 20:20:40 +00009988
Bram Moolenaard823fa92016-08-12 16:29:27 +02009989Hint: To find out if Vim supports backslashes in a file name (MS-Windows),
9990use: `if exists('+shellslash')`
9991
9992
Bram Moolenaar7cba6c02013-09-05 22:13:31 +02009993acl Compiled with |ACL| support.
Bram Moolenaar071d4272004-06-13 20:20:40 +00009994all_builtin_terms Compiled with all builtin terminals enabled.
9995amiga Amiga version of Vim.
9996arabic Compiled with Arabic support |Arabic|.
9997arp Compiled with ARP support (Amiga).
Bram Moolenaara9b1e742005-12-19 22:14:58 +00009998autocmd Compiled with autocommand support. |autocommand|
Bram Moolenaar91f84f62018-07-29 15:07:52 +02009999autochdir Compiled with support for 'autochdir'
Bram Moolenaare42a6d22017-11-12 19:21:51 +010010000autoservername Automatically enable |clientserver|
Bram Moolenaar071d4272004-06-13 20:20:40 +000010001balloon_eval Compiled with |balloon-eval| support.
Bram Moolenaar45360022005-07-21 21:08:21 +000010002balloon_multiline GUI supports multiline balloons.
Bram Moolenaar071d4272004-06-13 20:20:40 +000010003beos BeOS version of Vim.
10004browse Compiled with |:browse| support, and browse() will
10005 work.
Bram Moolenaar30b65812012-07-12 22:01:11 +020010006browsefilter Compiled with support for |browsefilter|.
Bram Moolenaar071d4272004-06-13 20:20:40 +000010007builtin_terms Compiled with some builtin terminals.
10008byte_offset Compiled with support for 'o' in 'statusline'
10009cindent Compiled with 'cindent' support.
10010clientserver Compiled with remote invocation support |clientserver|.
10011clipboard Compiled with 'clipboard' support.
10012cmdline_compl Compiled with |cmdline-completion| support.
10013cmdline_hist Compiled with |cmdline-history| support.
10014cmdline_info Compiled with 'showcmd' and 'ruler' support.
10015comments Compiled with |'comments'| support.
Bram Moolenaar2a8a3ec2011-01-08 16:06:37 +010010016compatible Compiled to be very Vi compatible.
Bram Moolenaar071d4272004-06-13 20:20:40 +000010017cryptv Compiled with encryption support |encryption|.
10018cscope Compiled with |cscope| support.
Bram Moolenaar071d4272004-06-13 20:20:40 +000010019debug Compiled with "DEBUG" defined.
10020dialog_con Compiled with console dialog support.
10021dialog_gui Compiled with GUI dialog support.
10022diff Compiled with |vimdiff| and 'diff' support.
10023digraphs Compiled with support for digraphs.
Bram Moolenaar58b85342016-08-14 19:54:54 +020010024directx Compiled with support for DirectX and 'renderoptions'.
Bram Moolenaar071d4272004-06-13 20:20:40 +000010025dnd Compiled with support for the "~ register |quote_~|.
Bram Moolenaar071d4272004-06-13 20:20:40 +000010026ebcdic Compiled on a machine with ebcdic character set.
10027emacs_tags Compiled with support for Emacs tags.
10028eval Compiled with expression evaluation support. Always
10029 true, of course!
Bram Moolenaar5e9b2fa2016-02-01 22:37:05 +010010030ex_extra |+ex_extra|, always true now
Bram Moolenaar071d4272004-06-13 20:20:40 +000010031extra_search Compiled with support for |'incsearch'| and
10032 |'hlsearch'|
10033farsi Compiled with Farsi support |farsi|.
10034file_in_path Compiled with support for |gf| and |<cfile>|
Bram Moolenaar26a60b42005-02-22 08:49:11 +000010035filterpipe When 'shelltemp' is off pipes are used for shell
10036 read/write/filter commands
Bram Moolenaar071d4272004-06-13 20:20:40 +000010037find_in_path Compiled with support for include file searches
10038 |+find_in_path|.
Bram Moolenaar446cb832008-06-24 21:56:24 +000010039float Compiled with support for |Float|.
Bram Moolenaar071d4272004-06-13 20:20:40 +000010040fname_case Case in file names matters (for Amiga, MS-DOS, and
10041 Windows this is not present).
10042folding Compiled with |folding| support.
10043footer Compiled with GUI footer support. |gui-footer|
10044fork Compiled to use fork()/exec() instead of system().
10045gettext Compiled with message translation |multi-lang|
10046gui Compiled with GUI enabled.
10047gui_athena Compiled with Athena GUI.
Bram Moolenaar2a8a3ec2011-01-08 16:06:37 +010010048gui_gnome Compiled with Gnome support (gui_gtk is also defined).
Bram Moolenaar071d4272004-06-13 20:20:40 +000010049gui_gtk Compiled with GTK+ GUI (any version).
10050gui_gtk2 Compiled with GTK+ 2 GUI (gui_gtk is also defined).
Bram Moolenaar98921892016-02-23 17:14:37 +010010051gui_gtk3 Compiled with GTK+ 3 GUI (gui_gtk is also defined).
Bram Moolenaar071d4272004-06-13 20:20:40 +000010052gui_mac Compiled with Macintosh GUI.
10053gui_motif Compiled with Motif GUI.
10054gui_photon Compiled with Photon GUI.
Bram Moolenaar2a8a3ec2011-01-08 16:06:37 +010010055gui_running Vim is running in the GUI, or it will start soon.
Bram Moolenaar071d4272004-06-13 20:20:40 +000010056gui_win32 Compiled with MS Windows Win32 GUI.
10057gui_win32s idem, and Win32s system being used (Windows 3.1)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010058hangul_input Compiled with Hangul input support. |hangul|
10059iconv Can use iconv() for conversion.
10060insert_expand Compiled with support for CTRL-X expansion commands in
10061 Insert mode.
10062jumplist Compiled with |jumplist| support.
10063keymap Compiled with 'keymap' support.
Bram Moolenaar437bafe2016-08-01 15:40:54 +020010064lambda Compiled with |lambda| support.
Bram Moolenaar071d4272004-06-13 20:20:40 +000010065langmap Compiled with 'langmap' support.
10066libcall Compiled with |libcall()| support.
Bram Moolenaar597a4222014-06-25 14:39:50 +020010067linebreak Compiled with 'linebreak', 'breakat', 'showbreak' and
10068 'breakindent' support.
Bram Moolenaar071d4272004-06-13 20:20:40 +000010069lispindent Compiled with support for lisp indenting.
10070listcmds Compiled with commands for the buffer list |:files|
10071 and the argument list |arglist|.
10072localmap Compiled with local mappings and abbr. |:map-local|
Bram Moolenaar0ba04292010-07-14 23:23:17 +020010073lua Compiled with Lua interface |Lua|.
Bram Moolenaard0573012017-10-28 21:11:06 +020010074mac Any Macintosh version of Vim cf. osx
10075macunix Synonym for osxdarwin
Bram Moolenaar071d4272004-06-13 20:20:40 +000010076menu Compiled with support for |:menu|.
10077mksession Compiled with support for |:mksession|.
10078modify_fname Compiled with file name modifiers. |filename-modifiers|
10079mouse Compiled with support mouse.
Bram Moolenaar071d4272004-06-13 20:20:40 +000010080mouse_dec Compiled with support for Dec terminal mouse.
10081mouse_gpm Compiled with support for gpm (Linux console mouse)
10082mouse_netterm Compiled with support for netterm mouse.
10083mouse_pterm Compiled with support for qnx pterm mouse.
Bram Moolenaar446cb832008-06-24 21:56:24 +000010084mouse_sysmouse Compiled with support for sysmouse (*BSD console mouse)
Bram Moolenaar9b451252012-08-15 17:43:31 +020010085mouse_sgr Compiled with support for sgr mouse.
Bram Moolenaarf1568ec2011-12-14 21:17:39 +010010086mouse_urxvt Compiled with support for urxvt mouse.
Bram Moolenaar071d4272004-06-13 20:20:40 +000010087mouse_xterm Compiled with support for xterm mouse.
Bram Moolenaar2a8a3ec2011-01-08 16:06:37 +010010088mouseshape Compiled with support for 'mouseshape'.
Bram Moolenaar42022d52008-12-09 09:57:49 +000010089multi_byte Compiled with support for 'encoding'
10090multi_byte_encoding 'encoding' is set to a multi-byte encoding.
Bram Moolenaar071d4272004-06-13 20:20:40 +000010091multi_byte_ime Compiled with support for IME input method.
10092multi_lang Compiled with support for multiple languages.
Bram Moolenaar325b7a22004-07-05 15:58:32 +000010093mzscheme Compiled with MzScheme interface |mzscheme|.
Bram Moolenaarb26e6322010-05-22 21:34:09 +020010094netbeans_enabled Compiled with support for |netbeans| and connected.
Bram Moolenaar2a8a3ec2011-01-08 16:06:37 +010010095netbeans_intg Compiled with support for |netbeans|.
Bram Moolenaar22fcfad2016-07-01 18:17:26 +020010096num64 Compiled with 64-bit |Number| support.
Bram Moolenaar071d4272004-06-13 20:20:40 +000010097ole Compiled with OLE automation support for Win32.
Bram Moolenaard0573012017-10-28 21:11:06 +020010098osx Compiled for macOS cf. mac
10099osxdarwin Compiled for macOS, with |mac-darwin-feature|
Bram Moolenaar91c49372016-05-08 09:50:29 +020010100packages Compiled with |packages| support.
Bram Moolenaar071d4272004-06-13 20:20:40 +000010101path_extra Compiled with up/downwards search in 'path' and 'tags'
10102perl Compiled with Perl interface.
Bram Moolenaar55debbe2010-05-23 23:34:36 +020010103persistent_undo Compiled with support for persistent undo history.
Bram Moolenaar071d4272004-06-13 20:20:40 +000010104postscript Compiled with PostScript file printing.
10105printer Compiled with |:hardcopy| support.
Bram Moolenaar05159a02005-02-26 23:04:13 +000010106profile Compiled with |:profile| support.
Bram Moolenaar84b242c2018-01-28 17:45:49 +010010107python Python 2.x interface available. |has-python|
10108python_compiled Compiled with Python 2.x interface. |has-python|
10109python_dynamic Python 2.x interface is dynamically loaded. |has-python|
10110python3 Python 3.x interface available. |has-python|
10111python3_compiled Compiled with Python 3.x interface. |has-python|
10112python3_dynamic Python 3.x interface is dynamically loaded. |has-python|
Bram Moolenaarf42dd3c2017-01-28 16:06:38 +010010113pythonx Compiled with |python_x| interface. |has-pythonx|
Bram Moolenaar071d4272004-06-13 20:20:40 +000010114qnx QNX version of Vim.
10115quickfix Compiled with |quickfix| support.
Bram Moolenaard68071d2006-05-02 22:08:30 +000010116reltime Compiled with |reltime()| support.
Bram Moolenaar071d4272004-06-13 20:20:40 +000010117rightleft Compiled with 'rightleft' support.
10118ruby Compiled with Ruby interface |ruby|.
10119scrollbind Compiled with 'scrollbind' support.
10120showcmd Compiled with 'showcmd' support.
10121signs Compiled with |:sign| support.
10122smartindent Compiled with 'smartindent' support.
Bram Moolenaar2a8a3ec2011-01-08 16:06:37 +010010123spell Compiled with spell checking support |spell|.
Bram Moolenaaref94eec2009-11-11 13:22:11 +000010124startuptime Compiled with |--startuptime| support.
Bram Moolenaar071d4272004-06-13 20:20:40 +000010125statusline Compiled with support for 'statusline', 'rulerformat'
10126 and special formats of 'titlestring' and 'iconstring'.
10127sun_workshop Compiled with support for Sun |workshop|.
Bram Moolenaar82cf9b62005-06-07 21:09:25 +000010128syntax Compiled with syntax highlighting support |syntax|.
Bram Moolenaar071d4272004-06-13 20:20:40 +000010129syntax_items There are active syntax highlighting items for the
10130 current buffer.
10131system Compiled to use system() instead of fork()/exec().
10132tag_binary Compiled with binary searching in tags files
10133 |tag-binary-search|.
10134tag_old_static Compiled with support for old static tags
10135 |tag-old-static|.
10136tag_any_white Compiled with support for any white characters in tags
10137 files |tag-any-white|.
10138tcl Compiled with Tcl interface.
Bram Moolenaar91c49372016-05-08 09:50:29 +020010139termguicolors Compiled with true color in terminal support.
Bram Moolenaarc2ce52c2017-08-01 18:35:38 +020010140terminal Compiled with |terminal| support.
Bram Moolenaar071d4272004-06-13 20:20:40 +000010141terminfo Compiled with terminfo instead of termcap.
10142termresponse Compiled with support for |t_RV| and |v:termresponse|.
10143textobjects Compiled with support for |text-objects|.
Bram Moolenaar98aefe72018-12-13 22:20:09 +010010144textprop Compiled with support for |text-properties|.
Bram Moolenaar071d4272004-06-13 20:20:40 +000010145tgetent Compiled with tgetent support, able to use a termcap
10146 or terminfo file.
Bram Moolenaar975b5272016-03-15 23:10:59 +010010147timers Compiled with |timer_start()| support.
Bram Moolenaar071d4272004-06-13 20:20:40 +000010148title Compiled with window title support |'title'|.
10149toolbar Compiled with support for |gui-toolbar|.
Bram Moolenaar2cab0e12016-11-24 15:09:07 +010010150ttyin input is a terminal (tty)
10151ttyout output is a terminal (tty)
Bram Moolenaar37c64c72017-09-19 22:06:03 +020010152unix Unix version of Vim. *+unix*
Bram Moolenaar3df01732017-02-17 22:47:16 +010010153unnamedplus Compiled with support for "unnamedplus" in 'clipboard'
Bram Moolenaar071d4272004-06-13 20:20:40 +000010154user_commands User-defined commands.
Bram Moolenaar22f1d0e2018-02-27 14:53:30 +010010155vcon Win32: Virtual console support is working, can use
10156 'termguicolors'. Also see |+vtp|.
Bram Moolenaar071d4272004-06-13 20:20:40 +000010157vertsplit Compiled with vertically split windows |:vsplit|.
Bram Moolenaar2a8a3ec2011-01-08 16:06:37 +010010158vim_starting True while initial source'ing takes place. |startup|
Bram Moolenaar4f3f6682016-03-26 23:01:59 +010010159 *vim_starting*
Bram Moolenaar2a8a3ec2011-01-08 16:06:37 +010010160viminfo Compiled with viminfo support.
Bram Moolenaar071d4272004-06-13 20:20:40 +000010161virtualedit Compiled with 'virtualedit' option.
Bram Moolenaar5b69c222019-01-11 14:50:06 +010010162visual Compiled with Visual mode. (always true)
10163visualextra Compiled with extra Visual mode commands. (always
10164 true) |blockwise-operators|.
Bram Moolenaar071d4272004-06-13 20:20:40 +000010165vms VMS version of Vim.
10166vreplace Compiled with |gR| and |gr| commands.
Bram Moolenaar98ef2332018-03-18 14:44:37 +010010167vtp Compiled for vcon support |+vtp| (check vcon to find
Bram Moolenaar5a3a49e2018-03-20 18:35:53 +010010168 out if it works in the current console).
Bram Moolenaar071d4272004-06-13 20:20:40 +000010169wildignore Compiled with 'wildignore' option.
10170wildmenu Compiled with 'wildmenu' option.
Bram Moolenaar0e5979a2018-06-17 19:36:33 +020010171win16 old version for MS-Windows 3.1 (always False)
Bram Moolenaard58e9292011-02-09 17:07:58 +010010172win32 Win32 version of Vim (MS-Windows 95 and later, 32 or
10173 64 bits)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010174win32unix Win32 version of Vim, using Unix files (Cygwin)
Bram Moolenaar2a8a3ec2011-01-08 16:06:37 +010010175win64 Win64 version of Vim (MS-Windows 64 bit).
Bram Moolenaar0e5979a2018-06-17 19:36:33 +020010176win95 Win32 version for MS-Windows 95/98/ME (always False)
Bram Moolenaar2a8a3ec2011-01-08 16:06:37 +010010177winaltkeys Compiled with 'winaltkeys' option.
10178windows Compiled with support for more than one window.
Bram Moolenaar071d4272004-06-13 20:20:40 +000010179writebackup Compiled with 'writebackup' default on.
10180xfontset Compiled with X fontset support |xfontset|.
10181xim Compiled with X input method support |xim|.
Bram Moolenaar7cba6c02013-09-05 22:13:31 +020010182xpm Compiled with pixmap support.
10183xpm_w32 Compiled with pixmap support for Win32. (Only for
10184 backward compatibility. Use "xpm" instead.)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010185xsmp Compiled with X session management support.
10186xsmp_interact Compiled with interactive X session management support.
10187xterm_clipboard Compiled with support for xterm clipboard.
10188xterm_save Compiled with support for saving and restoring the
10189 xterm screen.
10190x11 Compiled with X11 support.
10191
10192 *string-match*
10193Matching a pattern in a String
10194
10195A regexp pattern as explained at |pattern| is normally used to find a match in
10196the buffer lines. When a pattern is used to find a match in a String, almost
10197everything works in the same way. The difference is that a String is handled
10198like it is one line. When it contains a "\n" character, this is not seen as a
10199line break for the pattern. It can be matched with a "\n" in the pattern, or
10200with ".". Example: >
10201 :let a = "aaaa\nxxxx"
10202 :echo matchstr(a, "..\n..")
10203 aa
10204 xx
10205 :echo matchstr(a, "a.x")
10206 a
10207 x
10208
10209Don't forget that "^" will only match at the first character of the String and
10210"$" at the last character of the string. They don't match after or before a
10211"\n".
10212
10213==============================================================================
102145. Defining functions *user-functions*
10215
10216New functions can be defined. These can be called just like builtin
10217functions. The function executes a sequence of Ex commands. Normal mode
10218commands can be executed with the |:normal| command.
10219
10220The function name must start with an uppercase letter, to avoid confusion with
10221builtin functions. To prevent from using the same name in different scripts
10222avoid obvious, short names. A good habit is to start the function name with
10223the name of the script, e.g., "HTMLcolor()".
10224
Bram Moolenaar92d640f2005-09-05 22:11:52 +000010225It's also possible to use curly braces, see |curly-braces-names|. And the
10226|autoload| facility is useful to define a function only when it's called.
Bram Moolenaar071d4272004-06-13 20:20:40 +000010227
10228 *local-function*
10229A function local to a script must start with "s:". A local script function
10230can only be called from within the script and from functions, user commands
10231and autocommands defined in the script. It is also possible to call the
Bram Moolenaare37d50a2008-08-06 17:06:04 +000010232function from a mapping defined in the script, but then |<SID>| must be used
Bram Moolenaar071d4272004-06-13 20:20:40 +000010233instead of "s:" when the mapping is expanded outside of the script.
Bram Moolenaarbcb98982014-05-01 14:08:19 +020010234There are only script-local functions, no buffer-local or window-local
10235functions.
Bram Moolenaar071d4272004-06-13 20:20:40 +000010236
10237 *:fu* *:function* *E128* *E129* *E123*
10238:fu[nction] List all functions and their arguments.
10239
10240:fu[nction] {name} List function {name}.
Bram Moolenaar32466aa2006-02-24 23:53:04 +000010241 {name} can also be a |Dictionary| entry that is a
10242 |Funcref|: >
Bram Moolenaar3a3a7232005-01-17 22:16:15 +000010243 :function dict.init
Bram Moolenaar92d640f2005-09-05 22:11:52 +000010244
10245:fu[nction] /{pattern} List functions with a name matching {pattern}.
10246 Example that lists all functions ending with "File": >
10247 :function /File$
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +000010248<
10249 *:function-verbose*
10250When 'verbose' is non-zero, listing a function will also display where it was
10251last defined. Example: >
10252
10253 :verbose function SetFileTypeSH
10254 function SetFileTypeSH(name)
10255 Last set from /usr/share/vim/vim-7.0/filetype.vim
10256<
Bram Moolenaar8aff23a2005-08-19 20:40:30 +000010257See |:verbose-cmd| for more information.
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +000010258
Bram Moolenaarbcb98982014-05-01 14:08:19 +020010259 *E124* *E125* *E853* *E884*
Bram Moolenaar10ce39a2016-07-29 22:37:06 +020010260:fu[nction][!] {name}([arguments]) [range] [abort] [dict] [closure]
Bram Moolenaar01164a62017-11-02 22:58:42 +010010261 Define a new function by the name {name}. The body of
10262 the function follows in the next lines, until the
10263 matching |:endfunction|.
Bram Moolenaarb0d45e72017-11-05 18:19:24 +010010264
Bram Moolenaar01164a62017-11-02 22:58:42 +010010265 The name must be made of alphanumeric characters and
10266 '_', and must start with a capital or "s:" (see
10267 above). Note that using "b:" or "g:" is not allowed.
10268 (since patch 7.4.260 E884 is given if the function
10269 name has a colon in the name, e.g. for "foo:bar()".
10270 Before that patch no error was given).
Bram Moolenaar3a3a7232005-01-17 22:16:15 +000010271
Bram Moolenaar32466aa2006-02-24 23:53:04 +000010272 {name} can also be a |Dictionary| entry that is a
10273 |Funcref|: >
Bram Moolenaar3a3a7232005-01-17 22:16:15 +000010274 :function dict.init(arg)
Bram Moolenaar58b85342016-08-14 19:54:54 +020010275< "dict" must be an existing dictionary. The entry
Bram Moolenaar3a3a7232005-01-17 22:16:15 +000010276 "init" is added if it didn't exist yet. Otherwise [!]
Bram Moolenaar58b85342016-08-14 19:54:54 +020010277 is required to overwrite an existing function. The
Bram Moolenaar3a3a7232005-01-17 22:16:15 +000010278 result is a |Funcref| to a numbered function. The
10279 function can only be used with a |Funcref| and will be
10280 deleted if there are no more references to it.
Bram Moolenaar071d4272004-06-13 20:20:40 +000010281 *E127* *E122*
10282 When a function by this name already exists and [!] is
Bram Moolenaarded5f1b2018-11-10 17:33:29 +010010283 not used an error message is given. There is one
10284 exception: When sourcing a script again, a function
10285 that was previously defined in that script will be
10286 silently replaced.
10287 When [!] is used, an existing function is silently
10288 replaced. Unless it is currently being executed, that
10289 is an error.
Bram Moolenaarf8be4612017-06-23 20:52:40 +020010290 NOTE: Use ! wisely. If used without care it can cause
10291 an existing function to be replaced unexpectedly,
10292 which is hard to debug.
Bram Moolenaar8f999f12005-01-25 22:12:55 +000010293
10294 For the {arguments} see |function-argument|.
10295
Bram Moolenaar8d043172014-01-23 14:24:41 +010010296 *:func-range* *a:firstline* *a:lastline*
Bram Moolenaar071d4272004-06-13 20:20:40 +000010297 When the [range] argument is added, the function is
10298 expected to take care of a range itself. The range is
10299 passed as "a:firstline" and "a:lastline". If [range]
10300 is excluded, ":{range}call" will call the function for
10301 each line in the range, with the cursor on the start
10302 of each line. See |function-range-example|.
Bram Moolenaar2df58b42012-11-28 18:21:11 +010010303 The cursor is still moved to the first line of the
10304 range, as is the case with all Ex commands.
Bram Moolenaar8d043172014-01-23 14:24:41 +010010305 *:func-abort*
Bram Moolenaar071d4272004-06-13 20:20:40 +000010306 When the [abort] argument is added, the function will
10307 abort as soon as an error is detected.
Bram Moolenaar8d043172014-01-23 14:24:41 +010010308 *:func-dict*
Bram Moolenaar2fda12f2005-01-15 22:14:15 +000010309 When the [dict] argument is added, the function must
Bram Moolenaar58b85342016-08-14 19:54:54 +020010310 be invoked through an entry in a |Dictionary|. The
Bram Moolenaar2fda12f2005-01-15 22:14:15 +000010311 local variable "self" will then be set to the
10312 dictionary. See |Dictionary-function|.
Bram Moolenaar10ce39a2016-07-29 22:37:06 +020010313 *:func-closure* *E932*
10314 When the [closure] argument is added, the function
10315 can access variables and arguments from the outer
10316 scope. This is usually called a closure. In this
10317 example Bar() uses "x" from the scope of Foo(). It
10318 remains referenced even after Foo() returns: >
10319 :function! Foo()
10320 : let x = 0
10321 : function! Bar() closure
10322 : let x += 1
10323 : return x
10324 : endfunction
Bram Moolenaarbc8801c2016-08-02 21:04:33 +020010325 : return funcref('Bar')
Bram Moolenaar10ce39a2016-07-29 22:37:06 +020010326 :endfunction
10327
10328 :let F = Foo()
10329 :echo F()
10330< 1 >
10331 :echo F()
10332< 2 >
10333 :echo F()
10334< 3
Bram Moolenaar071d4272004-06-13 20:20:40 +000010335
Bram Moolenaar446cb832008-06-24 21:56:24 +000010336 *function-search-undo*
Bram Moolenaar98692072006-02-04 00:57:42 +000010337 The last used search pattern and the redo command "."
Bram Moolenaar446cb832008-06-24 21:56:24 +000010338 will not be changed by the function. This also
10339 implies that the effect of |:nohlsearch| is undone
10340 when the function returns.
Bram Moolenaar98692072006-02-04 00:57:42 +000010341
Bram Moolenaarf8be4612017-06-23 20:52:40 +020010342 *:endf* *:endfunction* *E126* *E193* *W22*
Bram Moolenaar663bb232017-06-22 19:12:10 +020010343:endf[unction] [argument]
10344 The end of a function definition. Best is to put it
10345 on a line by its own, without [argument].
10346
10347 [argument] can be:
10348 | command command to execute next
10349 \n command command to execute next
10350 " comment always ignored
Bram Moolenaarf8be4612017-06-23 20:52:40 +020010351 anything else ignored, warning given when
10352 'verbose' is non-zero
Bram Moolenaar663bb232017-06-22 19:12:10 +020010353 The support for a following command was added in Vim
10354 8.0.0654, before that any argument was silently
10355 ignored.
Bram Moolenaar071d4272004-06-13 20:20:40 +000010356
Bram Moolenaarf8be4612017-06-23 20:52:40 +020010357 To be able to define a function inside an `:execute`
10358 command, use line breaks instead of |:bar|: >
10359 :exe "func Foo()\necho 'foo'\nendfunc"
10360<
Bram Moolenaar437bafe2016-08-01 15:40:54 +020010361 *:delf* *:delfunction* *E130* *E131* *E933*
Bram Moolenaar663bb232017-06-22 19:12:10 +020010362:delf[unction][!] {name}
10363 Delete function {name}.
Bram Moolenaar32466aa2006-02-24 23:53:04 +000010364 {name} can also be a |Dictionary| entry that is a
10365 |Funcref|: >
Bram Moolenaar3a3a7232005-01-17 22:16:15 +000010366 :delfunc dict.init
Bram Moolenaar58b85342016-08-14 19:54:54 +020010367< This will remove the "init" entry from "dict". The
Bram Moolenaar3a3a7232005-01-17 22:16:15 +000010368 function is deleted if there are no more references to
10369 it.
Bram Moolenaar663bb232017-06-22 19:12:10 +020010370 With the ! there is no error if the function does not
10371 exist.
Bram Moolenaar071d4272004-06-13 20:20:40 +000010372 *:retu* *:return* *E133*
10373:retu[rn] [expr] Return from a function. When "[expr]" is given, it is
10374 evaluated and returned as the result of the function.
10375 If "[expr]" is not given, the number 0 is returned.
10376 When a function ends without an explicit ":return",
10377 the number 0 is returned.
10378 Note that there is no check for unreachable lines,
10379 thus there is no warning if commands follow ":return".
10380
10381 If the ":return" is used after a |:try| but before the
10382 matching |:finally| (if present), the commands
10383 following the ":finally" up to the matching |:endtry|
10384 are executed first. This process applies to all
10385 nested ":try"s inside the function. The function
10386 returns at the outermost ":endtry".
10387
Bram Moolenaar8f999f12005-01-25 22:12:55 +000010388 *function-argument* *a:var*
Bram Moolenaar58b85342016-08-14 19:54:54 +020010389An argument can be defined by giving its name. In the function this can then
Bram Moolenaar8f999f12005-01-25 22:12:55 +000010390be used as "a:name" ("a:" for argument).
Bram Moolenaaref2f6562007-05-06 13:32:59 +000010391 *a:0* *a:1* *a:000* *E740* *...*
Bram Moolenaar8f999f12005-01-25 22:12:55 +000010392Up to 20 arguments can be given, separated by commas. After the named
10393arguments an argument "..." can be specified, which means that more arguments
10394may optionally be following. In the function the extra arguments can be used
10395as "a:1", "a:2", etc. "a:0" is set to the number of extra arguments (which
Bram Moolenaar32466aa2006-02-24 23:53:04 +000010396can be 0). "a:000" is set to a |List| that contains these arguments. Note
10397that "a:1" is the same as "a:000[0]".
Bram Moolenaar2ce06f62005-01-31 19:19:04 +000010398 *E742*
10399The a: scope and the variables in it cannot be changed, they are fixed.
Bram Moolenaar069c1e72016-07-15 21:25:08 +020010400However, if a composite type is used, such as |List| or |Dictionary| , you can
10401change their contents. Thus you can pass a |List| to a function and have the
10402function add an item to it. If you want to make sure the function cannot
10403change a |List| or |Dictionary| use |:lockvar|.
Bram Moolenaar071d4272004-06-13 20:20:40 +000010404
Bram Moolenaar8f999f12005-01-25 22:12:55 +000010405When not using "...", the number of arguments in a function call must be equal
10406to the number of named arguments. When using "...", the number of arguments
10407may be larger.
10408
10409It is also possible to define a function without any arguments. You must
Bram Moolenaar01164a62017-11-02 22:58:42 +010010410still supply the () then.
10411
Bram Moolenaar98ef2332018-03-18 14:44:37 +010010412It is allowed to define another function inside a function body.
Bram Moolenaar8f999f12005-01-25 22:12:55 +000010413
10414 *local-variables*
Bram Moolenaar069c1e72016-07-15 21:25:08 +020010415Inside a function local variables can be used. These will disappear when the
10416function returns. Global variables need to be accessed with "g:".
Bram Moolenaar071d4272004-06-13 20:20:40 +000010417
10418Example: >
10419 :function Table(title, ...)
10420 : echohl Title
10421 : echo a:title
10422 : echohl None
Bram Moolenaar677ee682005-01-27 14:41:15 +000010423 : echo a:0 . " items:"
10424 : for s in a:000
10425 : echon ' ' . s
10426 : endfor
Bram Moolenaar071d4272004-06-13 20:20:40 +000010427 :endfunction
10428
10429This function can then be called with: >
Bram Moolenaar677ee682005-01-27 14:41:15 +000010430 call Table("Table", "line1", "line2")
10431 call Table("Empty Table")
Bram Moolenaar071d4272004-06-13 20:20:40 +000010432
Bram Moolenaaref2f6562007-05-06 13:32:59 +000010433To return more than one value, return a |List|: >
10434 :function Compute(n1, n2)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010435 : if a:n2 == 0
Bram Moolenaaref2f6562007-05-06 13:32:59 +000010436 : return ["fail", 0]
Bram Moolenaar071d4272004-06-13 20:20:40 +000010437 : endif
Bram Moolenaaref2f6562007-05-06 13:32:59 +000010438 : return ["ok", a:n1 / a:n2]
Bram Moolenaar071d4272004-06-13 20:20:40 +000010439 :endfunction
10440
10441This function can then be called with: >
Bram Moolenaaref2f6562007-05-06 13:32:59 +000010442 :let [success, div] = Compute(102, 6)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010443 :if success == "ok"
10444 : echo div
10445 :endif
Bram Moolenaaref2f6562007-05-06 13:32:59 +000010446<
Bram Moolenaar39f05632006-03-19 22:15:26 +000010447 *:cal* *:call* *E107* *E117*
Bram Moolenaar071d4272004-06-13 20:20:40 +000010448:[range]cal[l] {name}([arguments])
10449 Call a function. The name of the function and its arguments
10450 are as specified with |:function|. Up to 20 arguments can be
Bram Moolenaaref2f6562007-05-06 13:32:59 +000010451 used. The returned value is discarded.
Bram Moolenaar071d4272004-06-13 20:20:40 +000010452 Without a range and for functions that accept a range, the
10453 function is called once. When a range is given the cursor is
10454 positioned at the start of the first line before executing the
10455 function.
10456 When a range is given and the function doesn't handle it
10457 itself, the function is executed for each line in the range,
10458 with the cursor in the first column of that line. The cursor
10459 is left at the last line (possibly moved by the last function
Bram Moolenaar58b85342016-08-14 19:54:54 +020010460 call). The arguments are re-evaluated for each line. Thus
Bram Moolenaar071d4272004-06-13 20:20:40 +000010461 this works:
10462 *function-range-example* >
10463 :function Mynumber(arg)
10464 : echo line(".") . " " . a:arg
10465 :endfunction
10466 :1,5call Mynumber(getline("."))
10467<
10468 The "a:firstline" and "a:lastline" are defined anyway, they
10469 can be used to do something different at the start or end of
10470 the range.
10471
10472 Example of a function that handles the range itself: >
10473
10474 :function Cont() range
10475 : execute (a:firstline + 1) . "," . a:lastline . 's/^/\t\\ '
10476 :endfunction
10477 :4,8call Cont()
10478<
10479 This function inserts the continuation character "\" in front
10480 of all the lines in the range, except the first one.
10481
Bram Moolenaaref2f6562007-05-06 13:32:59 +000010482 When the function returns a composite value it can be further
10483 dereferenced, but the range will not be used then. Example: >
10484 :4,8call GetDict().method()
10485< Here GetDict() gets the range but method() does not.
10486
Bram Moolenaar071d4272004-06-13 20:20:40 +000010487 *E132*
10488The recursiveness of user functions is restricted with the |'maxfuncdepth'|
10489option.
10490
Bram Moolenaar7c626922005-02-07 22:01:03 +000010491
10492AUTOMATICALLY LOADING FUNCTIONS ~
Bram Moolenaar071d4272004-06-13 20:20:40 +000010493 *autoload-functions*
10494When using many or large functions, it's possible to automatically define them
Bram Moolenaar7c626922005-02-07 22:01:03 +000010495only when they are used. There are two methods: with an autocommand and with
10496the "autoload" directory in 'runtimepath'.
10497
10498
10499Using an autocommand ~
10500
Bram Moolenaar05159a02005-02-26 23:04:13 +000010501This is introduced in the user manual, section |41.14|.
10502
Bram Moolenaar7c626922005-02-07 22:01:03 +000010503The autocommand is useful if you have a plugin that is a long Vim script file.
10504You can define the autocommand and quickly quit the script with |:finish|.
Bram Moolenaar58b85342016-08-14 19:54:54 +020010505That makes Vim startup faster. The autocommand should then load the same file
Bram Moolenaar7c626922005-02-07 22:01:03 +000010506again, setting a variable to skip the |:finish| command.
10507
10508Use the FuncUndefined autocommand event with a pattern that matches the
10509function(s) to be defined. Example: >
Bram Moolenaar071d4272004-06-13 20:20:40 +000010510
10511 :au FuncUndefined BufNet* source ~/vim/bufnetfuncs.vim
10512
10513The file "~/vim/bufnetfuncs.vim" should then define functions that start with
10514"BufNet". Also see |FuncUndefined|.
10515
Bram Moolenaar7c626922005-02-07 22:01:03 +000010516
10517Using an autoload script ~
Bram Moolenaar26a60b42005-02-22 08:49:11 +000010518 *autoload* *E746*
Bram Moolenaar05159a02005-02-26 23:04:13 +000010519This is introduced in the user manual, section |41.15|.
10520
Bram Moolenaar7c626922005-02-07 22:01:03 +000010521Using a script in the "autoload" directory is simpler, but requires using
10522exactly the right file name. A function that can be autoloaded has a name
10523like this: >
10524
Bram Moolenaara7fc0102005-05-18 22:17:12 +000010525 :call filename#funcname()
Bram Moolenaar7c626922005-02-07 22:01:03 +000010526
10527When such a function is called, and it is not defined yet, Vim will search the
10528"autoload" directories in 'runtimepath' for a script file called
10529"filename.vim". For example "~/.vim/autoload/filename.vim". That file should
10530then define the function like this: >
10531
Bram Moolenaara7fc0102005-05-18 22:17:12 +000010532 function filename#funcname()
Bram Moolenaar7c626922005-02-07 22:01:03 +000010533 echo "Done!"
10534 endfunction
10535
Bram Moolenaar60a795a2005-09-16 21:55:43 +000010536The file name and the name used before the # in the function must match
Bram Moolenaar7c626922005-02-07 22:01:03 +000010537exactly, and the defined function must have the name exactly as it will be
10538called.
10539
Bram Moolenaara7fc0102005-05-18 22:17:12 +000010540It is possible to use subdirectories. Every # in the function name works like
10541a path separator. Thus when calling a function: >
Bram Moolenaar7c626922005-02-07 22:01:03 +000010542
Bram Moolenaara7fc0102005-05-18 22:17:12 +000010543 :call foo#bar#func()
Bram Moolenaar7c626922005-02-07 22:01:03 +000010544
10545Vim will look for the file "autoload/foo/bar.vim" in 'runtimepath'.
10546
Bram Moolenaar26a60b42005-02-22 08:49:11 +000010547This also works when reading a variable that has not been set yet: >
10548
Bram Moolenaara7fc0102005-05-18 22:17:12 +000010549 :let l = foo#bar#lvar
Bram Moolenaar26a60b42005-02-22 08:49:11 +000010550
Bram Moolenaara5792f52005-11-23 21:25:05 +000010551However, when the autoload script was already loaded it won't be loaded again
10552for an unknown variable.
10553
Bram Moolenaar26a60b42005-02-22 08:49:11 +000010554When assigning a value to such a variable nothing special happens. This can
10555be used to pass settings to the autoload script before it's loaded: >
10556
Bram Moolenaara7fc0102005-05-18 22:17:12 +000010557 :let foo#bar#toggle = 1
10558 :call foo#bar#func()
Bram Moolenaar26a60b42005-02-22 08:49:11 +000010559
Bram Moolenaar4399ef42005-02-12 14:29:27 +000010560Note that when you make a mistake and call a function that is supposed to be
10561defined in an autoload script, but the script doesn't actually define the
10562function, the script will be sourced every time you try to call the function.
Bram Moolenaar26a60b42005-02-22 08:49:11 +000010563And you will get an error message every time.
10564
10565Also note that if you have two script files, and one calls a function in the
Bram Moolenaar446cb832008-06-24 21:56:24 +000010566other and vice versa, before the used function is defined, it won't work.
Bram Moolenaar26a60b42005-02-22 08:49:11 +000010567Avoid using the autoload functionality at the toplevel.
Bram Moolenaar7c626922005-02-07 22:01:03 +000010568
Bram Moolenaar433f7c82006-03-21 21:29:36 +000010569Hint: If you distribute a bunch of scripts you can pack them together with the
10570|vimball| utility. Also read the user manual |distribute-script|.
10571
Bram Moolenaar071d4272004-06-13 20:20:40 +000010572==============================================================================
105736. Curly braces names *curly-braces-names*
10574
Bram Moolenaar84f72352012-03-11 15:57:40 +010010575In most places where you can use a variable, you can use a "curly braces name"
10576variable. This is a regular variable name with one or more expressions
10577wrapped in braces {} like this: >
Bram Moolenaar071d4272004-06-13 20:20:40 +000010578 my_{adjective}_variable
10579
10580When Vim encounters this, it evaluates the expression inside the braces, puts
10581that in place of the expression, and re-interprets the whole as a variable
10582name. So in the above example, if the variable "adjective" was set to
10583"noisy", then the reference would be to "my_noisy_variable", whereas if
10584"adjective" was set to "quiet", then it would be to "my_quiet_variable".
10585
10586One application for this is to create a set of variables governed by an option
Bram Moolenaar58b85342016-08-14 19:54:54 +020010587value. For example, the statement >
Bram Moolenaar071d4272004-06-13 20:20:40 +000010588 echo my_{&background}_message
10589
10590would output the contents of "my_dark_message" or "my_light_message" depending
10591on the current value of 'background'.
10592
10593You can use multiple brace pairs: >
10594 echo my_{adverb}_{adjective}_message
10595..or even nest them: >
10596 echo my_{ad{end_of_word}}_message
10597where "end_of_word" is either "verb" or "jective".
10598
10599However, the expression inside the braces must evaluate to a valid single
Bram Moolenaar402d2fe2005-04-15 21:00:38 +000010600variable name, e.g. this is invalid: >
Bram Moolenaar071d4272004-06-13 20:20:40 +000010601 :let foo='a + b'
10602 :echo c{foo}d
10603.. since the result of expansion is "ca + bd", which is not a variable name.
10604
10605 *curly-braces-function-names*
10606You can call and define functions by an evaluated name in a similar way.
10607Example: >
10608 :let func_end='whizz'
10609 :call my_func_{func_end}(parameter)
10610
10611This would call the function "my_func_whizz(parameter)".
10612
Bram Moolenaar84f72352012-03-11 15:57:40 +010010613This does NOT work: >
10614 :let i = 3
10615 :let @{i} = '' " error
10616 :echo @{i} " error
10617
Bram Moolenaar071d4272004-06-13 20:20:40 +000010618==============================================================================
106197. Commands *expression-commands*
10620
10621:let {var-name} = {expr1} *:let* *E18*
10622 Set internal variable {var-name} to the result of the
10623 expression {expr1}. The variable will get the type
10624 from the {expr}. If {var-name} didn't exist yet, it
10625 is created.
10626
Bram Moolenaar13065c42005-01-08 16:08:21 +000010627:let {var-name}[{idx}] = {expr1} *E689*
10628 Set a list item to the result of the expression
10629 {expr1}. {var-name} must refer to a list and {idx}
10630 must be a valid index in that list. For nested list
10631 the index can be repeated.
Bram Moolenaar446cb832008-06-24 21:56:24 +000010632 This cannot be used to add an item to a |List|.
Bram Moolenaar58b85342016-08-14 19:54:54 +020010633 This cannot be used to set a byte in a String. You
Bram Moolenaar446cb832008-06-24 21:56:24 +000010634 can do that like this: >
10635 :let var = var[0:2] . 'X' . var[4:]
Bram Moolenaar6e5ea8d2019-01-12 22:47:31 +010010636< When {var-name} is a |Blob| then {idx} can be the
10637 length of the blob, in which case one byte is
10638 appended.
10639
Bram Moolenaar3a3a7232005-01-17 22:16:15 +000010640 *E711* *E719*
10641:let {var-name}[{idx1}:{idx2}] = {expr1} *E708* *E709* *E710*
Bram Moolenaar32466aa2006-02-24 23:53:04 +000010642 Set a sequence of items in a |List| to the result of
10643 the expression {expr1}, which must be a list with the
Bram Moolenaar9588a0f2005-01-08 21:45:39 +000010644 correct number of items.
10645 {idx1} can be omitted, zero is used instead.
10646 {idx2} can be omitted, meaning the end of the list.
10647 When the selected range of items is partly past the
10648 end of the list, items will be added.
10649
Bram Moolenaar748bf032005-02-02 23:04:36 +000010650 *:let+=* *:let-=* *:let.=* *E734*
Bram Moolenaar3a3a7232005-01-17 22:16:15 +000010651:let {var} += {expr1} Like ":let {var} = {var} + {expr1}".
10652:let {var} -= {expr1} Like ":let {var} = {var} - {expr1}".
10653:let {var} .= {expr1} Like ":let {var} = {var} . {expr1}".
10654 These fail if {var} was not set yet and when the type
10655 of {var} and {expr1} don't fit the operator.
10656
10657
Bram Moolenaar071d4272004-06-13 20:20:40 +000010658:let ${env-name} = {expr1} *:let-environment* *:let-$*
10659 Set environment variable {env-name} to the result of
10660 the expression {expr1}. The type is always String.
Bram Moolenaar3a3a7232005-01-17 22:16:15 +000010661:let ${env-name} .= {expr1}
10662 Append {expr1} to the environment variable {env-name}.
10663 If the environment variable didn't exist yet this
10664 works like "=".
Bram Moolenaar071d4272004-06-13 20:20:40 +000010665
10666:let @{reg-name} = {expr1} *:let-register* *:let-@*
10667 Write the result of the expression {expr1} in register
10668 {reg-name}. {reg-name} must be a single letter, and
10669 must be the name of a writable register (see
10670 |registers|). "@@" can be used for the unnamed
10671 register, "@/" for the search pattern.
10672 If the result of {expr1} ends in a <CR> or <NL>, the
10673 register will be linewise, otherwise it will be set to
10674 characterwise.
10675 This can be used to clear the last search pattern: >
10676 :let @/ = ""
10677< This is different from searching for an empty string,
10678 that would match everywhere.
10679
Bram Moolenaar3a3a7232005-01-17 22:16:15 +000010680:let @{reg-name} .= {expr1}
Bram Moolenaar58b85342016-08-14 19:54:54 +020010681 Append {expr1} to register {reg-name}. If the
Bram Moolenaar3a3a7232005-01-17 22:16:15 +000010682 register was empty it's like setting it to {expr1}.
10683
Bram Moolenaaref2f6562007-05-06 13:32:59 +000010684:let &{option-name} = {expr1} *:let-option* *:let-&*
Bram Moolenaar071d4272004-06-13 20:20:40 +000010685 Set option {option-name} to the result of the
Bram Moolenaarfca34d62005-01-04 21:38:36 +000010686 expression {expr1}. A String or Number value is
10687 always converted to the type of the option.
Bram Moolenaar071d4272004-06-13 20:20:40 +000010688 For an option local to a window or buffer the effect
10689 is just like using the |:set| command: both the local
Bram Moolenaara5fac542005-10-12 20:58:49 +000010690 value and the global value are changed.
Bram Moolenaarfca34d62005-01-04 21:38:36 +000010691 Example: >
10692 :let &path = &path . ',/usr/local/include'
Bram Moolenaar3df01732017-02-17 22:47:16 +010010693< This also works for terminal codes in the form t_xx.
10694 But only for alphanumerical names. Example: >
10695 :let &t_k1 = "\<Esc>[234;"
10696< When the code does not exist yet it will be created as
10697 a terminal key code, there is no error.
Bram Moolenaar071d4272004-06-13 20:20:40 +000010698
Bram Moolenaar3a3a7232005-01-17 22:16:15 +000010699:let &{option-name} .= {expr1}
10700 For a string option: Append {expr1} to the value.
10701 Does not insert a comma like |:set+=|.
10702
10703:let &{option-name} += {expr1}
10704:let &{option-name} -= {expr1}
10705 For a number or boolean option: Add or subtract
10706 {expr1}.
10707
Bram Moolenaar071d4272004-06-13 20:20:40 +000010708:let &l:{option-name} = {expr1}
Bram Moolenaar3a3a7232005-01-17 22:16:15 +000010709:let &l:{option-name} .= {expr1}
10710:let &l:{option-name} += {expr1}
10711:let &l:{option-name} -= {expr1}
Bram Moolenaar071d4272004-06-13 20:20:40 +000010712 Like above, but only set the local value of an option
10713 (if there is one). Works like |:setlocal|.
10714
10715:let &g:{option-name} = {expr1}
Bram Moolenaar3a3a7232005-01-17 22:16:15 +000010716:let &g:{option-name} .= {expr1}
10717:let &g:{option-name} += {expr1}
10718:let &g:{option-name} -= {expr1}
Bram Moolenaar071d4272004-06-13 20:20:40 +000010719 Like above, but only set the global value of an option
10720 (if there is one). Works like |:setglobal|.
10721
Bram Moolenaar13065c42005-01-08 16:08:21 +000010722:let [{name1}, {name2}, ...] = {expr1} *:let-unpack* *E687* *E688*
Bram Moolenaar32466aa2006-02-24 23:53:04 +000010723 {expr1} must evaluate to a |List|. The first item in
Bram Moolenaarfca34d62005-01-04 21:38:36 +000010724 the list is assigned to {name1}, the second item to
10725 {name2}, etc.
10726 The number of names must match the number of items in
Bram Moolenaar32466aa2006-02-24 23:53:04 +000010727 the |List|.
Bram Moolenaarfca34d62005-01-04 21:38:36 +000010728 Each name can be one of the items of the ":let"
10729 command as mentioned above.
10730 Example: >
10731 :let [s, item] = GetItem(s)
Bram Moolenaar3a3a7232005-01-17 22:16:15 +000010732< Detail: {expr1} is evaluated first, then the
10733 assignments are done in sequence. This matters if
10734 {name2} depends on {name1}. Example: >
10735 :let x = [0, 1]
10736 :let i = 0
10737 :let [i, x[i]] = [1, 2]
10738 :echo x
10739< The result is [0, 2].
10740
10741:let [{name1}, {name2}, ...] .= {expr1}
10742:let [{name1}, {name2}, ...] += {expr1}
10743:let [{name1}, {name2}, ...] -= {expr1}
10744 Like above, but append/add/subtract the value for each
Bram Moolenaar32466aa2006-02-24 23:53:04 +000010745 |List| item.
Bram Moolenaarfca34d62005-01-04 21:38:36 +000010746
10747:let [{name}, ..., ; {lastname}] = {expr1}
Bram Moolenaar32466aa2006-02-24 23:53:04 +000010748 Like |:let-unpack| above, but the |List| may have more
Bram Moolenaar3a3a7232005-01-17 22:16:15 +000010749 items than there are names. A list of the remaining
10750 items is assigned to {lastname}. If there are no
10751 remaining items {lastname} is set to an empty list.
Bram Moolenaarfca34d62005-01-04 21:38:36 +000010752 Example: >
10753 :let [a, b; rest] = ["aval", "bval", 3, 4]
10754<
Bram Moolenaar3a3a7232005-01-17 22:16:15 +000010755:let [{name}, ..., ; {lastname}] .= {expr1}
10756:let [{name}, ..., ; {lastname}] += {expr1}
10757:let [{name}, ..., ; {lastname}] -= {expr1}
10758 Like above, but append/add/subtract the value for each
Bram Moolenaar32466aa2006-02-24 23:53:04 +000010759 |List| item.
Bram Moolenaar4a748032010-09-30 21:47:56 +020010760
10761 *E121*
Bram Moolenaar58b85342016-08-14 19:54:54 +020010762:let {var-name} .. List the value of variable {var-name}. Multiple
Bram Moolenaardcaf10e2005-01-21 11:55:25 +000010763 variable names may be given. Special names recognized
10764 here: *E738*
Bram Moolenaarca003e12006-03-17 23:19:38 +000010765 g: global variables
10766 b: local buffer variables
10767 w: local window variables
Bram Moolenaar910f66f2006-04-05 20:41:53 +000010768 t: local tab page variables
Bram Moolenaarca003e12006-03-17 23:19:38 +000010769 s: script-local variables
10770 l: local function variables
Bram Moolenaardcaf10e2005-01-21 11:55:25 +000010771 v: Vim variables.
Bram Moolenaar071d4272004-06-13 20:20:40 +000010772
Bram Moolenaard7ee7ce2005-01-03 21:02:03 +000010773:let List the values of all variables. The type of the
10774 variable is indicated before the value:
10775 <nothing> String
10776 # Number
Bram Moolenaarc9b4b052006-04-30 18:54:39 +000010777 * Funcref
Bram Moolenaar071d4272004-06-13 20:20:40 +000010778
Bram Moolenaar2ce06f62005-01-31 19:19:04 +000010779
Bram Moolenaaref2f6562007-05-06 13:32:59 +000010780:unl[et][!] {name} ... *:unlet* *:unl* *E108* *E795*
Bram Moolenaar2ce06f62005-01-31 19:19:04 +000010781 Remove the internal variable {name}. Several variable
10782 names can be given, they are all removed. The name
Bram Moolenaar32466aa2006-02-24 23:53:04 +000010783 may also be a |List| or |Dictionary| item.
Bram Moolenaar071d4272004-06-13 20:20:40 +000010784 With [!] no error message is given for non-existing
10785 variables.
Bram Moolenaar32466aa2006-02-24 23:53:04 +000010786 One or more items from a |List| can be removed: >
Bram Moolenaar9cd15162005-01-16 22:02:49 +000010787 :unlet list[3] " remove fourth item
10788 :unlet list[3:] " remove fourth item to last
Bram Moolenaar32466aa2006-02-24 23:53:04 +000010789< One item from a |Dictionary| can be removed at a time: >
Bram Moolenaar9cd15162005-01-16 22:02:49 +000010790 :unlet dict['two']
10791 :unlet dict.two
Bram Moolenaarc236c162008-07-13 17:41:49 +000010792< This is especially useful to clean up used global
10793 variables and script-local variables (these are not
10794 deleted when the script ends). Function-local
10795 variables are automatically deleted when the function
10796 ends.
Bram Moolenaar071d4272004-06-13 20:20:40 +000010797
Bram Moolenaar137374f2018-05-13 15:59:50 +020010798:unl[et] ${env-name} ... *:unlet-environment* *:unlet-$*
10799 Remove environment variable {env-name}.
10800 Can mix {name} and ${env-name} in one :unlet command.
10801 No error message is given for a non-existing
10802 variable, also without !.
10803 If the system does not support deleting an environment
10804 variable, it is made emtpy.
10805
Bram Moolenaar2ce06f62005-01-31 19:19:04 +000010806:lockv[ar][!] [depth] {name} ... *:lockvar* *:lockv*
10807 Lock the internal variable {name}. Locking means that
10808 it can no longer be changed (until it is unlocked).
10809 A locked variable can be deleted: >
10810 :lockvar v
10811 :let v = 'asdf' " fails!
10812 :unlet v
Bram Moolenaare7877fe2017-02-20 22:35:33 +010010813< *E741* *E940*
Bram Moolenaar2ce06f62005-01-31 19:19:04 +000010814 If you try to change a locked variable you get an
Bram Moolenaare7877fe2017-02-20 22:35:33 +010010815 error message: "E741: Value is locked: {name}".
10816 If you try to lock or unlock a built-in variable you
10817 get an error message: "E940: Cannot lock or unlock
10818 variable {name}".
Bram Moolenaar2ce06f62005-01-31 19:19:04 +000010819
Bram Moolenaar32466aa2006-02-24 23:53:04 +000010820 [depth] is relevant when locking a |List| or
10821 |Dictionary|. It specifies how deep the locking goes:
10822 1 Lock the |List| or |Dictionary| itself,
Bram Moolenaar2ce06f62005-01-31 19:19:04 +000010823 cannot add or remove items, but can
10824 still change their values.
10825 2 Also lock the values, cannot change
Bram Moolenaar32466aa2006-02-24 23:53:04 +000010826 the items. If an item is a |List| or
10827 |Dictionary|, cannot add or remove
Bram Moolenaar2ce06f62005-01-31 19:19:04 +000010828 items, but can still change the
10829 values.
Bram Moolenaar32466aa2006-02-24 23:53:04 +000010830 3 Like 2 but for the |List| /
10831 |Dictionary| in the |List| /
10832 |Dictionary|, one level deeper.
10833 The default [depth] is 2, thus when {name} is a |List|
10834 or |Dictionary| the values cannot be changed.
Bram Moolenaar2ce06f62005-01-31 19:19:04 +000010835 *E743*
10836 For unlimited depth use [!] and omit [depth].
10837 However, there is a maximum depth of 100 to catch
10838 loops.
10839
Bram Moolenaar32466aa2006-02-24 23:53:04 +000010840 Note that when two variables refer to the same |List|
10841 and you lock one of them, the |List| will also be
Bram Moolenaar910f66f2006-04-05 20:41:53 +000010842 locked when used through the other variable.
10843 Example: >
Bram Moolenaar2ce06f62005-01-31 19:19:04 +000010844 :let l = [0, 1, 2, 3]
10845 :let cl = l
10846 :lockvar l
10847 :let cl[1] = 99 " won't work!
10848< You may want to make a copy of a list to avoid this.
10849 See |deepcopy()|.
10850
10851
10852:unlo[ckvar][!] [depth] {name} ... *:unlockvar* *:unlo*
10853 Unlock the internal variable {name}. Does the
10854 opposite of |:lockvar|.
10855
10856
Bram Moolenaar071d4272004-06-13 20:20:40 +000010857:if {expr1} *:if* *:endif* *:en* *E171* *E579* *E580*
10858:en[dif] Execute the commands until the next matching ":else"
10859 or ":endif" if {expr1} evaluates to non-zero.
10860
10861 From Vim version 4.5 until 5.0, every Ex command in
10862 between the ":if" and ":endif" is ignored. These two
10863 commands were just to allow for future expansions in a
Bram Moolenaar85084ef2016-01-17 22:26:33 +010010864 backward compatible way. Nesting was allowed. Note
Bram Moolenaar071d4272004-06-13 20:20:40 +000010865 that any ":else" or ":elseif" was ignored, the "else"
10866 part was not executed either.
10867
10868 You can use this to remain compatible with older
10869 versions: >
10870 :if version >= 500
10871 : version-5-specific-commands
10872 :endif
10873< The commands still need to be parsed to find the
10874 "endif". Sometimes an older Vim has a problem with a
10875 new command. For example, ":silent" is recognized as
10876 a ":substitute" command. In that case ":execute" can
10877 avoid problems: >
10878 :if version >= 600
10879 : execute "silent 1,$delete"
10880 :endif
10881<
10882 NOTE: The ":append" and ":insert" commands don't work
10883 properly in between ":if" and ":endif".
10884
10885 *:else* *:el* *E581* *E583*
10886:el[se] Execute the commands until the next matching ":else"
10887 or ":endif" if they previously were not being
10888 executed.
10889
10890 *:elseif* *:elsei* *E582* *E584*
10891:elsei[f] {expr1} Short for ":else" ":if", with the addition that there
10892 is no extra ":endif".
10893
10894:wh[ile] {expr1} *:while* *:endwhile* *:wh* *:endw*
Bram Moolenaar3a3a7232005-01-17 22:16:15 +000010895 *E170* *E585* *E588* *E733*
Bram Moolenaar071d4272004-06-13 20:20:40 +000010896:endw[hile] Repeat the commands between ":while" and ":endwhile",
10897 as long as {expr1} evaluates to non-zero.
10898 When an error is detected from a command inside the
10899 loop, execution continues after the "endwhile".
Bram Moolenaar12805862005-01-05 22:16:17 +000010900 Example: >
10901 :let lnum = 1
10902 :while lnum <= line("$")
10903 :call FixLine(lnum)
10904 :let lnum = lnum + 1
10905 :endwhile
10906<
Bram Moolenaar071d4272004-06-13 20:20:40 +000010907 NOTE: The ":append" and ":insert" commands don't work
Bram Moolenaard8b02732005-01-14 21:48:43 +000010908 properly inside a ":while" and ":for" loop.
Bram Moolenaar071d4272004-06-13 20:20:40 +000010909
Bram Moolenaar3a3a7232005-01-17 22:16:15 +000010910:for {var} in {list} *:for* *E690* *E732*
Bram Moolenaar12805862005-01-05 22:16:17 +000010911:endfo[r] *:endfo* *:endfor*
10912 Repeat the commands between ":for" and ":endfor" for
Bram Moolenaar3a7c85b2005-02-05 21:39:53 +000010913 each item in {list}. Variable {var} is set to the
Bram Moolenaarde8866b2005-01-06 23:24:37 +000010914 value of each item.
10915 When an error is detected for a command inside the
Bram Moolenaar12805862005-01-05 22:16:17 +000010916 loop, execution continues after the "endfor".
Bram Moolenaar572cb562005-08-05 21:35:02 +000010917 Changing {list} inside the loop affects what items are
10918 used. Make a copy if this is unwanted: >
Bram Moolenaarde8866b2005-01-06 23:24:37 +000010919 :for item in copy(mylist)
10920< When not making a copy, Vim stores a reference to the
10921 next item in the list, before executing the commands
Bram Moolenaar58b85342016-08-14 19:54:54 +020010922 with the current item. Thus the current item can be
Bram Moolenaarde8866b2005-01-06 23:24:37 +000010923 removed without effect. Removing any later item means
10924 it will not be found. Thus the following example
10925 works (an inefficient way to make a list empty): >
Bram Moolenaar8f3f58f2010-01-06 20:52:26 +010010926 for item in mylist
10927 call remove(mylist, 0)
10928 endfor
Bram Moolenaar9588a0f2005-01-08 21:45:39 +000010929< Note that reordering the list (e.g., with sort() or
10930 reverse()) may have unexpected effects.
Bram Moolenaar12805862005-01-05 22:16:17 +000010931
Bram Moolenaar12805862005-01-05 22:16:17 +000010932:for [{var1}, {var2}, ...] in {listlist}
10933:endfo[r]
10934 Like ":for" above, but each item in {listlist} must be
10935 a list, of which each item is assigned to {var1},
10936 {var2}, etc. Example: >
10937 :for [lnum, col] in [[1, 3], [2, 5], [3, 8]]
10938 :echo getline(lnum)[col]
10939 :endfor
10940<
Bram Moolenaar071d4272004-06-13 20:20:40 +000010941 *:continue* *:con* *E586*
Bram Moolenaar12805862005-01-05 22:16:17 +000010942:con[tinue] When used inside a ":while" or ":for" loop, jumps back
10943 to the start of the loop.
10944 If it is used after a |:try| inside the loop but
10945 before the matching |:finally| (if present), the
10946 commands following the ":finally" up to the matching
10947 |:endtry| are executed first. This process applies to
10948 all nested ":try"s inside the loop. The outermost
10949 ":endtry" then jumps back to the start of the loop.
Bram Moolenaar071d4272004-06-13 20:20:40 +000010950
10951 *:break* *:brea* *E587*
Bram Moolenaar12805862005-01-05 22:16:17 +000010952:brea[k] When used inside a ":while" or ":for" loop, skips to
10953 the command after the matching ":endwhile" or
10954 ":endfor".
10955 If it is used after a |:try| inside the loop but
10956 before the matching |:finally| (if present), the
10957 commands following the ":finally" up to the matching
10958 |:endtry| are executed first. This process applies to
10959 all nested ":try"s inside the loop. The outermost
10960 ":endtry" then jumps to the command after the loop.
Bram Moolenaar071d4272004-06-13 20:20:40 +000010961
10962:try *:try* *:endt* *:endtry* *E600* *E601* *E602*
10963:endt[ry] Change the error handling for the commands between
10964 ":try" and ":endtry" including everything being
10965 executed across ":source" commands, function calls,
10966 or autocommand invocations.
10967
10968 When an error or interrupt is detected and there is
10969 a |:finally| command following, execution continues
10970 after the ":finally". Otherwise, or when the
10971 ":endtry" is reached thereafter, the next
10972 (dynamically) surrounding ":try" is checked for
10973 a corresponding ":finally" etc. Then the script
10974 processing is terminated. (Whether a function
10975 definition has an "abort" argument does not matter.)
10976 Example: >
10977 :try | edit too much | finally | echo "cleanup" | endtry
10978 :echo "impossible" " not reached, script terminated above
10979<
10980 Moreover, an error or interrupt (dynamically) inside
10981 ":try" and ":endtry" is converted to an exception. It
10982 can be caught as if it were thrown by a |:throw|
10983 command (see |:catch|). In this case, the script
10984 processing is not terminated.
10985
10986 The value "Vim:Interrupt" is used for an interrupt
10987 exception. An error in a Vim command is converted
10988 to a value of the form "Vim({command}):{errmsg}",
10989 other errors are converted to a value of the form
10990 "Vim:{errmsg}". {command} is the full command name,
10991 and {errmsg} is the message that is displayed if the
10992 error exception is not caught, always beginning with
10993 the error number.
10994 Examples: >
10995 :try | sleep 100 | catch /^Vim:Interrupt$/ | endtry
10996 :try | edit | catch /^Vim(edit):E\d\+/ | echo "error" | endtry
10997<
10998 *:cat* *:catch* *E603* *E604* *E605*
Bram Moolenaar8f3f58f2010-01-06 20:52:26 +010010999:cat[ch] /{pattern}/ The following commands until the next |:catch|,
Bram Moolenaar071d4272004-06-13 20:20:40 +000011000 |:finally|, or |:endtry| that belongs to the same
11001 |:try| as the ":catch" are executed when an exception
11002 matching {pattern} is being thrown and has not yet
11003 been caught by a previous ":catch". Otherwise, these
11004 commands are skipped.
11005 When {pattern} is omitted all errors are caught.
11006 Examples: >
11007 :catch /^Vim:Interrupt$/ " catch interrupts (CTRL-C)
11008 :catch /^Vim\%((\a\+)\)\=:E/ " catch all Vim errors
11009 :catch /^Vim\%((\a\+)\)\=:/ " catch errors and interrupts
11010 :catch /^Vim(write):/ " catch all errors in :write
11011 :catch /^Vim\%((\a\+)\)\=:E123/ " catch error E123
11012 :catch /my-exception/ " catch user exception
11013 :catch /.*/ " catch everything
11014 :catch " same as /.*/
11015<
11016 Another character can be used instead of / around the
11017 {pattern}, so long as it does not have a special
11018 meaning (e.g., '|' or '"') and doesn't occur inside
11019 {pattern}.
Bram Moolenaar7e38ea22014-04-05 22:55:53 +020011020 Information about the exception is available in
11021 |v:exception|. Also see |throw-variables|.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011022 NOTE: It is not reliable to ":catch" the TEXT of
11023 an error message because it may vary in different
11024 locales.
11025
11026 *:fina* *:finally* *E606* *E607*
11027:fina[lly] The following commands until the matching |:endtry|
11028 are executed whenever the part between the matching
11029 |:try| and the ":finally" is left: either by falling
11030 through to the ":finally" or by a |:continue|,
11031 |:break|, |:finish|, or |:return|, or by an error or
11032 interrupt or exception (see |:throw|).
11033
11034 *:th* *:throw* *E608*
11035:th[row] {expr1} The {expr1} is evaluated and thrown as an exception.
11036 If the ":throw" is used after a |:try| but before the
11037 first corresponding |:catch|, commands are skipped
11038 until the first ":catch" matching {expr1} is reached.
11039 If there is no such ":catch" or if the ":throw" is
11040 used after a ":catch" but before the |:finally|, the
11041 commands following the ":finally" (if present) up to
11042 the matching |:endtry| are executed. If the ":throw"
11043 is after the ":finally", commands up to the ":endtry"
11044 are skipped. At the ":endtry", this process applies
11045 again for the next dynamically surrounding ":try"
11046 (which may be found in a calling function or sourcing
11047 script), until a matching ":catch" has been found.
11048 If the exception is not caught, the command processing
11049 is terminated.
11050 Example: >
11051 :try | throw "oops" | catch /^oo/ | echo "caught" | endtry
Bram Moolenaar662db672011-03-22 14:05:35 +010011052< Note that "catch" may need to be on a separate line
11053 for when an error causes the parsing to skip the whole
11054 line and not see the "|" that separates the commands.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011055
11056 *:ec* *:echo*
11057:ec[ho] {expr1} .. Echoes each {expr1}, with a space in between. The
11058 first {expr1} starts on a new line.
11059 Also see |:comment|.
11060 Use "\n" to start a new line. Use "\r" to move the
11061 cursor to the first column.
11062 Uses the highlighting set by the |:echohl| command.
11063 Cannot be followed by a comment.
11064 Example: >
11065 :echo "the value of 'shell' is" &shell
Bram Moolenaaref2f6562007-05-06 13:32:59 +000011066< *:echo-redraw*
11067 A later redraw may make the message disappear again.
11068 And since Vim mostly postpones redrawing until it's
11069 finished with a sequence of commands this happens
11070 quite often. To avoid that a command from before the
11071 ":echo" causes a redraw afterwards (redraws are often
11072 postponed until you type something), force a redraw
11073 with the |:redraw| command. Example: >
Bram Moolenaar071d4272004-06-13 20:20:40 +000011074 :new | redraw | echo "there is a new window"
11075<
11076 *:echon*
11077:echon {expr1} .. Echoes each {expr1}, without anything added. Also see
11078 |:comment|.
11079 Uses the highlighting set by the |:echohl| command.
11080 Cannot be followed by a comment.
11081 Example: >
11082 :echon "the value of 'shell' is " &shell
11083<
11084 Note the difference between using ":echo", which is a
11085 Vim command, and ":!echo", which is an external shell
11086 command: >
11087 :!echo % --> filename
11088< The arguments of ":!" are expanded, see |:_%|. >
11089 :!echo "%" --> filename or "filename"
11090< Like the previous example. Whether you see the double
11091 quotes or not depends on your 'shell'. >
11092 :echo % --> nothing
11093< The '%' is an illegal character in an expression. >
11094 :echo "%" --> %
11095< This just echoes the '%' character. >
11096 :echo expand("%") --> filename
11097< This calls the expand() function to expand the '%'.
11098
11099 *:echoh* *:echohl*
11100:echoh[l] {name} Use the highlight group {name} for the following
11101 |:echo|, |:echon| and |:echomsg| commands. Also used
11102 for the |input()| prompt. Example: >
11103 :echohl WarningMsg | echo "Don't panic!" | echohl None
11104< Don't forget to set the group back to "None",
11105 otherwise all following echo's will be highlighted.
11106
11107 *:echom* *:echomsg*
11108:echom[sg] {expr1} .. Echo the expression(s) as a true message, saving the
11109 message in the |message-history|.
11110 Spaces are placed between the arguments as with the
11111 |:echo| command. But unprintable characters are
11112 displayed, not interpreted.
Bram Moolenaaref2f6562007-05-06 13:32:59 +000011113 The parsing works slightly different from |:echo|,
11114 more like |:execute|. All the expressions are first
11115 evaluated and concatenated before echoing anything.
Bram Moolenaar461a7fc2018-12-22 13:28:07 +010011116 If expressions does not evaluate to a Number or
11117 String, string() is used to turn it into a string.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011118 Uses the highlighting set by the |:echohl| command.
11119 Example: >
11120 :echomsg "It's a Zizzer Zazzer Zuzz, as you can plainly see."
Bram Moolenaaref2f6562007-05-06 13:32:59 +000011121< See |:echo-redraw| to avoid the message disappearing
11122 when the screen is redrawn.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011123 *:echoe* *:echoerr*
11124:echoe[rr] {expr1} .. Echo the expression(s) as an error message, saving the
11125 message in the |message-history|. When used in a
11126 script or function the line number will be added.
11127 Spaces are placed between the arguments as with the
Bram Moolenaar461a7fc2018-12-22 13:28:07 +010011128 |:echomsg| command. When used inside a try conditional,
Bram Moolenaar071d4272004-06-13 20:20:40 +000011129 the message is raised as an error exception instead
11130 (see |try-echoerr|).
11131 Example: >
11132 :echoerr "This script just failed!"
11133< If you just want a highlighted message use |:echohl|.
11134 And to get a beep: >
11135 :exe "normal \<Esc>"
11136<
11137 *:exe* *:execute*
11138:exe[cute] {expr1} .. Executes the string that results from the evaluation
Bram Moolenaar00a927d2010-05-14 23:24:24 +020011139 of {expr1} as an Ex command.
11140 Multiple arguments are concatenated, with a space in
11141 between. To avoid the extra space use the "."
11142 operator to concatenate strings into one argument.
11143 {expr1} is used as the processed command, command line
11144 editing keys are not recognized.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011145 Cannot be followed by a comment.
11146 Examples: >
Bram Moolenaar00a927d2010-05-14 23:24:24 +020011147 :execute "buffer" nextbuf
11148 :execute "normal" count . "w"
Bram Moolenaar071d4272004-06-13 20:20:40 +000011149<
11150 ":execute" can be used to append a command to commands
11151 that don't accept a '|'. Example: >
11152 :execute '!ls' | echo "theend"
11153
11154< ":execute" is also a nice way to avoid having to type
11155 control characters in a Vim script for a ":normal"
11156 command: >
11157 :execute "normal ixxx\<Esc>"
11158< This has an <Esc> character, see |expr-string|.
11159
Bram Moolenaar446cb832008-06-24 21:56:24 +000011160 Be careful to correctly escape special characters in
11161 file names. The |fnameescape()| function can be used
Bram Moolenaar05bb9532008-07-04 09:44:11 +000011162 for Vim commands, |shellescape()| for |:!| commands.
11163 Examples: >
Bram Moolenaar446cb832008-06-24 21:56:24 +000011164 :execute "e " . fnameescape(filename)
Bram Moolenaar251835e2014-02-24 02:51:51 +010011165 :execute "!ls " . shellescape(filename, 1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000011166<
Bram Moolenaar071d4272004-06-13 20:20:40 +000011167 Note: The executed string may be any command-line, but
Bram Moolenaar76f3b1a2014-03-27 22:30:07 +010011168 starting or ending "if", "while" and "for" does not
11169 always work, because when commands are skipped the
11170 ":execute" is not evaluated and Vim loses track of
11171 where blocks start and end. Also "break" and
11172 "continue" should not be inside ":execute".
11173 This example does not work, because the ":execute" is
11174 not evaluated and Vim does not see the "while", and
11175 gives an error for finding an ":endwhile": >
11176 :if 0
11177 : execute 'while i > 5'
11178 : echo "test"
11179 : endwhile
11180 :endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011181<
11182 It is allowed to have a "while" or "if" command
11183 completely in the executed string: >
11184 :execute 'while i < 5 | echo i | let i = i + 1 | endwhile'
11185<
11186
Bram Moolenaar8f3f58f2010-01-06 20:52:26 +010011187 *:exe-comment*
Bram Moolenaar071d4272004-06-13 20:20:40 +000011188 ":execute", ":echo" and ":echon" cannot be followed by
11189 a comment directly, because they see the '"' as the
11190 start of a string. But, you can use '|' followed by a
11191 comment. Example: >
11192 :echo "foo" | "this is a comment
11193
11194==============================================================================
111958. Exception handling *exception-handling*
11196
11197The Vim script language comprises an exception handling feature. This section
11198explains how it can be used in a Vim script.
11199
11200Exceptions may be raised by Vim on an error or on interrupt, see
11201|catch-errors| and |catch-interrupt|. You can also explicitly throw an
11202exception by using the ":throw" command, see |throw-catch|.
11203
11204
11205TRY CONDITIONALS *try-conditionals*
11206
11207Exceptions can be caught or can cause cleanup code to be executed. You can
11208use a try conditional to specify catch clauses (that catch exceptions) and/or
11209a finally clause (to be executed for cleanup).
11210 A try conditional begins with a |:try| command and ends at the matching
11211|:endtry| command. In between, you can use a |:catch| command to start
11212a catch clause, or a |:finally| command to start a finally clause. There may
11213be none or multiple catch clauses, but there is at most one finally clause,
11214which must not be followed by any catch clauses. The lines before the catch
11215clauses and the finally clause is called a try block. >
11216
11217 :try
Bram Moolenaar446cb832008-06-24 21:56:24 +000011218 : ...
11219 : ... TRY BLOCK
11220 : ...
Bram Moolenaar071d4272004-06-13 20:20:40 +000011221 :catch /{pattern}/
Bram Moolenaar446cb832008-06-24 21:56:24 +000011222 : ...
11223 : ... CATCH CLAUSE
11224 : ...
Bram Moolenaar071d4272004-06-13 20:20:40 +000011225 :catch /{pattern}/
Bram Moolenaar446cb832008-06-24 21:56:24 +000011226 : ...
11227 : ... CATCH CLAUSE
11228 : ...
Bram Moolenaar071d4272004-06-13 20:20:40 +000011229 :finally
Bram Moolenaar446cb832008-06-24 21:56:24 +000011230 : ...
11231 : ... FINALLY CLAUSE
11232 : ...
Bram Moolenaar071d4272004-06-13 20:20:40 +000011233 :endtry
11234
11235The try conditional allows to watch code for exceptions and to take the
11236appropriate actions. Exceptions from the try block may be caught. Exceptions
11237from the try block and also the catch clauses may cause cleanup actions.
11238 When no exception is thrown during execution of the try block, the control
11239is transferred to the finally clause, if present. After its execution, the
11240script continues with the line following the ":endtry".
11241 When an exception occurs during execution of the try block, the remaining
11242lines in the try block are skipped. The exception is matched against the
11243patterns specified as arguments to the ":catch" commands. The catch clause
11244after the first matching ":catch" is taken, other catch clauses are not
11245executed. The catch clause ends when the next ":catch", ":finally", or
11246":endtry" command is reached - whatever is first. Then, the finally clause
11247(if present) is executed. When the ":endtry" is reached, the script execution
11248continues in the following line as usual.
11249 When an exception that does not match any of the patterns specified by the
11250":catch" commands is thrown in the try block, the exception is not caught by
11251that try conditional and none of the catch clauses is executed. Only the
11252finally clause, if present, is taken. The exception pends during execution of
11253the finally clause. It is resumed at the ":endtry", so that commands after
11254the ":endtry" are not executed and the exception might be caught elsewhere,
11255see |try-nesting|.
11256 When during execution of a catch clause another exception is thrown, the
Bram Moolenaar58b85342016-08-14 19:54:54 +020011257remaining lines in that catch clause are not executed. The new exception is
Bram Moolenaar071d4272004-06-13 20:20:40 +000011258not matched against the patterns in any of the ":catch" commands of the same
11259try conditional and none of its catch clauses is taken. If there is, however,
11260a finally clause, it is executed, and the exception pends during its
11261execution. The commands following the ":endtry" are not executed. The new
11262exception might, however, be caught elsewhere, see |try-nesting|.
11263 When during execution of the finally clause (if present) an exception is
Bram Moolenaar58b85342016-08-14 19:54:54 +020011264thrown, the remaining lines in the finally clause are skipped. If the finally
Bram Moolenaar071d4272004-06-13 20:20:40 +000011265clause has been taken because of an exception from the try block or one of the
11266catch clauses, the original (pending) exception is discarded. The commands
11267following the ":endtry" are not executed, and the exception from the finally
11268clause is propagated and can be caught elsewhere, see |try-nesting|.
11269
11270The finally clause is also executed, when a ":break" or ":continue" for
11271a ":while" loop enclosing the complete try conditional is executed from the
11272try block or a catch clause. Or when a ":return" or ":finish" is executed
11273from the try block or a catch clause of a try conditional in a function or
11274sourced script, respectively. The ":break", ":continue", ":return", or
11275":finish" pends during execution of the finally clause and is resumed when the
11276":endtry" is reached. It is, however, discarded when an exception is thrown
11277from the finally clause.
11278 When a ":break" or ":continue" for a ":while" loop enclosing the complete
11279try conditional or when a ":return" or ":finish" is encountered in the finally
11280clause, the rest of the finally clause is skipped, and the ":break",
11281":continue", ":return" or ":finish" is executed as usual. If the finally
11282clause has been taken because of an exception or an earlier ":break",
11283":continue", ":return", or ":finish" from the try block or a catch clause,
11284this pending exception or command is discarded.
11285
11286For examples see |throw-catch| and |try-finally|.
11287
11288
11289NESTING OF TRY CONDITIONALS *try-nesting*
11290
11291Try conditionals can be nested arbitrarily. That is, a complete try
11292conditional can be put into the try block, a catch clause, or the finally
11293clause of another try conditional. If the inner try conditional does not
11294catch an exception thrown in its try block or throws a new exception from one
11295of its catch clauses or its finally clause, the outer try conditional is
11296checked according to the rules above. If the inner try conditional is in the
11297try block of the outer try conditional, its catch clauses are checked, but
Bram Moolenaar58b85342016-08-14 19:54:54 +020011298otherwise only the finally clause is executed. It does not matter for
Bram Moolenaar071d4272004-06-13 20:20:40 +000011299nesting, whether the inner try conditional is directly contained in the outer
11300one, or whether the outer one sources a script or calls a function containing
11301the inner try conditional.
11302
11303When none of the active try conditionals catches an exception, just their
11304finally clauses are executed. Thereafter, the script processing terminates.
11305An error message is displayed in case of an uncaught exception explicitly
11306thrown by a ":throw" command. For uncaught error and interrupt exceptions
11307implicitly raised by Vim, the error message(s) or interrupt message are shown
11308as usual.
11309
11310For examples see |throw-catch|.
11311
11312
11313EXAMINING EXCEPTION HANDLING CODE *except-examine*
11314
11315Exception handling code can get tricky. If you are in doubt what happens, set
11316'verbose' to 13 or use the ":13verbose" command modifier when sourcing your
11317script file. Then you see when an exception is thrown, discarded, caught, or
11318finished. When using a verbosity level of at least 14, things pending in
11319a finally clause are also shown. This information is also given in debug mode
11320(see |debug-scripts|).
11321
11322
11323THROWING AND CATCHING EXCEPTIONS *throw-catch*
11324
11325You can throw any number or string as an exception. Use the |:throw| command
11326and pass the value to be thrown as argument: >
11327 :throw 4711
11328 :throw "string"
11329< *throw-expression*
11330You can also specify an expression argument. The expression is then evaluated
11331first, and the result is thrown: >
11332 :throw 4705 + strlen("string")
11333 :throw strpart("strings", 0, 6)
11334
11335An exception might be thrown during evaluation of the argument of the ":throw"
11336command. Unless it is caught there, the expression evaluation is abandoned.
11337The ":throw" command then does not throw a new exception.
11338 Example: >
11339
11340 :function! Foo(arg)
11341 : try
11342 : throw a:arg
11343 : catch /foo/
11344 : endtry
11345 : return 1
11346 :endfunction
11347 :
11348 :function! Bar()
11349 : echo "in Bar"
11350 : return 4710
11351 :endfunction
11352 :
11353 :throw Foo("arrgh") + Bar()
11354
11355This throws "arrgh", and "in Bar" is not displayed since Bar() is not
11356executed. >
11357 :throw Foo("foo") + Bar()
11358however displays "in Bar" and throws 4711.
11359
11360Any other command that takes an expression as argument might also be
Bram Moolenaar58b85342016-08-14 19:54:54 +020011361abandoned by an (uncaught) exception during the expression evaluation. The
Bram Moolenaar071d4272004-06-13 20:20:40 +000011362exception is then propagated to the caller of the command.
11363 Example: >
11364
11365 :if Foo("arrgh")
11366 : echo "then"
11367 :else
11368 : echo "else"
11369 :endif
11370
11371Here neither of "then" or "else" is displayed.
11372
11373 *catch-order*
11374Exceptions can be caught by a try conditional with one or more |:catch|
11375commands, see |try-conditionals|. The values to be caught by each ":catch"
11376command can be specified as a pattern argument. The subsequent catch clause
11377gets executed when a matching exception is caught.
11378 Example: >
11379
11380 :function! Foo(value)
11381 : try
11382 : throw a:value
11383 : catch /^\d\+$/
11384 : echo "Number thrown"
11385 : catch /.*/
11386 : echo "String thrown"
11387 : endtry
11388 :endfunction
11389 :
11390 :call Foo(0x1267)
11391 :call Foo('string')
11392
11393The first call to Foo() displays "Number thrown", the second "String thrown".
11394An exception is matched against the ":catch" commands in the order they are
11395specified. Only the first match counts. So you should place the more
11396specific ":catch" first. The following order does not make sense: >
11397
11398 : catch /.*/
11399 : echo "String thrown"
11400 : catch /^\d\+$/
11401 : echo "Number thrown"
11402
11403The first ":catch" here matches always, so that the second catch clause is
11404never taken.
11405
11406 *throw-variables*
11407If you catch an exception by a general pattern, you may access the exact value
11408in the variable |v:exception|: >
11409
11410 : catch /^\d\+$/
11411 : echo "Number thrown. Value is" v:exception
11412
11413You may also be interested where an exception was thrown. This is stored in
11414|v:throwpoint|. Note that "v:exception" and "v:throwpoint" are valid for the
11415exception most recently caught as long it is not finished.
11416 Example: >
11417
11418 :function! Caught()
11419 : if v:exception != ""
11420 : echo 'Caught "' . v:exception . '" in ' . v:throwpoint
11421 : else
11422 : echo 'Nothing caught'
11423 : endif
11424 :endfunction
11425 :
11426 :function! Foo()
11427 : try
11428 : try
11429 : try
11430 : throw 4711
11431 : finally
11432 : call Caught()
11433 : endtry
11434 : catch /.*/
11435 : call Caught()
11436 : throw "oops"
11437 : endtry
11438 : catch /.*/
11439 : call Caught()
11440 : finally
11441 : call Caught()
11442 : endtry
11443 :endfunction
11444 :
11445 :call Foo()
11446
11447This displays >
11448
11449 Nothing caught
11450 Caught "4711" in function Foo, line 4
11451 Caught "oops" in function Foo, line 10
11452 Nothing caught
11453
11454A practical example: The following command ":LineNumber" displays the line
11455number in the script or function where it has been used: >
11456
11457 :function! LineNumber()
11458 : return substitute(v:throwpoint, '.*\D\(\d\+\).*', '\1', "")
11459 :endfunction
11460 :command! LineNumber try | throw "" | catch | echo LineNumber() | endtry
11461<
11462 *try-nested*
11463An exception that is not caught by a try conditional can be caught by
11464a surrounding try conditional: >
11465
11466 :try
11467 : try
11468 : throw "foo"
11469 : catch /foobar/
11470 : echo "foobar"
11471 : finally
11472 : echo "inner finally"
11473 : endtry
11474 :catch /foo/
11475 : echo "foo"
11476 :endtry
11477
11478The inner try conditional does not catch the exception, just its finally
11479clause is executed. The exception is then caught by the outer try
11480conditional. The example displays "inner finally" and then "foo".
11481
11482 *throw-from-catch*
11483You can catch an exception and throw a new one to be caught elsewhere from the
11484catch clause: >
11485
11486 :function! Foo()
11487 : throw "foo"
11488 :endfunction
11489 :
11490 :function! Bar()
11491 : try
11492 : call Foo()
11493 : catch /foo/
11494 : echo "Caught foo, throw bar"
11495 : throw "bar"
11496 : endtry
11497 :endfunction
11498 :
11499 :try
11500 : call Bar()
11501 :catch /.*/
11502 : echo "Caught" v:exception
11503 :endtry
11504
11505This displays "Caught foo, throw bar" and then "Caught bar".
11506
11507 *rethrow*
11508There is no real rethrow in the Vim script language, but you may throw
11509"v:exception" instead: >
11510
11511 :function! Bar()
11512 : try
11513 : call Foo()
11514 : catch /.*/
11515 : echo "Rethrow" v:exception
11516 : throw v:exception
11517 : endtry
11518 :endfunction
11519< *try-echoerr*
11520Note that this method cannot be used to "rethrow" Vim error or interrupt
11521exceptions, because it is not possible to fake Vim internal exceptions.
11522Trying so causes an error exception. You should throw your own exception
11523denoting the situation. If you want to cause a Vim error exception containing
11524the original error exception value, you can use the |:echoerr| command: >
11525
11526 :try
11527 : try
11528 : asdf
11529 : catch /.*/
11530 : echoerr v:exception
11531 : endtry
11532 :catch /.*/
11533 : echo v:exception
11534 :endtry
11535
11536This code displays
11537
Bram Moolenaar446cb832008-06-24 21:56:24 +000011538 Vim(echoerr):Vim:E492: Not an editor command: asdf ~
Bram Moolenaar071d4272004-06-13 20:20:40 +000011539
11540
11541CLEANUP CODE *try-finally*
11542
11543Scripts often change global settings and restore them at their end. If the
11544user however interrupts the script by pressing CTRL-C, the settings remain in
Bram Moolenaar58b85342016-08-14 19:54:54 +020011545an inconsistent state. The same may happen to you in the development phase of
Bram Moolenaar071d4272004-06-13 20:20:40 +000011546a script when an error occurs or you explicitly throw an exception without
11547catching it. You can solve these problems by using a try conditional with
11548a finally clause for restoring the settings. Its execution is guaranteed on
11549normal control flow, on error, on an explicit ":throw", and on interrupt.
11550(Note that errors and interrupts from inside the try conditional are converted
Bram Moolenaar58b85342016-08-14 19:54:54 +020011551to exceptions. When not caught, they terminate the script after the finally
Bram Moolenaar071d4272004-06-13 20:20:40 +000011552clause has been executed.)
11553Example: >
11554
11555 :try
11556 : let s:saved_ts = &ts
11557 : set ts=17
11558 :
11559 : " Do the hard work here.
11560 :
11561 :finally
11562 : let &ts = s:saved_ts
11563 : unlet s:saved_ts
11564 :endtry
11565
11566This method should be used locally whenever a function or part of a script
11567changes global settings which need to be restored on failure or normal exit of
11568that function or script part.
11569
11570 *break-finally*
11571Cleanup code works also when the try block or a catch clause is left by
11572a ":continue", ":break", ":return", or ":finish".
11573 Example: >
11574
11575 :let first = 1
11576 :while 1
11577 : try
11578 : if first
11579 : echo "first"
11580 : let first = 0
11581 : continue
11582 : else
11583 : throw "second"
11584 : endif
11585 : catch /.*/
11586 : echo v:exception
11587 : break
11588 : finally
11589 : echo "cleanup"
11590 : endtry
11591 : echo "still in while"
11592 :endwhile
11593 :echo "end"
11594
11595This displays "first", "cleanup", "second", "cleanup", and "end". >
11596
11597 :function! Foo()
11598 : try
11599 : return 4711
11600 : finally
11601 : echo "cleanup\n"
11602 : endtry
11603 : echo "Foo still active"
11604 :endfunction
11605 :
11606 :echo Foo() "returned by Foo"
11607
11608This displays "cleanup" and "4711 returned by Foo". You don't need to add an
Bram Moolenaar58b85342016-08-14 19:54:54 +020011609extra ":return" in the finally clause. (Above all, this would override the
Bram Moolenaar071d4272004-06-13 20:20:40 +000011610return value.)
11611
11612 *except-from-finally*
11613Using either of ":continue", ":break", ":return", ":finish", or ":throw" in
11614a finally clause is possible, but not recommended since it abandons the
11615cleanup actions for the try conditional. But, of course, interrupt and error
11616exceptions might get raised from a finally clause.
11617 Example where an error in the finally clause stops an interrupt from
11618working correctly: >
11619
11620 :try
11621 : try
11622 : echo "Press CTRL-C for interrupt"
11623 : while 1
11624 : endwhile
11625 : finally
11626 : unlet novar
11627 : endtry
11628 :catch /novar/
11629 :endtry
11630 :echo "Script still running"
11631 :sleep 1
11632
11633If you need to put commands that could fail into a finally clause, you should
11634think about catching or ignoring the errors in these commands, see
11635|catch-errors| and |ignore-errors|.
11636
11637
11638CATCHING ERRORS *catch-errors*
11639
11640If you want to catch specific errors, you just have to put the code to be
11641watched in a try block and add a catch clause for the error message. The
11642presence of the try conditional causes all errors to be converted to an
11643exception. No message is displayed and |v:errmsg| is not set then. To find
11644the right pattern for the ":catch" command, you have to know how the format of
11645the error exception is.
11646 Error exceptions have the following format: >
11647
11648 Vim({cmdname}):{errmsg}
11649or >
11650 Vim:{errmsg}
11651
11652{cmdname} is the name of the command that failed; the second form is used when
Bram Moolenaar58b85342016-08-14 19:54:54 +020011653the command name is not known. {errmsg} is the error message usually produced
Bram Moolenaar071d4272004-06-13 20:20:40 +000011654when the error occurs outside try conditionals. It always begins with
11655a capital "E", followed by a two or three-digit error number, a colon, and
11656a space.
11657
11658Examples:
11659
11660The command >
11661 :unlet novar
11662normally produces the error message >
11663 E108: No such variable: "novar"
11664which is converted inside try conditionals to an exception >
11665 Vim(unlet):E108: No such variable: "novar"
11666
11667The command >
11668 :dwim
11669normally produces the error message >
11670 E492: Not an editor command: dwim
11671which is converted inside try conditionals to an exception >
11672 Vim:E492: Not an editor command: dwim
11673
11674You can catch all ":unlet" errors by a >
11675 :catch /^Vim(unlet):/
11676or all errors for misspelled command names by a >
11677 :catch /^Vim:E492:/
11678
11679Some error messages may be produced by different commands: >
11680 :function nofunc
11681and >
11682 :delfunction nofunc
11683both produce the error message >
11684 E128: Function name must start with a capital: nofunc
11685which is converted inside try conditionals to an exception >
11686 Vim(function):E128: Function name must start with a capital: nofunc
11687or >
11688 Vim(delfunction):E128: Function name must start with a capital: nofunc
11689respectively. You can catch the error by its number independently on the
11690command that caused it if you use the following pattern: >
11691 :catch /^Vim(\a\+):E128:/
11692
11693Some commands like >
11694 :let x = novar
11695produce multiple error messages, here: >
11696 E121: Undefined variable: novar
11697 E15: Invalid expression: novar
11698Only the first is used for the exception value, since it is the most specific
11699one (see |except-several-errors|). So you can catch it by >
11700 :catch /^Vim(\a\+):E121:/
11701
11702You can catch all errors related to the name "nofunc" by >
11703 :catch /\<nofunc\>/
11704
11705You can catch all Vim errors in the ":write" and ":read" commands by >
11706 :catch /^Vim(\(write\|read\)):E\d\+:/
11707
11708You can catch all Vim errors by the pattern >
11709 :catch /^Vim\((\a\+)\)\=:E\d\+:/
11710<
11711 *catch-text*
11712NOTE: You should never catch the error message text itself: >
11713 :catch /No such variable/
Bram Moolenaar2b8388b2015-02-28 13:11:45 +010011714only works in the English locale, but not when the user has selected
Bram Moolenaar071d4272004-06-13 20:20:40 +000011715a different language by the |:language| command. It is however helpful to
11716cite the message text in a comment: >
11717 :catch /^Vim(\a\+):E108:/ " No such variable
11718
11719
11720IGNORING ERRORS *ignore-errors*
11721
11722You can ignore errors in a specific Vim command by catching them locally: >
11723
11724 :try
11725 : write
11726 :catch
11727 :endtry
11728
11729But you are strongly recommended NOT to use this simple form, since it could
11730catch more than you want. With the ":write" command, some autocommands could
11731be executed and cause errors not related to writing, for instance: >
11732
11733 :au BufWritePre * unlet novar
11734
11735There could even be such errors you are not responsible for as a script
11736writer: a user of your script might have defined such autocommands. You would
11737then hide the error from the user.
11738 It is much better to use >
11739
11740 :try
11741 : write
11742 :catch /^Vim(write):/
11743 :endtry
11744
11745which only catches real write errors. So catch only what you'd like to ignore
11746intentionally.
11747
11748For a single command that does not cause execution of autocommands, you could
11749even suppress the conversion of errors to exceptions by the ":silent!"
11750command: >
11751 :silent! nunmap k
11752This works also when a try conditional is active.
11753
11754
11755CATCHING INTERRUPTS *catch-interrupt*
11756
11757When there are active try conditionals, an interrupt (CTRL-C) is converted to
Bram Moolenaar58b85342016-08-14 19:54:54 +020011758the exception "Vim:Interrupt". You can catch it like every exception. The
Bram Moolenaar071d4272004-06-13 20:20:40 +000011759script is not terminated, then.
11760 Example: >
11761
11762 :function! TASK1()
11763 : sleep 10
11764 :endfunction
11765
11766 :function! TASK2()
11767 : sleep 20
11768 :endfunction
11769
11770 :while 1
11771 : let command = input("Type a command: ")
11772 : try
11773 : if command == ""
11774 : continue
11775 : elseif command == "END"
11776 : break
11777 : elseif command == "TASK1"
11778 : call TASK1()
11779 : elseif command == "TASK2"
11780 : call TASK2()
11781 : else
11782 : echo "\nIllegal command:" command
11783 : continue
11784 : endif
11785 : catch /^Vim:Interrupt$/
11786 : echo "\nCommand interrupted"
11787 : " Caught the interrupt. Continue with next prompt.
11788 : endtry
11789 :endwhile
11790
11791You can interrupt a task here by pressing CTRL-C; the script then asks for
Bram Moolenaar58b85342016-08-14 19:54:54 +020011792a new command. If you press CTRL-C at the prompt, the script is terminated.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011793
11794For testing what happens when CTRL-C would be pressed on a specific line in
11795your script, use the debug mode and execute the |>quit| or |>interrupt|
11796command on that line. See |debug-scripts|.
11797
11798
11799CATCHING ALL *catch-all*
11800
11801The commands >
11802
11803 :catch /.*/
11804 :catch //
11805 :catch
11806
11807catch everything, error exceptions, interrupt exceptions and exceptions
11808explicitly thrown by the |:throw| command. This is useful at the top level of
11809a script in order to catch unexpected things.
11810 Example: >
11811
11812 :try
11813 :
11814 : " do the hard work here
11815 :
11816 :catch /MyException/
11817 :
11818 : " handle known problem
11819 :
11820 :catch /^Vim:Interrupt$/
11821 : echo "Script interrupted"
11822 :catch /.*/
11823 : echo "Internal error (" . v:exception . ")"
11824 : echo " - occurred at " . v:throwpoint
11825 :endtry
11826 :" end of script
11827
11828Note: Catching all might catch more things than you want. Thus, you are
11829strongly encouraged to catch only for problems that you can really handle by
11830specifying a pattern argument to the ":catch".
11831 Example: Catching all could make it nearly impossible to interrupt a script
11832by pressing CTRL-C: >
11833
11834 :while 1
11835 : try
11836 : sleep 1
11837 : catch
11838 : endtry
11839 :endwhile
11840
11841
11842EXCEPTIONS AND AUTOCOMMANDS *except-autocmd*
11843
11844Exceptions may be used during execution of autocommands. Example: >
11845
11846 :autocmd User x try
11847 :autocmd User x throw "Oops!"
11848 :autocmd User x catch
11849 :autocmd User x echo v:exception
11850 :autocmd User x endtry
11851 :autocmd User x throw "Arrgh!"
11852 :autocmd User x echo "Should not be displayed"
11853 :
11854 :try
11855 : doautocmd User x
11856 :catch
11857 : echo v:exception
11858 :endtry
11859
11860This displays "Oops!" and "Arrgh!".
11861
11862 *except-autocmd-Pre*
11863For some commands, autocommands get executed before the main action of the
11864command takes place. If an exception is thrown and not caught in the sequence
11865of autocommands, the sequence and the command that caused its execution are
11866abandoned and the exception is propagated to the caller of the command.
11867 Example: >
11868
11869 :autocmd BufWritePre * throw "FAIL"
11870 :autocmd BufWritePre * echo "Should not be displayed"
11871 :
11872 :try
11873 : write
11874 :catch
11875 : echo "Caught:" v:exception "from" v:throwpoint
11876 :endtry
11877
11878Here, the ":write" command does not write the file currently being edited (as
11879you can see by checking 'modified'), since the exception from the BufWritePre
11880autocommand abandons the ":write". The exception is then caught and the
11881script displays: >
11882
11883 Caught: FAIL from BufWrite Auto commands for "*"
11884<
11885 *except-autocmd-Post*
11886For some commands, autocommands get executed after the main action of the
11887command has taken place. If this main action fails and the command is inside
11888an active try conditional, the autocommands are skipped and an error exception
11889is thrown that can be caught by the caller of the command.
11890 Example: >
11891
11892 :autocmd BufWritePost * echo "File successfully written!"
11893 :
11894 :try
11895 : write /i/m/p/o/s/s/i/b/l/e
11896 :catch
11897 : echo v:exception
11898 :endtry
11899
11900This just displays: >
11901
11902 Vim(write):E212: Can't open file for writing (/i/m/p/o/s/s/i/b/l/e)
11903
11904If you really need to execute the autocommands even when the main action
11905fails, trigger the event from the catch clause.
11906 Example: >
11907
11908 :autocmd BufWritePre * set noreadonly
11909 :autocmd BufWritePost * set readonly
11910 :
11911 :try
11912 : write /i/m/p/o/s/s/i/b/l/e
11913 :catch
11914 : doautocmd BufWritePost /i/m/p/o/s/s/i/b/l/e
11915 :endtry
11916<
11917You can also use ":silent!": >
11918
11919 :let x = "ok"
11920 :let v:errmsg = ""
11921 :autocmd BufWritePost * if v:errmsg != ""
11922 :autocmd BufWritePost * let x = "after fail"
11923 :autocmd BufWritePost * endif
11924 :try
11925 : silent! write /i/m/p/o/s/s/i/b/l/e
11926 :catch
11927 :endtry
11928 :echo x
11929
11930This displays "after fail".
11931
11932If the main action of the command does not fail, exceptions from the
11933autocommands will be catchable by the caller of the command: >
11934
11935 :autocmd BufWritePost * throw ":-("
11936 :autocmd BufWritePost * echo "Should not be displayed"
11937 :
11938 :try
11939 : write
11940 :catch
11941 : echo v:exception
11942 :endtry
11943<
11944 *except-autocmd-Cmd*
11945For some commands, the normal action can be replaced by a sequence of
11946autocommands. Exceptions from that sequence will be catchable by the caller
11947of the command.
11948 Example: For the ":write" command, the caller cannot know whether the file
Bram Moolenaar58b85342016-08-14 19:54:54 +020011949had actually been written when the exception occurred. You need to tell it in
Bram Moolenaar071d4272004-06-13 20:20:40 +000011950some way. >
11951
11952 :if !exists("cnt")
11953 : let cnt = 0
11954 :
11955 : autocmd BufWriteCmd * if &modified
11956 : autocmd BufWriteCmd * let cnt = cnt + 1
11957 : autocmd BufWriteCmd * if cnt % 3 == 2
11958 : autocmd BufWriteCmd * throw "BufWriteCmdError"
11959 : autocmd BufWriteCmd * endif
11960 : autocmd BufWriteCmd * write | set nomodified
11961 : autocmd BufWriteCmd * if cnt % 3 == 0
11962 : autocmd BufWriteCmd * throw "BufWriteCmdError"
11963 : autocmd BufWriteCmd * endif
11964 : autocmd BufWriteCmd * echo "File successfully written!"
11965 : autocmd BufWriteCmd * endif
11966 :endif
11967 :
11968 :try
11969 : write
11970 :catch /^BufWriteCmdError$/
11971 : if &modified
11972 : echo "Error on writing (file contents not changed)"
11973 : else
11974 : echo "Error after writing"
11975 : endif
11976 :catch /^Vim(write):/
11977 : echo "Error on writing"
11978 :endtry
11979
11980When this script is sourced several times after making changes, it displays
11981first >
11982 File successfully written!
11983then >
11984 Error on writing (file contents not changed)
11985then >
11986 Error after writing
11987etc.
11988
11989 *except-autocmd-ill*
11990You cannot spread a try conditional over autocommands for different events.
11991The following code is ill-formed: >
11992
11993 :autocmd BufWritePre * try
11994 :
11995 :autocmd BufWritePost * catch
11996 :autocmd BufWritePost * echo v:exception
11997 :autocmd BufWritePost * endtry
11998 :
11999 :write
12000
12001
12002EXCEPTION HIERARCHIES AND PARAMETERIZED EXCEPTIONS *except-hier-param*
12003
12004Some programming languages allow to use hierarchies of exception classes or to
12005pass additional information with the object of an exception class. You can do
12006similar things in Vim.
12007 In order to throw an exception from a hierarchy, just throw the complete
12008class name with the components separated by a colon, for instance throw the
12009string "EXCEPT:MATHERR:OVERFLOW" for an overflow in a mathematical library.
12010 When you want to pass additional information with your exception class, add
12011it in parentheses, for instance throw the string "EXCEPT:IO:WRITEERR(myfile)"
12012for an error when writing "myfile".
12013 With the appropriate patterns in the ":catch" command, you can catch for
12014base classes or derived classes of your hierarchy. Additional information in
12015parentheses can be cut out from |v:exception| with the ":substitute" command.
12016 Example: >
12017
12018 :function! CheckRange(a, func)
12019 : if a:a < 0
12020 : throw "EXCEPT:MATHERR:RANGE(" . a:func . ")"
12021 : endif
12022 :endfunction
12023 :
12024 :function! Add(a, b)
12025 : call CheckRange(a:a, "Add")
12026 : call CheckRange(a:b, "Add")
12027 : let c = a:a + a:b
12028 : if c < 0
12029 : throw "EXCEPT:MATHERR:OVERFLOW"
12030 : endif
12031 : return c
12032 :endfunction
12033 :
12034 :function! Div(a, b)
12035 : call CheckRange(a:a, "Div")
12036 : call CheckRange(a:b, "Div")
12037 : if (a:b == 0)
12038 : throw "EXCEPT:MATHERR:ZERODIV"
12039 : endif
12040 : return a:a / a:b
12041 :endfunction
12042 :
12043 :function! Write(file)
12044 : try
Bram Moolenaar446cb832008-06-24 21:56:24 +000012045 : execute "write" fnameescape(a:file)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012046 : catch /^Vim(write):/
12047 : throw "EXCEPT:IO(" . getcwd() . ", " . a:file . "):WRITEERR"
12048 : endtry
12049 :endfunction
12050 :
12051 :try
12052 :
12053 : " something with arithmetics and I/O
12054 :
12055 :catch /^EXCEPT:MATHERR:RANGE/
12056 : let function = substitute(v:exception, '.*(\(\a\+\)).*', '\1', "")
12057 : echo "Range error in" function
12058 :
12059 :catch /^EXCEPT:MATHERR/ " catches OVERFLOW and ZERODIV
12060 : echo "Math error"
12061 :
12062 :catch /^EXCEPT:IO/
12063 : let dir = substitute(v:exception, '.*(\(.\+\),\s*.\+).*', '\1', "")
12064 : let file = substitute(v:exception, '.*(.\+,\s*\(.\+\)).*', '\1', "")
12065 : if file !~ '^/'
12066 : let file = dir . "/" . file
12067 : endif
12068 : echo 'I/O error for "' . file . '"'
12069 :
12070 :catch /^EXCEPT/
12071 : echo "Unspecified error"
12072 :
12073 :endtry
12074
12075The exceptions raised by Vim itself (on error or when pressing CTRL-C) use
12076a flat hierarchy: they are all in the "Vim" class. You cannot throw yourself
12077exceptions with the "Vim" prefix; they are reserved for Vim.
12078 Vim error exceptions are parameterized with the name of the command that
12079failed, if known. See |catch-errors|.
12080
12081
12082PECULIARITIES
12083 *except-compat*
12084The exception handling concept requires that the command sequence causing the
12085exception is aborted immediately and control is transferred to finally clauses
12086and/or a catch clause.
12087
12088In the Vim script language there are cases where scripts and functions
12089continue after an error: in functions without the "abort" flag or in a command
12090after ":silent!", control flow goes to the following line, and outside
12091functions, control flow goes to the line following the outermost ":endwhile"
12092or ":endif". On the other hand, errors should be catchable as exceptions
12093(thus, requiring the immediate abortion).
12094
12095This problem has been solved by converting errors to exceptions and using
12096immediate abortion (if not suppressed by ":silent!") only when a try
Bram Moolenaar58b85342016-08-14 19:54:54 +020012097conditional is active. This is no restriction since an (error) exception can
12098be caught only from an active try conditional. If you want an immediate
Bram Moolenaar071d4272004-06-13 20:20:40 +000012099termination without catching the error, just use a try conditional without
12100catch clause. (You can cause cleanup code being executed before termination
12101by specifying a finally clause.)
12102
12103When no try conditional is active, the usual abortion and continuation
12104behavior is used instead of immediate abortion. This ensures compatibility of
12105scripts written for Vim 6.1 and earlier.
12106
12107However, when sourcing an existing script that does not use exception handling
12108commands (or when calling one of its functions) from inside an active try
12109conditional of a new script, you might change the control flow of the existing
12110script on error. You get the immediate abortion on error and can catch the
12111error in the new script. If however the sourced script suppresses error
12112messages by using the ":silent!" command (checking for errors by testing
Bram Moolenaar58b85342016-08-14 19:54:54 +020012113|v:errmsg| if appropriate), its execution path is not changed. The error is
12114not converted to an exception. (See |:silent|.) So the only remaining cause
Bram Moolenaar071d4272004-06-13 20:20:40 +000012115where this happens is for scripts that don't care about errors and produce
12116error messages. You probably won't want to use such code from your new
12117scripts.
12118
12119 *except-syntax-err*
12120Syntax errors in the exception handling commands are never caught by any of
12121the ":catch" commands of the try conditional they belong to. Its finally
12122clauses, however, is executed.
12123 Example: >
12124
12125 :try
12126 : try
12127 : throw 4711
12128 : catch /\(/
12129 : echo "in catch with syntax error"
12130 : catch
12131 : echo "inner catch-all"
12132 : finally
12133 : echo "inner finally"
12134 : endtry
12135 :catch
12136 : echo 'outer catch-all caught "' . v:exception . '"'
12137 : finally
12138 : echo "outer finally"
12139 :endtry
12140
12141This displays: >
12142 inner finally
12143 outer catch-all caught "Vim(catch):E54: Unmatched \("
12144 outer finally
12145The original exception is discarded and an error exception is raised, instead.
12146
12147 *except-single-line*
12148The ":try", ":catch", ":finally", and ":endtry" commands can be put on
12149a single line, but then syntax errors may make it difficult to recognize the
12150"catch" line, thus you better avoid this.
12151 Example: >
12152 :try | unlet! foo # | catch | endtry
12153raises an error exception for the trailing characters after the ":unlet!"
12154argument, but does not see the ":catch" and ":endtry" commands, so that the
12155error exception is discarded and the "E488: Trailing characters" message gets
12156displayed.
12157
12158 *except-several-errors*
12159When several errors appear in a single command, the first error message is
12160usually the most specific one and therefor converted to the error exception.
12161 Example: >
12162 echo novar
12163causes >
12164 E121: Undefined variable: novar
12165 E15: Invalid expression: novar
12166The value of the error exception inside try conditionals is: >
12167 Vim(echo):E121: Undefined variable: novar
12168< *except-syntax-error*
12169But when a syntax error is detected after a normal error in the same command,
12170the syntax error is used for the exception being thrown.
12171 Example: >
12172 unlet novar #
12173causes >
12174 E108: No such variable: "novar"
12175 E488: Trailing characters
12176The value of the error exception inside try conditionals is: >
12177 Vim(unlet):E488: Trailing characters
12178This is done because the syntax error might change the execution path in a way
12179not intended by the user. Example: >
12180 try
12181 try | unlet novar # | catch | echo v:exception | endtry
12182 catch /.*/
12183 echo "outer catch:" v:exception
12184 endtry
12185This displays "outer catch: Vim(unlet):E488: Trailing characters", and then
12186a "E600: Missing :endtry" error message is given, see |except-single-line|.
12187
12188==============================================================================
121899. Examples *eval-examples*
12190
Bram Moolenaaref2f6562007-05-06 13:32:59 +000012191Printing in Binary ~
Bram Moolenaar071d4272004-06-13 20:20:40 +000012192>
Bram Moolenaar8f3f58f2010-01-06 20:52:26 +010012193 :" The function Nr2Bin() returns the binary string representation of a number.
Bram Moolenaaref2f6562007-05-06 13:32:59 +000012194 :func Nr2Bin(nr)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012195 : let n = a:nr
12196 : let r = ""
12197 : while n
Bram Moolenaaref2f6562007-05-06 13:32:59 +000012198 : let r = '01'[n % 2] . r
12199 : let n = n / 2
Bram Moolenaar071d4272004-06-13 20:20:40 +000012200 : endwhile
12201 : return r
12202 :endfunc
12203
Bram Moolenaaref2f6562007-05-06 13:32:59 +000012204 :" The function String2Bin() converts each character in a string to a
12205 :" binary string, separated with dashes.
12206 :func String2Bin(str)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012207 : let out = ''
Bram Moolenaaref2f6562007-05-06 13:32:59 +000012208 : for ix in range(strlen(a:str))
12209 : let out = out . '-' . Nr2Bin(char2nr(a:str[ix]))
12210 : endfor
12211 : return out[1:]
Bram Moolenaar071d4272004-06-13 20:20:40 +000012212 :endfunc
12213
12214Example of its use: >
Bram Moolenaaref2f6562007-05-06 13:32:59 +000012215 :echo Nr2Bin(32)
12216result: "100000" >
12217 :echo String2Bin("32")
12218result: "110011-110010"
Bram Moolenaar071d4272004-06-13 20:20:40 +000012219
12220
Bram Moolenaaref2f6562007-05-06 13:32:59 +000012221Sorting lines ~
Bram Moolenaar071d4272004-06-13 20:20:40 +000012222
Bram Moolenaaref2f6562007-05-06 13:32:59 +000012223This example sorts lines with a specific compare function. >
12224
12225 :func SortBuffer()
12226 : let lines = getline(1, '$')
12227 : call sort(lines, function("Strcmp"))
12228 : call setline(1, lines)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012229 :endfunction
12230
Bram Moolenaaref2f6562007-05-06 13:32:59 +000012231As a one-liner: >
12232 :call setline(1, sort(getline(1, '$'), function("Strcmp")))
Bram Moolenaar071d4272004-06-13 20:20:40 +000012233
Bram Moolenaar071d4272004-06-13 20:20:40 +000012234
Bram Moolenaaref2f6562007-05-06 13:32:59 +000012235scanf() replacement ~
Bram Moolenaar071d4272004-06-13 20:20:40 +000012236 *sscanf*
12237There is no sscanf() function in Vim. If you need to extract parts from a
12238line, you can use matchstr() and substitute() to do it. This example shows
12239how to get the file name, line number and column number out of a line like
12240"foobar.txt, 123, 45". >
12241 :" Set up the match bit
12242 :let mx='\(\f\+\),\s*\(\d\+\),\s*\(\d\+\)'
12243 :"get the part matching the whole expression
12244 :let l = matchstr(line, mx)
12245 :"get each item out of the match
12246 :let file = substitute(l, mx, '\1', '')
12247 :let lnum = substitute(l, mx, '\2', '')
12248 :let col = substitute(l, mx, '\3', '')
12249
12250The input is in the variable "line", the results in the variables "file",
12251"lnum" and "col". (idea from Michael Geddes)
12252
Bram Moolenaaref2f6562007-05-06 13:32:59 +000012253
12254getting the scriptnames in a Dictionary ~
12255 *scriptnames-dictionary*
12256The |:scriptnames| command can be used to get a list of all script files that
12257have been sourced. There is no equivalent function or variable for this
12258(because it's rarely needed). In case you need to manipulate the list this
12259code can be used: >
12260 " Get the output of ":scriptnames" in the scriptnames_output variable.
12261 let scriptnames_output = ''
12262 redir => scriptnames_output
12263 silent scriptnames
12264 redir END
Bram Moolenaarb0d45e72017-11-05 18:19:24 +010012265
Bram Moolenaar446cb832008-06-24 21:56:24 +000012266 " Split the output into lines and parse each line. Add an entry to the
Bram Moolenaaref2f6562007-05-06 13:32:59 +000012267 " "scripts" dictionary.
12268 let scripts = {}
12269 for line in split(scriptnames_output, "\n")
12270 " Only do non-blank lines.
12271 if line =~ '\S'
12272 " Get the first number in the line.
Bram Moolenaar446cb832008-06-24 21:56:24 +000012273 let nr = matchstr(line, '\d\+')
Bram Moolenaaref2f6562007-05-06 13:32:59 +000012274 " Get the file name, remove the script number " 123: ".
Bram Moolenaar446cb832008-06-24 21:56:24 +000012275 let name = substitute(line, '.\+:\s*', '', '')
Bram Moolenaaref2f6562007-05-06 13:32:59 +000012276 " Add an item to the Dictionary
Bram Moolenaar446cb832008-06-24 21:56:24 +000012277 let scripts[nr] = name
Bram Moolenaaref2f6562007-05-06 13:32:59 +000012278 endif
12279 endfor
12280 unlet scriptnames_output
12281
Bram Moolenaar071d4272004-06-13 20:20:40 +000012282==============================================================================
1228310. No +eval feature *no-eval-feature*
12284
12285When the |+eval| feature was disabled at compile time, none of the expression
12286evaluation commands are available. To prevent this from causing Vim scripts
12287to generate all kinds of errors, the ":if" and ":endif" commands are still
12288recognized, though the argument of the ":if" and everything between the ":if"
12289and the matching ":endif" is ignored. Nesting of ":if" blocks is allowed, but
12290only if the commands are at the start of the line. The ":else" command is not
12291recognized.
12292
12293Example of how to avoid executing commands when the |+eval| feature is
12294missing: >
12295
12296 :if 1
12297 : echo "Expression evaluation is compiled in"
12298 :else
12299 : echo "You will _never_ see this message"
12300 :endif
12301
Bram Moolenaarcd5c8f82017-04-09 20:11:58 +020012302To execute a command only when the |+eval| feature is disabled requires a trick,
12303as this example shows: >
Bram Moolenaar45d2cca2017-04-30 16:36:05 +020012304
12305 silent! while 0
12306 set history=111
12307 silent! endwhile
12308
12309When the |+eval| feature is available the command is skipped because of the
12310"while 0". Without the |+eval| feature the "while 0" is an error, which is
12311silently ignored, and the command is executed.
Bram Moolenaarcd5c8f82017-04-09 20:11:58 +020012312
Bram Moolenaar071d4272004-06-13 20:20:40 +000012313==============================================================================
1231411. The sandbox *eval-sandbox* *sandbox* *E48*
12315
Bram Moolenaar368373e2010-07-19 20:46:22 +020012316The 'foldexpr', 'formatexpr', 'includeexpr', 'indentexpr', 'statusline' and
12317'foldtext' options may be evaluated in a sandbox. This means that you are
12318protected from these expressions having nasty side effects. This gives some
12319safety for when these options are set from a modeline. It is also used when
12320the command from a tags file is executed and for CTRL-R = in the command line.
Bram Moolenaar7b0294c2004-10-11 10:16:09 +000012321The sandbox is also used for the |:sandbox| command.
Bram Moolenaar071d4272004-06-13 20:20:40 +000012322
12323These items are not allowed in the sandbox:
12324 - changing the buffer text
Bram Moolenaarb477af22018-07-15 20:20:18 +020012325 - defining or changing mapping, autocommands, user commands
Bram Moolenaar071d4272004-06-13 20:20:40 +000012326 - setting certain options (see |option-summary|)
Bram Moolenaaref2f6562007-05-06 13:32:59 +000012327 - setting certain v: variables (see |v:var|) *E794*
Bram Moolenaar071d4272004-06-13 20:20:40 +000012328 - executing a shell command
12329 - reading or writing a file
12330 - jumping to another buffer or editing a file
Bram Moolenaar4770d092006-01-12 23:22:24 +000012331 - executing Python, Perl, etc. commands
Bram Moolenaar7b0294c2004-10-11 10:16:09 +000012332This is not guaranteed 100% secure, but it should block most attacks.
12333
12334 *:san* *:sandbox*
Bram Moolenaar045e82d2005-07-08 22:25:33 +000012335:san[dbox] {cmd} Execute {cmd} in the sandbox. Useful to evaluate an
Bram Moolenaar7b0294c2004-10-11 10:16:09 +000012336 option that may have been set from a modeline, e.g.
12337 'foldexpr'.
12338
Bram Moolenaarb71eaae2006-01-20 23:10:18 +000012339 *sandbox-option*
12340A few options contain an expression. When this expression is evaluated it may
Bram Moolenaar9b2200a2006-03-20 21:55:45 +000012341have to be done in the sandbox to avoid a security risk. But the sandbox is
Bram Moolenaarb71eaae2006-01-20 23:10:18 +000012342restrictive, thus this only happens when the option was set from an insecure
12343location. Insecure in this context are:
Bram Moolenaar551dbcc2006-04-25 22:13:59 +000012344- sourcing a .vimrc or .exrc in the current directory
Bram Moolenaarb71eaae2006-01-20 23:10:18 +000012345- while executing in the sandbox
12346- value coming from a modeline
Bram Moolenaarb477af22018-07-15 20:20:18 +020012347- executing a function that was defined in the sandbox
Bram Moolenaarb71eaae2006-01-20 23:10:18 +000012348
12349Note that when in the sandbox and saving an option value and restoring it, the
12350option will still be marked as it was set in the sandbox.
12351
12352==============================================================================
1235312. Textlock *textlock*
12354
12355In a few situations it is not allowed to change the text in the buffer, jump
12356to another window and some other things that might confuse or break what Vim
12357is currently doing. This mostly applies to things that happen when Vim is
Bram Moolenaar58b85342016-08-14 19:54:54 +020012358actually doing something else. For example, evaluating the 'balloonexpr' may
Bram Moolenaarb71eaae2006-01-20 23:10:18 +000012359happen any moment the mouse cursor is resting at some position.
12360
12361This is not allowed when the textlock is active:
12362 - changing the buffer text
12363 - jumping to another buffer or window
12364 - editing another file
12365 - closing a window or quitting Vim
12366 - etc.
12367
Bram Moolenaardc1f1642016-08-16 18:33:43 +020012368==============================================================================
1236913. Testing *testing*
12370
12371Vim can be tested after building it, usually with "make test".
12372The tests are located in the directory "src/testdir".
12373
12374There are several types of tests added over time:
12375 test33.in oldest, don't add any more
12376 test_something.in old style tests
12377 test_something.vim new style tests
12378
12379 *new-style-testing*
12380New tests should be added as new style tests. These use functions such as
12381|assert_equal()| to keep the test commands and the expected result in one
12382place.
12383 *old-style-testing*
12384In some cases an old style test needs to be used. E.g. when testing Vim
12385without the |+eval| feature.
12386
12387Find more information in the file src/testdir/README.txt.
12388
Bram Moolenaar071d4272004-06-13 20:20:40 +000012389
Bram Moolenaar91f84f62018-07-29 15:07:52 +020012390 vim:tw=78:ts=8:noet:ft=help:norl: