Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

With emacs, how to go to the pairing (balancing) parentheses

Tags:

emacs

When cursor on one parentheses, how to jump to the pairing parentheses. Good to work in emacs -nw .

Just like % in Vim.

;;After got hint from @Lindy, @Francesco, I found more:

  C-M-f     Move forward over a balanced expression   C-M-b     Move backward over a balanced expression   C-M-k     Kill balanced expression forward   C-M-SPC   put the mark at the end of the sexp.   C-M-n  Move forward over a parenthetical group    C-M-p  Move backward over a parenthetical group    ;; C-M key binding can also be done by --> ESC Control-key    ;;And put this to .emacs, it will highlight opening/closing parens:   (show-paren-mode 1) 
like image 384
Andrew_1510 Avatar asked Mar 23 '12 19:03

Andrew_1510


People also ask

How to check parenthesis in Emacs?

In Emacs, if you are checking for balanced parentheses in a script, you can display which parenthesis matches the one you have selected by deleting it and reinserting it. Emacs will blink the cursor on the matching parentheses.

How do I view brackets in vim?

You can easily use the % key to jump to a matching opening or closing parenthesis, bracket or curly brace. You can also set the option showmatch . The cursor will briefly jump to the matching bracket, wen you insert one.


2 Answers

Use C-M-right and C-M-left (respectively backward-sexp and forward-sexp) to go to the beginning or the end of the current expression. This works for parenthesis pairs but also for plain words.

like image 115
Lindydancer Avatar answered Oct 14 '22 23:10

Lindydancer


As mentioned in emacs wiki (http://www.emacswiki.org/emacs/NavigatingParentheses):

  • C-M-n forward-list Move forward over a parenthetical group

  • C-M-p backward-list Move backward over a parenthetical group

  • C-M-f forward-sexp Move forward over a balanced expression

  • C-M-b backward-sexp Move backward over a balanced expression

  • C-M-k kill-sexp Kill balanced expression forward

  • C-M-SPC mark-sexp Put the mark at the end of the sexp.

https://superuser.com/questions/677516/how-do-i-jump-to-the-opening-or-closing-paren-brace-in-emacs

like image 24
Buzz Avatar answered Oct 14 '22 22:10

Buzz