Emacs: Move Cursor to Bracket 📜

By Xah Lee. Date: . Last updated: .

Move Cursor to Bracket

Here are commands to move cursor to any open/close brackets. They are extremely useful when working with computer language source code such as Python, JavaScript, Golang, etc.

put this in your Emacs Init File:

(defvar xah-brackets '( "“”" "()" "[]" "{}" "<>" "<>" "()" "[]" "{}" "⦅⦆" "〚〛" "⦃⦄" "‹›" "«»" "「」" "〈〉" "《》" "【】" "〔〕" "⦗⦘" "『』" "〖〗" "〘〙" "「」" "⟦⟧" "⟨⟩" "⟪⟫" "⟮⟯" "⟬⟭" "⌈⌉" "⌊⌋" "⦇⦈" "⦉⦊" "❛❜" "❝❞" "❨❩" "❪❫" "❴❵" "❬❭" "❮❯" "❰❱" "❲❳" "〈〉" "⦑⦒" "⧼⧽" "﹙﹚" "﹛﹜" "﹝﹞" "⁽⁾" "₍₎" "⦋⦌" "⦍⦎" "⦏⦐" "⁅⁆" "⸢⸣" "⸤⸥" "⟅⟆" "⦓⦔" "⦕⦖" "⸦⸧" "⸨⸩" "⦅⦆")
 "A list of strings, each element is a string of 2 chars, the left bracket and a matching right bracket.
Used by
`xah-backward-left-bracket'.
`xah-forward-right-bracket'.
`xah-goto-matching-bracket'.
URL `http://xahlee.info/emacs/emacs/emacs_navigating_keys_for_brackets.html'
")
(defconst xah-left-brackets
  (regexp-opt (mapcar (lambda (x) (substring x 0 1)) xah-brackets))
  "Regex string of left bracket chars. Generated from `xah-brackets'.
URL `http://xahlee.info/emacs/emacs/emacs_navigating_keys_for_brackets.html'
")
(defconst xah-right-brackets
  (regexp-opt (mapcar (lambda (x) (substring x 1 2)) xah-brackets))
  "Regex string of right bracket chars. Generated from `xah-brackets'.
URL `http://xahlee.info/emacs/emacs/emacs_navigating_keys_for_brackets.html'
")
(defun xah-backward-left-bracket ()
  "Move cursor to the previous occurrence of left bracket.
The list of brackets to jump to is defined by `xah-left-brackets'.

URL `http://xahlee.info/emacs/emacs/emacs_navigating_keys_for_brackets.html'
Created: 2015-10-01
Version: 2026-07-09"
  (interactive)
  (re-search-backward xah-left-brackets nil t))
(defun xah-forward-right-bracket ()
  "Move cursor to the next occurrence of right bracket.
The list of brackets to jump to is defined by `xah-right-brackets'.

URL `http://xahlee.info/emacs/emacs/emacs_navigating_keys_for_brackets.html'
Created: 2015-10-01
Version: 2026-07-09"
  (interactive)
  (re-search-forward xah-right-brackets nil t))

You should assign them keys. I suggest one of the following key pairs:

[see Emacs Keys: Define Key ⌨]

Emacs, Work with Brackets