For most my projects I prefer my directory to be at a particular project root. However for some (mostly vimwiki) it's easier to have vim change the folder to the file location. This is easily done with: au BufEnter *.wiki lcd %:p:h.

Every so often I need to make wiki entries during my programming so I end up with several :lcd jumps. Going back to the project I'm then stuck in the directory of the last change. When it was just one page I visited I can go back with :cd -, but that's a rare case. Often the other buffers from the project are not useful as they are "deep" down in the hierarchy of the project.

Is there any way to get the last "global" directory (from startup or a :cd) and reset to it?

I experimented with separate windows and tabs, which would separate the changes, but they don't work for me. My screen is too small to have several windows next to each other and with tabs I keep accidentally opening the wiki in my "main" one.

1 Answer 1


Is there any way to get the last "global" directory

Yes, it's getcwd(-1). So it could be, for example

:exe 'lcd' fnameescape(getcwd(-1))

Your Answer

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

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