Question: 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](http://wiki.bash-hackers.org/scripting/terminalcodes), under the heading *Save/restore screen*.

Answer: 
Ok, so I've figured out how I can do this with Gary Johnson's help on the [Google Groups vim\_use](https://groups.google.com/forum/#!topic/vim_use/5ZgILsZkIuc) group. He helped by stating how to run the `tput` commands from vim. Here is my final solution:

1. Have the following function script in vim memory:

```
function! ShowTerm()
    call system(">/dev/tty tput rmcup")
    call input("")
    call system(">/dev/tty tput smcup")
    redraw!
endfunction

```
2. Map the script to some command key sequence like this:

```
map [= :call ShowTerm()<CR>

```

I used the sequence `[=`, but you can use whatever you want.

Now type the *key sequence* and you get the other screen. Press *Enter* and you're back to the vim screen. The Enter doesn't add a line feed to the terminal screen either, so no marching lines.

Nice! :) Note that this probably isn't the way it was done 15-20 years ago, but it works.

EDIT
====

In order not to be dependent on `tput` being available, I've found that the following that @MarkPlotnick inferred works just as well. Just replace the function `ShowTerm()` above with:

```
function! ShowTerm()
    silent !read -sN 1
    redraw!
endfunction

```

This depends on `bash` being used as the shell (or others that have a similar read call).

2nd Edit
========

Further, you can have this automated by putting a `.vim` file into your ~/.vim/plugins folder that contains the following:

```
" Function that allows viewing command line display last time it was seen.
" Note: Will only work on terminals that allow saving/restoring the display.
function! ShowTerm()
    " This will invoke the command shell and call the read function.
    " Will exit when a key is pressed.  This is specific to bash and
    " and may have to be changed if using a different shell.
    silent !read -sN 1
    redraw!
endfunction

" Maps [= sequence to view command line display last time it was seen.
map [= :call ShowTerm()<CR>

```
`Ctrl`+`w`+`w` can be used to switch between split panes in vim also works with terminal split.