Whenever I open a tmux session in terminal, all of the tabs containing vim sessions are labelled vim.

My question is: How to configure it to label tmux tabs with the name of the edited file or something like vim | test.cpp used as the title of the tabs in question.

  • 1
    can this help : stackoverflow.com/a/15124717/2558252 ? – nobe4 Jul 8 '15 at 19:34
  • thanks for this but can you please elaborate the process in a bit detail? Moreover the answer in not complete. The guy just gave an hint – Mayukh Sarkar Jul 8 '15 at 19:36
  • as the question was answered (and IMHO correctly) could you accept it ? – nobe4 Aug 19 '15 at 9:56
up vote 19 down vote accepted

There you go :

autocmd BufReadPost,FileReadPost,BufNewFile,BufEnter * call system("tmux rename-window 'vim | " . expand("%:t") . "'")

Decomposing :

autocmd BufReadPost,FileReadPost,BufNewFile,BufEnter * call

On buffer read, file read or buffer new file event (see :help autocmd-events) execute the next command :

call system()

Call a system function and pass it the text :

"tmux rename-window 'vim | "  

Rename the current window with a string starting with vim |

. expand("%:t") 

Add to the string the filename (see this article for the formatting and this post for the expand insert)

. "'"

Add the final ' to close the command.

After expanding it will look like (while editing the .vimrc file):

system("tmux rename-window 'vim | .vimrc'")

As @erthalion said in the comment, you can clean up when leaving vim with :

autocmd VimLeave * call system("tmux rename-window 'tmux'")
  • 1
    I think it will be nice to include BufEnter event into this list (to change label even when we switch between existing buffers), and something like this autocmd VimLeave * call system("tmux rename-window 'tmux'") for cleanup. – erthalion Jul 16 '15 at 4:02

To restore the default tmux naming scheme when quitting vim you can also do:

autocmd VimLeave * call system("tmux setw automatic-rename")

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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