Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sourcing nvim.init does not source required Lua files

Tags:

lua

neovim

I have neovim 0.7.0 running and my .vimrc is at ~/.config/nvim/init.vim

I also have the following file: ~/.config/nvim/lua/statusline.lua with one line of code: print('message from statusline.lua')

Inside init.vim I have:

echo 'from init.vim'
lua require('statusline')

When I start nvim I get both messages printed out ('from init.vim' and 'message from statusline.lua') which is what I would expect.

When I run :source $MYVIMRC I only see 'from init.vim'. I would expect the other message ('message from statusline.lua') to appear as well.

I assume this means any changes I make in statusline.lua will not take effect when I run :source $MYVIMRC. How should I source my init.vim file plus any files it requires without closing and restarting neovim?

like image 260
user3425506 Avatar asked Oct 15 '25 14:10

user3425506


1 Answers

Either invalidate cache entry by appending return false to the end of a module.

Or don't use require at all, as you need neither cache nor path search anyway. E.g.

for k, v in ipairs(vim.fn.glob("~/.config/nvim/init.d/*.lua", false, true)) do
    dofile(v)
end

P.S. Lua is not a "config tool". It is a full-featured programming language. If you don't like wasting your time by learning it properly (i.e. reading books and tutorials) you're highly suggested to use VimScript instead. It has some "dark corners" of its own but it is much better suited for writing config.

like image 61
Matt Avatar answered Oct 17 '25 03:10

Matt