I know this thread is long dead, but I've made a minor improvement to
my choice of solution that I feel is worth mentioning.
The solution I chose previously was:
if (argc() == 0)
cd C:\my\preferred\startup\dir
endif
This works perfectly all the time, when STARTING vim; the only problem
is if you ever want to re-source your vimrc file while editing (for
example, to reset your settings to your preferred settings). If you
had started vim with no arguments (meaning, for example, from a
shortcut, like I usually do), then argc() will remain 0 for the
duration of the instance of vim (as far as I know and have tested),
and so the directory will ALWAYS be reset to your "preferred"
directory whenever you re-source your vimrc. This is undesirable,
because usually, once you've gotten into editing files in an instance
of vim, you don't want to be cd'd to any default directory.
My solution is as follows:
if (bufnr("$") == 1 && bufname("$") == "" && getcwd() == $VIMRUNTIME)
cd C:\my\preferred\startup\dir
endif
With this solution, your directory will only be changed to your
preferred directory when (A) there is only one buffer, (B) that buffer
has yet to be named, and (C) the current directory is still the vim
default installation directory. Note that the first time vim is
opened, if it was given no arguments (i.e. opened from a shortcut),
then it will automatically be cd'd out of the vim default installation
directory and into your preferred directory, disqualifying (C) for the
remainder of the instance of vim, unless you for some reason cd
yourself back into that directory, but then in that case presumably
you would start editing a file with a name, which would disqualify
(B).
On Oct 8, 11:20 pm, Tony Mechelynck <[EMAIL PROTECTED]>
wrote:
> On 09/10/08 05:32, Ben Schmidt wrote:
>
>
>
> >> Method 2. There's nothing obvious in wanting Vim to always set the
> >> current directory to the directory of the current file: 'autochdir'
> >> (q.v.) defaults to off, and as a matter of fact I don't set it on.
> >> However if you do, I think it doesn't matter which directory you :cd to
> >> in your vimrc, whenever you enter a file (including the first file on
> >> the command-line) Vim should change to the file's directory. So in that
> >> case I think you could just write the following into your vimrc:
>
> >> set autochdir
> >> cd C:\my\preferred\startup\dir
>
> > You don't need autochdir, and may not want it (e.g. because you don't
> > want it changing after opening the first file, but only when opening the
> > first file). Also, the Windows version automatically does that (changes
> > for the first file, but doesn't set autochdir).
>
> > :help vim-default-editor
> > :help send-to-menu
>
> > Ben.
>
> See the other replies. The simplest seems to be
>
> if !argc()
> cd C:\my\preferred\startup\dir
> endif
>
> Best regards,
> Tony.
> --
> "God gives burdens; also shoulders"
>
> Jimmy Carter cited this Jewish saying in his concession speech at the
> end of the 1980 election. At least he said it was a Jewish saying; I
> can't find it anywhere. I'm sure he's telling the truth though; why
> would he lie about a thing like that?
> -- Arthur Naiman, "Every Goy's Guide to Yiddish"
--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---