Navigation: Homepage | xmlgawk | Buchkritik | Sitemap

My installation of vim on Mac OS X

Of course, there is GVim on Mac OS X, it can be placed in the Dock, drag-n-drop of files work and it is a real OS X application bundle. But I am not pleased with it, the working directory of GVim is the users home directory and not the directory containing the files. Additionally it uses a different color scheme for its syntax highligthing then the console version of Vim.

In November 2007 I found MacVim, a cool Cocoa based wrapper around Vim7. It looks much nicer then GVim and it worked for me out of the box. The default font is also 'DejaVu Sans Mono', one of the best monospaced fonts around. Take a look at: http://code.google.com/p/macvim/ Included in the package is a helper mvim script to edit a file from the commandline.

As regular vi(m) user in the terminal, I had the strong need to have an icon in the dock, to drop some files on, and a console/terminal Vim opens in a new window. All files are already loaded and the working directory is switch to the directory of the frontmost finder window.

Automater helped to implement this little application, which can be installed as application icon in the dock and/or as a Finder Automator action.

Automator and Applescript Action

First you have to open Automator and create a new workflow, ypu can do this also with via the Finders action menu item 'new workflow'.

Drag to Automator actions on the right pane:

  1. Get selection from finder
  2. Execute Applescript

The following screenshot, shows what I mean

Paste the Applescript code:

 on run {input, parameters}
    set filesToEdit to {}
    repeat with i in input
        copy " " to end of filesToEdit
        copy (quoted form of (POSIX path of (i as string))) to end of filesToEdit
    end repeat
    tell application "Finder"
        set thePath to "Desktop"
        if exists window 1 then
            set myWin to window 1
            set thePath to (quoted form of POSIX path of (target of myWin as alias))
        end if
        tell application "Terminal"
            activate
            tell window 1
                do script "cd " & thePath & "
 vim " & (filesToEdit as string) & " && exit 0"
                set the position to {300, 50}
            end tell
        end tell
    end tell
    
    return input
 end run

Then save the workflow as Finder workflow and as an application. Change the application icon of the saved application via 'Get Info', rigth click the application icon. (I reused the Vim icon) After dragging the new application into the Dock, you are done.

Why Applescript? Applescript is a very strange language, but I used it here for the automatic filename conversion functions. The Finder hands over the dragged files as Mac pathnames, which must be converted to POSIX names for Vim. This seems a lot easier in Applescript. It is possible to implement Bash actions, but the we must convert pathnames on our own and issue an Applescript to open a new Terminwl window via the 'osascript(1)' command.

More on Applescript and Unix can be found here: http://homepage.mac.com/swain/Macinchem/Applescript/lecture/applescript_unix.html

 last modified: $Date: 2007/12/19 17:11:53 $