What is the command to match brackets in Emacs?

40,707

Solution 1

See show-paren-mode as described in 5.27 How do I show which parenthesis matches the one I'm looking at?

Solution 2

C-M-f, or M-x forward-sexp, goes forward to the closing brace, or to the opening brace in the next set of braces. C-M-b, or M-x backward-sexp, goes backward to the opening brace, or to the closing brace in the next set of braces. These commands will work for parentheses, square brackets, curly braces, angle brackets, etc., and can be customized to recognize other delimiters.

Solution 3

Just to complete the last response. I use C-M-n for forward match and C-M-u for backward match. C-M maps to Esc+Ctrl on windows keyboards.

Solution 4

There is also a show-paren-mode. For navigation, I think it's better C-M-n and C-M-n

Solution 5

https://github.com/redguardtoo/evil-matchit

I read vim matchit code before developing evil-matchit. evil-matchit is offering much more than original vim matchit now.

Besides, you can easily extend evil-matchit to support any new languages in your own ~/.emacs.

Share:
40,707

Related videos on Youtube

Chris Huang-Leaver
Author by

Chris Huang-Leaver

Clean, Clear and under control.

Updated on April 26, 2020

Comments

  • Chris Huang-Leaver
    Chris Huang-Leaver about 3 years

    What is the command to match brackets in Emacs (the equivalent of the % command in Vim)?

  • Chris Conway
    Chris Conway over 14 years
    Yes, but sometimes the matching paren isn't currently on the screen. This is when forward/backward-sexp really come in handy.
  • Peter.O
    Peter.O over 11 years
    Also C-M-u and C-M-d. see Moving in the Parenthesis Structure...
  • x-yuri
    x-yuri almost 9 years
    Strange combination of shortcuts, but I'm new to emacs and anyway here's the useful related link.

Related