This may sound trivial but, on more than one occasion, I have found myself having forgotten which file in vim I have open (e.g. when I am looking through different log files and such) and the only way I knew how to find out was to close the file and look in the command history for the most recent command.

Is there a command within vim to tell you which file you currently have opened without exiting the program or the file you have opened (e.g. :<which_file_cmd>?)


9 Answers 9


In addition to uprego's answer, you can press Ctrl+G (in normal mode) to get the current buffer's name as well as the total number of lines in it and your current position within it.


As per rxdazn's comment, you can press 1 before Ctrl+G to get the full file path. If you press 2, you get the full file path and the buffer number you currently have open (useful when you have opened multiple files with vim).

  • 1
    Like a lot of vim commands this also applies to the less command which I use when viewing files as opposed to editing.
    – jmathew
    Commented Dec 12, 2013 at 21:56
  • 21
    also, pressing 1 before Ctrl+G gives you the file's full path
    – rxdazn
    Commented Dec 13, 2013 at 1:57

gives the name of file currently open.

  • 2
    brilliant and very minimalist
    – amphibient
    Commented Dec 18, 2013 at 16:51

When in vim I always use the :ls command.


  1 %a   "blah.txt"                         line 1

Where blah.txt is the file's name.


When vim is not called with many args, :args is helpful.

  • 5
    The other problem with this is that if the file was opened after vim was launched, it won't be listed.
    – phemmer
    Commented Dec 12, 2013 at 17:57

If you can have a default vim configuration file, you can add a statusline to always have file details available. I understand that if you're constantly remoting into different servers this won't be much help. Here's my slightly complex one pulled from my .vimrc.

" %F(Full file path)
" %m(Shows + if modified - if not modifiable)
" %r(Shows RO if readonly)
" %<(Truncate here if necessary)
" \ (Separator)
" %=(Right align)
" %l(Line number)
" %v(Column number)
" %L(Total number of lines)
" %p(How far in file we are percentage wise)
" %%(Percent sign)
set statusline=%F%m%r%<\ %=%l,%v\ [%L]\ %p%%

" Change the highlighting so it stands out
hi statusline ctermbg=white ctermfg=black

" Make sure it always shows
set laststatus=2

And it looks like this in MacVim (but works in terminals as well). enter image description here

As always you can do :help statusline to get some more options and details. And checkout Learning Vim the Hard Way ch 17 for a good explanation of statusline.

  • I always use statusline as well. +1
    – Rob
    Commented Dec 13, 2013 at 15:46

I my vimrc I have this mapping

nnoremap <leader>pfn :echo expand('%:p')<CR>

So if I type ,pfn, or "print file name", it echos the entire file path.


There's also :echo @%, which gives you the name of the file relative to the current directory.


There countless ways to get this kind of info, but if you want something so that you only have to press a key and the filename will be displayed then insert the following into your ~/.vimrc:

map <F4> <ESC>:file<CR>

This says,

bind the `F4' key to the following sequence: Escape-key, :file, Carriage-Return (enter-key)

And the file command, as is probably apparent, returns the name of the current file along with other info.

You could also setup a status-line so that you wouldn't even have to do anything but look.

To keep the status-line always insert the following into your ~/.vimrc:

set laststatus=2

This tells ViM to always display a status-line, other options are 0, for never, and 1 for only when you have two or more windows open in ViM.


I usually just type :e and this shows me the full file path and number of lines and characters too.

Caveat: it reopens the file from disk essentially, so it's most useful when the file is already saved.

:help :e says:

                          *:e* *:edit*
Edit the current file.  This is useful to re-edit the
current file, when it has been changed outside of Vim.
This fails when changes have been made to the current
buffer and 'autowriteall' isn't set or the file can't
be written.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .