Every time I use vim within sudo and Konsole, the coloring seems to switch to bright backgrounds, but without a white background. Or else some kind of alternative coloring. NOTE that it still uses the same color scheme, but instead of cyan it uses blue, and so on.
This puzzles me because everything else works as is intended for. Editing with su or with my own user works normally (in Konsole). Xterm and the Virtual Consoles out of the X sessions displays proper colors even with sudo.
Also, this only seems to affect vim, within konsole and with sudo. Tryed to rum some color table script, and it renders properly in any case.
By digging this up, I found that If I switch the TERM variable from xterm to linux, vim within sudo and konsole will render the correct colors.
As the say, a single picture equals a million words:
$sudo env | grep TERM TERM=xterm $TERM=linux $sudo env | grep TERM TERM=linux
This is getting somewhat distant to konsole itself, and many of my own information are dubious or misleading.
So, let's start this again. There is something strange by the way Konsole (or something else) handles which color to use. Let's for now, forget about sudo too.
It seems that the color pallete is divided into two parts, the intense colors and the normal ones. From what I am seeing now, the TERM can instruct applications to use one or another "set" of colors.
If I'm right, TERM=xterm is inteded for the normal colors, and TERM=linux is suposed to indicate Intense colors.
As vim is the only program that is consistently keeping track of this input, I will do my "benchmark" with it.
Gnome-terminal: TERM=xterm vim uses the normal colors TERM=linux vim uses the intense colors
Xterm: TERM=xterm vim uses the normal colors TERM=linux vim uses the intense colors
Framebuffer Terminal: TERM=xterm vim uses the normal colors TERM=linux vim uses the intese colors
Up to this point everything is consistent
Konsole: TERM=xterm vim uses the intense colors TERM=linux vim uses the intense colors
Konsole with bright theme/background + restart: TERM=xterm vim uses the normal colors TERM=linux vim uses the intense colors
Konsole changed back to dark theme,but WITHOUT restart: TERM=xterm vim uses the normal colors TERM=linux vim uses the intense colors
What puzzles me is that, this may not be a bug at all. I like the intense colors (mainly because I use dark backgrounds) and this could be some nice hack or something else built into the terminal emulator.
Now... what I don't like is that this comes with some quirks (as seem in the "benchmark") and konsole + sudo won't somehow propagate it (which is the whole point of this topic!)
I would appreciate if you all could verify this kind of behaviour. In the end this could be a bug.
I cannot reproduce your "bug" in my Kubuntu9.10+KDE4.3 and Arch+KDE4.3. (Arch by default clears the environment, Kubuntu don't, which is more a distribution-specific issue than the KDE issue)
I always get the so called "intense" colors. If all you want is to use vim. then I've got some suggestions:
1. try set background=dark then set t_Co=8 or t_Co=16 or t_Co=256 in your ~/.vimrc, which should work for most cases. i.e. If you had hard-coded your background and t_Co (try 3 color options and one of them should work) in your .vimrc then there won't be any further problem. (just make sure sudo uses the same .vimrc)
2. try use sudo -e foobar instead of sudo vi foobar, the previous version uses the normal user to edit the file.