;; Behave like vi's o command (defun open-next-line (arg) "Move to the next line and then opens a line. See also `newline-and-indent'." (interactive "p") (end-of-line) (open-line arg) (next-line 1) (when newline-and-indent (indent-according-to-mode)))
(global-set-key (kbd "C-o") 'open-next-line)
;; Behave like vi's O command (defun open-previous-line (arg) "Open a new line before the current one. See also `newline-and-indent'." (interactive "p") (beginning-of-line) (open-line arg) (when newline-and-indent (indent-according-to-mode)))
(global-set-key (kbd "M-o") 'open-previous-line) ;; Autoindent open-*-lines (defvar newline-and-indent t "Modify the behavior of the open-*-line functions to cause them to autoindent.")
‘O’ commands of vi are closely equivalent to
‘C-a C-M-o’ and
‘C-e C-j’ in Emacs, respectively. The
‘open-previous-line’ functions above accept a
‘C-u’ prefix, while
‘C-M-o’) does not. This doesn’t get you exactly vi-like behavior as everything you type after an
‘O’ and before you hit ESC is inserted prefix times in vi. Ultimately KeyboardMacros would be the answer there.
I think TextMate uses Shift+Enter for “open next line”. (Ctrl+Shift+Enter might be a good candidate for “open previous line”.) So if you’re into consistency,
(global-set-key [S-return] 'open-next-line) (global-set-key [C-S-return] 'open-previous-line)
and comment out the lines above which begin with “
(global-set-key …”. Also, this retains the original
‘C-o’, which still has its uses.