How do you show the name of the file you're working with in vim?

How do you show the name of the file you're working with in vim?

+132
vim vi
Nov 06 '10 at 3:10
source share
9 answers

:f ( :file ) will do the same as <CG> . :f! will provide an unused version, if applicable.

+176
Nov 06 '10 at 3:27
source share

ctrl + g will do this.

Also, I like:

 set statusline="%f%m%r%h%w [%Y] [0x%02.2B]%< %F%=%4v,%4l %3p%% of %L" 

What produces:

 foo.c [C] [0x23] <code / foo.c 1, 1 2% of 50

Also, as mentioned (but now deleted), % will be replaced with the current file name. For example:

 :! echo "current file:%"
 current file: foo.c
 Press ENTER or type command to continue
+63
Nov 06 '10 at 3:14
source share

set the status bar. Further information with :help statusline

These commands can be included in your .vimrc file, or you can enter them as commands in vim mode by entering ":" in command mode.

First set the last status to 2 using the following:

set laststatus=2

Then set the status bar to% f for the short file name.

set statusline=%f

For full file path use% F.

+17
Nov 06 '10 at 3:13
source share

To show the full path for any file, including allowed symlinks, use the following.

 :echo resolve(expand('%:p')) 

You can add this to your status bar by adding the line below to ~./vimrc

 set statusline +=%{resolve(expand('%:p'))}\ %* 
+3
Feb 13 '17 at 0:34
source share

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

+2
Apr 28 '18 at 6:45
source share

Why is it so complicated? Control-G will do the job

+2
Apr 25 '19 at 1:16
source share

I am using amazing vimrc from amix: https://github.com/amix/vimrc

It uses lightline.vim lightline.vim and displays the file name in the status bar.

The great thing about using amix/vimrc is that this plugin takes care of most of the settings, it is very stable and has been tested by thousands of people, which you can check by looking at the number of github stars ... and infrequent problems.

Its also updated quite often.

PS: not the author of any of the plugins .. just a fan :)

+1
Apr 21 '18 at 17:01
source share

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" into my .vimrc file and after restarting my terminal the status bar is displayed correctly.

+1
Jul 26 '18 at 11:21
source share

One of the above suggestions should be changed to

set statusline=%f%m%r%h%w\ [%Y]\ [0x%02.2B]%<\ %F%4v,%4l\ %3p%%\ of\ %L\ lines

to make it work. Also

set laststatus=2

was used.

0
Jul 12 '19 at 18:56
source share



All Articles