Super User is a question and answer site for computer enthusiasts and power users. 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

In Vim, how can I capture the path of the current file?

I know that the % register contains the name of the current file, but I want the path, so I can do something like

:w **bar.txt

... to "Save As" a new file, with ** representing the current file's path so that the new file will go in the same folder.

share|improve this question
up vote 12 down vote accepted

Answered at http://stackoverflow.com/questions/2233905/howto-get-full-path-of-current-file-in-vim

% is the actual file

%:p:h

is the dirname of the file

%:p

is the full path of the file. Use what you prefer.

In order to save files, just

:w %:p:h/something
share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .