Recent

Author Topic: How to break new line in Lazarus IDE Editor just like in Visual Studio?  (Read 2755 times)

wytwyt02

  • Jr. Member
  • **
  • Posts: 83
In VisualStudio, I can Shift+Enter will make a new line and move cursor to it, Is lazarus have similar shortcut for that?

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 9792
  • Debugger - SynEdit - and more
    • wiki
Re: How to break new line in Lazarus IDE Editor just like in Visual Studio?
« Reply #1 on: January 23, 2020, 02:21:47 pm »
Your description is somewhat unclear. Pressing Enter already creates a new line, and the cursor will be in that new line?

Google suggests, that the shift-enter also adds a semicolon? Not sure if that is all, or if there is more to it?

Anyway you can record an editor macro https://wiki.lazarus.freepascal.org/IDE_Window:_Editor_Macros which has the 2 keystrokes ; and return.
Then make it IDE global and assign it to shift + return.

wytwyt02

  • Jr. Member
  • **
  • Posts: 83
Re: How to break new line in Lazarus IDE Editor just like in Visual Studio?
« Reply #2 on: January 23, 2020, 02:30:51 pm »
Your description is somewhat unclear. Pressing Enter already creates a new line, and the cursor will be in that new line?

Google suggests, that the shift-enter also adds a semicolon? Not sure if that is all, or if there is more to it?

Anyway you can record an editor macro https://wiki.lazarus.freepascal.org/IDE_Window:_Editor_Macros which has the 2 keystrokes ; and return.
Then make it IDE global and assign it to shift + return.

Shift+Enter will insert a blank line below the current line

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 9792
  • Debugger - SynEdit - and more
    • wiki
Re: How to break new line in Lazarus IDE Editor just like in Visual Studio?
« Reply #3 on: January 23, 2020, 03:06:46 pm »
Shift+Enter will insert a blank line below the current line

To further clarify (since I do not have VS installed): It will insert a new line below the current, independent where the caret is in the current line (the caret can be in the middle of the current line).

So then it does: end-key followed by return.
And you can record this as a macro too.

Note: In Lazarus there is on option "end key jumps to nearest end". This will mean, it recognizes the "last none space" as first end, and then the real end after trailing spaces as 2nd end.
If this option is on, your macro should be:
   <home key>  <end key>  <end key>  <return>

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 9792
  • Debugger - SynEdit - and more
    • wiki
Re: How to break new line in Lazarus IDE Editor just like in Visual Studio?
« Reply #4 on: January 23, 2020, 03:17:17 pm »
Off topic, but in case you need it.

The normal return can act smart, if you are inside a comment or string. The comment or string will be continued (i.e., ' or // will be inserted).
See Tools > Option > Editor > General > Tab and Indent

If you enable this for // comments, then this will apply to the above macro too.
Alternatively you can do the macro <end key> <home key>  <home key>  <down key>  <ctrl N>
This does not work, if you are at the very last line of text, as <down key> can not go down.

ctrl-N is (Tools > Option >Editor > Keymap)  "Break line, leave cursor"
Insert a new line, but does not move the caret (yet also extends strings and comments, but if you are at the start of the (next) line, then there is no open string or // comment)


wytwyt02

  • Jr. Member
  • **
  • Posts: 83
Re: How to break new line in Lazarus IDE Editor just like in Visual Studio?
« Reply #5 on: January 24, 2020, 01:43:40 am »
Off topic, but in case you need it.

The normal return can act smart, if you are inside a comment or string. The comment or string will be continued (i.e., ' or // will be inserted).
See Tools > Option > Editor > General > Tab and Indent

If you enable this for // comments, then this will apply to the above macro too.
Alternatively you can do the macro <end key> <home key>  <home key>  <down key>  <ctrl N>
This does not work, if you are at the very last line of text, as <down key> can not go down.

ctrl-N is (Tools > Option >Editor > Keymap)  "Break line, leave cursor"
Insert a new line, but does not move the caret (yet also extends strings and comments, but if you are at the start of the (next) line, then there is no open string or // comment)

On my machine, The Ctrl+N and Enter is the same behavior, Is it normal?

winni

  • Hero Member
  • *****
  • Posts: 3197
Re: How to break new line in Lazarus IDE Editor just like in Visual Studio?
« Reply #6 on: January 24, 2020, 02:27:27 am »
Hi!

Goto:

MainMenu --> Tools--> Options --> Editor --> Key Mappings

On that page TopRight: "Find key combination" --> Dialog

In that dialog press "Grab Key"

Then press Ctrl N - then OK

Now you are shown what function is connected to this HotKey - by default that what @Martin_fr told you:

 "Break line, leave cursor"

Winni
 

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 9792
  • Debugger - SynEdit - and more
    • wiki
Re: How to break new line in Lazarus IDE Editor just like in Visual Studio?
« Reply #7 on: January 24, 2020, 04:09:59 am »
On my machine, The Ctrl+N and Enter is the same behavior, Is it normal?
Maybe your OS is sending keystrokes that way.
Also what is your OS?

For MAC the IDE has an entirely different key-combo setting.

You can always assign keycombos as you need, see post by winni.


If you record the macro with normal return, you can edit the macro and replace
ecLineBreak;  with  ecInsertLine;

PascalDragon

  • Hero Member
  • *****
  • Posts: 5446
  • Compiler Developer
Re: How to break new line in Lazarus IDE Editor just like in Visual Studio?
« Reply #8 on: January 24, 2020, 09:27:49 am »
Shift+Enter will insert a blank line below the current line

To further clarify (since I do not have VS installed): It will insert a new line below the current, independent where the caret is in the current line (the caret can be in the middle of the current line).
I tested it in VS (it's Ctrl + Enter for me). First of by default VS does not allow to freely position the cursor (it always goes to the last character of the line). But if I have a line with space (I'll mark them with . below and | denotes the cursor) the following will happen:

Code: C  [Select][+][-]
  1. {
  2. ...
  3. .........|
  4. }

-> Ctrl + Enter

Code: C  [Select][+][-]
  1. {
  2. ...
  3.    |
  4. .........
  5. }

The cursor is now at the ident where it would insert the next identifier and if I start typing three spaces would be inserted at the front as well.

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 9792
  • Debugger - SynEdit - and more
    • wiki
Re: How to break new line in Lazarus IDE Editor just like in Visual Studio?
« Reply #9 on: January 24, 2020, 03:31:12 pm »
So it is above the current line?
Record a macro to go one line up, end of line, return ?

Sorry, I am blindly guessing here.

--------------
The normal return in Lazarus can position the caret according to indent.
Tools > Options > Edtior > General > Tab and Indent:

Section "Indent"
CheckBox "Auto indent" => Checked (True)
DropDown "Auto indent" => "Position only"

Follow the link "smart indent" which leads to page: Codetools > General
Checkbox "On break line" (under "Indentation for Pascal sources")  => OFF

-------------
If you use "Trim trailing spaces" then instead of "Position only", you can use any other setting. It will insert the spaces or tabs, but if you leave the line without typing anything the spaces will be cleared away.
"Trim trailing spaces" is under Editor > General > Miscellaneous

 

TinyPortal © 2005-2018