Sunday, April 28, 2024
61
rated 0 times [  61] [ 0]  / answers: 1 / hits: 135568  / 3 Years ago, fri, may 14, 2021, 2:56:43

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?


More From » command-line

 Answers
0

You can set the $EDITOR variable with this command:



export EDITOR="/usr/bin/nano"


This will define the variable EDITOR for the current session and pass it into the environment of all its child processes. To set it permanently you must define it in one of the system configuration files. The highest level at which you can do this is to set it in /etc/environment. This defines it globally:



PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games"
EDITOR="/usr/bin/nano"


Check that variable is defined:



$ echo $EDITOR
/usr/bin/nano


Editor's note: it's often preferable to put environment variables in your own ~/.profile, which is a lot easier to fix if something goes wrong.


[#26581] Friday, May 14, 2021, 3 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
itchlos

Total Points: 486
Total Questions: 115
Total Answers: 110

Location: Macau
Member since Fri, Apr 28, 2023
1 Year ago
;