Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

When I am using ipython or ipython3, I can use the %edit command to open up an editor to write my python scripts in. My problem is that the default editor is vim and I really do not get how to use that editor. What I would like to do is to change the editor to either nano or gedit. I think to stay with the terminal I would prefer to change it to the nano editor.

When I type in the 'edit?' command into the ipython terminal it says :

%edit runs IPython's editor hook. The default version of this hook is set to call the editor specified by your $EDITOR environment variable. If this isn't found, it will default to vi under Linux/Unix and to notepad under Windows. See the end of this docstring for how to change the editor hook.

Then when I see the end of that docstring I see this:

Changing the default editor hook:

If you wish to write your own editor hook, you can put it in a configuration file which you load at startup time. The default hook is defined in the IPython.core.hooks module, and you can use that as a starting example for further modifications. That file also has general instructions on how to set a new hook for use once you've defined it.

Sorry to be such a newbie, but I get lost here. I am not sure how to get to the IPython.core.hooks module, or just simply set an environment variable $EDITOR to nano.

Any suggestions?

share|improve this question
If someone's answer was helpful to you, then please consider marking it as the accepted answer so others may more easily find it in the future. This is also a polite way to thank the person answering your question for helping you out. – Danatela Mar 11 '14 at 5:26
up vote 14 down vote accepted

You can set $EDITOR variable by such command:

export EDITOR="/usr/bin/nano"

Thus it will define variable named EDITOR for current session. Another option is to set it in /etc/environment file (to define it globally):


Check that variable is defined:

$ echo $EDITOR
share|improve this answer
I added the line 'EDITOR="/usr/bin/nano"' to my /etc/environment file, but it does not seem to work. Do I need to reboot? – Willoczy Mar 11 '14 at 4:00
Now reboot your system and settings will apply. – Danatela Mar 11 '14 at 4:01
start a new session and you are done! – Luis Siquot Jul 9 '15 at 20:52
You don't need to reboot for changes to take effect, just run source /etc/environment after you edit the file. – cremefraiche Oct 16 '15 at 23:31

Add line

export EDITOR=nano

to your ~/.profile and ~/.bashrcas in following picture. Do not put quotes around nano

enter image description here

and then run

source ~/.profile 
source ~/.bashrc

at the prompt after modifying .profile and .bashrcfor the modification to take effect.

enter image description here

Now the %edit in ipython will open nano.

~/.bashrc will be called for interactive + non-loginshell

whereas ~/.profile will be called for interactive + login shell

In your case it is enough to just add it in ~/.bashrc instead of ~/.profile.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.