Emacs: Jump to the next line with same indentation
A little improvement on Stefan’s answer:
(defun jump-to-same-indent (direction) (interactive "P") (let ((start-indent (current-indentation))) (while (and (not (bobp)) (zerop (forward-line (or direction 1))) (or (= (current-indentation) 0) (> (current-indentation) start-indent))))) (back-to-indentation))
This function takes a prefix argument (e.g., +1/-1) that designates the number of lines to move over when searching for a line with the same indentation. It also skips empty lines. Finally one can bind both forward and backward searches using keybindings similar to M-{ and M-} for paragraphs:
(global-set-key [?\C-{] #'(lambda () (interactive) (jump-to-same-indent -1)))
(global-set-key [?\C-}] 'jump-to-same-indent)
Comments
Comments powered by Disqus