sixsixsix
sixsixsix

Reputation: 1878

How to save ipython alias forever?

I am a bit confused on how to save ipython alias so that everytime i open a ipython session(after saving alias firstly ) and use the alias command directly(at the point,you should not input the alias again ). For example,when use ipython in linux(or windows) ,i would use vi rather than !vi a file .

vi fileneme

!vi filename

Upvotes: 1

Views: 762

Answers (2)

sixsixsix
sixsixsix

Reputation: 1878

To generate the default configuration files ipython_config.py in your IPython directory under profile_default :

$ ipython profile create

Find ipython_config.py in linux/windows

#use find command in linux
find / -name ipython_config.py
#in window,you can use all kinds of tools to search .
#in commands line,you can use 
ipython locate profile.
#in the directory,you can get it

Edit the ipython_config.py file to add the fellowing content

c = get_config()
c.TerminalIPythonApp.display_banner = True
c.InteractiveShellApp.log_level = 20
c.InteractiveShellApp.extensions = []
c.InteractiveShellApp.exec_lines = []
c.InteractiveShellApp.exec_files = ['mycode.py']#load Module when open ipython
c.InteractiveShell.autoindent = True
c.InteractiveShell.colors = 'LightBG'#ipython console color
c.InteractiveShell.confirm_exit = False
c.InteractiveShell.editor = 'vim'#you can change your favorite editor
c.InteractiveShell.xmode = 'Context'
c.PrefilterManager.multi_line_specials = True
#you can add your alias in the fellowing list
c.AliasManager.user_aliases = [('vi','vim'),('py','python'),('git','git'),]#i add git ,vim python .i really dislike "!"

Save the file and exit and get it

Upvotes: 2

Miozus
Miozus

Reputation: 1

thx@jack yang

1. emacs ~/.ipython/profile_default/python_config.py

2.in the end wirte down c.AliasManager.user_aliases = [('e', 'emacsclient -t')]

3.exit and restart ipython

Upvotes: 0

Related Questions