Edit Stata do-files with Notepad++

Notepad is nice, but you can do better. Notepad++ can highlight your syntax, help you match your parentheses and, coolest of all, fold your code. If you already program in some other language using some graphical IDE, you know what that means. If you don't, here: when you enclose slabs of your Stata do-files inside what Stata calls "programmer's if" braces, Notepad++ will tuck those slabs away (fold) or reveal (unfold) them at the click of a side button labeled [+] or [-]. This kind of help makes a Stata user's life much easier than Stata's own do-file editor could as of version 10.

Notepad++ is my Stata do-file editing environment. I set it up following directions from two people: Friedrich Huebler and Keith Kranker. Huebler provides the files needed for running Stata code, either as selected lines (rundolines.exe) or complete do-files (rundo.exe), directly from Notepad++, and provides excellent general directions for integrating your Stata with any other text editor you might like. I gave Crimson a try before I settled on Notepad++. Kranker wrote a very nice Stata language specification -- the file that contains the directions that Notepad++ uses for recognizing Stata syntax. He also put his own spin on rundo.exe, and added a way to get Stata help from inside Notepad++, which I have not tested.

There are only two things I might add.

First, when you install Notepad++, you may want to check the box that says "don't use App Data". If you do so, then you can copy Kranker's userDefineLang_stata.xml file in the root of your Notepad++ installation and save it as userDefineLang.xml. Otherwise Notepad++ will look for this file in C:/Documents and Settings/YourUserName/Application Data/ which you may not have. Of course, you can create an Application Data folder if you wish. Directions for that are here (scroll down). 

Second, in case the problem hasn't been fixed by the time you read this, your Stata language definition sheet should include the double quotation mark " as an operator, not just as a delimiter. Otherwise your Stata syntax, under certain circumstances, will not fold properly. Why and how that happens is not that important. It can happen, but it can be easily fixed. Section 5 of the Notepad++ User Language Define System Manual here shows how to activate a new operator, with screen shots. It doesn't get any easier. Enjoy.

13 Responses to “Edit Stata do-files with Notepad++”

  1. Jess writes:

    I hadn't heard of Notepad++. I use UltraEdit as my do-file editor. It's not free but it can do syntax highlighting, folding/unfolding, and column/block text selection and typing. Does Notepad++ have the column/block mode? This is invaluable to me and saves a lot of time. I have UltraEdit at work but could use a free editor for my personal laptop.

  2. Gabi Huiber writes:

    Yes, Notepad++ knows columns. Either Alt+left-click, or Ctrl+Shift+arrow will put you in column select mode.

    Another thing I love about Notepad++, though probably all better text editors have it, is the "outdent" feature. It's nice enough that you can select a block of code, hit tab, and that will indent it by one tab. But if you need to go the other way, you can also select text, hit Shift+tab, and that will shift it back to the left by one tab -- "outdent" it, that is.

    I've never used UltraEdit but I've never head a bad thing about it either.

  3. Jess writes:

    Thanks for the info!

  4. Petri writes:

    I just evaluated the "column mode" in notepad++. Unfortunately it has nothing compared to Ultraedit.

    I can only manage to change the characters in highlighted area (rectangle selection). This is useless, unless you want everything to be one and the same character in the selection.

  5. Gabi Huiber writes:

    It gets worse than that. Notepad++ has acquired a habit of freezing up on me and shutting down with a warning that data loss is likely. That's not a catastrophe if you save often, which I do, but it is annoying. Maybe there's a reason so many people have so many good things to say about Ultraedit.

  6. Brandon writes:

    That IS a catastrophe. I just spent an entire day working on a python script. I saved all day long to test the results of running the script. I was almost done when I saved and got the warning. Everything shut down, and when I opened the script back up, it had completely been wiped out. I was only annoyed by the fact that it froze every once in awhile, but this time I'm pissed off. I'm going to research ultraedit right now.

  7. Gabi Huiber writes:

    That's bad news. Would you care to post here which version you are using? The behavior I reported in my earlier comment showed up unexpectedly in 5.0.3 but I never saw it again after I updated to 5.1.1 a while back. I've been happy with it, but now I'm concerned. The current version is 5.1.3.

  8. Jake writes:

    Regarding the column-block mode, you can insert text into selected columns, although not as nice as UltraEdit. When you select a block to insert via alt+shift, press Alt+C, and enter the text you want to insert.

    I'd love it much more if Notepad++ could insert text right on the editor though.

  9. Joon writes:

    While I like Notepad++ and use it frequently, the text process engines of commercial text editors - EditPlus, Ultraedit - are much better at dealing with huge text files. If you do "replace all" with such file, while in EP and UE does the job in matter of seconds, free text editors such as Notepad++ will freeze.

  10. Mema writes:

    Hi all!
    I am a big fan of Notepad++! I just updated to version 4.1.2 and one of my favorite functions disappeared: it used to highlight all the instances of a selected word, and now it doesn't anymore! Can anybody help me???
    Thanks! /M

  11. RPasquini writes:

    Thanks for the post. Very useful.

  12. Little things I like about Notepad++ « Stata Daily writes:

    [...] integrate Notepad++ into Stata are available in Friedrich Huebler. But first, I found this tip from Gabi Huiber very [...]

  13. Seb writes:

    I couldn't get the syntax highlighting to work (get Notepad++ to speak Stata). Tried pretty much everything I found on the web, nothing worked, e.g. copying the xml file to the appdata folder. If somebody could give some instructions or experienced the same problems, I would appreciate it.

Leave a Reply