How do you source neovim config file without restarting nvim?
Asked Answered
A

3

24

Is there a way to source the ~/.config/nvim/init.vim file from within nvim?

With vanilla vim you can source .vimrc with :so % : Is there an equivalent method do with similarly in neovim?

Analyzer answered 24/10, 2020 at 11:56 Comment(0)
A
32

$MYVIMRC is always available from inside vim or neovim, so you can just use

:source $MYVIMRC

and bind it to a convenient mapping:

nnoremap <Leader>sv :source $MYVIMRC<CR>

2021 update: If you are using neovim with a lua config, you can use :luafile $MYVIMRC

Analyzer answered 2/11, 2020 at 18:49 Comment(2)
Thanks a lot for sharing, didn't know about $MYVIMRC. In my setup I have multiple files lua files which I import from the entry-point init.lua. I noticed that executing :so nor :luafile didn't recursively source changes I made in the other files. Is there a way to work around that?Jacobine
@VladislavKovechenkov are you using something like this vim.cmd('luafile ~/.config/lvim/lua/mappings.lua')?Analyzer
S
5

How about use the map

let $my_vimrc = $localappdata.'\nvim\init.vim'
nnoremap <leader>s :source $my_vimrc<cr>
Smirch answered 2/11, 2020 at 9:1 Comment(1)
Thanks. I discovered that the variable $MYVIMRC is already set by default so you can just use that.Analyzer
K
0

If you use Neovim you can do something like :

local bind = vim.keymap.set
bind("n", "<leader>s", ":source $HOME/.config/nvim/init.lua <CR>")

But it's not use with Lazy.nvim

Klausenburg answered 30/5, 2023 at 12:5 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.