Method 1. Change the properties of your desktop shortcut so that it loads
gvim --cmd "cd C:\my\preferred\startup\dir"
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
Best regards,
Tony.
--
People need good lies. There are too many bad ones.
-- Bokonon, "Cat's Cradle" by Kurt Vonnegut, Jr.
You need to do exactly one thing to get this behaviour: In your shortcut, change the value of 'Start in:' to 'your\prefered\startup\directory'. When starting vim from the command line, it should use the current directory, and likewise when you right-click and 'Edit' or 'Edit with Vim' in Explorer. This is how my gvim works; there's no need to mess around with 'autochdir' or '--cmd'.
Henrik.
You probably can write a function that hooks into the VimEnter event
(:help autocommand-events) and then checks if there is only one buffer
(:help bufnr()) and if this buffer is a unnamed buffer (:help bufname()).
HTH,
Dennis Benzinger
You can get the number of file arguments:
:h argc()
--
Andy
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"
When starting [g]vim from a prompt (a cmd promt in the Dos Box or a
shell prompt in a Unix-like shell including Cygwin bash), the current
directory can be anything (I expect most often $HOME or the filesystem
root rather than $VIMRUNTIME) so in that case your getcwd() test will
disable the cd to your/preferred/startup/dir/. OTOH you may want to set
your preferred startup dir as the current directory in your preferred
shell and your desktop icon (maybe define a desktop icon with a startup
directory and another one without, to disable the cd command when
dropping a file on the latter icon).
Another possibility to avoid running a certain part of the vimrc when
re-sourcing it a 2nd (3rd, etc.) time in a vim session is the way it is
done in other plugins: in this case, put it near the end:
if exists(vimrc_started)
finish
endif
let vimrc_started = 1
" add any first-time-only commands here,
" until the end of the vimrc.
cd /my/preferred/startup/directory
Still another possibility would be to set any first-time-only commands
in an autocommand for the VimEnter event, which is triggered exactly
once in each session, at the very end of startup; but of course only if
the +autocmd feature has been compiled-in. (The above ":if" method won't
work in versions without +eval, where every ":if" is regarded as a
nestable comment, and ":let" causes an error.)
Best regards,
Tony.
--
Back up my hard drive? I can't find the reverse switch!