sponsor Vim development Vim logo Vim Book Ad

Screen (vim + gnu screen/tmux) : Simulate a split shell, using gnu screen or tmux, that you can send commands to.

 script karma  Rating 217/74, Downloaded by 12719  Comments, bugs, improvements  Vim wiki

created by
Eric Van Dewoestine
script type

This plugin aims to simulate an embedded shell in vim by allowing you to easily
convert your current vim session into one running in gnu screen (or tmux) with
a split gnu screen window containing a shell, and to quickly send statements /
code to whatever program is running in that shell (bash, python, irb, etc.).
Spawning the shell in your favorite terminal emulator is also supported for
gvim users or anyone else that just prefers an external shell.

Currently tested on Linux and Windows (win32 gvim and cygwin vim), but
should also work on any unix based platform where screen is supported
(OSX, BSD, Solaris, etc.).

Windows Users: Whether you are using gvim or not, you will need cygwin
installed with cygwin's bin directory in your windows PATH.

  :ScreenShell [cmd] - Starts a screen hosted shell performing the
    following steps depending on your environment.

    When running a console vim on a unix based OS (Linux, BSD, OSX):
      1. save a session file from your currently running vim instance
         (current tab only)
      2. start gnu screen with vim running in it
      3. load your saved session file
      4. create a lower gnu screen split window and start a shell, or if
         g:ScreenShellExternal is set, start an external terminal with
         screen running.
      5. if a command was supplied to :ScreenShell, run it in the new
         Ex. :ScreenShell ipython

      Note: If you are already in a gnu screen session, then only steps
            4 and 5 above will be run.

    When running gvim:
      1. start an external terminal with screen running.
      2. if a command was supplied to :ScreenShell, run it in the new
         Ex. :ScreenShell ipython

  :ScreenSend - Send the visual selection or the entire buffer contents to
    the running gnu screen shell window.

An example workflow may be:
  Open a python file to work on:
    $ vim something.py

  Decide you want to run all or pieces of the code in an interactive
  python shell:
    :ScreenShell python

  Send code from a vim buffer to the shell:

  Quit the screen session and return to your original vim session:

install details
1. Download the vimball (screen.vba) to any directory.
2. Open the file in vim ($ vim screen.vba)
3. Source the file (:so %)

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
screen.vba 1.5 2011-07-19 7.0 Eric Van Dewoestine - expose :ScreenQuit command for all cases where screen.vim is the owner of a region, window, session, or terminal.
- improved tmux pane handling for tmux 1.5 (backwards compatible for tmux 1.4).  Patch by Sung Pae
screen.vba 1.4 2011-04-02 7.0 Eric Van Dewoestine Fixes some tmux related focusing/hanging issues.
screen.vba 1.3 2010-11-04 7.0 Eric Van Dewoestine - added g:ScreenVersion var indicating the screen plugin version (requested by Jakson Alves de Aquino)
- added a setting which enables expansion of tabs to spaces before sending to the target app running in screen (suggested by Joe Bain)
- fixed focusing tmux pane when splitting vertically (thanks to Ben Boeckel)
- added option to force attaching to the currently focused screen region when attaching to an existing session.
screen.vba 1.2 2010-09-27 7.0 Eric Van Dewoestine - suppress screen message when sending text to it
- moved the bulk of the logic to an autoload script
- support for tmux 1.3 added (previous version of tmux no longer supported) (thanks to Ben Boeckel)
- update ScreenShellAttach for newer screen listings (thanks to benbooth5)
- other enhancements + bug fixes
screen.vba 1.1 2010-01-25 7.0 Eric Van Dewoestine - fixed to handle non screen TERM env var better
- added support for vertically split screen/tmux regions (suggested by Hemant Borole)
- added setting to specify whether vim or the shell gain focus when first opening a split region (suggested by Sung Pae)
screen.vba 1.0 2009-12-03 7.0 Eric Van Dewoestine - added support for using tmux instead of gnu screen
- now distributing as a vimball with a help file (:h screen)
screen.vim 0.8 2009-10-12 7.0 Eric Van Dewoestine Added a global funcref allowing other plugins to send strings to the running screen session (based on suggestion by Jakson Alves de Aquino)
screen.vim 0.7 2009-09-08 7.0 Eric Van Dewoestine - fixed grabbing of partial visual selection on one line for sending
- now suppresses vim's reload prompt when returning to your original vim session, and auto reloads the modified files for you.
screen.vim 0.6 2009-08-26 7.0 Eric Van Dewoestine - fixed running :ScreenShell when vim is already in a screen session.
- fixed starting screen in an external terminal on Windows.
- fixed executing of command supplied to :ScreenShell when using an external shell (thanks to Tobais Wolf for reporting this issue).
screen.vim 0.5 2009-08-24 7.0 Eric Van Dewoestine - gvim (windows, linux, etc.) now supported by forcing usage of an external terminal
- multiple vim instances running independent screen shells now supported
- when using an external terminal from a console vim, only restart vim in a screen session if g:ScreenShellServername is set and clientserver is supported.
- ability to attach to an existing screen session.
screen.vim 0.4 2009-08-12 7.0 Eric Van Dewoestine - fixed usage in cygwin, which the previous version broke
- fixed handling of large amounts of text sent through :ScreenSend (thanks to Tobias Wolf for discovering the issue)
screen.vim 0.3 2009-08-10 7.0 Eric Van Dewoestine - Improved error handling running :ScreenShell when not all buffers can be saved.
Several enhancements based on suggestions by Tobias Wolf.
- Added support for spawning a terminal instead of using a split region for the shell.
- The vim instance started in screen now has its server name set, permitting remote calls.
- The shell screen window title is now based on the command supplied to :ScreenShell, if any.
- Other minor improvements behind the scenes.
screen.vim 0.2 2009-08-04 7.0 Eric Van Dewoestine Replaced control characters with the vim escape sequence equivalents.
screen.vim 0.1 2009-07-11 7.0 Eric Van Dewoestine 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.