Recent

Author Topic: [solved] IDE Shortcuts to move and duplicate lines?  (Read 13657 times)

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 7410
  • Debugger - SynEdit - and more
    • wiki
Re: [solved] IDE Shortcuts to move and duplicate lines?
« Reply #15 on: January 19, 2020, 01:08:29 am »
It'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

  • Administrator
  • Hero Member
  • *
  • Posts: 7410
  • Debugger - SynEdit - and more
    • wiki
Re: [solved] IDE Shortcuts to move and duplicate lines?
« Reply #16 on: January 21, 2020, 08:29:45 pm »
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
« Last Edit: January 21, 2020, 08:32:56 pm by Martin_fr »

del

  • Full Member
  • ***
  • Posts: 215
Re: [solved] IDE Shortcuts to move and duplicate lines?
« Reply #17 on: April 26, 2021, 12:47:38 am »
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][+][-]
  1. var
  2.   s: String;
  3.   b1, b2: TPoint;
  4. begin
  5.   with Caller do
  6.     if SelAvail then
  7.     begin
  8.       b1 := BlockBegin;
  9.       b2 := BlockEnd;
  10.       s := TextBetweenPoints[b1, b2];
  11.       TextBetweenPoints[b1, b2] := s + s;
  12.       BlockBegin := b1;
  13.       BlockEnd := b2;
  14.     end
  15.     else
  16.     begin
  17.       s := Lines[CaretY - 1];
  18.       b1.x := 1;
  19.       b1.y := CaretY;
  20.       TextBetweenPoints[b1, b1] := s + #10;
  21.     end;
  22. end.                
  23.  
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.

 

TinyPortal © 2005-2018