[vimshell] vimshell + screen = never ending shell

Rybarczyk Tomasz paluho at gmail.com
Tue Jun 10 13:44:07 CEST 2008


Hi all,

I've written simple script for operating on many vimshells in vim.
It's written in Python so it requires vim compiled with
--enable-pythoninterp (you can check easily  if you have it by calling
 :python print "foo" ).

Problem:
This script gives some solution (by using screen) for two problems
which I've encounter during my adventure with vimshell:
- it's impossible (or maybe I just don't know the way) to prevent
vimshell buffer from deletion after window with it is closed.
- there is lack of scrolling in vimshell.

Solution:

Test it at first:
Copy bash.vim and bash.py to ~/.vim/plugin (I've attached them to this
mail). Run vim and type:
\sn 	- opens (creates) new shell (with lowest aviable number)
run some command for example: ps
\s2	- opens (creates) new shell (with number 2)
run other command for example: ls

Close <C-W>c those two vimshells windows. Type:
\sh 	- opens (default) shell (you should see shell 0 again)
\s2	- open again shell 2

You should see terminals which you have spawned before.

Of course this is one way of mapping and using this script (my
mappings are added in bash.vim).

Attention:
There are some hardcoded paths in bash.vim change them if you need.

If you want to really close some shell you should finish it explicitly
(in bash for example by running exit or <C-D>).
When you close vim all processes (and screen daemons) should be killed
too. There is only danger situation when vim is terminated  in non
proper way. Then you should kill processes and run 'screen -wipe' by
hand.


Explanations:
Everything is done with use of screen program.
This script allows to open vimshell with some process, close window
(with <C-W>c) and open vimshell again with those process. It bases on
screen daemons shells (check screen --help and -dmS and -x options).
Addtionally it allows to have numbered shells. Because every shell
runs in screen terminal you can easily scroll it with (<C-[>a) if you
have started vim in shell without screen ;-P ---> I mean no nested
screens.

There is only one function which is important for user:
:python bash.run_bash(number=None)
this function splits window, runs vimshell with screen and bash inside
it. Parameter number tells which shell should be chosen. If there is
no number given function creates new bash with lowest number which is
not in use. Unfortunately there is kind of shell hardcoded in script
so if you want to use other shell then bash you should change path to
binary in bash.py.

I've also attached my two files as an example: ipython.py and
python.vim. Put them in ~/.vim/ftplugin they sets shortcuts like
previous scripts but they uses 'p' in place of 's' for example: \pn
\p1 \pn, for running ipython shell.


Additions:
I reverted one change in vimshell. In my Vim I can run vimshellac
(after closing shell process window is automatically closed too). I
can send them in next mail if someone is interested.

TODO:
This script should be rewritten so it can take path to binary as a parameter.
Everything should be rewritten in vim scripting language...
							    but there is so nice weather out there ;-P.

Best regards
paluh
-------------- next part --------------
A non-text attachment was scrubbed...
Name: bash.vim
Type: application/octetstream
Size: 500 bytes
Desc: not available
Url : http://www.wogri.at/pipermail/vimshell/attachments/20080610/3d063d51/attachment.bin 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: bash.py
Type: text/x-python
Size: 2199 bytes
Desc: not available
Url : http://www.wogri.at/pipermail/vimshell/attachments/20080610/3d063d51/attachment.py 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: python.vim
Type: application/octetstream
Size: 918 bytes
Desc: not available
Url : http://www.wogri.at/pipermail/vimshell/attachments/20080610/3d063d51/attachment-0001.bin 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: ipython.py
Type: text/x-python
Size: 2216 bytes
Desc: not available
Url : http://www.wogri.at/pipermail/vimshell/attachments/20080610/3d063d51/attachment-0001.py 


More information about the vimshell mailing list