0

Out of the box title:

filename.txt (~/projects/blabla/foo/bar) - VIM

Desired title when the current folder ~/projects/blabla/foo:

foo/bar/filename.txt 45/500

The last numbers represent current line / all lines. I got this with %L-%P.

Where can I read about title syntax? Is this the same as for statusline?

It looks like I can build a statusline in the title, which is potentially useful! I can display many things in the title, but minimalism is better for my computer's performance.

2
  • 4
    :help 'titlestring'
    – D. Ben Knoble
    Commented Jul 22, 2022 at 13:35
  • Moving the computation from the core to the runtime will certainly help you get a tailored title but it will be less performant. Minimalism is not only about looks.
    – romainl
    Commented Feb 6, 2023 at 19:05

1 Answer 1

0

I prefer using functions for the titlestring

I left some comments in there for you to take a look at and experiment with.

This is essentially how my titlestring is built in my .vimrc.

vim9script
def MyTitle(): string
  var user = $USER
  var hostname = hostname()
  var userhost = $"{user}@{hostname}"

  var fname = '%t'
  var fpath_relative = "(%f)"
  # var fpath_absolute = '(%F)'
  # var flag_modified = "%M"
  # var argument_list_status = "%a"
  var flags = '%h%w%m%r' # [help],[Preview],[+] (modified),[RO] (readonly)
  var cwd = substitute(getcwd(), $HOME, '~', '')
  var title_parts = [
        \ has('gui_running') ? "gvim " : "vim ",
        \ fname,
        \ flags,
        \ fpath_relative,
        \ $"[{cwd}]",
        \ $"({userhost})",
        \]

  return join(title_parts, '')
enddef

augroup vimrc
  autocmd!
  autocmd BufEnter * &titlestring = MyTitle()
augroup END

legacy

function s:MyTitle()
  let s:user = $USER
  let s:hostname = hostname()
  let s:userhost = $"{s:user}@{s:hostname}"

  let s:fname = '%t'
  let s:fpath_relative = "(%f)"
  " let s:fpath_absolute = '(%F)'
  " let s:flag_modified = "%M"
  " let s:argument_list_status = "%a"
  let s:flags = '%h%w%m%r' " [help],[Preview],[+] (modified),[RO] (readonly)
  let s:cwd = substitute(getcwd(), $HOME, '~', '')
  let s:title_parts = [
        \ has('gui_running') ? "gvim " : "vim ",
        \ s:fname,
        \ s:flags,
        \ s:fpath_relative,
        \ $"[{s:cwd}]",
        \ $"({s:userhost})",
        \]

  return join(s:title_parts, '')
endfunction

augroup vimrc
  autocmd!
  autocmd BufEnter * let &titlestring = s:MyTitle()
augroup END

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.