I would like to navigate quickly between classes in Python code. I'm looking for a command to go to the next / previous class so I can bind that to a key sequence. This question is not about graphical navigation tools like treemacs.

It might be interesting to hear about things like hydras too, but that's also not the focus of this question.


What I found so far and use to navigate between classes in python-mode:

First C-M-u which runs the command python-nav-backward-up-list to navigate up to class definition. After that C-M-a (beginning-of-defun) and C-M-e (end-of-defun) to navigate to previous and next class definition respectively.


Based on @muffinmad's answer:

(defun my/python-navigate-up-to-class-statement ()
  (let ((pos nil))
    (while (not (equal pos (point)))
      (setf pos (point))

(defun my/python-navigate-to-next-python-class ()

(defun my/python-navigate-to-previous-python-class ()

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.