4

I'm aware I can do !commands but I'd like to somehow integrate a shell in vim. Or could I use screen and split the screen so that vim takes up say, half of the screen?

4 Answers 4

9

CtrlZ will suspend vim and return control to bash. Use fg to return to vim.

5

Integrating subprocesses is Vim's main weak point. There's no built-in support for a shell window, but you can try the vimsh plugin.

In Screen, press C-a c to create a new (full-screen) window. Press C-a p or C-a n to move to the previous/next window (C-a space also moves to the next window). Also the split command (C-a S) will split your screen into two regions; you can use one for a shell and one for Vim. Press C-a tab to switch between regions.

You can always press Ctrl+Z to suspend Vim and run commands in the parent shell; type fg to return to Vim. Or you can use :shell to create a (full-screen) subshell; type exit to return to Vim.

3

As you suggest, I would just use screen.

  • screen
  • ^A-c to create a new window
  • ^A-S to split the screen horizontally into two regions (some versions have Ctrl-| to split vertically)
  • ^A-Tab to move to the new region
  • ^A-n to change the region to the next window

If you don't want exactly half and half you can:

  • ^A-+ to increase the size of the current region

If you need to see what's in vim when you're on the command line, this is a good way to go. If you don't the Ctrl-Z/fg method already mentioned is the way to go.

2

You can also use :shell to just spawn a shell. Type exit or Ctrl+D to exit the shell and return to vim. If you want both running simultaneously, using fg/bg (per Ignacio), screen (as you suggested) or just two separate terminals (xterms, virtual consoles, whatever) are about your best options.

If you go to vim.org, you can probably find an extension which launches a shell directly, but you're getting dangerously close to emacs at that point. ;) Here's an example using screen: http://www.vim.org/scripts/script.php?script_id=2711

1
  • 1
    "you can probably find an extension which launches a shell directly, but you're getting dangerously close to emacs at that point". Stop that talk, you're scaring the children.
    – TTM
    Nov 12, 2010 at 23:45

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .