Vim: use the path of the current file

8

4

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.

Nathan Long

Posted 2011-03-03T21:44:32.840

Reputation: 20 371

Answers

16

Answered at https://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

ssice

Posted 2011-03-03T21:44:32.840

Reputation: 756