My development environment setup consists of several tools, however the 2 most used and essential tools that have a great impact on my workflow are tmux & vim. Since I often work on several projects, I find it best to work on different vim sessions in separate tmux windows.

However tmux by default only shows the name of the currently running process in the title and that can often lead to confusion as to which tmux window is which project. To solve this issue I came up with a very simple vim script that utilizes tmux’s powerful API to automatically rename the tmux window appropriately and hence make it incredibly easy for me to know which tmux window is for which project.

Here is the vimscript, that you can put anywhere within your ~/.vimrc :

augroup Tmux "{{{2 au! autocmd VimEnter,BufNewFile,BufReadPost * call system('tmux rename-window "vim - ' . split(substitute(getcwd(), $HOME, '~', ''), '/')[-1] . '"') autocmd VimLeave * call system('tmux rename-window ' . split(substitute(getcwd(), $HOME, '~', ''), '/')[-1]) augroup END 1 2 3 4 5 6 augroup Tmux "{{{2 au ! autocmd VimEnter , BufNewFile , BufReadPost * call system ( 'tmux rename-window "vim - ' . split ( substitute ( getcwd ( ) , $ HOME , '~' , '' ) , '/' ) [ - 1 ] . '"' ) autocmd VimLeave * call system ( 'tmux rename-window ' . split ( substitute ( getcwd ( ) , $ HOME , '~' , '' ) , '/' ) [ - 1 ] ) augroup END

Here’s a screenshot of the same :

