[snip lengthy description]
> I've tried putting a "set noautochdir" in my .vimrc file, but that
> doesn't seem to make any difference.
>
Have you tried disabling your .(g)vimrc and .vim directory to see if the behavior persists?
Dave
--
"Only two things are infinite, the universe and human stupidity, and I'm not sure about the universe."
-- Albert Einstein
> Have you tried disabling your .(g)vimrc and .vim directory to see if the behavior persists?
Good thought, and yes it does. Moving all .vim* stuff out of my home
directory and starting macvim again, I get the same behaviour - the
working directory changes whenever I drag a file into the MacVim
window.
David
Try going through all the steps at
http://code.google.com/p/macvim/wiki/ReportingBugs
I cannot reproduce this behavior. If I open Terminal, mvim file1,
open another directory in Finder and drag the file onto the MacVim
window, then :pwd yields the folder of "file1". Please follow the
steps above to the letter -- there really should be no reason why the
working dir should change on a drag and drop. My initial thought was
that it sounds like you have an autocommand or something that causes
this.
Björn
The behaviour change is more subtle than I thought.
You're right - if I follow your steps exactly, i.e. cd into a
directory and then type "mvim file1" to open the MacVim window to edit
file1, then the working directory stays the same regardless of what
files I drag in from the finder window.
But, what I usually do is cd into my project directory and just type
"mvim" to open a blank window with the working directory set to the
project root. In that case, when I first do :pwd, the working
directory is the project root.
Then, as soon as I drag in a file from a different directory, the
working directory changes. In fact, the working directory seems to
lock to the directory containing whichever file is dragged in first.
Subsequent file drag and drops do not change :pwd
That's the difference from 7.2 - with MacVim 7.2, the working
directory stays at the project root, regardless of what files I drag
in, even if there was no file being edited in the first window.
Now that I know what's happening, I can work around it by always being
careful to type "mvim somefile" to open MacVim, or just make sure I
drag in a file from the project root before I do anything else.
Many thanks for taking the time to look into this.
David
> --
> You received this message from the "vim_mac" maillist.
> Do not top-post! Type your reply below the text you are replying to.
> For more information, visit http://www.vim.org/maillist.php
>
Good, I'm glad you figured it out.
This behavior of changing the pwd is a feature and not a bug. If you
open a new file (via open panel, by dropping, ...) the pwd is changed
if the window is "unused". A windows is classified as "unused" if:
1. only one tab
2. no changes in buffer
3. buffer has no filename associated with it
In most cases I think this is what you'd expect, but I can see that it
is confusing if you use "mvim" specifically to open a new window in a
certain directory. Not sure what to do about this? (I'm open to
suggestions.)
Björn
> This behavior of changing the pwd is a feature and not a bug. If you
> open a new file (via open panel, by dropping, ...) the pwd is changed
> if the window is "unused".
I can see the rationale for that.
Personally I often find myself working on a group of files, then
closing every buffer to have a "clean slate" before starting work on
the next bug/feature in the current project.
So, for me, this behaviour is unfortunate because it means I really
need to always keep at least one file open, so that the working
directory is not changed by the next file I open. That's not a serious
problem, of course, and I don't know if other people work in the same
way as I do, and find the behaviour unwelcome. Maybe it's just me!
> In most cases I think this is what you'd expect, but I can see that it
> is confusing if you use "mvim" specifically to open a new window in a
> certain directory. Not sure what to do about this? (I'm open to
> suggestions.)
How about testing for "noautochdir" at the point where the code
decides the window is unused? If noautochdir is set, then don't mess
with pwd. That way, users could have a way of disabling this behaviour
if they don't want it, and noautochdir is a fairly intuitive way to
think about turning it off.
Another possibility that I might look at for my own purposes is to use
a shell script to launch mvim, which first sets an environment
variable to `pwd`, and an autocmd in my .vimrc that chdirs to that
directory whenever a file is opened. That should force the working
directory to stay the same.
David
Hmmm...no that wouldn't work since "autochdir" is off by default so
this would effectively disable this feature.
I think I'll leave things as they are; if more people complain about
it I'll start thinking about a better solution. (It's only a guess,
but I think most people do want the pwd to be set to the first file
they open.)
Björn
Fair enough.
If I get my autocmd workaround done, I'll post it here.
David
On Sep 2, 2010 8:10 PM, "björn" <bjorn.w...@gmail.com> wrote:
On 2 September 2010 15:22, David Salgado wrote:
>
>> This behavior of changing the pwd is a feature ...
>> In most cases I think this is what you'd expect, but I can see that it
>> is confusing if you use...
Hmmm...no that wouldn't work since "autochdir" is off by default so
this would effectively disable this feature.
I think I'll leave things as they are; if more people complain about
it I'll start thinking about a better solution. (It's only a guess,
but I think most people do want the pwd to be set to the first file
they open.)
Björn
--
You received this message from the "vim_mac" maillist.
Do not top-post! Type your reply ...
My ideal would be the ability to fix the cwd for a given window by
opening it on a particular directory. Like this:
% mvim ~/ProjectDir
% mvim .
etc.
But I'm not that bothered.
cheers, J
This actually would not change the pwd since supplying a directory
name causes Vim to browse the directory with netrw...but I get what
you mean. ;-)
Björn
Right, I notice it doesn't, I'm just saying it would in the world
where my pet unicorn barfs rainbows :)
cheers, J
I see that something has to change...but I'm still not sure how. The
current behavior is confusing to say the least -- when I change it I
want it to be completely obvious what is going on. I'd rather avoid
introducing another option for this.
Under what circumstances _should_ the pwd be set?
Well, if new files open in a new window then I guess it should always
be set when opening a file (?), so the question only really applies to
when you've set MacVim to open files in the "current" window. Maybe
with this option set the pwd should never be touched? At least this
is consistent (I think your suggestions 1 & 2 may lead to some
confusion however).
Does anybody have comments on this (please make yourselves heard)?
Let me rephrase this slightly: is there anybody out there who has got
MacVim set to open files in the "current" window and who wants the pwd
to be set when they open a new file? (If so, when?)
> PS. Thanks for your work on MacVim, it is fantastic :)
I'm glad you like it!
Björn
My preference would be to never mess with the pwd if the window is already open.
If opening the file opens a new window, then I think it makes sense to
set the pwd to the directory containing the file.
David
I agree. This is the most intuitive behavior. I've pushed a patch already:
http://github.com/b4winckler/macvim/commit/c96d4dcc8e5b65bf989efa7e1b86f262974f935c
Björn
I'm glad you like it!
> PS. Thanks for your work on MacVim, it is fantastic :)
Björn
--
You received this message from the "vim_mac" maillist.
if the file has siblings, I'll just automatically use %:h/ to get to them
I'd like to try and avoid introducing more options. What different
types of behavior do you want?
Currently (after the latest patch) it goes like this when you open one
or more files (not using the "mvim" script):
1. If this causes a new window to appear on screen then the working
directory is set to the first file that is being opened (they are
sorted alphabetically because Finder does not "remember" the order in
which you select them).
2. Otherwise (i.e. you have gone into the prefs and set MacVim to open
new files in the "current" window, or you're dragging to a window) the
current directory is not touched.
The old behavior was broken because the pwd would change even if you
had manually gone in and changed it (e.g. via a ":cd .." command).
If you open files using the "mvim" script the working directory is the
same as Terminal's working directory.
If you open a new empty window (e.g. via Cmd+N, or when starting
MacVim) the working directory will be set to your home directory.
Björn
--
To explain what this is doing, I believe the help topic in vim for the description of these is 'filename-modifiers', and % is the filename of the current buffer.