vim9script process a range with a function

24 views
Skip to first unread message

Maxim Kim

unread,
Jan 11, 2022, 9:48:40 AMJan 11
to vim_use
How in vim9script a range should be processed by a def function?

Vim9.txt states that def functions do not support range option.

So given a range what def function would/should do? Run it for every line in range?

How do I get smth similar to a:firstline and a:lastline?

Bram Moolenaar

unread,
Jan 11, 2022, 1:15:04 PMJan 11
to vim...@googlegroups.com, Maxim Kim

> How in vim9script a range should be processed by a def function?
>
> Vim9.txt states that def functions do not support range option.
>
> So given a range what def function would/should do? Run it for every line
> in range?

Normally the function will be called for each line in the range.

> How do I get smth similar to a:firstline and a:lastline?

You can pass a range as an argument. Or use marks.

Thus you can't do "1,10call Func()" and have the function called once
for the range. You can define a user command that takes the range and
passes it to the function.

You could also use a legacy function with the range option that calls
the :def function with a:firstline and a:lastine.

--
Facepalm statement #4: "3000 year old graves? That's not possible, it's only
2014!"

/// Bram Moolenaar -- Br...@Moolenaar.net -- http://www.Moolenaar.net \\\
/// \\\
\\\ sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ ///
\\\ help me help AIDS victims -- http://ICCF-Holland.org ///
Reply all
Reply to author
Forward
0 new messages