[solved] IDE Shortcuts to move and duplicate lines? lazarus / 9-Editor ---------------------------------------------------------------------- coliv_aja · 2017-02-18 02:17 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  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i 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  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i 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  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i 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 · 2017-02-18 02:23 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 · 2017-02-18 02:30 @coliv_aja If you use shortcuts often, you may interested to custom the shortcut keys: Lazarus main menu > Tools > Options > Editor > Keymappings ---------------------------------------------------------------------- Thaddy · 2017-02-18 07:28 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 · 2017-02-25 16:32 Quote from: Martin_fr on February 18, 2017, 03:23:18 amNot 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. Thanks, yes I ended up with Editor Macros and assign the keys to them. Quote from: Thaddy on February 18, 2017, 08:28:16 amWith 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. 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. ---------------------------------------------------------------------- eny · 2017-02-25 19:57 Shift-CuDn Ctrl-C (or Ctrl-X) Ctrl-V Ctrl-V Only works on Window$ though. ---------------------------------------------------------------------- jacmoe · 2017-02-25 20:04 It works on Linux too - KDE at least. ---------------------------------------------------------------------- coliv_aja · 2017-02-26 04:15 Quote from: eny on February 25, 2017, 08:57:26 pmShift-CuDn Ctrl-C (or Ctrl-X) Ctrl-V Ctrl-V Only works on Window$ though. I previously using various keyboard like yours. It's solved now with editor macros. Thanks for the reply. ---------------------------------------------------------------------- eny · 2017-02-27 23:10 Quote from: jacmoe on February 25, 2017, 09:04:03 pmIt works on Linux too - KDE at least. Never worked and still does not work with the numpad keys. IOW it's not possible to mimic the Window$ keypad behavior. (Tested on Linux Mint 18.1 KDE) ---------------------------------------------------------------------- dogriz · 2017-02-28 07:08 I don't know about KDE, but in Xfce, you can remap keyboard shortcuts as you like. ---------------------------------------------------------------------- Trenatos · 2018-06-15 17:50 Thanks @coliv_aja, these macros help! ---------------------------------------------------------------------- Martin_fr · 2019-11-04 11:47 Lazarus trunk 2.1 now has line-up/down/duplicate keys. ---------------------------------------------------------------------- coliv_aja · 2020-01-18 15:03 Quote from: Martin_fr on November 04, 2019, 12:47:26 pmLazarus trunk 2.1 now has line-up/down/duplicate keys. Thanks Martin. Can you please add duplicate selection also? In npp, ctrl+d will duplicate selection or line if nothing selected. But, since you already added the duplicate line(s), duplicate selection with different key would be nice too. ---------------------------------------------------------------------- Martin_fr · 2020-01-18 15:48 Quote from: coliv_aja on January 18, 2020, 04:03:06 pmCan you please add duplicate selection also? In npp, ctrl+d will duplicate selection or line if nothing selected. I'll have a look. Currently in the middle of another project.... ---------------------------------------------------------------------- argb32 · 2020-01-18 21:49 It's better to move whole statements when possible. Like in IntelliJ. There is little sense to move a part of statement or declaration. ---------------------------------------------------------------------- Martin_fr · 2020-01-19 00:08 Quote from: argb32 on January 18, 2020, 10:49:46 pmIt's better to move whole statements when possible. Like in IntelliJ. There is little sense to move a part of statement or declaration. I can see that people may want to move part of an expression/calculation. Or change order of arguments passed to a function. Anyway, if there is move-line an move-selection, then it would be a matter of selecting to statement boundaries (which is not on my current list, sorry). Most people will not have more than one statement per line. So moving lines will do this in that case. ---------------------------------------------------------------------- Martin_fr · 2020-01-21 19:29 Added DuplicateSelection, Also added MoveSelection... left/right/up/down They do nothing, if there is no selection. If you want the "duplicate line" to act on selection (if a selection is available), then you can create an editor macro "if Caller.SelAvail then ecDuplicateSelection else ecDuplicateLine;" https://wiki.lazarus.freepascal.org/Editor_Macros_PascalScript ---------------------------------------------------------------------- del · 2021-04-25 22:47 Quote from: coliv_aja on February 18, 2017, 03:17:36 amAre 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  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i 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.                  This is awesome. Doing the full block is the key. No pun intended. There's no way I could figure out all the nuances. I use Geany a lot and have really missed this feature in Lazarus. Thank you and I hope this message finds you in good health.