Reputation: 13816
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.
Upvotes: 2
Views: 538
Reputation: 51603
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
Upvotes: 3