Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I permanently display the path of the current file in Vim?

Tags:

vim

vi

I know CTRLg displays the current file you're working on. Is there a way to modify my .vimrc such that the filename/path is always displayed?

like image 851
zallarak Avatar asked May 07 '12 20:05

zallarak


People also ask

How do I find the path of a file in Vim?

By default, Vim only shows the filename of the currently open file in the status line and the command line below it. Sometimes, you might want to view the full path of the file. To do that, press 1 followed by Ctrl-G . The full path of the file is displayed in the command line at the bottom.

Where the path of the current file is displayed?

The answer is the pwd command, which stands for print working directory. The word print in print working directory means “print to the screen,” not “send to printer.” The pwd command displays the full, absolute path of the current, or working, directory.

How do I get full path of file in Gvim?

Pressing 1 followed by Ctrl + G shows the full path of the current file.

How do I change the path of a file in Vim?

You can change the working directory with :cd path/to/new/directory . Or you can enter the full path to the location where you want to save the file with the write command, e.g., :w /var/www/filename .


2 Answers

In your statusline, add a %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 a path relative to the working directory, use %f.

If your statusline is not already visible, you may first need to configure it to be always visible, via laststatus=2

set laststatus=2 

See :help laststatus for what the options mean. Normally, the statusline may be hidden, or hidden unless multiple buffers are open, but I find it extremely useful to have on all the time with customizations like this, well worth giving up one screen line reserve for it.

like image 136
Michael Berkowski Avatar answered Oct 09 '22 08:10

Michael Berkowski


set ls=2

add this in vimrc, and you will see the file name at the bottom always.

like image 28
SD. Avatar answered Oct 09 '22 09:10

SD.