1

The :lua and :luafile commands take an optional [range] specification. But it's unclear what effect it has (unlike the :luado command, where the effect is explained clearly in the help text).

Is there some way for the invoked chunk of Lua code to ask what the range was?

For example, the result of vim.api.nvim_get_current_line() is unaffected by the range. And for the nvim_buf_get_lines() function you have to pass start and end line numbers explicitly (there's no magic passing through of the command's range to these functions, AFAICT).

1 Answer 1

0

it's unclear what effect it has

It is ignored.

Is there some way for the invoked chunk of Lua code to ask what the range was?

As an example,

command! -range -nargs=1 MyLua
    \ call v:lua.loadstring('local line1, line2 = select(1, ...);'
    \   .. <q-args>)(<line1>, <line2>)

:/foo/,/bar/MyLua for n, l in pairs(vim.fn.getline(line1, line2)) do print(line1 - 1 + n, l) end
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.