blob: 8be5ee49ad8e4f27edebbbd806f6b0c5aaa32382 [file] [log] [blame]
Bram Moolenaar22fcfad2016-07-01 18:17:26 +02001*eval.txt* For Vim version 7.4. Last change: 2016 Jul 01
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 Moolenaar446cb832008-06-24 21:56:24 +000012done, 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 Moolenaar071d4272004-06-13 20:20:40 +000032
33{Vi does not have any of these commands}
34
35==============================================================================
361. Variables *variables*
37
Bram Moolenaar13065c42005-01-08 16:08:21 +0000381.1 Variable types ~
Bram Moolenaar3a3a7232005-01-17 22:16:15 +000039 *E712*
Bram Moolenaar38a55632016-02-15 22:07:32 +010040There are nine types of variables:
Bram Moolenaar071d4272004-06-13 20:20:40 +000041
Bram Moolenaar5302d9e2011-09-14 17:55:08 +020042Number A 32 or 64 bit signed number. |expr-number| *Number*
Bram Moolenaar22fcfad2016-07-01 18:17:26 +020043 64-bit Number is available only when compiled with the
44 |+num64| feature.
Bram Moolenaard8b02732005-01-14 21:48:43 +000045 Examples: -123 0x10 0177
46
Bram Moolenaar446cb832008-06-24 21:56:24 +000047Float A floating point number. |floating-point-format| *Float*
48 {only when compiled with the |+float| feature}
49 Examples: 123.456 1.15e-6 -1.1e3
50
Bram Moolenaar06481422016-04-30 15:13:38 +020051 *E928*
Bram Moolenaard8b02732005-01-14 21:48:43 +000052String A NUL terminated string of 8-bit unsigned characters (bytes).
Bram Moolenaar446cb832008-06-24 21:56:24 +000053 |expr-string| Examples: "ab\txx\"--" 'x-z''a,c'
Bram Moolenaard8b02732005-01-14 21:48:43 +000054
Bram Moolenaard8b02732005-01-14 21:48:43 +000055List An ordered sequence of items |List|.
56 Example: [1, 2, ['a', 'b']]
Bram Moolenaar071d4272004-06-13 20:20:40 +000057
Bram Moolenaar39a58ca2005-06-27 22:42:44 +000058Dictionary An associative, unordered array: Each entry has a key and a
59 value. |Dictionary|
60 Example: {'blue': "#0000ff", 'red': "#ff0000"}
61
Bram Moolenaar835dc632016-02-07 14:27:38 +010062Funcref A reference to a function |Funcref|.
63 Example: function("strlen")
Bram Moolenaar1d429612016-05-24 15:44:17 +020064 It can be bound to a dictionary and arguments, it then works
65 like a Partial.
66 Example: function("Callback", [arg], myDict)
Bram Moolenaar835dc632016-02-07 14:27:38 +010067
Bram Moolenaar02e83b42016-02-21 20:10:26 +010068Special |v:false|, |v:true|, |v:none| and |v:null|. *Special*
Bram Moolenaar835dc632016-02-07 14:27:38 +010069
Bram Moolenaarebf7dfa2016-04-14 12:46:51 +020070Job Used for a job, see |job_start()|. *Job* *Jobs*
Bram Moolenaar38a55632016-02-15 22:07:32 +010071
Bram Moolenaarebf7dfa2016-04-14 12:46:51 +020072Channel Used for a channel, see |ch_open()|. *Channel* *Channels*
Bram Moolenaar835dc632016-02-07 14:27:38 +010073
Bram Moolenaard7ee7ce2005-01-03 21:02:03 +000074The Number and String types are converted automatically, depending on how they
75are used.
Bram Moolenaar071d4272004-06-13 20:20:40 +000076
77Conversion from a Number to a String is by making the ASCII representation of
Bram Moolenaar24ea3ba2010-09-19 19:01:21 +020078the Number. Examples:
79 Number 123 --> String "123" ~
80 Number 0 --> String "0" ~
81 Number -1 --> String "-1" ~
Bram Moolenaar00a927d2010-05-14 23:24:24 +020082 *octal*
Bram Moolenaarfa735342016-01-03 22:14:44 +010083Conversion from a String to a Number is done by converting the first digits to
84a number. Hexadecimal "0xf9", Octal "017", and Binary "0b10" numbers are
85recognized. If the String doesn't start with digits, the result is zero.
86Examples:
Bram Moolenaar24ea3ba2010-09-19 19:01:21 +020087 String "456" --> Number 456 ~
88 String "6bar" --> Number 6 ~
89 String "foo" --> Number 0 ~
90 String "0xf1" --> Number 241 ~
91 String "0100" --> Number 64 ~
Bram Moolenaarfa735342016-01-03 22:14:44 +010092 String "0b101" --> Number 5 ~
Bram Moolenaar24ea3ba2010-09-19 19:01:21 +020093 String "-8" --> Number -8 ~
94 String "+8" --> Number 0 ~
Bram Moolenaar071d4272004-06-13 20:20:40 +000095
96To force conversion from String to Number, add zero to it: >
97 :echo "0100" + 0
Bram Moolenaar97b2ad32006-03-18 21:40:56 +000098< 64 ~
99
100To avoid a leading zero to cause octal conversion, or for using a different
101base, use |str2nr()|.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000102
103For boolean operators Numbers are used. Zero is FALSE, non-zero is TRUE.
104
105Note that in the command >
106 :if "foo"
107"foo" is converted to 0, which means FALSE. To test for a non-empty string,
Bram Moolenaar3a0d8092012-10-21 03:02:54 +0200108use empty(): >
109 :if !empty("foo")
Bram Moolenaar835dc632016-02-07 14:27:38 +0100110<
Bram Moolenaar38a55632016-02-15 22:07:32 +0100111 *E745* *E728* *E703* *E729* *E730* *E731* *E908* *E910* *E913*
Bram Moolenaar835dc632016-02-07 14:27:38 +0100112List, Dictionary, Funcref and Job types are not automatically converted.
Bram Moolenaard7ee7ce2005-01-03 21:02:03 +0000113
Bram Moolenaar446cb832008-06-24 21:56:24 +0000114 *E805* *E806* *E808*
115When mixing Number and Float the Number is converted to Float. Otherwise
116there is no automatic conversion of Float. You can use str2float() for String
117to Float, printf() for Float to String and float2nr() for Float to Number.
118
Bram Moolenaar38a55632016-02-15 22:07:32 +0100119 *E891* *E892* *E893* *E894* *E907* *E911* *E914*
Bram Moolenaar13d5aee2016-01-21 23:36:05 +0100120When expecting a Float a Number can also be used, but nothing else.
121
Bram Moolenaarf6f32c32016-03-12 19:03:59 +0100122 *no-type-checking*
123You will not get an error if you try to change the type of a variable.
Bram Moolenaard7ee7ce2005-01-03 21:02:03 +0000124
Bram Moolenaar13065c42005-01-08 16:08:21 +0000125
Bram Moolenaar9588a0f2005-01-08 21:45:39 +00001261.2 Function references ~
Bram Moolenaar748bf032005-02-02 23:04:36 +0000127 *Funcref* *E695* *E718*
Bram Moolenaar446cb832008-06-24 21:56:24 +0000128A Funcref variable is obtained with the |function()| function. It can be used
Bram Moolenaar3a3a7232005-01-17 22:16:15 +0000129in an expression in the place of a function name, before the parenthesis
130around the arguments, to invoke the function it refers to. Example: >
Bram Moolenaard7ee7ce2005-01-03 21:02:03 +0000131
132 :let Fn = function("MyFunc")
133 :echo Fn()
Bram Moolenaar3a3a7232005-01-17 22:16:15 +0000134< *E704* *E705* *E707*
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000135A Funcref variable must start with a capital, "s:", "w:", "t:" or "b:". You
Bram Moolenaar7cba6c02013-09-05 22:13:31 +0200136can use "g:" but the following name must still start with a capital. You
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000137cannot have both a Funcref variable and a function with the same name.
Bram Moolenaard7ee7ce2005-01-03 21:02:03 +0000138
Bram Moolenaar3a3a7232005-01-17 22:16:15 +0000139A special case is defining a function and directly assigning its Funcref to a
140Dictionary entry. Example: >
141 :function dict.init() dict
142 : let self.val = 0
143 :endfunction
144
145The key of the Dictionary can start with a lower case letter. The actual
146function name is not used here. Also see |numbered-function|.
147
148A Funcref can also be used with the |:call| command: >
149 :call Fn()
150 :call dict.init()
Bram Moolenaar13065c42005-01-08 16:08:21 +0000151
152The name of the referenced function can be obtained with |string()|. >
Bram Moolenaar383f9bc2005-01-19 22:18:32 +0000153 :let func = string(Fn)
Bram Moolenaar13065c42005-01-08 16:08:21 +0000154
155You can use |call()| to invoke a Funcref and use a list variable for the
156arguments: >
Bram Moolenaar383f9bc2005-01-19 22:18:32 +0000157 :let r = call(Fn, mylist)
Bram Moolenaar1d429612016-05-24 15:44:17 +0200158<
159 *Partial*
160A Funcref optionally binds a Dictionary and/or arguments. This is also called
161a Partial. This is created by passing the Dictionary and/or arguments to
162function(). When calling the function the Dictionary and/or arguments will be
163passed to the function. Example: >
164
165 let Cb = function('Callback', ['foo'], myDict)
166 call Cb()
167
168This will invoke the function as if using: >
169 call myDict.Callback('foo')
170
171This is very useful when passing a function around, e.g. in the arguments of
172|ch_open()|.
173
174Note that binding a function to a Dictionary also happens when the function is
175a member of the Dictionary: >
176
177 let myDict.myFunction = MyFunction
178 call myDict.myFunction()
179
180Here MyFunction() will get myDict passed as "self". This happens when the
181"myFunction" member is accessed. When making assigning "myFunction" to
182otherDict and calling it, it will be bound to otherDict: >
183
184 let otherDict.myFunction = myDict.myFunction
185 call otherDict.myFunction()
186
187Now "self" will be "otherDict". But when the dictionary was bound explicitly
188this won't happen: >
189
190 let myDict.myFunction = function(MyFunction, myDict)
191 let otherDict.myFunction = myDict.myFunction
192 call otherDict.myFunction()
193
194Here "self" will be "myDict", because it was bound explitly.
Bram Moolenaard7ee7ce2005-01-03 21:02:03 +0000195
196
Bram Moolenaar9588a0f2005-01-08 21:45:39 +00001971.3 Lists ~
Bram Moolenaar7e38ea22014-04-05 22:55:53 +0200198 *list* *List* *Lists* *E686*
Bram Moolenaard7ee7ce2005-01-03 21:02:03 +0000199A List is an ordered sequence of items. An item can be of any type. Items
Bram Moolenaar446cb832008-06-24 21:56:24 +0000200can be accessed by their index number. Items can be added and removed at any
Bram Moolenaard7ee7ce2005-01-03 21:02:03 +0000201position in the sequence.
202
Bram Moolenaar13065c42005-01-08 16:08:21 +0000203
204List creation ~
205 *E696* *E697*
Bram Moolenaard7ee7ce2005-01-03 21:02:03 +0000206A List is created with a comma separated list of items in square brackets.
Bram Moolenaar13065c42005-01-08 16:08:21 +0000207Examples: >
208 :let mylist = [1, two, 3, "four"]
209 :let emptylist = []
Bram Moolenaard7ee7ce2005-01-03 21:02:03 +0000210
Bram Moolenaar446cb832008-06-24 21:56:24 +0000211An item can be any expression. Using a List for an item creates a
Bram Moolenaarf9393ef2006-04-24 19:47:27 +0000212List of Lists: >
Bram Moolenaar13065c42005-01-08 16:08:21 +0000213 :let nestlist = [[11, 12], [21, 22], [31, 32]]
Bram Moolenaard7ee7ce2005-01-03 21:02:03 +0000214
215An extra comma after the last item is ignored.
216
Bram Moolenaar13065c42005-01-08 16:08:21 +0000217
218List index ~
219 *list-index* *E684*
Bram Moolenaard7ee7ce2005-01-03 21:02:03 +0000220An item in the List can be accessed by putting the index in square brackets
Bram Moolenaar13065c42005-01-08 16:08:21 +0000221after the List. Indexes are zero-based, thus the first item has index zero. >
222 :let item = mylist[0] " get the first item: 1
Bram Moolenaard7ee7ce2005-01-03 21:02:03 +0000223 :let item = mylist[2] " get the third item: 3
Bram Moolenaar13065c42005-01-08 16:08:21 +0000224
Bram Moolenaar9588a0f2005-01-08 21:45:39 +0000225When the resulting item is a list this can be repeated: >
Bram Moolenaar13065c42005-01-08 16:08:21 +0000226 :let item = nestlist[0][1] " get the first list, second item: 12
Bram Moolenaard7ee7ce2005-01-03 21:02:03 +0000227<
Bram Moolenaar13065c42005-01-08 16:08:21 +0000228A negative index is counted from the end. Index -1 refers to the last item in
229the List, -2 to the last but one item, etc. >
Bram Moolenaard7ee7ce2005-01-03 21:02:03 +0000230 :let last = mylist[-1] " get the last item: "four"
231
Bram Moolenaar13065c42005-01-08 16:08:21 +0000232To avoid an error for an invalid index use the |get()| function. When an item
Bram Moolenaar9588a0f2005-01-08 21:45:39 +0000233is not available it returns zero or the default value you specify: >
Bram Moolenaar13065c42005-01-08 16:08:21 +0000234 :echo get(mylist, idx)
235 :echo get(mylist, idx, "NONE")
236
237
238List concatenation ~
239
240Two lists can be concatenated with the "+" operator: >
241 :let longlist = mylist + [5, 6]
Bram Moolenaar383f9bc2005-01-19 22:18:32 +0000242 :let mylist += [7, 8]
Bram Moolenaar13065c42005-01-08 16:08:21 +0000243
244To prepend or append an item turn the item into a list by putting [] around
245it. To change a list in-place see |list-modification| below.
246
247
248Sublist ~
249
Bram Moolenaard7ee7ce2005-01-03 21:02:03 +0000250A part of the List can be obtained by specifying the first and last index,
251separated by a colon in square brackets: >
Bram Moolenaar13065c42005-01-08 16:08:21 +0000252 :let shortlist = mylist[2:-1] " get List [3, "four"]
Bram Moolenaard7ee7ce2005-01-03 21:02:03 +0000253
254Omitting the first index is similar to zero. Omitting the last index is
Bram Moolenaaref2f6562007-05-06 13:32:59 +0000255similar to -1. >
Bram Moolenaar540d6e32005-01-09 21:20:18 +0000256 :let endlist = mylist[2:] " from item 2 to the end: [3, "four"]
257 :let shortlist = mylist[2:2] " List with one item: [3]
258 :let otherlist = mylist[:] " make a copy of the List
Bram Moolenaard7ee7ce2005-01-03 21:02:03 +0000259
Bram Moolenaarf9393ef2006-04-24 19:47:27 +0000260If the first index is beyond the last item of the List or the second item is
261before the first item, the result is an empty list. There is no error
262message.
263
264If the second index is equal to or greater than the length of the list the
265length minus one is used: >
Bram Moolenaar9e54a0e2006-04-14 20:42:25 +0000266 :let mylist = [0, 1, 2, 3]
267 :echo mylist[2:8] " result: [2, 3]
268
Bram Moolenaara7fc0102005-05-18 22:17:12 +0000269NOTE: mylist[s:e] means using the variable "s:e" as index. Watch out for
Bram Moolenaar446cb832008-06-24 21:56:24 +0000270using a single letter variable before the ":". Insert a space when needed:
Bram Moolenaara7fc0102005-05-18 22:17:12 +0000271mylist[s : e].
272
Bram Moolenaard7ee7ce2005-01-03 21:02:03 +0000273
Bram Moolenaar13065c42005-01-08 16:08:21 +0000274List identity ~
Bram Moolenaard8b02732005-01-14 21:48:43 +0000275 *list-identity*
Bram Moolenaar13065c42005-01-08 16:08:21 +0000276When variable "aa" is a list and you assign it to another variable "bb", both
277variables refer to the same list. Thus changing the list "aa" will also
278change "bb": >
279 :let aa = [1, 2, 3]
280 :let bb = aa
281 :call add(aa, 4)
282 :echo bb
Bram Moolenaar3a3a7232005-01-17 22:16:15 +0000283< [1, 2, 3, 4]
Bram Moolenaar13065c42005-01-08 16:08:21 +0000284
285Making a copy of a list is done with the |copy()| function. Using [:] also
286works, as explained above. This creates a shallow copy of the list: Changing
Bram Moolenaar9588a0f2005-01-08 21:45:39 +0000287a list item in the list will also change the item in the copied list: >
Bram Moolenaar13065c42005-01-08 16:08:21 +0000288 :let aa = [[1, 'a'], 2, 3]
289 :let bb = copy(aa)
Bram Moolenaar3a3a7232005-01-17 22:16:15 +0000290 :call add(aa, 4)
Bram Moolenaar13065c42005-01-08 16:08:21 +0000291 :let aa[0][1] = 'aaa'
292 :echo aa
Bram Moolenaar3a3a7232005-01-17 22:16:15 +0000293< [[1, aaa], 2, 3, 4] >
Bram Moolenaar13065c42005-01-08 16:08:21 +0000294 :echo bb
Bram Moolenaar3a3a7232005-01-17 22:16:15 +0000295< [[1, aaa], 2, 3]
Bram Moolenaar13065c42005-01-08 16:08:21 +0000296
Bram Moolenaar9588a0f2005-01-08 21:45:39 +0000297To make a completely independent list use |deepcopy()|. This also makes a
Bram Moolenaar3a3a7232005-01-17 22:16:15 +0000298copy of the values in the list, recursively. Up to a hundred levels deep.
Bram Moolenaar13065c42005-01-08 16:08:21 +0000299
300The operator "is" can be used to check if two variables refer to the same
Bram Moolenaar3a3a7232005-01-17 22:16:15 +0000301List. "isnot" does the opposite. In contrast "==" compares if two lists have
Bram Moolenaar9588a0f2005-01-08 21:45:39 +0000302the same value. >
303 :let alist = [1, 2, 3]
304 :let blist = [1, 2, 3]
305 :echo alist is blist
Bram Moolenaar3a3a7232005-01-17 22:16:15 +0000306< 0 >
Bram Moolenaar9588a0f2005-01-08 21:45:39 +0000307 :echo alist == blist
Bram Moolenaar3a3a7232005-01-17 22:16:15 +0000308< 1
Bram Moolenaar13065c42005-01-08 16:08:21 +0000309
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +0000310Note about comparing lists: Two lists are considered equal if they have the
311same length and all items compare equal, as with using "==". There is one
Bram Moolenaar7d1f5db2005-07-03 21:39:27 +0000312exception: When comparing a number with a string they are considered
313different. There is no automatic type conversion, as with using "==" on
314variables. Example: >
315 echo 4 == "4"
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +0000316< 1 >
Bram Moolenaar7d1f5db2005-07-03 21:39:27 +0000317 echo [4] == ["4"]
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +0000318< 0
319
Bram Moolenaar7d1f5db2005-07-03 21:39:27 +0000320Thus comparing Lists is more strict than comparing numbers and strings. You
Bram Moolenaar446cb832008-06-24 21:56:24 +0000321can compare simple values this way too by putting them in a list: >
Bram Moolenaar7d1f5db2005-07-03 21:39:27 +0000322
323 :let a = 5
324 :let b = "5"
Bram Moolenaar446cb832008-06-24 21:56:24 +0000325 :echo a == b
Bram Moolenaar7d1f5db2005-07-03 21:39:27 +0000326< 1 >
Bram Moolenaar446cb832008-06-24 21:56:24 +0000327 :echo [a] == [b]
Bram Moolenaar7d1f5db2005-07-03 21:39:27 +0000328< 0
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +0000329
Bram Moolenaar13065c42005-01-08 16:08:21 +0000330
331List unpack ~
332
333To unpack the items in a list to individual variables, put the variables in
334square brackets, like list items: >
335 :let [var1, var2] = mylist
336
337When the number of variables does not match the number of items in the list
338this produces an error. To handle any extra items from the list append ";"
339and a variable name: >
340 :let [var1, var2; rest] = mylist
341
342This works like: >
343 :let var1 = mylist[0]
344 :let var2 = mylist[1]
Bram Moolenaar5f2bb9f2005-01-11 21:29:04 +0000345 :let rest = mylist[2:]
Bram Moolenaar13065c42005-01-08 16:08:21 +0000346
347Except that there is no error if there are only two items. "rest" will be an
348empty list then.
349
350
351List modification ~
352 *list-modification*
Bram Moolenaar9588a0f2005-01-08 21:45:39 +0000353To change a specific item of a list use |:let| this way: >
Bram Moolenaar13065c42005-01-08 16:08:21 +0000354 :let list[4] = "four"
355 :let listlist[0][3] = item
356
Bram Moolenaar9588a0f2005-01-08 21:45:39 +0000357To change part of a list you can specify the first and last item to be
Bram Moolenaar3a3a7232005-01-17 22:16:15 +0000358modified. The value must at least have the number of items in the range: >
Bram Moolenaar9588a0f2005-01-08 21:45:39 +0000359 :let list[3:5] = [3, 4, 5]
360
Bram Moolenaar13065c42005-01-08 16:08:21 +0000361Adding and removing items from a list is done with functions. Here are a few
362examples: >
363 :call insert(list, 'a') " prepend item 'a'
364 :call insert(list, 'a', 3) " insert item 'a' before list[3]
365 :call add(list, "new") " append String item
Bram Moolenaar3a3a7232005-01-17 22:16:15 +0000366 :call add(list, [1, 2]) " append a List as one new item
Bram Moolenaar13065c42005-01-08 16:08:21 +0000367 :call extend(list, [1, 2]) " extend the list with two more items
368 :let i = remove(list, 3) " remove item 3
Bram Moolenaar9cd15162005-01-16 22:02:49 +0000369 :unlet list[3] " idem
Bram Moolenaar13065c42005-01-08 16:08:21 +0000370 :let l = remove(list, 3, -1) " remove items 3 to last item
Bram Moolenaar9cd15162005-01-16 22:02:49 +0000371 :unlet list[3 : ] " idem
Bram Moolenaar3a3a7232005-01-17 22:16:15 +0000372 :call filter(list, 'v:val !~ "x"') " remove items with an 'x'
Bram Moolenaar13065c42005-01-08 16:08:21 +0000373
Bram Moolenaar3a3a7232005-01-17 22:16:15 +0000374Changing the order of items in a list: >
Bram Moolenaar9588a0f2005-01-08 21:45:39 +0000375 :call sort(list) " sort a list alphabetically
376 :call reverse(list) " reverse the order of items
Bram Moolenaar327aa022014-03-25 18:24:23 +0100377 :call uniq(sort(list)) " sort and remove duplicates
Bram Moolenaar9588a0f2005-01-08 21:45:39 +0000378
Bram Moolenaar13065c42005-01-08 16:08:21 +0000379
380For loop ~
381
Bram Moolenaar9588a0f2005-01-08 21:45:39 +0000382The |:for| loop executes commands for each item in a list. A variable is set
383to each item in the list in sequence. Example: >
Bram Moolenaar3a3a7232005-01-17 22:16:15 +0000384 :for item in mylist
385 : call Doit(item)
Bram Moolenaar13065c42005-01-08 16:08:21 +0000386 :endfor
387
388This works like: >
389 :let index = 0
390 :while index < len(mylist)
Bram Moolenaar3a3a7232005-01-17 22:16:15 +0000391 : let item = mylist[index]
392 : :call Doit(item)
Bram Moolenaar13065c42005-01-08 16:08:21 +0000393 : let index = index + 1
394 :endwhile
395
Bram Moolenaar5f2bb9f2005-01-11 21:29:04 +0000396If all you want to do is modify each item in the list then the |map()|
Bram Moolenaar3a3a7232005-01-17 22:16:15 +0000397function will be a simpler method than a for loop.
Bram Moolenaar5f2bb9f2005-01-11 21:29:04 +0000398
Bram Moolenaar446cb832008-06-24 21:56:24 +0000399Just like the |:let| command, |:for| also accepts a list of variables. This
Bram Moolenaar13065c42005-01-08 16:08:21 +0000400requires the argument to be a list of lists. >
401 :for [lnum, col] in [[1, 3], [2, 8], [3, 0]]
402 : call Doit(lnum, col)
403 :endfor
404
405This works like a |:let| command is done for each list item. Again, the types
406must remain the same to avoid an error.
407
Bram Moolenaar3a3a7232005-01-17 22:16:15 +0000408It is also possible to put remaining items in a List variable: >
Bram Moolenaar13065c42005-01-08 16:08:21 +0000409 :for [i, j; rest] in listlist
410 : call Doit(i, j)
411 : if !empty(rest)
412 : echo "remainder: " . string(rest)
413 : endif
414 :endfor
415
416
417List functions ~
Bram Moolenaar3a3a7232005-01-17 22:16:15 +0000418 *E714*
Bram Moolenaar13065c42005-01-08 16:08:21 +0000419Functions that are useful with a List: >
Bram Moolenaar9588a0f2005-01-08 21:45:39 +0000420 :let r = call(funcname, list) " call a function with an argument list
Bram Moolenaar13065c42005-01-08 16:08:21 +0000421 :if empty(list) " check if list is empty
Bram Moolenaar2fda12f2005-01-15 22:14:15 +0000422 :let l = len(list) " number of items in list
423 :let big = max(list) " maximum value in list
424 :let small = min(list) " minimum value in list
Bram Moolenaar9588a0f2005-01-08 21:45:39 +0000425 :let xs = count(list, 'x') " count nr of times 'x' appears in list
426 :let i = index(list, 'x') " index of first 'x' in list
Bram Moolenaar13065c42005-01-08 16:08:21 +0000427 :let lines = getline(1, 10) " get ten text lines from buffer
428 :call append('$', lines) " append text lines in buffer
Bram Moolenaar5f2bb9f2005-01-11 21:29:04 +0000429 :let list = split("a b c") " create list from items in a string
430 :let string = join(list, ', ') " create string from list items
Bram Moolenaar2fda12f2005-01-15 22:14:15 +0000431 :let s = string(list) " String representation of list
432 :call map(list, '">> " . v:val') " prepend ">> " to each item
Bram Moolenaar13065c42005-01-08 16:08:21 +0000433
Bram Moolenaar0cb032e2005-04-23 20:52:00 +0000434Don't forget that a combination of features can make things simple. For
435example, to add up all the numbers in a list: >
436 :exe 'let sum = ' . join(nrlist, '+')
437
Bram Moolenaar13065c42005-01-08 16:08:21 +0000438
Bram Moolenaard8b02732005-01-14 21:48:43 +00004391.4 Dictionaries ~
Bram Moolenaar7e38ea22014-04-05 22:55:53 +0200440 *dict* *Dictionaries* *Dictionary*
Bram Moolenaard8b02732005-01-14 21:48:43 +0000441A Dictionary is an associative array: Each entry has a key and a value. The
Bram Moolenaar3a3a7232005-01-17 22:16:15 +0000442entry can be located with the key. The entries are stored without a specific
443ordering.
Bram Moolenaard8b02732005-01-14 21:48:43 +0000444
445
446Dictionary creation ~
Bram Moolenaar3a3a7232005-01-17 22:16:15 +0000447 *E720* *E721* *E722* *E723*
Bram Moolenaard8b02732005-01-14 21:48:43 +0000448A Dictionary is created with a comma separated list of entries in curly
Bram Moolenaar3a3a7232005-01-17 22:16:15 +0000449braces. Each entry has a key and a value, separated by a colon. Each key can
450only appear once. Examples: >
Bram Moolenaard8b02732005-01-14 21:48:43 +0000451 :let mydict = {1: 'one', 2: 'two', 3: 'three'}
452 :let emptydict = {}
Bram Moolenaar3a3a7232005-01-17 22:16:15 +0000453< *E713* *E716* *E717*
Bram Moolenaard8b02732005-01-14 21:48:43 +0000454A key is always a String. You can use a Number, it will be converted to a
455String automatically. Thus the String '4' and the number 4 will find the same
Bram Moolenaar446cb832008-06-24 21:56:24 +0000456entry. Note that the String '04' and the Number 04 are different, since the
Bram Moolenaar03413f42016-04-12 21:07:15 +0200457Number will be converted to the String '4'. The empty string can be used as a
458key.
Bram Moolenaard8b02732005-01-14 21:48:43 +0000459
Bram Moolenaar446cb832008-06-24 21:56:24 +0000460A value can be any expression. Using a Dictionary for a value creates a
Bram Moolenaard8b02732005-01-14 21:48:43 +0000461nested Dictionary: >
462 :let nestdict = {1: {11: 'a', 12: 'b'}, 2: {21: 'c'}}
463
464An extra comma after the last entry is ignored.
465
466
467Accessing entries ~
468
469The normal way to access an entry is by putting the key in square brackets: >
470 :let val = mydict["one"]
471 :let mydict["four"] = 4
472
Bram Moolenaar3a3a7232005-01-17 22:16:15 +0000473You can add new entries to an existing Dictionary this way, unlike Lists.
Bram Moolenaard8b02732005-01-14 21:48:43 +0000474
475For keys that consist entirely of letters, digits and underscore the following
476form can be used |expr-entry|: >
477 :let val = mydict.one
478 :let mydict.four = 4
479
480Since an entry can be any type, also a List and a Dictionary, the indexing and
481key lookup can be repeated: >
Bram Moolenaar3a3a7232005-01-17 22:16:15 +0000482 :echo dict.key[idx].key
Bram Moolenaard8b02732005-01-14 21:48:43 +0000483
484
485Dictionary to List conversion ~
486
Bram Moolenaar446cb832008-06-24 21:56:24 +0000487You may want to loop over the entries in a dictionary. For this you need to
Bram Moolenaard8b02732005-01-14 21:48:43 +0000488turn the Dictionary into a List and pass it to |:for|.
489
490Most often you want to loop over the keys, using the |keys()| function: >
491 :for key in keys(mydict)
492 : echo key . ': ' . mydict[key]
493 :endfor
494
495The List of keys is unsorted. You may want to sort them first: >
496 :for key in sort(keys(mydict))
497
498To loop over the values use the |values()| function: >
499 :for v in values(mydict)
500 : echo "value: " . v
501 :endfor
502
503If you want both the key and the value use the |items()| function. It returns
Bram Moolenaar446cb832008-06-24 21:56:24 +0000504a List in which each item is a List with two items, the key and the value: >
Bram Moolenaaref2f6562007-05-06 13:32:59 +0000505 :for [key, value] in items(mydict)
506 : echo key . ': ' . value
Bram Moolenaard8b02732005-01-14 21:48:43 +0000507 :endfor
508
509
510Dictionary identity ~
Bram Moolenaar7c626922005-02-07 22:01:03 +0000511 *dict-identity*
Bram Moolenaard8b02732005-01-14 21:48:43 +0000512Just like Lists you need to use |copy()| and |deepcopy()| to make a copy of a
513Dictionary. Otherwise, assignment results in referring to the same
514Dictionary: >
515 :let onedict = {'a': 1, 'b': 2}
516 :let adict = onedict
517 :let adict['a'] = 11
518 :echo onedict['a']
519 11
520
Bram Moolenaarf3bd51a2005-06-14 22:11:18 +0000521Two Dictionaries compare equal if all the key-value pairs compare equal. For
522more info see |list-identity|.
Bram Moolenaard8b02732005-01-14 21:48:43 +0000523
524
525Dictionary modification ~
526 *dict-modification*
527To change an already existing entry of a Dictionary, or to add a new entry,
528use |:let| this way: >
529 :let dict[4] = "four"
530 :let dict['one'] = item
531
Bram Moolenaar9cd15162005-01-16 22:02:49 +0000532Removing an entry from a Dictionary is done with |remove()| or |:unlet|.
533Three ways to remove the entry with key "aaa" from dict: >
534 :let i = remove(dict, 'aaa')
535 :unlet dict.aaa
536 :unlet dict['aaa']
Bram Moolenaard8b02732005-01-14 21:48:43 +0000537
538Merging a Dictionary with another is done with |extend()|: >
Bram Moolenaar3a3a7232005-01-17 22:16:15 +0000539 :call extend(adict, bdict)
540This extends adict with all entries from bdict. Duplicate keys cause entries
541in adict to be overwritten. An optional third argument can change this.
Bram Moolenaar383f9bc2005-01-19 22:18:32 +0000542Note that the order of entries in a Dictionary is irrelevant, thus don't
543expect ":echo adict" to show the items from bdict after the older entries in
544adict.
Bram Moolenaard8b02732005-01-14 21:48:43 +0000545
546Weeding out entries from a Dictionary can be done with |filter()|: >
Bram Moolenaaref2f6562007-05-06 13:32:59 +0000547 :call filter(dict, 'v:val =~ "x"')
Bram Moolenaar3a3a7232005-01-17 22:16:15 +0000548This removes all entries from "dict" with a value not matching 'x'.
Bram Moolenaar2fda12f2005-01-15 22:14:15 +0000549
550
551Dictionary function ~
Bram Moolenaar26402cb2013-02-20 21:26:00 +0100552 *Dictionary-function* *self* *E725* *E862*
Bram Moolenaar2fda12f2005-01-15 22:14:15 +0000553When a function is defined with the "dict" attribute it can be used in a
Bram Moolenaar446cb832008-06-24 21:56:24 +0000554special way with a dictionary. Example: >
Bram Moolenaar2fda12f2005-01-15 22:14:15 +0000555 :function Mylen() dict
Bram Moolenaar3a3a7232005-01-17 22:16:15 +0000556 : return len(self.data)
Bram Moolenaar2fda12f2005-01-15 22:14:15 +0000557 :endfunction
Bram Moolenaar3a3a7232005-01-17 22:16:15 +0000558 :let mydict = {'data': [0, 1, 2, 3], 'len': function("Mylen")}
559 :echo mydict.len()
Bram Moolenaar2fda12f2005-01-15 22:14:15 +0000560
561This is like a method in object oriented programming. The entry in the
562Dictionary is a |Funcref|. The local variable "self" refers to the dictionary
563the function was invoked from.
564
Bram Moolenaar3a3a7232005-01-17 22:16:15 +0000565It is also possible to add a function without the "dict" attribute as a
566Funcref to a Dictionary, but the "self" variable is not available then.
567
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000568 *numbered-function* *anonymous-function*
Bram Moolenaar2fda12f2005-01-15 22:14:15 +0000569To avoid the extra name for the function it can be defined and directly
570assigned to a Dictionary in this way: >
Bram Moolenaar3a3a7232005-01-17 22:16:15 +0000571 :let mydict = {'data': [0, 1, 2, 3]}
Bram Moolenaar5a5f4592015-04-13 12:43:06 +0200572 :function mydict.len()
Bram Moolenaar3a3a7232005-01-17 22:16:15 +0000573 : return len(self.data)
Bram Moolenaar2fda12f2005-01-15 22:14:15 +0000574 :endfunction
Bram Moolenaar3a3a7232005-01-17 22:16:15 +0000575 :echo mydict.len()
Bram Moolenaar2fda12f2005-01-15 22:14:15 +0000576
Bram Moolenaar3a3a7232005-01-17 22:16:15 +0000577The function will then get a number and the value of dict.len is a |Funcref|
Bram Moolenaar446cb832008-06-24 21:56:24 +0000578that references this function. The function can only be used through a
Bram Moolenaar3a3a7232005-01-17 22:16:15 +0000579|Funcref|. It will automatically be deleted when there is no |Funcref|
580remaining that refers to it.
581
582It is not necessary to use the "dict" attribute for a numbered function.
Bram Moolenaar2fda12f2005-01-15 22:14:15 +0000583
Bram Moolenaar1affd722010-08-04 17:49:30 +0200584If you get an error for a numbered function, you can find out what it is with
585a trick. Assuming the function is 42, the command is: >
586 :function {42}
587
Bram Moolenaar2fda12f2005-01-15 22:14:15 +0000588
589Functions for Dictionaries ~
Bram Moolenaar3a3a7232005-01-17 22:16:15 +0000590 *E715*
591Functions that can be used with a Dictionary: >
Bram Moolenaar2fda12f2005-01-15 22:14:15 +0000592 :if has_key(dict, 'foo') " TRUE if dict has entry with key "foo"
593 :if empty(dict) " TRUE if dict is empty
594 :let l = len(dict) " number of items in dict
595 :let big = max(dict) " maximum value in dict
596 :let small = min(dict) " minimum value in dict
597 :let xs = count(dict, 'x') " count nr of times 'x' appears in dict
598 :let s = string(dict) " String representation of dict
599 :call map(dict, '">> " . v:val') " prepend ">> " to each item
Bram Moolenaard8b02732005-01-14 21:48:43 +0000600
601
6021.5 More about variables ~
Bram Moolenaar13065c42005-01-08 16:08:21 +0000603 *more-variables*
Bram Moolenaar071d4272004-06-13 20:20:40 +0000604If you need to know the type of a variable or expression, use the |type()|
605function.
606
607When the '!' flag is included in the 'viminfo' option, global variables that
608start with an uppercase letter, and don't contain a lowercase letter, are
609stored in the viminfo file |viminfo-file|.
610
611When the 'sessionoptions' option contains "global", global variables that
612start with an uppercase letter and contain at least one lowercase letter are
613stored in the session file |session-file|.
614
615variable name can be stored where ~
616my_var_6 not
617My_Var_6 session file
618MY_VAR_6 viminfo file
619
620
621It's possible to form a variable name with curly braces, see
622|curly-braces-names|.
623
624==============================================================================
6252. Expression syntax *expression-syntax*
626
627Expression syntax summary, from least to most significant:
628
629|expr1| expr2 ? expr1 : expr1 if-then-else
630
631|expr2| expr3 || expr3 .. logical OR
632
633|expr3| expr4 && expr4 .. logical AND
634
635|expr4| expr5 == expr5 equal
636 expr5 != expr5 not equal
637 expr5 > expr5 greater than
638 expr5 >= expr5 greater than or equal
639 expr5 < expr5 smaller than
640 expr5 <= expr5 smaller than or equal
641 expr5 =~ expr5 regexp matches
642 expr5 !~ expr5 regexp doesn't match
643
644 expr5 ==? expr5 equal, ignoring case
645 expr5 ==# expr5 equal, match case
646 etc. As above, append ? for ignoring case, # for
647 matching case
648
Bram Moolenaar32466aa2006-02-24 23:53:04 +0000649 expr5 is expr5 same |List| instance
650 expr5 isnot expr5 different |List| instance
Bram Moolenaarde8866b2005-01-06 23:24:37 +0000651
652|expr5| expr6 + expr6 .. number addition or list concatenation
Bram Moolenaar071d4272004-06-13 20:20:40 +0000653 expr6 - expr6 .. number subtraction
654 expr6 . expr6 .. string concatenation
655
656|expr6| expr7 * expr7 .. number multiplication
657 expr7 / expr7 .. number division
658 expr7 % expr7 .. number modulo
659
660|expr7| ! expr7 logical NOT
661 - expr7 unary minus
662 + expr7 unary plus
Bram Moolenaar071d4272004-06-13 20:20:40 +0000663
Bram Moolenaar32466aa2006-02-24 23:53:04 +0000664|expr8| expr8[expr1] byte of a String or item of a |List|
665 expr8[expr1 : expr1] substring of a String or sublist of a |List|
666 expr8.name entry in a |Dictionary|
667 expr8(expr1, ...) function call with |Funcref| variable
Bram Moolenaar2fda12f2005-01-15 22:14:15 +0000668
669|expr9| number number constant
Bram Moolenaar3fdfa4a2004-10-07 21:02:47 +0000670 "string" string constant, backslash is special
Bram Moolenaard8b02732005-01-14 21:48:43 +0000671 'string' string constant, ' is doubled
Bram Moolenaar32466aa2006-02-24 23:53:04 +0000672 [expr1, ...] |List|
673 {expr1: expr1, ...} |Dictionary|
Bram Moolenaar071d4272004-06-13 20:20:40 +0000674 &option option value
675 (expr1) nested expression
676 variable internal variable
677 va{ria}ble internal variable with curly braces
678 $VAR environment variable
679 @r contents of register 'r'
680 function(expr1, ...) function call
681 func{ti}on(expr1, ...) function call with curly braces
682
683
684".." indicates that the operations in this level can be concatenated.
685Example: >
686 &nu || &list && &shell == "csh"
687
688All expressions within one level are parsed from left to right.
689
690
691expr1 *expr1* *E109*
692-----
693
694expr2 ? expr1 : expr1
695
696The expression before the '?' is evaluated to a number. If it evaluates to
697non-zero, the result is the value of the expression between the '?' and ':',
698otherwise the result is the value of the expression after the ':'.
699Example: >
700 :echo lnum == 1 ? "top" : lnum
701
702Since the first expression is an "expr2", it cannot contain another ?:. The
703other two expressions can, thus allow for recursive use of ?:.
704Example: >
705 :echo lnum == 1 ? "top" : lnum == 1000 ? "last" : lnum
706
707To keep this readable, using |line-continuation| is suggested: >
708 :echo lnum == 1
709 :\ ? "top"
710 :\ : lnum == 1000
711 :\ ? "last"
712 :\ : lnum
713
Bram Moolenaaref2f6562007-05-06 13:32:59 +0000714You should always put a space before the ':', otherwise it can be mistaken for
715use in a variable such as "a:1".
716
Bram Moolenaar071d4272004-06-13 20:20:40 +0000717
718expr2 and expr3 *expr2* *expr3*
719---------------
720
721 *expr-barbar* *expr-&&*
722The "||" and "&&" operators take one argument on each side. The arguments
723are (converted to) Numbers. The result is:
724
725 input output ~
726n1 n2 n1 || n2 n1 && n2 ~
727zero zero zero zero
728zero non-zero non-zero zero
729non-zero zero non-zero zero
730non-zero non-zero non-zero non-zero
731
732The operators can be concatenated, for example: >
733
734 &nu || &list && &shell == "csh"
735
736Note that "&&" takes precedence over "||", so this has the meaning of: >
737
738 &nu || (&list && &shell == "csh")
739
740Once the result is known, the expression "short-circuits", that is, further
741arguments are not evaluated. This is like what happens in C. For example: >
742
743 let a = 1
744 echo a || b
745
746This is valid even if there is no variable called "b" because "a" is non-zero,
747so the result must be non-zero. Similarly below: >
748
749 echo exists("b") && b == "yes"
750
751This is valid whether "b" has been defined or not. The second clause will
752only be evaluated if "b" has been defined.
753
754
755expr4 *expr4*
756-----
757
758expr5 {cmp} expr5
759
760Compare two expr5 expressions, resulting in a 0 if it evaluates to false, or 1
761if it evaluates to true.
762
Bram Moolenaar446cb832008-06-24 21:56:24 +0000763 *expr-==* *expr-!=* *expr->* *expr->=*
Bram Moolenaar071d4272004-06-13 20:20:40 +0000764 *expr-<* *expr-<=* *expr-=~* *expr-!~*
765 *expr-==#* *expr-!=#* *expr->#* *expr->=#*
766 *expr-<#* *expr-<=#* *expr-=~#* *expr-!~#*
767 *expr-==?* *expr-!=?* *expr->?* *expr->=?*
768 *expr-<?* *expr-<=?* *expr-=~?* *expr-!~?*
Bram Moolenaar251e1912011-06-19 05:09:16 +0200769 *expr-is* *expr-isnot* *expr-is#* *expr-isnot#*
770 *expr-is?* *expr-isnot?*
Bram Moolenaar071d4272004-06-13 20:20:40 +0000771 use 'ignorecase' match case ignore case ~
772equal == ==# ==?
773not equal != !=# !=?
774greater than > ># >?
775greater than or equal >= >=# >=?
776smaller than < <# <?
777smaller than or equal <= <=# <=?
778regexp matches =~ =~# =~?
779regexp doesn't match !~ !~# !~?
Bram Moolenaar251e1912011-06-19 05:09:16 +0200780same instance is is# is?
781different instance isnot isnot# isnot?
Bram Moolenaar071d4272004-06-13 20:20:40 +0000782
783Examples:
784"abc" ==# "Abc" evaluates to 0
785"abc" ==? "Abc" evaluates to 1
786"abc" == "Abc" evaluates to 1 if 'ignorecase' is set, 0 otherwise
787
Bram Moolenaar13065c42005-01-08 16:08:21 +0000788 *E691* *E692*
Bram Moolenaar32466aa2006-02-24 23:53:04 +0000789A |List| can only be compared with a |List| and only "equal", "not equal" and
790"is" can be used. This compares the values of the list, recursively.
791Ignoring case means case is ignored when comparing item values.
Bram Moolenaarde8866b2005-01-06 23:24:37 +0000792
Bram Moolenaar3a3a7232005-01-17 22:16:15 +0000793 *E735* *E736*
Bram Moolenaar32466aa2006-02-24 23:53:04 +0000794A |Dictionary| can only be compared with a |Dictionary| and only "equal", "not
795equal" and "is" can be used. This compares the key/values of the |Dictionary|
Bram Moolenaar3a3a7232005-01-17 22:16:15 +0000796recursively. Ignoring case means case is ignored when comparing item values.
797
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +0200798 *E694*
Bram Moolenaar32466aa2006-02-24 23:53:04 +0000799A |Funcref| can only be compared with a |Funcref| and only "equal" and "not
Bram Moolenaar03602ec2016-03-20 20:57:45 +0100800equal" can be used. Case is never ignored. Whether arguments or a Dictionary
801are bound (with a partial) is ignored. This is so that when a function is
802made a member of a Dictionary it is still considered to be the same function.
803To compare partials to see if they bind the same argument and Dictionary
804values use string(): >
805 echo string(Partial1) == string(Partial2)
Bram Moolenaarde8866b2005-01-06 23:24:37 +0000806
Bram Moolenaar251e1912011-06-19 05:09:16 +0200807When using "is" or "isnot" with a |List| or a |Dictionary| this checks if the
808expressions are referring to the same |List| or |Dictionary| instance. A copy
809of a |List| is different from the original |List|. When using "is" without
810a |List| or a |Dictionary| it is equivalent to using "equal", using "isnot"
811equivalent to using "not equal". Except that a different type means the
Bram Moolenaar86edef62016-03-13 18:07:30 +0100812values are different: >
813 echo 4 == '4'
814 1
815 echo 4 is '4'
816 0
817 echo 0 is []
818 0
819"is#"/"isnot#" and "is?"/"isnot?" can be used to match and ignore case.
Bram Moolenaarde8866b2005-01-06 23:24:37 +0000820
Bram Moolenaar071d4272004-06-13 20:20:40 +0000821When comparing a String with a Number, the String is converted to a Number,
Bram Moolenaar86edef62016-03-13 18:07:30 +0100822and the comparison is done on Numbers. This means that: >
823 echo 0 == 'x'
824 1
825because 'x' converted to a Number is zero. However: >
826 echo [0] == ['x']
827 0
828Inside a List or Dictionary this conversion is not used.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000829
830When comparing two Strings, this is done with strcmp() or stricmp(). This
831results in the mathematical difference (comparing byte values), not
832necessarily the alphabetical difference in the local language.
833
Bram Moolenaar446cb832008-06-24 21:56:24 +0000834When using the operators with a trailing '#', or the short version and
Bram Moolenaaref2f6562007-05-06 13:32:59 +0000835'ignorecase' is off, the comparing is done with strcmp(): case matters.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000836
837When using the operators with a trailing '?', or the short version and
Bram Moolenaaref2f6562007-05-06 13:32:59 +0000838'ignorecase' is set, the comparing is done with stricmp(): case is ignored.
839
840'smartcase' is not used.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000841
842The "=~" and "!~" operators match the lefthand argument with the righthand
843argument, which is used as a pattern. See |pattern| for what a pattern is.
844This matching is always done like 'magic' was set and 'cpoptions' is empty, no
845matter what the actual value of 'magic' or 'cpoptions' is. This makes scripts
846portable. To avoid backslashes in the regexp pattern to be doubled, use a
847single-quote string, see |literal-string|.
848Since a string is considered to be a single line, a multi-line pattern
849(containing \n, backslash-n) will not match. However, a literal NL character
850can be matched like an ordinary character. Examples:
851 "foo\nbar" =~ "\n" evaluates to 1
852 "foo\nbar" =~ "\\n" evaluates to 0
853
854
855expr5 and expr6 *expr5* *expr6*
856---------------
Bram Moolenaar32466aa2006-02-24 23:53:04 +0000857expr6 + expr6 .. Number addition or |List| concatenation *expr-+*
Bram Moolenaarde8866b2005-01-06 23:24:37 +0000858expr6 - expr6 .. Number subtraction *expr--*
859expr6 . expr6 .. String concatenation *expr-.*
Bram Moolenaar071d4272004-06-13 20:20:40 +0000860
Bram Moolenaara23ccb82006-02-27 00:08:02 +0000861For |Lists| only "+" is possible and then both expr6 must be a list. The
Bram Moolenaar32466aa2006-02-24 23:53:04 +0000862result is a new list with the two lists Concatenated.
Bram Moolenaarde8866b2005-01-06 23:24:37 +0000863
Bram Moolenaard6e256c2011-12-14 15:32:50 +0100864expr7 * expr7 .. Number multiplication *expr-star*
865expr7 / expr7 .. Number division *expr-/*
866expr7 % expr7 .. Number modulo *expr-%*
Bram Moolenaar071d4272004-06-13 20:20:40 +0000867
868For all, except ".", Strings are converted to Numbers.
Bram Moolenaard6e256c2011-12-14 15:32:50 +0100869For bitwise operators see |and()|, |or()| and |xor()|.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000870
871Note the difference between "+" and ".":
872 "123" + "456" = 579
873 "123" . "456" = "123456"
874
Bram Moolenaar446cb832008-06-24 21:56:24 +0000875Since '.' has the same precedence as '+' and '-', you need to read: >
876 1 . 90 + 90.0
877As: >
878 (1 . 90) + 90.0
879That works, since the String "190" is automatically converted to the Number
880190, which can be added to the Float 90.0. However: >
881 1 . 90 * 90.0
882Should be read as: >
883 1 . (90 * 90.0)
884Since '.' has lower precedence than '*'. This does NOT work, since this
885attempts to concatenate a Float and a String.
886
887When dividing a Number by zero the result depends on the value:
888 0 / 0 = -0x80000000 (like NaN for Float)
889 >0 / 0 = 0x7fffffff (like positive infinity)
890 <0 / 0 = -0x7fffffff (like negative infinity)
891 (before Vim 7.2 it was always 0x7fffffff)
892
Bram Moolenaar22fcfad2016-07-01 18:17:26 +0200893When 64-bit Number support is enabled:
894 0 / 0 = -0x8000000000000000 (like NaN for Float)
895 >0 / 0 = 0x7fffffffffffffff (like positive infinity)
896 <0 / 0 = -0x7fffffffffffffff (like negative infinity)
897
Bram Moolenaar071d4272004-06-13 20:20:40 +0000898When the righthand side of '%' is zero, the result is 0.
899
Bram Moolenaar32466aa2006-02-24 23:53:04 +0000900None of these work for |Funcref|s.
Bram Moolenaarde8866b2005-01-06 23:24:37 +0000901
Bram Moolenaar446cb832008-06-24 21:56:24 +0000902. and % do not work for Float. *E804*
903
Bram Moolenaar071d4272004-06-13 20:20:40 +0000904
905expr7 *expr7*
906-----
907! expr7 logical NOT *expr-!*
908- expr7 unary minus *expr-unary--*
909+ expr7 unary plus *expr-unary-+*
910
911For '!' non-zero becomes zero, zero becomes one.
912For '-' the sign of the number is changed.
913For '+' the number is unchanged.
914
915A String will be converted to a Number first.
916
Bram Moolenaar446cb832008-06-24 21:56:24 +0000917These three can be repeated and mixed. Examples:
Bram Moolenaar071d4272004-06-13 20:20:40 +0000918 !-1 == 0
919 !!8 == 1
920 --9 == 9
921
922
923expr8 *expr8*
924-----
Bram Moolenaar32466aa2006-02-24 23:53:04 +0000925expr8[expr1] item of String or |List| *expr-[]* *E111*
Bram Moolenaar03413f42016-04-12 21:07:15 +0200926 *E909* *subscript*
Bram Moolenaar2fda12f2005-01-15 22:14:15 +0000927If expr8 is a Number or String this results in a String that contains the
928expr1'th single byte from expr8. expr8 is used as a String, expr1 as a
Bram Moolenaar8f3f58f2010-01-06 20:52:26 +0100929Number. This doesn't recognize multi-byte encodings, see |byteidx()| for
Bram Moolenaar03413f42016-04-12 21:07:15 +0200930an alternative, or use `split()` to turn the string into a list of characters.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000931
Bram Moolenaar256972a2015-12-29 19:10:25 +0100932Index zero gives the first byte. This is like it works in C. Careful:
933text column numbers start with one! Example, to get the byte under the
Bram Moolenaard7ee7ce2005-01-03 21:02:03 +0000934cursor: >
Bram Moolenaar61660ea2006-04-07 21:40:07 +0000935 :let c = getline(".")[col(".") - 1]
Bram Moolenaar071d4272004-06-13 20:20:40 +0000936
937If the length of the String is less than the index, the result is an empty
Bram Moolenaar85084ef2016-01-17 22:26:33 +0100938String. A negative index always results in an empty string (reason: backward
Bram Moolenaard7ee7ce2005-01-03 21:02:03 +0000939compatibility). Use [-1:] to get the last byte.
940
Bram Moolenaar32466aa2006-02-24 23:53:04 +0000941If expr8 is a |List| then it results the item at index expr1. See |list-index|
Bram Moolenaard7ee7ce2005-01-03 21:02:03 +0000942for possible index values. If the index is out of range this results in an
Bram Moolenaar446cb832008-06-24 21:56:24 +0000943error. Example: >
Bram Moolenaard7ee7ce2005-01-03 21:02:03 +0000944 :let item = mylist[-1] " get last item
945
Bram Moolenaar32466aa2006-02-24 23:53:04 +0000946Generally, if a |List| index is equal to or higher than the length of the
947|List|, or more negative than the length of the |List|, this results in an
948error.
Bram Moolenaard7ee7ce2005-01-03 21:02:03 +0000949
Bram Moolenaard8b02732005-01-14 21:48:43 +0000950
Bram Moolenaar2fda12f2005-01-15 22:14:15 +0000951expr8[expr1a : expr1b] substring or sublist *expr-[:]*
Bram Moolenaard7ee7ce2005-01-03 21:02:03 +0000952
Bram Moolenaar2fda12f2005-01-15 22:14:15 +0000953If expr8 is a Number or String this results in the substring with the bytes
954from expr1a to and including expr1b. expr8 is used as a String, expr1a and
Bram Moolenaar8f3f58f2010-01-06 20:52:26 +0100955expr1b are used as a Number. This doesn't recognize multi-byte encodings, see
956|byteidx()| for computing the indexes.
Bram Moolenaard7ee7ce2005-01-03 21:02:03 +0000957
958If expr1a is omitted zero is used. If expr1b is omitted the length of the
959string minus one is used.
960
961A negative number can be used to measure from the end of the string. -1 is
962the last character, -2 the last but one, etc.
963
964If an index goes out of range for the string characters are omitted. If
965expr1b is smaller than expr1a the result is an empty string.
966
967Examples: >
968 :let c = name[-1:] " last byte of a string
969 :let c = name[-2:-2] " last but one byte of a string
970 :let s = line(".")[4:] " from the fifth byte to the end
971 :let s = s[:-3] " remove last two bytes
Bram Moolenaar8f3f58f2010-01-06 20:52:26 +0100972<
973 *sublist* *slice*
Bram Moolenaar32466aa2006-02-24 23:53:04 +0000974If expr8 is a |List| this results in a new |List| with the items indicated by
Bram Moolenaar446cb832008-06-24 21:56:24 +0000975the indexes expr1a and expr1b. This works like with a String, as explained
Bram Moolenaar32466aa2006-02-24 23:53:04 +0000976just above, except that indexes out of range cause an error. Examples: >
Bram Moolenaard7ee7ce2005-01-03 21:02:03 +0000977 :let l = mylist[:3] " first four items
978 :let l = mylist[4:4] " List with one item
979 :let l = mylist[:] " shallow copy of a List
980
Bram Moolenaar32466aa2006-02-24 23:53:04 +0000981Using expr8[expr1] or expr8[expr1a : expr1b] on a |Funcref| results in an
982error.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000983
Bram Moolenaarda440d22016-01-16 21:27:23 +0100984Watch out for confusion between a namespace and a variable followed by a colon
985for a sublist: >
986 mylist[n:] " uses variable n
987 mylist[s:] " uses namespace s:, error!
988
Bram Moolenaard8b02732005-01-14 21:48:43 +0000989
Bram Moolenaar32466aa2006-02-24 23:53:04 +0000990expr8.name entry in a |Dictionary| *expr-entry*
Bram Moolenaard8b02732005-01-14 21:48:43 +0000991
Bram Moolenaar32466aa2006-02-24 23:53:04 +0000992If expr8 is a |Dictionary| and it is followed by a dot, then the following
993name will be used as a key in the |Dictionary|. This is just like:
994expr8[name].
Bram Moolenaard8b02732005-01-14 21:48:43 +0000995
996The name must consist of alphanumeric characters, just like a variable name,
997but it may start with a number. Curly braces cannot be used.
998
999There must not be white space before or after the dot.
1000
1001Examples: >
1002 :let dict = {"one": 1, 2: "two"}
1003 :echo dict.one
1004 :echo dict .2
1005
1006Note that the dot is also used for String concatenation. To avoid confusion
1007always put spaces around the dot for String concatenation.
1008
1009
Bram Moolenaar32466aa2006-02-24 23:53:04 +00001010expr8(expr1, ...) |Funcref| function call
Bram Moolenaar2fda12f2005-01-15 22:14:15 +00001011
1012When expr8 is a |Funcref| type variable, invoke the function it refers to.
1013
1014
1015
1016 *expr9*
Bram Moolenaar071d4272004-06-13 20:20:40 +00001017number
1018------
Bram Moolenaarf1568ec2011-12-14 21:17:39 +01001019number number constant *expr-number*
1020 *hex-number* *octal-number*
Bram Moolenaar071d4272004-06-13 20:20:40 +00001021
1022Decimal, Hexadecimal (starting with 0x or 0X), or Octal (starting with 0).
1023
Bram Moolenaar446cb832008-06-24 21:56:24 +00001024 *floating-point-format*
1025Floating point numbers can be written in two forms:
1026
1027 [-+]{N}.{M}
Bram Moolenaar8a94d872015-01-25 13:02:57 +01001028 [-+]{N}.{M}[eE][-+]{exp}
Bram Moolenaar446cb832008-06-24 21:56:24 +00001029
1030{N} and {M} are numbers. Both {N} and {M} must be present and can only
1031contain digits.
1032[-+] means there is an optional plus or minus sign.
1033{exp} is the exponent, power of 10.
1034Only a decimal point is accepted, not a comma. No matter what the current
1035locale is.
1036{only when compiled with the |+float| feature}
1037
1038Examples:
1039 123.456
1040 +0.0001
1041 55.0
1042 -0.123
1043 1.234e03
1044 1.0E-6
1045 -3.1416e+88
1046
1047These are INVALID:
1048 3. empty {M}
1049 1e40 missing .{M}
1050
Bram Moolenaare37d50a2008-08-06 17:06:04 +00001051 *float-pi* *float-e*
1052A few useful values to copy&paste: >
1053 :let pi = 3.14159265359
1054 :let e = 2.71828182846
1055
Bram Moolenaar446cb832008-06-24 21:56:24 +00001056Rationale:
1057Before floating point was introduced, the text "123.456" was interpreted as
1058the two numbers "123" and "456", both converted to a string and concatenated,
1059resulting in the string "123456". Since this was considered pointless, and we
Bram Moolenaare37d50a2008-08-06 17:06:04 +00001060could not find it intentionally being used in Vim scripts, this backwards
Bram Moolenaar446cb832008-06-24 21:56:24 +00001061incompatibility was accepted in favor of being able to use the normal notation
1062for floating point numbers.
1063
1064 *floating-point-precision*
1065The precision and range of floating points numbers depends on what "double"
1066means in the library Vim was compiled with. There is no way to change this at
1067runtime.
1068
1069The default for displaying a |Float| is to use 6 decimal places, like using
1070printf("%g", f). You can select something else when using the |printf()|
1071function. Example: >
1072 :echo printf('%.15e', atan(1))
1073< 7.853981633974483e-01
1074
1075
Bram Moolenaar071d4272004-06-13 20:20:40 +00001076
Bram Moolenaar979243b2015-06-26 19:35:49 +02001077string *string* *String* *expr-string* *E114*
Bram Moolenaar071d4272004-06-13 20:20:40 +00001078------
1079"string" string constant *expr-quote*
1080
1081Note that double quotes are used.
1082
1083A string constant accepts these special characters:
1084\... three-digit octal number (e.g., "\316")
1085\.. two-digit octal number (must be followed by non-digit)
1086\. one-digit octal number (must be followed by non-digit)
1087\x.. byte specified with two hex numbers (e.g., "\x1f")
1088\x. byte specified with one hex number (must be followed by non-hex char)
1089\X.. same as \x..
1090\X. same as \x.
Bram Moolenaar446cb832008-06-24 21:56:24 +00001091\u.... character specified with up to 4 hex numbers, stored according to the
Bram Moolenaar071d4272004-06-13 20:20:40 +00001092 current value of 'encoding' (e.g., "\u02a4")
Bram Moolenaar541f92d2015-06-19 13:27:23 +02001093\U.... same as \u but allows up to 8 hex numbers.
Bram Moolenaar071d4272004-06-13 20:20:40 +00001094\b backspace <BS>
1095\e escape <Esc>
1096\f formfeed <FF>
1097\n newline <NL>
1098\r return <CR>
1099\t tab <Tab>
1100\\ backslash
1101\" double quote
Bram Moolenaar00a927d2010-05-14 23:24:24 +02001102\<xxx> Special key named "xxx". e.g. "\<C-W>" for CTRL-W. This is for use
1103 in mappings, the 0x80 byte is escaped. Don't use <Char-xxxx> to get a
1104 utf-8 character, use \uxxxx as mentioned above.
Bram Moolenaar071d4272004-06-13 20:20:40 +00001105
Bram Moolenaaref2f6562007-05-06 13:32:59 +00001106Note that "\xff" is stored as the byte 255, which may be invalid in some
1107encodings. Use "\u00ff" to store character 255 according to the current value
1108of 'encoding'.
1109
Bram Moolenaar071d4272004-06-13 20:20:40 +00001110Note that "\000" and "\x00" force the end of the string.
1111
1112
1113literal-string *literal-string* *E115*
1114---------------
Bram Moolenaar3fdfa4a2004-10-07 21:02:47 +00001115'string' string constant *expr-'*
Bram Moolenaar071d4272004-06-13 20:20:40 +00001116
1117Note that single quotes are used.
1118
Bram Moolenaar446cb832008-06-24 21:56:24 +00001119This string is taken as it is. No backslashes are removed or have a special
Bram Moolenaard8b02732005-01-14 21:48:43 +00001120meaning. The only exception is that two quotes stand for one quote.
Bram Moolenaar3fdfa4a2004-10-07 21:02:47 +00001121
1122Single quoted strings are useful for patterns, so that backslashes do not need
Bram Moolenaar446cb832008-06-24 21:56:24 +00001123to be doubled. These two commands are equivalent: >
Bram Moolenaar3fdfa4a2004-10-07 21:02:47 +00001124 if a =~ "\\s*"
1125 if a =~ '\s*'
Bram Moolenaar071d4272004-06-13 20:20:40 +00001126
1127
1128option *expr-option* *E112* *E113*
1129------
1130&option option value, local value if possible
1131&g:option global option value
1132&l:option local option value
1133
1134Examples: >
1135 echo "tabstop is " . &tabstop
1136 if &insertmode
1137
1138Any option name can be used here. See |options|. When using the local value
1139and there is no buffer-local or window-local value, the global value is used
1140anyway.
1141
1142
Bram Moolenaaref2f6562007-05-06 13:32:59 +00001143register *expr-register* *@r*
Bram Moolenaar071d4272004-06-13 20:20:40 +00001144--------
1145@r contents of register 'r'
1146
1147The result is the contents of the named register, as a single string.
1148Newlines are inserted where required. To get the contents of the unnamed
Bram Moolenaar446cb832008-06-24 21:56:24 +00001149register use @" or @@. See |registers| for an explanation of the available
Bram Moolenaare7566042005-06-17 22:00:15 +00001150registers.
1151
1152When using the '=' register you get the expression itself, not what it
1153evaluates to. Use |eval()| to evaluate it.
Bram Moolenaar071d4272004-06-13 20:20:40 +00001154
1155
1156nesting *expr-nesting* *E110*
1157-------
1158(expr1) nested expression
1159
1160
1161environment variable *expr-env*
1162--------------------
1163$VAR environment variable
1164
1165The String value of any environment variable. When it is not defined, the
1166result is an empty string.
1167 *expr-env-expand*
1168Note that there is a difference between using $VAR directly and using
1169expand("$VAR"). Using it directly will only expand environment variables that
1170are known inside the current Vim session. Using expand() will first try using
1171the environment variables known inside the current Vim session. If that
1172fails, a shell will be used to expand the variable. This can be slow, but it
1173does expand all variables that the shell knows about. Example: >
Bram Moolenaar34401cc2014-08-29 15:12:19 +02001174 :echo $shell
1175 :echo expand("$shell")
1176The first one probably doesn't echo anything, the second echoes the $shell
Bram Moolenaar071d4272004-06-13 20:20:40 +00001177variable (if your shell supports it).
1178
1179
1180internal variable *expr-variable*
1181-----------------
1182variable internal variable
1183See below |internal-variables|.
1184
1185
Bram Moolenaar05159a02005-02-26 23:04:13 +00001186function call *expr-function* *E116* *E118* *E119* *E120*
Bram Moolenaar071d4272004-06-13 20:20:40 +00001187-------------
1188function(expr1, ...) function call
1189See below |functions|.
1190
1191
1192==============================================================================
Bram Moolenaar4a748032010-09-30 21:47:56 +020011933. Internal variable *internal-variables* *E461*
1194
Bram Moolenaar071d4272004-06-13 20:20:40 +00001195An internal variable name can be made up of letters, digits and '_'. But it
1196cannot start with a digit. It's also possible to use curly braces, see
1197|curly-braces-names|.
1198
1199An internal variable is created with the ":let" command |:let|.
Bram Moolenaar9588a0f2005-01-08 21:45:39 +00001200An internal variable is explicitly destroyed with the ":unlet" command
1201|:unlet|.
1202Using a name that is not an internal variable or refers to a variable that has
1203been destroyed results in an error.
Bram Moolenaar071d4272004-06-13 20:20:40 +00001204
1205There are several name spaces for variables. Which one is to be used is
1206specified by what is prepended:
1207
1208 (nothing) In a function: local to a function; otherwise: global
1209|buffer-variable| b: Local to the current buffer.
1210|window-variable| w: Local to the current window.
Bram Moolenaar910f66f2006-04-05 20:41:53 +00001211|tabpage-variable| t: Local to the current tab page.
Bram Moolenaar071d4272004-06-13 20:20:40 +00001212|global-variable| g: Global.
1213|local-variable| l: Local to a function.
1214|script-variable| s: Local to a |:source|'ed Vim script.
1215|function-argument| a: Function argument (only inside a function).
Bram Moolenaar75b81562014-04-06 14:09:13 +02001216|vim-variable| v: Global, predefined by Vim.
Bram Moolenaar071d4272004-06-13 20:20:40 +00001217
Bram Moolenaar32466aa2006-02-24 23:53:04 +00001218The scope name by itself can be used as a |Dictionary|. For example, to
1219delete all script-local variables: >
Bram Moolenaar8f999f12005-01-25 22:12:55 +00001220 :for k in keys(s:)
1221 : unlet s:[k]
1222 :endfor
1223<
Bram Moolenaar531da592013-05-06 05:58:55 +02001224 *buffer-variable* *b:var* *b:*
Bram Moolenaar071d4272004-06-13 20:20:40 +00001225A variable name that is preceded with "b:" is local to the current buffer.
1226Thus you can have several "b:foo" variables, one for each buffer.
1227This kind of variable is deleted when the buffer is wiped out or deleted with
1228|:bdelete|.
1229
1230One local buffer variable is predefined:
Bram Moolenaarbf884932013-04-05 22:26:15 +02001231 *b:changedtick* *changetick*
Bram Moolenaar071d4272004-06-13 20:20:40 +00001232b:changedtick The total number of changes to the current buffer. It is
1233 incremented for each change. An undo command is also a change
1234 in this case. This can be used to perform an action only when
1235 the buffer has changed. Example: >
1236 :if my_changedtick != b:changedtick
Bram Moolenaar446cb832008-06-24 21:56:24 +00001237 : let my_changedtick = b:changedtick
1238 : call My_Update()
Bram Moolenaar071d4272004-06-13 20:20:40 +00001239 :endif
1240<
Bram Moolenaar531da592013-05-06 05:58:55 +02001241 *window-variable* *w:var* *w:*
Bram Moolenaar071d4272004-06-13 20:20:40 +00001242A variable name that is preceded with "w:" is local to the current window. It
1243is deleted when the window is closed.
1244
Bram Moolenaarad3b3662013-05-17 18:14:19 +02001245 *tabpage-variable* *t:var* *t:*
Bram Moolenaar910f66f2006-04-05 20:41:53 +00001246A variable name that is preceded with "t:" is local to the current tab page,
1247It is deleted when the tab page is closed. {not available when compiled
Bram Moolenaardb84e452010-08-15 13:50:43 +02001248without the |+windows| feature}
Bram Moolenaar910f66f2006-04-05 20:41:53 +00001249
Bram Moolenaar531da592013-05-06 05:58:55 +02001250 *global-variable* *g:var* *g:*
Bram Moolenaar071d4272004-06-13 20:20:40 +00001251Inside functions global variables are accessed with "g:". Omitting this will
Bram Moolenaar446cb832008-06-24 21:56:24 +00001252access a variable local to a function. But "g:" can also be used in any other
Bram Moolenaar071d4272004-06-13 20:20:40 +00001253place if you like.
1254
Bram Moolenaar531da592013-05-06 05:58:55 +02001255 *local-variable* *l:var* *l:*
Bram Moolenaar071d4272004-06-13 20:20:40 +00001256Inside functions local variables are accessed without prepending anything.
Bram Moolenaaref2f6562007-05-06 13:32:59 +00001257But you can also prepend "l:" if you like. However, without prepending "l:"
1258you may run into reserved variable names. For example "count". By itself it
1259refers to "v:count". Using "l:count" you can have a local variable with the
1260same name.
Bram Moolenaar071d4272004-06-13 20:20:40 +00001261
1262 *script-variable* *s:var*
1263In a Vim script variables starting with "s:" can be used. They cannot be
1264accessed from outside of the scripts, thus are local to the script.
1265
1266They can be used in:
1267- commands executed while the script is sourced
1268- functions defined in the script
1269- autocommands defined in the script
1270- functions and autocommands defined in functions and autocommands which were
1271 defined in the script (recursively)
1272- user defined commands defined in the script
1273Thus not in:
1274- other scripts sourced from this one
1275- mappings
Bram Moolenaar8f3f58f2010-01-06 20:52:26 +01001276- menus
Bram Moolenaar071d4272004-06-13 20:20:40 +00001277- etc.
1278
Bram Moolenaaref2f6562007-05-06 13:32:59 +00001279Script variables can be used to avoid conflicts with global variable names.
1280Take this example: >
Bram Moolenaar071d4272004-06-13 20:20:40 +00001281
1282 let s:counter = 0
1283 function MyCounter()
1284 let s:counter = s:counter + 1
1285 echo s:counter
1286 endfunction
1287 command Tick call MyCounter()
1288
1289You can now invoke "Tick" from any script, and the "s:counter" variable in
1290that script will not be changed, only the "s:counter" in the script where
1291"Tick" was defined is used.
1292
1293Another example that does the same: >
1294
1295 let s:counter = 0
1296 command Tick let s:counter = s:counter + 1 | echo s:counter
1297
1298When calling a function and invoking a user-defined command, the context for
Bram Moolenaar69a7cb42004-06-20 12:51:53 +00001299script variables is set to the script where the function or command was
Bram Moolenaar071d4272004-06-13 20:20:40 +00001300defined.
1301
1302The script variables are also available when a function is defined inside a
1303function that is defined in a script. Example: >
1304
1305 let s:counter = 0
1306 function StartCounting(incr)
1307 if a:incr
1308 function MyCounter()
1309 let s:counter = s:counter + 1
1310 endfunction
1311 else
1312 function MyCounter()
1313 let s:counter = s:counter - 1
1314 endfunction
1315 endif
1316 endfunction
1317
1318This defines the MyCounter() function either for counting up or counting down
1319when calling StartCounting(). It doesn't matter from where StartCounting() is
1320called, the s:counter variable will be accessible in MyCounter().
1321
1322When the same script is sourced again it will use the same script variables.
1323They will remain valid as long as Vim is running. This can be used to
1324maintain a counter: >
1325
1326 if !exists("s:counter")
1327 let s:counter = 1
1328 echo "script executed for the first time"
1329 else
1330 let s:counter = s:counter + 1
1331 echo "script executed " . s:counter . " times now"
1332 endif
1333
1334Note that this means that filetype plugins don't get a different set of script
1335variables for each buffer. Use local buffer variables instead |b:var|.
1336
1337
Bram Moolenaar531da592013-05-06 05:58:55 +02001338Predefined Vim variables: *vim-variable* *v:var* *v:*
Bram Moolenaar071d4272004-06-13 20:20:40 +00001339
Bram Moolenaare4efc3b2005-03-07 23:16:51 +00001340 *v:beval_col* *beval_col-variable*
1341v:beval_col The number of the column, over which the mouse pointer is.
1342 This is the byte index in the |v:beval_lnum| line.
1343 Only valid while evaluating the 'balloonexpr' option.
1344
1345 *v:beval_bufnr* *beval_bufnr-variable*
1346v:beval_bufnr The number of the buffer, over which the mouse pointer is. Only
1347 valid while evaluating the 'balloonexpr' option.
1348
1349 *v:beval_lnum* *beval_lnum-variable*
1350v:beval_lnum The number of the line, over which the mouse pointer is. Only
1351 valid while evaluating the 'balloonexpr' option.
1352
1353 *v:beval_text* *beval_text-variable*
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00001354v:beval_text The text under or after the mouse pointer. Usually a word as
1355 it is useful for debugging a C program. 'iskeyword' applies,
1356 but a dot and "->" before the position is included. When on a
1357 ']' the text before it is used, including the matching '[' and
Bram Moolenaare4efc3b2005-03-07 23:16:51 +00001358 word before it. When on a Visual area within one line the
1359 highlighted text is used.
1360 Only valid while evaluating the 'balloonexpr' option.
1361
1362 *v:beval_winnr* *beval_winnr-variable*
1363v:beval_winnr The number of the window, over which the mouse pointer is. Only
Bram Moolenaar00654022011-02-25 14:42:19 +01001364 valid while evaluating the 'balloonexpr' option. The first
1365 window has number zero (unlike most other places where a
1366 window gets a number).
Bram Moolenaare4efc3b2005-03-07 23:16:51 +00001367
Bram Moolenaar511972d2016-06-04 18:09:59 +02001368 *v:beval_winid* *beval_winid-variable*
1369v:beval_winid The window ID of the window, over which the mouse pointer is.
1370 Otherwise like v:beval_winnr.
1371
Bram Moolenaarf193fff2006-04-27 00:02:13 +00001372 *v:char* *char-variable*
Bram Moolenaar8f3f58f2010-01-06 20:52:26 +01001373v:char Argument for evaluating 'formatexpr' and used for the typed
Bram Moolenaar945e2db2010-06-05 17:43:32 +02001374 character when using <expr> in an abbreviation |:map-<expr>|.
Bram Moolenaare6ae6222013-05-21 21:01:10 +02001375 It is also used by the |InsertCharPre| and |InsertEnter| events.
Bram Moolenaarf193fff2006-04-27 00:02:13 +00001376
Bram Moolenaar071d4272004-06-13 20:20:40 +00001377 *v:charconvert_from* *charconvert_from-variable*
1378v:charconvert_from
1379 The name of the character encoding of a file to be converted.
1380 Only valid while evaluating the 'charconvert' option.
1381
1382 *v:charconvert_to* *charconvert_to-variable*
1383v:charconvert_to
1384 The name of the character encoding of a file after conversion.
1385 Only valid while evaluating the 'charconvert' option.
1386
1387 *v:cmdarg* *cmdarg-variable*
1388v:cmdarg This variable is used for two purposes:
1389 1. The extra arguments given to a file read/write command.
1390 Currently these are "++enc=" and "++ff=". This variable is
1391 set before an autocommand event for a file read/write
1392 command is triggered. There is a leading space to make it
1393 possible to append this variable directly after the
Bram Moolenaar446cb832008-06-24 21:56:24 +00001394 read/write command. Note: The "+cmd" argument isn't
Bram Moolenaar071d4272004-06-13 20:20:40 +00001395 included here, because it will be executed anyway.
1396 2. When printing a PostScript file with ":hardcopy" this is
1397 the argument for the ":hardcopy" command. This can be used
1398 in 'printexpr'.
1399
1400 *v:cmdbang* *cmdbang-variable*
1401v:cmdbang Set like v:cmdarg for a file read/write command. When a "!"
1402 was used the value is 1, otherwise it is 0. Note that this
1403 can only be used in autocommands. For user commands |<bang>|
1404 can be used.
1405
Bram Moolenaar42a45122015-07-10 17:56:23 +02001406 *v:completed_item* *completed_item-variable*
1407v:completed_item
1408 |Dictionary| containing the |complete-items| for the most
1409 recently completed word after |CompleteDone|. The
1410 |Dictionary| is empty if the completion failed.
1411
Bram Moolenaar071d4272004-06-13 20:20:40 +00001412 *v:count* *count-variable*
1413v:count The count given for the last Normal mode command. Can be used
Bram Moolenaar446cb832008-06-24 21:56:24 +00001414 to get the count before a mapping. Read-only. Example: >
Bram Moolenaar071d4272004-06-13 20:20:40 +00001415 :map _x :<C-U>echo "the count is " . v:count<CR>
1416< Note: The <C-U> is required to remove the line range that you
1417 get when typing ':' after a count.
Bram Moolenaar8f3f58f2010-01-06 20:52:26 +01001418 When there are two counts, as in "3d2w", they are multiplied,
1419 just like what happens in the command, "d6w" for the example.
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00001420 Also used for evaluating the 'formatexpr' option.
Bram Moolenaar071d4272004-06-13 20:20:40 +00001421 "count" also works, for backwards compatibility.
1422
1423 *v:count1* *count1-variable*
1424v:count1 Just like "v:count", but defaults to one when no count is
1425 used.
1426
1427 *v:ctype* *ctype-variable*
1428v:ctype The current locale setting for characters of the runtime
1429 environment. This allows Vim scripts to be aware of the
1430 current locale encoding. Technical: it's the value of
1431 LC_CTYPE. When not using a locale the value is "C".
1432 This variable can not be set directly, use the |:language|
1433 command.
1434 See |multi-lang|.
1435
1436 *v:dying* *dying-variable*
Bram Moolenaar446cb832008-06-24 21:56:24 +00001437v:dying Normally zero. When a deadly signal is caught it's set to
Bram Moolenaar071d4272004-06-13 20:20:40 +00001438 one. When multiple signals are caught the number increases.
1439 Can be used in an autocommand to check if Vim didn't
1440 terminate normally. {only works on Unix}
1441 Example: >
1442 :au VimLeave * if v:dying | echo "\nAAAAaaaarrrggghhhh!!!\n" | endif
Bram Moolenaar0e1e25f2010-05-28 21:07:08 +02001443< Note: if another deadly signal is caught when v:dying is one,
1444 VimLeave autocommands will not be executed.
1445
Bram Moolenaar071d4272004-06-13 20:20:40 +00001446 *v:errmsg* *errmsg-variable*
1447v:errmsg Last given error message. It's allowed to set this variable.
1448 Example: >
1449 :let v:errmsg = ""
1450 :silent! next
1451 :if v:errmsg != ""
1452 : ... handle error
1453< "errmsg" also works, for backwards compatibility.
1454
Bram Moolenaar43345542015-11-29 17:35:35 +01001455 *v:errors* *errors-variable*
Bram Moolenaar683fa182015-11-30 21:38:24 +01001456v:errors Errors found by assert functions, such as |assert_true()|.
Bram Moolenaar43345542015-11-29 17:35:35 +01001457 This is a list of strings.
1458 The assert functions append an item when an assert fails.
1459 To remove old results make it empty: >
1460 :let v:errors = []
1461< If v:errors is set to anything but a list it is made an empty
1462 list by the assert function.
1463
Bram Moolenaar071d4272004-06-13 20:20:40 +00001464 *v:exception* *exception-variable*
1465v:exception The value of the exception most recently caught and not
1466 finished. See also |v:throwpoint| and |throw-variables|.
1467 Example: >
1468 :try
1469 : throw "oops"
1470 :catch /.*/
1471 : echo "caught" v:exception
1472 :endtry
1473< Output: "caught oops".
1474
Bram Moolenaar520e1e42016-01-23 19:46:28 +01001475 *v:false* *false-variable*
1476v:false A Number with value zero. Used to put "false" in JSON. See
Bram Moolenaar6463ca22016-02-13 17:04:46 +01001477 |json_encode()|.
Bram Moolenaarc95a3022016-06-12 23:01:46 +02001478 When used as a string this evaluates to "v:false". >
Bram Moolenaar705ada12016-01-24 17:56:50 +01001479 echo v:false
Bram Moolenaarc95a3022016-06-12 23:01:46 +02001480< v:false ~
1481 That is so that eval() can parse the string back to the same
1482 value.
Bram Moolenaar520e1e42016-01-23 19:46:28 +01001483
Bram Moolenaar19a09a12005-03-04 23:39:37 +00001484 *v:fcs_reason* *fcs_reason-variable*
1485v:fcs_reason The reason why the |FileChangedShell| event was triggered.
1486 Can be used in an autocommand to decide what to do and/or what
1487 to set v:fcs_choice to. Possible values:
1488 deleted file no longer exists
1489 conflict file contents, mode or timestamp was
1490 changed and buffer is modified
1491 changed file contents has changed
1492 mode mode of file changed
1493 time only file timestamp changed
1494
1495 *v:fcs_choice* *fcs_choice-variable*
1496v:fcs_choice What should happen after a |FileChangedShell| event was
1497 triggered. Can be used in an autocommand to tell Vim what to
1498 do with the affected buffer:
1499 reload Reload the buffer (does not work if
1500 the file was deleted).
1501 ask Ask the user what to do, as if there
1502 was no autocommand. Except that when
1503 only the timestamp changed nothing
1504 will happen.
1505 <empty> Nothing, the autocommand should do
1506 everything that needs to be done.
1507 The default is empty. If another (invalid) value is used then
1508 Vim behaves like it is empty, there is no warning message.
1509
Bram Moolenaar071d4272004-06-13 20:20:40 +00001510 *v:fname_in* *fname_in-variable*
Bram Moolenaar4e330bb2005-12-07 21:04:31 +00001511v:fname_in The name of the input file. Valid while evaluating:
Bram Moolenaar071d4272004-06-13 20:20:40 +00001512 option used for ~
1513 'charconvert' file to be converted
1514 'diffexpr' original file
1515 'patchexpr' original file
1516 'printexpr' file to be printed
Bram Moolenaar2c7a29c2005-12-12 22:02:31 +00001517 And set to the swap file name for |SwapExists|.
Bram Moolenaar071d4272004-06-13 20:20:40 +00001518
1519 *v:fname_out* *fname_out-variable*
1520v:fname_out The name of the output file. Only valid while
1521 evaluating:
1522 option used for ~
1523 'charconvert' resulting converted file (*)
1524 'diffexpr' output of diff
1525 'patchexpr' resulting patched file
1526 (*) When doing conversion for a write command (e.g., ":w
Bram Moolenaar446cb832008-06-24 21:56:24 +00001527 file") it will be equal to v:fname_in. When doing conversion
Bram Moolenaar071d4272004-06-13 20:20:40 +00001528 for a read command (e.g., ":e file") it will be a temporary
1529 file and different from v:fname_in.
1530
1531 *v:fname_new* *fname_new-variable*
1532v:fname_new The name of the new version of the file. Only valid while
1533 evaluating 'diffexpr'.
1534
1535 *v:fname_diff* *fname_diff-variable*
1536v:fname_diff The name of the diff (patch) file. Only valid while
1537 evaluating 'patchexpr'.
1538
1539 *v:folddashes* *folddashes-variable*
1540v:folddashes Used for 'foldtext': dashes representing foldlevel of a closed
1541 fold.
Bram Moolenaar7b0294c2004-10-11 10:16:09 +00001542 Read-only in the |sandbox|. |fold-foldtext|
Bram Moolenaar071d4272004-06-13 20:20:40 +00001543
1544 *v:foldlevel* *foldlevel-variable*
1545v:foldlevel Used for 'foldtext': foldlevel of closed fold.
Bram Moolenaar7b0294c2004-10-11 10:16:09 +00001546 Read-only in the |sandbox|. |fold-foldtext|
Bram Moolenaar071d4272004-06-13 20:20:40 +00001547
1548 *v:foldend* *foldend-variable*
1549v:foldend Used for 'foldtext': last line of closed fold.
Bram Moolenaar7b0294c2004-10-11 10:16:09 +00001550 Read-only in the |sandbox|. |fold-foldtext|
Bram Moolenaar071d4272004-06-13 20:20:40 +00001551
1552 *v:foldstart* *foldstart-variable*
1553v:foldstart Used for 'foldtext': first line of closed fold.
Bram Moolenaar7b0294c2004-10-11 10:16:09 +00001554 Read-only in the |sandbox|. |fold-foldtext|
Bram Moolenaar071d4272004-06-13 20:20:40 +00001555
Bram Moolenaar817a8802013-11-09 01:44:43 +01001556 *v:hlsearch* *hlsearch-variable*
Bram Moolenaar76440e22014-11-27 19:14:49 +01001557v:hlsearch Variable that indicates whether search highlighting is on.
1558 Setting it makes sense only if 'hlsearch' is enabled which
1559 requires |+extra_search|. Setting this variable to zero acts
Bram Moolenaar705ada12016-01-24 17:56:50 +01001560 like the |:nohlsearch| command, setting it to one acts like >
Bram Moolenaar817a8802013-11-09 01:44:43 +01001561 let &hlsearch = &hlsearch
Bram Moolenaar86ae7202015-07-10 19:31:35 +02001562< Note that the value is restored when returning from a
1563 function. |function-search-undo|.
1564
Bram Moolenaar843ee412004-06-30 16:16:41 +00001565 *v:insertmode* *insertmode-variable*
1566v:insertmode Used for the |InsertEnter| and |InsertChange| autocommand
1567 events. Values:
1568 i Insert mode
1569 r Replace mode
1570 v Virtual Replace mode
1571
Bram Moolenaar2fda12f2005-01-15 22:14:15 +00001572 *v:key* *key-variable*
Bram Moolenaar32466aa2006-02-24 23:53:04 +00001573v:key Key of the current item of a |Dictionary|. Only valid while
Bram Moolenaar2fda12f2005-01-15 22:14:15 +00001574 evaluating the expression used with |map()| and |filter()|.
1575 Read-only.
1576
Bram Moolenaar071d4272004-06-13 20:20:40 +00001577 *v:lang* *lang-variable*
1578v:lang The current locale setting for messages of the runtime
1579 environment. This allows Vim scripts to be aware of the
1580 current language. Technical: it's the value of LC_MESSAGES.
1581 The value is system dependent.
1582 This variable can not be set directly, use the |:language|
1583 command.
1584 It can be different from |v:ctype| when messages are desired
1585 in a different language than what is used for character
1586 encoding. See |multi-lang|.
1587
1588 *v:lc_time* *lc_time-variable*
1589v:lc_time The current locale setting for time messages of the runtime
1590 environment. This allows Vim scripts to be aware of the
1591 current language. Technical: it's the value of LC_TIME.
1592 This variable can not be set directly, use the |:language|
1593 command. See |multi-lang|.
1594
1595 *v:lnum* *lnum-variable*
Bram Moolenaar368373e2010-07-19 20:46:22 +02001596v:lnum Line number for the 'foldexpr' |fold-expr|, 'formatexpr' and
1597 'indentexpr' expressions, tab page number for 'guitablabel'
1598 and 'guitabtooltip'. Only valid while one of these
1599 expressions is being evaluated. Read-only when in the
1600 |sandbox|.
Bram Moolenaar071d4272004-06-13 20:20:40 +00001601
Bram Moolenaar219b8702006-11-01 14:32:36 +00001602 *v:mouse_win* *mouse_win-variable*
1603v:mouse_win Window number for a mouse click obtained with |getchar()|.
1604 First window has number 1, like with |winnr()|. The value is
1605 zero when there was no mouse button click.
1606
Bram Moolenaar511972d2016-06-04 18:09:59 +02001607 *v:mouse_winid* *mouse_winid-variable*
1608v:mouse_winid Window ID for a mouse click obtained with |getchar()|.
1609 The value is zero when there was no mouse button click.
1610
Bram Moolenaar219b8702006-11-01 14:32:36 +00001611 *v:mouse_lnum* *mouse_lnum-variable*
1612v:mouse_lnum Line number for a mouse click obtained with |getchar()|.
1613 This is the text line number, not the screen line number. The
1614 value is zero when there was no mouse button click.
1615
1616 *v:mouse_col* *mouse_col-variable*
1617v:mouse_col Column number for a mouse click obtained with |getchar()|.
1618 This is the screen column number, like with |virtcol()|. The
1619 value is zero when there was no mouse button click.
1620
Bram Moolenaar520e1e42016-01-23 19:46:28 +01001621 *v:none* *none-variable*
1622v:none An empty String. Used to put an empty item in JSON. See
Bram Moolenaar6463ca22016-02-13 17:04:46 +01001623 |json_encode()|.
Bram Moolenaar705ada12016-01-24 17:56:50 +01001624 When used as a number this evaluates to zero.
Bram Moolenaarc95a3022016-06-12 23:01:46 +02001625 When used as a string this evaluates to "v:none". >
Bram Moolenaar705ada12016-01-24 17:56:50 +01001626 echo v:none
Bram Moolenaarc95a3022016-06-12 23:01:46 +02001627< v:none ~
1628 That is so that eval() can parse the string back to the same
1629 value.
Bram Moolenaar520e1e42016-01-23 19:46:28 +01001630
1631 *v:null* *null-variable*
1632v:null An empty String. Used to put "null" in JSON. See
Bram Moolenaar6463ca22016-02-13 17:04:46 +01001633 |json_encode()|.
Bram Moolenaar705ada12016-01-24 17:56:50 +01001634 When used as a number this evaluates to zero.
Bram Moolenaarc95a3022016-06-12 23:01:46 +02001635 When used as a string this evaluates to "v:null". >
Bram Moolenaar705ada12016-01-24 17:56:50 +01001636 echo v:null
Bram Moolenaarc95a3022016-06-12 23:01:46 +02001637< v:null ~
1638 That is so that eval() can parse the string back to the same
1639 value.
Bram Moolenaar520e1e42016-01-23 19:46:28 +01001640
Bram Moolenaard812df62008-11-09 12:46:09 +00001641 *v:oldfiles* *oldfiles-variable*
1642v:oldfiles List of file names that is loaded from the |viminfo| file on
1643 startup. These are the files that Vim remembers marks for.
1644 The length of the List is limited by the ' argument of the
1645 'viminfo' option (default is 100).
Bram Moolenaar8d043172014-01-23 14:24:41 +01001646 When the |viminfo| file is not used the List is empty.
Bram Moolenaard812df62008-11-09 12:46:09 +00001647 Also see |:oldfiles| and |c_#<|.
1648 The List can be modified, but this has no effect on what is
1649 stored in the |viminfo| file later. If you use values other
1650 than String this will cause trouble.
Bram Moolenaardb84e452010-08-15 13:50:43 +02001651 {only when compiled with the |+viminfo| feature}
Bram Moolenaard812df62008-11-09 12:46:09 +00001652
Bram Moolenaar53744302015-07-17 17:38:22 +02001653 *v:option_new*
1654v:option_new New value of the option. Valid while executing an |OptionSet|
1655 autocommand.
1656 *v:option_old*
1657v:option_old Old value of the option. Valid while executing an |OptionSet|
1658 autocommand.
1659 *v:option_type*
1660v:option_type Scope of the set command. Valid while executing an
1661 |OptionSet| autocommand. Can be either "global" or "local"
Bram Moolenaar8af1fbf2008-01-05 12:35:21 +00001662 *v:operator* *operator-variable*
1663v:operator The last operator given in Normal mode. This is a single
1664 character except for commands starting with <g> or <z>,
1665 in which case it is two characters. Best used alongside
1666 |v:prevcount| and |v:register|. Useful if you want to cancel
1667 Operator-pending mode and then use the operator, e.g.: >
1668 :omap O <Esc>:call MyMotion(v:operator)<CR>
1669< The value remains set until another operator is entered, thus
1670 don't expect it to be empty.
1671 v:operator is not set for |:delete|, |:yank| or other Ex
1672 commands.
1673 Read-only.
1674
Bram Moolenaar071d4272004-06-13 20:20:40 +00001675 *v:prevcount* *prevcount-variable*
1676v:prevcount The count given for the last but one Normal mode command.
1677 This is the v:count value of the previous command. Useful if
Bram Moolenaar8af1fbf2008-01-05 12:35:21 +00001678 you want to cancel Visual or Operator-pending mode and then
1679 use the count, e.g.: >
Bram Moolenaar071d4272004-06-13 20:20:40 +00001680 :vmap % <Esc>:call MyFilter(v:prevcount)<CR>
1681< Read-only.
1682
Bram Moolenaar05159a02005-02-26 23:04:13 +00001683 *v:profiling* *profiling-variable*
Bram Moolenaar446cb832008-06-24 21:56:24 +00001684v:profiling Normally zero. Set to one after using ":profile start".
Bram Moolenaar05159a02005-02-26 23:04:13 +00001685 See |profiling|.
1686
Bram Moolenaar071d4272004-06-13 20:20:40 +00001687 *v:progname* *progname-variable*
1688v:progname Contains the name (with path removed) with which Vim was
Bram Moolenaard38b0552012-04-25 19:07:41 +02001689 invoked. Allows you to do special initialisations for |view|,
1690 |evim| etc., or any other name you might symlink to Vim.
Bram Moolenaar071d4272004-06-13 20:20:40 +00001691 Read-only.
1692
Bram Moolenaara1706c92014-04-01 19:55:49 +02001693 *v:progpath* *progpath-variable*
1694v:progpath Contains the command with which Vim was invoked, including the
1695 path. Useful if you want to message a Vim server using a
1696 |--remote-expr|.
Bram Moolenaarc7f02552014-04-01 21:00:59 +02001697 To get the full path use: >
1698 echo exepath(v:progpath)
1699< NOTE: This does not work when the command is a relative path
1700 and the current directory has changed.
Bram Moolenaara1706c92014-04-01 19:55:49 +02001701 Read-only.
1702
Bram Moolenaar071d4272004-06-13 20:20:40 +00001703 *v:register* *register-variable*
Bram Moolenaard58e9292011-02-09 17:07:58 +01001704v:register The name of the register in effect for the current normal mode
Bram Moolenaard38b0552012-04-25 19:07:41 +02001705 command (regardless of whether that command actually used a
1706 register). Or for the currently executing normal mode mapping
1707 (use this in custom commands that take a register).
1708 If none is supplied it is the default register '"', unless
1709 'clipboard' contains "unnamed" or "unnamedplus", then it is
1710 '*' or '+'.
Bram Moolenaard58e9292011-02-09 17:07:58 +01001711 Also see |getreg()| and |setreg()|
Bram Moolenaar071d4272004-06-13 20:20:40 +00001712
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00001713 *v:scrollstart* *scrollstart-variable*
1714v:scrollstart String describing the script or function that caused the
1715 screen to scroll up. It's only set when it is empty, thus the
1716 first reason is remembered. It is set to "Unknown" for a
1717 typed command.
1718 This can be used to find out why your script causes the
1719 hit-enter prompt.
1720
Bram Moolenaar071d4272004-06-13 20:20:40 +00001721 *v:servername* *servername-variable*
1722v:servername The resulting registered |x11-clientserver| name if any.
1723 Read-only.
1724
Bram Moolenaar446cb832008-06-24 21:56:24 +00001725
1726v:searchforward *v:searchforward* *searchforward-variable*
1727 Search direction: 1 after a forward search, 0 after a
1728 backward search. It is reset to forward when directly setting
1729 the last search pattern, see |quote/|.
1730 Note that the value is restored when returning from a
1731 function. |function-search-undo|.
1732 Read-write.
1733
Bram Moolenaar071d4272004-06-13 20:20:40 +00001734 *v:shell_error* *shell_error-variable*
1735v:shell_error Result of the last shell command. When non-zero, the last
1736 shell command had an error. When zero, there was no problem.
1737 This only works when the shell returns the error code to Vim.
1738 The value -1 is often used when the command could not be
1739 executed. Read-only.
1740 Example: >
1741 :!mv foo bar
1742 :if v:shell_error
1743 : echo 'could not rename "foo" to "bar"!'
1744 :endif
1745< "shell_error" also works, for backwards compatibility.
1746
1747 *v:statusmsg* *statusmsg-variable*
1748v:statusmsg Last given status message. It's allowed to set this variable.
1749
Bram Moolenaar4e330bb2005-12-07 21:04:31 +00001750 *v:swapname* *swapname-variable*
1751v:swapname Only valid when executing |SwapExists| autocommands: Name of
1752 the swap file found. Read-only.
1753
1754 *v:swapchoice* *swapchoice-variable*
1755v:swapchoice |SwapExists| autocommands can set this to the selected choice
1756 for handling an existing swap file:
1757 'o' Open read-only
1758 'e' Edit anyway
1759 'r' Recover
1760 'd' Delete swapfile
1761 'q' Quit
1762 'a' Abort
Bram Moolenaar446cb832008-06-24 21:56:24 +00001763 The value should be a single-character string. An empty value
Bram Moolenaar4e330bb2005-12-07 21:04:31 +00001764 results in the user being asked, as would happen when there is
1765 no SwapExists autocommand. The default is empty.
1766
Bram Moolenaarb3480382005-12-11 21:33:32 +00001767 *v:swapcommand* *swapcommand-variable*
Bram Moolenaar4770d092006-01-12 23:22:24 +00001768v:swapcommand Normal mode command to be executed after a file has been
Bram Moolenaarb3480382005-12-11 21:33:32 +00001769 opened. Can be used for a |SwapExists| autocommand to have
Bram Moolenaar446cb832008-06-24 21:56:24 +00001770 another Vim open the file and jump to the right place. For
Bram Moolenaarb3480382005-12-11 21:33:32 +00001771 example, when jumping to a tag the value is ":tag tagname\r".
Bram Moolenaar1f35bf92006-03-07 22:38:47 +00001772 For ":edit +cmd file" the value is ":cmd\r".
Bram Moolenaarb3480382005-12-11 21:33:32 +00001773
Bram Moolenaar071d4272004-06-13 20:20:40 +00001774 *v:termresponse* *termresponse-variable*
1775v:termresponse The escape sequence returned by the terminal for the |t_RV|
Bram Moolenaar446cb832008-06-24 21:56:24 +00001776 termcap entry. It is set when Vim receives an escape sequence
Bram Moolenaar071d4272004-06-13 20:20:40 +00001777 that starts with ESC [ or CSI and ends in a 'c', with only
1778 digits, ';' and '.' in between.
1779 When this option is set, the TermResponse autocommand event is
1780 fired, so that you can react to the response from the
1781 terminal.
1782 The response from a new xterm is: "<Esc>[ Pp ; Pv ; Pc c". Pp
1783 is the terminal type: 0 for vt100 and 1 for vt220. Pv is the
1784 patch level (since this was introduced in patch 95, it's
1785 always 95 or bigger). Pc is always zero.
1786 {only when compiled with |+termresponse| feature}
1787
Bram Moolenaarebf7dfa2016-04-14 12:46:51 +02001788 *v:testing* *testing-variable*
Bram Moolenaar8e8df252016-05-25 21:23:21 +02001789v:testing Must be set before using `test_garbagecollect_now()`.
Bram Moolenaarebf7dfa2016-04-14 12:46:51 +02001790
Bram Moolenaar071d4272004-06-13 20:20:40 +00001791 *v:this_session* *this_session-variable*
1792v:this_session Full filename of the last loaded or saved session file. See
1793 |:mksession|. It is allowed to set this variable. When no
1794 session file has been saved, this variable is empty.
1795 "this_session" also works, for backwards compatibility.
1796
1797 *v:throwpoint* *throwpoint-variable*
1798v:throwpoint The point where the exception most recently caught and not
Bram Moolenaar446cb832008-06-24 21:56:24 +00001799 finished was thrown. Not set when commands are typed. See
Bram Moolenaar071d4272004-06-13 20:20:40 +00001800 also |v:exception| and |throw-variables|.
1801 Example: >
1802 :try
1803 : throw "oops"
1804 :catch /.*/
1805 : echo "Exception from" v:throwpoint
1806 :endtry
1807< Output: "Exception from test.vim, line 2"
1808
Bram Moolenaar520e1e42016-01-23 19:46:28 +01001809 *v:true* *true-variable*
1810v:true A Number with value one. Used to put "true" in JSON. See
Bram Moolenaar6463ca22016-02-13 17:04:46 +01001811 |json_encode()|.
Bram Moolenaarc95a3022016-06-12 23:01:46 +02001812 When used as a string this evaluates to "v:true". >
Bram Moolenaar705ada12016-01-24 17:56:50 +01001813 echo v:true
Bram Moolenaarc95a3022016-06-12 23:01:46 +02001814< v:true ~
1815 That is so that eval() can parse the string back to the same
1816 value.
Bram Moolenaar2fda12f2005-01-15 22:14:15 +00001817 *v:val* *val-variable*
Bram Moolenaar446cb832008-06-24 21:56:24 +00001818v:val Value of the current item of a |List| or |Dictionary|. Only
Bram Moolenaar32466aa2006-02-24 23:53:04 +00001819 valid while evaluating the expression used with |map()| and
Bram Moolenaar2fda12f2005-01-15 22:14:15 +00001820 |filter()|. Read-only.
1821
Bram Moolenaar071d4272004-06-13 20:20:40 +00001822 *v:version* *version-variable*
1823v:version Version number of Vim: Major version number times 100 plus
1824 minor version number. Version 5.0 is 500. Version 5.1 (5.01)
1825 is 501. Read-only. "version" also works, for backwards
1826 compatibility.
1827 Use |has()| to check if a certain patch was included, e.g.: >
Bram Moolenaar6716d9a2014-04-02 12:12:08 +02001828 if has("patch-7.4.123")
Bram Moolenaar071d4272004-06-13 20:20:40 +00001829< Note that patch numbers are specific to the version, thus both
1830 version 5.0 and 5.1 may have a patch 123, but these are
1831 completely different.
1832
Bram Moolenaar14735512016-03-26 21:00:08 +01001833 *v:vim_did_enter* *vim_did_enter-variable*
1834v:vim_did_enter Zero until most of startup is done. It is set to one just
1835 before |VimEnter| autocommands are triggered.
1836
Bram Moolenaar071d4272004-06-13 20:20:40 +00001837 *v:warningmsg* *warningmsg-variable*
1838v:warningmsg Last given warning message. It's allowed to set this variable.
1839
Bram Moolenaar727c8762010-10-20 19:17:48 +02001840 *v:windowid* *windowid-variable*
1841v:windowid When any X11 based GUI is running or when running in a
1842 terminal and Vim connects to the X server (|-X|) this will be
Bram Moolenaar264e9fd2010-10-27 12:33:17 +02001843 set to the window ID.
1844 When an MS-Windows GUI is running this will be set to the
1845 window handle.
1846 Otherwise the value is zero.
Bram Moolenaar511972d2016-06-04 18:09:59 +02001847 Note: for windows inside Vim use |winnr()| or |win_getid()|.
Bram Moolenaar727c8762010-10-20 19:17:48 +02001848
Bram Moolenaar071d4272004-06-13 20:20:40 +00001849==============================================================================
18504. Builtin Functions *functions*
1851
1852See |function-list| for a list grouped by what the function is used for.
1853
Bram Moolenaar402d2fe2005-04-15 21:00:38 +00001854(Use CTRL-] on the function name to jump to the full explanation.)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001855
1856USAGE RESULT DESCRIPTION ~
1857
Bram Moolenaar81edd172016-04-14 13:51:37 +02001858abs({expr}) Float or Number absolute value of {expr}
1859acos({expr}) Float arc cosine of {expr}
1860add({list}, {item}) List append {item} to |List| {list}
Bram Moolenaar81edd172016-04-14 13:51:37 +02001861and({expr}, {expr}) Number bitwise AND
1862append({lnum}, {string}) Number append {string} below line {lnum}
1863append({lnum}, {list}) Number append lines {list} below line {lnum}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001864argc() Number number of files in the argument list
Bram Moolenaard7ee7ce2005-01-03 21:02:03 +00001865argidx() Number current index in the argument list
Bram Moolenaar81edd172016-04-14 13:51:37 +02001866arglistid([{winnr} [, {tabnr}]]) Number argument list id
1867argv({nr}) String {nr} entry of the argument list
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001868argv() List the argument list
Bram Moolenaar81edd172016-04-14 13:51:37 +02001869assert_equal({exp}, {act} [, {msg}]) none assert {exp} is equal to {act}
1870assert_exception({error} [, {msg}]) none assert {error} is in v:exception
1871assert_fails({cmd} [, {error}]) none assert {cmd} fails
1872assert_false({actual} [, {msg}]) none assert {actual} is false
1873assert_match({pat}, {text} [, {msg}]) none assert {pat} matches {text}
1874assert_notequal({exp}, {act} [, {msg}]) none assert {exp} is not equal {act}
1875assert_notmatch({pat}, {text} [, {msg}]) none assert {pat} not matches {text}
1876assert_true({actual} [, {msg}]) none assert {actual} is true
1877asin({expr}) Float arc sine of {expr}
1878atan({expr}) Float arc tangent of {expr}
1879atan2({expr}, {expr}) Float arc tangent of {expr1} / {expr2}
1880browse({save}, {title}, {initdir}, {default})
Bram Moolenaar071d4272004-06-13 20:20:40 +00001881 String put up a file requester
Bram Moolenaar81edd172016-04-14 13:51:37 +02001882browsedir({title}, {initdir}) String put up a directory requester
1883bufexists({expr}) Number TRUE if buffer {expr} exists
1884buflisted({expr}) Number TRUE if buffer {expr} is listed
1885bufloaded({expr}) Number TRUE if buffer {expr} is loaded
1886bufname({expr}) String Name of the buffer {expr}
1887bufnr({expr} [, {create}]) Number Number of the buffer {expr}
Bram Moolenaarb3619a92016-06-04 17:58:52 +02001888bufwinid({expr}) Number window ID of buffer {expr}
Bram Moolenaar81edd172016-04-14 13:51:37 +02001889bufwinnr({expr}) Number window number of buffer {expr}
1890byte2line({byte}) Number line number at byte count {byte}
1891byteidx({expr}, {nr}) Number byte index of {nr}'th char in {expr}
1892byteidxcomp({expr}, {nr}) Number byte index of {nr}'th char in {expr}
1893call({func}, {arglist} [, {dict}])
Bram Moolenaar2fda12f2005-01-15 22:14:15 +00001894 any call {func} with arguments {arglist}
Bram Moolenaar81edd172016-04-14 13:51:37 +02001895ceil({expr}) Float round {expr} up
1896ch_close({handle}) none close {handle}
1897ch_evalexpr({handle}, {expr} [, {options}])
Bram Moolenaar5f148ec2016-03-07 22:59:26 +01001898 any evaluate {expr} on JSON {handle}
Bram Moolenaar81edd172016-04-14 13:51:37 +02001899ch_evalraw({handle}, {string} [, {options}])
Bram Moolenaar5f148ec2016-03-07 22:59:26 +01001900 any evaluate {string} on raw {handle}
Bram Moolenaar81edd172016-04-14 13:51:37 +02001901ch_getbufnr({handle}, {what}) Number get buffer number for {handle}/{what}
1902ch_getjob({channel}) Job get the Job of {channel}
1903ch_info({handle}) String info about channel {handle}
1904ch_log({msg} [, {handle}]) none write {msg} in the channel log file
1905ch_logfile({fname} [, {mode}]) none start logging channel activity
1906ch_open({address} [, {options}])
1907 Channel open a channel to {address}
1908ch_read({handle} [, {options}]) String read from {handle}
1909ch_readraw({handle} [, {options}])
1910 String read raw from {handle}
1911ch_sendexpr({handle}, {expr} [, {options}])
Bram Moolenaar5f148ec2016-03-07 22:59:26 +01001912 any send {expr} over JSON {handle}
Bram Moolenaar81edd172016-04-14 13:51:37 +02001913ch_sendraw({handle}, {string} [, {options}])
Bram Moolenaar5f148ec2016-03-07 22:59:26 +01001914 any send {string} over raw {handle}
Bram Moolenaar81edd172016-04-14 13:51:37 +02001915ch_setoptions({handle}, {options})
1916 none set options for {handle}
1917ch_status({handle}) String status of channel {handle}
Bram Moolenaar446cb832008-06-24 21:56:24 +00001918changenr() Number current change number
Bram Moolenaar81edd172016-04-14 13:51:37 +02001919char2nr({expr}[, {utf8}]) Number ASCII/UTF8 value of first char in {expr}
1920cindent({lnum}) Number C indent for line {lnum}
Bram Moolenaar8f3f58f2010-01-06 20:52:26 +01001921clearmatches() none clear all matches
Bram Moolenaar81edd172016-04-14 13:51:37 +02001922col({expr}) Number column nr of cursor or mark
1923complete({startcol}, {matches}) none set Insert mode completion
1924complete_add({expr}) Number add completion match
Bram Moolenaar446cb832008-06-24 21:56:24 +00001925complete_check() Number check for key typed during completion
Bram Moolenaar81edd172016-04-14 13:51:37 +02001926confirm({msg} [, {choices} [, {default} [, {type}]]])
Bram Moolenaar071d4272004-06-13 20:20:40 +00001927 Number number of choice picked by user
Bram Moolenaar81edd172016-04-14 13:51:37 +02001928copy({expr}) any make a shallow copy of {expr}
1929cos({expr}) Float cosine of {expr}
1930cosh({expr}) Float hyperbolic cosine of {expr}
1931count({list}, {expr} [, {ic} [, {start}]])
Bram Moolenaar5f2bb9f2005-01-11 21:29:04 +00001932 Number count how many {expr} are in {list}
Bram Moolenaar81edd172016-04-14 13:51:37 +02001933cscope_connection([{num} , {dbpath} [, {prepend}]])
Bram Moolenaar071d4272004-06-13 20:20:40 +00001934 Number checks existence of cscope connection
Bram Moolenaar81edd172016-04-14 13:51:37 +02001935cursor({lnum}, {col} [, {off}])
Bram Moolenaar2f3b5102014-11-19 18:54:17 +01001936 Number move cursor to {lnum}, {col}, {off}
Bram Moolenaar81edd172016-04-14 13:51:37 +02001937cursor({list}) Number move cursor to position in {list}
1938deepcopy({expr} [, {noref}]) any make a full copy of {expr}
1939delete({fname} [, {flags}]) Number delete the file or directory {fname}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001940did_filetype() Number TRUE if FileType autocommand event used
Bram Moolenaar81edd172016-04-14 13:51:37 +02001941diff_filler({lnum}) Number diff filler lines about {lnum}
1942diff_hlID({lnum}, {col}) Number diff highlighting at {lnum}/{col}
Bram Moolenaar81edd172016-04-14 13:51:37 +02001943empty({expr}) Number TRUE if {expr} is empty
1944escape({string}, {chars}) String escape {chars} in {string} with '\'
1945eval({string}) any evaluate {string} into its value
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001946eventhandler() Number TRUE if inside an event handler
Bram Moolenaar81edd172016-04-14 13:51:37 +02001947executable({expr}) Number 1 if executable {expr} exists
1948exepath({expr}) String full path of the command {expr}
1949exists({expr}) Number TRUE if {expr} exists
1950extend({expr1}, {expr2} [, {expr3}])
Bram Moolenaarc6fe9192006-04-09 21:54:49 +00001951 List/Dict insert items of {expr2} into {expr1}
Bram Moolenaar81edd172016-04-14 13:51:37 +02001952exp({expr}) Float exponential of {expr}
1953expand({expr} [, {nosuf} [, {list}]])
Bram Moolenaar146e9c32012-03-07 19:18:23 +01001954 any expand special keywords in {expr}
Bram Moolenaar81edd172016-04-14 13:51:37 +02001955feedkeys({string} [, {mode}]) Number add key sequence to typeahead buffer
1956filereadable({file}) Number TRUE if {file} is a readable file
1957filewritable({file}) Number TRUE if {file} is a writable file
1958filter({expr}, {string}) List/Dict remove items from {expr} where
Bram Moolenaar2fda12f2005-01-15 22:14:15 +00001959 {string} is 0
Bram Moolenaar81edd172016-04-14 13:51:37 +02001960finddir({name}[, {path}[, {count}]])
Bram Moolenaarc6fe9192006-04-09 21:54:49 +00001961 String find directory {name} in {path}
Bram Moolenaar81edd172016-04-14 13:51:37 +02001962findfile({name}[, {path}[, {count}]])
Bram Moolenaarc6fe9192006-04-09 21:54:49 +00001963 String find file {name} in {path}
Bram Moolenaar81edd172016-04-14 13:51:37 +02001964float2nr({expr}) Number convert Float {expr} to a Number
1965floor({expr}) Float round {expr} down
1966fmod({expr1}, {expr2}) Float remainder of {expr1} / {expr2}
1967fnameescape({fname}) String escape special characters in {fname}
1968fnamemodify({fname}, {mods}) String modify file name
1969foldclosed({lnum}) Number first line of fold at {lnum} if closed
1970foldclosedend({lnum}) Number last line of fold at {lnum} if closed
1971foldlevel({lnum}) Number fold level at {lnum}
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001972foldtext() String line displayed for closed fold
Bram Moolenaar81edd172016-04-14 13:51:37 +02001973foldtextresult({lnum}) String text for closed fold at {lnum}
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001974foreground() Number bring the Vim window to the foreground
Bram Moolenaar81edd172016-04-14 13:51:37 +02001975function({name} [, {arglist}] [, {dict}])
Bram Moolenaar1735bc92016-03-14 23:05:14 +01001976 Funcref reference to function {name}
Bram Moolenaar81edd172016-04-14 13:51:37 +02001977garbagecollect([{atexit}]) none free memory, breaking cyclic references
Bram Moolenaar81edd172016-04-14 13:51:37 +02001978get({list}, {idx} [, {def}]) any get item {idx} from {list} or {def}
1979get({dict}, {key} [, {def}]) any get item {key} from {dict} or {def}
Bram Moolenaar03e19a02016-05-24 22:29:49 +02001980get({func}, {what}) any get property of funcref/partial {func}
Bram Moolenaar81edd172016-04-14 13:51:37 +02001981getbufline({expr}, {lnum} [, {end}])
Bram Moolenaar45360022005-07-21 21:08:21 +00001982 List lines {lnum} to {end} of buffer {expr}
Bram Moolenaar81edd172016-04-14 13:51:37 +02001983getbufvar({expr}, {varname} [, {def}])
Bram Moolenaar63dbda12013-02-20 21:12:10 +01001984 any variable {varname} in buffer {expr}
Bram Moolenaar81edd172016-04-14 13:51:37 +02001985getchar([expr]) Number get one character from the user
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001986getcharmod() Number modifiers for the last typed character
Bram Moolenaarfc39ecf2015-08-11 20:34:49 +02001987getcharsearch() Dict last character search
Bram Moolenaar071d4272004-06-13 20:20:40 +00001988getcmdline() String return the current command-line
1989getcmdpos() Number return cursor position in command-line
Bram Moolenaarfb539272014-08-22 19:21:47 +02001990getcmdtype() String return current command-line type
1991getcmdwintype() String return current command-line window type
Bram Moolenaar6f6c0f82014-05-28 20:31:42 +02001992getcurpos() List position of the cursor
Bram Moolenaar81edd172016-04-14 13:51:37 +02001993getcwd([{winnr} [, {tabnr}]]) String get the current working directory
1994getfontname([{name}]) String name of font being used
1995getfperm({fname}) String file permissions of file {fname}
1996getfsize({fname}) Number size in bytes of file {fname}
1997getftime({fname}) Number last modification time of file
1998getftype({fname}) String description of type of file {fname}
1999getline({lnum}) String line {lnum} of current buffer
2000getline({lnum}, {end}) List lines {lnum} to {end} of current buffer
2001getloclist({nr}) List list of location list items
Bram Moolenaar6ee10162007-07-26 20:58:42 +00002002getmatches() List list of current matches
Bram Moolenaar18081e32008-02-20 19:11:07 +00002003getpid() Number process ID of Vim
Bram Moolenaar81edd172016-04-14 13:51:37 +02002004getpos({expr}) List position of cursor, mark, etc.
Bram Moolenaar68b76a62005-03-25 21:53:48 +00002005getqflist() List list of quickfix items
Bram Moolenaar81edd172016-04-14 13:51:37 +02002006getreg([{regname} [, 1 [, {list}]]])
Bram Moolenaarb7cb42b2014-04-02 19:55:10 +02002007 String or List contents of register
Bram Moolenaar81edd172016-04-14 13:51:37 +02002008getregtype([{regname}]) String type of register
2009gettabvar({nr}, {varname} [, {def}])
Bram Moolenaar63dbda12013-02-20 21:12:10 +01002010 any variable {varname} in tab {nr} or {def}
Bram Moolenaar81edd172016-04-14 13:51:37 +02002011gettabwinvar({tabnr}, {winnr}, {name} [, {def}])
Bram Moolenaarc6249bb2006-04-15 20:25:09 +00002012 any {name} in {winnr} in tab page {tabnr}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002013getwinposx() Number X coord in pixels of GUI Vim window
2014getwinposy() Number Y coord in pixels of GUI Vim window
Bram Moolenaar81edd172016-04-14 13:51:37 +02002015getwinvar({nr}, {varname} [, {def}])
Bram Moolenaar63dbda12013-02-20 21:12:10 +01002016 any variable {varname} in window {nr}
Bram Moolenaar81edd172016-04-14 13:51:37 +02002017glob({expr} [, {nosuf} [, {list} [, {alllinks}]]])
Bram Moolenaar146e9c32012-03-07 19:18:23 +01002018 any expand file wildcards in {expr}
Bram Moolenaar81edd172016-04-14 13:51:37 +02002019glob2regpat({expr}) String convert a glob pat into a search pat
2020globpath({path}, {expr} [, {nosuf} [, {list} [, {alllinks}]]])
Bram Moolenaarbb5ddda2008-11-28 10:01:10 +00002021 String do glob({expr}) for all dirs in {path}
Bram Moolenaar81edd172016-04-14 13:51:37 +02002022has({feature}) Number TRUE if feature {feature} supported
2023has_key({dict}, {key}) Number TRUE if {dict} has entry {key}
2024haslocaldir([{winnr} [, {tabnr}]])
Bram Moolenaarc9703302016-01-17 21:49:33 +01002025 Number TRUE if the window executed |:lcd|
Bram Moolenaar81edd172016-04-14 13:51:37 +02002026hasmapto({what} [, {mode} [, {abbr}]])
Bram Moolenaar97b2ad32006-03-18 21:40:56 +00002027 Number TRUE if mapping to {what} exists
Bram Moolenaar81edd172016-04-14 13:51:37 +02002028histadd({history}, {item}) String add an item to a history
2029histdel({history} [, {item}]) String remove an item from a history
2030histget({history} [, {index}]) String get the item {index} from a history
2031histnr({history}) Number highest index of a history
2032hlexists({name}) Number TRUE if highlight group {name} exists
2033hlID({name}) Number syntax ID of highlight group {name}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002034hostname() String name of the machine Vim is running on
Bram Moolenaar81edd172016-04-14 13:51:37 +02002035iconv({expr}, {from}, {to}) String convert encoding of {expr}
2036indent({lnum}) Number indent of line {lnum}
2037index({list}, {expr} [, {start} [, {ic}]])
Bram Moolenaar5f2bb9f2005-01-11 21:29:04 +00002038 Number index in {list} where {expr} appears
Bram Moolenaar81edd172016-04-14 13:51:37 +02002039input({prompt} [, {text} [, {completion}]])
Bram Moolenaarbfd8fc02005-09-20 23:22:24 +00002040 String get input from the user
Bram Moolenaar81edd172016-04-14 13:51:37 +02002041inputdialog({prompt} [, {text} [, {completion}]]])
2042 String like input() but in a GUI dialog
2043inputlist({textlist}) Number let the user pick from a choice list
Bram Moolenaard7ee7ce2005-01-03 21:02:03 +00002044inputrestore() Number restore typeahead
2045inputsave() Number save and clear typeahead
Bram Moolenaar81edd172016-04-14 13:51:37 +02002046inputsecret({prompt} [, {text}]) String like input() but hiding the text
2047insert({list}, {item} [, {idx}]) List insert {item} in {list} [before {idx}]
2048invert({expr}) Number bitwise invert
2049isdirectory({directory}) Number TRUE if {directory} is a directory
2050islocked({expr}) Number TRUE if {expr} is locked
2051isnan({expr}) Number TRUE if {expr} is NaN
2052items({dict}) List key-value pairs in {dict}
2053job_getchannel({job}) Channel get the channel handle for {job}
2054job_info({job}) Dict get information about {job}
2055job_setoptions({job}, {options}) none set options for {job}
2056job_start({command} [, {options}])
2057 Job start a job
2058job_status({job}) String get the status of {job}
2059job_stop({job} [, {how}]) Number stop {job}
2060join({list} [, {sep}]) String join {list} items into one String
2061js_decode({string}) any decode JS style JSON
2062js_encode({expr}) String encode JS style JSON
2063json_decode({string}) any decode JSON
2064json_encode({expr}) String encode JSON
2065keys({dict}) List keys in {dict}
2066len({expr}) Number the length of {expr}
2067libcall({lib}, {func}, {arg}) String call {func} in library {lib} with {arg}
Bram Moolenaar802a0d92016-06-26 16:17:58 +02002068libcallnr({lib}, {func}, {arg}) Number idem, but return a Number
Bram Moolenaar81edd172016-04-14 13:51:37 +02002069line({expr}) Number line nr of cursor, last line or mark
2070line2byte({lnum}) Number byte count of line {lnum}
2071lispindent({lnum}) Number Lisp indent for line {lnum}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002072localtime() Number current time
Bram Moolenaar81edd172016-04-14 13:51:37 +02002073log({expr}) Float natural logarithm (base e) of {expr}
2074log10({expr}) Float logarithm of Float {expr} to base 10
2075luaeval({expr}[, {expr}]) any evaluate |Lua| expression
2076map({expr}, {string}) List/Dict change each item in {expr} to {expr}
2077maparg({name}[, {mode} [, {abbr} [, {dict}]]])
Bram Moolenaarf1568ec2011-12-14 21:17:39 +01002078 String or Dict
2079 rhs of mapping {name} in mode {mode}
Bram Moolenaar81edd172016-04-14 13:51:37 +02002080mapcheck({name}[, {mode} [, {abbr}]])
Bram Moolenaar97b2ad32006-03-18 21:40:56 +00002081 String check for mappings matching {name}
Bram Moolenaar81edd172016-04-14 13:51:37 +02002082match({expr}, {pat}[, {start}[, {count}]])
Bram Moolenaar071d4272004-06-13 20:20:40 +00002083 Number position where {pat} matches in {expr}
Bram Moolenaar81edd172016-04-14 13:51:37 +02002084matchadd({group}, {pattern}[, {priority}[, {id} [, {dict}]]])
Bram Moolenaar6ee10162007-07-26 20:58:42 +00002085 Number highlight {pattern} with {group}
Bram Moolenaar81edd172016-04-14 13:51:37 +02002086matchaddpos({group}, {pos}[, {priority}[, {id}[, {dict}]]])
Bram Moolenaarb3414592014-06-17 17:48:32 +02002087 Number highlight positions with {group}
Bram Moolenaar81edd172016-04-14 13:51:37 +02002088matcharg({nr}) List arguments of |:match|
2089matchdelete({id}) Number delete match identified by {id}
2090matchend({expr}, {pat}[, {start}[, {count}]])
Bram Moolenaar071d4272004-06-13 20:20:40 +00002091 Number position where {pat} ends in {expr}
Bram Moolenaar81edd172016-04-14 13:51:37 +02002092matchlist({expr}, {pat}[, {start}[, {count}]])
Bram Moolenaar3a7c85b2005-02-05 21:39:53 +00002093 List match and submatches of {pat} in {expr}
Bram Moolenaar81edd172016-04-14 13:51:37 +02002094matchstr({expr}, {pat}[, {start}[, {count}]])
Bram Moolenaar89cb5e02004-07-19 20:55:54 +00002095 String {count}'th match of {pat} in {expr}
Bram Moolenaar81edd172016-04-14 13:51:37 +02002096matchstrpos({expr}, {pat}[, {start}[, {count}]])
Bram Moolenaar7fed5c12016-03-29 23:10:31 +02002097 List {count}'th match of {pat} in {expr}
Bram Moolenaar81edd172016-04-14 13:51:37 +02002098max({list}) Number maximum value of items in {list}
2099min({list}) Number minimum value of items in {list}
2100mkdir({name} [, {path} [, {prot}]])
Bram Moolenaar26a60b42005-02-22 08:49:11 +00002101 Number create directory {name}
Bram Moolenaar81edd172016-04-14 13:51:37 +02002102mode([expr]) String current editing mode
2103mzeval({expr}) any evaluate |MzScheme| expression
2104nextnonblank({lnum}) Number line nr of non-blank line >= {lnum}
2105nr2char({expr}[, {utf8}]) String single char with ASCII/UTF8 value {expr}
2106or({expr}, {expr}) Number bitwise OR
2107pathshorten({expr}) String shorten directory names in a path
2108perleval({expr}) any evaluate |Perl| expression
2109pow({x}, {y}) Float {x} to the power of {y}
2110prevnonblank({lnum}) Number line nr of non-blank line <= {lnum}
2111printf({fmt}, {expr1}...) String format text
Bram Moolenaar446cb832008-06-24 21:56:24 +00002112pumvisible() Number whether popup menu is visible
Bram Moolenaar81edd172016-04-14 13:51:37 +02002113pyeval({expr}) any evaluate |Python| expression
2114py3eval({expr}) any evaluate |python3| expression
2115range({expr} [, {max} [, {stride}]])
Bram Moolenaard8b02732005-01-14 21:48:43 +00002116 List items from {expr} to {max}
Bram Moolenaar81edd172016-04-14 13:51:37 +02002117readfile({fname} [, {binary} [, {max}]])
Bram Moolenaar26a60b42005-02-22 08:49:11 +00002118 List get list of lines from file {fname}
Bram Moolenaar81edd172016-04-14 13:51:37 +02002119reltime([{start} [, {end}]]) List get time value
2120reltimefloat({time}) Float turn the time value into a Float
2121reltimestr({time}) String turn time value into a String
2122remote_expr({server}, {string} [, {idvar}])
Bram Moolenaar071d4272004-06-13 20:20:40 +00002123 String send expression
Bram Moolenaar81edd172016-04-14 13:51:37 +02002124remote_foreground({server}) Number bring Vim server to the foreground
2125remote_peek({serverid} [, {retvar}])
Bram Moolenaar071d4272004-06-13 20:20:40 +00002126 Number check for reply string
Bram Moolenaar81edd172016-04-14 13:51:37 +02002127remote_read({serverid}) String read reply string
2128remote_send({server}, {string} [, {idvar}])
Bram Moolenaar071d4272004-06-13 20:20:40 +00002129 String send key sequence
Bram Moolenaar802a0d92016-06-26 16:17:58 +02002130remove({list}, {idx} [, {end}]) any remove items {idx}-{end} from {list}
Bram Moolenaar81edd172016-04-14 13:51:37 +02002131remove({dict}, {key}) any remove entry {key} from {dict}
2132rename({from}, {to}) Number rename (move) file from {from} to {to}
2133repeat({expr}, {count}) String repeat {expr} {count} times
2134resolve({filename}) String get filename a shortcut points to
2135reverse({list}) List reverse {list} in-place
2136round({expr}) Float round off {expr}
2137screenattr({row}, {col}) Number attribute at screen position
2138screenchar({row}, {col}) Number character at screen position
Bram Moolenaar9750bb12012-12-05 16:10:42 +01002139screencol() Number current cursor column
2140screenrow() Number current cursor row
Bram Moolenaar81edd172016-04-14 13:51:37 +02002141search({pattern} [, {flags} [, {stopline} [, {timeout}]]])
Bram Moolenaar76929292008-01-06 19:07:36 +00002142 Number search for {pattern}
Bram Moolenaar81edd172016-04-14 13:51:37 +02002143searchdecl({name} [, {global} [, {thisblock}]])
Bram Moolenaar446cb832008-06-24 21:56:24 +00002144 Number search for variable declaration
Bram Moolenaar81edd172016-04-14 13:51:37 +02002145searchpair({start}, {middle}, {end} [, {flags} [, {skip} [...]]])
Bram Moolenaard7ee7ce2005-01-03 21:02:03 +00002146 Number search for other end of start/end pair
Bram Moolenaar81edd172016-04-14 13:51:37 +02002147searchpairpos({start}, {middle}, {end} [, {flags} [, {skip} [...]]])
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00002148 List search for other end of start/end pair
Bram Moolenaar81edd172016-04-14 13:51:37 +02002149searchpos({pattern} [, {flags} [, {stopline} [, {timeout}]]])
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00002150 List search for {pattern}
Bram Moolenaar81edd172016-04-14 13:51:37 +02002151server2client({clientid}, {string})
Bram Moolenaar071d4272004-06-13 20:20:40 +00002152 Number send reply string
2153serverlist() String get a list of available servers
Bram Moolenaar81edd172016-04-14 13:51:37 +02002154setbufvar({expr}, {varname}, {val})
2155 none set {varname} in buffer {expr} to {val}
2156setcharsearch({dict}) Dict set character search from {dict}
2157setcmdpos({pos}) Number set cursor position in command-line
2158setfperm({fname}, {mode}) Number set {fname} file permissions to {mode}
2159setline({lnum}, {line}) Number set line {lnum} to {line}
2160setloclist({nr}, {list}[, {action}])
Bram Moolenaar17c7c012006-01-26 22:25:15 +00002161 Number modify location list using {list}
Bram Moolenaar81edd172016-04-14 13:51:37 +02002162setmatches({list}) Number restore a list of matches
2163setpos({expr}, {list}) Number set the {expr} position to {list}
2164setqflist({list}[, {action}]) Number modify quickfix list using {list}
2165setreg({n}, {v}[, {opt}]) Number set register to value and type
2166settabvar({nr}, {varname}, {val}) none set {varname} in tab page {nr} to {val}
2167settabwinvar({tabnr}, {winnr}, {varname}, {val})
2168 none set {varname} in window {winnr} in tab
2169 page {tabnr} to {val}
2170setwinvar({nr}, {varname}, {val}) none set {varname} in window {nr} to {val}
2171sha256({string}) String SHA256 checksum of {string}
2172shellescape({string} [, {special}])
Bram Moolenaar05bb9532008-07-04 09:44:11 +00002173 String escape {string} for use as shell
Bram Moolenaar60a495f2006-10-03 12:44:42 +00002174 command argument
Bram Moolenaar2d17fa32012-10-21 00:45:18 +02002175shiftwidth() Number effective value of 'shiftwidth'
Bram Moolenaar81edd172016-04-14 13:51:37 +02002176simplify({filename}) String simplify filename as much as possible
2177sin({expr}) Float sine of {expr}
2178sinh({expr}) Float hyperbolic sine of {expr}
2179sort({list} [, {func} [, {dict}]])
Bram Moolenaar5f894962011-06-19 02:55:37 +02002180 List sort {list}, using {func} to compare
Bram Moolenaar81edd172016-04-14 13:51:37 +02002181soundfold({word}) String sound-fold {word}
Bram Moolenaard857f0e2005-06-21 22:37:39 +00002182spellbadword() String badly spelled word at cursor
Bram Moolenaar81edd172016-04-14 13:51:37 +02002183spellsuggest({word} [, {max} [, {capital}]])
Bram Moolenaarc54b8a72005-09-30 21:20:29 +00002184 List spelling suggestions
Bram Moolenaar81edd172016-04-14 13:51:37 +02002185split({expr} [, {pat} [, {keepempty}]])
Bram Moolenaar32466aa2006-02-24 23:53:04 +00002186 List make |List| from {pat} separated {expr}
Bram Moolenaar81edd172016-04-14 13:51:37 +02002187sqrt({expr}) Float square root of {expr}
2188str2float({expr}) Float convert String to Float
2189str2nr({expr} [, {base}]) Number convert String to Number
2190strchars({expr} [, {skipcc}]) Number character length of the String {expr}
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02002191strcharpart({str}, {start}[, {len}])
2192 String {len} characters of {str} at {start}
Bram Moolenaar81edd172016-04-14 13:51:37 +02002193strdisplaywidth({expr} [, {col}]) Number display length of the String {expr}
2194strftime({format}[, {time}]) String time in specified format
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02002195strgetchar({str}, {index}) Number get char {index} from {str}
Bram Moolenaar81edd172016-04-14 13:51:37 +02002196stridx({haystack}, {needle}[, {start}])
Bram Moolenaar8f999f12005-01-25 22:12:55 +00002197 Number index of {needle} in {haystack}
Bram Moolenaar81edd172016-04-14 13:51:37 +02002198string({expr}) String String representation of {expr} value
2199strlen({expr}) Number length of the String {expr}
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02002200strpart({str}, {start}[, {len}])
2201 String {len} characters of {str} at {start}
Bram Moolenaar81edd172016-04-14 13:51:37 +02002202strridx({haystack}, {needle} [, {start}])
Bram Moolenaar677ee682005-01-27 14:41:15 +00002203 Number last index of {needle} in {haystack}
Bram Moolenaar81edd172016-04-14 13:51:37 +02002204strtrans({expr}) String translate string to make it printable
2205strwidth({expr}) Number display cell length of the String {expr}
2206submatch({nr}[, {list}]) String or List
Bram Moolenaar41571762014-04-02 19:00:58 +02002207 specific match in ":s" or substitute()
Bram Moolenaar81edd172016-04-14 13:51:37 +02002208substitute({expr}, {pat}, {sub}, {flags})
Bram Moolenaar071d4272004-06-13 20:20:40 +00002209 String all {pat} in {expr} replaced with {sub}
Bram Moolenaar81edd172016-04-14 13:51:37 +02002210synID({lnum}, {col}, {trans}) Number syntax ID at {lnum} and {col}
2211synIDattr({synID}, {what} [, {mode}])
Bram Moolenaar071d4272004-06-13 20:20:40 +00002212 String attribute {what} of syntax ID {synID}
Bram Moolenaar81edd172016-04-14 13:51:37 +02002213synIDtrans({synID}) Number translated syntax ID of {synID}
2214synconcealed({lnum}, {col}) List info about concealing
2215synstack({lnum}, {col}) List stack of syntax IDs at {lnum} and {col}
2216system({expr} [, {input}]) String output of shell command/filter {expr}
2217systemlist({expr} [, {input}]) List output of shell command/filter {expr}
Bram Moolenaar802a0d92016-06-26 16:17:58 +02002218tabpagebuflist([{arg}]) List list of buffer numbers in tab page
Bram Moolenaar81edd172016-04-14 13:51:37 +02002219tabpagenr([{arg}]) Number number of current or last tab page
2220tabpagewinnr({tabarg}[, {arg}]) Number number of current window in tab page
2221taglist({expr}) List list of tags matching {expr}
Bram Moolenaar446cb832008-06-24 21:56:24 +00002222tagfiles() List tags files used
Bram Moolenaar81edd172016-04-14 13:51:37 +02002223tan({expr}) Float tangent of {expr}
2224tanh({expr}) Float hyperbolic tangent of {expr}
Bram Moolenaar975b5272016-03-15 23:10:59 +01002225tempname() String name for a temporary file
Bram Moolenaar8e8df252016-05-25 21:23:21 +02002226test_alloc_fail({id}, {countdown}, {repeat})
2227 none make memory allocation fail
2228test_disable_char_avail({expr}) none test without typeahead
Bram Moolenaar574860b2016-05-24 17:33:34 +02002229test_garbagecollect_now() none free memory right now for testing
2230test_null_channel() Channel null value for testing
2231test_null_dict() Dict null value for testing
2232test_null_job() Job null value for testing
2233test_null_list() List null value for testing
2234test_null_partial() Funcref null value for testing
2235test_null_string() String null value for testing
Bram Moolenaarc95a3022016-06-12 23:01:46 +02002236test_settime({expr}) none set current time for testing
Bram Moolenaar81edd172016-04-14 13:51:37 +02002237timer_start({time}, {callback} [, {options}])
Bram Moolenaar975b5272016-03-15 23:10:59 +01002238 Number create a timer
Bram Moolenaar81edd172016-04-14 13:51:37 +02002239timer_stop({timer}) none stop a timer
2240tolower({expr}) String the String {expr} switched to lowercase
2241toupper({expr}) String the String {expr} switched to uppercase
2242tr({src}, {fromstr}, {tostr}) String translate chars of {src} in {fromstr}
Bram Moolenaar8299df92004-07-10 09:47:34 +00002243 to chars in {tostr}
Bram Moolenaar81edd172016-04-14 13:51:37 +02002244trunc({expr}) Float truncate Float {expr}
2245type({name}) Number type of variable {name}
2246undofile({name}) String undo file name for {name}
Bram Moolenaara800b422010-06-27 01:15:55 +02002247undotree() List undo file tree
Bram Moolenaar81edd172016-04-14 13:51:37 +02002248uniq({list} [, {func} [, {dict}]])
Bram Moolenaar327aa022014-03-25 18:24:23 +01002249 List remove adjacent duplicates from a list
Bram Moolenaar81edd172016-04-14 13:51:37 +02002250values({dict}) List values in {dict}
2251virtcol({expr}) Number screen column of cursor or mark
2252visualmode([expr]) String last visual mode used
Bram Moolenaar8738fc12013-02-20 17:59:11 +01002253wildmenumode() Number whether 'wildmenu' mode is active
Bram Moolenaar81edd172016-04-14 13:51:37 +02002254win_findbuf({bufnr}) List find windows containing {bufnr}
2255win_getid([{win} [, {tab}]]) Number get window ID for {win} in {tab}
2256win_gotoid({expr}) Number go to window with ID {expr}
2257win_id2tabwin({expr}) List get tab and window nr from window ID
2258win_id2win({expr}) Number get window nr from window ID
2259winbufnr({nr}) Number buffer number of window {nr}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002260wincol() Number window column of the cursor
Bram Moolenaar81edd172016-04-14 13:51:37 +02002261winheight({nr}) Number height of window {nr}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002262winline() Number window line of the cursor
Bram Moolenaar81edd172016-04-14 13:51:37 +02002263winnr([{expr}]) Number number of current window
Bram Moolenaard7ee7ce2005-01-03 21:02:03 +00002264winrestcmd() String returns command to restore window sizes
Bram Moolenaar81edd172016-04-14 13:51:37 +02002265winrestview({dict}) none restore view of current window
Bram Moolenaar87b5ca52006-03-04 21:55:31 +00002266winsaveview() Dict save view of current window
Bram Moolenaar81edd172016-04-14 13:51:37 +02002267winwidth({nr}) Number width of window {nr}
Bram Moolenaared767a22016-01-03 22:49:16 +01002268wordcount() Dict get byte/char/word statistics
Bram Moolenaar81edd172016-04-14 13:51:37 +02002269writefile({list}, {fname} [, {flags}])
Bram Moolenaar3a7c85b2005-02-05 21:39:53 +00002270 Number write list of lines to file {fname}
Bram Moolenaar81edd172016-04-14 13:51:37 +02002271xor({expr}, {expr}) Number bitwise XOR
Bram Moolenaar071d4272004-06-13 20:20:40 +00002272
Bram Moolenaar03413f42016-04-12 21:07:15 +02002273
Bram Moolenaar446cb832008-06-24 21:56:24 +00002274abs({expr}) *abs()*
2275 Return the absolute value of {expr}. When {expr} evaluates to
2276 a |Float| abs() returns a |Float|. When {expr} can be
2277 converted to a |Number| abs() returns a |Number|. Otherwise
2278 abs() gives an error message and returns -1.
2279 Examples: >
2280 echo abs(1.456)
2281< 1.456 >
2282 echo abs(-5.456)
2283< 5.456 >
2284 echo abs(-4)
2285< 4
2286 {only available when compiled with the |+float| feature}
2287
Bram Moolenaardb7c6862010-05-21 16:33:48 +02002288
2289acos({expr}) *acos()*
2290 Return the arc cosine of {expr} measured in radians, as a
Bram Moolenaar9855d6b2010-07-18 14:34:51 +02002291 |Float| in the range of [0, pi].
2292 {expr} must evaluate to a |Float| or a |Number| in the range
Bram Moolenaardb7c6862010-05-21 16:33:48 +02002293 [-1, 1].
2294 Examples: >
2295 :echo acos(0)
2296< 1.570796 >
2297 :echo acos(-0.5)
2298< 2.094395
Bram Moolenaardb84e452010-08-15 13:50:43 +02002299 {only available when compiled with the |+float| feature}
Bram Moolenaardb7c6862010-05-21 16:33:48 +02002300
2301
Bram Moolenaara14de3d2005-01-07 21:48:26 +00002302add({list}, {expr}) *add()*
Bram Moolenaar32466aa2006-02-24 23:53:04 +00002303 Append the item {expr} to |List| {list}. Returns the
2304 resulting |List|. Examples: >
Bram Moolenaara14de3d2005-01-07 21:48:26 +00002305 :let alist = add([1, 2, 3], item)
2306 :call add(mylist, "woodstock")
Bram Moolenaar32466aa2006-02-24 23:53:04 +00002307< Note that when {expr} is a |List| it is appended as a single
Bram Moolenaara23ccb82006-02-27 00:08:02 +00002308 item. Use |extend()| to concatenate |Lists|.
Bram Moolenaar13065c42005-01-08 16:08:21 +00002309 Use |insert()| to add an item at another position.
Bram Moolenaar071d4272004-06-13 20:20:40 +00002310
Bram Moolenaara14de3d2005-01-07 21:48:26 +00002311
Bram Moolenaard6e256c2011-12-14 15:32:50 +01002312and({expr}, {expr}) *and()*
2313 Bitwise AND on the two arguments. The arguments are converted
2314 to a number. A List, Dict or Float argument causes an error.
2315 Example: >
2316 :let flag = and(bits, 0x80)
2317
2318
Bram Moolenaara14de3d2005-01-07 21:48:26 +00002319append({lnum}, {expr}) *append()*
Bram Moolenaar32466aa2006-02-24 23:53:04 +00002320 When {expr} is a |List|: Append each item of the |List| as a
2321 text line below line {lnum} in the current buffer.
Bram Moolenaar748bf032005-02-02 23:04:36 +00002322 Otherwise append {expr} as one text line below line {lnum} in
2323 the current buffer.
2324 {lnum} can be zero to insert a line before the first one.
Bram Moolenaara14de3d2005-01-07 21:48:26 +00002325 Returns 1 for failure ({lnum} out of range or out of memory),
Bram Moolenaar446cb832008-06-24 21:56:24 +00002326 0 for success. Example: >
Bram Moolenaard7ee7ce2005-01-03 21:02:03 +00002327 :let failed = append(line('$'), "# THE END")
Bram Moolenaara14de3d2005-01-07 21:48:26 +00002328 :let failed = append(0, ["Chapter 1", "the beginning"])
Bram Moolenaard7ee7ce2005-01-03 21:02:03 +00002329<
Bram Moolenaar071d4272004-06-13 20:20:40 +00002330 *argc()*
2331argc() The result is the number of files in the argument list of the
2332 current window. See |arglist|.
2333
2334 *argidx()*
2335argidx() The result is the current index in the argument list. 0 is
2336 the first file. argc() - 1 is the last one. See |arglist|.
2337
Bram Moolenaar2d1fe052014-05-28 18:22:57 +02002338 *arglistid()*
Bram Moolenaare0fa3742016-02-20 15:47:01 +01002339arglistid([{winnr} [, {tabnr}]])
Bram Moolenaar2d1fe052014-05-28 18:22:57 +02002340 Return the argument list ID. This is a number which
2341 identifies the argument list being used. Zero is used for the
Bram Moolenaarfb539272014-08-22 19:21:47 +02002342 global argument list. See |arglist|.
2343 Return -1 if the arguments are invalid.
Bram Moolenaar2d1fe052014-05-28 18:22:57 +02002344
2345 Without arguments use the current window.
2346 With {winnr} only use this window in the current tab page.
2347 With {winnr} and {tabnr} use the window in the specified tab
2348 page.
Bram Moolenaar888ccac2016-06-04 18:49:36 +02002349 {winnr} can be the window number or the window ID.
Bram Moolenaar2d1fe052014-05-28 18:22:57 +02002350
Bram Moolenaar071d4272004-06-13 20:20:40 +00002351 *argv()*
Bram Moolenaare2f98b92006-03-29 21:18:24 +00002352argv([{nr}]) The result is the {nr}th file in the argument list of the
Bram Moolenaar071d4272004-06-13 20:20:40 +00002353 current window. See |arglist|. "argv(0)" is the first one.
2354 Example: >
2355 :let i = 0
2356 :while i < argc()
Bram Moolenaar446cb832008-06-24 21:56:24 +00002357 : let f = escape(fnameescape(argv(i)), '.')
Bram Moolenaar071d4272004-06-13 20:20:40 +00002358 : exe 'amenu Arg.' . f . ' :e ' . f . '<CR>'
2359 : let i = i + 1
2360 :endwhile
Bram Moolenaare2f98b92006-03-29 21:18:24 +00002361< Without the {nr} argument a |List| with the whole |arglist| is
2362 returned.
2363
Bram Moolenaar683fa182015-11-30 21:38:24 +01002364 *assert_equal()*
Bram Moolenaara803c7f2016-01-15 15:31:39 +01002365assert_equal({expected}, {actual} [, {msg}])
Bram Moolenaar43345542015-11-29 17:35:35 +01002366 When {expected} and {actual} are not equal an error message is
2367 added to |v:errors|.
2368 There is no automatic conversion, the String "4" is different
2369 from the Number 4. And the number 4 is different from the
2370 Float 4.0. The value of 'ignorecase' is not used here, case
2371 always matters.
Bram Moolenaar683fa182015-11-30 21:38:24 +01002372 When {msg} is omitted an error in the form "Expected
2373 {expected} but got {actual}" is produced.
Bram Moolenaar43345542015-11-29 17:35:35 +01002374 Example: >
Bram Moolenaar683fa182015-11-30 21:38:24 +01002375 assert_equal('foo', 'bar')
Bram Moolenaar43345542015-11-29 17:35:35 +01002376< Will result in a string to be added to |v:errors|:
2377 test.vim line 12: Expected 'foo' but got 'bar' ~
2378
Bram Moolenaara803c7f2016-01-15 15:31:39 +01002379assert_exception({error} [, {msg}]) *assert_exception()*
2380 When v:exception does not contain the string {error} an error
2381 message is added to |v:errors|.
2382 This can be used to assert that a command throws an exception.
2383 Using the error number, followed by a colon, avoids problems
2384 with translations: >
2385 try
2386 commandthatfails
2387 call assert_false(1, 'command should have failed')
2388 catch
2389 call assert_exception('E492:')
2390 endtry
2391
Bram Moolenaara260b872016-01-15 20:48:22 +01002392assert_fails({cmd} [, {error}]) *assert_fails()*
2393 Run {cmd} and add an error message to |v:errors| if it does
2394 NOT produce an error.
2395 When {error} is given it must match |v:errmsg|.
2396
Bram Moolenaara803c7f2016-01-15 15:31:39 +01002397assert_false({actual} [, {msg}]) *assert_false()*
Bram Moolenaar43345542015-11-29 17:35:35 +01002398 When {actual} is not false an error message is added to
Bram Moolenaara803c7f2016-01-15 15:31:39 +01002399 |v:errors|, like with |assert_equal()|.
Bram Moolenaar6463ca22016-02-13 17:04:46 +01002400 A value is false when it is zero. When {actual} is not a
Bram Moolenaar43345542015-11-29 17:35:35 +01002401 number the assert fails.
Bram Moolenaar683fa182015-11-30 21:38:24 +01002402 When {msg} is omitted an error in the form "Expected False but
2403 got {actual}" is produced.
Bram Moolenaar43345542015-11-29 17:35:35 +01002404
Bram Moolenaarea6553b2016-03-27 15:13:38 +02002405 *assert_match()*
2406assert_match({pattern}, {actual} [, {msg}])
2407 When {pattern} does not match {actual} an error message is
2408 added to |v:errors|.
2409
2410 {pattern} is used as with |=~|: The matching is always done
2411 like 'magic' was set and 'cpoptions' is empty, no matter what
2412 the actual value of 'magic' or 'cpoptions' is.
2413
2414 {actual} is used as a string, automatic conversion applies.
2415 Use "^" and "$" to match with the start and end of the text.
2416 Use both to match the whole text.
2417
2418 When {msg} is omitted an error in the form "Pattern {pattern}
2419 does not match {actual}" is produced.
2420 Example: >
2421 assert_match('^f.*o$', 'foobar')
2422< Will result in a string to be added to |v:errors|:
2423 test.vim line 12: Pattern '^f.*o$' does not match 'foobar' ~
2424
Bram Moolenaarb50e5f52016-04-03 20:57:20 +02002425 *assert_notequal()*
2426assert_notequal({expected}, {actual} [, {msg}])
2427 The opposite of `assert_equal()`: add an error message to
2428 |v:errors| when {expected} and {actual} are equal.
2429
2430 *assert_notmatch()*
2431assert_notmatch({pattern}, {actual} [, {msg}])
2432 The opposite of `assert_match()`: add an error message to
2433 |v:errors| when {pattern} matches {actual}.
2434
Bram Moolenaara803c7f2016-01-15 15:31:39 +01002435assert_true({actual} [, {msg}]) *assert_true()*
Bram Moolenaar43345542015-11-29 17:35:35 +01002436 When {actual} is not true an error message is added to
Bram Moolenaara803c7f2016-01-15 15:31:39 +01002437 |v:errors|, like with |assert_equal()|.
2438 A value is true when it is a non-zero number. When {actual}
Bram Moolenaar43345542015-11-29 17:35:35 +01002439 is not a number the assert fails.
Bram Moolenaar683fa182015-11-30 21:38:24 +01002440 When {msg} is omitted an error in the form "Expected True but
2441 got {actual}" is produced.
Bram Moolenaar43345542015-11-29 17:35:35 +01002442
Bram Moolenaardb7c6862010-05-21 16:33:48 +02002443asin({expr}) *asin()*
Bram Moolenaar9855d6b2010-07-18 14:34:51 +02002444 Return the arc sine of {expr} measured in radians, as a |Float|
Bram Moolenaardb7c6862010-05-21 16:33:48 +02002445 in the range of [-pi/2, pi/2].
Bram Moolenaar9855d6b2010-07-18 14:34:51 +02002446 {expr} must evaluate to a |Float| or a |Number| in the range
Bram Moolenaardb7c6862010-05-21 16:33:48 +02002447 [-1, 1].
2448 Examples: >
2449 :echo asin(0.8)
2450< 0.927295 >
2451 :echo asin(-0.5)
2452< -0.523599
Bram Moolenaardb84e452010-08-15 13:50:43 +02002453 {only available when compiled with the |+float| feature}
Bram Moolenaardb7c6862010-05-21 16:33:48 +02002454
2455
Bram Moolenaar446cb832008-06-24 21:56:24 +00002456atan({expr}) *atan()*
2457 Return the principal value of the arc tangent of {expr}, in
2458 the range [-pi/2, +pi/2] radians, as a |Float|.
2459 {expr} must evaluate to a |Float| or a |Number|.
2460 Examples: >
2461 :echo atan(100)
2462< 1.560797 >
2463 :echo atan(-4.01)
2464< -1.326405
2465 {only available when compiled with the |+float| feature}
2466
Bram Moolenaardb7c6862010-05-21 16:33:48 +02002467
2468atan2({expr1}, {expr2}) *atan2()*
2469 Return the arc tangent of {expr1} / {expr2}, measured in
Bram Moolenaar9855d6b2010-07-18 14:34:51 +02002470 radians, as a |Float| in the range [-pi, pi].
2471 {expr1} and {expr2} must evaluate to a |Float| or a |Number|.
Bram Moolenaardb7c6862010-05-21 16:33:48 +02002472 Examples: >
2473 :echo atan2(-1, 1)
2474< -0.785398 >
2475 :echo atan2(1, -1)
2476< 2.356194
Bram Moolenaardb84e452010-08-15 13:50:43 +02002477 {only available when compiled with the |+float| feature}
Bram Moolenaardb7c6862010-05-21 16:33:48 +02002478
2479
Bram Moolenaar071d4272004-06-13 20:20:40 +00002480 *browse()*
2481browse({save}, {title}, {initdir}, {default})
2482 Put up a file requester. This only works when "has("browse")"
2483 returns non-zero (only in some GUI versions).
2484 The input fields are:
2485 {save} when non-zero, select file to write
2486 {title} title for the requester
2487 {initdir} directory to start browsing in
2488 {default} default file name
2489 When the "Cancel" button is hit, something went wrong, or
2490 browsing is not possible, an empty string is returned.
2491
Bram Moolenaar7b0294c2004-10-11 10:16:09 +00002492 *browsedir()*
2493browsedir({title}, {initdir})
2494 Put up a directory requester. This only works when
2495 "has("browse")" returns non-zero (only in some GUI versions).
2496 On systems where a directory browser is not supported a file
2497 browser is used. In that case: select a file in the directory
2498 to be used.
2499 The input fields are:
2500 {title} title for the requester
2501 {initdir} directory to start browsing in
2502 When the "Cancel" button is hit, something went wrong, or
2503 browsing is not possible, an empty string is returned.
2504
Bram Moolenaar071d4272004-06-13 20:20:40 +00002505bufexists({expr}) *bufexists()*
2506 The result is a Number, which is non-zero if a buffer called
2507 {expr} exists.
Bram Moolenaar69a7cb42004-06-20 12:51:53 +00002508 If the {expr} argument is a number, buffer numbers are used.
Bram Moolenaar071d4272004-06-13 20:20:40 +00002509 If the {expr} argument is a string it must match a buffer name
Bram Moolenaar69a7cb42004-06-20 12:51:53 +00002510 exactly. The name can be:
2511 - Relative to the current directory.
2512 - A full path.
Bram Moolenaar446cb832008-06-24 21:56:24 +00002513 - The name of a buffer with 'buftype' set to "nofile".
Bram Moolenaar69a7cb42004-06-20 12:51:53 +00002514 - A URL name.
Bram Moolenaar071d4272004-06-13 20:20:40 +00002515 Unlisted buffers will be found.
2516 Note that help files are listed by their short name in the
2517 output of |:buffers|, but bufexists() requires using their
2518 long name to be able to find them.
Bram Moolenaar446cb832008-06-24 21:56:24 +00002519 bufexists() may report a buffer exists, but to use the name
2520 with a |:buffer| command you may need to use |expand()|. Esp
2521 for MS-Windows 8.3 names in the form "c:\DOCUME~1"
Bram Moolenaar071d4272004-06-13 20:20:40 +00002522 Use "bufexists(0)" to test for the existence of an alternate
2523 file name.
2524 *buffer_exists()*
2525 Obsolete name: buffer_exists().
2526
2527buflisted({expr}) *buflisted()*
2528 The result is a Number, which is non-zero if a buffer called
2529 {expr} exists and is listed (has the 'buflisted' option set).
Bram Moolenaar69a7cb42004-06-20 12:51:53 +00002530 The {expr} argument is used like with |bufexists()|.
Bram Moolenaar071d4272004-06-13 20:20:40 +00002531
2532bufloaded({expr}) *bufloaded()*
2533 The result is a Number, which is non-zero if a buffer called
2534 {expr} exists and is loaded (shown in a window or hidden).
Bram Moolenaar69a7cb42004-06-20 12:51:53 +00002535 The {expr} argument is used like with |bufexists()|.
Bram Moolenaar071d4272004-06-13 20:20:40 +00002536
2537bufname({expr}) *bufname()*
2538 The result is the name of a buffer, as it is displayed by the
2539 ":ls" command.
2540 If {expr} is a Number, that buffer number's name is given.
2541 Number zero is the alternate buffer for the current window.
2542 If {expr} is a String, it is used as a |file-pattern| to match
Bram Moolenaar446cb832008-06-24 21:56:24 +00002543 with the buffer names. This is always done like 'magic' is
Bram Moolenaar071d4272004-06-13 20:20:40 +00002544 set and 'cpoptions' is empty. When there is more than one
2545 match an empty string is returned.
2546 "" or "%" can be used for the current buffer, "#" for the
2547 alternate buffer.
2548 A full match is preferred, otherwise a match at the start, end
Bram Moolenaaref2f6562007-05-06 13:32:59 +00002549 or middle of the buffer name is accepted. If you only want a
2550 full match then put "^" at the start and "$" at the end of the
2551 pattern.
Bram Moolenaar071d4272004-06-13 20:20:40 +00002552 Listed buffers are found first. If there is a single match
2553 with a listed buffer, that one is returned. Next unlisted
2554 buffers are searched for.
2555 If the {expr} is a String, but you want to use it as a buffer
2556 number, force it to be a Number by adding zero to it: >
2557 :echo bufname("3" + 0)
2558< If the buffer doesn't exist, or doesn't have a name, an empty
2559 string is returned. >
2560 bufname("#") alternate buffer name
2561 bufname(3) name of buffer 3
2562 bufname("%") name of current buffer
2563 bufname("file2") name of buffer where "file2" matches.
2564< *buffer_name()*
2565 Obsolete name: buffer_name().
2566
2567 *bufnr()*
Bram Moolenaar65c923a2006-03-03 22:56:30 +00002568bufnr({expr} [, {create}])
2569 The result is the number of a buffer, as it is displayed by
Bram Moolenaar071d4272004-06-13 20:20:40 +00002570 the ":ls" command. For the use of {expr}, see |bufname()|
Bram Moolenaar65c923a2006-03-03 22:56:30 +00002571 above.
2572 If the buffer doesn't exist, -1 is returned. Or, if the
2573 {create} argument is present and not zero, a new, unlisted,
2574 buffer is created and its number is returned.
Bram Moolenaar071d4272004-06-13 20:20:40 +00002575 bufnr("$") is the last buffer: >
2576 :let last_buffer = bufnr("$")
2577< The result is a Number, which is the highest buffer number
2578 of existing buffers. Note that not all buffers with a smaller
2579 number necessarily exist, because ":bwipeout" may have removed
2580 them. Use bufexists() to test for the existence of a buffer.
2581 *buffer_number()*
2582 Obsolete name: buffer_number().
2583 *last_buffer_nr()*
2584 Obsolete name for bufnr("$"): last_buffer_nr().
2585
Bram Moolenaarb3619a92016-06-04 17:58:52 +02002586bufwinid({expr}) *bufwinid()*
2587 The result is a Number, which is the window ID of the first
2588 window associated with buffer {expr}. For the use of {expr},
2589 see |bufname()| above. If buffer {expr} doesn't exist or
2590 there is no such window, -1 is returned. Example: >
2591
2592 echo "A window containing buffer 1 is " . (bufwinid(1))
2593<
2594 Only deals with the current tab page.
2595
Bram Moolenaar071d4272004-06-13 20:20:40 +00002596bufwinnr({expr}) *bufwinnr()*
2597 The result is a Number, which is the number of the first
2598 window associated with buffer {expr}. For the use of {expr},
Bram Moolenaar446cb832008-06-24 21:56:24 +00002599 see |bufname()| above. If buffer {expr} doesn't exist or
Bram Moolenaar071d4272004-06-13 20:20:40 +00002600 there is no such window, -1 is returned. Example: >
2601
2602 echo "A window containing buffer 1 is " . (bufwinnr(1))
2603
2604< The number can be used with |CTRL-W_w| and ":wincmd w"
2605 |:wincmd|.
Bram Moolenaaref2f6562007-05-06 13:32:59 +00002606 Only deals with the current tab page.
Bram Moolenaar071d4272004-06-13 20:20:40 +00002607
Bram Moolenaar071d4272004-06-13 20:20:40 +00002608byte2line({byte}) *byte2line()*
2609 Return the line number that contains the character at byte
2610 count {byte} in the current buffer. This includes the
2611 end-of-line character, depending on the 'fileformat' option
2612 for the current buffer. The first character has byte count
2613 one.
2614 Also see |line2byte()|, |go| and |:goto|.
2615 {not available when compiled without the |+byte_offset|
2616 feature}
2617
Bram Moolenaarab79bcb2004-07-18 21:34:53 +00002618byteidx({expr}, {nr}) *byteidx()*
2619 Return byte index of the {nr}'th character in the string
2620 {expr}. Use zero for the first character, it returns zero.
2621 This function is only useful when there are multibyte
2622 characters, otherwise the returned value is equal to {nr}.
Bram Moolenaar0ffbbf92013-11-02 23:29:26 +01002623 Composing characters are not counted separately, their byte
2624 length is added to the preceding base character. See
2625 |byteidxcomp()| below for counting composing characters
2626 separately.
Bram Moolenaarab79bcb2004-07-18 21:34:53 +00002627 Example : >
2628 echo matchstr(str, ".", byteidx(str, 3))
2629< will display the fourth character. Another way to do the
2630 same: >
2631 let s = strpart(str, byteidx(str, 3))
2632 echo strpart(s, 0, byteidx(s, 1))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02002633< Also see |strgetchar()| and |strcharpart()|.
2634
2635 If there are less than {nr} characters -1 is returned.
Bram Moolenaarab79bcb2004-07-18 21:34:53 +00002636 If there are exactly {nr} characters the length of the string
Bram Moolenaar0ffbbf92013-11-02 23:29:26 +01002637 in bytes is returned.
2638
2639byteidxcomp({expr}, {nr}) *byteidxcomp()*
2640 Like byteidx(), except that a composing character is counted
2641 as a separate character. Example: >
2642 let s = 'e' . nr2char(0x301)
2643 echo byteidx(s, 1)
2644 echo byteidxcomp(s, 1)
2645 echo byteidxcomp(s, 2)
2646< The first and third echo result in 3 ('e' plus composing
2647 character is 3 bytes), the second echo results in 1 ('e' is
2648 one byte).
2649 Only works different from byteidx() when 'encoding' is set to
2650 a Unicode encoding.
Bram Moolenaarab79bcb2004-07-18 21:34:53 +00002651
Bram Moolenaar2fda12f2005-01-15 22:14:15 +00002652call({func}, {arglist} [, {dict}]) *call()* *E699*
Bram Moolenaar32466aa2006-02-24 23:53:04 +00002653 Call function {func} with the items in |List| {arglist} as
Bram Moolenaarde8866b2005-01-06 23:24:37 +00002654 arguments.
Bram Moolenaar32466aa2006-02-24 23:53:04 +00002655 {func} can either be a |Funcref| or the name of a function.
Bram Moolenaarde8866b2005-01-06 23:24:37 +00002656 a:firstline and a:lastline are set to the cursor line.
2657 Returns the return value of the called function.
Bram Moolenaar2fda12f2005-01-15 22:14:15 +00002658 {dict} is for functions with the "dict" attribute. It will be
2659 used to set the local variable "self". |Dictionary-function|
Bram Moolenaarde8866b2005-01-06 23:24:37 +00002660
Bram Moolenaar446cb832008-06-24 21:56:24 +00002661ceil({expr}) *ceil()*
2662 Return the smallest integral value greater than or equal to
2663 {expr} as a |Float| (round up).
2664 {expr} must evaluate to a |Float| or a |Number|.
2665 Examples: >
2666 echo ceil(1.456)
2667< 2.0 >
2668 echo ceil(-5.456)
2669< -5.0 >
2670 echo ceil(4.0)
2671< 4.0
2672 {only available when compiled with the |+float| feature}
2673
Bram Moolenaarca003e12006-03-17 23:19:38 +00002674changenr() *changenr()*
2675 Return the number of the most recent change. This is the same
2676 number as what is displayed with |:undolist| and can be used
2677 with the |:undo| command.
2678 When a change was made it is the number of that change. After
2679 redo it is the number of the redone change. After undo it is
2680 one less than the number of the undone change.
2681
Bram Moolenaard35d7842013-01-23 17:17:10 +01002682char2nr({expr}[, {utf8}]) *char2nr()*
Bram Moolenaar071d4272004-06-13 20:20:40 +00002683 Return number value of the first char in {expr}. Examples: >
2684 char2nr(" ") returns 32
2685 char2nr("ABC") returns 65
Bram Moolenaard35d7842013-01-23 17:17:10 +01002686< When {utf8} is omitted or zero, the current 'encoding' is used.
2687 Example for "utf-8": >
Bram Moolenaaref2f6562007-05-06 13:32:59 +00002688 char2nr("á") returns 225
2689 char2nr("á"[0]) returns 195
Bram Moolenaard35d7842013-01-23 17:17:10 +01002690< With {utf8} set to 1, always treat as utf-8 characters.
2691 A combining character is a separate character.
Bram Moolenaar97293012011-07-18 19:40:27 +02002692 |nr2char()| does the opposite.
Bram Moolenaar071d4272004-06-13 20:20:40 +00002693
2694cindent({lnum}) *cindent()*
2695 Get the amount of indent for line {lnum} according the C
2696 indenting rules, as with 'cindent'.
2697 The indent is counted in spaces, the value of 'tabstop' is
2698 relevant. {lnum} is used just like in |getline()|.
2699 When {lnum} is invalid or Vim was not compiled the |+cindent|
2700 feature, -1 is returned.
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +00002701 See |C-indenting|.
Bram Moolenaar071d4272004-06-13 20:20:40 +00002702
Bram Moolenaar6ee10162007-07-26 20:58:42 +00002703clearmatches() *clearmatches()*
2704 Clears all matches previously defined by |matchadd()| and the
2705 |:match| commands.
2706
Bram Moolenaar071d4272004-06-13 20:20:40 +00002707 *col()*
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002708col({expr}) The result is a Number, which is the byte index of the column
Bram Moolenaar071d4272004-06-13 20:20:40 +00002709 position given with {expr}. The accepted positions are:
2710 . the cursor position
2711 $ the end of the cursor line (the result is the
Bram Moolenaar1aeaf8c2012-05-18 13:46:39 +02002712 number of bytes in the cursor line plus one)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002713 'x position of mark x (if the mark is not set, 0 is
2714 returned)
Bram Moolenaare3faf442014-12-14 01:27:49 +01002715 v In Visual mode: the start of the Visual area (the
2716 cursor is the end). When not in Visual mode
2717 returns the cursor position. Differs from |'<| in
2718 that it's updated right away.
Bram Moolenaar477933c2007-07-17 14:32:23 +00002719 Additionally {expr} can be [lnum, col]: a |List| with the line
2720 and column number. Most useful when the column is "$", to get
Bram Moolenaar446cb832008-06-24 21:56:24 +00002721 the last column of a specific line. When "lnum" or "col" is
Bram Moolenaar477933c2007-07-17 14:32:23 +00002722 out of range then col() returns zero.
Bram Moolenaaref2f6562007-05-06 13:32:59 +00002723 To get the line number use |line()|. To get both use
Bram Moolenaar0b238792006-03-02 22:49:12 +00002724 |getpos()|.
Bram Moolenaar071d4272004-06-13 20:20:40 +00002725 For the screen column position use |virtcol()|.
2726 Note that only marks in the current file can be used.
2727 Examples: >
2728 col(".") column of cursor
2729 col("$") length of cursor line plus one
2730 col("'t") column of mark t
2731 col("'" . markname) column of mark markname
Bram Moolenaar446cb832008-06-24 21:56:24 +00002732< The first column is 1. 0 is returned for an error.
Bram Moolenaaref2f6562007-05-06 13:32:59 +00002733 For an uppercase mark the column may actually be in another
2734 buffer.
Bram Moolenaar071d4272004-06-13 20:20:40 +00002735 For the cursor position, when 'virtualedit' is active, the
2736 column is one higher if the cursor is after the end of the
2737 line. This can be used to obtain the column in Insert mode: >
2738 :imap <F2> <C-O>:let save_ve = &ve<CR>
2739 \<C-O>:set ve=all<CR>
2740 \<C-O>:echo col(".") . "\n" <Bar>
2741 \let &ve = save_ve<CR>
2742<
Bram Moolenaar572cb562005-08-05 21:35:02 +00002743
Bram Moolenaara94bc432006-03-10 21:42:59 +00002744complete({startcol}, {matches}) *complete()* *E785*
2745 Set the matches for Insert mode completion.
2746 Can only be used in Insert mode. You need to use a mapping
Bram Moolenaaref2f6562007-05-06 13:32:59 +00002747 with CTRL-R = |i_CTRL-R|. It does not work after CTRL-O or
2748 with an expression mapping.
Bram Moolenaara94bc432006-03-10 21:42:59 +00002749 {startcol} is the byte offset in the line where the completed
2750 text start. The text up to the cursor is the original text
2751 that will be replaced by the matches. Use col('.') for an
2752 empty string. "col('.') - 1" will replace one character by a
2753 match.
2754 {matches} must be a |List|. Each |List| item is one match.
2755 See |complete-items| for the kind of items that are possible.
2756 Note that the after calling this function you need to avoid
Bram Moolenaar8f3f58f2010-01-06 20:52:26 +01002757 inserting anything that would cause completion to stop.
Bram Moolenaara94bc432006-03-10 21:42:59 +00002758 The match can be selected with CTRL-N and CTRL-P as usual with
2759 Insert mode completion. The popup menu will appear if
2760 specified, see |ins-completion-menu|.
2761 Example: >
Bram Moolenaaref2f6562007-05-06 13:32:59 +00002762 inoremap <F5> <C-R>=ListMonths()<CR>
Bram Moolenaara94bc432006-03-10 21:42:59 +00002763
2764 func! ListMonths()
2765 call complete(col('.'), ['January', 'February', 'March',
2766 \ 'April', 'May', 'June', 'July', 'August', 'September',
2767 \ 'October', 'November', 'December'])
2768 return ''
2769 endfunc
2770< This isn't very useful, but it shows how it works. Note that
2771 an empty string is returned to avoid a zero being inserted.
2772
Bram Moolenaar572cb562005-08-05 21:35:02 +00002773complete_add({expr}) *complete_add()*
2774 Add {expr} to the list of matches. Only to be used by the
2775 function specified with the 'completefunc' option.
2776 Returns 0 for failure (empty string or out of memory),
2777 1 when the match was added, 2 when the match was already in
2778 the list.
Bram Moolenaar446cb832008-06-24 21:56:24 +00002779 See |complete-functions| for an explanation of {expr}. It is
Bram Moolenaar39f05632006-03-19 22:15:26 +00002780 the same as one item in the list that 'omnifunc' would return.
Bram Moolenaar572cb562005-08-05 21:35:02 +00002781
2782complete_check() *complete_check()*
2783 Check for a key typed while looking for completion matches.
2784 This is to be used when looking for matches takes some time.
2785 Returns non-zero when searching for matches is to be aborted,
2786 zero otherwise.
2787 Only to be used by the function specified with the
2788 'completefunc' option.
2789
Bram Moolenaar071d4272004-06-13 20:20:40 +00002790 *confirm()*
2791confirm({msg} [, {choices} [, {default} [, {type}]]])
2792 Confirm() offers the user a dialog, from which a choice can be
2793 made. It returns the number of the choice. For the first
2794 choice this is 1.
2795 Note: confirm() is only supported when compiled with dialog
2796 support, see |+dialog_con| and |+dialog_gui|.
Bram Moolenaara800b422010-06-27 01:15:55 +02002797
Bram Moolenaar071d4272004-06-13 20:20:40 +00002798 {msg} is displayed in a |dialog| with {choices} as the
2799 alternatives. When {choices} is missing or empty, "&OK" is
2800 used (and translated).
2801 {msg} is a String, use '\n' to include a newline. Only on
2802 some systems the string is wrapped when it doesn't fit.
Bram Moolenaara800b422010-06-27 01:15:55 +02002803
Bram Moolenaar071d4272004-06-13 20:20:40 +00002804 {choices} is a String, with the individual choices separated
2805 by '\n', e.g. >
2806 confirm("Save changes?", "&Yes\n&No\n&Cancel")
2807< The letter after the '&' is the shortcut key for that choice.
2808 Thus you can type 'c' to select "Cancel". The shortcut does
2809 not need to be the first letter: >
2810 confirm("file has been modified", "&Save\nSave &All")
2811< For the console, the first letter of each choice is used as
2812 the default shortcut key.
Bram Moolenaara800b422010-06-27 01:15:55 +02002813
Bram Moolenaar071d4272004-06-13 20:20:40 +00002814 The optional {default} argument is the number of the choice
2815 that is made if the user hits <CR>. Use 1 to make the first
2816 choice the default one. Use 0 to not set a default. If
2817 {default} is omitted, 1 is used.
Bram Moolenaara800b422010-06-27 01:15:55 +02002818
2819 The optional {type} argument gives the type of dialog. This
2820 is only used for the icon of the GTK, Mac, Motif and Win32
2821 GUI. It can be one of these values: "Error", "Question",
2822 "Info", "Warning" or "Generic". Only the first character is
2823 relevant. When {type} is omitted, "Generic" is used.
2824
Bram Moolenaar071d4272004-06-13 20:20:40 +00002825 If the user aborts the dialog by pressing <Esc>, CTRL-C,
2826 or another valid interrupt key, confirm() returns 0.
2827
2828 An example: >
2829 :let choice = confirm("What do you want?", "&Apples\n&Oranges\n&Bananas", 2)
2830 :if choice == 0
2831 : echo "make up your mind!"
2832 :elseif choice == 3
2833 : echo "tasteful"
2834 :else
2835 : echo "I prefer bananas myself."
2836 :endif
2837< In a GUI dialog, buttons are used. The layout of the buttons
2838 depends on the 'v' flag in 'guioptions'. If it is included,
Bram Moolenaar446cb832008-06-24 21:56:24 +00002839 the buttons are always put vertically. Otherwise, confirm()
Bram Moolenaar071d4272004-06-13 20:20:40 +00002840 tries to put the buttons in one horizontal line. If they
2841 don't fit, a vertical layout is used anyway. For some systems
2842 the horizontal layout is always used.
2843
Bram Moolenaar5f148ec2016-03-07 22:59:26 +01002844ch_close({handle}) *ch_close()*
2845 Close {handle}. See |channel-close|.
2846 {handle} can be Channel or a Job that has a Channel.
Bram Moolenaar328da0d2016-03-04 22:22:32 +01002847
Bram Moolenaar835dc632016-02-07 14:27:38 +01002848 {only available when compiled with the |+channel| feature}
Bram Moolenaarf57969a2016-02-02 20:47:49 +01002849
Bram Moolenaar5f148ec2016-03-07 22:59:26 +01002850ch_evalexpr({handle}, {expr} [, {options}]) *ch_evalexpr()*
2851 Send {expr} over {handle}. The {expr} is encoded
Bram Moolenaar8b1862a2016-02-27 19:21:24 +01002852 according to the type of channel. The function cannot be used
Bram Moolenaardae8d212016-02-27 22:40:16 +01002853 with a raw channel. See |channel-use|.
Bram Moolenaar5f148ec2016-03-07 22:59:26 +01002854 {handle} can be Channel or a Job that has a Channel.
Bram Moolenaar8b1862a2016-02-27 19:21:24 +01002855 *E917*
2856 {options} must be a Dictionary. It must not have a "callback"
Bram Moolenaar4f3f6682016-03-26 23:01:59 +01002857 entry. It can have a "timeout" entry to specify the timeout
2858 for this specific request.
Bram Moolenaar8b1862a2016-02-27 19:21:24 +01002859
2860 ch_evalexpr() waits for a response and returns the decoded
2861 expression. When there is an error or timeout it returns an
2862 empty string.
2863
2864 {only available when compiled with the |+channel| feature}
2865
Bram Moolenaar5f148ec2016-03-07 22:59:26 +01002866ch_evalraw({handle}, {string} [, {options}]) *ch_evalraw()*
2867 Send {string} over {handle}.
2868 {handle} can be Channel or a Job that has a Channel.
2869
Bram Moolenaar8b1862a2016-02-27 19:21:24 +01002870 Works like |ch_evalexpr()|, but does not encode the request or
2871 decode the response. The caller is responsible for the
2872 correct contents. Also does not add a newline for a channel
2873 in NL mode, the caller must do that. The NL in the response
2874 is removed.
2875 See |channel-use|.
2876
2877 {only available when compiled with the |+channel| feature}
2878
Bram Moolenaar5f148ec2016-03-07 22:59:26 +01002879ch_getbufnr({handle}, {what}) *ch_getbufnr()*
2880 Get the buffer number that {handle} is using for {what}.
2881 {handle} can be Channel or a Job that has a Channel.
Bram Moolenaarc7f0ebc2016-02-27 21:10:09 +01002882 {what} can be "err" for stderr, "out" for stdout or empty for
2883 socket output.
2884 Returns -1 when there is no buffer.
2885 {only available when compiled with the |+channel| feature}
2886
Bram Moolenaar02e83b42016-02-21 20:10:26 +01002887ch_getjob({channel}) *ch_getjob()*
2888 Get the Job associated with {channel}.
2889 If there is no job calling |job_status()| on the returned Job
2890 will result in "fail".
2891
2892 {only available when compiled with the |+channel| and
2893 |+job| features}
2894
Bram Moolenaar03602ec2016-03-20 20:57:45 +01002895ch_info({handle}) *ch_info()*
2896 Returns a Dictionary with information about {handle}. The
2897 items are:
2898 "id" number of the channel
2899 "status" "open" (any part is open) or "closed"
2900 When opened with ch_open():
2901 "hostname" the hostname of the address
2902 "port" the port of the address
2903 "sock_status" "open" or "closed"
2904 "sock_mode" "NL", "RAW", "JSON" or "JS"
2905 "sock_io" "socket"
2906 "sock_timeout" timeout in msec
2907 When opened with job_start():
2908 "out_status" "open" or "closed"
2909 "out_mode" "NL", "RAW", "JSON" or "JS"
2910 "out_io" "null", "pipe", "file" or "buffer"
2911 "out_timeout" timeout in msec
2912 "err_status" "open" or "closed"
2913 "err_mode" "NL", "RAW", "JSON" or "JS"
2914 "err_io" "out", "null", "pipe", "file" or "buffer"
2915 "err_timeout" timeout in msec
2916 "in_status" "open" or "closed"
2917 "in_mode" "NL", "RAW", "JSON" or "JS"
2918 "in_io" "null", "pipe", "file" or "buffer"
2919 "in_timeout" timeout in msec
2920
Bram Moolenaar5f148ec2016-03-07 22:59:26 +01002921ch_log({msg} [, {handle}]) *ch_log()*
Bram Moolenaare0fa3742016-02-20 15:47:01 +01002922 Write {msg} in the channel log file, if it was opened with
2923 |ch_logfile()|.
Bram Moolenaar5f148ec2016-03-07 22:59:26 +01002924 When {handle} is passed the channel number is used for the
2925 message.
2926 {handle} can be Channel or a Job that has a Channel. The
2927 Channel must open.
Bram Moolenaare0fa3742016-02-20 15:47:01 +01002928
2929ch_logfile({fname} [, {mode}]) *ch_logfile()*
Bram Moolenaar6463ca22016-02-13 17:04:46 +01002930 Start logging channel activity to {fname}.
Bram Moolenaar38a55632016-02-15 22:07:32 +01002931 When {fname} is an empty string: stop logging.
2932
Bram Moolenaar6463ca22016-02-13 17:04:46 +01002933 When {mode} is omitted or "a" append to the file.
2934 When {mode} is "w" start with an empty file.
Bram Moolenaar38a55632016-02-15 22:07:32 +01002935
2936 The file is flushed after every message, on Unix you can use
2937 "tail -f" to see what is going on in real time.
Bram Moolenaar6463ca22016-02-13 17:04:46 +01002938
Bram Moolenaar328da0d2016-03-04 22:22:32 +01002939
Bram Moolenaare0fa3742016-02-20 15:47:01 +01002940ch_open({address} [, {options}]) *ch_open()*
Bram Moolenaar3b5f9292016-01-28 22:37:01 +01002941 Open a channel to {address}. See |channel|.
Bram Moolenaar4f3f6682016-03-26 23:01:59 +01002942 Returns a Channel. Use |ch_status()| to check for failure.
Bram Moolenaar3b5f9292016-01-28 22:37:01 +01002943
2944 {address} has the form "hostname:port", e.g.,
2945 "localhost:8765".
2946
Bram Moolenaar4f3f6682016-03-26 23:01:59 +01002947 If {options} is given it must be a |Dictionary|.
2948 See |channel-open-options|.
2949
Bram Moolenaar835dc632016-02-07 14:27:38 +01002950 {only available when compiled with the |+channel| feature}
Bram Moolenaar3b5f9292016-01-28 22:37:01 +01002951
Bram Moolenaar5f148ec2016-03-07 22:59:26 +01002952ch_read({handle} [, {options}]) *ch_read()*
2953 Read from {handle} and return the received message.
2954 {handle} can be Channel or a Job that has a Channel.
Bram Moolenaar4f3f6682016-03-26 23:01:59 +01002955 See |channel-more|.
2956 {only available when compiled with the |+channel| feature}
Bram Moolenaar02e83b42016-02-21 20:10:26 +01002957
Bram Moolenaar5f148ec2016-03-07 22:59:26 +01002958ch_readraw({handle} [, {options}]) *ch_readraw()*
Bram Moolenaar02e83b42016-02-21 20:10:26 +01002959 Like ch_read() but for a JS and JSON channel does not decode
Bram Moolenaar4f3f6682016-03-26 23:01:59 +01002960 the message. See |channel-more|.
2961 {only available when compiled with the |+channel| feature}
Bram Moolenaar02e83b42016-02-21 20:10:26 +01002962
Bram Moolenaar5f148ec2016-03-07 22:59:26 +01002963ch_sendexpr({handle}, {expr} [, {options}]) *ch_sendexpr()*
2964 Send {expr} over {handle}. The {expr} is encoded
Bram Moolenaarcbebd482016-02-07 23:02:56 +01002965 according to the type of channel. The function cannot be used
Bram Moolenaar4f3f6682016-03-26 23:01:59 +01002966 with a raw channel.
2967 See |channel-use|. *E912*
Bram Moolenaar5f148ec2016-03-07 22:59:26 +01002968 {handle} can be Channel or a Job that has a Channel.
Bram Moolenaarf57969a2016-02-02 20:47:49 +01002969
Bram Moolenaar835dc632016-02-07 14:27:38 +01002970 {only available when compiled with the |+channel| feature}
2971
Bram Moolenaar5f148ec2016-03-07 22:59:26 +01002972ch_sendraw({handle}, {string} [, {options}]) *ch_sendraw()*
2973 Send {string} over {handle}.
Bram Moolenaarcbebd482016-02-07 23:02:56 +01002974 Works like |ch_sendexpr()|, but does not encode the request or
2975 decode the response. The caller is responsible for the
Bram Moolenaar910b8aa2016-02-16 21:03:07 +01002976 correct contents. Also does not add a newline for a channel
2977 in NL mode, the caller must do that. The NL in the response
2978 is removed.
2979 See |channel-use|.
Bram Moolenaarf57969a2016-02-02 20:47:49 +01002980
Bram Moolenaar835dc632016-02-07 14:27:38 +01002981 {only available when compiled with the |+channel| feature}
2982
Bram Moolenaar5f148ec2016-03-07 22:59:26 +01002983ch_setoptions({handle}, {options}) *ch_setoptions()*
2984 Set options on {handle}:
Bram Moolenaare0fa3742016-02-20 15:47:01 +01002985 "callback" the channel callback
2986 "timeout" default read timeout in msec
Bram Moolenaar02e83b42016-02-21 20:10:26 +01002987 "mode" mode for the whole channel
Bram Moolenaare0fa3742016-02-20 15:47:01 +01002988 See |ch_open()| for more explanation.
Bram Moolenaar5f148ec2016-03-07 22:59:26 +01002989 {handle} can be Channel or a Job that has a Channel.
Bram Moolenaare0fa3742016-02-20 15:47:01 +01002990
Bram Moolenaar02e83b42016-02-21 20:10:26 +01002991 Note that changing the mode may cause queued messages to be
2992 lost.
2993
Bram Moolenaare0fa3742016-02-20 15:47:01 +01002994 These options cannot be changed:
Bram Moolenaare0fa3742016-02-20 15:47:01 +01002995 "waittime" only applies to "ch_open()|
2996
Bram Moolenaar5f148ec2016-03-07 22:59:26 +01002997ch_status({handle}) *ch_status()*
2998 Return the status of {handle}:
Bram Moolenaar38a55632016-02-15 22:07:32 +01002999 "fail" failed to open the channel
3000 "open" channel can be used
Bram Moolenaar06481422016-04-30 15:13:38 +02003001 "buffered" channel can be read, not written to
Bram Moolenaar38a55632016-02-15 22:07:32 +01003002 "closed" channel can not be used
Bram Moolenaar5f148ec2016-03-07 22:59:26 +01003003 {handle} can be Channel or a Job that has a Channel.
Bram Moolenaar06481422016-04-30 15:13:38 +02003004 "buffered" is used when the channel was closed but there is
3005 still data that can be obtained with |ch_read()|.
Bram Moolenaar38a55632016-02-15 22:07:32 +01003006
Bram Moolenaard7ee7ce2005-01-03 21:02:03 +00003007 *copy()*
Bram Moolenaar446cb832008-06-24 21:56:24 +00003008copy({expr}) Make a copy of {expr}. For Numbers and Strings this isn't
Bram Moolenaard7ee7ce2005-01-03 21:02:03 +00003009 different from using {expr} directly.
Bram Moolenaar32466aa2006-02-24 23:53:04 +00003010 When {expr} is a |List| a shallow copy is created. This means
3011 that the original |List| can be changed without changing the
Bram Moolenaar446cb832008-06-24 21:56:24 +00003012 copy, and vice versa. But the items are identical, thus
Bram Moolenaar7823a3b2016-02-11 21:08:32 +01003013 changing an item changes the contents of both |Lists|.
3014 A |Dictionary| is copied in a similar way as a |List|.
3015 Also see |deepcopy()|.
Bram Moolenaard7ee7ce2005-01-03 21:02:03 +00003016
Bram Moolenaar446cb832008-06-24 21:56:24 +00003017cos({expr}) *cos()*
3018 Return the cosine of {expr}, measured in radians, as a |Float|.
3019 {expr} must evaluate to a |Float| or a |Number|.
3020 Examples: >
3021 :echo cos(100)
3022< 0.862319 >
3023 :echo cos(-4.01)
3024< -0.646043
3025 {only available when compiled with the |+float| feature}
3026
Bram Moolenaardb7c6862010-05-21 16:33:48 +02003027
3028cosh({expr}) *cosh()*
Bram Moolenaar9855d6b2010-07-18 14:34:51 +02003029 Return the hyperbolic cosine of {expr} as a |Float| in the range
Bram Moolenaardb7c6862010-05-21 16:33:48 +02003030 [1, inf].
Bram Moolenaar9855d6b2010-07-18 14:34:51 +02003031 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaardb7c6862010-05-21 16:33:48 +02003032 Examples: >
3033 :echo cosh(0.5)
3034< 1.127626 >
3035 :echo cosh(-0.5)
3036< -1.127626
Bram Moolenaardb84e452010-08-15 13:50:43 +02003037 {only available when compiled with the |+float| feature}
Bram Moolenaardb7c6862010-05-21 16:33:48 +02003038
Bram Moolenaar446cb832008-06-24 21:56:24 +00003039
Bram Moolenaar2fda12f2005-01-15 22:14:15 +00003040count({comp}, {expr} [, {ic} [, {start}]]) *count()*
Bram Moolenaarde8866b2005-01-06 23:24:37 +00003041 Return the number of times an item with value {expr} appears
Bram Moolenaar32466aa2006-02-24 23:53:04 +00003042 in |List| or |Dictionary| {comp}.
Bram Moolenaar2fda12f2005-01-15 22:14:15 +00003043 If {start} is given then start with the item with this index.
Bram Moolenaar32466aa2006-02-24 23:53:04 +00003044 {start} can only be used with a |List|.
Bram Moolenaarde8866b2005-01-06 23:24:37 +00003045 When {ic} is given and it's non-zero then case is ignored.
3046
3047
Bram Moolenaar071d4272004-06-13 20:20:40 +00003048 *cscope_connection()*
3049cscope_connection([{num} , {dbpath} [, {prepend}]])
3050 Checks for the existence of a |cscope| connection. If no
3051 parameters are specified, then the function returns:
3052 0, if cscope was not available (not compiled in), or
3053 if there are no cscope connections;
3054 1, if there is at least one cscope connection.
3055
3056 If parameters are specified, then the value of {num}
3057 determines how existence of a cscope connection is checked:
3058
3059 {num} Description of existence check
3060 ----- ------------------------------
3061 0 Same as no parameters (e.g., "cscope_connection()").
3062 1 Ignore {prepend}, and use partial string matches for
3063 {dbpath}.
3064 2 Ignore {prepend}, and use exact string matches for
3065 {dbpath}.
3066 3 Use {prepend}, use partial string matches for both
3067 {dbpath} and {prepend}.
3068 4 Use {prepend}, use exact string matches for both
3069 {dbpath} and {prepend}.
3070
3071 Note: All string comparisons are case sensitive!
3072
3073 Examples. Suppose we had the following (from ":cs show"): >
3074
3075 # pid database name prepend path
3076 0 27664 cscope.out /usr/local
3077<
3078 Invocation Return Val ~
3079 ---------- ---------- >
3080 cscope_connection() 1
3081 cscope_connection(1, "out") 1
3082 cscope_connection(2, "out") 0
3083 cscope_connection(3, "out") 0
3084 cscope_connection(3, "out", "local") 1
3085 cscope_connection(4, "out") 0
3086 cscope_connection(4, "out", "local") 0
3087 cscope_connection(4, "cscope.out", "/usr/local") 1
3088<
Bram Moolenaar0b238792006-03-02 22:49:12 +00003089cursor({lnum}, {col} [, {off}]) *cursor()*
3090cursor({list})
Bram Moolenaaref2f6562007-05-06 13:32:59 +00003091 Positions the cursor at the column (byte count) {col} in the
3092 line {lnum}. The first column is one.
Bram Moolenaar493c1782014-05-28 14:34:46 +02003093
Bram Moolenaar0b238792006-03-02 22:49:12 +00003094 When there is one argument {list} this is used as a |List|
Bram Moolenaar493c1782014-05-28 14:34:46 +02003095 with two, three or four item:
Bram Moolenaar03413f42016-04-12 21:07:15 +02003096 [{lnum}, {col}]
Bram Moolenaar493c1782014-05-28 14:34:46 +02003097 [{lnum}, {col}, {off}]
3098 [{lnum}, {col}, {off}, {curswant}]
Bram Moolenaar946e27a2014-06-25 18:50:27 +02003099 This is like the return value of |getpos()| or |getcurpos()|,
Bram Moolenaar6f6c0f82014-05-28 20:31:42 +02003100 but without the first item.
Bram Moolenaar493c1782014-05-28 14:34:46 +02003101
Bram Moolenaar071d4272004-06-13 20:20:40 +00003102 Does not change the jumplist.
3103 If {lnum} is greater than the number of lines in the buffer,
3104 the cursor will be positioned at the last line in the buffer.
3105 If {lnum} is zero, the cursor will stay in the current line.
Bram Moolenaar6f16eb82005-08-23 21:02:42 +00003106 If {col} is greater than the number of bytes in the line,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003107 the cursor will be positioned at the last character in the
3108 line.
3109 If {col} is zero, the cursor will stay in the current column.
Bram Moolenaar6f6c0f82014-05-28 20:31:42 +02003110 If {curswant} is given it is used to set the preferred column
Bram Moolenaar34401cc2014-08-29 15:12:19 +02003111 for vertical movement. Otherwise {col} is used.
Bram Moolenaar2f3b5102014-11-19 18:54:17 +01003112
Bram Moolenaar0b238792006-03-02 22:49:12 +00003113 When 'virtualedit' is used {off} specifies the offset in
3114 screen columns from the start of the character. E.g., a
Bram Moolenaard46bbc72007-05-12 14:38:41 +00003115 position within a <Tab> or after the last character.
Bram Moolenaar798b30b2009-04-22 10:56:16 +00003116 Returns 0 when the position could be set, -1 otherwise.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003117
Bram Moolenaard7ee7ce2005-01-03 21:02:03 +00003118
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003119deepcopy({expr}[, {noref}]) *deepcopy()* *E698*
Bram Moolenaar446cb832008-06-24 21:56:24 +00003120 Make a copy of {expr}. For Numbers and Strings this isn't
Bram Moolenaard7ee7ce2005-01-03 21:02:03 +00003121 different from using {expr} directly.
Bram Moolenaar32466aa2006-02-24 23:53:04 +00003122 When {expr} is a |List| a full copy is created. This means
3123 that the original |List| can be changed without changing the
Bram Moolenaar6463ca22016-02-13 17:04:46 +01003124 copy, and vice versa. When an item is a |List| or
3125 |Dictionary|, a copy for it is made, recursively. Thus
3126 changing an item in the copy does not change the contents of
3127 the original |List|.
3128 A |Dictionary| is copied in a similar way as a |List|.
Bram Moolenaar32466aa2006-02-24 23:53:04 +00003129 When {noref} is omitted or zero a contained |List| or
3130 |Dictionary| is only copied once. All references point to
3131 this single copy. With {noref} set to 1 every occurrence of a
3132 |List| or |Dictionary| results in a new copy. This also means
3133 that a cyclic reference causes deepcopy() to fail.
Bram Moolenaar3a3a7232005-01-17 22:16:15 +00003134 *E724*
3135 Nesting is possible up to 100 levels. When there is an item
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003136 that refers back to a higher level making a deep copy with
3137 {noref} set to 1 will fail.
Bram Moolenaard7ee7ce2005-01-03 21:02:03 +00003138 Also see |copy()|.
3139
Bram Moolenaarda440d22016-01-16 21:27:23 +01003140delete({fname} [, {flags}]) *delete()*
3141 Without {flags} or with {flags} empty: Deletes the file by the
Bram Moolenaar43a34f92016-01-17 15:56:34 +01003142 name {fname}. This also works when {fname} is a symbolic link.
Bram Moolenaarda440d22016-01-16 21:27:23 +01003143
3144 When {flags} is "d": Deletes the directory by the name
Bram Moolenaar43a34f92016-01-17 15:56:34 +01003145 {fname}. This fails when directory {fname} is not empty.
Bram Moolenaarda440d22016-01-16 21:27:23 +01003146
3147 When {flags} is "rf": Deletes the directory by the name
Bram Moolenaar43a34f92016-01-17 15:56:34 +01003148 {fname} and everything in it, recursively. BE CAREFUL!
3149 A symbolic link itself is deleted, not what it points to.
Bram Moolenaarda440d22016-01-16 21:27:23 +01003150
3151 The result is a Number, which is 0 if the delete operation was
3152 successful and -1 when the deletion failed or partly failed.
3153
Bram Moolenaar32466aa2006-02-24 23:53:04 +00003154 Use |remove()| to delete an item from a |List|.
Bram Moolenaarac7bd632013-03-19 11:35:58 +01003155 To delete a line from the buffer use |:delete|. Use |:exe|
3156 when the line number is in a variable.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003157
3158 *did_filetype()*
3159did_filetype() Returns non-zero when autocommands are being executed and the
3160 FileType event has been triggered at least once. Can be used
3161 to avoid triggering the FileType event again in the scripts
3162 that detect the file type. |FileType|
3163 When editing another file, the counter is reset, thus this
3164 really checks if the FileType event has been triggered for the
3165 current buffer. This allows an autocommand that starts
3166 editing another buffer to set 'filetype' and load a syntax
3167 file.
3168
Bram Moolenaar47136d72004-10-12 20:02:24 +00003169diff_filler({lnum}) *diff_filler()*
3170 Returns the number of filler lines above line {lnum}.
3171 These are the lines that were inserted at this point in
3172 another diff'ed window. These filler lines are shown in the
3173 display but don't exist in the buffer.
3174 {lnum} is used like with |getline()|. Thus "." is the current
3175 line, "'m" mark m, etc.
3176 Returns 0 if the current window is not in diff mode.
3177
3178diff_hlID({lnum}, {col}) *diff_hlID()*
3179 Returns the highlight ID for diff mode at line {lnum} column
3180 {col} (byte index). When the current line does not have a
3181 diff change zero is returned.
3182 {lnum} is used like with |getline()|. Thus "." is the current
3183 line, "'m" mark m, etc.
3184 {col} is 1 for the leftmost column, {lnum} is 1 for the first
3185 line.
3186 The highlight ID can be used with |synIDattr()| to obtain
3187 syntax information about the highlighting.
3188
Bram Moolenaar13065c42005-01-08 16:08:21 +00003189empty({expr}) *empty()*
3190 Return the Number 1 if {expr} is empty, zero otherwise.
Bram Moolenaar835dc632016-02-07 14:27:38 +01003191 - A |List| or |Dictionary| is empty when it does not have any
3192 items.
3193 - A Number and Float is empty when its value is zero.
3194 - |v:false|, |v:none| and |v:null| are empty, |v:true| is not.
3195 - A Job is empty when it failed to start.
Bram Moolenaar38a55632016-02-15 22:07:32 +01003196 - A Channel is empty when it is closed.
Bram Moolenaar835dc632016-02-07 14:27:38 +01003197
Bram Moolenaar8f3f58f2010-01-06 20:52:26 +01003198 For a long |List| this is much faster than comparing the
Bram Moolenaar32466aa2006-02-24 23:53:04 +00003199 length with zero.
Bram Moolenaar13065c42005-01-08 16:08:21 +00003200
Bram Moolenaar071d4272004-06-13 20:20:40 +00003201escape({string}, {chars}) *escape()*
3202 Escape the characters in {chars} that occur in {string} with a
3203 backslash. Example: >
3204 :echo escape('c:\program files\vim', ' \')
3205< results in: >
3206 c:\\program\ files\\vim
Bram Moolenaar446cb832008-06-24 21:56:24 +00003207< Also see |shellescape()|.
Bram Moolenaar5f2bb9f2005-01-11 21:29:04 +00003208
Bram Moolenaar446cb832008-06-24 21:56:24 +00003209 *eval()*
Bram Moolenaar5f2bb9f2005-01-11 21:29:04 +00003210eval({string}) Evaluate {string} and return the result. Especially useful to
3211 turn the result of |string()| back into the original value.
Bram Moolenaar446cb832008-06-24 21:56:24 +00003212 This works for Numbers, Floats, Strings and composites of
3213 them. Also works for |Funcref|s that refer to existing
3214 functions.
Bram Moolenaar5f2bb9f2005-01-11 21:29:04 +00003215
Bram Moolenaar071d4272004-06-13 20:20:40 +00003216eventhandler() *eventhandler()*
3217 Returns 1 when inside an event handler. That is that Vim got
3218 interrupted while waiting for the user to type a character,
3219 e.g., when dropping a file on Vim. This means interactive
3220 commands cannot be used. Otherwise zero is returned.
3221
3222executable({expr}) *executable()*
3223 This function checks if an executable with the name {expr}
3224 exists. {expr} must be the name of the program without any
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003225 arguments.
3226 executable() uses the value of $PATH and/or the normal
3227 searchpath for programs. *PATHEXT*
3228 On MS-DOS and MS-Windows the ".exe", ".bat", etc. can
3229 optionally be included. Then the extensions in $PATHEXT are
Bram Moolenaar446cb832008-06-24 21:56:24 +00003230 tried. Thus if "foo.exe" does not exist, "foo.exe.bat" can be
3231 found. If $PATHEXT is not set then ".exe;.com;.bat;.cmd" is
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003232 used. A dot by itself can be used in $PATHEXT to try using
Bram Moolenaar446cb832008-06-24 21:56:24 +00003233 the name without an extension. When 'shell' looks like a
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003234 Unix shell, then the name is also tried without adding an
3235 extension.
3236 On MS-DOS and MS-Windows it only checks if the file exists and
3237 is not a directory, not if it's really executable.
Bram Moolenaar910f66f2006-04-05 20:41:53 +00003238 On MS-Windows an executable in the same directory as Vim is
3239 always found. Since this directory is added to $PATH it
3240 should also work to execute it |win32-PATH|.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003241 The result is a Number:
3242 1 exists
3243 0 does not exist
3244 -1 not implemented on this system
3245
Bram Moolenaarc7f02552014-04-01 21:00:59 +02003246exepath({expr}) *exepath()*
3247 If {expr} is an executable and is either an absolute path, a
3248 relative path or found in $PATH, return the full path.
3249 Note that the current directory is used when {expr} starts
3250 with "./", which may be a problem for Vim: >
3251 echo exepath(v:progpath)
Bram Moolenaar7e38ea22014-04-05 22:55:53 +02003252< If {expr} cannot be found in $PATH or is not executable then
Bram Moolenaarc7f02552014-04-01 21:00:59 +02003253 an empty string is returned.
3254
Bram Moolenaar071d4272004-06-13 20:20:40 +00003255 *exists()*
3256exists({expr}) The result is a Number, which is non-zero if {expr} is
3257 defined, zero otherwise. The {expr} argument is a string,
3258 which contains one of these:
3259 &option-name Vim option (only checks if it exists,
3260 not if it really works)
3261 +option-name Vim option that works.
3262 $ENVNAME environment variable (could also be
3263 done by comparing with an empty
3264 string)
3265 *funcname built-in function (see |functions|)
3266 or user defined function (see
Bram Moolenaarbcb98982014-05-01 14:08:19 +02003267 |user-functions|). Also works for a
3268 variable that is a Funcref.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003269 varname internal variable (see
Bram Moolenaar446cb832008-06-24 21:56:24 +00003270 |internal-variables|). Also works
Bram Moolenaar32466aa2006-02-24 23:53:04 +00003271 for |curly-braces-names|, |Dictionary|
3272 entries, |List| items, etc. Beware
Bram Moolenaarc236c162008-07-13 17:41:49 +00003273 that evaluating an index may cause an
3274 error message for an invalid
3275 expression. E.g.: >
3276 :let l = [1, 2, 3]
3277 :echo exists("l[5]")
3278< 0 >
3279 :echo exists("l[xx]")
3280< E121: Undefined variable: xx
3281 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00003282 :cmdname Ex command: built-in command, user
3283 command or command modifier |:command|.
3284 Returns:
3285 1 for match with start of a command
3286 2 full match with a command
3287 3 matches several user commands
3288 To check for a supported command
3289 always check the return value to be 2.
Bram Moolenaar14716812006-05-04 21:54:08 +00003290 :2match The |:2match| command.
3291 :3match The |:3match| command.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003292 #event autocommand defined for this event
3293 #event#pattern autocommand defined for this event and
3294 pattern (the pattern is taken
3295 literally and compared to the
3296 autocommand patterns character by
3297 character)
Bram Moolenaara9b1e742005-12-19 22:14:58 +00003298 #group autocommand group exists
3299 #group#event autocommand defined for this group and
3300 event.
3301 #group#event#pattern
Bram Moolenaarc9b4b052006-04-30 18:54:39 +00003302 autocommand defined for this group,
Bram Moolenaara9b1e742005-12-19 22:14:58 +00003303 event and pattern.
Bram Moolenaarf4cd3e82005-12-22 22:47:02 +00003304 ##event autocommand for this event is
3305 supported.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003306 For checking for a supported feature use |has()|.
3307
3308 Examples: >
3309 exists("&shortname")
3310 exists("$HOSTNAME")
3311 exists("*strftime")
3312 exists("*s:MyFunc")
3313 exists("bufcount")
3314 exists(":Make")
Bram Moolenaara9b1e742005-12-19 22:14:58 +00003315 exists("#CursorHold")
Bram Moolenaar071d4272004-06-13 20:20:40 +00003316 exists("#BufReadPre#*.gz")
Bram Moolenaara9b1e742005-12-19 22:14:58 +00003317 exists("#filetypeindent")
3318 exists("#filetypeindent#FileType")
3319 exists("#filetypeindent#FileType#*")
Bram Moolenaarf4cd3e82005-12-22 22:47:02 +00003320 exists("##ColorScheme")
Bram Moolenaar071d4272004-06-13 20:20:40 +00003321< There must be no space between the symbol (&/$/*/#) and the
3322 name.
Bram Moolenaar91170f82006-05-05 21:15:17 +00003323 There must be no extra characters after the name, although in
3324 a few cases this is ignored. That may become more strict in
3325 the future, thus don't count on it!
3326 Working example: >
3327 exists(":make")
3328< NOT working example: >
3329 exists(":make install")
Bram Moolenaar9c102382006-05-03 21:26:49 +00003330
3331< Note that the argument must be a string, not the name of the
3332 variable itself. For example: >
Bram Moolenaar071d4272004-06-13 20:20:40 +00003333 exists(bufcount)
3334< This doesn't check for existence of the "bufcount" variable,
Bram Moolenaar06a89a52006-04-29 22:01:03 +00003335 but gets the value of "bufcount", and checks if that exists.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003336
Bram Moolenaardb7c6862010-05-21 16:33:48 +02003337exp({expr}) *exp()*
Bram Moolenaar9855d6b2010-07-18 14:34:51 +02003338 Return the exponential of {expr} as a |Float| in the range
Bram Moolenaardb7c6862010-05-21 16:33:48 +02003339 [0, inf].
Bram Moolenaar9855d6b2010-07-18 14:34:51 +02003340 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaardb7c6862010-05-21 16:33:48 +02003341 Examples: >
3342 :echo exp(2)
3343< 7.389056 >
3344 :echo exp(-1)
3345< 0.367879
Bram Moolenaardb84e452010-08-15 13:50:43 +02003346 {only available when compiled with the |+float| feature}
Bram Moolenaardb7c6862010-05-21 16:33:48 +02003347
3348
Bram Moolenaar84f72352012-03-11 15:57:40 +01003349expand({expr} [, {nosuf} [, {list}]]) *expand()*
Bram Moolenaar071d4272004-06-13 20:20:40 +00003350 Expand wildcards and the following special keywords in {expr}.
Bram Moolenaar84f72352012-03-11 15:57:40 +01003351 'wildignorecase' applies.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003352
Bram Moolenaar84f72352012-03-11 15:57:40 +01003353 If {list} is given and it is non-zero, a List will be returned.
3354 Otherwise the result is a String and when there are several
3355 matches, they are separated by <NL> characters. [Note: in
3356 version 5.0 a space was used, which caused problems when a
3357 file name contains a space]
Bram Moolenaar071d4272004-06-13 20:20:40 +00003358
Bram Moolenaar446cb832008-06-24 21:56:24 +00003359 If the expansion fails, the result is an empty string. A name
Bram Moolenaarec7944a2013-06-12 21:29:15 +02003360 for a non-existing file is not included, unless {expr} does
3361 not start with '%', '#' or '<', see below.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003362
3363 When {expr} starts with '%', '#' or '<', the expansion is done
3364 like for the |cmdline-special| variables with their associated
3365 modifiers. Here is a short overview:
3366
3367 % current file name
3368 # alternate file name
3369 #n alternate file name n
3370 <cfile> file name under the cursor
3371 <afile> autocmd file name
3372 <abuf> autocmd buffer number (as a String!)
3373 <amatch> autocmd matched name
Bram Moolenaara6878372014-03-22 21:02:50 +01003374 <sfile> sourced script file or function name
Bram Moolenaar81af9252010-12-10 20:35:50 +01003375 <slnum> sourced script file line number
Bram Moolenaar071d4272004-06-13 20:20:40 +00003376 <cword> word under the cursor
3377 <cWORD> WORD under the cursor
3378 <client> the {clientid} of the last received
3379 message |server2client()|
3380 Modifiers:
3381 :p expand to full path
3382 :h head (last path component removed)
3383 :t tail (last path component only)
3384 :r root (one extension removed)
3385 :e extension only
3386
3387 Example: >
3388 :let &tags = expand("%:p:h") . "/tags"
3389< Note that when expanding a string that starts with '%', '#' or
3390 '<', any following text is ignored. This does NOT work: >
3391 :let doesntwork = expand("%:h.bak")
3392< Use this: >
3393 :let doeswork = expand("%:h") . ".bak"
3394< Also note that expanding "<cfile>" and others only returns the
3395 referenced file name without further expansion. If "<cfile>"
3396 is "~/.cshrc", you need to do another expand() to have the
3397 "~/" expanded into the path of the home directory: >
3398 :echo expand(expand("<cfile>"))
3399<
3400 There cannot be white space between the variables and the
3401 following modifier. The |fnamemodify()| function can be used
3402 to modify normal file names.
3403
3404 When using '%' or '#', and the current or alternate file name
3405 is not defined, an empty string is used. Using "%:p" in a
3406 buffer with no name, results in the current directory, with a
3407 '/' added.
3408
3409 When {expr} does not start with '%', '#' or '<', it is
3410 expanded like a file name is expanded on the command line.
3411 'suffixes' and 'wildignore' are used, unless the optional
Bram Moolenaar146e9c32012-03-07 19:18:23 +01003412 {nosuf} argument is given and it is non-zero.
3413 Names for non-existing files are included. The "**" item can
3414 be used to search in a directory tree. For example, to find
3415 all "README" files in the current directory and below: >
Bram Moolenaar02743632005-07-25 20:42:36 +00003416 :echo expand("**/README")
3417<
Bram Moolenaar071d4272004-06-13 20:20:40 +00003418 Expand() can also be used to expand variables and environment
3419 variables that are only known in a shell. But this can be
Bram Moolenaar34401cc2014-08-29 15:12:19 +02003420 slow, because a shell may be used to do the expansion. See
3421 |expr-env-expand|.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003422 The expanded variable is still handled like a list of file
Bram Moolenaar446cb832008-06-24 21:56:24 +00003423 names. When an environment variable cannot be expanded, it is
Bram Moolenaar071d4272004-06-13 20:20:40 +00003424 left unchanged. Thus ":echo expand('$FOOBAR')" results in
3425 "$FOOBAR".
3426
3427 See |glob()| for finding existing files. See |system()| for
3428 getting the raw output of an external command.
3429
Bram Moolenaar2fda12f2005-01-15 22:14:15 +00003430extend({expr1}, {expr2} [, {expr3}]) *extend()*
Bram Moolenaara23ccb82006-02-27 00:08:02 +00003431 {expr1} and {expr2} must be both |Lists| or both
3432 |Dictionaries|.
Bram Moolenaar2fda12f2005-01-15 22:14:15 +00003433
Bram Moolenaara23ccb82006-02-27 00:08:02 +00003434 If they are |Lists|: Append {expr2} to {expr1}.
Bram Moolenaar2fda12f2005-01-15 22:14:15 +00003435 If {expr3} is given insert the items of {expr2} before item
3436 {expr3} in {expr1}. When {expr3} is zero insert before the
3437 first item. When {expr3} is equal to len({expr1}) then
3438 {expr2} is appended.
Bram Moolenaarde8866b2005-01-06 23:24:37 +00003439 Examples: >
3440 :echo sort(extend(mylist, [7, 5]))
3441 :call extend(mylist, [2, 3], 1)
Bram Moolenaardc9cf9c2008-08-08 10:36:31 +00003442< When {expr1} is the same List as {expr2} then the number of
3443 items copied is equal to the original length of the List.
3444 E.g., when {expr3} is 1 you get N new copies of the first item
3445 (where N is the original length of the List).
3446 Use |add()| to concatenate one item to a list. To concatenate
Bram Moolenaara14de3d2005-01-07 21:48:26 +00003447 two lists into a new list use the + operator: >
Bram Moolenaarde8866b2005-01-06 23:24:37 +00003448 :let newlist = [1, 2, 3] + [4, 5]
Bram Moolenaar2fda12f2005-01-15 22:14:15 +00003449<
Bram Moolenaara23ccb82006-02-27 00:08:02 +00003450 If they are |Dictionaries|:
Bram Moolenaar2fda12f2005-01-15 22:14:15 +00003451 Add all entries from {expr2} to {expr1}.
3452 If a key exists in both {expr1} and {expr2} then {expr3} is
3453 used to decide what to do:
3454 {expr3} = "keep": keep the value of {expr1}
3455 {expr3} = "force": use the value of {expr2}
Bram Moolenaarc9b4b052006-04-30 18:54:39 +00003456 {expr3} = "error": give an error message *E737*
Bram Moolenaar2fda12f2005-01-15 22:14:15 +00003457 When {expr3} is omitted then "force" is assumed.
3458
3459 {expr1} is changed when {expr2} is not empty. If necessary
3460 make a copy of {expr1} first.
3461 {expr2} remains unchanged.
Bram Moolenaarf2571c62015-06-09 19:44:55 +02003462 When {expr1} is locked and {expr2} is not empty the operation
3463 fails.
Bram Moolenaar2fda12f2005-01-15 22:14:15 +00003464 Returns {expr1}.
3465
Bram Moolenaarde8866b2005-01-06 23:24:37 +00003466
Bram Moolenaarf9393ef2006-04-24 19:47:27 +00003467feedkeys({string} [, {mode}]) *feedkeys()*
3468 Characters in {string} are queued for processing as if they
Bram Moolenaar0a988df2015-01-27 15:19:24 +01003469 come from a mapping or were typed by the user.
3470 By default the string is added to the end of the typeahead
3471 buffer, thus if a mapping is still being executed the
3472 characters come after them. Use the 'i' flag to insert before
3473 other characters, they will be executed next, before any
3474 characters from a mapping.
Bram Moolenaarf9393ef2006-04-24 19:47:27 +00003475 The function does not wait for processing of keys contained in
3476 {string}.
3477 To include special keys into {string}, use double-quotes
3478 and "\..." notation |expr-quote|. For example,
Bram Moolenaar79166c42007-05-10 18:29:51 +00003479 feedkeys("\<CR>") simulates pressing of the <Enter> key. But
Bram Moolenaarf9393ef2006-04-24 19:47:27 +00003480 feedkeys('\<CR>') pushes 5 characters.
3481 If {mode} is absent, keys are remapped.
3482 {mode} is a String, which can contain these character flags:
Bram Moolenaar551dbcc2006-04-25 22:13:59 +00003483 'm' Remap keys. This is default.
3484 'n' Do not remap keys.
3485 't' Handle keys as if typed; otherwise they are handled as
3486 if coming from a mapping. This matters for undo,
3487 opening folds, etc.
Bram Moolenaar0a988df2015-01-27 15:19:24 +01003488 'i' Insert the string instead of appending (see above).
Bram Moolenaar25281632016-01-21 23:32:32 +01003489 'x' Execute commands until typeahead is empty. This is
3490 similar to using ":normal!". You can call feedkeys()
3491 several times without 'x' and then one time with 'x'
3492 (possibly with an empty {string}) to execute all the
Bram Moolenaar03413f42016-04-12 21:07:15 +02003493 typeahead. Note that when Vim ends in Insert mode it
3494 will behave as if <Esc> is typed, to avoid getting
3495 stuck, waiting for a character to be typed before the
3496 script continues.
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02003497 '!' When used with 'x' will not end Insert mode. Can be
3498 used in a test when a timer is set to exit Insert mode
3499 a little later. Useful for testing CursorHoldI.
3500
Bram Moolenaarf9393ef2006-04-24 19:47:27 +00003501 Return value is always 0.
3502
Bram Moolenaar071d4272004-06-13 20:20:40 +00003503filereadable({file}) *filereadable()*
3504 The result is a Number, which is TRUE when a file with the
3505 name {file} exists, and can be read. If {file} doesn't exist,
3506 or is a directory, the result is FALSE. {file} is any
3507 expression, which is used as a String.
Bram Moolenaaref2f6562007-05-06 13:32:59 +00003508 If you don't care about the file being readable you can use
3509 |glob()|.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003510 *file_readable()*
3511 Obsolete name: file_readable().
3512
Bram Moolenaar5f2bb9f2005-01-11 21:29:04 +00003513
Bram Moolenaaref2f6562007-05-06 13:32:59 +00003514filewritable({file}) *filewritable()*
3515 The result is a Number, which is 1 when a file with the
3516 name {file} exists, and can be written. If {file} doesn't
Bram Moolenaar446cb832008-06-24 21:56:24 +00003517 exist, or is not writable, the result is 0. If {file} is a
Bram Moolenaaref2f6562007-05-06 13:32:59 +00003518 directory, and we can write to it, the result is 2.
3519
3520
Bram Moolenaar2fda12f2005-01-15 22:14:15 +00003521filter({expr}, {string}) *filter()*
Bram Moolenaar32466aa2006-02-24 23:53:04 +00003522 {expr} must be a |List| or a |Dictionary|.
Bram Moolenaar2fda12f2005-01-15 22:14:15 +00003523 For each item in {expr} evaluate {string} and when the result
Bram Moolenaar32466aa2006-02-24 23:53:04 +00003524 is zero remove the item from the |List| or |Dictionary|.
Bram Moolenaar2fda12f2005-01-15 22:14:15 +00003525 Inside {string} |v:val| has the value of the current item.
Bram Moolenaar32466aa2006-02-24 23:53:04 +00003526 For a |Dictionary| |v:key| has the key of the current item.
Bram Moolenaar2fda12f2005-01-15 22:14:15 +00003527 Examples: >
3528 :call filter(mylist, 'v:val !~ "OLD"')
3529< Removes the items where "OLD" appears. >
3530 :call filter(mydict, 'v:key >= 8')
3531< Removes the items with a key below 8. >
3532 :call filter(var, 0)
Bram Moolenaar32466aa2006-02-24 23:53:04 +00003533< Removes all the items, thus clears the |List| or |Dictionary|.
Bram Moolenaard8b02732005-01-14 21:48:43 +00003534
Bram Moolenaar2fda12f2005-01-15 22:14:15 +00003535 Note that {string} is the result of expression and is then
3536 used as an expression again. Often it is good to use a
3537 |literal-string| to avoid having to double backslashes.
3538
Bram Moolenaar32466aa2006-02-24 23:53:04 +00003539 The operation is done in-place. If you want a |List| or
3540 |Dictionary| to remain unmodified make a copy first: >
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00003541 :let l = filter(copy(mylist), 'v:val =~ "KEEP"')
Bram Moolenaar2fda12f2005-01-15 22:14:15 +00003542
Bram Moolenaar32466aa2006-02-24 23:53:04 +00003543< Returns {expr}, the |List| or |Dictionary| that was filtered.
Bram Moolenaar280f1262006-01-30 00:14:18 +00003544 When an error is encountered while evaluating {string} no
3545 further items in {expr} are processed.
Bram Moolenaar5f2bb9f2005-01-11 21:29:04 +00003546
3547
Bram Moolenaar89cb5e02004-07-19 20:55:54 +00003548finddir({name}[, {path}[, {count}]]) *finddir()*
Bram Moolenaar5b6b1ca2007-03-27 08:19:43 +00003549 Find directory {name} in {path}. Supports both downwards and
3550 upwards recursive directory searches. See |file-searching|
3551 for the syntax of {path}.
3552 Returns the path of the first found match. When the found
3553 directory is below the current directory a relative path is
3554 returned. Otherwise a full path is returned.
Bram Moolenaar89cb5e02004-07-19 20:55:54 +00003555 If {path} is omitted or empty then 'path' is used.
3556 If the optional {count} is given, find {count}'s occurrence of
Bram Moolenaar433f7c82006-03-21 21:29:36 +00003557 {name} in {path} instead of the first one.
Bram Moolenaar899dddf2006-03-26 21:06:50 +00003558 When {count} is negative return all the matches in a |List|.
Bram Moolenaar89cb5e02004-07-19 20:55:54 +00003559 This is quite similar to the ex-command |:find|.
Bram Moolenaardb84e452010-08-15 13:50:43 +02003560 {only available when compiled with the |+file_in_path|
3561 feature}
Bram Moolenaar89cb5e02004-07-19 20:55:54 +00003562
3563findfile({name}[, {path}[, {count}]]) *findfile()*
3564 Just like |finddir()|, but find a file instead of a directory.
Bram Moolenaar433f7c82006-03-21 21:29:36 +00003565 Uses 'suffixesadd'.
3566 Example: >
3567 :echo findfile("tags.vim", ".;")
Bram Moolenaaref2f6562007-05-06 13:32:59 +00003568< Searches from the directory of the current file upwards until
3569 it finds the file "tags.vim".
Bram Moolenaar071d4272004-06-13 20:20:40 +00003570
Bram Moolenaar446cb832008-06-24 21:56:24 +00003571float2nr({expr}) *float2nr()*
3572 Convert {expr} to a Number by omitting the part after the
3573 decimal point.
3574 {expr} must evaluate to a |Float| or a Number.
3575 When the value of {expr} is out of range for a |Number| the
Bram Moolenaar22fcfad2016-07-01 18:17:26 +02003576 result is truncated to 0x7fffffff or -0x7fffffff (or when
3577 64-bit Number support is enabled, 0x7fffffffffffffff or
3578 -0x7fffffffffffffff. NaN results in -0x80000000 (or when
3579 64-bit Number support is enabled, -0x8000000000000000).
Bram Moolenaar446cb832008-06-24 21:56:24 +00003580 Examples: >
3581 echo float2nr(3.95)
3582< 3 >
3583 echo float2nr(-23.45)
3584< -23 >
3585 echo float2nr(1.0e100)
Bram Moolenaar22fcfad2016-07-01 18:17:26 +02003586< 2147483647 (or 9223372036854775807) >
Bram Moolenaar446cb832008-06-24 21:56:24 +00003587 echo float2nr(-1.0e150)
Bram Moolenaar22fcfad2016-07-01 18:17:26 +02003588< -2147483647 (or -9223372036854775807) >
Bram Moolenaar446cb832008-06-24 21:56:24 +00003589 echo float2nr(1.0e-100)
3590< 0
3591 {only available when compiled with the |+float| feature}
3592
3593
3594floor({expr}) *floor()*
3595 Return the largest integral value less than or equal to
3596 {expr} as a |Float| (round down).
3597 {expr} must evaluate to a |Float| or a |Number|.
3598 Examples: >
3599 echo floor(1.856)
3600< 1.0 >
3601 echo floor(-5.456)
3602< -6.0 >
3603 echo floor(4.0)
3604< 4.0
3605 {only available when compiled with the |+float| feature}
3606
Bram Moolenaardb7c6862010-05-21 16:33:48 +02003607
3608fmod({expr1}, {expr2}) *fmod()*
3609 Return the remainder of {expr1} / {expr2}, even if the
3610 division is not representable. Returns {expr1} - i * {expr2}
3611 for some integer i such that if {expr2} is non-zero, the
3612 result has the same sign as {expr1} and magnitude less than
3613 the magnitude of {expr2}. If {expr2} is zero, the value
Bram Moolenaar9855d6b2010-07-18 14:34:51 +02003614 returned is zero. The value returned is a |Float|.
3615 {expr1} and {expr2} must evaluate to a |Float| or a |Number|.
Bram Moolenaardb7c6862010-05-21 16:33:48 +02003616 Examples: >
3617 :echo fmod(12.33, 1.22)
3618< 0.13 >
3619 :echo fmod(-12.33, 1.22)
3620< -0.13
Bram Moolenaardb84e452010-08-15 13:50:43 +02003621 {only available when compiled with |+float| feature}
Bram Moolenaardb7c6862010-05-21 16:33:48 +02003622
3623
Bram Moolenaaraebaf892008-05-28 14:49:58 +00003624fnameescape({string}) *fnameescape()*
Bram Moolenaar446cb832008-06-24 21:56:24 +00003625 Escape {string} for use as file name command argument. All
Bram Moolenaaraebaf892008-05-28 14:49:58 +00003626 characters that have a special meaning, such as '%' and '|'
3627 are escaped with a backslash.
Bram Moolenaar446cb832008-06-24 21:56:24 +00003628 For most systems the characters escaped are
3629 " \t\n*?[{`$\\%#'\"|!<". For systems where a backslash
3630 appears in a filename, it depends on the value of 'isfname'.
Bram Moolenaar1b24e4b2008-08-08 10:59:17 +00003631 A leading '+' and '>' is also escaped (special after |:edit|
3632 and |:write|). And a "-" by itself (special after |:cd|).
Bram Moolenaaraebaf892008-05-28 14:49:58 +00003633 Example: >
Bram Moolenaar1b24e4b2008-08-08 10:59:17 +00003634 :let fname = '+some str%nge|name'
Bram Moolenaaraebaf892008-05-28 14:49:58 +00003635 :exe "edit " . fnameescape(fname)
3636< results in executing: >
Bram Moolenaar1b24e4b2008-08-08 10:59:17 +00003637 edit \+some\ str\%nge\|name
Bram Moolenaaraebaf892008-05-28 14:49:58 +00003638
Bram Moolenaar071d4272004-06-13 20:20:40 +00003639fnamemodify({fname}, {mods}) *fnamemodify()*
3640 Modify file name {fname} according to {mods}. {mods} is a
3641 string of characters like it is used for file names on the
3642 command line. See |filename-modifiers|.
3643 Example: >
3644 :echo fnamemodify("main.c", ":p:h")
3645< results in: >
3646 /home/mool/vim/vim/src
Bram Moolenaar446cb832008-06-24 21:56:24 +00003647< Note: Environment variables don't work in {fname}, use
Bram Moolenaar071d4272004-06-13 20:20:40 +00003648 |expand()| first then.
3649
3650foldclosed({lnum}) *foldclosed()*
3651 The result is a Number. If the line {lnum} is in a closed
3652 fold, the result is the number of the first line in that fold.
3653 If the line {lnum} is not in a closed fold, -1 is returned.
3654
3655foldclosedend({lnum}) *foldclosedend()*
3656 The result is a Number. If the line {lnum} is in a closed
3657 fold, the result is the number of the last line in that fold.
3658 If the line {lnum} is not in a closed fold, -1 is returned.
3659
3660foldlevel({lnum}) *foldlevel()*
3661 The result is a Number, which is the foldlevel of line {lnum}
Bram Moolenaar446cb832008-06-24 21:56:24 +00003662 in the current buffer. For nested folds the deepest level is
Bram Moolenaar071d4272004-06-13 20:20:40 +00003663 returned. If there is no fold at line {lnum}, zero is
3664 returned. It doesn't matter if the folds are open or closed.
3665 When used while updating folds (from 'foldexpr') -1 is
3666 returned for lines where folds are still to be updated and the
3667 foldlevel is unknown. As a special case the level of the
3668 previous line is usually available.
3669
3670 *foldtext()*
3671foldtext() Returns a String, to be displayed for a closed fold. This is
3672 the default function used for the 'foldtext' option and should
3673 only be called from evaluating 'foldtext'. It uses the
3674 |v:foldstart|, |v:foldend| and |v:folddashes| variables.
3675 The returned string looks like this: >
3676 +-- 45 lines: abcdef
Bram Moolenaar446cb832008-06-24 21:56:24 +00003677< The number of dashes depends on the foldlevel. The "45" is
Bram Moolenaar071d4272004-06-13 20:20:40 +00003678 the number of lines in the fold. "abcdef" is the text in the
3679 first non-blank line of the fold. Leading white space, "//"
3680 or "/*" and the text from the 'foldmarker' and 'commentstring'
3681 options is removed.
3682 {not available when compiled without the |+folding| feature}
3683
Bram Moolenaar7b0294c2004-10-11 10:16:09 +00003684foldtextresult({lnum}) *foldtextresult()*
3685 Returns the text that is displayed for the closed fold at line
3686 {lnum}. Evaluates 'foldtext' in the appropriate context.
3687 When there is no closed fold at {lnum} an empty string is
3688 returned.
3689 {lnum} is used like with |getline()|. Thus "." is the current
3690 line, "'m" mark m, etc.
3691 Useful when exporting folded text, e.g., to HTML.
3692 {not available when compiled without the |+folding| feature}
3693
Bram Moolenaar071d4272004-06-13 20:20:40 +00003694 *foreground()*
Bram Moolenaar446cb832008-06-24 21:56:24 +00003695foreground() Move the Vim window to the foreground. Useful when sent from
Bram Moolenaar071d4272004-06-13 20:20:40 +00003696 a client to a Vim server. |remote_send()|
3697 On Win32 systems this might not work, the OS does not always
3698 allow a window to bring itself to the foreground. Use
3699 |remote_foreground()| instead.
3700 {only in the Win32, Athena, Motif and GTK GUI versions and the
3701 Win32 console version}
3702
Bram Moolenaara14de3d2005-01-07 21:48:26 +00003703
Bram Moolenaar1735bc92016-03-14 23:05:14 +01003704 *function()* *E700* *E922* *E923*
3705function({name} [, {arglist}] [, {dict}])
Bram Moolenaar32466aa2006-02-24 23:53:04 +00003706 Return a |Funcref| variable that refers to function {name}.
Bram Moolenaar975b5272016-03-15 23:10:59 +01003707 {name} can be the name of a user defined function or an
3708 internal function.
Bram Moolenaard7ee7ce2005-01-03 21:02:03 +00003709
Bram Moolenaar975b5272016-03-15 23:10:59 +01003710 {name} can also be a Funcref, also a partial. When it is a
3711 partial the dict stored in it will be used and the {dict}
3712 argument is not allowed. E.g.: >
3713 let FuncWithArg = function(dict.Func, [arg])
3714 let Broken = function(dict.Func, [arg], dict)
3715<
Bram Moolenaar1735bc92016-03-14 23:05:14 +01003716 When {arglist} or {dict} is present this creates a partial.
Bram Moolenaar06d2d382016-05-20 17:24:11 +02003717 That means the argument list and/or the dictionary is stored in
Bram Moolenaar1735bc92016-03-14 23:05:14 +01003718 the Funcref and will be used when the Funcref is called.
3719
3720 The arguments are passed to the function in front of other
3721 arguments. Example: >
3722 func Callback(arg1, arg2, name)
3723 ...
3724 let Func = function('Callback', ['one', 'two'])
3725 ...
3726 call Func('name')
3727< Invokes the function as with: >
3728 call Callback('one', 'two', 'name')
3729
Bram Moolenaar03602ec2016-03-20 20:57:45 +01003730< The function() call can be nested to add more arguments to the
3731 Funcref. The extra arguments are appended to the list of
3732 arguments. Example: >
3733 func Callback(arg1, arg2, name)
3734 ...
3735 let Func = function('Callback', ['one'])
3736 let Func2 = function(Func, ['two'])
3737 ...
3738 call Func2('name')
3739< Invokes the function as with: >
3740 call Callback('one', 'two', 'name')
3741
Bram Moolenaar1735bc92016-03-14 23:05:14 +01003742< The Dictionary is only useful when calling a "dict" function.
3743 In that case the {dict} is passed in as "self". Example: >
3744 function Callback() dict
3745 echo "called for " . self.name
3746 endfunction
3747 ...
3748 let context = {"name": "example"}
3749 let Func = function('Callback', context)
3750 ...
3751 call Func() " will echo: called for example
Bram Moolenaar975b5272016-03-15 23:10:59 +01003752< The use of function() is not needed when there are no extra
3753 arguments, these two are equivalent: >
3754 let Func = function('Callback', context)
3755 let Func = context.Callback
Bram Moolenaar1735bc92016-03-14 23:05:14 +01003756
3757< The argument list and the Dictionary can be combined: >
3758 function Callback(arg1, count) dict
3759 ...
3760 let context = {"name": "example"}
3761 let Func = function('Callback', ['one'], context)
3762 ...
3763 call Func(500)
3764< Invokes the function as with: >
3765 call context.Callback('one', 500)
3766
Bram Moolenaara14de3d2005-01-07 21:48:26 +00003767
Bram Moolenaarf1568ec2011-12-14 21:17:39 +01003768garbagecollect([{atexit}]) *garbagecollect()*
Bram Moolenaarebf7dfa2016-04-14 12:46:51 +02003769 Cleanup unused |Lists|, |Dictionaries|, |Channels| and |Jobs|
3770 that have circular references.
3771
3772 There is hardly ever a need to invoke this function, as it is
3773 automatically done when Vim runs out of memory or is waiting
3774 for the user to press a key after 'updatetime'. Items without
3775 circular references are always freed when they become unused.
Bram Moolenaar32466aa2006-02-24 23:53:04 +00003776 This is useful if you have deleted a very big |List| and/or
3777 |Dictionary| with circular references in a script that runs
3778 for a long time.
Bram Moolenaarebf7dfa2016-04-14 12:46:51 +02003779
Bram Moolenaarf1568ec2011-12-14 21:17:39 +01003780 When the optional {atexit} argument is one, garbage
Bram Moolenaar9d2c8c12007-09-25 16:00:00 +00003781 collection will also be done when exiting Vim, if it wasn't
3782 done before. This is useful when checking for memory leaks.
Bram Moolenaar39a58ca2005-06-27 22:42:44 +00003783
Bram Moolenaar574860b2016-05-24 17:33:34 +02003784 The garbage collection is not done immediately but only when
3785 it's safe to perform. This is when waiting for the user to
3786 type a character. To force garbage collection immediately use
3787 |test_garbagecollect_now()|.
Bram Moolenaarebf7dfa2016-04-14 12:46:51 +02003788
Bram Moolenaar677ee682005-01-27 14:41:15 +00003789get({list}, {idx} [, {default}]) *get()*
Bram Moolenaar32466aa2006-02-24 23:53:04 +00003790 Get item {idx} from |List| {list}. When this item is not
Bram Moolenaara14de3d2005-01-07 21:48:26 +00003791 available return {default}. Return zero when {default} is
3792 omitted.
Bram Moolenaar2fda12f2005-01-15 22:14:15 +00003793get({dict}, {key} [, {default}])
Bram Moolenaar32466aa2006-02-24 23:53:04 +00003794 Get item with key {key} from |Dictionary| {dict}. When this
Bram Moolenaar2fda12f2005-01-15 22:14:15 +00003795 item is not available return {default}. Return zero when
3796 {default} is omitted.
Bram Moolenaar03e19a02016-05-24 22:29:49 +02003797get({func}, {what})
3798 Get an item with from Funcref {func}. Possible values for
Bram Moolenaar2bbf8ef2016-05-24 18:37:12 +02003799 {what} are:
Bram Moolenaar03e19a02016-05-24 22:29:49 +02003800 'name' The function name
Bram Moolenaar2bbf8ef2016-05-24 18:37:12 +02003801 'func' The function
3802 'dict' The dictionary
3803 'args' The list with arguments
Bram Moolenaar2fda12f2005-01-15 22:14:15 +00003804
Bram Moolenaar45360022005-07-21 21:08:21 +00003805 *getbufline()*
3806getbufline({expr}, {lnum} [, {end}])
Bram Moolenaar32466aa2006-02-24 23:53:04 +00003807 Return a |List| with the lines starting from {lnum} to {end}
3808 (inclusive) in the buffer {expr}. If {end} is omitted, a
3809 |List| with only the line {lnum} is returned.
Bram Moolenaar45360022005-07-21 21:08:21 +00003810
3811 For the use of {expr}, see |bufname()| above.
3812
Bram Moolenaar661b1822005-07-28 22:36:45 +00003813 For {lnum} and {end} "$" can be used for the last line of the
3814 buffer. Otherwise a number must be used.
Bram Moolenaar45360022005-07-21 21:08:21 +00003815
3816 When {lnum} is smaller than 1 or bigger than the number of
Bram Moolenaar32466aa2006-02-24 23:53:04 +00003817 lines in the buffer, an empty |List| is returned.
Bram Moolenaar45360022005-07-21 21:08:21 +00003818
3819 When {end} is greater than the number of lines in the buffer,
3820 it is treated as {end} is set to the number of lines in the
Bram Moolenaar32466aa2006-02-24 23:53:04 +00003821 buffer. When {end} is before {lnum} an empty |List| is
Bram Moolenaar45360022005-07-21 21:08:21 +00003822 returned.
3823
Bram Moolenaar661b1822005-07-28 22:36:45 +00003824 This function works only for loaded buffers. For unloaded and
Bram Moolenaar32466aa2006-02-24 23:53:04 +00003825 non-existing buffers, an empty |List| is returned.
Bram Moolenaar45360022005-07-21 21:08:21 +00003826
3827 Example: >
3828 :let lines = getbufline(bufnr("myfile"), 1, "$")
Bram Moolenaara14de3d2005-01-07 21:48:26 +00003829
Bram Moolenaar63dbda12013-02-20 21:12:10 +01003830getbufvar({expr}, {varname} [, {def}]) *getbufvar()*
Bram Moolenaara14de3d2005-01-07 21:48:26 +00003831 The result is the value of option or local buffer variable
3832 {varname} in buffer {expr}. Note that the name without "b:"
3833 must be used.
Bram Moolenaarc236c162008-07-13 17:41:49 +00003834 When {varname} is empty returns a dictionary with all the
3835 buffer-local variables.
Bram Moolenaar4317d9b2005-03-18 20:25:31 +00003836 This also works for a global or buffer-local option, but it
3837 doesn't work for a global variable, window-local variable or
3838 window-local option.
Bram Moolenaara14de3d2005-01-07 21:48:26 +00003839 For the use of {expr}, see |bufname()| above.
Bram Moolenaar63dbda12013-02-20 21:12:10 +01003840 When the buffer or variable doesn't exist {def} or an empty
3841 string is returned, there is no error message.
Bram Moolenaara14de3d2005-01-07 21:48:26 +00003842 Examples: >
3843 :let bufmodified = getbufvar(1, "&mod")
3844 :echo "todo myvar = " . getbufvar("todo", "myvar")
3845<
Bram Moolenaar071d4272004-06-13 20:20:40 +00003846getchar([expr]) *getchar()*
Bram Moolenaar91170f82006-05-05 21:15:17 +00003847 Get a single character from the user or input stream.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003848 If [expr] is omitted, wait until a character is available.
3849 If [expr] is 0, only get a character when one is available.
Bram Moolenaar91170f82006-05-05 21:15:17 +00003850 Return zero otherwise.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003851 If [expr] is 1, only check if a character is available, it is
Bram Moolenaar91170f82006-05-05 21:15:17 +00003852 not consumed. Return zero if no character available.
3853
Bram Moolenaardfb18412013-12-11 18:53:29 +01003854 Without [expr] and when [expr] is 0 a whole character or
Bram Moolenaar91170f82006-05-05 21:15:17 +00003855 special key is returned. If it is an 8-bit character, the
3856 result is a number. Use nr2char() to convert it to a String.
3857 Otherwise a String is returned with the encoded character.
3858 For a special key it's a sequence of bytes starting with 0x80
Bram Moolenaar56a907a2006-05-06 21:44:30 +00003859 (decimal: 128). This is the same value as the string
3860 "\<Key>", e.g., "\<Left>". The returned value is also a
3861 String when a modifier (shift, control, alt) was used that is
3862 not included in the character.
Bram Moolenaar91170f82006-05-05 21:15:17 +00003863
Bram Moolenaar822ff862014-06-12 21:46:14 +02003864 When [expr] is 0 and Esc is typed, there will be a short delay
3865 while Vim waits to see if this is the start of an escape
3866 sequence.
3867
Bram Moolenaardfb18412013-12-11 18:53:29 +01003868 When [expr] is 1 only the first byte is returned. For a
Bram Moolenaar56a907a2006-05-06 21:44:30 +00003869 one-byte character it is the character itself as a number.
3870 Use nr2char() to convert it to a String.
Bram Moolenaar91170f82006-05-05 21:15:17 +00003871
Bram Moolenaarf1568ec2011-12-14 21:17:39 +01003872 Use getcharmod() to obtain any additional modifiers.
3873
Bram Moolenaar219b8702006-11-01 14:32:36 +00003874 When the user clicks a mouse button, the mouse event will be
3875 returned. The position can then be found in |v:mouse_col|,
Bram Moolenaar511972d2016-06-04 18:09:59 +02003876 |v:mouse_lnum|, |v:mouse_winid| and |v:mouse_win|. This
3877 example positions the mouse as it would normally happen: >
Bram Moolenaar219b8702006-11-01 14:32:36 +00003878 let c = getchar()
Bram Moolenaar446cb832008-06-24 21:56:24 +00003879 if c == "\<LeftMouse>" && v:mouse_win > 0
Bram Moolenaar219b8702006-11-01 14:32:36 +00003880 exe v:mouse_win . "wincmd w"
3881 exe v:mouse_lnum
3882 exe "normal " . v:mouse_col . "|"
3883 endif
3884<
Bram Moolenaar071d4272004-06-13 20:20:40 +00003885 There is no prompt, you will somehow have to make clear to the
3886 user that a character has to be typed.
3887 There is no mapping for the character.
3888 Key codes are replaced, thus when the user presses the <Del>
3889 key you get the code for the <Del> key, not the raw character
3890 sequence. Examples: >
3891 getchar() == "\<Del>"
3892 getchar() == "\<S-Left>"
3893< This example redefines "f" to ignore case: >
3894 :nmap f :call FindChar()<CR>
3895 :function FindChar()
3896 : let c = nr2char(getchar())
3897 : while col('.') < col('$') - 1
3898 : normal l
3899 : if getline('.')[col('.') - 1] ==? c
3900 : break
3901 : endif
3902 : endwhile
3903 :endfunction
Bram Moolenaared32d942014-12-06 23:33:00 +01003904<
Bram Moolenaar2b8388b2015-02-28 13:11:45 +01003905 You may also receive synthetic characters, such as
Bram Moolenaared32d942014-12-06 23:33:00 +01003906 |<CursorHold>|. Often you will want to ignore this and get
3907 another character: >
3908 :function GetKey()
3909 : let c = getchar()
3910 : while c == "\<CursorHold>"
3911 : let c = getchar()
3912 : endwhile
3913 : return c
3914 :endfunction
Bram Moolenaar071d4272004-06-13 20:20:40 +00003915
3916getcharmod() *getcharmod()*
3917 The result is a Number which is the state of the modifiers for
3918 the last obtained character with getchar() or in another way.
3919 These values are added together:
3920 2 shift
3921 4 control
3922 8 alt (meta)
Bram Moolenaarf1568ec2011-12-14 21:17:39 +01003923 16 meta (when it's different from ALT)
3924 32 mouse double click
3925 64 mouse triple click
3926 96 mouse quadruple click (== 32 + 64)
3927 128 command (Macintosh only)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003928 Only the modifiers that have not been included in the
Bram Moolenaar446cb832008-06-24 21:56:24 +00003929 character itself are obtained. Thus Shift-a results in "A"
Bram Moolenaar8f3f58f2010-01-06 20:52:26 +01003930 without a modifier.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003931
Bram Moolenaardbd24b52015-08-11 14:26:19 +02003932getcharsearch() *getcharsearch()*
3933 Return the current character search information as a {dict}
3934 with the following entries:
3935
3936 char character previously used for a character
3937 search (|t|, |f|, |T|, or |F|); empty string
3938 if no character search has been performed
3939 forward direction of character search; 1 for forward,
3940 0 for backward
3941 until type of character search; 1 for a |t| or |T|
3942 character search, 0 for an |f| or |F|
3943 character search
3944
3945 This can be useful to always have |;| and |,| search
3946 forward/backward regardless of the direction of the previous
3947 character search: >
3948 :nnoremap <expr> ; getcharsearch().forward ? ';' : ','
3949 :nnoremap <expr> , getcharsearch().forward ? ',' : ';'
3950< Also see |setcharsearch()|.
3951
Bram Moolenaar071d4272004-06-13 20:20:40 +00003952getcmdline() *getcmdline()*
3953 Return the current command-line. Only works when the command
3954 line is being edited, thus requires use of |c_CTRL-\_e| or
3955 |c_CTRL-R_=|.
3956 Example: >
3957 :cmap <F7> <C-\>eescape(getcmdline(), ' \')<CR>
Bram Moolenaarbfd8fc02005-09-20 23:22:24 +00003958< Also see |getcmdtype()|, |getcmdpos()| and |setcmdpos()|.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003959
Bram Moolenaar5f2bb9f2005-01-11 21:29:04 +00003960getcmdpos() *getcmdpos()*
Bram Moolenaar071d4272004-06-13 20:20:40 +00003961 Return the position of the cursor in the command line as a
3962 byte count. The first column is 1.
3963 Only works when editing the command line, thus requires use of
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003964 |c_CTRL-\_e| or |c_CTRL-R_=| or an expression mapping.
3965 Returns 0 otherwise.
Bram Moolenaarbfd8fc02005-09-20 23:22:24 +00003966 Also see |getcmdtype()|, |setcmdpos()| and |getcmdline()|.
3967
3968getcmdtype() *getcmdtype()*
3969 Return the current command-line type. Possible return values
3970 are:
Bram Moolenaar1e015462005-09-25 22:16:38 +00003971 : normal Ex command
3972 > debug mode command |debug-mode|
3973 / forward search command
3974 ? backward search command
3975 @ |input()| command
3976 - |:insert| or |:append| command
Bram Moolenaar6e932462014-09-09 18:48:09 +02003977 = |i_CTRL-R_=|
Bram Moolenaarbfd8fc02005-09-20 23:22:24 +00003978 Only works when editing the command line, thus requires use of
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003979 |c_CTRL-\_e| or |c_CTRL-R_=| or an expression mapping.
3980 Returns an empty string otherwise.
Bram Moolenaarbfd8fc02005-09-20 23:22:24 +00003981 Also see |getcmdpos()|, |setcmdpos()| and |getcmdline()|.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003982
Bram Moolenaarfb539272014-08-22 19:21:47 +02003983getcmdwintype() *getcmdwintype()*
3984 Return the current |command-line-window| type. Possible return
3985 values are the same as |getcmdtype()|. Returns an empty string
3986 when not in the command-line window.
3987
Bram Moolenaar6f6c0f82014-05-28 20:31:42 +02003988 *getcurpos()*
3989getcurpos() Get the position of the cursor. This is like getpos('.'), but
3990 includes an extra item in the list:
Bram Moolenaar345efa02016-01-15 20:57:49 +01003991 [bufnum, lnum, col, off, curswant] ~
Bram Moolenaar6f6c0f82014-05-28 20:31:42 +02003992 The "curswant" number is the preferred column when moving the
3993 cursor vertically.
3994 This can be used to save and restore the cursor position: >
3995 let save_cursor = getcurpos()
3996 MoveTheCursorAround
3997 call setpos('.', save_cursor)
Bram Moolenaarfb539272014-08-22 19:21:47 +02003998<
Bram Moolenaar071d4272004-06-13 20:20:40 +00003999 *getcwd()*
Bram Moolenaarc9703302016-01-17 21:49:33 +01004000getcwd([{winnr} [, {tabnr}]])
4001 The result is a String, which is the name of the current
Bram Moolenaar071d4272004-06-13 20:20:40 +00004002 working directory.
Bram Moolenaarc9703302016-01-17 21:49:33 +01004003 Without arguments, for the current window.
4004
4005 With {winnr} return the local current directory of this window
4006 in the current tab page.
4007 With {winnr} and {tabnr} return the local current directory of
4008 the window in the specified tab page.
Bram Moolenaar888ccac2016-06-04 18:49:36 +02004009 {winnr} can be the window number or the window ID.
Bram Moolenaarc9703302016-01-17 21:49:33 +01004010 Return an empty string if the arguments are invalid.
Bram Moolenaar071d4272004-06-13 20:20:40 +00004011
4012getfsize({fname}) *getfsize()*
4013 The result is a Number, which is the size in bytes of the
4014 given file {fname}.
4015 If {fname} is a directory, 0 is returned.
4016 If the file {fname} can't be found, -1 is returned.
Bram Moolenaard827ada2007-06-19 15:19:55 +00004017 If the size of {fname} is too big to fit in a Number then -2
4018 is returned.
Bram Moolenaar071d4272004-06-13 20:20:40 +00004019
Bram Moolenaard8b0cf12004-12-12 11:33:30 +00004020getfontname([{name}]) *getfontname()*
4021 Without an argument returns the name of the normal font being
4022 used. Like what is used for the Normal highlight group
4023 |hl-Normal|.
4024 With an argument a check is done whether {name} is a valid
4025 font name. If not then an empty string is returned.
4026 Otherwise the actual font name is returned, or {name} if the
4027 GUI does not support obtaining the real name.
Bram Moolenaarc6fe9192006-04-09 21:54:49 +00004028 Only works when the GUI is running, thus not in your vimrc or
Bram Moolenaard8b0cf12004-12-12 11:33:30 +00004029 gvimrc file. Use the |GUIEnter| autocommand to use this
4030 function just after the GUI has started.
Bram Moolenaar910f66f2006-04-05 20:41:53 +00004031 Note that the GTK 2 GUI accepts any font name, thus checking
4032 for a valid name does not work.
Bram Moolenaard8b0cf12004-12-12 11:33:30 +00004033
Bram Moolenaar5eb86f92004-07-26 12:53:41 +00004034getfperm({fname}) *getfperm()*
4035 The result is a String, which is the read, write, and execute
4036 permissions of the given file {fname}.
4037 If {fname} does not exist or its directory cannot be read, an
4038 empty string is returned.
4039 The result is of the form "rwxrwxrwx", where each group of
4040 "rwx" flags represent, in turn, the permissions of the owner
4041 of the file, the group the file belongs to, and other users.
4042 If a user does not have a given permission the flag for this
Bram Moolenaar9b451252012-08-15 17:43:31 +02004043 is replaced with the string "-". Examples: >
Bram Moolenaar5eb86f92004-07-26 12:53:41 +00004044 :echo getfperm("/etc/passwd")
Bram Moolenaar9b451252012-08-15 17:43:31 +02004045 :echo getfperm(expand("~/.vimrc"))
Bram Moolenaar5eb86f92004-07-26 12:53:41 +00004046< This will hopefully (from a security point of view) display
4047 the string "rw-r--r--" or even "rw-------".
Bram Moolenaare2cc9702005-03-15 22:43:58 +00004048
Bram Moolenaar80492532016-03-08 17:08:53 +01004049 For setting permissins use |setfperm()|.
4050
Bram Moolenaar071d4272004-06-13 20:20:40 +00004051getftime({fname}) *getftime()*
4052 The result is a Number, which is the last modification time of
4053 the given file {fname}. The value is measured as seconds
4054 since 1st Jan 1970, and may be passed to strftime(). See also
4055 |localtime()| and |strftime()|.
4056 If the file {fname} can't be found -1 is returned.
4057
Bram Moolenaar5eb86f92004-07-26 12:53:41 +00004058getftype({fname}) *getftype()*
4059 The result is a String, which is a description of the kind of
4060 file of the given file {fname}.
4061 If {fname} does not exist an empty string is returned.
4062 Here is a table over different kinds of files and their
4063 results:
4064 Normal file "file"
4065 Directory "dir"
4066 Symbolic link "link"
4067 Block device "bdev"
4068 Character device "cdev"
4069 Socket "socket"
4070 FIFO "fifo"
4071 All other "other"
4072 Example: >
4073 getftype("/home")
4074< Note that a type such as "link" will only be returned on
4075 systems that support it. On some systems only "dir" and
Bram Moolenaar13d5aee2016-01-21 23:36:05 +01004076 "file" are returned. On MS-Windows a symbolic link to a
4077 directory returns "dir" instead of "link".
Bram Moolenaar5eb86f92004-07-26 12:53:41 +00004078
Bram Moolenaar071d4272004-06-13 20:20:40 +00004079 *getline()*
Bram Moolenaara14de3d2005-01-07 21:48:26 +00004080getline({lnum} [, {end}])
4081 Without {end} the result is a String, which is line {lnum}
4082 from the current buffer. Example: >
Bram Moolenaar071d4272004-06-13 20:20:40 +00004083 getline(1)
4084< When {lnum} is a String that doesn't start with a
4085 digit, line() is called to translate the String into a Number.
4086 To get the line under the cursor: >
4087 getline(".")
4088< When {lnum} is smaller than 1 or bigger than the number of
4089 lines in the buffer, an empty string is returned.
4090
Bram Moolenaar32466aa2006-02-24 23:53:04 +00004091 When {end} is given the result is a |List| where each item is
4092 a line from the current buffer in the range {lnum} to {end},
Bram Moolenaara14de3d2005-01-07 21:48:26 +00004093 including line {end}.
4094 {end} is used in the same way as {lnum}.
4095 Non-existing lines are silently omitted.
Bram Moolenaar32466aa2006-02-24 23:53:04 +00004096 When {end} is before {lnum} an empty |List| is returned.
Bram Moolenaara14de3d2005-01-07 21:48:26 +00004097 Example: >
4098 :let start = line('.')
4099 :let end = search("^$") - 1
4100 :let lines = getline(start, end)
4101
Bram Moolenaaref2f6562007-05-06 13:32:59 +00004102< To get lines from another buffer see |getbufline()|
4103
Bram Moolenaar17c7c012006-01-26 22:25:15 +00004104getloclist({nr}) *getloclist()*
4105 Returns a list with all the entries in the location list for
Bram Moolenaar888ccac2016-06-04 18:49:36 +02004106 window {nr}. {nr} can be the window number or the window ID.
4107 When {nr} is zero the current window is used.
4108
Bram Moolenaar17c7c012006-01-26 22:25:15 +00004109 For a location list window, the displayed location list is
Bram Moolenaar280f1262006-01-30 00:14:18 +00004110 returned. For an invalid window number {nr}, an empty list is
Bram Moolenaar8f3f58f2010-01-06 20:52:26 +01004111 returned. Otherwise, same as |getqflist()|.
Bram Moolenaara14de3d2005-01-07 21:48:26 +00004112
Bram Moolenaar6ee10162007-07-26 20:58:42 +00004113getmatches() *getmatches()*
4114 Returns a |List| with all matches previously defined by
4115 |matchadd()| and the |:match| commands. |getmatches()| is
4116 useful in combination with |setmatches()|, as |setmatches()|
4117 can restore a list of matches saved by |getmatches()|.
4118 Example: >
4119 :echo getmatches()
4120< [{'group': 'MyGroup1', 'pattern': 'TODO',
4121 'priority': 10, 'id': 1}, {'group': 'MyGroup2',
4122 'pattern': 'FIXME', 'priority': 10, 'id': 2}] >
4123 :let m = getmatches()
4124 :call clearmatches()
4125 :echo getmatches()
4126< [] >
4127 :call setmatches(m)
4128 :echo getmatches()
4129< [{'group': 'MyGroup1', 'pattern': 'TODO',
4130 'priority': 10, 'id': 1}, {'group': 'MyGroup2',
4131 'pattern': 'FIXME', 'priority': 10, 'id': 2}] >
4132 :unlet m
4133<
Bram Moolenaar822ff862014-06-12 21:46:14 +02004134 *getpid()*
4135getpid() Return a Number which is the process ID of the Vim process.
4136 On Unix and MS-Windows this is a unique number, until Vim
4137 exits. On MS-DOS it's always zero.
4138
4139 *getpos()*
4140getpos({expr}) Get the position for {expr}. For possible values of {expr}
4141 see |line()|. For getting the cursor position see
4142 |getcurpos()|.
4143 The result is a |List| with four numbers:
4144 [bufnum, lnum, col, off]
4145 "bufnum" is zero, unless a mark like '0 or 'A is used, then it
4146 is the buffer number of the mark.
4147 "lnum" and "col" are the position in the buffer. The first
4148 column is 1.
4149 The "off" number is zero, unless 'virtualedit' is used. Then
4150 it is the offset in screen columns from the start of the
4151 character. E.g., a position within a <Tab> or after the last
4152 character.
4153 Note that for '< and '> Visual mode matters: when it is "V"
4154 (visual line mode) the column of '< is zero and the column of
4155 '> is a large number.
4156 This can be used to save and restore the position of a mark: >
4157 let save_a_mark = getpos("'a")
4158 ...
Bram Moolenaared32d942014-12-06 23:33:00 +01004159 call setpos("'a", save_a_mark)
Bram Moolenaar822ff862014-06-12 21:46:14 +02004160< Also see |getcurpos()| and |setpos()|.
4161
Bram Moolenaar6ee10162007-07-26 20:58:42 +00004162
Bram Moolenaar68b76a62005-03-25 21:53:48 +00004163getqflist() *getqflist()*
4164 Returns a list with all the current quickfix errors. Each
4165 list item is a dictionary with these entries:
4166 bufnr number of buffer that has the file name, use
4167 bufname() to get the name
4168 lnum line number in the buffer (first line is 1)
4169 col column number (first column is 1)
Bram Moolenaar582fd852005-03-28 20:58:01 +00004170 vcol non-zero: "col" is visual column
4171 zero: "col" is byte index
Bram Moolenaar68b76a62005-03-25 21:53:48 +00004172 nr error number
Bram Moolenaar48b66fb2007-02-04 01:58:18 +00004173 pattern search pattern used to locate the error
Bram Moolenaar68b76a62005-03-25 21:53:48 +00004174 text description of the error
4175 type type of the error, 'E', '1', etc.
4176 valid non-zero: recognized error message
4177
Bram Moolenaare7eb9df2005-09-09 19:49:30 +00004178 When there is no error list or it's empty an empty list is
Bram Moolenaar48b66fb2007-02-04 01:58:18 +00004179 returned. Quickfix list entries with non-existing buffer
4180 number are returned with "bufnr" set to zero.
Bram Moolenaare7eb9df2005-09-09 19:49:30 +00004181
Bram Moolenaar68b76a62005-03-25 21:53:48 +00004182 Useful application: Find pattern matches in multiple files and
4183 do something with them: >
4184 :vimgrep /theword/jg *.c
4185 :for d in getqflist()
4186 : echo bufname(d.bufnr) ':' d.lnum '=' d.text
4187 :endfor
4188
4189
Bram Moolenaarb7cb42b2014-04-02 19:55:10 +02004190getreg([{regname} [, 1 [, {list}]]]) *getreg()*
Bram Moolenaar071d4272004-06-13 20:20:40 +00004191 The result is a String, which is the contents of register
Bram Moolenaar402d2fe2005-04-15 21:00:38 +00004192 {regname}. Example: >
Bram Moolenaar071d4272004-06-13 20:20:40 +00004193 :let cliptext = getreg('*')
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004194< When {regname} was not set the result is a empty string.
4195
4196 getreg('=') returns the last evaluated value of the expression
Bram Moolenaar402d2fe2005-04-15 21:00:38 +00004197 register. (For use in maps.)
Bram Moolenaar2389c3c2005-05-22 22:07:59 +00004198 getreg('=', 1) returns the expression itself, so that it can
4199 be restored with |setreg()|. For other registers the extra
4200 argument is ignored, thus you can always give it.
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004201
4202 If {list} is present and non-zero, the result type is changed
4203 to |List|. Each list item is one text line. Use it if you care
Bram Moolenaarb7cb42b2014-04-02 19:55:10 +02004204 about zero bytes possibly present inside register: without
4205 third argument both NLs and zero bytes are represented as NLs
4206 (see |NL-used-for-Nul|).
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004207 When the register was not set an empty list is returned.
4208
Bram Moolenaar071d4272004-06-13 20:20:40 +00004209 If {regname} is not specified, |v:register| is used.
4210
Bram Moolenaara14de3d2005-01-07 21:48:26 +00004211
Bram Moolenaar071d4272004-06-13 20:20:40 +00004212getregtype([{regname}]) *getregtype()*
4213 The result is a String, which is type of register {regname}.
4214 The value will be one of:
4215 "v" for |characterwise| text
4216 "V" for |linewise| text
4217 "<CTRL-V>{width}" for |blockwise-visual| text
Bram Moolenaar32b92012014-01-14 12:33:36 +01004218 "" for an empty or unknown register
Bram Moolenaar071d4272004-06-13 20:20:40 +00004219 <CTRL-V> is one character with value 0x16.
4220 If {regname} is not specified, |v:register| is used.
4221
Bram Moolenaar63dbda12013-02-20 21:12:10 +01004222gettabvar({tabnr}, {varname} [, {def}]) *gettabvar()*
Bram Moolenaar06b5d512010-05-22 15:37:44 +02004223 Get the value of a tab-local variable {varname} in tab page
4224 {tabnr}. |t:var|
4225 Tabs are numbered starting with one.
Bram Moolenaar0e2ea1b2014-09-09 16:13:08 +02004226 When {varname} is empty a dictionary with all tab-local
4227 variables is returned.
Bram Moolenaar06b5d512010-05-22 15:37:44 +02004228 Note that the name without "t:" must be used.
Bram Moolenaar63dbda12013-02-20 21:12:10 +01004229 When the tab or variable doesn't exist {def} or an empty
4230 string is returned, there is no error message.
Bram Moolenaar06b5d512010-05-22 15:37:44 +02004231
Bram Moolenaar63dbda12013-02-20 21:12:10 +01004232gettabwinvar({tabnr}, {winnr}, {varname} [, {def}]) *gettabwinvar()*
Bram Moolenaaref2f6562007-05-06 13:32:59 +00004233 Get the value of window-local variable {varname} in window
4234 {winnr} in tab page {tabnr}.
4235 When {varname} starts with "&" get the value of a window-local
4236 option.
Bram Moolenaar63dbda12013-02-20 21:12:10 +01004237 When {varname} is empty a dictionary with all window-local
4238 variables is returned.
4239 Note that {varname} must be the name without "w:".
Bram Moolenaarc6249bb2006-04-15 20:25:09 +00004240 Tabs are numbered starting with one. For the current tabpage
4241 use |getwinvar()|.
Bram Moolenaar888ccac2016-06-04 18:49:36 +02004242 {winnr} can be the window number or the window ID.
Bram Moolenaarc6249bb2006-04-15 20:25:09 +00004243 When {winnr} is zero the current window is used.
4244 This also works for a global option, buffer-local option and
4245 window-local option, but it doesn't work for a global variable
4246 or buffer-local variable.
Bram Moolenaar63dbda12013-02-20 21:12:10 +01004247 When the tab, window or variable doesn't exist {def} or an
4248 empty string is returned, there is no error message.
Bram Moolenaarc6249bb2006-04-15 20:25:09 +00004249 Examples: >
4250 :let list_is_on = gettabwinvar(1, 2, '&list')
4251 :echo "myvar = " . gettabwinvar(3, 1, 'myvar')
Bram Moolenaard46bbc72007-05-12 14:38:41 +00004252<
Bram Moolenaar071d4272004-06-13 20:20:40 +00004253 *getwinposx()*
4254getwinposx() The result is a Number, which is the X coordinate in pixels of
4255 the left hand side of the GUI Vim window. The result will be
4256 -1 if the information is not available.
4257
4258 *getwinposy()*
4259getwinposy() The result is a Number, which is the Y coordinate in pixels of
Bram Moolenaar446cb832008-06-24 21:56:24 +00004260 the top of the GUI Vim window. The result will be -1 if the
Bram Moolenaar071d4272004-06-13 20:20:40 +00004261 information is not available.
4262
Bram Moolenaar63dbda12013-02-20 21:12:10 +01004263getwinvar({winnr}, {varname} [, {def}]) *getwinvar()*
Bram Moolenaarc6249bb2006-04-15 20:25:09 +00004264 Like |gettabwinvar()| for the current tabpage.
Bram Moolenaar071d4272004-06-13 20:20:40 +00004265 Examples: >
4266 :let list_is_on = getwinvar(2, '&list')
4267 :echo "myvar = " . getwinvar(1, 'myvar')
4268<
Bram Moolenaard8b77f72015-03-05 21:21:19 +01004269glob({expr} [, {nosuf} [, {list} [, {alllinks}]]]) *glob()*
Bram Moolenaarbb5ddda2008-11-28 10:01:10 +00004270 Expand the file wildcards in {expr}. See |wildcards| for the
Bram Moolenaaref2f6562007-05-06 13:32:59 +00004271 use of special characters.
Bram Moolenaar84f72352012-03-11 15:57:40 +01004272
4273 Unless the optional {nosuf} argument is given and is non-zero,
Bram Moolenaarbb5ddda2008-11-28 10:01:10 +00004274 the 'suffixes' and 'wildignore' options apply: Names matching
4275 one of the patterns in 'wildignore' will be skipped and
4276 'suffixes' affect the ordering of matches.
Bram Moolenaar81af9252010-12-10 20:35:50 +01004277 'wildignorecase' always applies.
Bram Moolenaar84f72352012-03-11 15:57:40 +01004278
4279 When {list} is present and it is non-zero the result is a List
4280 with all matching files. The advantage of using a List is,
4281 you also get filenames containing newlines correctly.
4282 Otherwise the result is a String and when there are several
4283 matches, they are separated by <NL> characters.
4284
4285 If the expansion fails, the result is an empty String or List.
Bram Moolenaard8b77f72015-03-05 21:21:19 +01004286
Bram Moolenaar61d35bd2012-03-28 20:51:51 +02004287 A name for a non-existing file is not included. A symbolic
4288 link is only included if it points to an existing file.
Bram Moolenaard8b77f72015-03-05 21:21:19 +01004289 However, when the {alllinks} argument is present and it is
4290 non-zero then all symbolic links are included.
Bram Moolenaar071d4272004-06-13 20:20:40 +00004291
4292 For most systems backticks can be used to get files names from
4293 any external command. Example: >
4294 :let tagfiles = glob("`find . -name tags -print`")
4295 :let &tags = substitute(tagfiles, "\n", ",", "g")
4296< The result of the program inside the backticks should be one
Bram Moolenaar446cb832008-06-24 21:56:24 +00004297 item per line. Spaces inside an item are allowed.
Bram Moolenaar071d4272004-06-13 20:20:40 +00004298
4299 See |expand()| for expanding special Vim variables. See
4300 |system()| for getting the raw output of an external command.
4301
Bram Moolenaar5837f1f2015-03-21 18:06:14 +01004302glob2regpat({expr}) *glob2regpat()*
4303 Convert a file pattern, as used by glob(), into a search
4304 pattern. The result can be used to match with a string that
4305 is a file name. E.g. >
4306 if filename =~ glob2regpat('Make*.mak')
4307< This is equivalent to: >
4308 if filename =~ '^Make.*\.mak$'
Bram Moolenaar3b5f9292016-01-28 22:37:01 +01004309< When {expr} is an empty string the result is "^$", match an
4310 empty string.
4311
Bram Moolenaard8b77f72015-03-05 21:21:19 +01004312 *globpath()*
Bram Moolenaar6463ca22016-02-13 17:04:46 +01004313globpath({path}, {expr} [, {nosuf} [, {list} [, {alllinks}]]])
Bram Moolenaar071d4272004-06-13 20:20:40 +00004314 Perform glob() on all directories in {path} and concatenate
4315 the results. Example: >
4316 :echo globpath(&rtp, "syntax/c.vim")
Bram Moolenaar1b1063a2014-05-07 18:35:30 +02004317<
4318 {path} is a comma-separated list of directory names. Each
Bram Moolenaar071d4272004-06-13 20:20:40 +00004319 directory name is prepended to {expr} and expanded like with
Bram Moolenaarbb5ddda2008-11-28 10:01:10 +00004320 |glob()|. A path separator is inserted when needed.
Bram Moolenaar071d4272004-06-13 20:20:40 +00004321 To add a comma inside a directory name escape it with a
4322 backslash. Note that on MS-Windows a directory may have a
4323 trailing backslash, remove it if you put a comma after it.
4324 If the expansion fails for one of the directories, there is no
4325 error message.
Bram Moolenaar1b1063a2014-05-07 18:35:30 +02004326
4327 Unless the optional {nosuf} argument is given and is non-zero,
Bram Moolenaarbb5ddda2008-11-28 10:01:10 +00004328 the 'suffixes' and 'wildignore' options apply: Names matching
4329 one of the patterns in 'wildignore' will be skipped and
4330 'suffixes' affect the ordering of matches.
Bram Moolenaar071d4272004-06-13 20:20:40 +00004331
Bram Moolenaar1b1063a2014-05-07 18:35:30 +02004332 When {list} is present and it is non-zero the result is a List
4333 with all matching files. The advantage of using a List is, you
4334 also get filenames containing newlines correctly. Otherwise
4335 the result is a String and when there are several matches,
4336 they are separated by <NL> characters. Example: >
4337 :echo globpath(&rtp, "syntax/c.vim", 0, 1)
4338<
Bram Moolenaar6463ca22016-02-13 17:04:46 +01004339 {alllinks} is used as with |glob()|.
Bram Moolenaard8b77f72015-03-05 21:21:19 +01004340
Bram Moolenaar02743632005-07-25 20:42:36 +00004341 The "**" item can be used to search in a directory tree.
4342 For example, to find all "README.txt" files in the directories
4343 in 'runtimepath' and below: >
4344 :echo globpath(&rtp, "**/README.txt")
Bram Moolenaarc236c162008-07-13 17:41:49 +00004345< Upwards search and limiting the depth of "**" is not
4346 supported, thus using 'path' will not always work properly.
4347
Bram Moolenaar071d4272004-06-13 20:20:40 +00004348 *has()*
4349has({feature}) The result is a Number, which is 1 if the feature {feature} is
4350 supported, zero otherwise. The {feature} argument is a
4351 string. See |feature-list| below.
4352 Also see |exists()|.
4353
Bram Moolenaar2fda12f2005-01-15 22:14:15 +00004354
4355has_key({dict}, {key}) *has_key()*
Bram Moolenaar32466aa2006-02-24 23:53:04 +00004356 The result is a Number, which is 1 if |Dictionary| {dict} has
4357 an entry with key {key}. Zero otherwise.
Bram Moolenaar2fda12f2005-01-15 22:14:15 +00004358
Bram Moolenaarc9703302016-01-17 21:49:33 +01004359haslocaldir([{winnr} [, {tabnr}]]) *haslocaldir()*
4360 The result is a Number, which is 1 when the window has set a
4361 local path via |:lcd|, and 0 otherwise.
4362
4363 Without arguments use the current window.
4364 With {winnr} use this window in the current tab page.
4365 With {winnr} and {tabnr} use the window in the specified tab
4366 page.
Bram Moolenaar888ccac2016-06-04 18:49:36 +02004367 {winnr} can be the window number or the window ID.
Bram Moolenaarc9703302016-01-17 21:49:33 +01004368 Return 0 if the arguments are invalid.
Bram Moolenaar2fda12f2005-01-15 22:14:15 +00004369
Bram Moolenaar97b2ad32006-03-18 21:40:56 +00004370hasmapto({what} [, {mode} [, {abbr}]]) *hasmapto()*
Bram Moolenaar071d4272004-06-13 20:20:40 +00004371 The result is a Number, which is 1 if there is a mapping that
4372 contains {what} in somewhere in the rhs (what it is mapped to)
4373 and this mapping exists in one of the modes indicated by
4374 {mode}.
Bram Moolenaar97b2ad32006-03-18 21:40:56 +00004375 When {abbr} is there and it is non-zero use abbreviations
Bram Moolenaar39f05632006-03-19 22:15:26 +00004376 instead of mappings. Don't forget to specify Insert and/or
4377 Command-line mode.
Bram Moolenaar071d4272004-06-13 20:20:40 +00004378 Both the global mappings and the mappings local to the current
4379 buffer are checked for a match.
4380 If no matching mapping is found 0 is returned.
4381 The following characters are recognized in {mode}:
4382 n Normal mode
4383 v Visual mode
4384 o Operator-pending mode
4385 i Insert mode
4386 l Language-Argument ("r", "f", "t", etc.)
4387 c Command-line mode
4388 When {mode} is omitted, "nvo" is used.
4389
4390 This function is useful to check if a mapping already exists
Bram Moolenaar446cb832008-06-24 21:56:24 +00004391 to a function in a Vim script. Example: >
Bram Moolenaar071d4272004-06-13 20:20:40 +00004392 :if !hasmapto('\ABCdoit')
4393 : map <Leader>d \ABCdoit
4394 :endif
4395< This installs the mapping to "\ABCdoit" only if there isn't
4396 already a mapping to "\ABCdoit".
4397
4398histadd({history}, {item}) *histadd()*
4399 Add the String {item} to the history {history} which can be
4400 one of: *hist-names*
4401 "cmd" or ":" command line history
4402 "search" or "/" search pattern history
Bram Moolenaar446cb832008-06-24 21:56:24 +00004403 "expr" or "=" typed expression history
Bram Moolenaar071d4272004-06-13 20:20:40 +00004404 "input" or "@" input line history
Bram Moolenaar30b65812012-07-12 22:01:11 +02004405 "debug" or ">" debug command history
4406 The {history} string does not need to be the whole name, one
4407 character is sufficient.
Bram Moolenaar071d4272004-06-13 20:20:40 +00004408 If {item} does already exist in the history, it will be
4409 shifted to become the newest entry.
4410 The result is a Number: 1 if the operation was successful,
4411 otherwise 0 is returned.
4412
4413 Example: >
4414 :call histadd("input", strftime("%Y %b %d"))
4415 :let date=input("Enter date: ")
4416< This function is not available in the |sandbox|.
4417
4418histdel({history} [, {item}]) *histdel()*
Bram Moolenaar402d2fe2005-04-15 21:00:38 +00004419 Clear {history}, i.e. delete all its entries. See |hist-names|
Bram Moolenaar071d4272004-06-13 20:20:40 +00004420 for the possible values of {history}.
4421
Bram Moolenaarc236c162008-07-13 17:41:49 +00004422 If the parameter {item} evaluates to a String, it is used as a
4423 regular expression. All entries matching that expression will
4424 be removed from the history (if there are any).
Bram Moolenaar071d4272004-06-13 20:20:40 +00004425 Upper/lowercase must match, unless "\c" is used |/\c|.
Bram Moolenaarc236c162008-07-13 17:41:49 +00004426 If {item} evaluates to a Number, it will be interpreted as
4427 an index, see |:history-indexing|. The respective entry will
4428 be removed if it exists.
Bram Moolenaar071d4272004-06-13 20:20:40 +00004429
4430 The result is a Number: 1 for a successful operation,
4431 otherwise 0 is returned.
4432
4433 Examples:
4434 Clear expression register history: >
4435 :call histdel("expr")
4436<
4437 Remove all entries starting with "*" from the search history: >
4438 :call histdel("/", '^\*')
4439<
4440 The following three are equivalent: >
4441 :call histdel("search", histnr("search"))
4442 :call histdel("search", -1)
4443 :call histdel("search", '^'.histget("search", -1).'$')
4444<
4445 To delete the last search pattern and use the last-but-one for
4446 the "n" command and 'hlsearch': >
4447 :call histdel("search", -1)
4448 :let @/ = histget("search", -1)
4449
4450histget({history} [, {index}]) *histget()*
4451 The result is a String, the entry with Number {index} from
4452 {history}. See |hist-names| for the possible values of
4453 {history}, and |:history-indexing| for {index}. If there is
4454 no such entry, an empty String is returned. When {index} is
4455 omitted, the most recent item from the history is used.
4456
4457 Examples:
4458 Redo the second last search from history. >
4459 :execute '/' . histget("search", -2)
4460
4461< Define an Ex command ":H {num}" that supports re-execution of
4462 the {num}th entry from the output of |:history|. >
4463 :command -nargs=1 H execute histget("cmd", 0+<args>)
4464<
4465histnr({history}) *histnr()*
4466 The result is the Number of the current entry in {history}.
4467 See |hist-names| for the possible values of {history}.
4468 If an error occurred, -1 is returned.
4469
4470 Example: >
4471 :let inp_index = histnr("expr")
4472<
4473hlexists({name}) *hlexists()*
4474 The result is a Number, which is non-zero if a highlight group
4475 called {name} exists. This is when the group has been
4476 defined in some way. Not necessarily when highlighting has
4477 been defined for it, it may also have been used for a syntax
4478 item.
4479 *highlight_exists()*
4480 Obsolete name: highlight_exists().
4481
4482 *hlID()*
4483hlID({name}) The result is a Number, which is the ID of the highlight group
4484 with name {name}. When the highlight group doesn't exist,
4485 zero is returned.
4486 This can be used to retrieve information about the highlight
Bram Moolenaar446cb832008-06-24 21:56:24 +00004487 group. For example, to get the background color of the
Bram Moolenaar071d4272004-06-13 20:20:40 +00004488 "Comment" group: >
4489 :echo synIDattr(synIDtrans(hlID("Comment")), "bg")
4490< *highlightID()*
4491 Obsolete name: highlightID().
4492
4493hostname() *hostname()*
4494 The result is a String, which is the name of the machine on
Bram Moolenaar402d2fe2005-04-15 21:00:38 +00004495 which Vim is currently running. Machine names greater than
Bram Moolenaar071d4272004-06-13 20:20:40 +00004496 256 characters long are truncated.
4497
4498iconv({expr}, {from}, {to}) *iconv()*
4499 The result is a String, which is the text {expr} converted
4500 from encoding {from} to encoding {to}.
Bram Moolenaar8f3f58f2010-01-06 20:52:26 +01004501 When the conversion completely fails an empty string is
4502 returned. When some characters could not be converted they
4503 are replaced with "?".
Bram Moolenaar071d4272004-06-13 20:20:40 +00004504 The encoding names are whatever the iconv() library function
4505 can accept, see ":!man 3 iconv".
4506 Most conversions require Vim to be compiled with the |+iconv|
4507 feature. Otherwise only UTF-8 to latin1 conversion and back
4508 can be done.
4509 This can be used to display messages with special characters,
4510 no matter what 'encoding' is set to. Write the message in
4511 UTF-8 and use: >
4512 echo iconv(utf8_str, "utf-8", &enc)
4513< Note that Vim uses UTF-8 for all Unicode encodings, conversion
4514 from/to UCS-2 is automatically changed to use UTF-8. You
4515 cannot use UCS-2 in a string anyway, because of the NUL bytes.
Bram Moolenaardb84e452010-08-15 13:50:43 +02004516 {only available when compiled with the |+multi_byte| feature}
Bram Moolenaar071d4272004-06-13 20:20:40 +00004517
4518 *indent()*
4519indent({lnum}) The result is a Number, which is indent of line {lnum} in the
4520 current buffer. The indent is counted in spaces, the value
4521 of 'tabstop' is relevant. {lnum} is used just like in
4522 |getline()|.
4523 When {lnum} is invalid -1 is returned.
4524
Bram Moolenaarde8866b2005-01-06 23:24:37 +00004525
Bram Moolenaar5f2bb9f2005-01-11 21:29:04 +00004526index({list}, {expr} [, {start} [, {ic}]]) *index()*
Bram Moolenaar32466aa2006-02-24 23:53:04 +00004527 Return the lowest index in |List| {list} where the item has a
Bram Moolenaar8f3f58f2010-01-06 20:52:26 +01004528 value equal to {expr}. There is no automatic conversion, so
4529 the String "4" is different from the Number 4. And the number
4530 4 is different from the Float 4.0. The value of 'ignorecase'
4531 is not used here, case always matters.
Bram Moolenaar748bf032005-02-02 23:04:36 +00004532 If {start} is given then start looking at the item with index
4533 {start} (may be negative for an item relative to the end).
Bram Moolenaarde8866b2005-01-06 23:24:37 +00004534 When {ic} is given and it is non-zero, ignore case. Otherwise
4535 case must match.
4536 -1 is returned when {expr} is not found in {list}.
4537 Example: >
4538 :let idx = index(words, "the")
Bram Moolenaar9588a0f2005-01-08 21:45:39 +00004539 :if index(numbers, 123) >= 0
Bram Moolenaarde8866b2005-01-06 23:24:37 +00004540
4541
Bram Moolenaarbfd8fc02005-09-20 23:22:24 +00004542input({prompt} [, {text} [, {completion}]]) *input()*
Bram Moolenaar071d4272004-06-13 20:20:40 +00004543 The result is a String, which is whatever the user typed on
Bram Moolenaar8f3f58f2010-01-06 20:52:26 +01004544 the command-line. The {prompt} argument is either a prompt
4545 string, or a blank string (for no prompt). A '\n' can be used
4546 in the prompt to start a new line.
Bram Moolenaarbfd8fc02005-09-20 23:22:24 +00004547 The highlighting set with |:echohl| is used for the prompt.
4548 The input is entered just like a command-line, with the same
Bram Moolenaar446cb832008-06-24 21:56:24 +00004549 editing commands and mappings. There is a separate history
Bram Moolenaarbfd8fc02005-09-20 23:22:24 +00004550 for lines typed for input().
4551 Example: >
4552 :if input("Coffee or beer? ") == "beer"
4553 : echo "Cheers!"
4554 :endif
4555<
Bram Moolenaar8f3f58f2010-01-06 20:52:26 +01004556 If the optional {text} argument is present and not empty, this
4557 is used for the default reply, as if the user typed this.
4558 Example: >
Bram Moolenaarbfd8fc02005-09-20 23:22:24 +00004559 :let color = input("Color? ", "white")
4560
4561< The optional {completion} argument specifies the type of
4562 completion supported for the input. Without it completion is
Bram Moolenaar446cb832008-06-24 21:56:24 +00004563 not performed. The supported completion types are the same as
Bram Moolenaarbfd8fc02005-09-20 23:22:24 +00004564 that can be supplied to a user-defined command using the
Bram Moolenaar446cb832008-06-24 21:56:24 +00004565 "-complete=" argument. Refer to |:command-completion| for
Bram Moolenaarbfd8fc02005-09-20 23:22:24 +00004566 more information. Example: >
4567 let fname = input("File: ", "", "file")
4568<
4569 NOTE: This function must not be used in a startup file, for
4570 the versions that only run in GUI mode (e.g., the Win32 GUI).
Bram Moolenaar071d4272004-06-13 20:20:40 +00004571 Note: When input() is called from within a mapping it will
4572 consume remaining characters from that mapping, because a
4573 mapping is handled like the characters were typed.
4574 Use |inputsave()| before input() and |inputrestore()|
4575 after input() to avoid that. Another solution is to avoid
4576 that further characters follow in the mapping, e.g., by using
4577 |:execute| or |:normal|.
4578
Bram Moolenaarbfd8fc02005-09-20 23:22:24 +00004579 Example with a mapping: >
Bram Moolenaar071d4272004-06-13 20:20:40 +00004580 :nmap \x :call GetFoo()<CR>:exe "/" . Foo<CR>
4581 :function GetFoo()
4582 : call inputsave()
4583 : let g:Foo = input("enter search pattern: ")
4584 : call inputrestore()
4585 :endfunction
4586
4587inputdialog({prompt} [, {text} [, {cancelreturn}]]) *inputdialog()*
Bram Moolenaar8f3f58f2010-01-06 20:52:26 +01004588 Like |input()|, but when the GUI is running and text dialogs
4589 are supported, a dialog window pops up to input the text.
Bram Moolenaar071d4272004-06-13 20:20:40 +00004590 Example: >
Bram Moolenaar2d17fa32012-10-21 00:45:18 +02004591 :let n = inputdialog("value for shiftwidth", shiftwidth())
4592 :if n != ""
4593 : let &sw = n
4594 :endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004595< When the dialog is cancelled {cancelreturn} is returned. When
4596 omitted an empty string is returned.
4597 Hitting <Enter> works like pressing the OK button. Hitting
4598 <Esc> works like pressing the Cancel button.
Bram Moolenaarbfd8fc02005-09-20 23:22:24 +00004599 NOTE: Command-line completion is not supported.
Bram Moolenaar071d4272004-06-13 20:20:40 +00004600
Bram Moolenaar578b49e2005-09-10 19:22:57 +00004601inputlist({textlist}) *inputlist()*
Bram Moolenaar910f66f2006-04-05 20:41:53 +00004602 {textlist} must be a |List| of strings. This |List| is
4603 displayed, one string per line. The user will be prompted to
4604 enter a number, which is returned.
Bram Moolenaar578b49e2005-09-10 19:22:57 +00004605 The user can also select an item by clicking on it with the
Bram Moolenaar446cb832008-06-24 21:56:24 +00004606 mouse. For the first string 0 is returned. When clicking
Bram Moolenaar578b49e2005-09-10 19:22:57 +00004607 above the first item a negative number is returned. When
4608 clicking on the prompt one more than the length of {textlist}
4609 is returned.
Bram Moolenaar8f3f58f2010-01-06 20:52:26 +01004610 Make sure {textlist} has less than 'lines' entries, otherwise
Bram Moolenaar446cb832008-06-24 21:56:24 +00004611 it won't work. It's a good idea to put the entry number at
Bram Moolenaaref2f6562007-05-06 13:32:59 +00004612 the start of the string. And put a prompt in the first item.
4613 Example: >
Bram Moolenaar578b49e2005-09-10 19:22:57 +00004614 let color = inputlist(['Select color:', '1. red',
4615 \ '2. green', '3. blue'])
4616
Bram Moolenaar071d4272004-06-13 20:20:40 +00004617inputrestore() *inputrestore()*
Bram Moolenaar8f3f58f2010-01-06 20:52:26 +01004618 Restore typeahead that was saved with a previous |inputsave()|.
Bram Moolenaar071d4272004-06-13 20:20:40 +00004619 Should be called the same number of times inputsave() is
4620 called. Calling it more often is harmless though.
4621 Returns 1 when there is nothing to restore, 0 otherwise.
4622
4623inputsave() *inputsave()*
4624 Preserve typeahead (also from mappings) and clear it, so that
4625 a following prompt gets input from the user. Should be
4626 followed by a matching inputrestore() after the prompt. Can
4627 be used several times, in which case there must be just as
4628 many inputrestore() calls.
4629 Returns 1 when out of memory, 0 otherwise.
4630
4631inputsecret({prompt} [, {text}]) *inputsecret()*
4632 This function acts much like the |input()| function with but
4633 two exceptions:
4634 a) the user's response will be displayed as a sequence of
4635 asterisks ("*") thereby keeping the entry secret, and
4636 b) the user's response will not be recorded on the input
4637 |history| stack.
4638 The result is a String, which is whatever the user actually
4639 typed on the command-line in response to the issued prompt.
Bram Moolenaarbfd8fc02005-09-20 23:22:24 +00004640 NOTE: Command-line completion is not supported.
Bram Moolenaar071d4272004-06-13 20:20:40 +00004641
Bram Moolenaard7ee7ce2005-01-03 21:02:03 +00004642insert({list}, {item} [, {idx}]) *insert()*
Bram Moolenaar32466aa2006-02-24 23:53:04 +00004643 Insert {item} at the start of |List| {list}.
Bram Moolenaard7ee7ce2005-01-03 21:02:03 +00004644 If {idx} is specified insert {item} before the item with index
Bram Moolenaar446cb832008-06-24 21:56:24 +00004645 {idx}. If {idx} is zero it goes before the first item, just
Bram Moolenaard7ee7ce2005-01-03 21:02:03 +00004646 like omitting {idx}. A negative {idx} is also possible, see
4647 |list-index|. -1 inserts just before the last item.
Bram Moolenaar32466aa2006-02-24 23:53:04 +00004648 Returns the resulting |List|. Examples: >
Bram Moolenaard7ee7ce2005-01-03 21:02:03 +00004649 :let mylist = insert([2, 3, 5], 1)
4650 :call insert(mylist, 4, -1)
4651 :call insert(mylist, 6, len(mylist))
Bram Moolenaara14de3d2005-01-07 21:48:26 +00004652< The last example can be done simpler with |add()|.
Bram Moolenaar32466aa2006-02-24 23:53:04 +00004653 Note that when {item} is a |List| it is inserted as a single
Bram Moolenaara23ccb82006-02-27 00:08:02 +00004654 item. Use |extend()| to concatenate |Lists|.
Bram Moolenaard7ee7ce2005-01-03 21:02:03 +00004655
Bram Moolenaard6e256c2011-12-14 15:32:50 +01004656invert({expr}) *invert()*
4657 Bitwise invert. The argument is converted to a number. A
4658 List, Dict or Float argument causes an error. Example: >
4659 :let bits = invert(bits)
4660
Bram Moolenaar071d4272004-06-13 20:20:40 +00004661isdirectory({directory}) *isdirectory()*
4662 The result is a Number, which is non-zero when a directory
4663 with the name {directory} exists. If {directory} doesn't
4664 exist, or isn't a directory, the result is FALSE. {directory}
4665 is any expression, which is used as a String.
4666
Bram Moolenaar910f66f2006-04-05 20:41:53 +00004667islocked({expr}) *islocked()* *E786*
Bram Moolenaar2ce06f62005-01-31 19:19:04 +00004668 The result is a Number, which is non-zero when {expr} is the
4669 name of a locked variable.
Bram Moolenaar32466aa2006-02-24 23:53:04 +00004670 {expr} must be the name of a variable, |List| item or
4671 |Dictionary| entry, not the variable itself! Example: >
Bram Moolenaar2ce06f62005-01-31 19:19:04 +00004672 :let alist = [0, ['a', 'b'], 2, 3]
4673 :lockvar 1 alist
4674 :echo islocked('alist') " 1
4675 :echo islocked('alist[1]') " 0
4676
4677< When {expr} is a variable that does not exist you get an error
Bram Moolenaar551dbcc2006-04-25 22:13:59 +00004678 message. Use |exists()| to check for existence.
Bram Moolenaar2ce06f62005-01-31 19:19:04 +00004679
Bram Moolenaarf3913272016-02-25 00:00:01 +01004680isnan({expr}) *isnan()*
4681 Return non-zero if {expr} is a float with value NaN. >
4682 echo isnan(0.0 / 0.0)
4683< 1 ~
4684
4685 {only available when compiled with the |+float| feature}
4686
Bram Moolenaar677ee682005-01-27 14:41:15 +00004687items({dict}) *items()*
Bram Moolenaar32466aa2006-02-24 23:53:04 +00004688 Return a |List| with all the key-value pairs of {dict}. Each
4689 |List| item is a list with two items: the key of a {dict}
4690 entry and the value of this entry. The |List| is in arbitrary
4691 order.
Bram Moolenaar677ee682005-01-27 14:41:15 +00004692
Bram Moolenaar38a55632016-02-15 22:07:32 +01004693job_getchannel({job}) *job_getchannel()*
4694 Get the channel handle that {job} is using.
Bram Moolenaar77cdfd12016-03-12 12:57:59 +01004695 To check if the job has no channel: >
4696 if string(job_getchannel()) == 'channel fail'
4697<
Bram Moolenaar38a55632016-02-15 22:07:32 +01004698 {only available when compiled with the |+job| feature}
4699
Bram Moolenaarf6f32c32016-03-12 19:03:59 +01004700job_info({job}) *job_info()*
4701 Returns a Dictionary with information about {job}:
4702 "status" what |job_status()| returns
4703 "channel" what |job_getchannel()| returns
4704 "exitval" only valid when "status" is "dead"
Bram Moolenaar975b5272016-03-15 23:10:59 +01004705 "exit_cb" function to be called on exit
Bram Moolenaarf6f32c32016-03-12 19:03:59 +01004706 "stoponexit" |job-stoponexit|
4707
Bram Moolenaar02e83b42016-02-21 20:10:26 +01004708job_setoptions({job}, {options}) *job_setoptions()*
4709 Change options for {job}. Supported are:
Bram Moolenaarf6f32c32016-03-12 19:03:59 +01004710 "stoponexit" |job-stoponexit|
Bram Moolenaar975b5272016-03-15 23:10:59 +01004711 "exit_cb" |job-exit_cb|
Bram Moolenaar02e83b42016-02-21 20:10:26 +01004712
Bram Moolenaar38a55632016-02-15 22:07:32 +01004713job_start({command} [, {options}]) *job_start()*
Bram Moolenaar835dc632016-02-07 14:27:38 +01004714 Start a job and return a Job object. Unlike |system()| and
4715 |:!cmd| this does not wait for the job to finish.
4716
Bram Moolenaar6463ca22016-02-13 17:04:46 +01004717 {command} can be a String. This works best on MS-Windows. On
Bram Moolenaar835dc632016-02-07 14:27:38 +01004718 Unix it is split up in white-separated parts to be passed to
4719 execvp(). Arguments in double quotes can contain white space.
4720
Bram Moolenaar6463ca22016-02-13 17:04:46 +01004721 {command} can be a List, where the first item is the executable
Bram Moolenaar835dc632016-02-07 14:27:38 +01004722 and further items are the arguments. All items are converted
4723 to String. This works best on Unix.
4724
Bram Moolenaar6463ca22016-02-13 17:04:46 +01004725 On MS-Windows, job_start() makes a GUI application hidden. If
4726 want to show it, Use |:!start| instead.
4727
Bram Moolenaar835dc632016-02-07 14:27:38 +01004728 The command is executed directly, not through a shell, the
4729 'shell' option is not used. To use the shell: >
4730 let job = job_start(["/bin/sh", "-c", "echo hello"])
4731< Or: >
4732 let job = job_start('/bin/sh -c "echo hello"')
Bram Moolenaar6463ca22016-02-13 17:04:46 +01004733< Note that this will start two processes, the shell and the
4734 command it executes. If you don't want this use the "exec"
4735 shell command.
Bram Moolenaar835dc632016-02-07 14:27:38 +01004736
4737 On Unix $PATH is used to search for the executable only when
4738 the command does not contain a slash.
4739
4740 The job will use the same terminal as Vim. If it reads from
4741 stdin the job and Vim will be fighting over input, that
4742 doesn't work. Redirect stdin and stdout to avoid problems: >
4743 let job = job_start(['sh', '-c', "myserver </dev/null >/dev/null"])
4744<
4745 The returned Job object can be used to get the status with
4746 |job_status()| and stop the job with |job_stop()|.
4747
Bram Moolenaar6463ca22016-02-13 17:04:46 +01004748 {options} must be a Dictionary. It can contain many optional
4749 items, see |job-options|.
Bram Moolenaar835dc632016-02-07 14:27:38 +01004750
Bram Moolenaar6463ca22016-02-13 17:04:46 +01004751 {only available when compiled with the |+job| feature}
Bram Moolenaar835dc632016-02-07 14:27:38 +01004752
Bram Moolenaar02e83b42016-02-21 20:10:26 +01004753job_status({job}) *job_status()* *E916*
Bram Moolenaar835dc632016-02-07 14:27:38 +01004754 Returns a String with the status of {job}:
4755 "run" job is running
4756 "fail" job failed to start
4757 "dead" job died or was stopped after running
Bram Moolenaar02e83b42016-02-21 20:10:26 +01004758
Bram Moolenaar511972d2016-06-04 18:09:59 +02004759 On Unix a non-existing command results in "dead" instead of
4760 "fail", because a fork happens before the failure can be
4761 detected.
4762
Bram Moolenaar03413f42016-04-12 21:07:15 +02004763 If an exit callback was set with the "exit_cb" option and the
Bram Moolenaar02e83b42016-02-21 20:10:26 +01004764 job is now detected to be "dead" the callback will be invoked.
Bram Moolenaar835dc632016-02-07 14:27:38 +01004765
Bram Moolenaar8950a562016-03-12 15:22:55 +01004766 For more information see |job_info()|.
4767
Bram Moolenaar6463ca22016-02-13 17:04:46 +01004768 {only available when compiled with the |+job| feature}
Bram Moolenaar835dc632016-02-07 14:27:38 +01004769
4770job_stop({job} [, {how}]) *job_stop()*
4771 Stop the {job}. This can also be used to signal the job.
4772
Bram Moolenaar923d9262016-02-25 20:56:01 +01004773 When {how} is omitted or is "term" the job will be terminated.
4774 For Unix SIGTERM is sent. On MS-Windows the job will be
4775 terminated forcedly (there is no "gentle" way).
4776 This goes to the process group, thus children may also be
4777 affected.
Bram Moolenaar6463ca22016-02-13 17:04:46 +01004778
Bram Moolenaar923d9262016-02-25 20:56:01 +01004779 Effect for Unix:
4780 "term" SIGTERM (default)
4781 "hup" SIGHUP
4782 "quit" SIGQUIT
4783 "int" SIGINT
4784 "kill" SIGKILL (strongest way to stop)
4785 number signal with that number
Bram Moolenaar835dc632016-02-07 14:27:38 +01004786
Bram Moolenaar923d9262016-02-25 20:56:01 +01004787 Effect for MS-Windows:
4788 "term" terminate process forcedly (default)
4789 "hup" CTRL_BREAK
4790 "quit" CTRL_BREAK
4791 "int" CTRL_C
4792 "kill" terminate process forcedly
4793 Others CTRL_BREAK
Bram Moolenaar6463ca22016-02-13 17:04:46 +01004794
4795 On Unix the signal is sent to the process group. This means
4796 that when the job is "sh -c command" it affects both the shell
4797 and the command.
4798
Bram Moolenaar835dc632016-02-07 14:27:38 +01004799 The result is a Number: 1 if the operation could be executed,
4800 0 if "how" is not supported on the system.
4801 Note that even when the operation was executed, whether the
4802 job was actually stopped needs to be checked with
4803 job_status().
Bram Moolenaar6463ca22016-02-13 17:04:46 +01004804 The status of the job isn't checked, the operation will even
4805 be done when Vim thinks the job isn't running.
Bram Moolenaar835dc632016-02-07 14:27:38 +01004806
Bram Moolenaar6463ca22016-02-13 17:04:46 +01004807 {only available when compiled with the |+job| feature}
Bram Moolenaar835dc632016-02-07 14:27:38 +01004808
Bram Moolenaar5f2bb9f2005-01-11 21:29:04 +00004809join({list} [, {sep}]) *join()*
4810 Join the items in {list} together into one String.
4811 When {sep} is specified it is put in between the items. If
4812 {sep} is omitted a single space is used.
4813 Note that {sep} is not added at the end. You might want to
4814 add it there too: >
4815 let lines = join(mylist, "\n") . "\n"
Bram Moolenaara23ccb82006-02-27 00:08:02 +00004816< String items are used as-is. |Lists| and |Dictionaries| are
Bram Moolenaar5f2bb9f2005-01-11 21:29:04 +00004817 converted into a string like with |string()|.
4818 The opposite function is |split()|.
4819
Bram Moolenaar7823a3b2016-02-11 21:08:32 +01004820js_decode({string}) *js_decode()*
4821 This is similar to |json_decode()| with these differences:
Bram Moolenaar595e64e2016-02-07 19:19:53 +01004822 - Object key names do not have to be in quotes.
4823 - Empty items in an array (between two commas) are allowed and
4824 result in v:none items.
4825
Bram Moolenaar7823a3b2016-02-11 21:08:32 +01004826js_encode({expr}) *js_encode()*
4827 This is similar to |json_encode()| with these differences:
Bram Moolenaar595e64e2016-02-07 19:19:53 +01004828 - Object key names are not in quotes.
4829 - v:none items in an array result in an empty item between
4830 commas.
4831 For example, the Vim object:
Bram Moolenaar7823a3b2016-02-11 21:08:32 +01004832 [1,v:none,{"one":1},v:none] ~
Bram Moolenaar595e64e2016-02-07 19:19:53 +01004833 Will be encoded as:
4834 [1,,{one:1},,] ~
Bram Moolenaar7823a3b2016-02-11 21:08:32 +01004835 While json_encode() would produce:
Bram Moolenaar595e64e2016-02-07 19:19:53 +01004836 [1,null,{"one":1},null] ~
4837 This encoding is valid for JavaScript. It is more efficient
4838 than JSON, especially when using an array with optional items.
4839
4840
Bram Moolenaar7823a3b2016-02-11 21:08:32 +01004841json_decode({string}) *json_decode()*
Bram Moolenaar705ada12016-01-24 17:56:50 +01004842 This parses a JSON formatted string and returns the equivalent
Bram Moolenaar7823a3b2016-02-11 21:08:32 +01004843 in Vim values. See |json_encode()| for the relation between
Bram Moolenaar705ada12016-01-24 17:56:50 +01004844 JSON and Vim values.
4845 The decoding is permissive:
4846 - A trailing comma in an array and object is ignored.
Bram Moolenaar705ada12016-01-24 17:56:50 +01004847 - More floating point numbers are recognized, e.g. "1." for
4848 "1.0".
Bram Moolenaar009d84a2016-01-28 14:12:00 +01004849 The result must be a valid Vim type:
4850 - An empty object member name is not allowed.
4851 - Duplicate object member names are not allowed.
Bram Moolenaar520e1e42016-01-23 19:46:28 +01004852
Bram Moolenaar7823a3b2016-02-11 21:08:32 +01004853json_encode({expr}) *json_encode()*
Bram Moolenaar705ada12016-01-24 17:56:50 +01004854 Encode {expr} as JSON and return this as a string.
Bram Moolenaar520e1e42016-01-23 19:46:28 +01004855 The encoding is specified in:
Bram Moolenaar009d84a2016-01-28 14:12:00 +01004856 https://tools.ietf.org/html/rfc7159.html
Bram Moolenaar520e1e42016-01-23 19:46:28 +01004857 Vim values are converted as follows:
4858 Number decimal number
4859 Float floating point number
Bram Moolenaar7ce686c2016-02-27 16:33:22 +01004860 Float nan "NaN"
4861 Float inf "Infinity"
Bram Moolenaar520e1e42016-01-23 19:46:28 +01004862 String in double quotes (possibly null)
Bram Moolenaar705ada12016-01-24 17:56:50 +01004863 Funcref not possible, error
Bram Moolenaar520e1e42016-01-23 19:46:28 +01004864 List as an array (possibly null); when
Bram Moolenaar81edd172016-04-14 13:51:37 +02004865 used recursively: []
Bram Moolenaar520e1e42016-01-23 19:46:28 +01004866 Dict as an object (possibly null); when
Bram Moolenaar81edd172016-04-14 13:51:37 +02004867 used recursively: {}
Bram Moolenaar520e1e42016-01-23 19:46:28 +01004868 v:false "false"
4869 v:true "true"
Bram Moolenaar595e64e2016-02-07 19:19:53 +01004870 v:none "null"
Bram Moolenaar520e1e42016-01-23 19:46:28 +01004871 v:null "null"
Bram Moolenaar7ce686c2016-02-27 16:33:22 +01004872 Note that NaN and Infinity are passed on as values. This is
4873 missing in the JSON standard, but several implementations do
4874 allow it. If not then you will get an error.
Bram Moolenaar520e1e42016-01-23 19:46:28 +01004875
Bram Moolenaard8b02732005-01-14 21:48:43 +00004876keys({dict}) *keys()*
Bram Moolenaar32466aa2006-02-24 23:53:04 +00004877 Return a |List| with all the keys of {dict}. The |List| is in
Bram Moolenaard8b02732005-01-14 21:48:43 +00004878 arbitrary order.
4879
Bram Moolenaar13065c42005-01-08 16:08:21 +00004880 *len()* *E701*
Bram Moolenaard7ee7ce2005-01-03 21:02:03 +00004881len({expr}) The result is a Number, which is the length of the argument.
4882 When {expr} is a String or a Number the length in bytes is
4883 used, as with |strlen()|.
Bram Moolenaar32466aa2006-02-24 23:53:04 +00004884 When {expr} is a |List| the number of items in the |List| is
Bram Moolenaard7ee7ce2005-01-03 21:02:03 +00004885 returned.
Bram Moolenaar32466aa2006-02-24 23:53:04 +00004886 When {expr} is a |Dictionary| the number of entries in the
4887 |Dictionary| is returned.
Bram Moolenaard7ee7ce2005-01-03 21:02:03 +00004888 Otherwise an error is given.
4889
Bram Moolenaar071d4272004-06-13 20:20:40 +00004890 *libcall()* *E364* *E368*
4891libcall({libname}, {funcname}, {argument})
4892 Call function {funcname} in the run-time library {libname}
4893 with single argument {argument}.
4894 This is useful to call functions in a library that you
4895 especially made to be used with Vim. Since only one argument
4896 is possible, calling standard library functions is rather
4897 limited.
4898 The result is the String returned by the function. If the
4899 function returns NULL, this will appear as an empty string ""
4900 to Vim.
4901 If the function returns a number, use libcallnr()!
4902 If {argument} is a number, it is passed to the function as an
4903 int; if {argument} is a string, it is passed as a
4904 null-terminated string.
4905 This function will fail in |restricted-mode|.
4906
4907 libcall() allows you to write your own 'plug-in' extensions to
4908 Vim without having to recompile the program. It is NOT a
4909 means to call system functions! If you try to do so Vim will
4910 very probably crash.
4911
4912 For Win32, the functions you write must be placed in a DLL
4913 and use the normal C calling convention (NOT Pascal which is
4914 used in Windows System DLLs). The function must take exactly
4915 one parameter, either a character pointer or a long integer,
4916 and must return a character pointer or NULL. The character
4917 pointer returned must point to memory that will remain valid
4918 after the function has returned (e.g. in static data in the
4919 DLL). If it points to allocated memory, that memory will
4920 leak away. Using a static buffer in the function should work,
4921 it's then freed when the DLL is unloaded.
4922
4923 WARNING: If the function returns a non-valid pointer, Vim may
Bram Moolenaar446cb832008-06-24 21:56:24 +00004924 crash! This also happens if the function returns a number,
Bram Moolenaar071d4272004-06-13 20:20:40 +00004925 because Vim thinks it's a pointer.
4926 For Win32 systems, {libname} should be the filename of the DLL
4927 without the ".DLL" suffix. A full path is only required if
4928 the DLL is not in the usual places.
4929 For Unix: When compiling your own plugins, remember that the
4930 object code must be compiled as position-independent ('PIC').
Bram Moolenaar8f3f58f2010-01-06 20:52:26 +01004931 {only in Win32 and some Unix versions, when the |+libcall|
Bram Moolenaar071d4272004-06-13 20:20:40 +00004932 feature is present}
4933 Examples: >
4934 :echo libcall("libc.so", "getenv", "HOME")
Bram Moolenaar071d4272004-06-13 20:20:40 +00004935<
4936 *libcallnr()*
4937libcallnr({libname}, {funcname}, {argument})
Bram Moolenaar8f3f58f2010-01-06 20:52:26 +01004938 Just like |libcall()|, but used for a function that returns an
Bram Moolenaar071d4272004-06-13 20:20:40 +00004939 int instead of a string.
4940 {only in Win32 on some Unix versions, when the |+libcall|
4941 feature is present}
Bram Moolenaar446cb832008-06-24 21:56:24 +00004942 Examples: >
4943 :echo libcallnr("/usr/lib/libc.so", "getpid", "")
Bram Moolenaar071d4272004-06-13 20:20:40 +00004944 :call libcallnr("libc.so", "printf", "Hello World!\n")
4945 :call libcallnr("libc.so", "sleep", 10)
4946<
4947 *line()*
4948line({expr}) The result is a Number, which is the line number of the file
4949 position given with {expr}. The accepted positions are:
4950 . the cursor position
4951 $ the last line in the current buffer
4952 'x position of mark x (if the mark is not set, 0 is
4953 returned)
Bram Moolenaarc7453f52006-02-10 23:20:28 +00004954 w0 first line visible in current window
4955 w$ last line visible in current window
Bram Moolenaar9ecd0232008-06-20 15:31:51 +00004956 v In Visual mode: the start of the Visual area (the
4957 cursor is the end). When not in Visual mode
4958 returns the cursor position. Differs from |'<| in
4959 that it's updated right away.
Bram Moolenaaref2f6562007-05-06 13:32:59 +00004960 Note that a mark in another file can be used. The line number
4961 then applies to another buffer.
Bram Moolenaar0b238792006-03-02 22:49:12 +00004962 To get the column number use |col()|. To get both use
4963 |getpos()|.
Bram Moolenaar071d4272004-06-13 20:20:40 +00004964 Examples: >
4965 line(".") line number of the cursor
4966 line("'t") line number of mark t
4967 line("'" . marker) line number of mark marker
4968< *last-position-jump*
4969 This autocommand jumps to the last known position in a file
4970 just after opening it, if the '" mark is set: >
Bram Moolenaar8f3f58f2010-01-06 20:52:26 +01004971 :au BufReadPost * if line("'\"") > 1 && line("'\"") <= line("$") | exe "normal! g`\"" | endif
Bram Moolenaar69a7cb42004-06-20 12:51:53 +00004972
Bram Moolenaar071d4272004-06-13 20:20:40 +00004973line2byte({lnum}) *line2byte()*
4974 Return the byte count from the start of the buffer for line
4975 {lnum}. This includes the end-of-line character, depending on
4976 the 'fileformat' option for the current buffer. The first
Bram Moolenaarb6b046b2011-12-30 13:11:27 +01004977 line returns 1. 'encoding' matters, 'fileencoding' is ignored.
Bram Moolenaar071d4272004-06-13 20:20:40 +00004978 This can also be used to get the byte count for the line just
4979 below the last line: >
4980 line2byte(line("$") + 1)
Bram Moolenaarb6b046b2011-12-30 13:11:27 +01004981< This is the buffer size plus one. If 'fileencoding' is empty
4982 it is the file size plus one.
Bram Moolenaar071d4272004-06-13 20:20:40 +00004983 When {lnum} is invalid, or the |+byte_offset| feature has been
4984 disabled at compile time, -1 is returned.
4985 Also see |byte2line()|, |go| and |:goto|.
4986
4987lispindent({lnum}) *lispindent()*
4988 Get the amount of indent for line {lnum} according the lisp
4989 indenting rules, as with 'lisp'.
4990 The indent is counted in spaces, the value of 'tabstop' is
4991 relevant. {lnum} is used just like in |getline()|.
4992 When {lnum} is invalid or Vim was not compiled the
4993 |+lispindent| feature, -1 is returned.
4994
4995localtime() *localtime()*
4996 Return the current time, measured as seconds since 1st Jan
4997 1970. See also |strftime()| and |getftime()|.
4998
Bram Moolenaar5f2bb9f2005-01-11 21:29:04 +00004999
Bram Moolenaardb7c6862010-05-21 16:33:48 +02005000log({expr}) *log()*
Bram Moolenaar9855d6b2010-07-18 14:34:51 +02005001 Return the natural logarithm (base e) of {expr} as a |Float|.
5002 {expr} must evaluate to a |Float| or a |Number| in the range
Bram Moolenaardb7c6862010-05-21 16:33:48 +02005003 (0, inf].
5004 Examples: >
5005 :echo log(10)
5006< 2.302585 >
5007 :echo log(exp(5))
5008< 5.0
Bram Moolenaardb84e452010-08-15 13:50:43 +02005009 {only available when compiled with the |+float| feature}
Bram Moolenaardb7c6862010-05-21 16:33:48 +02005010
5011
Bram Moolenaar446cb832008-06-24 21:56:24 +00005012log10({expr}) *log10()*
5013 Return the logarithm of Float {expr} to base 10 as a |Float|.
5014 {expr} must evaluate to a |Float| or a |Number|.
5015 Examples: >
5016 :echo log10(1000)
5017< 3.0 >
5018 :echo log10(0.01)
5019< -2.0
5020 {only available when compiled with the |+float| feature}
5021
Bram Moolenaard38b0552012-04-25 19:07:41 +02005022luaeval({expr}[, {expr}]) *luaeval()*
5023 Evaluate Lua expression {expr} and return its result converted
5024 to Vim data structures. Second {expr} may hold additional
5025 argument accessible as _A inside first {expr}.
5026 Strings are returned as they are.
5027 Boolean objects are converted to numbers.
5028 Numbers are converted to |Float| values if vim was compiled
5029 with |+float| and to numbers otherwise.
5030 Dictionaries and lists obtained by vim.eval() are returned
5031 as-is.
5032 Other objects are returned as zero without any errors.
5033 See |lua-luaeval| for more details.
5034 {only available when compiled with the |+lua| feature}
5035
Bram Moolenaar2fda12f2005-01-15 22:14:15 +00005036map({expr}, {string}) *map()*
Bram Moolenaar32466aa2006-02-24 23:53:04 +00005037 {expr} must be a |List| or a |Dictionary|.
Bram Moolenaar2fda12f2005-01-15 22:14:15 +00005038 Replace each item in {expr} with the result of evaluating
5039 {string}.
5040 Inside {string} |v:val| has the value of the current item.
Bram Moolenaar627b1d32009-11-17 11:20:35 +00005041 For a |Dictionary| |v:key| has the key of the current item
5042 and for a |List| |v:key| has the index of the current item.
Bram Moolenaar2fda12f2005-01-15 22:14:15 +00005043 Example: >
5044 :call map(mylist, '"> " . v:val . " <"')
Bram Moolenaar5f2bb9f2005-01-11 21:29:04 +00005045< This puts "> " before and " <" after each item in "mylist".
Bram Moolenaar2fda12f2005-01-15 22:14:15 +00005046
Bram Moolenaar3a7c85b2005-02-05 21:39:53 +00005047 Note that {string} is the result of an expression and is then
Bram Moolenaar2fda12f2005-01-15 22:14:15 +00005048 used as an expression again. Often it is good to use a
Bram Moolenaar3a7c85b2005-02-05 21:39:53 +00005049 |literal-string| to avoid having to double backslashes. You
5050 still have to double ' quotes
Bram Moolenaar2fda12f2005-01-15 22:14:15 +00005051
Bram Moolenaar32466aa2006-02-24 23:53:04 +00005052 The operation is done in-place. If you want a |List| or
5053 |Dictionary| to remain unmodified make a copy first: >
Bram Moolenaar30b65812012-07-12 22:01:11 +02005054 :let tlist = map(copy(mylist), ' v:val . "\t"')
Bram Moolenaar2fda12f2005-01-15 22:14:15 +00005055
Bram Moolenaar32466aa2006-02-24 23:53:04 +00005056< Returns {expr}, the |List| or |Dictionary| that was filtered.
Bram Moolenaar280f1262006-01-30 00:14:18 +00005057 When an error is encountered while evaluating {string} no
5058 further items in {expr} are processed.
Bram Moolenaar5f2bb9f2005-01-11 21:29:04 +00005059
5060
Bram Moolenaarbd743252010-10-20 21:23:33 +02005061maparg({name}[, {mode} [, {abbr} [, {dict}]]]) *maparg()*
5062 When {dict} is omitted or zero: Return the rhs of mapping
5063 {name} in mode {mode}. The returned String has special
5064 characters translated like in the output of the ":map" command
5065 listing.
5066
5067 When there is no mapping for {name}, an empty String is
5068 returned.
5069
5070 The {name} can have special key names, like in the ":map"
5071 command.
5072
Bram Moolenaard12f5c12006-01-25 22:10:52 +00005073 {mode} can be one of these strings:
Bram Moolenaar071d4272004-06-13 20:20:40 +00005074 "n" Normal
Bram Moolenaarbd743252010-10-20 21:23:33 +02005075 "v" Visual (including Select)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005076 "o" Operator-pending
5077 "i" Insert
5078 "c" Cmd-line
Bram Moolenaarbd743252010-10-20 21:23:33 +02005079 "s" Select
5080 "x" Visual
Bram Moolenaar071d4272004-06-13 20:20:40 +00005081 "l" langmap |language-mapping|
5082 "" Normal, Visual and Operator-pending
Bram Moolenaard12f5c12006-01-25 22:10:52 +00005083 When {mode} is omitted, the modes for "" are used.
Bram Moolenaarbd743252010-10-20 21:23:33 +02005084
Bram Moolenaar97b2ad32006-03-18 21:40:56 +00005085 When {abbr} is there and it is non-zero use abbreviations
5086 instead of mappings.
Bram Moolenaarbd743252010-10-20 21:23:33 +02005087
5088 When {dict} is there and it is non-zero return a dictionary
5089 containing all the information of the mapping with the
5090 following items:
5091 "lhs" The {lhs} of the mapping.
5092 "rhs" The {rhs} of the mapping as typed.
5093 "silent" 1 for a |:map-silent| mapping, else 0.
Bram Moolenaar05365702010-10-27 18:34:44 +02005094 "noremap" 1 if the {rhs} of the mapping is not remappable.
Bram Moolenaarbd743252010-10-20 21:23:33 +02005095 "expr" 1 for an expression mapping (|:map-<expr>|).
5096 "buffer" 1 for a buffer local mapping (|:map-local|).
5097 "mode" Modes for which the mapping is defined. In
5098 addition to the modes mentioned above, these
5099 characters will be used:
5100 " " Normal, Visual and Operator-pending
5101 "!" Insert and Commandline mode
Bram Moolenaar166af9b2010-11-16 20:34:40 +01005102 (|mapmode-ic|)
Bram Moolenaar05365702010-10-27 18:34:44 +02005103 "sid" The script local ID, used for <sid> mappings
5104 (|<SID>|).
Bram Moolenaardfb18412013-12-11 18:53:29 +01005105 "nowait" Do not wait for other, longer mappings.
5106 (|:map-<nowait>|).
Bram Moolenaarbd743252010-10-20 21:23:33 +02005107
Bram Moolenaar071d4272004-06-13 20:20:40 +00005108 The mappings local to the current buffer are checked first,
5109 then the global mappings.
Bram Moolenaara40ceaf2006-01-13 22:35:40 +00005110 This function can be used to map a key even when it's already
5111 mapped, and have it do the original mapping too. Sketch: >
5112 exe 'nnoremap <Tab> ==' . maparg('<Tab>', 'n')
5113
Bram Moolenaar071d4272004-06-13 20:20:40 +00005114
Bram Moolenaar97b2ad32006-03-18 21:40:56 +00005115mapcheck({name}[, {mode} [, {abbr}]]) *mapcheck()*
Bram Moolenaar071d4272004-06-13 20:20:40 +00005116 Check if there is a mapping that matches with {name} in mode
5117 {mode}. See |maparg()| for {mode} and special names in
5118 {name}.
Bram Moolenaar97b2ad32006-03-18 21:40:56 +00005119 When {abbr} is there and it is non-zero use abbreviations
5120 instead of mappings.
Bram Moolenaar071d4272004-06-13 20:20:40 +00005121 A match happens with a mapping that starts with {name} and
5122 with a mapping which is equal to the start of {name}.
5123
Bram Moolenaar446cb832008-06-24 21:56:24 +00005124 matches mapping "a" "ab" "abc" ~
Bram Moolenaar071d4272004-06-13 20:20:40 +00005125 mapcheck("a") yes yes yes
5126 mapcheck("abc") yes yes yes
5127 mapcheck("ax") yes no no
5128 mapcheck("b") no no no
5129
5130 The difference with maparg() is that mapcheck() finds a
5131 mapping that matches with {name}, while maparg() only finds a
5132 mapping for {name} exactly.
5133 When there is no mapping that starts with {name}, an empty
5134 String is returned. If there is one, the rhs of that mapping
5135 is returned. If there are several mappings that start with
5136 {name}, the rhs of one of them is returned.
5137 The mappings local to the current buffer are checked first,
5138 then the global mappings.
5139 This function can be used to check if a mapping can be added
5140 without being ambiguous. Example: >
5141 :if mapcheck("_vv") == ""
5142 : map _vv :set guifont=7x13<CR>
5143 :endif
5144< This avoids adding the "_vv" mapping when there already is a
5145 mapping for "_v" or for "_vvv".
5146
Bram Moolenaar89cb5e02004-07-19 20:55:54 +00005147match({expr}, {pat}[, {start}[, {count}]]) *match()*
Bram Moolenaar32466aa2006-02-24 23:53:04 +00005148 When {expr} is a |List| then this returns the index of the
5149 first item where {pat} matches. Each item is used as a
Bram Moolenaara23ccb82006-02-27 00:08:02 +00005150 String, |Lists| and |Dictionaries| are used as echoed.
Bram Moolenaar446cb832008-06-24 21:56:24 +00005151 Otherwise, {expr} is used as a String. The result is a
Bram Moolenaar5f2bb9f2005-01-11 21:29:04 +00005152 Number, which gives the index (byte offset) in {expr} where
5153 {pat} matches.
Bram Moolenaar32466aa2006-02-24 23:53:04 +00005154 A match at the first character or |List| item returns zero.
Bram Moolenaar89cb5e02004-07-19 20:55:54 +00005155 If there is no match -1 is returned.
Bram Moolenaar20f90cf2011-05-19 12:22:51 +02005156 For getting submatches see |matchlist()|.
Bram Moolenaar89cb5e02004-07-19 20:55:54 +00005157 Example: >
Bram Moolenaar5f2bb9f2005-01-11 21:29:04 +00005158 :echo match("testing", "ing") " results in 4
Bram Moolenaar362e1a32006-03-06 23:29:24 +00005159 :echo match([1, 'x'], '\a') " results in 1
Bram Moolenaar5f2bb9f2005-01-11 21:29:04 +00005160< See |string-match| for how {pat} is used.
Bram Moolenaar05159a02005-02-26 23:04:13 +00005161 *strpbrk()*
Bram Moolenaar446cb832008-06-24 21:56:24 +00005162 Vim doesn't have a strpbrk() function. But you can do: >
Bram Moolenaar05159a02005-02-26 23:04:13 +00005163 :let sepidx = match(line, '[.,;: \t]')
5164< *strcasestr()*
5165 Vim doesn't have a strcasestr() function. But you can add
5166 "\c" to the pattern to ignore case: >
5167 :let idx = match(haystack, '\cneedle')
5168<
Bram Moolenaar5f2bb9f2005-01-11 21:29:04 +00005169 If {start} is given, the search starts from byte index
Bram Moolenaar32466aa2006-02-24 23:53:04 +00005170 {start} in a String or item {start} in a |List|.
Bram Moolenaar071d4272004-06-13 20:20:40 +00005171 The result, however, is still the index counted from the
Bram Moolenaar402d2fe2005-04-15 21:00:38 +00005172 first character/item. Example: >
Bram Moolenaar071d4272004-06-13 20:20:40 +00005173 :echo match("testing", "ing", 2)
5174< result is again "4". >
5175 :echo match("testing", "ing", 4)
5176< result is again "4". >
5177 :echo match("testing", "t", 2)
5178< result is "3".
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005179 For a String, if {start} > 0 then it is like the string starts
Bram Moolenaar0b238792006-03-02 22:49:12 +00005180 {start} bytes later, thus "^" will match at {start}. Except
5181 when {count} is given, then it's like matches before the
5182 {start} byte are ignored (this is a bit complicated to keep it
5183 backwards compatible).
Bram Moolenaar5f2bb9f2005-01-11 21:29:04 +00005184 For a String, if {start} < 0, it will be set to 0. For a list
5185 the index is counted from the end.
Bram Moolenaare224ffa2006-03-01 00:01:28 +00005186 If {start} is out of range ({start} > strlen({expr}) for a
5187 String or {start} > len({expr}) for a |List|) -1 is returned.
Bram Moolenaar5f2bb9f2005-01-11 21:29:04 +00005188
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005189 When {count} is given use the {count}'th match. When a match
Bram Moolenaare224ffa2006-03-01 00:01:28 +00005190 is found in a String the search for the next one starts one
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005191 character further. Thus this example results in 1: >
5192 echo match("testing", "..", 0, 2)
5193< In a |List| the search continues in the next item.
Bram Moolenaar0b238792006-03-02 22:49:12 +00005194 Note that when {count} is added the way {start} works changes,
5195 see above.
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005196
Bram Moolenaar071d4272004-06-13 20:20:40 +00005197 See |pattern| for the patterns that are accepted.
5198 The 'ignorecase' option is used to set the ignore-caseness of
Bram Moolenaar446cb832008-06-24 21:56:24 +00005199 the pattern. 'smartcase' is NOT used. The matching is always
Bram Moolenaar071d4272004-06-13 20:20:40 +00005200 done like 'magic' is set and 'cpoptions' is empty.
5201
Bram Moolenaar6ee10162007-07-26 20:58:42 +00005202 *matchadd()* *E798* *E799* *E801*
Bram Moolenaar6463ca22016-02-13 17:04:46 +01005203matchadd({group}, {pattern}[, {priority}[, {id}[, {dict}]]])
Bram Moolenaar6ee10162007-07-26 20:58:42 +00005204 Defines a pattern to be highlighted in the current window (a
5205 "match"). It will be highlighted with {group}. Returns an
5206 identification number (ID), which can be used to delete the
5207 match using |matchdelete()|.
Bram Moolenaar8e69b4a2013-11-09 03:41:58 +01005208 Matching is case sensitive and magic, unless case sensitivity
5209 or magicness are explicitly overridden in {pattern}. The
5210 'magic', 'smartcase' and 'ignorecase' options are not used.
Bram Moolenaarf9132812015-07-21 19:19:13 +02005211 The "Conceal" value is special, it causes the match to be
5212 concealed.
Bram Moolenaar6ee10162007-07-26 20:58:42 +00005213
5214 The optional {priority} argument assigns a priority to the
Bram Moolenaar446cb832008-06-24 21:56:24 +00005215 match. A match with a high priority will have its
Bram Moolenaar6ee10162007-07-26 20:58:42 +00005216 highlighting overrule that of a match with a lower priority.
5217 A priority is specified as an integer (negative numbers are no
5218 exception). If the {priority} argument is not specified, the
5219 default priority is 10. The priority of 'hlsearch' is zero,
5220 hence all matches with a priority greater than zero will
5221 overrule it. Syntax highlighting (see 'syntax') is a separate
5222 mechanism, and regardless of the chosen priority a match will
5223 always overrule syntax highlighting.
5224
5225 The optional {id} argument allows the request for a specific
5226 match ID. If a specified ID is already taken, an error
5227 message will appear and the match will not be added. An ID
5228 is specified as a positive integer (zero excluded). IDs 1, 2
5229 and 3 are reserved for |:match|, |:2match| and |:3match|,
Bram Moolenaar6561d522015-07-21 15:48:27 +02005230 respectively. If the {id} argument is not specified or -1,
Bram Moolenaar6ee10162007-07-26 20:58:42 +00005231 |matchadd()| automatically chooses a free ID.
5232
Bram Moolenaar85084ef2016-01-17 22:26:33 +01005233 The optional {dict} argument allows for further custom
5234 values. Currently this is used to specify a match specific
Bram Moolenaar6561d522015-07-21 15:48:27 +02005235 conceal character that will be shown for |hl-Conceal|
5236 highlighted matches. The dict can have the following members:
5237
5238 conceal Special character to show instead of the
Bram Moolenaar6463ca22016-02-13 17:04:46 +01005239 match (only for |hl-Conceal| highlighted
Bram Moolenaar6561d522015-07-21 15:48:27 +02005240 matches, see |:syn-cchar|)
5241
Bram Moolenaar6ee10162007-07-26 20:58:42 +00005242 The number of matches is not limited, as it is the case with
5243 the |:match| commands.
5244
5245 Example: >
5246 :highlight MyGroup ctermbg=green guibg=green
5247 :let m = matchadd("MyGroup", "TODO")
5248< Deletion of the pattern: >
5249 :call matchdelete(m)
5250
5251< A list of matches defined by |matchadd()| and |:match| are
Bram Moolenaar446cb832008-06-24 21:56:24 +00005252 available from |getmatches()|. All matches can be deleted in
Bram Moolenaar6ee10162007-07-26 20:58:42 +00005253 one operation by |clearmatches()|.
Bram Moolenaar910f66f2006-04-05 20:41:53 +00005254
Bram Moolenaar6561d522015-07-21 15:48:27 +02005255matchaddpos({group}, {pos}[, {priority}[, {id}[, {dict}]]]) *matchaddpos()*
Bram Moolenaarb3414592014-06-17 17:48:32 +02005256 Same as |matchadd()|, but requires a list of positions {pos}
5257 instead of a pattern. This command is faster than |matchadd()|
5258 because it does not require to handle regular expressions and
5259 sets buffer line boundaries to redraw screen. It is supposed
5260 to be used when fast match additions and deletions are
5261 required, for example to highlight matching parentheses.
5262
5263 The list {pos} can contain one of these items:
Bram Moolenaarb6da44a2014-06-25 18:15:22 +02005264 - A number. This whole line will be highlighted. The first
Bram Moolenaarb3414592014-06-17 17:48:32 +02005265 line has number 1.
5266 - A list with one number, e.g., [23]. The whole line with this
5267 number will be highlighted.
5268 - A list with two numbers, e.g., [23, 11]. The first number is
Bram Moolenaarb6da44a2014-06-25 18:15:22 +02005269 the line number, the second one is the column number (first
5270 column is 1, the value must correspond to the byte index as
5271 |col()| would return). The character at this position will
5272 be highlighted.
Bram Moolenaarb3414592014-06-17 17:48:32 +02005273 - A list with three numbers, e.g., [23, 11, 3]. As above, but
Bram Moolenaarb6da44a2014-06-25 18:15:22 +02005274 the third number gives the length of the highlight in bytes.
Bram Moolenaarb3414592014-06-17 17:48:32 +02005275
5276 The maximum number of positions is 8.
5277
5278 Example: >
5279 :highlight MyGroup ctermbg=green guibg=green
5280 :let m = matchaddpos("MyGroup", [[23, 24], 34])
5281< Deletion of the pattern: >
5282 :call matchdelete(m)
5283
5284< Matches added by |matchaddpos()| are returned by
5285 |getmatches()| with an entry "pos1", "pos2", etc., with the
5286 value a list like the {pos} item.
5287 These matches cannot be set via |setmatches()|, however they
5288 can still be deleted by |clearmatches()|.
5289
Bram Moolenaar910f66f2006-04-05 20:41:53 +00005290matcharg({nr}) *matcharg()*
Bram Moolenaarc9b4b052006-04-30 18:54:39 +00005291 Selects the {nr} match item, as set with a |:match|,
Bram Moolenaar910f66f2006-04-05 20:41:53 +00005292 |:2match| or |:3match| command.
5293 Return a |List| with two elements:
5294 The name of the highlight group used
5295 The pattern used.
5296 When {nr} is not 1, 2 or 3 returns an empty |List|.
5297 When there is no match item set returns ['', ''].
Bram Moolenaar6ee10162007-07-26 20:58:42 +00005298 This is useful to save and restore a |:match|.
5299 Highlighting matches using the |:match| commands are limited
5300 to three matches. |matchadd()| does not have this limitation.
Bram Moolenaar910f66f2006-04-05 20:41:53 +00005301
Bram Moolenaar6ee10162007-07-26 20:58:42 +00005302matchdelete({id}) *matchdelete()* *E802* *E803*
5303 Deletes a match with ID {id} previously defined by |matchadd()|
Bram Moolenaar446cb832008-06-24 21:56:24 +00005304 or one of the |:match| commands. Returns 0 if successful,
Bram Moolenaar6ee10162007-07-26 20:58:42 +00005305 otherwise -1. See example for |matchadd()|. All matches can
5306 be deleted in one operation by |clearmatches()|.
Bram Moolenaar910f66f2006-04-05 20:41:53 +00005307
Bram Moolenaar89cb5e02004-07-19 20:55:54 +00005308matchend({expr}, {pat}[, {start}[, {count}]]) *matchend()*
Bram Moolenaar8f3f58f2010-01-06 20:52:26 +01005309 Same as |match()|, but return the index of first character
5310 after the match. Example: >
Bram Moolenaar071d4272004-06-13 20:20:40 +00005311 :echo matchend("testing", "ing")
5312< results in "7".
Bram Moolenaar05159a02005-02-26 23:04:13 +00005313 *strspn()* *strcspn()*
5314 Vim doesn't have a strspn() or strcspn() function, but you can
5315 do it with matchend(): >
5316 :let span = matchend(line, '[a-zA-Z]')
5317 :let span = matchend(line, '[^a-zA-Z]')
5318< Except that -1 is returned when there are no matches.
5319
Bram Moolenaar8f3f58f2010-01-06 20:52:26 +01005320 The {start}, if given, has the same meaning as for |match()|. >
Bram Moolenaar071d4272004-06-13 20:20:40 +00005321 :echo matchend("testing", "ing", 2)
5322< results in "7". >
5323 :echo matchend("testing", "ing", 5)
5324< result is "-1".
Bram Moolenaar8f3f58f2010-01-06 20:52:26 +01005325 When {expr} is a |List| the result is equal to |match()|.
Bram Moolenaar071d4272004-06-13 20:20:40 +00005326
Bram Moolenaar3a7c85b2005-02-05 21:39:53 +00005327matchlist({expr}, {pat}[, {start}[, {count}]]) *matchlist()*
Bram Moolenaar8f3f58f2010-01-06 20:52:26 +01005328 Same as |match()|, but return a |List|. The first item in the
Bram Moolenaar3a7c85b2005-02-05 21:39:53 +00005329 list is the matched string, same as what matchstr() would
5330 return. Following items are submatches, like "\1", "\2", etc.
Bram Moolenaarf9393ef2006-04-24 19:47:27 +00005331 in |:substitute|. When an optional submatch didn't match an
5332 empty string is used. Example: >
5333 echo matchlist('acd', '\(a\)\?\(b\)\?\(c\)\?\(.*\)')
5334< Results in: ['acd', 'a', '', 'c', 'd', '', '', '', '', '']
Bram Moolenaar3a7c85b2005-02-05 21:39:53 +00005335 When there is no match an empty list is returned.
5336
Bram Moolenaar89cb5e02004-07-19 20:55:54 +00005337matchstr({expr}, {pat}[, {start}[, {count}]]) *matchstr()*
Bram Moolenaar446cb832008-06-24 21:56:24 +00005338 Same as |match()|, but return the matched string. Example: >
Bram Moolenaar071d4272004-06-13 20:20:40 +00005339 :echo matchstr("testing", "ing")
5340< results in "ing".
5341 When there is no match "" is returned.
Bram Moolenaar8f3f58f2010-01-06 20:52:26 +01005342 The {start}, if given, has the same meaning as for |match()|. >
Bram Moolenaar071d4272004-06-13 20:20:40 +00005343 :echo matchstr("testing", "ing", 2)
5344< results in "ing". >
5345 :echo matchstr("testing", "ing", 5)
5346< result is "".
Bram Moolenaar32466aa2006-02-24 23:53:04 +00005347 When {expr} is a |List| then the matching item is returned.
Bram Moolenaar5f2bb9f2005-01-11 21:29:04 +00005348 The type isn't changed, it's not necessarily a String.
Bram Moolenaar071d4272004-06-13 20:20:40 +00005349
Bram Moolenaar7fed5c12016-03-29 23:10:31 +02005350matchstrpos({expr}, {pat}[, {start}[, {count}]]) *matchstrpos()*
5351 Same as |matchstr()|, but return the matched string, the start
5352 position and the end position of the match. Example: >
5353 :echo matchstrpos("testing", "ing")
5354< results in ["ing", 4, 7].
5355 When there is no match ["", -1, -1] is returned.
5356 The {start}, if given, has the same meaning as for |match()|. >
5357 :echo matchstrpos("testing", "ing", 2)
5358< results in ["ing", 4, 7]. >
5359 :echo matchstrpos("testing", "ing", 5)
5360< result is ["", -1, -1].
5361 When {expr} is a |List| then the matching item, the index
5362 of first item where {pat} matches, the start position and the
5363 end position of the match are returned. >
5364 :echo matchstrpos([1, '__x'], '\a')
5365< result is ["x", 1, 2, 3].
5366 The type isn't changed, it's not necessarily a String.
5367
Bram Moolenaar9588a0f2005-01-08 21:45:39 +00005368 *max()*
5369max({list}) Return the maximum value of all items in {list}.
5370 If {list} is not a list or one of the items in {list} cannot
5371 be used as a Number this results in an error.
Bram Moolenaar32466aa2006-02-24 23:53:04 +00005372 An empty |List| results in zero.
Bram Moolenaar9588a0f2005-01-08 21:45:39 +00005373
5374 *min()*
Bram Moolenaar79166c42007-05-10 18:29:51 +00005375min({list}) Return the minimum value of all items in {list}.
Bram Moolenaar9588a0f2005-01-08 21:45:39 +00005376 If {list} is not a list or one of the items in {list} cannot
5377 be used as a Number this results in an error.
Bram Moolenaar32466aa2006-02-24 23:53:04 +00005378 An empty |List| results in zero.
Bram Moolenaar9588a0f2005-01-08 21:45:39 +00005379
Bram Moolenaar551dbcc2006-04-25 22:13:59 +00005380 *mkdir()* *E739*
Bram Moolenaar26a60b42005-02-22 08:49:11 +00005381mkdir({name} [, {path} [, {prot}]])
5382 Create directory {name}.
5383 If {path} is "p" then intermediate directories are created as
5384 necessary. Otherwise it must be "".
5385 If {prot} is given it is used to set the protection bits of
5386 the new directory. The default is 0755 (rwxr-xr-x: r/w for
Bram Moolenaar446cb832008-06-24 21:56:24 +00005387 the user readable for others). Use 0700 to make it unreadable
Bram Moolenaared39e1d2008-08-09 17:55:22 +00005388 for others. This is only used for the last part of {name}.
5389 Thus if you create /tmp/foo/bar then /tmp/foo will be created
5390 with 0755.
5391 Example: >
5392 :call mkdir($HOME . "/tmp/foo/bar", "p", 0700)
5393< This function is not available in the |sandbox|.
Bram Moolenaar26a60b42005-02-22 08:49:11 +00005394 Not available on all systems. To check use: >
5395 :if exists("*mkdir")
5396<
Bram Moolenaar071d4272004-06-13 20:20:40 +00005397 *mode()*
Bram Moolenaar446cb832008-06-24 21:56:24 +00005398mode([expr]) Return a string that indicates the current mode.
Bram Moolenaar05bb9532008-07-04 09:44:11 +00005399 If [expr] is supplied and it evaluates to a non-zero Number or
5400 a non-empty String (|non-zero-arg|), then the full mode is
5401 returned, otherwise only the first letter is returned. Note
5402 that " " and "0" are also non-empty strings.
Bram Moolenaar446cb832008-06-24 21:56:24 +00005403
Bram Moolenaar071d4272004-06-13 20:20:40 +00005404 n Normal
Bram Moolenaar446cb832008-06-24 21:56:24 +00005405 no Operator-pending
Bram Moolenaar071d4272004-06-13 20:20:40 +00005406 v Visual by character
5407 V Visual by line
5408 CTRL-V Visual blockwise
5409 s Select by character
5410 S Select by line
5411 CTRL-S Select blockwise
5412 i Insert
Bram Moolenaar446cb832008-06-24 21:56:24 +00005413 R Replace |R|
5414 Rv Virtual Replace |gR|
Bram Moolenaar071d4272004-06-13 20:20:40 +00005415 c Command-line
Bram Moolenaar446cb832008-06-24 21:56:24 +00005416 cv Vim Ex mode |gQ|
5417 ce Normal Ex mode |Q|
Bram Moolenaar071d4272004-06-13 20:20:40 +00005418 r Hit-enter prompt
Bram Moolenaar446cb832008-06-24 21:56:24 +00005419 rm The -- more -- prompt
5420 r? A |:confirm| query of some sort
5421 ! Shell or external command is executing
5422 This is useful in the 'statusline' option or when used
5423 with |remote_expr()| In most other places it always returns
5424 "c" or "n".
5425 Also see |visualmode()|.
Bram Moolenaar071d4272004-06-13 20:20:40 +00005426
Bram Moolenaar7e506b62010-01-19 15:55:06 +01005427mzeval({expr}) *mzeval()*
5428 Evaluate MzScheme expression {expr} and return its result
Bram Moolenaard38b0552012-04-25 19:07:41 +02005429 converted to Vim data structures.
Bram Moolenaar7e506b62010-01-19 15:55:06 +01005430 Numbers and strings are returned as they are.
5431 Pairs (including lists and improper lists) and vectors are
5432 returned as Vim |Lists|.
5433 Hash tables are represented as Vim |Dictionary| type with keys
5434 converted to strings.
5435 All other types are converted to string with display function.
5436 Examples: >
5437 :mz (define l (list 1 2 3))
5438 :mz (define h (make-hash)) (hash-set! h "list" l)
5439 :echo mzeval("l")
5440 :echo mzeval("h")
5441<
5442 {only available when compiled with the |+mzscheme| feature}
5443
Bram Moolenaar071d4272004-06-13 20:20:40 +00005444nextnonblank({lnum}) *nextnonblank()*
5445 Return the line number of the first line at or below {lnum}
5446 that is not blank. Example: >
5447 if getline(nextnonblank(1)) =~ "Java"
5448< When {lnum} is invalid or there is no non-blank line at or
5449 below it, zero is returned.
5450 See also |prevnonblank()|.
5451
Bram Moolenaard35d7842013-01-23 17:17:10 +01005452nr2char({expr}[, {utf8}]) *nr2char()*
Bram Moolenaar071d4272004-06-13 20:20:40 +00005453 Return a string with a single character, which has the number
5454 value {expr}. Examples: >
5455 nr2char(64) returns "@"
5456 nr2char(32) returns " "
Bram Moolenaard35d7842013-01-23 17:17:10 +01005457< When {utf8} is omitted or zero, the current 'encoding' is used.
5458 Example for "utf-8": >
Bram Moolenaar071d4272004-06-13 20:20:40 +00005459 nr2char(300) returns I with bow character
Bram Moolenaard35d7842013-01-23 17:17:10 +01005460< With {utf8} set to 1, always return utf-8 characters.
5461 Note that a NUL character in the file is specified with
Bram Moolenaar071d4272004-06-13 20:20:40 +00005462 nr2char(10), because NULs are represented with newline
5463 characters. nr2char(0) is a real NUL and terminates the
Bram Moolenaar383f9bc2005-01-19 22:18:32 +00005464 string, thus results in an empty string.
Bram Moolenaar071d4272004-06-13 20:20:40 +00005465
Bram Moolenaard6e256c2011-12-14 15:32:50 +01005466or({expr}, {expr}) *or()*
5467 Bitwise OR on the two arguments. The arguments are converted
5468 to a number. A List, Dict or Float argument causes an error.
5469 Example: >
5470 :let bits = or(bits, 0x80)
5471
5472
Bram Moolenaar910f66f2006-04-05 20:41:53 +00005473pathshorten({expr}) *pathshorten()*
5474 Shorten directory names in the path {expr} and return the
5475 result. The tail, the file name, is kept as-is. The other
5476 components in the path are reduced to single letters. Leading
5477 '~' and '.' characters are kept. Example: >
5478 :echo pathshorten('~/.vim/autoload/myfile.vim')
5479< ~/.v/a/myfile.vim ~
5480 It doesn't matter if the path exists or not.
5481
Bram Moolenaare9b892e2016-01-17 21:15:58 +01005482perleval({expr}) *perleval()*
5483 Evaluate Perl expression {expr} in scalar context and return
5484 its result converted to Vim data structures. If value can't be
Bram Moolenaar85084ef2016-01-17 22:26:33 +01005485 converted, it is returned as a string Perl representation.
5486 Note: If you want an array or hash, {expr} must return a
5487 reference to it.
Bram Moolenaare9b892e2016-01-17 21:15:58 +01005488 Example: >
5489 :echo perleval('[1 .. 4]')
5490< [1, 2, 3, 4]
5491 {only available when compiled with the |+perl| feature}
5492
Bram Moolenaar446cb832008-06-24 21:56:24 +00005493pow({x}, {y}) *pow()*
5494 Return the power of {x} to the exponent {y} as a |Float|.
5495 {x} and {y} must evaluate to a |Float| or a |Number|.
5496 Examples: >
5497 :echo pow(3, 3)
5498< 27.0 >
5499 :echo pow(2, 16)
5500< 65536.0 >
5501 :echo pow(32, 0.20)
5502< 2.0
5503 {only available when compiled with the |+float| feature}
5504
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00005505prevnonblank({lnum}) *prevnonblank()*
5506 Return the line number of the first line at or above {lnum}
5507 that is not blank. Example: >
5508 let ind = indent(prevnonblank(v:lnum - 1))
5509< When {lnum} is invalid or there is no non-blank line at or
5510 above it, zero is returned.
5511 Also see |nextnonblank()|.
5512
5513
Bram Moolenaar4be06f92005-07-29 22:36:03 +00005514printf({fmt}, {expr1} ...) *printf()*
5515 Return a String with {fmt}, where "%" items are replaced by
5516 the formatted form of their respective arguments. Example: >
Bram Moolenaar5a8684e2005-07-30 22:43:24 +00005517 printf("%4d: E%d %.30s", lnum, errno, msg)
Bram Moolenaar4be06f92005-07-29 22:36:03 +00005518< May result in:
Bram Moolenaar5a8684e2005-07-30 22:43:24 +00005519 " 99: E42 asdfasdfasdfasdfasdfasdfasdfas" ~
Bram Moolenaar4be06f92005-07-29 22:36:03 +00005520
5521 Often used items are:
Bram Moolenaarc9b4b052006-04-30 18:54:39 +00005522 %s string
Bram Moolenaar3ab72c52012-11-14 18:10:56 +01005523 %6S string right-aligned in 6 display cells
Bram Moolenaar98692072006-02-04 00:57:42 +00005524 %6s string right-aligned in 6 bytes
Bram Moolenaar446cb832008-06-24 21:56:24 +00005525 %.9s string truncated to 9 bytes
5526 %c single byte
5527 %d decimal number
5528 %5d decimal number padded with spaces to 5 characters
5529 %x hex number
5530 %04x hex number padded with zeros to at least 4 characters
5531 %X hex number using upper case letters
5532 %o octal number
5533 %f floating point number in the form 123.456
5534 %e floating point number in the form 1.234e3
5535 %E floating point number in the form 1.234E3
5536 %g floating point number, as %f or %e depending on value
5537 %G floating point number, as %f or %E depending on value
5538 %% the % character itself
Bram Moolenaar4be06f92005-07-29 22:36:03 +00005539
5540 Conversion specifications start with '%' and end with the
5541 conversion type. All other characters are copied unchanged to
5542 the result.
5543
5544 The "%" starts a conversion specification. The following
Bram Moolenaar5a8684e2005-07-30 22:43:24 +00005545 arguments appear in sequence:
Bram Moolenaar4be06f92005-07-29 22:36:03 +00005546
Bram Moolenaar5a8684e2005-07-30 22:43:24 +00005547 % [flags] [field-width] [.precision] type
Bram Moolenaar4be06f92005-07-29 22:36:03 +00005548
Bram Moolenaarc9b4b052006-04-30 18:54:39 +00005549 flags
Bram Moolenaar5a8684e2005-07-30 22:43:24 +00005550 Zero or more of the following flags:
5551
Bram Moolenaar4be06f92005-07-29 22:36:03 +00005552 # The value should be converted to an "alternate
5553 form". For c, d, and s conversions, this option
5554 has no effect. For o conversions, the precision
5555 of the number is increased to force the first
5556 character of the output string to a zero (except
5557 if a zero value is printed with an explicit
5558 precision of zero).
5559 For x and X conversions, a non-zero result has
5560 the string "0x" (or "0X" for X conversions)
5561 prepended to it.
Bram Moolenaar5a8684e2005-07-30 22:43:24 +00005562
Bram Moolenaar4be06f92005-07-29 22:36:03 +00005563 0 (zero) Zero padding. For all conversions the converted
5564 value is padded on the left with zeros rather
5565 than blanks. If a precision is given with a
5566 numeric conversion (d, o, x, and X), the 0 flag
5567 is ignored.
Bram Moolenaar5a8684e2005-07-30 22:43:24 +00005568
Bram Moolenaar4be06f92005-07-29 22:36:03 +00005569 - A negative field width flag; the converted value
5570 is to be left adjusted on the field boundary.
5571 The converted value is padded on the right with
5572 blanks, rather than on the left with blanks or
5573 zeros. A - overrides a 0 if both are given.
Bram Moolenaar5a8684e2005-07-30 22:43:24 +00005574
Bram Moolenaar4be06f92005-07-29 22:36:03 +00005575 ' ' (space) A blank should be left before a positive
5576 number produced by a signed conversion (d).
Bram Moolenaar5a8684e2005-07-30 22:43:24 +00005577
Bram Moolenaar4be06f92005-07-29 22:36:03 +00005578 + A sign must always be placed before a number
Bram Moolenaar446cb832008-06-24 21:56:24 +00005579 produced by a signed conversion. A + overrides
Bram Moolenaar4be06f92005-07-29 22:36:03 +00005580 a space if both are used.
Bram Moolenaar5a8684e2005-07-30 22:43:24 +00005581
5582 field-width
5583 An optional decimal digit string specifying a minimum
Bram Moolenaar98692072006-02-04 00:57:42 +00005584 field width. If the converted value has fewer bytes
5585 than the field width, it will be padded with spaces on
5586 the left (or right, if the left-adjustment flag has
5587 been given) to fill out the field width.
Bram Moolenaar5a8684e2005-07-30 22:43:24 +00005588
5589 .precision
5590 An optional precision, in the form of a period '.'
5591 followed by an optional digit string. If the digit
5592 string is omitted, the precision is taken as zero.
5593 This gives the minimum number of digits to appear for
5594 d, o, x, and X conversions, or the maximum number of
Bram Moolenaar98692072006-02-04 00:57:42 +00005595 bytes to be printed from a string for s conversions.
Bram Moolenaar446cb832008-06-24 21:56:24 +00005596 For floating point it is the number of digits after
5597 the decimal point.
Bram Moolenaar5a8684e2005-07-30 22:43:24 +00005598
5599 type
5600 A character that specifies the type of conversion to
5601 be applied, see below.
5602
Bram Moolenaar4be06f92005-07-29 22:36:03 +00005603 A field width or precision, or both, may be indicated by an
5604 asterisk '*' instead of a digit string. In this case, a
Bram Moolenaar446cb832008-06-24 21:56:24 +00005605 Number argument supplies the field width or precision. A
Bram Moolenaar4be06f92005-07-29 22:36:03 +00005606 negative field width is treated as a left adjustment flag
5607 followed by a positive field width; a negative precision is
5608 treated as though it were missing. Example: >
Bram Moolenaar5a8684e2005-07-30 22:43:24 +00005609 :echo printf("%d: %.*s", nr, width, line)
Bram Moolenaar4be06f92005-07-29 22:36:03 +00005610< This limits the length of the text used from "line" to
Bram Moolenaar5a8684e2005-07-30 22:43:24 +00005611 "width" bytes.
Bram Moolenaar4be06f92005-07-29 22:36:03 +00005612
Bram Moolenaarc9b4b052006-04-30 18:54:39 +00005613 The conversion specifiers and their meanings are:
Bram Moolenaar5a8684e2005-07-30 22:43:24 +00005614
Bram Moolenaar446cb832008-06-24 21:56:24 +00005615 *printf-d* *printf-o* *printf-x* *printf-X*
5616 doxX The Number argument is converted to signed decimal
Bram Moolenaar4be06f92005-07-29 22:36:03 +00005617 (d), unsigned octal (o), or unsigned hexadecimal (x
5618 and X) notation. The letters "abcdef" are used for
5619 x conversions; the letters "ABCDEF" are used for X
Bram Moolenaar5a8684e2005-07-30 22:43:24 +00005620 conversions.
5621 The precision, if any, gives the minimum number of
5622 digits that must appear; if the converted value
5623 requires fewer digits, it is padded on the left with
5624 zeros.
5625 In no case does a non-existent or small field width
5626 cause truncation of a numeric field; if the result of
5627 a conversion is wider than the field width, the field
5628 is expanded to contain the conversion result.
5629
Bram Moolenaar446cb832008-06-24 21:56:24 +00005630 *printf-c*
Bram Moolenaar5a8684e2005-07-30 22:43:24 +00005631 c The Number argument is converted to a byte, and the
5632 resulting character is written.
5633
Bram Moolenaar446cb832008-06-24 21:56:24 +00005634 *printf-s*
Bram Moolenaar5a8684e2005-07-30 22:43:24 +00005635 s The text of the String argument is used. If a
5636 precision is specified, no more bytes than the number
5637 specified are used.
Bram Moolenaar0122c402015-02-03 19:13:34 +01005638 *printf-S*
Bram Moolenaar3ab72c52012-11-14 18:10:56 +01005639 S The text of the String argument is used. If a
5640 precision is specified, no more display cells than the
5641 number specified are used. Without the |+multi_byte|
5642 feature works just like 's'.
Bram Moolenaar5a8684e2005-07-30 22:43:24 +00005643
Bram Moolenaar446cb832008-06-24 21:56:24 +00005644 *printf-f* *E807*
5645 f The Float argument is converted into a string of the
5646 form 123.456. The precision specifies the number of
5647 digits after the decimal point. When the precision is
5648 zero the decimal point is omitted. When the precision
5649 is not specified 6 is used. A really big number
5650 (out of range or dividing by zero) results in "inf".
5651 "0.0 / 0.0" results in "nan".
5652 Example: >
5653 echo printf("%.2f", 12.115)
5654< 12.12
5655 Note that roundoff depends on the system libraries.
5656 Use |round()| when in doubt.
5657
5658 *printf-e* *printf-E*
5659 e E The Float argument is converted into a string of the
5660 form 1.234e+03 or 1.234E+03 when using 'E'. The
5661 precision specifies the number of digits after the
5662 decimal point, like with 'f'.
5663
5664 *printf-g* *printf-G*
5665 g G The Float argument is converted like with 'f' if the
5666 value is between 0.001 (inclusive) and 10000000.0
5667 (exclusive). Otherwise 'e' is used for 'g' and 'E'
5668 for 'G'. When no precision is specified superfluous
5669 zeroes and '+' signs are removed, except for the zero
5670 immediately after the decimal point. Thus 10000000.0
5671 results in 1.0e7.
5672
5673 *printf-%*
Bram Moolenaar4be06f92005-07-29 22:36:03 +00005674 % A '%' is written. No argument is converted. The
5675 complete conversion specification is "%%".
Bram Moolenaar4be06f92005-07-29 22:36:03 +00005676
Bram Moolenaarc236c162008-07-13 17:41:49 +00005677 When a Number argument is expected a String argument is also
5678 accepted and automatically converted.
5679 When a Float or String argument is expected a Number argument
5680 is also accepted and automatically converted.
5681 Any other argument type results in an error message.
Bram Moolenaar4be06f92005-07-29 22:36:03 +00005682
Bram Moolenaar83bab712005-08-01 21:58:57 +00005683 *E766* *E767*
Bram Moolenaar4be06f92005-07-29 22:36:03 +00005684 The number of {exprN} arguments must exactly match the number
5685 of "%" items. If there are not sufficient or too many
Bram Moolenaar5a8684e2005-07-30 22:43:24 +00005686 arguments an error is given. Up to 18 arguments can be used.
Bram Moolenaar4be06f92005-07-29 22:36:03 +00005687
5688
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00005689pumvisible() *pumvisible()*
5690 Returns non-zero when the popup menu is visible, zero
5691 otherwise. See |ins-completion-menu|.
Bram Moolenaar87b5ca52006-03-04 21:55:31 +00005692 This can be used to avoid some things that would remove the
5693 popup menu.
Bram Moolenaar071d4272004-06-13 20:20:40 +00005694
Bram Moolenaar30b65812012-07-12 22:01:11 +02005695py3eval({expr}) *py3eval()*
5696 Evaluate Python expression {expr} and return its result
5697 converted to Vim data structures.
5698 Numbers and strings are returned as they are (strings are
Bram Moolenaar2b8388b2015-02-28 13:11:45 +01005699 copied though, Unicode strings are additionally converted to
Bram Moolenaar30b65812012-07-12 22:01:11 +02005700 'encoding').
5701 Lists are represented as Vim |List| type.
5702 Dictionaries are represented as Vim |Dictionary| type with
5703 keys converted to strings.
5704 {only available when compiled with the |+python3| feature}
5705
5706 *E858* *E859*
5707pyeval({expr}) *pyeval()*
5708 Evaluate Python expression {expr} and return its result
5709 converted to Vim data structures.
5710 Numbers and strings are returned as they are (strings are
5711 copied though).
5712 Lists are represented as Vim |List| type.
Bram Moolenaard09acef2012-09-21 14:54:30 +02005713 Dictionaries are represented as Vim |Dictionary| type,
5714 non-string keys result in error.
Bram Moolenaar30b65812012-07-12 22:01:11 +02005715 {only available when compiled with the |+python| feature}
5716
Bram Moolenaar3a3a7232005-01-17 22:16:15 +00005717 *E726* *E727*
Bram Moolenaard8b02732005-01-14 21:48:43 +00005718range({expr} [, {max} [, {stride}]]) *range()*
Bram Moolenaar32466aa2006-02-24 23:53:04 +00005719 Returns a |List| with Numbers:
Bram Moolenaard8b02732005-01-14 21:48:43 +00005720 - If only {expr} is specified: [0, 1, ..., {expr} - 1]
5721 - If {max} is specified: [{expr}, {expr} + 1, ..., {max}]
5722 - If {stride} is specified: [{expr}, {expr} + {stride}, ...,
5723 {max}] (increasing {expr} with {stride} each time, not
5724 producing a value past {max}).
Bram Moolenaare7566042005-06-17 22:00:15 +00005725 When the maximum is one before the start the result is an
5726 empty list. When the maximum is more than one before the
5727 start this is an error.
Bram Moolenaard8b02732005-01-14 21:48:43 +00005728 Examples: >
Bram Moolenaarc9b4b052006-04-30 18:54:39 +00005729 range(4) " [0, 1, 2, 3]
Bram Moolenaard8b02732005-01-14 21:48:43 +00005730 range(2, 4) " [2, 3, 4]
5731 range(2, 9, 3) " [2, 5, 8]
Bram Moolenaarc9b4b052006-04-30 18:54:39 +00005732 range(2, -2, -1) " [2, 1, 0, -1, -2]
Bram Moolenaare7566042005-06-17 22:00:15 +00005733 range(0) " []
5734 range(2, 0) " error!
Bram Moolenaard8b02732005-01-14 21:48:43 +00005735<
Bram Moolenaar3a7c85b2005-02-05 21:39:53 +00005736 *readfile()*
Bram Moolenaar26a60b42005-02-22 08:49:11 +00005737readfile({fname} [, {binary} [, {max}]])
Bram Moolenaar32466aa2006-02-24 23:53:04 +00005738 Read file {fname} and return a |List|, each line of the file
5739 as an item. Lines broken at NL characters. Macintosh files
Bram Moolenaar3a7c85b2005-02-05 21:39:53 +00005740 separated with CR will result in a single long line (unless a
5741 NL appears somewhere).
Bram Moolenaar06583f12010-08-07 20:30:49 +02005742 All NUL characters are replaced with a NL character.
Bram Moolenaar86ae7202015-07-10 19:31:35 +02005743 When {binary} contains "b" binary mode is used:
Bram Moolenaar3a7c85b2005-02-05 21:39:53 +00005744 - When the last line ends in a NL an extra empty list item is
5745 added.
5746 - No CR characters are removed.
5747 Otherwise:
5748 - CR characters that appear before a NL are removed.
5749 - Whether the last line ends in a NL or not does not matter.
Bram Moolenaar06583f12010-08-07 20:30:49 +02005750 - When 'encoding' is Unicode any UTF-8 byte order mark is
5751 removed from the text.
Bram Moolenaar26a60b42005-02-22 08:49:11 +00005752 When {max} is given this specifies the maximum number of lines
5753 to be read. Useful if you only want to check the first ten
5754 lines of a file: >
5755 :for line in readfile(fname, '', 10)
5756 : if line =~ 'Date' | echo line | endif
5757 :endfor
Bram Moolenaar582fd852005-03-28 20:58:01 +00005758< When {max} is negative -{max} lines from the end of the file
5759 are returned, or as many as there are.
5760 When {max} is zero the result is an empty list.
Bram Moolenaar26a60b42005-02-22 08:49:11 +00005761 Note that without {max} the whole file is read into memory.
5762 Also note that there is no recognition of encoding. Read a
5763 file into a buffer if you need to.
Bram Moolenaar3a7c85b2005-02-05 21:39:53 +00005764 When the file can't be opened an error message is given and
5765 the result is an empty list.
5766 Also see |writefile()|.
5767
Bram Moolenaar433f7c82006-03-21 21:29:36 +00005768reltime([{start} [, {end}]]) *reltime()*
5769 Return an item that represents a time value. The format of
5770 the item depends on the system. It can be passed to
Bram Moolenaar03413f42016-04-12 21:07:15 +02005771 |reltimestr()| to convert it to a string or |reltimefloat()|
5772 to convert to a Float.
Bram Moolenaar433f7c82006-03-21 21:29:36 +00005773 Without an argument it returns the current time.
5774 With one argument is returns the time passed since the time
5775 specified in the argument.
Bram Moolenaar551dbcc2006-04-25 22:13:59 +00005776 With two arguments it returns the time passed between {start}
Bram Moolenaar433f7c82006-03-21 21:29:36 +00005777 and {end}.
5778 The {start} and {end} arguments must be values returned by
5779 reltime().
Bram Moolenaardb84e452010-08-15 13:50:43 +02005780 {only available when compiled with the |+reltime| feature}
Bram Moolenaar433f7c82006-03-21 21:29:36 +00005781
Bram Moolenaar03413f42016-04-12 21:07:15 +02005782reltimefloat({time}) *reltimefloat()*
5783 Return a Float that represents the time value of {time}.
5784 Example: >
5785 let start = reltime()
5786 call MyFunction()
5787 let seconds = reltimefloat(reltime(start))
5788< See the note of reltimestr() about overhead.
5789 Also see |profiling|.
5790 {only available when compiled with the |+reltime| feature}
5791
Bram Moolenaar433f7c82006-03-21 21:29:36 +00005792reltimestr({time}) *reltimestr()*
5793 Return a String that represents the time value of {time}.
5794 This is the number of seconds, a dot and the number of
5795 microseconds. Example: >
5796 let start = reltime()
5797 call MyFunction()
5798 echo reltimestr(reltime(start))
5799< Note that overhead for the commands will be added to the time.
5800 The accuracy depends on the system.
Bram Moolenaaref2f6562007-05-06 13:32:59 +00005801 Leading spaces are used to make the string align nicely. You
5802 can use split() to remove it. >
5803 echo split(reltimestr(reltime(start)))[0]
5804< Also see |profiling|.
Bram Moolenaardb84e452010-08-15 13:50:43 +02005805 {only available when compiled with the |+reltime| feature}
Bram Moolenaar433f7c82006-03-21 21:29:36 +00005806
Bram Moolenaar071d4272004-06-13 20:20:40 +00005807 *remote_expr()* *E449*
5808remote_expr({server}, {string} [, {idvar}])
Bram Moolenaar446cb832008-06-24 21:56:24 +00005809 Send the {string} to {server}. The string is sent as an
Bram Moolenaar071d4272004-06-13 20:20:40 +00005810 expression and the result is returned after evaluation.
Bram Moolenaar362e1a32006-03-06 23:29:24 +00005811 The result must be a String or a |List|. A |List| is turned
5812 into a String by joining the items with a line break in
5813 between (not at the end), like with join(expr, "\n").
Bram Moolenaar071d4272004-06-13 20:20:40 +00005814 If {idvar} is present, it is taken as the name of a
5815 variable and a {serverid} for later use with
5816 remote_read() is stored there.
5817 See also |clientserver| |RemoteReply|.
5818 This function is not available in the |sandbox|.
5819 {only available when compiled with the |+clientserver| feature}
5820 Note: Any errors will cause a local error message to be issued
5821 and the result will be the empty string.
5822 Examples: >
5823 :echo remote_expr("gvim", "2+2")
5824 :echo remote_expr("gvim1", "b:current_syntax")
5825<
5826
5827remote_foreground({server}) *remote_foreground()*
5828 Move the Vim server with the name {server} to the foreground.
5829 This works like: >
5830 remote_expr({server}, "foreground()")
5831< Except that on Win32 systems the client does the work, to work
5832 around the problem that the OS doesn't always allow the server
5833 to bring itself to the foreground.
Bram Moolenaar9372a112005-12-06 19:59:18 +00005834 Note: This does not restore the window if it was minimized,
5835 like foreground() does.
Bram Moolenaar071d4272004-06-13 20:20:40 +00005836 This function is not available in the |sandbox|.
5837 {only in the Win32, Athena, Motif and GTK GUI versions and the
5838 Win32 console version}
5839
5840
5841remote_peek({serverid} [, {retvar}]) *remote_peek()*
5842 Returns a positive number if there are available strings
5843 from {serverid}. Copies any reply string into the variable
Bram Moolenaar446cb832008-06-24 21:56:24 +00005844 {retvar} if specified. {retvar} must be a string with the
Bram Moolenaar071d4272004-06-13 20:20:40 +00005845 name of a variable.
5846 Returns zero if none are available.
5847 Returns -1 if something is wrong.
5848 See also |clientserver|.
5849 This function is not available in the |sandbox|.
5850 {only available when compiled with the |+clientserver| feature}
5851 Examples: >
5852 :let repl = ""
5853 :echo "PEEK: ".remote_peek(id, "repl").": ".repl
5854
5855remote_read({serverid}) *remote_read()*
5856 Return the oldest available reply from {serverid} and consume
5857 it. It blocks until a reply is available.
5858 See also |clientserver|.
5859 This function is not available in the |sandbox|.
5860 {only available when compiled with the |+clientserver| feature}
5861 Example: >
5862 :echo remote_read(id)
5863<
5864 *remote_send()* *E241*
5865remote_send({server}, {string} [, {idvar}])
Bram Moolenaar446cb832008-06-24 21:56:24 +00005866 Send the {string} to {server}. The string is sent as input
Bram Moolenaard4755bb2004-09-02 19:12:26 +00005867 keys and the function returns immediately. At the Vim server
5868 the keys are not mapped |:map|.
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00005869 If {idvar} is present, it is taken as the name of a variable
5870 and a {serverid} for later use with remote_read() is stored
5871 there.
Bram Moolenaar071d4272004-06-13 20:20:40 +00005872 See also |clientserver| |RemoteReply|.
5873 This function is not available in the |sandbox|.
5874 {only available when compiled with the |+clientserver| feature}
5875 Note: Any errors will be reported in the server and may mess
5876 up the display.
5877 Examples: >
5878 :echo remote_send("gvim", ":DropAndReply ".file, "serverid").
5879 \ remote_read(serverid)
5880
5881 :autocmd NONE RemoteReply *
5882 \ echo remote_read(expand("<amatch>"))
5883 :echo remote_send("gvim", ":sleep 10 | echo ".
5884 \ 'server2client(expand("<client>"), "HELLO")<CR>')
Bram Moolenaara14de3d2005-01-07 21:48:26 +00005885<
Bram Moolenaarde8866b2005-01-06 23:24:37 +00005886remove({list}, {idx} [, {end}]) *remove()*
Bram Moolenaar32466aa2006-02-24 23:53:04 +00005887 Without {end}: Remove the item at {idx} from |List| {list} and
Bram Moolenaar8f3f58f2010-01-06 20:52:26 +01005888 return the item.
Bram Moolenaarde8866b2005-01-06 23:24:37 +00005889 With {end}: Remove items from {idx} to {end} (inclusive) and
Bram Moolenaar8f3f58f2010-01-06 20:52:26 +01005890 return a List with these items. When {idx} points to the same
Bram Moolenaarde8866b2005-01-06 23:24:37 +00005891 item as {end} a list with one item is returned. When {end}
5892 points to an item before {idx} this is an error.
5893 See |list-index| for possible values of {idx} and {end}.
Bram Moolenaard7ee7ce2005-01-03 21:02:03 +00005894 Example: >
5895 :echo "last item: " . remove(mylist, -1)
Bram Moolenaarde8866b2005-01-06 23:24:37 +00005896 :call remove(mylist, 0, 9)
Bram Moolenaard8b02732005-01-14 21:48:43 +00005897remove({dict}, {key})
5898 Remove the entry from {dict} with key {key}. Example: >
5899 :echo "removed " . remove(dict, "one")
5900< If there is no {key} in {dict} this is an error.
5901
5902 Use |delete()| to remove a file.
Bram Moolenaard7ee7ce2005-01-03 21:02:03 +00005903
Bram Moolenaar071d4272004-06-13 20:20:40 +00005904rename({from}, {to}) *rename()*
5905 Rename the file by the name {from} to the name {to}. This
5906 should also work to move files across file systems. The
5907 result is a Number, which is 0 if the file was renamed
5908 successfully, and non-zero when the renaming failed.
Bram Moolenaar798b30b2009-04-22 10:56:16 +00005909 NOTE: If {to} exists it is overwritten without warning.
Bram Moolenaar071d4272004-06-13 20:20:40 +00005910 This function is not available in the |sandbox|.
5911
Bram Moolenaarab79bcb2004-07-18 21:34:53 +00005912repeat({expr}, {count}) *repeat()*
5913 Repeat {expr} {count} times and return the concatenated
5914 result. Example: >
Bram Moolenaar551dbcc2006-04-25 22:13:59 +00005915 :let separator = repeat('-', 80)
Bram Moolenaarab79bcb2004-07-18 21:34:53 +00005916< When {count} is zero or negative the result is empty.
Bram Moolenaar32466aa2006-02-24 23:53:04 +00005917 When {expr} is a |List| the result is {expr} concatenated
Bram Moolenaar446cb832008-06-24 21:56:24 +00005918 {count} times. Example: >
Bram Moolenaarde8866b2005-01-06 23:24:37 +00005919 :let longlist = repeat(['a', 'b'], 3)
5920< Results in ['a', 'b', 'a', 'b', 'a', 'b'].
Bram Moolenaarab79bcb2004-07-18 21:34:53 +00005921
Bram Moolenaara14de3d2005-01-07 21:48:26 +00005922
Bram Moolenaar071d4272004-06-13 20:20:40 +00005923resolve({filename}) *resolve()* *E655*
5924 On MS-Windows, when {filename} is a shortcut (a .lnk file),
5925 returns the path the shortcut points to in a simplified form.
5926 On Unix, repeat resolving symbolic links in all path
5927 components of {filename} and return the simplified result.
5928 To cope with link cycles, resolving of symbolic links is
5929 stopped after 100 iterations.
5930 On other systems, return the simplified {filename}.
5931 The simplification step is done as by |simplify()|.
5932 resolve() keeps a leading path component specifying the
5933 current directory (provided the result is still a relative
5934 path name) and also keeps a trailing path separator.
5935
Bram Moolenaara14de3d2005-01-07 21:48:26 +00005936 *reverse()*
Bram Moolenaar446cb832008-06-24 21:56:24 +00005937reverse({list}) Reverse the order of items in {list} in-place. Returns
Bram Moolenaara14de3d2005-01-07 21:48:26 +00005938 {list}.
5939 If you want a list to remain unmodified make a copy first: >
5940 :let revlist = reverse(copy(mylist))
5941
Bram Moolenaar446cb832008-06-24 21:56:24 +00005942round({expr}) *round()*
Bram Moolenaarc236c162008-07-13 17:41:49 +00005943 Round off {expr} to the nearest integral value and return it
Bram Moolenaar446cb832008-06-24 21:56:24 +00005944 as a |Float|. If {expr} lies halfway between two integral
5945 values, then use the larger one (away from zero).
5946 {expr} must evaluate to a |Float| or a |Number|.
5947 Examples: >
5948 echo round(0.456)
5949< 0.0 >
5950 echo round(4.5)
5951< 5.0 >
5952 echo round(-4.5)
5953< -5.0
5954 {only available when compiled with the |+float| feature}
Bram Moolenaar34feacb2012-12-05 19:01:43 +01005955
Bram Moolenaar9a773482013-06-11 18:40:13 +02005956screenattr(row, col) *screenattr()*
5957 Like screenchar(), but return the attribute. This is a rather
5958 arbitrary number that can only be used to compare to the
5959 attribute at other positions.
5960
5961screenchar(row, col) *screenchar()*
5962 The result is a Number, which is the character at position
5963 [row, col] on the screen. This works for every possible
5964 screen position, also status lines, window separators and the
5965 command line. The top left position is row one, column one
5966 The character excludes composing characters. For double-byte
5967 encodings it may only be the first byte.
5968 This is mainly to be used for testing.
5969 Returns -1 when row or col is out of range.
5970
Bram Moolenaar34feacb2012-12-05 19:01:43 +01005971screencol() *screencol()*
5972 The result is a Number, which is the current screen column of
5973 the cursor. The leftmost column has number 1.
5974 This function is mainly used for testing.
5975
5976 Note: Always returns the current screen column, thus if used
5977 in a command (e.g. ":echo screencol()") it will return the
5978 column inside the command line, which is 1 when the command is
5979 executed. To get the cursor position in the file use one of
5980 the following mappings: >
5981 nnoremap <expr> GG ":echom ".screencol()."\n"
5982 nnoremap <silent> GG :echom screencol()<CR>
5983<
5984screenrow() *screenrow()*
5985 The result is a Number, which is the current screen row of the
5986 cursor. The top line has number one.
5987 This function is mainly used for testing.
5988
5989 Note: Same restrictions as with |screencol()|.
5990
Bram Moolenaar76929292008-01-06 19:07:36 +00005991search({pattern} [, {flags} [, {stopline} [, {timeout}]]]) *search()*
Bram Moolenaar071d4272004-06-13 20:20:40 +00005992 Search for regexp pattern {pattern}. The search starts at the
Bram Moolenaar383f9bc2005-01-19 22:18:32 +00005993 cursor position (you can use |cursor()| to set it).
Bram Moolenaar65c923a2006-03-03 22:56:30 +00005994
Bram Moolenaar2df58b42012-11-28 18:21:11 +01005995 When a match has been found its line number is returned.
Bram Moolenaarb8ff1fb2012-02-04 21:59:01 +01005996 If there is no match a 0 is returned and the cursor doesn't
5997 move. No error message is given.
Bram Moolenaarb8ff1fb2012-02-04 21:59:01 +01005998
Bram Moolenaar071d4272004-06-13 20:20:40 +00005999 {flags} is a String, which can contain these character flags:
Bram Moolenaarad4d8a12015-12-28 19:20:36 +01006000 'b' search Backward instead of forward
6001 'c' accept a match at the Cursor position
Bram Moolenaar87b5ca52006-03-04 21:55:31 +00006002 'e' move to the End of the match
Bram Moolenaar5eb86f92004-07-26 12:53:41 +00006003 'n' do Not move the cursor
Bram Moolenaarad4d8a12015-12-28 19:20:36 +01006004 'p' return number of matching sub-Pattern (see below)
6005 's' Set the ' mark at the previous location of the cursor
6006 'w' Wrap around the end of the file
6007 'W' don't Wrap around the end of the file
6008 'z' start searching at the cursor column instead of zero
Bram Moolenaar071d4272004-06-13 20:20:40 +00006009 If neither 'w' or 'W' is given, the 'wrapscan' option applies.
6010
Bram Moolenaar02743632005-07-25 20:42:36 +00006011 If the 's' flag is supplied, the ' mark is set, only if the
6012 cursor is moved. The 's' flag cannot be combined with the 'n'
6013 flag.
6014
Bram Moolenaaref2f6562007-05-06 13:32:59 +00006015 'ignorecase', 'smartcase' and 'magic' are used.
Bram Moolenaarad4d8a12015-12-28 19:20:36 +01006016
Bram Moolenaar85084ef2016-01-17 22:26:33 +01006017 When the 'z' flag is not given, searching always starts in
Bram Moolenaarad4d8a12015-12-28 19:20:36 +01006018 column zero and then matches before the cursor are skipped.
6019 When the 'c' flag is present in 'cpo' the next search starts
6020 after the match. Without the 'c' flag the next search starts
6021 one column further.
Bram Moolenaaref2f6562007-05-06 13:32:59 +00006022
Bram Moolenaara23ccb82006-02-27 00:08:02 +00006023 When the {stopline} argument is given then the search stops
6024 after searching this line. This is useful to restrict the
6025 search to a range of lines. Examples: >
6026 let match = search('(', 'b', line("w0"))
6027 let end = search('END', '', line("w$"))
6028< When {stopline} is used and it is not zero this also implies
6029 that the search does not wrap around the end of the file.
Bram Moolenaar76929292008-01-06 19:07:36 +00006030 A zero value is equal to not giving the argument.
6031
6032 When the {timeout} argument is given the search stops when
Bram Moolenaar1aeaf8c2012-05-18 13:46:39 +02006033 more than this many milliseconds have passed. Thus when
Bram Moolenaar76929292008-01-06 19:07:36 +00006034 {timeout} is 500 the search stops after half a second.
6035 The value must not be negative. A zero value is like not
6036 giving the argument.
Bram Moolenaardb84e452010-08-15 13:50:43 +02006037 {only available when compiled with the |+reltime| feature}
Bram Moolenaara23ccb82006-02-27 00:08:02 +00006038
Bram Moolenaar362e1a32006-03-06 23:29:24 +00006039 *search()-sub-match*
6040 With the 'p' flag the returned value is one more than the
6041 first sub-match in \(\). One if none of them matched but the
6042 whole pattern did match.
Bram Moolenaara23ccb82006-02-27 00:08:02 +00006043 To get the column number too use |searchpos()|.
Bram Moolenaar071d4272004-06-13 20:20:40 +00006044
Bram Moolenaar87b5ca52006-03-04 21:55:31 +00006045 The cursor will be positioned at the match, unless the 'n'
6046 flag is used.
6047
Bram Moolenaar071d4272004-06-13 20:20:40 +00006048 Example (goes over all files in the argument list): >
6049 :let n = 1
6050 :while n <= argc() " loop over all files in arglist
6051 : exe "argument " . n
6052 : " start at the last char in the file and wrap for the
6053 : " first search to find match at start of file
6054 : normal G$
6055 : let flags = "w"
6056 : while search("foo", flags) > 0
Bram Moolenaar446cb832008-06-24 21:56:24 +00006057 : s/foo/bar/g
Bram Moolenaar071d4272004-06-13 20:20:40 +00006058 : let flags = "W"
6059 : endwhile
6060 : update " write the file if modified
6061 : let n = n + 1
6062 :endwhile
6063<
Bram Moolenaar87b5ca52006-03-04 21:55:31 +00006064 Example for using some flags: >
6065 :echo search('\<if\|\(else\)\|\(endif\)', 'ncpe')
6066< This will search for the keywords "if", "else", and "endif"
6067 under or after the cursor. Because of the 'p' flag, it
6068 returns 1, 2, or 3 depending on which keyword is found, or 0
6069 if the search fails. With the cursor on the first word of the
6070 line:
6071 if (foo == 0) | let foo = foo + 1 | endif ~
6072 the function returns 1. Without the 'c' flag, the function
6073 finds the "endif" and returns 3. The same thing happens
6074 without the 'e' flag if the cursor is on the "f" of "if".
6075 The 'n' flag tells the function not to move the cursor.
6076
Bram Moolenaar92d640f2005-09-05 22:11:52 +00006077
Bram Moolenaarf75a9632005-09-13 21:20:47 +00006078searchdecl({name} [, {global} [, {thisblock}]]) *searchdecl()*
6079 Search for the declaration of {name}.
Bram Moolenaarc9b4b052006-04-30 18:54:39 +00006080
Bram Moolenaarf75a9632005-09-13 21:20:47 +00006081 With a non-zero {global} argument it works like |gD|, find
6082 first match in the file. Otherwise it works like |gd|, find
6083 first match in the function.
6084
6085 With a non-zero {thisblock} argument matches in a {} block
6086 that ends before the cursor position are ignored. Avoids
6087 finding variable declarations only valid in another scope.
6088
Bram Moolenaar92d640f2005-09-05 22:11:52 +00006089 Moves the cursor to the found match.
6090 Returns zero for success, non-zero for failure.
6091 Example: >
6092 if searchdecl('myvar') == 0
6093 echo getline('.')
6094 endif
6095<
Bram Moolenaar071d4272004-06-13 20:20:40 +00006096 *searchpair()*
Bram Moolenaar76929292008-01-06 19:07:36 +00006097searchpair({start}, {middle}, {end} [, {flags} [, {skip}
6098 [, {stopline} [, {timeout}]]]])
Bram Moolenaar071d4272004-06-13 20:20:40 +00006099 Search for the match of a nested start-end pair. This can be
6100 used to find the "endif" that matches an "if", while other
6101 if/endif pairs in between are ignored.
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00006102 The search starts at the cursor. The default is to search
6103 forward, include 'b' in {flags} to search backward.
6104 If a match is found, the cursor is positioned at it and the
6105 line number is returned. If no match is found 0 or -1 is
6106 returned and the cursor doesn't move. No error message is
6107 given.
Bram Moolenaar071d4272004-06-13 20:20:40 +00006108
6109 {start}, {middle} and {end} are patterns, see |pattern|. They
6110 must not contain \( \) pairs. Use of \%( \) is allowed. When
6111 {middle} is not empty, it is found when searching from either
6112 direction, but only when not in a nested start-end pair. A
6113 typical use is: >
6114 searchpair('\<if\>', '\<else\>', '\<endif\>')
6115< By leaving {middle} empty the "else" is skipped.
6116
Bram Moolenaar87b5ca52006-03-04 21:55:31 +00006117 {flags} 'b', 'c', 'n', 's', 'w' and 'W' are used like with
6118 |search()|. Additionally:
Bram Moolenaar071d4272004-06-13 20:20:40 +00006119 'r' Repeat until no more matches found; will find the
Bram Moolenaar446cb832008-06-24 21:56:24 +00006120 outer pair. Implies the 'W' flag.
6121 'm' Return number of matches instead of line number with
Bram Moolenaar87b5ca52006-03-04 21:55:31 +00006122 the match; will be > 1 when 'r' is used.
Bram Moolenaar446cb832008-06-24 21:56:24 +00006123 Note: it's nearly always a good idea to use the 'W' flag, to
6124 avoid wrapping around the end of the file.
Bram Moolenaar071d4272004-06-13 20:20:40 +00006125
6126 When a match for {start}, {middle} or {end} is found, the
6127 {skip} expression is evaluated with the cursor positioned on
6128 the start of the match. It should return non-zero if this
6129 match is to be skipped. E.g., because it is inside a comment
6130 or a string.
6131 When {skip} is omitted or empty, every match is accepted.
6132 When evaluating {skip} causes an error the search is aborted
6133 and -1 returned.
6134
Bram Moolenaar76929292008-01-06 19:07:36 +00006135 For {stopline} and {timeout} see |search()|.
Bram Moolenaara23ccb82006-02-27 00:08:02 +00006136
Bram Moolenaar071d4272004-06-13 20:20:40 +00006137 The value of 'ignorecase' is used. 'magic' is ignored, the
6138 patterns are used like it's on.
6139
6140 The search starts exactly at the cursor. A match with
6141 {start}, {middle} or {end} at the next character, in the
6142 direction of searching, is the first one found. Example: >
6143 if 1
6144 if 2
6145 endif 2
6146 endif 1
6147< When starting at the "if 2", with the cursor on the "i", and
6148 searching forwards, the "endif 2" is found. When starting on
6149 the character just before the "if 2", the "endif 1" will be
Bram Moolenaar446cb832008-06-24 21:56:24 +00006150 found. That's because the "if 2" will be found first, and
Bram Moolenaar071d4272004-06-13 20:20:40 +00006151 then this is considered to be a nested if/endif from "if 2" to
6152 "endif 2".
6153 When searching backwards and {end} is more than one character,
6154 it may be useful to put "\zs" at the end of the pattern, so
6155 that when the cursor is inside a match with the end it finds
6156 the matching start.
6157
6158 Example, to find the "endif" command in a Vim script: >
6159
6160 :echo searchpair('\<if\>', '\<el\%[seif]\>', '\<en\%[dif]\>', 'W',
6161 \ 'getline(".") =~ "^\\s*\""')
6162
6163< The cursor must be at or after the "if" for which a match is
6164 to be found. Note that single-quote strings are used to avoid
6165 having to double the backslashes. The skip expression only
6166 catches comments at the start of a line, not after a command.
6167 Also, a word "en" or "if" halfway a line is considered a
6168 match.
6169 Another example, to search for the matching "{" of a "}": >
6170
6171 :echo searchpair('{', '', '}', 'bW')
6172
6173< This works when the cursor is at or before the "}" for which a
6174 match is to be found. To reject matches that syntax
6175 highlighting recognized as strings: >
6176
6177 :echo searchpair('{', '', '}', 'bW',
6178 \ 'synIDattr(synID(line("."), col("."), 0), "name") =~? "string"')
6179<
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00006180 *searchpairpos()*
Bram Moolenaar76929292008-01-06 19:07:36 +00006181searchpairpos({start}, {middle}, {end} [, {flags} [, {skip}
6182 [, {stopline} [, {timeout}]]]])
Bram Moolenaar8f3f58f2010-01-06 20:52:26 +01006183 Same as |searchpair()|, but returns a |List| with the line and
Bram Moolenaar32466aa2006-02-24 23:53:04 +00006184 column position of the match. The first element of the |List|
6185 is the line number and the second element is the byte index of
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00006186 the column position of the match. If no match is found,
Bram Moolenaar9855d6b2010-07-18 14:34:51 +02006187 returns [0, 0]. >
6188
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00006189 :let [lnum,col] = searchpairpos('{', '', '}', 'n')
6190<
6191 See |match-parens| for a bigger and more useful example.
6192
Bram Moolenaar76929292008-01-06 19:07:36 +00006193searchpos({pattern} [, {flags} [, {stopline} [, {timeout}]]]) *searchpos()*
Bram Moolenaara23ccb82006-02-27 00:08:02 +00006194 Same as |search()|, but returns a |List| with the line and
Bram Moolenaar32466aa2006-02-24 23:53:04 +00006195 column position of the match. The first element of the |List|
6196 is the line number and the second element is the byte index of
6197 the column position of the match. If no match is found,
6198 returns [0, 0].
Bram Moolenaar362e1a32006-03-06 23:29:24 +00006199 Example: >
6200 :let [lnum, col] = searchpos('mypattern', 'n')
6201
6202< When the 'p' flag is given then there is an extra item with
6203 the sub-pattern match number |search()-sub-match|. Example: >
6204 :let [lnum, col, submatch] = searchpos('\(\l\)\|\(\u\)', 'np')
6205< In this example "submatch" is 2 when a lowercase letter is
6206 found |/\l|, 3 when an uppercase letter is found |/\u|.
6207
Bram Moolenaar81edd172016-04-14 13:51:37 +02006208server2client({clientid}, {string}) *server2client()*
Bram Moolenaar071d4272004-06-13 20:20:40 +00006209 Send a reply string to {clientid}. The most recent {clientid}
6210 that sent a string can be retrieved with expand("<client>").
6211 {only available when compiled with the |+clientserver| feature}
6212 Note:
6213 This id has to be stored before the next command can be
Bram Moolenaar402d2fe2005-04-15 21:00:38 +00006214 received. I.e. before returning from the received command and
Bram Moolenaar071d4272004-06-13 20:20:40 +00006215 before calling any commands that waits for input.
6216 See also |clientserver|.
6217 Example: >
6218 :echo server2client(expand("<client>"), "HELLO")
6219<
6220serverlist() *serverlist()*
6221 Return a list of available server names, one per line.
6222 When there are no servers or the information is not available
6223 an empty string is returned. See also |clientserver|.
6224 {only available when compiled with the |+clientserver| feature}
6225 Example: >
6226 :echo serverlist()
6227<
6228setbufvar({expr}, {varname}, {val}) *setbufvar()*
6229 Set option or local variable {varname} in buffer {expr} to
6230 {val}.
6231 This also works for a global or local window option, but it
6232 doesn't work for a global or local window variable.
6233 For a local window option the global value is unchanged.
6234 For the use of {expr}, see |bufname()| above.
6235 Note that the variable name without "b:" must be used.
6236 Examples: >
6237 :call setbufvar(1, "&mod", 1)
6238 :call setbufvar("todo", "myvar", "foobar")
6239< This function is not available in the |sandbox|.
6240
Bram Moolenaar12969c02015-09-08 23:36:10 +02006241setcharsearch({dict}) *setcharsearch()*
Bram Moolenaardbd24b52015-08-11 14:26:19 +02006242 Set the current character search information to {dict},
6243 which contains one or more of the following entries:
6244
6245 char character which will be used for a subsequent
6246 |,| or |;| command; an empty string clears the
6247 character search
6248 forward direction of character search; 1 for forward,
6249 0 for backward
6250 until type of character search; 1 for a |t| or |T|
6251 character search, 0 for an |f| or |F|
6252 character search
6253
6254 This can be useful to save/restore a user's character search
6255 from a script: >
6256 :let prevsearch = getcharsearch()
6257 :" Perform a command which clobbers user's search
6258 :call setcharsearch(prevsearch)
6259< Also see |getcharsearch()|.
6260
Bram Moolenaar071d4272004-06-13 20:20:40 +00006261setcmdpos({pos}) *setcmdpos()*
6262 Set the cursor position in the command line to byte position
Bram Moolenaar446cb832008-06-24 21:56:24 +00006263 {pos}. The first position is 1.
Bram Moolenaar071d4272004-06-13 20:20:40 +00006264 Use |getcmdpos()| to obtain the current position.
6265 Only works while editing the command line, thus you must use
Bram Moolenaard8b02732005-01-14 21:48:43 +00006266 |c_CTRL-\_e|, |c_CTRL-R_=| or |c_CTRL-R_CTRL-R| with '='. For
6267 |c_CTRL-\_e| and |c_CTRL-R_CTRL-R| with '=' the position is
6268 set after the command line is set to the expression. For
6269 |c_CTRL-R_=| it is set after evaluating the expression but
6270 before inserting the resulting text.
Bram Moolenaar071d4272004-06-13 20:20:40 +00006271 When the number is too big the cursor is put at the end of the
6272 line. A number smaller than one has undefined results.
6273 Returns 0 when successful, 1 when not editing the command
6274 line.
6275
Bram Moolenaar80492532016-03-08 17:08:53 +01006276setfperm({fname}, {mode}) *setfperm()* *chmod*
6277 Set the file permissions for {fname} to {mode}.
6278 {mode} must be a string with 9 characters. It is of the form
6279 "rwxrwxrwx", where each group of "rwx" flags represent, in
6280 turn, the permissions of the owner of the file, the group the
6281 file belongs to, and other users. A '-' character means the
6282 permission is off, any other character means on. Multi-byte
6283 characters are not supported.
6284
6285 For example "rw-r-----" means read-write for the user,
6286 readable by the group, not accessible by others. "xx-x-----"
6287 would do the same thing.
6288
6289 Returns non-zero for success, zero for failure.
6290
6291 To read permissions see |getfperm()|.
6292
6293
Bram Moolenaar446cb832008-06-24 21:56:24 +00006294setline({lnum}, {text}) *setline()*
Bram Moolenaarb8ff1fb2012-02-04 21:59:01 +01006295 Set line {lnum} of the current buffer to {text}. To insert
6296 lines use |append()|.
Bram Moolenaar402d2fe2005-04-15 21:00:38 +00006297 {lnum} is used like with |getline()|.
Bram Moolenaar446cb832008-06-24 21:56:24 +00006298 When {lnum} is just below the last line the {text} will be
Bram Moolenaar2389c3c2005-05-22 22:07:59 +00006299 added as a new line.
Bram Moolenaar402d2fe2005-04-15 21:00:38 +00006300 If this succeeds, 0 is returned. If this fails (most likely
6301 because {lnum} is invalid) 1 is returned. Example: >
Bram Moolenaar071d4272004-06-13 20:20:40 +00006302 :call setline(5, strftime("%c"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006303< When {text} is a |List| then line {lnum} and following lines
Bram Moolenaar2389c3c2005-05-22 22:07:59 +00006304 will be set to the items in the list. Example: >
6305 :call setline(5, ['aaa', 'bbb', 'ccc'])
6306< This is equivalent to: >
Bram Moolenaar53bfca22012-04-13 23:04:47 +02006307 :for [n, l] in [[5, 'aaa'], [6, 'bbb'], [7, 'ccc']]
Bram Moolenaar2389c3c2005-05-22 22:07:59 +00006308 : call setline(n, l)
6309 :endfor
Bram Moolenaar071d4272004-06-13 20:20:40 +00006310< Note: The '[ and '] marks are not set.
6311
Bram Moolenaar17c7c012006-01-26 22:25:15 +00006312setloclist({nr}, {list} [, {action}]) *setloclist()*
6313 Create or replace or add to the location list for window {nr}.
Bram Moolenaar888ccac2016-06-04 18:49:36 +02006314 {nr} can be the window number or the window ID.
6315 When {nr} is zero the current window is used.
6316
6317 For a location list window, the displayed location list is
6318 modified. For an invalid window number {nr}, -1 is returned.
Bram Moolenaar6ee10162007-07-26 20:58:42 +00006319 Otherwise, same as |setqflist()|.
6320 Also see |location-list|.
6321
6322setmatches({list}) *setmatches()*
6323 Restores a list of matches saved by |getmatches()|. Returns 0
Bram Moolenaar446cb832008-06-24 21:56:24 +00006324 if successful, otherwise -1. All current matches are cleared
Bram Moolenaar6ee10162007-07-26 20:58:42 +00006325 before the list is restored. See example for |getmatches()|.
Bram Moolenaar68b76a62005-03-25 21:53:48 +00006326
Bram Moolenaar65c923a2006-03-03 22:56:30 +00006327 *setpos()*
6328setpos({expr}, {list})
6329 Set the position for {expr}. Possible values:
6330 . the cursor
6331 'x mark x
6332
Bram Moolenaar493c1782014-05-28 14:34:46 +02006333 {list} must be a |List| with four or five numbers:
Bram Moolenaar65c923a2006-03-03 22:56:30 +00006334 [bufnum, lnum, col, off]
Bram Moolenaar493c1782014-05-28 14:34:46 +02006335 [bufnum, lnum, col, off, curswant]
Bram Moolenaar65c923a2006-03-03 22:56:30 +00006336
Bram Moolenaar446cb832008-06-24 21:56:24 +00006337 "bufnum" is the buffer number. Zero can be used for the
Bram Moolenaarc9b4b052006-04-30 18:54:39 +00006338 current buffer. Setting the cursor is only possible for
Bram Moolenaar65c923a2006-03-03 22:56:30 +00006339 the current buffer. To set a mark in another buffer you can
6340 use the |bufnr()| function to turn a file name into a buffer
6341 number.
Bram Moolenaardb552d602006-03-23 22:59:57 +00006342 Does not change the jumplist.
Bram Moolenaar65c923a2006-03-03 22:56:30 +00006343
6344 "lnum" and "col" are the position in the buffer. The first
Bram Moolenaar8f3f58f2010-01-06 20:52:26 +01006345 column is 1. Use a zero "lnum" to delete a mark. If "col" is
6346 smaller than 1 then 1 is used.
Bram Moolenaar65c923a2006-03-03 22:56:30 +00006347
6348 The "off" number is only used when 'virtualedit' is set. Then
6349 it is the offset in screen columns from the start of the
Bram Moolenaard46bbc72007-05-12 14:38:41 +00006350 character. E.g., a position within a <Tab> or after the last
Bram Moolenaar65c923a2006-03-03 22:56:30 +00006351 character.
6352
Bram Moolenaar493c1782014-05-28 14:34:46 +02006353 The "curswant" number is only used when setting the cursor
6354 position. It sets the preferred column for when moving the
6355 cursor vertically. When the "curswant" number is missing the
6356 preferred column is not set. When it is present and setting a
6357 mark position it is not used.
6358
Bram Moolenaardfb18412013-12-11 18:53:29 +01006359 Note that for '< and '> changing the line number may result in
6360 the marks to be effectively be swapped, so that '< is always
6361 before '>.
6362
Bram Moolenaar08250432008-02-13 11:42:46 +00006363 Returns 0 when the position could be set, -1 otherwise.
6364 An error message is given if {expr} is invalid.
6365
Bram Moolenaar6f6c0f82014-05-28 20:31:42 +02006366 Also see |getpos()| and |getcurpos()|.
Bram Moolenaar65c923a2006-03-03 22:56:30 +00006367
Bram Moolenaaref2f6562007-05-06 13:32:59 +00006368 This does not restore the preferred column for moving
Bram Moolenaar493c1782014-05-28 14:34:46 +02006369 vertically; if you set the cursor position with this, |j| and
6370 |k| motions will jump to previous columns! Use |cursor()| to
6371 also set the preferred column. Also see the "curswant" key in
6372 |winrestview()|.
Bram Moolenaaref2f6562007-05-06 13:32:59 +00006373
Bram Moolenaar65c923a2006-03-03 22:56:30 +00006374
Bram Moolenaar35c54e52005-05-20 21:25:31 +00006375setqflist({list} [, {action}]) *setqflist()*
Bram Moolenaar17c7c012006-01-26 22:25:15 +00006376 Create or replace or add to the quickfix list using the items
6377 in {list}. Each item in {list} is a dictionary.
6378 Non-dictionary items in {list} are ignored. Each dictionary
6379 item can contain the following entries:
Bram Moolenaar68b76a62005-03-25 21:53:48 +00006380
Bram Moolenaar48b66fb2007-02-04 01:58:18 +00006381 bufnr buffer number; must be the number of a valid
Bram Moolenaar446cb832008-06-24 21:56:24 +00006382 buffer
Bram Moolenaar48b66fb2007-02-04 01:58:18 +00006383 filename name of a file; only used when "bufnr" is not
Bram Moolenaar446cb832008-06-24 21:56:24 +00006384 present or it is invalid.
Bram Moolenaar68b76a62005-03-25 21:53:48 +00006385 lnum line number in the file
Bram Moolenaar68b76a62005-03-25 21:53:48 +00006386 pattern search pattern used to locate the error
Bram Moolenaar582fd852005-03-28 20:58:01 +00006387 col column number
6388 vcol when non-zero: "col" is visual column
Bram Moolenaarc9b4b052006-04-30 18:54:39 +00006389 when zero: "col" is byte index
Bram Moolenaar582fd852005-03-28 20:58:01 +00006390 nr error number
Bram Moolenaar68b76a62005-03-25 21:53:48 +00006391 text description of the error
Bram Moolenaar582fd852005-03-28 20:58:01 +00006392 type single-character error type, 'E', 'W', etc.
Bram Moolenaar68b76a62005-03-25 21:53:48 +00006393
Bram Moolenaar582fd852005-03-28 20:58:01 +00006394 The "col", "vcol", "nr", "type" and "text" entries are
6395 optional. Either "lnum" or "pattern" entry can be used to
6396 locate a matching error line.
Bram Moolenaar48b66fb2007-02-04 01:58:18 +00006397 If the "filename" and "bufnr" entries are not present or
6398 neither the "lnum" or "pattern" entries are present, then the
6399 item will not be handled as an error line.
Bram Moolenaar68b76a62005-03-25 21:53:48 +00006400 If both "pattern" and "lnum" are present then "pattern" will
6401 be used.
Bram Moolenaar00a927d2010-05-14 23:24:24 +02006402 If you supply an empty {list}, the quickfix list will be
6403 cleared.
Bram Moolenaar48b66fb2007-02-04 01:58:18 +00006404 Note that the list is not exactly the same as what
6405 |getqflist()| returns.
Bram Moolenaar68b76a62005-03-25 21:53:48 +00006406
Bram Moolenaar06481422016-04-30 15:13:38 +02006407 *E927*
Bram Moolenaar35c54e52005-05-20 21:25:31 +00006408 If {action} is set to 'a', then the items from {list} are
6409 added to the existing quickfix list. If there is no existing
Bram Moolenaar511972d2016-06-04 18:09:59 +02006410 list, then a new list is created.
6411
6412 If {action} is set to 'r', then the items from the current
6413 quickfix list are replaced with the items from {list}. This
6414 can also be used to clear the list: >
6415 :call setqflist([], 'r')
6416<
6417 If {action} is not present or is set to ' ', then a new list
6418 is created.
Bram Moolenaar35c54e52005-05-20 21:25:31 +00006419
Bram Moolenaar68b76a62005-03-25 21:53:48 +00006420 Returns zero for success, -1 for failure.
6421
6422 This function can be used to create a quickfix list
6423 independent of the 'errorformat' setting. Use a command like
6424 ":cc 1" to jump to the first position.
6425
6426
Bram Moolenaar071d4272004-06-13 20:20:40 +00006427 *setreg()*
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006428setreg({regname}, {value} [, {options}])
Bram Moolenaar071d4272004-06-13 20:20:40 +00006429 Set the register {regname} to {value}.
Bram Moolenaar5a50c222014-04-02 22:17:10 +02006430 {value} may be any value returned by |getreg()|, including
6431 a |List|.
Bram Moolenaar071d4272004-06-13 20:20:40 +00006432 If {options} contains "a" or {regname} is upper case,
6433 then the value is appended.
Bram Moolenaarc6485bc2010-07-28 17:02:55 +02006434 {options} can also contain a register type specification:
Bram Moolenaar071d4272004-06-13 20:20:40 +00006435 "c" or "v" |characterwise| mode
6436 "l" or "V" |linewise| mode
6437 "b" or "<CTRL-V>" |blockwise-visual| mode
6438 If a number immediately follows "b" or "<CTRL-V>" then this is
6439 used as the width of the selection - if it is not specified
6440 then the width of the block is set to the number of characters
Bram Moolenaard46bbc72007-05-12 14:38:41 +00006441 in the longest line (counting a <Tab> as 1 character).
Bram Moolenaar071d4272004-06-13 20:20:40 +00006442
6443 If {options} contains no register settings, then the default
Bram Moolenaar5a50c222014-04-02 22:17:10 +02006444 is to use character mode unless {value} ends in a <NL> for
6445 string {value} and linewise mode for list {value}. Blockwise
6446 mode is never selected automatically.
6447 Returns zero for success, non-zero for failure.
6448
6449 *E883*
Bram Moolenaar34401cc2014-08-29 15:12:19 +02006450 Note: you may not use |List| containing more than one item to
Bram Moolenaar5a50c222014-04-02 22:17:10 +02006451 set search and expression registers. Lists containing no
6452 items act like empty strings.
Bram Moolenaar071d4272004-06-13 20:20:40 +00006453
6454 Examples: >
6455 :call setreg(v:register, @*)
6456 :call setreg('*', @%, 'ac')
6457 :call setreg('a', "1\n2\n3", 'b5')
6458
6459< This example shows using the functions to save and restore a
Bram Moolenaar5a50c222014-04-02 22:17:10 +02006460 register (note: you may not reliably restore register value
6461 without using the third argument to |getreg()| as without it
6462 newlines are represented as newlines AND Nul bytes are
6463 represented as newlines as well, see |NL-used-for-Nul|). >
6464 :let var_a = getreg('a', 1, 1)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006465 :let var_amode = getregtype('a')
6466 ....
6467 :call setreg('a', var_a, var_amode)
6468
6469< You can also change the type of a register by appending
6470 nothing: >
6471 :call setreg('a', '', 'al')
6472
Bram Moolenaar06b5d512010-05-22 15:37:44 +02006473settabvar({tabnr}, {varname}, {val}) *settabvar()*
6474 Set tab-local variable {varname} to {val} in tab page {tabnr}.
6475 |t:var|
6476 Note that the variable name without "t:" must be used.
6477 Tabs are numbered starting with one.
Bram Moolenaar06b5d512010-05-22 15:37:44 +02006478 This function is not available in the |sandbox|.
6479
Bram Moolenaarc6249bb2006-04-15 20:25:09 +00006480settabwinvar({tabnr}, {winnr}, {varname}, {val}) *settabwinvar()*
6481 Set option or local variable {varname} in window {winnr} to
6482 {val}.
6483 Tabs are numbered starting with one. For the current tabpage
6484 use |setwinvar()|.
Bram Moolenaar888ccac2016-06-04 18:49:36 +02006485 {winnr} can be the window number or the window ID.
Bram Moolenaarc6249bb2006-04-15 20:25:09 +00006486 When {winnr} is zero the current window is used.
Bram Moolenaar071d4272004-06-13 20:20:40 +00006487 This also works for a global or local buffer option, but it
6488 doesn't work for a global or local buffer variable.
6489 For a local buffer option the global value is unchanged.
6490 Note that the variable name without "w:" must be used.
Bram Moolenaarc6249bb2006-04-15 20:25:09 +00006491 Examples: >
6492 :call settabwinvar(1, 1, "&list", 0)
6493 :call settabwinvar(3, 2, "myvar", "foobar")
6494< This function is not available in the |sandbox|.
6495
6496setwinvar({nr}, {varname}, {val}) *setwinvar()*
6497 Like |settabwinvar()| for the current tab page.
Bram Moolenaar071d4272004-06-13 20:20:40 +00006498 Examples: >
6499 :call setwinvar(1, "&list", 0)
6500 :call setwinvar(2, "myvar", "foobar")
Bram Moolenaar071d4272004-06-13 20:20:40 +00006501
Bram Moolenaaraf9aeb92013-02-13 17:35:04 +01006502sha256({string}) *sha256()*
Bram Moolenaar2b8388b2015-02-28 13:11:45 +01006503 Returns a String with 64 hex characters, which is the SHA256
Bram Moolenaaraf9aeb92013-02-13 17:35:04 +01006504 checksum of {string}.
6505 {only available when compiled with the |+cryptv| feature}
6506
Bram Moolenaar05bb9532008-07-04 09:44:11 +00006507shellescape({string} [, {special}]) *shellescape()*
Bram Moolenaar8f3f58f2010-01-06 20:52:26 +01006508 Escape {string} for use as a shell command argument.
Bram Moolenaar60a495f2006-10-03 12:44:42 +00006509 On MS-Windows and MS-DOS, when 'shellslash' is not set, it
Bram Moolenaar05bb9532008-07-04 09:44:11 +00006510 will enclose {string} in double quotes and double all double
Bram Moolenaar60a495f2006-10-03 12:44:42 +00006511 quotes within {string}.
6512 For other systems, it will enclose {string} in single quotes
6513 and replace all "'" with "'\''".
Bram Moolenaar05bb9532008-07-04 09:44:11 +00006514 When the {special} argument is present and it's a non-zero
6515 Number or a non-empty String (|non-zero-arg|), then special
Bram Moolenaare37d50a2008-08-06 17:06:04 +00006516 items such as "!", "%", "#" and "<cword>" will be preceded by
6517 a backslash. This backslash will be removed again by the |:!|
Bram Moolenaar05bb9532008-07-04 09:44:11 +00006518 command.
Bram Moolenaare37d50a2008-08-06 17:06:04 +00006519 The "!" character will be escaped (again with a |non-zero-arg|
6520 {special}) when 'shell' contains "csh" in the tail. That is
6521 because for csh and tcsh "!" is used for history replacement
6522 even when inside single quotes.
6523 The <NL> character is also escaped. With a |non-zero-arg|
6524 {special} and 'shell' containing "csh" in the tail it's
6525 escaped a second time.
Bram Moolenaar05bb9532008-07-04 09:44:11 +00006526 Example of use with a |:!| command: >
6527 :exe '!dir ' . shellescape(expand('<cfile>'), 1)
6528< This results in a directory listing for the file under the
6529 cursor. Example of use with |system()|: >
6530 :call system("chmod +w -- " . shellescape(expand("%")))
Bram Moolenaar26df0922014-02-23 23:39:13 +01006531< See also |::S|.
Bram Moolenaar60a495f2006-10-03 12:44:42 +00006532
6533
Bram Moolenaar2d17fa32012-10-21 00:45:18 +02006534shiftwidth() *shiftwidth()*
6535 Returns the effective value of 'shiftwidth'. This is the
6536 'shiftwidth' value unless it is zero, in which case it is the
Bram Moolenaar009d84a2016-01-28 14:12:00 +01006537 'tabstop' value. This function was introduced with patch
6538 7.3.694 in 2012, everybody should have it by now.
Bram Moolenaar2d17fa32012-10-21 00:45:18 +02006539
6540
Bram Moolenaar071d4272004-06-13 20:20:40 +00006541simplify({filename}) *simplify()*
6542 Simplify the file name as much as possible without changing
6543 the meaning. Shortcuts (on MS-Windows) or symbolic links (on
6544 Unix) are not resolved. If the first path component in
6545 {filename} designates the current directory, this will be
6546 valid for the result as well. A trailing path separator is
6547 not removed either.
6548 Example: >
6549 simplify("./dir/.././/file/") == "./file/"
6550< Note: The combination "dir/.." is only removed if "dir" is
6551 a searchable directory or does not exist. On Unix, it is also
6552 removed when "dir" is a symbolic link within the same
6553 directory. In order to resolve all the involved symbolic
6554 links before simplifying the path name, use |resolve()|.
6555
Bram Moolenaara14de3d2005-01-07 21:48:26 +00006556
Bram Moolenaar446cb832008-06-24 21:56:24 +00006557sin({expr}) *sin()*
6558 Return the sine of {expr}, measured in radians, as a |Float|.
6559 {expr} must evaluate to a |Float| or a |Number|.
6560 Examples: >
6561 :echo sin(100)
6562< -0.506366 >
6563 :echo sin(-4.01)
6564< 0.763301
6565 {only available when compiled with the |+float| feature}
6566
6567
Bram Moolenaardb7c6862010-05-21 16:33:48 +02006568sinh({expr}) *sinh()*
Bram Moolenaar9855d6b2010-07-18 14:34:51 +02006569 Return the hyperbolic sine of {expr} as a |Float| in the range
Bram Moolenaardb7c6862010-05-21 16:33:48 +02006570 [-inf, inf].
Bram Moolenaar9855d6b2010-07-18 14:34:51 +02006571 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaardb7c6862010-05-21 16:33:48 +02006572 Examples: >
6573 :echo sinh(0.5)
6574< 0.521095 >
6575 :echo sinh(-0.9)
6576< -1.026517
Bram Moolenaardb84e452010-08-15 13:50:43 +02006577 {only available when compiled with the |+float| feature}
Bram Moolenaardb7c6862010-05-21 16:33:48 +02006578
6579
Bram Moolenaar5f894962011-06-19 02:55:37 +02006580sort({list} [, {func} [, {dict}]]) *sort()* *E702*
Bram Moolenaar327aa022014-03-25 18:24:23 +01006581 Sort the items in {list} in-place. Returns {list}.
6582
6583 If you want a list to remain unmodified make a copy first: >
Bram Moolenaara14de3d2005-01-07 21:48:26 +00006584 :let sortedlist = sort(copy(mylist))
Bram Moolenaar822ff862014-06-12 21:46:14 +02006585
Bram Moolenaar946e27a2014-06-25 18:50:27 +02006586< When {func} is omitted, is empty or zero, then sort() uses the
6587 string representation of each item to sort on. Numbers sort
6588 after Strings, |Lists| after Numbers. For sorting text in the
6589 current buffer use |:sort|.
Bram Moolenaar327aa022014-03-25 18:24:23 +01006590
Bram Moolenaar34401cc2014-08-29 15:12:19 +02006591 When {func} is given and it is '1' or 'i' then case is
Bram Moolenaar946e27a2014-06-25 18:50:27 +02006592 ignored.
6593
6594 When {func} is given and it is 'n' then all items will be
6595 sorted numerical (Implementation detail: This uses the
6596 strtod() function to parse numbers, Strings, Lists, Dicts and
6597 Funcrefs will be considered as being 0).
6598
Bram Moolenaarb00da1d2015-12-03 16:33:12 +01006599 When {func} is given and it is 'N' then all items will be
6600 sorted numerical. This is like 'n' but a string containing
6601 digits will be used as the number they represent.
6602
Bram Moolenaar13d5aee2016-01-21 23:36:05 +01006603 When {func} is given and it is 'f' then all items will be
6604 sorted numerical. All values must be a Number or a Float.
6605
Bram Moolenaar32466aa2006-02-24 23:53:04 +00006606 When {func} is a |Funcref| or a function name, this function
6607 is called to compare items. The function is invoked with two
Bram Moolenaar8f3f58f2010-01-06 20:52:26 +01006608 items as argument and must return zero if they are equal, 1 or
6609 bigger if the first one sorts after the second one, -1 or
6610 smaller if the first one sorts before the second one.
Bram Moolenaar327aa022014-03-25 18:24:23 +01006611
6612 {dict} is for functions with the "dict" attribute. It will be
6613 used to set the local variable "self". |Dictionary-function|
6614
Bram Moolenaar8bb1c3e2014-07-04 16:43:17 +02006615 The sort is stable, items which compare equal (as number or as
6616 string) will keep their relative position. E.g., when sorting
Bram Moolenaardb6ea062014-07-10 22:01:47 +02006617 on numbers, text strings will sort next to each other, in the
Bram Moolenaar8bb1c3e2014-07-04 16:43:17 +02006618 same order as they were originally.
6619
Bram Moolenaar327aa022014-03-25 18:24:23 +01006620 Also see |uniq()|.
6621
Bram Moolenaar8f3f58f2010-01-06 20:52:26 +01006622 Example: >
Bram Moolenaara14de3d2005-01-07 21:48:26 +00006623 func MyCompare(i1, i2)
6624 return a:i1 == a:i2 ? 0 : a:i1 > a:i2 ? 1 : -1
6625 endfunc
6626 let sortedlist = sort(mylist, "MyCompare")
Bram Moolenaar8f3f58f2010-01-06 20:52:26 +01006627< A shorter compare version for this specific simple case, which
6628 ignores overflow: >
6629 func MyCompare(i1, i2)
6630 return a:i1 - a:i2
6631 endfunc
Bram Moolenaard857f0e2005-06-21 22:37:39 +00006632<
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00006633 *soundfold()*
6634soundfold({word})
6635 Return the sound-folded equivalent of {word}. Uses the first
Bram Moolenaar446cb832008-06-24 21:56:24 +00006636 language in 'spelllang' for the current window that supports
Bram Moolenaar42eeac32005-06-29 22:40:58 +00006637 soundfolding. 'spell' must be set. When no sound folding is
6638 possible the {word} is returned unmodified.
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00006639 This can be used for making spelling suggestions. Note that
6640 the method can be quite slow.
6641
Bram Moolenaard857f0e2005-06-21 22:37:39 +00006642 *spellbadword()*
Bram Moolenaar1e015462005-09-25 22:16:38 +00006643spellbadword([{sentence}])
6644 Without argument: The result is the badly spelled word under
6645 or after the cursor. The cursor is moved to the start of the
6646 bad word. When no bad word is found in the cursor line the
6647 result is an empty string and the cursor doesn't move.
6648
6649 With argument: The result is the first word in {sentence} that
6650 is badly spelled. If there are no spelling mistakes the
6651 result is an empty string.
6652
6653 The return value is a list with two items:
6654 - The badly spelled word or an empty string.
6655 - The type of the spelling error:
Bram Moolenaarc9b4b052006-04-30 18:54:39 +00006656 "bad" spelling mistake
Bram Moolenaar1e015462005-09-25 22:16:38 +00006657 "rare" rare word
6658 "local" word only valid in another region
6659 "caps" word should start with Capital
6660 Example: >
6661 echo spellbadword("the quik brown fox")
6662< ['quik', 'bad'] ~
6663
6664 The spelling information for the current window is used. The
6665 'spell' option must be set and the value of 'spelllang' is
6666 used.
Bram Moolenaard857f0e2005-06-21 22:37:39 +00006667
6668 *spellsuggest()*
Bram Moolenaarc54b8a72005-09-30 21:20:29 +00006669spellsuggest({word} [, {max} [, {capital}]])
Bram Moolenaar32466aa2006-02-24 23:53:04 +00006670 Return a |List| with spelling suggestions to replace {word}.
Bram Moolenaard857f0e2005-06-21 22:37:39 +00006671 When {max} is given up to this number of suggestions are
6672 returned. Otherwise up to 25 suggestions are returned.
6673
Bram Moolenaarc54b8a72005-09-30 21:20:29 +00006674 When the {capital} argument is given and it's non-zero only
6675 suggestions with a leading capital will be given. Use this
6676 after a match with 'spellcapcheck'.
6677
Bram Moolenaard857f0e2005-06-21 22:37:39 +00006678 {word} can be a badly spelled word followed by other text.
6679 This allows for joining two words that were split. The
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00006680 suggestions also include the following text, thus you can
6681 replace a line.
6682
6683 {word} may also be a good word. Similar words will then be
Bram Moolenaarc54b8a72005-09-30 21:20:29 +00006684 returned. {word} itself is not included in the suggestions,
6685 although it may appear capitalized.
Bram Moolenaard857f0e2005-06-21 22:37:39 +00006686
6687 The spelling information for the current window is used. The
Bram Moolenaar42eeac32005-06-29 22:40:58 +00006688 'spell' option must be set and the values of 'spelllang' and
6689 'spellsuggest' are used.
Bram Moolenaard857f0e2005-06-21 22:37:39 +00006690
Bram Moolenaara14de3d2005-01-07 21:48:26 +00006691
Bram Moolenaar2389c3c2005-05-22 22:07:59 +00006692split({expr} [, {pattern} [, {keepempty}]]) *split()*
Bram Moolenaar32466aa2006-02-24 23:53:04 +00006693 Make a |List| out of {expr}. When {pattern} is omitted or
6694 empty each white-separated sequence of characters becomes an
6695 item.
Bram Moolenaara14de3d2005-01-07 21:48:26 +00006696 Otherwise the string is split where {pattern} matches,
Bram Moolenaar97d62492012-11-15 21:28:22 +01006697 removing the matched characters. 'ignorecase' is not used
6698 here, add \c to ignore case. |/\c|
Bram Moolenaar2389c3c2005-05-22 22:07:59 +00006699 When the first or last item is empty it is omitted, unless the
6700 {keepempty} argument is given and it's non-zero.
Bram Moolenaar5c06f8b2005-05-31 22:14:58 +00006701 Other empty items are kept when {pattern} matches at least one
6702 character or when {keepempty} is non-zero.
Bram Moolenaara14de3d2005-01-07 21:48:26 +00006703 Example: >
Bram Moolenaar5f2bb9f2005-01-11 21:29:04 +00006704 :let words = split(getline('.'), '\W\+')
Bram Moolenaar2389c3c2005-05-22 22:07:59 +00006705< To split a string in individual characters: >
Bram Moolenaar402d2fe2005-04-15 21:00:38 +00006706 :for c in split(mystring, '\zs')
Bram Moolenaar12969c02015-09-08 23:36:10 +02006707< If you want to keep the separator you can also use '\zs' at
6708 the end of the pattern: >
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00006709 :echo split('abc:def:ghi', ':\zs')
6710< ['abc:', 'def:', 'ghi'] ~
Bram Moolenaar2389c3c2005-05-22 22:07:59 +00006711 Splitting a table where the first element can be empty: >
6712 :let items = split(line, ':', 1)
6713< The opposite function is |join()|.
Bram Moolenaara14de3d2005-01-07 21:48:26 +00006714
6715
Bram Moolenaar446cb832008-06-24 21:56:24 +00006716sqrt({expr}) *sqrt()*
6717 Return the non-negative square root of Float {expr} as a
6718 |Float|.
6719 {expr} must evaluate to a |Float| or a |Number|. When {expr}
6720 is negative the result is NaN (Not a Number).
6721 Examples: >
6722 :echo sqrt(100)
6723< 10.0 >
6724 :echo sqrt(-4.01)
6725< nan
Bram Moolenaarc236c162008-07-13 17:41:49 +00006726 "nan" may be different, it depends on system libraries.
Bram Moolenaar446cb832008-06-24 21:56:24 +00006727 {only available when compiled with the |+float| feature}
6728
6729
Bram Moolenaar81edd172016-04-14 13:51:37 +02006730str2float({expr}) *str2float()*
Bram Moolenaar446cb832008-06-24 21:56:24 +00006731 Convert String {expr} to a Float. This mostly works the same
6732 as when using a floating point number in an expression, see
6733 |floating-point-format|. But it's a bit more permissive.
6734 E.g., "1e40" is accepted, while in an expression you need to
6735 write "1.0e40".
6736 Text after the number is silently ignored.
6737 The decimal point is always '.', no matter what the locale is
6738 set to. A comma ends the number: "12,345.67" is converted to
6739 12.0. You can strip out thousands separators with
6740 |substitute()|: >
6741 let f = str2float(substitute(text, ',', '', 'g'))
6742< {only available when compiled with the |+float| feature}
6743
6744
Bram Moolenaar81edd172016-04-14 13:51:37 +02006745str2nr({expr} [, {base}]) *str2nr()*
Bram Moolenaar97b2ad32006-03-18 21:40:56 +00006746 Convert string {expr} to a number.
Bram Moolenaarfa735342016-01-03 22:14:44 +01006747 {base} is the conversion base, it can be 2, 8, 10 or 16.
Bram Moolenaar97b2ad32006-03-18 21:40:56 +00006748 When {base} is omitted base 10 is used. This also means that
6749 a leading zero doesn't cause octal conversion to be used, as
6750 with the default String to Number conversion.
6751 When {base} is 16 a leading "0x" or "0X" is ignored. With a
Bram Moolenaarfa735342016-01-03 22:14:44 +01006752 different base the result will be zero. Similarly, when
6753 {base} is 8 a leading "0" is ignored, and when {base} is 2 a
6754 leading "0b" or "0B" is ignored.
Bram Moolenaar97b2ad32006-03-18 21:40:56 +00006755 Text after the number is silently ignored.
Bram Moolenaarc9b4b052006-04-30 18:54:39 +00006756
Bram Moolenaar97b2ad32006-03-18 21:40:56 +00006757
Bram Moolenaar979243b2015-06-26 19:35:49 +02006758strchars({expr} [, {skipcc}]) *strchars()*
Bram Moolenaar72597a52010-07-18 15:31:08 +02006759 The result is a Number, which is the number of characters
Bram Moolenaar979243b2015-06-26 19:35:49 +02006760 in String {expr}.
6761 When {skipcc} is omitted or zero, composing characters are
6762 counted separately.
6763 When {skipcc} set to 1, Composing characters are ignored.
Bram Moolenaardc536092010-07-18 15:45:49 +02006764 Also see |strlen()|, |strdisplaywidth()| and |strwidth()|.
Bram Moolenaar86ae7202015-07-10 19:31:35 +02006765
6766 {skipcc} is only available after 7.4.755. For backward
6767 compatibility, you can define a wrapper function: >
6768 if has("patch-7.4.755")
6769 function s:strchars(str, skipcc)
6770 return strchars(a:str, a:skipcc)
6771 endfunction
6772 else
6773 function s:strchars(str, skipcc)
6774 if a:skipcc
6775 return strlen(substitute(a:str, ".", "x", "g"))
6776 else
6777 return strchars(a:str)
6778 endif
6779 endfunction
6780 endif
6781<
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02006782strcharpart({src}, {start}[, {len}]) *strcharpart()*
6783 Like |strpart()| but using character index and length instead
6784 of byte index and length.
6785 When a character index is used where a character does not
6786 exist it is assumed to be one byte. For example: >
6787 strcharpart('abc', -1, 2)
6788< results in 'a'.
Bram Moolenaar86ae7202015-07-10 19:31:35 +02006789
Bram Moolenaardc536092010-07-18 15:45:49 +02006790strdisplaywidth({expr}[, {col}]) *strdisplaywidth()*
6791 The result is a Number, which is the number of display cells
Bram Moolenaar979243b2015-06-26 19:35:49 +02006792 String {expr} occupies on the screen when it starts at {col}.
Bram Moolenaardc536092010-07-18 15:45:49 +02006793 When {col} is omitted zero is used. Otherwise it is the
6794 screen column where to start. This matters for Tab
6795 characters.
Bram Moolenaar4d32c2d2010-07-18 22:10:01 +02006796 The option settings of the current window are used. This
6797 matters for anything that's displayed differently, such as
6798 'tabstop' and 'display'.
Bram Moolenaardc536092010-07-18 15:45:49 +02006799 When {expr} contains characters with East Asian Width Class
6800 Ambiguous, this function's return value depends on 'ambiwidth'.
6801 Also see |strlen()|, |strwidth()| and |strchars()|.
Bram Moolenaar72597a52010-07-18 15:31:08 +02006802
Bram Moolenaar071d4272004-06-13 20:20:40 +00006803strftime({format} [, {time}]) *strftime()*
6804 The result is a String, which is a formatted date and time, as
6805 specified by the {format} string. The given {time} is used,
6806 or the current time if no time is given. The accepted
6807 {format} depends on your system, thus this is not portable!
6808 See the manual page of the C function strftime() for the
6809 format. The maximum length of the result is 80 characters.
6810 See also |localtime()| and |getftime()|.
6811 The language can be changed with the |:language| command.
6812 Examples: >
6813 :echo strftime("%c") Sun Apr 27 11:49:23 1997
6814 :echo strftime("%Y %b %d %X") 1997 Apr 27 11:53:25
6815 :echo strftime("%y%m%d %T") 970427 11:53:55
6816 :echo strftime("%H:%M") 11:55
6817 :echo strftime("%c", getftime("file.c"))
6818 Show mod time of file.c.
Bram Moolenaara14de3d2005-01-07 21:48:26 +00006819< Not available on all systems. To check use: >
6820 :if exists("*strftime")
6821
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02006822strgetchar({str}, {index}) *strgetchar()*
6823 Get character {index} from {str}. This uses a character
6824 index, not a byte index. Composing characters are considered
6825 separate characters here.
6826 Also see |strcharpart()| and |strchars()|.
6827
Bram Moolenaar8f999f12005-01-25 22:12:55 +00006828stridx({haystack}, {needle} [, {start}]) *stridx()*
6829 The result is a Number, which gives the byte index in
6830 {haystack} of the first occurrence of the String {needle}.
Bram Moolenaar677ee682005-01-27 14:41:15 +00006831 If {start} is specified, the search starts at index {start}.
6832 This can be used to find a second match: >
Bram Moolenaar81af9252010-12-10 20:35:50 +01006833 :let colon1 = stridx(line, ":")
6834 :let colon2 = stridx(line, ":", colon1 + 1)
Bram Moolenaar677ee682005-01-27 14:41:15 +00006835< The search is done case-sensitive.
Bram Moolenaare2cc9702005-03-15 22:43:58 +00006836 For pattern searches use |match()|.
Bram Moolenaar8f999f12005-01-25 22:12:55 +00006837 -1 is returned if the {needle} does not occur in {haystack}.
Bram Moolenaar677ee682005-01-27 14:41:15 +00006838 See also |strridx()|.
6839 Examples: >
Bram Moolenaar071d4272004-06-13 20:20:40 +00006840 :echo stridx("An Example", "Example") 3
6841 :echo stridx("Starting point", "Start") 0
6842 :echo stridx("Starting point", "start") -1
Bram Moolenaarc9b4b052006-04-30 18:54:39 +00006843< *strstr()* *strchr()*
Bram Moolenaar05159a02005-02-26 23:04:13 +00006844 stridx() works similar to the C function strstr(). When used
6845 with a single character it works similar to strchr().
6846
Bram Moolenaard7ee7ce2005-01-03 21:02:03 +00006847 *string()*
Bram Moolenaar5f2bb9f2005-01-11 21:29:04 +00006848string({expr}) Return {expr} converted to a String. If {expr} is a Number,
Bram Moolenaar446cb832008-06-24 21:56:24 +00006849 Float, String or a composition of them, then the result can be
6850 parsed back with |eval()|.
Bram Moolenaard7ee7ce2005-01-03 21:02:03 +00006851 {expr} type result ~
Bram Moolenaar4f3f6682016-03-26 23:01:59 +01006852 String 'string' (single quotes are doubled)
Bram Moolenaar5f2bb9f2005-01-11 21:29:04 +00006853 Number 123
Bram Moolenaar446cb832008-06-24 21:56:24 +00006854 Float 123.123456 or 1.123456e8
Bram Moolenaard8b02732005-01-14 21:48:43 +00006855 Funcref function('name')
Bram Moolenaar5f2bb9f2005-01-11 21:29:04 +00006856 List [item, item]
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00006857 Dictionary {key: value, key: value}
Bram Moolenaar4f3f6682016-03-26 23:01:59 +01006858
6859 When a List or Dictionary has a recursive reference it is
6860 replaced by "[...]" or "{...}". Using eval() on the result
6861 will then fail.
6862
Bram Moolenaaref2f6562007-05-06 13:32:59 +00006863 Also see |strtrans()|.
Bram Moolenaard7ee7ce2005-01-03 21:02:03 +00006864
Bram Moolenaar071d4272004-06-13 20:20:40 +00006865 *strlen()*
6866strlen({expr}) The result is a Number, which is the length of the String
Bram Moolenaare344bea2005-09-01 20:46:49 +00006867 {expr} in bytes.
Bram Moolenaard7ee7ce2005-01-03 21:02:03 +00006868 If the argument is a Number it is first converted to a String.
6869 For other types an error is given.
Bram Moolenaar641e48c2015-06-25 16:09:26 +02006870 If you want to count the number of multi-byte characters use
6871 |strchars()|.
6872 Also see |len()|, |strdisplaywidth()| and |strwidth()|.
Bram Moolenaar071d4272004-06-13 20:20:40 +00006873
6874strpart({src}, {start}[, {len}]) *strpart()*
6875 The result is a String, which is part of {src}, starting from
Bram Moolenaar9372a112005-12-06 19:59:18 +00006876 byte {start}, with the byte length {len}.
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02006877 To count characters instead of bytes use |strcharpart()|.
6878
6879 When bytes are selected which do not exist, this doesn't
6880 result in an error, the bytes are simply omitted.
Bram Moolenaar071d4272004-06-13 20:20:40 +00006881 If {len} is missing, the copy continues from {start} till the
6882 end of the {src}. >
6883 strpart("abcdefg", 3, 2) == "de"
6884 strpart("abcdefg", -2, 4) == "ab"
6885 strpart("abcdefg", 5, 4) == "fg"
Bram Moolenaar446cb832008-06-24 21:56:24 +00006886 strpart("abcdefg", 3) == "defg"
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02006887
Bram Moolenaar071d4272004-06-13 20:20:40 +00006888< Note: To get the first character, {start} must be 0. For
6889 example, to get three bytes under and after the cursor: >
Bram Moolenaar61660ea2006-04-07 21:40:07 +00006890 strpart(getline("."), col(".") - 1, 3)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006891<
Bram Moolenaar677ee682005-01-27 14:41:15 +00006892strridx({haystack}, {needle} [, {start}]) *strridx()*
6893 The result is a Number, which gives the byte index in
6894 {haystack} of the last occurrence of the String {needle}.
6895 When {start} is specified, matches beyond this index are
6896 ignored. This can be used to find a match before a previous
6897 match: >
6898 :let lastcomma = strridx(line, ",")
6899 :let comma2 = strridx(line, ",", lastcomma - 1)
6900< The search is done case-sensitive.
Bram Moolenaar8f999f12005-01-25 22:12:55 +00006901 For pattern searches use |match()|.
6902 -1 is returned if the {needle} does not occur in {haystack}.
Bram Moolenaard4755bb2004-09-02 19:12:26 +00006903 If the {needle} is empty the length of {haystack} is returned.
Bram Moolenaar402d2fe2005-04-15 21:00:38 +00006904 See also |stridx()|. Examples: >
Bram Moolenaar071d4272004-06-13 20:20:40 +00006905 :echo strridx("an angry armadillo", "an") 3
Bram Moolenaarc9b4b052006-04-30 18:54:39 +00006906< *strrchr()*
Bram Moolenaar05159a02005-02-26 23:04:13 +00006907 When used with a single character it works similar to the C
6908 function strrchr().
6909
Bram Moolenaar071d4272004-06-13 20:20:40 +00006910strtrans({expr}) *strtrans()*
6911 The result is a String, which is {expr} with all unprintable
6912 characters translated into printable characters |'isprint'|.
6913 Like they are shown in a window. Example: >
6914 echo strtrans(@a)
6915< This displays a newline in register a as "^@" instead of
6916 starting a new line.
6917
Bram Moolenaar72597a52010-07-18 15:31:08 +02006918strwidth({expr}) *strwidth()*
6919 The result is a Number, which is the number of display cells
6920 String {expr} occupies. A Tab character is counted as one
Bram Moolenaardc536092010-07-18 15:45:49 +02006921 cell, alternatively use |strdisplaywidth()|.
Bram Moolenaar72597a52010-07-18 15:31:08 +02006922 When {expr} contains characters with East Asian Width Class
6923 Ambiguous, this function's return value depends on 'ambiwidth'.
Bram Moolenaardc536092010-07-18 15:45:49 +02006924 Also see |strlen()|, |strdisplaywidth()| and |strchars()|.
Bram Moolenaar72597a52010-07-18 15:31:08 +02006925
Bram Moolenaar41571762014-04-02 19:00:58 +02006926submatch({nr}[, {list}]) *submatch()*
Bram Moolenaar251e1912011-06-19 05:09:16 +02006927 Only for an expression in a |:substitute| command or
6928 substitute() function.
6929 Returns the {nr}'th submatch of the matched text. When {nr}
6930 is 0 the whole matched text is returned.
Bram Moolenaar41571762014-04-02 19:00:58 +02006931 Note that a NL in the string can stand for a line break of a
6932 multi-line match or a NUL character in the text.
Bram Moolenaar251e1912011-06-19 05:09:16 +02006933 Also see |sub-replace-expression|.
Bram Moolenaar41571762014-04-02 19:00:58 +02006934
6935 If {list} is present and non-zero then submatch() returns
6936 a list of strings, similar to |getline()| with two arguments.
6937 NL characters in the text represent NUL characters in the
6938 text.
6939 Only returns more than one item for |:substitute|, inside
6940 |substitute()| this list will always contain one or zero
6941 items, since there are no real line breaks.
6942
Bram Moolenaar071d4272004-06-13 20:20:40 +00006943 Example: >
6944 :s/\d\+/\=submatch(0) + 1/
6945< This finds the first number in the line and adds one to it.
6946 A line break is included as a newline character.
6947
6948substitute({expr}, {pat}, {sub}, {flags}) *substitute()*
6949 The result is a String, which is a copy of {expr}, in which
Bram Moolenaar251e1912011-06-19 05:09:16 +02006950 the first match of {pat} is replaced with {sub}.
6951 When {flags} is "g", all matches of {pat} in {expr} are
6952 replaced. Otherwise {flags} should be "".
6953
6954 This works like the ":substitute" command (without any flags).
6955 But the matching with {pat} is always done like the 'magic'
6956 option is set and 'cpoptions' is empty (to make scripts
Bram Moolenaar2df58b42012-11-28 18:21:11 +01006957 portable). 'ignorecase' is still relevant, use |/\c| or |/\C|
6958 if you want to ignore or match case and ignore 'ignorecase'.
6959 'smartcase' is not used. See |string-match| for how {pat} is
6960 used.
Bram Moolenaar251e1912011-06-19 05:09:16 +02006961
6962 A "~" in {sub} is not replaced with the previous {sub}.
Bram Moolenaar071d4272004-06-13 20:20:40 +00006963 Note that some codes in {sub} have a special meaning
Bram Moolenaar446cb832008-06-24 21:56:24 +00006964 |sub-replace-special|. For example, to replace something with
Bram Moolenaar071d4272004-06-13 20:20:40 +00006965 "\n" (two characters), use "\\\\n" or '\\n'.
Bram Moolenaar251e1912011-06-19 05:09:16 +02006966
Bram Moolenaar071d4272004-06-13 20:20:40 +00006967 When {pat} does not match in {expr}, {expr} is returned
6968 unmodified.
Bram Moolenaar251e1912011-06-19 05:09:16 +02006969
Bram Moolenaar071d4272004-06-13 20:20:40 +00006970 Example: >
6971 :let &path = substitute(&path, ",\\=[^,]*$", "", "")
6972< This removes the last component of the 'path' option. >
6973 :echo substitute("testing", ".*", "\\U\\0", "")
6974< results in "TESTING".
Bram Moolenaar251e1912011-06-19 05:09:16 +02006975
6976 When {sub} starts with "\=", the remainder is interpreted as
6977 an expression. See |sub-replace-expression|. Example: >
Bram Moolenaar20f90cf2011-05-19 12:22:51 +02006978 :echo substitute(s, '%\(\x\x\)',
6979 \ '\=nr2char("0x" . submatch(1))', 'g')
Bram Moolenaar071d4272004-06-13 20:20:40 +00006980
Bram Moolenaar47136d72004-10-12 20:02:24 +00006981synID({lnum}, {col}, {trans}) *synID()*
Bram Moolenaar071d4272004-06-13 20:20:40 +00006982 The result is a Number, which is the syntax ID at the position
Bram Moolenaar47136d72004-10-12 20:02:24 +00006983 {lnum} and {col} in the current window.
Bram Moolenaar071d4272004-06-13 20:20:40 +00006984 The syntax ID can be used with |synIDattr()| and
6985 |synIDtrans()| to obtain syntax information about text.
Bram Moolenaarce0842a2005-07-18 21:58:11 +00006986
Bram Moolenaar47136d72004-10-12 20:02:24 +00006987 {col} is 1 for the leftmost column, {lnum} is 1 for the first
Bram Moolenaarce0842a2005-07-18 21:58:11 +00006988 line. 'synmaxcol' applies, in a longer line zero is returned.
Bram Moolenaarca635012015-09-25 20:34:21 +02006989 Note that when the position is after the last character,
6990 that's where the cursor can be in Insert mode, synID() returns
6991 zero.
Bram Moolenaarce0842a2005-07-18 21:58:11 +00006992
Bram Moolenaar071d4272004-06-13 20:20:40 +00006993 When {trans} is non-zero, transparent items are reduced to the
Bram Moolenaar446cb832008-06-24 21:56:24 +00006994 item that they reveal. This is useful when wanting to know
Bram Moolenaar071d4272004-06-13 20:20:40 +00006995 the effective color. When {trans} is zero, the transparent
6996 item is returned. This is useful when wanting to know which
6997 syntax item is effective (e.g. inside parens).
6998 Warning: This function can be very slow. Best speed is
6999 obtained by going through the file in forward direction.
7000
7001 Example (echoes the name of the syntax item under the cursor): >
7002 :echo synIDattr(synID(line("."), col("."), 1), "name")
7003<
Bram Moolenaar7510fe72010-07-25 12:46:44 +02007004
Bram Moolenaar071d4272004-06-13 20:20:40 +00007005synIDattr({synID}, {what} [, {mode}]) *synIDattr()*
7006 The result is a String, which is the {what} attribute of
7007 syntax ID {synID}. This can be used to obtain information
7008 about a syntax item.
7009 {mode} can be "gui", "cterm" or "term", to get the attributes
Bram Moolenaar446cb832008-06-24 21:56:24 +00007010 for that mode. When {mode} is omitted, or an invalid value is
Bram Moolenaar071d4272004-06-13 20:20:40 +00007011 used, the attributes for the currently active highlighting are
7012 used (GUI, cterm or term).
7013 Use synIDtrans() to follow linked highlight groups.
7014 {what} result
7015 "name" the name of the syntax item
7016 "fg" foreground color (GUI: color name used to set
7017 the color, cterm: color number as a string,
7018 term: empty string)
Bram Moolenaar6f507d62008-11-28 10:16:05 +00007019 "bg" background color (as with "fg")
Bram Moolenaar12682fd2010-03-10 13:43:49 +01007020 "font" font name (only available in the GUI)
7021 |highlight-font|
Bram Moolenaar6f507d62008-11-28 10:16:05 +00007022 "sp" special color (as with "fg") |highlight-guisp|
Bram Moolenaar071d4272004-06-13 20:20:40 +00007023 "fg#" like "fg", but for the GUI and the GUI is
7024 running the name in "#RRGGBB" form
7025 "bg#" like "fg#" for "bg"
Bram Moolenaar6f507d62008-11-28 10:16:05 +00007026 "sp#" like "fg#" for "sp"
Bram Moolenaar071d4272004-06-13 20:20:40 +00007027 "bold" "1" if bold
7028 "italic" "1" if italic
7029 "reverse" "1" if reverse
7030 "inverse" "1" if inverse (= reverse)
Bram Moolenaar12682fd2010-03-10 13:43:49 +01007031 "standout" "1" if standout
Bram Moolenaar071d4272004-06-13 20:20:40 +00007032 "underline" "1" if underlined
Bram Moolenaare2cc9702005-03-15 22:43:58 +00007033 "undercurl" "1" if undercurled
Bram Moolenaar071d4272004-06-13 20:20:40 +00007034
7035 Example (echoes the color of the syntax item under the
7036 cursor): >
7037 :echo synIDattr(synIDtrans(synID(line("."), col("."), 1)), "fg")
7038<
7039synIDtrans({synID}) *synIDtrans()*
7040 The result is a Number, which is the translated syntax ID of
7041 {synID}. This is the syntax group ID of what is being used to
7042 highlight the character. Highlight links given with
7043 ":highlight link" are followed.
7044
Bram Moolenaar483c5d82010-10-20 18:45:33 +02007045synconcealed({lnum}, {col}) *synconcealed()*
7046 The result is a List. The first item in the list is 0 if the
7047 character at the position {lnum} and {col} is not part of a
7048 concealable region, 1 if it is. The second item in the list is
7049 a string. If the first item is 1, the second item contains the
7050 text which will be displayed in place of the concealed text,
7051 depending on the current setting of 'conceallevel'. The third
7052 and final item in the list is a unique number representing the
7053 specific syntax region matched. This allows detection of the
7054 beginning of a new concealable region if there are two
7055 consecutive regions with the same replacement character.
7056 For an example use see $VIMRUNTIME/syntax/2html.vim .
7057
7058
Bram Moolenaar9d188ab2008-01-10 21:24:39 +00007059synstack({lnum}, {col}) *synstack()*
7060 Return a |List|, which is the stack of syntax items at the
7061 position {lnum} and {col} in the current window. Each item in
7062 the List is an ID like what |synID()| returns.
Bram Moolenaar9d188ab2008-01-10 21:24:39 +00007063 The first item in the List is the outer region, following are
7064 items contained in that one. The last one is what |synID()|
7065 returns, unless not the whole item is highlighted or it is a
7066 transparent item.
7067 This function is useful for debugging a syntax file.
7068 Example that shows the syntax stack under the cursor: >
7069 for id in synstack(line("."), col("."))
7070 echo synIDattr(id, "name")
7071 endfor
Bram Moolenaar0bc380a2010-07-10 13:52:13 +02007072< When the position specified with {lnum} and {col} is invalid
7073 nothing is returned. The position just after the last
7074 character in a line and the first column in an empty line are
7075 valid positions.
Bram Moolenaar9d188ab2008-01-10 21:24:39 +00007076
Bram Moolenaarc0197e22004-09-13 20:26:32 +00007077system({expr} [, {input}]) *system()* *E677*
Bram Moolenaar39c29ed2014-04-05 19:44:40 +02007078 Get the output of the shell command {expr} as a string. See
7079 |systemlist()| to get the output as a List.
Bram Moolenaar57ebe6e2014-04-05 18:55:46 +02007080
7081 When {input} is given and is a string this string is written
7082 to a file and passed as stdin to the command. The string is
7083 written as-is, you need to take care of using the correct line
7084 separators yourself.
7085 If {input} is given and is a |List| it is written to the file
7086 in a way |writefile()| does with {binary} set to "b" (i.e.
7087 with a newline between each list item with newlines inside
7088 list items converted to NULs).
7089 Pipes are not used.
7090
Bram Moolenaar52a72462014-08-29 15:53:52 +02007091 When prepended by |:silent| the shell will not be set to
7092 cooked mode. This is meant to be used for commands that do
7093 not need the user to type. It avoids stray characters showing
7094 up on the screen which require |CTRL-L| to remove. >
7095 :silent let f = system('ls *.vim')
7096<
Bram Moolenaar26df0922014-02-23 23:39:13 +01007097 Note: Use |shellescape()| or |::S| with |expand()| or
7098 |fnamemodify()| to escape special characters in a command
7099 argument. Newlines in {expr} may cause the command to fail.
7100 The characters in 'shellquote' and 'shellxquote' may also
7101 cause trouble.
Bram Moolenaar071d4272004-06-13 20:20:40 +00007102 This is not to be used for interactive commands.
Bram Moolenaar071d4272004-06-13 20:20:40 +00007103
Bram Moolenaar05bb9532008-07-04 09:44:11 +00007104 The result is a String. Example: >
7105 :let files = system("ls " . shellescape(expand('%:h')))
Bram Moolenaar26df0922014-02-23 23:39:13 +01007106 :let files = system('ls ' . expand('%:h:S'))
Bram Moolenaar071d4272004-06-13 20:20:40 +00007107
7108< To make the result more system-independent, the shell output
7109 is filtered to replace <CR> with <NL> for Macintosh, and
7110 <CR><NL> with <NL> for DOS-like systems.
Bram Moolenaar9d98fe92013-08-03 18:35:36 +02007111 To avoid the string being truncated at a NUL, all NUL
7112 characters are replaced with SOH (0x01).
7113
Bram Moolenaar071d4272004-06-13 20:20:40 +00007114 The command executed is constructed using several options:
7115 'shell' 'shellcmdflag' 'shellxquote' {expr} 'shellredir' {tmp} 'shellxquote'
7116 ({tmp} is an automatically generated file name).
7117 For Unix and OS/2 braces are put around {expr} to allow for
7118 concatenated commands.
7119
Bram Moolenaar433f7c82006-03-21 21:29:36 +00007120 The command will be executed in "cooked" mode, so that a
7121 CTRL-C will interrupt the command (on Unix at least).
7122
Bram Moolenaar071d4272004-06-13 20:20:40 +00007123 The resulting error code can be found in |v:shell_error|.
7124 This function will fail in |restricted-mode|.
Bram Moolenaar4770d092006-01-12 23:22:24 +00007125
7126 Note that any wrong value in the options mentioned above may
7127 make the function fail. It has also been reported to fail
7128 when using a security agent application.
Bram Moolenaar071d4272004-06-13 20:20:40 +00007129 Unlike ":!cmd" there is no automatic check for changed files.
7130 Use |:checktime| to force a check.
7131
Bram Moolenaare2cc9702005-03-15 22:43:58 +00007132
Bram Moolenaar39c29ed2014-04-05 19:44:40 +02007133systemlist({expr} [, {input}]) *systemlist()*
7134 Same as |system()|, but returns a |List| with lines (parts of
7135 output separated by NL) with NULs transformed into NLs. Output
7136 is the same as |readfile()| will output with {binary} argument
7137 set to "b".
7138
Bram Moolenaar975b5272016-03-15 23:10:59 +01007139 Returns an empty string on error.
Bram Moolenaar39c29ed2014-04-05 19:44:40 +02007140
7141
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00007142tabpagebuflist([{arg}]) *tabpagebuflist()*
Bram Moolenaar32466aa2006-02-24 23:53:04 +00007143 The result is a |List|, where each item is the number of the
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00007144 buffer associated with each window in the current tab page.
7145 {arg} specifies the number of tab page to be used. When
7146 omitted the current tab page is used.
7147 When {arg} is invalid the number zero is returned.
7148 To get a list of all buffers in all tabs use this: >
Bram Moolenaar61d35bd2012-03-28 20:51:51 +02007149 let buflist = []
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00007150 for i in range(tabpagenr('$'))
Bram Moolenaar61d35bd2012-03-28 20:51:51 +02007151 call extend(buflist, tabpagebuflist(i + 1))
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00007152 endfor
7153< Note that a buffer may appear in more than one window.
7154
7155
7156tabpagenr([{arg}]) *tabpagenr()*
Bram Moolenaar7e8fd632006-02-18 22:14:51 +00007157 The result is a Number, which is the number of the current
7158 tab page. The first tab page has number 1.
7159 When the optional argument is "$", the number of the last tab
7160 page is returned (the tab page count).
7161 The number can be used with the |:tab| command.
7162
7163
Bram Moolenaar76f3b1a2014-03-27 22:30:07 +01007164tabpagewinnr({tabarg} [, {arg}]) *tabpagewinnr()*
Bram Moolenaard04f4402010-08-15 13:30:34 +02007165 Like |winnr()| but for tab page {tabarg}.
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00007166 {tabarg} specifies the number of tab page to be used.
7167 {arg} is used like with |winnr()|:
7168 - When omitted the current window number is returned. This is
7169 the window which will be used when going to this tab page.
7170 - When "$" the number of windows is returned.
7171 - When "#" the previous window nr is returned.
7172 Useful examples: >
7173 tabpagewinnr(1) " current window of tab page 1
7174 tabpagewinnr(4, '$') " number of windows in tab page 4
7175< When {tabarg} is invalid zero is returned.
7176
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00007177 *tagfiles()*
7178tagfiles() Returns a |List| with the file names used to search for tags
7179 for the current buffer. This is the 'tags' option expanded.
7180
7181
Bram Moolenaare2cc9702005-03-15 22:43:58 +00007182taglist({expr}) *taglist()*
7183 Returns a list of tags matching the regular expression {expr}.
Bram Moolenaard8c00872005-07-22 21:52:15 +00007184 Each list item is a dictionary with at least the following
7185 entries:
Bram Moolenaar280f1262006-01-30 00:14:18 +00007186 name Name of the tag.
7187 filename Name of the file where the tag is
Bram Moolenaaref2f6562007-05-06 13:32:59 +00007188 defined. It is either relative to the
7189 current directory or a full path.
Bram Moolenaare2cc9702005-03-15 22:43:58 +00007190 cmd Ex command used to locate the tag in
7191 the file.
Bram Moolenaar280f1262006-01-30 00:14:18 +00007192 kind Type of the tag. The value for this
Bram Moolenaare2cc9702005-03-15 22:43:58 +00007193 entry depends on the language specific
Bram Moolenaaref2f6562007-05-06 13:32:59 +00007194 kind values. Only available when
7195 using a tags file generated by
7196 Exuberant ctags or hdrtag.
Bram Moolenaar280f1262006-01-30 00:14:18 +00007197 static A file specific tag. Refer to
Bram Moolenaare2cc9702005-03-15 22:43:58 +00007198 |static-tag| for more information.
Bram Moolenaaref2f6562007-05-06 13:32:59 +00007199 More entries may be present, depending on the content of the
7200 tags file: access, implementation, inherits and signature.
7201 Refer to the ctags documentation for information about these
7202 fields. For C code the fields "struct", "class" and "enum"
7203 may appear, they give the name of the entity the tag is
7204 contained in.
Bram Moolenaar5a8684e2005-07-30 22:43:24 +00007205
Bram Moolenaar4317d9b2005-03-18 20:25:31 +00007206 The ex-command 'cmd' can be either an ex search pattern, a
7207 line number or a line number followed by a byte number.
Bram Moolenaare2cc9702005-03-15 22:43:58 +00007208
7209 If there are no matching tags, then an empty list is returned.
7210
7211 To get an exact tag match, the anchors '^' and '$' should be
Bram Moolenaara3e6bc92013-01-30 14:18:00 +01007212 used in {expr}. This also make the function work faster.
7213 Refer to |tag-regexp| for more information about the tag
7214 search regular expression pattern.
Bram Moolenaare2cc9702005-03-15 22:43:58 +00007215
7216 Refer to |'tags'| for information about how the tags file is
7217 located by Vim. Refer to |tags-file-format| for the format of
7218 the tags file generated by the different ctags tools.
7219
Bram Moolenaardb7c6862010-05-21 16:33:48 +02007220tan({expr}) *tan()*
Bram Moolenaar9855d6b2010-07-18 14:34:51 +02007221 Return the tangent of {expr}, measured in radians, as a |Float|
Bram Moolenaardb7c6862010-05-21 16:33:48 +02007222 in the range [-inf, inf].
Bram Moolenaar9855d6b2010-07-18 14:34:51 +02007223 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaardb7c6862010-05-21 16:33:48 +02007224 Examples: >
7225 :echo tan(10)
7226< 0.648361 >
7227 :echo tan(-4.01)
7228< -1.181502
Bram Moolenaardb84e452010-08-15 13:50:43 +02007229 {only available when compiled with the |+float| feature}
Bram Moolenaardb7c6862010-05-21 16:33:48 +02007230
7231
7232tanh({expr}) *tanh()*
Bram Moolenaar9855d6b2010-07-18 14:34:51 +02007233 Return the hyperbolic tangent of {expr} as a |Float| in the
Bram Moolenaardb7c6862010-05-21 16:33:48 +02007234 range [-1, 1].
Bram Moolenaar9855d6b2010-07-18 14:34:51 +02007235 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaardb7c6862010-05-21 16:33:48 +02007236 Examples: >
7237 :echo tanh(0.5)
7238< 0.462117 >
7239 :echo tanh(-1)
7240< -0.761594
Bram Moolenaardb84e452010-08-15 13:50:43 +02007241 {only available when compiled with the |+float| feature}
Bram Moolenaardb7c6862010-05-21 16:33:48 +02007242
7243
Bram Moolenaar574860b2016-05-24 17:33:34 +02007244tempname() *tempname()* *temp-file-name*
7245 The result is a String, which is the name of a file that
7246 doesn't exist. It can be used for a temporary file. The name
7247 is different for at least 26 consecutive calls. Example: >
7248 :let tmpfile = tempname()
7249 :exe "redir > " . tmpfile
7250< For Unix, the file will be in a private directory |tempfile|.
7251 For MS-Windows forward slashes are used when the 'shellslash'
7252 option is set or when 'shellcmdflag' starts with '-'.
7253
7254
Bram Moolenaar8e8df252016-05-25 21:23:21 +02007255test_alloc_fail({id}, {countdown}, {repeat}) *test_alloc_fail()*
7256 This is for testing: If the memory allocation with {id} is
7257 called, then decrement {countdown}, and when it reaches zero
7258 let memory allocation fail {repeat} times. When {repeat} is
7259 smaller than one it fails one time.
7260
7261
7262 *test_disable_char_avail()*
7263test_disable_char_avail({expr})
7264 When {expr} is 1 the internal char_avail() function will
7265 return FALSE. When {expr} is 0 the char_avail() function will
7266 function normally.
7267 Only use this for a test where typeahead causes the test not
7268 to work. E.g., to trigger the CursorMovedI autocommand event.
7269
Bram Moolenaar574860b2016-05-24 17:33:34 +02007270test_garbagecollect_now() *test_garbagecollect_now()*
7271 Like garbagecollect(), but executed right away. This must
7272 only be called directly to avoid any structure to exist
7273 internally, and |v:testing| must have been set before calling
7274 any function.
7275
7276test_null_channel() *test_null_channel()*
7277 Return a Channel that is null. Only useful for testing.
7278 {only available when compiled with the +channel feature}
7279
7280test_null_dict() *test_null_dict()*
7281 Return a Dict that is null. Only useful for testing.
7282
7283test_null_job() *test_null_job()*
7284 Return a Job that is null. Only useful for testing.
7285 {only available when compiled with the +job feature}
7286
7287test_null_list() *test_null_list()*
7288 Return a List that is null. Only useful for testing.
7289
7290test_null_partial() *test_null_partial()*
7291 Return a Partial that is null. Only useful for testing.
7292
7293test_null_string() *test_null_string()*
7294 Return a String that is null. Only useful for testing.
7295
Bram Moolenaarc95a3022016-06-12 23:01:46 +02007296test_settime({expr}) *test_settime()*
7297 Set the time Vim uses internally. Currently only used for
7298 timestamps in the history, as they are used in viminfo.
7299 {expr} must evaluate to a number. When the value is zero the
7300 normal behavior is restored.
Bram Moolenaar574860b2016-05-24 17:33:34 +02007301
Bram Moolenaar975b5272016-03-15 23:10:59 +01007302 *timer_start()*
7303timer_start({time}, {callback} [, {options}])
7304 Create a timer and return the timer ID.
7305
7306 {time} is the waiting time in milliseconds. This is the
7307 minimum time before invoking the callback. When the system is
7308 busy or Vim is not waiting for input the time will be longer.
7309
7310 {callback} is the function to call. It can be the name of a
7311 function or a Funcref. It is called with one argument, which
7312 is the timer ID. The callback is only invoked when Vim is
7313 waiting for input.
7314
7315 {options} is a dictionary. Supported entries:
7316 "repeat" Number of times to repeat calling the
Bram Moolenaar81edd172016-04-14 13:51:37 +02007317 callback. -1 means forever.
Bram Moolenaar975b5272016-03-15 23:10:59 +01007318
7319 Example: >
7320 func MyHandler(timer)
7321 echo 'Handler called'
7322 endfunc
7323 let timer = timer_start(500, 'MyHandler',
7324 \ {'repeat': 3})
7325< This will invoke MyHandler() three times at 500 msec
7326 intervals.
7327 {only available when compiled with the |+timers| feature}
7328
Bram Moolenaar03602ec2016-03-20 20:57:45 +01007329timer_stop({timer}) *timer_stop()*
Bram Moolenaar06d2d382016-05-20 17:24:11 +02007330 Stop a timer. The timer callback will no longer be invoked.
7331 {timer} is an ID returned by timer_start(), thus it must be a
7332 Number.
Bram Moolenaar03602ec2016-03-20 20:57:45 +01007333
Bram Moolenaar071d4272004-06-13 20:20:40 +00007334tolower({expr}) *tolower()*
7335 The result is a copy of the String given, with all uppercase
7336 characters turned into lowercase (just like applying |gu| to
7337 the string).
7338
7339toupper({expr}) *toupper()*
7340 The result is a copy of the String given, with all lowercase
7341 characters turned into uppercase (just like applying |gU| to
7342 the string).
7343
Bram Moolenaar8299df92004-07-10 09:47:34 +00007344tr({src}, {fromstr}, {tostr}) *tr()*
7345 The result is a copy of the {src} string with all characters
7346 which appear in {fromstr} replaced by the character in that
7347 position in the {tostr} string. Thus the first character in
7348 {fromstr} is translated into the first character in {tostr}
7349 and so on. Exactly like the unix "tr" command.
7350 This code also deals with multibyte characters properly.
7351
7352 Examples: >
7353 echo tr("hello there", "ht", "HT")
7354< returns "Hello THere" >
7355 echo tr("<blob>", "<>", "{}")
7356< returns "{blob}"
7357
Bram Moolenaar446cb832008-06-24 21:56:24 +00007358trunc({expr}) *trunc()*
Bram Moolenaarc236c162008-07-13 17:41:49 +00007359 Return the largest integral value with magnitude less than or
Bram Moolenaar446cb832008-06-24 21:56:24 +00007360 equal to {expr} as a |Float| (truncate towards zero).
7361 {expr} must evaluate to a |Float| or a |Number|.
7362 Examples: >
7363 echo trunc(1.456)
7364< 1.0 >
7365 echo trunc(-5.456)
7366< -5.0 >
7367 echo trunc(4.0)
7368< 4.0
7369 {only available when compiled with the |+float| feature}
7370
Bram Moolenaar9588a0f2005-01-08 21:45:39 +00007371 *type()*
7372type({expr}) The result is a Number, depending on the type of {expr}:
Bram Moolenaar748bf032005-02-02 23:04:36 +00007373 Number: 0
7374 String: 1
7375 Funcref: 2
7376 List: 3
7377 Dictionary: 4
Bram Moolenaar446cb832008-06-24 21:56:24 +00007378 Float: 5
Bram Moolenaar705ada12016-01-24 17:56:50 +01007379 Boolean: 6 (v:false and v:true)
7380 None 7 (v:null and v:none)
Bram Moolenaar835dc632016-02-07 14:27:38 +01007381 Job 8
Bram Moolenaar38a55632016-02-15 22:07:32 +01007382 Channel 9
Bram Moolenaar748bf032005-02-02 23:04:36 +00007383 To avoid the magic numbers it should be used this way: >
Bram Moolenaar9588a0f2005-01-08 21:45:39 +00007384 :if type(myvar) == type(0)
7385 :if type(myvar) == type("")
7386 :if type(myvar) == type(function("tr"))
7387 :if type(myvar) == type([])
Bram Moolenaar748bf032005-02-02 23:04:36 +00007388 :if type(myvar) == type({})
Bram Moolenaar446cb832008-06-24 21:56:24 +00007389 :if type(myvar) == type(0.0)
Bram Moolenaar705ada12016-01-24 17:56:50 +01007390 :if type(myvar) == type(v:false)
Bram Moolenaar6463ca22016-02-13 17:04:46 +01007391 :if type(myvar) == type(v:none)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007392
Bram Moolenaara17d4c12010-05-30 18:30:36 +02007393undofile({name}) *undofile()*
7394 Return the name of the undo file that would be used for a file
7395 with name {name} when writing. This uses the 'undodir'
7396 option, finding directories that exist. It does not check if
Bram Moolenaar860cae12010-06-05 23:22:07 +02007397 the undo file exists.
Bram Moolenaar945e2db2010-06-05 17:43:32 +02007398 {name} is always expanded to the full path, since that is what
7399 is used internally.
Bram Moolenaar80716072012-05-01 21:14:34 +02007400 If {name} is empty undofile() returns an empty string, since a
7401 buffer without a file name will not write an undo file.
Bram Moolenaara17d4c12010-05-30 18:30:36 +02007402 Useful in combination with |:wundo| and |:rundo|.
7403 When compiled without the +persistent_undo option this always
7404 returns an empty string.
7405
Bram Moolenaara800b422010-06-27 01:15:55 +02007406undotree() *undotree()*
7407 Return the current state of the undo tree in a dictionary with
7408 the following items:
7409 "seq_last" The highest undo sequence number used.
7410 "seq_cur" The sequence number of the current position in
7411 the undo tree. This differs from "seq_last"
7412 when some changes were undone.
7413 "time_cur" Time last used for |:earlier| and related
7414 commands. Use |strftime()| to convert to
7415 something readable.
7416 "save_last" Number of the last file write. Zero when no
7417 write yet.
Bram Moolenaar730cde92010-06-27 05:18:54 +02007418 "save_cur" Number of the current position in the undo
7419 tree.
Bram Moolenaara800b422010-06-27 01:15:55 +02007420 "synced" Non-zero when the last undo block was synced.
7421 This happens when waiting from input from the
7422 user. See |undo-blocks|.
7423 "entries" A list of dictionaries with information about
7424 undo blocks.
7425
7426 The first item in the "entries" list is the oldest undo item.
7427 Each List item is a Dictionary with these items:
7428 "seq" Undo sequence number. Same as what appears in
7429 |:undolist|.
7430 "time" Timestamp when the change happened. Use
7431 |strftime()| to convert to something readable.
7432 "newhead" Only appears in the item that is the last one
7433 that was added. This marks the last change
7434 and where further changes will be added.
7435 "curhead" Only appears in the item that is the last one
7436 that was undone. This marks the current
7437 position in the undo tree, the block that will
7438 be used by a redo command. When nothing was
7439 undone after the last change this item will
7440 not appear anywhere.
7441 "save" Only appears on the last block before a file
7442 write. The number is the write count. The
7443 first write has number 1, the last one the
7444 "save_last" mentioned above.
7445 "alt" Alternate entry. This is again a List of undo
7446 blocks. Each item may again have an "alt"
7447 item.
7448
Bram Moolenaar327aa022014-03-25 18:24:23 +01007449uniq({list} [, {func} [, {dict}]]) *uniq()* *E882*
7450 Remove second and succeeding copies of repeated adjacent
7451 {list} items in-place. Returns {list}. If you want a list
7452 to remain unmodified make a copy first: >
7453 :let newlist = uniq(copy(mylist))
7454< The default compare function uses the string representation of
7455 each item. For the use of {func} and {dict} see |sort()|.
7456
Bram Moolenaar677ee682005-01-27 14:41:15 +00007457values({dict}) *values()*
Bram Moolenaar446cb832008-06-24 21:56:24 +00007458 Return a |List| with all the values of {dict}. The |List| is
Bram Moolenaar32466aa2006-02-24 23:53:04 +00007459 in arbitrary order.
Bram Moolenaar677ee682005-01-27 14:41:15 +00007460
7461
Bram Moolenaar071d4272004-06-13 20:20:40 +00007462virtcol({expr}) *virtcol()*
7463 The result is a Number, which is the screen column of the file
7464 position given with {expr}. That is, the last screen position
7465 occupied by the character at that position, when the screen
7466 would be of unlimited width. When there is a <Tab> at the
7467 position, the returned Number will be the column at the end of
7468 the <Tab>. For example, for a <Tab> in column 1, with 'ts'
Bram Moolenaar61d35bd2012-03-28 20:51:51 +02007469 set to 8, it returns 8. |conceal| is ignored.
Bram Moolenaar477933c2007-07-17 14:32:23 +00007470 For the byte position use |col()|.
7471 For the use of {expr} see |col()|.
7472 When 'virtualedit' is used {expr} can be [lnum, col, off], where
Bram Moolenaar0b238792006-03-02 22:49:12 +00007473 "off" is the offset in screen columns from the start of the
Bram Moolenaard46bbc72007-05-12 14:38:41 +00007474 character. E.g., a position within a <Tab> or after the last
Bram Moolenaar97293012011-07-18 19:40:27 +02007475 character. When "off" is omitted zero is used.
Bram Moolenaar071d4272004-06-13 20:20:40 +00007476 When Virtual editing is active in the current mode, a position
7477 beyond the end of the line can be returned. |'virtualedit'|
7478 The accepted positions are:
7479 . the cursor position
7480 $ the end of the cursor line (the result is the
7481 number of displayed characters in the cursor line
7482 plus one)
7483 'x position of mark x (if the mark is not set, 0 is
7484 returned)
Bram Moolenaare3faf442014-12-14 01:27:49 +01007485 v In Visual mode: the start of the Visual area (the
7486 cursor is the end). When not in Visual mode
7487 returns the cursor position. Differs from |'<| in
7488 that it's updated right away.
Bram Moolenaar071d4272004-06-13 20:20:40 +00007489 Note that only marks in the current file can be used.
7490 Examples: >
7491 virtcol(".") with text "foo^Lbar", with cursor on the "^L", returns 5
7492 virtcol("$") with text "foo^Lbar", returns 9
Bram Moolenaar446cb832008-06-24 21:56:24 +00007493 virtcol("'t") with text " there", with 't at 'h', returns 6
7494< The first column is 1. 0 is returned for an error.
Bram Moolenaaref2f6562007-05-06 13:32:59 +00007495 A more advanced example that echoes the maximum length of
7496 all lines: >
7497 echo max(map(range(1, line('$')), "virtcol([v:val, '$'])"))
7498
Bram Moolenaar071d4272004-06-13 20:20:40 +00007499
7500visualmode([expr]) *visualmode()*
7501 The result is a String, which describes the last Visual mode
Bram Moolenaarc9b4b052006-04-30 18:54:39 +00007502 used in the current buffer. Initially it returns an empty
7503 string, but once Visual mode has been used, it returns "v",
7504 "V", or "<CTRL-V>" (a single CTRL-V character) for
7505 character-wise, line-wise, or block-wise Visual mode
7506 respectively.
Bram Moolenaar071d4272004-06-13 20:20:40 +00007507 Example: >
7508 :exe "normal " . visualmode()
7509< This enters the same Visual mode as before. It is also useful
7510 in scripts if you wish to act differently depending on the
7511 Visual mode that was used.
Bram Moolenaar446cb832008-06-24 21:56:24 +00007512 If Visual mode is active, use |mode()| to get the Visual mode
7513 (e.g., in a |:vmap|).
Bram Moolenaar05bb9532008-07-04 09:44:11 +00007514 *non-zero-arg*
7515 If [expr] is supplied and it evaluates to a non-zero Number or
7516 a non-empty String, then the Visual mode will be cleared and
Bram Moolenaar446cb832008-06-24 21:56:24 +00007517 the old value is returned. Note that " " and "0" are also
Bram Moolenaar05bb9532008-07-04 09:44:11 +00007518 non-empty strings, thus cause the mode to be cleared. A List,
7519 Dictionary or Float is not a Number or String, thus does not
7520 cause the mode to be cleared.
Bram Moolenaar071d4272004-06-13 20:20:40 +00007521
Bram Moolenaar8738fc12013-02-20 17:59:11 +01007522wildmenumode() *wildmenumode()*
7523 Returns non-zero when the wildmenu is active and zero
7524 otherwise. See 'wildmenu' and 'wildmode'.
7525 This can be used in mappings to handle the 'wildcharm' option
7526 gracefully. (Makes only sense with |mapmode-c| mappings).
7527
7528 For example to make <c-j> work like <down> in wildmode, use: >
7529 :cnoremap <expr> <C-j> wildmenumode() ? "\<Down>\<Tab>" : "\<c-j>"
7530<
7531 (Note, this needs the 'wildcharm' option set appropriately).
7532
7533
Bram Moolenaar9cdf86b2016-03-13 19:04:51 +01007534win_findbuf({bufnr}) *win_findbuf()*
7535 Returns a list with window IDs for windows that contain buffer
7536 {bufnr}. When there is none the list is empty.
7537
Bram Moolenaar86edef62016-03-13 18:07:30 +01007538win_getid([{win} [, {tab}]]) *win_getid()*
7539 Get the window ID for the specified window.
7540 When {win} is missing use the current window.
7541 With {win} this is the window number. The top window has
7542 number 1.
7543 Without {tab} use the current tab, otherwise the tab with
7544 number {tab}. The first tab has number one.
7545 Return zero if the window cannot be found.
7546
7547win_gotoid({expr}) *win_gotoid()*
7548 Go to window with ID {expr}. This may also change the current
7549 tabpage.
7550 Return 1 if successful, 0 if the window cannot be found.
7551
Bram Moolenaar03413f42016-04-12 21:07:15 +02007552win_id2tabwin({expr}) *win_id2tabwin()*
Bram Moolenaar86edef62016-03-13 18:07:30 +01007553 Return a list with the tab number and window number of window
7554 with ID {expr}: [tabnr, winnr].
7555 Return [0, 0] if the window cannot be found.
7556
7557win_id2win({expr}) *win_id2win()*
7558 Return the window number of window with ID {expr}.
7559 Return 0 if the window cannot be found in the current tabpage.
7560
Bram Moolenaar071d4272004-06-13 20:20:40 +00007561 *winbufnr()*
7562winbufnr({nr}) The result is a Number, which is the number of the buffer
Bram Moolenaar888ccac2016-06-04 18:49:36 +02007563 associated with window {nr}. {nr} can be the window number or
7564 the window ID.
7565 When {nr} is zero, the number of the buffer in the current
7566 window is returned.
7567 When window {nr} doesn't exist, -1 is returned.
Bram Moolenaar071d4272004-06-13 20:20:40 +00007568 Example: >
7569 :echo "The file in the current window is " . bufname(winbufnr(0))
7570<
7571 *wincol()*
7572wincol() The result is a Number, which is the virtual column of the
7573 cursor in the window. This is counting screen cells from the
7574 left side of the window. The leftmost column is one.
7575
7576winheight({nr}) *winheight()*
7577 The result is a Number, which is the height of window {nr}.
Bram Moolenaar888ccac2016-06-04 18:49:36 +02007578 {nr} can be the window number or the window ID.
Bram Moolenaar071d4272004-06-13 20:20:40 +00007579 When {nr} is zero, the height of the current window is
7580 returned. When window {nr} doesn't exist, -1 is returned.
7581 An existing window always has a height of zero or more.
7582 Examples: >
7583 :echo "The current window has " . winheight(0) . " lines."
7584<
7585 *winline()*
7586winline() The result is a Number, which is the screen line of the cursor
Bram Moolenaar446cb832008-06-24 21:56:24 +00007587 in the window. This is counting screen lines from the top of
Bram Moolenaar071d4272004-06-13 20:20:40 +00007588 the window. The first line is one.
Bram Moolenaarbfd8fc02005-09-20 23:22:24 +00007589 If the cursor was moved the view on the file will be updated
7590 first, this may cause a scroll.
Bram Moolenaar071d4272004-06-13 20:20:40 +00007591
7592 *winnr()*
Bram Moolenaar5eb86f92004-07-26 12:53:41 +00007593winnr([{arg}]) The result is a Number, which is the number of the current
7594 window. The top window has number 1.
7595 When the optional argument is "$", the number of the
Bram Moolenaar2df58b42012-11-28 18:21:11 +01007596 last window is returned (the window count). >
7597 let window_count = winnr('$')
7598< When the optional argument is "#", the number of the last
Bram Moolenaar5eb86f92004-07-26 12:53:41 +00007599 accessed window is returned (where |CTRL-W_p| goes to).
Bram Moolenaaref2f6562007-05-06 13:32:59 +00007600 If there is no previous window or it is in another tab page 0
7601 is returned.
Bram Moolenaar5eb86f92004-07-26 12:53:41 +00007602 The number can be used with |CTRL-W_w| and ":wincmd w"
7603 |:wincmd|.
Bram Moolenaaref2f6562007-05-06 13:32:59 +00007604 Also see |tabpagewinnr()|.
Bram Moolenaar071d4272004-06-13 20:20:40 +00007605
7606 *winrestcmd()*
7607winrestcmd() Returns a sequence of |:resize| commands that should restore
7608 the current window sizes. Only works properly when no windows
Bram Moolenaar87b5ca52006-03-04 21:55:31 +00007609 are opened or closed and the current window and tab page is
7610 unchanged.
Bram Moolenaar071d4272004-06-13 20:20:40 +00007611 Example: >
7612 :let cmd = winrestcmd()
7613 :call MessWithWindowSizes()
7614 :exe cmd
Bram Moolenaar87b5ca52006-03-04 21:55:31 +00007615<
7616 *winrestview()*
7617winrestview({dict})
7618 Uses the |Dictionary| returned by |winsaveview()| to restore
7619 the view of the current window.
Bram Moolenaar82c25852014-05-28 16:47:16 +02007620 Note: The {dict} does not have to contain all values, that are
7621 returned by |winsaveview()|. If values are missing, those
7622 settings won't be restored. So you can use: >
7623 :call winrestview({'curswant': 4})
7624<
7625 This will only set the curswant value (the column the cursor
7626 wants to move on vertical movements) of the cursor to column 5
7627 (yes, that is 5), while all other settings will remain the
7628 same. This is useful, if you set the cursor position manually.
7629
Bram Moolenaar87b5ca52006-03-04 21:55:31 +00007630 If you have changed the values the result is unpredictable.
7631 If the window size changed the result won't be the same.
7632
7633 *winsaveview()*
7634winsaveview() Returns a |Dictionary| that contains information to restore
7635 the view of the current window. Use |winrestview()| to
7636 restore the view.
7637 This is useful if you have a mapping that jumps around in the
7638 buffer and you want to go back to the original view.
7639 This does not save fold information. Use the 'foldenable'
Bram Moolenaardb552d602006-03-23 22:59:57 +00007640 option to temporarily switch off folding, so that folds are
Bram Moolenaar07d87792014-07-19 14:04:47 +02007641 not opened when moving around. This may have side effects.
Bram Moolenaar87b5ca52006-03-04 21:55:31 +00007642 The return value includes:
7643 lnum cursor line number
Bram Moolenaar82c25852014-05-28 16:47:16 +02007644 col cursor column (Note: the first column
7645 zero, as opposed to what getpos()
7646 returns)
Bram Moolenaar87b5ca52006-03-04 21:55:31 +00007647 coladd cursor column offset for 'virtualedit'
7648 curswant column for vertical movement
7649 topline first line in the window
7650 topfill filler lines, only in diff mode
7651 leftcol first column displayed
7652 skipcol columns skipped
7653 Note that no option values are saved.
7654
Bram Moolenaar071d4272004-06-13 20:20:40 +00007655
7656winwidth({nr}) *winwidth()*
7657 The result is a Number, which is the width of window {nr}.
Bram Moolenaar888ccac2016-06-04 18:49:36 +02007658 {nr} can be the window number or the window ID.
Bram Moolenaar071d4272004-06-13 20:20:40 +00007659 When {nr} is zero, the width of the current window is
7660 returned. When window {nr} doesn't exist, -1 is returned.
7661 An existing window always has a width of zero or more.
7662 Examples: >
7663 :echo "The current window has " . winwidth(0) . " columns."
7664 :if winwidth(0) <= 50
7665 : exe "normal 50\<C-W>|"
7666 :endif
Bram Moolenaar22fcfad2016-07-01 18:17:26 +02007667< For getting the terminal or screen size, see the 'columns'
7668 option.
7669
7670
Bram Moolenaared767a22016-01-03 22:49:16 +01007671wordcount() *wordcount()*
7672 The result is a dictionary of byte/chars/word statistics for
7673 the current buffer. This is the same info as provided by
7674 |g_CTRL-G|
7675 The return value includes:
7676 bytes Number of bytes in the buffer
7677 chars Number of chars in the buffer
7678 words Number of words in the buffer
7679 cursor_bytes Number of bytes before cursor position
7680 (not in Visual mode)
7681 cursor_chars Number of chars before cursor position
7682 (not in Visual mode)
7683 cursor_words Number of words before cursor position
7684 (not in Visual mode)
7685 visual_bytes Number of bytes visually selected
7686 (only in Visual mode)
7687 visual_chars Number of chars visually selected
7688 (only in Visual mode)
7689 visual_words Number of chars visually selected
7690 (only in Visual mode)
7691
7692
Bram Moolenaar3a7c85b2005-02-05 21:39:53 +00007693 *writefile()*
Bram Moolenaar6b2e9382014-11-05 18:06:01 +01007694writefile({list}, {fname} [, {flags}])
Bram Moolenaar32466aa2006-02-24 23:53:04 +00007695 Write |List| {list} to file {fname}. Each list item is
Bram Moolenaar3a7c85b2005-02-05 21:39:53 +00007696 separated with a NL. Each list item must be a String or
7697 Number.
Bram Moolenaar6b2e9382014-11-05 18:06:01 +01007698 When {flags} contains "b" then binary mode is used: There will
Bram Moolenaar3a7c85b2005-02-05 21:39:53 +00007699 not be a NL after the last list item. An empty item at the
7700 end does cause the last line in the file to end in a NL.
Bram Moolenaar6b2e9382014-11-05 18:06:01 +01007701
7702 When {flags} contains "a" then append mode is used, lines are
7703 append to the file: >
7704 :call writefile(["foo"], "event.log", "a")
7705 :call writefile(["bar"], "event.log", "a")
7706>
7707< All NL characters are replaced with a NUL character.
Bram Moolenaar3a7c85b2005-02-05 21:39:53 +00007708 Inserting CR characters needs to be done before passing {list}
7709 to writefile().
7710 An existing file is overwritten, if possible.
7711 When the write fails -1 is returned, otherwise 0. There is an
7712 error message if the file can't be created or when writing
7713 fails.
7714 Also see |readfile()|.
7715 To copy a file byte for byte: >
7716 :let fl = readfile("foo", "b")
7717 :call writefile(fl, "foocopy", "b")
Bram Moolenaard6e256c2011-12-14 15:32:50 +01007718
7719
7720xor({expr}, {expr}) *xor()*
7721 Bitwise XOR on the two arguments. The arguments are converted
7722 to a number. A List, Dict or Float argument causes an error.
7723 Example: >
7724 :let bits = xor(bits, 0x80)
Bram Moolenaar6ee8d892012-01-10 14:55:01 +01007725<
Bram Moolenaard6e256c2011-12-14 15:32:50 +01007726
Bram Moolenaar071d4272004-06-13 20:20:40 +00007727
7728 *feature-list*
Bram Moolenaar946e27a2014-06-25 18:50:27 +02007729There are four types of features:
Bram Moolenaar071d4272004-06-13 20:20:40 +000077301. Features that are only supported when they have been enabled when Vim
7731 was compiled |+feature-list|. Example: >
7732 :if has("cindent")
77332. Features that are only supported when certain conditions have been met.
7734 Example: >
7735 :if has("gui_running")
7736< *has-patch*
Bram Moolenaar7e38ea22014-04-05 22:55:53 +020077373. Included patches. The "patch123" feature means that patch 123 has been
7738 included. Note that this form does not check the version of Vim, you need
7739 to inspect |v:version| for that.
7740 Example (checking version 6.2.148 or later): >
Bram Moolenaar071d4272004-06-13 20:20:40 +00007741 :if v:version > 602 || v:version == 602 && has("patch148")
Bram Moolenaar7e38ea22014-04-05 22:55:53 +02007742< Note that it's possible for patch 147 to be omitted even though 148 is
7743 included.
7744
77454. Beyond a certain version or at a certain version and including a specific
Bram Moolenaarbcb98982014-05-01 14:08:19 +02007746 patch. The "patch-7.4.237" feature means that the Vim version is 7.5 or
7747 later, or it is version 7.4 and patch 237 was included.
7748 Note that this only works for patch 7.4.237 and later, before that you
7749 need to use the example above that checks v:version. Example: >
7750 :if has("patch-7.4.248")
Bram Moolenaar7e38ea22014-04-05 22:55:53 +02007751< Note that it's possible for patch 147 to be omitted even though 148 is
Bram Moolenaaref2f6562007-05-06 13:32:59 +00007752 included.
Bram Moolenaar071d4272004-06-13 20:20:40 +00007753
Bram Moolenaar7cba6c02013-09-05 22:13:31 +02007754acl Compiled with |ACL| support.
Bram Moolenaar071d4272004-06-13 20:20:40 +00007755all_builtin_terms Compiled with all builtin terminals enabled.
7756amiga Amiga version of Vim.
7757arabic Compiled with Arabic support |Arabic|.
7758arp Compiled with ARP support (Amiga).
Bram Moolenaara9b1e742005-12-19 22:14:58 +00007759autocmd Compiled with autocommand support. |autocommand|
Bram Moolenaar071d4272004-06-13 20:20:40 +00007760balloon_eval Compiled with |balloon-eval| support.
Bram Moolenaar45360022005-07-21 21:08:21 +00007761balloon_multiline GUI supports multiline balloons.
Bram Moolenaar071d4272004-06-13 20:20:40 +00007762beos BeOS version of Vim.
7763browse Compiled with |:browse| support, and browse() will
7764 work.
Bram Moolenaar30b65812012-07-12 22:01:11 +02007765browsefilter Compiled with support for |browsefilter|.
Bram Moolenaar071d4272004-06-13 20:20:40 +00007766builtin_terms Compiled with some builtin terminals.
7767byte_offset Compiled with support for 'o' in 'statusline'
7768cindent Compiled with 'cindent' support.
7769clientserver Compiled with remote invocation support |clientserver|.
7770clipboard Compiled with 'clipboard' support.
7771cmdline_compl Compiled with |cmdline-completion| support.
7772cmdline_hist Compiled with |cmdline-history| support.
7773cmdline_info Compiled with 'showcmd' and 'ruler' support.
7774comments Compiled with |'comments'| support.
Bram Moolenaar2a8a3ec2011-01-08 16:06:37 +01007775compatible Compiled to be very Vi compatible.
Bram Moolenaar071d4272004-06-13 20:20:40 +00007776cryptv Compiled with encryption support |encryption|.
7777cscope Compiled with |cscope| support.
Bram Moolenaar071d4272004-06-13 20:20:40 +00007778debug Compiled with "DEBUG" defined.
7779dialog_con Compiled with console dialog support.
7780dialog_gui Compiled with GUI dialog support.
7781diff Compiled with |vimdiff| and 'diff' support.
7782digraphs Compiled with support for digraphs.
Bram Moolenaarb5a7a8b2014-08-06 14:52:30 +02007783directx Compiled with support for Direct-X and 'renderoptions'.
Bram Moolenaar071d4272004-06-13 20:20:40 +00007784dnd Compiled with support for the "~ register |quote_~|.
Bram Moolenaar071d4272004-06-13 20:20:40 +00007785dos16 16 bits DOS version of Vim.
Bram Moolenaar2a8a3ec2011-01-08 16:06:37 +01007786dos32 32 bits DOS (DJGPP) version of Vim.
Bram Moolenaar071d4272004-06-13 20:20:40 +00007787ebcdic Compiled on a machine with ebcdic character set.
7788emacs_tags Compiled with support for Emacs tags.
7789eval Compiled with expression evaluation support. Always
7790 true, of course!
Bram Moolenaar5e9b2fa2016-02-01 22:37:05 +01007791ex_extra |+ex_extra|, always true now
Bram Moolenaar071d4272004-06-13 20:20:40 +00007792extra_search Compiled with support for |'incsearch'| and
7793 |'hlsearch'|
7794farsi Compiled with Farsi support |farsi|.
7795file_in_path Compiled with support for |gf| and |<cfile>|
Bram Moolenaar26a60b42005-02-22 08:49:11 +00007796filterpipe When 'shelltemp' is off pipes are used for shell
7797 read/write/filter commands
Bram Moolenaar071d4272004-06-13 20:20:40 +00007798find_in_path Compiled with support for include file searches
7799 |+find_in_path|.
Bram Moolenaar446cb832008-06-24 21:56:24 +00007800float Compiled with support for |Float|.
Bram Moolenaar071d4272004-06-13 20:20:40 +00007801fname_case Case in file names matters (for Amiga, MS-DOS, and
7802 Windows this is not present).
7803folding Compiled with |folding| support.
7804footer Compiled with GUI footer support. |gui-footer|
7805fork Compiled to use fork()/exec() instead of system().
7806gettext Compiled with message translation |multi-lang|
7807gui Compiled with GUI enabled.
7808gui_athena Compiled with Athena GUI.
Bram Moolenaar2a8a3ec2011-01-08 16:06:37 +01007809gui_gnome Compiled with Gnome support (gui_gtk is also defined).
Bram Moolenaar071d4272004-06-13 20:20:40 +00007810gui_gtk Compiled with GTK+ GUI (any version).
7811gui_gtk2 Compiled with GTK+ 2 GUI (gui_gtk is also defined).
Bram Moolenaar98921892016-02-23 17:14:37 +01007812gui_gtk3 Compiled with GTK+ 3 GUI (gui_gtk is also defined).
Bram Moolenaar071d4272004-06-13 20:20:40 +00007813gui_mac Compiled with Macintosh GUI.
7814gui_motif Compiled with Motif GUI.
7815gui_photon Compiled with Photon GUI.
Bram Moolenaar2a8a3ec2011-01-08 16:06:37 +01007816gui_running Vim is running in the GUI, or it will start soon.
Bram Moolenaar071d4272004-06-13 20:20:40 +00007817gui_win32 Compiled with MS Windows Win32 GUI.
7818gui_win32s idem, and Win32s system being used (Windows 3.1)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007819hangul_input Compiled with Hangul input support. |hangul|
7820iconv Can use iconv() for conversion.
7821insert_expand Compiled with support for CTRL-X expansion commands in
7822 Insert mode.
7823jumplist Compiled with |jumplist| support.
7824keymap Compiled with 'keymap' support.
7825langmap Compiled with 'langmap' support.
7826libcall Compiled with |libcall()| support.
Bram Moolenaar597a4222014-06-25 14:39:50 +02007827linebreak Compiled with 'linebreak', 'breakat', 'showbreak' and
7828 'breakindent' support.
Bram Moolenaar071d4272004-06-13 20:20:40 +00007829lispindent Compiled with support for lisp indenting.
7830listcmds Compiled with commands for the buffer list |:files|
7831 and the argument list |arglist|.
7832localmap Compiled with local mappings and abbr. |:map-local|
Bram Moolenaar0ba04292010-07-14 23:23:17 +02007833lua Compiled with Lua interface |Lua|.
Bram Moolenaar910b8aa2016-02-16 21:03:07 +01007834mac Any Macintosh version of Vim.
Bram Moolenaarf8df7ad2016-02-16 14:07:40 +01007835macunix Compiled for OS X, with darwin
7836osx Compiled for OS X, with or without darwin
Bram Moolenaar071d4272004-06-13 20:20:40 +00007837menu Compiled with support for |:menu|.
7838mksession Compiled with support for |:mksession|.
7839modify_fname Compiled with file name modifiers. |filename-modifiers|
7840mouse Compiled with support mouse.
Bram Moolenaar071d4272004-06-13 20:20:40 +00007841mouse_dec Compiled with support for Dec terminal mouse.
7842mouse_gpm Compiled with support for gpm (Linux console mouse)
7843mouse_netterm Compiled with support for netterm mouse.
7844mouse_pterm Compiled with support for qnx pterm mouse.
Bram Moolenaar446cb832008-06-24 21:56:24 +00007845mouse_sysmouse Compiled with support for sysmouse (*BSD console mouse)
Bram Moolenaar9b451252012-08-15 17:43:31 +02007846mouse_sgr Compiled with support for sgr mouse.
Bram Moolenaarf1568ec2011-12-14 21:17:39 +01007847mouse_urxvt Compiled with support for urxvt mouse.
Bram Moolenaar071d4272004-06-13 20:20:40 +00007848mouse_xterm Compiled with support for xterm mouse.
Bram Moolenaar2a8a3ec2011-01-08 16:06:37 +01007849mouseshape Compiled with support for 'mouseshape'.
Bram Moolenaar42022d52008-12-09 09:57:49 +00007850multi_byte Compiled with support for 'encoding'
7851multi_byte_encoding 'encoding' is set to a multi-byte encoding.
Bram Moolenaar071d4272004-06-13 20:20:40 +00007852multi_byte_ime Compiled with support for IME input method.
7853multi_lang Compiled with support for multiple languages.
Bram Moolenaar325b7a22004-07-05 15:58:32 +00007854mzscheme Compiled with MzScheme interface |mzscheme|.
Bram Moolenaarb26e6322010-05-22 21:34:09 +02007855netbeans_enabled Compiled with support for |netbeans| and connected.
Bram Moolenaar2a8a3ec2011-01-08 16:06:37 +01007856netbeans_intg Compiled with support for |netbeans|.
Bram Moolenaar22fcfad2016-07-01 18:17:26 +02007857num64 Compiled with 64-bit |Number| support.
Bram Moolenaar071d4272004-06-13 20:20:40 +00007858ole Compiled with OLE automation support for Win32.
7859os2 OS/2 version of Vim.
Bram Moolenaar91c49372016-05-08 09:50:29 +02007860packages Compiled with |packages| support.
Bram Moolenaar071d4272004-06-13 20:20:40 +00007861path_extra Compiled with up/downwards search in 'path' and 'tags'
7862perl Compiled with Perl interface.
Bram Moolenaar55debbe2010-05-23 23:34:36 +02007863persistent_undo Compiled with support for persistent undo history.
Bram Moolenaar071d4272004-06-13 20:20:40 +00007864postscript Compiled with PostScript file printing.
7865printer Compiled with |:hardcopy| support.
Bram Moolenaar05159a02005-02-26 23:04:13 +00007866profile Compiled with |:profile| support.
Bram Moolenaar446beb42011-05-10 17:18:44 +02007867python Compiled with Python 2.x interface. |has-python|
7868python3 Compiled with Python 3.x interface. |has-python|
Bram Moolenaar071d4272004-06-13 20:20:40 +00007869qnx QNX version of Vim.
7870quickfix Compiled with |quickfix| support.
Bram Moolenaard68071d2006-05-02 22:08:30 +00007871reltime Compiled with |reltime()| support.
Bram Moolenaar071d4272004-06-13 20:20:40 +00007872rightleft Compiled with 'rightleft' support.
7873ruby Compiled with Ruby interface |ruby|.
7874scrollbind Compiled with 'scrollbind' support.
7875showcmd Compiled with 'showcmd' support.
7876signs Compiled with |:sign| support.
7877smartindent Compiled with 'smartindent' support.
Bram Moolenaar2a8a3ec2011-01-08 16:06:37 +01007878spell Compiled with spell checking support |spell|.
Bram Moolenaaref94eec2009-11-11 13:22:11 +00007879startuptime Compiled with |--startuptime| support.
Bram Moolenaar071d4272004-06-13 20:20:40 +00007880statusline Compiled with support for 'statusline', 'rulerformat'
7881 and special formats of 'titlestring' and 'iconstring'.
7882sun_workshop Compiled with support for Sun |workshop|.
Bram Moolenaar82cf9b62005-06-07 21:09:25 +00007883syntax Compiled with syntax highlighting support |syntax|.
Bram Moolenaar071d4272004-06-13 20:20:40 +00007884syntax_items There are active syntax highlighting items for the
7885 current buffer.
7886system Compiled to use system() instead of fork()/exec().
7887tag_binary Compiled with binary searching in tags files
7888 |tag-binary-search|.
7889tag_old_static Compiled with support for old static tags
7890 |tag-old-static|.
7891tag_any_white Compiled with support for any white characters in tags
7892 files |tag-any-white|.
7893tcl Compiled with Tcl interface.
Bram Moolenaar91c49372016-05-08 09:50:29 +02007894termguicolors Compiled with true color in terminal support.
Bram Moolenaar071d4272004-06-13 20:20:40 +00007895terminfo Compiled with terminfo instead of termcap.
7896termresponse Compiled with support for |t_RV| and |v:termresponse|.
7897textobjects Compiled with support for |text-objects|.
7898tgetent Compiled with tgetent support, able to use a termcap
7899 or terminfo file.
Bram Moolenaar975b5272016-03-15 23:10:59 +01007900timers Compiled with |timer_start()| support.
Bram Moolenaar071d4272004-06-13 20:20:40 +00007901title Compiled with window title support |'title'|.
7902toolbar Compiled with support for |gui-toolbar|.
7903unix Unix version of Vim.
7904user_commands User-defined commands.
Bram Moolenaar071d4272004-06-13 20:20:40 +00007905vertsplit Compiled with vertically split windows |:vsplit|.
Bram Moolenaar2a8a3ec2011-01-08 16:06:37 +01007906vim_starting True while initial source'ing takes place. |startup|
Bram Moolenaar4f3f6682016-03-26 23:01:59 +01007907 *vim_starting*
Bram Moolenaar2a8a3ec2011-01-08 16:06:37 +01007908viminfo Compiled with viminfo support.
Bram Moolenaar071d4272004-06-13 20:20:40 +00007909virtualedit Compiled with 'virtualedit' option.
7910visual Compiled with Visual mode.
7911visualextra Compiled with extra Visual mode commands.
7912 |blockwise-operators|.
7913vms VMS version of Vim.
7914vreplace Compiled with |gR| and |gr| commands.
7915wildignore Compiled with 'wildignore' option.
7916wildmenu Compiled with 'wildmenu' option.
Bram Moolenaard58e9292011-02-09 17:07:58 +01007917win32 Win32 version of Vim (MS-Windows 95 and later, 32 or
7918 64 bits)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007919win32unix Win32 version of Vim, using Unix files (Cygwin)
Bram Moolenaar2a8a3ec2011-01-08 16:06:37 +01007920win64 Win64 version of Vim (MS-Windows 64 bit).
Bram Moolenaar071d4272004-06-13 20:20:40 +00007921win95 Win32 version for MS-Windows 95/98/ME.
Bram Moolenaar2a8a3ec2011-01-08 16:06:37 +01007922winaltkeys Compiled with 'winaltkeys' option.
7923windows Compiled with support for more than one window.
Bram Moolenaar071d4272004-06-13 20:20:40 +00007924writebackup Compiled with 'writebackup' default on.
7925xfontset Compiled with X fontset support |xfontset|.
7926xim Compiled with X input method support |xim|.
Bram Moolenaar7cba6c02013-09-05 22:13:31 +02007927xpm Compiled with pixmap support.
7928xpm_w32 Compiled with pixmap support for Win32. (Only for
7929 backward compatibility. Use "xpm" instead.)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007930xsmp Compiled with X session management support.
7931xsmp_interact Compiled with interactive X session management support.
7932xterm_clipboard Compiled with support for xterm clipboard.
7933xterm_save Compiled with support for saving and restoring the
7934 xterm screen.
7935x11 Compiled with X11 support.
7936
7937 *string-match*
7938Matching a pattern in a String
7939
7940A regexp pattern as explained at |pattern| is normally used to find a match in
7941the buffer lines. When a pattern is used to find a match in a String, almost
7942everything works in the same way. The difference is that a String is handled
7943like it is one line. When it contains a "\n" character, this is not seen as a
7944line break for the pattern. It can be matched with a "\n" in the pattern, or
7945with ".". Example: >
7946 :let a = "aaaa\nxxxx"
7947 :echo matchstr(a, "..\n..")
7948 aa
7949 xx
7950 :echo matchstr(a, "a.x")
7951 a
7952 x
7953
7954Don't forget that "^" will only match at the first character of the String and
7955"$" at the last character of the string. They don't match after or before a
7956"\n".
7957
7958==============================================================================
79595. Defining functions *user-functions*
7960
7961New functions can be defined. These can be called just like builtin
7962functions. The function executes a sequence of Ex commands. Normal mode
7963commands can be executed with the |:normal| command.
7964
7965The function name must start with an uppercase letter, to avoid confusion with
7966builtin functions. To prevent from using the same name in different scripts
7967avoid obvious, short names. A good habit is to start the function name with
7968the name of the script, e.g., "HTMLcolor()".
7969
Bram Moolenaar92d640f2005-09-05 22:11:52 +00007970It's also possible to use curly braces, see |curly-braces-names|. And the
7971|autoload| facility is useful to define a function only when it's called.
Bram Moolenaar071d4272004-06-13 20:20:40 +00007972
7973 *local-function*
7974A function local to a script must start with "s:". A local script function
7975can only be called from within the script and from functions, user commands
7976and autocommands defined in the script. It is also possible to call the
Bram Moolenaare37d50a2008-08-06 17:06:04 +00007977function from a mapping defined in the script, but then |<SID>| must be used
Bram Moolenaar071d4272004-06-13 20:20:40 +00007978instead of "s:" when the mapping is expanded outside of the script.
Bram Moolenaarbcb98982014-05-01 14:08:19 +02007979There are only script-local functions, no buffer-local or window-local
7980functions.
Bram Moolenaar071d4272004-06-13 20:20:40 +00007981
7982 *:fu* *:function* *E128* *E129* *E123*
7983:fu[nction] List all functions and their arguments.
7984
7985:fu[nction] {name} List function {name}.
Bram Moolenaar32466aa2006-02-24 23:53:04 +00007986 {name} can also be a |Dictionary| entry that is a
7987 |Funcref|: >
Bram Moolenaar3a3a7232005-01-17 22:16:15 +00007988 :function dict.init
Bram Moolenaar92d640f2005-09-05 22:11:52 +00007989
7990:fu[nction] /{pattern} List functions with a name matching {pattern}.
7991 Example that lists all functions ending with "File": >
7992 :function /File$
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00007993<
7994 *:function-verbose*
7995When 'verbose' is non-zero, listing a function will also display where it was
7996last defined. Example: >
7997
7998 :verbose function SetFileTypeSH
7999 function SetFileTypeSH(name)
8000 Last set from /usr/share/vim/vim-7.0/filetype.vim
8001<
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00008002See |:verbose-cmd| for more information.
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00008003
Bram Moolenaarbcb98982014-05-01 14:08:19 +02008004 *E124* *E125* *E853* *E884*
Bram Moolenaar2fda12f2005-01-15 22:14:15 +00008005:fu[nction][!] {name}([arguments]) [range] [abort] [dict]
Bram Moolenaar071d4272004-06-13 20:20:40 +00008006 Define a new function by the name {name}. The name
8007 must be made of alphanumeric characters and '_', and
Bram Moolenaarbcb98982014-05-01 14:08:19 +02008008 must start with a capital or "s:" (see above). Note
8009 that using "b:" or "g:" is not allowed. (since patch
8010 7.4.260 E884 is given if the function name has a colon
8011 in the name, e.g. for "foo:bar()". Before that patch
8012 no error was given).
Bram Moolenaar3a3a7232005-01-17 22:16:15 +00008013
Bram Moolenaar32466aa2006-02-24 23:53:04 +00008014 {name} can also be a |Dictionary| entry that is a
8015 |Funcref|: >
Bram Moolenaar3a3a7232005-01-17 22:16:15 +00008016 :function dict.init(arg)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008017< "dict" must be an existing dictionary. The entry
Bram Moolenaar3a3a7232005-01-17 22:16:15 +00008018 "init" is added if it didn't exist yet. Otherwise [!]
Bram Moolenaar446cb832008-06-24 21:56:24 +00008019 is required to overwrite an existing function. The
Bram Moolenaar3a3a7232005-01-17 22:16:15 +00008020 result is a |Funcref| to a numbered function. The
8021 function can only be used with a |Funcref| and will be
8022 deleted if there are no more references to it.
Bram Moolenaar071d4272004-06-13 20:20:40 +00008023 *E127* *E122*
8024 When a function by this name already exists and [!] is
8025 not used an error message is given. When [!] is used,
8026 an existing function is silently replaced. Unless it
8027 is currently being executed, that is an error.
Bram Moolenaar8f999f12005-01-25 22:12:55 +00008028
8029 For the {arguments} see |function-argument|.
8030
Bram Moolenaar8d043172014-01-23 14:24:41 +01008031 *:func-range* *a:firstline* *a:lastline*
Bram Moolenaar071d4272004-06-13 20:20:40 +00008032 When the [range] argument is added, the function is
8033 expected to take care of a range itself. The range is
8034 passed as "a:firstline" and "a:lastline". If [range]
8035 is excluded, ":{range}call" will call the function for
8036 each line in the range, with the cursor on the start
8037 of each line. See |function-range-example|.
Bram Moolenaar2df58b42012-11-28 18:21:11 +01008038 The cursor is still moved to the first line of the
8039 range, as is the case with all Ex commands.
Bram Moolenaar8d043172014-01-23 14:24:41 +01008040 *:func-abort*
Bram Moolenaar071d4272004-06-13 20:20:40 +00008041 When the [abort] argument is added, the function will
8042 abort as soon as an error is detected.
Bram Moolenaar8d043172014-01-23 14:24:41 +01008043 *:func-dict*
Bram Moolenaar2fda12f2005-01-15 22:14:15 +00008044 When the [dict] argument is added, the function must
Bram Moolenaar446cb832008-06-24 21:56:24 +00008045 be invoked through an entry in a |Dictionary|. The
Bram Moolenaar2fda12f2005-01-15 22:14:15 +00008046 local variable "self" will then be set to the
8047 dictionary. See |Dictionary-function|.
Bram Moolenaar071d4272004-06-13 20:20:40 +00008048
Bram Moolenaar446cb832008-06-24 21:56:24 +00008049 *function-search-undo*
Bram Moolenaar98692072006-02-04 00:57:42 +00008050 The last used search pattern and the redo command "."
Bram Moolenaar446cb832008-06-24 21:56:24 +00008051 will not be changed by the function. This also
8052 implies that the effect of |:nohlsearch| is undone
8053 when the function returns.
Bram Moolenaar98692072006-02-04 00:57:42 +00008054
Bram Moolenaar071d4272004-06-13 20:20:40 +00008055 *:endf* *:endfunction* *E126* *E193*
8056:endf[unction] The end of a function definition. Must be on a line
8057 by its own, without other commands.
8058
8059 *:delf* *:delfunction* *E130* *E131*
8060:delf[unction] {name} Delete function {name}.
Bram Moolenaar32466aa2006-02-24 23:53:04 +00008061 {name} can also be a |Dictionary| entry that is a
8062 |Funcref|: >
Bram Moolenaar3a3a7232005-01-17 22:16:15 +00008063 :delfunc dict.init
Bram Moolenaar446cb832008-06-24 21:56:24 +00008064< This will remove the "init" entry from "dict". The
Bram Moolenaar3a3a7232005-01-17 22:16:15 +00008065 function is deleted if there are no more references to
8066 it.
Bram Moolenaar071d4272004-06-13 20:20:40 +00008067 *:retu* *:return* *E133*
8068:retu[rn] [expr] Return from a function. When "[expr]" is given, it is
8069 evaluated and returned as the result of the function.
8070 If "[expr]" is not given, the number 0 is returned.
8071 When a function ends without an explicit ":return",
8072 the number 0 is returned.
8073 Note that there is no check for unreachable lines,
8074 thus there is no warning if commands follow ":return".
8075
8076 If the ":return" is used after a |:try| but before the
8077 matching |:finally| (if present), the commands
8078 following the ":finally" up to the matching |:endtry|
8079 are executed first. This process applies to all
8080 nested ":try"s inside the function. The function
8081 returns at the outermost ":endtry".
8082
Bram Moolenaar8f999f12005-01-25 22:12:55 +00008083 *function-argument* *a:var*
Bram Moolenaar446cb832008-06-24 21:56:24 +00008084An argument can be defined by giving its name. In the function this can then
Bram Moolenaar8f999f12005-01-25 22:12:55 +00008085be used as "a:name" ("a:" for argument).
Bram Moolenaaref2f6562007-05-06 13:32:59 +00008086 *a:0* *a:1* *a:000* *E740* *...*
Bram Moolenaar8f999f12005-01-25 22:12:55 +00008087Up to 20 arguments can be given, separated by commas. After the named
8088arguments an argument "..." can be specified, which means that more arguments
8089may optionally be following. In the function the extra arguments can be used
8090as "a:1", "a:2", etc. "a:0" is set to the number of extra arguments (which
Bram Moolenaar32466aa2006-02-24 23:53:04 +00008091can be 0). "a:000" is set to a |List| that contains these arguments. Note
8092that "a:1" is the same as "a:000[0]".
Bram Moolenaar2ce06f62005-01-31 19:19:04 +00008093 *E742*
8094The a: scope and the variables in it cannot be changed, they are fixed.
Bram Moolenaare37d50a2008-08-06 17:06:04 +00008095However, if a |List| or |Dictionary| is used, you can change their contents.
Bram Moolenaar32466aa2006-02-24 23:53:04 +00008096Thus you can pass a |List| to a function and have the function add an item to
8097it. If you want to make sure the function cannot change a |List| or
8098|Dictionary| use |:lockvar|.
Bram Moolenaar071d4272004-06-13 20:20:40 +00008099
Bram Moolenaar8f999f12005-01-25 22:12:55 +00008100When not using "...", the number of arguments in a function call must be equal
8101to the number of named arguments. When using "...", the number of arguments
8102may be larger.
8103
8104It is also possible to define a function without any arguments. You must
8105still supply the () then. The body of the function follows in the next lines,
8106until the matching |:endfunction|. It is allowed to define another function
8107inside a function body.
8108
8109 *local-variables*
Bram Moolenaar071d4272004-06-13 20:20:40 +00008110Inside a function variables can be used. These are local variables, which
8111will disappear when the function returns. Global variables need to be
8112accessed with "g:".
8113
8114Example: >
8115 :function Table(title, ...)
8116 : echohl Title
8117 : echo a:title
8118 : echohl None
Bram Moolenaar677ee682005-01-27 14:41:15 +00008119 : echo a:0 . " items:"
8120 : for s in a:000
8121 : echon ' ' . s
8122 : endfor
Bram Moolenaar071d4272004-06-13 20:20:40 +00008123 :endfunction
8124
8125This function can then be called with: >
Bram Moolenaar677ee682005-01-27 14:41:15 +00008126 call Table("Table", "line1", "line2")
8127 call Table("Empty Table")
Bram Moolenaar071d4272004-06-13 20:20:40 +00008128
Bram Moolenaaref2f6562007-05-06 13:32:59 +00008129To return more than one value, return a |List|: >
8130 :function Compute(n1, n2)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008131 : if a:n2 == 0
Bram Moolenaaref2f6562007-05-06 13:32:59 +00008132 : return ["fail", 0]
Bram Moolenaar071d4272004-06-13 20:20:40 +00008133 : endif
Bram Moolenaaref2f6562007-05-06 13:32:59 +00008134 : return ["ok", a:n1 / a:n2]
Bram Moolenaar071d4272004-06-13 20:20:40 +00008135 :endfunction
8136
8137This function can then be called with: >
Bram Moolenaaref2f6562007-05-06 13:32:59 +00008138 :let [success, div] = Compute(102, 6)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008139 :if success == "ok"
8140 : echo div
8141 :endif
Bram Moolenaaref2f6562007-05-06 13:32:59 +00008142<
Bram Moolenaar39f05632006-03-19 22:15:26 +00008143 *:cal* *:call* *E107* *E117*
Bram Moolenaar071d4272004-06-13 20:20:40 +00008144:[range]cal[l] {name}([arguments])
8145 Call a function. The name of the function and its arguments
8146 are as specified with |:function|. Up to 20 arguments can be
Bram Moolenaaref2f6562007-05-06 13:32:59 +00008147 used. The returned value is discarded.
Bram Moolenaar071d4272004-06-13 20:20:40 +00008148 Without a range and for functions that accept a range, the
8149 function is called once. When a range is given the cursor is
8150 positioned at the start of the first line before executing the
8151 function.
8152 When a range is given and the function doesn't handle it
8153 itself, the function is executed for each line in the range,
8154 with the cursor in the first column of that line. The cursor
8155 is left at the last line (possibly moved by the last function
Bram Moolenaar446cb832008-06-24 21:56:24 +00008156 call). The arguments are re-evaluated for each line. Thus
Bram Moolenaar071d4272004-06-13 20:20:40 +00008157 this works:
8158 *function-range-example* >
8159 :function Mynumber(arg)
8160 : echo line(".") . " " . a:arg
8161 :endfunction
8162 :1,5call Mynumber(getline("."))
8163<
8164 The "a:firstline" and "a:lastline" are defined anyway, they
8165 can be used to do something different at the start or end of
8166 the range.
8167
8168 Example of a function that handles the range itself: >
8169
8170 :function Cont() range
8171 : execute (a:firstline + 1) . "," . a:lastline . 's/^/\t\\ '
8172 :endfunction
8173 :4,8call Cont()
8174<
8175 This function inserts the continuation character "\" in front
8176 of all the lines in the range, except the first one.
8177
Bram Moolenaaref2f6562007-05-06 13:32:59 +00008178 When the function returns a composite value it can be further
8179 dereferenced, but the range will not be used then. Example: >
8180 :4,8call GetDict().method()
8181< Here GetDict() gets the range but method() does not.
8182
Bram Moolenaar071d4272004-06-13 20:20:40 +00008183 *E132*
8184The recursiveness of user functions is restricted with the |'maxfuncdepth'|
8185option.
8186
Bram Moolenaar7c626922005-02-07 22:01:03 +00008187
8188AUTOMATICALLY LOADING FUNCTIONS ~
Bram Moolenaar071d4272004-06-13 20:20:40 +00008189 *autoload-functions*
8190When using many or large functions, it's possible to automatically define them
Bram Moolenaar7c626922005-02-07 22:01:03 +00008191only when they are used. There are two methods: with an autocommand and with
8192the "autoload" directory in 'runtimepath'.
8193
8194
8195Using an autocommand ~
8196
Bram Moolenaar05159a02005-02-26 23:04:13 +00008197This is introduced in the user manual, section |41.14|.
8198
Bram Moolenaar7c626922005-02-07 22:01:03 +00008199The autocommand is useful if you have a plugin that is a long Vim script file.
8200You can define the autocommand and quickly quit the script with |:finish|.
Bram Moolenaar446cb832008-06-24 21:56:24 +00008201That makes Vim startup faster. The autocommand should then load the same file
Bram Moolenaar7c626922005-02-07 22:01:03 +00008202again, setting a variable to skip the |:finish| command.
8203
8204Use the FuncUndefined autocommand event with a pattern that matches the
8205function(s) to be defined. Example: >
Bram Moolenaar071d4272004-06-13 20:20:40 +00008206
8207 :au FuncUndefined BufNet* source ~/vim/bufnetfuncs.vim
8208
8209The file "~/vim/bufnetfuncs.vim" should then define functions that start with
8210"BufNet". Also see |FuncUndefined|.
8211
Bram Moolenaar7c626922005-02-07 22:01:03 +00008212
8213Using an autoload script ~
Bram Moolenaar26a60b42005-02-22 08:49:11 +00008214 *autoload* *E746*
Bram Moolenaar05159a02005-02-26 23:04:13 +00008215This is introduced in the user manual, section |41.15|.
8216
Bram Moolenaar7c626922005-02-07 22:01:03 +00008217Using a script in the "autoload" directory is simpler, but requires using
8218exactly the right file name. A function that can be autoloaded has a name
8219like this: >
8220
Bram Moolenaara7fc0102005-05-18 22:17:12 +00008221 :call filename#funcname()
Bram Moolenaar7c626922005-02-07 22:01:03 +00008222
8223When such a function is called, and it is not defined yet, Vim will search the
8224"autoload" directories in 'runtimepath' for a script file called
8225"filename.vim". For example "~/.vim/autoload/filename.vim". That file should
8226then define the function like this: >
8227
Bram Moolenaara7fc0102005-05-18 22:17:12 +00008228 function filename#funcname()
Bram Moolenaar7c626922005-02-07 22:01:03 +00008229 echo "Done!"
8230 endfunction
8231
Bram Moolenaar60a795a2005-09-16 21:55:43 +00008232The file name and the name used before the # in the function must match
Bram Moolenaar7c626922005-02-07 22:01:03 +00008233exactly, and the defined function must have the name exactly as it will be
8234called.
8235
Bram Moolenaara7fc0102005-05-18 22:17:12 +00008236It is possible to use subdirectories. Every # in the function name works like
8237a path separator. Thus when calling a function: >
Bram Moolenaar7c626922005-02-07 22:01:03 +00008238
Bram Moolenaara7fc0102005-05-18 22:17:12 +00008239 :call foo#bar#func()
Bram Moolenaar7c626922005-02-07 22:01:03 +00008240
8241Vim will look for the file "autoload/foo/bar.vim" in 'runtimepath'.
8242
Bram Moolenaar26a60b42005-02-22 08:49:11 +00008243This also works when reading a variable that has not been set yet: >
8244
Bram Moolenaara7fc0102005-05-18 22:17:12 +00008245 :let l = foo#bar#lvar
Bram Moolenaar26a60b42005-02-22 08:49:11 +00008246
Bram Moolenaara5792f52005-11-23 21:25:05 +00008247However, when the autoload script was already loaded it won't be loaded again
8248for an unknown variable.
8249
Bram Moolenaar26a60b42005-02-22 08:49:11 +00008250When assigning a value to such a variable nothing special happens. This can
8251be used to pass settings to the autoload script before it's loaded: >
8252
Bram Moolenaara7fc0102005-05-18 22:17:12 +00008253 :let foo#bar#toggle = 1
8254 :call foo#bar#func()
Bram Moolenaar26a60b42005-02-22 08:49:11 +00008255
Bram Moolenaar4399ef42005-02-12 14:29:27 +00008256Note that when you make a mistake and call a function that is supposed to be
8257defined in an autoload script, but the script doesn't actually define the
8258function, the script will be sourced every time you try to call the function.
Bram Moolenaar26a60b42005-02-22 08:49:11 +00008259And you will get an error message every time.
8260
8261Also note that if you have two script files, and one calls a function in the
Bram Moolenaar446cb832008-06-24 21:56:24 +00008262other and vice versa, before the used function is defined, it won't work.
Bram Moolenaar26a60b42005-02-22 08:49:11 +00008263Avoid using the autoload functionality at the toplevel.
Bram Moolenaar7c626922005-02-07 22:01:03 +00008264
Bram Moolenaar433f7c82006-03-21 21:29:36 +00008265Hint: If you distribute a bunch of scripts you can pack them together with the
8266|vimball| utility. Also read the user manual |distribute-script|.
8267
Bram Moolenaar071d4272004-06-13 20:20:40 +00008268==============================================================================
82696. Curly braces names *curly-braces-names*
8270
Bram Moolenaar84f72352012-03-11 15:57:40 +01008271In most places where you can use a variable, you can use a "curly braces name"
8272variable. This is a regular variable name with one or more expressions
8273wrapped in braces {} like this: >
Bram Moolenaar071d4272004-06-13 20:20:40 +00008274 my_{adjective}_variable
8275
8276When Vim encounters this, it evaluates the expression inside the braces, puts
8277that in place of the expression, and re-interprets the whole as a variable
8278name. So in the above example, if the variable "adjective" was set to
8279"noisy", then the reference would be to "my_noisy_variable", whereas if
8280"adjective" was set to "quiet", then it would be to "my_quiet_variable".
8281
8282One application for this is to create a set of variables governed by an option
Bram Moolenaar446cb832008-06-24 21:56:24 +00008283value. For example, the statement >
Bram Moolenaar071d4272004-06-13 20:20:40 +00008284 echo my_{&background}_message
8285
8286would output the contents of "my_dark_message" or "my_light_message" depending
8287on the current value of 'background'.
8288
8289You can use multiple brace pairs: >
8290 echo my_{adverb}_{adjective}_message
8291..or even nest them: >
8292 echo my_{ad{end_of_word}}_message
8293where "end_of_word" is either "verb" or "jective".
8294
8295However, the expression inside the braces must evaluate to a valid single
Bram Moolenaar402d2fe2005-04-15 21:00:38 +00008296variable name, e.g. this is invalid: >
Bram Moolenaar071d4272004-06-13 20:20:40 +00008297 :let foo='a + b'
8298 :echo c{foo}d
8299.. since the result of expansion is "ca + bd", which is not a variable name.
8300
8301 *curly-braces-function-names*
8302You can call and define functions by an evaluated name in a similar way.
8303Example: >
8304 :let func_end='whizz'
8305 :call my_func_{func_end}(parameter)
8306
8307This would call the function "my_func_whizz(parameter)".
8308
Bram Moolenaar84f72352012-03-11 15:57:40 +01008309This does NOT work: >
8310 :let i = 3
8311 :let @{i} = '' " error
8312 :echo @{i} " error
8313
Bram Moolenaar071d4272004-06-13 20:20:40 +00008314==============================================================================
83157. Commands *expression-commands*
8316
8317:let {var-name} = {expr1} *:let* *E18*
8318 Set internal variable {var-name} to the result of the
8319 expression {expr1}. The variable will get the type
8320 from the {expr}. If {var-name} didn't exist yet, it
8321 is created.
8322
Bram Moolenaar13065c42005-01-08 16:08:21 +00008323:let {var-name}[{idx}] = {expr1} *E689*
8324 Set a list item to the result of the expression
8325 {expr1}. {var-name} must refer to a list and {idx}
8326 must be a valid index in that list. For nested list
8327 the index can be repeated.
Bram Moolenaar446cb832008-06-24 21:56:24 +00008328 This cannot be used to add an item to a |List|.
8329 This cannot be used to set a byte in a String. You
8330 can do that like this: >
8331 :let var = var[0:2] . 'X' . var[4:]
8332<
Bram Moolenaar3a3a7232005-01-17 22:16:15 +00008333 *E711* *E719*
8334:let {var-name}[{idx1}:{idx2}] = {expr1} *E708* *E709* *E710*
Bram Moolenaar32466aa2006-02-24 23:53:04 +00008335 Set a sequence of items in a |List| to the result of
8336 the expression {expr1}, which must be a list with the
Bram Moolenaar9588a0f2005-01-08 21:45:39 +00008337 correct number of items.
8338 {idx1} can be omitted, zero is used instead.
8339 {idx2} can be omitted, meaning the end of the list.
8340 When the selected range of items is partly past the
8341 end of the list, items will be added.
8342
Bram Moolenaar748bf032005-02-02 23:04:36 +00008343 *:let+=* *:let-=* *:let.=* *E734*
Bram Moolenaar3a3a7232005-01-17 22:16:15 +00008344:let {var} += {expr1} Like ":let {var} = {var} + {expr1}".
8345:let {var} -= {expr1} Like ":let {var} = {var} - {expr1}".
8346:let {var} .= {expr1} Like ":let {var} = {var} . {expr1}".
8347 These fail if {var} was not set yet and when the type
8348 of {var} and {expr1} don't fit the operator.
8349
8350
Bram Moolenaar071d4272004-06-13 20:20:40 +00008351:let ${env-name} = {expr1} *:let-environment* *:let-$*
8352 Set environment variable {env-name} to the result of
8353 the expression {expr1}. The type is always String.
Bram Moolenaar3a3a7232005-01-17 22:16:15 +00008354:let ${env-name} .= {expr1}
8355 Append {expr1} to the environment variable {env-name}.
8356 If the environment variable didn't exist yet this
8357 works like "=".
Bram Moolenaar071d4272004-06-13 20:20:40 +00008358
8359:let @{reg-name} = {expr1} *:let-register* *:let-@*
8360 Write the result of the expression {expr1} in register
8361 {reg-name}. {reg-name} must be a single letter, and
8362 must be the name of a writable register (see
8363 |registers|). "@@" can be used for the unnamed
8364 register, "@/" for the search pattern.
8365 If the result of {expr1} ends in a <CR> or <NL>, the
8366 register will be linewise, otherwise it will be set to
8367 characterwise.
8368 This can be used to clear the last search pattern: >
8369 :let @/ = ""
8370< This is different from searching for an empty string,
8371 that would match everywhere.
8372
Bram Moolenaar3a3a7232005-01-17 22:16:15 +00008373:let @{reg-name} .= {expr1}
Bram Moolenaar446cb832008-06-24 21:56:24 +00008374 Append {expr1} to register {reg-name}. If the
Bram Moolenaar3a3a7232005-01-17 22:16:15 +00008375 register was empty it's like setting it to {expr1}.
8376
Bram Moolenaaref2f6562007-05-06 13:32:59 +00008377:let &{option-name} = {expr1} *:let-option* *:let-&*
Bram Moolenaar071d4272004-06-13 20:20:40 +00008378 Set option {option-name} to the result of the
Bram Moolenaarfca34d62005-01-04 21:38:36 +00008379 expression {expr1}. A String or Number value is
8380 always converted to the type of the option.
Bram Moolenaar071d4272004-06-13 20:20:40 +00008381 For an option local to a window or buffer the effect
8382 is just like using the |:set| command: both the local
Bram Moolenaara5fac542005-10-12 20:58:49 +00008383 value and the global value are changed.
Bram Moolenaarfca34d62005-01-04 21:38:36 +00008384 Example: >
8385 :let &path = &path . ',/usr/local/include'
Bram Moolenaar071d4272004-06-13 20:20:40 +00008386
Bram Moolenaar3a3a7232005-01-17 22:16:15 +00008387:let &{option-name} .= {expr1}
8388 For a string option: Append {expr1} to the value.
8389 Does not insert a comma like |:set+=|.
8390
8391:let &{option-name} += {expr1}
8392:let &{option-name} -= {expr1}
8393 For a number or boolean option: Add or subtract
8394 {expr1}.
8395
Bram Moolenaar071d4272004-06-13 20:20:40 +00008396:let &l:{option-name} = {expr1}
Bram Moolenaar3a3a7232005-01-17 22:16:15 +00008397:let &l:{option-name} .= {expr1}
8398:let &l:{option-name} += {expr1}
8399:let &l:{option-name} -= {expr1}
Bram Moolenaar071d4272004-06-13 20:20:40 +00008400 Like above, but only set the local value of an option
8401 (if there is one). Works like |:setlocal|.
8402
8403:let &g:{option-name} = {expr1}
Bram Moolenaar3a3a7232005-01-17 22:16:15 +00008404:let &g:{option-name} .= {expr1}
8405:let &g:{option-name} += {expr1}
8406:let &g:{option-name} -= {expr1}
Bram Moolenaar071d4272004-06-13 20:20:40 +00008407 Like above, but only set the global value of an option
8408 (if there is one). Works like |:setglobal|.
8409
Bram Moolenaar13065c42005-01-08 16:08:21 +00008410:let [{name1}, {name2}, ...] = {expr1} *:let-unpack* *E687* *E688*
Bram Moolenaar32466aa2006-02-24 23:53:04 +00008411 {expr1} must evaluate to a |List|. The first item in
Bram Moolenaarfca34d62005-01-04 21:38:36 +00008412 the list is assigned to {name1}, the second item to
8413 {name2}, etc.
8414 The number of names must match the number of items in
Bram Moolenaar32466aa2006-02-24 23:53:04 +00008415 the |List|.
Bram Moolenaarfca34d62005-01-04 21:38:36 +00008416 Each name can be one of the items of the ":let"
8417 command as mentioned above.
8418 Example: >
8419 :let [s, item] = GetItem(s)
Bram Moolenaar3a3a7232005-01-17 22:16:15 +00008420< Detail: {expr1} is evaluated first, then the
8421 assignments are done in sequence. This matters if
8422 {name2} depends on {name1}. Example: >
8423 :let x = [0, 1]
8424 :let i = 0
8425 :let [i, x[i]] = [1, 2]
8426 :echo x
8427< The result is [0, 2].
8428
8429:let [{name1}, {name2}, ...] .= {expr1}
8430:let [{name1}, {name2}, ...] += {expr1}
8431:let [{name1}, {name2}, ...] -= {expr1}
8432 Like above, but append/add/subtract the value for each
Bram Moolenaar32466aa2006-02-24 23:53:04 +00008433 |List| item.
Bram Moolenaarfca34d62005-01-04 21:38:36 +00008434
8435:let [{name}, ..., ; {lastname}] = {expr1}
Bram Moolenaar32466aa2006-02-24 23:53:04 +00008436 Like |:let-unpack| above, but the |List| may have more
Bram Moolenaar3a3a7232005-01-17 22:16:15 +00008437 items than there are names. A list of the remaining
8438 items is assigned to {lastname}. If there are no
8439 remaining items {lastname} is set to an empty list.
Bram Moolenaarfca34d62005-01-04 21:38:36 +00008440 Example: >
8441 :let [a, b; rest] = ["aval", "bval", 3, 4]
8442<
Bram Moolenaar3a3a7232005-01-17 22:16:15 +00008443:let [{name}, ..., ; {lastname}] .= {expr1}
8444:let [{name}, ..., ; {lastname}] += {expr1}
8445:let [{name}, ..., ; {lastname}] -= {expr1}
8446 Like above, but append/add/subtract the value for each
Bram Moolenaar32466aa2006-02-24 23:53:04 +00008447 |List| item.
Bram Moolenaar4a748032010-09-30 21:47:56 +02008448
8449 *E121*
Bram Moolenaar446cb832008-06-24 21:56:24 +00008450:let {var-name} .. List the value of variable {var-name}. Multiple
Bram Moolenaardcaf10e2005-01-21 11:55:25 +00008451 variable names may be given. Special names recognized
8452 here: *E738*
Bram Moolenaarca003e12006-03-17 23:19:38 +00008453 g: global variables
8454 b: local buffer variables
8455 w: local window variables
Bram Moolenaar910f66f2006-04-05 20:41:53 +00008456 t: local tab page variables
Bram Moolenaarca003e12006-03-17 23:19:38 +00008457 s: script-local variables
8458 l: local function variables
Bram Moolenaardcaf10e2005-01-21 11:55:25 +00008459 v: Vim variables.
Bram Moolenaar071d4272004-06-13 20:20:40 +00008460
Bram Moolenaard7ee7ce2005-01-03 21:02:03 +00008461:let List the values of all variables. The type of the
8462 variable is indicated before the value:
8463 <nothing> String
8464 # Number
Bram Moolenaarc9b4b052006-04-30 18:54:39 +00008465 * Funcref
Bram Moolenaar071d4272004-06-13 20:20:40 +00008466
Bram Moolenaar2ce06f62005-01-31 19:19:04 +00008467
Bram Moolenaaref2f6562007-05-06 13:32:59 +00008468:unl[et][!] {name} ... *:unlet* *:unl* *E108* *E795*
Bram Moolenaar2ce06f62005-01-31 19:19:04 +00008469 Remove the internal variable {name}. Several variable
8470 names can be given, they are all removed. The name
Bram Moolenaar32466aa2006-02-24 23:53:04 +00008471 may also be a |List| or |Dictionary| item.
Bram Moolenaar071d4272004-06-13 20:20:40 +00008472 With [!] no error message is given for non-existing
8473 variables.
Bram Moolenaar32466aa2006-02-24 23:53:04 +00008474 One or more items from a |List| can be removed: >
Bram Moolenaar9cd15162005-01-16 22:02:49 +00008475 :unlet list[3] " remove fourth item
8476 :unlet list[3:] " remove fourth item to last
Bram Moolenaar32466aa2006-02-24 23:53:04 +00008477< One item from a |Dictionary| can be removed at a time: >
Bram Moolenaar9cd15162005-01-16 22:02:49 +00008478 :unlet dict['two']
8479 :unlet dict.two
Bram Moolenaarc236c162008-07-13 17:41:49 +00008480< This is especially useful to clean up used global
8481 variables and script-local variables (these are not
8482 deleted when the script ends). Function-local
8483 variables are automatically deleted when the function
8484 ends.
Bram Moolenaar071d4272004-06-13 20:20:40 +00008485
Bram Moolenaar2ce06f62005-01-31 19:19:04 +00008486:lockv[ar][!] [depth] {name} ... *:lockvar* *:lockv*
8487 Lock the internal variable {name}. Locking means that
8488 it can no longer be changed (until it is unlocked).
8489 A locked variable can be deleted: >
8490 :lockvar v
8491 :let v = 'asdf' " fails!
8492 :unlet v
8493< *E741*
8494 If you try to change a locked variable you get an
Bram Moolenaar8a94d872015-01-25 13:02:57 +01008495 error message: "E741: Value is locked: {name}"
Bram Moolenaar2ce06f62005-01-31 19:19:04 +00008496
Bram Moolenaar32466aa2006-02-24 23:53:04 +00008497 [depth] is relevant when locking a |List| or
8498 |Dictionary|. It specifies how deep the locking goes:
8499 1 Lock the |List| or |Dictionary| itself,
Bram Moolenaar2ce06f62005-01-31 19:19:04 +00008500 cannot add or remove items, but can
8501 still change their values.
8502 2 Also lock the values, cannot change
Bram Moolenaar32466aa2006-02-24 23:53:04 +00008503 the items. If an item is a |List| or
8504 |Dictionary|, cannot add or remove
Bram Moolenaar2ce06f62005-01-31 19:19:04 +00008505 items, but can still change the
8506 values.
Bram Moolenaar32466aa2006-02-24 23:53:04 +00008507 3 Like 2 but for the |List| /
8508 |Dictionary| in the |List| /
8509 |Dictionary|, one level deeper.
8510 The default [depth] is 2, thus when {name} is a |List|
8511 or |Dictionary| the values cannot be changed.
Bram Moolenaar2ce06f62005-01-31 19:19:04 +00008512 *E743*
8513 For unlimited depth use [!] and omit [depth].
8514 However, there is a maximum depth of 100 to catch
8515 loops.
8516
Bram Moolenaar32466aa2006-02-24 23:53:04 +00008517 Note that when two variables refer to the same |List|
8518 and you lock one of them, the |List| will also be
Bram Moolenaar910f66f2006-04-05 20:41:53 +00008519 locked when used through the other variable.
8520 Example: >
Bram Moolenaar2ce06f62005-01-31 19:19:04 +00008521 :let l = [0, 1, 2, 3]
8522 :let cl = l
8523 :lockvar l
8524 :let cl[1] = 99 " won't work!
8525< You may want to make a copy of a list to avoid this.
8526 See |deepcopy()|.
8527
8528
8529:unlo[ckvar][!] [depth] {name} ... *:unlockvar* *:unlo*
8530 Unlock the internal variable {name}. Does the
8531 opposite of |:lockvar|.
8532
8533
Bram Moolenaar071d4272004-06-13 20:20:40 +00008534:if {expr1} *:if* *:endif* *:en* *E171* *E579* *E580*
8535:en[dif] Execute the commands until the next matching ":else"
8536 or ":endif" if {expr1} evaluates to non-zero.
8537
8538 From Vim version 4.5 until 5.0, every Ex command in
8539 between the ":if" and ":endif" is ignored. These two
8540 commands were just to allow for future expansions in a
Bram Moolenaar85084ef2016-01-17 22:26:33 +01008541 backward compatible way. Nesting was allowed. Note
Bram Moolenaar071d4272004-06-13 20:20:40 +00008542 that any ":else" or ":elseif" was ignored, the "else"
8543 part was not executed either.
8544
8545 You can use this to remain compatible with older
8546 versions: >
8547 :if version >= 500
8548 : version-5-specific-commands
8549 :endif
8550< The commands still need to be parsed to find the
8551 "endif". Sometimes an older Vim has a problem with a
8552 new command. For example, ":silent" is recognized as
8553 a ":substitute" command. In that case ":execute" can
8554 avoid problems: >
8555 :if version >= 600
8556 : execute "silent 1,$delete"
8557 :endif
8558<
8559 NOTE: The ":append" and ":insert" commands don't work
8560 properly in between ":if" and ":endif".
8561
8562 *:else* *:el* *E581* *E583*
8563:el[se] Execute the commands until the next matching ":else"
8564 or ":endif" if they previously were not being
8565 executed.
8566
8567 *:elseif* *:elsei* *E582* *E584*
8568:elsei[f] {expr1} Short for ":else" ":if", with the addition that there
8569 is no extra ":endif".
8570
8571:wh[ile] {expr1} *:while* *:endwhile* *:wh* *:endw*
Bram Moolenaar3a3a7232005-01-17 22:16:15 +00008572 *E170* *E585* *E588* *E733*
Bram Moolenaar071d4272004-06-13 20:20:40 +00008573:endw[hile] Repeat the commands between ":while" and ":endwhile",
8574 as long as {expr1} evaluates to non-zero.
8575 When an error is detected from a command inside the
8576 loop, execution continues after the "endwhile".
Bram Moolenaar12805862005-01-05 22:16:17 +00008577 Example: >
8578 :let lnum = 1
8579 :while lnum <= line("$")
8580 :call FixLine(lnum)
8581 :let lnum = lnum + 1
8582 :endwhile
8583<
Bram Moolenaar071d4272004-06-13 20:20:40 +00008584 NOTE: The ":append" and ":insert" commands don't work
Bram Moolenaard8b02732005-01-14 21:48:43 +00008585 properly inside a ":while" and ":for" loop.
Bram Moolenaar071d4272004-06-13 20:20:40 +00008586
Bram Moolenaar3a3a7232005-01-17 22:16:15 +00008587:for {var} in {list} *:for* *E690* *E732*
Bram Moolenaar12805862005-01-05 22:16:17 +00008588:endfo[r] *:endfo* *:endfor*
8589 Repeat the commands between ":for" and ":endfor" for
Bram Moolenaar3a7c85b2005-02-05 21:39:53 +00008590 each item in {list}. Variable {var} is set to the
Bram Moolenaarde8866b2005-01-06 23:24:37 +00008591 value of each item.
8592 When an error is detected for a command inside the
Bram Moolenaar12805862005-01-05 22:16:17 +00008593 loop, execution continues after the "endfor".
Bram Moolenaar572cb562005-08-05 21:35:02 +00008594 Changing {list} inside the loop affects what items are
8595 used. Make a copy if this is unwanted: >
Bram Moolenaarde8866b2005-01-06 23:24:37 +00008596 :for item in copy(mylist)
8597< When not making a copy, Vim stores a reference to the
8598 next item in the list, before executing the commands
Bram Moolenaar446cb832008-06-24 21:56:24 +00008599 with the current item. Thus the current item can be
Bram Moolenaarde8866b2005-01-06 23:24:37 +00008600 removed without effect. Removing any later item means
8601 it will not be found. Thus the following example
8602 works (an inefficient way to make a list empty): >
Bram Moolenaar8f3f58f2010-01-06 20:52:26 +01008603 for item in mylist
8604 call remove(mylist, 0)
8605 endfor
Bram Moolenaar9588a0f2005-01-08 21:45:39 +00008606< Note that reordering the list (e.g., with sort() or
8607 reverse()) may have unexpected effects.
Bram Moolenaar12805862005-01-05 22:16:17 +00008608
Bram Moolenaar12805862005-01-05 22:16:17 +00008609:for [{var1}, {var2}, ...] in {listlist}
8610:endfo[r]
8611 Like ":for" above, but each item in {listlist} must be
8612 a list, of which each item is assigned to {var1},
8613 {var2}, etc. Example: >
8614 :for [lnum, col] in [[1, 3], [2, 5], [3, 8]]
8615 :echo getline(lnum)[col]
8616 :endfor
8617<
Bram Moolenaar071d4272004-06-13 20:20:40 +00008618 *:continue* *:con* *E586*
Bram Moolenaar12805862005-01-05 22:16:17 +00008619:con[tinue] When used inside a ":while" or ":for" loop, jumps back
8620 to the start of the loop.
8621 If it is used after a |:try| inside the loop but
8622 before the matching |:finally| (if present), the
8623 commands following the ":finally" up to the matching
8624 |:endtry| are executed first. This process applies to
8625 all nested ":try"s inside the loop. The outermost
8626 ":endtry" then jumps back to the start of the loop.
Bram Moolenaar071d4272004-06-13 20:20:40 +00008627
8628 *:break* *:brea* *E587*
Bram Moolenaar12805862005-01-05 22:16:17 +00008629:brea[k] When used inside a ":while" or ":for" loop, skips to
8630 the command after the matching ":endwhile" or
8631 ":endfor".
8632 If it is used after a |:try| inside the loop but
8633 before the matching |:finally| (if present), the
8634 commands following the ":finally" up to the matching
8635 |:endtry| are executed first. This process applies to
8636 all nested ":try"s inside the loop. The outermost
8637 ":endtry" then jumps to the command after the loop.
Bram Moolenaar071d4272004-06-13 20:20:40 +00008638
8639:try *:try* *:endt* *:endtry* *E600* *E601* *E602*
8640:endt[ry] Change the error handling for the commands between
8641 ":try" and ":endtry" including everything being
8642 executed across ":source" commands, function calls,
8643 or autocommand invocations.
8644
8645 When an error or interrupt is detected and there is
8646 a |:finally| command following, execution continues
8647 after the ":finally". Otherwise, or when the
8648 ":endtry" is reached thereafter, the next
8649 (dynamically) surrounding ":try" is checked for
8650 a corresponding ":finally" etc. Then the script
8651 processing is terminated. (Whether a function
8652 definition has an "abort" argument does not matter.)
8653 Example: >
8654 :try | edit too much | finally | echo "cleanup" | endtry
8655 :echo "impossible" " not reached, script terminated above
8656<
8657 Moreover, an error or interrupt (dynamically) inside
8658 ":try" and ":endtry" is converted to an exception. It
8659 can be caught as if it were thrown by a |:throw|
8660 command (see |:catch|). In this case, the script
8661 processing is not terminated.
8662
8663 The value "Vim:Interrupt" is used for an interrupt
8664 exception. An error in a Vim command is converted
8665 to a value of the form "Vim({command}):{errmsg}",
8666 other errors are converted to a value of the form
8667 "Vim:{errmsg}". {command} is the full command name,
8668 and {errmsg} is the message that is displayed if the
8669 error exception is not caught, always beginning with
8670 the error number.
8671 Examples: >
8672 :try | sleep 100 | catch /^Vim:Interrupt$/ | endtry
8673 :try | edit | catch /^Vim(edit):E\d\+/ | echo "error" | endtry
8674<
8675 *:cat* *:catch* *E603* *E604* *E605*
Bram Moolenaar8f3f58f2010-01-06 20:52:26 +01008676:cat[ch] /{pattern}/ The following commands until the next |:catch|,
Bram Moolenaar071d4272004-06-13 20:20:40 +00008677 |:finally|, or |:endtry| that belongs to the same
8678 |:try| as the ":catch" are executed when an exception
8679 matching {pattern} is being thrown and has not yet
8680 been caught by a previous ":catch". Otherwise, these
8681 commands are skipped.
8682 When {pattern} is omitted all errors are caught.
8683 Examples: >
8684 :catch /^Vim:Interrupt$/ " catch interrupts (CTRL-C)
8685 :catch /^Vim\%((\a\+)\)\=:E/ " catch all Vim errors
8686 :catch /^Vim\%((\a\+)\)\=:/ " catch errors and interrupts
8687 :catch /^Vim(write):/ " catch all errors in :write
8688 :catch /^Vim\%((\a\+)\)\=:E123/ " catch error E123
8689 :catch /my-exception/ " catch user exception
8690 :catch /.*/ " catch everything
8691 :catch " same as /.*/
8692<
8693 Another character can be used instead of / around the
8694 {pattern}, so long as it does not have a special
8695 meaning (e.g., '|' or '"') and doesn't occur inside
8696 {pattern}.
Bram Moolenaar7e38ea22014-04-05 22:55:53 +02008697 Information about the exception is available in
8698 |v:exception|. Also see |throw-variables|.
Bram Moolenaar071d4272004-06-13 20:20:40 +00008699 NOTE: It is not reliable to ":catch" the TEXT of
8700 an error message because it may vary in different
8701 locales.
8702
8703 *:fina* *:finally* *E606* *E607*
8704:fina[lly] The following commands until the matching |:endtry|
8705 are executed whenever the part between the matching
8706 |:try| and the ":finally" is left: either by falling
8707 through to the ":finally" or by a |:continue|,
8708 |:break|, |:finish|, or |:return|, or by an error or
8709 interrupt or exception (see |:throw|).
8710
8711 *:th* *:throw* *E608*
8712:th[row] {expr1} The {expr1} is evaluated and thrown as an exception.
8713 If the ":throw" is used after a |:try| but before the
8714 first corresponding |:catch|, commands are skipped
8715 until the first ":catch" matching {expr1} is reached.
8716 If there is no such ":catch" or if the ":throw" is
8717 used after a ":catch" but before the |:finally|, the
8718 commands following the ":finally" (if present) up to
8719 the matching |:endtry| are executed. If the ":throw"
8720 is after the ":finally", commands up to the ":endtry"
8721 are skipped. At the ":endtry", this process applies
8722 again for the next dynamically surrounding ":try"
8723 (which may be found in a calling function or sourcing
8724 script), until a matching ":catch" has been found.
8725 If the exception is not caught, the command processing
8726 is terminated.
8727 Example: >
8728 :try | throw "oops" | catch /^oo/ | echo "caught" | endtry
Bram Moolenaar662db672011-03-22 14:05:35 +01008729< Note that "catch" may need to be on a separate line
8730 for when an error causes the parsing to skip the whole
8731 line and not see the "|" that separates the commands.
Bram Moolenaar071d4272004-06-13 20:20:40 +00008732
8733 *:ec* *:echo*
8734:ec[ho] {expr1} .. Echoes each {expr1}, with a space in between. The
8735 first {expr1} starts on a new line.
8736 Also see |:comment|.
8737 Use "\n" to start a new line. Use "\r" to move the
8738 cursor to the first column.
8739 Uses the highlighting set by the |:echohl| command.
8740 Cannot be followed by a comment.
8741 Example: >
8742 :echo "the value of 'shell' is" &shell
Bram Moolenaaref2f6562007-05-06 13:32:59 +00008743< *:echo-redraw*
8744 A later redraw may make the message disappear again.
8745 And since Vim mostly postpones redrawing until it's
8746 finished with a sequence of commands this happens
8747 quite often. To avoid that a command from before the
8748 ":echo" causes a redraw afterwards (redraws are often
8749 postponed until you type something), force a redraw
8750 with the |:redraw| command. Example: >
Bram Moolenaar071d4272004-06-13 20:20:40 +00008751 :new | redraw | echo "there is a new window"
8752<
8753 *:echon*
8754:echon {expr1} .. Echoes each {expr1}, without anything added. Also see
8755 |:comment|.
8756 Uses the highlighting set by the |:echohl| command.
8757 Cannot be followed by a comment.
8758 Example: >
8759 :echon "the value of 'shell' is " &shell
8760<
8761 Note the difference between using ":echo", which is a
8762 Vim command, and ":!echo", which is an external shell
8763 command: >
8764 :!echo % --> filename
8765< The arguments of ":!" are expanded, see |:_%|. >
8766 :!echo "%" --> filename or "filename"
8767< Like the previous example. Whether you see the double
8768 quotes or not depends on your 'shell'. >
8769 :echo % --> nothing
8770< The '%' is an illegal character in an expression. >
8771 :echo "%" --> %
8772< This just echoes the '%' character. >
8773 :echo expand("%") --> filename
8774< This calls the expand() function to expand the '%'.
8775
8776 *:echoh* *:echohl*
8777:echoh[l] {name} Use the highlight group {name} for the following
8778 |:echo|, |:echon| and |:echomsg| commands. Also used
8779 for the |input()| prompt. Example: >
8780 :echohl WarningMsg | echo "Don't panic!" | echohl None
8781< Don't forget to set the group back to "None",
8782 otherwise all following echo's will be highlighted.
8783
8784 *:echom* *:echomsg*
8785:echom[sg] {expr1} .. Echo the expression(s) as a true message, saving the
8786 message in the |message-history|.
8787 Spaces are placed between the arguments as with the
8788 |:echo| command. But unprintable characters are
8789 displayed, not interpreted.
Bram Moolenaaref2f6562007-05-06 13:32:59 +00008790 The parsing works slightly different from |:echo|,
8791 more like |:execute|. All the expressions are first
8792 evaluated and concatenated before echoing anything.
8793 The expressions must evaluate to a Number or String, a
8794 Dictionary or List causes an error.
Bram Moolenaar071d4272004-06-13 20:20:40 +00008795 Uses the highlighting set by the |:echohl| command.
8796 Example: >
8797 :echomsg "It's a Zizzer Zazzer Zuzz, as you can plainly see."
Bram Moolenaaref2f6562007-05-06 13:32:59 +00008798< See |:echo-redraw| to avoid the message disappearing
8799 when the screen is redrawn.
Bram Moolenaar071d4272004-06-13 20:20:40 +00008800 *:echoe* *:echoerr*
8801:echoe[rr] {expr1} .. Echo the expression(s) as an error message, saving the
8802 message in the |message-history|. When used in a
8803 script or function the line number will be added.
8804 Spaces are placed between the arguments as with the
Bram Moolenaar446cb832008-06-24 21:56:24 +00008805 :echo command. When used inside a try conditional,
Bram Moolenaar071d4272004-06-13 20:20:40 +00008806 the message is raised as an error exception instead
8807 (see |try-echoerr|).
8808 Example: >
8809 :echoerr "This script just failed!"
8810< If you just want a highlighted message use |:echohl|.
8811 And to get a beep: >
8812 :exe "normal \<Esc>"
8813<
8814 *:exe* *:execute*
8815:exe[cute] {expr1} .. Executes the string that results from the evaluation
Bram Moolenaar00a927d2010-05-14 23:24:24 +02008816 of {expr1} as an Ex command.
8817 Multiple arguments are concatenated, with a space in
8818 between. To avoid the extra space use the "."
8819 operator to concatenate strings into one argument.
8820 {expr1} is used as the processed command, command line
8821 editing keys are not recognized.
Bram Moolenaar071d4272004-06-13 20:20:40 +00008822 Cannot be followed by a comment.
8823 Examples: >
Bram Moolenaar00a927d2010-05-14 23:24:24 +02008824 :execute "buffer" nextbuf
8825 :execute "normal" count . "w"
Bram Moolenaar071d4272004-06-13 20:20:40 +00008826<
8827 ":execute" can be used to append a command to commands
8828 that don't accept a '|'. Example: >
8829 :execute '!ls' | echo "theend"
8830
8831< ":execute" is also a nice way to avoid having to type
8832 control characters in a Vim script for a ":normal"
8833 command: >
8834 :execute "normal ixxx\<Esc>"
8835< This has an <Esc> character, see |expr-string|.
8836
Bram Moolenaar446cb832008-06-24 21:56:24 +00008837 Be careful to correctly escape special characters in
8838 file names. The |fnameescape()| function can be used
Bram Moolenaar05bb9532008-07-04 09:44:11 +00008839 for Vim commands, |shellescape()| for |:!| commands.
8840 Examples: >
Bram Moolenaar446cb832008-06-24 21:56:24 +00008841 :execute "e " . fnameescape(filename)
Bram Moolenaar251835e2014-02-24 02:51:51 +01008842 :execute "!ls " . shellescape(filename, 1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008843<
Bram Moolenaar071d4272004-06-13 20:20:40 +00008844 Note: The executed string may be any command-line, but
Bram Moolenaar76f3b1a2014-03-27 22:30:07 +01008845 starting or ending "if", "while" and "for" does not
8846 always work, because when commands are skipped the
8847 ":execute" is not evaluated and Vim loses track of
8848 where blocks start and end. Also "break" and
8849 "continue" should not be inside ":execute".
8850 This example does not work, because the ":execute" is
8851 not evaluated and Vim does not see the "while", and
8852 gives an error for finding an ":endwhile": >
8853 :if 0
8854 : execute 'while i > 5'
8855 : echo "test"
8856 : endwhile
8857 :endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008858<
8859 It is allowed to have a "while" or "if" command
8860 completely in the executed string: >
8861 :execute 'while i < 5 | echo i | let i = i + 1 | endwhile'
8862<
8863
Bram Moolenaar8f3f58f2010-01-06 20:52:26 +01008864 *:exe-comment*
Bram Moolenaar071d4272004-06-13 20:20:40 +00008865 ":execute", ":echo" and ":echon" cannot be followed by
8866 a comment directly, because they see the '"' as the
8867 start of a string. But, you can use '|' followed by a
8868 comment. Example: >
8869 :echo "foo" | "this is a comment
8870
8871==============================================================================
88728. Exception handling *exception-handling*
8873
8874The Vim script language comprises an exception handling feature. This section
8875explains how it can be used in a Vim script.
8876
8877Exceptions may be raised by Vim on an error or on interrupt, see
8878|catch-errors| and |catch-interrupt|. You can also explicitly throw an
8879exception by using the ":throw" command, see |throw-catch|.
8880
8881
8882TRY CONDITIONALS *try-conditionals*
8883
8884Exceptions can be caught or can cause cleanup code to be executed. You can
8885use a try conditional to specify catch clauses (that catch exceptions) and/or
8886a finally clause (to be executed for cleanup).
8887 A try conditional begins with a |:try| command and ends at the matching
8888|:endtry| command. In between, you can use a |:catch| command to start
8889a catch clause, or a |:finally| command to start a finally clause. There may
8890be none or multiple catch clauses, but there is at most one finally clause,
8891which must not be followed by any catch clauses. The lines before the catch
8892clauses and the finally clause is called a try block. >
8893
8894 :try
Bram Moolenaar446cb832008-06-24 21:56:24 +00008895 : ...
8896 : ... TRY BLOCK
8897 : ...
Bram Moolenaar071d4272004-06-13 20:20:40 +00008898 :catch /{pattern}/
Bram Moolenaar446cb832008-06-24 21:56:24 +00008899 : ...
8900 : ... CATCH CLAUSE
8901 : ...
Bram Moolenaar071d4272004-06-13 20:20:40 +00008902 :catch /{pattern}/
Bram Moolenaar446cb832008-06-24 21:56:24 +00008903 : ...
8904 : ... CATCH CLAUSE
8905 : ...
Bram Moolenaar071d4272004-06-13 20:20:40 +00008906 :finally
Bram Moolenaar446cb832008-06-24 21:56:24 +00008907 : ...
8908 : ... FINALLY CLAUSE
8909 : ...
Bram Moolenaar071d4272004-06-13 20:20:40 +00008910 :endtry
8911
8912The try conditional allows to watch code for exceptions and to take the
8913appropriate actions. Exceptions from the try block may be caught. Exceptions
8914from the try block and also the catch clauses may cause cleanup actions.
8915 When no exception is thrown during execution of the try block, the control
8916is transferred to the finally clause, if present. After its execution, the
8917script continues with the line following the ":endtry".
8918 When an exception occurs during execution of the try block, the remaining
8919lines in the try block are skipped. The exception is matched against the
8920patterns specified as arguments to the ":catch" commands. The catch clause
8921after the first matching ":catch" is taken, other catch clauses are not
8922executed. The catch clause ends when the next ":catch", ":finally", or
8923":endtry" command is reached - whatever is first. Then, the finally clause
8924(if present) is executed. When the ":endtry" is reached, the script execution
8925continues in the following line as usual.
8926 When an exception that does not match any of the patterns specified by the
8927":catch" commands is thrown in the try block, the exception is not caught by
8928that try conditional and none of the catch clauses is executed. Only the
8929finally clause, if present, is taken. The exception pends during execution of
8930the finally clause. It is resumed at the ":endtry", so that commands after
8931the ":endtry" are not executed and the exception might be caught elsewhere,
8932see |try-nesting|.
8933 When during execution of a catch clause another exception is thrown, the
Bram Moolenaar446cb832008-06-24 21:56:24 +00008934remaining lines in that catch clause are not executed. The new exception is
Bram Moolenaar071d4272004-06-13 20:20:40 +00008935not matched against the patterns in any of the ":catch" commands of the same
8936try conditional and none of its catch clauses is taken. If there is, however,
8937a finally clause, it is executed, and the exception pends during its
8938execution. The commands following the ":endtry" are not executed. The new
8939exception might, however, be caught elsewhere, see |try-nesting|.
8940 When during execution of the finally clause (if present) an exception is
Bram Moolenaar446cb832008-06-24 21:56:24 +00008941thrown, the remaining lines in the finally clause are skipped. If the finally
Bram Moolenaar071d4272004-06-13 20:20:40 +00008942clause has been taken because of an exception from the try block or one of the
8943catch clauses, the original (pending) exception is discarded. The commands
8944following the ":endtry" are not executed, and the exception from the finally
8945clause is propagated and can be caught elsewhere, see |try-nesting|.
8946
8947The finally clause is also executed, when a ":break" or ":continue" for
8948a ":while" loop enclosing the complete try conditional is executed from the
8949try block or a catch clause. Or when a ":return" or ":finish" is executed
8950from the try block or a catch clause of a try conditional in a function or
8951sourced script, respectively. The ":break", ":continue", ":return", or
8952":finish" pends during execution of the finally clause and is resumed when the
8953":endtry" is reached. It is, however, discarded when an exception is thrown
8954from the finally clause.
8955 When a ":break" or ":continue" for a ":while" loop enclosing the complete
8956try conditional or when a ":return" or ":finish" is encountered in the finally
8957clause, the rest of the finally clause is skipped, and the ":break",
8958":continue", ":return" or ":finish" is executed as usual. If the finally
8959clause has been taken because of an exception or an earlier ":break",
8960":continue", ":return", or ":finish" from the try block or a catch clause,
8961this pending exception or command is discarded.
8962
8963For examples see |throw-catch| and |try-finally|.
8964
8965
8966NESTING OF TRY CONDITIONALS *try-nesting*
8967
8968Try conditionals can be nested arbitrarily. That is, a complete try
8969conditional can be put into the try block, a catch clause, or the finally
8970clause of another try conditional. If the inner try conditional does not
8971catch an exception thrown in its try block or throws a new exception from one
8972of its catch clauses or its finally clause, the outer try conditional is
8973checked according to the rules above. If the inner try conditional is in the
8974try block of the outer try conditional, its catch clauses are checked, but
Bram Moolenaar446cb832008-06-24 21:56:24 +00008975otherwise only the finally clause is executed. It does not matter for
Bram Moolenaar071d4272004-06-13 20:20:40 +00008976nesting, whether the inner try conditional is directly contained in the outer
8977one, or whether the outer one sources a script or calls a function containing
8978the inner try conditional.
8979
8980When none of the active try conditionals catches an exception, just their
8981finally clauses are executed. Thereafter, the script processing terminates.
8982An error message is displayed in case of an uncaught exception explicitly
8983thrown by a ":throw" command. For uncaught error and interrupt exceptions
8984implicitly raised by Vim, the error message(s) or interrupt message are shown
8985as usual.
8986
8987For examples see |throw-catch|.
8988
8989
8990EXAMINING EXCEPTION HANDLING CODE *except-examine*
8991
8992Exception handling code can get tricky. If you are in doubt what happens, set
8993'verbose' to 13 or use the ":13verbose" command modifier when sourcing your
8994script file. Then you see when an exception is thrown, discarded, caught, or
8995finished. When using a verbosity level of at least 14, things pending in
8996a finally clause are also shown. This information is also given in debug mode
8997(see |debug-scripts|).
8998
8999
9000THROWING AND CATCHING EXCEPTIONS *throw-catch*
9001
9002You can throw any number or string as an exception. Use the |:throw| command
9003and pass the value to be thrown as argument: >
9004 :throw 4711
9005 :throw "string"
9006< *throw-expression*
9007You can also specify an expression argument. The expression is then evaluated
9008first, and the result is thrown: >
9009 :throw 4705 + strlen("string")
9010 :throw strpart("strings", 0, 6)
9011
9012An exception might be thrown during evaluation of the argument of the ":throw"
9013command. Unless it is caught there, the expression evaluation is abandoned.
9014The ":throw" command then does not throw a new exception.
9015 Example: >
9016
9017 :function! Foo(arg)
9018 : try
9019 : throw a:arg
9020 : catch /foo/
9021 : endtry
9022 : return 1
9023 :endfunction
9024 :
9025 :function! Bar()
9026 : echo "in Bar"
9027 : return 4710
9028 :endfunction
9029 :
9030 :throw Foo("arrgh") + Bar()
9031
9032This throws "arrgh", and "in Bar" is not displayed since Bar() is not
9033executed. >
9034 :throw Foo("foo") + Bar()
9035however displays "in Bar" and throws 4711.
9036
9037Any other command that takes an expression as argument might also be
Bram Moolenaar446cb832008-06-24 21:56:24 +00009038abandoned by an (uncaught) exception during the expression evaluation. The
Bram Moolenaar071d4272004-06-13 20:20:40 +00009039exception is then propagated to the caller of the command.
9040 Example: >
9041
9042 :if Foo("arrgh")
9043 : echo "then"
9044 :else
9045 : echo "else"
9046 :endif
9047
9048Here neither of "then" or "else" is displayed.
9049
9050 *catch-order*
9051Exceptions can be caught by a try conditional with one or more |:catch|
9052commands, see |try-conditionals|. The values to be caught by each ":catch"
9053command can be specified as a pattern argument. The subsequent catch clause
9054gets executed when a matching exception is caught.
9055 Example: >
9056
9057 :function! Foo(value)
9058 : try
9059 : throw a:value
9060 : catch /^\d\+$/
9061 : echo "Number thrown"
9062 : catch /.*/
9063 : echo "String thrown"
9064 : endtry
9065 :endfunction
9066 :
9067 :call Foo(0x1267)
9068 :call Foo('string')
9069
9070The first call to Foo() displays "Number thrown", the second "String thrown".
9071An exception is matched against the ":catch" commands in the order they are
9072specified. Only the first match counts. So you should place the more
9073specific ":catch" first. The following order does not make sense: >
9074
9075 : catch /.*/
9076 : echo "String thrown"
9077 : catch /^\d\+$/
9078 : echo "Number thrown"
9079
9080The first ":catch" here matches always, so that the second catch clause is
9081never taken.
9082
9083 *throw-variables*
9084If you catch an exception by a general pattern, you may access the exact value
9085in the variable |v:exception|: >
9086
9087 : catch /^\d\+$/
9088 : echo "Number thrown. Value is" v:exception
9089
9090You may also be interested where an exception was thrown. This is stored in
9091|v:throwpoint|. Note that "v:exception" and "v:throwpoint" are valid for the
9092exception most recently caught as long it is not finished.
9093 Example: >
9094
9095 :function! Caught()
9096 : if v:exception != ""
9097 : echo 'Caught "' . v:exception . '" in ' . v:throwpoint
9098 : else
9099 : echo 'Nothing caught'
9100 : endif
9101 :endfunction
9102 :
9103 :function! Foo()
9104 : try
9105 : try
9106 : try
9107 : throw 4711
9108 : finally
9109 : call Caught()
9110 : endtry
9111 : catch /.*/
9112 : call Caught()
9113 : throw "oops"
9114 : endtry
9115 : catch /.*/
9116 : call Caught()
9117 : finally
9118 : call Caught()
9119 : endtry
9120 :endfunction
9121 :
9122 :call Foo()
9123
9124This displays >
9125
9126 Nothing caught
9127 Caught "4711" in function Foo, line 4
9128 Caught "oops" in function Foo, line 10
9129 Nothing caught
9130
9131A practical example: The following command ":LineNumber" displays the line
9132number in the script or function where it has been used: >
9133
9134 :function! LineNumber()
9135 : return substitute(v:throwpoint, '.*\D\(\d\+\).*', '\1', "")
9136 :endfunction
9137 :command! LineNumber try | throw "" | catch | echo LineNumber() | endtry
9138<
9139 *try-nested*
9140An exception that is not caught by a try conditional can be caught by
9141a surrounding try conditional: >
9142
9143 :try
9144 : try
9145 : throw "foo"
9146 : catch /foobar/
9147 : echo "foobar"
9148 : finally
9149 : echo "inner finally"
9150 : endtry
9151 :catch /foo/
9152 : echo "foo"
9153 :endtry
9154
9155The inner try conditional does not catch the exception, just its finally
9156clause is executed. The exception is then caught by the outer try
9157conditional. The example displays "inner finally" and then "foo".
9158
9159 *throw-from-catch*
9160You can catch an exception and throw a new one to be caught elsewhere from the
9161catch clause: >
9162
9163 :function! Foo()
9164 : throw "foo"
9165 :endfunction
9166 :
9167 :function! Bar()
9168 : try
9169 : call Foo()
9170 : catch /foo/
9171 : echo "Caught foo, throw bar"
9172 : throw "bar"
9173 : endtry
9174 :endfunction
9175 :
9176 :try
9177 : call Bar()
9178 :catch /.*/
9179 : echo "Caught" v:exception
9180 :endtry
9181
9182This displays "Caught foo, throw bar" and then "Caught bar".
9183
9184 *rethrow*
9185There is no real rethrow in the Vim script language, but you may throw
9186"v:exception" instead: >
9187
9188 :function! Bar()
9189 : try
9190 : call Foo()
9191 : catch /.*/
9192 : echo "Rethrow" v:exception
9193 : throw v:exception
9194 : endtry
9195 :endfunction
9196< *try-echoerr*
9197Note that this method cannot be used to "rethrow" Vim error or interrupt
9198exceptions, because it is not possible to fake Vim internal exceptions.
9199Trying so causes an error exception. You should throw your own exception
9200denoting the situation. If you want to cause a Vim error exception containing
9201the original error exception value, you can use the |:echoerr| command: >
9202
9203 :try
9204 : try
9205 : asdf
9206 : catch /.*/
9207 : echoerr v:exception
9208 : endtry
9209 :catch /.*/
9210 : echo v:exception
9211 :endtry
9212
9213This code displays
9214
Bram Moolenaar446cb832008-06-24 21:56:24 +00009215 Vim(echoerr):Vim:E492: Not an editor command: asdf ~
Bram Moolenaar071d4272004-06-13 20:20:40 +00009216
9217
9218CLEANUP CODE *try-finally*
9219
9220Scripts often change global settings and restore them at their end. If the
9221user however interrupts the script by pressing CTRL-C, the settings remain in
Bram Moolenaar446cb832008-06-24 21:56:24 +00009222an inconsistent state. The same may happen to you in the development phase of
Bram Moolenaar071d4272004-06-13 20:20:40 +00009223a script when an error occurs or you explicitly throw an exception without
9224catching it. You can solve these problems by using a try conditional with
9225a finally clause for restoring the settings. Its execution is guaranteed on
9226normal control flow, on error, on an explicit ":throw", and on interrupt.
9227(Note that errors and interrupts from inside the try conditional are converted
Bram Moolenaar446cb832008-06-24 21:56:24 +00009228to exceptions. When not caught, they terminate the script after the finally
Bram Moolenaar071d4272004-06-13 20:20:40 +00009229clause has been executed.)
9230Example: >
9231
9232 :try
9233 : let s:saved_ts = &ts
9234 : set ts=17
9235 :
9236 : " Do the hard work here.
9237 :
9238 :finally
9239 : let &ts = s:saved_ts
9240 : unlet s:saved_ts
9241 :endtry
9242
9243This method should be used locally whenever a function or part of a script
9244changes global settings which need to be restored on failure or normal exit of
9245that function or script part.
9246
9247 *break-finally*
9248Cleanup code works also when the try block or a catch clause is left by
9249a ":continue", ":break", ":return", or ":finish".
9250 Example: >
9251
9252 :let first = 1
9253 :while 1
9254 : try
9255 : if first
9256 : echo "first"
9257 : let first = 0
9258 : continue
9259 : else
9260 : throw "second"
9261 : endif
9262 : catch /.*/
9263 : echo v:exception
9264 : break
9265 : finally
9266 : echo "cleanup"
9267 : endtry
9268 : echo "still in while"
9269 :endwhile
9270 :echo "end"
9271
9272This displays "first", "cleanup", "second", "cleanup", and "end". >
9273
9274 :function! Foo()
9275 : try
9276 : return 4711
9277 : finally
9278 : echo "cleanup\n"
9279 : endtry
9280 : echo "Foo still active"
9281 :endfunction
9282 :
9283 :echo Foo() "returned by Foo"
9284
9285This displays "cleanup" and "4711 returned by Foo". You don't need to add an
Bram Moolenaar446cb832008-06-24 21:56:24 +00009286extra ":return" in the finally clause. (Above all, this would override the
Bram Moolenaar071d4272004-06-13 20:20:40 +00009287return value.)
9288
9289 *except-from-finally*
9290Using either of ":continue", ":break", ":return", ":finish", or ":throw" in
9291a finally clause is possible, but not recommended since it abandons the
9292cleanup actions for the try conditional. But, of course, interrupt and error
9293exceptions might get raised from a finally clause.
9294 Example where an error in the finally clause stops an interrupt from
9295working correctly: >
9296
9297 :try
9298 : try
9299 : echo "Press CTRL-C for interrupt"
9300 : while 1
9301 : endwhile
9302 : finally
9303 : unlet novar
9304 : endtry
9305 :catch /novar/
9306 :endtry
9307 :echo "Script still running"
9308 :sleep 1
9309
9310If you need to put commands that could fail into a finally clause, you should
9311think about catching or ignoring the errors in these commands, see
9312|catch-errors| and |ignore-errors|.
9313
9314
9315CATCHING ERRORS *catch-errors*
9316
9317If you want to catch specific errors, you just have to put the code to be
9318watched in a try block and add a catch clause for the error message. The
9319presence of the try conditional causes all errors to be converted to an
9320exception. No message is displayed and |v:errmsg| is not set then. To find
9321the right pattern for the ":catch" command, you have to know how the format of
9322the error exception is.
9323 Error exceptions have the following format: >
9324
9325 Vim({cmdname}):{errmsg}
9326or >
9327 Vim:{errmsg}
9328
9329{cmdname} is the name of the command that failed; the second form is used when
Bram Moolenaar446cb832008-06-24 21:56:24 +00009330the command name is not known. {errmsg} is the error message usually produced
Bram Moolenaar071d4272004-06-13 20:20:40 +00009331when the error occurs outside try conditionals. It always begins with
9332a capital "E", followed by a two or three-digit error number, a colon, and
9333a space.
9334
9335Examples:
9336
9337The command >
9338 :unlet novar
9339normally produces the error message >
9340 E108: No such variable: "novar"
9341which is converted inside try conditionals to an exception >
9342 Vim(unlet):E108: No such variable: "novar"
9343
9344The command >
9345 :dwim
9346normally produces the error message >
9347 E492: Not an editor command: dwim
9348which is converted inside try conditionals to an exception >
9349 Vim:E492: Not an editor command: dwim
9350
9351You can catch all ":unlet" errors by a >
9352 :catch /^Vim(unlet):/
9353or all errors for misspelled command names by a >
9354 :catch /^Vim:E492:/
9355
9356Some error messages may be produced by different commands: >
9357 :function nofunc
9358and >
9359 :delfunction nofunc
9360both produce the error message >
9361 E128: Function name must start with a capital: nofunc
9362which is converted inside try conditionals to an exception >
9363 Vim(function):E128: Function name must start with a capital: nofunc
9364or >
9365 Vim(delfunction):E128: Function name must start with a capital: nofunc
9366respectively. You can catch the error by its number independently on the
9367command that caused it if you use the following pattern: >
9368 :catch /^Vim(\a\+):E128:/
9369
9370Some commands like >
9371 :let x = novar
9372produce multiple error messages, here: >
9373 E121: Undefined variable: novar
9374 E15: Invalid expression: novar
9375Only the first is used for the exception value, since it is the most specific
9376one (see |except-several-errors|). So you can catch it by >
9377 :catch /^Vim(\a\+):E121:/
9378
9379You can catch all errors related to the name "nofunc" by >
9380 :catch /\<nofunc\>/
9381
9382You can catch all Vim errors in the ":write" and ":read" commands by >
9383 :catch /^Vim(\(write\|read\)):E\d\+:/
9384
9385You can catch all Vim errors by the pattern >
9386 :catch /^Vim\((\a\+)\)\=:E\d\+:/
9387<
9388 *catch-text*
9389NOTE: You should never catch the error message text itself: >
9390 :catch /No such variable/
Bram Moolenaar2b8388b2015-02-28 13:11:45 +01009391only works in the English locale, but not when the user has selected
Bram Moolenaar071d4272004-06-13 20:20:40 +00009392a different language by the |:language| command. It is however helpful to
9393cite the message text in a comment: >
9394 :catch /^Vim(\a\+):E108:/ " No such variable
9395
9396
9397IGNORING ERRORS *ignore-errors*
9398
9399You can ignore errors in a specific Vim command by catching them locally: >
9400
9401 :try
9402 : write
9403 :catch
9404 :endtry
9405
9406But you are strongly recommended NOT to use this simple form, since it could
9407catch more than you want. With the ":write" command, some autocommands could
9408be executed and cause errors not related to writing, for instance: >
9409
9410 :au BufWritePre * unlet novar
9411
9412There could even be such errors you are not responsible for as a script
9413writer: a user of your script might have defined such autocommands. You would
9414then hide the error from the user.
9415 It is much better to use >
9416
9417 :try
9418 : write
9419 :catch /^Vim(write):/
9420 :endtry
9421
9422which only catches real write errors. So catch only what you'd like to ignore
9423intentionally.
9424
9425For a single command that does not cause execution of autocommands, you could
9426even suppress the conversion of errors to exceptions by the ":silent!"
9427command: >
9428 :silent! nunmap k
9429This works also when a try conditional is active.
9430
9431
9432CATCHING INTERRUPTS *catch-interrupt*
9433
9434When there are active try conditionals, an interrupt (CTRL-C) is converted to
Bram Moolenaar446cb832008-06-24 21:56:24 +00009435the exception "Vim:Interrupt". You can catch it like every exception. The
Bram Moolenaar071d4272004-06-13 20:20:40 +00009436script is not terminated, then.
9437 Example: >
9438
9439 :function! TASK1()
9440 : sleep 10
9441 :endfunction
9442
9443 :function! TASK2()
9444 : sleep 20
9445 :endfunction
9446
9447 :while 1
9448 : let command = input("Type a command: ")
9449 : try
9450 : if command == ""
9451 : continue
9452 : elseif command == "END"
9453 : break
9454 : elseif command == "TASK1"
9455 : call TASK1()
9456 : elseif command == "TASK2"
9457 : call TASK2()
9458 : else
9459 : echo "\nIllegal command:" command
9460 : continue
9461 : endif
9462 : catch /^Vim:Interrupt$/
9463 : echo "\nCommand interrupted"
9464 : " Caught the interrupt. Continue with next prompt.
9465 : endtry
9466 :endwhile
9467
9468You can interrupt a task here by pressing CTRL-C; the script then asks for
Bram Moolenaar446cb832008-06-24 21:56:24 +00009469a new command. If you press CTRL-C at the prompt, the script is terminated.
Bram Moolenaar071d4272004-06-13 20:20:40 +00009470
9471For testing what happens when CTRL-C would be pressed on a specific line in
9472your script, use the debug mode and execute the |>quit| or |>interrupt|
9473command on that line. See |debug-scripts|.
9474
9475
9476CATCHING ALL *catch-all*
9477
9478The commands >
9479
9480 :catch /.*/
9481 :catch //
9482 :catch
9483
9484catch everything, error exceptions, interrupt exceptions and exceptions
9485explicitly thrown by the |:throw| command. This is useful at the top level of
9486a script in order to catch unexpected things.
9487 Example: >
9488
9489 :try
9490 :
9491 : " do the hard work here
9492 :
9493 :catch /MyException/
9494 :
9495 : " handle known problem
9496 :
9497 :catch /^Vim:Interrupt$/
9498 : echo "Script interrupted"
9499 :catch /.*/
9500 : echo "Internal error (" . v:exception . ")"
9501 : echo " - occurred at " . v:throwpoint
9502 :endtry
9503 :" end of script
9504
9505Note: Catching all might catch more things than you want. Thus, you are
9506strongly encouraged to catch only for problems that you can really handle by
9507specifying a pattern argument to the ":catch".
9508 Example: Catching all could make it nearly impossible to interrupt a script
9509by pressing CTRL-C: >
9510
9511 :while 1
9512 : try
9513 : sleep 1
9514 : catch
9515 : endtry
9516 :endwhile
9517
9518
9519EXCEPTIONS AND AUTOCOMMANDS *except-autocmd*
9520
9521Exceptions may be used during execution of autocommands. Example: >
9522
9523 :autocmd User x try
9524 :autocmd User x throw "Oops!"
9525 :autocmd User x catch
9526 :autocmd User x echo v:exception
9527 :autocmd User x endtry
9528 :autocmd User x throw "Arrgh!"
9529 :autocmd User x echo "Should not be displayed"
9530 :
9531 :try
9532 : doautocmd User x
9533 :catch
9534 : echo v:exception
9535 :endtry
9536
9537This displays "Oops!" and "Arrgh!".
9538
9539 *except-autocmd-Pre*
9540For some commands, autocommands get executed before the main action of the
9541command takes place. If an exception is thrown and not caught in the sequence
9542of autocommands, the sequence and the command that caused its execution are
9543abandoned and the exception is propagated to the caller of the command.
9544 Example: >
9545
9546 :autocmd BufWritePre * throw "FAIL"
9547 :autocmd BufWritePre * echo "Should not be displayed"
9548 :
9549 :try
9550 : write
9551 :catch
9552 : echo "Caught:" v:exception "from" v:throwpoint
9553 :endtry
9554
9555Here, the ":write" command does not write the file currently being edited (as
9556you can see by checking 'modified'), since the exception from the BufWritePre
9557autocommand abandons the ":write". The exception is then caught and the
9558script displays: >
9559
9560 Caught: FAIL from BufWrite Auto commands for "*"
9561<
9562 *except-autocmd-Post*
9563For some commands, autocommands get executed after the main action of the
9564command has taken place. If this main action fails and the command is inside
9565an active try conditional, the autocommands are skipped and an error exception
9566is thrown that can be caught by the caller of the command.
9567 Example: >
9568
9569 :autocmd BufWritePost * echo "File successfully written!"
9570 :
9571 :try
9572 : write /i/m/p/o/s/s/i/b/l/e
9573 :catch
9574 : echo v:exception
9575 :endtry
9576
9577This just displays: >
9578
9579 Vim(write):E212: Can't open file for writing (/i/m/p/o/s/s/i/b/l/e)
9580
9581If you really need to execute the autocommands even when the main action
9582fails, trigger the event from the catch clause.
9583 Example: >
9584
9585 :autocmd BufWritePre * set noreadonly
9586 :autocmd BufWritePost * set readonly
9587 :
9588 :try
9589 : write /i/m/p/o/s/s/i/b/l/e
9590 :catch
9591 : doautocmd BufWritePost /i/m/p/o/s/s/i/b/l/e
9592 :endtry
9593<
9594You can also use ":silent!": >
9595
9596 :let x = "ok"
9597 :let v:errmsg = ""
9598 :autocmd BufWritePost * if v:errmsg != ""
9599 :autocmd BufWritePost * let x = "after fail"
9600 :autocmd BufWritePost * endif
9601 :try
9602 : silent! write /i/m/p/o/s/s/i/b/l/e
9603 :catch
9604 :endtry
9605 :echo x
9606
9607This displays "after fail".
9608
9609If the main action of the command does not fail, exceptions from the
9610autocommands will be catchable by the caller of the command: >
9611
9612 :autocmd BufWritePost * throw ":-("
9613 :autocmd BufWritePost * echo "Should not be displayed"
9614 :
9615 :try
9616 : write
9617 :catch
9618 : echo v:exception
9619 :endtry
9620<
9621 *except-autocmd-Cmd*
9622For some commands, the normal action can be replaced by a sequence of
9623autocommands. Exceptions from that sequence will be catchable by the caller
9624of the command.
9625 Example: For the ":write" command, the caller cannot know whether the file
Bram Moolenaar446cb832008-06-24 21:56:24 +00009626had actually been written when the exception occurred. You need to tell it in
Bram Moolenaar071d4272004-06-13 20:20:40 +00009627some way. >
9628
9629 :if !exists("cnt")
9630 : let cnt = 0
9631 :
9632 : autocmd BufWriteCmd * if &modified
9633 : autocmd BufWriteCmd * let cnt = cnt + 1
9634 : autocmd BufWriteCmd * if cnt % 3 == 2
9635 : autocmd BufWriteCmd * throw "BufWriteCmdError"
9636 : autocmd BufWriteCmd * endif
9637 : autocmd BufWriteCmd * write | set nomodified
9638 : autocmd BufWriteCmd * if cnt % 3 == 0
9639 : autocmd BufWriteCmd * throw "BufWriteCmdError"
9640 : autocmd BufWriteCmd * endif
9641 : autocmd BufWriteCmd * echo "File successfully written!"
9642 : autocmd BufWriteCmd * endif
9643 :endif
9644 :
9645 :try
9646 : write
9647 :catch /^BufWriteCmdError$/
9648 : if &modified
9649 : echo "Error on writing (file contents not changed)"
9650 : else
9651 : echo "Error after writing"
9652 : endif
9653 :catch /^Vim(write):/
9654 : echo "Error on writing"
9655 :endtry
9656
9657When this script is sourced several times after making changes, it displays
9658first >
9659 File successfully written!
9660then >
9661 Error on writing (file contents not changed)
9662then >
9663 Error after writing
9664etc.
9665
9666 *except-autocmd-ill*
9667You cannot spread a try conditional over autocommands for different events.
9668The following code is ill-formed: >
9669
9670 :autocmd BufWritePre * try
9671 :
9672 :autocmd BufWritePost * catch
9673 :autocmd BufWritePost * echo v:exception
9674 :autocmd BufWritePost * endtry
9675 :
9676 :write
9677
9678
9679EXCEPTION HIERARCHIES AND PARAMETERIZED EXCEPTIONS *except-hier-param*
9680
9681Some programming languages allow to use hierarchies of exception classes or to
9682pass additional information with the object of an exception class. You can do
9683similar things in Vim.
9684 In order to throw an exception from a hierarchy, just throw the complete
9685class name with the components separated by a colon, for instance throw the
9686string "EXCEPT:MATHERR:OVERFLOW" for an overflow in a mathematical library.
9687 When you want to pass additional information with your exception class, add
9688it in parentheses, for instance throw the string "EXCEPT:IO:WRITEERR(myfile)"
9689for an error when writing "myfile".
9690 With the appropriate patterns in the ":catch" command, you can catch for
9691base classes or derived classes of your hierarchy. Additional information in
9692parentheses can be cut out from |v:exception| with the ":substitute" command.
9693 Example: >
9694
9695 :function! CheckRange(a, func)
9696 : if a:a < 0
9697 : throw "EXCEPT:MATHERR:RANGE(" . a:func . ")"
9698 : endif
9699 :endfunction
9700 :
9701 :function! Add(a, b)
9702 : call CheckRange(a:a, "Add")
9703 : call CheckRange(a:b, "Add")
9704 : let c = a:a + a:b
9705 : if c < 0
9706 : throw "EXCEPT:MATHERR:OVERFLOW"
9707 : endif
9708 : return c
9709 :endfunction
9710 :
9711 :function! Div(a, b)
9712 : call CheckRange(a:a, "Div")
9713 : call CheckRange(a:b, "Div")
9714 : if (a:b == 0)
9715 : throw "EXCEPT:MATHERR:ZERODIV"
9716 : endif
9717 : return a:a / a:b
9718 :endfunction
9719 :
9720 :function! Write(file)
9721 : try
Bram Moolenaar446cb832008-06-24 21:56:24 +00009722 : execute "write" fnameescape(a:file)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009723 : catch /^Vim(write):/
9724 : throw "EXCEPT:IO(" . getcwd() . ", " . a:file . "):WRITEERR"
9725 : endtry
9726 :endfunction
9727 :
9728 :try
9729 :
9730 : " something with arithmetics and I/O
9731 :
9732 :catch /^EXCEPT:MATHERR:RANGE/
9733 : let function = substitute(v:exception, '.*(\(\a\+\)).*', '\1', "")
9734 : echo "Range error in" function
9735 :
9736 :catch /^EXCEPT:MATHERR/ " catches OVERFLOW and ZERODIV
9737 : echo "Math error"
9738 :
9739 :catch /^EXCEPT:IO/
9740 : let dir = substitute(v:exception, '.*(\(.\+\),\s*.\+).*', '\1', "")
9741 : let file = substitute(v:exception, '.*(.\+,\s*\(.\+\)).*', '\1', "")
9742 : if file !~ '^/'
9743 : let file = dir . "/" . file
9744 : endif
9745 : echo 'I/O error for "' . file . '"'
9746 :
9747 :catch /^EXCEPT/
9748 : echo "Unspecified error"
9749 :
9750 :endtry
9751
9752The exceptions raised by Vim itself (on error or when pressing CTRL-C) use
9753a flat hierarchy: they are all in the "Vim" class. You cannot throw yourself
9754exceptions with the "Vim" prefix; they are reserved for Vim.
9755 Vim error exceptions are parameterized with the name of the command that
9756failed, if known. See |catch-errors|.
9757
9758
9759PECULIARITIES
9760 *except-compat*
9761The exception handling concept requires that the command sequence causing the
9762exception is aborted immediately and control is transferred to finally clauses
9763and/or a catch clause.
9764
9765In the Vim script language there are cases where scripts and functions
9766continue after an error: in functions without the "abort" flag or in a command
9767after ":silent!", control flow goes to the following line, and outside
9768functions, control flow goes to the line following the outermost ":endwhile"
9769or ":endif". On the other hand, errors should be catchable as exceptions
9770(thus, requiring the immediate abortion).
9771
9772This problem has been solved by converting errors to exceptions and using
9773immediate abortion (if not suppressed by ":silent!") only when a try
Bram Moolenaar446cb832008-06-24 21:56:24 +00009774conditional is active. This is no restriction since an (error) exception can
9775be caught only from an active try conditional. If you want an immediate
Bram Moolenaar071d4272004-06-13 20:20:40 +00009776termination without catching the error, just use a try conditional without
9777catch clause. (You can cause cleanup code being executed before termination
9778by specifying a finally clause.)
9779
9780When no try conditional is active, the usual abortion and continuation
9781behavior is used instead of immediate abortion. This ensures compatibility of
9782scripts written for Vim 6.1 and earlier.
9783
9784However, when sourcing an existing script that does not use exception handling
9785commands (or when calling one of its functions) from inside an active try
9786conditional of a new script, you might change the control flow of the existing
9787script on error. You get the immediate abortion on error and can catch the
9788error in the new script. If however the sourced script suppresses error
9789messages by using the ":silent!" command (checking for errors by testing
Bram Moolenaar446cb832008-06-24 21:56:24 +00009790|v:errmsg| if appropriate), its execution path is not changed. The error is
9791not converted to an exception. (See |:silent|.) So the only remaining cause
Bram Moolenaar071d4272004-06-13 20:20:40 +00009792where this happens is for scripts that don't care about errors and produce
9793error messages. You probably won't want to use such code from your new
9794scripts.
9795
9796 *except-syntax-err*
9797Syntax errors in the exception handling commands are never caught by any of
9798the ":catch" commands of the try conditional they belong to. Its finally
9799clauses, however, is executed.
9800 Example: >
9801
9802 :try
9803 : try
9804 : throw 4711
9805 : catch /\(/
9806 : echo "in catch with syntax error"
9807 : catch
9808 : echo "inner catch-all"
9809 : finally
9810 : echo "inner finally"
9811 : endtry
9812 :catch
9813 : echo 'outer catch-all caught "' . v:exception . '"'
9814 : finally
9815 : echo "outer finally"
9816 :endtry
9817
9818This displays: >
9819 inner finally
9820 outer catch-all caught "Vim(catch):E54: Unmatched \("
9821 outer finally
9822The original exception is discarded and an error exception is raised, instead.
9823
9824 *except-single-line*
9825The ":try", ":catch", ":finally", and ":endtry" commands can be put on
9826a single line, but then syntax errors may make it difficult to recognize the
9827"catch" line, thus you better avoid this.
9828 Example: >
9829 :try | unlet! foo # | catch | endtry
9830raises an error exception for the trailing characters after the ":unlet!"
9831argument, but does not see the ":catch" and ":endtry" commands, so that the
9832error exception is discarded and the "E488: Trailing characters" message gets
9833displayed.
9834
9835 *except-several-errors*
9836When several errors appear in a single command, the first error message is
9837usually the most specific one and therefor converted to the error exception.
9838 Example: >
9839 echo novar
9840causes >
9841 E121: Undefined variable: novar
9842 E15: Invalid expression: novar
9843The value of the error exception inside try conditionals is: >
9844 Vim(echo):E121: Undefined variable: novar
9845< *except-syntax-error*
9846But when a syntax error is detected after a normal error in the same command,
9847the syntax error is used for the exception being thrown.
9848 Example: >
9849 unlet novar #
9850causes >
9851 E108: No such variable: "novar"
9852 E488: Trailing characters
9853The value of the error exception inside try conditionals is: >
9854 Vim(unlet):E488: Trailing characters
9855This is done because the syntax error might change the execution path in a way
9856not intended by the user. Example: >
9857 try
9858 try | unlet novar # | catch | echo v:exception | endtry
9859 catch /.*/
9860 echo "outer catch:" v:exception
9861 endtry
9862This displays "outer catch: Vim(unlet):E488: Trailing characters", and then
9863a "E600: Missing :endtry" error message is given, see |except-single-line|.
9864
9865==============================================================================
98669. Examples *eval-examples*
9867
Bram Moolenaaref2f6562007-05-06 13:32:59 +00009868Printing in Binary ~
Bram Moolenaar071d4272004-06-13 20:20:40 +00009869>
Bram Moolenaar8f3f58f2010-01-06 20:52:26 +01009870 :" The function Nr2Bin() returns the binary string representation of a number.
Bram Moolenaaref2f6562007-05-06 13:32:59 +00009871 :func Nr2Bin(nr)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009872 : let n = a:nr
9873 : let r = ""
9874 : while n
Bram Moolenaaref2f6562007-05-06 13:32:59 +00009875 : let r = '01'[n % 2] . r
9876 : let n = n / 2
Bram Moolenaar071d4272004-06-13 20:20:40 +00009877 : endwhile
9878 : return r
9879 :endfunc
9880
Bram Moolenaaref2f6562007-05-06 13:32:59 +00009881 :" The function String2Bin() converts each character in a string to a
9882 :" binary string, separated with dashes.
9883 :func String2Bin(str)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009884 : let out = ''
Bram Moolenaaref2f6562007-05-06 13:32:59 +00009885 : for ix in range(strlen(a:str))
9886 : let out = out . '-' . Nr2Bin(char2nr(a:str[ix]))
9887 : endfor
9888 : return out[1:]
Bram Moolenaar071d4272004-06-13 20:20:40 +00009889 :endfunc
9890
9891Example of its use: >
Bram Moolenaaref2f6562007-05-06 13:32:59 +00009892 :echo Nr2Bin(32)
9893result: "100000" >
9894 :echo String2Bin("32")
9895result: "110011-110010"
Bram Moolenaar071d4272004-06-13 20:20:40 +00009896
9897
Bram Moolenaaref2f6562007-05-06 13:32:59 +00009898Sorting lines ~
Bram Moolenaar071d4272004-06-13 20:20:40 +00009899
Bram Moolenaaref2f6562007-05-06 13:32:59 +00009900This example sorts lines with a specific compare function. >
9901
9902 :func SortBuffer()
9903 : let lines = getline(1, '$')
9904 : call sort(lines, function("Strcmp"))
9905 : call setline(1, lines)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009906 :endfunction
9907
Bram Moolenaaref2f6562007-05-06 13:32:59 +00009908As a one-liner: >
9909 :call setline(1, sort(getline(1, '$'), function("Strcmp")))
Bram Moolenaar071d4272004-06-13 20:20:40 +00009910
Bram Moolenaar071d4272004-06-13 20:20:40 +00009911
Bram Moolenaaref2f6562007-05-06 13:32:59 +00009912scanf() replacement ~
Bram Moolenaar071d4272004-06-13 20:20:40 +00009913 *sscanf*
9914There is no sscanf() function in Vim. If you need to extract parts from a
9915line, you can use matchstr() and substitute() to do it. This example shows
9916how to get the file name, line number and column number out of a line like
9917"foobar.txt, 123, 45". >
9918 :" Set up the match bit
9919 :let mx='\(\f\+\),\s*\(\d\+\),\s*\(\d\+\)'
9920 :"get the part matching the whole expression
9921 :let l = matchstr(line, mx)
9922 :"get each item out of the match
9923 :let file = substitute(l, mx, '\1', '')
9924 :let lnum = substitute(l, mx, '\2', '')
9925 :let col = substitute(l, mx, '\3', '')
9926
9927The input is in the variable "line", the results in the variables "file",
9928"lnum" and "col". (idea from Michael Geddes)
9929
Bram Moolenaaref2f6562007-05-06 13:32:59 +00009930
9931getting the scriptnames in a Dictionary ~
9932 *scriptnames-dictionary*
9933The |:scriptnames| command can be used to get a list of all script files that
9934have been sourced. There is no equivalent function or variable for this
9935(because it's rarely needed). In case you need to manipulate the list this
9936code can be used: >
9937 " Get the output of ":scriptnames" in the scriptnames_output variable.
9938 let scriptnames_output = ''
9939 redir => scriptnames_output
9940 silent scriptnames
9941 redir END
9942
Bram Moolenaar446cb832008-06-24 21:56:24 +00009943 " Split the output into lines and parse each line. Add an entry to the
Bram Moolenaaref2f6562007-05-06 13:32:59 +00009944 " "scripts" dictionary.
9945 let scripts = {}
9946 for line in split(scriptnames_output, "\n")
9947 " Only do non-blank lines.
9948 if line =~ '\S'
9949 " Get the first number in the line.
Bram Moolenaar446cb832008-06-24 21:56:24 +00009950 let nr = matchstr(line, '\d\+')
Bram Moolenaaref2f6562007-05-06 13:32:59 +00009951 " Get the file name, remove the script number " 123: ".
Bram Moolenaar446cb832008-06-24 21:56:24 +00009952 let name = substitute(line, '.\+:\s*', '', '')
Bram Moolenaaref2f6562007-05-06 13:32:59 +00009953 " Add an item to the Dictionary
Bram Moolenaar446cb832008-06-24 21:56:24 +00009954 let scripts[nr] = name
Bram Moolenaaref2f6562007-05-06 13:32:59 +00009955 endif
9956 endfor
9957 unlet scriptnames_output
9958
Bram Moolenaar071d4272004-06-13 20:20:40 +00009959==============================================================================
996010. No +eval feature *no-eval-feature*
9961
9962When the |+eval| feature was disabled at compile time, none of the expression
9963evaluation commands are available. To prevent this from causing Vim scripts
9964to generate all kinds of errors, the ":if" and ":endif" commands are still
9965recognized, though the argument of the ":if" and everything between the ":if"
9966and the matching ":endif" is ignored. Nesting of ":if" blocks is allowed, but
9967only if the commands are at the start of the line. The ":else" command is not
9968recognized.
9969
9970Example of how to avoid executing commands when the |+eval| feature is
9971missing: >
9972
9973 :if 1
9974 : echo "Expression evaluation is compiled in"
9975 :else
9976 : echo "You will _never_ see this message"
9977 :endif
9978
9979==============================================================================
998011. The sandbox *eval-sandbox* *sandbox* *E48*
9981
Bram Moolenaar368373e2010-07-19 20:46:22 +02009982The 'foldexpr', 'formatexpr', 'includeexpr', 'indentexpr', 'statusline' and
9983'foldtext' options may be evaluated in a sandbox. This means that you are
9984protected from these expressions having nasty side effects. This gives some
9985safety for when these options are set from a modeline. It is also used when
9986the command from a tags file is executed and for CTRL-R = in the command line.
Bram Moolenaar7b0294c2004-10-11 10:16:09 +00009987The sandbox is also used for the |:sandbox| command.
Bram Moolenaar071d4272004-06-13 20:20:40 +00009988
9989These items are not allowed in the sandbox:
9990 - changing the buffer text
9991 - defining or changing mapping, autocommands, functions, user commands
9992 - setting certain options (see |option-summary|)
Bram Moolenaaref2f6562007-05-06 13:32:59 +00009993 - setting certain v: variables (see |v:var|) *E794*
Bram Moolenaar071d4272004-06-13 20:20:40 +00009994 - executing a shell command
9995 - reading or writing a file
9996 - jumping to another buffer or editing a file
Bram Moolenaar4770d092006-01-12 23:22:24 +00009997 - executing Python, Perl, etc. commands
Bram Moolenaar7b0294c2004-10-11 10:16:09 +00009998This is not guaranteed 100% secure, but it should block most attacks.
9999
10000 *:san* *:sandbox*
Bram Moolenaar045e82d2005-07-08 22:25:33 +000010001:san[dbox] {cmd} Execute {cmd} in the sandbox. Useful to evaluate an
Bram Moolenaar7b0294c2004-10-11 10:16:09 +000010002 option that may have been set from a modeline, e.g.
10003 'foldexpr'.
10004
Bram Moolenaarb71eaae2006-01-20 23:10:18 +000010005 *sandbox-option*
10006A few options contain an expression. When this expression is evaluated it may
Bram Moolenaar9b2200a2006-03-20 21:55:45 +000010007have to be done in the sandbox to avoid a security risk. But the sandbox is
Bram Moolenaarb71eaae2006-01-20 23:10:18 +000010008restrictive, thus this only happens when the option was set from an insecure
10009location. Insecure in this context are:
Bram Moolenaar551dbcc2006-04-25 22:13:59 +000010010- sourcing a .vimrc or .exrc in the current directory
Bram Moolenaarb71eaae2006-01-20 23:10:18 +000010011- while executing in the sandbox
10012- value coming from a modeline
10013
10014Note that when in the sandbox and saving an option value and restoring it, the
10015option will still be marked as it was set in the sandbox.
10016
10017==============================================================================
1001812. Textlock *textlock*
10019
10020In a few situations it is not allowed to change the text in the buffer, jump
10021to another window and some other things that might confuse or break what Vim
10022is currently doing. This mostly applies to things that happen when Vim is
Bram Moolenaar446cb832008-06-24 21:56:24 +000010023actually doing something else. For example, evaluating the 'balloonexpr' may
Bram Moolenaarb71eaae2006-01-20 23:10:18 +000010024happen any moment the mouse cursor is resting at some position.
10025
10026This is not allowed when the textlock is active:
10027 - changing the buffer text
10028 - jumping to another buffer or window
10029 - editing another file
10030 - closing a window or quitting Vim
10031 - etc.
10032
Bram Moolenaar071d4272004-06-13 20:20:40 +000010033
10034 vim:tw=78:ts=8:ft=help:norl: