Is there a "good" way to rename the terminal buffer in neovim?

I know that renaming is possible with the :file command, and that works fine for current session.

The problem with this approach is that it breaks :mksession. If you change the terminal window name with :file and save the session, upon restore it will no longer create a terminal window, but a regular file buffer instead.

I want to avoid this.

2 Answers 2


From :h terminal-start:

When the terminal starts, the buffer contents are updated and the buffer is named in the form of term://{cwd}//{pid}:{cmd}. This naming scheme is used by |:mksession| to restore a terminal buffer (by restarting the {cmd}).

Therefore you can not do this, unless you manually "swap" buffer names before :mksession and on autocmd SessionLoadPost. But I don't believe such oversophisticated scheme is worth.


In case if you use your session file just to get you started - like the right set of files to be edited and terminals, tabs set up then you can do something like this

  • Save the session
  • Edit the session file look for bufexists() line and add the file term_name below that
  • On Restore the terminals are available with the term_name

This will not work if you rename the file in the session and save the session

  • Welcome to Vi and Vim! Please consider adding more details to your answer (perhaps it's worth showing an example?). Also note that this approach require you to make the fix every time you update the session file, which may not fit well with some workflows.
    – D. Ben Knoble
    Jan 26, 2021 at 13:04
  • Agree, in my case I keep my session file more as a script to get me started with right files, terminals and not save every time i use the session
    – vkt
    Jan 26, 2021 at 13:37
  • Updated my answer with some more details around the workflow for which this answer suits
    – vkt
    Jan 26, 2021 at 13:44

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.