Krzysztof MaJ wrote:
[...]
Hi,
I have a question. If I open my GVIM from the Dock and after that I open some file from the gui it sets PWD to my home directory not to the place from the file really is. If I open the same file clicking on it in Finder VIM sets PWD to the right place (to directory from this file is). I have written above lines to my .gvimrc but without any effects. Could somebody explain me what's going on? It's really frustrating because if I don't change the path manually forgetting about it, GVIM write my file in the home directory not in the place where it really is, making two diffrent copies of it.

How to correct it?

Cheers,
--Pozdrawiam - Krzysztof Maj
 I'm a Mac now, are you PC?
Oh, dear... ;-)






By default, Vim doesn't change directories when you open a file. If you open Vim from the Dock, without a filename, the current dir is your home directory. If you later edit one or more files, the current directory is unchanged. If you want to edit a file which is not in the current dir, you should specify the path as part of the argument to the ":edit" command. (You can use command-line completion repeatedly to complete one subdirectory or file name at a time.) If you type just ":e filename", then if "filename" doesn't exist in the current directory, Vim will assume that you want to create a new file there.

If, instead, you click a file in Finder, the OS sets the current directory to that file's directory, then invokes Vim.

If Vim is compiled with +netbeans_intg or with +sun_workshop, you can set 'autochdir'. This will change the current directory whenever you edit a new file, switch buffers, etc., so the current directory will follow the current file. Vim will still not "guess" a directory name (how could it?): ":e filename" with no path, still means that you want to edit (or create) a file in the current directory, whatever it is.

Alternately, you can use

        :autocmd BufWinEnter * lcd %:p:h

which will set a "local directory" for each buffer. This alternative only requires +autocmd, which is included in "Normal", "Big" and "Huge" builds of Vim.

Personally, I've tried it, and I've found that I don't like directory changes happening, so to speak, "behind my back". I prefer that directories only be changed when I use ":cd" or ":lcd" explicitly. (YMMV)

In any case, each window's status line (when present) displays the path to the file in that window, relative to the current directory if possible, or otherwise as an absolute path.

See
        :help 'autochdir'
        :help :autocmd
        :help BufWinEnter
        :help :cd
        :help :lcd
        :help 'laststatus'


Best regards,
Tony.

Reply via email to