Skip to content

Instantly share code, notes, and snippets.

@kylewlacy
Created July 10, 2012 02:39
Show Gist options
  • Save kylewlacy/3080651 to your computer and use it in GitHub Desktop.
Save kylewlacy/3080651 to your computer and use it in GitHub Desktop.
mvim - Better Clientserver Management
--- src/MacVim/mvim 2012-07-09 19:52:34.000000000 -0700
+++ /usr/local/bin/mvim 2012-07-11 04:12:00.000000000 -0700
@@ -61,7 +61,30 @@
# The program should fork by default when started in GUI mode, but it does
# not; we work around this when this script is invoked as "gvim" or "rgview"
# etc., but not when it is invoked as "vim -g".
-if [ "$gui" ]; then
+
+# When we launch mvim with --remote-tab-silent, it won't work if
+# no file is provided. This is a workaround to that.
+#
+# The best use case for this is doing the following in your .bash_profile
+# or .zshrc:
+# alias vim="mvim -v --remote-tab-silent"
+# or:
+# alias mvim="mvim --remote-tab-silent"
+if [[ ${1:+"$@"} == "-v --remote-tab-silent" ]]; then
+ if [[ `"$binary" --serverlist` = "VIM" ]]; then
+ osascript -e "tell application \"MacVim\" to activate"
+ exec "$binary" -g --remote-send ":tabnew<CR>"
+ else
+ exec "$binary"
+ fi
+elif [[ ${1:+"$@"} == "--remote-tab-silent" ]]; then
+ if [[ `"$binary" --serverlist` = "VIM" ]]; then
+ osascript -e "tell application \"MacVim\" to activate"
+ exec "$binary" -g --remote-send ":tabnew<CR>"
+ else
+ exec "$binary" -g
+ fi
+elif [ "$gui" ]; then
# Note: this isn't perfect, because any error output goes to the
# terminal instead of the console log.
# But if you use open instead, you will need to fully qualify the
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment