recursing vimrc

I use vim a lot. a *LOT*. One thing that really annoys me is page width. When I’m writing code, I like to have a width set to 78 characters. But in some instances, say when I’m working on a book, I like the width set to 90 characters since it’s easier to read. This got me thinking… if I had vim check the current directory for a config, I could have custom configs for different directories. so in ~/.vimrc, I added

if filereadable("./.vimrc")
        source ./.vimrc
endif

and this works great, with one exception… what if i’m sitting in my home directory?

morgajel@p-nut ~ $ vim .vimrc
Error detected while processing /home/morgajel/.vimrc:
E169: Command too recursive
Hit ENTER or type command to continue

it goes into a recursive loop… so now my question is, how do I prevent that? I’m presuming that “changing the if statement to also check and make sure the current directory isn’t home” is the way to go, but I’m not seeing much documentation on how to go about doing it, or at least I’m not looking for the correct thing. Any suggestions?

3 Responses to “recursing vimrc”

  1. on 21 Jun 2006 at 5:44 pm dendrite

    One way to avoid the recursion issue is to use .pwdvimrc (Or something like that) for the directory specific vim runtime configs. E.g., if filereadable(”./.pwdvimrc”) … Note that I just made up the name .pwdvimrc. Could be .AnythingNotMagicallyReadWhenVimLoads

  2. on 21 Jun 2006 at 7:51 pm Marc

    I like dendrite’s suggestion - no reason why they need to be called .vimrc - in fact it might be more confusing.

  3. on 30 Jun 2006 at 12:43 pm Jesse Morgan

    forgot to mention- I did end up going with a new filename- .pvimrc

    I’d like to learn how to do it eventually, but for right now I’m not too concerned.

Trackback this Post | Feed on comments to this Post

Leave a Reply