Using Notepad++ as IPython default code editor

IPython supplies you the convenience of editing code from command prompt, the magic command %edit. However in Windows it will use notepad as default editor which is not suitable for editing python source code. Here is the method to config the editor option.

As IPython official doc said:

Editor configuration

IPython can integrate with text editors in a number of different ways:

  • Editors (such as (X)Emacsvim and TextMate) can send code to IPython for execution.
  • IPython’s %edit magic command can open an editor of choice to edit a code block.

The %edit command (and its alias %ed) will invoke the editor set in your environment as EDITOR. If this variable is not set, it will default to vi under Linux/Unix and to notepad under Windows. You may want to set this variable properly and to a lightweight editor which doesn’t take too long to start (that is, something other than a new instance of Emacs). This way you can edit multi-line code quickly and with the power of a real editor right inside IPython.

You can also control the editor by setting TerminalInteractiveShell.editor in ipython_config.py.

What we should do is just set the TerminalInteractiveShell.editor variable in ipython_config.py. So where is the ipython_config.py?

 The official doc gives a method to locating the file, using the command "ipython locate" in command line.

In my computer, the result is as follows. B.T.W, my os is Win7. 

>> ipython locate

C:\Users\xxx\.ipython

So, just find the ipython_config.py file there, if not exist just create one.

Then write the following code in the file:

c = get_config()
# use DOS style path
c.TerminalInteractiveShell.editor = "C:/PROGRA~1/Notepad++/notepad++.exe"
# set editor for Qt Console, if you wish to use that
c.IPythonWidget.editor = "C:/PROGRA~1/Notepad++/notepad++.exe"

Enjoy IPython with Notepad++.

原文地址:https://www.cnblogs.com/nn0p/p/2995266.html