Reply to message «Re: Way to skip systemwide vimrc?», 
sent 04:27:08 13 May 2011, Friday
by Ben Schmidt:

> redir => s:vars
>     let
> redir end
> for s:var in split(s:vars,'\n')
>     if s:var =~ '^v:' | continue | endif
>     if s:var =~ '^s:' | continue | endif
>     if s:var =~ '^b:changedtick\s' | continue | endif
>     exec "unlet ".matchstr(s:var,'^.\{-}\ze\s')
>     unlet s:var
> endfor
> unlet s:vars
    call map(keys(g:), 'remove(g:, v:val)')
    call map(filter(range(1, bufnr('$')), 'bufexists(v:val)'),
            \'map(keys(getbufvar(v:val, "")), '.
            \    '"remove(getbufvar(".v:val.", \"\"), v:val)")')
    let curtabnr=tabpagenr()
    for tabnr in range(1, tabpagenr('$'))
        for winnr in range(1, tabpagewinnr(tabnr, '$'))
            let windict=gettabwinvar(tabnr, winnr, '')
            call map(keys(windict), 'remove(windict, v:val)')
        endfor
        execute 'tabn' tabnr
        call map(keys(t:), 'remove(t:, v:val)')
    endfor
    execute 'tabn' curtabnr
    unlet tabnr curtabnr winnr

It will clear all variables: global, buffer, window, tabpage for all buffers, 
windows and tab pages. It does not uses redirections which I do not like.

    for s:group in split(s:augroups)
        exec "autocmd! ".s:group
        unlet s:group
    endfor
You forgot to delete the augroup itself:
    for s:group in split(s:augroups)
        exec "autocmd! ".s:group
        execute 'augroup!' s:group
        unlet s:group
    endfor

Original message:
> > Unfortunately, $VIM is only used for the user rc. $VIM =
> > /usr/share/vim, but global vimrc = /etc/vimrc, despite whatever I
> > tried to override VIM/VIMRUNTIME with.
> 
> How annoying. Your Vim must be compiled with a system vimrc path
> hardcoded in, rather than using $VIM.
> 
> > Going with the alias v='vim -u ~/.vimrc -N' solution. Not too
> > horrible, I guess.
> 
> Hmm. That's not a bad option. Just pondering the problem, though,
> another thing you can try, if you don't mind the increased startup time,
> is trying to clear everything (well, as much as you can) and start from
> scratch in your vimrc. I had fun putting together a little script to do
> it:
> 
> set all&
> syntax off
> filetype off
> highlight clear
> comclear
> mapclear
> mapclear!
> autocmd!
> set nomore
> redir => s:augroups
>     augroup
> redir end
> for s:group in split(s:augroups)
>     exec "autocmd! ".s:group
>     unlet s:group
> endfor
> unlet s:augroups
> redir => s:funcs
>     function
> redir end
> for s:func in split(s:funcs,'\n')
>     exec "delfunction ".matchstr(s:func,'\s\zs.\{-}\ze(')
>     unlet s:func
> endfor
> unlet s:funcs
> redir => s:vars
>     let
> redir end
> for s:var in split(s:vars,'\n')
>     if s:var =~ '^v:' | continue | endif
>     if s:var =~ '^s:' | continue | endif
>     if s:var =~ '^b:changedtick\s' | continue | endif
>     exec "unlet ".matchstr(s:var,'^.\{-}\ze\s')
>     unlet s:var
> endfor
> unlet s:vars
> set more&
> 
> It won't clear out local variables for other buffers/windows/scripts,
> but otherwise should pretty much clear everything, I think. And before
> plugins are loaded there shouldn't be much/any of that stuff anyway.
> 
> You might want to protect it somehow if you source your vimrc
> mid-session (I sometimes do) so that the clearing only happens at
> startup. Otherwise you'll 'turn off' all your plugins each time you
> source your vimrc mid-session (as they won't be loaded automatically
> like they are at startup). Just using a global variable or something
> like that should work. Another way around it would be to do
> 
> :set noloadplugins
> :runtime! plugin/**/*.vim
> 
> in vimrc and then plugins would be loaded by your vimrc, not Vim itself,
> and it would happen every time your vimrc was sourced.
> 
> Just another few ideas.
> 
> Ben.

Attachment: signature.asc
Description: This is a digitally signed message part.

Reply via email to