Vimscript is great for configuration, but in Neovim, Lua is becoming more of an attractive choice (at least IMO) for configuration, such that I'm switching my init.vim over as much as I can to an init.lua. While doing this, I've noticed that there isn't a simple and easy-to-use Lua equivalent to the Vimscript functions plug#start(), Plug 'foo' and plug#end(). How feasible would it be to add these Lua functions for Neovim users?
Example functions which could be added: plug_start(), plug(), and plug_end(). However, it would be nice to be able to call plug() once, giving it a Lua table containing each plugin name. Then plug_start() and plug_end() wouldn't be necessary: just the (potential?) requirement of only calling plug() once.
So, after some discussion on neovim's gitter @norcalli came up with this implementation:
local vim = vim
local function plug(path, config)
vim.validate {
path = {path, 's'};
config = {config, vim.tbl_islist, 'an array of packages'};
}
vim.fn["plug#begin"](path)
for _, v in ipairs(config) do
if type(v) == 'string' then
vim.fn["plug#"](v)
elseif type(v) == 'table' then
local p = v[1]
assert(p, 'Must specify package as first index.')
v[1] = nil
vim.fn["plug#"](p, v)
v[1] = p
end
end
vim.fn["plug#end"]()
end
-- Example usageplug {'julia', { g = {default_julia_version = '1.1'} }}
plug('~/.config/nvim/plugged', {
'norcalli/nvim-colorizer.lua';
{'Peeja/vim-cdo'; on = {'Cdo', 'Ldo'} };
})
@norcalli Also mentioned some possible additions, like adding a g = {} option for setting globals (e.g. plug {'julia', { g = {default_julia_version = '1.1'} }} and a disabled flag.
Nice thing is that all of this could be added to plug.vim via a lua block, like so:
lua << EOF
-- Lua code goes here
EOF
@junegunn What do you think?
Hi, I don't see myself using it anytime soon so I'm not interested in maintaining it in this project (implementing it, adding tests for it, documenting it, answering questions and responding to feature requests about it, etc).
Most helpful comment
So, after some discussion on neovim's gitter @norcalli came up with this implementation:
@norcalli Also mentioned some possible additions, like adding a
g = {}option for setting globals (e.g.plug {'julia', { g = {default_julia_version = '1.1'} }}and adisabledflag.Nice thing is that all of this could be added to
plug.vimvia a lua block, like so:@junegunn What do you think?