klen / nvim-config-local

Secure load local config files for neovim
MIT License
151 stars 9 forks source link

Late sourcing #8

Closed coffebar closed 1 year ago

coffebar commented 1 year ago

I'm using this autocmd instead of plugin and tried to move to using plugin. But something doesn't work for me.

local au = vim.api.nvim_create_autocmd
local augroup = vim.api.nvim_create_augroup("user_cmds", { clear = true })

au("DirChanged", {
    group = augroup,
    desc = "Source local nvim config",
    callback = function()
        local rc = ".vimrc.lua"
        if vim.fn.filereadable(rc) == 1 then
            local cwd = vim.fn.getcwd()
            local confirm = "Do you trust " .. cwd .. "/" .. rc .. "?"
            if vim.fn.confirm(confirm, "Yes\nNo") == 1 then
                vim.api.nvim_command("source " .. rc)
            end
        end
    end,
})

Also I'm using this thing to switching projects. And with my "DirChanged" auto-command sourcing is working as expected. But with this plugin, for some reason, sourcing is late for 1 dir change. So for example, i go to dir1/project1 (without .vimrc.lua) then switching to dir2/project2 (has .vimrc.lua), cwd changed, but vimrc not sourced, then i go back to dir1/project1 and now sourcing dir2/project2/.vimrc.lua

klen commented 1 year ago

@coffebar Please try the latest version 2.0.0