I'm trying to customize my window title, which uses the same format as the statusline. I know I can show the full path to the file with %F (or %-0.20F to restrict it to 20 characters). I'd prefer to show the file name separately (i.e. with %t). In this case, is there a way to show the full path to the containing directory instead?

If I don't set titlestring at all, vim's window title seems to default to

file.txt (/full/path/to/containing/directory) - VIM3

I thought I might pillage the code for this, but set titlestring? doesn't show anything.

  • @JairLópez That changes the title to . for me.
    – Sparhawk
    Commented Oct 28, 2016 at 10:58

1 Answer 1


I'm not sure I fully understood what you mean so feel free to correct me in the comment if I didn't understood.

If what you are trying to do is simply show the directory containing your file in your title bar you can use:

set titlestring=%{expand(\"%:p:h\")}

With this configuration when I'm on the help file options.txt my title bar looks like this:

enter image description here

Note that the example I gave you uses expand and the filename modifiers thus you can customize it the way you want with the help of :h filename-modifiers

  • Thank you, that seems to work. But wow, that help page is confusing! Out of interest, what inspired you to look at this help page? I didn't see any reference to it in the titlestring or statusline pages.
    – Sparhawk
    Commented Oct 28, 2016 at 11:29
  • 1
    @Sparhawk in :h 'titlestring' an example mentions set titlestring=%t%(\ %M%)%(\ (%{expand(\"%:~:.:h\")})%)%(\ %a%) and I knew that :~, :h, etc are documented in filename-modififers :)
    – statox
    Commented Oct 28, 2016 at 11:39

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.