* * *

Author Topic: [solved] IDE Shortcuts to move and duplicate lines?  (Read 2001 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: 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: 4333
    • 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: 1514
  • 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: 4432
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 »
"Logically, no number of positive outcomes at the level of experimental testing can confirm a scientific theory, but a single counterexample is logically decisive."

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: 1561
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

  • Sr. Member
  • ****
  • Posts: 255
    • 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: 1561
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: 86
    • 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