Kerry Buckley

What’s the simplest thing that could possibly go wrong?

Quick-and-dirty “edit text in vim” Mac service

one comment

Today I wanted to edit a big chunk of text (the source of a wiki page) in a browser textarea, and remembered that I used to have an app that let me open any text in vim, then paste the result back where it came from. Eventually I found the app I was thinking of – QuickCursor – but it turns out it’s no longer available.

Coincidentally I was looking into how to do something else tonight, and the answer was to create a service that ran an AppleScript, and it occurred to me that I could probably make a basic “edit in vim” service fairly easily. Turns out I was right…

Open the “Automator” app, and create a new service. Add a shell script action, and paste in the following script (this assumes you’ve installed the mvim script that comes with MacVim):

filename=`mktemp ~/.edit-in-vim-XXXX`
cat > $filename
/usr/local/bin/mvim -f $filename
cat $filename
rm $filename

Creating a service in Automator

Select “Output replaces selected text” in Automator, save the service, and you’re done. Just select some text (it doesn’t select-all for you like QuickCursor did), right-click and run your new service. You can also assign a keyboard shortcut in System Preferences:

Setting a keyboard shortcut

Written by Kerry

September 5th, 2013 at 8:11 pm

Posted in Software

Tagged with , , ,

One Response to 'Quick-and-dirty “edit text in vim” Mac service'

Subscribe to comments with RSS or TrackBack to 'Quick-and-dirty “edit text in vim” Mac service'.

  1. I’m editing this in vim. Thank you for the awesome tip! Hopefully this doesn’t end up with me putting a buch of :wq’s in text comments all over the internet.

    msouth

    3 Mar 14 at 7:31 pm

Leave a Reply

You must be logged in to post a comment.