help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Equivalent of vim's o or O commands


From: Brian Adkins
Subject: Re: Equivalent of vim's o or O commands
Date: Tue, 5 Feb 2008 11:47:58 -0800 (PST)
User-agent: G2/1.0

On Feb 5, 2:22 pm, Brian Adkins <lojicdot...@gmail.com> wrote:
> I would like to have the equivalent of vim's o or O commands in emacs.
> The o command will open a new line below the cursor and position the
> cursor properly indented (if autoindent is on). The O command does the
> same but opens the line above the cursor.
>
> In emacs, C-o will open a line above the cursor if the cursor is at
> the beginning of the line (but won't properly indent), but splits the
> line if the cursor is within some text.
>
> This is such a common operation for me, that I would like to bind it
> to a simple combination instead of requiring C-e C-j.
>
> I failed to find a good "emacs for vim users" reference on Google.
> There are some partial ones that are helpful, but I would like a more
> complete reference as I consider transitioning from vim to emacs. If
> anyone knows of one, I'd appreciate a link.
>
> Thanks,
> Brian Adkins

I should have searched the group archives first. I found a
satisfactory solution from a 2002 posting :)

(defun bja-open-line-below ()
  (interactive)
  (end-of-line)
  (open-line 1)
  (next-line 1)
  (indent-according-to-mode))

(defun bja-open-line-above ()
  (interactive)
  (beginning-of-line)
  (open-line 1)
  (indent-according-to-mode))

(global-set-key [?\C-o] 'bja-open-line-below)
(global-set-key [?\M-o] 'bja-open-line-above)

Being able to customize emacs with elisp is one of the main reasons
I'm considering a switch (that and being able to use emacs/slime for
Lisp programming).

Brian


reply via email to

[Prev in Thread] Current Thread [Next in Thread]