Vim Tips Wiki
(format)
(Change <tt> to <code>, perhaps also minor tweak.)
 
(4 intermediate revisions by 3 users not shown)
Line 1: Line 1:
 
{{TipNew
 
{{TipNew
 
|id=1551
 
|id=1551
|previous=1550
+
|previous=1549
 
|next=1552
 
|next=1552
|created=April 3, 2008
+
|created=2008
 
|complexity=basic
 
|complexity=basic
 
|author=Srepmub
 
|author=Srepmub
Line 11: Line 11:
 
|category2=
 
|category2=
 
}}
 
}}
'''Note:''' the following tips are very outdated. If you're using IPython 0.11 or newer, have a look at [https://github.com/ivanov/vim-ipython vim-ipython] (wish ships with IPython, and provides bidirectional interface between vim and ipython.
+
{{Deprecated|If you're using [http://ipython.org IPython] 0.11 or newer, have a look at [https://github.com/ivanov/vim-ipython vim-ipython]. It ships with ipython, provides bidirectional interface between vim and ipython, and works on all platforms.}}
  +
   
 
IPython and Vim make for a great IDE. The following shortcuts can help to make it even better.
 
IPython and Vim make for a great IDE. The following shortcuts can help to make it even better.
   
To also avoid having to enter a test command in IPython, I use konsole and dcop to send the command to IPython automatically. In the following, <tt>'</tt> is mapped to run the command <tt>'r'</tt> in IPython. First, start IPython as follows:
+
To also avoid having to enter a test command in IPython, I use konsole and dcop to send the command to IPython automatically. In the following, <code>'</code> is mapped to run the command <code>'r'</code> in IPython. First, start IPython as follows:
 
<pre>
 
<pre>
 
konsole --script
 
konsole --script
Line 41: Line 42:
 
gnome-terminal -e 'screen -S blah'
 
gnome-terminal -e 'screen -S blah'
 
</pre>
 
</pre>
 
   
 
Please feel free to add more tips for integration with IPython below.
 
Please feel free to add more tips for integration with IPython below.
Line 51: Line 51:
   
 
" opens a new konsole window with ipython running in screen
 
" opens a new konsole window with ipython running in screen
com OpenIPython :!konsole -e screen -S ipython_vim ipython
+
com OpenIPython :!konsole -e screen -S ipython_vim ipython
 
</pre>
 
</pre>
   
 
==Windows==
 
==Windows==
Find <tt>ipythonrc.ini</tt> and in this file find this line:
+
Find <code>ipythonrc.ini</code> and in this file find this line:
 
<pre>
 
<pre>
 
editor 0
 
editor 0
Line 65: Line 65:
 
</pre>
 
</pre>
   
In <tt>ipythonrc.ini</tt> the hash symbol (#) means comments as in Python. Be aware that there are two <tt>ipythonrc.ini</tt> files: one in the installation directory, the other in C:\Documents and Settings\<UserName>; one needs to modify the file in <Documents and Settings> and '''not''' in the installation directory for the effects to take place.
+
In <code>ipythonrc.ini</code> the hash symbol (#) means comments as in Python. Be aware that there are two <code>ipythonrc.ini</code> files: one in the installation directory, the other in C:\Documents and Settings\<UserName>; one needs to modify the file in <Documents and Settings> and '''not''' in the installation directory for the effects to take place.
   
 
After doing these modifications, restart IPython and type:
 
After doing these modifications, restart IPython and type:
Line 86: Line 86:
 
c.TerminalInteractiveShell.editor = 'gvim -f'
 
c.TerminalInteractiveShell.editor = 'gvim -f'
 
</pre>
 
</pre>
Restart ipython, then <tt>%edit</tt> should work.
+
Restart ipython, then <code>%edit</code> should work.

Latest revision as of 07:54, 11 July 2012

Tip 1551 Printable Monobook Previous Next

created 2008 · complexity basic · author Srepmub · version 7.0


This tip is deprecated for the following reasons:

If you're using IPython 0.11 or newer, have a look at vim-ipython. It ships with ipython, provides bidirectional interface between vim and ipython, and works on all platforms.


IPython and Vim make for a great IDE. The following shortcuts can help to make it even better.

To also avoid having to enter a test command in IPython, I use konsole and dcop to send the command to IPython automatically. In the following, ' is mapped to run the command 'r' in IPython. First, start IPython as follows:

konsole --script
ipython

Next, add the following mapping to vimrc:

nnoremap ' :wa<CR>:!dcop konsole-`pidof konsole` session-1 sendSession r<CR><CR>

I wanted to make this work in gnome-terminal as well, but couldn't figure out how to do this with DBUS. So here's a nice trick to make it work in any terminal that supports the 'screen' utility. First, create a 'virtual' screen named 'blah':

screen -S blah
ipython

Now to send a command to the 'blah' screen:

nnoremap ' :wa<CR>:!screen -x blah -X stuff $'r\n'<CR><CR>

To start screen with gnome-terminal:

gnome-terminal -e 'screen -S blah'

Please feel free to add more tips for integration with IPython below.

I used the following script:

" maps ' to save and run the current buffer in the ipython session
nnoremap ' :wa<CR>:!screen -x ipython_vim -X stuff $'\%run "%:p"\n'<CR><CR>

" opens a new konsole window with ipython running in screen
com OpenIPython :!konsole -e screen -S ipython_vim ipython

Windows[]

Find ipythonrc.ini and in this file find this line:

editor 0

and change this line to this line:

editor gvim -f

In ipythonrc.ini the hash symbol (#) means comments as in Python. Be aware that there are two ipythonrc.ini files: one in the installation directory, the other in C:\Documents and Settings\<UserName>; one needs to modify the file in <Documents and Settings> and not in the installation directory for the effects to take place.

After doing these modifications, restart IPython and type:

%edit

and gvim will start.

Comments[]

I tried this on Windows, and when I type %edit in IPython it opens Notepad and not gvim.

It works with:

ipython profile create
# creates ipython_config.py in document and settings/username/.ipython
Then edit this file to replace
c.TerminalInteractiveShell.editor = 'notepad'
with
c.TerminalInteractiveShell.editor = 'gvim -f'

Restart ipython, then %edit should work.