5

I do not want an answer about something like Imenu or tags - features that suppose you know some keywords about the method/function name to move to.

What I want is just general commands which jump forward to next or jumps backward to previous method, e.g. in ruby-mode or emacs-lisp-mode.

1 Answer 1

9

Use C-M-a (beginning-of-defun) to move backward before each "defun" (top-level sexp).

Use C-M-e (end-of-defun) to move forward after each "defun".

To move across several by repeating, just hold down Control, Alt (Meta), and a or e.

To move forward/backward N defuns, use a numeric prefix arg. E.g. C-u 1 0 C-M-e moves forward 10 defuns.

(There are several pairs of commands that end in a or e, for moving to the beginning or end of things. The most commonly used are probably C-a and C-e.)

3
  • Is there a mnemonic that makes this memorable? e for end (-of-defun) makes sense, but then a doesn't associate with beginning. They're not adjacent on the keyboard either, or even in line with each other, in order to have a forward/back or up/down association with each other. :(
    – Ben
    Mar 4 at 21:26
  • 1
    @Ben: In Emacs a and e often stand for beginning and end, respectively. Not sure what mnemonic might be helpful for thinking of a. But at least it's conventional in Emacs. See also b and f (back, forward) and p and n (previous, next).
    – Drew
    Mar 5 at 16:58
  • Ah thanks, I hadn't noticed that pattern yet.
    – Ben
    Mar 5 at 20:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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