Do Enter create newline in Eclipse editor

In the Eclipse C / C ++ editor, I have an option to automatically close brackets (

)

and [

square brackets ]

. This works well if I want the content to span more than one line. When one or more closing characters are automatically generated, pressing Enter simply moves the cursor to the end of those closing characters. Therefore, if I want to print the code

if ( f() > 1 &&
     g() )

      

formatted in the same way as pressing [Enter] &&

does not start a new line immediately after typing , and it is not clear how easy it is to get this formatting. The best I've come up with is [Esc], then [Enter], but then manually closing by pressing )

inserts another character instead of moving on to the existing one.

Is there a way to get [Enter] in this context to do what I want? Or is there some command I can bind to a single key (like Shift + Enter or Ctrl + J) to just insert a new line and auto indent? Ideally, I could still skip the auto-generated )

one by typing )

, but one key like [Esc], then [Enter] would also be useful.

+3


source to share


1 answer


There is already a key binding that you can use to insert a new line below / above an existing line. You can see that if you go to Window -> Preferences -> Keys. There you can find the key bindings for the commands Insert Line Below Current Line and Insert Line Above Current Line.



You can change the keybindings to the keys you are comfortable with, or create a new keybind and make it reflect this action (when using your own key binding, you can also make it reflect to the C / C ++ Editor by choosing "Editor C / C ++ "instead of the generic Text Edit option in When: combo). However, I don't think it is possible to bind both the newline and auto-indent actions to one specific key by binding it in a direct way using custom settings.

0


source







All Articles