Vim Tips Wiki
Advertisement

Duplicate tip

This tip is very similar to the following:

These tips need to be merged – see the merge guidelines.

Tip 530 Printable Monobook Previous Next

created 2003 · complexity basic · author Geoff Hubbard · version 5.7


To get the name of the file you are currently editing use:

@%

If you want to make sure of the path as well use:

expand("%:p")

References

Comments

To enter the name of the current file in insert or command mode, use <C-R>%.


If you want to use it as part of a command line just use %, for example:

!echo %

Without the extention:

!echo %:r

Ctrl-G is an easier way to get this info.


If you need to insert otherfile names (say the *.h name in an #include), you can do C-X+C-F for filename completion.


Complete path, filename and extension:

2+Ctrl-G

It can be useful to get the name of the current file in command mode, and be able to edit it. The % sign can be used to get the name, but that will not allow you to edit the path. By pressing ^R#, the current path will be inserted, and you can edit it to open another file.

Advertisement