3

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).
maged
  • 195
  • 4

1 Answers1

6

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.

Rich
  • 31,891
  • 3
  • 72
  • 139