Quote


A good programmer is a lazy programmer, because he writes minimum code.
--Anonymous


Saturday, December 4, 2010

Creating Notepad++ Macro for HTML Tag Wrapper

I know lot of people using Notepad++ (NPP) for editing HTML and XML rather than Visual Studio, including me. Its color highlighting and outlining are better compared with Visual Studio even though NPP misses features like auto intending and auto completion of tags. However, the new features in VS 2010 are awesome. Probably, I will not use NPP for HTML editing any more.

Having said that one limitation with NPP is that it does not insert closing tags automatically. You have to type  the <, >, /> every thing by yourself. Whatever advantages HTML and XML have, no one said it is keyboard friendly. 

When I have to create some HTML, I found this is a big inconvenience. I quickly searched for a work around. I found macros are supported in NPP. The macros in NPP is much simple (and less sophisticated) than that in Office and Windows. It simply allows you to record key presses and you can play it back on demand.

Here is the steps to create an HTML tag wrapper macro in NPP.
  1. Open Notepad++ (I use version 5.4.3)
  2. Type some html tag, say html (without < and >) and double click on it to select it.
  3.  Now click on Macro menu, and click on Start Recording.
  4. Press these keys. CTRL+C, LEFT ARROW, <,  CTRL+RIGHT ARROW, >, <, /, CTRL+V, >, LEFT ARROW, CTRL+LEFT ARROW, LEFT ARROW.
  5. Click on Macro menu, and on Stop Recording.
  6. Now test this. Move to a new line and type in another html tag. for e.g. body. Now select it, and click on Macro, Play Back.See the <, > and closing tags are inserted.
  7. Save this macro by clicking on Save current recorded macro in Macro menu.Give a name to it, some thing like TagWrapper. Click OK. From experience I learned that the keyboard shortcut that you can add here starts recording only. So, don't bother about it time being.
  8. Now you can see the TagWrapper is added to the macro menu. See screen shot below. 
  9. Next time when you want to insert an html tag, do like this. Type in the tag name, like table, select it, and then click on Macro menu, and select TagWrapper.










By the way, if you want to edit HTML in NPP, first select the language as HTML. To do this, click on Language menu and select HTML.

Also, this macro clears the clipboard. See the Ctrl+C and Ctrl+V keys in the step 4.

Hope this helps some one. 

Thanks.

2 comments:

  1. TextFX

    About auto closing html and xml tags :)

    ReplyDelete
  2. The only thing I don't necessarily like is that if you are one of the people that would rather put in the closing tags once your done with something this is pretty useless. I'll still use it whenever I remember I have it saved though because it is also useful for making sure you didnn't screw up with the tags.

    ReplyDelete