Friday, November 21, 2014

Re: vim opening files in wrong directory

On Friday, November 21, 2014 2:57:16 AM UTC-6, Paul Jungwirth wrote:
> Hello,
>
> Sometimes when I'm using vim it will start behaving as if I ran it in
> a different directory. It seems to be particular files that set it
> off, where I have other files with the same name elsewhere on my disk.
> For example, if I `cd ~/src/a/app/controllers` and `vi
> users_controller.rb`, then I `:e application_controller.rb`, vim will
> open ~/src/b/app/controllers/application_controller.rb. If I `:!pwd`
> I'll get ~/src/b/app/controllers. If I `:ls` it will show this:
>
> ~/src/a/app/controllers/users_controller.rb
> application_controller.rb
>
> I've been living with this for years, and I've never had success
> trying to Google it. If I close all my vim sessions and `rm -rf
> ~/.vim/view` the problem goes away for a little while, but it always
> comes back.
> ...
> My .vimrc is pretty short, but I'll paste it below just in case.
> ...
> au BufWinLeave * mkview
> au BufWinEnter * silent loadview
>

According to :help :mkview, view files will contain "the local current directory" which will be restored with loadview.

I don't see any way in 'viewoptions' to disable this.

I'd guess that at some point you changed directory while editing a file, which got stored in the view file.

I see that view files I create end with "doautoall SessionLoadPost" so you could probably create a SessionLoadPost autocmd to restore the directory to what you want.

Unfortunately, I don't know whether it is possible to get the current global directory, if a local directory is set.

To avoid the problem, you can avoid using :lcd, using either :cd or 'autochdir' to mess with the directory.

I thought maybe you could modify your mkview autocmd to not fire if global cd doesn't match local cd, but as mentioned I'm not sure how you'd do that. I suppose you could :cd to the current directory in that autocmd to clear any previous :lcd but then your directory could change whenever you save.

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

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment