I am new to Vim and I want to be able to edit scripts with my keyboard bindings and other Vim settings while still working in Vim.

For instance I would like all most of my set xx commands to be in one file and have the ability to update the file and reapply its settings while still in Vim. Is it a matter of source-ing the file as I am editing it?


Is it a matter of source-ing the file as I am editing it?

Yes! :so % should do the trick when you're editing your vimrc. Or you can also use the special variable $MYVIMRC to access it from anywhere. I have a mapping like the following:

nnoremap <F5> :source $MYVIMRC<CR>


There are a few things you need to do to your vimrc to make sure you can re-source it safely.

  • Make sure all your functions start with function!. The ! makes a re-declaration of the function simply overwrite the function without a warning.
  • If you have any autocmds, make sure you include them in a group and start the group with au!. This will make sure that you don't set up your autocmds more than once. And if you edit one, it will delete the old instance.


augroup MyAutocmds
augroup END
  • map <F9> :so $MYVIMRC<Enter>:echo ".vimrc reloaded"<Enter> is mine, but roughly the same thing :) Apr 20 '17 at 21:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.