Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Displaying the relative path of the currently edited file in Vim's statusline?

Tags:

vim

:help statusline claims %f will render as:

Path to the file in the buffer, as typed or relative to current directory.

When I set statusline=%f, the path in the statusline is sometimes relative, but often absolute.

Is there a way to make sure the path displayed is always relative?

like image 688
Dun Peal Avatar asked Jul 21 '17 00:07

Dun Peal


2 Answers

There may be a better way, but you could try this:

set stl+=%{expand('%:~:.')}

The expression inside %{} should be evaluated and added to your statusline. Here the expression is:

expand('%:~:.')

... which expands the name of the current file, but prevents the expansion of the tilde (:~), and makes the path relative to the current working directory (:.).

like image 59
user852573 Avatar answered Nov 09 '22 18:11

user852573


Just below the explanation of %f, you will find explanation of F. Using %F instead of %f will give you the desired display.

item  meaning ~
f S   Path to the file in the buffer, as typed or relative to current
      directory.
F S   Full path to the file in the buffer.
like image 24
dlmeetei Avatar answered Nov 09 '22 18:11

dlmeetei