0

I use the following settings to have the filename in the header line before the rest of the path:

set titlestring=
set titlestring+=%M
set titlestring+=%(\ %t%)
set titlestring+=%(\ (%{expand('%:p:h')})%)
set titlestring+=%a

This results to:

filename.txt (path/to/the/file)

The problem is the empty buffer. Instead of [No Name], it also contains the path to the home directory:

[No Name] (path/to/the/home/directory)

What is the way to get rid of the path to the home directory for the empty buffer?

I should probably differentiate the empty buffer from non-empty ones, but I don't know how. I know there are some functions line bufwinnr(), but I don't understand which one I should use here.

2
  • use a function, that checks whether expand('%') returns an empty string. And if not, append the path. Sep 14 at 16:12
  • @ChristianBrabandt Thanks, I will try it. Typos are now corrected, sorry for them.
    – jsv
    Sep 14 at 16:17
0

Based on the comment by Christian Brabandt:

function! SetTitlestring()
  set titlestring=
  set titlestring+=%M
  set titlestring+=%(\ %t%)
  if expand('%') != ''
    set titlestring+=%(\ (%{expand('%:p:h')})%)
  endif
  set titlestring+=%a
endfunction
autocmd! BufReadPre,FileReadPre * call SetTitlestring()
1
  • This function gives the same title string as the default one, with the only difference that the path in parentheses is absolute. Maybe there is a simpler way, something like set absolutepathintitlestring?
    – jsv
    Sep 14 at 18:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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