Forum > Editor

[solved] IDE Shortcuts to move and duplicate lines?

(1/4) > >>

coliv_aja:
Are there any shortcuts to move lines like Notepad++?
In Notepad++ we can move lines up or down with Ctrl+Up or Ctrl+Down.
Also, we can duplicate text/lines with Ctrl+D. This 2 feature that keeps me back to Notepad++ if I need to quick edit my pascal files.

Edit:
Solved with editor macros and assign keys to them.
Here are my editor macros to mimic the Notepad++ behavior.

duplicate line/seltext

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---var  s: String;  b1, b2: TPoint;begin  with Caller do    if SelAvail then    begin      b1 := BlockBegin;      b2 := BlockEnd;      s := TextBetweenPoints[b1, b2];      TextBetweenPoints[b1, b2] := s + s;      BlockBegin := b1;      BlockEnd := b2;    end    else    begin      s := Lines[CaretY - 1];      b1.x := 1;      b1.y := CaretY;      TextBetweenPoints[b1, b1] := s + #10;    end;end.                  
move line/seltext up

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---var  b1, b2, b3, b4: TPoint;begin  with Caller do  begin    b1 := BlockBegin;    if b1.y = 1 then Exit;    b1.x := 1;    b2 := BlockEnd;    b2.x := Length(Lines[b2.y-1]) + 1;    b3.x := b1.x;    b3.y := b1.y - 1;    b4.y := b3.y;    b4.x := Length(Lines[b4.y-1]) + 1;    TextBetweenPoints[b3, b2] := TextBetweenPoints[b1, b2] + TextBetweenPoints[b4, b1] + TextBetweenPoints[b3, b4];    CaretY := CaretY-1;    Dec(b1.y);    Dec(b2.y);    BlockBegin:= b1;    BlockEnd:= b2;  end;end.     
move line/seltext down

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---var  b1, b2, b3, b4: TPoint;begin  with Caller do  begin    b1 := BlockBegin;    b2 := BlockEnd;    BlockEnd := Point(b2.x, b2.y + 1);    b3 := BlockEnd;    if b3.y = b2.y then    begin      BlockBegin := b1;      BlockEnd := b2;      exit;    end;    b1.x := 1;    b2.x := Length(Lines[b2.y - 1]) + 1;    b3.x := 1;    b3.y := b2.y + 1;    b4.y := b3.y;    b4.x := Length(Lines[b4.y - 1]) + 1;    TextBetweenPoints[b1, b4] := TextBetweenPoints[b3, b4] + TextBetweenPoints[b2, b3] + TextBetweenPoints[b1, b2];    CaretY := CaretY + 1;    Inc(b1.y);    Inc(b2.y);    BlockBegin:= b1;    BlockEnd:= b2;  end;end. 

Martin_fr:
Not by default.
But it is easy to create some macros, and assign them keys.
http://wiki.lazarus.freepascal.org/IDE_Window:_Editor_Macros

without pas script, use copy paste....

Using pas script, you can do it without clipboard.

Handoko:
@coliv_aja

If you use shortcuts often, you may interested to custom the shortcut keys:
Lazarus main menu > Tools > Options > Editor > Keymappings

Thaddy:
With the mouse it is easy to move lines.
Select the line(s) you want to move and ctrl+drag the line(s) to where you want them. This copies the line. w/o ctrl it moves the line.

coliv_aja:

--- Quote from: Martin_fr on February 18, 2017, 03:23:18 am ---Not by default.
But it is easy to create some macros, and assign them keys.
http://wiki.lazarus.freepascal.org/IDE_Window:_Editor_Macros

without pas script, use copy paste....

Using pas script, you can do it without clipboard.

--- End quote ---
Thanks, yes I ended up with Editor Macros and assign the keys to them.


--- Quote from: Thaddy on February 18, 2017, 08:28:16 am ---With the mouse it is easy to move lines.
Select the line(s) you want to move and ctrl+drag the line(s) to where you want them. This copies the line. w/o ctrl it moves the line.

--- End quote ---
For me, selecting a lines with mouse is slower than using keyboard. Selecting using keyboard then copy paste is much faster.
Problem solved with Editor Macros.

Navigation

[0] Message Index

[#] Next page

Go to full version