|
|
|
|
@ -1,4 +1,4 @@
|
|
|
|
|
*eval.txt* For Vim version 7.0aa. Last change: 2005 Jan 14
|
|
|
|
|
*eval.txt* For Vim version 7.0aa. Last change: 2005 Jan 15
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
VIM REFERENCE MANUAL by Bram Moolenaar
|
|
|
|
|
@ -117,7 +117,7 @@ arguments: >
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1.3 Lists ~
|
|
|
|
|
*List* *E686*
|
|
|
|
|
*List* *E686* *E712*
|
|
|
|
|
A List is an ordered sequence of items. An item can be of any type. Items
|
|
|
|
|
can be accessed by their index number. Items can be added and removed at any
|
|
|
|
|
position in the sequence.
|
|
|
|
|
@ -261,7 +261,7 @@ examples: >
|
|
|
|
|
:call extend(list, [1, 2]) " extend the list with two more items
|
|
|
|
|
:let i = remove(list, 3) " remove item 3
|
|
|
|
|
:let l = remove(list, 3, -1) " remove items 3 to last item
|
|
|
|
|
:call filter(list, '& =~ "x"') " remove items with an 'x'
|
|
|
|
|
:call filter(list, 'v:val =~ "x"') " remove items with an 'x'
|
|
|
|
|
|
|
|
|
|
Changing the oder of items in a list: >
|
|
|
|
|
:call sort(list) " sort a list alphabetically
|
|
|
|
|
@ -314,17 +314,17 @@ List functions ~
|
|
|
|
|
Functions that are useful with a List: >
|
|
|
|
|
:let r = call(funcname, list) " call a function with an argument list
|
|
|
|
|
:if empty(list) " check if list is empty
|
|
|
|
|
:let l = len(list) " number of items in a list
|
|
|
|
|
:let big = max(list) " maximum value in a list
|
|
|
|
|
:let small = min(list) " minimum value in a list
|
|
|
|
|
:let l = len(list) " number of items in list
|
|
|
|
|
:let big = max(list) " maximum value in list
|
|
|
|
|
:let small = min(list) " minimum value in list
|
|
|
|
|
:let xs = count(list, 'x') " count nr of times 'x' appears in list
|
|
|
|
|
:let i = index(list, 'x') " index of first 'x' in list
|
|
|
|
|
:let lines = getline(1, 10) " get ten text lines from buffer
|
|
|
|
|
:call append('$', lines) " append text lines in buffer
|
|
|
|
|
:let list = split("a b c") " create list from items in a string
|
|
|
|
|
:let string = join(list, ', ') " create string from list items
|
|
|
|
|
:let s = string() " String representation of a list
|
|
|
|
|
:call map(list, '">> " . &') " prepend ">> " to each item
|
|
|
|
|
:let s = string(list) " String representation of list
|
|
|
|
|
:call map(list, '">> " . v:val') " prepend ">> " to each item
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1.4 Dictionaries ~
|
|
|
|
|
@ -423,7 +423,44 @@ Merging a Dictionary with another is done with |extend()|: >
|
|
|
|
|
:call extend(adict, bdict) " extend adict with entries from bdict
|
|
|
|
|
|
|
|
|
|
Weeding out entries from a Dictionary can be done with |filter()|: >
|
|
|
|
|
:call filter(dict '& =~ "x"') " remove entries with value 'x'
|
|
|
|
|
:call filter(dict 'v:val =~ "x"') " remove entries with value 'x'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Dictionary function ~
|
|
|
|
|
*Dictionary-function* *self*
|
|
|
|
|
When a function is defined with the "dict" attribute it can be used in a
|
|
|
|
|
special way with a dictionary. Example: >
|
|
|
|
|
:function Mylen() dict
|
|
|
|
|
: return len(self) - 4
|
|
|
|
|
:endfunction
|
|
|
|
|
:let dict.len = function(Mylen)
|
|
|
|
|
:let l = dict.len()
|
|
|
|
|
|
|
|
|
|
This is like a method in object oriented programming. The entry in the
|
|
|
|
|
Dictionary is a |Funcref|. The local variable "self" refers to the dictionary
|
|
|
|
|
the function was invoked from.
|
|
|
|
|
|
|
|
|
|
To avoid the extra name for the function it can be defined and directly
|
|
|
|
|
assigned to a Dictionary in this way: >
|
|
|
|
|
:function dict.len() dict
|
|
|
|
|
: return len(self) - 4
|
|
|
|
|
:endfunction
|
|
|
|
|
|
|
|
|
|
It is also possible to add a Funcref to a Dictionary without the "dict"
|
|
|
|
|
attribute, but the "self" variable is not available then.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Functions for Dictionaries ~
|
|
|
|
|
|
|
|
|
|
Functions that are useful with a Dictionary: >
|
|
|
|
|
:if has_key(dict, 'foo') " TRUE if dict has entry with key "foo"
|
|
|
|
|
:if empty(dict) " TRUE if dict is empty
|
|
|
|
|
:let l = len(dict) " number of items in dict
|
|
|
|
|
:let big = max(dict) " maximum value in dict
|
|
|
|
|
:let small = min(dict) " minimum value in dict
|
|
|
|
|
:let xs = count(dict, 'x') " count nr of times 'x' appears in dict
|
|
|
|
|
:let s = string(dict) " String representation of dict
|
|
|
|
|
:call map(dict, '">> " . v:val') " prepend ">> " to each item
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1.5 More about variables ~
|
|
|
|
|
@ -487,16 +524,18 @@ Expression syntax summary, from least to most significant:
|
|
|
|
|
|expr7| ! expr7 logical NOT
|
|
|
|
|
- expr7 unary minus
|
|
|
|
|
+ expr7 unary plus
|
|
|
|
|
expr8
|
|
|
|
|
|
|
|
|
|
|expr8| expr9[expr1] byte of a String or item of a List
|
|
|
|
|
expr9[expr1 : expr2] substring of a String or sublist of a List
|
|
|
|
|
expr9.name entry in a Dictionary
|
|
|
|
|
|
|
|
|
|
|expr9| number number constant
|
|
|
|
|
|expr8| expr8[expr1] byte of a String or item of a List
|
|
|
|
|
expr8[expr1 : expr1] substring of a String or sublist of a List
|
|
|
|
|
expr8.name entry in a Dictionary
|
|
|
|
|
expr8(expr1, ...) function call with Funcref variable
|
|
|
|
|
|
|
|
|
|
|expr9| number number constant
|
|
|
|
|
"string" string constant, backslash is special
|
|
|
|
|
'string' string constant, ' is doubled
|
|
|
|
|
[expr1, ...] List
|
|
|
|
|
{expr1: expr1, ...} Dictionary
|
|
|
|
|
&option option value
|
|
|
|
|
(expr1) nested expression
|
|
|
|
|
variable internal variable
|
|
|
|
|
@ -504,7 +543,6 @@ Expression syntax summary, from least to most significant:
|
|
|
|
|
$VAR environment variable
|
|
|
|
|
@r contents of register 'r'
|
|
|
|
|
function(expr1, ...) function call
|
|
|
|
|
Funcref(expr1, ...) function call with Funcref variable
|
|
|
|
|
func{ti}on(expr1, ...) function call with curly braces
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -696,10 +734,10 @@ These three can be repeated and mixed. Examples:
|
|
|
|
|
|
|
|
|
|
expr8 *expr8*
|
|
|
|
|
-----
|
|
|
|
|
expr9[expr1] item of String or List *expr-[]* *E111*
|
|
|
|
|
expr8[expr1] item of String or List *expr-[]* *E111*
|
|
|
|
|
|
|
|
|
|
If expr9 is a Number or String this results in a String that contains the
|
|
|
|
|
expr1'th single byte from expr9. expr9 is used as a String, expr1 as a
|
|
|
|
|
If expr8 is a Number or String this results in a String that contains the
|
|
|
|
|
expr1'th single byte from expr8. expr8 is used as a String, expr1 as a
|
|
|
|
|
Number. Note that this doesn't recognize multi-byte encodings.
|
|
|
|
|
|
|
|
|
|
Index zero gives the first character. This is like it works in C. Careful:
|
|
|
|
|
@ -711,7 +749,7 @@ If the length of the String is less than the index, the result is an empty
|
|
|
|
|
String. A negative index always results in an empty string (reason: backwards
|
|
|
|
|
compatibility). Use [-1:] to get the last byte.
|
|
|
|
|
|
|
|
|
|
If expr9 is a List then it results the item at index expr1. See |list-index|
|
|
|
|
|
If expr8 is a List then it results the item at index expr1. See |list-index|
|
|
|
|
|
for possible index values. If the index is out of range this results in an
|
|
|
|
|
error. Example: >
|
|
|
|
|
:let item = mylist[-1] " get last item
|
|
|
|
|
@ -720,10 +758,10 @@ Generally, if a List index is equal to or higher than the length of the List,
|
|
|
|
|
or more negative than the length of the List, this results in an error.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
expr9[expr1a : expr1b] substring or sublist *expr-[:]*
|
|
|
|
|
expr8[expr1a : expr1b] substring or sublist *expr-[:]*
|
|
|
|
|
|
|
|
|
|
If expr9 is a Number or String this results in the substring with the bytes
|
|
|
|
|
from expr1a to and including expr1b. expr9 is used as a String, expr1a and
|
|
|
|
|
If expr8 is a Number or String this results in the substring with the bytes
|
|
|
|
|
from expr1a to and including expr1b. expr8 is used as a String, expr1a and
|
|
|
|
|
expr1b are used as a Number. Note that this doesn't recognize multi-byte
|
|
|
|
|
encodings.
|
|
|
|
|
|
|
|
|
|
@ -742,20 +780,20 @@ Examples: >
|
|
|
|
|
:let s = line(".")[4:] " from the fifth byte to the end
|
|
|
|
|
:let s = s[:-3] " remove last two bytes
|
|
|
|
|
|
|
|
|
|
If expr9 is a List this results in a new List with the items indicated by the
|
|
|
|
|
If expr8 is a List this results in a new List with the items indicated by the
|
|
|
|
|
indexes expr1a and expr1b. This works like with a String, as explained just
|
|
|
|
|
above, except that indexes out of range cause an error. Examples: >
|
|
|
|
|
:let l = mylist[:3] " first four items
|
|
|
|
|
:let l = mylist[4:4] " List with one item
|
|
|
|
|
:let l = mylist[:] " shallow copy of a List
|
|
|
|
|
|
|
|
|
|
Using expr9[expr1] or expr9[expr1a : expr1b] on a Funcref results in an error.
|
|
|
|
|
Using expr8[expr1] or expr8[expr1a : expr1b] on a Funcref results in an error.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
expr9.name entry in a Dictionary *expr-entry*
|
|
|
|
|
expr8.name entry in a Dictionary *expr-entry*
|
|
|
|
|
|
|
|
|
|
If expr9 is a Dictionary and it is followed by a dot, then the following name
|
|
|
|
|
will be used as a key in the Dictionary. This is just like: expr9[name].
|
|
|
|
|
If expr8 is a Dictionary and it is followed by a dot, then the following name
|
|
|
|
|
will be used as a key in the Dictionary. This is just like: expr8[name].
|
|
|
|
|
|
|
|
|
|
The name must consist of alphanumeric characters, just like a variable name,
|
|
|
|
|
but it may start with a number. Curly braces cannot be used.
|
|
|
|
|
@ -771,7 +809,13 @@ Note that the dot is also used for String concatenation. To avoid confusion
|
|
|
|
|
always put spaces around the dot for String concatenation.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
*expr9*
|
|
|
|
|
expr8(expr1, ...) Funcref function call
|
|
|
|
|
|
|
|
|
|
When expr8 is a |Funcref| type variable, invoke the function it refers to.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
*expr9*
|
|
|
|
|
number
|
|
|
|
|
------
|
|
|
|
|
number number constant *expr-number*
|
|
|
|
|
@ -1147,6 +1191,11 @@ v:insertmode Used for the |InsertEnter| and |InsertChange| autocommand
|
|
|
|
|
r Replace mode
|
|
|
|
|
v Virtual Replace mode
|
|
|
|
|
|
|
|
|
|
*v:key* *key-variable*
|
|
|
|
|
v:key Key of the current item of a Dictionary. Only valid while
|
|
|
|
|
evaluating the expression used with |map()| and |filter()|.
|
|
|
|
|
Read-only.
|
|
|
|
|
|
|
|
|
|
*v:lang* *lang-variable*
|
|
|
|
|
v:lang The current locale setting for messages of the runtime
|
|
|
|
|
environment. This allows Vim scripts to be aware of the
|
|
|
|
|
@ -1239,6 +1288,11 @@ v:throwpoint The point where the exception most recently caught and not
|
|
|
|
|
:endtry
|
|
|
|
|
< Output: "Exception from test.vim, line 2"
|
|
|
|
|
|
|
|
|
|
*v:val* *val-variable*
|
|
|
|
|
v:val Value of the current item of a List or Dictionary. Only valid
|
|
|
|
|
while evaluating the expression used with |map()| and
|
|
|
|
|
|filter()|. Read-only.
|
|
|
|
|
|
|
|
|
|
*v:version* *version-variable*
|
|
|
|
|
v:version Version number of Vim: Major version number times 100 plus
|
|
|
|
|
minor version number. Version 5.0 is 500. Version 5.1 (5.01)
|
|
|
|
|
@ -1278,7 +1332,8 @@ bufnr( {expr}) Number Number of the buffer {expr}
|
|
|
|
|
bufwinnr( {expr}) Number window number of buffer {expr}
|
|
|
|
|
byte2line( {byte}) Number line number at byte count {byte}
|
|
|
|
|
byteidx( {expr}, {nr}) Number byte index of {nr}'th char in {expr}
|
|
|
|
|
call( {func}, {arglist}) any call {func} with arguments {arglist}
|
|
|
|
|
call( {func}, {arglist} [, {dict}])
|
|
|
|
|
any call {func} with arguments {arglist}
|
|
|
|
|
char2nr( {expr}) Number ASCII value of first char in {expr}
|
|
|
|
|
cindent( {lnum}) Number C indent for line {lnum}
|
|
|
|
|
col( {expr}) Number column nr of cursor or mark
|
|
|
|
|
@ -1303,7 +1358,8 @@ executable( {expr}) Number 1 if executable {expr} exists
|
|
|
|
|
exists( {expr}) Number TRUE if {expr} exists
|
|
|
|
|
expand( {expr}) String expand special keywords in {expr}
|
|
|
|
|
filereadable( {file}) Number TRUE if {file} is a readable file
|
|
|
|
|
filter( {list}, {expr}) List remove from {list} where {expr} is 0
|
|
|
|
|
filter( {expr}, {string}) List/Dict remove items from {expr} where
|
|
|
|
|
{string} is 0
|
|
|
|
|
finddir( {name}[, {path}[, {count}]])
|
|
|
|
|
String Find directory {name} in {path}
|
|
|
|
|
findfile( {name}[, {path}[, {count}]])
|
|
|
|
|
@ -1317,6 +1373,7 @@ foldtext( ) String line displayed for closed fold
|
|
|
|
|
foreground( ) Number bring the Vim window to the foreground
|
|
|
|
|
function( {name}) Funcref reference to function {name}
|
|
|
|
|
get( {list}, {idx} [, {def}]) any get item {idx} from {list} or {def}
|
|
|
|
|
get( {dict}, {key} [, {def}]) any get item {key} from {dict} or {def}
|
|
|
|
|
getchar( [expr]) Number get one character from the user
|
|
|
|
|
getcharmod( ) Number modifiers for the last typed character
|
|
|
|
|
getbufvar( {expr}, {varname}) variable {varname} in buffer {expr}
|
|
|
|
|
@ -1337,6 +1394,7 @@ getwinvar( {nr}, {varname}) variable {varname} in window {nr}
|
|
|
|
|
glob( {expr}) String expand file wildcards in {expr}
|
|
|
|
|
globpath( {path}, {expr}) String do glob({expr}) for all dirs in {path}
|
|
|
|
|
has( {feature}) Number TRUE if feature {feature} supported
|
|
|
|
|
has_key( {dict}, {key}) Number TRUE if {dict} has entry {key}
|
|
|
|
|
hasmapto( {what} [, {mode}]) Number TRUE if mapping to {what} exists
|
|
|
|
|
histadd( {history},{item}) String add an item to a history
|
|
|
|
|
histdel( {history} [, {item}]) String remove an item from a history
|
|
|
|
|
@ -1365,7 +1423,7 @@ line( {expr}) Number line nr of cursor, last line or mark
|
|
|
|
|
line2byte( {lnum}) Number byte count of line {lnum}
|
|
|
|
|
lispindent( {lnum}) Number Lisp indent for line {lnum}
|
|
|
|
|
localtime() Number current time
|
|
|
|
|
map( {list}, {expr}) List change each item in {list} to {expr}
|
|
|
|
|
map( {expr}, {string}) List/Dict change each item in {expr} to {expr}
|
|
|
|
|
maparg( {name}[, {mode}]) String rhs of mapping {name} in mode {mode}
|
|
|
|
|
mapcheck( {name}[, {mode}]) String check for mappings matching {name}
|
|
|
|
|
match( {expr}, {pat}[, {start}[, {count}]])
|
|
|
|
|
@ -1617,12 +1675,14 @@ byteidx({expr}, {nr}) *byteidx()*
|
|
|
|
|
If there are exactly {nr} characters the length of the string
|
|
|
|
|
is returned.
|
|
|
|
|
|
|
|
|
|
call({func}, {arglist}) *call()* *E699*
|
|
|
|
|
call({func}, {arglist} [, {dict}]) *call()* *E699*
|
|
|
|
|
Call function {func} with the items in List {arglist} as
|
|
|
|
|
arguments.
|
|
|
|
|
{func} can either be a Funcref or the name of a function.
|
|
|
|
|
a:firstline and a:lastline are set to the cursor line.
|
|
|
|
|
Returns the return value of the called function.
|
|
|
|
|
{dict} is for functions with the "dict" attribute. It will be
|
|
|
|
|
used to set the local variable "self". |Dictionary-function|
|
|
|
|
|
|
|
|
|
|
char2nr({expr}) *char2nr()*
|
|
|
|
|
Return number value of the first char in {expr}. Examples: >
|
|
|
|
|
@ -1722,10 +1782,11 @@ copy({expr}) Make a copy of {expr}. For Numbers and Strings this isn't
|
|
|
|
|
changing an item changes the contents of both Lists. Also see
|
|
|
|
|
|deepcopy()|.
|
|
|
|
|
|
|
|
|
|
count({list}, {expr} [, {start} [, {ic}]]) *count()*
|
|
|
|
|
count({comp}, {expr} [, {ic} [, {start}]]) *count()*
|
|
|
|
|
Return the number of times an item with value {expr} appears
|
|
|
|
|
in List {list}.
|
|
|
|
|
If {start} is given then don't count items with a lower index.
|
|
|
|
|
in List or Dictionary {comp}.
|
|
|
|
|
If {start} is given then start with the item with this index.
|
|
|
|
|
{start} can only be used with a List.
|
|
|
|
|
When {ic} is given and it's non-zero then case is ignored.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -1831,7 +1892,7 @@ diff_hlID({lnum}, {col}) *diff_hlID()*
|
|
|
|
|
|
|
|
|
|
empty({expr}) *empty()*
|
|
|
|
|
Return the Number 1 if {expr} is empty, zero otherwise.
|
|
|
|
|
A List is empty when it does not have any items.
|
|
|
|
|
A List or Dictionary is empty when it does not have any items.
|
|
|
|
|
A Number is empty when its value is zero.
|
|
|
|
|
For a long List this is much faster then comparing the length
|
|
|
|
|
with zero.
|
|
|
|
|
@ -1999,22 +2060,35 @@ expand({expr} [, {flag}]) *expand()*
|
|
|
|
|
See |glob()| for finding existing files. See |system()| for
|
|
|
|
|
getting the raw output of an external command.
|
|
|
|
|
|
|
|
|
|
extend({list1}, {list2} [, {idx}]) *extend()*
|
|
|
|
|
Append {list2} to {list1}.
|
|
|
|
|
If {idx} is given insert the items of {list2} before item
|
|
|
|
|
{idx} in {list1}. When {idx} is zero insert before the first
|
|
|
|
|
item. When {idx} is equal to len({list1}) then {list2} is
|
|
|
|
|
appended.
|
|
|
|
|
{list1} is changed when {list2} is not empty.
|
|
|
|
|
{list2} remains unchanged.
|
|
|
|
|
{list1} and {list2} must be Lists.
|
|
|
|
|
Returns {list1}.
|
|
|
|
|
extend({expr1}, {expr2} [, {expr3}]) *extend()*
|
|
|
|
|
{expr1} and {expr2} must be both Lists or both Dictionaries.
|
|
|
|
|
|
|
|
|
|
If they are Lists: Append {expr2} to {expr1}.
|
|
|
|
|
If {expr3} is given insert the items of {expr2} before item
|
|
|
|
|
{expr3} in {expr1}. When {expr3} is zero insert before the
|
|
|
|
|
first item. When {expr3} is equal to len({expr1}) then
|
|
|
|
|
{expr2} is appended.
|
|
|
|
|
Examples: >
|
|
|
|
|
:echo sort(extend(mylist, [7, 5]))
|
|
|
|
|
:call extend(mylist, [2, 3], 1)
|
|
|
|
|
< Use |add()| to concatenate one item to a list. To concatenate
|
|
|
|
|
two lists into a new list use the + operator: >
|
|
|
|
|
:let newlist = [1, 2, 3] + [4, 5]
|
|
|
|
|
<
|
|
|
|
|
If they are Dictionaries:
|
|
|
|
|
Add all entries from {expr2} to {expr1}.
|
|
|
|
|
If a key exists in both {expr1} and {expr2} then {expr3} is
|
|
|
|
|
used to decide what to do:
|
|
|
|
|
{expr3} = "keep": keep the value of {expr1}
|
|
|
|
|
{expr3} = "force": use the value of {expr2}
|
|
|
|
|
{expr3} = "error": give an error message
|
|
|
|
|
When {expr3} is omitted then "force" is assumed.
|
|
|
|
|
|
|
|
|
|
{expr1} is changed when {expr2} is not empty. If necessary
|
|
|
|
|
make a copy of {expr1} first.
|
|
|
|
|
{expr2} remains unchanged.
|
|
|
|
|
Returns {expr1}.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
filereadable({file}) *filereadable()*
|
|
|
|
|
The result is a Number, which is TRUE when a file with the
|
|
|
|
|
@ -2025,23 +2099,29 @@ filereadable({file}) *filereadable()*
|
|
|
|
|
Obsolete name: file_readable().
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
filter({list}, {expr}) *filter()* *E712*
|
|
|
|
|
For each item in {list} evaluate {expr} and when the result is
|
|
|
|
|
zero remove the item from the List.
|
|
|
|
|
Inside {expr} the symbol "&" stands for the existing
|
|
|
|
|
item. Example: >
|
|
|
|
|
:call filter(mylist, '& !~ "OLD"')
|
|
|
|
|
< Removes the items where "OLD" appears. And this: >
|
|
|
|
|
:call filter(mylist, 0)
|
|
|
|
|
filter({expr}, {string}) *filter()*
|
|
|
|
|
{expr} must be a List or a Dictionary.
|
|
|
|
|
For each item in {expr} evaluate {string} and when the result
|
|
|
|
|
is zero remove the item from the List or Dictionary.
|
|
|
|
|
Inside {string} |v:val| has the value of the current item.
|
|
|
|
|
For a Dictionary |v:key| has the key of the current item.
|
|
|
|
|
Examples: >
|
|
|
|
|
:call filter(mylist, 'v:val !~ "OLD"')
|
|
|
|
|
< Removes the items where "OLD" appears. >
|
|
|
|
|
:call filter(mydict, 'v:key >= 8')
|
|
|
|
|
< Removes the items with a key below 8. >
|
|
|
|
|
:call filter(var, 0)
|
|
|
|
|
< Removes all the items, thus clears the List or Dictionary.
|
|
|
|
|
|
|
|
|
|
Note that {expr} is an expression that evaluates to an
|
|
|
|
|
expression. Often it is good to use a |literal-string| to
|
|
|
|
|
avoid having to double backslashes.
|
|
|
|
|
The operation is done in-place. If you want a list to remain
|
|
|
|
|
unmodified make a copy first: >
|
|
|
|
|
Note that {string} is the result of expression and is then
|
|
|
|
|
used as an expression again. Often it is good to use a
|
|
|
|
|
|literal-string| to avoid having to double backslashes.
|
|
|
|
|
|
|
|
|
|
The operation is done in-place. If you want a List or
|
|
|
|
|
Dictionary to remain unmodified make a copy first: >
|
|
|
|
|
:let l = filter(copy(mylist), '& =~ "KEEP"')
|
|
|
|
|
< Returns {list}.
|
|
|
|
|
|
|
|
|
|
< Returns {expr}, the List or Dictionary that was filtered.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
finddir({name}[, {path}[, {count}]]) *finddir()*
|
|
|
|
|
@ -2141,6 +2221,11 @@ get({list}, {idx} [, {default}]) *get*
|
|
|
|
|
Get item {idx} from List {list}. When this item is not
|
|
|
|
|
available return {default}. Return zero when {default} is
|
|
|
|
|
omitted.
|
|
|
|
|
get({dict}, {key} [, {default}])
|
|
|
|
|
Get item with key {key} from Dictionary {dict}. When this
|
|
|
|
|
item is not available return {default}. Return zero when
|
|
|
|
|
{default} is omitted.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
getbufvar({expr}, {varname}) *getbufvar()*
|
|
|
|
|
The result is the value of option or local buffer variable
|
|
|
|
|
@ -2388,6 +2473,12 @@ has({feature}) The result is a Number, which is 1 if the feature {feature} is
|
|
|
|
|
string. See |feature-list| below.
|
|
|
|
|
Also see |exists()|.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
has_key({dict}, {key}) *has_key()*
|
|
|
|
|
The result is a Number, which is 1 if Dictionary {dict} has an
|
|
|
|
|
entry with key {key}. Zero otherwise.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
hasmapto({what} [, {mode}]) *hasmapto()*
|
|
|
|
|
The result is a Number, which is 1 if there is a mapping that
|
|
|
|
|
contains {what} in somewhere in the rhs (what it is mapped to)
|
|
|
|
|
@ -2662,6 +2753,8 @@ len({expr}) The result is a Number, which is the length of the argument.
|
|
|
|
|
used, as with |strlen()|.
|
|
|
|
|
When {expr} is a List the number of items in the List is
|
|
|
|
|
returned.
|
|
|
|
|
When {expr} is a Dictionary the number of entries in the
|
|
|
|
|
Dictionary is returned.
|
|
|
|
|
Otherwise an error is given.
|
|
|
|
|
|
|
|
|
|
*libcall()* *E364* *E368*
|
|
|
|
|
@ -2764,20 +2857,25 @@ localtime() *localtime()*
|
|
|
|
|
1970. See also |strftime()| and |getftime()|.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
map({list}, {expr}) *map()*
|
|
|
|
|
Replace each item in {list} with the result of evaluating
|
|
|
|
|
{expr}.
|
|
|
|
|
Inside {expr} the symbol "&" stands for the existing
|
|
|
|
|
item. Example: >
|
|
|
|
|
:call map(mylist, '"> " . & . " <"')
|
|
|
|
|
map({expr}, {string}) *map()*
|
|
|
|
|
{expr} must be a List or a Dictionary.
|
|
|
|
|
Replace each item in {expr} with the result of evaluating
|
|
|
|
|
{string}.
|
|
|
|
|
Inside {string} |v:val| has the value of the current item.
|
|
|
|
|
For a Dictionary |v:key| has the key of the current item.
|
|
|
|
|
Example: >
|
|
|
|
|
:call map(mylist, '"> " . v:val . " <"')
|
|
|
|
|
< This puts "> " before and " <" after each item in "mylist".
|
|
|
|
|
Note that {expr} is an expression that evaluates to an
|
|
|
|
|
expression. Often it is good to use a |literal-string| to
|
|
|
|
|
avoid having to double backslashes.
|
|
|
|
|
The operation is done in-place. If you want a list to remain
|
|
|
|
|
unmodified make a copy first: >
|
|
|
|
|
|
|
|
|
|
Note that {string} is the result of expression and is then
|
|
|
|
|
used as an expression again. Often it is good to use a
|
|
|
|
|
|literal-string| to avoid having to double backslashes.
|
|
|
|
|
|
|
|
|
|
The operation is done in-place. If you want a List or
|
|
|
|
|
Dictionary to remain unmodified make a copy first: >
|
|
|
|
|
:let tlist = map(copy(mylist), ' & . "\t"')
|
|
|
|
|
< Returns {list}.
|
|
|
|
|
|
|
|
|
|
< Returns {expr}, the List or Dictionary that was filtered.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
maparg({name}[, {mode}]) *maparg()*
|
|
|
|
|
@ -3911,7 +4009,7 @@ instead of "s:" when the mapping is expanded outside of the script.
|
|
|
|
|
|
|
|
|
|
:fu[nction] {name} List function {name}.
|
|
|
|
|
*E124* *E125*
|
|
|
|
|
:fu[nction][!] {name}([arguments]) [range] [abort]
|
|
|
|
|
:fu[nction][!] {name}([arguments]) [range] [abort] [dict]
|
|
|
|
|
Define a new function by the name {name}. The name
|
|
|
|
|
must be made of alphanumeric characters and '_', and
|
|
|
|
|
must start with a capital or "s:" (see above).
|
|
|
|
|
@ -3950,6 +4048,10 @@ instead of "s:" when the mapping is expanded outside of the script.
|
|
|
|
|
abort as soon as an error is detected.
|
|
|
|
|
The last used search pattern and the redo command "."
|
|
|
|
|
will not be changed by the function.
|
|
|
|
|
When the [dict] argument is added, the function must
|
|
|
|
|
be invoked through an entry in a Dictionary. The
|
|
|
|
|
local variable "self" will then be set to the
|
|
|
|
|
dictionary. See |Dictionary-function|.
|
|
|
|
|
|
|
|
|
|
*:endf* *:endfunction* *E126* *E193*
|
|
|
|
|
:endf[unction] The end of a function definition. Must be on a line
|
|
|
|
|
|