How can I forever display the path to the current file in Vim?

I know that CTRL g displays the current file you are working on. Is there a way to change my .vimrc so that the file name / path always displays?

+78
vim vi
May 7 '12 at 20:33
source share
8 answers

In your status bar, add %F to display the full path:

 :help statusline " Add full file path to your existing statusline set statusline+=%F 

Note. %F will be the full path. To get the path relative to the working directory, use %F

If your status line is not yet visible, first you need to configure it so that it is always visible, through laststatus=2

 set laststatus=2 

See :help laststatus for parameters. As a rule, the status line can be hidden or hidden if only a few buffers are open, but I find it extremely useful to have all this time with such settings, so you should abandon one reserve of the screen line for it.

+116
May 7 '12 at 20:35
source share

set ls = 2

add this to vimrc and you will always see the file name below.

+17
Nov 13 '13 at 6:32
source share

I found 2 ways to display the file path in the gnome terminal's title bar when editing a file using Vim.

The simplest (and best) way: add the following line to ~/.vimrc :

 set title 

What will be shown at the top:

 filename.ext (~/path_to_directory_where_your_file_is/) - VIM 

A more complicated way will show you the absolute path to the file. This is described in more detail in this blog post I recently wrote.

+12
Nov 06 '12 at 5:05
source share

The only way to find the full path to the file I'm working in is :echo expand('%:p') . You can rearrange ctrl + g if you want, but I personally don’t like to deviate too much from the standards. I matched F7 as follows:

 map <F7> <Esc>:echo expand('%:p')<Return> 
+6
May 7 '12 at 20:35
source share

I always used :f , but the answer and links from @MichaelBerkowski are awesome!

:f shows the path, number of lines, changed state, current cursor position and much more ...

I did not know about CTRL G , but it seems to be about the same.

+5
Nov 17
source share

The status line is very powerful and convenient, I think. Spilling out of the box will display the file name, cursor position and some flags. But you want to do the same as me, and replace the part of the file name with the full path to the file.

Thus, when editing my .vimrc my status line may look something like this: by default:

 .vimrc 26,16 7% 

You can view the status line settings with:

 :set statusline? 

But if you did not make any changes and not a single module changed it, it would be empty. But from the examples in the help section ( :help statusline ), you may find that by default:

 :set statusline=%<%f\ %h%m%r%=%-14.(%l,%c%V%)\ %P 

So include this in your .vimrc and change %f to %f . I also added the added filetype ( %y ) flag to my status line, as I find it convenient. So, my resulting configuration is as follows:

 :set statusline=%<%F\ %h%m%r%y%=%-14.(%l,%c%V%)\ %P 

And the result will look something like this:

 ~/.vimrc [vim] 26,16 7% 

Good reading:

PS. I am running vim 7.3

+3
Feb 14 '14 at 10:07
source share

If you are using vim-airline , enter .vimrc :

 let g:airline_section_c = '%<%F%m %#__accent_red#%{airline#util#wrap(airline#parts#readonly(),0)}%#__restore__#' 

This is the default modification of the airline, changing %f to %f .

+2
Mar 24 '15 at 2:40
source share

If you want the path to include allowed symbolic links, use the following:

 set statusline +=%{resolve(expand('%:p'))}\ %* 

To save the abbreviation '~' for your home directory, enable fnamemodify

 set statusline +=%{fnamemodify(resolve(expand('%:p')),':~')}\ %* 
+2
Feb 13 '17 at 0:27
source share



All Articles