Shell in VIM

I’ve been looking for a good shell-in-vim solution. Emacs does it pretty well, but I’d rather stick with VIM since I’ve been using it as my primary editor for a while. The two solutions I’ve found so far are vimsh and vim-shell. I’ve gotten vimsh to do what I’d like to do., but there are some problems, discussed below, that prevent it from being an ideal solution.

Vimsh is the more convenient of the two because it will work with vim as long as it has python support compiled in. (The package vim-full in the Ubuntu repository has the python support compiled in. The standard package, vim-tiny, may also have the python support, but I’m not sure.) In order to use it, just download and unpackage the vimsh.tar and map a shortcut in your .vimrc

"activate vimsh
map ,sh :source /path/to/vimsh/vimsh.vim

This is the most basic call, causing the current buffer to split horizontally and open a shell in the top window. I use a slight variation of this shortcut to make sure that the shell is always opened at the bottom of the screen. Just append Ja to the last shortcut:


If you would like vim to open a python prompt, just add python:


To have it execute the python file you are currently editing and then remain in interactive shell mode afterwards, use the following (note that the post-execution interactive shell is only supported on python3):

map...vimsh.vimJapython3 -i #

If you would like to have the shell execute the python script, but not go into the interactive python shell afterwards, omit the “-i” from the above command. This is great for running unit test programs.

The major drawback to vimsh is that the commands listed above work only once. If you terminate the shell session and close the window so you are left with your original document (A state that seems to be identical to the state before we opened the shell) and try to execute the command again, it creates the shell terminal inside of the currently active window instead of splitting it like it did the first time. This issue might be resolved by changing some configuration options, but the application is not well documented. The documentation basically says “Look in the source file if you want to find out what the configuration options are”, something I’ll have to get around to eventually. Another issue with vimsh is that the shell has some display issues with more complex programs. This prevents the shell window from opening lynx, irssi and most other ncurses applications.

As for vim-shell, I haven’t tried it yet as it requires a recompilation of vim. I’ll make another post once I’ve found the time to get it working.

1 Comment

  1. Hi there,

    I’m the author of vimsh, thanks for trying it. The first thing you mention seems like a bug. I’ll try to reproduce it.

    As for lynx, etc. Only pure text (non-ncurses etc) based programs can run due to vim’s architecture. The vimshell patch you mentioned adds all that stuff to vim.

    take care,

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>