Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm currently adding a little bit of Git functionality to my menu.vim file, and for using a certain command (Gitk) I need to find out Vim's current directory.

How does one do that and include it in a command? (i.e. :!echo "%current-directory")

I'll admit here that I asked the wrong question - but I figured it out.

I'm currently using these in my menu.vim:

function g:Gitk()
  :!cd $(dirname %); gitk

function g:GitGui()
  :!cd $(dirname %); git gui
share|improve this question
I removed the "active-directory" tag, it has a different meaning. – phunehehe Feb 26 '11 at 5:11
If you're running a shell command, the current directory is in the shell variable $PWD. – Gilles Feb 26 '11 at 11:19
up vote 22 down vote accepted

I think either :pwd or getcwd() is what you are looking for.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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