2

I'm working in gvim with sessions and tabs, and everything works great. However there is something that is bothering me.

Say I have two files open: /A/B/foo.ext and /C/D/E/bar.ext, the latter being opened last. Now say I want to open /A/B/foobar.ext. I have to go through the hassle of navigating upwards to / and from there to /A/B.

I would like to simply change my active tab to /A/B/foo.ext and have gvim automatically change its active directory to /A/B/, so that when I want to open /A/B/foobar.ext with /A/B/foo.ext being active, I'm already in the right CWD.

This would be very time-saving if you work with two different projects at a time and need to switch back and forth between the two.

Is there any such script that does just that?

Thanks.

1
  • Sorry, found it: set autochdir. It seems the directive was too early in my .vimrc and got overwritten by something else. Commented Mar 12, 2010 at 13:20

1 Answer 1

3

I have this in my .vimrc:

if exists('+autochdir') set autochdir else autocmd BufEnter * silent! lcd %:p:h:gs/ /\\ / endif 

As far as I remember, Vim has this option since v7.

HTH

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.