UP | HOME

Jump between matching parens

One of my most-used evil's feature is jumping between matching parens with % key, in Emacs keybinding, there's no such a thing.

So here's a workaround:

(global-set-key "%" 'match-paren)
(defun match-paren (arg)
  "Go to the matching paren if on a paren; otherwise insert %."
  (interactive "p")
  (cond ((looking-at "\\s(") (forward-list 1) (backward-char 1))
        ((looking-at "\\s)") (forward-char 1) (backward-list 1))
        (t (self-insert-command (or arg 1)))))

The above snippet will bind the % key, to jump between matching parens, or just insert % character if there's no parens.

Source: https://www.gnu.org/software/emacs/manual/html_node/efaq/Matching-parentheses.html

Date: 2019-01-18 Fri 00:00

Author: Huy Tran

Created: 2019-04-22 Mon 14:41