开发者

How to reenter Vim after :! bash?

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 J开发者_StackOverflow社区ava 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.)


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.


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


You must exit the bash shell. This can be done by the exit command, or more simply by pressing CTRL+D at the prompt.


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).


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.


If your in Mac OS, you'll probably have to type fg to return back to vim after executing a bash command. Others didn't work for me.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜