Recent

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

coliv_aja

  • New Member
  • *
  • Posts: 38
[solved] IDE Shortcuts to move and duplicate lines?
« on: February 18, 2017, 03:17:36 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.  

move line/seltext up
Code: Pascal  [Select][+][-]
  1. var
  2.   b1, b2, b3, b4: TPoint;
  3. begin
  4.   with Caller do
  5.   begin
  6.     b1 := BlockBegin;
  7.     if b1.y = 1 then Exit;
  8.     b1.x := 1;
  9.     b2 := BlockEnd;
  10.     b2.x := Length(Lines[b2.y-1]) + 1;
  11.     b3.x := b1.x;
  12.     b3.y := b1.y - 1;
  13.     b4.y := b3.y;
  14.     b4.x := Length(Lines[b4.y-1]) + 1;
  15.     TextBetweenPoints[b3, b2] := TextBetweenPoints[b1, b2] + TextBetweenPoints[b4, b1] + TextBetweenPoints[b3, b4];
  16.     CaretY := CaretY-1;
  17.     Dec(b1.y);
  18.     Dec(b2.y);
  19.     BlockBegin:= b1;
  20.     BlockEnd:= b2;
  21.   end;
  22. end.    
  23.  

move line/seltext down
Code: Pascal  [Select][+][-]
  1. var
  2.   b1, b2, b3, b4: TPoint;
  3. begin
  4.   with Caller do
  5.   begin
  6.     b1 := BlockBegin;
  7.     b2 := BlockEnd;
  8.     BlockEnd := Point(b2.x, b2.y + 1);
  9.     b3 := BlockEnd;
  10.     if b3.y = b2.y then
  11.     begin
  12.       BlockBegin := b1;
  13.       BlockEnd := b2;
  14.       exit;
  15.     end;
  16.     b1.x := 1;
  17.     b2.x := Length(Lines[b2.y - 1]) + 1;
  18.     b3.x := 1;
  19.     b3.y := b2.y + 1;
  20.     b4.y := b3.y;
  21.     b4.x := Length(Lines[b4.y - 1]) + 1;
  22.     TextBetweenPoints[b1, b4] := TextBetweenPoints[b3, b4] + TextBetweenPoints[b2, b3] + TextBetweenPoints[b1, b2];
  23.     CaretY := CaretY + 1;
  24.     Inc(b1.y);
  25.     Inc(b2.y);
  26.     BlockBegin:= b1;
  27.     BlockEnd:= b2;
  28.   end;
  29. end.
  30.  
« Last Edit: August 11, 2017, 08:26:41 am by coliv_aja »

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 9754
  • Debugger - SynEdit - and more
    • wiki
Re: IDE Shortcuts to move and duplicate lines?
« Reply #1 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.

Handoko

  • Hero Member
  • *****
  • Posts: 5122
  • My goal: build my own game engine using Lazarus
Re: IDE Shortcuts to move and duplicate lines?
« Reply #2 on: February 18, 2017, 03:30:41 am »
@coliv_aja

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

Thaddy

  • Hero Member
  • *****
  • Posts: 14158
  • Probably until I exterminate Putin.
Re: IDE Shortcuts to move and duplicate lines?
« Reply #3 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.
« Last Edit: February 18, 2017, 08:33:00 am by Thaddy »
Specialize a type, not a var.

coliv_aja

  • New Member
  • *
  • Posts: 38
Re: IDE Shortcuts to move and duplicate lines?
« Reply #4 on: February 25, 2017, 05:32:09 pm »
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.
Thanks, yes I ended up with Editor Macros and assign the keys to them.

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.
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.
« Last Edit: February 28, 2017, 08:50:11 am by coliv_aja »

eny

  • Hero Member
  • *****
  • Posts: 1634
Re: IDE Shortcuts to move and duplicate lines?
« Reply #5 on: February 25, 2017, 08:57:26 pm »
Shift-CuDn
Ctrl-C (or Ctrl-X)
Ctrl-V
Ctrl-V

Only works on Window$ though.
All posts based on: Win10 (Win64); Lazarus 2.0.10 'stable' (x64) unless specified otherwise...

jacmoe

  • Full Member
  • ***
  • Posts: 249
    • Jacmoe's Cyber SoapBox
Re: IDE Shortcuts to move and duplicate lines?
« Reply #6 on: February 25, 2017, 09:04:03 pm »
It works on Linux too - KDE at least.
more signal - less noise

coliv_aja

  • New Member
  • *
  • Posts: 38
Re: IDE Shortcuts to move and duplicate lines?
« Reply #7 on: February 26, 2017, 05:15:33 am »
Shift-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

  • Hero Member
  • *****
  • Posts: 1634
Re: IDE Shortcuts to move and duplicate lines?
« Reply #8 on: February 28, 2017, 12:10:30 am »
It 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)
All posts based on: Win10 (Win64); Lazarus 2.0.10 'stable' (x64) unless specified otherwise...

dogriz

  • Full Member
  • ***
  • Posts: 126
Re: IDE Shortcuts to move and duplicate lines?
« Reply #9 on: February 28, 2017, 08:08:47 am »
I don't know about KDE, but in Xfce, you can remap keyboard shortcuts as you like.
FPC 3.2.2
Lazarus 2.2.4
Debian x86_64, arm

Trenatos

  • Hero Member
  • *****
  • Posts: 533
    • MarcusFernstrom.com
Re: [solved] IDE Shortcuts to move and duplicate lines?
« Reply #10 on: June 15, 2018, 07:50:17 pm »
Thanks @coliv_aja, these macros help!

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 9754
  • Debugger - SynEdit - and more
    • wiki
Re: [solved] IDE Shortcuts to move and duplicate lines?
« Reply #11 on: November 04, 2019, 12:47:26 pm »
Lazarus trunk 2.1 now has line-up/down/duplicate keys.

coliv_aja

  • New Member
  • *
  • Posts: 38
Re: [solved] IDE Shortcuts to move and duplicate lines?
« Reply #12 on: January 18, 2020, 04:03:06 pm »
Lazarus 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

  • Administrator
  • Hero Member
  • *
  • Posts: 9754
  • Debugger - SynEdit - and more
    • wiki
Re: [solved] IDE Shortcuts to move and duplicate lines?
« Reply #13 on: January 18, 2020, 04:48:19 pm »
Can 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

  • Jr. Member
  • **
  • Posts: 89
    • Pascal IDE based on IntelliJ platform
Re: [solved] IDE Shortcuts to move and duplicate lines?
« Reply #14 on: January 18, 2020, 10:49:46 pm »
It's better to move whole statements when possible. Like in IntelliJ.
There is little sense to move a part of statement or declaration.

 

TinyPortal © 2005-2018