Windows: Changing IPython's default editor

Windows: Changing IPython's default editor

iPython's default editor is Notepad, which is invoked with the magic command %edit. While Notepad is quick and simple, it does not provide any helpful syntax highlighting or automatic indentation, which makes it cumbersome for code editing.

To change the default editor to something other than Notepad, we just need to create an environment variable called EDITOR and point it to the path of our favorite editor. One thing to consider is that the %edit command is meant for relatively quick editing, so you should choose an editor that is somewhat lightweight and does not take long to start. In the following example, we will be setting Programmer's Notepad as our default editor. (To see how to install Programmer's Notepad, you can go to these instructions.)

To add an environment variable, go to My Computer in an Explorer window and click on View system information. Alternately, you can right-click on the My Computer icon, if it is visible on your desktop and choose Properties.



This will bring up the System Properties window. Click on the Advanced tab and then on the Environment Variables button. This will bring up an Environment Variables window. Under the System Variables section click on New. Then enter EDITOR (make sure you use ALL CAPS) in the Variable name field, and finally, in the Variable value field, enter the full path of the editor executable. In this case, the Programmers Notepad 2 executable path is "C:\Program Files\Programmers Notepad\pn.exe". Important note: since this windows path has spaces in it, you must include the quotes around the entire path for IPython to read it correctly!!!



Once those fields are entered, click OK in all of the windows. Now when you use the %edit command in IPython, it will run Programmer's Notepad rather than the regular Windows Notepad.