Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I jump to the matching tag, when editing HTML in Emacs?

Tags:

html

emacs

Suppose I'm editing a very long and messy HTML file. With my cursor at an open tag, is there a way to jump to its closing tag?

like image 939
Steve Avatar asked Sep 23 '09 19:09

Steve


3 Answers

And if you're using sgml-mode or its derivatives (e.g. html-mode):

sgml-skip-tag-forward is an interactive compiled Lisp function in ``sgml-mode.el'`.

It is bound to

C-c C-f

or

C-c <right>

and bound to the menu bar:

<menu-bar> <sgml> <sgml-skip-tag-forward>`

From emacslisp:

(sgml-skip-tag-forward arg)

Skip to end of tag or matching closing tag if present. With prefix argument arg, repeat this arg times. Return t if after a closing tag.

like image 142
viam0Zah Avatar answered Oct 20 '22 17:10

viam0Zah


Assuming you're using nxml-mode:

C-M-n runs the command nxml-forward-element, which is an interactive
compiled Lisp function in `nxml-mode.el'.

It is bound to C-M-n.

(nxml-forward-element &optional ARG)

Move forward over one element.
With ARG, do it that many times.
Negative ARG means move backward.
like image 43
Derek Slager Avatar answered Oct 20 '22 17:10

Derek Slager


...and if you're using web-mode C-c C-n will jump from an opening tag to the corresponding closing tag. The mode also has some other features (code folding, auto-closing HTML tags, ...) that might be worth taking a look at.

like image 12
dat Avatar answered Oct 20 '22 18:10

dat