Skip to main content
  1. Posts/

How Do I Show the Current File Path In Neovim?

··378 words·2 mins·
Table of Contents

I saw on StackExchange that someone asked about how to see the full path of current file in Vim. I think it would be helpful to write about how I do it.

Temporary solution
#

To show the full path of current file, you can press {count}Ctrl-G, that is, a count bigger or equaling to 1, followed by Ctrl-G. If you press 1<C-G>, only the full path of the file will be shown. If you press a number bigger than 1, the buffer index of current file will also be shown. For more info, see :h Ctrl-G.

You can also use expand() function to see the full path of current file:

:echo expand('%:p')

In the above command, % is special character which represents the name of current file. :p is a path modifier which is used to show the full path of the file. Please see the expand() doc on other types of path modifiers.

Permanent solution
#

If you want to show the current file path permanently so that you can see its path whenever you like. A good place to put the file path is the title bar. In order to do that, you need to set the title and titlestring. Currently, 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.

The titlestring is just a string. You can use pre-defined modifier to show the content of various variables and the results of various functions. It seems a bit complicated. But in fact, it is not so scary. It uses the same syntax as the statusline (see :h statusline).

In the above setting for titlestring, we first show the hostname of the Nvim using the hostname() function. %{} is a special modifier, which will evaluate the expression inside and subsititute the returned result as a string. %F is a modifier used to show the full path of the file. The getftime() function is used to show the last modified time of the current file. strftime() function is used to convert the time to pre-defined format, that is YYYY-mm-dd HH:MM.

The end result is something like the following

Related

Sort lines based on a column in Vim/Nvim
··231 words·2 mins
Vim 实现的输入法体验
··195 words·1 min
A Beginner's Guide on Creating Your Own Text Objects from Scratch in Neovim/Vim
··1234 words·6 mins