sponsor Vim development Vim logo Vim Book Ad

vimsh.tar.gz : terminal/shell buffer script for python enabled [g]vim

 script karma  Rating 251/93, Downloaded by 10202    Comments, bugs, improvements  Vim wiki

created by
brian sturk
script type
A terminal/shell buffer script for python enabled [g]vim (+python).  Allows execution of shell commands in a vim buffer.
It does not use r! <cmd>.  

Some of it's features:

* It retains state because it's interactive.  Set an environment variable and it "stays" because the shell process is the same through the whole session.
* It can run interactive line based programs like ftp/telnet/python/ssh/etc including masked password input (pty supported platform only).
* Since it's a vim buffer you can go into normal mode and move around the buffer, yank, paste, use word completion, etc.
* Runs on Linux, OS X, Windows, and other UNIX platforms.  Primary development and testing is done on Linux.  Windows has limitations (no interactive programs or Ctrl-C) due to lack of pty support.
To use it you must have a python enabled [g]vim and run on a platform that supports pty (i.e. Linux, OS X),
or pipes (Windows). The pty version has much better formatted output than the pipes
version and supports running interactive programs.  Please read the README for other installation
and configuration details.  Tested on vim 6.0/7.x using Slackware, Ubuntu, and Gentoo Linux, FreeBSD, Mac OS X, and Windows XP/Vista.  

I'd also like to hear from users running other operating systems, i.e. QNX/Solaris/other BSDs.

!!!!! WINDOWS USERS !!!!!, there is a zip file available at the below link. The version
kept here on vimonline is a tarred, gzipped file ( tar.gz ). If you are going to use
Winzip with the .tar.gz file be sure to turn off the "Tar file smart CR/LF handling". It doesn't work

Please send me bug reports and suggestions if you use it.  I appreciate all the patches
I've been getting lately!



See "terminal buffer" for more information.  There is also a (old) screenshot
of it running on Slackware Linux and Vim 6.0.
install details
run via:
:source vimsh.vim

rate this script Life Changing Helpful Unfulfilling 
script versions (upload new version)

Click on the package to download.

package script version date Vim version user release notes
vimsh.tar.gz 0.22 2012-11-15 6.0 brian sturk * Fixed reverse logic for sending EOF.
* Fixed logic bug w/ setting IGNBRK.
* Added new keymaping for 'Enter' in normal mode.  This also pages output ala F5 does by default.
* Added <silent> to all mappings to surpress echo'ing of execution of map in ex window.
* Changed tabstop to 8 which seems to be the default for bash.
* Cleaned up Win32 ^M handling.
* Correctly handle output from programs ending with multiple ^M.  On Windows > 1 is ignored, pty all are honored.
* Fixed the handling of the sometimes echo'ed executed command on Win32.
* Workaround warning now shows actual mapped keys for page_output and new_prompt.
vimsh.tar.gz 0.21 2010-02-13 6.0 brian sturk Back from the dead.  Windows is working again, and a few bugs fixed.
vimsh.tar .20 2004-03-26 6.0 brian sturk This version has gone through more testing now that I am using Linux all day @ work on my desktop.  I also did some decent testing on Windows.  Please let me know if you find any bugs...


* Leading space in output issue now works 100%, even when doing
  wacky stuff like 'sleep 10', then 'ls', without waiting for the prompt to return.
* Typing 'exit' now works as expected when running ssh, telnet,
  etc.  This fix also doesn't need the procs_in_pty hack I had previously used.
* exit'ing the initially spawned shell correctly deletes the buffer.
* Fixed race conditions w/ SIGCHLD (async) setting flag and bdelete
  path not always seeing flag toggle.
* Fixed bug where exiting vimsh buffer kept vim in insert mode.
* Ctrl-D (EOF) now closes buffer only when sent to initial spawned shell.
* Fixed bug on Windows (pipes) for multiple line command or leading space in command.
vimsh.tar.gz 0.19 2004-03-20 6.0 brian sturk * Fixed clear_screen call.
* Changed default mapping for clearing screen to ^L.
* Preserve mode (insert/normal) when clearing screen.
* Fix leading space in output when paging commands like ping(8).
* Added some tips for [t]csh users to the readme.
vimsh.tar.gz 0.18 2004-01-31 6.0 brian sturk * Use waitpid rather than wait, now correctly handles :!cmd <mbays@sdf.lonestar.org>
* Run pyfile command once when sourcing vimsh.vim <mbays@sdf.lonestar.org>
* Handle programs that do not have a prompt <mbays@sdf.lonestar.org>
* Moved invocation of startup shell in vimsh.vim to outside of pyfile sourcing conditional.
* Fixed case where buffer deleted through autocommand and same
  buffer name used again would cause an error (multiple buf fix).
* Fixed multiple au BufDelete commands being invoked for same vimsh buffer name
  (multiple buf fix).
* Fixed password regex for ssh, now handles leading spaces if present within vimsh.
vimsh.tar.gz 0.17 2003-11-29 6.0 brian sturk * Multiple buffer support <ddarius@hotpop.com>.
  i.e. :VimShNewBuf foo
* Default behavior of creating a single vimsh buffer
  when sourced added to multiple buffer patch.
* Multi-line command support <ddarius@hotpop.com>
* made a clear screen routine honoring g:vimsh_clear_all
* clear screen key mapping g:vimsh_clear_key (default F9) <ddarius@hotpop.com>
* use startinsert! <ddarius@hotpop.com>
vimsh.tar.gz 0.16 2003-09-19 6.0 brian sturk * Changed '^M' to '\n' for python 2.3.  Vimsh would not
  run w/ python 2.3. Backwards compatible change.
vimsh.tar.gz 0.15 2002-09-30 6.0 brian sturk Too many changes/bugfixes to list here, please see changelog for this version.
vimsh.tar.gz 0.14 2002-05-09 6.0 brian sturk * Changed name of buffer name from vimsh to _vimsh_ since this
  script is usually placed in a directory called vimsh.
  If vimsh was a directory in vim's cwd it would edit
  the directory using the explorer plugin.
* Fixed procs_in_pty to return full name of command last executed.
* Fixed not going back to insert mode after changing timeout.
* Added current timeout to timeout prompt.
* Correctly handle bogus entered timeout values, like 'ls'.
* Added support routine to return the current mode.
* Added a support routine to determine if last command
  executed is still running.
vimsh.tar.gz 0.13 2002-04-10 6.0 brian sturk * Figured out the line break always creeping in to
  files for some users.  Winzip has feature under
  called "Tar file smart CF/LF conversion".  
  It's not so smart... Turn it off if you want
  to unpack the tarball using Winzip.  Better yet
use the vimsh.zip file available at my website.
* Fixed 'exit' of shell killing entire vim session rather
than just the vimsh buffer.
* Fixed empty line being added after paging output (F5)
* Now check for password prompt when paging slow output(F5).
* Cleanup of filename handling
* Removed some un-needed ';' characters at the end of
lines ( this is what happens when you do C all day )
* Removed duplicate sending of EOF in send_eof.
* Fixed pty/# of proc detection
vimsh.tar.gz 0.12 2002-04-04 6.0 brian sturk * Fix for Solaris pty detection.
* EOF and SIGINT now query termios settings so
  the 'right thing' happens.  Users can still map
  whatever vim key sequence they want for these
  operations.  Support for more of these coming
  in future versions.
* Removed now unused vimsh.signal function.
* Output of slower commands after refresh give
  better but still not perfect output.
* For pty, SIGINT now flushes remaining data which will
  work for some commands, i.e. ping.  Some apps still
  will not flush correctly, find(1) for example.
* Added a help message for SIGINT handler which can be
  disabled by setting vimsh_show_workaround_msgs
  to 0 in your .vimrc.  It just explains how to get
  around not seeing the prompt for commands that don't
  flush correctly after SIGINT.
* Go back to insert mode after paging output.
* Fixes and speed ups for Windows
      - BufWipeout wasn't being hit so lots of cmd.exe
        instances being left around, changed to
wasn't being removed from end of lines that
        had it, i.e. ping.exe.
      - Buffer size for reading from pipe has been
        optimized somewhat.
      - Return to insert mode after trying to execute
        unsupported command.
      - Changed redraw frequency for better interactive
vimsh.tar.gz 0.11 2002-03-08 6.0 brian sturk * Added support for sending EOF. Default
   mapping is Ctrl-D <C-d>.  Now you can run python
   for example in a buffer and quit it by typing
* Fixed snafu of line split in the middle of python
   statement which kept script from loading.  WHOOPS.
* Made the signalling mechanism more generic so I can
   add more handlers in the future.
vimsh.tar.gz .10 2001-12-21 6.0 brian sturk * !! NOTE !!: new way to run is to "source" vimsh.vim, see vimsh.readme in tarball
   Windows users need to use the link in the description to get a .zip file.
* /bin/sh is symlinked to csh on *bsd, added csh prompt.
* Fixed mappings
* Added check for buffer's existence before writing prompt
  and jump to prompt if it already exists.
* Ctrl-c ( SIGINT ) for interrupting continuous cmds, prompts
  if multiple processes besides shell running.
* Cleaned up exit handling
* Added function and mapping for refreshing/paging
  output when timeout is too short.
* Added vim function to redraw periodically during long
  operations or continuous operations ( ie ping <host> or
  find /.
vimsh.tar.gz 0.9 2001-12-13 6.0 brian sturk Set buftype=nofile <b.cerrina@wanadoo.fr>
Option to use current buffer if non-modified
Use vim variables for options so this file doesn't need
to be modified to allow customization.  See script for info.
Handle cancelling of input dialogs
Flag unsupported windows console commands
( partial list see:unsupp_regex )
See NOTE for this version in script for more Windows specific information.
vimsh.tar.gz 0.8 2001-12-11 6.0 brian sturk - Windows support, tested on NT4 w/ ActiveState Python 2.2
    Should also work on 2K/XP. Caveat hacktor  :).  Non interactive
    programs dir, findstr, attrib etc work fine, no ftp, telnet, etc yet.
- Made clear check more explicit, cleartool was triggering it
- Fixed the mysterious missing single char issue.

I'm getting some good feedback from Windows users, are there any Unix
vim people using it?
vimsh.tar.gz 0.7 2001-12-09 6.0 brian sturk Made import/usage of tty, pty conditional on not being windows
Removed popen buffer size
Increased timeout if using popen3
Fixed output for lines crossing consecutive reads for pty
Added map for starting a new prompt at bottom of buffer
vimsh.tar.gz 0.6 2001-12-08 6.0 brian sturk NOTE: the python module select doesn't seem to be available except for sockets on Windows so I need to investigate this more
- Removed the <Delete><BS> hooks.  They just weren't working as I thought they would.  Now just check for cursor to not be in prompt.
- Figured out the ftp issue see "notes".
- Added a mapping & func to set timeouts.
- Changed pty prompt to something useful
- fixed clear
vimsh.tar.gz 0.5 2001-12-07 6.0 brian sturk Implemented secure input of passwords,
Exit cmd works as expected, for subprocesses it
exits to parent, initial shell exit will delete buffer,
Keep <Delete> from overwriting prompt
vimsh.tar.gz 0.4a 2001-12-07 6.0 brian sturk implemented alternate subprocess control ( popen ) so it should *in theory* work on any platform that supports
pipes, i.e. WinXX, albiet the output isn't as pretty-formatted as with pty.  I cannot at the moment test on Windows
and would like some feedback.  Shell commands clear and exit are also implemented.
vimsh.tar.gz 0.3a 2001-12-06 6.0 brian sturk Fixed up the 1st line issue, and ^M printing.  The script is starting to firm up so I'm
going to next try to get it to work on windows.  Please send any feedback/issues not listed
in the script.
vimsh.tar.gz 0.2a 2001-12-05 6.0 brian sturk Fixed tabwidth, not on prompt message, handling of user input execution rm -i works, and shells now die via autocommand
vimsh.tar.gz 0.1a 2001-12-04 6.0 brian sturk Initial upload
ip used for rating:

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to the maillist. Help Bram help Uganda.
SourceForge.net Logo