sessionvim

How to add the current session file name in the status line in Vim?


I recently added the sessionman plugin to my Vim configuration, and I like it so far.

I understand that Vim sets v:this_session to the session file name when a session is being used and I’d like to add it to my status line. Unfortunately, v:this_session contains the full file path and it is often way too long for it to fit in the status line.

So my question is: How can I extract the file name without its full path from v:this_session and add it to my status line?


Solution

  • For this, Vim has the :help filename-modifiers like :t for the last component of the file. You can use them with the fnamemodify() function (or expand() if you want to modify a built-in Vim file identifier like %):

    :echo fnamemodify(v:this_session, ':t')