Skip to content

[Discussion] equivalence of example .vimrc in Lua? #456

@SichangHe

Description

@SichangHe

This is not a bug report.
I just want to discuss a bit about using dein in init.lua.

Problems summary

I could not find any instructions from the internet on how to use dein in init.lua.
Though, I found people asking for Lua apis.
I suppose posting my solution on dein's issue might help some people find theirs.

My solution

This is done by calling Vim functions from Lua.

In lua/dein.lua: (Edit: simplified. Edit2: Noice: NvimConfigPath and HomeDir are global variables defined in init.lua, see below. )

Dein = {}
local set = vim.opt
local fn = vim.fn
local add = fn['dein#add']
local begin = fn['dein#begin']
local check_install = fn['dein#check_install']
local install = fn['dein#install']
local end_ = fn['dein#end']

function Dein.activate()
    -- Neovim is always "nocompatible".

    -- Required:
    -- Add the dein installation directory into runtimepath
    local dein_path = NvimConfigPath .. "dein" -- Replace with yours.
    set.runtimepath:append(dein_path)

    -- Required:
    local cache_path = HomeDir .. "/.local/share/dein" -- Replace with yours.
    begin(cache_path)

    -- Let dein manage dein
    add(dein_path)

    -- Add or remove your plugins here like this:
    -- add('Shougo/neosnippet.vim')
    -- add('Shougo/neosnippet-snippets')

    -- Required:
    end_()

    -- Syntax highlighting is enabled by default on Neovim.

    -- If you want to install not installed plugins on startup.
    -- if check_install() == 1 then install() end
end

return Dein

And call this function in init.lua

-- `~/.config/nvim/`
NvimConfigPath = debug.getinfo(1).source:match("@?(.*/)")
-- `~`
HomeDir = os.getenv('HOME')

-- other stuff

require('dein')
Dein.activate()

Please critisize 🙏. Otherwise, feel free to use it.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions