Emacs: Move Cursor to Bracket 📜
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:
- Alt+m, Alt+.
- Alt+7, Alt+8
- Ctrl+7, Ctrl+8
- Alt+←, Alt+→
- F11, F12
[see Emacs Keys: Define Key ⌨]
Emacs, Work with Brackets
- Emacs: How to Edit Lisp Code
- emacs init: Highlight Brackets
- emacs init: Auto Insert Closing Bracket (electric-pair-mode)
- Emacs: Insert Brackets by Pair 📜
- Emacs: Delete Brackets by Pair 📜
- Emacs: Move Cursor to Bracket 📜
- Emacs: Jump to Matching Bracket 📜
- Emacs: Change Brackets 📜
- Emacs: Navigate Lisp Code as Tree
- Emacs: Select Text Between Quotes 📜
- Emacs: Xah Elisp Mode 📦