|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.
or map to a key, something like this
nmap <leader>sh :runtime after/usr/macros/vimsh/vimsh.vim<CR>
Click on the package to download.
||* 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.
||Back from the dead. Windows is working again, and a few bugs fixed.
||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.
||* 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.
||* Use waitpid rather than wait, now correctly handles :!cmd <email@example.com>
* Run pyfile command once when sourcing vimsh.vim <firstname.lastname@example.org>
* Handle programs that do not have a prompt <email@example.com>
* 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.
||* Multiple buffer support <firstname.lastname@example.org>.
i.e. :VimShNewBuf foo
* Default behavior of creating a single vimsh buffer
when sourced added to multiple buffer patch.
* Multi-line command support <email@example.com>
* made a clear screen routine honoring g:vimsh_clear_all
* clear screen key mapping g:vimsh_clear_key (default F9) <firstname.lastname@example.org>
* use startinsert! <email@example.com>
||* Changed '^M' to '\n' for python 2.3. Vimsh would not
run w/ python 2.3. Backwards compatible change.
||Too many changes/bugfixes to list here, please see changelog for this version.
||* 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.
||* 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
||* 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
- Return to insert mode after trying to execute
- Changed redraw frequency for better interactive
||* 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.
||* !! 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
||Set buftype=nofile <firstname.lastname@example.org>
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.
||- 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?
||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
||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
||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
||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.
||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.
||Fixed tabwidth, not on prompt message, handling of user input execution rm -i works, and shells now die via autocommand