6

vim has a number of ways to execute shell commands from within vim. One can jump to the shell and back to vim using shell, ctrl+z the current process and get back using fg. Selected/Current lines can be executed using !w bash.

However, all these approaches are helpful only for running one command. Once the command executes, the shell is process is killed.

I wanted to know if there is a way to keep executing snippets of code in the shell and have the shell remember functions/variables from the previous command (similar to copying snippets of code to a shell prompt) to debug code. For this the shell session would have to be persisted somehow.

I often run into cases where I need to execute a few functions on the shell and then test them out by calling them. The standard approach would be to copy paste them in a different shell and then execute them. How to do this from within vim?

Qantas 94 Heavy
  • 15,750
  • 31
  • 68
  • 83
nutsiepully
  • 1,066
  • 3
  • 14
  • 21
  • 2
    try vimshell plugin, https://github.com/Shougo/vimshell.vim – henices Mar 11 '14 at 07:35
  • 1
    Another approach is to use a terminal multiplexer like `tmux` or `screen` to allow a "split" terminal window with `vim` in one half and a shell session in the other. – chepner Mar 11 '14 at 12:02

2 Answers2

1

If your Vim was build with Python support (most Unix builds are, Windows / Cygwin builds are not), you might want to have a look at the Conque Shell plugin, which allows to run a shell inside a Vim buffer.

Edit: Correction, apparently Vim 7.3 for Windows now also comes with Python support (and thus, Conque compatibility).

DevSolar
  • 67,862
  • 21
  • 134
  • 209
  • I was also looking for something like that. Would you help me with the set up this with Gvim ? – Arup Rakshit Mar 11 '14 at 14:37
  • @ArupRakshit: I don't use it myself, I just remembered the link. The installation instructions seem to be pretty straightforward. If you encounter problems, just post a question on SuperUser. I'm sure you'll get help. ;-) – DevSolar Mar 11 '14 at 15:20
0

You could start vim (not gvim) from a shell, then use <C-Z> to suspend vim. You return to the calling shell (not a sub-shell) and resume vim with fg. According to the docs, this works "On many Unix systems".

:help suspend
benjifisher
  • 5,054
  • 16
  • 18