Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I use Ctrl-G to see the path. But I want to enter the path to the file itself.

How can I achieve this in Vim?

share|improve this question

1 Answer 1

up vote 6 down vote accepted

The name of the current file is contained in the % register. See

:help quote%

You can insert the contents of that register as you would any other register, e.g.,

"%p
"%P
:put %

and in insert mode as

<C-R>%

where <C-R> means Ctrl-R.

You can also expand the file name to its full path and select various parts of the path or file name using expand() and file name modifiers. See

:help expand()
:help filename-modifiers

As an example, while in insert mode, you could type

<C-R>=expand("%:p")

followed by Enter, where again <C-R> means Ctrl-R, which would insert the full path name of the current file. See

:help i_CTRL-R_=
share|improve this answer

Your Answer

 
discard

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.