Vi(m) tip #10: Current file name

A friend at work wanted to be able to see the name of the current file he was editing in vim without closing it or saving it. The solution he found was to enter in command mode:


<ctrl> <shift> G

This displays a little info bar on the bottom.

This made me remember that you can use % as a standin for the current file's name when issuing a command. As in:


:!echo %

which displays the current file name (up to bash gotchas).

Or you could write the current file to filename.temp with:


:w %.temp

I used this in an earlier post to typeset a latex document from vim as a oneliner.

Tags: , ,

Leave a Reply