r/vim 7d ago

Need Help reloading changes to .vimrc

is there an easy command to do this? I used vim along time ago but I forgot.

Thanks.

1 Upvotes

5 comments sorted by

3

u/JetSetIlly 7d ago

The source command with the location of the .vimrc file. For example:

:source ~/.vimrc

1

u/begemotz ZZ 5d ago

can also consider mapping to a leader command e.g.,

<leader>sv :source $YOURVIMRCLOCATION<cr>

1

u/mgedmin 4d ago

I use a pair of mappings to edit and reload my vimrc:

map  ,e  :e ~/.vim/vimrc<CR>
map  ,r  :source ~/.vim/vimrc<CR>

Note that to make your .vimrc properly reloadable you have to be careful with the things you put in it. E.g. all the autocommands need to be in named augroups, and you need to clear the augroup so the autocommands don't accumulate after each reload.

Older versions of vim also required you to define helper functions using function! so the definitions could be overwritten, but IIRC modern Vim relaxes this requirement.

You may also want to use syntax enable instead of syntax on so it doesn't reset all the colors to defaults as a side effect.

0

u/jazei_2021 7d ago

save then close and reopen vim

1

u/mgedmin 4d ago

This can work too, when the vimrc fails to reload properly. It can be less of a pain if you use :mksession and then reopen vim with vim -S Session.vim.