Move line up and down

Help with writing and playing macros

Move line up and down

Postby Cye3s » Wed May 02, 2007 8:03 am

Can UE add this two features?
Move Up Current Line
Move Down Current Line

Many free text editor have this features.
User avatar
Cye3s
Newbie
 
Posts: 4
Joined: Tue May 01, 2007 11:00 pm

Re: Move line up and down

Postby Mofi » Wed May 02, 2007 9:44 am

Yes, with 2 JavaScripts or 2 macros assigned to hotkeys for fast execution you can move current line up or down. Here is the macro for current line down:

InsertMode
ColumnModeOff
HexOff
Clipboard 9
SelectLine
Cut
Key DOWN ARROW
Paste
Key UP ARROW
ClearClipboard
Clipboard 0

The cursor is at start of the moved line after execution.
User avatar
Mofi
Grand Master
Grand Master
 
Posts: 4069
Joined: Thu Jul 29, 2004 11:00 pm
Location: Vienna

Re: Move line up and down

Postby Cye3s » Wed May 02, 2007 12:28 pm

I write 2 macros like this, but it failed at the last line without push the "Enter" key.

Like this(The second line):
Line1 1111
Line2 2222
Line3 3333(No "Enter" here)

Sorry for my poor English :-)
User avatar
Cye3s
Newbie
 
Posts: 4
Joined: Tue May 01, 2007 11:00 pm

Re: Move line up and down

Postby Mofi » Wed May 02, 2007 2:08 pm

I really don't like text files where the last line has no line termination.

Here is the macro for Line Down which handles this situation also correct:

InsertMode
ColumnModeOff
HexOff
Key END
IfEof
"
"
Else
Clipboard 9
SelectLine
Cut
Key DOWN ARROW
Key END
IfEof
"
"
Else
Key HOME
IfColNumGt 1
Key HOME
EndIf
EndIf
Paste
ClearClipboard
Clipboard 0
EndIf
Key UP ARROW


And here is the macro for Line Up:

InsertMode
ColumnModeOff
HexOff
Clipboard 9
Key END
IfEof
"
"
Key UP ARROW
EndIf
SelectLine
Cut
Key UP ARROW
Paste

Key UP ARROW
ClearClipboard
Clipboard 0


Note: These macros will not work for Unicode or UTF-8 files because of a bug with IfEof in currently latest release v13.00a+2 of UE (and any previous version).

2007-11-02: The IfEof bug with Unicode files was fixed in UE v13.20.

2010-12-31: Inserted command Key UP ARROW in the macro for moving line up to set the cursor to start of just moved line to be able to use the macro immediately again.
User avatar
Mofi
Grand Master
Grand Master
 
Posts: 4069
Joined: Thu Jul 29, 2004 11:00 pm
Location: Vienna

Re: Move line up and down

Postby Cye3s » Thu May 03, 2007 12:17 am

Thank you :-)
User avatar
Cye3s
Newbie
 
Posts: 4
Joined: Tue May 01, 2007 11:00 pm

Re: Move line up and down

Postby Cye3s » Wed Jun 13, 2007 7:20 am

Another problem : Undo to the original state must press "CTRL + Z" many times. Very inconvenient.
Add this feature please :-)

Edit: Move current line up and down is supported by UltraEdit since v14.00.
User avatar
Cye3s
Newbie
 
Posts: 4
Joined: Tue May 01, 2007 11:00 pm


Return to Macros