vim is showing a different current working directory than the one I started vim with from the command-line. The problem goes away if I run without my .vimrc (vim -u NONE). How can I debug this to figure out why this is happening?

$ pwd
$ vim --noplugin
:edit settings.sh

The problem goes away if I don't use my .vimrc:

$ vim -u NONE


  • :set autochdir? outputs noautochdir
  • :verbose set autochdir? outputs noautochdir
  • :!pwd and :pwd both output the same directory
  • The problem also occurs with vim --noplugin
  • I have recently upgraded vim and python (via brew upgrade).
  • I have not changed my .vimrc lately (other than adding some comments). It's under version control in git, so I confirmed these have been the only changes.
  • I have installed and updated my plugins with vundle (:VundleInstall and :VundleUpdate).
  • I have made some changes to my .bashrc but nothing that I think would change vim behavior.
  • OS: macOS Mojave 10.14.6
  • vim: 8.2 (2019 Dec 12, compiled Aug 20 2020 22:44:15) Compiled by Homebrew

EDIT: I initially thought this was due to doing :edit other-file, but now I see it with just editing a single file, so I changed the above to remove that unnecessary aspect.

  • Hmmm, in answering this question, I'm assuming that the "different directory" is actually the directory of "other-file", is that the case? If not, does the other directory have any relation to any of the files?
    – filbranden
    Aug 22, 2020 at 1:45
  • 1
    I just discovered that I can reproduce the problem with just editing a single file (:edit other-file is not necessary). I have updated the question now to reflect that. No, I don't the the other directory having any relation to the file. Aug 22, 2020 at 7:07
  • 2
    Are there symlinks involved?
    – D. Ben Knoble
    Aug 22, 2020 at 11:56
  • Since with -u NONE the problem doesn't happen, perhaps take a look at How do I debug my vimrc file?
    – filbranden
    Aug 22, 2020 at 17:42
  • 1
    Thanks @filbranden -- that lead me to the source of the issue and the solution! See my answer below. Aug 23, 2020 at 19:23

1 Answer 1


Reason: I had done an :lcd at some point, and my .vimrc has autocmds to mkview and loadview when leaving and entering a buffer, so editing the file again was doing an :lcd to the other directory.


option 1 -- change the current working directory to the directory of the file being edited, and save:

cd %:p:h

option 2 -- remove the corresponding view file, e.g.,

$ rm ~/.vim/view/*myfile*

How I solved / debugged:
I bisected my .vimrc file to determine the offending line, which was:

autocmd BufWinEnter * silent! loadview

That indicated it was due to a view that was getting loaded. I then viewed the corresponding view file in ~/.vim/view and searched for the directory name, which yielded this line:

lcd ~/quizme-read-only-prod

See also: Working directory different than current file directory?

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.