Wikia

Vim Tips Wiki

Changes: Vim-sessions under Mac

Edit

Back to page

(Add the ==Comments== which we keep even when no comments to encourage new comments in that location. Also some style trivia.)
(Change <tt> to <code>, perhaps also minor tweak.)
 
Line 11: Line 11:
 
|category2=Mac OS X
 
|category2=Mac OS X
 
}}
 
}}
On Mac OS X systems, you can automatically source Vim sessions by creating an Automator Application that forwards the file to Vim with the <tt>-S</tt> option.
+
On Mac OS X systems, you can automatically source Vim sessions by creating an Automator Application that forwards the file to Vim with the <code>-S</code> option.
   
 
==Procedure==
 
==Procedure==
*Name all your Vim sessions with the same extension, for example "<tt>.vis</tt>".
+
*Name all your Vim sessions with the same extension, for example "<code>.vis</code>".
 
*Open ''Automator'' and create a workflow, using ''File > New''.
 
*Open ''Automator'' and create a workflow, using ''File > New''.
 
*Choose ''Application'' as the type for your document.
 
*Choose ''Application'' as the type for your document.
Line 39: Line 39:
 
==Result==
 
==Result==
 
Whenever you double-click a session file in Finder, will open Vim or MacVim sourcing the saved session.<br />
 
Whenever you double-click a session file in Finder, will open Vim or MacVim sourcing the saved session.<br />
It also works using a command line in ''Terminal'': <tt>$ open test.vis</tt> <br />
+
It also works using a command line in ''Terminal'': <code>$ open test.vis</code> <br />
And can be useful when Vim is already running: using ''netrw browser'' and hitting <tt>"x"</tt> while cursor is on file name ''test.vis'' open a new MacVim window with this saved session.
+
And can be useful when Vim is already running: using ''netrw browser'' and hitting <code>"x"</code> while cursor is on file name ''test.vis'' open a new MacVim window with this saved session.
   
 
==Comments==
 
==Comments==

Latest revision as of 06:43, July 13, 2012

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.

ProcedureEdit

  • Name all your Vim sessions with the same extension, for example ".vis".
  • Open Automator and create a workflow, using File > New.
  • Choose Application as the type for your document.
  • In the Library of Actions, choose Utilities.
  • From the Utilities section, drag the Run Shell Script action.
  • In the Run Shell Script window, choose /bin/bash in Shell pop-up button and as arguments in Pass input pop-up button.
  • Write the script:
source ~/.bash_profile  # necessary to locate mvim
FILE=$@                 # the session file to open
FILE=${FILE// /\\ }     # replace spaces with escaped spaces
mvim -S "$FILE"         # -S open MacVim sourcing the file

It is possible to write the script in some other language, but bash is more simple.

Automator bash

  • Save the Automator Application in some folder that is already in your path.
  • Set this application as the default app to open Vim session files (borrowed from the Finder Help):
    1. Select the document in Finder 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.

ResultEdit

Whenever you double-click a session file in Finder, will open Vim or MacVim sourcing the saved session.
It also works using a command line in Terminal: $ open test.vis
And can be useful when Vim is already running: using netrw browser and hitting "x" while cursor is on file name test.vis open a new MacVim window with this saved session.

CommentsEdit

Around Wikia's network

Random Wiki