How to Find the Currently Opened File in vim – Editor Tips

vim

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>?)

Best Answer

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.

Update

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).

Related Question