Thursday, August 11, 2011

Re: "Edit with vim": Set working directory as folder containing editted file

On 12/08/11 01:39, sc wrote:
> On Thursday, August 11, 2011 18:13:27 Tony Mechelynck wrote:
>
>> On 11/08/11 23:19, Paul wrote:
>>> I have gvim 7.3 installed on Windows 7 Enterprise (32-bit).
>>> When I select a bunch of files, right-click, and choose
>>> "Edit with single Vim", the working directory for vim
>>> becomes "Symantec Endpoint Protection" rather than the
>>> folder that contains the selected files. Is there a simple
>>> tweak that I can make to ensure that the working directory
>>> is the same as the folder containing the editted files?
>
>> Possibility 1: (in Vimrc)
>
>> au VimEnter * silent! cd %:h
>
>> Note: This will always cd to the directory containing the last
>> edited file (if any), even if _not_ using Edit with Vim
>
>> Possibility 2: (at the keyboard) type
>
>> :cd %:h
>
>> Note: this is not automatic, you have to do it every time
>
>> Possibility 3: construct a keyboard shortcut and/or a .bat
>> file which would execute
>
>> gvim -c 'silent! cd %:h'
>
>> followed by all your file names
>
>> Note: This is not a complete solution, the detail is left to
>> the student as an exercise.
>
>
>> I tested none of them, and I am not on Windows (i.e., no "Edit
>> with Vim menu here).
>
> you missed one, tony:
>
> possibility 4: (in .vimrc)
>
> set autochdir
>
> sc
>

I didn't miss it, I left it out, because unlike the solutions I proposed
(all of which :cd once only, at the end of startup), it changes the
current directory whenever you change buffers, and it doesn't play well
with some plugins, including (IIRC) netrw.

If you set 'autochdir' in vimrc accompanied with an autocommand to set
'nooautochdir' at the VimEnter event, that becomes equivalent to my
first solution.


Best regards,
Tony.
--
hundred-and-one symptoms of being an internet addict:
155. You forget to eat because you're too busy surfing the net.

--
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: