2

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!

  • 1
    The function vim calls the function vim calls the function vim, etc. Replace vim "$1" with command vim "$1" to avoid this loop. – thrig Feb 24 '16 at 18:06
1

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"
}
  • Much better to follow the advice of @thrig and use the Bash built-in command in front of vim in order to use the standard lookup mechanisms instead of hardcoding the path. – 0xC0000022L Jul 26 '18 at 16:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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