Tuesday, April 26, 2011

Re: Current Directory; how can I set it permanently?

On 26/04/11 10:46, pablo@ezrider.co.uk wrote:
>
> Hi All,
>
> Basically, VIM remembers the CD (Current Directory) from a file ages
> ago, and I simply cannot goad VIM into remembering a new one, try as I
> might. When I manually set CD using :cd /mypath, VIM remembers it for
> this session, but as soon as I close VIM and then start again, VIM
> starts using a current directory from ages ago. This must now be over a
> year ago that I was last using that directory. Tried using a modeline
> in each file to set current directory, but only options are allowed, not
> commands like cd. Googled and found out that I can use autochdir to
> forcibly change current directory as each file is opened, which works
> but seems a bit aggressive. As per my subject, please someone where
> does VIM remember the current directory?
>
> Much appreciated!
>
> Take care,
> Pablo.
>
> --
> You received this message from the "vim_use" 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

By default, Vim uses as "current" the directory which it inherits from
the terminal or from the desktop shortcut from which it was launched.

If you want Vim to start with a certain (constant) directory, either set
your desktop shortcut to use that as current directory, or start Vim
from a shell prompt (cmd.exe, bash, tcsh, ksh, zsh, Terminal.app,
whatever) after a cd to that directory.

If you want to remember the current directory from one session to the
next... beware that Vim can have several windows open at the same time,
with "local current directories" in any number of them. AFAIK :pwd and
getcwd() will return the local current directory (if any) of the current
window, or failing that the global current directory. You could still
store fnamemodify(getcwd(), ':p') at the VimLeave event and restore it
at the VimEnter event, or even from your vimrc, but if closing Vim with
several windows open in different directories, there's no guarantee that
you'll get the right one.


Best regards,
Tony.
--
hundred-and-one symptoms of being an internet addict:
75. You start wondering whether you could actually upgrade your brain
with a Pentium Pro microprocessor 80. The upgrade works just fine.

--
You received this message from the "vim_use" 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

No comments: