How do you display the filename of the file you are working on in vim?
-
1If your terminal's set up correctly, you should get the filename in the window title. – Cascabel Nov 09 '10 at 19:05
-
1Also see: [How can I permanently display the path of the current file in Vim?](http://stackoverflow.com/questions/10488717/how-can-i-permanently-display-the-path-of-the-current-file-in-vim) – User Jun 02 '14 at 04:28
-
1Related: [How can I see the full path of the current file?](http://vi.stackexchange.com/q/104/467) at Vim SE – kenorb Feb 19 '15 at 12:01
-
4ctrl+g is can show the file info – Dhiren Hamal Jun 24 '19 at 06:42
10 Answers
:f
(:file
) will do same as <C-G>
. :f!
will give a untruncated version, if applicable.

- 5,254
- 1
- 23
- 19
-
3Nice, but it is possible to show it in the top bar of the terminal? (or terminator) or somewhere without type a command. – eMarine Sep 22 '14 at 08:34
-
27
-
1How about a full path? When I start vim from `~/dev/file.py` and execure `:f` within vim, I get `file.py` as the output instead of `~/dev/file.py`. – gxyd Dec 08 '17 at 13:43
-
2
-
2@jobima: it modifies `ctrl-g` to return path + file. `:f` will return filename without path, as might `ctrl-g`. A `1` before `ctrl-g` will show path & name (not necessarily expanded though). i.e. it will show `~/dev/file.py` instead of `file.py`. `2` followed by `ctrl-g` will include which buffer: `buf 1: "~/dev/file.py"`. – ives Jan 11 '19 at 18:04
-
ctrl+g will do it.
Also, I like to have:
set statusline="%f%m%r%h%w [%Y] [0x%02.2B]%< %F%=%4v,%4l %3p%% of %L"
Which produces:
foo.c [C] [0x23]<code/foo.c 1, 1 2% of 50
Also, as someone mentioned (but now deleted) %
will be replaced with the current filename. For example:
:!echo "current file: %" current file: foo.c Press ENTER or type command to continue

- 148,955
- 89
- 346
- 502
-
2
-
1
-
2`'statusline'` is a string, but you don't include quotes in the set: `set statuslineset statusline=%f%m%r%h%w\ [%Y]\ [0x%02.2B]%<\ %F%4v,%4l\ %3p%%\ of\ %L\ lines` also needs escaped spaces – D. Ben Knoble Jul 13 '19 at 14:10
-
If you want to edit Unicode and see the hex values of characters, change the second (`%02.2B`) item in brackets to not limit the number of digits to two, like this: `[0x%02B]`. (The precision `.2` did the limiting. The `02B` means zero fill and display at least two digits.) – Tom Hundt Feb 25 '21 at 01:26
set the status line. more info with :help statusline
These commands can go in your .vimrc file, or you can enter them as commands while in vim by typing ':' in command mode.
First, set last status to 2 using the following:
set laststatus=2
Then set status line to %f for short file name.
set statusline=%f
For the full path to the file, use %F.

- 3,787
- 1
- 25
- 26
-
-
I've updated the answer, Isius. Hopefully that makes it more clear. – Brian Clements May 19 '17 at 15:46
-
this should be the accepted answer since the currently accepted answer only show the file name temporarily – KuhakuPixel Feb 13 '22 at 01:13
To show the full path for any file, including resolved symlinks, use the following.
:echo resolve(expand('%:p'))
This can be added to your statusbar by adding the line below to your ~./vimrc
set statusline +=%{resolve(expand('%:p'))}\ %*

- 43,590
- 17
- 150
- 159
I also needed to put this in my .vimrc file:
set noruler
set laststatus=2
Then I could put something like set statusline="%f%m%r%h%w [%Y] [0x%02.2B]%< %F%=%4v,%4l %3p%% of %L"
in my .vimrc file and after restarting my terminal the statusline displays properly.

- 61
- 5
-
`'statusline'` is a string, but you don't include quotes in the set: `set statuslineset statusline=%f%m%r%h%w\ [%Y]\ [0x%02.2B]%<\ %F%4v,%4l\ %3p%%\ of\ %L\ lines` also needs escaped spaces – D. Ben Knoble Jul 13 '19 at 14:09
I use the amazing vimrc
from amix: https://github.com/amix/vimrc
It uses the lightline.vim
pluging and displays the filename on the status bar.
The great thing about using the amix/vimrc
is that this plugin takes care of most of the customization, its very stable, and has been tested by 1000s of people, as you can check by looking at the number of github stars.. and the infrequent issues.
Its also updated quite frequently.
P.S.: not the author of either of the plugins.. just a fan :)

- 4,882
- 2
- 37
- 48
One of the above suggestions had to be changed to
set statusline=%f%m%r%h%w\ [%Y]\ [0x%02.2B]%<\ %F%4v,%4l\ %3p%%\ of\ %L\ lines
to get it working. Also
set laststatus=2
was used.

- 31
- 2
-
Welcome to [so]! This should probably be a suggested edit or comment on the relevant answer(s)—you don't have enough reputation to comment or edit yet, but you will soon if you ask good questions and write good answers! In the meantime, I will suggest the relevant fixes to the authors of the answers. Good catch! – D. Ben Knoble Jul 13 '19 at 14:09
To display it at the top, add this to your ~/.vimrc
:
" Statusline at the top (use tabline)
set tabline=%F\ %y " only the format
set showtabline=2 " this turns on the tabline

- 998
- 11
- 26