I tweaked this a bit and you asked for feedback…
        " Clear then re-read options after editing
        silent! function! ReloadVimrc()
                au!
                set all&
                source $MYVIMRC
        endfunction
        autocmd! BufWritePost $MYVIMRC nested call ReloadVimrc()

With $MYVIMRC this is not platform specific. However, vim forgets that $MYVIMRC 
is filetype=vim after running. I added a modeline:
        " vim: set filetype=vim :
…to the top of the file as a workaround.

-Adrian

On Dec 21, 2012, at 10:45 PM, stillLearningVim <[email protected]> wrote:

> @Marcin and @Gary, thanks for the brilliant suggestions of resetting the 
> options and the auto commands. Here's what I ended up with:
> 
> if !exists("*ReloadVimrc")
>     function! ReloadVimrc()
>          au!
>          set all&
>          so $HOME/.vimrc
>     endfunction
> endif
> 
> I tried "au BufWritePost .vimrc call ReloadVimrc()", but vim ends up doing 
> something recursive and progressively gives me more errors every time I save 
> (BufWrite isn't supposed to be recursive, not sure what's happening).
> 
> "au!" removes all autocommands, although I should definitely start putting 
> mine in groups. "set all&" resets all global and local variables to their 
> default values (calling set on anything changes both the local and global, 
> interesting info at ":h local-options" and a cool table a scroll away from 
> ":h setg").
> 
> Sorry it took me so long to respond. I kept getting a black-and-white every 
> time I called the function. Apparently calling :source on the vimrc didn't 
> change all the options back (used :set before and after calling this function 
> to see changes between non-default options), this included filetype=vim. I 
> hardcoded this into the function, hopefully I can find a better fix later.
> 
> I usually don't like long posts, so sorry about this one. Thanks again for 
> all the suggestions and cool tips. If you think of anything to improve on 
> this, please let me know. Every little bit helps. Thanks!
> 
> -- 
> You received this message from the "vim_use" maillist.
> Do not top-post! Type your reply below the text you are replying to.
> For more information, visit http://www.vim.org/maillist.php

-- 
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

Reply via email to