: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?
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 (:.
).
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With