While I'm still new here, I would like to share my "version" based on
Yakov's.  Below uses "\\" directory separator so this will not work on
any *nix.  I could make it more os-independent by doing an `if' and `let
cmdsep=whatever', but I'm positive there's a better way to do it.  Or
maybe there's just a way to chop off the topmost directory name from a
string. In any case, the function below simply seeks to the root of the
filesystem searching for a _lvimrc and stops after finding one.

function! ExecuteLocalConfig()
        let x = expand('%:p:h')
        let fn = x . "/_lvimrc"

        if filereadable(fn)
                exe "source " . substitute(fn, ' ', '\\ ', 'g')
        else
                while strridx(x, "\\") != -1
                        let p = strridx(x, "\\")
                        let x = strpart(x, 0, p)
                        let fn = x . "/_lvimrc"

                        echo fn
                        if filereadable(fn)
                                exe "source " . substitute(fn, ' ', '\\
', 'g')
                                break
                        endif
                endwhile
        endif
endfunc

" handle local config au
if !exists("au_localconfig")
  let au_localconfig = 1

  au BufNewFIle,BufRead * call ExecuteLocalConfig()
endif


Chuck

-----Original Message-----
From: Yakov Lerner [mailto:[EMAIL PROTECTED] 
Sent: Tuesday, September 05, 2006 3:20 AM
To: Andrea Spadaccini
Cc: [email protected]
Subject: Re: Execute something when I enter in a directory

On 9/5/06, Andrea Spadaccini <[EMAIL PROTECTED]> wrote:
> Hello vimmers,
> I'd like to load some settings when I enter in a directory, like for
> instance setting makeprg.
>
> Is there a way to do it?
> Thanks in advance from a lurker! :)

I have this in my .vimrc:

au BufRead,BufNewFile * let x=expand('%:p:h')."/.lvimrc" | if
filereadable(x) | exe "source ".x | endif
let x=expand('%:p:h')."/.lvimrc" | if filereadable(x) | exe "source ".x
| endif

Then I put directory-specififc settings into file .lvimrc in that
directory.

Yakov

Reply via email to