Sign up ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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

1 Answer 1

up vote 8 down vote accepted

Answered at

% is the actual file


is the dirname of the file


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

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.