On 2006-05-24, "A.J.Mechelynck" <[EMAIL PROTECTED]> wrote:
> Furash Gary wrote:
> > I'm using VIM on windows with cygwin.  In my _vimrc I've got the
> > following
> >
> >     " automatically swithc directories 
> >     set autochdir
> >
> >     " For cygwin shell
> >     set shell=C:/cygwin/bin/bash 
> >     set shellcmdflag=--login\ -c 
> >     set shellxquote=\" 
> >
> > When I try to use cygwin stuff with the "!" command or similar things
> > from vim, it doesn't seem to know where it is.
> >
> > That is, if I open up a file on the desktop with gvim, and do
> >
> >     :pwd
> >
> > It prints out the path of the desktop (thanks to autochdir I think).
> > However, if I do
> >
> >     :! pwd
> >
> > It prints out the location of my windows home directory.  Is there
> > anyway I could automatically pass to the shell the location it should
> > start in?
> >
> >
> >
> >   
> ":pwd" and ":! pwd" don't return the same directory, that is normal. 

In my experience, such behavior is not normal.

> ":pwd" returns Vim's internal "current directory", it changes whenever 
> you use internal ":cd", and 'autochdir' can change it implicitly; such 
> changes are not brought back to the shell.

They are not "brought back" to the parent shell's environment, but
they do affect the environment of any shell that vim executes.

>                                            To change the shell's current 
> directory (as shown by ":! pwd" on Unix-like systems and by ":! cd" on 
> dos-like systems) you can use the ":! cd" command, as follows:

":!cd somedirectory" will not do anything useful.  It will start a
shell, change the working directory of that shell, and the shell
will exit, returning control to vim.  It will not affect the
environment of vim or of any subsequent shell.

> au BufReadPost * exe "!cd" expand("%:p:h")
> 
> The above is untested but I believe it ought to work on Unix as well as 
> on Windows.

Windows handles its process environments differently than Unix does.
If the Windows shell, cmd.exe, starts another program and that
program performs a cd, when that program exits, the working
directory of cmd.exe will have changed to the directory set by the
program.  In Unix, on the other hand, a process inherits its
environment from its parent and passes its environment on to its
children, but changes to the environment by a child are never
reflected in the parent's environment.

Regards,
Gary

-- 
Gary Johnson                 | Agilent Technologies
[EMAIL PROTECTED]     | Wireless Division
                             | Spokane, Washington, USA

Reply via email to