Please add the ability to swap lines

Started by: ArthurZ5 voices9 posts

Please add the ability to swap lines

E.g. when we have several lines like

int main () {
ofstream myfile;
myfile.open ("example.txt");
myfile.close();
myfile << "Writing this to a file.n";
return 0; }

May want to swap to
int main () {
ofstream myfile;
myfile.open ("example.txt");
myfile << "Writing this to a file.n";
myfile.close();
return 0; }

using a simply keystroke while standing within myfile.close (w/o the need to highlight the line).

Thank You!

Oh no! Please no!

EE is a lightning fast, full featured great editor. Why do you need such a "feature"? It requires learning, remembering, a shortcut, configuring GUI, etc., etc. Why can't you select a line and drag it up one line?

Even as it is, there are numerous functions people, including me, are not aware of. These forums are replete with questions about this and that and poor Yutaka has so much work just pointing people in the right direction (meaning the right menus path.)

Please do not burden EE and make it a big footprint, slow monster. We have those and I hate them!

Thumbs down, absolutely, totally!!!
I would disagree with you on this comment Meir,

Such functionality exists in many editors EE has to compete against.
For example Sublime Text can swap lines with Ctrl-Shift-ArrowUp.
And it is one of its most used features: http://bit.ly/VYn8xW

Does it add slowness? I doubt that. Yet, people who shell $50 for an editor probably are on a 2-3 year hardware refresh cycle. For the rest, slowness is in each app.

On the contrary, it adds productivity.

Dragging is not going to do that in one hit, and for example not possible if you want to position a line at the top.

I think most EE users work on platforms as say Unix and use Windows as merely a window into their OS editing files quickly on the Win side. For them using keyboard is more natural and unintuitive than the mouse and they pick new commands naturally.
.

You can extend EmEditor yourself.
Just save a macro, add to My Macros, add an shortcut.
(or use Snippet plugin)


A macro could look like:

SwapWithLineAbove.jsee

document.selection.SelectLine(); //select line with cursor
cLine = document.selection.text; //store line to var
if(cLine.indexOf("n") < 0){cLine = cLine + "rn";}
document.selection.Delete(); //delete line
document.selection.LineUp(); //move cursor up one line
document.write(cLine); //paste line from var


or

MoveLineUp_(on-and-on).jsee
(assign to Shift+Alt+U)

document.selection.SelectLine(); //select line with cursor
cLine = document.selection.text; //store line to var
if(cLine.indexOf("n") < 0){cLine = cLine + "rn";}
document.selection.Delete(); //delete line
document.selection.LineUp(); //move cursor up on line
document.write(cLine); //paste line from var
document.selection.LineUp(); //move cursor up one line


and

MoveLineDown_(on-and-on).jsee
(assign to Shift+Alt+D)

document.selection.SelectLine(); //select line with cursor
cLine = document.selection.text; //store line to var
if(cLine.indexOf("n") < 0){cLine = cLine + "rn";}
document.selection.Delete(); //delete line
document.selection.LineDown(); //move cursor down one line
document.write(cLine); //paste line from var
document.selection.LineUp(); //move cursor up one line



- - -

Swap Lines UpSideDown.jsee

FROM:
1 - x
2 - Y
3 - Z
TO:
3 - Z
2 - Y
1 - x

Sel = document.selection.text;
SelArr = Sel.split("rn"); SelArr.reverse();
for(i=0,L=SelArr.length; i<L; i++){
document.selection.text = SelArr[i];
if(i<L-1){document.selection.text ="rn";}
}


.
This is an excellent idea and the Macros, too; thank you for supplying them!

Besides, are you the same Stefan who is the moderator on the HippoEdit forum?
Thanks Stefan,

Is it possible to have it move numerous lines if preselected?
Hi Steven,

no, the macro even does not run on highlighted lines.
I would also love this feature. I, too, have created a one line macro to do this in the meantime, but it doesn't work perfectly with "auto indent" enabled. It'd be nice to have this and multi line support too.
This is implemented now, see: http://emeditor.wpengine.com/text-editor-features/history/new-in-version-14/
The Move Line Up and Move Line Down commands were added. By default, these commands were assigned as CTRL + SHIFT + UP and CTRL + SHIFT + DOWN. If these shortcut keys don’t work, please go to Configuration Properties, Keyboard tab, and click Reset, or assign your favorite shortcut keys to these commands.
Thank you, Yutaka. Find me: transpose lines move line up move lines down switch lines

9 posts in this topic