If I'm at file /a/b/c/foo.txt, I'd like the statusline to display c/foo.txt. Is this possible?

The reason for this is that for web development, too many files are named index.js to make just the tail useful, while the full path (or relative path) is too long to make it easy to parse.

The only relevant statusline options I see are:

  • %f which is the path relative to the current directory
  • %F the full path to the file
  • %t only the filename (tail).
  • Using the default %f I would simply cd /a/b/ :) Commented Mar 21, 2018 at 22:19

1 Answer 1


You can include arbitrary expressions in your status line with %{}. Try this:

:set statusline=%{expand('%:p:h:t')}/%t

This finds the tail of the head of the full path (i.e. just the parent directory) and then tacks on filename using the %t item you already mentioned.

See :help expand() for more details.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.