1
0
forked from aniani/vim
vim/runtime/syntax/testdir/input/vim_lambda.vim
Doug Kearns 1aa287e048
runtime(vim): Update base-syntax, improve variable matching
- Match variables after operators, including line continuations.
- Match option variables without leading whitespace.
- Explicitly match expression subscripts.
- Match Vim9 variables in LHS of assignments and method calls.
- Match option variables (&option) with a dedicated syntax group like
  environment variables.
- Match list literals, fixes: #5830
- Match :{un}lockvar arguments.
- Match registers and environment variables in :let unpack lists.
- Match lambda expressions
- Match Vim9 scope blocks
- Match variables in :for subject
- Highlight user variables with Normal
- Improve this/super keyword matching, fixes: #15970

closes: #16476

Signed-off-by: Doug Kearns <dougkearns@gmail.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
2025-02-10 22:00:27 +01:00

121 lines
1.6 KiB
VimL

" Vim lambda expressions
let expr = 42
let Foo = {-> expr}
let Foo = {_ -> expr}
let Foo = {... -> expr}
let Foo = {x -> expr}
let Foo = {x, _ -> expr}
let Foo = {x, ... -> expr}
let Foo = {x, y -> expr}
" line continuations
let Foo = {->
"\ comment
\ expr
\ }
let Foo = {_ ->
"\ comment
\ expr
\ }
let Foo = {... ->
"\ comment
\ expr
\ }
let Foo = {x ->
\ expr
"\ comment
\ }
let Foo = {x, y ->
"\ comment
\ expr
\ }
let Foo = {
\ ->
"\ comment
\ expr
\ }
let Foo = {x
\ ->
"\ comment
\ expr
\ }
let Foo = {x, y
\ ->
"\ comment
\ expr
\ }
let Foo = {x,
\ y,
\ z -> expr}
let Foo = {
\ x,
\ y,
\ z
\ ->
"\ comment
\ expr
\ }
let Foo = {-> [
\ 42,
\ 83
\]}
let Foo = {-> {
\ 'a': 42,
\ 'b': 83
\}}
let Foo = {-> #{
\ a: 42,
\ b: 83
\}}
let Foo = {-> {->[
\ 42,
\ 83
\]}}
let Foo = {-> {-> {
\ 'a': 42,
\ 'b': 83
\}}}
let Foo = {-> {-> #{
\ a: 42,
\ b: 83
\}}}
" :help lambda
:let F = {arg1, arg2 -> arg1 - arg2}
:echo F(5, 2)
:let F = {-> 'error function'}
:echo F('ignored')
:function Foo(arg)
: let i = 3
: return {x -> x + i - a:arg}
:endfunction
:let Bar = Foo(4)
:echo Bar(6)
:echo map([1, 2, 3], {idx, val -> val + 1})
" [2, 3, 4]
:echo sort([3,7,2,1,4], {a, b -> a - b})
" [1, 2, 3, 4, 7]
:let timer = timer_start(500,
\ {-> execute("echo 'Handler called'", "")},
\ {'repeat': 3})