How do I check the file name that is open in the terminal? That is, how do I check which file is open now in the terminal?

Now whenever I want to see the file name I have to exit and then have to check. Is there a way to check the current file name in the terminal?

  • 1
    if the file is open, then you must be reading it with some program. How are you opening the file? – Zanna Sep 30 '16 at 14:18
  • using vi editor , but once I open the file I could not see file name – Avani badheka Sep 30 '16 at 14:19

Use :f. It will display the filename as well as extra info:

enter image description here

You can also use :args to see what filenames as command line arguments were given to vim. This is convenient when you want to know which of the buffers you are using, if you opened multiple files (the current one is enclosed in brackets):

enter image description here

| improve this answer | |

To see the filename in vi(m) press esc and then type

:set title

The filename appears in the top bar of the terminal window. You can also do


to see the file(s) currently open - the information is displayed inside the terminal at the bottom. If you have multiple files open, you can tell which one you are in as %a is shown beside the current file, for example

  1 %a=   "unicorns"      line 19     
  2       "rainbows"      line 1
Press ENTER or type command to continue
| improve this answer | |
  • 4
    And it might be a great idea to simply add set title in the ~/.vimrc configuration file.... – andrew.46 Sep 30 '16 at 21:42

I prefer Ctrl-G:


CTRL-G      or              *CTRL-G* *:f* *:fi* *:file*
:f[ile]         Prints the current file name (as typed, unless ":cd"
            was used), the cursor position (unless the 'ruler'
            option is set), and the file status (readonly,
            modified, read errors, new file).  See the 'shortmess'
            option about how to make this message shorter.
            {Vi does not include column number}
| improve this answer | |

The filename of the currently edited file is in the % register. You can view it with :reg %.

| improve this answer | |

I like a lot the status line: set laststatus=2 (or set ls=2)

vim status line screenshot

As you see, among other useful info like current mode, file status, ruler, etc. the status line displays the full path of the currently opened file.

See :help laststatus for more details.

*thanks Sven

I like to see the status line at any time, so I added the above instruction to my vim local configuration:

 sudo sh -c "echo 'set ls=2' >> ~/.vimrc"
| improve this answer | |
  • 1
    Ah, i see. The status line contains the name of the file. Good ! But you might edit your answer to actually explain why status line is necessary. First time I read your answer , I was confused , so a lot of people probably will be confused too. You need to edit for clarity – Sergiy Kolodyazhnyy Oct 5 '16 at 7:29
  • 1
    Also it's not necessary to set it in /etc/vim/vimrc.local. Set it in your ~/.vimrc will be sufficient. /etc/vim/vimrc.local is pretty much global, for all users – Sergiy Kolodyazhnyy Oct 5 '16 at 7:32

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.