The Problem
I would like to automatically set the scroll offset to half the value of vim.opt.lines
(see :help lines
).
I Tried
I tried the following:
vim.opt.scrolloff = vim.opt.lines // 2
I Expected
I expected this to retrieve the current value of vim.opt.lines
, divide it by 2, and assign the result to vim.opt.scrolloff
.
Results
This is what happened instead (upon reopening NeoVim):
Error detected while processing C:Users<user>AppDataLocalnviminit.lua:
E5112: Error while creating lua chunk: C:<user>AppDataLocalnviminit.lua:24: unexpected symbol near '/'
Press ENTER or type command to continue
My Questions
- Is this a syntax error?
- Is there any way to access
vim.opt.lines
or an equivalent value? - Can I not access vim option values? Is this universally true, or only true in this situation because vim options are still being defined while
init.lua
is being processed?
Note
I have previously just used
vim.opt.scrolloff = 26
which worked fine, but I was experimenting and wonering whether I could set it dynamically, which would be useful if I ever want to set the scroll offset to a quarter of the screen or something.
acid_tigR is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.