Vim background with gnu screen
[filling in for the OP, see the comment]
The OP found the issue:
I needed to have this set:
defbce "on"
This forces background colours to refresh.
"Change background-color-erase setting. If
bce
is set to “on”, all characters cleared by an erase/insert/scroll/clear operation will be displayed in the current background color. Otherwise the default background color is used."
– Ravi 19 hours ago
Why is the default vim's background option is differrent when run in gnome-terminal and gnu-screen?
vim's using an escape sequence from xterm's repertoire to ask what the background color is, which you can see in the block in term.c
beginning with the comment
/* Check for background color response from the terminal:
*
* {lead}11;rgb:{rrrr}/{gggg}/{bbbb}{tail}
*
* {lead} can be <Esc>] or OSC
* {tail} can be '\007', <Esc>\ or STERM.
culminating in some code (which I'd recommend rewriting...):
{/* TODO: don't set option when already the right value */
LOG_TR("Received RBG");
rbg_status = RBG_GOT;
set_option_value((char_u *)"bg", 0L, (char_u *)(
(3 * '6' < tp[j+7] + tp[j+12] + tp[j+17])
? "light" : "dark"), 0);
which was added in mid-2015:
commit b5c3265521749fda81ae4b052de35a0d1209cf50
Author: Bram Moolenaar <Bram@vim.org>
Date: Thu Jun 25 17:03:36 2015 +0200
patch 7.4.757
Problem: Cannot detect the background color of a terminal.
Solution: Add T_RBG to request the background color if possible. (Lubomir
Rintel)
xterm patch #94 (March 1999) added the control sequence for querying colors:
extend dynamic colors control sequences to allow users to determine the colors and font which are currently active.
VTE's developers copied the feature early in 2014 (see #567444).
But GNU screen doesn't recognize the sequence (or its response), so it doesn't allow it to pass through.
By the way, there's more than one way that vim could have done this. I checked to see which method it used with strace
.
Running Vim in GNU Screen: How to avoid Shift+left/right to delete characters
You may need to run screen
with a different TERM
, such as xterm
, e.g.
$ screen -T xterm
...
Strange behavior of vim color inside screen with 256 colors
Short Answer
Set TERM
to xterm-256color
in your .bashrc
, and put term screen-256color
in your .screenrc
.
Long Answer
Here's why this breaks: gnome-terminal, screen, tmux, bash, putty and vim have all been written to intelligently handle 256 colors, but you need to set things up correctly at the earliest possible point. Using termcapinfo
in your .screenrc
is actually a duct tape solution!
If your TERM
is set correctly, it will signal to bash that you're in 256-color mode, which means it will play nice with screen being in 256-color mode as well.
So, in your .bashrc
, export TERM=xterm-256color
. [1]
In your .screenrc
, use screen-256color
for TERM
instead of xterm-256color
, and delete the rest of the cruft!
In your PuTTy configuration, use putty-256color
.
You can download the termcap entry files and put them in ~/.terminfo/s
and ~/.terminfo/p
, if your box doesn't have them by default.
Footnotes
[1] Setting TERM
to xterm-256color
in your .bashrc
can be a little presumptuous, especially if you use the same .bashrc
on multiple machines. I have found the following snippet to be fairly effective:
case "$TERM" in
*-256color)
alias ssh='TERM=${TERM%-256color} ssh'
;;
*)
POTENTIAL_TERM=${TERM}-256color
POTENTIAL_TERMINFO=${TERM:0:1}/$POTENTIAL_TERM
# better to check $(toe -a | awk '{print $1}') maybe?
BOX_TERMINFO_DIR=/usr/share/terminfo
[[ -f $BOX_TERMINFO_DIR/$POTENTIAL_TERMINFO ]] && \
export TERM=$POTENTIAL_TERM
HOME_TERMINFO_DIR=$HOME/.terminfo
[[ -f $HOME_TERMINFO_DIR/$POTENTIAL_TERMINFO ]] && \
export TERM=$POTENTIAL_TERM
;;
esac
The alias
of ssh is a defensive measure to prevent us from trying to open a 256-color terminal on a remote machine that doesn't necessarily support it. The main block is the other half of the equation; it checks to see if the corresponding terminfo entry exists, and sets it if it does.
set GNU screen background color
This doesn't change the background color, but I have a screenrc file which will put a status line at the bottom which makes it obvious when you're in screen:
As a gist: https://gist.github.com/cwacek/5724875
# Turn off that annoying start up message
startup_message off
# Turn the even more annoying whole-screen-flash-on-tab-complete "feature"
vbell off
terminfo xterm-color hs@:cs=\E[%i%p1%d;%p2%dr:im=\E[4h:ei=\E[4l
term xterm-color
# Window list at the bottom. hostname, centered tabs and redmarked active windows:
hardstatus alwayslastline
hardstatus string '%{= kG}[ %{G}%H %{g}][%= %{= kw}%?%-Lw%?%{r}(%{W}%n*%f%t%?(%u)%?%{r})%{w}%?%+Lw%?%?%= %{g}][%{B} %d/%m %{W}%c %{g}]'
Related Topics
Decrypt Obfuscated Perl Script
Automated Test Tools for Linux/Ncurses
Linux - Without Hardware Soundcard, Capture Audio Playback, and Record It to File
How to Set Cronjob with Non-Root User
Zsh Menu Completion Causes Problems After Zle Reset-Prompt
Populate a Ms Access Database in Linux
Printing Current Time in Milliseconds or Nanoseconds with Printf Builtin
"Stdin: Is Not a Tty" from Cronjob
Cross Compile from Linux to Arm-Elf (Arm926Ej-S/Mt7108)
Awk and Special Brackets Delimiters
How to Prevent a Linux User Space Pthread Yielding in Critical Code
Detecting Command Not Found in Bash Script
How to Execve a Process, Retaining Capabilities in Spite of Missing Filesystem-Based Capabilities