Open MacVim tabs from command-line


MacVim takes vim and provides better integration with Apple’s OS X - I’ve only just started using it and I am already loving it. Provided along with the application is a wrapper-script written to handle calls from the command-line:

cd project
mvim project_file.php

MacVim supports tabs, but unfortunately calling mvim multiple times from the command-line results in multiple separate windows opening, instead of multiple tabs in one window. I made the following modifications to the mvim script to correct this.

Add the following line to the top of the file, below the commented section:

tabs=true

Replace the if structure at the bottom of the file with the following:

# Last step:  fire up vim.
if [ "$gui" ]; then
  if $tabs && [[ `$binary --serverlist` = "VIM" ]]; then
    exec "$binary" -g $opts --remote-tab-silent ${1:+"$@"}
  else
    exec "$binary" -g $opts ${1:+"$@"}
  fi
else
  exec "$binary" $opts ${1:+"$@"}
fi
Share this post
  • Digg
  • StumbleUpon
  • Reddit
  • del.icio.us
  • Facebook
  • muti
  • Mixx
  • Google
  • laaik.it

Tags: , ,

This entry was posted on Monday, October 13th, 2008 at 1:41 pm and is filed under OS X. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

15 Responses to “Open MacVim tabs from command-line”

  1. Bryan said this on

    Thank you! This tip was just what I was looking for. Much appreciated.

  2. cybertoast said this on

    And the obvious addition to this is that starting multiple tabs from the command-line is to do mvim -p file1 file2 ..

    It would be very useful to have a command-line option to specify whether the new file should be opened in an existing tab, or in a new window.

  3. choey said this on

    thanks for the tip! it works great.

    cyboertoast, a quick fix would be to add the following right after tabs=true:

    if [ "$1" = "-n" ]
    then
    tabs=false
    fi

    then, by default, “mvim foo” will open foo in a new tab, while “mvim -n foo” will open foo in a new window.

  4. Brian Smith said this on

    Thanks! Just what I was looking for. =)

  5. Agapov said this on

    75. ???? ???? ????? ????????? ?? ?????????? ??????. ?????, ????? ??????? :)

  6. Dzung Hong said this on

    Cool! Thank you so much

  7. bryan kennedy said this on

    Oh faboo.

    Thanks for this. It really helps complete my Vim environment.

  8. Faith Heuwinkel said this on

    You raise plenty of questions in my thoughts; you wrote a superb submit, but this publish is also thought scary, and I must think about it some extra; I will probably be again soon.

  9. Kylie Egeland said this on

    Greetings, this is a genuinely absorbing internet blog and I’ve cherished learning several in the content and posts contained around the internet internet site, keep up the exceptional get the job done and want to learn a great deal much more stimulating content inside the future.

  10. Daniel said this on

    Great tip. Thank you very much!

  11. Lincoln Whitebear said this on

    That’s Too great, when it comes in india hope it could make a Rocking location for youngster.. hope that
    come true.

  12. Nick said this on

    You can set this alias in you .bash_profile instead:

    alias mvim=”open -a MacVim.app”

    Then in MacVim 7.3 go to preferences and set “Open files from applications:” to “in the current window” “with a tab for each file”.

  13. Junita Loughry said this on

    Good article thank you. I prefer that you mention which SEO rquires continuing attention; too a lot of individuals believe that SEO demands a big total amount of work and after that almost nothing further should be carried out!

  14. Making MacVim open files in vertical splits :: yjsoon said this on

    [...] I’m at it, here’s another useful one: this link shows you how to edit mvim, the command line script to open MacVim, so that it doesn’t open [...]

  15. Isidra Toti said this on

    nvr found your website like this, relaly amazed. as compared with alternative sites with this information and facts i thought this was definatly the ideal internet site. will prove to add in order to offerings.

Leave a Reply