'Display name of the current file in vim?
How do you display the filename of the file you are working on in vim?
Solution 1:[1]
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 2:[2]
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 3:[3]
:set title to display file name in window title bar.
Solution 4:[4]
Why so complicated? Control-G will do the job
Solution 5:[5]
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 6:[6]
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 7:[7]
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 8:[8]
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 9:[9]
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
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
