Lines Matching refs:function
18 |41.7| Defining a function
190 g:name global variable (also in a function)
217 The "exists()" function checks if a variable has already been defined. Its
539 value, you can use the eval() function: >
556 A function is called with the ":call" command. The parameters are passed in
561 This calls the search() function, with arguments "Date: " and "W". The
562 search() function uses its first argument as a search pattern and the second
566 A function can be called in an expression. Example: >
572 The getline() function obtains a line from the current buffer. Its argument
575 The substitute() function does something similar to the ":substitute"
579 The setline() function sets the line, specified by the first argument, to a
590 FUNCTIONS *function-list*
594 the function name to jump to detailed help on it.
670 call() call a function with List as arguments
730 Other computation: *bitwise-function*
743 funcref() get a Funcref for a function reference
744 function() get a Funcref for a function name
1043 test_null_partial() return a null Partial function
1122 term_setapi() set terminal JSON API function name prefix
1191 exists() check if a variable, function, etc. exists
1204 libcall() call a function in an external library
1232 *41.7* Defining a function
1234 Vim enables you to define your own functions. The basic function declaration
1237 :function {name}({var1}, {var2}, ...)
1244 Let's define a short function to return the smaller of two numbers. It starts
1247 :function Min(num1, num2)
1249 This tells Vim that the function is named "Min" and it takes two arguments:
1255 The special prefix "a:" tells Vim that the variable is a function argument.
1264 The variable "smaller" is a local variable. Variables used inside a function
1268 To access a global variable from inside a function you must prepend
1269 "g:" to it. Thus "g:today" inside a function is used for the global
1271 function.
1274 Finally, you end the function: >
1279 The complete function definition is as follows: >
1281 :function Min(num1, num2)
1292 :function Min(num1, num2)
1299 A user defined function is called in exactly the same way as a built-in
1300 function. Only the name is different. The Min function can be used like
1305 Only now will the function be executed and the lines be interpreted by Vim.
1306 If there are mistakes, like using an undefined variable or function, you will
1307 now get an error message. When defining the function these errors are not
1310 When a function reaches ":endfunction" or ":return" is used without an
1311 argument, the function returns zero.
1313 To redefine a function that already exists, use the ! for the ":function"
1316 :function! Min(num1, num2, num3)
1322 meanings. When a function has been defined with the "range" keyword, it will
1324 The function will be passed the variables "a:firstline" and "a:lastline".
1325 These will have the line numbers from the range the function was called with.
1328 :function Count_words() range
1338 You can call this function with: >
1343 The other way to use a line range is by defining a function without the
1344 "range" keyword. The function will be called once for every line in the
1347 :function Number()
1351 If you call this function with: >
1355 The function will be called six times.
1361 The following command, for instance, defines a function that must have 1
1364 :function Show(start, ...)
1370 :function Show(start, ...)
1392 The ":function" command lists the names and arguments of all user-defined
1395 :function
1396 < function Show(start, ...) ~
1397 function GetVimIndent() ~
1398 function SetSyn(name) ~
1400 To see what a function does, use its name as an argument for ":function": >
1402 :function SetSyn
1413 You can also set the 'verbose' option to 12 or higher to see all function
1419 To delete the Show() function: >
1423 You get an error when the function doesn't exist.
1428 Sometimes it can be useful to have a variable point to one function or
1429 another. You can do it with the function() function. It turns the name of a
1430 function into a reference: >
1433 :function! Right()
1436 :function! Wrong()
1441 : let Afunc = function('Right')
1443 : let Afunc = function('Wrong')
1448 Note that the name of a variable that holds a function reference must start
1450 function.
1451 The way to invoke a function that a variable refers to is with the call()
1452 function. Its first argument is the function reference, the second argument
1477 You can add items to a List with the add() function: >
1527 range() function creates one for you: >
1623 And now for something special: you can directly define a function and store a
1626 :function uk2nl.translate(line) dict
1635 The first special thing you notice is the "dict" at the end of the ":function"
1636 line. This marks the function as being used from a Dictionary. The "self"
1642 The split() function takes a string, chops it into whitespace separated words
1648 This list is the first argument to the map() function. This will go through
1661 The get() function checks if a key is present in a Dictionary. If it is, then
1666 The join() function does the opposite of split(): it joins together a list of
1678 Dictionary) that has the translate function, but no words to translate: >
1681 :function transdict.translate(line) dict
1685 It's slightly different from the function above, using 'self.words' to lookup
1703 You see that the copy() function is used to make a copy of the "transdict"
1722 translate() function to do nothing: >
1725 :function! uk2uk.translate(line)
1731 Notice that a ! was used to overwrite the existing function reference. Now
1947 To avoid your function names to interfere with functions that you get from
1949 - Prepend a unique string before each function name. I often use an
1963 function XXX_one(a)
1964 ... body of function ...
1967 function XXX_two(b)
1968 ... body of function ...
2082 the variable in a function (without "g:" it would be a variable local to the
2083 function).
2133 could define a function Add(), but another script could try to define the same
2134 function. To avoid this, we define the function local to the script by
2137 We will define a function that adds a new typing correction: >
2139 30 function s:Add(from, correct)
2145 Now we can call the function s:Add() from within this script. If another
2148 function (without the "s:"), which is again another function.
2167 the Add() function.
2208 number. Thus a function "<SID>Add()" will have a name "<SNR>11_Add()"
2210 you use the ":function" command to get a list of functions. The
2212 can call a script-local function from a mapping.
2243 30 function s:Add(from, correct)
2250 s:Add() function is called, it increments s:count. It doesn't matter from
2251 where the function was called, since it has been defined in the script, it
2288 30 function s:Add(from, correct)
2305 that mappings and abbreviations are expanded here, even though the function
2523 When defining a function, this only needs to be done once. But the filetype
2525 This construct makes sure the function is only defined once: >
2528 : function s:Func(arg)
2581 exists("*s:Func") Check if a function was already defined.
2666 function BufNetRead(...)
2671 function BufNetWrite(...)
2692 BufNetRead() or BufNetWrite() function will be called.
2694 3. Vim can't find the function and triggers the |FuncUndefined| autocommand
2695 event. Since the pattern "BufNet*" matches the invoked function, the
2715 when it's already done. You can do this with the |exists()| function.
2731 That's a lot simpler, isn't it? Vim will recognize the function name and when
2733 That script must define the "mylib#myfunction()" function.
2736 organize your functions in library scripts. But you must use function names
2749 Where the function is defined like this: >
2751 function netlib#ftp#read(fname)
2755 Notice that the name the function is defined with is exactly the same as the
2756 name used for calling the function. And the part before the last '#'