2

I saw something strange happen today. I was in directory /some/path/ and opened a file with vim file.html.

I then did :pwd in vim and it gave me /some/other/path. What could cause this to happen?

EDIT: :verbose set autochdir? outputs noautochdir

EDIT2: putting set autochdir in ~/.vimrc doesn't solve it.

I tried this:

  1. cd /dir1/
  2. vim dir2/newfile
  3. :pwd -> /dir1/
  4. cd /dir1/dir2/
  5. vim newfile
  6. :pwd -> /dir1/dir2/

This is the behavious I expect (:pwd returning the directory in which I launched vim) so I don't understand why for one particular file it doesn't work like that.

I figured it must be somehow caused by It is definitely caused by these lines in ~/.vimrc:

autocmd BufWinLeave * mkview
autocmd BufWinEnter * silent loadview

I deleted my ~/.vimrc and :pwd returned the correct directory.

After I restored it, the situation reverted to the original problem. I still don't understand how it happenned, I can't recreate the issue.

3
  • Please add the output of :verbose set autochdir? to the question.
    – muru
    Commented Mar 28, 2017 at 10:23
  • this gave me no output EDIT: my bad, forgot ?
    – pocpoc47
    Commented Mar 28, 2017 at 11:14
  • Hmm... mkview stores a lot of stuff, not just folds. It mentions 'sessionoptions' in the documentation and sessionoptions has a curdir option. This might be what's causing it, but I'm not sure. You could try taking curdir out of sessionoptions and see if that helps.
    – Tumbler41
    Commented Mar 28, 2017 at 15:04

2 Answers 2

4

As of vim8, mkview by default stores current directory for every buffer. You can find lcd <path> lines inside your views.

To disable this: set viewoptions-=curdir

2

In your vimrc put set autochdir and your path will always follow your current file. Otherwise vim will usually stay in either your home directory or in the first file you edited without you explicitly telling it to change with cd.

See :help 'autochdir' for more info.

1
  • please see my edits
    – pocpoc47
    Commented Mar 28, 2017 at 14:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.