LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware
User Name
Password
Slackware This Forum is for the discussion of Slackware Linux.

Notices


Reply
  Search this Thread
Old 05-04-2011, 04:40 PM   #1
goldfinch
LQ Newbie
 
Registered: May 2011
Distribution: Slackware
Posts: 6

Rep: Reputation: 0
vim colours change slightly in xterm when a key is pressed


Hi,

I'm having a problem with vim and xterm.

When I open a file and press any key, the colour scheme changes slightly.

This doesn't happen if I run a 256-colour xterm (export TERM='xterm-256color') but if TERM is set to 'xterm' (the default) I see the colour change.

Setting TERM='xterm-256color' in my ~/.bashrc is a "solution", but I'd rather not have to do that since it's never been necessary in the past (e.g., on 13.1) and I don't use any 256-color schemes for vim (usually just the default or possibly "delek").

It doesn't happen with rxvt or with Xfce's terminal.

I've tried compiling some other versions of xterm but they either exhibit the same behaviour or don't build.

I have tried running without any ~/.vimrc file just to be sure it wasn't one of my settings and I've also tried the sample file at /usr/share/vim/vimrc; the effect is the same.


Can anyone else confirm this issue?

Is there a solution besides running a 256-colour xterm?

Thanks in advance for any help with this.
 
Old 05-04-2011, 08:36 PM   #2
elyk
Member
 
Registered: Jun 2004
Distribution: Slackware
Posts: 241

Rep: Reputation: 49
Yeah, I notice it here too. It's obnoxious. After looking at the escape codes it sends to the terminal, I'm blaming vim. (Hint: Run `script`, open vim and trigger the bug, then quit vim and `exit`. Look at the typescript file in a hex editor.)

On xterm it does this:

1. Draws the column of ~ in bold blue (escape code "\e[1m\e[34m")
2. Queries xterm for several items. I guess this is where it figures out that xterm can support more colors.
3. On the first keypress, redraws the column of ~ in a different shade of blue (escape code "\e[94m")

It doesn't even try step 2 with rxvt. Seems like step 2 should be before step 1.
 
1 members found this post helpful.
Old 05-05-2011, 09:25 PM   #3
goldfinch
LQ Newbie
 
Registered: May 2011
Distribution: Slackware
Posts: 6

Original Poster
Rep: Reputation: 0
Thanks for the information.

As a temporary workaround, I've added the following to my ~/.bashrc:

Code:
case "$TERM" in
xterm*)
    alias vim='vim -T xterm-256color'
    ;;
*)
    ;;
esac
I might build an updated vim package someday but it's not at the top of my list.
 
Old 05-05-2011, 11:59 PM   #4
elyk
Member
 
Registered: Jun 2004
Distribution: Slackware
Posts: 241

Rep: Reputation: 49
I'm trying the following workaround right now, no problems yet.

Add this to your ~/.Xresources:
Code:
XTerm*termName: xterm-256color
UXTerm*termName: xterm-256color
Then do an `xrdb -load ~/.Xresources` (restarting X should also work). `xrdb -query` will print those lines back to you if it worked.

Now if you start xterm it should set $TERM to xterm-256color, and now vim should work fine.

But... for some reason it doesn't set $TERM correctly. Appears that xterm checks for "xterm-256color" in termcap instead of the more modern terminfo, and since it's not there by default, it falls back to using "xterm". So I added xterm-256color after xterm-color in /etc/termcap like this. I don't know if it's correct, but it seems to work okay so far.
Code:
vs|xterm|xterm-color|xterm-256color|vs100|xterm terminal emulator (X Window System):\
 
Old 05-06-2011, 11:50 AM   #5
goldfinch
LQ Newbie
 
Registered: May 2011
Distribution: Slackware
Posts: 6

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by elyk View Post
So I added xterm-256color after xterm-color in /etc/termcap like this. I don't know if it's correct, but it seems to work okay so far.
Code:
vs|xterm|xterm-color|xterm-256color|vs100|xterm terminal emulator (X Window System):\
I made the same modification to /etc/termcap yesterday while I was experimenting with setting the TERM variable to xterm-256color. I'm not sure if it's correct, but I didn't notice any issues with it either.

In the end, I decided to go with the alias workaround I posted last night, TERM=xterm (default), and the original /etc/termcap. I'm still not sure which solution I prefer.

With regard to xrdb, I generally use -merge instead of -load, just to be on the safe side.
 
Old 05-07-2011, 07:31 PM   #6
rouvas
Member
 
Registered: Aug 2006
Location: Greece
Distribution: Slackware.12.2
Posts: 104
Blog Entries: 3

Rep: Reputation: 21
vim in xterm: cursor jumps over words in addition to colour changes

In my case colour changing behaviour is accompanied with an additional quirk.

If edit a line that contains the following :

Code:
   "Xft:v1:antialias=true"
then with the cursor being on the "t" of true and the left arrow key is pressed, instead of positioning over to the "=" it skips to the "a" of "antialias". Similar behaviour happens in the right direction also, it skips to "t" of "true" skipping "antialias".

Both the erratic cursor positioning and the colour changes happen in XFCE and FVWM.2.6.1 (in extra).

Neither this erratic cursor positioning nor the colour changes happen when trying vim under rxvt in either window managers.

I haven't tried the workarounds presented here... I just found this topic...
 
Old 05-07-2011, 09:48 PM   #7
slakmagik
Senior Member
 
Registered: Feb 2003
Distribution: Slackware
Posts: 4,113

Rep: Reputation: Disabled
Quote:
Originally Posted by elyk View Post
But... for some reason it doesn't set $TERM correctly. Appears that xterm checks for "xterm-256color" in termcap instead of the more modern terminfo, and since it's not there by default, it falls back to using "xterm". So I added xterm-256color after xterm-color in /etc/termcap like this. I don't know if it's correct, but it seems to work okay so far.
Code:
vs|xterm|xterm-color|xterm-256color|vs100|xterm terminal emulator (X Window System):\
This may really be more of a vim problem. IOW, vim is receiving TERM as 'xterm-256color' and treating it differently even though it's the exact same termcap as 'xterm'. Putting the following in ~/.vimrc also seems to fix the issue for me (and it wasn't always needed - this is some relatively recent change):

Code:
if &term =~ "xterm"
  set t_Co=256
endif

Last edited by slakmagik; 05-07-2011 at 09:50 PM.
 
Old 05-09-2011, 09:21 AM   #8
rouvas
Member
 
Registered: Aug 2006
Location: Greece
Distribution: Slackware.12.2
Posts: 104
Blog Entries: 3

Rep: Reputation: 21
Well, setting t_Co to 256 solved the "changing colors" syndrome, but had not effect on the erratic cursor movement I have as described in http://www.linuxquestions.org/questi...6/#post4349599

I have to add that if I navigate using the h,j,k,l keys instead of the arrow keys then the erratic behavior is not observed.

Could it be an xorg issue?

I have the following in /etc/X11/xorg.conf.d/90-keyboard-layout.conf :

Code:
Section "InputClass"
        Identifier "keyboard-all"
        MatchIsKeyboard "on"
        MatchDevicePath "/dev/input/event*"
        Driver "evdev"
        Option "XkbLayout" "us,el"
        #Option "XkbVariant" ""
        #Option "XkbOptions" "terminate:ctrl_alt_bksp"
        Option "XkbOptions" "grp:ctrl_shift_toggle"
        #Option "XkbModel"  "pc104"
EndSection
I don't have any other custom xorg config files.

I should also add, that for the last 10 years or so I have the following .Xdefaults entries for xterm:

Code:
xterm*background:       black
xterm*foreground:       grey
xterm*geometry: 90x43
xterm*font:     -etl-grfixed-medium-r-normal-*-*-120-*-*-c-*-iso8859-7
xterm.eightBitInput:    true
xterm*multiScroll:      on
xterm*jumpScroll:       on
xterm*ScrollBar: on
xterm*SaveLines: 2000
xterm.eightBitOutput:   true

Last edited by rouvas; 05-09-2011 at 09:25 AM. Reason: Add .Xdefaults entries
 
Old 05-09-2011, 01:41 PM   #9
slakmagik
Senior Member
 
Registered: Feb 2003
Distribution: Slackware
Posts: 4,113

Rep: Reputation: Disabled
Quote:
Originally Posted by rouvas View Post
Well, setting t_Co to 256 solved the "changing colors" syndrome, but had not effect on the erratic cursor movement I have as described in http://www.linuxquestions.org/questi...6/#post4349599
Sorry, that wasn't to you, as such, but to the thread topic - t_Co would only effect colors. I don't know what the cursor movement fix would be. I suspect that's not a vim problem but, if it is, maybe ':h term.txt' will provide some ideas.
 
Old 05-09-2011, 03:08 PM   #10
rouvas
Member
 
Registered: Aug 2006
Location: Greece
Distribution: Slackware.12.2
Posts: 104
Blog Entries: 3

Rep: Reputation: 21
Nothing to worry about. My response was to the thread.

About the erratic cursor movement, it must be something else. I have also trouble with the "Home" key in the rxvt command line.

I don't really understand the situation. I have the same settings for .Xdefaults and xorg.conf for the last 10-12 years or so. The only time I had queer issues like these, was when the keyboard model was faulty recognised, only it's been a *long* time that had happened.
 
Old 05-11-2011, 07:01 PM   #11
goldfinch
LQ Newbie
 
Registered: May 2011
Distribution: Slackware
Posts: 6

Original Poster
Rep: Reputation: 0
Thanks for all the replies.

I'm going to mark this thread [SOLVED] since there are some good workarounds for the problem presented here. (They are easier than rebuilding/upgrading vim. )
 
Old 04-27-2012, 01:59 PM   #12
me1040468
LQ Newbie
 
Registered: Apr 2007
Location: Delhi, India
Distribution: Gentoo
Posts: 12

Rep: Reputation: 0
writing set term=xterm-256colors in .vimrc also works for me
 
Old 08-19-2012, 01:52 AM   #13
elyk
Member
 
Registered: Jun 2004
Distribution: Slackware
Posts: 241

Rep: Reputation: 49
I noticed the color changing again after testing out 14.0, so I'm looking for a better solution. This time I'm going to blame xterm. Here's what happens:
  1. vim starts and queries termcap/terminfo/built-in settings/etc. for what the terminal supports. If the terminal identifies itself as "xterm" then the default is 8 colors.
  2. Next, vim says to itself, "I don't really trust what termcap says, so I'll just query the terminal myself." It asks xterm how many colors it supports, among other things. This behavior must have changed between 13.1 and 13.37.
  3. xterm is compiled with --enable-256-color so the response is always going to be 256, even though the termcap says 8 if $TERM == "xterm" (which was set by xterm).
  4. On the next screen redraw, vim switches over to 256-color mode. Since this happens after the first screen redraw it's obvious and annoying.

So I think the solution is to prevent xterm from lying about what it supports. It should set $TERM to xterm-256color if it's going to report that it supports 256 colors. Recompiling xterm with
Code:
--disable-full-tgetent --with-terminal-type=xterm-256color
seems to work. (That first flag tells it to link against libncurses instead of libtermcap. It will use terminfo instead of the obsolete termcap so you don't have to modify /etc/termcap like in my earlier post.)

Also I noticed that rxvt identifies itself with $TERM="xterm". It doesn't respond when vim asks how many colors it supports, so you get 8 colors. Recompiling rxvt with
Code:
--enable-256-color --with-term=rxvt-256color
improves things. Try it out with
Code:
:runtime syntax/colortest.vim
from within vim.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Vim: making him not to use colours. stf92 Linux - Newbie 1 11-09-2010 10:06 PM
How to change Xterm colours satimis Ubuntu 2 10-01-2007 05:54 AM
Which ioctl to use to get the key pressed in the key board? Sreeram B S Linux - Kernel 0 02-24-2007 02:02 AM
Colours in Xterm, Xmms and mounting issues cheema Debian 13 01-12-2006 02:58 PM
VIM and Colours krumms Linux - Software 5 05-23-2004 09:15 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware

All times are GMT -5. The time now is 02:01 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration