Display name of the current file in vim?

VimVi

Vim Problem Overview


How do you display the filename of the file you are working on in vim?

Vim Solutions


Solution 1 - Vim

:f (:file) will do same as <C-G>. :f! will give a untruncated version, if applicable.

Solution 2 - Vim

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

Solution 3 - Vim

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.

Solution 4 - Vim

:set title to display file name in window title bar.

Solution 5 - Vim

Why so complicated? Control-G will do the job

Solution 6 - Vim

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'))}\ %*

Solution 7 - Vim

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

Solution 8 - Vim

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.

Solution 9 - Vim

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.

Solution 10 - Vim

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

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionDrew LeSueurView Question on Stackoverflow
Solution 1 - VimsmilingthaxView Answer on Stackoverflow
Solution 2 - VimDavid WoleverView Answer on Stackoverflow
Solution 3 - VimBrian ClementsView Answer on Stackoverflow
Solution 4 - VimRyan LeView Answer on Stackoverflow
Solution 5 - VimseanView Answer on Stackoverflow
Solution 6 - VimjoelostblomView Answer on Stackoverflow
Solution 7 - Vimalpha_989View Answer on Stackoverflow
Solution 8 - VimAlex Fenwood HughesView Answer on Stackoverflow
Solution 9 - VimcucujoideaView Answer on Stackoverflow
Solution 10 - VimM Imam PratamaView Answer on Stackoverflow