Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IntelliJ: Suppress quote insertion for HTML attributes

In IntelliJ IDEA 11 or 12, with an HTML file open, typing

<img src=

causes automatic insertion of double quotes, resulting in

<img src=""

Since I type ahead of where I read, this usually means I end up with something like

<img src=""image.png" alt="Image"/>"

How do I prevent double-quotes from being inserted automatically after attribute names?

like image 345
Anonymoose Avatar asked Dec 14 '12 23:12

Anonymoose


1 Answers

In Intellij IDEA 14 and 15 (see @Zook's comment for IDEA 13), the option is now

Windows:

Menu File→Settings→Editor→General→Smart Keys→Add quotes for attribute value on typing '=' and attribute completion (under XML/HTML section on the right side of the Settings dialog)

Mac:

Preferences→Editor→General→Smart Keys→Add quotes for attribute value on typing '='

I don't know if it was the same for previous versions, but what actually happens in IDEA 14 is it automatically inserts both quotes and puts the cursor inside them. That's fine, but then when you type what you expect to be your opening double-quote, the smart punctuation mechanism thinks you're closing the quotes and skips you over the automatically-inserted close quote (the same as it does in e.g. java code when you type a closing parenthesis when it has already auto-inserted one). So you wind up with the cursor after the pair of quotes, typing your attribute value. This seems consistent with the original observation.

I would actually consider this a bug in IDEA but I guess the fact that opening and closing punctuation are the same symbol in this case makes things complicated. The smart punctuation mechanism would need to know to ignore the first quote you typed, but if you actually wanted to type an empty attribute value like src="", it would need to ignore the first quote and then jump over the close quote for the second one. Fiddly, but not impossible.

like image 153
CupawnTae Avatar answered Nov 23 '22 08:11

CupawnTae