Vim Tips Wiki
Advertisement
Tip 1645 Printable Monobook Previous Next

created January 4, 2010 · complexity basic · author Lotusone · version 7.0


On Mac OS X systems, you can automatically source Vim sessions by creating an Automator Application that forwards the file to Vim with the -S option.

Procedure

Name all your Vim sessions with the same extension, for example ".vis".

Create an Automator application. File > New

Create a new application in Automator


Add a "Run Shell Script" action.

Action in automator

Edit the details of the action to start MacVim with the -S option applied to the argument (with a backslash preceding each space, if any, in the file name).

file_name = ARGV[0].split(' ').join('\ ')
system(%Q!mvim -S "#{file_name}"!)

Save the application.

Set the Automator application as the default app for your session files (from the Finder Help):

  1. Select the document and choose File > Get Info.
  2. Click the triangle next to “Open with” to expand the section.
  3. Choose an application from the pop-up menu, or choose Other to locate a different application.
  4. If you want to use that application to open all documents of the same type as the current document and created by the same application, click Change All.

Result

Whenever you double-click a session file in Finder, the session will automatically open and source in Vim.

Comments

I have applied a more standard formatting, and tweaked some wording. I suspect that some steps are missing ("check Google" and a bit more), and it would be helpful if someone with some MacVim smarts could confirm that the tip is adequate. I replaced File:Shell script code.png with the actual text so it can be copied. Later, that image should be deleted as redundant. JohnBeckett 04:24, May 16, 2010 (UTC)


The image doesn't just show what text to enter, it also shows where to enter the text for those who don't know already. I think it adds value. It would add more value if it also showed how to bring up the text entry box shown, but maybe this is self-evident. Certainly we need to complete the instructions, and I'd like to expand this tip to include other mappings, like using --remote-tab-silent to launch files in tabs. We should cross-reference with the Windows and Unix file association tips.

--Fritzophrenic 04:30, June 24, 2010 (UTC)

Click File:Shell script code.png to see the image that I removed (replacing it with the actual text; this old version of the tip shows how it appeared). I have no problem with the images that are currently in the article. JohnBeckett 04:49, June 26, 2010 (UTC)

Newton Furia 20:00, Mar 12, 2012 (BRT)

This Automator Application using ruby does not work properly in Mac OS Lion.
I created an Automator MacVimSessions.app and setted it as the default app for my session files (*.vis).
Then, when I open a session file from the terminal using $ open test.vis the MacvimSessions.app runs correctly, opening MacVim and loading the session.
But when I double click the same test.vis file it doesn't work.
And more strange, if I run the Application inside Automator (adding a temporary Get Specified Finder Items action to capture the session file), it works...

So, I did a modified version, that works correctly, using bin/bash as shell that is more simple:

source ~/.bash_profile  # necessary to locate mvim
FILE=$@                 # the file to open
FILE=${FILE// /\\ }     # replace spaces (who uses spaces in vim files?)
mvim -S "$FILE"         # open MacVim

Also, as already commented, I think that the procedure is not so clear and only one image showing more is better. Bellow, commented (Edit to see), a new version of the whole tip to be reviewed.
And I think that "Vim sessions under Mac OS X" is a better title.


Advertisement