Whenever I do source! %MYVIMRC
it gets reloaded, but it is copied inside the file I am editing at the cursor location and comments are inserted all over the place and multiple times (.vimrc is about 200 lines, but I get over 600 lines inserted into whatever file I am editing) and it's all indented in a strange way.
I can't pinpoint the location of the error in vimrc. I've been experimenting with some fancy plugins lately like neocomplete and nerdcommenter, but removing them did not help. Commented out everything from vimrc and sourcing it did the same thing.
The thing is vim works perfectly as expected. I understand more or less everything I have in my vimrc (exceptions are some plugin configs), but it behaves 100% when I start it and just work in it. However, when I source it while working all hell breaks loose. I am on a slightly older version of vim on Debian stable.
Here is my vimrc just in case: https://github.com/sergenikov/vim-tmux-config/blob/master/.vimrc.
:source $MYVIMRC
sources all the Ex commands written in your vimrc. However, if you add a bang:source! $MYVIMRC
, it doesn't read Ex commands anymore but Vim commands (executed from normal mode, likedd
for example). So when you type:source! $MYVIMRC
, Vim probably searches for anything which looks like a normal command.a
,i
,A
,I
...), the rest of your vimrc file is inserted in your current buffer. So maybe try to remove the bang after the:source
command to see if that solves your issue.function
. If you don't put a bang afterfunction
, when you reload your vimrc, Vim will complain because you are trying to define a new function whose name is already taken by a previous version. To avoid this, you should always put a bang after every keywordfunction
in your vimrc:function! MyFunction()
This way the new version will overwrite the older one.command
andfunction
declarations have a bang attribute!
, which I can put afterfunction! Foo()
orcommand! Foo
. When vimrc is sourced, it will source the function. If there is not bang attribute, then it will not.