Hey, thanks for your suggestions.

I'd rather not change the properties of the shortcut, because that
would mean I'd have to make sure each vim shortcut has the right
properties, so using gvim --cmd or changing the 'Start in' property is
not what I want. I also tried using autochdir, but that didn't work;
vim still executed the cd C:\... line in my vimrc and I always started
in that same directory.

But I've found a pretty good solution; I know that when vim opens
without a file, it defaults to the installation directory, which in my
case is "C:\Program Files\Vim\vim72" at the moment. So in my vimrc I
just added a test:

if (getcwd() == "C:\\Program Files\\Vim\\vim72")
        cd C:\my\preferred\directory
endif

So now whenever I open vim with a file, it stays in the file's
directory, but when I open vim without a file, it starts in whatever
directory I want.

There are 2 problems with this solution: (1) If I ever change the
installation directory (say if I install a new version of vim, which I
obviously will at some point), then I'd have to change the if
statement to match the new installation directory. Actually, if
someone knows a way of testing the installation/default start-up
directory from vim, then that would solve this problem. (2) If I ever
for some reason want to edit a file in the installation directory, vim
would cd to my preferred directory instead of staying in the file's
directory. But I don't see why I would want to do that.

On Oct 8, 6:19 am, Henrik Öhman <[EMAIL PROTECTED]> wrote:
> > -----Original Message-----
> > From: [email protected]
> > [mailto:[EMAIL PROTECTED] On Behalf Ofbgold12
> > Sent: Wednesday, October 08, 2008 9:05 AM
> > To: vim_use
> > Subject: Test if vim just opened with no file
>
> > Hey, is there way to test if vim was just started with no file?
> > Actually, I should start from the beginning:
>
> > I usually like to start vim by clicking on a shortcut on my Windows
> > taskbar, which means it'll start with an empty [No Name] buffer. In
> > this case, I would like my vimrc file to automatically set the
> > directory to a preferred start-up directory. But obviously when I
> > start vim with a file specified, either from the command line or from
> > double-clicking on a vim-associated file, I want the current directory
> > to be the directory the opened file is in, so I don't want my vimrc to
> > set the directory in that case. Any suggestions?
>
> > Thanks.
>
> 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 received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---

Reply via email to