Notepad++ XML Auto Indent + Tag Closing
I'm migrating a question I posted on stackoverflow to here as it may be more relevant.
Here is the question:
I'm looking for a way to code XML (mxml, specifically) in Notepad++ such that it follows the behavior of the "Indent by Fold" plugin - indentation after pressing 'enter' following an opening tag - but also includes automatic tag closing similar to what is provided by the "XML Tools" plugin.
The issue with enabling both at once is that I start with something like this:
<hello|
(Note: the '|' character represents the cursor)
Then after hitting the '>' key, I get this:
<hello>|</hello>
And after pressing 'Enter,' I get something that looks like this:
<hello>
|</hello>
What I'm looking for is something that looks like this (after hitting the '>' key):
<hello>
|
</hello>
Any help would be much appreciated.
Here's my quick and dirty solution. Really it just involves creating a macro along with enabling a XML tools feature.
First, remove the "Indent By Fold" plugin, if installed.
Then, enable the "Tag auto-close" feature by going to Plugins>XML Tools.
Also, enable Notepad++'s auto indent by going to Settings > Preferences > MISC. Tab
Next, go to Macro > Start Recording.
Now, hit the following keys in this sequence:
>, enter, enter, up, tab.
Then, go to Macro > Stop Recording. Followed by, Macro > Save Current Recorded Macro.
This will create the final '>' as well as the closing tag, but then leave your cursor indented in a new line between the opening and closing tags.
I saved mine as "CTRL + '.'".
The reasoning behind this was that if I was here:
<hello|
The natural thing to do would be to hit the '>' key. Since I need to hit SHIFT+ '.' on a QWERTY keyboard to get this character, I figure I'd use CTRL+'.' (only one key away) to perform the macro and save SHIFT+'.' for cases where I just want the plain old character (e.g. <hello />
).
Here is the result after hitting CTRL + '.'
<hello>
|
</hello>
I'll be on the lookout for a more elegant solution, but for now this seems to be pretty good.
Hope this helps!