* * *

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

coliv_aja

  • New member
  • *
  • Posts: 28
[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, lb: String;
  3.   b1, b2: TPoint;
  4. begin
  5.   with Caller do
  6.     if SelAvail then
  7.     begin
  8.       b1 := BlockBegin;
  9.       b2 := BlockEnd;
  10.       InsertTextAtCaret(SelText, scamIgnore);
  11.       BlockBegin := b1;
  12.       BlockEnd := b2;
  13.     end
  14.     else
  15.     begin
  16.       s := Lines[CaretY - 1];
  17.       b2 := CaretXY;
  18.       b2 := Point(Length(s) + 1, CaretY);
  19.       TextBetweenPoints[b2, b2] := #13#10 + s;
  20.     end;
  21. end.
  22.  

move line/seltext up
Code: Pascal  [Select]
  1. var
  2.   lb, s1, s2: String;
  3.   b1, b2, b3: TPoint;
  4. begin
  5.   with Caller do
  6.   begin
  7.     b1 := BlockBegin;
  8.     if b1.y = 1 then Exit;
  9.     lb := TextBetweenPoints[Point(Length(Lines[b1.y - 2]) + 2, b1.y - 1), Point(1, b1.y)];
  10.     if SelAvail then
  11.     begin
  12.       b2 := BlockEnd;
  13.       if b1.x <> 1 then
  14.       begin
  15.         b1.x := 1;
  16.         BlockBegin := b1;
  17.       end;
  18.       b2.x := Length(Lines[b2.y - 1]) + 1;
  19.       BlockEnd := b2;
  20.       s1 := Lines[b1.y - 2];
  21.       s2 := SelText;
  22.       b3.x := 1;
  23.       b3.y := b1.y - 1;
  24.       TextBetweenPoints[b3, b2] := s2 + lb + s1;
  25.       Dec(b1.y);
  26.       Dec(b2.y);
  27.       CaretY := CaretY - 1;
  28.       BlockBegin := b1;
  29.       BlockEnd := b2;
  30.     end
  31.     else
  32.     begin
  33.       s1 := Lines[CaretY - 2];
  34.       s2 := Lines[CaretY - 1];
  35.       b1.x := 1;
  36.       Dec(b1.y);
  37.       b2.x := Length(s2) + 1;
  38.       b2.y := CaretY;
  39.       TextBetweenPoints[b1, b2] := s2 + lb + s1;
  40.       CaretY := CaretY - 1;
  41.     end;
  42.   end;
  43. end.
  44.  

move line/seltext down
Code: Pascal  [Select]
  1. var
  2.   lb, s1, s2: String;
  3.   b1, b2, b3, c1, c2: TPoint;
  4. begin
  5.   with Caller do
  6.   begin
  7.     b1 := BlockBegin;
  8.     b2 := BlockEnd;
  9.     c1 := b2;
  10.     Inc(c1.y);
  11.     BlockEnd := c1;
  12.     c2 := BlockEnd;
  13.     BlockBegin := b1;
  14.     BlockEnd := b2;
  15.     if c1.y <> c2.y then Exit;
  16.     lb := TextBetweenPoints[Point(Length(Lines[b1.y - 1]) + 2, b1.y), Point(1, b1.y + 1)];
  17.     if SelAvail then
  18.     begin
  19.       if b1.x <> 1 then
  20.       begin
  21.         b1.x := 1;
  22.         BlockBegin := b1;
  23.       end;
  24.       b2.x := Length(Lines[b2.y - 1]) + 1;
  25.       BlockEnd := b2;
  26.       s1 := SelText;
  27.       s2 := Lines[b2.y];
  28.       b3.x := Length(s2) + 1;
  29.       b3.y := b2.y + 1;
  30.       TextBetweenPoints[b1, b3] := s2 + lb + s1;
  31.       Inc(b1.y);
  32.       Inc(b2.y);
  33.       CaretY := CaretY + 1;
  34.       BlockBegin := b1;
  35.       BlockEnd := b2;
  36.     end
  37.     else
  38.     begin
  39.       s1 := Lines[CaretY - 1];
  40.       s2 := Lines[CaretY];
  41.       b1.x := 1;
  42.       b2.x := Length(s2) + 1;
  43.       Inc(b2.y);
  44.       TextBetweenPoints[b1, b2] := s2 + lb + s1;
  45.       CaretY := CaretY + 1;
  46.     end;
  47.   end;
  48. end.
  49.  
« Last Edit: February 28, 2017, 08:53:10 am by coliv_aja »

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 4218
    • 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: 991
  • 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: 3418
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 »

coliv_aja

  • New member
  • *
  • Posts: 28
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: 1549
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 1.4.2 'stable' (#49524 win32) unless specified otherwise...

jacmoe

  • Full Member
  • ***
  • Posts: 242
    • 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: 28
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: 1549
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 1.4.2 'stable' (#49524 win32) unless specified otherwise...

dogriz

  • Jr. Member
  • **
  • Posts: 84
    • Tech blog - Delphi, Lazarus, Firebird, Windows, Linux, Android...
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.0.3
Lazarus 1.6.5
Debian x86_64, arm

 

Recent

Get Lazarus at SourceForge.net. Fast, secure and Free Open Source software downloads Open Hub project report for Lazarus