views:

166

answers:

5

I'm slowing getting to know Vim and Bash shell scripting and am running into this issue:

When I'm running MacVim, I sometimes want to use the command line to compile whatever it is I'm working on (in this case a small Java program). So I type :! bash and compile whatever it is that I need and test it. Then when I want to go back to the program I was editing I type vim MyProgram.java and get all kinds of messyness in my Vim session like [8;1H~ [9:1H~ [10:1H~ ... etc.

What am I doing wrong here? Can I not jump back into Vim once I've started running the shell inside of it?

Are there better ways of compiling and running your current file?

(I'm using MacVim 7.2 and Bash 3.2.48 on OSX 10.6.2.)

+4  A: 

just type:

exit

This will exit the bash sub-process and return to vim. It would be better to use something like GNU Screen to maintain a Vim and Bash session simultaneously (and it's easier to switch than :!bash...exit

Draemon
+1 for screen....
Greg Hewgill
+7  A: 

Two suggestions:

  1. Use exit to quit the bash shell and return to vim.
  2. Within vim, use :set makeprg=name_of_your_make_program to automatically compile from within vim with the :make command. As a bonus, if it's a toolset that vim recognizes, vim will parse the compiler's output, show you the errors, and allow you to jump to each of them so you can fix them. See the commands :cl, :cc, :cn, and :cp for starters.
Adam Liss
It's helpful to :map a couple of function keys to the :cn and :cp commands. Jumping back and forth is a lot faster that way.
Steve K
+1  A: 

Try typing exit or ctrl-d from within the bash shell. That will take you back into vim. Bash is running "inside" vim, so if you try and run vim again, you're running vim inside bash inside vim and hence the errors.

Tom
+1  A: 

You must exit the bash shell. This can be done via the exit command, or more simply, by pressing

ctrl^d

from an empty prompt.

brianegge
+1  A: 

The other answers are right.

I just want to mention that you can use

:sh

instead of

:!bash

See :help sh.

This way vim knows you are running a shell instead of just some command (which happens to be bash).

0x89