Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

How to efficiently type in a pair of XML tags such as <tag></tag> in Emacs?

I am hoping some sort of auto-complete behavior.

share|improve this question
I think the most effective way is to use snippets like in the answers to your other question:…. Also, you might want to vote on useful answers to your questions to show appreciation. You have asked 22 question but only voted on 6 answers. – N.N. Mar 6 '12 at 15:03
up vote 2 down vote accepted

Add the following to your .emacs file.

;; associate xml, xsd, etc with nxml-mode
(add-to-list 'auto-mode-alist (cons (concat "\\." (regexp-opt '("xml" "xsd" "rng" "xslt" "xsl") t) "\\'") 'nxml-mode))

set the automplete flag to true

(setq nxml-slash-auto-complete-flag t)
share|improve this answer
This will complete the appropriate close tag after you type </ – Doug Harris Jan 30 '12 at 19:05
How to use this when I am inserting pairs of tags in a file that's not XML, XSD, etc.? – qazwsx Feb 24 '12 at 19:47
switch the nxml mode. M-x nmxl-mode – Oleg Pavliv Feb 24 '12 at 19:58
This basically works. One drawback of this is that when I need to insert pairs of tags frequently in a markdown file for which I use markdown-mode, I need to switch between markdown-mode and nxml-mode frequently. Any suggestion? – qazwsx Feb 25 '12 at 4:00
Emacs does not support multiple major modes. So you should switch between modes. Define a shortcut which does it quickly – Oleg Pavliv Feb 25 '12 at 6:40

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.