Thursday, November 20, 2008

Deleting a line with a keyboard shortcut in TextWrangler

I love using TextWrangler for doing quick text editing from an FTP server, but I discovered that I hated not being able to delete a line. I normally use Eclipse for my dev work and have become addicted to using command-D to delete a line or several lines at a time. I googled around a bit and found anoved's suggestion on googlegroups and decided to implement it. It worked great! Here's a simple howto:

Open Applications->AppleScript->Script Editor

Paste this script into the new window:

tell application "TextWrangler"
    tell text of text document 1
        set a to startLine of selection
        set b to endLine of selection
        delete (lines a through b)
    end tell
end tell

Save the script as (home dir)>Library>Applications>TextWrangler>Scripts>delete_line

You can open TextWrangler and check the scripts menu and make sure that it exists and works.

Open System Preferences>Keyboard & Mouse>Keyboard Shortcuts

Hit the plus sign

Set the application to TextWrangler the menu title to "delete_line" and the keyboard shortcut to command-D

That's it!

No comments: