I regularly ssh into a Linux cluster from an OS X (El Capitan) Terminal, sometimes with multiple Terminal tabs. I use bash and vim.

I'd like to do the following:

  • while ssh'd, set the Terminal tab title to the current working directory using PROMPT_COMMAND='printf "\e]1;"`basename $PWD`"\a"'
  • while using vim, set the Terminal tab title to "vim — FILENAME"

Here are my problems:

  • If I do let &titlestring = "vim — " . expand("%:t") and set title in .vimrc, it changes the Terminal window title, not the tab title. If I do not separately set the tab title (parameter 1), the tab title mirrors the window title (parameter 2), but as soon as I set the tab title, it "decouples" from the window title.
  • If I run an external command in .vimrc with :!, I get a "Press ENTER" dialog that's annoying.
  • If I use :silent ! in .vimrc, my Terminal prompt ends up at the bottom of the screen after exiting vim. I really don't want to muck around with saving the prompt position and resetting it every time I want to use vim.
  • If I define in my .bashrc the following function:

    function vim
        printf "\e]1;"`basename "$1"`"\a"
        vim "$1"

    then my terminal crashes upon calling vim from the command line. Calling the function vvim instead works, but I don't want to type vvim forever. I want to alias vim.

So I seem stuck. Any advice would be much appreciated. Thank you in advance!


Well, I've solved my own problem. I fail programming 101.

By defining vim as a function and then calling vim, I set up an infinite recursive loop. No wonder my terminal crashed. I need to call the "real" vim, the actual executable. This did the trick:

function vim
    printf "\e]1;"`basename "$1"`"\a"
    /usr/bin/vim "$1"

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .