Kimo Johnson

12 April 2006

I use TextWrangler as my default editor, but in cases where there's lots of repetitive editing to do, I prefer vim. Terminal vim is fine with me, the only downside is that it's a pain to launch files with it. The typical way I open a file is to drag it from the Finder onto TextWrangler in the Dock. This habit was developed because MATLAB files use the same extension as Objective-C files (.m) and if you open by double-clicking, you usually end up opening the wrong application. Anyway, the solution was to create a simple AppleScript that calls vim when you drop a file onto it.

Here’s the script. Paste it into Script Editor and save it as an application ( You can also give it a pretty icon if that’s important to you (I use the Word icon from IconFactory’s Smoothicons 7).

property terminal_rows : 48
property terminal_columns : 90

on open_file(filename)
    tell application "Terminal"
        do script with command ("vim " & filename)
        tell window frontmost
            set custom title to ""
            set number of columns to terminal_columns
            set number of rows to terminal_rows
            set pos to get position
            set position to {item 1 of pos, 22}
        end tell
    end tell
end open_file

on open of file_list
    set filenames to ""
    repeat with i in file_list
        set filenames to filenames & " " & quoted form of (POSIX path of (i as alias))
    end repeat
end open

To get syntax coloring, create a file called .vimrc in your home directory with the following line:

:syntax on