It's exactly the same as eclipse Shift+Enter.

E.g. I have a some text:

Hello, *everyone.
I'm Freewind.

The * in the first line is the cursor. Then I press some key shortcut, it becomes:

Hello, everyone.
*
I'm Freewind.

Notice there is a new line in the second line, and the cursor is in the new line.

What's the key shortcut can I use?

link|improve this question

2  
I always use C-e and then enter. – Milan Sep 2 '11 at 18:38
feedback

migrated from stackoverflow.com Sep 4 '11 at 0:16

This question came from our site for professional and enthusiast programmers.

3 Answers

up vote 5 down vote accepted

C-e C-m

or

C-e C-j

Both will move to end of the line and add newline. The second will also indent.

link|improve this answer
Can I map a key to do this job, so I just need to press once? – Freewind Sep 2 '11 at 18:42
That is a key mapping. Emacs allows binding commands to key sequences and most commands are two keys. It's generally a bad idea to bind to one key since most of the one key bindings are taken by emacs fundamentals. – Ross Patterson Sep 2 '11 at 18:46
feedback

For completeness:

(defun end-of-line-and-indented-new-line ()
  (interactive)
  (end-of-line)
  (newline-and-indent))

(global-set-key (kbd "<S-return>") 'end-of-line-and-indent-new-line)
link|improve this answer
Thank you, but how do I use it? Just map a key to this function? Can I map "Shift-Enter" to it? – Freewind Sep 2 '11 at 18:57
@Freewind answer updated – Trey Jackson Sep 2 '11 at 19:54
@Trey Jackson Thank you. – phimuemue Sep 2 '11 at 23:04
1  
If you use comment-indent-new-line instead, it will also insert the appropriate comment characters if you're currently inside a comment. – phils Sep 3 '11 at 0:19
feedback

You can make something akin to a keyboard macro like this.

(global-set-key (kbd "<S-return>") "\C-e\C-m")

or indeed:

(global-set-key (kbd "<S-return>") (kbd "C-e C-m"))

to avoid using two different kinds of syntax for keys.

link|improve this answer
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.