Bash – How to toggle between vim buffer and command shell screen in vim

bashrcvim

I find it annoying to constantly press Ctrl-Z and then fg to go between these screens (where command terminal is the command line that you used to invoke vim from). It also generates unwanted fg lines on my console. I'm pretty sure this can be done as I remember doing it when I was in university, but I can't remember how.

Information on Terminals and its Relation to vim

vt100 terminal and others have a way to save the screen prior to changing it and then it could restore it when it wants to. vim does this and can be seen if you go into vim and then shell or Ctrl-Z out. Most of the time it will show you what you had on the screen prior to entering vim by saving the screen prior to painting the vim screen. If your terminal doesn't support this functionality, it will just put the command line directly under the vim screen, scrolling it up. This can be seen by exporting to the TERM variable a less functional terminal emulation or clearing it (though by clearing it, it may put vim into line mode or may use the most basic of terminal codes depending on its implementation). To see more on saving/restoring a screen, see Terminal codes (ANSI/VT100) introduction, under the heading Save/restore screen.

Best Answer

Starting gvim opens a new window, so the terminal window stays available for commands. For intermediate "shell escapes" I do :sh to get access to a shell session, and type <Ctrl>-D to exit it; no fg is needed, but a prompt is added in this case to the console shell. And with no X running I start two consoles, one where vim is running, and the other where the shell is running, and I switch consoles by (in my case) e.g. <Ctrl>-<Alt>-<F1>. (Depending on the actual needs, one of those options should fit; I hope.)

Related Question