如何在不重新启动Neovim的情况下来源init.lua
是否有一种干净的方法来重新加载neovim init.lua配置及其所有模块(使用require()
函数)而无需重新启动Neovim?
我已经在另一篇文章上读到:luafile $ myvimrc
应该做到这一点,但不幸的是,它并没有重新加载那些缓存的文件。我希望像以前的init.vim
config一样设置keymap。沿着:
local opts = { noremap = true, silent = true }
vim.api.nvim_set_keymap("n", "<leader><CR>", ":luafile $MYVIMRC<CR>", opts)
我在NVIM v0.8.0上。
Is there a clean way to reload a neovim init.lua config and all its modules (using the require()
function) without restarting neovim?
I've read on another post that :luafile $MYVIMRC
was supposed to accomplish just that but it doesn't reload those cached files unfortunately. I'm hoping to setup a keymap like I used to have in my previous init.vim
config. Something along the lines of:
local opts = { noremap = true, silent = true }
vim.api.nvim_set_keymap("n", "<leader><CR>", ":luafile $MYVIMRC<CR>", opts)
I'm on nvim v0.8.0.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
尝试运行此命令:
Try to run this command :
如果从此reddit线程这似乎很好。我最终创建了一个称为
reload.lua
的小型模块:init.lua 中导入。
在
它 LUA文件需要包含在A 用户文件夹中:
〜/.config/nvim/lua/user/
。这也是reload.lua
生活的地方。注2:我认为可以使用
而不是名称:match('dublude-me')
REGEX语法来排除问题模块。If found an answer from creativenull on this reddit thread that seems to work well. I ended up creating a small module called
reload.lua
:That gets imported in
init.lua
:And for which I added a keymap:
Note 1: in the example above your lua files need to be contained in a user folder:
~/.config/nvim/lua/user/
. That's also wherereload.lua
lives.Note 2: I think it's possible to use the
not name:match('exclude-me')
regex syntax to exclude problematic modules.您可以使用
:luafile&lt; filename&gt;
。请参阅
:H:Luafile
有关更多信息。You can use
:luafile <filename>
for this.See
:h :luafile
for more information.这是另一个解决方案,还包括在/之后重新加载文件:
我的
〜/.config/nvim
文件夹树:我的
〜/.config/nvim。 init.lua
:Here's another solution that also includes reloading the files in the
after/
directory:My
~/.config/nvim
folder tree:my
~/.config/nvim.init.lua
:我不确定。我正在使用映射:W |因此%到源当前文件
源文件keymap
-update-
这仅在像这样的配置文件中起作用,
希望有这样的帮助
I am not sure yet. I am using mapping :w | so % to source current file
sourcing file keymap
--update --
this works in only config file
like this hope this help
此解决方案>解决方案在Neovim v0.7.7.7.7.7.7.7.2上对我有用。
然后,您可以将您的keymap配置为刷新$ myvimrc,如下所示:
This solution works for me on Neovim v0.7.2.
You can then config your keymap to refresh $MYVIMRC as follows:
:源
将做到。它也可以缩短为:so
。请参阅
:H:Source
有关更多信息。:source
will do it. It can also be shortened to:so
.See
:h :source
for more info.