sevko
sevko

Reputation: 1426

Source .vimrc after map/function deletion

I'd like to reload my .vimrc without restarting vim; the obvious answer is :source $MYVIMRC, but only works when I've scripted a new function/keymap, and fails if I've deleted one. For instance:

" empty .vimrc
" to which I've added L()

function! Temp()
    echo "ABC"
endfunc

:w | so ~/.vimrc

Now, :call Temp() will yield, as expected, "ABC".

" now, I've deleted Temp()
:w | so ~/.vimrc

...and :call Temp() still generates "ABC". Quitting and re-opening my .vimrc, however, would remove the function from memory entirely. Can I achieve that behavior with :source?

Upvotes: 2

Views: 453

Answers (1)

Ingo Karkat
Ingo Karkat

Reputation: 172698

You would need to write a custom :Reload command that parses your .vimrc for function / command / mapping definitions, and :delfunction / :delcommand / :unmaps them. This is a considerable effort, and still unlikely to catch all cases. And all that to avoid a restart of Vim?!

Think hard whether you really need this (I cannot imagine any reason). We're talking about a few seconds of startup time, max. If you're concerned about having to re-open files etc., you can use the built-in :mksession for that (but again have to be careful what the session itself persists!)

Upvotes: 4

Related Questions