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'")