# bash - returning from vim



## Wolfram (Nov 26, 2009)

Hello dear community,

I am new to BSD, have been moving from Linux to FreeBSD some months ago and since then I got some really nice experiences, but there are still some little problems, as one I have with bash (4.0).

In Linux, when I exit (e.g.) vim, it returns to the same shell prompt I had before starting vim, but in FreeBSD the output from vim remains after exit and returning to the prompt. I googled a lot about this case, but found nothing, so I would be very grateful if you could give me some useful hints.

With kind regards,
Wolf


----------



## DutchDaemon (Nov 26, 2009)

You just described my most annoying Linux experience ever  I hate information disappearing from my screen!


----------



## Wolfram (Nov 26, 2009)

Well, this is not really a "problem", but it would be anyhow nice to know how to handle it.


----------



## vorbote (Nov 26, 2009)

Wolf,

that means you have problems with your terminal emulation. Are you using an xterm or similar? Try forcing vim to send a refresh code qhen it quits. I don't remember off the top of my head all the vimcode but you'll have a start in the vim manual section on interacting with terminals.


----------



## vorbote (Nov 26, 2009)

Forgot to mention, you'll have to rebind your quit command to a function I'm afraid. I can't find an easy way to have vim execute a command on exit.


----------



## DutchDaemon (Nov 26, 2009)

It's not a 'problem' with terminal emulation, it's the default behavior on FreeBSD. The same will happen when you exit any other editor, or more/less, or screen.


----------



## Wolfram (Nov 26, 2009)

DutchDaemon said:
			
		

> It's not a 'problem' with terminal emulation, it's the default behavior on FreeBSD. The same will happen when you exit any other editor, or more/less, or screen.



That's it. But is it possible to set a linux-like behavior? 

Thank you anyway for your tips, vorbote.


----------



## vorbote (Nov 26, 2009)

Wolfram said:
			
		

> That's it. But is it possible to set a linux-like behavior?
> 
> Thank you anyway for your tips, vorbote.



You can always fix the termcap/terminfo definitions for your local account. Grab a copy of the termcap database, edit it and place it in your home directory as $HOME/.termcap. If it isn't loaded automatically, add a TERMCAP variable to your environment pointing to that file.

For terminfo entries, Thomas E. D1ckey keeps the master copy at his website.


----------



## DutchDaemon (Nov 27, 2009)

termcap(5)
terminfo(5)


----------



## Wolfram (Nov 27, 2009)

Thank you guys!

I tried a lot of things and variations (with te/ti in the .termcap file), but it still does not work.
What exactly has to be mentioned in $HOME/.termcap to achieve this feature?


----------



## crsd (Nov 27, 2009)

Rebuild editors/vim with -DWITH_XTERM_SAVE


----------



## Wolfram (Nov 28, 2009)

I got the solution!

The original xterm-section in /usr/share/misc/termcap should be like this:


```
xterm|xterm-color|X11 terminal emulator:\
       :ti@:te@:tc=xterm-xfree86:
```

replace (or comment out) it with this:


```
xterm|xterm-color|X11 terminal emulator:\
        :te=\E[2J\E[?47l\E8:ti=\E7\E[?47h::tc=xterm-xfree86:
```

After that rebuild the termcap-database (termcap.db) with:


```
cap_mkdb /usr/share/misc/termcap
```

That's it!


----------

