In Eclipse you can press ALT-(arrows) to move a line up or down.
Has anyone discovered these hotkey features in TextWrangler?
In Eclipse you can press ALT-(arrows) to move a line up or down.
Has anyone discovered these hotkey features in TextWrangler?
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.
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.
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.
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
If you'd like to leave the default mission control, and can face using control option then I started with the system preferences as mentioned here TextWrangler: hotkeys to move line up/down, but found it easier to change the Bbedit
to
In the menu settings, File->Settings Select Menu & Shortcuts
select Edit
unfold Lines
Click on the existing shortcut for Move Line Up
change it, and repeat for down