How to add a new line without breaking the current line?
I am using prelude, and S-RET is equivalent to vi's o and C-S-RET is equivalent to vi's O.
The command C-o open-line
that others have suggested is not quite the same as o in vi, because it splits the current line and lets the cursor remain in the current line.
You get the exact same effect as vi's o with two strokes: C-e RET, which moves the cursor to the end of the current line and then inserts a new line, which leaves the cursor at the beginning of that line.
You could bind that sequence to a key of its own (perhaps overriding the existing definition of C-o), but I doubt if it's worth the trouble.
(Incidentally, the symmetric sequence C-a RET gives you the effect of vi's capital O, inserting a line before the current line.)
have you solved your problem?
I just solved this problem. Feel free to use this code :)
You can bind to every key you like in the global-set-key
,also to replace newline-and-indent
with newline
in case you don't like the new line to be indented.
;; newline-without-break-of-line
(defun newline-without-break-of-line ()
"1. move to end of the line.
2. insert newline with index"
(interactive)
(let ((oldpos (point)))
(end-of-line)
(newline-and-indent)))
(global-set-key (kbd "<C-return>") 'newline-without-break-of-line)