Dictionary is created and returned. {expr1} remains
unchanged. Items can still be changed by {expr2}, if you
don't want that use |deepcopy()| first.
Parameters: ~
• {expr1} (`any`)
• {expr2} (`any`)
Return: ~
(`any`)
mapset({mode}, {abbr}, {dict}) *mapset()*
mapset({dict})
Restore a mapping from a dictionary, possibly returned by
|maparg()| or |maplist()|. A buffer mapping, when dict.buffer
is true, is set on the current buffer; it is up to the caller
to ensure that the intended buffer is the current buffer. This
feature allows copying mappings from one buffer to another.
The dict.mode value may restore a single mapping that covers
more than one mode, like with mode values of '!', ' ', "nox",
or 'v'. *E1276*
In the first form, {mode} and {abbr} should be the same as
for the call to |maparg()|. *E460*
{mode} is used to define the mode in which the mapping is set,
not the "mode" entry in {dict}.
Example for saving and restoring a mapping: >vim
let save_map = maparg('K', 'n', 0, 1)
nnoremap K somethingelse
" ...
call mapset('n', 0, save_map)
< Note that if you are going to replace a map in several modes,
e.g. with `:map!`, you need to save/restore the mapping for
all of them, when they might differ.
In the second form, with {dict} as the only argument, mode
and abbr are taken from the dict.
Example: >vim
let save_maps = maplist()->filter(
\ {_, m -> m.lhs == 'K'})
nnoremap K somethingelse
cnoremap K somethingelse2
" ...
unmap K
for d in save_maps
call mapset(d)
endfor
<
Parameters: ~
• {dict} (`table<string,any>`)
Return: ~
(`any`)
match({expr}, {pat} [, {start} [, {count}]]) *match()*
When {expr} is a |List| then this returns the index of the
first item where {pat} matches. Each item is used as a
String, |Lists| and |Dictionaries| are used as echoed.
Otherwise, {expr} is used as a String. The result is a
Number, which gives the index (byte offset) in {expr} where
{pat} matches.
A match at the first character or |List| item returns zero.
If there is no match -1 is returned.
For getting submatches see |matchlist()|.
Example: >vim
echo match("testing", "ing") " results in 4
echo match([1, 'x'], '\a') " results in 1
< See |string-match| for how {pat} is used.
*strpbrk()*
Vim doesn't have a strpbrk() function. But you can do: >vim
let sepidx = match(line, '[.,;: \t]')
< *strcasestr()*
Vim doesn't have a strcasestr() function. But you can add
"\c" to the pattern to ignore case: >vim
let idx = match(haystack, '\cneedle')
<
If {start} is given, the search starts from byte index
{start} in a String or item {start} in a |List|.
The result, however, is still the index counted from the
first character/item. Example: >vim
echo match("testing", "ing", 2)
< result is again "4". >vim
echo match("testing", "ing", 4)
< result is again "4". >vim
echo match("testing", "t", 2)
< result is "3".
For a String, if {start} > 0 then it is like the string starts
{start} bytes later, thus "^" will match at {start}. Except
when {count} is given, then it's like matches before the
{start} byte are ignored (this is a bit complicated to keep it
backwards compatible).
For a String, if {start} < 0, it will be set to 0. For a list
the index is counted from the end.
If {start} is out of range ({start} > strlen({expr}) for a
String or {start} > len({expr}) for a |List|) -1 is returned.
When {count} is given use the {count}th match. When a match
is found in a String the search for the next one starts one
character further. Thus this example results in 1: >vim
echo match("testing", "..", 0, 2)
< In a |List| the search continues in the next item.