TextWrangler: hotkeys to move line up/down

11

4

In Eclipse you can press ALT-(arrows) to move a line up or down.

Has anyone discovered these hotkey features in TextWrangler?

Peter K.

Posted 2011-01-21T19:31:14.657

Reputation: 111

this might be of use, but it looks like the answer is tentatively "no" http://groups.google.com/group/textwrangler/browse_thread/thread/47b62d5fe85f25d2

– zourtney – 2011-03-11T05:22:21.590

Answers

4

For Mac OS X it is ctrl+ or ctrl+.

You may need to change the Mission Control hotkey settings (in System Preferences) as the two keyboard strokes are preset there.

Tim

Posted 2011-01-21T19:31:14.657

Reputation: 41

1verified, this is the correct answer – Alex – 2016-06-03T09:37:51.403

1Works the same in BBEdit. Text Wrangler was "sunsetted" by Bare Bones (makers of TextWrangler and BBEdit). – iaforek – 2017-10-13T15:39:02.263

2

There's nothing mentioned in the manual (only Exchange characters and Exchange words).


If TextWrangler supports the Cocoa Text System (which I suspect it doesn't, but still) you can create the file ~/Library/Keybindings/DefaultKeyBinding.dict and enter the following:

{
    "~\UF701" = (
        "moveToBeginningOfLine:",
        "deleteToEndOfLine:",
        "deleteForward:",
        "moveDown:",
        "yank:",
        "insertNewline:",
        "moveUp:"
    );
}

This will add the shortcut Opt-DownArrow for a line-swap command (with the line below) to every application supporting the Cocoa text system.

Daniel Beck

Posted 2011-01-21T19:31:14.657

Reputation: 98 421

If TextWrangler does not support this: get a real text editor. Even TextMate supports this. – Daniel Beck – 2011-05-15T21:28:57.640

2

I do not think TextWrangler has this built in.

You can run applescripts in TextWrangler though, so you could make this work. I even found some applescripts that will do this.

You will need to replace BBEdit with TextWrangler in the applescripts. Put the scripts in "~/Library/Application Support/TextWrangler/Scripts/" and they will show up on the scripts menu in TextWrangler. Click Window -> Palettes -> Scripts to view the scripts palette, where you can set custom keyboard shortcuts.

Nathan Grigg

Posted 2011-01-21T19:31:14.657

Reputation: 1 601

If you want to assign those to Option-Up (⌥↑) and Down, you can use the Keyboard System Preference. TextWrangler didn't allow me to use "Option"(⌥) as an modifier. Now it works very sleek. – Klaas – 2012-08-03T12:39:47.617

0

nathangs solution works pretty well. But the provided link does not work anymore. So here are the scripts as plain text. Just paste them into the "AppleScript Editor" and save them to ~/Library/Application Support/TextWrangler/Scripts/

Works fine on Mountain Lion and with TextWrangler 4.

MoveLineDown.scpt:

tell application "TextWrangler"
    set x to startLine of selection
    tell text 1 of window 1
        if x = (count of lines) then return
        set myline to contents of line x
        delete line x
        if length of line x = 0 then
            make line at line x with data "
"
            make line at line (x + 1) with data myline
        else
            make line at line x with data myline

        end if
        select insertion point before line (x + 1)
    end tell
end tell

MoveLineUp.scpt:

tell application "TextWrangler"
    set x to startLine of selection
    if x = 1 then
        beep
        return
    end if
    tell text 1 of window 1
        set oldCount to count of lines
        set myline to contents of line x
        delete line x
        if x = 2 then
            if length of line 1 = 0 then
                make line at beginning with data "
"
            end if
            make line at beginning with data myline
        else
            if length of line (x - 2) = 0 then
                make line at line (x - 2) with data "
"
                make line at line (x - 1) with data myline
            else
                make line at line (x - 2) with data myline
            end if
        end if
        select insertion point before line (x - 1)
    end tell
end tell

Klaas

Posted 2011-01-21T19:31:14.657

Reputation: 101