RFC: Support for v:vim.opt dictionary to access vim options

59 views
Skip to first unread message

Yegappan Lakshmanan

unread,
Jan 24, 2022, 1:38:27 AM1/24/22
to vim_dev
Hi all,

Currently Vim options can be accessed from a Vim script by prefixing the
option name with a '&':

let &shiftwidth = 2
let oldval = &shiftwidth

The Python Vim interface supports a dictionary for accessing the Vim options
https://vimhelp.org/if_pyth.txt.html#python-options

The Lua Vim interface in Neovim support this:
https://github.com/neovim/neovim/blob/master/runtime/doc/lua.txt#L1022

But this is currently not supported by Vim script.

What do you think about adding support for a v:vim.opt dictionary to
read/modify Vim options:

let v:vim.opt.shiftwidth = 2
let oldval = v:vim.opt.shiftwidth
echo has_key(v:vim.opt, 'newopt')
echo keys(v:vim.opt)
echo items(v:vim.opt)

The changes to support this are available at:
https://github.com/yegappan/vim/commit/52beff56044e93c7bb982243ff593b461cd649c2

Regards,
Yegappan

Maxim Kim

unread,
Jan 24, 2022, 2:36:58 AM1/24/22
to vim_dev


&sw = 1
var old_sw = &sw
echo exists('&newopt')
echo getcompletion('', 'option') # this might be capped though, at least for other completions it is
for opt in getcompletion('', 'option')
    echo opt
endfor
for opt in getcompletion('', 'option')
    if !empty(opt)
       exe "set " .. opt .. "?"
    endif
endfor



And there is also buffer local options, are you about to have 2 dictionaries?

понедельник, 24 января 2022 г. в 09:38:27 UTC+3, yega...@gmail.com:

Bram Moolenaar

unread,
Jan 24, 2022, 6:43:09 AM1/24/22
to vim...@googlegroups.com, Yegappan Lakshmanan
I do not see the advantage. It's extra code, more choices for a script
writer, thus there needs to be a good justification.

--
BEDEVERE: How do you know so much about swallows?
ARTHUR: Well you have to know these things when you're a king, you know.
"Monty Python and the Holy Grail" PYTHON (MONTY) PICTURES LTD

/// 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