When I'm editing a file in Vim, is there a command to see the path of the current file? Sometimes this is very handy if there are multiple files with the same name in a project.

10 Answers 10


You can press {count}Ctrl-G:

{count}CTRL-G       Like CTRL-G, but prints the current file name with
                    full path.  If the count is higher than 1 the current
                    buffer number is also given.

Pressing 1 followed by Ctrl+G shows the full path of the current file. If {count} is higher than 1, the buffer name will also be shown.

(Pressing only Ctrl+G shows the path relative to Vim's current working directory, as pointed out by Jasper in the comments.)

You can use the following command in your .vimrc to add the full path to the status line, so it is always visible:

set statusline+=%F
  • 4
    Isn't Ctrl+G more like 'path relative to vim's cwd'? – Jasper Feb 3 '15 at 18:58
  • @Jasper Good catch! Updated the answer. – thameera Feb 3 '15 at 19:06
  • 4
    It seems C-g is default for 0C-g, and 2C-g shows buffer index number (starting from 1) as well in addition. – user10767 Apr 24 '17 at 16:27
  • I'm so happy to be the 100th to upvote your answer! Thanks for this 1C-g! – vault Nov 6 '18 at 15:08

Register % contains the name of the current file.

The following commands could be entered to display the information shown:

:echo @%                |" directory/name of file
:echo expand('%:t')     |" name of file ('tail')
:echo expand('%:p')     |" full path
:echo expand('%:p:h')   |" directory containing file ('head')

If all that is wanted is to display the name of the current file, type :f/:ls or press Ctrl-g (for full path press 1 then Ctrl-g).

In insert mode, type Ctrl-r then % to insert the name of the current file.

The following commands insert lines consisting of the full path of the current and alternate files into the buffer:

:put =expand('%:p')
:put =expand('#:p')

Source: Get the name of the current file at vim wikia


  • 2
    It may be worth noting that you can also use those =expand... expressions after Ctrl-R when in insert mode, too. – dash-tom-bang Jan 3 '18 at 2:01

You can use :!ls %:p to get the full path to the current file.

Depending on the ex context, % will either mean the contents of the file or the filename. When shelling out, it represents the file path relative to the current directory. The command '%:p' will add the full path filename modifier to %.

There are a few other interesting filename modifiers such as:

  • :~: Get the file path relative to the home directory (this one didn't work for me for some reason)
  • :.: Get the file path relative to the current directory (% default)
  • :r: File name root. The name of the file without the extension.
  • :e: File's extension.
  • :h: Split on / and return the left half (i.e. if I'm editing a file in a path of /tmp/test.txt and run %:p:h will return /tmp
  • :t: Split on / and return the right half (i.e. if I'm editing a file in a path of /tmp/test.txt and run %:p:t will return text.txt
  • I think you meant %:p: t will return text.txt – John O'M. Feb 5 '15 at 4:20
  • @JohnO'M. yep, that's right thanks :D. Fixed. – CharlesL Feb 5 '15 at 12:43

One can see the current working directory with :pwd. Of course, this is only the directory, and not the filename. To get the working directory and filename, we can use the special register %, which contains information about the current file.

If you use :echo @%, you'll get the directory and filename of the current file.
If you use :echo expand('%:p'), you'll get the full path and filename of the current file. This is very similar to CharlesL's answer.

I remember this one, though, because if you use vim's help :h expand, then it mentions that % and %:p and their relatives.


There are aleady better answers, but if (for some reason) you wanted to use the shell to get the full path of the file (this is more useful if you're going to perform some other operation on the file with the shell), on a Unix-like system you could run:

:!realpath %


:'<,'>!realpath %

to insert the path into the document over the current selection.

Register % always contains the name of the file. A realworld example might be if you're editing a config file, but don't have write permissions (and don't want ot run Vim as root), you could edit the file, then run:

:w ! sudo tee %

to save the file (a tiny bit offtopic there, but it's a good example of what else can be done with the % register).

  • realpath isn't POSIX, so it might be simpler to do: !echo "$PWD/%" – muru Feb 18 '15 at 0:57

To show the full path for all files, including resolved symlinks, use the following.

:echo resolve(expand('%:p'))

You need to set your status line to be viewable and also set it to path. I did so permanently by adding the two lines below to my ~/.vimrc

set laststatus=2
set statusline+=%F

If you want to just run that once. Then when VIing a document type

:set laststatus=2       <ENTER>
:set statusline+=%F     <ENTER>

The following will display the path relative to your current directory:


That is :f or :file.

  • Simple and useful – Morteza Ziyae Jun 22 '19 at 8:49
  • 1
    doesnt show the full path – sjas Nov 3 '19 at 1:50
  • @sjas indeed, updated – Cédric Van Rompay Nov 6 '19 at 17:26
  • added a proper answer to the OP:s question after i found it elsewhere – sjas Nov 7 '19 at 16:17

I use vim airline for that and some nice features:

enter image description here


You can show the complete path of the file you are editing in the title bar, which is a convenient way to show the file path in my opinion.

In order to do that, you need to set the title option and titlestring. Current I am using the following settings:

set title
set titlestring=%{hostname()}\ \ %F\ \ %{strftime('%Y-%m-%d\ %H:%M',getftime(expand('%')))}

It will show the hostname of Vim, then the complete path of the file and followed by last modified time of the file. See the figure below for a demo

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.