采购nvim.init并不采购所需的lua文件
我有Neovim 0.7.0运行,我的.vimrc在〜/.config/nvim/init.vim
我也有以下文件:〜/.config/nvim/nvim/lua/statusline.lua,带有一行代码: print('来自statusline.lua的消息')
insion.vim我有:
echo 'from init.vim'
lua require('statusline')
当我启动nvim时,我会收到两个消息('来自init.vim''和'statusline.lua'的消息))这就是我所期望的。
当我运行时:源$ myvimrc,我只会看到'init.vim'。我希望其他消息(来自statusline.lua'的消息)也会出现。
我认为这意味着我在statusline中进行的任何更改。当我运行:source $ myvimrc
时,LUA都不会生效。我应该如何在不关闭和重新启动Neovim的情况下源init.vim文件加上所需的任何文件?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
通过附加
将false
返回到模块的末尾,要么通过附加将缓存条目无效。或者根本不使用完全不需要,因为无论如何您都不需要缓存或路径搜索。例如
PS LUA不是“配置工具”。这是一种功能齐全的编程语言。如果您不喜欢通过正确学习时间来浪费时间(即阅读书籍和教程),则强烈建议您使用vimscript。它具有一些自己的“黑暗角落”,但更适合编写配置。
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.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.
这取决于您的statusline.lua的设计以及有关LUA'模块加载程序系统的知识。
看起来,因为我必须围绕statusline.lua烦恼,它没有任何返回。
因为返回已进入软件包。已加载和同一会话中的同样的要求首先在此处查找
statusline
因此,尝试一下...
我已经在上面测试了...
编辑
另一种用于做有用的事情的设计...
和...
比您有一个表查看器,您可以看到功能和表的来自...
:lua dump(_g)
-全局环境表:LUA DUMP(VIM)
- NVIM Stuff(aka模块):lua dump(vim.api)
- NVIM API函数(AKA库):Lua dump(jit)
- 正义编译器;-):lua dump([table name])
- 任何看起来有趣的表格: lua dump(package.poaded)
- 所需或需要的东西可以执行上述函数,而无需定义
dump
首先使用::lua require('dump')(_ g)
因此:首先需要加载dump.lua到package.loaded.dump中并返回它,每一个需要返回:
package.loaded.dump
如果您的眼睛敏锐,请看一下
_G.DUMP
,这只是一个引用(指针/链接)到package.loaded.dump。edit2
准备dump.lua将其与
vim.api.nvim_input()
一起使用> 'i')vim.api.nvim_input(dump(vim.api))
由于许多nvim api函数返回表,dump函数变得很方便...

It depends on the design of your statusline.lua and knowledge about Lua' module loader system.
It looks, because i have to riddle about statusline.lua, that it nothing returns.
Because the return is going into package.loaded and same require in same session looks first there for
statusline
So give following a try...
I have tested above with...
EDIT
Another design for doing something usefull...
And...
Than you have a table viewer and you can see where the functions and tables come from with...
:lua dump(_G)
-- The global environment table:lua dump(vim)
-- The nvim stuff (aka Module):lua dump(vim.api)
-- The nvim API functions (aka Library):lua dump(jit)
-- The Just In Time Compiler ;-):lua dump([Table Name])
-- Any table that looks interesting:lua dump(package.loaded)
-- The required or requireable stuffAbove function can be executed without defining
dump
first with::lua require('dump')(_G)
So: First require loads dump.lua into package.loaded.dump and returning it and every further require returning:
package.loaded.dump
If you have an sharp eye than take a look on
_G.dump
thats only a reference (pointer/link) to package.loaded.dump.EDIT2
Preparing dump.lua for using it with
vim.api.nvim_input()
Now the dump function returning a string and the output can be loaded into nvim with:
:lua vim.api.nvim_input('i') vim.api.nvim_input(dump(vim.api))
Since many nvim API functions returning a table the dump function becomes handy with...
